2
0

pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.280';
  24. PDFJS.build = '7d4303b';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var AnnotationBorderStyleType = {
  73. SOLID: 1,
  74. DASHED: 2,
  75. BEVELED: 3,
  76. INSET: 4,
  77. UNDERLINE: 5
  78. };
  79. var StreamType = {
  80. UNKNOWN: 0,
  81. FLATE: 1,
  82. LZW: 2,
  83. DCT: 3,
  84. JPX: 4,
  85. JBIG: 5,
  86. A85: 6,
  87. AHX: 7,
  88. CCF: 8,
  89. RL: 9
  90. };
  91. var FontType = {
  92. UNKNOWN: 0,
  93. TYPE1: 1,
  94. TYPE1C: 2,
  95. CIDFONTTYPE0: 3,
  96. CIDFONTTYPE0C: 4,
  97. TRUETYPE: 5,
  98. CIDFONTTYPE2: 6,
  99. TYPE3: 7,
  100. OPENTYPE: 8,
  101. TYPE0: 9,
  102. MMTYPE1: 10
  103. };
  104. // The global PDFJS object exposes the API
  105. // In production, it will be declared outside a global wrapper
  106. // In development, it will be declared here
  107. if (!globalScope.PDFJS) {
  108. globalScope.PDFJS = {};
  109. }
  110. globalScope.PDFJS.pdfBug = false;
  111. PDFJS.VERBOSITY_LEVELS = {
  112. errors: 0,
  113. warnings: 1,
  114. infos: 5
  115. };
  116. // All the possible operations for an operator list.
  117. var OPS = PDFJS.OPS = {
  118. // Intentionally start from 1 so it is easy to spot bad operators that will be
  119. // 0's.
  120. dependency: 1,
  121. setLineWidth: 2,
  122. setLineCap: 3,
  123. setLineJoin: 4,
  124. setMiterLimit: 5,
  125. setDash: 6,
  126. setRenderingIntent: 7,
  127. setFlatness: 8,
  128. setGState: 9,
  129. save: 10,
  130. restore: 11,
  131. transform: 12,
  132. moveTo: 13,
  133. lineTo: 14,
  134. curveTo: 15,
  135. curveTo2: 16,
  136. curveTo3: 17,
  137. closePath: 18,
  138. rectangle: 19,
  139. stroke: 20,
  140. closeStroke: 21,
  141. fill: 22,
  142. eoFill: 23,
  143. fillStroke: 24,
  144. eoFillStroke: 25,
  145. closeFillStroke: 26,
  146. closeEOFillStroke: 27,
  147. endPath: 28,
  148. clip: 29,
  149. eoClip: 30,
  150. beginText: 31,
  151. endText: 32,
  152. setCharSpacing: 33,
  153. setWordSpacing: 34,
  154. setHScale: 35,
  155. setLeading: 36,
  156. setFont: 37,
  157. setTextRenderingMode: 38,
  158. setTextRise: 39,
  159. moveText: 40,
  160. setLeadingMoveText: 41,
  161. setTextMatrix: 42,
  162. nextLine: 43,
  163. showText: 44,
  164. showSpacedText: 45,
  165. nextLineShowText: 46,
  166. nextLineSetSpacingShowText: 47,
  167. setCharWidth: 48,
  168. setCharWidthAndBounds: 49,
  169. setStrokeColorSpace: 50,
  170. setFillColorSpace: 51,
  171. setStrokeColor: 52,
  172. setStrokeColorN: 53,
  173. setFillColor: 54,
  174. setFillColorN: 55,
  175. setStrokeGray: 56,
  176. setFillGray: 57,
  177. setStrokeRGBColor: 58,
  178. setFillRGBColor: 59,
  179. setStrokeCMYKColor: 60,
  180. setFillCMYKColor: 61,
  181. shadingFill: 62,
  182. beginInlineImage: 63,
  183. beginImageData: 64,
  184. endInlineImage: 65,
  185. paintXObject: 66,
  186. markPoint: 67,
  187. markPointProps: 68,
  188. beginMarkedContent: 69,
  189. beginMarkedContentProps: 70,
  190. endMarkedContent: 71,
  191. beginCompat: 72,
  192. endCompat: 73,
  193. paintFormXObjectBegin: 74,
  194. paintFormXObjectEnd: 75,
  195. beginGroup: 76,
  196. endGroup: 77,
  197. beginAnnotations: 78,
  198. endAnnotations: 79,
  199. beginAnnotation: 80,
  200. endAnnotation: 81,
  201. paintJpegXObject: 82,
  202. paintImageMaskXObject: 83,
  203. paintImageMaskXObjectGroup: 84,
  204. paintImageXObject: 85,
  205. paintInlineImageXObject: 86,
  206. paintInlineImageXObjectGroup: 87,
  207. paintImageXObjectRepeat: 88,
  208. paintImageMaskXObjectRepeat: 89,
  209. paintSolidColorImageMask: 90,
  210. constructPath: 91
  211. };
  212. // A notice for devs. These are good for things that are helpful to devs, such
  213. // as warning that Workers were disabled, which is important to devs but not
  214. // end users.
  215. function info(msg) {
  216. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  217. console.log('Info: ' + msg);
  218. }
  219. }
  220. // Non-fatal warnings.
  221. function warn(msg) {
  222. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  223. console.log('Warning: ' + msg);
  224. }
  225. }
  226. // Fatal errors that should trigger the fallback UI and halt execution by
  227. // throwing an exception.
  228. function error(msg) {
  229. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  230. console.log('Error: ' + msg);
  231. console.log(backtrace());
  232. }
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgent support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function utf8StringToString(str) {
  875. return unescape(encodeURIComponent(str));
  876. }
  877. function isEmptyObj(obj) {
  878. for (var key in obj) {
  879. return false;
  880. }
  881. return true;
  882. }
  883. function isBool(v) {
  884. return typeof v === 'boolean';
  885. }
  886. function isInt(v) {
  887. return typeof v === 'number' && ((v | 0) === v);
  888. }
  889. function isNum(v) {
  890. return typeof v === 'number';
  891. }
  892. function isString(v) {
  893. return typeof v === 'string';
  894. }
  895. function isName(v) {
  896. return v instanceof Name;
  897. }
  898. function isCmd(v, cmd) {
  899. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  900. }
  901. function isDict(v, type) {
  902. if (!(v instanceof Dict)) {
  903. return false;
  904. }
  905. if (!type) {
  906. return true;
  907. }
  908. var dictType = v.get('Type');
  909. return isName(dictType) && dictType.name === type;
  910. }
  911. function isArray(v) {
  912. return v instanceof Array;
  913. }
  914. function isStream(v) {
  915. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  916. }
  917. function isArrayBuffer(v) {
  918. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  919. }
  920. function isRef(v) {
  921. return v instanceof Ref;
  922. }
  923. /**
  924. * Promise Capability object.
  925. *
  926. * @typedef {Object} PromiseCapability
  927. * @property {Promise} promise - A promise object.
  928. * @property {function} resolve - Fullfills the promise.
  929. * @property {function} reject - Rejects the promise.
  930. */
  931. /**
  932. * Creates a promise capability object.
  933. * @alias PDFJS.createPromiseCapability
  934. *
  935. * @return {PromiseCapability} A capability object contains:
  936. * - a Promise, resolve and reject methods.
  937. */
  938. function createPromiseCapability() {
  939. var capability = {};
  940. capability.promise = new Promise(function (resolve, reject) {
  941. capability.resolve = resolve;
  942. capability.reject = reject;
  943. });
  944. return capability;
  945. }
  946. PDFJS.createPromiseCapability = createPromiseCapability;
  947. /**
  948. * Polyfill for Promises:
  949. * The following promise implementation tries to generally implement the
  950. * Promise/A+ spec. Some notable differences from other promise libaries are:
  951. * - There currently isn't a seperate deferred and promise object.
  952. * - Unhandled rejections eventually show an error if they aren't handled.
  953. *
  954. * Based off of the work in:
  955. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  956. */
  957. (function PromiseClosure() {
  958. if (globalScope.Promise) {
  959. // Promises existing in the DOM/Worker, checking presence of all/resolve
  960. if (typeof globalScope.Promise.all !== 'function') {
  961. globalScope.Promise.all = function (iterable) {
  962. var count = 0, results = [], resolve, reject;
  963. var promise = new globalScope.Promise(function (resolve_, reject_) {
  964. resolve = resolve_;
  965. reject = reject_;
  966. });
  967. iterable.forEach(function (p, i) {
  968. count++;
  969. p.then(function (result) {
  970. results[i] = result;
  971. count--;
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. }, reject);
  976. });
  977. if (count === 0) {
  978. resolve(results);
  979. }
  980. return promise;
  981. };
  982. }
  983. if (typeof globalScope.Promise.resolve !== 'function') {
  984. globalScope.Promise.resolve = function (value) {
  985. return new globalScope.Promise(function (resolve) { resolve(value); });
  986. };
  987. }
  988. if (typeof globalScope.Promise.reject !== 'function') {
  989. globalScope.Promise.reject = function (reason) {
  990. return new globalScope.Promise(function (resolve, reject) {
  991. reject(reason);
  992. });
  993. };
  994. }
  995. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  996. globalScope.Promise.prototype.catch = function (onReject) {
  997. return globalScope.Promise.prototype.then(undefined, onReject);
  998. };
  999. }
  1000. return;
  1001. }
  1002. var STATUS_PENDING = 0;
  1003. var STATUS_RESOLVED = 1;
  1004. var STATUS_REJECTED = 2;
  1005. // In an attempt to avoid silent exceptions, unhandled rejections are
  1006. // tracked and if they aren't handled in a certain amount of time an
  1007. // error is logged.
  1008. var REJECTION_TIMEOUT = 500;
  1009. var HandlerManager = {
  1010. handlers: [],
  1011. running: false,
  1012. unhandledRejections: [],
  1013. pendingRejectionCheck: false,
  1014. scheduleHandlers: function scheduleHandlers(promise) {
  1015. if (promise._status === STATUS_PENDING) {
  1016. return;
  1017. }
  1018. this.handlers = this.handlers.concat(promise._handlers);
  1019. promise._handlers = [];
  1020. if (this.running) {
  1021. return;
  1022. }
  1023. this.running = true;
  1024. setTimeout(this.runHandlers.bind(this), 0);
  1025. },
  1026. runHandlers: function runHandlers() {
  1027. var RUN_TIMEOUT = 1; // ms
  1028. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1029. while (this.handlers.length > 0) {
  1030. var handler = this.handlers.shift();
  1031. var nextStatus = handler.thisPromise._status;
  1032. var nextValue = handler.thisPromise._value;
  1033. try {
  1034. if (nextStatus === STATUS_RESOLVED) {
  1035. if (typeof handler.onResolve === 'function') {
  1036. nextValue = handler.onResolve(nextValue);
  1037. }
  1038. } else if (typeof handler.onReject === 'function') {
  1039. nextValue = handler.onReject(nextValue);
  1040. nextStatus = STATUS_RESOLVED;
  1041. if (handler.thisPromise._unhandledRejection) {
  1042. this.removeUnhandeledRejection(handler.thisPromise);
  1043. }
  1044. }
  1045. } catch (ex) {
  1046. nextStatus = STATUS_REJECTED;
  1047. nextValue = ex;
  1048. }
  1049. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1050. if (Date.now() >= timeoutAt) {
  1051. break;
  1052. }
  1053. }
  1054. if (this.handlers.length > 0) {
  1055. setTimeout(this.runHandlers.bind(this), 0);
  1056. return;
  1057. }
  1058. this.running = false;
  1059. },
  1060. addUnhandledRejection: function addUnhandledRejection(promise) {
  1061. this.unhandledRejections.push({
  1062. promise: promise,
  1063. time: Date.now()
  1064. });
  1065. this.scheduleRejectionCheck();
  1066. },
  1067. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1068. promise._unhandledRejection = false;
  1069. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1070. if (this.unhandledRejections[i].promise === promise) {
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. },
  1076. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1077. if (this.pendingRejectionCheck) {
  1078. return;
  1079. }
  1080. this.pendingRejectionCheck = true;
  1081. setTimeout(function rejectionCheck() {
  1082. this.pendingRejectionCheck = false;
  1083. var now = Date.now();
  1084. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1085. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1086. var unhandled = this.unhandledRejections[i].promise._value;
  1087. var msg = 'Unhandled rejection: ' + unhandled;
  1088. if (unhandled.stack) {
  1089. msg += '\n' + unhandled.stack;
  1090. }
  1091. warn(msg);
  1092. this.unhandledRejections.splice(i);
  1093. i--;
  1094. }
  1095. }
  1096. if (this.unhandledRejections.length) {
  1097. this.scheduleRejectionCheck();
  1098. }
  1099. }.bind(this), REJECTION_TIMEOUT);
  1100. }
  1101. };
  1102. function Promise(resolver) {
  1103. this._status = STATUS_PENDING;
  1104. this._handlers = [];
  1105. try {
  1106. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1107. } catch (e) {
  1108. this._reject(e);
  1109. }
  1110. }
  1111. /**
  1112. * Builds a promise that is resolved when all the passed in promises are
  1113. * resolved.
  1114. * @param {array} array of data and/or promises to wait for.
  1115. * @return {Promise} New dependant promise.
  1116. */
  1117. Promise.all = function Promise_all(promises) {
  1118. var resolveAll, rejectAll;
  1119. var deferred = new Promise(function (resolve, reject) {
  1120. resolveAll = resolve;
  1121. rejectAll = reject;
  1122. });
  1123. var unresolved = promises.length;
  1124. var results = [];
  1125. if (unresolved === 0) {
  1126. resolveAll(results);
  1127. return deferred;
  1128. }
  1129. function reject(reason) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results = [];
  1134. rejectAll(reason);
  1135. }
  1136. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1137. var promise = promises[i];
  1138. var resolve = (function(i) {
  1139. return function(value) {
  1140. if (deferred._status === STATUS_REJECTED) {
  1141. return;
  1142. }
  1143. results[i] = value;
  1144. unresolved--;
  1145. if (unresolved === 0) {
  1146. resolveAll(results);
  1147. }
  1148. };
  1149. })(i);
  1150. if (Promise.isPromise(promise)) {
  1151. promise.then(resolve, reject);
  1152. } else {
  1153. resolve(promise);
  1154. }
  1155. }
  1156. return deferred;
  1157. };
  1158. /**
  1159. * Checks if the value is likely a promise (has a 'then' function).
  1160. * @return {boolean} true if value is thenable
  1161. */
  1162. Promise.isPromise = function Promise_isPromise(value) {
  1163. return value && typeof value.then === 'function';
  1164. };
  1165. /**
  1166. * Creates resolved promise
  1167. * @param value resolve value
  1168. * @returns {Promise}
  1169. */
  1170. Promise.resolve = function Promise_resolve(value) {
  1171. return new Promise(function (resolve) { resolve(value); });
  1172. };
  1173. /**
  1174. * Creates rejected promise
  1175. * @param reason rejection value
  1176. * @returns {Promise}
  1177. */
  1178. Promise.reject = function Promise_reject(reason) {
  1179. return new Promise(function (resolve, reject) { reject(reason); });
  1180. };
  1181. Promise.prototype = {
  1182. _status: null,
  1183. _value: null,
  1184. _handlers: null,
  1185. _unhandledRejection: null,
  1186. _updateStatus: function Promise__updateStatus(status, value) {
  1187. if (this._status === STATUS_RESOLVED ||
  1188. this._status === STATUS_REJECTED) {
  1189. return;
  1190. }
  1191. if (status === STATUS_RESOLVED &&
  1192. Promise.isPromise(value)) {
  1193. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1194. this._updateStatus.bind(this, STATUS_REJECTED));
  1195. return;
  1196. }
  1197. this._status = status;
  1198. this._value = value;
  1199. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1200. this._unhandledRejection = true;
  1201. HandlerManager.addUnhandledRejection(this);
  1202. }
  1203. HandlerManager.scheduleHandlers(this);
  1204. },
  1205. _resolve: function Promise_resolve(value) {
  1206. this._updateStatus(STATUS_RESOLVED, value);
  1207. },
  1208. _reject: function Promise_reject(reason) {
  1209. this._updateStatus(STATUS_REJECTED, reason);
  1210. },
  1211. then: function Promise_then(onResolve, onReject) {
  1212. var nextPromise = new Promise(function (resolve, reject) {
  1213. this.resolve = resolve;
  1214. this.reject = reject;
  1215. });
  1216. this._handlers.push({
  1217. thisPromise: this,
  1218. onResolve: onResolve,
  1219. onReject: onReject,
  1220. nextPromise: nextPromise
  1221. });
  1222. HandlerManager.scheduleHandlers(this);
  1223. return nextPromise;
  1224. },
  1225. catch: function Promise_catch(onReject) {
  1226. return this.then(undefined, onReject);
  1227. }
  1228. };
  1229. globalScope.Promise = Promise;
  1230. })();
  1231. var StatTimer = (function StatTimerClosure() {
  1232. function rpad(str, pad, length) {
  1233. while (str.length < length) {
  1234. str += pad;
  1235. }
  1236. return str;
  1237. }
  1238. function StatTimer() {
  1239. this.started = {};
  1240. this.times = [];
  1241. this.enabled = true;
  1242. }
  1243. StatTimer.prototype = {
  1244. time: function StatTimer_time(name) {
  1245. if (!this.enabled) {
  1246. return;
  1247. }
  1248. if (name in this.started) {
  1249. warn('Timer is already running for ' + name);
  1250. }
  1251. this.started[name] = Date.now();
  1252. },
  1253. timeEnd: function StatTimer_timeEnd(name) {
  1254. if (!this.enabled) {
  1255. return;
  1256. }
  1257. if (!(name in this.started)) {
  1258. warn('Timer has not been started for ' + name);
  1259. }
  1260. this.times.push({
  1261. 'name': name,
  1262. 'start': this.started[name],
  1263. 'end': Date.now()
  1264. });
  1265. // Remove timer from started so it can be called again.
  1266. delete this.started[name];
  1267. },
  1268. toString: function StatTimer_toString() {
  1269. var i, ii;
  1270. var times = this.times;
  1271. var out = '';
  1272. // Find the longest name for padding purposes.
  1273. var longest = 0;
  1274. for (i = 0, ii = times.length; i < ii; ++i) {
  1275. var name = times[i]['name'];
  1276. if (name.length > longest) {
  1277. longest = name.length;
  1278. }
  1279. }
  1280. for (i = 0, ii = times.length; i < ii; ++i) {
  1281. var span = times[i];
  1282. var duration = span.end - span.start;
  1283. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1284. }
  1285. return out;
  1286. }
  1287. };
  1288. return StatTimer;
  1289. })();
  1290. PDFJS.createBlob = function createBlob(data, contentType) {
  1291. if (typeof Blob !== 'undefined') {
  1292. return new Blob([data], { type: contentType });
  1293. }
  1294. // Blob builder is deprecated in FF14 and removed in FF18.
  1295. var bb = new MozBlobBuilder();
  1296. bb.append(data);
  1297. return bb.getBlob(contentType);
  1298. };
  1299. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1300. // Blob/createObjectURL is not available, falling back to data schema.
  1301. var digits =
  1302. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1303. return function createObjectURL(data, contentType) {
  1304. if (!PDFJS.disableCreateObjectURL &&
  1305. typeof URL !== 'undefined' && URL.createObjectURL) {
  1306. var blob = PDFJS.createBlob(data, contentType);
  1307. return URL.createObjectURL(blob);
  1308. }
  1309. var buffer = 'data:' + contentType + ';base64,';
  1310. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1311. var b1 = data[i] & 0xFF;
  1312. var b2 = data[i + 1] & 0xFF;
  1313. var b3 = data[i + 2] & 0xFF;
  1314. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1315. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1316. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1317. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1318. }
  1319. return buffer;
  1320. };
  1321. })();
  1322. function MessageHandler(name, comObj) {
  1323. this.name = name;
  1324. this.comObj = comObj;
  1325. this.callbackIndex = 1;
  1326. this.postMessageTransfers = true;
  1327. var callbacksCapabilities = this.callbacksCapabilities = {};
  1328. var ah = this.actionHandler = {};
  1329. ah['console_log'] = [function ahConsoleLog(data) {
  1330. console.log.apply(console, data);
  1331. }];
  1332. ah['console_error'] = [function ahConsoleError(data) {
  1333. console.error.apply(console, data);
  1334. }];
  1335. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1336. UnsupportedManager.notify(data);
  1337. }];
  1338. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1339. var data = event.data;
  1340. if (data.isReply) {
  1341. var callbackId = data.callbackId;
  1342. if (data.callbackId in callbacksCapabilities) {
  1343. var callback = callbacksCapabilities[callbackId];
  1344. delete callbacksCapabilities[callbackId];
  1345. if ('error' in data) {
  1346. callback.reject(data.error);
  1347. } else {
  1348. callback.resolve(data.data);
  1349. }
  1350. } else {
  1351. error('Cannot resolve callback ' + callbackId);
  1352. }
  1353. } else if (data.action in ah) {
  1354. var action = ah[data.action];
  1355. if (data.callbackId) {
  1356. Promise.resolve().then(function () {
  1357. return action[0].call(action[1], data.data);
  1358. }).then(function (result) {
  1359. comObj.postMessage({
  1360. isReply: true,
  1361. callbackId: data.callbackId,
  1362. data: result
  1363. });
  1364. }, function (reason) {
  1365. comObj.postMessage({
  1366. isReply: true,
  1367. callbackId: data.callbackId,
  1368. error: reason
  1369. });
  1370. });
  1371. } else {
  1372. action[0].call(action[1], data.data);
  1373. }
  1374. } else {
  1375. error('Unknown action from worker: ' + data.action);
  1376. }
  1377. };
  1378. }
  1379. MessageHandler.prototype = {
  1380. on: function messageHandlerOn(actionName, handler, scope) {
  1381. var ah = this.actionHandler;
  1382. if (ah[actionName]) {
  1383. error('There is already an actionName called "' + actionName + '"');
  1384. }
  1385. ah[actionName] = [handler, scope];
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * @param {String} actionName Action to call.
  1390. * @param {JSON} data JSON data to send.
  1391. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1392. */
  1393. send: function messageHandlerSend(actionName, data, transfers) {
  1394. var message = {
  1395. action: actionName,
  1396. data: data
  1397. };
  1398. this.postMessage(message, transfers);
  1399. },
  1400. /**
  1401. * Sends a message to the comObj to invoke the action with the supplied data.
  1402. * Expects that other side will callback with the response.
  1403. * @param {String} actionName Action to call.
  1404. * @param {JSON} data JSON data to send.
  1405. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1406. * @returns {Promise} Promise to be resolved with response data.
  1407. */
  1408. sendWithPromise:
  1409. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1410. var callbackId = this.callbackIndex++;
  1411. var message = {
  1412. action: actionName,
  1413. data: data,
  1414. callbackId: callbackId
  1415. };
  1416. var capability = createPromiseCapability();
  1417. this.callbacksCapabilities[callbackId] = capability;
  1418. try {
  1419. this.postMessage(message, transfers);
  1420. } catch (e) {
  1421. capability.reject(e);
  1422. }
  1423. return capability.promise;
  1424. },
  1425. /**
  1426. * Sends raw message to the comObj.
  1427. * @private
  1428. * @param message {Object} Raw message.
  1429. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1430. */
  1431. postMessage: function (message, transfers) {
  1432. if (transfers && this.postMessageTransfers) {
  1433. this.comObj.postMessage(message, transfers);
  1434. } else {
  1435. this.comObj.postMessage(message);
  1436. }
  1437. }
  1438. };
  1439. function loadJpegStream(id, imageUrl, objs) {
  1440. var img = new Image();
  1441. img.onload = (function loadJpegStream_onloadClosure() {
  1442. objs.resolve(id, img);
  1443. });
  1444. img.onerror = (function loadJpegStream_onerrorClosure() {
  1445. objs.resolve(id, null);
  1446. warn('Error during JPEG image loading');
  1447. });
  1448. img.src = imageUrl;
  1449. }
  1450. var NetworkManager = (function NetworkManagerClosure() {
  1451. var OK_RESPONSE = 200;
  1452. var PARTIAL_CONTENT_RESPONSE = 206;
  1453. function NetworkManager(url, args) {
  1454. this.url = url;
  1455. args = args || {};
  1456. this.isHttp = /^https?:/i.test(url);
  1457. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1458. this.withCredentials = args.withCredentials || false;
  1459. this.getXhr = args.getXhr ||
  1460. function NetworkManager_getXhr() {
  1461. return new XMLHttpRequest();
  1462. };
  1463. this.currXhrId = 0;
  1464. this.pendingRequests = {};
  1465. this.loadedRequests = {};
  1466. }
  1467. function getArrayBuffer(xhr) {
  1468. var data = xhr.response;
  1469. if (typeof data !== 'string') {
  1470. return data;
  1471. }
  1472. var length = data.length;
  1473. var array = new Uint8Array(length);
  1474. for (var i = 0; i < length; i++) {
  1475. array[i] = data.charCodeAt(i) & 0xFF;
  1476. }
  1477. return array.buffer;
  1478. }
  1479. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1480. var x = new XMLHttpRequest();
  1481. try {
  1482. // Firefox 37- required .open() to be called before setting responseType.
  1483. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1484. x.open('GET', 'https://example.com');
  1485. } catch (e) {
  1486. // Even though the URL is not visited, .open() could fail if the URL is
  1487. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1488. // When this error occurs, this feature detection method will mistakenly
  1489. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1490. }
  1491. try {
  1492. x.responseType = 'moz-chunked-arraybuffer';
  1493. return x.responseType === 'moz-chunked-arraybuffer';
  1494. } catch (e) {
  1495. return false;
  1496. }
  1497. })();
  1498. NetworkManager.prototype = {
  1499. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1500. var args = {
  1501. begin: begin,
  1502. end: end
  1503. };
  1504. for (var prop in listeners) {
  1505. args[prop] = listeners[prop];
  1506. }
  1507. return this.request(args);
  1508. },
  1509. requestFull: function NetworkManager_requestFull(listeners) {
  1510. return this.request(listeners);
  1511. },
  1512. request: function NetworkManager_request(args) {
  1513. var xhr = this.getXhr();
  1514. var xhrId = this.currXhrId++;
  1515. var pendingRequest = this.pendingRequests[xhrId] = {
  1516. xhr: xhr
  1517. };
  1518. xhr.open('GET', this.url);
  1519. xhr.withCredentials = this.withCredentials;
  1520. for (var property in this.httpHeaders) {
  1521. var value = this.httpHeaders[property];
  1522. if (typeof value === 'undefined') {
  1523. continue;
  1524. }
  1525. xhr.setRequestHeader(property, value);
  1526. }
  1527. if (this.isHttp && 'begin' in args && 'end' in args) {
  1528. var rangeStr = args.begin + '-' + (args.end - 1);
  1529. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1530. pendingRequest.expectedStatus = 206;
  1531. } else {
  1532. pendingRequest.expectedStatus = 200;
  1533. }
  1534. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1535. if (useMozChunkedLoading) {
  1536. xhr.responseType = 'moz-chunked-arraybuffer';
  1537. pendingRequest.onProgressiveData = args.onProgressiveData;
  1538. pendingRequest.mozChunked = true;
  1539. } else {
  1540. xhr.responseType = 'arraybuffer';
  1541. }
  1542. if (args.onError) {
  1543. xhr.onerror = function(evt) {
  1544. args.onError(xhr.status);
  1545. };
  1546. }
  1547. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1548. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1549. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1550. pendingRequest.onDone = args.onDone;
  1551. pendingRequest.onError = args.onError;
  1552. pendingRequest.onProgress = args.onProgress;
  1553. xhr.send(null);
  1554. return xhrId;
  1555. },
  1556. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1557. var pendingRequest = this.pendingRequests[xhrId];
  1558. if (!pendingRequest) {
  1559. // Maybe abortRequest was called...
  1560. return;
  1561. }
  1562. if (pendingRequest.mozChunked) {
  1563. var chunk = getArrayBuffer(pendingRequest.xhr);
  1564. pendingRequest.onProgressiveData(chunk);
  1565. }
  1566. var onProgress = pendingRequest.onProgress;
  1567. if (onProgress) {
  1568. onProgress(evt);
  1569. }
  1570. },
  1571. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1572. var pendingRequest = this.pendingRequests[xhrId];
  1573. if (!pendingRequest) {
  1574. // Maybe abortRequest was called...
  1575. return;
  1576. }
  1577. var xhr = pendingRequest.xhr;
  1578. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1579. pendingRequest.onHeadersReceived();
  1580. delete pendingRequest.onHeadersReceived;
  1581. }
  1582. if (xhr.readyState !== 4) {
  1583. return;
  1584. }
  1585. if (!(xhrId in this.pendingRequests)) {
  1586. // The XHR request might have been aborted in onHeadersReceived()
  1587. // callback, in which case we should abort request
  1588. return;
  1589. }
  1590. delete this.pendingRequests[xhrId];
  1591. // success status == 0 can be on ftp, file and other protocols
  1592. if (xhr.status === 0 && this.isHttp) {
  1593. if (pendingRequest.onError) {
  1594. pendingRequest.onError(xhr.status);
  1595. }
  1596. return;
  1597. }
  1598. var xhrStatus = xhr.status || OK_RESPONSE;
  1599. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1600. // "A server MAY ignore the Range header". This means it's possible to
  1601. // get a 200 rather than a 206 response from a range request.
  1602. var ok_response_on_range_request =
  1603. xhrStatus === OK_RESPONSE &&
  1604. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1605. if (!ok_response_on_range_request &&
  1606. xhrStatus !== pendingRequest.expectedStatus) {
  1607. if (pendingRequest.onError) {
  1608. pendingRequest.onError(xhr.status);
  1609. }
  1610. return;
  1611. }
  1612. this.loadedRequests[xhrId] = true;
  1613. var chunk = getArrayBuffer(xhr);
  1614. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1615. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1616. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1617. var begin = parseInt(matches[1], 10);
  1618. pendingRequest.onDone({
  1619. begin: begin,
  1620. chunk: chunk
  1621. });
  1622. } else if (pendingRequest.onProgressiveData) {
  1623. pendingRequest.onDone(null);
  1624. } else {
  1625. pendingRequest.onDone({
  1626. begin: 0,
  1627. chunk: chunk
  1628. });
  1629. }
  1630. },
  1631. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1632. for (var xhrId in this.pendingRequests) {
  1633. return true;
  1634. }
  1635. return false;
  1636. },
  1637. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1638. return this.pendingRequests[xhrId].xhr;
  1639. },
  1640. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1641. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1642. },
  1643. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1644. return xhrId in this.pendingRequests;
  1645. },
  1646. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1647. return xhrId in this.loadedRequests;
  1648. },
  1649. abortAllRequests: function NetworkManager_abortAllRequests() {
  1650. for (var xhrId in this.pendingRequests) {
  1651. this.abortRequest(xhrId | 0);
  1652. }
  1653. },
  1654. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1655. var xhr = this.pendingRequests[xhrId].xhr;
  1656. delete this.pendingRequests[xhrId];
  1657. xhr.abort();
  1658. }
  1659. };
  1660. return NetworkManager;
  1661. })();
  1662. var ChunkedStream = (function ChunkedStreamClosure() {
  1663. function ChunkedStream(length, chunkSize, manager) {
  1664. this.bytes = new Uint8Array(length);
  1665. this.start = 0;
  1666. this.pos = 0;
  1667. this.end = length;
  1668. this.chunkSize = chunkSize;
  1669. this.loadedChunks = [];
  1670. this.numChunksLoaded = 0;
  1671. this.numChunks = Math.ceil(length / chunkSize);
  1672. this.manager = manager;
  1673. this.progressiveDataLength = 0;
  1674. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1675. }
  1676. // required methods for a stream. if a particular stream does not
  1677. // implement these, an error should be thrown
  1678. ChunkedStream.prototype = {
  1679. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1680. var chunks = [];
  1681. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1682. if (!this.loadedChunks[chunk]) {
  1683. chunks.push(chunk);
  1684. }
  1685. }
  1686. return chunks;
  1687. },
  1688. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1689. return [this];
  1690. },
  1691. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1692. return this.numChunksLoaded === this.numChunks;
  1693. },
  1694. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1695. var end = begin + chunk.byteLength;
  1696. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1697. // Using this.length is inaccurate here since this.start can be moved
  1698. // See ChunkedStream.moveStart()
  1699. var length = this.bytes.length;
  1700. assert(end % this.chunkSize === 0 || end === length,
  1701. 'Bad end offset: ' + end);
  1702. this.bytes.set(new Uint8Array(chunk), begin);
  1703. var chunkSize = this.chunkSize;
  1704. var beginChunk = Math.floor(begin / chunkSize);
  1705. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1706. var curChunk;
  1707. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1708. if (!this.loadedChunks[curChunk]) {
  1709. this.loadedChunks[curChunk] = true;
  1710. ++this.numChunksLoaded;
  1711. }
  1712. }
  1713. },
  1714. onReceiveProgressiveData:
  1715. function ChunkedStream_onReceiveProgressiveData(data) {
  1716. var position = this.progressiveDataLength;
  1717. var beginChunk = Math.floor(position / this.chunkSize);
  1718. this.bytes.set(new Uint8Array(data), position);
  1719. position += data.byteLength;
  1720. this.progressiveDataLength = position;
  1721. var endChunk = position >= this.end ? this.numChunks :
  1722. Math.floor(position / this.chunkSize);
  1723. var curChunk;
  1724. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1725. if (!this.loadedChunks[curChunk]) {
  1726. this.loadedChunks[curChunk] = true;
  1727. ++this.numChunksLoaded;
  1728. }
  1729. }
  1730. },
  1731. ensureByte: function ChunkedStream_ensureByte(pos) {
  1732. var chunk = Math.floor(pos / this.chunkSize);
  1733. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1734. return;
  1735. }
  1736. if (!this.loadedChunks[chunk]) {
  1737. throw new MissingDataException(pos, pos + 1);
  1738. }
  1739. this.lastSuccessfulEnsureByteChunk = chunk;
  1740. },
  1741. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1742. if (begin >= end) {
  1743. return;
  1744. }
  1745. if (end <= this.progressiveDataLength) {
  1746. return;
  1747. }
  1748. var chunkSize = this.chunkSize;
  1749. var beginChunk = Math.floor(begin / chunkSize);
  1750. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1751. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1752. if (!this.loadedChunks[chunk]) {
  1753. throw new MissingDataException(begin, end);
  1754. }
  1755. }
  1756. },
  1757. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1758. var chunk, n;
  1759. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1760. if (!this.loadedChunks[chunk]) {
  1761. return chunk;
  1762. }
  1763. }
  1764. // Wrap around to beginning
  1765. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1766. if (!this.loadedChunks[chunk]) {
  1767. return chunk;
  1768. }
  1769. }
  1770. return null;
  1771. },
  1772. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1773. return !!this.loadedChunks[chunk];
  1774. },
  1775. get length() {
  1776. return this.end - this.start;
  1777. },
  1778. get isEmpty() {
  1779. return this.length === 0;
  1780. },
  1781. getByte: function ChunkedStream_getByte() {
  1782. var pos = this.pos;
  1783. if (pos >= this.end) {
  1784. return -1;
  1785. }
  1786. this.ensureByte(pos);
  1787. return this.bytes[this.pos++];
  1788. },
  1789. getUint16: function ChunkedStream_getUint16() {
  1790. var b0 = this.getByte();
  1791. var b1 = this.getByte();
  1792. if (b0 === -1 || b1 === -1) {
  1793. return -1;
  1794. }
  1795. return (b0 << 8) + b1;
  1796. },
  1797. getInt32: function ChunkedStream_getInt32() {
  1798. var b0 = this.getByte();
  1799. var b1 = this.getByte();
  1800. var b2 = this.getByte();
  1801. var b3 = this.getByte();
  1802. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1803. },
  1804. // returns subarray of original buffer
  1805. // should only be read
  1806. getBytes: function ChunkedStream_getBytes(length) {
  1807. var bytes = this.bytes;
  1808. var pos = this.pos;
  1809. var strEnd = this.end;
  1810. if (!length) {
  1811. this.ensureRange(pos, strEnd);
  1812. return bytes.subarray(pos, strEnd);
  1813. }
  1814. var end = pos + length;
  1815. if (end > strEnd) {
  1816. end = strEnd;
  1817. }
  1818. this.ensureRange(pos, end);
  1819. this.pos = end;
  1820. return bytes.subarray(pos, end);
  1821. },
  1822. peekByte: function ChunkedStream_peekByte() {
  1823. var peekedByte = this.getByte();
  1824. this.pos--;
  1825. return peekedByte;
  1826. },
  1827. peekBytes: function ChunkedStream_peekBytes(length) {
  1828. var bytes = this.getBytes(length);
  1829. this.pos -= bytes.length;
  1830. return bytes;
  1831. },
  1832. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1833. this.ensureRange(begin, end);
  1834. return this.bytes.subarray(begin, end);
  1835. },
  1836. skip: function ChunkedStream_skip(n) {
  1837. if (!n) {
  1838. n = 1;
  1839. }
  1840. this.pos += n;
  1841. },
  1842. reset: function ChunkedStream_reset() {
  1843. this.pos = this.start;
  1844. },
  1845. moveStart: function ChunkedStream_moveStart() {
  1846. this.start = this.pos;
  1847. },
  1848. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1849. this.ensureRange(start, start + length);
  1850. function ChunkedStreamSubstream() {}
  1851. ChunkedStreamSubstream.prototype = Object.create(this);
  1852. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1853. var chunkSize = this.chunkSize;
  1854. var beginChunk = Math.floor(this.start / chunkSize);
  1855. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1856. var missingChunks = [];
  1857. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1858. if (!this.loadedChunks[chunk]) {
  1859. missingChunks.push(chunk);
  1860. }
  1861. }
  1862. return missingChunks;
  1863. };
  1864. var subStream = new ChunkedStreamSubstream();
  1865. subStream.pos = subStream.start = start;
  1866. subStream.end = start + length || this.end;
  1867. subStream.dict = dict;
  1868. return subStream;
  1869. },
  1870. isStream: true
  1871. };
  1872. return ChunkedStream;
  1873. })();
  1874. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1875. function ChunkedStreamManager(length, chunkSize, url, args) {
  1876. this.stream = new ChunkedStream(length, chunkSize, this);
  1877. this.length = length;
  1878. this.chunkSize = chunkSize;
  1879. this.url = url;
  1880. this.disableAutoFetch = args.disableAutoFetch;
  1881. var msgHandler = this.msgHandler = args.msgHandler;
  1882. if (args.chunkedViewerLoading) {
  1883. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1884. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1885. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1886. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1887. };
  1888. } else {
  1889. var getXhr = function getXhr() {
  1890. return new XMLHttpRequest();
  1891. };
  1892. this.networkManager = new NetworkManager(this.url, {
  1893. getXhr: getXhr,
  1894. httpHeaders: args.httpHeaders,
  1895. withCredentials: args.withCredentials
  1896. });
  1897. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1898. this.networkManager.requestRange(begin, end, {
  1899. onDone: this.onReceiveData.bind(this),
  1900. onProgress: this.onProgress.bind(this)
  1901. });
  1902. };
  1903. }
  1904. this.currRequestId = 0;
  1905. this.chunksNeededByRequest = {};
  1906. this.requestsByChunk = {};
  1907. this.callbacksByRequest = {};
  1908. this.progressiveDataLength = 0;
  1909. this._loadedStreamCapability = createPromiseCapability();
  1910. if (args.initialData) {
  1911. this.onReceiveData({chunk: args.initialData});
  1912. }
  1913. }
  1914. ChunkedStreamManager.prototype = {
  1915. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1916. return this._loadedStreamCapability.promise;
  1917. },
  1918. // Get all the chunks that are not yet loaded and groups them into
  1919. // contiguous ranges to load in as few requests as possible
  1920. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1921. var missingChunks = this.stream.getMissingChunks();
  1922. this.requestChunks(missingChunks);
  1923. return this._loadedStreamCapability.promise;
  1924. },
  1925. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1926. callback) {
  1927. var requestId = this.currRequestId++;
  1928. var chunksNeeded;
  1929. var i, ii;
  1930. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1931. for (i = 0, ii = chunks.length; i < ii; i++) {
  1932. if (!this.stream.hasChunk(chunks[i])) {
  1933. chunksNeeded[chunks[i]] = true;
  1934. }
  1935. }
  1936. if (isEmptyObj(chunksNeeded)) {
  1937. if (callback) {
  1938. callback();
  1939. }
  1940. return;
  1941. }
  1942. this.callbacksByRequest[requestId] = callback;
  1943. var chunksToRequest = [];
  1944. for (var chunk in chunksNeeded) {
  1945. chunk = chunk | 0;
  1946. if (!(chunk in this.requestsByChunk)) {
  1947. this.requestsByChunk[chunk] = [];
  1948. chunksToRequest.push(chunk);
  1949. }
  1950. this.requestsByChunk[chunk].push(requestId);
  1951. }
  1952. if (!chunksToRequest.length) {
  1953. return;
  1954. }
  1955. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1956. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1957. var groupedChunk = groupedChunksToRequest[i];
  1958. var begin = groupedChunk.beginChunk * this.chunkSize;
  1959. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1960. this.sendRequest(begin, end);
  1961. }
  1962. },
  1963. getStream: function ChunkedStreamManager_getStream() {
  1964. return this.stream;
  1965. },
  1966. // Loads any chunks in the requested range that are not yet loaded
  1967. requestRange: function ChunkedStreamManager_requestRange(
  1968. begin, end, callback) {
  1969. end = Math.min(end, this.length);
  1970. var beginChunk = this.getBeginChunk(begin);
  1971. var endChunk = this.getEndChunk(end);
  1972. var chunks = [];
  1973. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1974. chunks.push(chunk);
  1975. }
  1976. this.requestChunks(chunks, callback);
  1977. },
  1978. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1979. callback) {
  1980. ranges = ranges || [];
  1981. var chunksToRequest = [];
  1982. for (var i = 0; i < ranges.length; i++) {
  1983. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1984. var endChunk = this.getEndChunk(ranges[i].end);
  1985. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1986. if (chunksToRequest.indexOf(chunk) < 0) {
  1987. chunksToRequest.push(chunk);
  1988. }
  1989. }
  1990. }
  1991. chunksToRequest.sort(function(a, b) { return a - b; });
  1992. this.requestChunks(chunksToRequest, callback);
  1993. },
  1994. // Groups a sorted array of chunks into as few continguous larger
  1995. // chunks as possible
  1996. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1997. var groupedChunks = [];
  1998. var beginChunk = -1;
  1999. var prevChunk = -1;
  2000. for (var i = 0; i < chunks.length; ++i) {
  2001. var chunk = chunks[i];
  2002. if (beginChunk < 0) {
  2003. beginChunk = chunk;
  2004. }
  2005. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  2006. groupedChunks.push({ beginChunk: beginChunk,
  2007. endChunk: prevChunk + 1 });
  2008. beginChunk = chunk;
  2009. }
  2010. if (i + 1 === chunks.length) {
  2011. groupedChunks.push({ beginChunk: beginChunk,
  2012. endChunk: chunk + 1 });
  2013. }
  2014. prevChunk = chunk;
  2015. }
  2016. return groupedChunks;
  2017. },
  2018. onProgress: function ChunkedStreamManager_onProgress(args) {
  2019. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2020. args.loaded);
  2021. this.msgHandler.send('DocProgress', {
  2022. loaded: bytesLoaded,
  2023. total: this.length
  2024. });
  2025. },
  2026. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2027. var chunk = args.chunk;
  2028. var isProgressive = args.begin === undefined;
  2029. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2030. var end = begin + chunk.byteLength;
  2031. var beginChunk = Math.floor(begin / this.chunkSize);
  2032. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2033. Math.ceil(end / this.chunkSize);
  2034. if (isProgressive) {
  2035. this.stream.onReceiveProgressiveData(chunk);
  2036. this.progressiveDataLength = end;
  2037. } else {
  2038. this.stream.onReceiveData(begin, chunk);
  2039. }
  2040. if (this.stream.allChunksLoaded()) {
  2041. this._loadedStreamCapability.resolve(this.stream);
  2042. }
  2043. var loadedRequests = [];
  2044. var i, requestId;
  2045. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2046. // The server might return more chunks than requested
  2047. var requestIds = this.requestsByChunk[chunk] || [];
  2048. delete this.requestsByChunk[chunk];
  2049. for (i = 0; i < requestIds.length; ++i) {
  2050. requestId = requestIds[i];
  2051. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2052. if (chunk in chunksNeeded) {
  2053. delete chunksNeeded[chunk];
  2054. }
  2055. if (!isEmptyObj(chunksNeeded)) {
  2056. continue;
  2057. }
  2058. loadedRequests.push(requestId);
  2059. }
  2060. }
  2061. // If there are no pending requests, automatically fetch the next
  2062. // unfetched chunk of the PDF
  2063. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2064. var nextEmptyChunk;
  2065. if (this.stream.numChunksLoaded === 1) {
  2066. // This is a special optimization so that after fetching the first
  2067. // chunk, rather than fetching the second chunk, we fetch the last
  2068. // chunk.
  2069. var lastChunk = this.stream.numChunks - 1;
  2070. if (!this.stream.hasChunk(lastChunk)) {
  2071. nextEmptyChunk = lastChunk;
  2072. }
  2073. } else {
  2074. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2075. }
  2076. if (isInt(nextEmptyChunk)) {
  2077. this.requestChunks([nextEmptyChunk]);
  2078. }
  2079. }
  2080. for (i = 0; i < loadedRequests.length; ++i) {
  2081. requestId = loadedRequests[i];
  2082. var callback = this.callbacksByRequest[requestId];
  2083. delete this.callbacksByRequest[requestId];
  2084. if (callback) {
  2085. callback();
  2086. }
  2087. }
  2088. this.msgHandler.send('DocProgress', {
  2089. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2090. total: this.length
  2091. });
  2092. },
  2093. onError: function ChunkedStreamManager_onError(err) {
  2094. this._loadedStreamCapability.reject(err);
  2095. },
  2096. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2097. var chunk = Math.floor(begin / this.chunkSize);
  2098. return chunk;
  2099. },
  2100. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2101. if (end % this.chunkSize === 0) {
  2102. return end / this.chunkSize;
  2103. }
  2104. // 0 -> 0
  2105. // 1 -> 1
  2106. // 99 -> 1
  2107. // 100 -> 1
  2108. // 101 -> 2
  2109. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2110. return chunk;
  2111. }
  2112. };
  2113. return ChunkedStreamManager;
  2114. })();
  2115. // The maximum number of bytes fetched per range request
  2116. var RANGE_CHUNK_SIZE = 65536;
  2117. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2118. var BasePdfManager = (function BasePdfManagerClosure() {
  2119. function BasePdfManager() {
  2120. throw new Error('Cannot initialize BaseManagerManager');
  2121. }
  2122. BasePdfManager.prototype = {
  2123. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2124. throw new NotImplementedException();
  2125. },
  2126. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2127. return this.ensure(this.pdfDocument, prop, args);
  2128. },
  2129. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2130. return this.ensure(this.pdfDocument.xref, prop, args);
  2131. },
  2132. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2133. return this.ensure(this.pdfDocument.catalog, prop, args);
  2134. },
  2135. getPage: function BasePdfManager_pagePage(pageIndex) {
  2136. return this.pdfDocument.getPage(pageIndex);
  2137. },
  2138. cleanup: function BasePdfManager_cleanup() {
  2139. return this.pdfDocument.cleanup();
  2140. },
  2141. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2142. return new NotImplementedException();
  2143. },
  2144. requestRange: function BasePdfManager_ensure(begin, end) {
  2145. return new NotImplementedException();
  2146. },
  2147. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2148. return new NotImplementedException();
  2149. },
  2150. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2151. return new NotImplementedException();
  2152. },
  2153. updatePassword: function BasePdfManager_updatePassword(password) {
  2154. this.pdfDocument.xref.password = this.password = password;
  2155. if (this._passwordChangedCapability) {
  2156. this._passwordChangedCapability.resolve();
  2157. }
  2158. },
  2159. passwordChanged: function BasePdfManager_passwordChanged() {
  2160. this._passwordChangedCapability = createPromiseCapability();
  2161. return this._passwordChangedCapability.promise;
  2162. },
  2163. terminate: function BasePdfManager_terminate() {
  2164. return new NotImplementedException();
  2165. }
  2166. };
  2167. return BasePdfManager;
  2168. })();
  2169. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2170. function LocalPdfManager(data, password) {
  2171. var stream = new Stream(data);
  2172. this.pdfDocument = new PDFDocument(this, stream, password);
  2173. this._loadedStreamCapability = createPromiseCapability();
  2174. this._loadedStreamCapability.resolve(stream);
  2175. }
  2176. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2177. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2178. LocalPdfManager.prototype.ensure =
  2179. function LocalPdfManager_ensure(obj, prop, args) {
  2180. return new Promise(function (resolve, reject) {
  2181. try {
  2182. var value = obj[prop];
  2183. var result;
  2184. if (typeof value === 'function') {
  2185. result = value.apply(obj, args);
  2186. } else {
  2187. result = value;
  2188. }
  2189. resolve(result);
  2190. } catch (e) {
  2191. reject(e);
  2192. }
  2193. });
  2194. };
  2195. LocalPdfManager.prototype.requestRange =
  2196. function LocalPdfManager_requestRange(begin, end) {
  2197. return Promise.resolve();
  2198. };
  2199. LocalPdfManager.prototype.requestLoadedStream =
  2200. function LocalPdfManager_requestLoadedStream() {
  2201. };
  2202. LocalPdfManager.prototype.onLoadedStream =
  2203. function LocalPdfManager_getLoadedStream() {
  2204. return this._loadedStreamCapability.promise;
  2205. };
  2206. LocalPdfManager.prototype.terminate =
  2207. function LocalPdfManager_terminate() {
  2208. return;
  2209. };
  2210. return LocalPdfManager;
  2211. })();
  2212. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2213. function NetworkPdfManager(args, msgHandler) {
  2214. this.msgHandler = msgHandler;
  2215. var params = {
  2216. msgHandler: msgHandler,
  2217. httpHeaders: args.httpHeaders,
  2218. withCredentials: args.withCredentials,
  2219. chunkedViewerLoading: args.chunkedViewerLoading,
  2220. disableAutoFetch: args.disableAutoFetch,
  2221. initialData: args.initialData
  2222. };
  2223. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2224. args.url, params);
  2225. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2226. args.password);
  2227. }
  2228. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2229. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2230. NetworkPdfManager.prototype.ensure =
  2231. function NetworkPdfManager_ensure(obj, prop, args) {
  2232. var pdfManager = this;
  2233. return new Promise(function (resolve, reject) {
  2234. function ensureHelper() {
  2235. try {
  2236. var result;
  2237. var value = obj[prop];
  2238. if (typeof value === 'function') {
  2239. result = value.apply(obj, args);
  2240. } else {
  2241. result = value;
  2242. }
  2243. resolve(result);
  2244. } catch(e) {
  2245. if (!(e instanceof MissingDataException)) {
  2246. reject(e);
  2247. return;
  2248. }
  2249. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2250. }
  2251. }
  2252. ensureHelper();
  2253. });
  2254. };
  2255. NetworkPdfManager.prototype.requestRange =
  2256. function NetworkPdfManager_requestRange(begin, end) {
  2257. return new Promise(function (resolve) {
  2258. this.streamManager.requestRange(begin, end, function() {
  2259. resolve();
  2260. });
  2261. }.bind(this));
  2262. };
  2263. NetworkPdfManager.prototype.requestLoadedStream =
  2264. function NetworkPdfManager_requestLoadedStream() {
  2265. this.streamManager.requestAllChunks();
  2266. };
  2267. NetworkPdfManager.prototype.sendProgressiveData =
  2268. function NetworkPdfManager_sendProgressiveData(chunk) {
  2269. this.streamManager.onReceiveData({ chunk: chunk });
  2270. };
  2271. NetworkPdfManager.prototype.onLoadedStream =
  2272. function NetworkPdfManager_getLoadedStream() {
  2273. return this.streamManager.onLoadedStream();
  2274. };
  2275. NetworkPdfManager.prototype.terminate =
  2276. function NetworkPdfManager_terminate() {
  2277. this.streamManager.networkManager.abortAllRequests();
  2278. };
  2279. return NetworkPdfManager;
  2280. })();
  2281. var Page = (function PageClosure() {
  2282. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2283. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2284. this.pdfManager = pdfManager;
  2285. this.pageIndex = pageIndex;
  2286. this.pageDict = pageDict;
  2287. this.xref = xref;
  2288. this.ref = ref;
  2289. this.fontCache = fontCache;
  2290. this.idCounters = {
  2291. obj: 0
  2292. };
  2293. this.resourcesPromise = null;
  2294. }
  2295. Page.prototype = {
  2296. getPageProp: function Page_getPageProp(key) {
  2297. return this.pageDict.get(key);
  2298. },
  2299. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2300. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2301. var MAX_LOOP_COUNT = 100;
  2302. // Always walk up the entire parent chain, to be able to find
  2303. // e.g. \Resources placed on multiple levels of the tree.
  2304. while (dict) {
  2305. var value = dict.get(key);
  2306. if (value) {
  2307. if (!valueArray) {
  2308. valueArray = [];
  2309. }
  2310. valueArray.push(value);
  2311. }
  2312. if (++loopCount > MAX_LOOP_COUNT) {
  2313. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2314. break;
  2315. }
  2316. dict = dict.get('Parent');
  2317. }
  2318. if (!valueArray) {
  2319. return Dict.empty;
  2320. }
  2321. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2322. loopCount > MAX_LOOP_COUNT) {
  2323. return valueArray[0];
  2324. }
  2325. return Dict.merge(this.xref, valueArray);
  2326. },
  2327. get content() {
  2328. return this.getPageProp('Contents');
  2329. },
  2330. get resources() {
  2331. // For robustness: The spec states that a \Resources entry has to be
  2332. // present, but can be empty. Some document omit it still, in this case
  2333. // we return an empty dictionary.
  2334. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2335. },
  2336. get mediaBox() {
  2337. var obj = this.getInheritedPageProp('MediaBox');
  2338. // Reset invalid media box to letter size.
  2339. if (!isArray(obj) || obj.length !== 4) {
  2340. obj = LETTER_SIZE_MEDIABOX;
  2341. }
  2342. return shadow(this, 'mediaBox', obj);
  2343. },
  2344. get view() {
  2345. var mediaBox = this.mediaBox;
  2346. var cropBox = this.getInheritedPageProp('CropBox');
  2347. if (!isArray(cropBox) || cropBox.length !== 4) {
  2348. return shadow(this, 'view', mediaBox);
  2349. }
  2350. // From the spec, 6th ed., p.963:
  2351. // "The crop, bleed, trim, and art boxes should not ordinarily
  2352. // extend beyond the boundaries of the media box. If they do, they are
  2353. // effectively reduced to their intersection with the media box."
  2354. cropBox = Util.intersect(cropBox, mediaBox);
  2355. if (!cropBox) {
  2356. return shadow(this, 'view', mediaBox);
  2357. }
  2358. return shadow(this, 'view', cropBox);
  2359. },
  2360. get annotationRefs() {
  2361. return shadow(this, 'annotationRefs',
  2362. this.getInheritedPageProp('Annots'));
  2363. },
  2364. get rotate() {
  2365. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2366. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2367. if (rotate % 90 !== 0) {
  2368. rotate = 0;
  2369. } else if (rotate >= 360) {
  2370. rotate = rotate % 360;
  2371. } else if (rotate < 0) {
  2372. // The spec doesn't cover negatives, assume its counterclockwise
  2373. // rotation. The following is the other implementation of modulo.
  2374. rotate = ((rotate % 360) + 360) % 360;
  2375. }
  2376. return shadow(this, 'rotate', rotate);
  2377. },
  2378. getContentStream: function Page_getContentStream() {
  2379. var content = this.content;
  2380. var stream;
  2381. if (isArray(content)) {
  2382. // fetching items
  2383. var xref = this.xref;
  2384. var i, n = content.length;
  2385. var streams = [];
  2386. for (i = 0; i < n; ++i) {
  2387. streams.push(xref.fetchIfRef(content[i]));
  2388. }
  2389. stream = new StreamsSequenceStream(streams);
  2390. } else if (isStream(content)) {
  2391. stream = content;
  2392. } else {
  2393. // replacing non-existent page content with empty one
  2394. stream = new NullStream();
  2395. }
  2396. return stream;
  2397. },
  2398. loadResources: function Page_loadResources(keys) {
  2399. if (!this.resourcesPromise) {
  2400. // TODO: add async getInheritedPageProp and remove this.
  2401. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2402. }
  2403. return this.resourcesPromise.then(function resourceSuccess() {
  2404. var objectLoader = new ObjectLoader(this.resources.map,
  2405. keys,
  2406. this.xref);
  2407. return objectLoader.load();
  2408. }.bind(this));
  2409. },
  2410. getOperatorList: function Page_getOperatorList(handler, intent) {
  2411. var self = this;
  2412. var pdfManager = this.pdfManager;
  2413. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2414. []);
  2415. var resourcesPromise = this.loadResources([
  2416. 'ExtGState',
  2417. 'ColorSpace',
  2418. 'Pattern',
  2419. 'Shading',
  2420. 'XObject',
  2421. 'Font'
  2422. // ProcSet
  2423. // Properties
  2424. ]);
  2425. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2426. handler, this.pageIndex,
  2427. 'p' + this.pageIndex + '_',
  2428. this.idCounters,
  2429. this.fontCache);
  2430. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2431. var pageListPromise = dataPromises.then(function(data) {
  2432. var contentStream = data[0];
  2433. var opList = new OperatorList(intent, handler, self.pageIndex);
  2434. handler.send('StartRenderPage', {
  2435. transparency: partialEvaluator.hasBlendModes(self.resources),
  2436. pageIndex: self.pageIndex,
  2437. intent: intent
  2438. });
  2439. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2440. opList).then(function () {
  2441. return opList;
  2442. });
  2443. });
  2444. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2445. return Promise.all([pageListPromise, annotationsPromise]).then(
  2446. function(datas) {
  2447. var pageOpList = datas[0];
  2448. var annotations = datas[1];
  2449. if (annotations.length === 0) {
  2450. pageOpList.flush(true);
  2451. return pageOpList;
  2452. }
  2453. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2454. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2455. return annotationsReadyPromise.then(function () {
  2456. pageOpList.flush(true);
  2457. return pageOpList;
  2458. });
  2459. });
  2460. },
  2461. extractTextContent: function Page_extractTextContent() {
  2462. var handler = {
  2463. on: function nullHandlerOn() {},
  2464. send: function nullHandlerSend() {}
  2465. };
  2466. var self = this;
  2467. var pdfManager = this.pdfManager;
  2468. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2469. []);
  2470. var resourcesPromise = this.loadResources([
  2471. 'ExtGState',
  2472. 'XObject',
  2473. 'Font'
  2474. ]);
  2475. var dataPromises = Promise.all([contentStreamPromise,
  2476. resourcesPromise]);
  2477. return dataPromises.then(function(data) {
  2478. var contentStream = data[0];
  2479. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2480. handler, self.pageIndex,
  2481. 'p' + self.pageIndex + '_',
  2482. self.idCounters,
  2483. self.fontCache);
  2484. return partialEvaluator.getTextContent(contentStream,
  2485. self.resources);
  2486. });
  2487. },
  2488. getAnnotationsData: function Page_getAnnotationsData() {
  2489. var annotations = this.annotations;
  2490. var annotationsData = [];
  2491. for (var i = 0, n = annotations.length; i < n; ++i) {
  2492. annotationsData.push(annotations[i].getData());
  2493. }
  2494. return annotationsData;
  2495. },
  2496. get annotations() {
  2497. var annotations = [];
  2498. var annotationRefs = (this.annotationRefs || []);
  2499. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2500. var annotationRef = annotationRefs[i];
  2501. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2502. if (annotation) {
  2503. annotations.push(annotation);
  2504. }
  2505. }
  2506. return shadow(this, 'annotations', annotations);
  2507. }
  2508. };
  2509. return Page;
  2510. })();
  2511. /**
  2512. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2513. * `PDFDoc`, this one doesn't have any job management code.
  2514. * Right now there exists one PDFDocument on the main thread + one object
  2515. * for each worker. If there is no worker support enabled, there are two
  2516. * `PDFDocument` objects on the main thread created.
  2517. */
  2518. var PDFDocument = (function PDFDocumentClosure() {
  2519. var FINGERPRINT_FIRST_BYTES = 1024;
  2520. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2521. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2522. function PDFDocument(pdfManager, arg, password) {
  2523. if (isStream(arg)) {
  2524. init.call(this, pdfManager, arg, password);
  2525. } else if (isArrayBuffer(arg)) {
  2526. init.call(this, pdfManager, new Stream(arg), password);
  2527. } else {
  2528. error('PDFDocument: Unknown argument type');
  2529. }
  2530. }
  2531. function init(pdfManager, stream, password) {
  2532. assert(stream.length > 0, 'stream must have data');
  2533. this.pdfManager = pdfManager;
  2534. this.stream = stream;
  2535. var xref = new XRef(this.stream, password, pdfManager);
  2536. this.xref = xref;
  2537. }
  2538. function find(stream, needle, limit, backwards) {
  2539. var pos = stream.pos;
  2540. var end = stream.end;
  2541. var strBuf = [];
  2542. if (pos + limit > end) {
  2543. limit = end - pos;
  2544. }
  2545. for (var n = 0; n < limit; ++n) {
  2546. strBuf.push(String.fromCharCode(stream.getByte()));
  2547. }
  2548. var str = strBuf.join('');
  2549. stream.pos = pos;
  2550. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2551. if (index === -1) {
  2552. return false; /* not found */
  2553. }
  2554. stream.pos += index;
  2555. return true; /* found */
  2556. }
  2557. var DocumentInfoValidators = {
  2558. get entries() {
  2559. // Lazily build this since all the validation functions below are not
  2560. // defined until after this file loads.
  2561. return shadow(this, 'entries', {
  2562. Title: isString,
  2563. Author: isString,
  2564. Subject: isString,
  2565. Keywords: isString,
  2566. Creator: isString,
  2567. Producer: isString,
  2568. CreationDate: isString,
  2569. ModDate: isString,
  2570. Trapped: isName
  2571. });
  2572. }
  2573. };
  2574. PDFDocument.prototype = {
  2575. parse: function PDFDocument_parse(recoveryMode) {
  2576. this.setup(recoveryMode);
  2577. var version = this.catalog.catDict.get('Version');
  2578. if (isName(version)) {
  2579. this.pdfFormatVersion = version.name;
  2580. }
  2581. try {
  2582. // checking if AcroForm is present
  2583. this.acroForm = this.catalog.catDict.get('AcroForm');
  2584. if (this.acroForm) {
  2585. this.xfa = this.acroForm.get('XFA');
  2586. var fields = this.acroForm.get('Fields');
  2587. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2588. !this.xfa) {
  2589. // no fields and no XFA -- not a form (?)
  2590. this.acroForm = null;
  2591. }
  2592. }
  2593. } catch (ex) {
  2594. info('Something wrong with AcroForm entry');
  2595. this.acroForm = null;
  2596. }
  2597. },
  2598. get linearization() {
  2599. var linearization = null;
  2600. if (this.stream.length) {
  2601. try {
  2602. linearization = Linearization.create(this.stream);
  2603. } catch (err) {
  2604. if (err instanceof MissingDataException) {
  2605. throw err;
  2606. }
  2607. info(err);
  2608. }
  2609. }
  2610. // shadow the prototype getter with a data property
  2611. return shadow(this, 'linearization', linearization);
  2612. },
  2613. get startXRef() {
  2614. var stream = this.stream;
  2615. var startXRef = 0;
  2616. var linearization = this.linearization;
  2617. if (linearization) {
  2618. // Find end of first obj.
  2619. stream.reset();
  2620. if (find(stream, 'endobj', 1024)) {
  2621. startXRef = stream.pos + 6;
  2622. }
  2623. } else {
  2624. // Find startxref by jumping backward from the end of the file.
  2625. var step = 1024;
  2626. var found = false, pos = stream.end;
  2627. while (!found && pos > 0) {
  2628. pos -= step - 'startxref'.length;
  2629. if (pos < 0) {
  2630. pos = 0;
  2631. }
  2632. stream.pos = pos;
  2633. found = find(stream, 'startxref', step, true);
  2634. }
  2635. if (found) {
  2636. stream.skip(9);
  2637. var ch;
  2638. do {
  2639. ch = stream.getByte();
  2640. } while (Lexer.isSpace(ch));
  2641. var str = '';
  2642. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2643. str += String.fromCharCode(ch);
  2644. ch = stream.getByte();
  2645. }
  2646. startXRef = parseInt(str, 10);
  2647. if (isNaN(startXRef)) {
  2648. startXRef = 0;
  2649. }
  2650. }
  2651. }
  2652. // shadow the prototype getter with a data property
  2653. return shadow(this, 'startXRef', startXRef);
  2654. },
  2655. get mainXRefEntriesOffset() {
  2656. var mainXRefEntriesOffset = 0;
  2657. var linearization = this.linearization;
  2658. if (linearization) {
  2659. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2660. }
  2661. // shadow the prototype getter with a data property
  2662. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2663. },
  2664. // Find the header, remove leading garbage and setup the stream
  2665. // starting from the header.
  2666. checkHeader: function PDFDocument_checkHeader() {
  2667. var stream = this.stream;
  2668. stream.reset();
  2669. if (find(stream, '%PDF-', 1024)) {
  2670. // Found the header, trim off any garbage before it.
  2671. stream.moveStart();
  2672. // Reading file format version
  2673. var MAX_VERSION_LENGTH = 12;
  2674. var version = '', ch;
  2675. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2676. if (version.length >= MAX_VERSION_LENGTH) {
  2677. break;
  2678. }
  2679. version += String.fromCharCode(ch);
  2680. }
  2681. if (!this.pdfFormatVersion) {
  2682. // removing "%PDF-"-prefix
  2683. this.pdfFormatVersion = version.substring(5);
  2684. }
  2685. return;
  2686. }
  2687. // May not be a PDF file, continue anyway.
  2688. },
  2689. parseStartXRef: function PDFDocument_parseStartXRef() {
  2690. var startXRef = this.startXRef;
  2691. this.xref.setStartXRef(startXRef);
  2692. },
  2693. setup: function PDFDocument_setup(recoveryMode) {
  2694. this.xref.parse(recoveryMode);
  2695. this.catalog = new Catalog(this.pdfManager, this.xref);
  2696. },
  2697. get numPages() {
  2698. var linearization = this.linearization;
  2699. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2700. // shadow the prototype getter
  2701. return shadow(this, 'numPages', num);
  2702. },
  2703. get documentInfo() {
  2704. var docInfo = {
  2705. PDFFormatVersion: this.pdfFormatVersion,
  2706. IsAcroFormPresent: !!this.acroForm,
  2707. IsXFAPresent: !!this.xfa
  2708. };
  2709. var infoDict;
  2710. try {
  2711. infoDict = this.xref.trailer.get('Info');
  2712. } catch (err) {
  2713. info('The document information dictionary is invalid.');
  2714. }
  2715. if (infoDict) {
  2716. var validEntries = DocumentInfoValidators.entries;
  2717. // Only fill the document info with valid entries from the spec.
  2718. for (var key in validEntries) {
  2719. if (infoDict.has(key)) {
  2720. var value = infoDict.get(key);
  2721. // Make sure the value conforms to the spec.
  2722. if (validEntries[key](value)) {
  2723. docInfo[key] = (typeof value !== 'string' ?
  2724. value : stringToPDFString(value));
  2725. } else {
  2726. info('Bad value in document info for "' + key + '"');
  2727. }
  2728. }
  2729. }
  2730. }
  2731. return shadow(this, 'documentInfo', docInfo);
  2732. },
  2733. get fingerprint() {
  2734. var xref = this.xref, idArray, hash, fileID = '';
  2735. if (xref.trailer.has('ID')) {
  2736. idArray = xref.trailer.get('ID');
  2737. }
  2738. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2739. hash = stringToBytes(idArray[0]);
  2740. } else {
  2741. if (this.stream.ensureRange) {
  2742. this.stream.ensureRange(0,
  2743. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2744. }
  2745. hash = calculateMD5(this.stream.bytes.subarray(0,
  2746. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2747. }
  2748. for (var i = 0, n = hash.length; i < n; i++) {
  2749. var hex = hash[i].toString(16);
  2750. fileID += hex.length === 1 ? '0' + hex : hex;
  2751. }
  2752. return shadow(this, 'fingerprint', fileID);
  2753. },
  2754. getPage: function PDFDocument_getPage(pageIndex) {
  2755. return this.catalog.getPage(pageIndex);
  2756. },
  2757. cleanup: function PDFDocument_cleanup() {
  2758. return this.catalog.cleanup();
  2759. }
  2760. };
  2761. return PDFDocument;
  2762. })();
  2763. var Name = (function NameClosure() {
  2764. function Name(name) {
  2765. this.name = name;
  2766. }
  2767. Name.prototype = {};
  2768. var nameCache = {};
  2769. Name.get = function Name_get(name) {
  2770. var nameValue = nameCache[name];
  2771. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2772. };
  2773. return Name;
  2774. })();
  2775. var Cmd = (function CmdClosure() {
  2776. function Cmd(cmd) {
  2777. this.cmd = cmd;
  2778. }
  2779. Cmd.prototype = {};
  2780. var cmdCache = {};
  2781. Cmd.get = function Cmd_get(cmd) {
  2782. var cmdValue = cmdCache[cmd];
  2783. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2784. };
  2785. return Cmd;
  2786. })();
  2787. var Dict = (function DictClosure() {
  2788. var nonSerializable = function nonSerializableClosure() {
  2789. return nonSerializable; // creating closure on some variable
  2790. };
  2791. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2792. 'Background': true,
  2793. 'ExtGState': true,
  2794. 'Halftone': true,
  2795. 'Layout': true,
  2796. 'Mask': true,
  2797. 'Pagination': true,
  2798. 'Printing': true
  2799. };
  2800. function isRecursionAllowedFor(dict) {
  2801. if (!isName(dict.Type)) {
  2802. return true;
  2803. }
  2804. var dictType = dict.Type.name;
  2805. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2806. }
  2807. // xref is optional
  2808. function Dict(xref) {
  2809. // Map should only be used internally, use functions below to access.
  2810. this.map = Object.create(null);
  2811. this.xref = xref;
  2812. this.objId = null;
  2813. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2814. }
  2815. Dict.prototype = {
  2816. assignXref: function Dict_assignXref(newXref) {
  2817. this.xref = newXref;
  2818. },
  2819. // automatically dereferences Ref objects
  2820. get: function Dict_get(key1, key2, key3) {
  2821. var value;
  2822. var xref = this.xref;
  2823. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2824. typeof key2 === 'undefined') {
  2825. return xref ? xref.fetchIfRef(value) : value;
  2826. }
  2827. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2828. typeof key3 === 'undefined') {
  2829. return xref ? xref.fetchIfRef(value) : value;
  2830. }
  2831. value = this.map[key3] || null;
  2832. return xref ? xref.fetchIfRef(value) : value;
  2833. },
  2834. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2835. getAsync: function Dict_getAsync(key1, key2, key3) {
  2836. var value;
  2837. var xref = this.xref;
  2838. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2839. typeof key2 === 'undefined') {
  2840. if (xref) {
  2841. return xref.fetchIfRefAsync(value);
  2842. }
  2843. return Promise.resolve(value);
  2844. }
  2845. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2846. typeof key3 === 'undefined') {
  2847. if (xref) {
  2848. return xref.fetchIfRefAsync(value);
  2849. }
  2850. return Promise.resolve(value);
  2851. }
  2852. value = this.map[key3] || null;
  2853. if (xref) {
  2854. return xref.fetchIfRefAsync(value);
  2855. }
  2856. return Promise.resolve(value);
  2857. },
  2858. // no dereferencing
  2859. getRaw: function Dict_getRaw(key) {
  2860. return this.map[key];
  2861. },
  2862. // creates new map and dereferences all Refs
  2863. getAll: function Dict_getAll() {
  2864. var all = Object.create(null);
  2865. var queue = null;
  2866. var key, obj;
  2867. for (key in this.map) {
  2868. obj = this.get(key);
  2869. if (obj instanceof Dict) {
  2870. if (isRecursionAllowedFor(obj)) {
  2871. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2872. } else {
  2873. all[key] = this.getRaw(key);
  2874. }
  2875. } else {
  2876. all[key] = obj;
  2877. }
  2878. }
  2879. if (!queue) {
  2880. return all;
  2881. }
  2882. // trying to take cyclic references into the account
  2883. var processed = Object.create(null);
  2884. while (queue.length > 0) {
  2885. var item = queue.shift();
  2886. var itemObj = item.obj;
  2887. var objId = itemObj.objId;
  2888. if (objId && objId in processed) {
  2889. item.target[item.key] = processed[objId];
  2890. continue;
  2891. }
  2892. var dereferenced = Object.create(null);
  2893. for (key in itemObj.map) {
  2894. obj = itemObj.get(key);
  2895. if (obj instanceof Dict) {
  2896. if (isRecursionAllowedFor(obj)) {
  2897. queue.push({target: dereferenced, key: key, obj: obj});
  2898. } else {
  2899. dereferenced[key] = itemObj.getRaw(key);
  2900. }
  2901. } else {
  2902. dereferenced[key] = obj;
  2903. }
  2904. }
  2905. if (objId) {
  2906. processed[objId] = dereferenced;
  2907. }
  2908. item.target[item.key] = dereferenced;
  2909. }
  2910. return all;
  2911. },
  2912. getKeys: function Dict_getKeys() {
  2913. return Object.keys(this.map);
  2914. },
  2915. set: function Dict_set(key, value) {
  2916. this.map[key] = value;
  2917. },
  2918. has: function Dict_has(key) {
  2919. return key in this.map;
  2920. },
  2921. forEach: function Dict_forEach(callback) {
  2922. for (var key in this.map) {
  2923. callback(key, this.get(key));
  2924. }
  2925. }
  2926. };
  2927. Dict.empty = new Dict(null);
  2928. Dict.merge = function Dict_merge(xref, dictArray) {
  2929. var mergedDict = new Dict(xref);
  2930. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  2931. var dict = dictArray[i];
  2932. if (!isDict(dict)) {
  2933. continue;
  2934. }
  2935. for (var keyName in dict.map) {
  2936. if (mergedDict.map[keyName]) {
  2937. continue;
  2938. }
  2939. mergedDict.map[keyName] = dict.map[keyName];
  2940. }
  2941. }
  2942. return mergedDict;
  2943. };
  2944. return Dict;
  2945. })();
  2946. var Ref = (function RefClosure() {
  2947. function Ref(num, gen) {
  2948. this.num = num;
  2949. this.gen = gen;
  2950. }
  2951. Ref.prototype = {
  2952. toString: function Ref_toString() {
  2953. // This function is hot, so we make the string as compact as possible.
  2954. // |this.gen| is almost always zero, so we treat that case specially.
  2955. var str = this.num + 'R';
  2956. if (this.gen !== 0) {
  2957. str += this.gen;
  2958. }
  2959. return str;
  2960. }
  2961. };
  2962. return Ref;
  2963. })();
  2964. // The reference is identified by number and generation.
  2965. // This structure stores only one instance of the reference.
  2966. var RefSet = (function RefSetClosure() {
  2967. function RefSet() {
  2968. this.dict = {};
  2969. }
  2970. RefSet.prototype = {
  2971. has: function RefSet_has(ref) {
  2972. return ref.toString() in this.dict;
  2973. },
  2974. put: function RefSet_put(ref) {
  2975. this.dict[ref.toString()] = true;
  2976. },
  2977. remove: function RefSet_remove(ref) {
  2978. delete this.dict[ref.toString()];
  2979. }
  2980. };
  2981. return RefSet;
  2982. })();
  2983. var RefSetCache = (function RefSetCacheClosure() {
  2984. function RefSetCache() {
  2985. this.dict = Object.create(null);
  2986. }
  2987. RefSetCache.prototype = {
  2988. get: function RefSetCache_get(ref) {
  2989. return this.dict[ref.toString()];
  2990. },
  2991. has: function RefSetCache_has(ref) {
  2992. return ref.toString() in this.dict;
  2993. },
  2994. put: function RefSetCache_put(ref, obj) {
  2995. this.dict[ref.toString()] = obj;
  2996. },
  2997. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2998. this.dict[ref.toString()] = this.get(aliasRef);
  2999. },
  3000. forEach: function RefSetCache_forEach(fn, thisArg) {
  3001. for (var i in this.dict) {
  3002. fn.call(thisArg, this.dict[i]);
  3003. }
  3004. },
  3005. clear: function RefSetCache_clear() {
  3006. this.dict = Object.create(null);
  3007. }
  3008. };
  3009. return RefSetCache;
  3010. })();
  3011. var Catalog = (function CatalogClosure() {
  3012. function Catalog(pdfManager, xref) {
  3013. this.pdfManager = pdfManager;
  3014. this.xref = xref;
  3015. this.catDict = xref.getCatalogObj();
  3016. this.fontCache = new RefSetCache();
  3017. assert(isDict(this.catDict),
  3018. 'catalog object is not a dictionary');
  3019. this.pagePromises = [];
  3020. }
  3021. Catalog.prototype = {
  3022. get metadata() {
  3023. var streamRef = this.catDict.getRaw('Metadata');
  3024. if (!isRef(streamRef)) {
  3025. return shadow(this, 'metadata', null);
  3026. }
  3027. var encryptMetadata = (!this.xref.encrypt ? false :
  3028. this.xref.encrypt.encryptMetadata);
  3029. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3030. var metadata;
  3031. if (stream && isDict(stream.dict)) {
  3032. var type = stream.dict.get('Type');
  3033. var subtype = stream.dict.get('Subtype');
  3034. if (isName(type) && isName(subtype) &&
  3035. type.name === 'Metadata' && subtype.name === 'XML') {
  3036. // XXX: This should examine the charset the XML document defines,
  3037. // however since there are currently no real means to decode
  3038. // arbitrary charsets, let's just hope that the author of the PDF
  3039. // was reasonable enough to stick with the XML default charset,
  3040. // which is UTF-8.
  3041. try {
  3042. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3043. } catch (e) {
  3044. info('Skipping invalid metadata.');
  3045. }
  3046. }
  3047. }
  3048. return shadow(this, 'metadata', metadata);
  3049. },
  3050. get toplevelPagesDict() {
  3051. var pagesObj = this.catDict.get('Pages');
  3052. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3053. // shadow the prototype getter
  3054. return shadow(this, 'toplevelPagesDict', pagesObj);
  3055. },
  3056. get documentOutline() {
  3057. var obj = null;
  3058. try {
  3059. obj = this.readDocumentOutline();
  3060. } catch (ex) {
  3061. if (ex instanceof MissingDataException) {
  3062. throw ex;
  3063. }
  3064. warn('Unable to read document outline');
  3065. }
  3066. return shadow(this, 'documentOutline', obj);
  3067. },
  3068. readDocumentOutline: function Catalog_readDocumentOutline() {
  3069. var xref = this.xref;
  3070. var obj = this.catDict.get('Outlines');
  3071. var root = { items: [] };
  3072. if (isDict(obj)) {
  3073. obj = obj.getRaw('First');
  3074. var processed = new RefSet();
  3075. if (isRef(obj)) {
  3076. var queue = [{obj: obj, parent: root}];
  3077. // to avoid recursion keeping track of the items
  3078. // in the processed dictionary
  3079. processed.put(obj);
  3080. while (queue.length > 0) {
  3081. var i = queue.shift();
  3082. var outlineDict = xref.fetchIfRef(i.obj);
  3083. if (outlineDict === null) {
  3084. continue;
  3085. }
  3086. if (!outlineDict.has('Title')) {
  3087. error('Invalid outline item');
  3088. }
  3089. var dest = outlineDict.get('A');
  3090. if (dest) {
  3091. dest = dest.get('D');
  3092. } else if (outlineDict.has('Dest')) {
  3093. dest = outlineDict.getRaw('Dest');
  3094. if (isName(dest)) {
  3095. dest = dest.name;
  3096. }
  3097. }
  3098. var title = outlineDict.get('Title');
  3099. var outlineItem = {
  3100. dest: dest,
  3101. title: stringToPDFString(title),
  3102. color: outlineDict.get('C') || [0, 0, 0],
  3103. count: outlineDict.get('Count'),
  3104. bold: !!(outlineDict.get('F') & 2),
  3105. italic: !!(outlineDict.get('F') & 1),
  3106. items: []
  3107. };
  3108. i.parent.items.push(outlineItem);
  3109. obj = outlineDict.getRaw('First');
  3110. if (isRef(obj) && !processed.has(obj)) {
  3111. queue.push({obj: obj, parent: outlineItem});
  3112. processed.put(obj);
  3113. }
  3114. obj = outlineDict.getRaw('Next');
  3115. if (isRef(obj) && !processed.has(obj)) {
  3116. queue.push({obj: obj, parent: i.parent});
  3117. processed.put(obj);
  3118. }
  3119. }
  3120. }
  3121. }
  3122. return (root.items.length > 0 ? root.items : null);
  3123. },
  3124. get numPages() {
  3125. var obj = this.toplevelPagesDict.get('Count');
  3126. assert(
  3127. isInt(obj),
  3128. 'page count in top level pages object is not an integer'
  3129. );
  3130. // shadow the prototype getter
  3131. return shadow(this, 'num', obj);
  3132. },
  3133. get destinations() {
  3134. function fetchDestination(dest) {
  3135. return isDict(dest) ? dest.get('D') : dest;
  3136. }
  3137. var xref = this.xref;
  3138. var dests = {}, nameTreeRef, nameDictionaryRef;
  3139. var obj = this.catDict.get('Names');
  3140. if (obj && obj.has('Dests')) {
  3141. nameTreeRef = obj.getRaw('Dests');
  3142. } else if (this.catDict.has('Dests')) {
  3143. nameDictionaryRef = this.catDict.get('Dests');
  3144. }
  3145. if (nameDictionaryRef) {
  3146. // reading simple destination dictionary
  3147. obj = nameDictionaryRef;
  3148. obj.forEach(function catalogForEach(key, value) {
  3149. if (!value) {
  3150. return;
  3151. }
  3152. dests[key] = fetchDestination(value);
  3153. });
  3154. }
  3155. if (nameTreeRef) {
  3156. var nameTree = new NameTree(nameTreeRef, xref);
  3157. var names = nameTree.getAll();
  3158. for (var name in names) {
  3159. if (!names.hasOwnProperty(name)) {
  3160. continue;
  3161. }
  3162. dests[name] = fetchDestination(names[name]);
  3163. }
  3164. }
  3165. return shadow(this, 'destinations', dests);
  3166. },
  3167. getDestination: function Catalog_getDestination(destinationId) {
  3168. function fetchDestination(dest) {
  3169. return isDict(dest) ? dest.get('D') : dest;
  3170. }
  3171. var xref = this.xref;
  3172. var dest, nameTreeRef, nameDictionaryRef;
  3173. var obj = this.catDict.get('Names');
  3174. if (obj && obj.has('Dests')) {
  3175. nameTreeRef = obj.getRaw('Dests');
  3176. } else if (this.catDict.has('Dests')) {
  3177. nameDictionaryRef = this.catDict.get('Dests');
  3178. }
  3179. if (nameDictionaryRef) {
  3180. // reading simple destination dictionary
  3181. obj = nameDictionaryRef;
  3182. obj.forEach(function catalogForEach(key, value) {
  3183. if (!value) {
  3184. return;
  3185. }
  3186. if (key === destinationId) {
  3187. dest = fetchDestination(value);
  3188. }
  3189. });
  3190. }
  3191. if (nameTreeRef) {
  3192. var nameTree = new NameTree(nameTreeRef, xref);
  3193. dest = fetchDestination(nameTree.get(destinationId));
  3194. }
  3195. return dest;
  3196. },
  3197. get attachments() {
  3198. var xref = this.xref;
  3199. var attachments = null, nameTreeRef;
  3200. var obj = this.catDict.get('Names');
  3201. if (obj) {
  3202. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3203. }
  3204. if (nameTreeRef) {
  3205. var nameTree = new NameTree(nameTreeRef, xref);
  3206. var names = nameTree.getAll();
  3207. for (var name in names) {
  3208. if (!names.hasOwnProperty(name)) {
  3209. continue;
  3210. }
  3211. var fs = new FileSpec(names[name], xref);
  3212. if (!attachments) {
  3213. attachments = {};
  3214. }
  3215. attachments[stringToPDFString(name)] = fs.serializable;
  3216. }
  3217. }
  3218. return shadow(this, 'attachments', attachments);
  3219. },
  3220. get javaScript() {
  3221. var xref = this.xref;
  3222. var obj = this.catDict.get('Names');
  3223. var javaScript = [];
  3224. if (obj && obj.has('JavaScript')) {
  3225. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3226. var names = nameTree.getAll();
  3227. for (var name in names) {
  3228. if (!names.hasOwnProperty(name)) {
  3229. continue;
  3230. }
  3231. // We don't really use the JavaScript right now. This code is
  3232. // defensive so we don't cause errors on document load.
  3233. var jsDict = names[name];
  3234. if (!isDict(jsDict)) {
  3235. continue;
  3236. }
  3237. var type = jsDict.get('S');
  3238. if (!isName(type) || type.name !== 'JavaScript') {
  3239. continue;
  3240. }
  3241. var js = jsDict.get('JS');
  3242. if (!isString(js) && !isStream(js)) {
  3243. continue;
  3244. }
  3245. if (isStream(js)) {
  3246. js = bytesToString(js.getBytes());
  3247. }
  3248. javaScript.push(stringToPDFString(js));
  3249. }
  3250. }
  3251. // Append OpenAction actions to javaScript array
  3252. var openactionDict = this.catDict.get('OpenAction');
  3253. if (isDict(openactionDict)) {
  3254. var objType = openactionDict.get('Type');
  3255. var actionType = openactionDict.get('S');
  3256. var action = openactionDict.get('N');
  3257. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3258. isName(actionType) && actionType.name === 'Named' &&
  3259. isName(action) && action.name === 'Print');
  3260. if (isPrintAction) {
  3261. javaScript.push('print(true);');
  3262. }
  3263. }
  3264. return shadow(this, 'javaScript', javaScript);
  3265. },
  3266. cleanup: function Catalog_cleanup() {
  3267. var promises = [];
  3268. this.fontCache.forEach(function (promise) {
  3269. promises.push(promise);
  3270. });
  3271. return Promise.all(promises).then(function (translatedFonts) {
  3272. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3273. var font = translatedFonts[i].dict;
  3274. delete font.translated;
  3275. }
  3276. this.fontCache.clear();
  3277. }.bind(this));
  3278. },
  3279. getPage: function Catalog_getPage(pageIndex) {
  3280. if (!(pageIndex in this.pagePromises)) {
  3281. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3282. function (a) {
  3283. var dict = a[0];
  3284. var ref = a[1];
  3285. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3286. this.fontCache);
  3287. }.bind(this)
  3288. );
  3289. }
  3290. return this.pagePromises[pageIndex];
  3291. },
  3292. getPageDict: function Catalog_getPageDict(pageIndex) {
  3293. var capability = createPromiseCapability();
  3294. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3295. var currentPageIndex = 0;
  3296. var xref = this.xref;
  3297. var checkAllKids = false;
  3298. function next() {
  3299. while (nodesToVisit.length) {
  3300. var currentNode = nodesToVisit.pop();
  3301. if (isRef(currentNode)) {
  3302. xref.fetchAsync(currentNode).then(function (obj) {
  3303. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3304. if (pageIndex === currentPageIndex) {
  3305. capability.resolve([obj, currentNode]);
  3306. } else {
  3307. currentPageIndex++;
  3308. next();
  3309. }
  3310. return;
  3311. }
  3312. nodesToVisit.push(obj);
  3313. next();
  3314. }, capability.reject);
  3315. return;
  3316. }
  3317. // Must be a child page dictionary.
  3318. assert(
  3319. isDict(currentNode),
  3320. 'page dictionary kid reference points to wrong type of object'
  3321. );
  3322. var count = currentNode.get('Count');
  3323. // If the current node doesn't have any children, avoid getting stuck
  3324. // in an empty node further down in the tree (see issue5644.pdf).
  3325. if (count === 0) {
  3326. checkAllKids = true;
  3327. }
  3328. // Skip nodes where the page can't be.
  3329. if (currentPageIndex + count <= pageIndex) {
  3330. currentPageIndex += count;
  3331. continue;
  3332. }
  3333. var kids = currentNode.get('Kids');
  3334. assert(isArray(kids), 'page dictionary kids object is not an array');
  3335. if (!checkAllKids && count === kids.length) {
  3336. // Nodes that don't have the page have been skipped and this is the
  3337. // bottom of the tree which means the page requested must be a
  3338. // descendant of this pages node. Ideally we would just resolve the
  3339. // promise with the page ref here, but there is the case where more
  3340. // pages nodes could link to single a page (see issue 3666 pdf). To
  3341. // handle this push it back on the queue so if it is a pages node it
  3342. // will be descended into.
  3343. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3344. currentPageIndex = pageIndex;
  3345. continue;
  3346. } else {
  3347. for (var last = kids.length - 1; last >= 0; last--) {
  3348. nodesToVisit.push(kids[last]);
  3349. }
  3350. }
  3351. }
  3352. capability.reject('Page index ' + pageIndex + ' not found.');
  3353. }
  3354. next();
  3355. return capability.promise;
  3356. },
  3357. getPageIndex: function Catalog_getPageIndex(ref) {
  3358. // The page tree nodes have the count of all the leaves below them. To get
  3359. // how many pages are before we just have to walk up the tree and keep
  3360. // adding the count of siblings to the left of the node.
  3361. var xref = this.xref;
  3362. function pagesBeforeRef(kidRef) {
  3363. var total = 0;
  3364. var parentRef;
  3365. return xref.fetchAsync(kidRef).then(function (node) {
  3366. if (!node) {
  3367. return null;
  3368. }
  3369. parentRef = node.getRaw('Parent');
  3370. return node.getAsync('Parent');
  3371. }).then(function (parent) {
  3372. if (!parent) {
  3373. return null;
  3374. }
  3375. return parent.getAsync('Kids');
  3376. }).then(function (kids) {
  3377. if (!kids) {
  3378. return null;
  3379. }
  3380. var kidPromises = [];
  3381. var found = false;
  3382. for (var i = 0; i < kids.length; i++) {
  3383. var kid = kids[i];
  3384. assert(isRef(kid), 'kids must be a ref');
  3385. if (kid.num === kidRef.num) {
  3386. found = true;
  3387. break;
  3388. }
  3389. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3390. if (kid.has('Count')) {
  3391. var count = kid.get('Count');
  3392. total += count;
  3393. } else { // page leaf node
  3394. total++;
  3395. }
  3396. }));
  3397. }
  3398. if (!found) {
  3399. error('kid ref not found in parents kids');
  3400. }
  3401. return Promise.all(kidPromises).then(function () {
  3402. return [total, parentRef];
  3403. });
  3404. });
  3405. }
  3406. var total = 0;
  3407. function next(ref) {
  3408. return pagesBeforeRef(ref).then(function (args) {
  3409. if (!args) {
  3410. return total;
  3411. }
  3412. var count = args[0];
  3413. var parentRef = args[1];
  3414. total += count;
  3415. return next(parentRef);
  3416. });
  3417. }
  3418. return next(ref);
  3419. }
  3420. };
  3421. return Catalog;
  3422. })();
  3423. var XRef = (function XRefClosure() {
  3424. function XRef(stream, password) {
  3425. this.stream = stream;
  3426. this.entries = [];
  3427. this.xrefstms = {};
  3428. // prepare the XRef cache
  3429. this.cache = [];
  3430. this.password = password;
  3431. this.stats = {
  3432. streamTypes: [],
  3433. fontTypes: []
  3434. };
  3435. }
  3436. XRef.prototype = {
  3437. setStartXRef: function XRef_setStartXRef(startXRef) {
  3438. // Store the starting positions of xref tables as we process them
  3439. // so we can recover from missing data errors
  3440. this.startXRefQueue = [startXRef];
  3441. },
  3442. parse: function XRef_parse(recoveryMode) {
  3443. var trailerDict;
  3444. if (!recoveryMode) {
  3445. trailerDict = this.readXRef();
  3446. } else {
  3447. warn('Indexing all PDF objects');
  3448. trailerDict = this.indexObjects();
  3449. }
  3450. trailerDict.assignXref(this);
  3451. this.trailer = trailerDict;
  3452. var encrypt = trailerDict.get('Encrypt');
  3453. if (encrypt) {
  3454. var ids = trailerDict.get('ID');
  3455. var fileId = (ids && ids.length) ? ids[0] : '';
  3456. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3457. this.password);
  3458. }
  3459. // get the root dictionary (catalog) object
  3460. if (!(this.root = trailerDict.get('Root'))) {
  3461. error('Invalid root reference');
  3462. }
  3463. },
  3464. processXRefTable: function XRef_processXRefTable(parser) {
  3465. if (!('tableState' in this)) {
  3466. // Stores state of the table as we process it so we can resume
  3467. // from middle of table in case of missing data error
  3468. this.tableState = {
  3469. entryNum: 0,
  3470. streamPos: parser.lexer.stream.pos,
  3471. parserBuf1: parser.buf1,
  3472. parserBuf2: parser.buf2
  3473. };
  3474. }
  3475. var obj = this.readXRefTable(parser);
  3476. // Sanity check
  3477. if (!isCmd(obj, 'trailer')) {
  3478. error('Invalid XRef table: could not find trailer dictionary');
  3479. }
  3480. // Read trailer dictionary, e.g.
  3481. // trailer
  3482. // << /Size 22
  3483. // /Root 20R
  3484. // /Info 10R
  3485. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3486. // >>
  3487. // The parser goes through the entire stream << ... >> and provides
  3488. // a getter interface for the key-value table
  3489. var dict = parser.getObj();
  3490. // The pdflib PDF generator can generate a nested trailer dictionary
  3491. if (!isDict(dict) && dict.dict) {
  3492. dict = dict.dict;
  3493. }
  3494. if (!isDict(dict)) {
  3495. error('Invalid XRef table: could not parse trailer dictionary');
  3496. }
  3497. delete this.tableState;
  3498. return dict;
  3499. },
  3500. readXRefTable: function XRef_readXRefTable(parser) {
  3501. // Example of cross-reference table:
  3502. // xref
  3503. // 0 1 <-- subsection header (first obj #, obj count)
  3504. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3505. // 23 2 <-- subsection header ... and so on ...
  3506. // 0000025518 00002 n
  3507. // 0000025635 00000 n
  3508. // trailer
  3509. // ...
  3510. var stream = parser.lexer.stream;
  3511. var tableState = this.tableState;
  3512. stream.pos = tableState.streamPos;
  3513. parser.buf1 = tableState.parserBuf1;
  3514. parser.buf2 = tableState.parserBuf2;
  3515. // Outer loop is over subsection headers
  3516. var obj;
  3517. while (true) {
  3518. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3519. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3520. break;
  3521. }
  3522. tableState.firstEntryNum = obj;
  3523. tableState.entryCount = parser.getObj();
  3524. }
  3525. var first = tableState.firstEntryNum;
  3526. var count = tableState.entryCount;
  3527. if (!isInt(first) || !isInt(count)) {
  3528. error('Invalid XRef table: wrong types in subsection header');
  3529. }
  3530. // Inner loop is over objects themselves
  3531. for (var i = tableState.entryNum; i < count; i++) {
  3532. tableState.streamPos = stream.pos;
  3533. tableState.entryNum = i;
  3534. tableState.parserBuf1 = parser.buf1;
  3535. tableState.parserBuf2 = parser.buf2;
  3536. var entry = {};
  3537. entry.offset = parser.getObj();
  3538. entry.gen = parser.getObj();
  3539. var type = parser.getObj();
  3540. if (isCmd(type, 'f')) {
  3541. entry.free = true;
  3542. } else if (isCmd(type, 'n')) {
  3543. entry.uncompressed = true;
  3544. }
  3545. // Validate entry obj
  3546. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3547. !(entry.free || entry.uncompressed)) {
  3548. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3549. }
  3550. if (!this.entries[i + first]) {
  3551. this.entries[i + first] = entry;
  3552. }
  3553. }
  3554. tableState.entryNum = 0;
  3555. tableState.streamPos = stream.pos;
  3556. tableState.parserBuf1 = parser.buf1;
  3557. tableState.parserBuf2 = parser.buf2;
  3558. delete tableState.firstEntryNum;
  3559. delete tableState.entryCount;
  3560. }
  3561. // Per issue 3248: hp scanners generate bad XRef
  3562. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3563. // shifting the entries
  3564. this.entries.shift();
  3565. }
  3566. // Sanity check: as per spec, first object must be free
  3567. if (this.entries[0] && !this.entries[0].free) {
  3568. error('Invalid XRef table: unexpected first object');
  3569. }
  3570. return obj;
  3571. },
  3572. processXRefStream: function XRef_processXRefStream(stream) {
  3573. if (!('streamState' in this)) {
  3574. // Stores state of the stream as we process it so we can resume
  3575. // from middle of stream in case of missing data error
  3576. var streamParameters = stream.dict;
  3577. var byteWidths = streamParameters.get('W');
  3578. var range = streamParameters.get('Index');
  3579. if (!range) {
  3580. range = [0, streamParameters.get('Size')];
  3581. }
  3582. this.streamState = {
  3583. entryRanges: range,
  3584. byteWidths: byteWidths,
  3585. entryNum: 0,
  3586. streamPos: stream.pos
  3587. };
  3588. }
  3589. this.readXRefStream(stream);
  3590. delete this.streamState;
  3591. return stream.dict;
  3592. },
  3593. readXRefStream: function XRef_readXRefStream(stream) {
  3594. var i, j;
  3595. var streamState = this.streamState;
  3596. stream.pos = streamState.streamPos;
  3597. var byteWidths = streamState.byteWidths;
  3598. var typeFieldWidth = byteWidths[0];
  3599. var offsetFieldWidth = byteWidths[1];
  3600. var generationFieldWidth = byteWidths[2];
  3601. var entryRanges = streamState.entryRanges;
  3602. while (entryRanges.length > 0) {
  3603. var first = entryRanges[0];
  3604. var n = entryRanges[1];
  3605. if (!isInt(first) || !isInt(n)) {
  3606. error('Invalid XRef range fields: ' + first + ', ' + n);
  3607. }
  3608. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3609. !isInt(generationFieldWidth)) {
  3610. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3611. }
  3612. for (i = streamState.entryNum; i < n; ++i) {
  3613. streamState.entryNum = i;
  3614. streamState.streamPos = stream.pos;
  3615. var type = 0, offset = 0, generation = 0;
  3616. for (j = 0; j < typeFieldWidth; ++j) {
  3617. type = (type << 8) | stream.getByte();
  3618. }
  3619. // if type field is absent, its default value is 1
  3620. if (typeFieldWidth === 0) {
  3621. type = 1;
  3622. }
  3623. for (j = 0; j < offsetFieldWidth; ++j) {
  3624. offset = (offset << 8) | stream.getByte();
  3625. }
  3626. for (j = 0; j < generationFieldWidth; ++j) {
  3627. generation = (generation << 8) | stream.getByte();
  3628. }
  3629. var entry = {};
  3630. entry.offset = offset;
  3631. entry.gen = generation;
  3632. switch (type) {
  3633. case 0:
  3634. entry.free = true;
  3635. break;
  3636. case 1:
  3637. entry.uncompressed = true;
  3638. break;
  3639. case 2:
  3640. break;
  3641. default:
  3642. error('Invalid XRef entry type: ' + type);
  3643. }
  3644. if (!this.entries[first + i]) {
  3645. this.entries[first + i] = entry;
  3646. }
  3647. }
  3648. streamState.entryNum = 0;
  3649. streamState.streamPos = stream.pos;
  3650. entryRanges.splice(0, 2);
  3651. }
  3652. },
  3653. indexObjects: function XRef_indexObjects() {
  3654. // Simple scan through the PDF content to find objects,
  3655. // trailers and XRef streams.
  3656. function readToken(data, offset) {
  3657. var token = '', ch = data[offset];
  3658. while (ch !== 13 && ch !== 10) {
  3659. if (++offset >= data.length) {
  3660. break;
  3661. }
  3662. token += String.fromCharCode(ch);
  3663. ch = data[offset];
  3664. }
  3665. return token;
  3666. }
  3667. function skipUntil(data, offset, what) {
  3668. var length = what.length, dataLength = data.length;
  3669. var skipped = 0;
  3670. // finding byte sequence
  3671. while (offset < dataLength) {
  3672. var i = 0;
  3673. while (i < length && data[offset + i] === what[i]) {
  3674. ++i;
  3675. }
  3676. if (i >= length) {
  3677. break; // sequence found
  3678. }
  3679. offset++;
  3680. skipped++;
  3681. }
  3682. return skipped;
  3683. }
  3684. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3685. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3686. 101, 102]);
  3687. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3688. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3689. var stream = this.stream;
  3690. stream.pos = 0;
  3691. var buffer = stream.getBytes();
  3692. var position = stream.start, length = buffer.length;
  3693. var trailers = [], xrefStms = [];
  3694. while (position < length) {
  3695. var ch = buffer[position];
  3696. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3697. ++position;
  3698. continue;
  3699. }
  3700. if (ch === 37) { // %-comment
  3701. do {
  3702. ++position;
  3703. if (position >= length) {
  3704. break;
  3705. }
  3706. ch = buffer[position];
  3707. } while (ch !== 13 && ch !== 10);
  3708. continue;
  3709. }
  3710. var token = readToken(buffer, position);
  3711. var m;
  3712. if (token === 'xref') {
  3713. position += skipUntil(buffer, position, trailerBytes);
  3714. trailers.push(position);
  3715. position += skipUntil(buffer, position, startxrefBytes);
  3716. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3717. if (typeof this.entries[m[1]] === 'undefined') {
  3718. this.entries[m[1]] = {
  3719. offset: position - stream.start,
  3720. gen: m[2] | 0,
  3721. uncompressed: true
  3722. };
  3723. }
  3724. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3725. var content = buffer.subarray(position, position + contentLength);
  3726. // checking XRef stream suspect
  3727. // (it shall have '/XRef' and next char is not a letter)
  3728. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3729. if (xrefTagOffset < contentLength &&
  3730. content[xrefTagOffset + 5] < 64) {
  3731. xrefStms.push(position - stream.start);
  3732. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  3733. }
  3734. position += contentLength;
  3735. } else {
  3736. position += token.length + 1;
  3737. }
  3738. }
  3739. // reading XRef streams
  3740. var i, ii;
  3741. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3742. this.startXRefQueue.push(xrefStms[i]);
  3743. this.readXRef(/* recoveryMode */ true);
  3744. }
  3745. // finding main trailer
  3746. var dict;
  3747. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3748. stream.pos = trailers[i];
  3749. var parser = new Parser(new Lexer(stream), true, this);
  3750. var obj = parser.getObj();
  3751. if (!isCmd(obj, 'trailer')) {
  3752. continue;
  3753. }
  3754. // read the trailer dictionary
  3755. if (!isDict(dict = parser.getObj())) {
  3756. continue;
  3757. }
  3758. // taking the first one with 'ID'
  3759. if (dict.has('ID')) {
  3760. return dict;
  3761. }
  3762. }
  3763. // no tailer with 'ID', taking last one (if exists)
  3764. if (dict) {
  3765. return dict;
  3766. }
  3767. // nothing helps
  3768. // calling error() would reject worker with an UnknownErrorException.
  3769. throw new InvalidPDFException('Invalid PDF structure');
  3770. },
  3771. readXRef: function XRef_readXRef(recoveryMode) {
  3772. var stream = this.stream;
  3773. try {
  3774. while (this.startXRefQueue.length) {
  3775. var startXRef = this.startXRefQueue[0];
  3776. stream.pos = startXRef + stream.start;
  3777. var parser = new Parser(new Lexer(stream), true, this);
  3778. var obj = parser.getObj();
  3779. var dict;
  3780. // Get dictionary
  3781. if (isCmd(obj, 'xref')) {
  3782. // Parse end-of-file XRef
  3783. dict = this.processXRefTable(parser);
  3784. if (!this.topDict) {
  3785. this.topDict = dict;
  3786. }
  3787. // Recursively get other XRefs 'XRefStm', if any
  3788. obj = dict.get('XRefStm');
  3789. if (isInt(obj)) {
  3790. var pos = obj;
  3791. // ignore previously loaded xref streams
  3792. // (possible infinite recursion)
  3793. if (!(pos in this.xrefstms)) {
  3794. this.xrefstms[pos] = 1;
  3795. this.startXRefQueue.push(pos);
  3796. }
  3797. }
  3798. } else if (isInt(obj)) {
  3799. // Parse in-stream XRef
  3800. if (!isInt(parser.getObj()) ||
  3801. !isCmd(parser.getObj(), 'obj') ||
  3802. !isStream(obj = parser.getObj())) {
  3803. error('Invalid XRef stream');
  3804. }
  3805. dict = this.processXRefStream(obj);
  3806. if (!this.topDict) {
  3807. this.topDict = dict;
  3808. }
  3809. if (!dict) {
  3810. error('Failed to read XRef stream');
  3811. }
  3812. } else {
  3813. error('Invalid XRef stream header');
  3814. }
  3815. // Recursively get previous dictionary, if any
  3816. obj = dict.get('Prev');
  3817. if (isInt(obj)) {
  3818. this.startXRefQueue.push(obj);
  3819. } else if (isRef(obj)) {
  3820. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3821. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3822. this.startXRefQueue.push(obj.num);
  3823. }
  3824. this.startXRefQueue.shift();
  3825. }
  3826. return this.topDict;
  3827. } catch (e) {
  3828. if (e instanceof MissingDataException) {
  3829. throw e;
  3830. }
  3831. info('(while reading XRef): ' + e);
  3832. }
  3833. if (recoveryMode) {
  3834. return;
  3835. }
  3836. throw new XRefParseException();
  3837. },
  3838. getEntry: function XRef_getEntry(i) {
  3839. var xrefEntry = this.entries[i];
  3840. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3841. return xrefEntry;
  3842. }
  3843. return null;
  3844. },
  3845. fetchIfRef: function XRef_fetchIfRef(obj) {
  3846. if (!isRef(obj)) {
  3847. return obj;
  3848. }
  3849. return this.fetch(obj);
  3850. },
  3851. fetch: function XRef_fetch(ref, suppressEncryption) {
  3852. assert(isRef(ref), 'ref object is not a reference');
  3853. var num = ref.num;
  3854. if (num in this.cache) {
  3855. var cacheEntry = this.cache[num];
  3856. return cacheEntry;
  3857. }
  3858. var xrefEntry = this.getEntry(num);
  3859. // the referenced entry can be free
  3860. if (xrefEntry === null) {
  3861. return (this.cache[num] = null);
  3862. }
  3863. if (xrefEntry.uncompressed) {
  3864. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3865. } else {
  3866. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3867. }
  3868. if (isDict(xrefEntry)){
  3869. xrefEntry.objId = ref.toString();
  3870. } else if (isStream(xrefEntry)) {
  3871. xrefEntry.dict.objId = ref.toString();
  3872. }
  3873. return xrefEntry;
  3874. },
  3875. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3876. suppressEncryption) {
  3877. var gen = ref.gen;
  3878. var num = ref.num;
  3879. if (xrefEntry.gen !== gen) {
  3880. error('inconsistent generation in XRef');
  3881. }
  3882. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3883. this.stream.start);
  3884. var parser = new Parser(new Lexer(stream), true, this);
  3885. var obj1 = parser.getObj();
  3886. var obj2 = parser.getObj();
  3887. var obj3 = parser.getObj();
  3888. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3889. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3890. !isCmd(obj3)) {
  3891. error('bad XRef entry');
  3892. }
  3893. if (!isCmd(obj3, 'obj')) {
  3894. // some bad PDFs use "obj1234" and really mean 1234
  3895. if (obj3.cmd.indexOf('obj') === 0) {
  3896. num = parseInt(obj3.cmd.substring(3), 10);
  3897. if (!isNaN(num)) {
  3898. return num;
  3899. }
  3900. }
  3901. error('bad XRef entry');
  3902. }
  3903. if (this.encrypt && !suppressEncryption) {
  3904. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3905. } else {
  3906. xrefEntry = parser.getObj();
  3907. }
  3908. if (!isStream(xrefEntry)) {
  3909. this.cache[num] = xrefEntry;
  3910. }
  3911. return xrefEntry;
  3912. },
  3913. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3914. suppressEncryption) {
  3915. var tableOffset = xrefEntry.offset;
  3916. var stream = this.fetch(new Ref(tableOffset, 0));
  3917. if (!isStream(stream)) {
  3918. error('bad ObjStm stream');
  3919. }
  3920. var first = stream.dict.get('First');
  3921. var n = stream.dict.get('N');
  3922. if (!isInt(first) || !isInt(n)) {
  3923. error('invalid first and n parameters for ObjStm stream');
  3924. }
  3925. var parser = new Parser(new Lexer(stream), false, this);
  3926. parser.allowStreams = true;
  3927. var i, entries = [], num, nums = [];
  3928. // read the object numbers to populate cache
  3929. for (i = 0; i < n; ++i) {
  3930. num = parser.getObj();
  3931. if (!isInt(num)) {
  3932. error('invalid object number in the ObjStm stream: ' + num);
  3933. }
  3934. nums.push(num);
  3935. var offset = parser.getObj();
  3936. if (!isInt(offset)) {
  3937. error('invalid object offset in the ObjStm stream: ' + offset);
  3938. }
  3939. }
  3940. // read stream objects for cache
  3941. for (i = 0; i < n; ++i) {
  3942. entries.push(parser.getObj());
  3943. num = nums[i];
  3944. var entry = this.entries[num];
  3945. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3946. this.cache[num] = entries[i];
  3947. }
  3948. }
  3949. xrefEntry = entries[xrefEntry.gen];
  3950. if (xrefEntry === undefined) {
  3951. error('bad XRef entry for compressed object');
  3952. }
  3953. return xrefEntry;
  3954. },
  3955. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3956. if (!isRef(obj)) {
  3957. return Promise.resolve(obj);
  3958. }
  3959. return this.fetchAsync(obj);
  3960. },
  3961. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3962. var streamManager = this.stream.manager;
  3963. var xref = this;
  3964. return new Promise(function tryFetch(resolve, reject) {
  3965. try {
  3966. resolve(xref.fetch(ref, suppressEncryption));
  3967. } catch (e) {
  3968. if (e instanceof MissingDataException) {
  3969. streamManager.requestRange(e.begin, e.end, function () {
  3970. tryFetch(resolve, reject);
  3971. });
  3972. return;
  3973. }
  3974. reject(e);
  3975. }
  3976. });
  3977. },
  3978. getCatalogObj: function XRef_getCatalogObj() {
  3979. return this.root;
  3980. }
  3981. };
  3982. return XRef;
  3983. })();
  3984. /**
  3985. * A NameTree is like a Dict but has some advantageous properties, see the
  3986. * spec (7.9.6) for more details.
  3987. * TODO: implement all the Dict functions and make this more efficent.
  3988. */
  3989. var NameTree = (function NameTreeClosure() {
  3990. function NameTree(root, xref) {
  3991. this.root = root;
  3992. this.xref = xref;
  3993. }
  3994. NameTree.prototype = {
  3995. getAll: function NameTree_getAll() {
  3996. var dict = {};
  3997. if (!this.root) {
  3998. return dict;
  3999. }
  4000. var xref = this.xref;
  4001. // reading name tree
  4002. var processed = new RefSet();
  4003. processed.put(this.root);
  4004. var queue = [this.root];
  4005. while (queue.length > 0) {
  4006. var i, n;
  4007. var obj = xref.fetchIfRef(queue.shift());
  4008. if (!isDict(obj)) {
  4009. continue;
  4010. }
  4011. if (obj.has('Kids')) {
  4012. var kids = obj.get('Kids');
  4013. for (i = 0, n = kids.length; i < n; i++) {
  4014. var kid = kids[i];
  4015. if (processed.has(kid)) {
  4016. error('invalid destinations');
  4017. }
  4018. queue.push(kid);
  4019. processed.put(kid);
  4020. }
  4021. continue;
  4022. }
  4023. var names = obj.get('Names');
  4024. if (names) {
  4025. for (i = 0, n = names.length; i < n; i += 2) {
  4026. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  4027. }
  4028. }
  4029. }
  4030. return dict;
  4031. },
  4032. get: function NameTree_get(destinationId) {
  4033. if (!this.root) {
  4034. return null;
  4035. }
  4036. var xref = this.xref;
  4037. var kidsOrNames = xref.fetchIfRef(this.root);
  4038. var loopCount = 0;
  4039. var MAX_NAMES_LEVELS = 10;
  4040. var l, r, m;
  4041. // Perform a binary search to quickly find the entry that
  4042. // contains the named destination we are looking for.
  4043. while (kidsOrNames.has('Kids')) {
  4044. loopCount++;
  4045. if (loopCount > MAX_NAMES_LEVELS) {
  4046. warn('Search depth limit for named destionations has been reached.');
  4047. return null;
  4048. }
  4049. var kids = kidsOrNames.get('Kids');
  4050. if (!isArray(kids)) {
  4051. return null;
  4052. }
  4053. l = 0;
  4054. r = kids.length - 1;
  4055. while (l <= r) {
  4056. m = (l + r) >> 1;
  4057. var kid = xref.fetchIfRef(kids[m]);
  4058. var limits = kid.get('Limits');
  4059. if (destinationId < limits[0]) {
  4060. r = m - 1;
  4061. } else if (destinationId > limits[1]) {
  4062. l = m + 1;
  4063. } else {
  4064. kidsOrNames = xref.fetchIfRef(kids[m]);
  4065. break;
  4066. }
  4067. }
  4068. if (l > r) {
  4069. return null;
  4070. }
  4071. }
  4072. // If we get here, then we have found the right entry. Now
  4073. // go through the named destinations in the Named dictionary
  4074. // until we find the exact destination we're looking for.
  4075. var names = kidsOrNames.get('Names');
  4076. if (isArray(names)) {
  4077. // Perform a binary search to reduce the lookup time.
  4078. l = 0;
  4079. r = names.length - 2;
  4080. while (l <= r) {
  4081. // Check only even indices (0, 2, 4, ...) because the
  4082. // odd indices contain the actual D array.
  4083. m = (l + r) & ~1;
  4084. if (destinationId < names[m]) {
  4085. r = m - 2;
  4086. } else if (destinationId > names[m]) {
  4087. l = m + 2;
  4088. } else {
  4089. return xref.fetchIfRef(names[m + 1]);
  4090. }
  4091. }
  4092. }
  4093. return null;
  4094. }
  4095. };
  4096. return NameTree;
  4097. })();
  4098. /**
  4099. * "A PDF file can refer to the contents of another file by using a File
  4100. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4101. * NOTE: Only embedded files are supported (as part of the attachments support)
  4102. * TODO: support the 'URL' file system (with caching if !/V), portable
  4103. * collections attributes and related files (/RF)
  4104. */
  4105. var FileSpec = (function FileSpecClosure() {
  4106. function FileSpec(root, xref) {
  4107. if (!root || !isDict(root)) {
  4108. return;
  4109. }
  4110. this.xref = xref;
  4111. this.root = root;
  4112. if (root.has('FS')) {
  4113. this.fs = root.get('FS');
  4114. }
  4115. this.description = root.has('Desc') ?
  4116. stringToPDFString(root.get('Desc')) :
  4117. '';
  4118. if (root.has('RF')) {
  4119. warn('Related file specifications are not supported');
  4120. }
  4121. this.contentAvailable = true;
  4122. if (!root.has('EF')) {
  4123. this.contentAvailable = false;
  4124. warn('Non-embedded file specifications are not supported');
  4125. }
  4126. }
  4127. function pickPlatformItem(dict) {
  4128. // Look for the filename in this order:
  4129. // UF, F, Unix, Mac, DOS
  4130. if (dict.has('UF')) {
  4131. return dict.get('UF');
  4132. } else if (dict.has('F')) {
  4133. return dict.get('F');
  4134. } else if (dict.has('Unix')) {
  4135. return dict.get('Unix');
  4136. } else if (dict.has('Mac')) {
  4137. return dict.get('Mac');
  4138. } else if (dict.has('DOS')) {
  4139. return dict.get('DOS');
  4140. } else {
  4141. return null;
  4142. }
  4143. }
  4144. FileSpec.prototype = {
  4145. get filename() {
  4146. if (!this._filename && this.root) {
  4147. var filename = pickPlatformItem(this.root) || 'unnamed';
  4148. this._filename = stringToPDFString(filename).
  4149. replace(/\\\\/g, '\\').
  4150. replace(/\\\//g, '/').
  4151. replace(/\\/g, '/');
  4152. }
  4153. return this._filename;
  4154. },
  4155. get content() {
  4156. if (!this.contentAvailable) {
  4157. return null;
  4158. }
  4159. if (!this.contentRef && this.root) {
  4160. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4161. }
  4162. var content = null;
  4163. if (this.contentRef) {
  4164. var xref = this.xref;
  4165. var fileObj = xref.fetchIfRef(this.contentRef);
  4166. if (fileObj && isStream(fileObj)) {
  4167. content = fileObj.getBytes();
  4168. } else {
  4169. warn('Embedded file specification points to non-existing/invalid ' +
  4170. 'content');
  4171. }
  4172. } else {
  4173. warn('Embedded file specification does not have a content');
  4174. }
  4175. return content;
  4176. },
  4177. get serializable() {
  4178. return {
  4179. filename: this.filename,
  4180. content: this.content
  4181. };
  4182. }
  4183. };
  4184. return FileSpec;
  4185. })();
  4186. /**
  4187. * A helper for loading missing data in object graphs. It traverses the graph
  4188. * depth first and queues up any objects that have missing data. Once it has
  4189. * has traversed as many objects that are available it attempts to bundle the
  4190. * missing data requests and then resume from the nodes that weren't ready.
  4191. *
  4192. * NOTE: It provides protection from circular references by keeping track of
  4193. * of loaded references. However, you must be careful not to load any graphs
  4194. * that have references to the catalog or other pages since that will cause the
  4195. * entire PDF document object graph to be traversed.
  4196. */
  4197. var ObjectLoader = (function() {
  4198. function mayHaveChildren(value) {
  4199. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4200. }
  4201. function addChildren(node, nodesToVisit) {
  4202. var value;
  4203. if (isDict(node) || isStream(node)) {
  4204. var map;
  4205. if (isDict(node)) {
  4206. map = node.map;
  4207. } else {
  4208. map = node.dict.map;
  4209. }
  4210. for (var key in map) {
  4211. value = map[key];
  4212. if (mayHaveChildren(value)) {
  4213. nodesToVisit.push(value);
  4214. }
  4215. }
  4216. } else if (isArray(node)) {
  4217. for (var i = 0, ii = node.length; i < ii; i++) {
  4218. value = node[i];
  4219. if (mayHaveChildren(value)) {
  4220. nodesToVisit.push(value);
  4221. }
  4222. }
  4223. }
  4224. }
  4225. function ObjectLoader(obj, keys, xref) {
  4226. this.obj = obj;
  4227. this.keys = keys;
  4228. this.xref = xref;
  4229. this.refSet = null;
  4230. }
  4231. ObjectLoader.prototype = {
  4232. load: function ObjectLoader_load() {
  4233. var keys = this.keys;
  4234. this.capability = createPromiseCapability();
  4235. // Don't walk the graph if all the data is already loaded.
  4236. if (!(this.xref.stream instanceof ChunkedStream) ||
  4237. this.xref.stream.getMissingChunks().length === 0) {
  4238. this.capability.resolve();
  4239. return this.capability.promise;
  4240. }
  4241. this.refSet = new RefSet();
  4242. // Setup the initial nodes to visit.
  4243. var nodesToVisit = [];
  4244. for (var i = 0; i < keys.length; i++) {
  4245. nodesToVisit.push(this.obj[keys[i]]);
  4246. }
  4247. this.walk(nodesToVisit);
  4248. return this.capability.promise;
  4249. },
  4250. walk: function ObjectLoader_walk(nodesToVisit) {
  4251. var nodesToRevisit = [];
  4252. var pendingRequests = [];
  4253. // DFS walk of the object graph.
  4254. while (nodesToVisit.length) {
  4255. var currentNode = nodesToVisit.pop();
  4256. // Only references or chunked streams can cause missing data exceptions.
  4257. if (isRef(currentNode)) {
  4258. // Skip nodes that have already been visited.
  4259. if (this.refSet.has(currentNode)) {
  4260. continue;
  4261. }
  4262. try {
  4263. var ref = currentNode;
  4264. this.refSet.put(ref);
  4265. currentNode = this.xref.fetch(currentNode);
  4266. } catch (e) {
  4267. if (!(e instanceof MissingDataException)) {
  4268. throw e;
  4269. }
  4270. nodesToRevisit.push(currentNode);
  4271. pendingRequests.push({ begin: e.begin, end: e.end });
  4272. }
  4273. }
  4274. if (currentNode && currentNode.getBaseStreams) {
  4275. var baseStreams = currentNode.getBaseStreams();
  4276. var foundMissingData = false;
  4277. for (var i = 0; i < baseStreams.length; i++) {
  4278. var stream = baseStreams[i];
  4279. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4280. foundMissingData = true;
  4281. pendingRequests.push({
  4282. begin: stream.start,
  4283. end: stream.end
  4284. });
  4285. }
  4286. }
  4287. if (foundMissingData) {
  4288. nodesToRevisit.push(currentNode);
  4289. }
  4290. }
  4291. addChildren(currentNode, nodesToVisit);
  4292. }
  4293. if (pendingRequests.length) {
  4294. this.xref.stream.manager.requestRanges(pendingRequests,
  4295. function pendingRequestCallback() {
  4296. nodesToVisit = nodesToRevisit;
  4297. for (var i = 0; i < nodesToRevisit.length; i++) {
  4298. var node = nodesToRevisit[i];
  4299. // Remove any reference nodes from the currrent refset so they
  4300. // aren't skipped when we revist them.
  4301. if (isRef(node)) {
  4302. this.refSet.remove(node);
  4303. }
  4304. }
  4305. this.walk(nodesToVisit);
  4306. }.bind(this));
  4307. return;
  4308. }
  4309. // Everything is loaded.
  4310. this.refSet = null;
  4311. this.capability.resolve();
  4312. }
  4313. };
  4314. return ObjectLoader;
  4315. })();
  4316. var ISOAdobeCharset = [
  4317. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4318. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4319. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4320. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4321. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4322. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4323. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4324. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4325. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4326. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4327. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4328. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4329. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4330. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4331. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4332. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4333. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4334. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4335. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4336. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4337. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4338. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4339. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4340. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4341. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4342. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4343. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4344. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4345. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4346. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4347. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4348. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4349. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4350. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4351. ];
  4352. var ExpertCharset = [
  4353. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4354. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4355. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4356. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4357. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4358. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4359. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4360. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4361. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4362. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4363. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4364. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4365. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4366. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4367. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4368. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4369. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4370. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4371. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4372. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4373. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4374. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4375. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4376. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4377. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4378. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4379. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4380. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4381. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4382. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4383. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4384. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4385. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4386. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4387. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4388. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4389. 'Ydieresissmall'
  4390. ];
  4391. var ExpertSubsetCharset = [
  4392. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4393. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4394. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4395. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4396. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4397. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4398. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4399. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4400. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4401. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4402. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4403. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4404. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4405. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4406. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4407. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4408. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4409. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4410. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4411. 'periodinferior', 'commainferior'
  4412. ];
  4413. var DEFAULT_ICON_SIZE = 22; // px
  4414. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4415. var Annotation = (function AnnotationClosure() {
  4416. // 12.5.5: Algorithm: Appearance streams
  4417. function getTransformMatrix(rect, bbox, matrix) {
  4418. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4419. var minX = bounds[0];
  4420. var minY = bounds[1];
  4421. var maxX = bounds[2];
  4422. var maxY = bounds[3];
  4423. if (minX === maxX || minY === maxY) {
  4424. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4425. // just apply the transform for rect
  4426. return [1, 0, 0, 1, rect[0], rect[1]];
  4427. }
  4428. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4429. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4430. return [
  4431. xRatio,
  4432. 0,
  4433. 0,
  4434. yRatio,
  4435. rect[0] - minX * xRatio,
  4436. rect[1] - minY * yRatio
  4437. ];
  4438. }
  4439. function getDefaultAppearance(dict) {
  4440. var appearanceState = dict.get('AP');
  4441. if (!isDict(appearanceState)) {
  4442. return;
  4443. }
  4444. var appearance;
  4445. var appearances = appearanceState.get('N');
  4446. if (isDict(appearances)) {
  4447. var as = dict.get('AS');
  4448. if (as && appearances.has(as.name)) {
  4449. appearance = appearances.get(as.name);
  4450. }
  4451. } else {
  4452. appearance = appearances;
  4453. }
  4454. return appearance;
  4455. }
  4456. function Annotation(params) {
  4457. var dict = params.dict;
  4458. var data = this.data = {};
  4459. data.subtype = dict.get('Subtype').name;
  4460. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4461. data.rect = Util.normalizeRect(rect);
  4462. data.annotationFlags = dict.get('F');
  4463. var color = dict.get('C');
  4464. if (!color) {
  4465. // The PDF spec does not mention how a missing color array is interpreted.
  4466. // Adobe Reader seems to default to black in this case.
  4467. data.color = [0, 0, 0];
  4468. } else if (isArray(color)) {
  4469. switch (color.length) {
  4470. case 0:
  4471. // Empty array denotes transparent border.
  4472. data.color = null;
  4473. break;
  4474. case 1:
  4475. // TODO: implement DeviceGray
  4476. break;
  4477. case 3:
  4478. data.color = color;
  4479. break;
  4480. case 4:
  4481. // TODO: implement DeviceCMYK
  4482. break;
  4483. }
  4484. }
  4485. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  4486. this.setBorderStyle(dict);
  4487. this.appearance = getDefaultAppearance(dict);
  4488. data.hasAppearance = !!this.appearance;
  4489. data.id = params.ref.num;
  4490. }
  4491. Annotation.prototype = {
  4492. /**
  4493. * Set the border style (as AnnotationBorderStyle object).
  4494. *
  4495. * @public
  4496. * @memberof Annotation
  4497. * @param {Dict} borderStyle - The border style dictionary
  4498. */
  4499. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  4500. if (!isDict(borderStyle)) {
  4501. return;
  4502. }
  4503. if (borderStyle.has('BS')) {
  4504. var dict = borderStyle.get('BS');
  4505. var dictType;
  4506. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  4507. dictType.name === 'Border')) {
  4508. this.borderStyle.setWidth(dict.get('W'));
  4509. this.borderStyle.setStyle(dict.get('S'));
  4510. this.borderStyle.setDashArray(dict.get('D'));
  4511. }
  4512. } else if (borderStyle.has('Border')) {
  4513. var array = borderStyle.get('Border');
  4514. if (isArray(array) && array.length >= 3) {
  4515. this.borderStyle.setHorizontalCornerRadius(array[0]);
  4516. this.borderStyle.setVerticalCornerRadius(array[1]);
  4517. this.borderStyle.setWidth(array[2]);
  4518. this.borderStyle.setStyle('S');
  4519. if (array.length === 4) { // Dash array available
  4520. this.borderStyle.setDashArray(array[3]);
  4521. }
  4522. }
  4523. } else {
  4524. // There are no border entries in the dictionary. According to the
  4525. // specification, we should draw a solid border of width 1 in that
  4526. // case, but Adobe Reader did not implement that part of the
  4527. // specification and instead draws no border at all, so we do the same.
  4528. // See also https://github.com/mozilla/pdf.js/issues/6179.
  4529. this.borderStyle.setWidth(0);
  4530. }
  4531. },
  4532. getData: function Annotation_getData() {
  4533. return this.data;
  4534. },
  4535. isInvisible: function Annotation_isInvisible() {
  4536. var data = this.data;
  4537. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4538. return false;
  4539. } else {
  4540. return !!(data &&
  4541. data.annotationFlags && // Default: not invisible
  4542. data.annotationFlags & 0x1); // Invisible
  4543. }
  4544. },
  4545. isViewable: function Annotation_isViewable() {
  4546. var data = this.data;
  4547. return !!(!this.isInvisible() &&
  4548. data &&
  4549. (!data.annotationFlags ||
  4550. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4551. data.rect); // rectangle is necessary
  4552. },
  4553. isPrintable: function Annotation_isPrintable() {
  4554. var data = this.data;
  4555. return !!(!this.isInvisible() &&
  4556. data &&
  4557. data.annotationFlags && // Default: not printable
  4558. data.annotationFlags & 0x4 && // Print
  4559. !(data.annotationFlags & 0x2) && // Hidden
  4560. data.rect); // rectangle is necessary
  4561. },
  4562. loadResources: function Annotation_loadResources(keys) {
  4563. return new Promise(function (resolve, reject) {
  4564. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4565. if (!resources) {
  4566. resolve();
  4567. return;
  4568. }
  4569. var objectLoader = new ObjectLoader(resources.map,
  4570. keys,
  4571. resources.xref);
  4572. objectLoader.load().then(function() {
  4573. resolve(resources);
  4574. }, reject);
  4575. }, reject);
  4576. }.bind(this));
  4577. },
  4578. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4579. if (!this.appearance) {
  4580. return Promise.resolve(new OperatorList());
  4581. }
  4582. var data = this.data;
  4583. var appearanceDict = this.appearance.dict;
  4584. var resourcesPromise = this.loadResources([
  4585. 'ExtGState',
  4586. 'ColorSpace',
  4587. 'Pattern',
  4588. 'Shading',
  4589. 'XObject',
  4590. 'Font'
  4591. // ProcSet
  4592. // Properties
  4593. ]);
  4594. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4595. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4596. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4597. var self = this;
  4598. return resourcesPromise.then(function(resources) {
  4599. var opList = new OperatorList();
  4600. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4601. return evaluator.getOperatorList(self.appearance, resources, opList).
  4602. then(function () {
  4603. opList.addOp(OPS.endAnnotation, []);
  4604. self.appearance.reset();
  4605. return opList;
  4606. });
  4607. });
  4608. }
  4609. };
  4610. Annotation.getConstructor =
  4611. function Annotation_getConstructor(subtype, fieldType) {
  4612. if (!subtype) {
  4613. return;
  4614. }
  4615. // TODO(mack): Implement FreeText annotations
  4616. if (subtype === 'Link') {
  4617. return LinkAnnotation;
  4618. } else if (subtype === 'Text') {
  4619. return TextAnnotation;
  4620. } else if (subtype === 'Widget') {
  4621. if (!fieldType) {
  4622. return;
  4623. }
  4624. if (fieldType === 'Tx') {
  4625. return TextWidgetAnnotation;
  4626. } else {
  4627. return WidgetAnnotation;
  4628. }
  4629. } else {
  4630. return Annotation;
  4631. }
  4632. };
  4633. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4634. var dict = xref.fetchIfRef(ref);
  4635. if (!isDict(dict)) {
  4636. return;
  4637. }
  4638. var subtype = dict.get('Subtype');
  4639. subtype = isName(subtype) ? subtype.name : '';
  4640. if (!subtype) {
  4641. return;
  4642. }
  4643. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4644. fieldType = isName(fieldType) ? fieldType.name : '';
  4645. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4646. if (!Constructor) {
  4647. return;
  4648. }
  4649. var params = {
  4650. dict: dict,
  4651. ref: ref,
  4652. };
  4653. var annotation = new Constructor(params);
  4654. if (annotation.isViewable() || annotation.isPrintable()) {
  4655. return annotation;
  4656. } else {
  4657. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4658. warn('unimplemented annotation type: ' + subtype);
  4659. }
  4660. }
  4661. };
  4662. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4663. annotations, opList, pdfManager, partialEvaluator, intent) {
  4664. function reject(e) {
  4665. annotationsReadyCapability.reject(e);
  4666. }
  4667. var annotationsReadyCapability = createPromiseCapability();
  4668. var annotationPromises = [];
  4669. for (var i = 0, n = annotations.length; i < n; ++i) {
  4670. if (intent === 'display' && annotations[i].isViewable() ||
  4671. intent === 'print' && annotations[i].isPrintable()) {
  4672. annotationPromises.push(
  4673. annotations[i].getOperatorList(partialEvaluator));
  4674. }
  4675. }
  4676. Promise.all(annotationPromises).then(function(datas) {
  4677. opList.addOp(OPS.beginAnnotations, []);
  4678. for (var i = 0, n = datas.length; i < n; ++i) {
  4679. var annotOpList = datas[i];
  4680. opList.addOpList(annotOpList);
  4681. }
  4682. opList.addOp(OPS.endAnnotations, []);
  4683. annotationsReadyCapability.resolve();
  4684. }, reject);
  4685. return annotationsReadyCapability.promise;
  4686. };
  4687. return Annotation;
  4688. })();
  4689. /**
  4690. * Contains all data regarding an annotation's border style.
  4691. *
  4692. * @class
  4693. */
  4694. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  4695. /**
  4696. * @constructor
  4697. * @private
  4698. */
  4699. function AnnotationBorderStyle() {
  4700. this.width = 1;
  4701. this.style = AnnotationBorderStyleType.SOLID;
  4702. this.dashArray = [3];
  4703. this.horizontalCornerRadius = 0;
  4704. this.verticalCornerRadius = 0;
  4705. }
  4706. AnnotationBorderStyle.prototype = {
  4707. /**
  4708. * Set the width.
  4709. *
  4710. * @public
  4711. * @memberof AnnotationBorderStyle
  4712. * @param {integer} width - The width
  4713. */
  4714. setWidth: function AnnotationBorderStyle_setWidth(width) {
  4715. if (width === (width | 0)) {
  4716. this.width = width;
  4717. }
  4718. },
  4719. /**
  4720. * Set the style.
  4721. *
  4722. * @public
  4723. * @memberof AnnotationBorderStyle
  4724. * @param {Object} style - The style object
  4725. * @see {@link shared/util.js}
  4726. */
  4727. setStyle: function AnnotationBorderStyle_setStyle(style) {
  4728. if (!style) {
  4729. return;
  4730. }
  4731. switch (style.name) {
  4732. case 'S':
  4733. this.style = AnnotationBorderStyleType.SOLID;
  4734. break;
  4735. case 'D':
  4736. this.style = AnnotationBorderStyleType.DASHED;
  4737. break;
  4738. case 'B':
  4739. this.style = AnnotationBorderStyleType.BEVELED;
  4740. break;
  4741. case 'I':
  4742. this.style = AnnotationBorderStyleType.INSET;
  4743. break;
  4744. case 'U':
  4745. this.style = AnnotationBorderStyleType.UNDERLINE;
  4746. break;
  4747. default:
  4748. break;
  4749. }
  4750. },
  4751. /**
  4752. * Set the dash array.
  4753. *
  4754. * @public
  4755. * @memberof AnnotationBorderStyle
  4756. * @param {Array} dashArray - The dash array with at least one element
  4757. */
  4758. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  4759. // We validate the dash array, but we do not use it because CSS does not
  4760. // allow us to change spacing of dashes. For more information, visit
  4761. // http://www.w3.org/TR/css3-background/#the-border-style.
  4762. if (isArray(dashArray) && dashArray.length > 0) {
  4763. // According to the PDF specification: the elements in a dashArray
  4764. // shall be numbers that are nonnegative and not all equal to zero.
  4765. var isValid = true;
  4766. var allZeros = true;
  4767. for (var i = 0, len = dashArray.length; i < len; i++) {
  4768. var element = dashArray[i];
  4769. var validNumber = (+element >= 0);
  4770. if (!validNumber) {
  4771. isValid = false;
  4772. break;
  4773. } else if (element > 0) {
  4774. allZeros = false;
  4775. }
  4776. }
  4777. if (isValid && !allZeros) {
  4778. this.dashArray = dashArray;
  4779. } else {
  4780. this.width = 0; // Adobe behavior when the array is invalid.
  4781. }
  4782. } else if (dashArray) {
  4783. this.width = 0; // Adobe behavior when the array is invalid.
  4784. }
  4785. },
  4786. /**
  4787. * Set the horizontal corner radius (from a Border dictionary).
  4788. *
  4789. * @public
  4790. * @memberof AnnotationBorderStyle
  4791. * @param {integer} radius - The horizontal corner radius
  4792. */
  4793. setHorizontalCornerRadius:
  4794. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  4795. if (radius === (radius | 0)) {
  4796. this.horizontalCornerRadius = radius;
  4797. }
  4798. },
  4799. /**
  4800. * Set the vertical corner radius (from a Border dictionary).
  4801. *
  4802. * @public
  4803. * @memberof AnnotationBorderStyle
  4804. * @param {integer} radius - The vertical corner radius
  4805. */
  4806. setVerticalCornerRadius:
  4807. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  4808. if (radius === (radius | 0)) {
  4809. this.verticalCornerRadius = radius;
  4810. }
  4811. }
  4812. };
  4813. return AnnotationBorderStyle;
  4814. })();
  4815. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4816. function WidgetAnnotation(params) {
  4817. Annotation.call(this, params);
  4818. var dict = params.dict;
  4819. var data = this.data;
  4820. data.fieldValue = stringToPDFString(
  4821. Util.getInheritableProperty(dict, 'V') || '');
  4822. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4823. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4824. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4825. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4826. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4827. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4828. // Building the full field name by collecting the field and
  4829. // its ancestors 'T' data and joining them using '.'.
  4830. var fieldName = [];
  4831. var namedItem = dict;
  4832. var ref = params.ref;
  4833. while (namedItem) {
  4834. var parent = namedItem.get('Parent');
  4835. var parentRef = namedItem.getRaw('Parent');
  4836. var name = namedItem.get('T');
  4837. if (name) {
  4838. fieldName.unshift(stringToPDFString(name));
  4839. } else if (parent && ref) {
  4840. // The field name is absent, that means more than one field
  4841. // with the same name may exist. Replacing the empty name
  4842. // with the '`' plus index in the parent's 'Kids' array.
  4843. // This is not in the PDF spec but necessary to id the
  4844. // the input controls.
  4845. var kids = parent.get('Kids');
  4846. var j, jj;
  4847. for (j = 0, jj = kids.length; j < jj; j++) {
  4848. var kidRef = kids[j];
  4849. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4850. break;
  4851. }
  4852. }
  4853. fieldName.unshift('`' + j);
  4854. }
  4855. namedItem = parent;
  4856. ref = parentRef;
  4857. }
  4858. data.fullName = fieldName.join('.');
  4859. }
  4860. var parent = Annotation.prototype;
  4861. Util.inherit(WidgetAnnotation, Annotation, {
  4862. isViewable: function WidgetAnnotation_isViewable() {
  4863. if (this.data.fieldType === 'Sig') {
  4864. warn('unimplemented annotation type: Widget signature');
  4865. return false;
  4866. }
  4867. return parent.isViewable.call(this);
  4868. }
  4869. });
  4870. return WidgetAnnotation;
  4871. })();
  4872. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4873. function TextWidgetAnnotation(params) {
  4874. WidgetAnnotation.call(this, params);
  4875. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4876. this.data.annotationType = AnnotationType.WIDGET;
  4877. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4878. }
  4879. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4880. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4881. if (this.appearance) {
  4882. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4883. }
  4884. var opList = new OperatorList();
  4885. var data = this.data;
  4886. // Even if there is an appearance stream, ignore it. This is the
  4887. // behaviour used by Adobe Reader.
  4888. if (!data.defaultAppearance) {
  4889. return Promise.resolve(opList);
  4890. }
  4891. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4892. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4893. then(function () {
  4894. return opList;
  4895. });
  4896. }
  4897. });
  4898. return TextWidgetAnnotation;
  4899. })();
  4900. var TextAnnotation = (function TextAnnotationClosure() {
  4901. function TextAnnotation(params) {
  4902. Annotation.call(this, params);
  4903. var dict = params.dict;
  4904. var data = this.data;
  4905. var content = dict.get('Contents');
  4906. var title = dict.get('T');
  4907. data.annotationType = AnnotationType.TEXT;
  4908. data.content = stringToPDFString(content || '');
  4909. data.title = stringToPDFString(title || '');
  4910. data.hasHtml = true;
  4911. if (data.hasAppearance) {
  4912. data.name = 'NoIcon';
  4913. } else {
  4914. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4915. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4916. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4917. }
  4918. if (dict.has('C')) {
  4919. data.hasBgColor = true;
  4920. }
  4921. }
  4922. Util.inherit(TextAnnotation, Annotation, { });
  4923. return TextAnnotation;
  4924. })();
  4925. var LinkAnnotation = (function LinkAnnotationClosure() {
  4926. function LinkAnnotation(params) {
  4927. Annotation.call(this, params);
  4928. var dict = params.dict;
  4929. var data = this.data;
  4930. data.annotationType = AnnotationType.LINK;
  4931. data.hasHtml = true;
  4932. var action = dict.get('A');
  4933. if (action && isDict(action)) {
  4934. var linkType = action.get('S').name;
  4935. if (linkType === 'URI') {
  4936. var url = action.get('URI');
  4937. if (isName(url)) {
  4938. // Some bad PDFs do not put parentheses around relative URLs.
  4939. url = '/' + url.name;
  4940. } else if (url) {
  4941. url = addDefaultProtocolToUrl(url);
  4942. }
  4943. // TODO: pdf spec mentions urls can be relative to a Base
  4944. // entry in the dictionary.
  4945. if (!isValidUrl(url, false)) {
  4946. url = '';
  4947. }
  4948. // According to ISO 32000-1:2008, section 12.6.4.7,
  4949. // URI should to be encoded in 7-bit ASCII.
  4950. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4951. try {
  4952. data.url = stringToUTF8String(url);
  4953. } catch (e) {
  4954. // Fall back to a simple copy.
  4955. data.url = url;
  4956. }
  4957. } else if (linkType === 'GoTo') {
  4958. data.dest = action.get('D');
  4959. } else if (linkType === 'GoToR') {
  4960. var urlDict = action.get('F');
  4961. if (isDict(urlDict)) {
  4962. // We assume that the 'url' is a Filspec dictionary
  4963. // and fetch the url without checking any further
  4964. url = urlDict.get('F') || '';
  4965. }
  4966. // TODO: pdf reference says that GoToR
  4967. // can also have 'NewWindow' attribute
  4968. if (!isValidUrl(url, false)) {
  4969. url = '';
  4970. }
  4971. data.url = url;
  4972. data.dest = action.get('D');
  4973. } else if (linkType === 'Named') {
  4974. data.action = action.get('N').name;
  4975. } else {
  4976. warn('unrecognized link type: ' + linkType);
  4977. }
  4978. } else if (dict.has('Dest')) {
  4979. // simple destination link
  4980. var dest = dict.get('Dest');
  4981. data.dest = isName(dest) ? dest.name : dest;
  4982. }
  4983. }
  4984. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4985. function addDefaultProtocolToUrl(url) {
  4986. if (url && url.indexOf('www.') === 0) {
  4987. return ('http://' + url);
  4988. }
  4989. return url;
  4990. }
  4991. Util.inherit(LinkAnnotation, Annotation, { });
  4992. return LinkAnnotation;
  4993. })();
  4994. var PDFFunction = (function PDFFunctionClosure() {
  4995. var CONSTRUCT_SAMPLED = 0;
  4996. var CONSTRUCT_INTERPOLATED = 2;
  4997. var CONSTRUCT_STICHED = 3;
  4998. var CONSTRUCT_POSTSCRIPT = 4;
  4999. return {
  5000. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  5001. str) {
  5002. var i, ii;
  5003. var length = 1;
  5004. for (i = 0, ii = size.length; i < ii; i++) {
  5005. length *= size[i];
  5006. }
  5007. length *= outputSize;
  5008. var array = new Array(length);
  5009. var codeSize = 0;
  5010. var codeBuf = 0;
  5011. // 32 is a valid bps so shifting won't work
  5012. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  5013. var strBytes = str.getBytes((length * bps + 7) / 8);
  5014. var strIdx = 0;
  5015. for (i = 0; i < length; i++) {
  5016. while (codeSize < bps) {
  5017. codeBuf <<= 8;
  5018. codeBuf |= strBytes[strIdx++];
  5019. codeSize += 8;
  5020. }
  5021. codeSize -= bps;
  5022. array[i] = (codeBuf >> codeSize) * sampleMul;
  5023. codeBuf &= (1 << codeSize) - 1;
  5024. }
  5025. return array;
  5026. },
  5027. getIR: function PDFFunction_getIR(xref, fn) {
  5028. var dict = fn.dict;
  5029. if (!dict) {
  5030. dict = fn;
  5031. }
  5032. var types = [this.constructSampled,
  5033. null,
  5034. this.constructInterpolated,
  5035. this.constructStiched,
  5036. this.constructPostScript];
  5037. var typeNum = dict.get('FunctionType');
  5038. var typeFn = types[typeNum];
  5039. if (!typeFn) {
  5040. error('Unknown type of function');
  5041. }
  5042. return typeFn.call(this, fn, dict, xref);
  5043. },
  5044. fromIR: function PDFFunction_fromIR(IR) {
  5045. var type = IR[0];
  5046. switch (type) {
  5047. case CONSTRUCT_SAMPLED:
  5048. return this.constructSampledFromIR(IR);
  5049. case CONSTRUCT_INTERPOLATED:
  5050. return this.constructInterpolatedFromIR(IR);
  5051. case CONSTRUCT_STICHED:
  5052. return this.constructStichedFromIR(IR);
  5053. //case CONSTRUCT_POSTSCRIPT:
  5054. default:
  5055. return this.constructPostScriptFromIR(IR);
  5056. }
  5057. },
  5058. parse: function PDFFunction_parse(xref, fn) {
  5059. var IR = this.getIR(xref, fn);
  5060. return this.fromIR(IR);
  5061. },
  5062. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  5063. if (!isArray(fnObj)) {
  5064. // not an array -- parsing as regular function
  5065. return this.parse(xref, fnObj);
  5066. }
  5067. var fnArray = [];
  5068. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  5069. var obj = xref.fetchIfRef(fnObj[j]);
  5070. fnArray.push(PDFFunction.parse(xref, obj));
  5071. }
  5072. return function (src, srcOffset, dest, destOffset) {
  5073. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  5074. fnArray[i](src, srcOffset, dest, destOffset + i);
  5075. }
  5076. };
  5077. },
  5078. constructSampled: function PDFFunction_constructSampled(str, dict) {
  5079. function toMultiArray(arr) {
  5080. var inputLength = arr.length;
  5081. var out = [];
  5082. var index = 0;
  5083. for (var i = 0; i < inputLength; i += 2) {
  5084. out[index] = [arr[i], arr[i + 1]];
  5085. ++index;
  5086. }
  5087. return out;
  5088. }
  5089. var domain = dict.get('Domain');
  5090. var range = dict.get('Range');
  5091. if (!domain || !range) {
  5092. error('No domain or range');
  5093. }
  5094. var inputSize = domain.length / 2;
  5095. var outputSize = range.length / 2;
  5096. domain = toMultiArray(domain);
  5097. range = toMultiArray(range);
  5098. var size = dict.get('Size');
  5099. var bps = dict.get('BitsPerSample');
  5100. var order = dict.get('Order') || 1;
  5101. if (order !== 1) {
  5102. // No description how cubic spline interpolation works in PDF32000:2008
  5103. // As in poppler, ignoring order, linear interpolation may work as good
  5104. info('No support for cubic spline interpolation: ' + order);
  5105. }
  5106. var encode = dict.get('Encode');
  5107. if (!encode) {
  5108. encode = [];
  5109. for (var i = 0; i < inputSize; ++i) {
  5110. encode.push(0);
  5111. encode.push(size[i] - 1);
  5112. }
  5113. }
  5114. encode = toMultiArray(encode);
  5115. var decode = dict.get('Decode');
  5116. if (!decode) {
  5117. decode = range;
  5118. } else {
  5119. decode = toMultiArray(decode);
  5120. }
  5121. var samples = this.getSampleArray(size, outputSize, bps, str);
  5122. return [
  5123. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  5124. outputSize, Math.pow(2, bps) - 1, range
  5125. ];
  5126. },
  5127. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  5128. // See chapter 3, page 109 of the PDF reference
  5129. function interpolate(x, xmin, xmax, ymin, ymax) {
  5130. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  5131. }
  5132. return function constructSampledFromIRResult(src, srcOffset,
  5133. dest, destOffset) {
  5134. // See chapter 3, page 110 of the PDF reference.
  5135. var m = IR[1];
  5136. var domain = IR[2];
  5137. var encode = IR[3];
  5138. var decode = IR[4];
  5139. var samples = IR[5];
  5140. var size = IR[6];
  5141. var n = IR[7];
  5142. //var mask = IR[8];
  5143. var range = IR[9];
  5144. // Building the cube vertices: its part and sample index
  5145. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5146. var cubeVertices = 1 << m;
  5147. var cubeN = new Float64Array(cubeVertices);
  5148. var cubeVertex = new Uint32Array(cubeVertices);
  5149. var i, j;
  5150. for (j = 0; j < cubeVertices; j++) {
  5151. cubeN[j] = 1;
  5152. }
  5153. var k = n, pos = 1;
  5154. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5155. for (i = 0; i < m; ++i) {
  5156. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5157. var domain_2i = domain[i][0];
  5158. var domain_2i_1 = domain[i][1];
  5159. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5160. domain_2i_1);
  5161. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5162. // Encode_2i, Encode_2i+1)
  5163. var e = interpolate(xi, domain_2i, domain_2i_1,
  5164. encode[i][0], encode[i][1]);
  5165. // e_i' = min(max(e_i, 0), Size_i - 1)
  5166. var size_i = size[i];
  5167. e = Math.min(Math.max(e, 0), size_i - 1);
  5168. // Adjusting the cube: N and vertex sample index
  5169. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5170. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5171. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5172. var offset0 = e0 * k;
  5173. var offset1 = offset0 + k; // e1 * k
  5174. for (j = 0; j < cubeVertices; j++) {
  5175. if (j & pos) {
  5176. cubeN[j] *= n1;
  5177. cubeVertex[j] += offset1;
  5178. } else {
  5179. cubeN[j] *= n0;
  5180. cubeVertex[j] += offset0;
  5181. }
  5182. }
  5183. k *= size_i;
  5184. pos <<= 1;
  5185. }
  5186. for (j = 0; j < n; ++j) {
  5187. // Sum all cube vertices' samples portions
  5188. var rj = 0;
  5189. for (i = 0; i < cubeVertices; i++) {
  5190. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5191. }
  5192. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5193. // Decode_2j, Decode_2j+1)
  5194. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5195. // y_j = min(max(r_j, range_2j), range_2j+1)
  5196. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5197. range[j][1]);
  5198. }
  5199. };
  5200. },
  5201. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5202. dict) {
  5203. var c0 = dict.get('C0') || [0];
  5204. var c1 = dict.get('C1') || [1];
  5205. var n = dict.get('N');
  5206. if (!isArray(c0) || !isArray(c1)) {
  5207. error('Illegal dictionary for interpolated function');
  5208. }
  5209. var length = c0.length;
  5210. var diff = [];
  5211. for (var i = 0; i < length; ++i) {
  5212. diff.push(c1[i] - c0[i]);
  5213. }
  5214. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5215. },
  5216. constructInterpolatedFromIR:
  5217. function PDFFunction_constructInterpolatedFromIR(IR) {
  5218. var c0 = IR[1];
  5219. var diff = IR[2];
  5220. var n = IR[3];
  5221. var length = diff.length;
  5222. return function constructInterpolatedFromIRResult(src, srcOffset,
  5223. dest, destOffset) {
  5224. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5225. for (var j = 0; j < length; ++j) {
  5226. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5227. }
  5228. };
  5229. },
  5230. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5231. var domain = dict.get('Domain');
  5232. if (!domain) {
  5233. error('No domain');
  5234. }
  5235. var inputSize = domain.length / 2;
  5236. if (inputSize !== 1) {
  5237. error('Bad domain for stiched function');
  5238. }
  5239. var fnRefs = dict.get('Functions');
  5240. var fns = [];
  5241. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5242. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5243. }
  5244. var bounds = dict.get('Bounds');
  5245. var encode = dict.get('Encode');
  5246. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5247. },
  5248. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5249. var domain = IR[1];
  5250. var bounds = IR[2];
  5251. var encode = IR[3];
  5252. var fnsIR = IR[4];
  5253. var fns = [];
  5254. var tmpBuf = new Float32Array(1);
  5255. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5256. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5257. }
  5258. return function constructStichedFromIRResult(src, srcOffset,
  5259. dest, destOffset) {
  5260. var clip = function constructStichedFromIRClip(v, min, max) {
  5261. if (v > max) {
  5262. v = max;
  5263. } else if (v < min) {
  5264. v = min;
  5265. }
  5266. return v;
  5267. };
  5268. // clip to domain
  5269. var v = clip(src[srcOffset], domain[0], domain[1]);
  5270. // calulate which bound the value is in
  5271. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5272. if (v < bounds[i]) {
  5273. break;
  5274. }
  5275. }
  5276. // encode value into domain of function
  5277. var dmin = domain[0];
  5278. if (i > 0) {
  5279. dmin = bounds[i - 1];
  5280. }
  5281. var dmax = domain[1];
  5282. if (i < bounds.length) {
  5283. dmax = bounds[i];
  5284. }
  5285. var rmin = encode[2 * i];
  5286. var rmax = encode[2 * i + 1];
  5287. // Prevent the value from becoming NaN as a result
  5288. // of division by zero (fixes issue6113.pdf).
  5289. tmpBuf[0] = dmin === dmax ? rmin :
  5290. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5291. // call the appropriate function
  5292. fns[i](tmpBuf, 0, dest, destOffset);
  5293. };
  5294. },
  5295. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5296. xref) {
  5297. var domain = dict.get('Domain');
  5298. var range = dict.get('Range');
  5299. if (!domain) {
  5300. error('No domain.');
  5301. }
  5302. if (!range) {
  5303. error('No range.');
  5304. }
  5305. var lexer = new PostScriptLexer(fn);
  5306. var parser = new PostScriptParser(lexer);
  5307. var code = parser.parse();
  5308. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5309. },
  5310. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5311. IR) {
  5312. var domain = IR[1];
  5313. var range = IR[2];
  5314. var code = IR[3];
  5315. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5316. if (compiled) {
  5317. // Compiled function consists of simple expressions such as addition,
  5318. // subtraction, Math.max, and also contains 'var' and 'return'
  5319. // statements. See the generation in the PostScriptCompiler below.
  5320. /*jshint -W054 */
  5321. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5322. }
  5323. info('Unable to compile PS function');
  5324. var numOutputs = range.length >> 1;
  5325. var numInputs = domain.length >> 1;
  5326. var evaluator = new PostScriptEvaluator(code);
  5327. // Cache the values for a big speed up, the cache size is limited though
  5328. // since the number of possible values can be huge from a PS function.
  5329. var cache = {};
  5330. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5331. // seen in our tests.
  5332. var MAX_CACHE_SIZE = 2048 * 4;
  5333. var cache_available = MAX_CACHE_SIZE;
  5334. var tmpBuf = new Float32Array(numInputs);
  5335. return function constructPostScriptFromIRResult(src, srcOffset,
  5336. dest, destOffset) {
  5337. var i, value;
  5338. var key = '';
  5339. var input = tmpBuf;
  5340. for (i = 0; i < numInputs; i++) {
  5341. value = src[srcOffset + i];
  5342. input[i] = value;
  5343. key += value + '_';
  5344. }
  5345. var cachedValue = cache[key];
  5346. if (cachedValue !== undefined) {
  5347. dest.set(cachedValue, destOffset);
  5348. return;
  5349. }
  5350. var output = new Float32Array(numOutputs);
  5351. var stack = evaluator.execute(input);
  5352. var stackIndex = stack.length - numOutputs;
  5353. for (i = 0; i < numOutputs; i++) {
  5354. value = stack[stackIndex + i];
  5355. var bound = range[i * 2];
  5356. if (value < bound) {
  5357. value = bound;
  5358. } else {
  5359. bound = range[i * 2 +1];
  5360. if (value > bound) {
  5361. value = bound;
  5362. }
  5363. }
  5364. output[i] = value;
  5365. }
  5366. if (cache_available > 0) {
  5367. cache_available--;
  5368. cache[key] = output;
  5369. }
  5370. dest.set(output, destOffset);
  5371. };
  5372. }
  5373. };
  5374. })();
  5375. function isPDFFunction(v) {
  5376. var fnDict;
  5377. if (typeof v !== 'object') {
  5378. return false;
  5379. } else if (isDict(v)) {
  5380. fnDict = v;
  5381. } else if (isStream(v)) {
  5382. fnDict = v.dict;
  5383. } else {
  5384. return false;
  5385. }
  5386. return fnDict.has('FunctionType');
  5387. }
  5388. var PostScriptStack = (function PostScriptStackClosure() {
  5389. var MAX_STACK_SIZE = 100;
  5390. function PostScriptStack(initialStack) {
  5391. this.stack = !initialStack ? [] :
  5392. Array.prototype.slice.call(initialStack, 0);
  5393. }
  5394. PostScriptStack.prototype = {
  5395. push: function PostScriptStack_push(value) {
  5396. if (this.stack.length >= MAX_STACK_SIZE) {
  5397. error('PostScript function stack overflow.');
  5398. }
  5399. this.stack.push(value);
  5400. },
  5401. pop: function PostScriptStack_pop() {
  5402. if (this.stack.length <= 0) {
  5403. error('PostScript function stack underflow.');
  5404. }
  5405. return this.stack.pop();
  5406. },
  5407. copy: function PostScriptStack_copy(n) {
  5408. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5409. error('PostScript function stack overflow.');
  5410. }
  5411. var stack = this.stack;
  5412. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5413. stack.push(stack[i]);
  5414. }
  5415. },
  5416. index: function PostScriptStack_index(n) {
  5417. this.push(this.stack[this.stack.length - n - 1]);
  5418. },
  5419. // rotate the last n stack elements p times
  5420. roll: function PostScriptStack_roll(n, p) {
  5421. var stack = this.stack;
  5422. var l = stack.length - n;
  5423. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5424. for (i = l, j = r; i < j; i++, j--) {
  5425. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5426. }
  5427. for (i = l, j = c - 1; i < j; i++, j--) {
  5428. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5429. }
  5430. for (i = c, j = r; i < j; i++, j--) {
  5431. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5432. }
  5433. }
  5434. };
  5435. return PostScriptStack;
  5436. })();
  5437. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5438. function PostScriptEvaluator(operators) {
  5439. this.operators = operators;
  5440. }
  5441. PostScriptEvaluator.prototype = {
  5442. execute: function PostScriptEvaluator_execute(initialStack) {
  5443. var stack = new PostScriptStack(initialStack);
  5444. var counter = 0;
  5445. var operators = this.operators;
  5446. var length = operators.length;
  5447. var operator, a, b;
  5448. while (counter < length) {
  5449. operator = operators[counter++];
  5450. if (typeof operator === 'number') {
  5451. // Operator is really an operand and should be pushed to the stack.
  5452. stack.push(operator);
  5453. continue;
  5454. }
  5455. switch (operator) {
  5456. // non standard ps operators
  5457. case 'jz': // jump if false
  5458. b = stack.pop();
  5459. a = stack.pop();
  5460. if (!a) {
  5461. counter = b;
  5462. }
  5463. break;
  5464. case 'j': // jump
  5465. a = stack.pop();
  5466. counter = a;
  5467. break;
  5468. // all ps operators in alphabetical order (excluding if/ifelse)
  5469. case 'abs':
  5470. a = stack.pop();
  5471. stack.push(Math.abs(a));
  5472. break;
  5473. case 'add':
  5474. b = stack.pop();
  5475. a = stack.pop();
  5476. stack.push(a + b);
  5477. break;
  5478. case 'and':
  5479. b = stack.pop();
  5480. a = stack.pop();
  5481. if (isBool(a) && isBool(b)) {
  5482. stack.push(a && b);
  5483. } else {
  5484. stack.push(a & b);
  5485. }
  5486. break;
  5487. case 'atan':
  5488. a = stack.pop();
  5489. stack.push(Math.atan(a));
  5490. break;
  5491. case 'bitshift':
  5492. b = stack.pop();
  5493. a = stack.pop();
  5494. if (a > 0) {
  5495. stack.push(a << b);
  5496. } else {
  5497. stack.push(a >> b);
  5498. }
  5499. break;
  5500. case 'ceiling':
  5501. a = stack.pop();
  5502. stack.push(Math.ceil(a));
  5503. break;
  5504. case 'copy':
  5505. a = stack.pop();
  5506. stack.copy(a);
  5507. break;
  5508. case 'cos':
  5509. a = stack.pop();
  5510. stack.push(Math.cos(a));
  5511. break;
  5512. case 'cvi':
  5513. a = stack.pop() | 0;
  5514. stack.push(a);
  5515. break;
  5516. case 'cvr':
  5517. // noop
  5518. break;
  5519. case 'div':
  5520. b = stack.pop();
  5521. a = stack.pop();
  5522. stack.push(a / b);
  5523. break;
  5524. case 'dup':
  5525. stack.copy(1);
  5526. break;
  5527. case 'eq':
  5528. b = stack.pop();
  5529. a = stack.pop();
  5530. stack.push(a === b);
  5531. break;
  5532. case 'exch':
  5533. stack.roll(2, 1);
  5534. break;
  5535. case 'exp':
  5536. b = stack.pop();
  5537. a = stack.pop();
  5538. stack.push(Math.pow(a, b));
  5539. break;
  5540. case 'false':
  5541. stack.push(false);
  5542. break;
  5543. case 'floor':
  5544. a = stack.pop();
  5545. stack.push(Math.floor(a));
  5546. break;
  5547. case 'ge':
  5548. b = stack.pop();
  5549. a = stack.pop();
  5550. stack.push(a >= b);
  5551. break;
  5552. case 'gt':
  5553. b = stack.pop();
  5554. a = stack.pop();
  5555. stack.push(a > b);
  5556. break;
  5557. case 'idiv':
  5558. b = stack.pop();
  5559. a = stack.pop();
  5560. stack.push((a / b) | 0);
  5561. break;
  5562. case 'index':
  5563. a = stack.pop();
  5564. stack.index(a);
  5565. break;
  5566. case 'le':
  5567. b = stack.pop();
  5568. a = stack.pop();
  5569. stack.push(a <= b);
  5570. break;
  5571. case 'ln':
  5572. a = stack.pop();
  5573. stack.push(Math.log(a));
  5574. break;
  5575. case 'log':
  5576. a = stack.pop();
  5577. stack.push(Math.log(a) / Math.LN10);
  5578. break;
  5579. case 'lt':
  5580. b = stack.pop();
  5581. a = stack.pop();
  5582. stack.push(a < b);
  5583. break;
  5584. case 'mod':
  5585. b = stack.pop();
  5586. a = stack.pop();
  5587. stack.push(a % b);
  5588. break;
  5589. case 'mul':
  5590. b = stack.pop();
  5591. a = stack.pop();
  5592. stack.push(a * b);
  5593. break;
  5594. case 'ne':
  5595. b = stack.pop();
  5596. a = stack.pop();
  5597. stack.push(a !== b);
  5598. break;
  5599. case 'neg':
  5600. a = stack.pop();
  5601. stack.push(-a);
  5602. break;
  5603. case 'not':
  5604. a = stack.pop();
  5605. if (isBool(a)) {
  5606. stack.push(!a);
  5607. } else {
  5608. stack.push(~a);
  5609. }
  5610. break;
  5611. case 'or':
  5612. b = stack.pop();
  5613. a = stack.pop();
  5614. if (isBool(a) && isBool(b)) {
  5615. stack.push(a || b);
  5616. } else {
  5617. stack.push(a | b);
  5618. }
  5619. break;
  5620. case 'pop':
  5621. stack.pop();
  5622. break;
  5623. case 'roll':
  5624. b = stack.pop();
  5625. a = stack.pop();
  5626. stack.roll(a, b);
  5627. break;
  5628. case 'round':
  5629. a = stack.pop();
  5630. stack.push(Math.round(a));
  5631. break;
  5632. case 'sin':
  5633. a = stack.pop();
  5634. stack.push(Math.sin(a));
  5635. break;
  5636. case 'sqrt':
  5637. a = stack.pop();
  5638. stack.push(Math.sqrt(a));
  5639. break;
  5640. case 'sub':
  5641. b = stack.pop();
  5642. a = stack.pop();
  5643. stack.push(a - b);
  5644. break;
  5645. case 'true':
  5646. stack.push(true);
  5647. break;
  5648. case 'truncate':
  5649. a = stack.pop();
  5650. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5651. stack.push(a);
  5652. break;
  5653. case 'xor':
  5654. b = stack.pop();
  5655. a = stack.pop();
  5656. if (isBool(a) && isBool(b)) {
  5657. stack.push(a !== b);
  5658. } else {
  5659. stack.push(a ^ b);
  5660. }
  5661. break;
  5662. default:
  5663. error('Unknown operator ' + operator);
  5664. break;
  5665. }
  5666. }
  5667. return stack.stack;
  5668. }
  5669. };
  5670. return PostScriptEvaluator;
  5671. })();
  5672. // Most of the PDFs functions consist of simple operations such as:
  5673. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5674. //
  5675. // We can compile most of such programs, and at the same moment, we can
  5676. // optimize some expressions using basic math properties. Keeping track of
  5677. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5678. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5679. function AstNode(type) {
  5680. this.type = type;
  5681. }
  5682. AstNode.prototype.visit = function (visitor) {
  5683. throw new Error('abstract method');
  5684. };
  5685. function AstArgument(index, min, max) {
  5686. AstNode.call(this, 'args');
  5687. this.index = index;
  5688. this.min = min;
  5689. this.max = max;
  5690. }
  5691. AstArgument.prototype = Object.create(AstNode.prototype);
  5692. AstArgument.prototype.visit = function (visitor) {
  5693. visitor.visitArgument(this);
  5694. };
  5695. function AstLiteral(number) {
  5696. AstNode.call(this, 'literal');
  5697. this.number = number;
  5698. this.min = number;
  5699. this.max = number;
  5700. }
  5701. AstLiteral.prototype = Object.create(AstNode.prototype);
  5702. AstLiteral.prototype.visit = function (visitor) {
  5703. visitor.visitLiteral(this);
  5704. };
  5705. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5706. AstNode.call(this, 'binary');
  5707. this.op = op;
  5708. this.arg1 = arg1;
  5709. this.arg2 = arg2;
  5710. this.min = min;
  5711. this.max = max;
  5712. }
  5713. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5714. AstBinaryOperation.prototype.visit = function (visitor) {
  5715. visitor.visitBinaryOperation(this);
  5716. };
  5717. function AstMin(arg, max) {
  5718. AstNode.call(this, 'max');
  5719. this.arg = arg;
  5720. this.min = arg.min;
  5721. this.max = max;
  5722. }
  5723. AstMin.prototype = Object.create(AstNode.prototype);
  5724. AstMin.prototype.visit = function (visitor) {
  5725. visitor.visitMin(this);
  5726. };
  5727. function AstVariable(index, min, max) {
  5728. AstNode.call(this, 'var');
  5729. this.index = index;
  5730. this.min = min;
  5731. this.max = max;
  5732. }
  5733. AstVariable.prototype = Object.create(AstNode.prototype);
  5734. AstVariable.prototype.visit = function (visitor) {
  5735. visitor.visitVariable(this);
  5736. };
  5737. function AstVariableDefinition(variable, arg) {
  5738. AstNode.call(this, 'definition');
  5739. this.variable = variable;
  5740. this.arg = arg;
  5741. }
  5742. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5743. AstVariableDefinition.prototype.visit = function (visitor) {
  5744. visitor.visitVariableDefinition(this);
  5745. };
  5746. function ExpressionBuilderVisitor() {
  5747. this.parts = [];
  5748. }
  5749. ExpressionBuilderVisitor.prototype = {
  5750. visitArgument: function (arg) {
  5751. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5752. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5753. },
  5754. visitVariable: function (variable) {
  5755. this.parts.push('v', variable.index);
  5756. },
  5757. visitLiteral: function (literal) {
  5758. this.parts.push(literal.number);
  5759. },
  5760. visitBinaryOperation: function (operation) {
  5761. this.parts.push('(');
  5762. operation.arg1.visit(this);
  5763. this.parts.push(' ', operation.op, ' ');
  5764. operation.arg2.visit(this);
  5765. this.parts.push(')');
  5766. },
  5767. visitVariableDefinition: function (definition) {
  5768. this.parts.push('var ');
  5769. definition.variable.visit(this);
  5770. this.parts.push(' = ');
  5771. definition.arg.visit(this);
  5772. this.parts.push(';');
  5773. },
  5774. visitMin: function (max) {
  5775. this.parts.push('Math.min(');
  5776. max.arg.visit(this);
  5777. this.parts.push(', ', max.max, ')');
  5778. },
  5779. toString: function () {
  5780. return this.parts.join('');
  5781. }
  5782. };
  5783. function buildAddOperation(num1, num2) {
  5784. if (num2.type === 'literal' && num2.number === 0) {
  5785. // optimization: second operand is 0
  5786. return num1;
  5787. }
  5788. if (num1.type === 'literal' && num1.number === 0) {
  5789. // optimization: first operand is 0
  5790. return num2;
  5791. }
  5792. if (num2.type === 'literal' && num1.type === 'literal') {
  5793. // optimization: operands operand are literals
  5794. return new AstLiteral(num1.number + num2.number);
  5795. }
  5796. return new AstBinaryOperation('+', num1, num2,
  5797. num1.min + num2.min, num1.max + num2.max);
  5798. }
  5799. function buildMulOperation(num1, num2) {
  5800. if (num2.type === 'literal') {
  5801. // optimization: second operands is a literal...
  5802. if (num2.number === 0) {
  5803. return new AstLiteral(0); // and it's 0
  5804. } else if (num2.number === 1) {
  5805. return num1; // and it's 1
  5806. } else if (num1.type === 'literal') {
  5807. // ... and first operands is a literal too
  5808. return new AstLiteral(num1.number * num2.number);
  5809. }
  5810. }
  5811. if (num1.type === 'literal') {
  5812. // optimization: first operands is a literal...
  5813. if (num1.number === 0) {
  5814. return new AstLiteral(0); // and it's 0
  5815. } else if (num1.number === 1) {
  5816. return num2; // and it's 1
  5817. }
  5818. }
  5819. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5820. num1.max * num2.min, num1.max * num2.max);
  5821. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5822. num1.max * num2.min, num1.max * num2.max);
  5823. return new AstBinaryOperation('*', num1, num2, min, max);
  5824. }
  5825. function buildSubOperation(num1, num2) {
  5826. if (num2.type === 'literal') {
  5827. // optimization: second operands is a literal...
  5828. if (num2.number === 0) {
  5829. return num1; // ... and it's 0
  5830. } else if (num1.type === 'literal') {
  5831. // ... and first operands is a literal too
  5832. return new AstLiteral(num1.number - num2.number);
  5833. }
  5834. }
  5835. if (num2.type === 'binary' && num2.op === '-' &&
  5836. num1.type === 'literal' && num1.number === 1 &&
  5837. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5838. // optimization for case: 1 - (1 - x)
  5839. return num2.arg2;
  5840. }
  5841. return new AstBinaryOperation('-', num1, num2,
  5842. num1.min - num2.max, num1.max - num2.min);
  5843. }
  5844. function buildMinOperation(num1, max) {
  5845. if (num1.min >= max) {
  5846. // optimization: num1 min value is not less than required max
  5847. return new AstLiteral(max); // just returning max
  5848. } else if (num1.max <= max) {
  5849. // optimization: num1 max value is not greater than required max
  5850. return num1; // just returning an argument
  5851. }
  5852. return new AstMin(num1, max);
  5853. }
  5854. function PostScriptCompiler() {}
  5855. PostScriptCompiler.prototype = {
  5856. compile: function PostScriptCompiler_compile(code, domain, range) {
  5857. var stack = [];
  5858. var i, ii;
  5859. var instructions = [];
  5860. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5861. var lastRegister = 0;
  5862. var n, j, min, max;
  5863. var num1, num2, ast1, ast2, tmpVar, item;
  5864. for (i = 0; i < inputSize; i++) {
  5865. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5866. }
  5867. for (i = 0, ii = code.length; i < ii; i++) {
  5868. item = code[i];
  5869. if (typeof item === 'number') {
  5870. stack.push(new AstLiteral(item));
  5871. continue;
  5872. }
  5873. switch (item) {
  5874. case 'add':
  5875. if (stack.length < 2) {
  5876. return null;
  5877. }
  5878. num2 = stack.pop();
  5879. num1 = stack.pop();
  5880. stack.push(buildAddOperation(num1, num2));
  5881. break;
  5882. case 'cvr':
  5883. if (stack.length < 1) {
  5884. return null;
  5885. }
  5886. break;
  5887. case 'mul':
  5888. if (stack.length < 2) {
  5889. return null;
  5890. }
  5891. num2 = stack.pop();
  5892. num1 = stack.pop();
  5893. stack.push(buildMulOperation(num1, num2));
  5894. break;
  5895. case 'sub':
  5896. if (stack.length < 2) {
  5897. return null;
  5898. }
  5899. num2 = stack.pop();
  5900. num1 = stack.pop();
  5901. stack.push(buildSubOperation(num1, num2));
  5902. break;
  5903. case 'exch':
  5904. if (stack.length < 2) {
  5905. return null;
  5906. }
  5907. ast1 = stack.pop(); ast2 = stack.pop();
  5908. stack.push(ast1, ast2);
  5909. break;
  5910. case 'pop':
  5911. if (stack.length < 1) {
  5912. return null;
  5913. }
  5914. stack.pop();
  5915. break;
  5916. case 'index':
  5917. if (stack.length < 1) {
  5918. return null;
  5919. }
  5920. num1 = stack.pop();
  5921. if (num1.type !== 'literal') {
  5922. return null;
  5923. }
  5924. n = num1.number;
  5925. if (n < 0 || (n|0) !== n || stack.length < n) {
  5926. return null;
  5927. }
  5928. ast1 = stack[stack.length - n - 1];
  5929. if (ast1.type === 'literal' || ast1.type === 'var') {
  5930. stack.push(ast1);
  5931. break;
  5932. }
  5933. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5934. stack[stack.length - n - 1] = tmpVar;
  5935. stack.push(tmpVar);
  5936. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5937. break;
  5938. case 'dup':
  5939. if (stack.length < 1) {
  5940. return null;
  5941. }
  5942. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5943. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5944. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5945. // special case of the commands sequence for the min operation
  5946. num1 = stack.pop();
  5947. stack.push(buildMinOperation(num1, code[i + 1]));
  5948. i += 6;
  5949. break;
  5950. }
  5951. ast1 = stack[stack.length - 1];
  5952. if (ast1.type === 'literal' || ast1.type === 'var') {
  5953. // we don't have to save into intermediate variable a literal or
  5954. // variable.
  5955. stack.push(ast1);
  5956. break;
  5957. }
  5958. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5959. stack[stack.length - 1] = tmpVar;
  5960. stack.push(tmpVar);
  5961. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5962. break;
  5963. case 'roll':
  5964. if (stack.length < 2) {
  5965. return null;
  5966. }
  5967. num2 = stack.pop();
  5968. num1 = stack.pop();
  5969. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5970. // both roll operands must be numbers
  5971. return null;
  5972. }
  5973. j = num2.number;
  5974. n = num1.number;
  5975. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5976. // ... and integers
  5977. return null;
  5978. }
  5979. j = ((j % n) + n) % n;
  5980. if (j === 0) {
  5981. break; // just skipping -- there are nothing to rotate
  5982. }
  5983. Array.prototype.push.apply(stack,
  5984. stack.splice(stack.length - n, n - j));
  5985. break;
  5986. default:
  5987. return null; // unsupported operator
  5988. }
  5989. }
  5990. if (stack.length !== outputSize) {
  5991. return null;
  5992. }
  5993. var result = [];
  5994. instructions.forEach(function (instruction) {
  5995. var statementBuilder = new ExpressionBuilderVisitor();
  5996. instruction.visit(statementBuilder);
  5997. result.push(statementBuilder.toString());
  5998. });
  5999. stack.forEach(function (expr, i) {
  6000. var statementBuilder = new ExpressionBuilderVisitor();
  6001. expr.visit(statementBuilder);
  6002. var min = range[i * 2], max = range[i * 2 + 1];
  6003. var out = [statementBuilder.toString()];
  6004. if (min > expr.min) {
  6005. out.unshift('Math.max(', min, ', ');
  6006. out.push(')');
  6007. }
  6008. if (max < expr.max) {
  6009. out.unshift('Math.min(', max, ', ');
  6010. out.push(')');
  6011. }
  6012. out.unshift('dest[destOffset + ', i, '] = ');
  6013. out.push(';');
  6014. result.push(out.join(''));
  6015. });
  6016. return result.join('\n');
  6017. }
  6018. };
  6019. return PostScriptCompiler;
  6020. })();
  6021. var ColorSpace = (function ColorSpaceClosure() {
  6022. // Constructor should define this.numComps, this.defaultColor, this.name
  6023. function ColorSpace() {
  6024. error('should not call ColorSpace constructor');
  6025. }
  6026. ColorSpace.prototype = {
  6027. /**
  6028. * Converts the color value to the RGB color. The color components are
  6029. * located in the src array starting from the srcOffset. Returns the array
  6030. * of the rgb components, each value ranging from [0,255].
  6031. */
  6032. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  6033. var rgb = new Uint8Array(3);
  6034. this.getRgbItem(src, srcOffset, rgb, 0);
  6035. return rgb;
  6036. },
  6037. /**
  6038. * Converts the color value to the RGB color, similar to the getRgb method.
  6039. * The result placed into the dest array starting from the destOffset.
  6040. */
  6041. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  6042. dest, destOffset) {
  6043. error('Should not call ColorSpace.getRgbItem');
  6044. },
  6045. /**
  6046. * Converts the specified number of the color values to the RGB colors.
  6047. * The colors are located in the src array starting from the srcOffset.
  6048. * The result is placed into the dest array starting from the destOffset.
  6049. * The src array items shall be in [0,2^bits) range, the dest array items
  6050. * will be in [0,255] range. alpha01 indicates how many alpha components
  6051. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  6052. * array).
  6053. */
  6054. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  6055. dest, destOffset, bits,
  6056. alpha01) {
  6057. error('Should not call ColorSpace.getRgbBuffer');
  6058. },
  6059. /**
  6060. * Determines the number of bytes required to store the result of the
  6061. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  6062. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  6063. */
  6064. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  6065. alpha01) {
  6066. error('Should not call ColorSpace.getOutputLength');
  6067. },
  6068. /**
  6069. * Returns true if source data will be equal the result/output data.
  6070. */
  6071. isPassthrough: function ColorSpace_isPassthrough(bits) {
  6072. return false;
  6073. },
  6074. /**
  6075. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  6076. * how many alpha components there are in the dest array; it will be either
  6077. * 0 (RGB array) or 1 (RGBA array).
  6078. */
  6079. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  6080. originalHeight, width, height,
  6081. actualHeight, bpc, comps, alpha01) {
  6082. var count = originalWidth * originalHeight;
  6083. var rgbBuf = null;
  6084. var numComponentColors = 1 << bpc;
  6085. var needsResizing = originalHeight !== height || originalWidth !== width;
  6086. var i, ii;
  6087. if (this.isPassthrough(bpc)) {
  6088. rgbBuf = comps;
  6089. } else if (this.numComps === 1 && count > numComponentColors &&
  6090. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  6091. // Optimization: create a color map when there is just one component and
  6092. // we are converting more colors than the size of the color map. We
  6093. // don't build the map if the colorspace is gray or rgb since those
  6094. // methods are faster than building a map. This mainly offers big speed
  6095. // ups for indexed and alternate colorspaces.
  6096. //
  6097. // TODO it may be worth while to cache the color map. While running
  6098. // testing I never hit a cache so I will leave that out for now (perhaps
  6099. // we are reparsing colorspaces too much?).
  6100. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  6101. new Uint16Array(numComponentColors);
  6102. var key;
  6103. for (i = 0; i < numComponentColors; i++) {
  6104. allColors[i] = i;
  6105. }
  6106. var colorMap = new Uint8Array(numComponentColors * 3);
  6107. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  6108. /* alpha01 = */ 0);
  6109. var destPos, rgbPos;
  6110. if (!needsResizing) {
  6111. // Fill in the RGB values directly into |dest|.
  6112. destPos = 0;
  6113. for (i = 0; i < count; ++i) {
  6114. key = comps[i] * 3;
  6115. dest[destPos++] = colorMap[key];
  6116. dest[destPos++] = colorMap[key + 1];
  6117. dest[destPos++] = colorMap[key + 2];
  6118. destPos += alpha01;
  6119. }
  6120. } else {
  6121. rgbBuf = new Uint8Array(count * 3);
  6122. rgbPos = 0;
  6123. for (i = 0; i < count; ++i) {
  6124. key = comps[i] * 3;
  6125. rgbBuf[rgbPos++] = colorMap[key];
  6126. rgbBuf[rgbPos++] = colorMap[key + 1];
  6127. rgbBuf[rgbPos++] = colorMap[key + 2];
  6128. }
  6129. }
  6130. } else {
  6131. if (!needsResizing) {
  6132. // Fill in the RGB values directly into |dest|.
  6133. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  6134. alpha01);
  6135. } else {
  6136. rgbBuf = new Uint8Array(count * 3);
  6137. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  6138. /* alpha01 = */ 0);
  6139. }
  6140. }
  6141. if (rgbBuf) {
  6142. if (needsResizing) {
  6143. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  6144. height, dest, alpha01);
  6145. } else {
  6146. rgbPos = 0;
  6147. destPos = 0;
  6148. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6149. dest[destPos++] = rgbBuf[rgbPos++];
  6150. dest[destPos++] = rgbBuf[rgbPos++];
  6151. dest[destPos++] = rgbBuf[rgbPos++];
  6152. destPos += alpha01;
  6153. }
  6154. }
  6155. }
  6156. },
  6157. /**
  6158. * True if the colorspace has components in the default range of [0, 1].
  6159. * This should be true for all colorspaces except for lab color spaces
  6160. * which are [0,100], [-128, 127], [-128, 127].
  6161. */
  6162. usesZeroToOneRange: true
  6163. };
  6164. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6165. var IR = ColorSpace.parseToIR(cs, xref, res);
  6166. if (IR instanceof AlternateCS) {
  6167. return IR;
  6168. }
  6169. return ColorSpace.fromIR(IR);
  6170. };
  6171. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6172. var name = isArray(IR) ? IR[0] : IR;
  6173. var whitePoint, blackPoint, gamma;
  6174. switch (name) {
  6175. case 'DeviceGrayCS':
  6176. return this.singletons.gray;
  6177. case 'DeviceRgbCS':
  6178. return this.singletons.rgb;
  6179. case 'DeviceCmykCS':
  6180. return this.singletons.cmyk;
  6181. case 'CalGrayCS':
  6182. whitePoint = IR[1].WhitePoint;
  6183. blackPoint = IR[1].BlackPoint;
  6184. gamma = IR[1].Gamma;
  6185. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6186. case 'CalRGBCS':
  6187. whitePoint = IR[1].WhitePoint;
  6188. blackPoint = IR[1].BlackPoint;
  6189. gamma = IR[1].Gamma;
  6190. var matrix = IR[1].Matrix;
  6191. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6192. case 'PatternCS':
  6193. var basePatternCS = IR[1];
  6194. if (basePatternCS) {
  6195. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6196. }
  6197. return new PatternCS(basePatternCS);
  6198. case 'IndexedCS':
  6199. var baseIndexedCS = IR[1];
  6200. var hiVal = IR[2];
  6201. var lookup = IR[3];
  6202. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6203. case 'AlternateCS':
  6204. var numComps = IR[1];
  6205. var alt = IR[2];
  6206. var tintFnIR = IR[3];
  6207. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6208. PDFFunction.fromIR(tintFnIR));
  6209. case 'LabCS':
  6210. whitePoint = IR[1].WhitePoint;
  6211. blackPoint = IR[1].BlackPoint;
  6212. var range = IR[1].Range;
  6213. return new LabCS(whitePoint, blackPoint, range);
  6214. default:
  6215. error('Unknown name ' + name);
  6216. }
  6217. return null;
  6218. };
  6219. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6220. if (isName(cs)) {
  6221. var colorSpaces = res.get('ColorSpace');
  6222. if (isDict(colorSpaces)) {
  6223. var refcs = colorSpaces.get(cs.name);
  6224. if (refcs) {
  6225. cs = refcs;
  6226. }
  6227. }
  6228. }
  6229. cs = xref.fetchIfRef(cs);
  6230. var mode;
  6231. if (isName(cs)) {
  6232. mode = cs.name;
  6233. this.mode = mode;
  6234. switch (mode) {
  6235. case 'DeviceGray':
  6236. case 'G':
  6237. return 'DeviceGrayCS';
  6238. case 'DeviceRGB':
  6239. case 'RGB':
  6240. return 'DeviceRgbCS';
  6241. case 'DeviceCMYK':
  6242. case 'CMYK':
  6243. return 'DeviceCmykCS';
  6244. case 'Pattern':
  6245. return ['PatternCS', null];
  6246. default:
  6247. error('unrecognized colorspace ' + mode);
  6248. }
  6249. } else if (isArray(cs)) {
  6250. mode = xref.fetchIfRef(cs[0]).name;
  6251. this.mode = mode;
  6252. var numComps, params, alt;
  6253. switch (mode) {
  6254. case 'DeviceGray':
  6255. case 'G':
  6256. return 'DeviceGrayCS';
  6257. case 'DeviceRGB':
  6258. case 'RGB':
  6259. return 'DeviceRgbCS';
  6260. case 'DeviceCMYK':
  6261. case 'CMYK':
  6262. return 'DeviceCmykCS';
  6263. case 'CalGray':
  6264. params = xref.fetchIfRef(cs[1]).getAll();
  6265. return ['CalGrayCS', params];
  6266. case 'CalRGB':
  6267. params = xref.fetchIfRef(cs[1]).getAll();
  6268. return ['CalRGBCS', params];
  6269. case 'ICCBased':
  6270. var stream = xref.fetchIfRef(cs[1]);
  6271. var dict = stream.dict;
  6272. numComps = dict.get('N');
  6273. alt = dict.get('Alternate');
  6274. if (alt) {
  6275. var altIR = ColorSpace.parseToIR(alt, xref, res);
  6276. // Parse the /Alternate CS to ensure that the number of components
  6277. // are correct, and also (indirectly) that it is not a PatternCS.
  6278. var altCS = ColorSpace.fromIR(altIR);
  6279. if (altCS.numComps === numComps) {
  6280. return altIR;
  6281. }
  6282. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  6283. }
  6284. if (numComps === 1) {
  6285. return 'DeviceGrayCS';
  6286. } else if (numComps === 3) {
  6287. return 'DeviceRgbCS';
  6288. } else if (numComps === 4) {
  6289. return 'DeviceCmykCS';
  6290. }
  6291. break;
  6292. case 'Pattern':
  6293. var basePatternCS = cs[1] || null;
  6294. if (basePatternCS) {
  6295. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6296. }
  6297. return ['PatternCS', basePatternCS];
  6298. case 'Indexed':
  6299. case 'I':
  6300. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6301. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  6302. var lookup = xref.fetchIfRef(cs[3]);
  6303. if (isStream(lookup)) {
  6304. lookup = lookup.getBytes();
  6305. }
  6306. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6307. case 'Separation':
  6308. case 'DeviceN':
  6309. var name = xref.fetchIfRef(cs[1]);
  6310. numComps = 1;
  6311. if (isName(name)) {
  6312. numComps = 1;
  6313. } else if (isArray(name)) {
  6314. numComps = name.length;
  6315. }
  6316. alt = ColorSpace.parseToIR(cs[2], xref, res);
  6317. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6318. return ['AlternateCS', numComps, alt, tintFnIR];
  6319. case 'Lab':
  6320. params = xref.fetchIfRef(cs[1]).getAll();
  6321. return ['LabCS', params];
  6322. default:
  6323. error('unimplemented color space object "' + mode + '"');
  6324. }
  6325. } else {
  6326. error('unrecognized color space object: "' + cs + '"');
  6327. }
  6328. return null;
  6329. };
  6330. /**
  6331. * Checks if a decode map matches the default decode map for a color space.
  6332. * This handles the general decode maps where there are two values per
  6333. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6334. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6335. * slightly different.
  6336. * @param {Array} decode Decode map (usually from an image).
  6337. * @param {Number} n Number of components the color space has.
  6338. */
  6339. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6340. if (!decode) {
  6341. return true;
  6342. }
  6343. if (n * 2 !== decode.length) {
  6344. warn('The decode map is not the correct length');
  6345. return true;
  6346. }
  6347. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6348. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6349. return false;
  6350. }
  6351. }
  6352. return true;
  6353. };
  6354. ColorSpace.singletons = {
  6355. get gray() {
  6356. return shadow(this, 'gray', new DeviceGrayCS());
  6357. },
  6358. get rgb() {
  6359. return shadow(this, 'rgb', new DeviceRgbCS());
  6360. },
  6361. get cmyk() {
  6362. return shadow(this, 'cmyk', new DeviceCmykCS());
  6363. }
  6364. };
  6365. return ColorSpace;
  6366. })();
  6367. /**
  6368. * Alternate color space handles both Separation and DeviceN color spaces. A
  6369. * Separation color space is actually just a DeviceN with one color component.
  6370. * Both color spaces use a tinting function to convert colors to a base color
  6371. * space.
  6372. */
  6373. var AlternateCS = (function AlternateCSClosure() {
  6374. function AlternateCS(numComps, base, tintFn) {
  6375. this.name = 'Alternate';
  6376. this.numComps = numComps;
  6377. this.defaultColor = new Float32Array(numComps);
  6378. for (var i = 0; i < numComps; ++i) {
  6379. this.defaultColor[i] = 1;
  6380. }
  6381. this.base = base;
  6382. this.tintFn = tintFn;
  6383. this.tmpBuf = new Float32Array(base.numComps);
  6384. }
  6385. AlternateCS.prototype = {
  6386. getRgb: ColorSpace.prototype.getRgb,
  6387. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6388. dest, destOffset) {
  6389. var tmpBuf = this.tmpBuf;
  6390. this.tintFn(src, srcOffset, tmpBuf, 0);
  6391. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6392. },
  6393. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6394. dest, destOffset, bits,
  6395. alpha01) {
  6396. var tintFn = this.tintFn;
  6397. var base = this.base;
  6398. var scale = 1 / ((1 << bits) - 1);
  6399. var baseNumComps = base.numComps;
  6400. var usesZeroToOneRange = base.usesZeroToOneRange;
  6401. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6402. alpha01 === 0;
  6403. var pos = isPassthrough ? destOffset : 0;
  6404. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6405. var numComps = this.numComps;
  6406. var scaled = new Float32Array(numComps);
  6407. var tinted = new Float32Array(baseNumComps);
  6408. var i, j;
  6409. if (usesZeroToOneRange) {
  6410. for (i = 0; i < count; i++) {
  6411. for (j = 0; j < numComps; j++) {
  6412. scaled[j] = src[srcOffset++] * scale;
  6413. }
  6414. tintFn(scaled, 0, tinted, 0);
  6415. for (j = 0; j < baseNumComps; j++) {
  6416. baseBuf[pos++] = tinted[j] * 255;
  6417. }
  6418. }
  6419. } else {
  6420. for (i = 0; i < count; i++) {
  6421. for (j = 0; j < numComps; j++) {
  6422. scaled[j] = src[srcOffset++] * scale;
  6423. }
  6424. tintFn(scaled, 0, tinted, 0);
  6425. base.getRgbItem(tinted, 0, baseBuf, pos);
  6426. pos += baseNumComps;
  6427. }
  6428. }
  6429. if (!isPassthrough) {
  6430. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6431. }
  6432. },
  6433. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6434. alpha01) {
  6435. return this.base.getOutputLength(inputLength *
  6436. this.base.numComps / this.numComps,
  6437. alpha01);
  6438. },
  6439. isPassthrough: ColorSpace.prototype.isPassthrough,
  6440. fillRgb: ColorSpace.prototype.fillRgb,
  6441. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6442. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6443. },
  6444. usesZeroToOneRange: true
  6445. };
  6446. return AlternateCS;
  6447. })();
  6448. var PatternCS = (function PatternCSClosure() {
  6449. function PatternCS(baseCS) {
  6450. this.name = 'Pattern';
  6451. this.base = baseCS;
  6452. }
  6453. PatternCS.prototype = {};
  6454. return PatternCS;
  6455. })();
  6456. var IndexedCS = (function IndexedCSClosure() {
  6457. function IndexedCS(base, highVal, lookup) {
  6458. this.name = 'Indexed';
  6459. this.numComps = 1;
  6460. this.defaultColor = new Uint8Array([0]);
  6461. this.base = base;
  6462. this.highVal = highVal;
  6463. var baseNumComps = base.numComps;
  6464. var length = baseNumComps * highVal;
  6465. var lookupArray;
  6466. if (isStream(lookup)) {
  6467. lookupArray = new Uint8Array(length);
  6468. var bytes = lookup.getBytes(length);
  6469. lookupArray.set(bytes);
  6470. } else if (isString(lookup)) {
  6471. lookupArray = new Uint8Array(length);
  6472. for (var i = 0; i < length; ++i) {
  6473. lookupArray[i] = lookup.charCodeAt(i);
  6474. }
  6475. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6476. lookupArray = lookup;
  6477. } else {
  6478. error('Unrecognized lookup table: ' + lookup);
  6479. }
  6480. this.lookup = lookupArray;
  6481. }
  6482. IndexedCS.prototype = {
  6483. getRgb: ColorSpace.prototype.getRgb,
  6484. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6485. dest, destOffset) {
  6486. var numComps = this.base.numComps;
  6487. var start = src[srcOffset] * numComps;
  6488. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6489. },
  6490. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6491. dest, destOffset, bits,
  6492. alpha01) {
  6493. var base = this.base;
  6494. var numComps = base.numComps;
  6495. var outputDelta = base.getOutputLength(numComps, alpha01);
  6496. var lookup = this.lookup;
  6497. for (var i = 0; i < count; ++i) {
  6498. var lookupPos = src[srcOffset++] * numComps;
  6499. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6500. destOffset += outputDelta;
  6501. }
  6502. },
  6503. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6504. return this.base.getOutputLength(inputLength * this.base.numComps,
  6505. alpha01);
  6506. },
  6507. isPassthrough: ColorSpace.prototype.isPassthrough,
  6508. fillRgb: ColorSpace.prototype.fillRgb,
  6509. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6510. // indexed color maps shouldn't be changed
  6511. return true;
  6512. },
  6513. usesZeroToOneRange: true
  6514. };
  6515. return IndexedCS;
  6516. })();
  6517. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6518. function DeviceGrayCS() {
  6519. this.name = 'DeviceGray';
  6520. this.numComps = 1;
  6521. this.defaultColor = new Float32Array([0]);
  6522. }
  6523. DeviceGrayCS.prototype = {
  6524. getRgb: ColorSpace.prototype.getRgb,
  6525. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6526. dest, destOffset) {
  6527. var c = (src[srcOffset] * 255) | 0;
  6528. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6529. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6530. },
  6531. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6532. dest, destOffset, bits,
  6533. alpha01) {
  6534. var scale = 255 / ((1 << bits) - 1);
  6535. var j = srcOffset, q = destOffset;
  6536. for (var i = 0; i < count; ++i) {
  6537. var c = (scale * src[j++]) | 0;
  6538. dest[q++] = c;
  6539. dest[q++] = c;
  6540. dest[q++] = c;
  6541. q += alpha01;
  6542. }
  6543. },
  6544. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6545. alpha01) {
  6546. return inputLength * (3 + alpha01);
  6547. },
  6548. isPassthrough: ColorSpace.prototype.isPassthrough,
  6549. fillRgb: ColorSpace.prototype.fillRgb,
  6550. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6551. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6552. },
  6553. usesZeroToOneRange: true
  6554. };
  6555. return DeviceGrayCS;
  6556. })();
  6557. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6558. function DeviceRgbCS() {
  6559. this.name = 'DeviceRGB';
  6560. this.numComps = 3;
  6561. this.defaultColor = new Float32Array([0, 0, 0]);
  6562. }
  6563. DeviceRgbCS.prototype = {
  6564. getRgb: ColorSpace.prototype.getRgb,
  6565. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6566. dest, destOffset) {
  6567. var r = (src[srcOffset] * 255) | 0;
  6568. var g = (src[srcOffset + 1] * 255) | 0;
  6569. var b = (src[srcOffset + 2] * 255) | 0;
  6570. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6571. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6572. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6573. },
  6574. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6575. dest, destOffset, bits,
  6576. alpha01) {
  6577. if (bits === 8 && alpha01 === 0) {
  6578. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6579. return;
  6580. }
  6581. var scale = 255 / ((1 << bits) - 1);
  6582. var j = srcOffset, q = destOffset;
  6583. for (var i = 0; i < count; ++i) {
  6584. dest[q++] = (scale * src[j++]) | 0;
  6585. dest[q++] = (scale * src[j++]) | 0;
  6586. dest[q++] = (scale * src[j++]) | 0;
  6587. q += alpha01;
  6588. }
  6589. },
  6590. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6591. alpha01) {
  6592. return (inputLength * (3 + alpha01) / 3) | 0;
  6593. },
  6594. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6595. return bits === 8;
  6596. },
  6597. fillRgb: ColorSpace.prototype.fillRgb,
  6598. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6599. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6600. },
  6601. usesZeroToOneRange: true
  6602. };
  6603. return DeviceRgbCS;
  6604. })();
  6605. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6606. // The coefficients below was found using numerical analysis: the method of
  6607. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6608. // where color_value is the tabular value from the table of sampled RGB colors
  6609. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6610. // CMYK color conversion using the estimation below:
  6611. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6612. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6613. var c = src[srcOffset + 0] * srcScale;
  6614. var m = src[srcOffset + 1] * srcScale;
  6615. var y = src[srcOffset + 2] * srcScale;
  6616. var k = src[srcOffset + 3] * srcScale;
  6617. var r =
  6618. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6619. 18.82290502165302 * y + 212.25662451639585 * k +
  6620. -285.2331026137004) +
  6621. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6622. -17.873870861415444 * k - 5.497006427196366) +
  6623. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6624. 17.5119270841813) +
  6625. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6626. var g =
  6627. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6628. 6.871425592049007 * y + 31.159100130055922 * k +
  6629. -79.2970844816548) +
  6630. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6631. 131.35250912493976 * k - 190.9453302588951) +
  6632. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6633. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6634. var b =
  6635. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6636. 30.89978309703729 * y - 0.23883238689178934 * k +
  6637. -14.183576799673286) +
  6638. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6639. 50.606957656360734 * k - 112.23884253719248) +
  6640. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6641. -193.58209356861505) +
  6642. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6643. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6644. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6645. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6646. }
  6647. function DeviceCmykCS() {
  6648. this.name = 'DeviceCMYK';
  6649. this.numComps = 4;
  6650. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6651. }
  6652. DeviceCmykCS.prototype = {
  6653. getRgb: ColorSpace.prototype.getRgb,
  6654. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6655. dest, destOffset) {
  6656. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6657. },
  6658. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6659. dest, destOffset, bits,
  6660. alpha01) {
  6661. var scale = 1 / ((1 << bits) - 1);
  6662. for (var i = 0; i < count; i++) {
  6663. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6664. srcOffset += 4;
  6665. destOffset += 3 + alpha01;
  6666. }
  6667. },
  6668. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6669. alpha01) {
  6670. return (inputLength / 4 * (3 + alpha01)) | 0;
  6671. },
  6672. isPassthrough: ColorSpace.prototype.isPassthrough,
  6673. fillRgb: ColorSpace.prototype.fillRgb,
  6674. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6675. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6676. },
  6677. usesZeroToOneRange: true
  6678. };
  6679. return DeviceCmykCS;
  6680. })();
  6681. //
  6682. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6683. //
  6684. var CalGrayCS = (function CalGrayCSClosure() {
  6685. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6686. this.name = 'CalGray';
  6687. this.numComps = 1;
  6688. this.defaultColor = new Float32Array([0]);
  6689. if (!whitePoint) {
  6690. error('WhitePoint missing - required for color space CalGray');
  6691. }
  6692. blackPoint = blackPoint || [0, 0, 0];
  6693. gamma = gamma || 1;
  6694. // Translate arguments to spec variables.
  6695. this.XW = whitePoint[0];
  6696. this.YW = whitePoint[1];
  6697. this.ZW = whitePoint[2];
  6698. this.XB = blackPoint[0];
  6699. this.YB = blackPoint[1];
  6700. this.ZB = blackPoint[2];
  6701. this.G = gamma;
  6702. // Validate variables as per spec.
  6703. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6704. error('Invalid WhitePoint components for ' + this.name +
  6705. ', no fallback available');
  6706. }
  6707. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6708. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6709. this.XB = this.YB = this.ZB = 0;
  6710. }
  6711. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6712. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6713. ', ZB: ' + this.ZB + ', only default values are supported.');
  6714. }
  6715. if (this.G < 1) {
  6716. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6717. ', falling back to default');
  6718. this.G = 1;
  6719. }
  6720. }
  6721. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6722. // A represents a gray component of a calibrated gray space.
  6723. // A <---> AG in the spec
  6724. var A = src[srcOffset] * scale;
  6725. var AG = Math.pow(A, cs.G);
  6726. // Computes L as per spec. ( = cs.YW * AG )
  6727. // Except if other than default BlackPoint values are used.
  6728. var L = cs.YW * AG;
  6729. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6730. // Convert values to rgb range [0, 255].
  6731. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6732. dest[destOffset] = val;
  6733. dest[destOffset + 1] = val;
  6734. dest[destOffset + 2] = val;
  6735. }
  6736. CalGrayCS.prototype = {
  6737. getRgb: ColorSpace.prototype.getRgb,
  6738. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6739. dest, destOffset) {
  6740. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6741. },
  6742. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6743. dest, destOffset, bits,
  6744. alpha01) {
  6745. var scale = 1 / ((1 << bits) - 1);
  6746. for (var i = 0; i < count; ++i) {
  6747. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6748. srcOffset += 1;
  6749. destOffset += 3 + alpha01;
  6750. }
  6751. },
  6752. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6753. return inputLength * (3 + alpha01);
  6754. },
  6755. isPassthrough: ColorSpace.prototype.isPassthrough,
  6756. fillRgb: ColorSpace.prototype.fillRgb,
  6757. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6758. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6759. },
  6760. usesZeroToOneRange: true
  6761. };
  6762. return CalGrayCS;
  6763. })();
  6764. //
  6765. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6766. //
  6767. var CalRGBCS = (function CalRGBCSClosure() {
  6768. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6769. // matrices.
  6770. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6771. 0.8951, 0.2664, -0.1614,
  6772. -0.7502, 1.7135, 0.0367,
  6773. 0.0389, -0.0685, 1.0296]);
  6774. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6775. 0.9869929, -0.1470543, 0.1599627,
  6776. 0.4323053, 0.5183603, 0.0492912,
  6777. -0.0085287, 0.0400428, 0.9684867]);
  6778. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6779. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6780. 3.2404542, -1.5371385, -0.4985314,
  6781. -0.9692660, 1.8760108, 0.0415560,
  6782. 0.0556434, -0.2040259, 1.0572252]);
  6783. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6784. var tempNormalizeMatrix = new Float32Array(3);
  6785. var tempConvertMatrix1 = new Float32Array(3);
  6786. var tempConvertMatrix2 = new Float32Array(3);
  6787. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6788. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6789. this.name = 'CalRGB';
  6790. this.numComps = 3;
  6791. this.defaultColor = new Float32Array(3);
  6792. if (!whitePoint) {
  6793. error('WhitePoint missing - required for color space CalRGB');
  6794. }
  6795. blackPoint = blackPoint || new Float32Array(3);
  6796. gamma = gamma || new Float32Array([1, 1, 1]);
  6797. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6798. // Translate arguments to spec variables.
  6799. var XW = whitePoint[0];
  6800. var YW = whitePoint[1];
  6801. var ZW = whitePoint[2];
  6802. this.whitePoint = whitePoint;
  6803. var XB = blackPoint[0];
  6804. var YB = blackPoint[1];
  6805. var ZB = blackPoint[2];
  6806. this.blackPoint = blackPoint;
  6807. this.GR = gamma[0];
  6808. this.GG = gamma[1];
  6809. this.GB = gamma[2];
  6810. this.MXA = matrix[0];
  6811. this.MYA = matrix[1];
  6812. this.MZA = matrix[2];
  6813. this.MXB = matrix[3];
  6814. this.MYB = matrix[4];
  6815. this.MZB = matrix[5];
  6816. this.MXC = matrix[6];
  6817. this.MYC = matrix[7];
  6818. this.MZC = matrix[8];
  6819. // Validate variables as per spec.
  6820. if (XW < 0 || ZW < 0 || YW !== 1) {
  6821. error('Invalid WhitePoint components for ' + this.name +
  6822. ', no fallback available');
  6823. }
  6824. if (XB < 0 || YB < 0 || ZB < 0) {
  6825. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6826. ', ' + ZB + '], falling back to default');
  6827. this.blackPoint = new Float32Array(3);
  6828. }
  6829. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6830. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6831. '] for ' + this.name + ', falling back to default');
  6832. this.GR = this.GG = this.GB = 1;
  6833. }
  6834. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6835. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6836. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6837. info('Invalid Matrix for ' + this.name + ' [' +
  6838. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6839. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6840. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6841. '], falling back to default');
  6842. this.MXA = this.MYB = this.MZC = 1;
  6843. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6844. }
  6845. }
  6846. function matrixProduct(a, b, result) {
  6847. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6848. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6849. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6850. }
  6851. function convertToFlat(sourceWhitePoint, LMS, result) {
  6852. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6853. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6854. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6855. }
  6856. function convertToD65(sourceWhitePoint, LMS, result) {
  6857. var D65X = 0.95047;
  6858. var D65Y = 1;
  6859. var D65Z = 1.08883;
  6860. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6861. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6862. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6863. }
  6864. function sRGBTransferFunction(color) {
  6865. // See http://en.wikipedia.org/wiki/SRGB.
  6866. if (color <= 0.0031308){
  6867. return adjustToRange(0, 1, 12.92 * color);
  6868. }
  6869. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6870. }
  6871. function adjustToRange(min, max, value) {
  6872. return Math.max(min, Math.min(max, value));
  6873. }
  6874. function decodeL(L) {
  6875. if (L < 0) {
  6876. return -decodeL(-L);
  6877. }
  6878. if (L > 8.0) {
  6879. return Math.pow(((L + 16) / 116), 3);
  6880. }
  6881. return L * DECODE_L_CONSTANT;
  6882. }
  6883. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6884. // In case the blackPoint is already the default blackPoint then there is
  6885. // no need to do compensation.
  6886. if (sourceBlackPoint[0] === 0 &&
  6887. sourceBlackPoint[1] === 0 &&
  6888. sourceBlackPoint[2] === 0) {
  6889. result[0] = XYZ_Flat[0];
  6890. result[1] = XYZ_Flat[1];
  6891. result[2] = XYZ_Flat[2];
  6892. return;
  6893. }
  6894. // For the blackPoint calculation details, please see
  6895. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6896. // AdobeBPC.pdf.
  6897. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6898. var zeroDecodeL = decodeL(0);
  6899. var X_DST = zeroDecodeL;
  6900. var X_SRC = decodeL(sourceBlackPoint[0]);
  6901. var Y_DST = zeroDecodeL;
  6902. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6903. var Z_DST = zeroDecodeL;
  6904. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6905. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6906. var X_Offset = 1 - X_Scale;
  6907. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6908. var Y_Offset = 1 - Y_Scale;
  6909. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6910. var Z_Offset = 1 - Z_Scale;
  6911. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6912. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6913. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6914. }
  6915. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6916. // In case the whitePoint is already flat then there is no need to do
  6917. // normalization.
  6918. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6919. result[0] = XYZ_In[0];
  6920. result[1] = XYZ_In[1];
  6921. result[2] = XYZ_In[2];
  6922. return;
  6923. }
  6924. var LMS = result;
  6925. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6926. var LMS_Flat = tempNormalizeMatrix;
  6927. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6928. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6929. }
  6930. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6931. var LMS = result;
  6932. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6933. var LMS_D65 = tempNormalizeMatrix;
  6934. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6935. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6936. }
  6937. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6938. // A, B and C represent a red, green and blue components of a calibrated
  6939. // rgb space.
  6940. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6941. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6942. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6943. // A <---> AGR in the spec
  6944. // B <---> BGG in the spec
  6945. // C <---> CGB in the spec
  6946. var AGR = Math.pow(A, cs.GR);
  6947. var BGG = Math.pow(B, cs.GG);
  6948. var CGB = Math.pow(C, cs.GB);
  6949. // Computes intermediate variables L, M, N as per spec.
  6950. // To decode X, Y, Z values map L, M, N directly to them.
  6951. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6952. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6953. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6954. // The following calculations are based on this document:
  6955. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6956. // AdobeBPC.pdf.
  6957. var XYZ = tempConvertMatrix1;
  6958. XYZ[0] = X;
  6959. XYZ[1] = Y;
  6960. XYZ[2] = Z;
  6961. var XYZ_Flat = tempConvertMatrix2;
  6962. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6963. var XYZ_Black = tempConvertMatrix1;
  6964. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6965. var XYZ_D65 = tempConvertMatrix2;
  6966. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6967. var SRGB = tempConvertMatrix1;
  6968. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6969. var sR = sRGBTransferFunction(SRGB[0]);
  6970. var sG = sRGBTransferFunction(SRGB[1]);
  6971. var sB = sRGBTransferFunction(SRGB[2]);
  6972. // Convert the values to rgb range [0, 255].
  6973. dest[destOffset] = Math.round(sR * 255);
  6974. dest[destOffset + 1] = Math.round(sG * 255);
  6975. dest[destOffset + 2] = Math.round(sB * 255);
  6976. }
  6977. CalRGBCS.prototype = {
  6978. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6979. var rgb = new Uint8Array(3);
  6980. this.getRgbItem(src, srcOffset, rgb, 0);
  6981. return rgb;
  6982. },
  6983. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6984. dest, destOffset) {
  6985. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6986. },
  6987. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6988. dest, destOffset, bits,
  6989. alpha01) {
  6990. var scale = 1 / ((1 << bits) - 1);
  6991. for (var i = 0; i < count; ++i) {
  6992. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6993. srcOffset += 3;
  6994. destOffset += 3 + alpha01;
  6995. }
  6996. },
  6997. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6998. return (inputLength * (3 + alpha01) / 3) | 0;
  6999. },
  7000. isPassthrough: ColorSpace.prototype.isPassthrough,
  7001. fillRgb: ColorSpace.prototype.fillRgb,
  7002. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  7003. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7004. },
  7005. usesZeroToOneRange: true
  7006. };
  7007. return CalRGBCS;
  7008. })();
  7009. //
  7010. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  7011. //
  7012. var LabCS = (function LabCSClosure() {
  7013. function LabCS(whitePoint, blackPoint, range) {
  7014. this.name = 'Lab';
  7015. this.numComps = 3;
  7016. this.defaultColor = new Float32Array([0, 0, 0]);
  7017. if (!whitePoint) {
  7018. error('WhitePoint missing - required for color space Lab');
  7019. }
  7020. blackPoint = blackPoint || [0, 0, 0];
  7021. range = range || [-100, 100, -100, 100];
  7022. // Translate args to spec variables
  7023. this.XW = whitePoint[0];
  7024. this.YW = whitePoint[1];
  7025. this.ZW = whitePoint[2];
  7026. this.amin = range[0];
  7027. this.amax = range[1];
  7028. this.bmin = range[2];
  7029. this.bmax = range[3];
  7030. // These are here just for completeness - the spec doesn't offer any
  7031. // formulas that use BlackPoint in Lab
  7032. this.XB = blackPoint[0];
  7033. this.YB = blackPoint[1];
  7034. this.ZB = blackPoint[2];
  7035. // Validate vars as per spec
  7036. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7037. error('Invalid WhitePoint components, no fallback available');
  7038. }
  7039. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7040. info('Invalid BlackPoint, falling back to default');
  7041. this.XB = this.YB = this.ZB = 0;
  7042. }
  7043. if (this.amin > this.amax || this.bmin > this.bmax) {
  7044. info('Invalid Range, falling back to defaults');
  7045. this.amin = -100;
  7046. this.amax = 100;
  7047. this.bmin = -100;
  7048. this.bmax = 100;
  7049. }
  7050. }
  7051. // Function g(x) from spec
  7052. function fn_g(x) {
  7053. if (x >= 6 / 29) {
  7054. return x * x * x;
  7055. } else {
  7056. return (108 / 841) * (x - 4 / 29);
  7057. }
  7058. }
  7059. function decode(value, high1, low2, high2) {
  7060. return low2 + (value) * (high2 - low2) / (high1);
  7061. }
  7062. // If decoding is needed maxVal should be 2^bits per component - 1.
  7063. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  7064. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  7065. // not the usual [0, 1]. If a command like setFillColor is used the src
  7066. // values will already be within the correct range. However, if we are
  7067. // converting an image we have to map the values to the correct range given
  7068. // above.
  7069. // Ls,as,bs <---> L*,a*,b* in the spec
  7070. var Ls = src[srcOffset];
  7071. var as = src[srcOffset + 1];
  7072. var bs = src[srcOffset + 2];
  7073. if (maxVal !== false) {
  7074. Ls = decode(Ls, maxVal, 0, 100);
  7075. as = decode(as, maxVal, cs.amin, cs.amax);
  7076. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  7077. }
  7078. // Adjust limits of 'as' and 'bs'
  7079. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  7080. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  7081. // Computes intermediate variables X,Y,Z as per spec
  7082. var M = (Ls + 16) / 116;
  7083. var L = M + (as / 500);
  7084. var N = M - (bs / 200);
  7085. var X = cs.XW * fn_g(L);
  7086. var Y = cs.YW * fn_g(M);
  7087. var Z = cs.ZW * fn_g(N);
  7088. var r, g, b;
  7089. // Using different conversions for D50 and D65 white points,
  7090. // per http://www.color.org/srgb.pdf
  7091. if (cs.ZW < 1) {
  7092. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  7093. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  7094. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  7095. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  7096. } else {
  7097. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  7098. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  7099. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  7100. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  7101. }
  7102. // clamp color values to [0,1] range then convert to [0,255] range.
  7103. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  7104. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  7105. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  7106. }
  7107. LabCS.prototype = {
  7108. getRgb: ColorSpace.prototype.getRgb,
  7109. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  7110. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  7111. },
  7112. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  7113. dest, destOffset, bits,
  7114. alpha01) {
  7115. var maxVal = (1 << bits) - 1;
  7116. for (var i = 0; i < count; i++) {
  7117. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  7118. srcOffset += 3;
  7119. destOffset += 3 + alpha01;
  7120. }
  7121. },
  7122. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  7123. return (inputLength * (3 + alpha01) / 3) | 0;
  7124. },
  7125. isPassthrough: ColorSpace.prototype.isPassthrough,
  7126. fillRgb: ColorSpace.prototype.fillRgb,
  7127. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  7128. // XXX: Decoding is handled with the lab conversion because of the strange
  7129. // ranges that are used.
  7130. return true;
  7131. },
  7132. usesZeroToOneRange: false
  7133. };
  7134. return LabCS;
  7135. })();
  7136. var ARCFourCipher = (function ARCFourCipherClosure() {
  7137. function ARCFourCipher(key) {
  7138. this.a = 0;
  7139. this.b = 0;
  7140. var s = new Uint8Array(256);
  7141. var i, j = 0, tmp, keyLength = key.length;
  7142. for (i = 0; i < 256; ++i) {
  7143. s[i] = i;
  7144. }
  7145. for (i = 0; i < 256; ++i) {
  7146. tmp = s[i];
  7147. j = (j + tmp + key[i % keyLength]) & 0xFF;
  7148. s[i] = s[j];
  7149. s[j] = tmp;
  7150. }
  7151. this.s = s;
  7152. }
  7153. ARCFourCipher.prototype = {
  7154. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  7155. var i, n = data.length, tmp, tmp2;
  7156. var a = this.a, b = this.b, s = this.s;
  7157. var output = new Uint8Array(n);
  7158. for (i = 0; i < n; ++i) {
  7159. a = (a + 1) & 0xFF;
  7160. tmp = s[a];
  7161. b = (b + tmp) & 0xFF;
  7162. tmp2 = s[b];
  7163. s[a] = tmp2;
  7164. s[b] = tmp;
  7165. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7166. }
  7167. this.a = a;
  7168. this.b = b;
  7169. return output;
  7170. }
  7171. };
  7172. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7173. return ARCFourCipher;
  7174. })();
  7175. var calculateMD5 = (function calculateMD5Closure() {
  7176. var r = new Uint8Array([
  7177. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7178. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7179. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7180. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7181. var k = new Int32Array([
  7182. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7183. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7184. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7185. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7186. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7187. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7188. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7189. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7190. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7191. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7192. -145523070, -1120210379, 718787259, -343485551]);
  7193. function hash(data, offset, length) {
  7194. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7195. // pre-processing
  7196. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7197. var padded = new Uint8Array(paddedLength);
  7198. var i, j, n;
  7199. for (i = 0; i < length; ++i) {
  7200. padded[i] = data[offset++];
  7201. }
  7202. padded[i++] = 0x80;
  7203. n = paddedLength - 8;
  7204. while (i < n) {
  7205. padded[i++] = 0;
  7206. }
  7207. padded[i++] = (length << 3) & 0xFF;
  7208. padded[i++] = (length >> 5) & 0xFF;
  7209. padded[i++] = (length >> 13) & 0xFF;
  7210. padded[i++] = (length >> 21) & 0xFF;
  7211. padded[i++] = (length >>> 29) & 0xFF;
  7212. padded[i++] = 0;
  7213. padded[i++] = 0;
  7214. padded[i++] = 0;
  7215. var w = new Int32Array(16);
  7216. for (i = 0; i < paddedLength;) {
  7217. for (j = 0; j < 16; ++j, i += 4) {
  7218. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7219. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7220. }
  7221. var a = h0, b = h1, c = h2, d = h3, f, g;
  7222. for (j = 0; j < 64; ++j) {
  7223. if (j < 16) {
  7224. f = (b & c) | ((~b) & d);
  7225. g = j;
  7226. } else if (j < 32) {
  7227. f = (d & b) | ((~d) & c);
  7228. g = (5 * j + 1) & 15;
  7229. } else if (j < 48) {
  7230. f = b ^ c ^ d;
  7231. g = (3 * j + 5) & 15;
  7232. } else {
  7233. f = c ^ (b | (~d));
  7234. g = (7 * j) & 15;
  7235. }
  7236. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7237. d = c;
  7238. c = b;
  7239. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7240. a = tmp;
  7241. }
  7242. h0 = (h0 + a) | 0;
  7243. h1 = (h1 + b) | 0;
  7244. h2 = (h2 + c) | 0;
  7245. h3 = (h3 + d) | 0;
  7246. }
  7247. return new Uint8Array([
  7248. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7249. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7250. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7251. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7252. ]);
  7253. }
  7254. return hash;
  7255. })();
  7256. var Word64 = (function Word64Closure() {
  7257. function Word64(highInteger, lowInteger) {
  7258. this.high = highInteger | 0;
  7259. this.low = lowInteger | 0;
  7260. }
  7261. Word64.prototype = {
  7262. and: function Word64_and(word) {
  7263. this.high &= word.high;
  7264. this.low &= word.low;
  7265. },
  7266. xor: function Word64_xor(word) {
  7267. this.high ^= word.high;
  7268. this.low ^= word.low;
  7269. },
  7270. or: function Word64_or(word) {
  7271. this.high |= word.high;
  7272. this.low |= word.low;
  7273. },
  7274. shiftRight: function Word64_shiftRight(places) {
  7275. if (places >= 32) {
  7276. this.low = (this.high >>> (places - 32)) | 0;
  7277. this.high = 0;
  7278. } else {
  7279. this.low = (this.low >>> places) | (this.high << (32 - places));
  7280. this.high = (this.high >>> places) | 0;
  7281. }
  7282. },
  7283. shiftLeft: function Word64_shiftLeft(places) {
  7284. if (places >= 32) {
  7285. this.high = this.low << (places - 32);
  7286. this.low = 0;
  7287. } else {
  7288. this.high = (this.high << places) | (this.low >>> (32 - places));
  7289. this.low = this.low << places;
  7290. }
  7291. },
  7292. rotateRight: function Word64_rotateRight(places) {
  7293. var low, high;
  7294. if (places & 32) {
  7295. high = this.low;
  7296. low = this.high;
  7297. } else {
  7298. low = this.low;
  7299. high = this.high;
  7300. }
  7301. places &= 31;
  7302. this.low = (low >>> places) | (high << (32 - places));
  7303. this.high = (high >>> places) | (low << (32 - places));
  7304. },
  7305. not: function Word64_not() {
  7306. this.high = ~this.high;
  7307. this.low = ~this.low;
  7308. },
  7309. add: function Word64_add(word) {
  7310. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7311. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7312. if (lowAdd > 0xFFFFFFFF) {
  7313. highAdd += 1;
  7314. }
  7315. this.low = lowAdd | 0;
  7316. this.high = highAdd | 0;
  7317. },
  7318. copyTo: function Word64_copyTo(bytes, offset) {
  7319. bytes[offset] = (this.high >>> 24) & 0xFF;
  7320. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7321. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7322. bytes[offset + 3] = this.high & 0xFF;
  7323. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7324. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7325. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7326. bytes[offset + 7] = this.low & 0xFF;
  7327. },
  7328. assign: function Word64_assign(word) {
  7329. this.high = word.high;
  7330. this.low = word.low;
  7331. }
  7332. };
  7333. return Word64;
  7334. })();
  7335. var calculateSHA256 = (function calculateSHA256Closure() {
  7336. function rotr(x, n) {
  7337. return (x >>> n) | (x << 32 - n);
  7338. }
  7339. function ch(x, y, z) {
  7340. return (x & y) ^ (~x & z);
  7341. }
  7342. function maj(x, y, z) {
  7343. return (x & y) ^ (x & z) ^ (y & z);
  7344. }
  7345. function sigma(x) {
  7346. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7347. }
  7348. function sigmaPrime(x) {
  7349. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7350. }
  7351. function littleSigma(x) {
  7352. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7353. }
  7354. function littleSigmaPrime(x) {
  7355. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7356. }
  7357. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7358. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7359. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7360. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7361. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7362. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7363. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7364. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7365. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7366. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7367. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7368. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7369. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7370. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7371. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7372. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7373. function hash(data, offset, length) {
  7374. // initial hash values
  7375. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7376. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7377. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7378. // pre-processing
  7379. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7380. var padded = new Uint8Array(paddedLength);
  7381. var i, j, n;
  7382. for (i = 0; i < length; ++i) {
  7383. padded[i] = data[offset++];
  7384. }
  7385. padded[i++] = 0x80;
  7386. n = paddedLength - 8;
  7387. while (i < n) {
  7388. padded[i++] = 0;
  7389. }
  7390. padded[i++] = 0;
  7391. padded[i++] = 0;
  7392. padded[i++] = 0;
  7393. padded[i++] = (length >>> 29) & 0xFF;
  7394. padded[i++] = (length >> 21) & 0xFF;
  7395. padded[i++] = (length >> 13) & 0xFF;
  7396. padded[i++] = (length >> 5) & 0xFF;
  7397. padded[i++] = (length << 3) & 0xFF;
  7398. var w = new Uint32Array(64);
  7399. // for each 512 bit block
  7400. for (i = 0; i < paddedLength;) {
  7401. for (j = 0; j < 16; ++j) {
  7402. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7403. (padded[i + 2] << 8) | (padded[i + 3]));
  7404. i += 4;
  7405. }
  7406. for (j = 16; j < 64; ++j) {
  7407. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7408. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7409. }
  7410. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7411. f = h5, g = h6, h = h7, t1, t2;
  7412. for (j = 0; j < 64; ++j) {
  7413. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7414. t2 = sigma(a) + maj(a, b, c);
  7415. h = g;
  7416. g = f;
  7417. f = e;
  7418. e = (d + t1) | 0;
  7419. d = c;
  7420. c = b;
  7421. b = a;
  7422. a = (t1 + t2) | 0;
  7423. }
  7424. h0 = (h0 + a) | 0;
  7425. h1 = (h1 + b) | 0;
  7426. h2 = (h2 + c) | 0;
  7427. h3 = (h3 + d) | 0;
  7428. h4 = (h4 + e) | 0;
  7429. h5 = (h5 + f) | 0;
  7430. h6 = (h6 + g) | 0;
  7431. h7 = (h7 + h) | 0;
  7432. }
  7433. return new Uint8Array([
  7434. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7435. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7436. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7437. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7438. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7439. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7440. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7441. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7442. ]);
  7443. }
  7444. return hash;
  7445. })();
  7446. var calculateSHA512 = (function calculateSHA512Closure() {
  7447. function ch(result, x, y, z, tmp) {
  7448. result.assign(x);
  7449. result.and(y);
  7450. tmp.assign(x);
  7451. tmp.not();
  7452. tmp.and(z);
  7453. result.xor(tmp);
  7454. }
  7455. function maj(result, x, y, z, tmp) {
  7456. result.assign(x);
  7457. result.and(y);
  7458. tmp.assign(x);
  7459. tmp.and(z);
  7460. result.xor(tmp);
  7461. tmp.assign(y);
  7462. tmp.and(z);
  7463. result.xor(tmp);
  7464. }
  7465. function sigma(result, x, tmp) {
  7466. result.assign(x);
  7467. result.rotateRight(28);
  7468. tmp.assign(x);
  7469. tmp.rotateRight(34);
  7470. result.xor(tmp);
  7471. tmp.assign(x);
  7472. tmp.rotateRight(39);
  7473. result.xor(tmp);
  7474. }
  7475. function sigmaPrime(result, x, tmp) {
  7476. result.assign(x);
  7477. result.rotateRight(14);
  7478. tmp.assign(x);
  7479. tmp.rotateRight(18);
  7480. result.xor(tmp);
  7481. tmp.assign(x);
  7482. tmp.rotateRight(41);
  7483. result.xor(tmp);
  7484. }
  7485. function littleSigma(result, x, tmp) {
  7486. result.assign(x);
  7487. result.rotateRight(1);
  7488. tmp.assign(x);
  7489. tmp.rotateRight(8);
  7490. result.xor(tmp);
  7491. tmp.assign(x);
  7492. tmp.shiftRight(7);
  7493. result.xor(tmp);
  7494. }
  7495. function littleSigmaPrime(result, x, tmp) {
  7496. result.assign(x);
  7497. result.rotateRight(19);
  7498. tmp.assign(x);
  7499. tmp.rotateRight(61);
  7500. result.xor(tmp);
  7501. tmp.assign(x);
  7502. tmp.shiftRight(6);
  7503. result.xor(tmp);
  7504. }
  7505. var k = [
  7506. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7507. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7508. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7509. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7510. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7511. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7512. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7513. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7514. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7515. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7516. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7517. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7518. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7519. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7520. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7521. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7522. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7523. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7524. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7525. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7526. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7527. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7528. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7529. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7530. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7531. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7532. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7533. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7534. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7535. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7536. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7537. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7538. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7539. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7540. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7541. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7542. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7543. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7544. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7545. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7546. function hash(data, offset, length, mode384) {
  7547. mode384 = !!mode384;
  7548. // initial hash values
  7549. var h0, h1, h2, h3, h4, h5, h6, h7;
  7550. if (!mode384) {
  7551. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7552. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7553. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7554. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7555. h4 = new Word64(0x510e527f, 0xade682d1);
  7556. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7557. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7558. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7559. }
  7560. else {
  7561. // SHA384 is exactly the same
  7562. // except with different starting values and a trimmed result
  7563. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7564. h1 = new Word64(0x629a292a, 0x367cd507);
  7565. h2 = new Word64(0x9159015a, 0x3070dd17);
  7566. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7567. h4 = new Word64(0x67332667, 0xffc00b31);
  7568. h5 = new Word64(0x8eb44a87, 0x68581511);
  7569. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7570. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7571. }
  7572. // pre-processing
  7573. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7574. var padded = new Uint8Array(paddedLength);
  7575. var i, j, n;
  7576. for (i = 0; i < length; ++i) {
  7577. padded[i] = data[offset++];
  7578. }
  7579. padded[i++] = 0x80;
  7580. n = paddedLength - 16;
  7581. while (i < n) {
  7582. padded[i++] = 0;
  7583. }
  7584. padded[i++] = 0;
  7585. padded[i++] = 0;
  7586. padded[i++] = 0;
  7587. padded[i++] = 0;
  7588. padded[i++] = 0;
  7589. padded[i++] = 0;
  7590. padded[i++] = 0;
  7591. padded[i++] = 0;
  7592. padded[i++] = 0;
  7593. padded[i++] = 0;
  7594. padded[i++] = 0;
  7595. padded[i++] = (length >>> 29) & 0xFF;
  7596. padded[i++] = (length >> 21) & 0xFF;
  7597. padded[i++] = (length >> 13) & 0xFF;
  7598. padded[i++] = (length >> 5) & 0xFF;
  7599. padded[i++] = (length << 3) & 0xFF;
  7600. var w = new Array(80);
  7601. for (i = 0; i < 80; i++) {
  7602. w[i] = new Word64(0, 0);
  7603. }
  7604. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7605. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7606. var g = new Word64(0, 0), h = new Word64(0, 0);
  7607. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7608. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7609. // for each 1024 bit block
  7610. for (i = 0; i < paddedLength;) {
  7611. for (j = 0; j < 16; ++j) {
  7612. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7613. (padded[i + 2] << 8) | (padded[i + 3]);
  7614. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7615. (padded[i + 6]) << 8 | (padded[i + 7]);
  7616. i += 8;
  7617. }
  7618. for (j = 16; j < 80; ++j) {
  7619. tmp3 = w[j];
  7620. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7621. tmp3.add(w[j - 7]);
  7622. littleSigma(tmp1, w[j - 15], tmp2);
  7623. tmp3.add(tmp1);
  7624. tmp3.add(w[j - 16]);
  7625. }
  7626. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7627. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7628. for (j = 0; j < 80; ++j) {
  7629. t1.assign(h);
  7630. sigmaPrime(tmp1, e, tmp2);
  7631. t1.add(tmp1);
  7632. ch(tmp1, e, f, g, tmp2);
  7633. t1.add(tmp1);
  7634. t1.add(k[j]);
  7635. t1.add(w[j]);
  7636. sigma(t2, a, tmp2);
  7637. maj(tmp1, a, b, c, tmp2);
  7638. t2.add(tmp1);
  7639. tmp3 = h;
  7640. h = g;
  7641. g = f;
  7642. f = e;
  7643. d.add(t1);
  7644. e = d;
  7645. d = c;
  7646. c = b;
  7647. b = a;
  7648. tmp3.assign(t1);
  7649. tmp3.add(t2);
  7650. a = tmp3;
  7651. }
  7652. h0.add(a);
  7653. h1.add(b);
  7654. h2.add(c);
  7655. h3.add(d);
  7656. h4.add(e);
  7657. h5.add(f);
  7658. h6.add(g);
  7659. h7.add(h);
  7660. }
  7661. var result;
  7662. if (!mode384) {
  7663. result = new Uint8Array(64);
  7664. h0.copyTo(result,0);
  7665. h1.copyTo(result,8);
  7666. h2.copyTo(result,16);
  7667. h3.copyTo(result,24);
  7668. h4.copyTo(result,32);
  7669. h5.copyTo(result,40);
  7670. h6.copyTo(result,48);
  7671. h7.copyTo(result,56);
  7672. }
  7673. else {
  7674. result = new Uint8Array(48);
  7675. h0.copyTo(result,0);
  7676. h1.copyTo(result,8);
  7677. h2.copyTo(result,16);
  7678. h3.copyTo(result,24);
  7679. h4.copyTo(result,32);
  7680. h5.copyTo(result,40);
  7681. }
  7682. return result;
  7683. }
  7684. return hash;
  7685. })();
  7686. var calculateSHA384 = (function calculateSHA384Closure() {
  7687. function hash(data, offset, length) {
  7688. return calculateSHA512(data, offset, length, true);
  7689. }
  7690. return hash;
  7691. })();
  7692. var NullCipher = (function NullCipherClosure() {
  7693. function NullCipher() {
  7694. }
  7695. NullCipher.prototype = {
  7696. decryptBlock: function NullCipher_decryptBlock(data) {
  7697. return data;
  7698. }
  7699. };
  7700. return NullCipher;
  7701. })();
  7702. var AES128Cipher = (function AES128CipherClosure() {
  7703. var rcon = new Uint8Array([
  7704. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7705. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7706. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7707. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7708. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7709. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7710. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7711. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7712. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7713. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7714. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7715. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7716. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7717. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7718. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7719. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7720. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7721. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7722. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7723. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7724. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7725. 0x74, 0xe8, 0xcb, 0x8d]);
  7726. var s = new Uint8Array([
  7727. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7728. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7729. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7730. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7731. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7732. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7733. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7734. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7735. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7736. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7737. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7738. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7739. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7740. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7741. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7742. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7743. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7744. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7745. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7746. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7747. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7748. 0xb0, 0x54, 0xbb, 0x16]);
  7749. var inv_s = new Uint8Array([
  7750. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7751. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7752. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7753. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7754. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7755. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7756. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7757. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7758. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7759. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7760. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7761. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7762. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7763. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7764. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7765. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7766. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7767. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7768. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7769. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7770. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7771. 0x55, 0x21, 0x0c, 0x7d]);
  7772. var mixCol = new Uint8Array(256);
  7773. for (var i = 0; i < 256; i++) {
  7774. if (i < 128) {
  7775. mixCol[i] = i << 1;
  7776. } else {
  7777. mixCol[i] = (i << 1) ^ 0x1b;
  7778. }
  7779. }
  7780. var mix = new Uint32Array([
  7781. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7782. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7783. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7784. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7785. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7786. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7787. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7788. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7789. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7790. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7791. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7792. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7793. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7794. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7795. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7796. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7797. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7798. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7799. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7800. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7801. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7802. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7803. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7804. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7805. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7806. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7807. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7808. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7809. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7810. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7811. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7812. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7813. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7814. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7815. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7816. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7817. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7818. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7819. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7820. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7821. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7822. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7823. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7824. function expandKey128(cipherKey) {
  7825. var b = 176, result = new Uint8Array(b);
  7826. result.set(cipherKey);
  7827. for (var j = 16, i = 1; j < b; ++i) {
  7828. // RotWord
  7829. var t1 = result[j - 3], t2 = result[j - 2],
  7830. t3 = result[j - 1], t4 = result[j - 4];
  7831. // SubWord
  7832. t1 = s[t1];
  7833. t2 = s[t2];
  7834. t3 = s[t3];
  7835. t4 = s[t4];
  7836. // Rcon
  7837. t1 = t1 ^ rcon[i];
  7838. for (var n = 0; n < 4; ++n) {
  7839. result[j] = (t1 ^= result[j - 16]);
  7840. j++;
  7841. result[j] = (t2 ^= result[j - 16]);
  7842. j++;
  7843. result[j] = (t3 ^= result[j - 16]);
  7844. j++;
  7845. result[j] = (t4 ^= result[j - 16]);
  7846. j++;
  7847. }
  7848. }
  7849. return result;
  7850. }
  7851. function decrypt128(input, key) {
  7852. var state = new Uint8Array(16);
  7853. state.set(input);
  7854. var i, j, k;
  7855. var t, u, v;
  7856. // AddRoundKey
  7857. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7858. state[j] ^= key[k];
  7859. }
  7860. for (i = 9; i >= 1; --i) {
  7861. // InvShiftRows
  7862. t = state[13];
  7863. state[13] = state[9];
  7864. state[9] = state[5];
  7865. state[5] = state[1];
  7866. state[1] = t;
  7867. t = state[14];
  7868. u = state[10];
  7869. state[14] = state[6];
  7870. state[10] = state[2];
  7871. state[6] = t;
  7872. state[2] = u;
  7873. t = state[15];
  7874. u = state[11];
  7875. v = state[7];
  7876. state[15] = state[3];
  7877. state[11] = t;
  7878. state[7] = u;
  7879. state[3] = v;
  7880. // InvSubBytes
  7881. for (j = 0; j < 16; ++j) {
  7882. state[j] = inv_s[state[j]];
  7883. }
  7884. // AddRoundKey
  7885. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7886. state[j] ^= key[k];
  7887. }
  7888. // InvMixColumns
  7889. for (j = 0; j < 16; j += 4) {
  7890. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7891. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7892. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7893. (s3 >>> 24) ^ (s3 << 8));
  7894. state[j] = (t >>> 24) & 0xFF;
  7895. state[j + 1] = (t >> 16) & 0xFF;
  7896. state[j + 2] = (t >> 8) & 0xFF;
  7897. state[j + 3] = t & 0xFF;
  7898. }
  7899. }
  7900. // InvShiftRows
  7901. t = state[13];
  7902. state[13] = state[9];
  7903. state[9] = state[5];
  7904. state[5] = state[1];
  7905. state[1] = t;
  7906. t = state[14];
  7907. u = state[10];
  7908. state[14] = state[6];
  7909. state[10] = state[2];
  7910. state[6] = t;
  7911. state[2] = u;
  7912. t = state[15];
  7913. u = state[11];
  7914. v = state[7];
  7915. state[15] = state[3];
  7916. state[11] = t;
  7917. state[7] = u;
  7918. state[3] = v;
  7919. for (j = 0; j < 16; ++j) {
  7920. // InvSubBytes
  7921. state[j] = inv_s[state[j]];
  7922. // AddRoundKey
  7923. state[j] ^= key[j];
  7924. }
  7925. return state;
  7926. }
  7927. function encrypt128(input, key) {
  7928. var t, u, v, k;
  7929. var state = new Uint8Array(16);
  7930. state.set(input);
  7931. for (j = 0; j < 16; ++j) {
  7932. // AddRoundKey
  7933. state[j] ^= key[j];
  7934. }
  7935. for (i = 1; i < 10; i++) {
  7936. //SubBytes
  7937. for (j = 0; j < 16; ++j) {
  7938. state[j] = s[state[j]];
  7939. }
  7940. //ShiftRows
  7941. v = state[1];
  7942. state[1] = state[5];
  7943. state[5] = state[9];
  7944. state[9] = state[13];
  7945. state[13] = v;
  7946. v = state[2];
  7947. u = state[6];
  7948. state[2] = state[10];
  7949. state[6] = state[14];
  7950. state[10] = v;
  7951. state[14] = u;
  7952. v = state[3];
  7953. u = state[7];
  7954. t = state[11];
  7955. state[3] = state[15];
  7956. state[7] = v;
  7957. state[11] = u;
  7958. state[15] = t;
  7959. //MixColumns
  7960. for (var j = 0; j < 16; j += 4) {
  7961. var s0 = state[j + 0], s1 = state[j + 1];
  7962. var s2 = state[j + 2], s3 = state[j + 3];
  7963. t = s0 ^ s1 ^ s2 ^ s3;
  7964. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7965. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7966. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7967. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7968. }
  7969. //AddRoundKey
  7970. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7971. state[j] ^= key[k];
  7972. }
  7973. }
  7974. //SubBytes
  7975. for (j = 0; j < 16; ++j) {
  7976. state[j] = s[state[j]];
  7977. }
  7978. //ShiftRows
  7979. v = state[1];
  7980. state[1] = state[5];
  7981. state[5] = state[9];
  7982. state[9] = state[13];
  7983. state[13] = v;
  7984. v = state[2];
  7985. u = state[6];
  7986. state[2] = state[10];
  7987. state[6] = state[14];
  7988. state[10] = v;
  7989. state[14] = u;
  7990. v = state[3];
  7991. u = state[7];
  7992. t = state[11];
  7993. state[3] = state[15];
  7994. state[7] = v;
  7995. state[11] = u;
  7996. state[15] = t;
  7997. //AddRoundKey
  7998. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7999. state[j] ^= key[k];
  8000. }
  8001. return state;
  8002. }
  8003. function AES128Cipher(key) {
  8004. this.key = expandKey128(key);
  8005. this.buffer = new Uint8Array(16);
  8006. this.bufferPosition = 0;
  8007. }
  8008. function decryptBlock2(data, finalize) {
  8009. var i, j, ii, sourceLength = data.length,
  8010. buffer = this.buffer, bufferLength = this.bufferPosition,
  8011. result = [], iv = this.iv;
  8012. for (i = 0; i < sourceLength; ++i) {
  8013. buffer[bufferLength] = data[i];
  8014. ++bufferLength;
  8015. if (bufferLength < 16) {
  8016. continue;
  8017. }
  8018. // buffer is full, decrypting
  8019. var plain = decrypt128(buffer, this.key);
  8020. // xor-ing the IV vector to get plain text
  8021. for (j = 0; j < 16; ++j) {
  8022. plain[j] ^= iv[j];
  8023. }
  8024. iv = buffer;
  8025. result.push(plain);
  8026. buffer = new Uint8Array(16);
  8027. bufferLength = 0;
  8028. }
  8029. // saving incomplete buffer
  8030. this.buffer = buffer;
  8031. this.bufferLength = bufferLength;
  8032. this.iv = iv;
  8033. if (result.length === 0) {
  8034. return new Uint8Array([]);
  8035. }
  8036. // combining plain text blocks into one
  8037. var outputLength = 16 * result.length;
  8038. if (finalize) {
  8039. // undo a padding that is described in RFC 2898
  8040. var lastBlock = result[result.length - 1];
  8041. var psLen = lastBlock[15];
  8042. if (psLen <= 16) {
  8043. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8044. if (lastBlock[i] !== psLen) {
  8045. // Invalid padding, assume that the block has no padding.
  8046. psLen = 0;
  8047. break;
  8048. }
  8049. }
  8050. outputLength -= psLen;
  8051. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8052. }
  8053. }
  8054. var output = new Uint8Array(outputLength);
  8055. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8056. output.set(result[i], j);
  8057. }
  8058. return output;
  8059. }
  8060. AES128Cipher.prototype = {
  8061. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  8062. var i, sourceLength = data.length;
  8063. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8064. // waiting for IV values -- they are at the start of the stream
  8065. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  8066. buffer[bufferLength] = data[i];
  8067. }
  8068. if (bufferLength < 16) {
  8069. // need more data
  8070. this.bufferLength = bufferLength;
  8071. return new Uint8Array([]);
  8072. }
  8073. this.iv = buffer;
  8074. this.buffer = new Uint8Array(16);
  8075. this.bufferLength = 0;
  8076. // starting decryption
  8077. this.decryptBlock = decryptBlock2;
  8078. return this.decryptBlock(data.subarray(16), finalize);
  8079. },
  8080. encrypt: function AES128Cipher_encrypt(data, iv) {
  8081. var i, j, ii, sourceLength = data.length,
  8082. buffer = this.buffer, bufferLength = this.bufferPosition,
  8083. result = [];
  8084. if (!iv) {
  8085. iv = new Uint8Array(16);
  8086. }
  8087. for (i = 0; i < sourceLength; ++i) {
  8088. buffer[bufferLength] = data[i];
  8089. ++bufferLength;
  8090. if (bufferLength < 16) {
  8091. continue;
  8092. }
  8093. for (j = 0; j < 16; ++j) {
  8094. buffer[j] ^= iv[j];
  8095. }
  8096. // buffer is full, encrypting
  8097. var cipher = encrypt128(buffer, this.key);
  8098. iv = cipher;
  8099. result.push(cipher);
  8100. buffer = new Uint8Array(16);
  8101. bufferLength = 0;
  8102. }
  8103. // saving incomplete buffer
  8104. this.buffer = buffer;
  8105. this.bufferLength = bufferLength;
  8106. this.iv = iv;
  8107. if (result.length === 0) {
  8108. return new Uint8Array([]);
  8109. }
  8110. // combining plain text blocks into one
  8111. var outputLength = 16 * result.length;
  8112. var output = new Uint8Array(outputLength);
  8113. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8114. output.set(result[i], j);
  8115. }
  8116. return output;
  8117. }
  8118. };
  8119. return AES128Cipher;
  8120. })();
  8121. var AES256Cipher = (function AES256CipherClosure() {
  8122. var rcon = new Uint8Array([
  8123. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8124. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8125. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8126. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8127. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8128. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8129. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8130. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8131. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8132. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8133. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8134. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8135. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8136. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8137. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8138. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8139. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8140. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8141. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8142. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8143. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8144. 0x74, 0xe8, 0xcb, 0x8d]);
  8145. var s = new Uint8Array([
  8146. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8147. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8148. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8149. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8150. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8151. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8152. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8153. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8154. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8155. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8156. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8157. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8158. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8159. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8160. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8161. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8162. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8163. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8164. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8165. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8166. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8167. 0xb0, 0x54, 0xbb, 0x16]);
  8168. var inv_s = new Uint8Array([
  8169. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8170. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8171. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8172. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8173. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8174. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8175. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8176. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8177. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8178. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8179. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8180. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8181. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8182. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8183. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8184. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8185. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8186. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8187. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8188. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8189. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8190. 0x55, 0x21, 0x0c, 0x7d]);
  8191. var mixCol = new Uint8Array(256);
  8192. for (var i = 0; i < 256; i++) {
  8193. if (i < 128) {
  8194. mixCol[i] = i << 1;
  8195. } else {
  8196. mixCol[i] = (i << 1) ^ 0x1b;
  8197. }
  8198. }
  8199. var mix = new Uint32Array([
  8200. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8201. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8202. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8203. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8204. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8205. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8206. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8207. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8208. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8209. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8210. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8211. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8212. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8213. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8214. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8215. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8216. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8217. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8218. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8219. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8220. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8221. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8222. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8223. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8224. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8225. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8226. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8227. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8228. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8229. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8230. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8231. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8232. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8233. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8234. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8235. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8236. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8237. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8238. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8239. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8240. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8241. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8242. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8243. function expandKey256(cipherKey) {
  8244. var b = 240, result = new Uint8Array(b);
  8245. var r = 1;
  8246. result.set(cipherKey);
  8247. for (var j = 32, i = 1; j < b; ++i) {
  8248. if (j % 32 === 16) {
  8249. t1 = s[t1];
  8250. t2 = s[t2];
  8251. t3 = s[t3];
  8252. t4 = s[t4];
  8253. } else if (j % 32 === 0) {
  8254. // RotWord
  8255. var t1 = result[j - 3], t2 = result[j - 2],
  8256. t3 = result[j - 1], t4 = result[j - 4];
  8257. // SubWord
  8258. t1 = s[t1];
  8259. t2 = s[t2];
  8260. t3 = s[t3];
  8261. t4 = s[t4];
  8262. // Rcon
  8263. t1 = t1 ^ r;
  8264. if ((r <<= 1) >= 256) {
  8265. r = (r ^ 0x1b) & 0xFF;
  8266. }
  8267. }
  8268. for (var n = 0; n < 4; ++n) {
  8269. result[j] = (t1 ^= result[j - 32]);
  8270. j++;
  8271. result[j] = (t2 ^= result[j - 32]);
  8272. j++;
  8273. result[j] = (t3 ^= result[j - 32]);
  8274. j++;
  8275. result[j] = (t4 ^= result[j - 32]);
  8276. j++;
  8277. }
  8278. }
  8279. return result;
  8280. }
  8281. function decrypt256(input, key) {
  8282. var state = new Uint8Array(16);
  8283. state.set(input);
  8284. var i, j, k;
  8285. var t, u, v;
  8286. // AddRoundKey
  8287. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8288. state[j] ^= key[k];
  8289. }
  8290. for (i = 13; i >= 1; --i) {
  8291. // InvShiftRows
  8292. t = state[13];
  8293. state[13] = state[9];
  8294. state[9] = state[5];
  8295. state[5] = state[1];
  8296. state[1] = t;
  8297. t = state[14];
  8298. u = state[10];
  8299. state[14] = state[6];
  8300. state[10] = state[2];
  8301. state[6] = t;
  8302. state[2] = u;
  8303. t = state[15];
  8304. u = state[11];
  8305. v = state[7];
  8306. state[15] = state[3];
  8307. state[11] = t;
  8308. state[7] = u;
  8309. state[3] = v;
  8310. // InvSubBytes
  8311. for (j = 0; j < 16; ++j) {
  8312. state[j] = inv_s[state[j]];
  8313. }
  8314. // AddRoundKey
  8315. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8316. state[j] ^= key[k];
  8317. }
  8318. // InvMixColumns
  8319. for (j = 0; j < 16; j += 4) {
  8320. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8321. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8322. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8323. (s3 >>> 24) ^ (s3 << 8));
  8324. state[j] = (t >>> 24) & 0xFF;
  8325. state[j + 1] = (t >> 16) & 0xFF;
  8326. state[j + 2] = (t >> 8) & 0xFF;
  8327. state[j + 3] = t & 0xFF;
  8328. }
  8329. }
  8330. // InvShiftRows
  8331. t = state[13];
  8332. state[13] = state[9];
  8333. state[9] = state[5];
  8334. state[5] = state[1];
  8335. state[1] = t;
  8336. t = state[14];
  8337. u = state[10];
  8338. state[14] = state[6];
  8339. state[10] = state[2];
  8340. state[6] = t;
  8341. state[2] = u;
  8342. t = state[15];
  8343. u = state[11];
  8344. v = state[7];
  8345. state[15] = state[3];
  8346. state[11] = t;
  8347. state[7] = u;
  8348. state[3] = v;
  8349. for (j = 0; j < 16; ++j) {
  8350. // InvSubBytes
  8351. state[j] = inv_s[state[j]];
  8352. // AddRoundKey
  8353. state[j] ^= key[j];
  8354. }
  8355. return state;
  8356. }
  8357. function encrypt256(input, key) {
  8358. var t, u, v, k;
  8359. var state = new Uint8Array(16);
  8360. state.set(input);
  8361. for (j = 0; j < 16; ++j) {
  8362. // AddRoundKey
  8363. state[j] ^= key[j];
  8364. }
  8365. for (i = 1; i < 14; i++) {
  8366. //SubBytes
  8367. for (j = 0; j < 16; ++j) {
  8368. state[j] = s[state[j]];
  8369. }
  8370. //ShiftRows
  8371. v = state[1];
  8372. state[1] = state[5];
  8373. state[5] = state[9];
  8374. state[9] = state[13];
  8375. state[13] = v;
  8376. v = state[2];
  8377. u = state[6];
  8378. state[2] = state[10];
  8379. state[6] = state[14];
  8380. state[10] = v;
  8381. state[14] = u;
  8382. v = state[3];
  8383. u = state[7];
  8384. t = state[11];
  8385. state[3] = state[15];
  8386. state[7] = v;
  8387. state[11] = u;
  8388. state[15] = t;
  8389. //MixColumns
  8390. for (var j = 0; j < 16; j += 4) {
  8391. var s0 = state[j + 0], s1 = state[j + 1];
  8392. var s2 = state[j + 2], s3 = state[j + 3];
  8393. t = s0 ^ s1 ^ s2 ^ s3;
  8394. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8395. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8396. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8397. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8398. }
  8399. //AddRoundKey
  8400. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8401. state[j] ^= key[k];
  8402. }
  8403. }
  8404. //SubBytes
  8405. for (j = 0; j < 16; ++j) {
  8406. state[j] = s[state[j]];
  8407. }
  8408. //ShiftRows
  8409. v = state[1];
  8410. state[1] = state[5];
  8411. state[5] = state[9];
  8412. state[9] = state[13];
  8413. state[13] = v;
  8414. v = state[2];
  8415. u = state[6];
  8416. state[2] = state[10];
  8417. state[6] = state[14];
  8418. state[10] = v;
  8419. state[14] = u;
  8420. v = state[3];
  8421. u = state[7];
  8422. t = state[11];
  8423. state[3] = state[15];
  8424. state[7] = v;
  8425. state[11] = u;
  8426. state[15] = t;
  8427. //AddRoundKey
  8428. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8429. state[j] ^= key[k];
  8430. }
  8431. return state;
  8432. }
  8433. function AES256Cipher(key) {
  8434. this.key = expandKey256(key);
  8435. this.buffer = new Uint8Array(16);
  8436. this.bufferPosition = 0;
  8437. }
  8438. function decryptBlock2(data, finalize) {
  8439. var i, j, ii, sourceLength = data.length,
  8440. buffer = this.buffer, bufferLength = this.bufferPosition,
  8441. result = [], iv = this.iv;
  8442. for (i = 0; i < sourceLength; ++i) {
  8443. buffer[bufferLength] = data[i];
  8444. ++bufferLength;
  8445. if (bufferLength < 16) {
  8446. continue;
  8447. }
  8448. // buffer is full, decrypting
  8449. var plain = decrypt256(buffer, this.key);
  8450. // xor-ing the IV vector to get plain text
  8451. for (j = 0; j < 16; ++j) {
  8452. plain[j] ^= iv[j];
  8453. }
  8454. iv = buffer;
  8455. result.push(plain);
  8456. buffer = new Uint8Array(16);
  8457. bufferLength = 0;
  8458. }
  8459. // saving incomplete buffer
  8460. this.buffer = buffer;
  8461. this.bufferLength = bufferLength;
  8462. this.iv = iv;
  8463. if (result.length === 0) {
  8464. return new Uint8Array([]);
  8465. }
  8466. // combining plain text blocks into one
  8467. var outputLength = 16 * result.length;
  8468. if (finalize) {
  8469. // undo a padding that is described in RFC 2898
  8470. var lastBlock = result[result.length - 1];
  8471. var psLen = lastBlock[15];
  8472. if (psLen <= 16) {
  8473. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8474. if (lastBlock[i] !== psLen) {
  8475. // Invalid padding, assume that the block has no padding.
  8476. psLen = 0;
  8477. break;
  8478. }
  8479. }
  8480. outputLength -= psLen;
  8481. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8482. }
  8483. }
  8484. var output = new Uint8Array(outputLength);
  8485. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8486. output.set(result[i], j);
  8487. }
  8488. return output;
  8489. }
  8490. AES256Cipher.prototype = {
  8491. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8492. var i, sourceLength = data.length;
  8493. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8494. // if not supplied an IV wait for IV values
  8495. // they are at the start of the stream
  8496. if (iv) {
  8497. this.iv = iv;
  8498. } else {
  8499. for (i = 0; bufferLength < 16 &&
  8500. i < sourceLength; ++i, ++bufferLength) {
  8501. buffer[bufferLength] = data[i];
  8502. }
  8503. if (bufferLength < 16) {
  8504. //need more data
  8505. this.bufferLength = bufferLength;
  8506. return new Uint8Array([]);
  8507. }
  8508. this.iv = buffer;
  8509. data = data.subarray(16);
  8510. }
  8511. this.buffer = new Uint8Array(16);
  8512. this.bufferLength = 0;
  8513. // starting decryption
  8514. this.decryptBlock = decryptBlock2;
  8515. return this.decryptBlock(data, finalize);
  8516. },
  8517. encrypt: function AES256Cipher_encrypt(data, iv) {
  8518. var i, j, ii, sourceLength = data.length,
  8519. buffer = this.buffer, bufferLength = this.bufferPosition,
  8520. result = [];
  8521. if (!iv) {
  8522. iv = new Uint8Array(16);
  8523. }
  8524. for (i = 0; i < sourceLength; ++i) {
  8525. buffer[bufferLength] = data[i];
  8526. ++bufferLength;
  8527. if (bufferLength < 16) {
  8528. continue;
  8529. }
  8530. for (j = 0; j < 16; ++j) {
  8531. buffer[j] ^= iv[j];
  8532. }
  8533. // buffer is full, encrypting
  8534. var cipher = encrypt256(buffer, this.key);
  8535. this.iv = cipher;
  8536. result.push(cipher);
  8537. buffer = new Uint8Array(16);
  8538. bufferLength = 0;
  8539. }
  8540. // saving incomplete buffer
  8541. this.buffer = buffer;
  8542. this.bufferLength = bufferLength;
  8543. this.iv = iv;
  8544. if (result.length === 0) {
  8545. return new Uint8Array([]);
  8546. }
  8547. // combining plain text blocks into one
  8548. var outputLength = 16 * result.length;
  8549. var output = new Uint8Array(outputLength);
  8550. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8551. output.set(result[i], j);
  8552. }
  8553. return output;
  8554. }
  8555. };
  8556. return AES256Cipher;
  8557. })();
  8558. var PDF17 = (function PDF17Closure() {
  8559. function compareByteArrays(array1, array2) {
  8560. if (array1.length !== array2.length) {
  8561. return false;
  8562. }
  8563. for (var i = 0; i < array1.length; i++) {
  8564. if (array1[i] !== array2[i]) {
  8565. return false;
  8566. }
  8567. }
  8568. return true;
  8569. }
  8570. function PDF17() {
  8571. }
  8572. PDF17.prototype = {
  8573. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8574. ownerValidationSalt,
  8575. userBytes,
  8576. ownerPassword) {
  8577. var hashData = new Uint8Array(password.length + 56);
  8578. hashData.set(password, 0);
  8579. hashData.set(ownerValidationSalt, password.length);
  8580. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8581. var result = calculateSHA256(hashData, 0, hashData.length);
  8582. return compareByteArrays(result, ownerPassword);
  8583. },
  8584. checkUserPassword: function PDF17_checkUserPassword(password,
  8585. userValidationSalt,
  8586. userPassword) {
  8587. var hashData = new Uint8Array(password.length + 8);
  8588. hashData.set(password, 0);
  8589. hashData.set(userValidationSalt, password.length);
  8590. var result = calculateSHA256(hashData, 0, hashData.length);
  8591. return compareByteArrays(result, userPassword);
  8592. },
  8593. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8594. ownerEncryption) {
  8595. var hashData = new Uint8Array(password.length + 56);
  8596. hashData.set(password, 0);
  8597. hashData.set(ownerKeySalt, password.length);
  8598. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8599. var key = calculateSHA256(hashData, 0, hashData.length);
  8600. var cipher = new AES256Cipher(key);
  8601. return cipher.decryptBlock(ownerEncryption,
  8602. false,
  8603. new Uint8Array(16));
  8604. },
  8605. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8606. userEncryption) {
  8607. var hashData = new Uint8Array(password.length + 8);
  8608. hashData.set(password, 0);
  8609. hashData.set(userKeySalt, password.length);
  8610. //key is the decryption key for the UE string
  8611. var key = calculateSHA256(hashData, 0, hashData.length);
  8612. var cipher = new AES256Cipher(key);
  8613. return cipher.decryptBlock(userEncryption,
  8614. false,
  8615. new Uint8Array(16));
  8616. }
  8617. };
  8618. return PDF17;
  8619. })();
  8620. var PDF20 = (function PDF20Closure() {
  8621. function concatArrays(array1, array2) {
  8622. var t = new Uint8Array(array1.length + array2.length);
  8623. t.set(array1, 0);
  8624. t.set(array2, array1.length);
  8625. return t;
  8626. }
  8627. function calculatePDF20Hash(password, input, userBytes) {
  8628. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8629. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8630. var e = [0];
  8631. var i = 0;
  8632. while (i < 64 || e[e.length - 1] > i - 32) {
  8633. var arrayLength = password.length + k.length + userBytes.length;
  8634. var k1 = new Uint8Array(arrayLength * 64);
  8635. var array = concatArrays(password, k);
  8636. array = concatArrays(array, userBytes);
  8637. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8638. k1.set(array, pos);
  8639. }
  8640. //AES128 CBC NO PADDING with
  8641. //first 16 bytes of k as the key and the second 16 as the iv.
  8642. var cipher = new AES128Cipher(k.subarray(0, 16));
  8643. e = cipher.encrypt(k1, k.subarray(16, 32));
  8644. //Now we have to take the first 16 bytes of an unsigned
  8645. //big endian integer... and compute the remainder
  8646. //modulo 3.... That is a fairly large number and
  8647. //JavaScript isn't going to handle that well...
  8648. //So we're using a trick that allows us to perform
  8649. //modulo math byte by byte
  8650. var remainder = 0;
  8651. for (var z = 0; z < 16; z++) {
  8652. remainder *= (256 % 3);
  8653. remainder %= 3;
  8654. remainder += ((e[z] >>> 0) % 3);
  8655. remainder %= 3;
  8656. }
  8657. if (remainder === 0) {
  8658. k = calculateSHA256(e, 0, e.length);
  8659. }
  8660. else if (remainder === 1) {
  8661. k = calculateSHA384(e, 0, e.length);
  8662. }
  8663. else if (remainder === 2) {
  8664. k = calculateSHA512(e, 0, e.length);
  8665. }
  8666. i++;
  8667. }
  8668. return k.subarray(0, 32);
  8669. }
  8670. function PDF20() {
  8671. }
  8672. function compareByteArrays(array1, array2) {
  8673. if (array1.length !== array2.length) {
  8674. return false;
  8675. }
  8676. for (var i = 0; i < array1.length; i++) {
  8677. if (array1[i] !== array2[i]) {
  8678. return false;
  8679. }
  8680. }
  8681. return true;
  8682. }
  8683. PDF20.prototype = {
  8684. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8685. return calculatePDF20Hash(password, concatBytes, userBytes);
  8686. },
  8687. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8688. ownerValidationSalt,
  8689. userBytes,
  8690. ownerPassword) {
  8691. var hashData = new Uint8Array(password.length + 56);
  8692. hashData.set(password, 0);
  8693. hashData.set(ownerValidationSalt, password.length);
  8694. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8695. var result = calculatePDF20Hash(password, hashData, userBytes);
  8696. return compareByteArrays(result, ownerPassword);
  8697. },
  8698. checkUserPassword: function PDF20_checkUserPassword(password,
  8699. userValidationSalt,
  8700. userPassword) {
  8701. var hashData = new Uint8Array(password.length + 8);
  8702. hashData.set(password, 0);
  8703. hashData.set(userValidationSalt, password.length);
  8704. var result = calculatePDF20Hash(password, hashData, []);
  8705. return compareByteArrays(result, userPassword);
  8706. },
  8707. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8708. ownerEncryption) {
  8709. var hashData = new Uint8Array(password.length + 56);
  8710. hashData.set(password, 0);
  8711. hashData.set(ownerKeySalt, password.length);
  8712. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8713. var key = calculatePDF20Hash(password, hashData, userBytes);
  8714. var cipher = new AES256Cipher(key);
  8715. return cipher.decryptBlock(ownerEncryption,
  8716. false,
  8717. new Uint8Array(16));
  8718. },
  8719. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8720. userEncryption) {
  8721. var hashData = new Uint8Array(password.length + 8);
  8722. hashData.set(password, 0);
  8723. hashData.set(userKeySalt, password.length);
  8724. //key is the decryption key for the UE string
  8725. var key = calculatePDF20Hash(password, hashData, []);
  8726. var cipher = new AES256Cipher(key);
  8727. return cipher.decryptBlock(userEncryption,
  8728. false,
  8729. new Uint8Array(16));
  8730. }
  8731. };
  8732. return PDF20;
  8733. })();
  8734. var CipherTransform = (function CipherTransformClosure() {
  8735. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8736. this.stringCipherConstructor = stringCipherConstructor;
  8737. this.streamCipherConstructor = streamCipherConstructor;
  8738. }
  8739. CipherTransform.prototype = {
  8740. createStream: function CipherTransform_createStream(stream, length) {
  8741. var cipher = new this.streamCipherConstructor();
  8742. return new DecryptStream(stream, length,
  8743. function cipherTransformDecryptStream(data, finalize) {
  8744. return cipher.decryptBlock(data, finalize);
  8745. }
  8746. );
  8747. },
  8748. decryptString: function CipherTransform_decryptString(s) {
  8749. var cipher = new this.stringCipherConstructor();
  8750. var data = stringToBytes(s);
  8751. data = cipher.decryptBlock(data, true);
  8752. return bytesToString(data);
  8753. }
  8754. };
  8755. return CipherTransform;
  8756. })();
  8757. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8758. var defaultPasswordBytes = new Uint8Array([
  8759. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8760. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8761. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8762. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8763. function createEncryptionKey20(revision, password, ownerPassword,
  8764. ownerValidationSalt, ownerKeySalt, uBytes,
  8765. userPassword, userValidationSalt, userKeySalt,
  8766. ownerEncryption, userEncryption, perms) {
  8767. if (password) {
  8768. var passwordLength = Math.min(127, password.length);
  8769. password = password.subarray(0, passwordLength);
  8770. } else {
  8771. password = [];
  8772. }
  8773. var pdfAlgorithm;
  8774. if (revision === 6) {
  8775. pdfAlgorithm = new PDF20();
  8776. } else {
  8777. pdfAlgorithm = new PDF17();
  8778. }
  8779. if (pdfAlgorithm) {
  8780. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8781. userPassword)) {
  8782. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8783. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8784. uBytes,
  8785. ownerPassword)) {
  8786. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8787. ownerEncryption);
  8788. }
  8789. }
  8790. return null;
  8791. }
  8792. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8793. flags, revision, keyLength, encryptMetadata) {
  8794. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8795. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8796. if (password) {
  8797. n = Math.min(32, password.length);
  8798. for (; i < n; ++i) {
  8799. hashData[i] = password[i];
  8800. }
  8801. }
  8802. j = 0;
  8803. while (i < 32) {
  8804. hashData[i++] = defaultPasswordBytes[j++];
  8805. }
  8806. // as now the padded password in the hashData[0..i]
  8807. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8808. hashData[i++] = ownerPassword[j];
  8809. }
  8810. hashData[i++] = flags & 0xFF;
  8811. hashData[i++] = (flags >> 8) & 0xFF;
  8812. hashData[i++] = (flags >> 16) & 0xFF;
  8813. hashData[i++] = (flags >>> 24) & 0xFF;
  8814. for (j = 0, n = fileId.length; j < n; ++j) {
  8815. hashData[i++] = fileId[j];
  8816. }
  8817. if (revision >= 4 && !encryptMetadata) {
  8818. hashData[i++] = 0xFF;
  8819. hashData[i++] = 0xFF;
  8820. hashData[i++] = 0xFF;
  8821. hashData[i++] = 0xFF;
  8822. }
  8823. var hash = calculateMD5(hashData, 0, i);
  8824. var keyLengthInBytes = keyLength >> 3;
  8825. if (revision >= 3) {
  8826. for (j = 0; j < 50; ++j) {
  8827. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8828. }
  8829. }
  8830. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8831. var cipher, checkData;
  8832. if (revision >= 3) {
  8833. for (i = 0; i < 32; ++i) {
  8834. hashData[i] = defaultPasswordBytes[i];
  8835. }
  8836. for (j = 0, n = fileId.length; j < n; ++j) {
  8837. hashData[i++] = fileId[j];
  8838. }
  8839. cipher = new ARCFourCipher(encryptionKey);
  8840. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8841. n = encryptionKey.length;
  8842. var derivedKey = new Uint8Array(n), k;
  8843. for (j = 1; j <= 19; ++j) {
  8844. for (k = 0; k < n; ++k) {
  8845. derivedKey[k] = encryptionKey[k] ^ j;
  8846. }
  8847. cipher = new ARCFourCipher(derivedKey);
  8848. checkData = cipher.encryptBlock(checkData);
  8849. }
  8850. for (j = 0, n = checkData.length; j < n; ++j) {
  8851. if (userPassword[j] !== checkData[j]) {
  8852. return null;
  8853. }
  8854. }
  8855. } else {
  8856. cipher = new ARCFourCipher(encryptionKey);
  8857. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8858. for (j = 0, n = checkData.length; j < n; ++j) {
  8859. if (userPassword[j] !== checkData[j]) {
  8860. return null;
  8861. }
  8862. }
  8863. }
  8864. return encryptionKey;
  8865. }
  8866. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8867. var hashData = new Uint8Array(32), i = 0, j, n;
  8868. n = Math.min(32, password.length);
  8869. for (; i < n; ++i) {
  8870. hashData[i] = password[i];
  8871. }
  8872. j = 0;
  8873. while (i < 32) {
  8874. hashData[i++] = defaultPasswordBytes[j++];
  8875. }
  8876. var hash = calculateMD5(hashData, 0, i);
  8877. var keyLengthInBytes = keyLength >> 3;
  8878. if (revision >= 3) {
  8879. for (j = 0; j < 50; ++j) {
  8880. hash = calculateMD5(hash, 0, hash.length);
  8881. }
  8882. }
  8883. var cipher, userPassword;
  8884. if (revision >= 3) {
  8885. userPassword = ownerPassword;
  8886. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8887. for (j = 19; j >= 0; j--) {
  8888. for (k = 0; k < keyLengthInBytes; ++k) {
  8889. derivedKey[k] = hash[k] ^ j;
  8890. }
  8891. cipher = new ARCFourCipher(derivedKey);
  8892. userPassword = cipher.encryptBlock(userPassword);
  8893. }
  8894. } else {
  8895. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8896. userPassword = cipher.encryptBlock(ownerPassword);
  8897. }
  8898. return userPassword;
  8899. }
  8900. var identityName = Name.get('Identity');
  8901. function CipherTransformFactory(dict, fileId, password) {
  8902. var filter = dict.get('Filter');
  8903. if (!isName(filter) || filter.name !== 'Standard') {
  8904. error('unknown encryption method');
  8905. }
  8906. this.dict = dict;
  8907. var algorithm = dict.get('V');
  8908. if (!isInt(algorithm) ||
  8909. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8910. algorithm !== 5)) {
  8911. error('unsupported encryption algorithm');
  8912. }
  8913. this.algorithm = algorithm;
  8914. var keyLength = dict.get('Length') || 40;
  8915. if (!isInt(keyLength) ||
  8916. keyLength < 40 || (keyLength % 8) !== 0) {
  8917. error('invalid key length');
  8918. }
  8919. // prepare keys
  8920. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8921. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8922. var flags = dict.get('P');
  8923. var revision = dict.get('R');
  8924. // meaningful when V is 4 or 5
  8925. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8926. dict.get('EncryptMetadata') !== false);
  8927. this.encryptMetadata = encryptMetadata;
  8928. var fileIdBytes = stringToBytes(fileId);
  8929. var passwordBytes;
  8930. if (password) {
  8931. if (revision === 6) {
  8932. try {
  8933. password = utf8StringToString(password);
  8934. } catch (ex) {
  8935. warn('CipherTransformFactory: ' +
  8936. 'Unable to convert UTF8 encoded password.');
  8937. }
  8938. }
  8939. passwordBytes = stringToBytes(password);
  8940. }
  8941. var encryptionKey;
  8942. if (algorithm !== 5) {
  8943. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8944. ownerPassword, userPassword, flags,
  8945. revision, keyLength, encryptMetadata);
  8946. }
  8947. else {
  8948. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8949. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8950. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8951. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8952. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8953. var ownerEncryption = stringToBytes(dict.get('OE'));
  8954. var userEncryption = stringToBytes(dict.get('UE'));
  8955. var perms = stringToBytes(dict.get('Perms'));
  8956. encryptionKey =
  8957. createEncryptionKey20(revision, passwordBytes,
  8958. ownerPassword, ownerValidationSalt,
  8959. ownerKeySalt, uBytes,
  8960. userPassword, userValidationSalt,
  8961. userKeySalt, ownerEncryption,
  8962. userEncryption, perms);
  8963. }
  8964. if (!encryptionKey && !password) {
  8965. throw new PasswordException('No password given',
  8966. PasswordResponses.NEED_PASSWORD);
  8967. } else if (!encryptionKey && password) {
  8968. // Attempting use the password as an owner password
  8969. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8970. revision, keyLength);
  8971. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8972. ownerPassword, userPassword, flags,
  8973. revision, keyLength, encryptMetadata);
  8974. }
  8975. if (!encryptionKey) {
  8976. throw new PasswordException('Incorrect Password',
  8977. PasswordResponses.INCORRECT_PASSWORD);
  8978. }
  8979. this.encryptionKey = encryptionKey;
  8980. if (algorithm >= 4) {
  8981. this.cf = dict.get('CF');
  8982. this.stmf = dict.get('StmF') || identityName;
  8983. this.strf = dict.get('StrF') || identityName;
  8984. this.eff = dict.get('EFF') || this.stmf;
  8985. }
  8986. }
  8987. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8988. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8989. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8990. key[i] = encryptionKey[i];
  8991. }
  8992. key[i++] = num & 0xFF;
  8993. key[i++] = (num >> 8) & 0xFF;
  8994. key[i++] = (num >> 16) & 0xFF;
  8995. key[i++] = gen & 0xFF;
  8996. key[i++] = (gen >> 8) & 0xFF;
  8997. if (isAes) {
  8998. key[i++] = 0x73;
  8999. key[i++] = 0x41;
  9000. key[i++] = 0x6C;
  9001. key[i++] = 0x54;
  9002. }
  9003. var hash = calculateMD5(key, 0, i);
  9004. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  9005. }
  9006. function buildCipherConstructor(cf, name, num, gen, key) {
  9007. var cryptFilter = cf.get(name.name);
  9008. var cfm;
  9009. if (cryptFilter !== null && cryptFilter !== undefined) {
  9010. cfm = cryptFilter.get('CFM');
  9011. }
  9012. if (!cfm || cfm.name === 'None') {
  9013. return function cipherTransformFactoryBuildCipherConstructorNone() {
  9014. return new NullCipher();
  9015. };
  9016. }
  9017. if ('V2' === cfm.name) {
  9018. return function cipherTransformFactoryBuildCipherConstructorV2() {
  9019. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  9020. };
  9021. }
  9022. if ('AESV2' === cfm.name) {
  9023. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  9024. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  9025. };
  9026. }
  9027. if ('AESV3' === cfm.name) {
  9028. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  9029. return new AES256Cipher(key);
  9030. };
  9031. }
  9032. error('Unknown crypto method');
  9033. }
  9034. CipherTransformFactory.prototype = {
  9035. createCipherTransform:
  9036. function CipherTransformFactory_createCipherTransform(num, gen) {
  9037. if (this.algorithm === 4 || this.algorithm === 5) {
  9038. return new CipherTransform(
  9039. buildCipherConstructor(this.cf, this.stmf,
  9040. num, gen, this.encryptionKey),
  9041. buildCipherConstructor(this.cf, this.strf,
  9042. num, gen, this.encryptionKey));
  9043. }
  9044. // algorithms 1 and 2
  9045. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  9046. var cipherConstructor = function buildCipherCipherConstructor() {
  9047. return new ARCFourCipher(key);
  9048. };
  9049. return new CipherTransform(cipherConstructor, cipherConstructor);
  9050. }
  9051. };
  9052. return CipherTransformFactory;
  9053. })();
  9054. var PatternType = {
  9055. FUNCTION_BASED: 1,
  9056. AXIAL: 2,
  9057. RADIAL: 3,
  9058. FREE_FORM_MESH: 4,
  9059. LATTICE_FORM_MESH: 5,
  9060. COONS_PATCH_MESH: 6,
  9061. TENSOR_PATCH_MESH: 7
  9062. };
  9063. var Pattern = (function PatternClosure() {
  9064. // Constructor should define this.getPattern
  9065. function Pattern() {
  9066. error('should not call Pattern constructor');
  9067. }
  9068. Pattern.prototype = {
  9069. // Input: current Canvas context
  9070. // Output: the appropriate fillStyle or strokeStyle
  9071. getPattern: function Pattern_getPattern(ctx) {
  9072. error('Should not call Pattern.getStyle: ' + ctx);
  9073. }
  9074. };
  9075. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  9076. res) {
  9077. var dict = isStream(shading) ? shading.dict : shading;
  9078. var type = dict.get('ShadingType');
  9079. try {
  9080. switch (type) {
  9081. case PatternType.AXIAL:
  9082. case PatternType.RADIAL:
  9083. // Both radial and axial shadings are handled by RadialAxial shading.
  9084. return new Shadings.RadialAxial(dict, matrix, xref, res);
  9085. case PatternType.FREE_FORM_MESH:
  9086. case PatternType.LATTICE_FORM_MESH:
  9087. case PatternType.COONS_PATCH_MESH:
  9088. case PatternType.TENSOR_PATCH_MESH:
  9089. return new Shadings.Mesh(shading, matrix, xref, res);
  9090. default:
  9091. throw new Error('Unknown PatternType: ' + type);
  9092. }
  9093. } catch (ex) {
  9094. if (ex instanceof MissingDataException) {
  9095. throw ex;
  9096. }
  9097. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  9098. warn(ex);
  9099. return new Shadings.Dummy();
  9100. }
  9101. };
  9102. return Pattern;
  9103. })();
  9104. var Shadings = {};
  9105. // A small number to offset the first/last color stops so we can insert ones to
  9106. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  9107. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  9108. // internally so we have to go bigger.
  9109. Shadings.SMALL_NUMBER = 1e-2;
  9110. // Radial and axial shading have very similar implementations
  9111. // If needed, the implementations can be broken into two classes
  9112. Shadings.RadialAxial = (function RadialAxialClosure() {
  9113. function RadialAxial(dict, matrix, xref, res) {
  9114. this.matrix = matrix;
  9115. this.coordsArr = dict.get('Coords');
  9116. this.shadingType = dict.get('ShadingType');
  9117. this.type = 'Pattern';
  9118. var cs = dict.get('ColorSpace', 'CS');
  9119. cs = ColorSpace.parse(cs, xref, res);
  9120. this.cs = cs;
  9121. var t0 = 0.0, t1 = 1.0;
  9122. if (dict.has('Domain')) {
  9123. var domainArr = dict.get('Domain');
  9124. t0 = domainArr[0];
  9125. t1 = domainArr[1];
  9126. }
  9127. var extendStart = false, extendEnd = false;
  9128. if (dict.has('Extend')) {
  9129. var extendArr = dict.get('Extend');
  9130. extendStart = extendArr[0];
  9131. extendEnd = extendArr[1];
  9132. }
  9133. if (this.shadingType === PatternType.RADIAL &&
  9134. (!extendStart || !extendEnd)) {
  9135. // Radial gradient only currently works if either circle is fully within
  9136. // the other circle.
  9137. var x1 = this.coordsArr[0];
  9138. var y1 = this.coordsArr[1];
  9139. var r1 = this.coordsArr[2];
  9140. var x2 = this.coordsArr[3];
  9141. var y2 = this.coordsArr[4];
  9142. var r2 = this.coordsArr[5];
  9143. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  9144. if (r1 <= r2 + distance &&
  9145. r2 <= r1 + distance) {
  9146. warn('Unsupported radial gradient.');
  9147. }
  9148. }
  9149. this.extendStart = extendStart;
  9150. this.extendEnd = extendEnd;
  9151. var fnObj = dict.get('Function');
  9152. var fn = PDFFunction.parseArray(xref, fnObj);
  9153. // 10 samples seems good enough for now, but probably won't work
  9154. // if there are sharp color changes. Ideally, we would implement
  9155. // the spec faithfully and add lossless optimizations.
  9156. var diff = t1 - t0;
  9157. var step = diff / 10;
  9158. var colorStops = this.colorStops = [];
  9159. // Protect against bad domains so we don't end up in an infinte loop below.
  9160. if (t0 >= t1 || step <= 0) {
  9161. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9162. // now.
  9163. info('Bad shading domain.');
  9164. return;
  9165. }
  9166. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9167. var rgbColor;
  9168. for (var i = t0; i <= t1; i += step) {
  9169. ratio[0] = i;
  9170. fn(ratio, 0, color, 0);
  9171. rgbColor = cs.getRgb(color, 0);
  9172. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9173. colorStops.push([(i - t0) / diff, cssColor]);
  9174. }
  9175. var background = 'transparent';
  9176. if (dict.has('Background')) {
  9177. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9178. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9179. }
  9180. if (!extendStart) {
  9181. // Insert a color stop at the front and offset the first real color stop
  9182. // so it doesn't conflict with the one we insert.
  9183. colorStops.unshift([0, background]);
  9184. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9185. }
  9186. if (!extendEnd) {
  9187. // Same idea as above in extendStart but for the end.
  9188. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9189. colorStops.push([1, background]);
  9190. }
  9191. this.colorStops = colorStops;
  9192. }
  9193. RadialAxial.prototype = {
  9194. getIR: function RadialAxial_getIR() {
  9195. var coordsArr = this.coordsArr;
  9196. var shadingType = this.shadingType;
  9197. var type, p0, p1, r0, r1;
  9198. if (shadingType === PatternType.AXIAL) {
  9199. p0 = [coordsArr[0], coordsArr[1]];
  9200. p1 = [coordsArr[2], coordsArr[3]];
  9201. r0 = null;
  9202. r1 = null;
  9203. type = 'axial';
  9204. } else if (shadingType === PatternType.RADIAL) {
  9205. p0 = [coordsArr[0], coordsArr[1]];
  9206. p1 = [coordsArr[3], coordsArr[4]];
  9207. r0 = coordsArr[2];
  9208. r1 = coordsArr[5];
  9209. type = 'radial';
  9210. } else {
  9211. error('getPattern type unknown: ' + shadingType);
  9212. }
  9213. var matrix = this.matrix;
  9214. if (matrix) {
  9215. p0 = Util.applyTransform(p0, matrix);
  9216. p1 = Util.applyTransform(p1, matrix);
  9217. }
  9218. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9219. }
  9220. };
  9221. return RadialAxial;
  9222. })();
  9223. // All mesh shading. For now, they will be presented as set of the triangles
  9224. // to be drawn on the canvas and rgb color for each vertex.
  9225. Shadings.Mesh = (function MeshClosure() {
  9226. function MeshStreamReader(stream, context) {
  9227. this.stream = stream;
  9228. this.context = context;
  9229. this.buffer = 0;
  9230. this.bufferLength = 0;
  9231. var numComps = context.numComps;
  9232. this.tmpCompsBuf = new Float32Array(numComps);
  9233. var csNumComps = context.colorSpace;
  9234. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9235. this.tmpCompsBuf;
  9236. }
  9237. MeshStreamReader.prototype = {
  9238. get hasData() {
  9239. if (this.stream.end) {
  9240. return this.stream.pos < this.stream.end;
  9241. }
  9242. if (this.bufferLength > 0) {
  9243. return true;
  9244. }
  9245. var nextByte = this.stream.getByte();
  9246. if (nextByte < 0) {
  9247. return false;
  9248. }
  9249. this.buffer = nextByte;
  9250. this.bufferLength = 8;
  9251. return true;
  9252. },
  9253. readBits: function MeshStreamReader_readBits(n) {
  9254. var buffer = this.buffer;
  9255. var bufferLength = this.bufferLength;
  9256. if (n === 32) {
  9257. if (bufferLength === 0) {
  9258. return ((this.stream.getByte() << 24) |
  9259. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9260. this.stream.getByte()) >>> 0;
  9261. }
  9262. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9263. (this.stream.getByte() << 8) | this.stream.getByte();
  9264. var nextByte = this.stream.getByte();
  9265. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9266. return ((buffer << (8 - bufferLength)) |
  9267. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9268. }
  9269. if (n === 8 && bufferLength === 0) {
  9270. return this.stream.getByte();
  9271. }
  9272. while (bufferLength < n) {
  9273. buffer = (buffer << 8) | this.stream.getByte();
  9274. bufferLength += 8;
  9275. }
  9276. bufferLength -= n;
  9277. this.bufferLength = bufferLength;
  9278. this.buffer = buffer & ((1 << bufferLength) - 1);
  9279. return buffer >> bufferLength;
  9280. },
  9281. align: function MeshStreamReader_align() {
  9282. this.buffer = 0;
  9283. this.bufferLength = 0;
  9284. },
  9285. readFlag: function MeshStreamReader_readFlag() {
  9286. return this.readBits(this.context.bitsPerFlag);
  9287. },
  9288. readCoordinate: function MeshStreamReader_readCoordinate() {
  9289. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9290. var xi = this.readBits(bitsPerCoordinate);
  9291. var yi = this.readBits(bitsPerCoordinate);
  9292. var decode = this.context.decode;
  9293. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9294. 2.3283064365386963e-10; // 2 ^ -32
  9295. return [
  9296. xi * scale * (decode[1] - decode[0]) + decode[0],
  9297. yi * scale * (decode[3] - decode[2]) + decode[2]
  9298. ];
  9299. },
  9300. readComponents: function MeshStreamReader_readComponents() {
  9301. var numComps = this.context.numComps;
  9302. var bitsPerComponent = this.context.bitsPerComponent;
  9303. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9304. 2.3283064365386963e-10; // 2 ^ -32
  9305. var decode = this.context.decode;
  9306. var components = this.tmpCompsBuf;
  9307. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9308. var ci = this.readBits(bitsPerComponent);
  9309. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9310. }
  9311. var color = this.tmpCsCompsBuf;
  9312. if (this.context.colorFn) {
  9313. this.context.colorFn(components, 0, color, 0);
  9314. }
  9315. return this.context.colorSpace.getRgb(color, 0);
  9316. }
  9317. };
  9318. function decodeType4Shading(mesh, reader) {
  9319. var coords = mesh.coords;
  9320. var colors = mesh.colors;
  9321. var operators = [];
  9322. var ps = []; // not maintaining cs since that will match ps
  9323. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9324. while (reader.hasData) {
  9325. var f = reader.readFlag();
  9326. var coord = reader.readCoordinate();
  9327. var color = reader.readComponents();
  9328. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9329. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9330. switch (f) {
  9331. case 0:
  9332. verticesLeft = 3;
  9333. break;
  9334. case 1:
  9335. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9336. verticesLeft = 1;
  9337. break;
  9338. case 2:
  9339. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9340. verticesLeft = 1;
  9341. break;
  9342. }
  9343. operators.push(f);
  9344. }
  9345. ps.push(coords.length);
  9346. coords.push(coord);
  9347. colors.push(color);
  9348. verticesLeft--;
  9349. reader.align();
  9350. }
  9351. var psPacked = new Int32Array(ps);
  9352. mesh.figures.push({
  9353. type: 'triangles',
  9354. coords: psPacked,
  9355. colors: psPacked
  9356. });
  9357. }
  9358. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9359. var coords = mesh.coords;
  9360. var colors = mesh.colors;
  9361. var ps = []; // not maintaining cs since that will match ps
  9362. while (reader.hasData) {
  9363. var coord = reader.readCoordinate();
  9364. var color = reader.readComponents();
  9365. ps.push(coords.length);
  9366. coords.push(coord);
  9367. colors.push(color);
  9368. }
  9369. var psPacked = new Int32Array(ps);
  9370. mesh.figures.push({
  9371. type: 'lattice',
  9372. coords: psPacked,
  9373. colors: psPacked,
  9374. verticesPerRow: verticesPerRow
  9375. });
  9376. }
  9377. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9378. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9379. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9380. var getB = (function getBClosure() {
  9381. function buildB(count) {
  9382. var lut = [];
  9383. for (var i = 0; i <= count; i++) {
  9384. var t = i / count, t_ = 1 - t;
  9385. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9386. 3 * t * t * t_, t * t * t]));
  9387. }
  9388. return lut;
  9389. }
  9390. var cache = [];
  9391. return function getB(count) {
  9392. if (!cache[count]) {
  9393. cache[count] = buildB(count);
  9394. }
  9395. return cache[count];
  9396. };
  9397. })();
  9398. function buildFigureFromPatch(mesh, index) {
  9399. var figure = mesh.figures[index];
  9400. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9401. var coords = mesh.coords, colors = mesh.colors;
  9402. var pi = figure.coords;
  9403. var ci = figure.colors;
  9404. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9405. coords[pi[12]][0], coords[pi[15]][0]);
  9406. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9407. coords[pi[12]][1], coords[pi[15]][1]);
  9408. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9409. coords[pi[12]][0], coords[pi[15]][0]);
  9410. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9411. coords[pi[12]][1], coords[pi[15]][1]);
  9412. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9413. (mesh.bounds[2] - mesh.bounds[0]));
  9414. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9415. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9416. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9417. (mesh.bounds[3] - mesh.bounds[1]));
  9418. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9419. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9420. var verticesPerRow = splitXBy + 1;
  9421. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9422. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9423. var k = 0;
  9424. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9425. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9426. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9427. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9428. for (var row = 0; row <= splitYBy; row++) {
  9429. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9430. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9431. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9432. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9433. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9434. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9435. for (var col = 0; col <= splitXBy; col++, k++) {
  9436. if ((row === 0 || row === splitYBy) &&
  9437. (col === 0 || col === splitXBy)) {
  9438. continue;
  9439. }
  9440. var x = 0, y = 0;
  9441. var q = 0;
  9442. for (var i = 0; i <= 3; i++) {
  9443. for (var j = 0; j <= 3; j++, q++) {
  9444. var m = bRow[row][i] * bCol[col][j];
  9445. x += coords[pi[q]][0] * m;
  9446. y += coords[pi[q]][1] * m;
  9447. }
  9448. }
  9449. figureCoords[k] = coords.length;
  9450. coords.push([x, y]);
  9451. figureColors[k] = colors.length;
  9452. var newColor = new Uint8Array(3);
  9453. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9454. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9455. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9456. colors.push(newColor);
  9457. }
  9458. }
  9459. figureCoords[0] = pi[0];
  9460. figureColors[0] = ci[0];
  9461. figureCoords[splitXBy] = pi[3];
  9462. figureColors[splitXBy] = ci[1];
  9463. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9464. figureColors[verticesPerRow * splitYBy] = ci[2];
  9465. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9466. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9467. mesh.figures[index] = {
  9468. type: 'lattice',
  9469. coords: figureCoords,
  9470. colors: figureColors,
  9471. verticesPerRow: verticesPerRow
  9472. };
  9473. }
  9474. function decodeType6Shading(mesh, reader) {
  9475. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9476. var coords = mesh.coords;
  9477. var colors = mesh.colors;
  9478. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9479. var cs = new Int32Array(4); // c00, c30, c03, c33
  9480. while (reader.hasData) {
  9481. var f = reader.readFlag();
  9482. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9483. var i, ii;
  9484. var pi = coords.length;
  9485. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9486. coords.push(reader.readCoordinate());
  9487. }
  9488. var ci = colors.length;
  9489. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9490. colors.push(reader.readComponents());
  9491. }
  9492. var tmp1, tmp2, tmp3, tmp4;
  9493. switch (f) {
  9494. case 0:
  9495. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9496. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9497. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9498. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9499. cs[2] = ci + 1; cs[3] = ci + 2;
  9500. cs[0] = ci; cs[1] = ci + 3;
  9501. break;
  9502. case 1:
  9503. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9504. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9505. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9506. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9507. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9508. tmp1 = cs[2]; tmp2 = cs[3];
  9509. cs[2] = ci + 1; cs[3] = ci;
  9510. cs[0] = tmp1; cs[1] = tmp2;
  9511. break;
  9512. case 2:
  9513. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9514. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9515. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9516. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9517. cs[2] = cs[3]; cs[3] = ci + 1;
  9518. cs[0] = cs[1]; cs[1] = ci;
  9519. break;
  9520. case 3:
  9521. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9522. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9523. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9524. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9525. cs[2] = cs[0]; cs[3] = cs[1];
  9526. cs[0] = ci; cs[1] = ci + 1;
  9527. break;
  9528. }
  9529. // set p11, p12, p21, p22
  9530. ps[5] = coords.length;
  9531. coords.push([
  9532. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9533. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9534. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9535. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9536. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9537. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9538. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9539. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9540. ]);
  9541. ps[6] = coords.length;
  9542. coords.push([
  9543. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9544. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9545. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9546. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9547. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9548. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9549. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9550. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9551. ]);
  9552. ps[9] = coords.length;
  9553. coords.push([
  9554. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9555. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9556. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9557. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9558. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9559. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9560. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9561. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9562. ]);
  9563. ps[10] = coords.length;
  9564. coords.push([
  9565. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9566. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9567. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9568. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9569. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9570. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9571. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9572. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9573. ]);
  9574. mesh.figures.push({
  9575. type: 'patch',
  9576. coords: new Int32Array(ps), // making copies of ps and cs
  9577. colors: new Int32Array(cs)
  9578. });
  9579. }
  9580. }
  9581. function decodeType7Shading(mesh, reader) {
  9582. var coords = mesh.coords;
  9583. var colors = mesh.colors;
  9584. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9585. var cs = new Int32Array(4); // c00, c30, c03, c33
  9586. while (reader.hasData) {
  9587. var f = reader.readFlag();
  9588. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9589. var i, ii;
  9590. var pi = coords.length;
  9591. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9592. coords.push(reader.readCoordinate());
  9593. }
  9594. var ci = colors.length;
  9595. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9596. colors.push(reader.readComponents());
  9597. }
  9598. var tmp1, tmp2, tmp3, tmp4;
  9599. switch (f) {
  9600. case 0:
  9601. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9602. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9603. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9604. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9605. cs[2] = ci + 1; cs[3] = ci + 2;
  9606. cs[0] = ci; cs[1] = ci + 3;
  9607. break;
  9608. case 1:
  9609. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9610. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9611. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9612. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9613. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9614. tmp1 = cs[2]; tmp2 = cs[3];
  9615. cs[2] = ci + 1; cs[3] = ci;
  9616. cs[0] = tmp1; cs[1] = tmp2;
  9617. break;
  9618. case 2:
  9619. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9620. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9621. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9622. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9623. cs[2] = cs[3]; cs[3] = ci + 1;
  9624. cs[0] = cs[1]; cs[1] = ci;
  9625. break;
  9626. case 3:
  9627. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9628. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9629. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9630. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9631. cs[2] = cs[0]; cs[3] = cs[1];
  9632. cs[0] = ci; cs[1] = ci + 1;
  9633. break;
  9634. }
  9635. mesh.figures.push({
  9636. type: 'patch',
  9637. coords: new Int32Array(ps), // making copies of ps and cs
  9638. colors: new Int32Array(cs)
  9639. });
  9640. }
  9641. }
  9642. function updateBounds(mesh) {
  9643. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9644. maxX = minX, maxY = minY;
  9645. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9646. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9647. minX = minX > x ? x : minX;
  9648. minY = minY > y ? y : minY;
  9649. maxX = maxX < x ? x : maxX;
  9650. maxY = maxY < y ? y : maxY;
  9651. }
  9652. mesh.bounds = [minX, minY, maxX, maxY];
  9653. }
  9654. function packData(mesh) {
  9655. var i, ii, j, jj;
  9656. var coords = mesh.coords;
  9657. var coordsPacked = new Float32Array(coords.length * 2);
  9658. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9659. var xy = coords[i];
  9660. coordsPacked[j++] = xy[0];
  9661. coordsPacked[j++] = xy[1];
  9662. }
  9663. mesh.coords = coordsPacked;
  9664. var colors = mesh.colors;
  9665. var colorsPacked = new Uint8Array(colors.length * 3);
  9666. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9667. var c = colors[i];
  9668. colorsPacked[j++] = c[0];
  9669. colorsPacked[j++] = c[1];
  9670. colorsPacked[j++] = c[2];
  9671. }
  9672. mesh.colors = colorsPacked;
  9673. var figures = mesh.figures;
  9674. for (i = 0, ii = figures.length; i < ii; i++) {
  9675. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9676. for (j = 0, jj = ps.length; j < jj; j++) {
  9677. ps[j] *= 2;
  9678. cs[j] *= 3;
  9679. }
  9680. }
  9681. }
  9682. function Mesh(stream, matrix, xref, res) {
  9683. assert(isStream(stream), 'Mesh data is not a stream');
  9684. var dict = stream.dict;
  9685. this.matrix = matrix;
  9686. this.shadingType = dict.get('ShadingType');
  9687. this.type = 'Pattern';
  9688. this.bbox = dict.get('BBox');
  9689. var cs = dict.get('ColorSpace', 'CS');
  9690. cs = ColorSpace.parse(cs, xref, res);
  9691. this.cs = cs;
  9692. this.background = dict.has('Background') ?
  9693. cs.getRgb(dict.get('Background'), 0) : null;
  9694. var fnObj = dict.get('Function');
  9695. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9696. this.coords = [];
  9697. this.colors = [];
  9698. this.figures = [];
  9699. var decodeContext = {
  9700. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9701. bitsPerComponent: dict.get('BitsPerComponent'),
  9702. bitsPerFlag: dict.get('BitsPerFlag'),
  9703. decode: dict.get('Decode'),
  9704. colorFn: fn,
  9705. colorSpace: cs,
  9706. numComps: fn ? 1 : cs.numComps
  9707. };
  9708. var reader = new MeshStreamReader(stream, decodeContext);
  9709. var patchMesh = false;
  9710. switch (this.shadingType) {
  9711. case PatternType.FREE_FORM_MESH:
  9712. decodeType4Shading(this, reader);
  9713. break;
  9714. case PatternType.LATTICE_FORM_MESH:
  9715. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9716. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9717. decodeType5Shading(this, reader, verticesPerRow);
  9718. break;
  9719. case PatternType.COONS_PATCH_MESH:
  9720. decodeType6Shading(this, reader);
  9721. patchMesh = true;
  9722. break;
  9723. case PatternType.TENSOR_PATCH_MESH:
  9724. decodeType7Shading(this, reader);
  9725. patchMesh = true;
  9726. break;
  9727. default:
  9728. error('Unsupported mesh type.');
  9729. break;
  9730. }
  9731. if (patchMesh) {
  9732. // dirty bounds calculation for determining, how dense shall be triangles
  9733. updateBounds(this);
  9734. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9735. buildFigureFromPatch(this, i);
  9736. }
  9737. }
  9738. // calculate bounds
  9739. updateBounds(this);
  9740. packData(this);
  9741. }
  9742. Mesh.prototype = {
  9743. getIR: function Mesh_getIR() {
  9744. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9745. this.bounds, this.matrix, this.bbox, this.background];
  9746. }
  9747. };
  9748. return Mesh;
  9749. })();
  9750. Shadings.Dummy = (function DummyClosure() {
  9751. function Dummy() {
  9752. this.type = 'Pattern';
  9753. }
  9754. Dummy.prototype = {
  9755. getIR: function Dummy_getIR() {
  9756. return ['Dummy'];
  9757. }
  9758. };
  9759. return Dummy;
  9760. })();
  9761. function getTilingPatternIR(operatorList, dict, args) {
  9762. var matrix = dict.get('Matrix');
  9763. var bbox = dict.get('BBox');
  9764. var xstep = dict.get('XStep');
  9765. var ystep = dict.get('YStep');
  9766. var paintType = dict.get('PaintType');
  9767. var tilingType = dict.get('TilingType');
  9768. return [
  9769. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9770. paintType, tilingType
  9771. ];
  9772. }
  9773. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9774. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9775. uniquePrefix, idCounters, fontCache) {
  9776. this.pdfManager = pdfManager;
  9777. this.xref = xref;
  9778. this.handler = handler;
  9779. this.pageIndex = pageIndex;
  9780. this.uniquePrefix = uniquePrefix;
  9781. this.idCounters = idCounters;
  9782. this.fontCache = fontCache;
  9783. }
  9784. // Trying to minimize Date.now() usage and check every 100 time
  9785. var TIME_SLOT_DURATION_MS = 20;
  9786. var CHECK_TIME_EVERY = 100;
  9787. function TimeSlotManager() {
  9788. this.reset();
  9789. }
  9790. TimeSlotManager.prototype = {
  9791. check: function TimeSlotManager_check() {
  9792. if (++this.checked < CHECK_TIME_EVERY) {
  9793. return false;
  9794. }
  9795. this.checked = 0;
  9796. return this.endTime <= Date.now();
  9797. },
  9798. reset: function TimeSlotManager_reset() {
  9799. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9800. this.checked = 0;
  9801. }
  9802. };
  9803. var deferred = Promise.resolve();
  9804. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9805. PartialEvaluator.prototype = {
  9806. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9807. if (!isDict(resources)) {
  9808. return false;
  9809. }
  9810. var processed = Object.create(null);
  9811. if (resources.objId) {
  9812. processed[resources.objId] = true;
  9813. }
  9814. var nodes = [resources];
  9815. while (nodes.length) {
  9816. var key;
  9817. var node = nodes.shift();
  9818. // First check the current resources for blend modes.
  9819. var graphicStates = node.get('ExtGState');
  9820. if (isDict(graphicStates)) {
  9821. graphicStates = graphicStates.getAll();
  9822. for (key in graphicStates) {
  9823. var graphicState = graphicStates[key];
  9824. var bm = graphicState['BM'];
  9825. if (isName(bm) && bm.name !== 'Normal') {
  9826. return true;
  9827. }
  9828. }
  9829. }
  9830. // Descend into the XObjects to look for more resources and blend modes.
  9831. var xObjects = node.get('XObject');
  9832. if (!isDict(xObjects)) {
  9833. continue;
  9834. }
  9835. xObjects = xObjects.getAll();
  9836. for (key in xObjects) {
  9837. var xObject = xObjects[key];
  9838. if (!isStream(xObject)) {
  9839. continue;
  9840. }
  9841. if (xObject.dict.objId) {
  9842. if (processed[xObject.dict.objId]) {
  9843. // stream has objId and is processed already
  9844. continue;
  9845. }
  9846. processed[xObject.dict.objId] = true;
  9847. }
  9848. var xResources = xObject.dict.get('Resources');
  9849. // Checking objId to detect an infinite loop.
  9850. if (isDict(xResources) &&
  9851. (!xResources.objId || !processed[xResources.objId])) {
  9852. nodes.push(xResources);
  9853. if (xResources.objId) {
  9854. processed[xResources.objId] = true;
  9855. }
  9856. }
  9857. }
  9858. }
  9859. return false;
  9860. },
  9861. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9862. xobj, smask,
  9863. operatorList,
  9864. initialState) {
  9865. var matrix = xobj.dict.get('Matrix');
  9866. var bbox = xobj.dict.get('BBox');
  9867. var group = xobj.dict.get('Group');
  9868. if (group) {
  9869. var groupOptions = {
  9870. matrix: matrix,
  9871. bbox: bbox,
  9872. smask: smask,
  9873. isolated: false,
  9874. knockout: false
  9875. };
  9876. var groupSubtype = group.get('S');
  9877. var colorSpace;
  9878. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9879. groupOptions.isolated = (group.get('I') || false);
  9880. groupOptions.knockout = (group.get('K') || false);
  9881. colorSpace = (group.has('CS') ?
  9882. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9883. }
  9884. if (smask && smask.backdrop) {
  9885. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9886. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9887. }
  9888. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9889. }
  9890. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9891. return this.getOperatorList(xobj,
  9892. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9893. then(function () {
  9894. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9895. if (group) {
  9896. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9897. }
  9898. });
  9899. },
  9900. buildPaintImageXObject:
  9901. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9902. inline, operatorList,
  9903. cacheKey, imageCache) {
  9904. var self = this;
  9905. var dict = image.dict;
  9906. var w = dict.get('Width', 'W');
  9907. var h = dict.get('Height', 'H');
  9908. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9909. warn('Image dimensions are missing, or not numbers.');
  9910. return;
  9911. }
  9912. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9913. warn('Image exceeded maximum allowed size and was removed.');
  9914. return;
  9915. }
  9916. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9917. var imgData, args;
  9918. if (imageMask) {
  9919. // This depends on a tmpCanvas being filled with the
  9920. // current fillStyle, such that processing the pixel
  9921. // data can't be done here. Instead of creating a
  9922. // complete PDFImage, only read the information needed
  9923. // for later.
  9924. var width = dict.get('Width', 'W');
  9925. var height = dict.get('Height', 'H');
  9926. var bitStrideLength = (width + 7) >> 3;
  9927. var imgArray = image.getBytes(bitStrideLength * height);
  9928. var decode = dict.get('Decode', 'D');
  9929. var inverseDecode = (!!decode && decode[0] > 0);
  9930. imgData = PDFImage.createMask(imgArray, width, height,
  9931. image instanceof DecodeStream,
  9932. inverseDecode);
  9933. imgData.cached = true;
  9934. args = [imgData];
  9935. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9936. if (cacheKey) {
  9937. imageCache[cacheKey] = {
  9938. fn: OPS.paintImageMaskXObject,
  9939. args: args
  9940. };
  9941. }
  9942. return;
  9943. }
  9944. var softMask = (dict.get('SMask', 'SM') || false);
  9945. var mask = (dict.get('Mask') || false);
  9946. var SMALL_IMAGE_DIMENSIONS = 200;
  9947. // Inlining small images into the queue as RGB data
  9948. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9949. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9950. var imageObj = new PDFImage(this.xref, resources, image,
  9951. inline, null, null);
  9952. // We force the use of RGBA_32BPP images here, because we can't handle
  9953. // any other kind.
  9954. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9955. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9956. return;
  9957. }
  9958. // If there is no imageMask, create the PDFImage and a lot
  9959. // of image processing can be done here.
  9960. var uniquePrefix = (this.uniquePrefix || '');
  9961. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9962. operatorList.addDependency(objId);
  9963. args = [objId, w, h];
  9964. if (!softMask && !mask && image instanceof JpegStream &&
  9965. image.isNativelySupported(this.xref, resources)) {
  9966. // These JPEGs don't need any more processing so we can just send it.
  9967. operatorList.addOp(OPS.paintJpegXObject, args);
  9968. this.handler.send('obj',
  9969. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9970. return;
  9971. }
  9972. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9973. then(function(imageObj) {
  9974. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9975. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9976. [imgData.data.buffer]);
  9977. }).then(undefined, function (reason) {
  9978. warn('Unable to decode image: ' + reason);
  9979. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9980. });
  9981. operatorList.addOp(OPS.paintImageXObject, args);
  9982. if (cacheKey) {
  9983. imageCache[cacheKey] = {
  9984. fn: OPS.paintImageXObject,
  9985. args: args
  9986. };
  9987. }
  9988. },
  9989. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9990. operatorList,
  9991. stateManager) {
  9992. var smaskContent = smask.get('G');
  9993. var smaskOptions = {
  9994. subtype: smask.get('S').name,
  9995. backdrop: smask.get('BC')
  9996. };
  9997. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9998. operatorList, stateManager.state.clone());
  9999. },
  10000. handleTilingType:
  10001. function PartialEvaluator_handleTilingType(fn, args, resources,
  10002. pattern, patternDict,
  10003. operatorList) {
  10004. // Create an IR of the pattern code.
  10005. var tilingOpList = new OperatorList();
  10006. return this.getOperatorList(pattern,
  10007. (patternDict.get('Resources') || resources), tilingOpList).
  10008. then(function () {
  10009. // Add the dependencies to the parent operator list so they are
  10010. // resolved before sub operator list is executed synchronously.
  10011. operatorList.addDependencies(tilingOpList.dependencies);
  10012. operatorList.addOp(fn, getTilingPatternIR({
  10013. fnArray: tilingOpList.fnArray,
  10014. argsArray: tilingOpList.argsArray
  10015. }, patternDict, args));
  10016. });
  10017. },
  10018. handleSetFont:
  10019. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  10020. operatorList, state) {
  10021. // TODO(mack): Not needed?
  10022. var fontName;
  10023. if (fontArgs) {
  10024. fontArgs = fontArgs.slice();
  10025. fontName = fontArgs[0].name;
  10026. }
  10027. var self = this;
  10028. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  10029. function (translated) {
  10030. if (!translated.font.isType3Font) {
  10031. return translated;
  10032. }
  10033. return translated.loadType3Data(self, resources, operatorList).then(
  10034. function () {
  10035. return translated;
  10036. });
  10037. }).then(function (translated) {
  10038. state.font = translated.font;
  10039. translated.send(self.handler);
  10040. return translated.loadedName;
  10041. });
  10042. },
  10043. handleText: function PartialEvaluator_handleText(chars, state) {
  10044. var font = state.font;
  10045. var glyphs = font.charsToGlyphs(chars);
  10046. var isAddToPathSet = !!(state.textRenderingMode &
  10047. TextRenderingMode.ADD_TO_PATH_FLAG);
  10048. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  10049. var buildPath = function (fontChar) {
  10050. if (!font.renderer.hasBuiltPath(fontChar)) {
  10051. var path = font.renderer.getPathJs(fontChar);
  10052. this.handler.send('commonobj', [
  10053. font.loadedName + '_path_' + fontChar,
  10054. 'FontPath',
  10055. path
  10056. ]);
  10057. }
  10058. }.bind(this);
  10059. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  10060. var glyph = glyphs[i];
  10061. if (glyph === null) {
  10062. continue;
  10063. }
  10064. buildPath(glyph.fontChar);
  10065. // If the glyph has an accent we need to build a path for its
  10066. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  10067. var accent = glyph.accent;
  10068. if (accent && accent.fontChar) {
  10069. buildPath(accent.fontChar);
  10070. }
  10071. }
  10072. }
  10073. return glyphs;
  10074. },
  10075. setGState: function PartialEvaluator_setGState(resources, gState,
  10076. operatorList, xref,
  10077. stateManager) {
  10078. // This array holds the converted/processed state data.
  10079. var gStateObj = [];
  10080. var gStateMap = gState.map;
  10081. var self = this;
  10082. var promise = Promise.resolve();
  10083. for (var key in gStateMap) {
  10084. var value = gStateMap[key];
  10085. switch (key) {
  10086. case 'Type':
  10087. break;
  10088. case 'LW':
  10089. case 'LC':
  10090. case 'LJ':
  10091. case 'ML':
  10092. case 'D':
  10093. case 'RI':
  10094. case 'FL':
  10095. case 'CA':
  10096. case 'ca':
  10097. gStateObj.push([key, value]);
  10098. break;
  10099. case 'Font':
  10100. promise = promise.then(function () {
  10101. return self.handleSetFont(resources, null, value[0],
  10102. operatorList, stateManager.state).
  10103. then(function (loadedName) {
  10104. operatorList.addDependency(loadedName);
  10105. gStateObj.push([key, [loadedName, value[1]]]);
  10106. });
  10107. });
  10108. break;
  10109. case 'BM':
  10110. gStateObj.push([key, value]);
  10111. break;
  10112. case 'SMask':
  10113. if (isName(value) && value.name === 'None') {
  10114. gStateObj.push([key, false]);
  10115. break;
  10116. }
  10117. var dict = xref.fetchIfRef(value);
  10118. if (isDict(dict)) {
  10119. promise = promise.then(function () {
  10120. return self.handleSMask(dict, resources, operatorList,
  10121. stateManager);
  10122. });
  10123. gStateObj.push([key, true]);
  10124. } else {
  10125. warn('Unsupported SMask type');
  10126. }
  10127. break;
  10128. // Only generate info log messages for the following since
  10129. // they are unlikely to have a big impact on the rendering.
  10130. case 'OP':
  10131. case 'op':
  10132. case 'OPM':
  10133. case 'BG':
  10134. case 'BG2':
  10135. case 'UCR':
  10136. case 'UCR2':
  10137. case 'TR':
  10138. case 'TR2':
  10139. case 'HT':
  10140. case 'SM':
  10141. case 'SA':
  10142. case 'AIS':
  10143. case 'TK':
  10144. // TODO implement these operators.
  10145. info('graphic state operator ' + key);
  10146. break;
  10147. default:
  10148. info('Unknown graphic state operator ' + key);
  10149. break;
  10150. }
  10151. }
  10152. return promise.then(function () {
  10153. if (gStateObj.length >= 0) {
  10154. operatorList.addOp(OPS.setGState, [gStateObj]);
  10155. }
  10156. });
  10157. },
  10158. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10159. resources) {
  10160. function errorFont() {
  10161. return Promise.resolve(new TranslatedFont('g_font_error',
  10162. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10163. }
  10164. var fontRef;
  10165. if (font) { // Loading by ref.
  10166. assert(isRef(font));
  10167. fontRef = font;
  10168. } else { // Loading by name.
  10169. var fontRes = resources.get('Font');
  10170. if (fontRes) {
  10171. fontRef = fontRes.getRaw(fontName);
  10172. } else {
  10173. warn('fontRes not available');
  10174. return errorFont();
  10175. }
  10176. }
  10177. if (!fontRef) {
  10178. warn('fontRef not available');
  10179. return errorFont();
  10180. }
  10181. if (this.fontCache.has(fontRef)) {
  10182. return this.fontCache.get(fontRef);
  10183. }
  10184. font = xref.fetchIfRef(fontRef);
  10185. if (!isDict(font)) {
  10186. return errorFont();
  10187. }
  10188. // We are holding font.translated references just for fontRef that are not
  10189. // dictionaries (Dict). See explanation below.
  10190. if (font.translated) {
  10191. return font.translated;
  10192. }
  10193. var fontCapability = createPromiseCapability();
  10194. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10195. var descriptor = preEvaluatedFont.descriptor;
  10196. var fontID = fontRef.num + '_' + fontRef.gen;
  10197. if (isDict(descriptor)) {
  10198. if (!descriptor.fontAliases) {
  10199. descriptor.fontAliases = Object.create(null);
  10200. }
  10201. var fontAliases = descriptor.fontAliases;
  10202. var hash = preEvaluatedFont.hash;
  10203. if (fontAliases[hash]) {
  10204. var aliasFontRef = fontAliases[hash].aliasRef;
  10205. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10206. this.fontCache.putAlias(fontRef, aliasFontRef);
  10207. return this.fontCache.get(fontRef);
  10208. }
  10209. }
  10210. if (!fontAliases[hash]) {
  10211. fontAliases[hash] = {
  10212. fontID: Font.getFontID()
  10213. };
  10214. }
  10215. fontAliases[hash].aliasRef = fontRef;
  10216. fontID = fontAliases[hash].fontID;
  10217. }
  10218. // Workaround for bad PDF generators that don't reference fonts
  10219. // properly, i.e. by not using an object identifier.
  10220. // Check if the fontRef is a Dict (as opposed to a standard object),
  10221. // in which case we don't cache the font and instead reference it by
  10222. // fontName in font.loadedName below.
  10223. var fontRefIsDict = isDict(fontRef);
  10224. if (!fontRefIsDict) {
  10225. this.fontCache.put(fontRef, fontCapability.promise);
  10226. }
  10227. // Keep track of each font we translated so the caller can
  10228. // load them asynchronously before calling display on a page.
  10229. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10230. fontName.replace(/\W/g, '') : fontID);
  10231. font.translated = fontCapability.promise;
  10232. // TODO move promises into translate font
  10233. var translatedPromise;
  10234. try {
  10235. translatedPromise = Promise.resolve(
  10236. this.translateFont(preEvaluatedFont, xref));
  10237. } catch (e) {
  10238. translatedPromise = Promise.reject(e);
  10239. }
  10240. translatedPromise.then(function (translatedFont) {
  10241. if (translatedFont.fontType !== undefined) {
  10242. var xrefFontStats = xref.stats.fontTypes;
  10243. xrefFontStats[translatedFont.fontType] = true;
  10244. }
  10245. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10246. translatedFont, font));
  10247. }, function (reason) {
  10248. // TODO fontCapability.reject?
  10249. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10250. try {
  10251. // error, but it's still nice to have font type reported
  10252. var descriptor = preEvaluatedFont.descriptor;
  10253. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10254. var subtype = fontFile3 && fontFile3.get('Subtype');
  10255. var fontType = getFontType(preEvaluatedFont.type,
  10256. subtype && subtype.name);
  10257. var xrefFontStats = xref.stats.fontTypes;
  10258. xrefFontStats[fontType] = true;
  10259. } catch (ex) { }
  10260. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10261. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10262. font));
  10263. });
  10264. return fontCapability.promise;
  10265. },
  10266. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10267. var lastIndex = operatorList.length - 1;
  10268. if (!args) {
  10269. args = [];
  10270. }
  10271. if (lastIndex < 0 ||
  10272. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10273. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10274. } else {
  10275. var opArgs = operatorList.argsArray[lastIndex];
  10276. opArgs[0].push(fn);
  10277. Array.prototype.push.apply(opArgs[1], args);
  10278. }
  10279. },
  10280. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10281. cs, patterns, resources, xref) {
  10282. // compile tiling patterns
  10283. var patternName = args[args.length - 1];
  10284. // SCN/scn applies patterns along with normal colors
  10285. var pattern;
  10286. if (isName(patternName) &&
  10287. (pattern = patterns.get(patternName.name))) {
  10288. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10289. var typeNum = dict.get('PatternType');
  10290. if (typeNum === TILING_PATTERN) {
  10291. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10292. return this.handleTilingType(fn, color, resources, pattern,
  10293. dict, operatorList);
  10294. } else if (typeNum === SHADING_PATTERN) {
  10295. var shading = dict.get('Shading');
  10296. var matrix = dict.get('Matrix');
  10297. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10298. operatorList.addOp(fn, pattern.getIR());
  10299. return Promise.resolve();
  10300. } else {
  10301. return Promise.reject('Unknown PatternType: ' + typeNum);
  10302. }
  10303. }
  10304. // TODO shall we fail here?
  10305. operatorList.addOp(fn, args);
  10306. return Promise.resolve();
  10307. },
  10308. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10309. resources,
  10310. operatorList,
  10311. initialState) {
  10312. var self = this;
  10313. var xref = this.xref;
  10314. var imageCache = {};
  10315. assert(operatorList);
  10316. resources = (resources || Dict.empty);
  10317. var xobjs = (resources.get('XObject') || Dict.empty);
  10318. var patterns = (resources.get('Pattern') || Dict.empty);
  10319. var stateManager = new StateManager(initialState || new EvalState());
  10320. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10321. var timeSlotManager = new TimeSlotManager();
  10322. return new Promise(function next(resolve, reject) {
  10323. timeSlotManager.reset();
  10324. var stop, operation = {}, i, ii, cs;
  10325. while (!(stop = timeSlotManager.check())) {
  10326. // The arguments parsed by read() are used beyond this loop, so we
  10327. // cannot reuse the same array on each iteration. Therefore we pass
  10328. // in |null| as the initial value (see the comment on
  10329. // EvaluatorPreprocessor_read() for why).
  10330. operation.args = null;
  10331. if (!(preprocessor.read(operation))) {
  10332. break;
  10333. }
  10334. var args = operation.args;
  10335. var fn = operation.fn;
  10336. switch (fn | 0) {
  10337. case OPS.paintXObject:
  10338. if (args[0].code) {
  10339. break;
  10340. }
  10341. // eagerly compile XForm objects
  10342. var name = args[0].name;
  10343. if (!name) {
  10344. warn('XObject must be referred to by name.');
  10345. continue;
  10346. }
  10347. if (imageCache[name] !== undefined) {
  10348. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10349. args = null;
  10350. continue;
  10351. }
  10352. var xobj = xobjs.get(name);
  10353. if (xobj) {
  10354. assert(isStream(xobj), 'XObject should be a stream');
  10355. var type = xobj.dict.get('Subtype');
  10356. assert(isName(type),
  10357. 'XObject should have a Name subtype');
  10358. if (type.name === 'Form') {
  10359. stateManager.save();
  10360. return self.buildFormXObject(resources, xobj, null,
  10361. operatorList,
  10362. stateManager.state.clone()).
  10363. then(function () {
  10364. stateManager.restore();
  10365. next(resolve, reject);
  10366. }, reject);
  10367. } else if (type.name === 'Image') {
  10368. self.buildPaintImageXObject(resources, xobj, false,
  10369. operatorList, name, imageCache);
  10370. args = null;
  10371. continue;
  10372. } else if (type.name === 'PS') {
  10373. // PostScript XObjects are unused when viewing documents.
  10374. // See section 4.7.1 of Adobe's PDF reference.
  10375. info('Ignored XObject subtype PS');
  10376. continue;
  10377. } else {
  10378. error('Unhandled XObject subtype ' + type.name);
  10379. }
  10380. }
  10381. break;
  10382. case OPS.setFont:
  10383. var fontSize = args[1];
  10384. // eagerly collect all fonts
  10385. return self.handleSetFont(resources, args, null,
  10386. operatorList, stateManager.state).
  10387. then(function (loadedName) {
  10388. operatorList.addDependency(loadedName);
  10389. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10390. next(resolve, reject);
  10391. }, reject);
  10392. case OPS.endInlineImage:
  10393. var cacheKey = args[0].cacheKey;
  10394. if (cacheKey) {
  10395. var cacheEntry = imageCache[cacheKey];
  10396. if (cacheEntry !== undefined) {
  10397. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10398. args = null;
  10399. continue;
  10400. }
  10401. }
  10402. self.buildPaintImageXObject(resources, args[0], true,
  10403. operatorList, cacheKey, imageCache);
  10404. args = null;
  10405. continue;
  10406. case OPS.showText:
  10407. args[0] = self.handleText(args[0], stateManager.state);
  10408. break;
  10409. case OPS.showSpacedText:
  10410. var arr = args[0];
  10411. var combinedGlyphs = [];
  10412. var arrLength = arr.length;
  10413. for (i = 0; i < arrLength; ++i) {
  10414. var arrItem = arr[i];
  10415. if (isString(arrItem)) {
  10416. Array.prototype.push.apply(combinedGlyphs,
  10417. self.handleText(arrItem, stateManager.state));
  10418. } else if (isNum(arrItem)) {
  10419. combinedGlyphs.push(arrItem);
  10420. }
  10421. }
  10422. args[0] = combinedGlyphs;
  10423. fn = OPS.showText;
  10424. break;
  10425. case OPS.nextLineShowText:
  10426. operatorList.addOp(OPS.nextLine);
  10427. args[0] = self.handleText(args[0], stateManager.state);
  10428. fn = OPS.showText;
  10429. break;
  10430. case OPS.nextLineSetSpacingShowText:
  10431. operatorList.addOp(OPS.nextLine);
  10432. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10433. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10434. args[0] = self.handleText(args[0], stateManager.state);
  10435. fn = OPS.showText;
  10436. break;
  10437. case OPS.setTextRenderingMode:
  10438. stateManager.state.textRenderingMode = args[0];
  10439. break;
  10440. case OPS.setFillColorSpace:
  10441. stateManager.state.fillColorSpace =
  10442. ColorSpace.parse(args[0], xref, resources);
  10443. continue;
  10444. case OPS.setStrokeColorSpace:
  10445. stateManager.state.strokeColorSpace =
  10446. ColorSpace.parse(args[0], xref, resources);
  10447. continue;
  10448. case OPS.setFillColor:
  10449. cs = stateManager.state.fillColorSpace;
  10450. args = cs.getRgb(args, 0);
  10451. fn = OPS.setFillRGBColor;
  10452. break;
  10453. case OPS.setStrokeColor:
  10454. cs = stateManager.state.strokeColorSpace;
  10455. args = cs.getRgb(args, 0);
  10456. fn = OPS.setStrokeRGBColor;
  10457. break;
  10458. case OPS.setFillGray:
  10459. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10460. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10461. fn = OPS.setFillRGBColor;
  10462. break;
  10463. case OPS.setStrokeGray:
  10464. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10465. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10466. fn = OPS.setStrokeRGBColor;
  10467. break;
  10468. case OPS.setFillCMYKColor:
  10469. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10470. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10471. fn = OPS.setFillRGBColor;
  10472. break;
  10473. case OPS.setStrokeCMYKColor:
  10474. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10475. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10476. fn = OPS.setStrokeRGBColor;
  10477. break;
  10478. case OPS.setFillRGBColor:
  10479. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10480. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10481. break;
  10482. case OPS.setStrokeRGBColor:
  10483. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10484. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10485. break;
  10486. case OPS.setFillColorN:
  10487. cs = stateManager.state.fillColorSpace;
  10488. if (cs.name === 'Pattern') {
  10489. return self.handleColorN(operatorList, OPS.setFillColorN,
  10490. args, cs, patterns, resources, xref).then(function() {
  10491. next(resolve, reject);
  10492. }, reject);
  10493. }
  10494. args = cs.getRgb(args, 0);
  10495. fn = OPS.setFillRGBColor;
  10496. break;
  10497. case OPS.setStrokeColorN:
  10498. cs = stateManager.state.strokeColorSpace;
  10499. if (cs.name === 'Pattern') {
  10500. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10501. args, cs, patterns, resources, xref).then(function() {
  10502. next(resolve, reject);
  10503. }, reject);
  10504. }
  10505. args = cs.getRgb(args, 0);
  10506. fn = OPS.setStrokeRGBColor;
  10507. break;
  10508. case OPS.shadingFill:
  10509. var shadingRes = resources.get('Shading');
  10510. if (!shadingRes) {
  10511. error('No shading resource found');
  10512. }
  10513. var shading = shadingRes.get(args[0].name);
  10514. if (!shading) {
  10515. error('No shading object found');
  10516. }
  10517. var shadingFill = Pattern.parseShading(shading, null, xref,
  10518. resources);
  10519. var patternIR = shadingFill.getIR();
  10520. args = [patternIR];
  10521. fn = OPS.shadingFill;
  10522. break;
  10523. case OPS.setGState:
  10524. var dictName = args[0];
  10525. var extGState = resources.get('ExtGState');
  10526. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10527. break;
  10528. }
  10529. var gState = extGState.get(dictName.name);
  10530. return self.setGState(resources, gState, operatorList, xref,
  10531. stateManager).then(function() {
  10532. next(resolve, reject);
  10533. }, reject);
  10534. case OPS.moveTo:
  10535. case OPS.lineTo:
  10536. case OPS.curveTo:
  10537. case OPS.curveTo2:
  10538. case OPS.curveTo3:
  10539. case OPS.closePath:
  10540. self.buildPath(operatorList, fn, args);
  10541. continue;
  10542. case OPS.rectangle:
  10543. self.buildPath(operatorList, fn, args);
  10544. continue;
  10545. }
  10546. operatorList.addOp(fn, args);
  10547. }
  10548. if (stop) {
  10549. deferred.then(function () {
  10550. next(resolve, reject);
  10551. });
  10552. return;
  10553. }
  10554. // Some PDFs don't close all restores inside object/form.
  10555. // Closing those for them.
  10556. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10557. operatorList.addOp(OPS.restore, []);
  10558. }
  10559. resolve();
  10560. });
  10561. },
  10562. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10563. stateManager) {
  10564. stateManager = (stateManager || new StateManager(new TextState()));
  10565. var textContent = {
  10566. items: [],
  10567. styles: Object.create(null)
  10568. };
  10569. var bidiTexts = textContent.items;
  10570. var SPACE_FACTOR = 0.3;
  10571. var MULTI_SPACE_FACTOR = 1.5;
  10572. var self = this;
  10573. var xref = this.xref;
  10574. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10575. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10576. var xobjs = null;
  10577. var xobjsCache = {};
  10578. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10579. var textState;
  10580. function newTextChunk() {
  10581. var font = textState.font;
  10582. if (!(font.loadedName in textContent.styles)) {
  10583. textContent.styles[font.loadedName] = {
  10584. fontFamily: font.fallbackName,
  10585. ascent: font.ascent,
  10586. descent: font.descent,
  10587. vertical: font.vertical
  10588. };
  10589. }
  10590. return {
  10591. // |str| is initially an array which we push individual chars to, and
  10592. // then runBidi() overwrites it with the final string.
  10593. str: [],
  10594. dir: null,
  10595. width: 0,
  10596. height: 0,
  10597. transform: null,
  10598. fontName: font.loadedName
  10599. };
  10600. }
  10601. function runBidi(textChunk) {
  10602. var str = textChunk.str.join('');
  10603. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10604. textChunk.str = bidiResult.str;
  10605. textChunk.dir = bidiResult.dir;
  10606. return textChunk;
  10607. }
  10608. function handleSetFont(fontName, fontRef) {
  10609. return self.loadFont(fontName, fontRef, xref, resources).
  10610. then(function (translated) {
  10611. textState.font = translated.font;
  10612. textState.fontMatrix = translated.font.fontMatrix ||
  10613. FONT_IDENTITY_MATRIX;
  10614. });
  10615. }
  10616. function buildTextGeometry(chars, textChunk) {
  10617. var font = textState.font;
  10618. textChunk = textChunk || newTextChunk();
  10619. if (!textChunk.transform) {
  10620. // 9.4.4 Text Space Details
  10621. var tsm = [textState.fontSize * textState.textHScale, 0,
  10622. 0, textState.fontSize,
  10623. 0, textState.textRise];
  10624. if (font.isType3Font &&
  10625. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10626. textState.fontSize === 1) {
  10627. var glyphHeight = font.bbox[3] - font.bbox[1];
  10628. if (glyphHeight > 0) {
  10629. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10630. tsm[3] *= glyphHeight;
  10631. }
  10632. }
  10633. var trm = textChunk.transform = Util.transform(textState.ctm,
  10634. Util.transform(textState.textMatrix, tsm));
  10635. if (!font.vertical) {
  10636. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10637. } else {
  10638. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10639. }
  10640. }
  10641. var width = 0;
  10642. var height = 0;
  10643. var glyphs = font.charsToGlyphs(chars);
  10644. var defaultVMetrics = font.defaultVMetrics;
  10645. for (var i = 0; i < glyphs.length; i++) {
  10646. var glyph = glyphs[i];
  10647. if (!glyph) { // Previous glyph was a space.
  10648. width += textState.wordSpacing * textState.textHScale;
  10649. continue;
  10650. }
  10651. var vMetricX = null;
  10652. var vMetricY = null;
  10653. var glyphWidth = null;
  10654. if (font.vertical) {
  10655. if (glyph.vmetric) {
  10656. glyphWidth = glyph.vmetric[0];
  10657. vMetricX = glyph.vmetric[1];
  10658. vMetricY = glyph.vmetric[2];
  10659. } else {
  10660. glyphWidth = glyph.width;
  10661. vMetricX = glyph.width * 0.5;
  10662. vMetricY = defaultVMetrics[2];
  10663. }
  10664. } else {
  10665. glyphWidth = glyph.width;
  10666. }
  10667. var glyphUnicode = glyph.unicode;
  10668. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10669. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10670. }
  10671. glyphUnicode = reverseIfRtl(glyphUnicode);
  10672. // The following will calculate the x and y of the individual glyphs.
  10673. // if (font.vertical) {
  10674. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10675. // textState.fontMatrix[0];
  10676. // tsm[5] -= vMetricY * textState.fontSize *
  10677. // textState.fontMatrix[0];
  10678. // }
  10679. // var trm = Util.transform(textState.textMatrix, tsm);
  10680. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10681. // var x = pt[0];
  10682. // var y = pt[1];
  10683. var charSpacing = 0;
  10684. if (textChunk.str.length > 0) {
  10685. // Apply char spacing only when there are chars.
  10686. // As a result there is only spacing between glyphs.
  10687. charSpacing = textState.charSpacing;
  10688. }
  10689. var tx = 0;
  10690. var ty = 0;
  10691. if (!font.vertical) {
  10692. var w0 = glyphWidth * textState.fontMatrix[0];
  10693. tx = (w0 * textState.fontSize + charSpacing) *
  10694. textState.textHScale;
  10695. width += tx;
  10696. } else {
  10697. var w1 = glyphWidth * textState.fontMatrix[0];
  10698. ty = w1 * textState.fontSize + charSpacing;
  10699. height += ty;
  10700. }
  10701. textState.translateTextMatrix(tx, ty);
  10702. textChunk.str.push(glyphUnicode);
  10703. }
  10704. var a = textState.textLineMatrix[0];
  10705. var b = textState.textLineMatrix[1];
  10706. var scaleLineX = Math.sqrt(a * a + b * b);
  10707. a = textState.ctm[0];
  10708. b = textState.ctm[1];
  10709. var scaleCtmX = Math.sqrt(a * a + b * b);
  10710. if (!font.vertical) {
  10711. textChunk.width += width * scaleCtmX * scaleLineX;
  10712. } else {
  10713. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10714. }
  10715. return textChunk;
  10716. }
  10717. var timeSlotManager = new TimeSlotManager();
  10718. return new Promise(function next(resolve, reject) {
  10719. timeSlotManager.reset();
  10720. var stop, operation = {}, args = [];
  10721. while (!(stop = timeSlotManager.check())) {
  10722. // The arguments parsed by read() are not used beyond this loop, so
  10723. // we can reuse the same array on every iteration, thus avoiding
  10724. // unnecessary allocations.
  10725. args.length = 0;
  10726. operation.args = args;
  10727. if (!(preprocessor.read(operation))) {
  10728. break;
  10729. }
  10730. textState = stateManager.state;
  10731. var fn = operation.fn;
  10732. args = operation.args;
  10733. switch (fn | 0) {
  10734. case OPS.setFont:
  10735. textState.fontSize = args[1];
  10736. return handleSetFont(args[0].name).then(function() {
  10737. next(resolve, reject);
  10738. }, reject);
  10739. case OPS.setTextRise:
  10740. textState.textRise = args[0];
  10741. break;
  10742. case OPS.setHScale:
  10743. textState.textHScale = args[0] / 100;
  10744. break;
  10745. case OPS.setLeading:
  10746. textState.leading = args[0];
  10747. break;
  10748. case OPS.moveText:
  10749. textState.translateTextLineMatrix(args[0], args[1]);
  10750. textState.textMatrix = textState.textLineMatrix.slice();
  10751. break;
  10752. case OPS.setLeadingMoveText:
  10753. textState.leading = -args[1];
  10754. textState.translateTextLineMatrix(args[0], args[1]);
  10755. textState.textMatrix = textState.textLineMatrix.slice();
  10756. break;
  10757. case OPS.nextLine:
  10758. textState.carriageReturn();
  10759. break;
  10760. case OPS.setTextMatrix:
  10761. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10762. args[4], args[5]);
  10763. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10764. args[4], args[5]);
  10765. break;
  10766. case OPS.setCharSpacing:
  10767. textState.charSpacing = args[0];
  10768. break;
  10769. case OPS.setWordSpacing:
  10770. textState.wordSpacing = args[0];
  10771. break;
  10772. case OPS.beginText:
  10773. textState.textMatrix = IDENTITY_MATRIX.slice();
  10774. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10775. break;
  10776. case OPS.showSpacedText:
  10777. var items = args[0];
  10778. var textChunk = newTextChunk();
  10779. var offset;
  10780. for (var j = 0, jj = items.length; j < jj; j++) {
  10781. if (typeof items[j] === 'string') {
  10782. buildTextGeometry(items[j], textChunk);
  10783. } else {
  10784. var val = items[j] / 1000;
  10785. if (!textState.font.vertical) {
  10786. offset = -val * textState.fontSize * textState.textHScale *
  10787. textState.textMatrix[0];
  10788. textState.translateTextMatrix(offset, 0);
  10789. textChunk.width += offset;
  10790. } else {
  10791. offset = -val * textState.fontSize *
  10792. textState.textMatrix[3];
  10793. textState.translateTextMatrix(0, offset);
  10794. textChunk.height += offset;
  10795. }
  10796. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10797. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10798. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10799. fakeSpaces = Math.round(fakeSpaces);
  10800. while (fakeSpaces--) {
  10801. textChunk.str.push(' ');
  10802. }
  10803. } else if (fakeSpaces > SPACE_FACTOR) {
  10804. textChunk.str.push(' ');
  10805. }
  10806. }
  10807. }
  10808. }
  10809. bidiTexts.push(runBidi(textChunk));
  10810. break;
  10811. case OPS.showText:
  10812. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10813. break;
  10814. case OPS.nextLineShowText:
  10815. textState.carriageReturn();
  10816. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10817. break;
  10818. case OPS.nextLineSetSpacingShowText:
  10819. textState.wordSpacing = args[0];
  10820. textState.charSpacing = args[1];
  10821. textState.carriageReturn();
  10822. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10823. break;
  10824. case OPS.paintXObject:
  10825. if (args[0].code) {
  10826. break;
  10827. }
  10828. if (!xobjs) {
  10829. xobjs = (resources.get('XObject') || Dict.empty);
  10830. }
  10831. var name = args[0].name;
  10832. if (xobjsCache.key === name) {
  10833. if (xobjsCache.texts) {
  10834. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10835. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10836. }
  10837. break;
  10838. }
  10839. var xobj = xobjs.get(name);
  10840. if (!xobj) {
  10841. break;
  10842. }
  10843. assert(isStream(xobj), 'XObject should be a stream');
  10844. var type = xobj.dict.get('Subtype');
  10845. assert(isName(type),
  10846. 'XObject should have a Name subtype');
  10847. if ('Form' !== type.name) {
  10848. xobjsCache.key = name;
  10849. xobjsCache.texts = null;
  10850. break;
  10851. }
  10852. stateManager.save();
  10853. var matrix = xobj.dict.get('Matrix');
  10854. if (isArray(matrix) && matrix.length === 6) {
  10855. stateManager.transform(matrix);
  10856. }
  10857. return self.getTextContent(xobj,
  10858. xobj.dict.get('Resources') || resources, stateManager).
  10859. then(function (formTextContent) {
  10860. Util.appendToArray(bidiTexts, formTextContent.items);
  10861. Util.extendObj(textContent.styles, formTextContent.styles);
  10862. stateManager.restore();
  10863. xobjsCache.key = name;
  10864. xobjsCache.texts = formTextContent;
  10865. next(resolve, reject);
  10866. }, reject);
  10867. case OPS.setGState:
  10868. var dictName = args[0];
  10869. var extGState = resources.get('ExtGState');
  10870. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10871. break;
  10872. }
  10873. var gsStateMap = extGState.get(dictName.name);
  10874. var gsStateFont = null;
  10875. for (var key in gsStateMap) {
  10876. if (key === 'Font') {
  10877. assert(!gsStateFont);
  10878. gsStateFont = gsStateMap[key];
  10879. }
  10880. }
  10881. if (gsStateFont) {
  10882. textState.fontSize = gsStateFont[1];
  10883. return handleSetFont(gsStateFont[0]).then(function() {
  10884. next(resolve, reject);
  10885. }, reject);
  10886. }
  10887. break;
  10888. } // switch
  10889. } // while
  10890. if (stop) {
  10891. deferred.then(function () {
  10892. next(resolve, reject);
  10893. });
  10894. return;
  10895. }
  10896. resolve(textContent);
  10897. });
  10898. },
  10899. extractDataStructures: function
  10900. partialEvaluatorExtractDataStructures(dict, baseDict,
  10901. xref, properties) {
  10902. // 9.10.2
  10903. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10904. if (toUnicode) {
  10905. properties.toUnicode = this.readToUnicode(toUnicode);
  10906. }
  10907. if (properties.composite) {
  10908. // CIDSystemInfo helps to match CID to glyphs
  10909. var cidSystemInfo = dict.get('CIDSystemInfo');
  10910. if (isDict(cidSystemInfo)) {
  10911. properties.cidSystemInfo = {
  10912. registry: cidSystemInfo.get('Registry'),
  10913. ordering: cidSystemInfo.get('Ordering'),
  10914. supplement: cidSystemInfo.get('Supplement')
  10915. };
  10916. }
  10917. var cidToGidMap = dict.get('CIDToGIDMap');
  10918. if (isStream(cidToGidMap)) {
  10919. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10920. }
  10921. }
  10922. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10923. // and depends on the font type. The base encoding and differences are
  10924. // read here, but the encoding that is actually used is chosen during
  10925. // glyph mapping in the font.
  10926. // TODO: Loading the built in encoding in the font would allow the
  10927. // differences to be merged in here not require us to hold on to it.
  10928. var differences = [];
  10929. var baseEncodingName = null;
  10930. var encoding;
  10931. if (dict.has('Encoding')) {
  10932. encoding = dict.get('Encoding');
  10933. if (isDict(encoding)) {
  10934. baseEncodingName = encoding.get('BaseEncoding');
  10935. baseEncodingName = (isName(baseEncodingName) ?
  10936. baseEncodingName.name : null);
  10937. // Load the differences between the base and original
  10938. if (encoding.has('Differences')) {
  10939. var diffEncoding = encoding.get('Differences');
  10940. var index = 0;
  10941. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10942. var data = diffEncoding[j];
  10943. if (isNum(data)) {
  10944. index = data;
  10945. } else if (isName(data)) {
  10946. differences[index++] = data.name;
  10947. } else if (isRef(data)) {
  10948. diffEncoding[j--] = xref.fetch(data);
  10949. continue;
  10950. } else {
  10951. error('Invalid entry in \'Differences\' array: ' + data);
  10952. }
  10953. }
  10954. }
  10955. } else if (isName(encoding)) {
  10956. baseEncodingName = encoding.name;
  10957. } else {
  10958. error('Encoding is not a Name nor a Dict');
  10959. }
  10960. // According to table 114 if the encoding is a named encoding it must be
  10961. // one of these predefined encodings.
  10962. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10963. baseEncodingName !== 'MacExpertEncoding' &&
  10964. baseEncodingName !== 'WinAnsiEncoding')) {
  10965. baseEncodingName = null;
  10966. }
  10967. }
  10968. if (baseEncodingName) {
  10969. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10970. } else {
  10971. encoding = (properties.type === 'TrueType' ?
  10972. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10973. // The Symbolic attribute can be misused for regular fonts
  10974. // Heuristic: we have to check if the font is a standard one also
  10975. if (!!(properties.flags & FontFlags.Symbolic)) {
  10976. encoding = Encodings.MacRomanEncoding;
  10977. if (!properties.file) {
  10978. if (/Symbol/i.test(properties.name)) {
  10979. encoding = Encodings.SymbolSetEncoding;
  10980. } else if (/Dingbats/i.test(properties.name)) {
  10981. encoding = Encodings.ZapfDingbatsEncoding;
  10982. }
  10983. }
  10984. }
  10985. properties.defaultEncoding = encoding;
  10986. }
  10987. properties.differences = differences;
  10988. properties.baseEncodingName = baseEncodingName;
  10989. properties.dict = dict;
  10990. },
  10991. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10992. var cmap, cmapObj = toUnicode;
  10993. if (isName(cmapObj)) {
  10994. cmap = CMapFactory.create(cmapObj,
  10995. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10996. if (cmap instanceof IdentityCMap) {
  10997. return new IdentityToUnicodeMap(0, 0xFFFF);
  10998. }
  10999. return new ToUnicodeMap(cmap.getMap());
  11000. } else if (isStream(cmapObj)) {
  11001. cmap = CMapFactory.create(cmapObj,
  11002. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11003. if (cmap instanceof IdentityCMap) {
  11004. return new IdentityToUnicodeMap(0, 0xFFFF);
  11005. }
  11006. cmap = cmap.getMap();
  11007. // Convert UTF-16BE
  11008. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  11009. // to iterate over all keys.
  11010. cmap.forEach(function(token, i) {
  11011. var str = [];
  11012. for (var k = 0; k < token.length; k += 2) {
  11013. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11014. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  11015. str.push(w1);
  11016. continue;
  11017. }
  11018. k += 2;
  11019. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11020. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  11021. }
  11022. cmap[i] = String.fromCharCode.apply(String, str);
  11023. });
  11024. return new ToUnicodeMap(cmap);
  11025. }
  11026. return null;
  11027. },
  11028. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  11029. // Extract the encoding from the CIDToGIDMap
  11030. var glyphsData = cidToGidStream.getBytes();
  11031. // Set encoding 0 to later verify the font has an encoding
  11032. var result = [];
  11033. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  11034. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  11035. if (glyphID === 0) {
  11036. continue;
  11037. }
  11038. var code = j >> 1;
  11039. result[code] = glyphID;
  11040. }
  11041. return result;
  11042. },
  11043. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  11044. descriptor,
  11045. properties) {
  11046. var glyphsWidths = [];
  11047. var defaultWidth = 0;
  11048. var glyphsVMetrics = [];
  11049. var defaultVMetrics;
  11050. var i, ii, j, jj, start, code, widths;
  11051. if (properties.composite) {
  11052. defaultWidth = dict.get('DW') || 1000;
  11053. widths = dict.get('W');
  11054. if (widths) {
  11055. for (i = 0, ii = widths.length; i < ii; i++) {
  11056. start = widths[i++];
  11057. code = xref.fetchIfRef(widths[i]);
  11058. if (isArray(code)) {
  11059. for (j = 0, jj = code.length; j < jj; j++) {
  11060. glyphsWidths[start++] = code[j];
  11061. }
  11062. } else {
  11063. var width = widths[++i];
  11064. for (j = start; j <= code; j++) {
  11065. glyphsWidths[j] = width;
  11066. }
  11067. }
  11068. }
  11069. }
  11070. if (properties.vertical) {
  11071. var vmetrics = (dict.get('DW2') || [880, -1000]);
  11072. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  11073. vmetrics = dict.get('W2');
  11074. if (vmetrics) {
  11075. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  11076. start = vmetrics[i++];
  11077. code = xref.fetchIfRef(vmetrics[i]);
  11078. if (isArray(code)) {
  11079. for (j = 0, jj = code.length; j < jj; j++) {
  11080. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  11081. }
  11082. } else {
  11083. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  11084. for (j = start; j <= code; j++) {
  11085. glyphsVMetrics[j] = vmetric;
  11086. }
  11087. }
  11088. }
  11089. }
  11090. }
  11091. } else {
  11092. var firstChar = properties.firstChar;
  11093. widths = dict.get('Widths');
  11094. if (widths) {
  11095. j = firstChar;
  11096. for (i = 0, ii = widths.length; i < ii; i++) {
  11097. glyphsWidths[j++] = widths[i];
  11098. }
  11099. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  11100. } else {
  11101. // Trying get the BaseFont metrics (see comment above).
  11102. var baseFontName = dict.get('BaseFont');
  11103. if (isName(baseFontName)) {
  11104. var metrics = this.getBaseFontMetrics(baseFontName.name);
  11105. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  11106. properties);
  11107. defaultWidth = metrics.defaultWidth;
  11108. }
  11109. }
  11110. }
  11111. // Heuristic: detection of monospace font by checking all non-zero widths
  11112. var isMonospace = true;
  11113. var firstWidth = defaultWidth;
  11114. for (var glyph in glyphsWidths) {
  11115. var glyphWidth = glyphsWidths[glyph];
  11116. if (!glyphWidth) {
  11117. continue;
  11118. }
  11119. if (!firstWidth) {
  11120. firstWidth = glyphWidth;
  11121. continue;
  11122. }
  11123. if (firstWidth !== glyphWidth) {
  11124. isMonospace = false;
  11125. break;
  11126. }
  11127. }
  11128. if (isMonospace) {
  11129. properties.flags |= FontFlags.FixedPitch;
  11130. }
  11131. properties.defaultWidth = defaultWidth;
  11132. properties.widths = glyphsWidths;
  11133. properties.defaultVMetrics = defaultVMetrics;
  11134. properties.vmetrics = glyphsVMetrics;
  11135. },
  11136. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  11137. // Simulating descriptor flags attribute
  11138. var fontNameWoStyle = baseFontName.split('-')[0];
  11139. return (fontNameWoStyle in serifFonts) ||
  11140. (fontNameWoStyle.search(/serif/gi) !== -1);
  11141. },
  11142. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  11143. var defaultWidth = 0;
  11144. var widths = [];
  11145. var monospace = false;
  11146. var lookupName = (stdFontMap[name] || name);
  11147. if (!(lookupName in Metrics)) {
  11148. // Use default fonts for looking up font metrics if the passed
  11149. // font is not a base font
  11150. if (this.isSerifFont(name)) {
  11151. lookupName = 'Times-Roman';
  11152. } else {
  11153. lookupName = 'Helvetica';
  11154. }
  11155. }
  11156. var glyphWidths = Metrics[lookupName];
  11157. if (isNum(glyphWidths)) {
  11158. defaultWidth = glyphWidths;
  11159. monospace = true;
  11160. } else {
  11161. widths = glyphWidths;
  11162. }
  11163. return {
  11164. defaultWidth: defaultWidth,
  11165. monospace: monospace,
  11166. widths: widths
  11167. };
  11168. },
  11169. buildCharCodeToWidth:
  11170. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11171. properties) {
  11172. var widths = Object.create(null);
  11173. var differences = properties.differences;
  11174. var encoding = properties.defaultEncoding;
  11175. for (var charCode = 0; charCode < 256; charCode++) {
  11176. if (charCode in differences &&
  11177. widthsByGlyphName[differences[charCode]]) {
  11178. widths[charCode] = widthsByGlyphName[differences[charCode]];
  11179. continue;
  11180. }
  11181. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  11182. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  11183. continue;
  11184. }
  11185. }
  11186. return widths;
  11187. },
  11188. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  11189. var baseDict = dict;
  11190. var type = dict.get('Subtype');
  11191. assert(isName(type), 'invalid font Subtype');
  11192. var composite = false;
  11193. var uint8array;
  11194. if (type.name === 'Type0') {
  11195. // If font is a composite
  11196. // - get the descendant font
  11197. // - set the type according to the descendant font
  11198. // - get the FontDescriptor from the descendant font
  11199. var df = dict.get('DescendantFonts');
  11200. if (!df) {
  11201. error('Descendant fonts are not specified');
  11202. }
  11203. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  11204. type = dict.get('Subtype');
  11205. assert(isName(type), 'invalid font Subtype');
  11206. composite = true;
  11207. }
  11208. var descriptor = dict.get('FontDescriptor');
  11209. if (descriptor) {
  11210. var hash = new MurmurHash3_64();
  11211. var encoding = baseDict.getRaw('Encoding');
  11212. if (isName(encoding)) {
  11213. hash.update(encoding.name);
  11214. } else if (isRef(encoding)) {
  11215. hash.update(encoding.num + '_' + encoding.gen);
  11216. } else if (isDict(encoding)) {
  11217. var keys = encoding.getKeys();
  11218. for (var i = 0, ii = keys.length; i < ii; i++) {
  11219. var entry = encoding.getRaw(keys[i]);
  11220. if (isName(entry)) {
  11221. hash.update(entry.name);
  11222. } else if (isRef(entry)) {
  11223. hash.update(entry.num + '_' + entry.gen);
  11224. } else if (isArray(entry)) { // 'Differences' entry.
  11225. // Ideally we should check the contents of the array, but to avoid
  11226. // parsing it here and then again in |extractDataStructures|,
  11227. // we only use the array length for now (fixes bug1157493.pdf).
  11228. hash.update(entry.length.toString());
  11229. }
  11230. }
  11231. }
  11232. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11233. if (isStream(toUnicode)) {
  11234. var stream = toUnicode.str || toUnicode;
  11235. uint8array = stream.buffer ?
  11236. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11237. new Uint8Array(stream.bytes.buffer,
  11238. stream.start, stream.end - stream.start);
  11239. hash.update(uint8array);
  11240. } else if (isName(toUnicode)) {
  11241. hash.update(toUnicode.name);
  11242. }
  11243. var widths = dict.get('Widths') || baseDict.get('Widths');
  11244. if (widths) {
  11245. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11246. hash.update(uint8array);
  11247. }
  11248. }
  11249. return {
  11250. descriptor: descriptor,
  11251. dict: dict,
  11252. baseDict: baseDict,
  11253. composite: composite,
  11254. type: type.name,
  11255. hash: hash ? hash.hexdigest() : ''
  11256. };
  11257. },
  11258. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11259. xref) {
  11260. var baseDict = preEvaluatedFont.baseDict;
  11261. var dict = preEvaluatedFont.dict;
  11262. var composite = preEvaluatedFont.composite;
  11263. var descriptor = preEvaluatedFont.descriptor;
  11264. var type = preEvaluatedFont.type;
  11265. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11266. var properties;
  11267. if (!descriptor) {
  11268. if (type === 'Type3') {
  11269. // FontDescriptor is only required for Type3 fonts when the document
  11270. // is a tagged pdf. Create a barbebones one to get by.
  11271. descriptor = new Dict(null);
  11272. descriptor.set('FontName', Name.get(type));
  11273. descriptor.set('FontBBox', dict.get('FontBBox'));
  11274. } else {
  11275. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11276. // FontDescriptor was not required.
  11277. // This case is here for compatibility.
  11278. var baseFontName = dict.get('BaseFont');
  11279. if (!isName(baseFontName)) {
  11280. error('Base font is not specified');
  11281. }
  11282. // Using base font name as a font name.
  11283. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11284. var metrics = this.getBaseFontMetrics(baseFontName);
  11285. // Simulating descriptor flags attribute
  11286. var fontNameWoStyle = baseFontName.split('-')[0];
  11287. var flags =
  11288. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11289. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11290. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11291. FontFlags.Nonsymbolic);
  11292. properties = {
  11293. type: type,
  11294. name: baseFontName,
  11295. widths: metrics.widths,
  11296. defaultWidth: metrics.defaultWidth,
  11297. flags: flags,
  11298. firstChar: 0,
  11299. lastChar: maxCharIndex
  11300. };
  11301. this.extractDataStructures(dict, dict, xref, properties);
  11302. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11303. properties);
  11304. return new Font(baseFontName, null, properties);
  11305. }
  11306. }
  11307. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11308. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11309. // to ignore this rule when a variant of a standart font is used.
  11310. // TODO Fill the width array depending on which of the base font this is
  11311. // a variant.
  11312. var firstChar = (dict.get('FirstChar') || 0);
  11313. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11314. var fontName = descriptor.get('FontName');
  11315. var baseFont = dict.get('BaseFont');
  11316. // Some bad PDFs have a string as the font name.
  11317. if (isString(fontName)) {
  11318. fontName = Name.get(fontName);
  11319. }
  11320. if (isString(baseFont)) {
  11321. baseFont = Name.get(baseFont);
  11322. }
  11323. if (type !== 'Type3') {
  11324. var fontNameStr = fontName && fontName.name;
  11325. var baseFontStr = baseFont && baseFont.name;
  11326. if (fontNameStr !== baseFontStr) {
  11327. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11328. '" but should be the same as the Font\'s BaseFont "' +
  11329. baseFontStr + '"');
  11330. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11331. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11332. if (fontNameStr && baseFontStr &&
  11333. baseFontStr.indexOf(fontNameStr) === 0) {
  11334. fontName = baseFont;
  11335. }
  11336. }
  11337. }
  11338. fontName = (fontName || baseFont);
  11339. assert(isName(fontName), 'invalid font name');
  11340. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11341. if (fontFile) {
  11342. if (fontFile.dict) {
  11343. var subtype = fontFile.dict.get('Subtype');
  11344. if (subtype) {
  11345. subtype = subtype.name;
  11346. }
  11347. var length1 = fontFile.dict.get('Length1');
  11348. var length2 = fontFile.dict.get('Length2');
  11349. }
  11350. }
  11351. properties = {
  11352. type: type,
  11353. name: fontName.name,
  11354. subtype: subtype,
  11355. file: fontFile,
  11356. length1: length1,
  11357. length2: length2,
  11358. loadedName: baseDict.loadedName,
  11359. composite: composite,
  11360. wideChars: composite,
  11361. fixedPitch: false,
  11362. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11363. firstChar: firstChar || 0,
  11364. lastChar: (lastChar || maxCharIndex),
  11365. bbox: descriptor.get('FontBBox'),
  11366. ascent: descriptor.get('Ascent'),
  11367. descent: descriptor.get('Descent'),
  11368. xHeight: descriptor.get('XHeight'),
  11369. capHeight: descriptor.get('CapHeight'),
  11370. flags: descriptor.get('Flags'),
  11371. italicAngle: descriptor.get('ItalicAngle'),
  11372. coded: false
  11373. };
  11374. if (composite) {
  11375. var cidEncoding = baseDict.get('Encoding');
  11376. if (isName(cidEncoding)) {
  11377. properties.cidEncoding = cidEncoding.name;
  11378. }
  11379. properties.cMap = CMapFactory.create(cidEncoding,
  11380. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11381. properties.vertical = properties.cMap.vertical;
  11382. }
  11383. this.extractDataStructures(dict, baseDict, xref, properties);
  11384. this.extractWidths(dict, xref, descriptor, properties);
  11385. if (type === 'Type3') {
  11386. properties.isType3Font = true;
  11387. }
  11388. return new Font(fontName.name, fontFile, properties);
  11389. }
  11390. };
  11391. return PartialEvaluator;
  11392. })();
  11393. var TranslatedFont = (function TranslatedFontClosure() {
  11394. function TranslatedFont(loadedName, font, dict) {
  11395. this.loadedName = loadedName;
  11396. this.font = font;
  11397. this.dict = dict;
  11398. this.type3Loaded = null;
  11399. this.sent = false;
  11400. }
  11401. TranslatedFont.prototype = {
  11402. send: function (handler) {
  11403. if (this.sent) {
  11404. return;
  11405. }
  11406. var fontData = this.font.exportData();
  11407. handler.send('commonobj', [
  11408. this.loadedName,
  11409. 'Font',
  11410. fontData
  11411. ]);
  11412. this.sent = true;
  11413. },
  11414. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11415. assert(this.font.isType3Font);
  11416. if (this.type3Loaded) {
  11417. return this.type3Loaded;
  11418. }
  11419. var translatedFont = this.font;
  11420. var loadCharProcsPromise = Promise.resolve();
  11421. var charProcs = this.dict.get('CharProcs').getAll();
  11422. var fontResources = this.dict.get('Resources') || resources;
  11423. var charProcKeys = Object.keys(charProcs);
  11424. var charProcOperatorList = {};
  11425. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11426. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11427. var glyphStream = charProcs[key];
  11428. var operatorList = new OperatorList();
  11429. return evaluator.getOperatorList(glyphStream, fontResources,
  11430. operatorList).then(function () {
  11431. charProcOperatorList[key] = operatorList.getIR();
  11432. // Add the dependencies to the parent operator list so they are
  11433. // resolved before sub operator list is executed synchronously.
  11434. parentOperatorList.addDependencies(operatorList.dependencies);
  11435. }, function (reason) {
  11436. warn('Type3 font resource \"' + key + '\" is not available');
  11437. var operatorList = new OperatorList();
  11438. charProcOperatorList[key] = operatorList.getIR();
  11439. });
  11440. }.bind(this, charProcKeys[i]));
  11441. }
  11442. this.type3Loaded = loadCharProcsPromise.then(function () {
  11443. translatedFont.charProcOperatorList = charProcOperatorList;
  11444. });
  11445. return this.type3Loaded;
  11446. }
  11447. };
  11448. return TranslatedFont;
  11449. })();
  11450. var OperatorList = (function OperatorListClosure() {
  11451. var CHUNK_SIZE = 1000;
  11452. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11453. function getTransfers(queue) {
  11454. var transfers = [];
  11455. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11456. for (var i = 0, ii = queue.length; i < ii; i++) {
  11457. switch (fnArray[i]) {
  11458. case OPS.paintInlineImageXObject:
  11459. case OPS.paintInlineImageXObjectGroup:
  11460. case OPS.paintImageMaskXObject:
  11461. var arg = argsArray[i][0]; // first param in imgData
  11462. if (!arg.cached) {
  11463. transfers.push(arg.data.buffer);
  11464. }
  11465. break;
  11466. }
  11467. }
  11468. return transfers;
  11469. }
  11470. function OperatorList(intent, messageHandler, pageIndex) {
  11471. this.messageHandler = messageHandler;
  11472. this.fnArray = [];
  11473. this.argsArray = [];
  11474. this.dependencies = {};
  11475. this.pageIndex = pageIndex;
  11476. this.intent = intent;
  11477. }
  11478. OperatorList.prototype = {
  11479. get length() {
  11480. return this.argsArray.length;
  11481. },
  11482. addOp: function(fn, args) {
  11483. this.fnArray.push(fn);
  11484. this.argsArray.push(args);
  11485. if (this.messageHandler) {
  11486. if (this.fnArray.length >= CHUNK_SIZE) {
  11487. this.flush();
  11488. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11489. (fn === OPS.restore || fn === OPS.endText)) {
  11490. // heuristic to flush on boundary of restore or endText
  11491. this.flush();
  11492. }
  11493. }
  11494. },
  11495. addDependency: function(dependency) {
  11496. if (dependency in this.dependencies) {
  11497. return;
  11498. }
  11499. this.dependencies[dependency] = true;
  11500. this.addOp(OPS.dependency, [dependency]);
  11501. },
  11502. addDependencies: function(dependencies) {
  11503. for (var key in dependencies) {
  11504. this.addDependency(key);
  11505. }
  11506. },
  11507. addOpList: function(opList) {
  11508. Util.extendObj(this.dependencies, opList.dependencies);
  11509. for (var i = 0, ii = opList.length; i < ii; i++) {
  11510. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11511. }
  11512. },
  11513. getIR: function() {
  11514. return {
  11515. fnArray: this.fnArray,
  11516. argsArray: this.argsArray,
  11517. length: this.length
  11518. };
  11519. },
  11520. flush: function(lastChunk) {
  11521. if (this.intent !== 'oplist') {
  11522. new QueueOptimizer().optimize(this);
  11523. }
  11524. var transfers = getTransfers(this);
  11525. this.messageHandler.send('RenderPageChunk', {
  11526. operatorList: {
  11527. fnArray: this.fnArray,
  11528. argsArray: this.argsArray,
  11529. lastChunk: lastChunk,
  11530. length: this.length
  11531. },
  11532. pageIndex: this.pageIndex,
  11533. intent: this.intent
  11534. }, transfers);
  11535. this.dependencies = {};
  11536. this.fnArray.length = 0;
  11537. this.argsArray.length = 0;
  11538. }
  11539. };
  11540. return OperatorList;
  11541. })();
  11542. var StateManager = (function StateManagerClosure() {
  11543. function StateManager(initialState) {
  11544. this.state = initialState;
  11545. this.stateStack = [];
  11546. }
  11547. StateManager.prototype = {
  11548. save: function () {
  11549. var old = this.state;
  11550. this.stateStack.push(this.state);
  11551. this.state = old.clone();
  11552. },
  11553. restore: function () {
  11554. var prev = this.stateStack.pop();
  11555. if (prev) {
  11556. this.state = prev;
  11557. }
  11558. },
  11559. transform: function (args) {
  11560. this.state.ctm = Util.transform(this.state.ctm, args);
  11561. }
  11562. };
  11563. return StateManager;
  11564. })();
  11565. var TextState = (function TextStateClosure() {
  11566. function TextState() {
  11567. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11568. this.fontSize = 0;
  11569. this.font = null;
  11570. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11571. this.textMatrix = IDENTITY_MATRIX.slice();
  11572. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11573. this.charSpacing = 0;
  11574. this.wordSpacing = 0;
  11575. this.leading = 0;
  11576. this.textHScale = 1;
  11577. this.textRise = 0;
  11578. }
  11579. TextState.prototype = {
  11580. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11581. var m = this.textMatrix;
  11582. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11583. },
  11584. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11585. var m = this.textLineMatrix;
  11586. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11587. },
  11588. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11589. var m = this.textMatrix;
  11590. m[4] = m[0] * x + m[2] * y + m[4];
  11591. m[5] = m[1] * x + m[3] * y + m[5];
  11592. },
  11593. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11594. var m = this.textLineMatrix;
  11595. m[4] = m[0] * x + m[2] * y + m[4];
  11596. m[5] = m[1] * x + m[3] * y + m[5];
  11597. },
  11598. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11599. // 9.4.4 Text Space Details
  11600. var tsm = [this.fontSize * this.textHScale, 0,
  11601. 0, this.fontSize,
  11602. 0, this.textRise];
  11603. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11604. },
  11605. carriageReturn: function TextState_carriageReturn() {
  11606. this.translateTextLineMatrix(0, -this.leading);
  11607. this.textMatrix = this.textLineMatrix.slice();
  11608. },
  11609. clone: function TextState_clone() {
  11610. var clone = Object.create(this);
  11611. clone.textMatrix = this.textMatrix.slice();
  11612. clone.textLineMatrix = this.textLineMatrix.slice();
  11613. clone.fontMatrix = this.fontMatrix.slice();
  11614. return clone;
  11615. }
  11616. };
  11617. return TextState;
  11618. })();
  11619. var EvalState = (function EvalStateClosure() {
  11620. function EvalState() {
  11621. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11622. this.font = null;
  11623. this.textRenderingMode = TextRenderingMode.FILL;
  11624. this.fillColorSpace = ColorSpace.singletons.gray;
  11625. this.strokeColorSpace = ColorSpace.singletons.gray;
  11626. }
  11627. EvalState.prototype = {
  11628. clone: function CanvasExtraState_clone() {
  11629. return Object.create(this);
  11630. },
  11631. };
  11632. return EvalState;
  11633. })();
  11634. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11635. // Specifies properties for each command
  11636. //
  11637. // If variableArgs === true: [0, `numArgs`] expected
  11638. // If variableArgs === false: exactly `numArgs` expected
  11639. var OP_MAP = {
  11640. // Graphic state
  11641. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11642. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11643. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11644. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11645. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11646. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11647. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11648. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11649. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11650. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11651. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11652. // Path
  11653. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11654. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11655. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11656. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11657. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11658. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11659. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11660. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11661. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11662. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11663. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11664. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11665. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11666. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11667. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11668. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11669. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11670. // Clipping
  11671. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11672. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11673. // Text
  11674. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11675. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11676. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11677. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11678. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11679. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11680. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11681. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11682. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11683. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11684. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11685. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11686. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11687. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11688. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11689. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11690. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11691. variableArgs: false },
  11692. // Type3 fonts
  11693. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11694. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11695. // Color
  11696. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11697. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11698. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11699. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11700. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11701. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11702. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11703. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11704. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11705. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11706. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11707. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11708. // Shading
  11709. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11710. // Images
  11711. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11712. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11713. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11714. // XObjects
  11715. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11716. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11717. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11718. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11719. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11720. variableArgs: false },
  11721. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11722. // Compatibility
  11723. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11724. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11725. // (reserved partial commands for the lexer)
  11726. BM: null,
  11727. BD: null,
  11728. 'true': null,
  11729. fa: null,
  11730. fal: null,
  11731. fals: null,
  11732. 'false': null,
  11733. nu: null,
  11734. nul: null,
  11735. 'null': null
  11736. };
  11737. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11738. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11739. // dictionary
  11740. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11741. this.stateManager = stateManager;
  11742. this.nonProcessedArgs = [];
  11743. }
  11744. EvaluatorPreprocessor.prototype = {
  11745. get savedStatesDepth() {
  11746. return this.stateManager.stateStack.length;
  11747. },
  11748. // |operation| is an object with two fields:
  11749. //
  11750. // - |fn| is an out param.
  11751. //
  11752. // - |args| is an inout param. On entry, it should have one of two values.
  11753. //
  11754. // - An empty array. This indicates that the caller is providing the
  11755. // array in which the args will be stored in. The caller should use
  11756. // this value if it can reuse a single array for each call to read().
  11757. //
  11758. // - |null|. This indicates that the caller needs this function to create
  11759. // the array in which any args are stored in. If there are zero args,
  11760. // this function will leave |operation.args| as |null| (thus avoiding
  11761. // allocations that would occur if we used an empty array to represent
  11762. // zero arguments). Otherwise, it will replace |null| with a new array
  11763. // containing the arguments. The caller should use this value if it
  11764. // cannot reuse an array for each call to read().
  11765. //
  11766. // These two modes are present because this function is very hot and so
  11767. // avoiding allocations where possible is worthwhile.
  11768. //
  11769. read: function EvaluatorPreprocessor_read(operation) {
  11770. var args = operation.args;
  11771. while (true) {
  11772. var obj = this.parser.getObj();
  11773. if (isCmd(obj)) {
  11774. var cmd = obj.cmd;
  11775. // Check that the command is valid
  11776. var opSpec = OP_MAP[cmd];
  11777. if (!opSpec) {
  11778. warn('Unknown command "' + cmd + '"');
  11779. continue;
  11780. }
  11781. var fn = opSpec.id;
  11782. var numArgs = opSpec.numArgs;
  11783. var argsLength = args !== null ? args.length : 0;
  11784. if (!opSpec.variableArgs) {
  11785. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11786. if (argsLength !== numArgs) {
  11787. var nonProcessedArgs = this.nonProcessedArgs;
  11788. while (argsLength > numArgs) {
  11789. nonProcessedArgs.push(args.shift());
  11790. argsLength--;
  11791. }
  11792. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11793. if (!args) {
  11794. args = [];
  11795. }
  11796. args.unshift(nonProcessedArgs.pop());
  11797. argsLength++;
  11798. }
  11799. }
  11800. if (argsLength < numArgs) {
  11801. // If we receive too few args, it's not possible to possible
  11802. // to execute the command, so skip the command
  11803. info('Command ' + fn + ': because expected ' +
  11804. numArgs + ' args, but received ' + argsLength +
  11805. ' args; skipping');
  11806. args = null;
  11807. continue;
  11808. }
  11809. } else if (argsLength > numArgs) {
  11810. info('Command ' + fn + ': expected [0,' + numArgs +
  11811. '] args, but received ' + argsLength + ' args');
  11812. }
  11813. // TODO figure out how to type-check vararg functions
  11814. this.preprocessCommand(fn, args);
  11815. operation.fn = fn;
  11816. operation.args = args;
  11817. return true;
  11818. } else {
  11819. if (isEOF(obj)) {
  11820. return false; // no more commands
  11821. }
  11822. // argument
  11823. if (obj !== null) {
  11824. if (!args) {
  11825. args = [];
  11826. }
  11827. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11828. assert(args.length <= 33, 'Too many arguments');
  11829. }
  11830. }
  11831. }
  11832. },
  11833. preprocessCommand:
  11834. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11835. switch (fn | 0) {
  11836. case OPS.save:
  11837. this.stateManager.save();
  11838. break;
  11839. case OPS.restore:
  11840. this.stateManager.restore();
  11841. break;
  11842. case OPS.transform:
  11843. this.stateManager.transform(args);
  11844. break;
  11845. }
  11846. }
  11847. };
  11848. return EvaluatorPreprocessor;
  11849. })();
  11850. var QueueOptimizer = (function QueueOptimizerClosure() {
  11851. function addState(parentState, pattern, fn) {
  11852. var state = parentState;
  11853. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11854. var item = pattern[i];
  11855. state = (state[item] || (state[item] = []));
  11856. }
  11857. state[pattern[pattern.length - 1]] = fn;
  11858. }
  11859. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11860. argsArray) {
  11861. // Handles special case of mainly LaTeX documents which use image masks to
  11862. // draw lines with the current fill style.
  11863. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11864. // have been found at iFirstSave.
  11865. var iFirstPIMXO = iFirstSave + 2;
  11866. for (var i = 0; i < count; i++) {
  11867. var arg = argsArray[iFirstPIMXO + 4 * i];
  11868. var imageMask = arg.length === 1 && arg[0];
  11869. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11870. (!imageMask.data.length ||
  11871. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11872. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11873. continue;
  11874. }
  11875. break;
  11876. }
  11877. return count - i;
  11878. }
  11879. var InitialState = [];
  11880. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11881. // sequences with one |paintInlineImageXObjectGroup| operation.
  11882. addState(InitialState,
  11883. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11884. function foundInlineImageGroup(context) {
  11885. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11886. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11887. var MAX_WIDTH = 1000;
  11888. var IMAGE_PADDING = 1;
  11889. var fnArray = context.fnArray, argsArray = context.argsArray;
  11890. var curr = context.iCurr;
  11891. var iFirstSave = curr - 3;
  11892. var iFirstTransform = curr - 2;
  11893. var iFirstPIIXO = curr - 1;
  11894. // Look for the quartets.
  11895. var i = iFirstSave + 4;
  11896. var ii = fnArray.length;
  11897. while (i + 3 < ii) {
  11898. if (fnArray[i] !== OPS.save ||
  11899. fnArray[i + 1] !== OPS.transform ||
  11900. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11901. fnArray[i + 3] !== OPS.restore) {
  11902. break; // ops don't match
  11903. }
  11904. i += 4;
  11905. }
  11906. // At this point, i is the index of the first op past the last valid
  11907. // quartet.
  11908. var count = Math.min((i - iFirstSave) / 4,
  11909. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11910. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11911. return i;
  11912. }
  11913. // assuming that heights of those image is too small (~1 pixel)
  11914. // packing as much as possible by lines
  11915. var maxX = 0;
  11916. var map = [], maxLineHeight = 0;
  11917. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11918. var q;
  11919. for (q = 0; q < count; q++) {
  11920. var transform = argsArray[iFirstTransform + (q << 2)];
  11921. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11922. if (currentX + img.width > MAX_WIDTH) {
  11923. // starting new line
  11924. maxX = Math.max(maxX, currentX);
  11925. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11926. currentX = 0;
  11927. maxLineHeight = 0;
  11928. }
  11929. map.push({
  11930. transform: transform,
  11931. x: currentX, y: currentY,
  11932. w: img.width, h: img.height
  11933. });
  11934. currentX += img.width + 2 * IMAGE_PADDING;
  11935. maxLineHeight = Math.max(maxLineHeight, img.height);
  11936. }
  11937. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11938. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11939. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11940. var imgRowSize = imgWidth << 2;
  11941. for (q = 0; q < count; q++) {
  11942. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11943. // Copy image by lines and extends pixels into padding.
  11944. var rowSize = map[q].w << 2;
  11945. var dataOffset = 0;
  11946. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11947. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11948. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11949. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11950. dataOffset += rowSize;
  11951. offset += imgRowSize;
  11952. }
  11953. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11954. while (offset >= 0) {
  11955. data[offset - 4] = data[offset];
  11956. data[offset - 3] = data[offset + 1];
  11957. data[offset - 2] = data[offset + 2];
  11958. data[offset - 1] = data[offset + 3];
  11959. data[offset + rowSize] = data[offset + rowSize - 4];
  11960. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11961. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11962. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11963. offset -= imgRowSize;
  11964. }
  11965. }
  11966. // Replace queue items.
  11967. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11968. argsArray.splice(iFirstSave, count * 4,
  11969. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11970. data: imgData }, map]);
  11971. return iFirstSave + 1;
  11972. });
  11973. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11974. // sequences with one |paintImageMaskXObjectGroup| or one
  11975. // |paintImageMaskXObjectRepeat| operation.
  11976. addState(InitialState,
  11977. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11978. function foundImageMaskGroup(context) {
  11979. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11980. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11981. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11982. var fnArray = context.fnArray, argsArray = context.argsArray;
  11983. var curr = context.iCurr;
  11984. var iFirstSave = curr - 3;
  11985. var iFirstTransform = curr - 2;
  11986. var iFirstPIMXO = curr - 1;
  11987. // Look for the quartets.
  11988. var i = iFirstSave + 4;
  11989. var ii = fnArray.length;
  11990. while (i + 3 < ii) {
  11991. if (fnArray[i] !== OPS.save ||
  11992. fnArray[i + 1] !== OPS.transform ||
  11993. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11994. fnArray[i + 3] !== OPS.restore) {
  11995. break; // ops don't match
  11996. }
  11997. i += 4;
  11998. }
  11999. // At this point, i is the index of the first op past the last valid
  12000. // quartet.
  12001. var count = (i - iFirstSave) / 4;
  12002. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12003. argsArray);
  12004. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  12005. return i;
  12006. }
  12007. var q;
  12008. var isSameImage = false;
  12009. var iTransform, transformArgs;
  12010. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  12011. if (argsArray[iFirstTransform][1] === 0 &&
  12012. argsArray[iFirstTransform][2] === 0) {
  12013. isSameImage = true;
  12014. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12015. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12016. iTransform = iFirstTransform + 4;
  12017. var iPIMXO = iFirstPIMXO + 4;
  12018. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  12019. transformArgs = argsArray[iTransform];
  12020. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  12021. transformArgs[0] !== firstTransformArg0 ||
  12022. transformArgs[1] !== 0 ||
  12023. transformArgs[2] !== 0 ||
  12024. transformArgs[3] !== firstTransformArg3) {
  12025. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  12026. isSameImage = false;
  12027. } else {
  12028. count = q;
  12029. }
  12030. break; // different image or transform
  12031. }
  12032. }
  12033. }
  12034. if (isSameImage) {
  12035. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  12036. var positions = new Float32Array(count * 2);
  12037. iTransform = iFirstTransform;
  12038. for (q = 0; q < count; q++, iTransform += 4) {
  12039. transformArgs = argsArray[iTransform];
  12040. positions[(q << 1)] = transformArgs[4];
  12041. positions[(q << 1) + 1] = transformArgs[5];
  12042. }
  12043. // Replace queue items.
  12044. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  12045. argsArray.splice(iFirstSave, count * 4,
  12046. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  12047. } else {
  12048. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  12049. var images = [];
  12050. for (q = 0; q < count; q++) {
  12051. transformArgs = argsArray[iFirstTransform + (q << 2)];
  12052. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  12053. images.push({ data: maskParams.data, width: maskParams.width,
  12054. height: maskParams.height,
  12055. transform: transformArgs });
  12056. }
  12057. // Replace queue items.
  12058. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  12059. argsArray.splice(iFirstSave, count * 4, [images]);
  12060. }
  12061. return iFirstSave + 1;
  12062. });
  12063. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  12064. // with one paintImageXObjectRepeat operation, if the |transform| and
  12065. // |paintImageXObjectRepeat| ops are appropriate.
  12066. addState(InitialState,
  12067. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  12068. function (context) {
  12069. var MIN_IMAGES_IN_BLOCK = 3;
  12070. var MAX_IMAGES_IN_BLOCK = 1000;
  12071. var fnArray = context.fnArray, argsArray = context.argsArray;
  12072. var curr = context.iCurr;
  12073. var iFirstSave = curr - 3;
  12074. var iFirstTransform = curr - 2;
  12075. var iFirstPIXO = curr - 1;
  12076. var iFirstRestore = curr;
  12077. if (argsArray[iFirstTransform][1] !== 0 ||
  12078. argsArray[iFirstTransform][2] !== 0) {
  12079. return iFirstRestore + 1; // transform has the wrong form
  12080. }
  12081. // Look for the quartets.
  12082. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  12083. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12084. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12085. var i = iFirstSave + 4;
  12086. var ii = fnArray.length;
  12087. while (i + 3 < ii) {
  12088. if (fnArray[i] !== OPS.save ||
  12089. fnArray[i + 1] !== OPS.transform ||
  12090. fnArray[i + 2] !== OPS.paintImageXObject ||
  12091. fnArray[i + 3] !== OPS.restore) {
  12092. break; // ops don't match
  12093. }
  12094. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  12095. argsArray[i + 1][1] !== 0 ||
  12096. argsArray[i + 1][2] !== 0 ||
  12097. argsArray[i + 1][3] !== firstTransformArg3) {
  12098. break; // transforms don't match
  12099. }
  12100. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  12101. break; // images don't match
  12102. }
  12103. i += 4;
  12104. }
  12105. // At this point, i is the index of the first op past the last valid
  12106. // quartet.
  12107. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  12108. if (count < MIN_IMAGES_IN_BLOCK) {
  12109. return i;
  12110. }
  12111. // Extract the (x,y) positions from all of the matching transforms.
  12112. var positions = new Float32Array(count * 2);
  12113. var iTransform = iFirstTransform;
  12114. for (var q = 0; q < count; q++, iTransform += 4) {
  12115. var transformArgs = argsArray[iTransform];
  12116. positions[(q << 1)] = transformArgs[4];
  12117. positions[(q << 1) + 1] = transformArgs[5];
  12118. }
  12119. // Replace queue items.
  12120. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  12121. positions];
  12122. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  12123. argsArray.splice(iFirstSave, count * 4, args);
  12124. return iFirstSave + 1;
  12125. });
  12126. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  12127. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  12128. // sequences, if the font for each one is the same.
  12129. addState(InitialState,
  12130. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  12131. function (context) {
  12132. var MIN_CHARS_IN_BLOCK = 3;
  12133. var MAX_CHARS_IN_BLOCK = 1000;
  12134. var fnArray = context.fnArray, argsArray = context.argsArray;
  12135. var curr = context.iCurr;
  12136. var iFirstBeginText = curr - 4;
  12137. var iFirstSetFont = curr - 3;
  12138. var iFirstSetTextMatrix = curr - 2;
  12139. var iFirstShowText = curr - 1;
  12140. var iFirstEndText = curr;
  12141. // Look for the quintets.
  12142. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  12143. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  12144. var i = iFirstBeginText + 5;
  12145. var ii = fnArray.length;
  12146. while (i + 4 < ii) {
  12147. if (fnArray[i] !== OPS.beginText ||
  12148. fnArray[i + 1] !== OPS.setFont ||
  12149. fnArray[i + 2] !== OPS.setTextMatrix ||
  12150. fnArray[i + 3] !== OPS.showText ||
  12151. fnArray[i + 4] !== OPS.endText) {
  12152. break; // ops don't match
  12153. }
  12154. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  12155. argsArray[i + 1][1] !== firstSetFontArg1) {
  12156. break; // fonts don't match
  12157. }
  12158. i += 5;
  12159. }
  12160. // At this point, i is the index of the first op past the last valid
  12161. // quintet.
  12162. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12163. if (count < MIN_CHARS_IN_BLOCK) {
  12164. return i;
  12165. }
  12166. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  12167. // showText, endText), include that as well. (E.g. <something> might be
  12168. // |dependency|.)
  12169. var iFirst = iFirstBeginText;
  12170. if (iFirstBeginText >= 4 &&
  12171. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  12172. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  12173. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  12174. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  12175. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  12176. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  12177. count++;
  12178. iFirst -= 5;
  12179. }
  12180. // Remove (endText, beginText, setFont) trios.
  12181. var iEndText = iFirst + 4;
  12182. for (var q = 1; q < count; q++) {
  12183. fnArray.splice(iEndText, 3);
  12184. argsArray.splice(iEndText, 3);
  12185. iEndText += 2;
  12186. }
  12187. return iEndText + 1;
  12188. });
  12189. function QueueOptimizer() {}
  12190. QueueOptimizer.prototype = {
  12191. optimize: function QueueOptimizer_optimize(queue) {
  12192. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12193. var context = {
  12194. iCurr: 0,
  12195. fnArray: fnArray,
  12196. argsArray: argsArray
  12197. };
  12198. var state;
  12199. var i = 0, ii = fnArray.length;
  12200. while (i < ii) {
  12201. state = (state || InitialState)[fnArray[i]];
  12202. if (typeof state === 'function') { // we found some handler
  12203. context.iCurr = i;
  12204. // state() returns the index of the first non-matching op (if we
  12205. // didn't match) or the first op past the modified ops (if we did
  12206. // match and replace).
  12207. i = state(context);
  12208. state = undefined; // reset the state machine
  12209. ii = context.fnArray.length;
  12210. } else {
  12211. i++;
  12212. }
  12213. }
  12214. }
  12215. };
  12216. return QueueOptimizer;
  12217. })();
  12218. var BUILT_IN_CMAPS = [
  12219. // << Start unicode maps.
  12220. 'Adobe-GB1-UCS2',
  12221. 'Adobe-CNS1-UCS2',
  12222. 'Adobe-Japan1-UCS2',
  12223. 'Adobe-Korea1-UCS2',
  12224. // >> End unicode maps.
  12225. '78-EUC-H',
  12226. '78-EUC-V',
  12227. '78-H',
  12228. '78-RKSJ-H',
  12229. '78-RKSJ-V',
  12230. '78-V',
  12231. '78ms-RKSJ-H',
  12232. '78ms-RKSJ-V',
  12233. '83pv-RKSJ-H',
  12234. '90ms-RKSJ-H',
  12235. '90ms-RKSJ-V',
  12236. '90msp-RKSJ-H',
  12237. '90msp-RKSJ-V',
  12238. '90pv-RKSJ-H',
  12239. '90pv-RKSJ-V',
  12240. 'Add-H',
  12241. 'Add-RKSJ-H',
  12242. 'Add-RKSJ-V',
  12243. 'Add-V',
  12244. 'Adobe-CNS1-0',
  12245. 'Adobe-CNS1-1',
  12246. 'Adobe-CNS1-2',
  12247. 'Adobe-CNS1-3',
  12248. 'Adobe-CNS1-4',
  12249. 'Adobe-CNS1-5',
  12250. 'Adobe-CNS1-6',
  12251. 'Adobe-GB1-0',
  12252. 'Adobe-GB1-1',
  12253. 'Adobe-GB1-2',
  12254. 'Adobe-GB1-3',
  12255. 'Adobe-GB1-4',
  12256. 'Adobe-GB1-5',
  12257. 'Adobe-Japan1-0',
  12258. 'Adobe-Japan1-1',
  12259. 'Adobe-Japan1-2',
  12260. 'Adobe-Japan1-3',
  12261. 'Adobe-Japan1-4',
  12262. 'Adobe-Japan1-5',
  12263. 'Adobe-Japan1-6',
  12264. 'Adobe-Korea1-0',
  12265. 'Adobe-Korea1-1',
  12266. 'Adobe-Korea1-2',
  12267. 'B5-H',
  12268. 'B5-V',
  12269. 'B5pc-H',
  12270. 'B5pc-V',
  12271. 'CNS-EUC-H',
  12272. 'CNS-EUC-V',
  12273. 'CNS1-H',
  12274. 'CNS1-V',
  12275. 'CNS2-H',
  12276. 'CNS2-V',
  12277. 'ETHK-B5-H',
  12278. 'ETHK-B5-V',
  12279. 'ETen-B5-H',
  12280. 'ETen-B5-V',
  12281. 'ETenms-B5-H',
  12282. 'ETenms-B5-V',
  12283. 'EUC-H',
  12284. 'EUC-V',
  12285. 'Ext-H',
  12286. 'Ext-RKSJ-H',
  12287. 'Ext-RKSJ-V',
  12288. 'Ext-V',
  12289. 'GB-EUC-H',
  12290. 'GB-EUC-V',
  12291. 'GB-H',
  12292. 'GB-V',
  12293. 'GBK-EUC-H',
  12294. 'GBK-EUC-V',
  12295. 'GBK2K-H',
  12296. 'GBK2K-V',
  12297. 'GBKp-EUC-H',
  12298. 'GBKp-EUC-V',
  12299. 'GBT-EUC-H',
  12300. 'GBT-EUC-V',
  12301. 'GBT-H',
  12302. 'GBT-V',
  12303. 'GBTpc-EUC-H',
  12304. 'GBTpc-EUC-V',
  12305. 'GBpc-EUC-H',
  12306. 'GBpc-EUC-V',
  12307. 'H',
  12308. 'HKdla-B5-H',
  12309. 'HKdla-B5-V',
  12310. 'HKdlb-B5-H',
  12311. 'HKdlb-B5-V',
  12312. 'HKgccs-B5-H',
  12313. 'HKgccs-B5-V',
  12314. 'HKm314-B5-H',
  12315. 'HKm314-B5-V',
  12316. 'HKm471-B5-H',
  12317. 'HKm471-B5-V',
  12318. 'HKscs-B5-H',
  12319. 'HKscs-B5-V',
  12320. 'Hankaku',
  12321. 'Hiragana',
  12322. 'KSC-EUC-H',
  12323. 'KSC-EUC-V',
  12324. 'KSC-H',
  12325. 'KSC-Johab-H',
  12326. 'KSC-Johab-V',
  12327. 'KSC-V',
  12328. 'KSCms-UHC-H',
  12329. 'KSCms-UHC-HW-H',
  12330. 'KSCms-UHC-HW-V',
  12331. 'KSCms-UHC-V',
  12332. 'KSCpc-EUC-H',
  12333. 'KSCpc-EUC-V',
  12334. 'Katakana',
  12335. 'NWP-H',
  12336. 'NWP-V',
  12337. 'RKSJ-H',
  12338. 'RKSJ-V',
  12339. 'Roman',
  12340. 'UniCNS-UCS2-H',
  12341. 'UniCNS-UCS2-V',
  12342. 'UniCNS-UTF16-H',
  12343. 'UniCNS-UTF16-V',
  12344. 'UniCNS-UTF32-H',
  12345. 'UniCNS-UTF32-V',
  12346. 'UniCNS-UTF8-H',
  12347. 'UniCNS-UTF8-V',
  12348. 'UniGB-UCS2-H',
  12349. 'UniGB-UCS2-V',
  12350. 'UniGB-UTF16-H',
  12351. 'UniGB-UTF16-V',
  12352. 'UniGB-UTF32-H',
  12353. 'UniGB-UTF32-V',
  12354. 'UniGB-UTF8-H',
  12355. 'UniGB-UTF8-V',
  12356. 'UniJIS-UCS2-H',
  12357. 'UniJIS-UCS2-HW-H',
  12358. 'UniJIS-UCS2-HW-V',
  12359. 'UniJIS-UCS2-V',
  12360. 'UniJIS-UTF16-H',
  12361. 'UniJIS-UTF16-V',
  12362. 'UniJIS-UTF32-H',
  12363. 'UniJIS-UTF32-V',
  12364. 'UniJIS-UTF8-H',
  12365. 'UniJIS-UTF8-V',
  12366. 'UniJIS2004-UTF16-H',
  12367. 'UniJIS2004-UTF16-V',
  12368. 'UniJIS2004-UTF32-H',
  12369. 'UniJIS2004-UTF32-V',
  12370. 'UniJIS2004-UTF8-H',
  12371. 'UniJIS2004-UTF8-V',
  12372. 'UniJISPro-UCS2-HW-V',
  12373. 'UniJISPro-UCS2-V',
  12374. 'UniJISPro-UTF8-V',
  12375. 'UniJISX0213-UTF32-H',
  12376. 'UniJISX0213-UTF32-V',
  12377. 'UniJISX02132004-UTF32-H',
  12378. 'UniJISX02132004-UTF32-V',
  12379. 'UniKS-UCS2-H',
  12380. 'UniKS-UCS2-V',
  12381. 'UniKS-UTF16-H',
  12382. 'UniKS-UTF16-V',
  12383. 'UniKS-UTF32-H',
  12384. 'UniKS-UTF32-V',
  12385. 'UniKS-UTF8-H',
  12386. 'UniKS-UTF8-V',
  12387. 'V',
  12388. 'WP-Symbol'];
  12389. // CMap, not to be confused with TrueType's cmap.
  12390. var CMap = (function CMapClosure() {
  12391. function CMap(builtInCMap) {
  12392. // Codespace ranges are stored as follows:
  12393. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12394. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12395. this.codespaceRanges = [[], [], [], []];
  12396. this.numCodespaceRanges = 0;
  12397. // Map entries have one of two forms.
  12398. // - cid chars are 16-bit unsigned integers, stored as integers.
  12399. // - bf chars are variable-length byte sequences, stored as strings, with
  12400. // one byte per character.
  12401. this._map = [];
  12402. this.name = '';
  12403. this.vertical = false;
  12404. this.useCMap = null;
  12405. this.builtInCMap = builtInCMap;
  12406. }
  12407. CMap.prototype = {
  12408. addCodespaceRange: function(n, low, high) {
  12409. this.codespaceRanges[n - 1].push(low, high);
  12410. this.numCodespaceRanges++;
  12411. },
  12412. mapCidRange: function(low, high, dstLow) {
  12413. while (low <= high) {
  12414. this._map[low++] = dstLow++;
  12415. }
  12416. },
  12417. mapBfRange: function(low, high, dstLow) {
  12418. var lastByte = dstLow.length - 1;
  12419. while (low <= high) {
  12420. this._map[low++] = dstLow;
  12421. // Only the last byte has to be incremented.
  12422. dstLow = dstLow.substr(0, lastByte) +
  12423. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12424. }
  12425. },
  12426. mapBfRangeToArray: function(low, high, array) {
  12427. var i = 0, ii = array.length;
  12428. while (low <= high && i < ii) {
  12429. this._map[low] = array[i++];
  12430. ++low;
  12431. }
  12432. },
  12433. // This is used for both bf and cid chars.
  12434. mapOne: function(src, dst) {
  12435. this._map[src] = dst;
  12436. },
  12437. lookup: function(code) {
  12438. return this._map[code];
  12439. },
  12440. contains: function(code) {
  12441. return this._map[code] !== undefined;
  12442. },
  12443. forEach: function(callback) {
  12444. // Most maps have fewer than 65536 entries, and for those we use normal
  12445. // array iteration. But really sparse tables are possible -- e.g. with
  12446. // indices in the *billions*. For such tables we use for..in, which isn't
  12447. // ideal because it stringifies the indices for all present elements, but
  12448. // it does avoid iterating over every undefined entry.
  12449. var map = this._map;
  12450. var length = map.length;
  12451. var i;
  12452. if (length <= 0x10000) {
  12453. for (i = 0; i < length; i++) {
  12454. if (map[i] !== undefined) {
  12455. callback(i, map[i]);
  12456. }
  12457. }
  12458. } else {
  12459. for (i in this._map) {
  12460. callback(i, map[i]);
  12461. }
  12462. }
  12463. },
  12464. charCodeOf: function(value) {
  12465. return this._map.indexOf(value);
  12466. },
  12467. getMap: function() {
  12468. return this._map;
  12469. },
  12470. readCharCode: function(str, offset, out) {
  12471. var c = 0;
  12472. var codespaceRanges = this.codespaceRanges;
  12473. var codespaceRangesLen = this.codespaceRanges.length;
  12474. // 9.7.6.2 CMap Mapping
  12475. // The code length is at most 4.
  12476. for (var n = 0; n < codespaceRangesLen; n++) {
  12477. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12478. // Check each codespace range to see if it falls within.
  12479. var codespaceRange = codespaceRanges[n];
  12480. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12481. var low = codespaceRange[k++];
  12482. var high = codespaceRange[k++];
  12483. if (c >= low && c <= high) {
  12484. out.charcode = c;
  12485. out.length = n + 1;
  12486. return;
  12487. }
  12488. }
  12489. }
  12490. out.charcode = 0;
  12491. out.length = 1;
  12492. },
  12493. get isIdentityCMap() {
  12494. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12495. return false;
  12496. }
  12497. if (this._map.length !== 0x10000) {
  12498. return false;
  12499. }
  12500. for (var i = 0; i < 0x10000; i++) {
  12501. if (this._map[i] !== i) {
  12502. return false;
  12503. }
  12504. }
  12505. return true;
  12506. }
  12507. };
  12508. return CMap;
  12509. })();
  12510. // A special case of CMap, where the _map array implicitly has a length of
  12511. // 65536 and each element is equal to its index.
  12512. var IdentityCMap = (function IdentityCMapClosure() {
  12513. function IdentityCMap(vertical, n) {
  12514. CMap.call(this);
  12515. this.vertical = vertical;
  12516. this.addCodespaceRange(n, 0, 0xffff);
  12517. }
  12518. Util.inherit(IdentityCMap, CMap, {});
  12519. IdentityCMap.prototype = {
  12520. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12521. mapCidRange: function(low, high, dstLow) {
  12522. error('should not call mapCidRange');
  12523. },
  12524. mapBfRange: function(low, high, dstLow) {
  12525. error('should not call mapBfRange');
  12526. },
  12527. mapBfRangeToArray: function(low, high, array) {
  12528. error('should not call mapBfRangeToArray');
  12529. },
  12530. mapOne: function(src, dst) {
  12531. error('should not call mapCidOne');
  12532. },
  12533. lookup: function(code) {
  12534. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12535. },
  12536. contains: function(code) {
  12537. return isInt(code) && code <= 0xffff;
  12538. },
  12539. forEach: function(callback) {
  12540. for (var i = 0; i <= 0xffff; i++) {
  12541. callback(i, i);
  12542. }
  12543. },
  12544. charCodeOf: function(value) {
  12545. return (isInt(value) && value <= 0xffff) ? value : -1;
  12546. },
  12547. getMap: function() {
  12548. // Sometimes identity maps must be instantiated, but it's rare.
  12549. var map = new Array(0x10000);
  12550. for (var i = 0; i <= 0xffff; i++) {
  12551. map[i] = i;
  12552. }
  12553. return map;
  12554. },
  12555. readCharCode: CMap.prototype.readCharCode,
  12556. get isIdentityCMap() {
  12557. error('should not access .isIdentityCMap');
  12558. }
  12559. };
  12560. return IdentityCMap;
  12561. })();
  12562. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12563. function fetchBinaryData(url) {
  12564. var nonBinaryRequest = PDFJS.disableWorker;
  12565. var request = new XMLHttpRequest();
  12566. request.open('GET', url, false);
  12567. if (!nonBinaryRequest) {
  12568. try {
  12569. request.responseType = 'arraybuffer';
  12570. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12571. } catch (e) {
  12572. nonBinaryRequest = true;
  12573. }
  12574. }
  12575. if (nonBinaryRequest && request.overrideMimeType) {
  12576. request.overrideMimeType('text/plain; charset=x-user-defined');
  12577. }
  12578. request.send(null);
  12579. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12580. error('Unable to get binary cMap at: ' + url);
  12581. }
  12582. if (nonBinaryRequest) {
  12583. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12584. return ch.charCodeAt(0) & 255;
  12585. });
  12586. return new Uint8Array(data);
  12587. }
  12588. return new Uint8Array(request.response);
  12589. }
  12590. function hexToInt(a, size) {
  12591. var n = 0;
  12592. for (var i = 0; i <= size; i++) {
  12593. n = (n << 8) | a[i];
  12594. }
  12595. return n >>> 0;
  12596. }
  12597. function hexToStr(a, size) {
  12598. // This code is hot. Special-case some common values to avoid creating an
  12599. // object with subarray().
  12600. if (size === 1) {
  12601. return String.fromCharCode(a[0], a[1]);
  12602. }
  12603. if (size === 3) {
  12604. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12605. }
  12606. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12607. }
  12608. function addHex(a, b, size) {
  12609. var c = 0;
  12610. for (var i = size; i >= 0; i--) {
  12611. c += a[i] + b[i];
  12612. a[i] = c & 255;
  12613. c >>= 8;
  12614. }
  12615. }
  12616. function incHex(a, size) {
  12617. var c = 1;
  12618. for (var i = size; i >= 0 && c > 0; i--) {
  12619. c += a[i];
  12620. a[i] = c & 255;
  12621. c >>= 8;
  12622. }
  12623. }
  12624. var MAX_NUM_SIZE = 16;
  12625. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12626. function BinaryCMapStream(data) {
  12627. this.buffer = data;
  12628. this.pos = 0;
  12629. this.end = data.length;
  12630. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12631. }
  12632. BinaryCMapStream.prototype = {
  12633. readByte: function () {
  12634. if (this.pos >= this.end) {
  12635. return -1;
  12636. }
  12637. return this.buffer[this.pos++];
  12638. },
  12639. readNumber: function () {
  12640. var n = 0;
  12641. var last;
  12642. do {
  12643. var b = this.readByte();
  12644. if (b < 0) {
  12645. error('unexpected EOF in bcmap');
  12646. }
  12647. last = !(b & 0x80);
  12648. n = (n << 7) | (b & 0x7F);
  12649. } while (!last);
  12650. return n;
  12651. },
  12652. readSigned: function () {
  12653. var n = this.readNumber();
  12654. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12655. },
  12656. readHex: function (num, size) {
  12657. num.set(this.buffer.subarray(this.pos,
  12658. this.pos + size + 1));
  12659. this.pos += size + 1;
  12660. },
  12661. readHexNumber: function (num, size) {
  12662. var last;
  12663. var stack = this.tmpBuf, sp = 0;
  12664. do {
  12665. var b = this.readByte();
  12666. if (b < 0) {
  12667. error('unexpected EOF in bcmap');
  12668. }
  12669. last = !(b & 0x80);
  12670. stack[sp++] = b & 0x7F;
  12671. } while (!last);
  12672. var i = size, buffer = 0, bufferSize = 0;
  12673. while (i >= 0) {
  12674. while (bufferSize < 8 && stack.length > 0) {
  12675. buffer = (stack[--sp] << bufferSize) | buffer;
  12676. bufferSize += 7;
  12677. }
  12678. num[i] = buffer & 255;
  12679. i--;
  12680. buffer >>= 8;
  12681. bufferSize -= 8;
  12682. }
  12683. },
  12684. readHexSigned: function (num, size) {
  12685. this.readHexNumber(num, size);
  12686. var sign = num[size] & 1 ? 255 : 0;
  12687. var c = 0;
  12688. for (var i = 0; i <= size; i++) {
  12689. c = ((c & 1) << 8) | num[i];
  12690. num[i] = (c >> 1) ^ sign;
  12691. }
  12692. },
  12693. readString: function () {
  12694. var len = this.readNumber();
  12695. var s = '';
  12696. for (var i = 0; i < len; i++) {
  12697. s += String.fromCharCode(this.readNumber());
  12698. }
  12699. return s;
  12700. }
  12701. };
  12702. function processBinaryCMap(url, cMap, extend) {
  12703. var data = fetchBinaryData(url);
  12704. var stream = new BinaryCMapStream(data);
  12705. var header = stream.readByte();
  12706. cMap.vertical = !!(header & 1);
  12707. var useCMap = null;
  12708. var start = new Uint8Array(MAX_NUM_SIZE);
  12709. var end = new Uint8Array(MAX_NUM_SIZE);
  12710. var char = new Uint8Array(MAX_NUM_SIZE);
  12711. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12712. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12713. var code;
  12714. var b;
  12715. while ((b = stream.readByte()) >= 0) {
  12716. var type = b >> 5;
  12717. if (type === 7) { // metadata, e.g. comment or usecmap
  12718. switch (b & 0x1F) {
  12719. case 0:
  12720. stream.readString(); // skipping comment
  12721. break;
  12722. case 1:
  12723. useCMap = stream.readString();
  12724. break;
  12725. }
  12726. continue;
  12727. }
  12728. var sequence = !!(b & 0x10);
  12729. var dataSize = b & 15;
  12730. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12731. var ucs2DataSize = 1;
  12732. var subitemsCount = stream.readNumber();
  12733. var i;
  12734. switch (type) {
  12735. case 0: // codespacerange
  12736. stream.readHex(start, dataSize);
  12737. stream.readHexNumber(end, dataSize);
  12738. addHex(end, start, dataSize);
  12739. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12740. hexToInt(end, dataSize));
  12741. for (i = 1; i < subitemsCount; i++) {
  12742. incHex(end, dataSize);
  12743. stream.readHexNumber(start, dataSize);
  12744. addHex(start, end, dataSize);
  12745. stream.readHexNumber(end, dataSize);
  12746. addHex(end, start, dataSize);
  12747. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12748. hexToInt(end, dataSize));
  12749. }
  12750. break;
  12751. case 1: // notdefrange
  12752. stream.readHex(start, dataSize);
  12753. stream.readHexNumber(end, dataSize);
  12754. addHex(end, start, dataSize);
  12755. code = stream.readNumber();
  12756. // undefined range, skipping
  12757. for (i = 1; i < subitemsCount; i++) {
  12758. incHex(end, dataSize);
  12759. stream.readHexNumber(start, dataSize);
  12760. addHex(start, end, dataSize);
  12761. stream.readHexNumber(end, dataSize);
  12762. addHex(end, start, dataSize);
  12763. code = stream.readNumber();
  12764. // nop
  12765. }
  12766. break;
  12767. case 2: // cidchar
  12768. stream.readHex(char, dataSize);
  12769. code = stream.readNumber();
  12770. cMap.mapOne(hexToInt(char, dataSize), code);
  12771. for (i = 1; i < subitemsCount; i++) {
  12772. incHex(char, dataSize);
  12773. if (!sequence) {
  12774. stream.readHexNumber(tmp, dataSize);
  12775. addHex(char, tmp, dataSize);
  12776. }
  12777. code = stream.readSigned() + (code + 1);
  12778. cMap.mapOne(hexToInt(char, dataSize), code);
  12779. }
  12780. break;
  12781. case 3: // cidrange
  12782. stream.readHex(start, dataSize);
  12783. stream.readHexNumber(end, dataSize);
  12784. addHex(end, start, dataSize);
  12785. code = stream.readNumber();
  12786. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12787. code);
  12788. for (i = 1; i < subitemsCount; i++) {
  12789. incHex(end, dataSize);
  12790. if (!sequence) {
  12791. stream.readHexNumber(start, dataSize);
  12792. addHex(start, end, dataSize);
  12793. } else {
  12794. start.set(end);
  12795. }
  12796. stream.readHexNumber(end, dataSize);
  12797. addHex(end, start, dataSize);
  12798. code = stream.readNumber();
  12799. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12800. code);
  12801. }
  12802. break;
  12803. case 4: // bfchar
  12804. stream.readHex(char, ucs2DataSize);
  12805. stream.readHex(charCode, dataSize);
  12806. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12807. hexToStr(charCode, dataSize));
  12808. for (i = 1; i < subitemsCount; i++) {
  12809. incHex(char, ucs2DataSize);
  12810. if (!sequence) {
  12811. stream.readHexNumber(tmp, ucs2DataSize);
  12812. addHex(char, tmp, ucs2DataSize);
  12813. }
  12814. incHex(charCode, dataSize);
  12815. stream.readHexSigned(tmp, dataSize);
  12816. addHex(charCode, tmp, dataSize);
  12817. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12818. hexToStr(charCode, dataSize));
  12819. }
  12820. break;
  12821. case 5: // bfrange
  12822. stream.readHex(start, ucs2DataSize);
  12823. stream.readHexNumber(end, ucs2DataSize);
  12824. addHex(end, start, ucs2DataSize);
  12825. stream.readHex(charCode, dataSize);
  12826. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12827. hexToInt(end, ucs2DataSize),
  12828. hexToStr(charCode, dataSize));
  12829. for (i = 1; i < subitemsCount; i++) {
  12830. incHex(end, ucs2DataSize);
  12831. if (!sequence) {
  12832. stream.readHexNumber(start, ucs2DataSize);
  12833. addHex(start, end, ucs2DataSize);
  12834. } else {
  12835. start.set(end);
  12836. }
  12837. stream.readHexNumber(end, ucs2DataSize);
  12838. addHex(end, start, ucs2DataSize);
  12839. stream.readHex(charCode, dataSize);
  12840. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12841. hexToInt(end, ucs2DataSize),
  12842. hexToStr(charCode, dataSize));
  12843. }
  12844. break;
  12845. default:
  12846. error('Unknown type: ' + type);
  12847. break;
  12848. }
  12849. }
  12850. if (useCMap) {
  12851. extend(useCMap);
  12852. }
  12853. return cMap;
  12854. }
  12855. function BinaryCMapReader() {}
  12856. BinaryCMapReader.prototype = {
  12857. read: processBinaryCMap
  12858. };
  12859. return BinaryCMapReader;
  12860. })();
  12861. var CMapFactory = (function CMapFactoryClosure() {
  12862. function strToInt(str) {
  12863. var a = 0;
  12864. for (var i = 0; i < str.length; i++) {
  12865. a = (a << 8) | str.charCodeAt(i);
  12866. }
  12867. return a >>> 0;
  12868. }
  12869. function expectString(obj) {
  12870. if (!isString(obj)) {
  12871. error('Malformed CMap: expected string.');
  12872. }
  12873. }
  12874. function expectInt(obj) {
  12875. if (!isInt(obj)) {
  12876. error('Malformed CMap: expected int.');
  12877. }
  12878. }
  12879. function parseBfChar(cMap, lexer) {
  12880. while (true) {
  12881. var obj = lexer.getObj();
  12882. if (isEOF(obj)) {
  12883. break;
  12884. }
  12885. if (isCmd(obj, 'endbfchar')) {
  12886. return;
  12887. }
  12888. expectString(obj);
  12889. var src = strToInt(obj);
  12890. obj = lexer.getObj();
  12891. // TODO are /dstName used?
  12892. expectString(obj);
  12893. var dst = obj;
  12894. cMap.mapOne(src, dst);
  12895. }
  12896. }
  12897. function parseBfRange(cMap, lexer) {
  12898. while (true) {
  12899. var obj = lexer.getObj();
  12900. if (isEOF(obj)) {
  12901. break;
  12902. }
  12903. if (isCmd(obj, 'endbfrange')) {
  12904. return;
  12905. }
  12906. expectString(obj);
  12907. var low = strToInt(obj);
  12908. obj = lexer.getObj();
  12909. expectString(obj);
  12910. var high = strToInt(obj);
  12911. obj = lexer.getObj();
  12912. if (isInt(obj) || isString(obj)) {
  12913. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12914. cMap.mapBfRange(low, high, dstLow);
  12915. } else if (isCmd(obj, '[')) {
  12916. obj = lexer.getObj();
  12917. var array = [];
  12918. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12919. array.push(obj);
  12920. obj = lexer.getObj();
  12921. }
  12922. cMap.mapBfRangeToArray(low, high, array);
  12923. } else {
  12924. break;
  12925. }
  12926. }
  12927. error('Invalid bf range.');
  12928. }
  12929. function parseCidChar(cMap, lexer) {
  12930. while (true) {
  12931. var obj = lexer.getObj();
  12932. if (isEOF(obj)) {
  12933. break;
  12934. }
  12935. if (isCmd(obj, 'endcidchar')) {
  12936. return;
  12937. }
  12938. expectString(obj);
  12939. var src = strToInt(obj);
  12940. obj = lexer.getObj();
  12941. expectInt(obj);
  12942. var dst = obj;
  12943. cMap.mapOne(src, dst);
  12944. }
  12945. }
  12946. function parseCidRange(cMap, lexer) {
  12947. while (true) {
  12948. var obj = lexer.getObj();
  12949. if (isEOF(obj)) {
  12950. break;
  12951. }
  12952. if (isCmd(obj, 'endcidrange')) {
  12953. return;
  12954. }
  12955. expectString(obj);
  12956. var low = strToInt(obj);
  12957. obj = lexer.getObj();
  12958. expectString(obj);
  12959. var high = strToInt(obj);
  12960. obj = lexer.getObj();
  12961. expectInt(obj);
  12962. var dstLow = obj;
  12963. cMap.mapCidRange(low, high, dstLow);
  12964. }
  12965. }
  12966. function parseCodespaceRange(cMap, lexer) {
  12967. while (true) {
  12968. var obj = lexer.getObj();
  12969. if (isEOF(obj)) {
  12970. break;
  12971. }
  12972. if (isCmd(obj, 'endcodespacerange')) {
  12973. return;
  12974. }
  12975. if (!isString(obj)) {
  12976. break;
  12977. }
  12978. var low = strToInt(obj);
  12979. obj = lexer.getObj();
  12980. if (!isString(obj)) {
  12981. break;
  12982. }
  12983. var high = strToInt(obj);
  12984. cMap.addCodespaceRange(obj.length, low, high);
  12985. }
  12986. error('Invalid codespace range.');
  12987. }
  12988. function parseWMode(cMap, lexer) {
  12989. var obj = lexer.getObj();
  12990. if (isInt(obj)) {
  12991. cMap.vertical = !!obj;
  12992. }
  12993. }
  12994. function parseCMapName(cMap, lexer) {
  12995. var obj = lexer.getObj();
  12996. if (isName(obj) && isString(obj.name)) {
  12997. cMap.name = obj.name;
  12998. }
  12999. }
  13000. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  13001. var previous;
  13002. var embededUseCMap;
  13003. objLoop: while (true) {
  13004. var obj = lexer.getObj();
  13005. if (isEOF(obj)) {
  13006. break;
  13007. } else if (isName(obj)) {
  13008. if (obj.name === 'WMode') {
  13009. parseWMode(cMap, lexer);
  13010. } else if (obj.name === 'CMapName') {
  13011. parseCMapName(cMap, lexer);
  13012. }
  13013. previous = obj;
  13014. } else if (isCmd(obj)) {
  13015. switch (obj.cmd) {
  13016. case 'endcmap':
  13017. break objLoop;
  13018. case 'usecmap':
  13019. if (isName(previous)) {
  13020. embededUseCMap = previous.name;
  13021. }
  13022. break;
  13023. case 'begincodespacerange':
  13024. parseCodespaceRange(cMap, lexer);
  13025. break;
  13026. case 'beginbfchar':
  13027. parseBfChar(cMap, lexer);
  13028. break;
  13029. case 'begincidchar':
  13030. parseCidChar(cMap, lexer);
  13031. break;
  13032. case 'beginbfrange':
  13033. parseBfRange(cMap, lexer);
  13034. break;
  13035. case 'begincidrange':
  13036. parseCidRange(cMap, lexer);
  13037. break;
  13038. }
  13039. }
  13040. }
  13041. if (!useCMap && embededUseCMap) {
  13042. // Load the usecmap definition from the file only if there wasn't one
  13043. // specified.
  13044. useCMap = embededUseCMap;
  13045. }
  13046. if (useCMap) {
  13047. extendCMap(cMap, builtInCMapParams, useCMap);
  13048. }
  13049. }
  13050. function extendCMap(cMap, builtInCMapParams, useCMap) {
  13051. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  13052. // If there aren't any code space ranges defined clone all the parent ones
  13053. // into this cMap.
  13054. if (cMap.numCodespaceRanges === 0) {
  13055. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  13056. for (var i = 0; i < useCodespaceRanges.length; i++) {
  13057. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  13058. }
  13059. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  13060. }
  13061. // Merge the map into the current one, making sure not to override
  13062. // any previously defined entries.
  13063. cMap.useCMap.forEach(function(key, value) {
  13064. if (!cMap.contains(key)) {
  13065. cMap.mapOne(key, cMap.useCMap.lookup(key));
  13066. }
  13067. });
  13068. }
  13069. function parseBinaryCMap(name, builtInCMapParams) {
  13070. var url = builtInCMapParams.url + name + '.bcmap';
  13071. var cMap = new CMap(true);
  13072. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  13073. extendCMap(cMap, builtInCMapParams, useCMap);
  13074. });
  13075. return cMap;
  13076. }
  13077. function createBuiltInCMap(name, builtInCMapParams) {
  13078. if (name === 'Identity-H') {
  13079. return new IdentityCMap(false, 2);
  13080. } else if (name === 'Identity-V') {
  13081. return new IdentityCMap(true, 2);
  13082. }
  13083. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  13084. error('Unknown cMap name: ' + name);
  13085. }
  13086. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  13087. if (builtInCMapParams.packed) {
  13088. return parseBinaryCMap(name, builtInCMapParams);
  13089. }
  13090. var request = new XMLHttpRequest();
  13091. var url = builtInCMapParams.url + name;
  13092. request.open('GET', url, false);
  13093. request.send(null);
  13094. if (!request.responseText) {
  13095. error('Unable to get cMap at: ' + url);
  13096. }
  13097. var cMap = new CMap(true);
  13098. var lexer = new Lexer(new StringStream(request.responseText));
  13099. parseCMap(cMap, lexer, builtInCMapParams, null);
  13100. return cMap;
  13101. }
  13102. return {
  13103. create: function (encoding, builtInCMapParams, useCMap) {
  13104. if (isName(encoding)) {
  13105. return createBuiltInCMap(encoding.name, builtInCMapParams);
  13106. } else if (isStream(encoding)) {
  13107. var cMap = new CMap();
  13108. var lexer = new Lexer(encoding);
  13109. try {
  13110. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  13111. } catch (e) {
  13112. warn('Invalid CMap data. ' + e);
  13113. }
  13114. if (cMap.isIdentityCMap) {
  13115. return createBuiltInCMap(cMap.name, builtInCMapParams);
  13116. }
  13117. return cMap;
  13118. }
  13119. error('Encoding required.');
  13120. }
  13121. };
  13122. })();
  13123. // Unicode Private Use Area
  13124. var PRIVATE_USE_OFFSET_START = 0xE000;
  13125. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  13126. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  13127. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  13128. // except for Type 3 fonts
  13129. var PDF_GLYPH_SPACE_UNITS = 1000;
  13130. // Hinting is currently disabled due to unknown problems on windows
  13131. // in tracemonkey and various other pdfs with type1 fonts.
  13132. var HINTING_ENABLED = false;
  13133. // Accented charactars are not displayed properly on windows, using this flag
  13134. // to control analysis of seac charstrings.
  13135. var SEAC_ANALYSIS_ENABLED = false;
  13136. var FontFlags = {
  13137. FixedPitch: 1,
  13138. Serif: 2,
  13139. Symbolic: 4,
  13140. Script: 8,
  13141. Nonsymbolic: 32,
  13142. Italic: 64,
  13143. AllCap: 65536,
  13144. SmallCap: 131072,
  13145. ForceBold: 262144
  13146. };
  13147. var Encodings = {
  13148. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13149. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13150. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  13151. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  13152. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  13153. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  13154. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  13155. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  13156. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  13157. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  13158. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  13159. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  13160. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  13161. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  13162. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  13163. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  13164. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  13165. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  13166. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  13167. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13168. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  13169. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  13170. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  13171. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  13172. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  13173. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  13174. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  13175. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  13176. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  13177. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  13178. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  13179. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  13180. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  13181. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  13182. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  13183. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  13184. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  13185. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  13186. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  13187. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  13188. 'Ydieresissmall'],
  13189. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13190. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13191. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  13192. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  13193. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  13194. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  13195. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  13196. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  13197. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  13198. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  13199. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  13200. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  13201. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  13202. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  13203. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  13204. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  13205. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  13206. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  13207. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  13208. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  13209. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  13210. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  13211. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  13212. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13213. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13214. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13215. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13216. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13217. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13218. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13219. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13220. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13221. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13222. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13223. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13224. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13225. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13226. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13227. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13228. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13229. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13230. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13231. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13232. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13233. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13234. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13235. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13236. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13237. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13238. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13239. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13240. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13241. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13242. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13243. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13244. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13245. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13246. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13247. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13248. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13249. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13250. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13251. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13252. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13253. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13254. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13255. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13256. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13257. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13258. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13259. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13260. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13261. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13262. 'ogonek', 'caron'],
  13263. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13264. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13265. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13266. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13267. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13268. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13269. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13270. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13271. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13272. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13273. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13274. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13275. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13276. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13277. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13278. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13279. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13280. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13281. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13282. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13283. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13284. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13285. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13286. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13287. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13288. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13289. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13290. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13291. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13292. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13293. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13294. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13295. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13296. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13297. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13298. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13299. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13300. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13301. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13302. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13303. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13304. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13305. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13306. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13307. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13308. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13309. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13310. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13311. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13312. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13313. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13314. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13315. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13316. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13317. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13318. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13319. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13320. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13321. 'ydieresis'],
  13322. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13323. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13324. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13325. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13326. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13327. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13328. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13329. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13330. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13331. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13332. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13333. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13334. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13335. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13336. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13337. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13338. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13339. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13340. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13341. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13342. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13343. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13344. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13345. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13346. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13347. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13348. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13349. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13350. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13351. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13352. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13353. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13354. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13355. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13356. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13357. 'bracerightbt'],
  13358. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13359. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13360. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13361. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13362. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13363. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13364. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13365. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13366. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13367. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13368. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13369. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13370. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13371. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13372. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13373. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13374. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13375. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13376. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13377. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13378. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13379. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13380. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13381. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13382. };
  13383. /**
  13384. * Hold a map of decoded fonts and of the standard fourteen Type1
  13385. * fonts and their acronyms.
  13386. */
  13387. var stdFontMap = {
  13388. 'ArialNarrow': 'Helvetica',
  13389. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13390. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13391. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13392. 'ArialBlack': 'Helvetica',
  13393. 'ArialBlack-Bold': 'Helvetica-Bold',
  13394. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13395. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13396. 'Arial': 'Helvetica',
  13397. 'Arial-Bold': 'Helvetica-Bold',
  13398. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13399. 'Arial-Italic': 'Helvetica-Oblique',
  13400. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13401. 'Arial-BoldMT': 'Helvetica-Bold',
  13402. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13403. 'ArialMT': 'Helvetica',
  13404. 'Courier-Bold': 'Courier-Bold',
  13405. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13406. 'Courier-Italic': 'Courier-Oblique',
  13407. 'CourierNew': 'Courier',
  13408. 'CourierNew-Bold': 'Courier-Bold',
  13409. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13410. 'CourierNew-Italic': 'Courier-Oblique',
  13411. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13412. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13413. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13414. 'CourierNewPSMT': 'Courier',
  13415. 'Helvetica': 'Helvetica',
  13416. 'Helvetica-Bold': 'Helvetica-Bold',
  13417. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13418. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13419. 'Helvetica-Italic': 'Helvetica-Oblique',
  13420. 'Helvetica-Oblique':'Helvetica-Oblique',
  13421. 'Symbol-Bold': 'Symbol',
  13422. 'Symbol-BoldItalic': 'Symbol',
  13423. 'Symbol-Italic': 'Symbol',
  13424. 'TimesNewRoman': 'Times-Roman',
  13425. 'TimesNewRoman-Bold': 'Times-Bold',
  13426. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13427. 'TimesNewRoman-Italic': 'Times-Italic',
  13428. 'TimesNewRomanPS': 'Times-Roman',
  13429. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13430. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13431. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13432. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13433. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13434. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13435. 'TimesNewRomanPSMT': 'Times-Roman',
  13436. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13437. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13438. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13439. };
  13440. /**
  13441. * Holds the map of the non-standard fonts that might be included as a standard
  13442. * fonts without glyph data.
  13443. */
  13444. var nonStdFontMap = {
  13445. 'CenturyGothic': 'Helvetica',
  13446. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13447. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13448. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13449. 'ComicSansMS': 'Comic Sans MS',
  13450. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13451. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13452. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13453. 'LucidaConsole': 'Courier',
  13454. 'LucidaConsole-Bold': 'Courier-Bold',
  13455. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13456. 'LucidaConsole-Italic': 'Courier-Oblique',
  13457. 'MS-Gothic': 'MS Gothic',
  13458. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13459. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13460. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13461. 'MS-Mincho': 'MS Mincho',
  13462. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13463. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13464. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13465. 'MS-PGothic': 'MS PGothic',
  13466. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13467. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13468. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13469. 'MS-PMincho': 'MS PMincho',
  13470. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13471. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13472. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13473. 'Wingdings': 'ZapfDingbats'
  13474. };
  13475. var serifFonts = {
  13476. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13477. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13478. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13479. 'Arno': true, 'Aster': true, 'Aurora': true,
  13480. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13481. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13482. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13483. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13484. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13485. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13486. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13487. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13488. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13489. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13490. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13491. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13492. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13493. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13494. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13495. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13496. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13497. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13498. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13499. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13500. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13501. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13502. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13503. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13504. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13505. 'Miller': true, 'Minion': true, 'Modern': true,
  13506. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13507. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13508. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13509. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13510. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13511. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13512. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13513. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13514. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13515. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13516. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13517. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13518. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13519. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13520. };
  13521. var symbolsFonts = {
  13522. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13523. };
  13524. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13525. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13526. // glyphs, but common for some set of the standard fonts.
  13527. var GlyphMapForStandardFonts = {
  13528. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13529. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13530. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13531. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13532. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13533. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13534. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13535. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13536. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13537. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13538. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13539. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13540. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13541. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13542. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13543. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13544. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13545. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13546. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13547. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13548. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13549. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13550. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13551. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13552. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13553. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13554. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13555. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13556. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13557. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13558. '298': 380, '305': 963,
  13559. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13560. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13561. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13562. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13563. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13564. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13565. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13566. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13567. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13568. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13569. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13570. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13571. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13572. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13573. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13574. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13575. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13576. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13577. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13578. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13579. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13580. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13581. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13582. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13583. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13584. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13585. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13586. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13587. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13588. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13589. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13590. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13591. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13592. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13593. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13594. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13595. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13596. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13597. };
  13598. // The glyph map for ArialBlack differs slightly from the glyph map used for
  13599. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  13600. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  13601. var SupplementalGlyphMapForArialBlack = {
  13602. '227': 322, '264': 261, '291': 346,
  13603. };
  13604. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13605. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13606. // to the similar equivalents in the normal characters range.
  13607. var SpecialPUASymbols = {
  13608. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13609. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13610. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13611. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13612. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13613. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13614. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13615. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13616. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13617. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13618. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13619. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13620. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13621. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13622. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13623. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13624. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13625. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13626. '63723': 0x239B, // parenlefttp (0xF8EB)
  13627. '63724': 0x239C, // parenleftex (0xF8EC)
  13628. '63725': 0x239D, // parenleftbt (0xF8ED)
  13629. '63734': 0x239E, // parenrighttp (0xF8F6)
  13630. '63735': 0x239F, // parenrightex (0xF8F7)
  13631. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13632. };
  13633. function mapSpecialUnicodeValues(code) {
  13634. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13635. return 0;
  13636. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13637. return (SpecialPUASymbols[code] || code);
  13638. }
  13639. return code;
  13640. }
  13641. var UnicodeRanges = [
  13642. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13643. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13644. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13645. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13646. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13647. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13648. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13649. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13650. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13651. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13652. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13653. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13654. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13655. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13656. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13657. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13658. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13659. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13660. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13661. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13662. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13663. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13664. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13665. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13666. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13667. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13668. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13669. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13670. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13671. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13672. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13673. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13674. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13675. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13676. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13677. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13678. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13679. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13680. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13681. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13682. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13683. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13684. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13685. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13686. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13687. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13688. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13689. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13690. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13691. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13692. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13693. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13694. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13695. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13696. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13697. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13698. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13699. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13700. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13701. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13702. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13703. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13704. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13705. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13706. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13707. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13708. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13709. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13710. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13711. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13712. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13713. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13714. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13715. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13716. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13717. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13718. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13719. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13720. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13721. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13722. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13723. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13724. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13725. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13726. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13727. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13728. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13729. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13730. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13731. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13732. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13733. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13734. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13735. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13736. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13737. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13738. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13739. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13740. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13741. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13742. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13743. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13744. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13745. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13746. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13747. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13748. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13749. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13750. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13751. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13752. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13753. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13754. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13755. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13756. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13757. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13758. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13759. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13760. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13761. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13762. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13763. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13764. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13765. ];
  13766. var MacStandardGlyphOrdering = [
  13767. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13768. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13769. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13770. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13771. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13772. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13773. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13774. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13775. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13776. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13777. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13778. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13779. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13780. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13781. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13782. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13783. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13784. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13785. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13786. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13787. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13788. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13789. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13790. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13791. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13792. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13793. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13794. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13795. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13796. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13797. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13798. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13799. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13800. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13801. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13802. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13803. function getUnicodeRangeFor(value) {
  13804. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13805. var range = UnicodeRanges[i];
  13806. if (value >= range.begin && value < range.end) {
  13807. return i;
  13808. }
  13809. }
  13810. return -1;
  13811. }
  13812. function isRTLRangeFor(value) {
  13813. var range = UnicodeRanges[13];
  13814. if (value >= range.begin && value < range.end) {
  13815. return true;
  13816. }
  13817. range = UnicodeRanges[11];
  13818. if (value >= range.begin && value < range.end) {
  13819. return true;
  13820. }
  13821. return false;
  13822. }
  13823. // The normalization table is obtained by filtering the Unicode characters
  13824. // database with <compat> entries.
  13825. var NormalizedUnicodes = {
  13826. '\u00A8': '\u0020\u0308',
  13827. '\u00AF': '\u0020\u0304',
  13828. '\u00B4': '\u0020\u0301',
  13829. '\u00B5': '\u03BC',
  13830. '\u00B8': '\u0020\u0327',
  13831. '\u0132': '\u0049\u004A',
  13832. '\u0133': '\u0069\u006A',
  13833. '\u013F': '\u004C\u00B7',
  13834. '\u0140': '\u006C\u00B7',
  13835. '\u0149': '\u02BC\u006E',
  13836. '\u017F': '\u0073',
  13837. '\u01C4': '\u0044\u017D',
  13838. '\u01C5': '\u0044\u017E',
  13839. '\u01C6': '\u0064\u017E',
  13840. '\u01C7': '\u004C\u004A',
  13841. '\u01C8': '\u004C\u006A',
  13842. '\u01C9': '\u006C\u006A',
  13843. '\u01CA': '\u004E\u004A',
  13844. '\u01CB': '\u004E\u006A',
  13845. '\u01CC': '\u006E\u006A',
  13846. '\u01F1': '\u0044\u005A',
  13847. '\u01F2': '\u0044\u007A',
  13848. '\u01F3': '\u0064\u007A',
  13849. '\u02D8': '\u0020\u0306',
  13850. '\u02D9': '\u0020\u0307',
  13851. '\u02DA': '\u0020\u030A',
  13852. '\u02DB': '\u0020\u0328',
  13853. '\u02DC': '\u0020\u0303',
  13854. '\u02DD': '\u0020\u030B',
  13855. '\u037A': '\u0020\u0345',
  13856. '\u0384': '\u0020\u0301',
  13857. '\u03D0': '\u03B2',
  13858. '\u03D1': '\u03B8',
  13859. '\u03D2': '\u03A5',
  13860. '\u03D5': '\u03C6',
  13861. '\u03D6': '\u03C0',
  13862. '\u03F0': '\u03BA',
  13863. '\u03F1': '\u03C1',
  13864. '\u03F2': '\u03C2',
  13865. '\u03F4': '\u0398',
  13866. '\u03F5': '\u03B5',
  13867. '\u03F9': '\u03A3',
  13868. '\u0587': '\u0565\u0582',
  13869. '\u0675': '\u0627\u0674',
  13870. '\u0676': '\u0648\u0674',
  13871. '\u0677': '\u06C7\u0674',
  13872. '\u0678': '\u064A\u0674',
  13873. '\u0E33': '\u0E4D\u0E32',
  13874. '\u0EB3': '\u0ECD\u0EB2',
  13875. '\u0EDC': '\u0EAB\u0E99',
  13876. '\u0EDD': '\u0EAB\u0EA1',
  13877. '\u0F77': '\u0FB2\u0F81',
  13878. '\u0F79': '\u0FB3\u0F81',
  13879. '\u1E9A': '\u0061\u02BE',
  13880. '\u1FBD': '\u0020\u0313',
  13881. '\u1FBF': '\u0020\u0313',
  13882. '\u1FC0': '\u0020\u0342',
  13883. '\u1FFE': '\u0020\u0314',
  13884. '\u2002': '\u0020',
  13885. '\u2003': '\u0020',
  13886. '\u2004': '\u0020',
  13887. '\u2005': '\u0020',
  13888. '\u2006': '\u0020',
  13889. '\u2008': '\u0020',
  13890. '\u2009': '\u0020',
  13891. '\u200A': '\u0020',
  13892. '\u2017': '\u0020\u0333',
  13893. '\u2024': '\u002E',
  13894. '\u2025': '\u002E\u002E',
  13895. '\u2026': '\u002E\u002E\u002E',
  13896. '\u2033': '\u2032\u2032',
  13897. '\u2034': '\u2032\u2032\u2032',
  13898. '\u2036': '\u2035\u2035',
  13899. '\u2037': '\u2035\u2035\u2035',
  13900. '\u203C': '\u0021\u0021',
  13901. '\u203E': '\u0020\u0305',
  13902. '\u2047': '\u003F\u003F',
  13903. '\u2048': '\u003F\u0021',
  13904. '\u2049': '\u0021\u003F',
  13905. '\u2057': '\u2032\u2032\u2032\u2032',
  13906. '\u205F': '\u0020',
  13907. '\u20A8': '\u0052\u0073',
  13908. '\u2100': '\u0061\u002F\u0063',
  13909. '\u2101': '\u0061\u002F\u0073',
  13910. '\u2103': '\u00B0\u0043',
  13911. '\u2105': '\u0063\u002F\u006F',
  13912. '\u2106': '\u0063\u002F\u0075',
  13913. '\u2107': '\u0190',
  13914. '\u2109': '\u00B0\u0046',
  13915. '\u2116': '\u004E\u006F',
  13916. '\u2121': '\u0054\u0045\u004C',
  13917. '\u2135': '\u05D0',
  13918. '\u2136': '\u05D1',
  13919. '\u2137': '\u05D2',
  13920. '\u2138': '\u05D3',
  13921. '\u213B': '\u0046\u0041\u0058',
  13922. '\u2160': '\u0049',
  13923. '\u2161': '\u0049\u0049',
  13924. '\u2162': '\u0049\u0049\u0049',
  13925. '\u2163': '\u0049\u0056',
  13926. '\u2164': '\u0056',
  13927. '\u2165': '\u0056\u0049',
  13928. '\u2166': '\u0056\u0049\u0049',
  13929. '\u2167': '\u0056\u0049\u0049\u0049',
  13930. '\u2168': '\u0049\u0058',
  13931. '\u2169': '\u0058',
  13932. '\u216A': '\u0058\u0049',
  13933. '\u216B': '\u0058\u0049\u0049',
  13934. '\u216C': '\u004C',
  13935. '\u216D': '\u0043',
  13936. '\u216E': '\u0044',
  13937. '\u216F': '\u004D',
  13938. '\u2170': '\u0069',
  13939. '\u2171': '\u0069\u0069',
  13940. '\u2172': '\u0069\u0069\u0069',
  13941. '\u2173': '\u0069\u0076',
  13942. '\u2174': '\u0076',
  13943. '\u2175': '\u0076\u0069',
  13944. '\u2176': '\u0076\u0069\u0069',
  13945. '\u2177': '\u0076\u0069\u0069\u0069',
  13946. '\u2178': '\u0069\u0078',
  13947. '\u2179': '\u0078',
  13948. '\u217A': '\u0078\u0069',
  13949. '\u217B': '\u0078\u0069\u0069',
  13950. '\u217C': '\u006C',
  13951. '\u217D': '\u0063',
  13952. '\u217E': '\u0064',
  13953. '\u217F': '\u006D',
  13954. '\u222C': '\u222B\u222B',
  13955. '\u222D': '\u222B\u222B\u222B',
  13956. '\u222F': '\u222E\u222E',
  13957. '\u2230': '\u222E\u222E\u222E',
  13958. '\u2474': '\u0028\u0031\u0029',
  13959. '\u2475': '\u0028\u0032\u0029',
  13960. '\u2476': '\u0028\u0033\u0029',
  13961. '\u2477': '\u0028\u0034\u0029',
  13962. '\u2478': '\u0028\u0035\u0029',
  13963. '\u2479': '\u0028\u0036\u0029',
  13964. '\u247A': '\u0028\u0037\u0029',
  13965. '\u247B': '\u0028\u0038\u0029',
  13966. '\u247C': '\u0028\u0039\u0029',
  13967. '\u247D': '\u0028\u0031\u0030\u0029',
  13968. '\u247E': '\u0028\u0031\u0031\u0029',
  13969. '\u247F': '\u0028\u0031\u0032\u0029',
  13970. '\u2480': '\u0028\u0031\u0033\u0029',
  13971. '\u2481': '\u0028\u0031\u0034\u0029',
  13972. '\u2482': '\u0028\u0031\u0035\u0029',
  13973. '\u2483': '\u0028\u0031\u0036\u0029',
  13974. '\u2484': '\u0028\u0031\u0037\u0029',
  13975. '\u2485': '\u0028\u0031\u0038\u0029',
  13976. '\u2486': '\u0028\u0031\u0039\u0029',
  13977. '\u2487': '\u0028\u0032\u0030\u0029',
  13978. '\u2488': '\u0031\u002E',
  13979. '\u2489': '\u0032\u002E',
  13980. '\u248A': '\u0033\u002E',
  13981. '\u248B': '\u0034\u002E',
  13982. '\u248C': '\u0035\u002E',
  13983. '\u248D': '\u0036\u002E',
  13984. '\u248E': '\u0037\u002E',
  13985. '\u248F': '\u0038\u002E',
  13986. '\u2490': '\u0039\u002E',
  13987. '\u2491': '\u0031\u0030\u002E',
  13988. '\u2492': '\u0031\u0031\u002E',
  13989. '\u2493': '\u0031\u0032\u002E',
  13990. '\u2494': '\u0031\u0033\u002E',
  13991. '\u2495': '\u0031\u0034\u002E',
  13992. '\u2496': '\u0031\u0035\u002E',
  13993. '\u2497': '\u0031\u0036\u002E',
  13994. '\u2498': '\u0031\u0037\u002E',
  13995. '\u2499': '\u0031\u0038\u002E',
  13996. '\u249A': '\u0031\u0039\u002E',
  13997. '\u249B': '\u0032\u0030\u002E',
  13998. '\u249C': '\u0028\u0061\u0029',
  13999. '\u249D': '\u0028\u0062\u0029',
  14000. '\u249E': '\u0028\u0063\u0029',
  14001. '\u249F': '\u0028\u0064\u0029',
  14002. '\u24A0': '\u0028\u0065\u0029',
  14003. '\u24A1': '\u0028\u0066\u0029',
  14004. '\u24A2': '\u0028\u0067\u0029',
  14005. '\u24A3': '\u0028\u0068\u0029',
  14006. '\u24A4': '\u0028\u0069\u0029',
  14007. '\u24A5': '\u0028\u006A\u0029',
  14008. '\u24A6': '\u0028\u006B\u0029',
  14009. '\u24A7': '\u0028\u006C\u0029',
  14010. '\u24A8': '\u0028\u006D\u0029',
  14011. '\u24A9': '\u0028\u006E\u0029',
  14012. '\u24AA': '\u0028\u006F\u0029',
  14013. '\u24AB': '\u0028\u0070\u0029',
  14014. '\u24AC': '\u0028\u0071\u0029',
  14015. '\u24AD': '\u0028\u0072\u0029',
  14016. '\u24AE': '\u0028\u0073\u0029',
  14017. '\u24AF': '\u0028\u0074\u0029',
  14018. '\u24B0': '\u0028\u0075\u0029',
  14019. '\u24B1': '\u0028\u0076\u0029',
  14020. '\u24B2': '\u0028\u0077\u0029',
  14021. '\u24B3': '\u0028\u0078\u0029',
  14022. '\u24B4': '\u0028\u0079\u0029',
  14023. '\u24B5': '\u0028\u007A\u0029',
  14024. '\u2A0C': '\u222B\u222B\u222B\u222B',
  14025. '\u2A74': '\u003A\u003A\u003D',
  14026. '\u2A75': '\u003D\u003D',
  14027. '\u2A76': '\u003D\u003D\u003D',
  14028. '\u2E9F': '\u6BCD',
  14029. '\u2EF3': '\u9F9F',
  14030. '\u2F00': '\u4E00',
  14031. '\u2F01': '\u4E28',
  14032. '\u2F02': '\u4E36',
  14033. '\u2F03': '\u4E3F',
  14034. '\u2F04': '\u4E59',
  14035. '\u2F05': '\u4E85',
  14036. '\u2F06': '\u4E8C',
  14037. '\u2F07': '\u4EA0',
  14038. '\u2F08': '\u4EBA',
  14039. '\u2F09': '\u513F',
  14040. '\u2F0A': '\u5165',
  14041. '\u2F0B': '\u516B',
  14042. '\u2F0C': '\u5182',
  14043. '\u2F0D': '\u5196',
  14044. '\u2F0E': '\u51AB',
  14045. '\u2F0F': '\u51E0',
  14046. '\u2F10': '\u51F5',
  14047. '\u2F11': '\u5200',
  14048. '\u2F12': '\u529B',
  14049. '\u2F13': '\u52F9',
  14050. '\u2F14': '\u5315',
  14051. '\u2F15': '\u531A',
  14052. '\u2F16': '\u5338',
  14053. '\u2F17': '\u5341',
  14054. '\u2F18': '\u535C',
  14055. '\u2F19': '\u5369',
  14056. '\u2F1A': '\u5382',
  14057. '\u2F1B': '\u53B6',
  14058. '\u2F1C': '\u53C8',
  14059. '\u2F1D': '\u53E3',
  14060. '\u2F1E': '\u56D7',
  14061. '\u2F1F': '\u571F',
  14062. '\u2F20': '\u58EB',
  14063. '\u2F21': '\u5902',
  14064. '\u2F22': '\u590A',
  14065. '\u2F23': '\u5915',
  14066. '\u2F24': '\u5927',
  14067. '\u2F25': '\u5973',
  14068. '\u2F26': '\u5B50',
  14069. '\u2F27': '\u5B80',
  14070. '\u2F28': '\u5BF8',
  14071. '\u2F29': '\u5C0F',
  14072. '\u2F2A': '\u5C22',
  14073. '\u2F2B': '\u5C38',
  14074. '\u2F2C': '\u5C6E',
  14075. '\u2F2D': '\u5C71',
  14076. '\u2F2E': '\u5DDB',
  14077. '\u2F2F': '\u5DE5',
  14078. '\u2F30': '\u5DF1',
  14079. '\u2F31': '\u5DFE',
  14080. '\u2F32': '\u5E72',
  14081. '\u2F33': '\u5E7A',
  14082. '\u2F34': '\u5E7F',
  14083. '\u2F35': '\u5EF4',
  14084. '\u2F36': '\u5EFE',
  14085. '\u2F37': '\u5F0B',
  14086. '\u2F38': '\u5F13',
  14087. '\u2F39': '\u5F50',
  14088. '\u2F3A': '\u5F61',
  14089. '\u2F3B': '\u5F73',
  14090. '\u2F3C': '\u5FC3',
  14091. '\u2F3D': '\u6208',
  14092. '\u2F3E': '\u6236',
  14093. '\u2F3F': '\u624B',
  14094. '\u2F40': '\u652F',
  14095. '\u2F41': '\u6534',
  14096. '\u2F42': '\u6587',
  14097. '\u2F43': '\u6597',
  14098. '\u2F44': '\u65A4',
  14099. '\u2F45': '\u65B9',
  14100. '\u2F46': '\u65E0',
  14101. '\u2F47': '\u65E5',
  14102. '\u2F48': '\u66F0',
  14103. '\u2F49': '\u6708',
  14104. '\u2F4A': '\u6728',
  14105. '\u2F4B': '\u6B20',
  14106. '\u2F4C': '\u6B62',
  14107. '\u2F4D': '\u6B79',
  14108. '\u2F4E': '\u6BB3',
  14109. '\u2F4F': '\u6BCB',
  14110. '\u2F50': '\u6BD4',
  14111. '\u2F51': '\u6BDB',
  14112. '\u2F52': '\u6C0F',
  14113. '\u2F53': '\u6C14',
  14114. '\u2F54': '\u6C34',
  14115. '\u2F55': '\u706B',
  14116. '\u2F56': '\u722A',
  14117. '\u2F57': '\u7236',
  14118. '\u2F58': '\u723B',
  14119. '\u2F59': '\u723F',
  14120. '\u2F5A': '\u7247',
  14121. '\u2F5B': '\u7259',
  14122. '\u2F5C': '\u725B',
  14123. '\u2F5D': '\u72AC',
  14124. '\u2F5E': '\u7384',
  14125. '\u2F5F': '\u7389',
  14126. '\u2F60': '\u74DC',
  14127. '\u2F61': '\u74E6',
  14128. '\u2F62': '\u7518',
  14129. '\u2F63': '\u751F',
  14130. '\u2F64': '\u7528',
  14131. '\u2F65': '\u7530',
  14132. '\u2F66': '\u758B',
  14133. '\u2F67': '\u7592',
  14134. '\u2F68': '\u7676',
  14135. '\u2F69': '\u767D',
  14136. '\u2F6A': '\u76AE',
  14137. '\u2F6B': '\u76BF',
  14138. '\u2F6C': '\u76EE',
  14139. '\u2F6D': '\u77DB',
  14140. '\u2F6E': '\u77E2',
  14141. '\u2F6F': '\u77F3',
  14142. '\u2F70': '\u793A',
  14143. '\u2F71': '\u79B8',
  14144. '\u2F72': '\u79BE',
  14145. '\u2F73': '\u7A74',
  14146. '\u2F74': '\u7ACB',
  14147. '\u2F75': '\u7AF9',
  14148. '\u2F76': '\u7C73',
  14149. '\u2F77': '\u7CF8',
  14150. '\u2F78': '\u7F36',
  14151. '\u2F79': '\u7F51',
  14152. '\u2F7A': '\u7F8A',
  14153. '\u2F7B': '\u7FBD',
  14154. '\u2F7C': '\u8001',
  14155. '\u2F7D': '\u800C',
  14156. '\u2F7E': '\u8012',
  14157. '\u2F7F': '\u8033',
  14158. '\u2F80': '\u807F',
  14159. '\u2F81': '\u8089',
  14160. '\u2F82': '\u81E3',
  14161. '\u2F83': '\u81EA',
  14162. '\u2F84': '\u81F3',
  14163. '\u2F85': '\u81FC',
  14164. '\u2F86': '\u820C',
  14165. '\u2F87': '\u821B',
  14166. '\u2F88': '\u821F',
  14167. '\u2F89': '\u826E',
  14168. '\u2F8A': '\u8272',
  14169. '\u2F8B': '\u8278',
  14170. '\u2F8C': '\u864D',
  14171. '\u2F8D': '\u866B',
  14172. '\u2F8E': '\u8840',
  14173. '\u2F8F': '\u884C',
  14174. '\u2F90': '\u8863',
  14175. '\u2F91': '\u897E',
  14176. '\u2F92': '\u898B',
  14177. '\u2F93': '\u89D2',
  14178. '\u2F94': '\u8A00',
  14179. '\u2F95': '\u8C37',
  14180. '\u2F96': '\u8C46',
  14181. '\u2F97': '\u8C55',
  14182. '\u2F98': '\u8C78',
  14183. '\u2F99': '\u8C9D',
  14184. '\u2F9A': '\u8D64',
  14185. '\u2F9B': '\u8D70',
  14186. '\u2F9C': '\u8DB3',
  14187. '\u2F9D': '\u8EAB',
  14188. '\u2F9E': '\u8ECA',
  14189. '\u2F9F': '\u8F9B',
  14190. '\u2FA0': '\u8FB0',
  14191. '\u2FA1': '\u8FB5',
  14192. '\u2FA2': '\u9091',
  14193. '\u2FA3': '\u9149',
  14194. '\u2FA4': '\u91C6',
  14195. '\u2FA5': '\u91CC',
  14196. '\u2FA6': '\u91D1',
  14197. '\u2FA7': '\u9577',
  14198. '\u2FA8': '\u9580',
  14199. '\u2FA9': '\u961C',
  14200. '\u2FAA': '\u96B6',
  14201. '\u2FAB': '\u96B9',
  14202. '\u2FAC': '\u96E8',
  14203. '\u2FAD': '\u9751',
  14204. '\u2FAE': '\u975E',
  14205. '\u2FAF': '\u9762',
  14206. '\u2FB0': '\u9769',
  14207. '\u2FB1': '\u97CB',
  14208. '\u2FB2': '\u97ED',
  14209. '\u2FB3': '\u97F3',
  14210. '\u2FB4': '\u9801',
  14211. '\u2FB5': '\u98A8',
  14212. '\u2FB6': '\u98DB',
  14213. '\u2FB7': '\u98DF',
  14214. '\u2FB8': '\u9996',
  14215. '\u2FB9': '\u9999',
  14216. '\u2FBA': '\u99AC',
  14217. '\u2FBB': '\u9AA8',
  14218. '\u2FBC': '\u9AD8',
  14219. '\u2FBD': '\u9ADF',
  14220. '\u2FBE': '\u9B25',
  14221. '\u2FBF': '\u9B2F',
  14222. '\u2FC0': '\u9B32',
  14223. '\u2FC1': '\u9B3C',
  14224. '\u2FC2': '\u9B5A',
  14225. '\u2FC3': '\u9CE5',
  14226. '\u2FC4': '\u9E75',
  14227. '\u2FC5': '\u9E7F',
  14228. '\u2FC6': '\u9EA5',
  14229. '\u2FC7': '\u9EBB',
  14230. '\u2FC8': '\u9EC3',
  14231. '\u2FC9': '\u9ECD',
  14232. '\u2FCA': '\u9ED1',
  14233. '\u2FCB': '\u9EF9',
  14234. '\u2FCC': '\u9EFD',
  14235. '\u2FCD': '\u9F0E',
  14236. '\u2FCE': '\u9F13',
  14237. '\u2FCF': '\u9F20',
  14238. '\u2FD0': '\u9F3B',
  14239. '\u2FD1': '\u9F4A',
  14240. '\u2FD2': '\u9F52',
  14241. '\u2FD3': '\u9F8D',
  14242. '\u2FD4': '\u9F9C',
  14243. '\u2FD5': '\u9FA0',
  14244. '\u3036': '\u3012',
  14245. '\u3038': '\u5341',
  14246. '\u3039': '\u5344',
  14247. '\u303A': '\u5345',
  14248. '\u309B': '\u0020\u3099',
  14249. '\u309C': '\u0020\u309A',
  14250. '\u3131': '\u1100',
  14251. '\u3132': '\u1101',
  14252. '\u3133': '\u11AA',
  14253. '\u3134': '\u1102',
  14254. '\u3135': '\u11AC',
  14255. '\u3136': '\u11AD',
  14256. '\u3137': '\u1103',
  14257. '\u3138': '\u1104',
  14258. '\u3139': '\u1105',
  14259. '\u313A': '\u11B0',
  14260. '\u313B': '\u11B1',
  14261. '\u313C': '\u11B2',
  14262. '\u313D': '\u11B3',
  14263. '\u313E': '\u11B4',
  14264. '\u313F': '\u11B5',
  14265. '\u3140': '\u111A',
  14266. '\u3141': '\u1106',
  14267. '\u3142': '\u1107',
  14268. '\u3143': '\u1108',
  14269. '\u3144': '\u1121',
  14270. '\u3145': '\u1109',
  14271. '\u3146': '\u110A',
  14272. '\u3147': '\u110B',
  14273. '\u3148': '\u110C',
  14274. '\u3149': '\u110D',
  14275. '\u314A': '\u110E',
  14276. '\u314B': '\u110F',
  14277. '\u314C': '\u1110',
  14278. '\u314D': '\u1111',
  14279. '\u314E': '\u1112',
  14280. '\u314F': '\u1161',
  14281. '\u3150': '\u1162',
  14282. '\u3151': '\u1163',
  14283. '\u3152': '\u1164',
  14284. '\u3153': '\u1165',
  14285. '\u3154': '\u1166',
  14286. '\u3155': '\u1167',
  14287. '\u3156': '\u1168',
  14288. '\u3157': '\u1169',
  14289. '\u3158': '\u116A',
  14290. '\u3159': '\u116B',
  14291. '\u315A': '\u116C',
  14292. '\u315B': '\u116D',
  14293. '\u315C': '\u116E',
  14294. '\u315D': '\u116F',
  14295. '\u315E': '\u1170',
  14296. '\u315F': '\u1171',
  14297. '\u3160': '\u1172',
  14298. '\u3161': '\u1173',
  14299. '\u3162': '\u1174',
  14300. '\u3163': '\u1175',
  14301. '\u3164': '\u1160',
  14302. '\u3165': '\u1114',
  14303. '\u3166': '\u1115',
  14304. '\u3167': '\u11C7',
  14305. '\u3168': '\u11C8',
  14306. '\u3169': '\u11CC',
  14307. '\u316A': '\u11CE',
  14308. '\u316B': '\u11D3',
  14309. '\u316C': '\u11D7',
  14310. '\u316D': '\u11D9',
  14311. '\u316E': '\u111C',
  14312. '\u316F': '\u11DD',
  14313. '\u3170': '\u11DF',
  14314. '\u3171': '\u111D',
  14315. '\u3172': '\u111E',
  14316. '\u3173': '\u1120',
  14317. '\u3174': '\u1122',
  14318. '\u3175': '\u1123',
  14319. '\u3176': '\u1127',
  14320. '\u3177': '\u1129',
  14321. '\u3178': '\u112B',
  14322. '\u3179': '\u112C',
  14323. '\u317A': '\u112D',
  14324. '\u317B': '\u112E',
  14325. '\u317C': '\u112F',
  14326. '\u317D': '\u1132',
  14327. '\u317E': '\u1136',
  14328. '\u317F': '\u1140',
  14329. '\u3180': '\u1147',
  14330. '\u3181': '\u114C',
  14331. '\u3182': '\u11F1',
  14332. '\u3183': '\u11F2',
  14333. '\u3184': '\u1157',
  14334. '\u3185': '\u1158',
  14335. '\u3186': '\u1159',
  14336. '\u3187': '\u1184',
  14337. '\u3188': '\u1185',
  14338. '\u3189': '\u1188',
  14339. '\u318A': '\u1191',
  14340. '\u318B': '\u1192',
  14341. '\u318C': '\u1194',
  14342. '\u318D': '\u119E',
  14343. '\u318E': '\u11A1',
  14344. '\u3200': '\u0028\u1100\u0029',
  14345. '\u3201': '\u0028\u1102\u0029',
  14346. '\u3202': '\u0028\u1103\u0029',
  14347. '\u3203': '\u0028\u1105\u0029',
  14348. '\u3204': '\u0028\u1106\u0029',
  14349. '\u3205': '\u0028\u1107\u0029',
  14350. '\u3206': '\u0028\u1109\u0029',
  14351. '\u3207': '\u0028\u110B\u0029',
  14352. '\u3208': '\u0028\u110C\u0029',
  14353. '\u3209': '\u0028\u110E\u0029',
  14354. '\u320A': '\u0028\u110F\u0029',
  14355. '\u320B': '\u0028\u1110\u0029',
  14356. '\u320C': '\u0028\u1111\u0029',
  14357. '\u320D': '\u0028\u1112\u0029',
  14358. '\u320E': '\u0028\u1100\u1161\u0029',
  14359. '\u320F': '\u0028\u1102\u1161\u0029',
  14360. '\u3210': '\u0028\u1103\u1161\u0029',
  14361. '\u3211': '\u0028\u1105\u1161\u0029',
  14362. '\u3212': '\u0028\u1106\u1161\u0029',
  14363. '\u3213': '\u0028\u1107\u1161\u0029',
  14364. '\u3214': '\u0028\u1109\u1161\u0029',
  14365. '\u3215': '\u0028\u110B\u1161\u0029',
  14366. '\u3216': '\u0028\u110C\u1161\u0029',
  14367. '\u3217': '\u0028\u110E\u1161\u0029',
  14368. '\u3218': '\u0028\u110F\u1161\u0029',
  14369. '\u3219': '\u0028\u1110\u1161\u0029',
  14370. '\u321A': '\u0028\u1111\u1161\u0029',
  14371. '\u321B': '\u0028\u1112\u1161\u0029',
  14372. '\u321C': '\u0028\u110C\u116E\u0029',
  14373. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14374. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14375. '\u3220': '\u0028\u4E00\u0029',
  14376. '\u3221': '\u0028\u4E8C\u0029',
  14377. '\u3222': '\u0028\u4E09\u0029',
  14378. '\u3223': '\u0028\u56DB\u0029',
  14379. '\u3224': '\u0028\u4E94\u0029',
  14380. '\u3225': '\u0028\u516D\u0029',
  14381. '\u3226': '\u0028\u4E03\u0029',
  14382. '\u3227': '\u0028\u516B\u0029',
  14383. '\u3228': '\u0028\u4E5D\u0029',
  14384. '\u3229': '\u0028\u5341\u0029',
  14385. '\u322A': '\u0028\u6708\u0029',
  14386. '\u322B': '\u0028\u706B\u0029',
  14387. '\u322C': '\u0028\u6C34\u0029',
  14388. '\u322D': '\u0028\u6728\u0029',
  14389. '\u322E': '\u0028\u91D1\u0029',
  14390. '\u322F': '\u0028\u571F\u0029',
  14391. '\u3230': '\u0028\u65E5\u0029',
  14392. '\u3231': '\u0028\u682A\u0029',
  14393. '\u3232': '\u0028\u6709\u0029',
  14394. '\u3233': '\u0028\u793E\u0029',
  14395. '\u3234': '\u0028\u540D\u0029',
  14396. '\u3235': '\u0028\u7279\u0029',
  14397. '\u3236': '\u0028\u8CA1\u0029',
  14398. '\u3237': '\u0028\u795D\u0029',
  14399. '\u3238': '\u0028\u52B4\u0029',
  14400. '\u3239': '\u0028\u4EE3\u0029',
  14401. '\u323A': '\u0028\u547C\u0029',
  14402. '\u323B': '\u0028\u5B66\u0029',
  14403. '\u323C': '\u0028\u76E3\u0029',
  14404. '\u323D': '\u0028\u4F01\u0029',
  14405. '\u323E': '\u0028\u8CC7\u0029',
  14406. '\u323F': '\u0028\u5354\u0029',
  14407. '\u3240': '\u0028\u796D\u0029',
  14408. '\u3241': '\u0028\u4F11\u0029',
  14409. '\u3242': '\u0028\u81EA\u0029',
  14410. '\u3243': '\u0028\u81F3\u0029',
  14411. '\u32C0': '\u0031\u6708',
  14412. '\u32C1': '\u0032\u6708',
  14413. '\u32C2': '\u0033\u6708',
  14414. '\u32C3': '\u0034\u6708',
  14415. '\u32C4': '\u0035\u6708',
  14416. '\u32C5': '\u0036\u6708',
  14417. '\u32C6': '\u0037\u6708',
  14418. '\u32C7': '\u0038\u6708',
  14419. '\u32C8': '\u0039\u6708',
  14420. '\u32C9': '\u0031\u0030\u6708',
  14421. '\u32CA': '\u0031\u0031\u6708',
  14422. '\u32CB': '\u0031\u0032\u6708',
  14423. '\u3358': '\u0030\u70B9',
  14424. '\u3359': '\u0031\u70B9',
  14425. '\u335A': '\u0032\u70B9',
  14426. '\u335B': '\u0033\u70B9',
  14427. '\u335C': '\u0034\u70B9',
  14428. '\u335D': '\u0035\u70B9',
  14429. '\u335E': '\u0036\u70B9',
  14430. '\u335F': '\u0037\u70B9',
  14431. '\u3360': '\u0038\u70B9',
  14432. '\u3361': '\u0039\u70B9',
  14433. '\u3362': '\u0031\u0030\u70B9',
  14434. '\u3363': '\u0031\u0031\u70B9',
  14435. '\u3364': '\u0031\u0032\u70B9',
  14436. '\u3365': '\u0031\u0033\u70B9',
  14437. '\u3366': '\u0031\u0034\u70B9',
  14438. '\u3367': '\u0031\u0035\u70B9',
  14439. '\u3368': '\u0031\u0036\u70B9',
  14440. '\u3369': '\u0031\u0037\u70B9',
  14441. '\u336A': '\u0031\u0038\u70B9',
  14442. '\u336B': '\u0031\u0039\u70B9',
  14443. '\u336C': '\u0032\u0030\u70B9',
  14444. '\u336D': '\u0032\u0031\u70B9',
  14445. '\u336E': '\u0032\u0032\u70B9',
  14446. '\u336F': '\u0032\u0033\u70B9',
  14447. '\u3370': '\u0032\u0034\u70B9',
  14448. '\u33E0': '\u0031\u65E5',
  14449. '\u33E1': '\u0032\u65E5',
  14450. '\u33E2': '\u0033\u65E5',
  14451. '\u33E3': '\u0034\u65E5',
  14452. '\u33E4': '\u0035\u65E5',
  14453. '\u33E5': '\u0036\u65E5',
  14454. '\u33E6': '\u0037\u65E5',
  14455. '\u33E7': '\u0038\u65E5',
  14456. '\u33E8': '\u0039\u65E5',
  14457. '\u33E9': '\u0031\u0030\u65E5',
  14458. '\u33EA': '\u0031\u0031\u65E5',
  14459. '\u33EB': '\u0031\u0032\u65E5',
  14460. '\u33EC': '\u0031\u0033\u65E5',
  14461. '\u33ED': '\u0031\u0034\u65E5',
  14462. '\u33EE': '\u0031\u0035\u65E5',
  14463. '\u33EF': '\u0031\u0036\u65E5',
  14464. '\u33F0': '\u0031\u0037\u65E5',
  14465. '\u33F1': '\u0031\u0038\u65E5',
  14466. '\u33F2': '\u0031\u0039\u65E5',
  14467. '\u33F3': '\u0032\u0030\u65E5',
  14468. '\u33F4': '\u0032\u0031\u65E5',
  14469. '\u33F5': '\u0032\u0032\u65E5',
  14470. '\u33F6': '\u0032\u0033\u65E5',
  14471. '\u33F7': '\u0032\u0034\u65E5',
  14472. '\u33F8': '\u0032\u0035\u65E5',
  14473. '\u33F9': '\u0032\u0036\u65E5',
  14474. '\u33FA': '\u0032\u0037\u65E5',
  14475. '\u33FB': '\u0032\u0038\u65E5',
  14476. '\u33FC': '\u0032\u0039\u65E5',
  14477. '\u33FD': '\u0033\u0030\u65E5',
  14478. '\u33FE': '\u0033\u0031\u65E5',
  14479. '\uFB00': '\u0066\u0066',
  14480. '\uFB01': '\u0066\u0069',
  14481. '\uFB02': '\u0066\u006C',
  14482. '\uFB03': '\u0066\u0066\u0069',
  14483. '\uFB04': '\u0066\u0066\u006C',
  14484. '\uFB05': '\u017F\u0074',
  14485. '\uFB06': '\u0073\u0074',
  14486. '\uFB13': '\u0574\u0576',
  14487. '\uFB14': '\u0574\u0565',
  14488. '\uFB15': '\u0574\u056B',
  14489. '\uFB16': '\u057E\u0576',
  14490. '\uFB17': '\u0574\u056D',
  14491. '\uFB4F': '\u05D0\u05DC',
  14492. '\uFB50': '\u0671',
  14493. '\uFB51': '\u0671',
  14494. '\uFB52': '\u067B',
  14495. '\uFB53': '\u067B',
  14496. '\uFB54': '\u067B',
  14497. '\uFB55': '\u067B',
  14498. '\uFB56': '\u067E',
  14499. '\uFB57': '\u067E',
  14500. '\uFB58': '\u067E',
  14501. '\uFB59': '\u067E',
  14502. '\uFB5A': '\u0680',
  14503. '\uFB5B': '\u0680',
  14504. '\uFB5C': '\u0680',
  14505. '\uFB5D': '\u0680',
  14506. '\uFB5E': '\u067A',
  14507. '\uFB5F': '\u067A',
  14508. '\uFB60': '\u067A',
  14509. '\uFB61': '\u067A',
  14510. '\uFB62': '\u067F',
  14511. '\uFB63': '\u067F',
  14512. '\uFB64': '\u067F',
  14513. '\uFB65': '\u067F',
  14514. '\uFB66': '\u0679',
  14515. '\uFB67': '\u0679',
  14516. '\uFB68': '\u0679',
  14517. '\uFB69': '\u0679',
  14518. '\uFB6A': '\u06A4',
  14519. '\uFB6B': '\u06A4',
  14520. '\uFB6C': '\u06A4',
  14521. '\uFB6D': '\u06A4',
  14522. '\uFB6E': '\u06A6',
  14523. '\uFB6F': '\u06A6',
  14524. '\uFB70': '\u06A6',
  14525. '\uFB71': '\u06A6',
  14526. '\uFB72': '\u0684',
  14527. '\uFB73': '\u0684',
  14528. '\uFB74': '\u0684',
  14529. '\uFB75': '\u0684',
  14530. '\uFB76': '\u0683',
  14531. '\uFB77': '\u0683',
  14532. '\uFB78': '\u0683',
  14533. '\uFB79': '\u0683',
  14534. '\uFB7A': '\u0686',
  14535. '\uFB7B': '\u0686',
  14536. '\uFB7C': '\u0686',
  14537. '\uFB7D': '\u0686',
  14538. '\uFB7E': '\u0687',
  14539. '\uFB7F': '\u0687',
  14540. '\uFB80': '\u0687',
  14541. '\uFB81': '\u0687',
  14542. '\uFB82': '\u068D',
  14543. '\uFB83': '\u068D',
  14544. '\uFB84': '\u068C',
  14545. '\uFB85': '\u068C',
  14546. '\uFB86': '\u068E',
  14547. '\uFB87': '\u068E',
  14548. '\uFB88': '\u0688',
  14549. '\uFB89': '\u0688',
  14550. '\uFB8A': '\u0698',
  14551. '\uFB8B': '\u0698',
  14552. '\uFB8C': '\u0691',
  14553. '\uFB8D': '\u0691',
  14554. '\uFB8E': '\u06A9',
  14555. '\uFB8F': '\u06A9',
  14556. '\uFB90': '\u06A9',
  14557. '\uFB91': '\u06A9',
  14558. '\uFB92': '\u06AF',
  14559. '\uFB93': '\u06AF',
  14560. '\uFB94': '\u06AF',
  14561. '\uFB95': '\u06AF',
  14562. '\uFB96': '\u06B3',
  14563. '\uFB97': '\u06B3',
  14564. '\uFB98': '\u06B3',
  14565. '\uFB99': '\u06B3',
  14566. '\uFB9A': '\u06B1',
  14567. '\uFB9B': '\u06B1',
  14568. '\uFB9C': '\u06B1',
  14569. '\uFB9D': '\u06B1',
  14570. '\uFB9E': '\u06BA',
  14571. '\uFB9F': '\u06BA',
  14572. '\uFBA0': '\u06BB',
  14573. '\uFBA1': '\u06BB',
  14574. '\uFBA2': '\u06BB',
  14575. '\uFBA3': '\u06BB',
  14576. '\uFBA4': '\u06C0',
  14577. '\uFBA5': '\u06C0',
  14578. '\uFBA6': '\u06C1',
  14579. '\uFBA7': '\u06C1',
  14580. '\uFBA8': '\u06C1',
  14581. '\uFBA9': '\u06C1',
  14582. '\uFBAA': '\u06BE',
  14583. '\uFBAB': '\u06BE',
  14584. '\uFBAC': '\u06BE',
  14585. '\uFBAD': '\u06BE',
  14586. '\uFBAE': '\u06D2',
  14587. '\uFBAF': '\u06D2',
  14588. '\uFBB0': '\u06D3',
  14589. '\uFBB1': '\u06D3',
  14590. '\uFBD3': '\u06AD',
  14591. '\uFBD4': '\u06AD',
  14592. '\uFBD5': '\u06AD',
  14593. '\uFBD6': '\u06AD',
  14594. '\uFBD7': '\u06C7',
  14595. '\uFBD8': '\u06C7',
  14596. '\uFBD9': '\u06C6',
  14597. '\uFBDA': '\u06C6',
  14598. '\uFBDB': '\u06C8',
  14599. '\uFBDC': '\u06C8',
  14600. '\uFBDD': '\u0677',
  14601. '\uFBDE': '\u06CB',
  14602. '\uFBDF': '\u06CB',
  14603. '\uFBE0': '\u06C5',
  14604. '\uFBE1': '\u06C5',
  14605. '\uFBE2': '\u06C9',
  14606. '\uFBE3': '\u06C9',
  14607. '\uFBE4': '\u06D0',
  14608. '\uFBE5': '\u06D0',
  14609. '\uFBE6': '\u06D0',
  14610. '\uFBE7': '\u06D0',
  14611. '\uFBE8': '\u0649',
  14612. '\uFBE9': '\u0649',
  14613. '\uFBEA': '\u0626\u0627',
  14614. '\uFBEB': '\u0626\u0627',
  14615. '\uFBEC': '\u0626\u06D5',
  14616. '\uFBED': '\u0626\u06D5',
  14617. '\uFBEE': '\u0626\u0648',
  14618. '\uFBEF': '\u0626\u0648',
  14619. '\uFBF0': '\u0626\u06C7',
  14620. '\uFBF1': '\u0626\u06C7',
  14621. '\uFBF2': '\u0626\u06C6',
  14622. '\uFBF3': '\u0626\u06C6',
  14623. '\uFBF4': '\u0626\u06C8',
  14624. '\uFBF5': '\u0626\u06C8',
  14625. '\uFBF6': '\u0626\u06D0',
  14626. '\uFBF7': '\u0626\u06D0',
  14627. '\uFBF8': '\u0626\u06D0',
  14628. '\uFBF9': '\u0626\u0649',
  14629. '\uFBFA': '\u0626\u0649',
  14630. '\uFBFB': '\u0626\u0649',
  14631. '\uFBFC': '\u06CC',
  14632. '\uFBFD': '\u06CC',
  14633. '\uFBFE': '\u06CC',
  14634. '\uFBFF': '\u06CC',
  14635. '\uFC00': '\u0626\u062C',
  14636. '\uFC01': '\u0626\u062D',
  14637. '\uFC02': '\u0626\u0645',
  14638. '\uFC03': '\u0626\u0649',
  14639. '\uFC04': '\u0626\u064A',
  14640. '\uFC05': '\u0628\u062C',
  14641. '\uFC06': '\u0628\u062D',
  14642. '\uFC07': '\u0628\u062E',
  14643. '\uFC08': '\u0628\u0645',
  14644. '\uFC09': '\u0628\u0649',
  14645. '\uFC0A': '\u0628\u064A',
  14646. '\uFC0B': '\u062A\u062C',
  14647. '\uFC0C': '\u062A\u062D',
  14648. '\uFC0D': '\u062A\u062E',
  14649. '\uFC0E': '\u062A\u0645',
  14650. '\uFC0F': '\u062A\u0649',
  14651. '\uFC10': '\u062A\u064A',
  14652. '\uFC11': '\u062B\u062C',
  14653. '\uFC12': '\u062B\u0645',
  14654. '\uFC13': '\u062B\u0649',
  14655. '\uFC14': '\u062B\u064A',
  14656. '\uFC15': '\u062C\u062D',
  14657. '\uFC16': '\u062C\u0645',
  14658. '\uFC17': '\u062D\u062C',
  14659. '\uFC18': '\u062D\u0645',
  14660. '\uFC19': '\u062E\u062C',
  14661. '\uFC1A': '\u062E\u062D',
  14662. '\uFC1B': '\u062E\u0645',
  14663. '\uFC1C': '\u0633\u062C',
  14664. '\uFC1D': '\u0633\u062D',
  14665. '\uFC1E': '\u0633\u062E',
  14666. '\uFC1F': '\u0633\u0645',
  14667. '\uFC20': '\u0635\u062D',
  14668. '\uFC21': '\u0635\u0645',
  14669. '\uFC22': '\u0636\u062C',
  14670. '\uFC23': '\u0636\u062D',
  14671. '\uFC24': '\u0636\u062E',
  14672. '\uFC25': '\u0636\u0645',
  14673. '\uFC26': '\u0637\u062D',
  14674. '\uFC27': '\u0637\u0645',
  14675. '\uFC28': '\u0638\u0645',
  14676. '\uFC29': '\u0639\u062C',
  14677. '\uFC2A': '\u0639\u0645',
  14678. '\uFC2B': '\u063A\u062C',
  14679. '\uFC2C': '\u063A\u0645',
  14680. '\uFC2D': '\u0641\u062C',
  14681. '\uFC2E': '\u0641\u062D',
  14682. '\uFC2F': '\u0641\u062E',
  14683. '\uFC30': '\u0641\u0645',
  14684. '\uFC31': '\u0641\u0649',
  14685. '\uFC32': '\u0641\u064A',
  14686. '\uFC33': '\u0642\u062D',
  14687. '\uFC34': '\u0642\u0645',
  14688. '\uFC35': '\u0642\u0649',
  14689. '\uFC36': '\u0642\u064A',
  14690. '\uFC37': '\u0643\u0627',
  14691. '\uFC38': '\u0643\u062C',
  14692. '\uFC39': '\u0643\u062D',
  14693. '\uFC3A': '\u0643\u062E',
  14694. '\uFC3B': '\u0643\u0644',
  14695. '\uFC3C': '\u0643\u0645',
  14696. '\uFC3D': '\u0643\u0649',
  14697. '\uFC3E': '\u0643\u064A',
  14698. '\uFC3F': '\u0644\u062C',
  14699. '\uFC40': '\u0644\u062D',
  14700. '\uFC41': '\u0644\u062E',
  14701. '\uFC42': '\u0644\u0645',
  14702. '\uFC43': '\u0644\u0649',
  14703. '\uFC44': '\u0644\u064A',
  14704. '\uFC45': '\u0645\u062C',
  14705. '\uFC46': '\u0645\u062D',
  14706. '\uFC47': '\u0645\u062E',
  14707. '\uFC48': '\u0645\u0645',
  14708. '\uFC49': '\u0645\u0649',
  14709. '\uFC4A': '\u0645\u064A',
  14710. '\uFC4B': '\u0646\u062C',
  14711. '\uFC4C': '\u0646\u062D',
  14712. '\uFC4D': '\u0646\u062E',
  14713. '\uFC4E': '\u0646\u0645',
  14714. '\uFC4F': '\u0646\u0649',
  14715. '\uFC50': '\u0646\u064A',
  14716. '\uFC51': '\u0647\u062C',
  14717. '\uFC52': '\u0647\u0645',
  14718. '\uFC53': '\u0647\u0649',
  14719. '\uFC54': '\u0647\u064A',
  14720. '\uFC55': '\u064A\u062C',
  14721. '\uFC56': '\u064A\u062D',
  14722. '\uFC57': '\u064A\u062E',
  14723. '\uFC58': '\u064A\u0645',
  14724. '\uFC59': '\u064A\u0649',
  14725. '\uFC5A': '\u064A\u064A',
  14726. '\uFC5B': '\u0630\u0670',
  14727. '\uFC5C': '\u0631\u0670',
  14728. '\uFC5D': '\u0649\u0670',
  14729. '\uFC5E': '\u0020\u064C\u0651',
  14730. '\uFC5F': '\u0020\u064D\u0651',
  14731. '\uFC60': '\u0020\u064E\u0651',
  14732. '\uFC61': '\u0020\u064F\u0651',
  14733. '\uFC62': '\u0020\u0650\u0651',
  14734. '\uFC63': '\u0020\u0651\u0670',
  14735. '\uFC64': '\u0626\u0631',
  14736. '\uFC65': '\u0626\u0632',
  14737. '\uFC66': '\u0626\u0645',
  14738. '\uFC67': '\u0626\u0646',
  14739. '\uFC68': '\u0626\u0649',
  14740. '\uFC69': '\u0626\u064A',
  14741. '\uFC6A': '\u0628\u0631',
  14742. '\uFC6B': '\u0628\u0632',
  14743. '\uFC6C': '\u0628\u0645',
  14744. '\uFC6D': '\u0628\u0646',
  14745. '\uFC6E': '\u0628\u0649',
  14746. '\uFC6F': '\u0628\u064A',
  14747. '\uFC70': '\u062A\u0631',
  14748. '\uFC71': '\u062A\u0632',
  14749. '\uFC72': '\u062A\u0645',
  14750. '\uFC73': '\u062A\u0646',
  14751. '\uFC74': '\u062A\u0649',
  14752. '\uFC75': '\u062A\u064A',
  14753. '\uFC76': '\u062B\u0631',
  14754. '\uFC77': '\u062B\u0632',
  14755. '\uFC78': '\u062B\u0645',
  14756. '\uFC79': '\u062B\u0646',
  14757. '\uFC7A': '\u062B\u0649',
  14758. '\uFC7B': '\u062B\u064A',
  14759. '\uFC7C': '\u0641\u0649',
  14760. '\uFC7D': '\u0641\u064A',
  14761. '\uFC7E': '\u0642\u0649',
  14762. '\uFC7F': '\u0642\u064A',
  14763. '\uFC80': '\u0643\u0627',
  14764. '\uFC81': '\u0643\u0644',
  14765. '\uFC82': '\u0643\u0645',
  14766. '\uFC83': '\u0643\u0649',
  14767. '\uFC84': '\u0643\u064A',
  14768. '\uFC85': '\u0644\u0645',
  14769. '\uFC86': '\u0644\u0649',
  14770. '\uFC87': '\u0644\u064A',
  14771. '\uFC88': '\u0645\u0627',
  14772. '\uFC89': '\u0645\u0645',
  14773. '\uFC8A': '\u0646\u0631',
  14774. '\uFC8B': '\u0646\u0632',
  14775. '\uFC8C': '\u0646\u0645',
  14776. '\uFC8D': '\u0646\u0646',
  14777. '\uFC8E': '\u0646\u0649',
  14778. '\uFC8F': '\u0646\u064A',
  14779. '\uFC90': '\u0649\u0670',
  14780. '\uFC91': '\u064A\u0631',
  14781. '\uFC92': '\u064A\u0632',
  14782. '\uFC93': '\u064A\u0645',
  14783. '\uFC94': '\u064A\u0646',
  14784. '\uFC95': '\u064A\u0649',
  14785. '\uFC96': '\u064A\u064A',
  14786. '\uFC97': '\u0626\u062C',
  14787. '\uFC98': '\u0626\u062D',
  14788. '\uFC99': '\u0626\u062E',
  14789. '\uFC9A': '\u0626\u0645',
  14790. '\uFC9B': '\u0626\u0647',
  14791. '\uFC9C': '\u0628\u062C',
  14792. '\uFC9D': '\u0628\u062D',
  14793. '\uFC9E': '\u0628\u062E',
  14794. '\uFC9F': '\u0628\u0645',
  14795. '\uFCA0': '\u0628\u0647',
  14796. '\uFCA1': '\u062A\u062C',
  14797. '\uFCA2': '\u062A\u062D',
  14798. '\uFCA3': '\u062A\u062E',
  14799. '\uFCA4': '\u062A\u0645',
  14800. '\uFCA5': '\u062A\u0647',
  14801. '\uFCA6': '\u062B\u0645',
  14802. '\uFCA7': '\u062C\u062D',
  14803. '\uFCA8': '\u062C\u0645',
  14804. '\uFCA9': '\u062D\u062C',
  14805. '\uFCAA': '\u062D\u0645',
  14806. '\uFCAB': '\u062E\u062C',
  14807. '\uFCAC': '\u062E\u0645',
  14808. '\uFCAD': '\u0633\u062C',
  14809. '\uFCAE': '\u0633\u062D',
  14810. '\uFCAF': '\u0633\u062E',
  14811. '\uFCB0': '\u0633\u0645',
  14812. '\uFCB1': '\u0635\u062D',
  14813. '\uFCB2': '\u0635\u062E',
  14814. '\uFCB3': '\u0635\u0645',
  14815. '\uFCB4': '\u0636\u062C',
  14816. '\uFCB5': '\u0636\u062D',
  14817. '\uFCB6': '\u0636\u062E',
  14818. '\uFCB7': '\u0636\u0645',
  14819. '\uFCB8': '\u0637\u062D',
  14820. '\uFCB9': '\u0638\u0645',
  14821. '\uFCBA': '\u0639\u062C',
  14822. '\uFCBB': '\u0639\u0645',
  14823. '\uFCBC': '\u063A\u062C',
  14824. '\uFCBD': '\u063A\u0645',
  14825. '\uFCBE': '\u0641\u062C',
  14826. '\uFCBF': '\u0641\u062D',
  14827. '\uFCC0': '\u0641\u062E',
  14828. '\uFCC1': '\u0641\u0645',
  14829. '\uFCC2': '\u0642\u062D',
  14830. '\uFCC3': '\u0642\u0645',
  14831. '\uFCC4': '\u0643\u062C',
  14832. '\uFCC5': '\u0643\u062D',
  14833. '\uFCC6': '\u0643\u062E',
  14834. '\uFCC7': '\u0643\u0644',
  14835. '\uFCC8': '\u0643\u0645',
  14836. '\uFCC9': '\u0644\u062C',
  14837. '\uFCCA': '\u0644\u062D',
  14838. '\uFCCB': '\u0644\u062E',
  14839. '\uFCCC': '\u0644\u0645',
  14840. '\uFCCD': '\u0644\u0647',
  14841. '\uFCCE': '\u0645\u062C',
  14842. '\uFCCF': '\u0645\u062D',
  14843. '\uFCD0': '\u0645\u062E',
  14844. '\uFCD1': '\u0645\u0645',
  14845. '\uFCD2': '\u0646\u062C',
  14846. '\uFCD3': '\u0646\u062D',
  14847. '\uFCD4': '\u0646\u062E',
  14848. '\uFCD5': '\u0646\u0645',
  14849. '\uFCD6': '\u0646\u0647',
  14850. '\uFCD7': '\u0647\u062C',
  14851. '\uFCD8': '\u0647\u0645',
  14852. '\uFCD9': '\u0647\u0670',
  14853. '\uFCDA': '\u064A\u062C',
  14854. '\uFCDB': '\u064A\u062D',
  14855. '\uFCDC': '\u064A\u062E',
  14856. '\uFCDD': '\u064A\u0645',
  14857. '\uFCDE': '\u064A\u0647',
  14858. '\uFCDF': '\u0626\u0645',
  14859. '\uFCE0': '\u0626\u0647',
  14860. '\uFCE1': '\u0628\u0645',
  14861. '\uFCE2': '\u0628\u0647',
  14862. '\uFCE3': '\u062A\u0645',
  14863. '\uFCE4': '\u062A\u0647',
  14864. '\uFCE5': '\u062B\u0645',
  14865. '\uFCE6': '\u062B\u0647',
  14866. '\uFCE7': '\u0633\u0645',
  14867. '\uFCE8': '\u0633\u0647',
  14868. '\uFCE9': '\u0634\u0645',
  14869. '\uFCEA': '\u0634\u0647',
  14870. '\uFCEB': '\u0643\u0644',
  14871. '\uFCEC': '\u0643\u0645',
  14872. '\uFCED': '\u0644\u0645',
  14873. '\uFCEE': '\u0646\u0645',
  14874. '\uFCEF': '\u0646\u0647',
  14875. '\uFCF0': '\u064A\u0645',
  14876. '\uFCF1': '\u064A\u0647',
  14877. '\uFCF2': '\u0640\u064E\u0651',
  14878. '\uFCF3': '\u0640\u064F\u0651',
  14879. '\uFCF4': '\u0640\u0650\u0651',
  14880. '\uFCF5': '\u0637\u0649',
  14881. '\uFCF6': '\u0637\u064A',
  14882. '\uFCF7': '\u0639\u0649',
  14883. '\uFCF8': '\u0639\u064A',
  14884. '\uFCF9': '\u063A\u0649',
  14885. '\uFCFA': '\u063A\u064A',
  14886. '\uFCFB': '\u0633\u0649',
  14887. '\uFCFC': '\u0633\u064A',
  14888. '\uFCFD': '\u0634\u0649',
  14889. '\uFCFE': '\u0634\u064A',
  14890. '\uFCFF': '\u062D\u0649',
  14891. '\uFD00': '\u062D\u064A',
  14892. '\uFD01': '\u062C\u0649',
  14893. '\uFD02': '\u062C\u064A',
  14894. '\uFD03': '\u062E\u0649',
  14895. '\uFD04': '\u062E\u064A',
  14896. '\uFD05': '\u0635\u0649',
  14897. '\uFD06': '\u0635\u064A',
  14898. '\uFD07': '\u0636\u0649',
  14899. '\uFD08': '\u0636\u064A',
  14900. '\uFD09': '\u0634\u062C',
  14901. '\uFD0A': '\u0634\u062D',
  14902. '\uFD0B': '\u0634\u062E',
  14903. '\uFD0C': '\u0634\u0645',
  14904. '\uFD0D': '\u0634\u0631',
  14905. '\uFD0E': '\u0633\u0631',
  14906. '\uFD0F': '\u0635\u0631',
  14907. '\uFD10': '\u0636\u0631',
  14908. '\uFD11': '\u0637\u0649',
  14909. '\uFD12': '\u0637\u064A',
  14910. '\uFD13': '\u0639\u0649',
  14911. '\uFD14': '\u0639\u064A',
  14912. '\uFD15': '\u063A\u0649',
  14913. '\uFD16': '\u063A\u064A',
  14914. '\uFD17': '\u0633\u0649',
  14915. '\uFD18': '\u0633\u064A',
  14916. '\uFD19': '\u0634\u0649',
  14917. '\uFD1A': '\u0634\u064A',
  14918. '\uFD1B': '\u062D\u0649',
  14919. '\uFD1C': '\u062D\u064A',
  14920. '\uFD1D': '\u062C\u0649',
  14921. '\uFD1E': '\u062C\u064A',
  14922. '\uFD1F': '\u062E\u0649',
  14923. '\uFD20': '\u062E\u064A',
  14924. '\uFD21': '\u0635\u0649',
  14925. '\uFD22': '\u0635\u064A',
  14926. '\uFD23': '\u0636\u0649',
  14927. '\uFD24': '\u0636\u064A',
  14928. '\uFD25': '\u0634\u062C',
  14929. '\uFD26': '\u0634\u062D',
  14930. '\uFD27': '\u0634\u062E',
  14931. '\uFD28': '\u0634\u0645',
  14932. '\uFD29': '\u0634\u0631',
  14933. '\uFD2A': '\u0633\u0631',
  14934. '\uFD2B': '\u0635\u0631',
  14935. '\uFD2C': '\u0636\u0631',
  14936. '\uFD2D': '\u0634\u062C',
  14937. '\uFD2E': '\u0634\u062D',
  14938. '\uFD2F': '\u0634\u062E',
  14939. '\uFD30': '\u0634\u0645',
  14940. '\uFD31': '\u0633\u0647',
  14941. '\uFD32': '\u0634\u0647',
  14942. '\uFD33': '\u0637\u0645',
  14943. '\uFD34': '\u0633\u062C',
  14944. '\uFD35': '\u0633\u062D',
  14945. '\uFD36': '\u0633\u062E',
  14946. '\uFD37': '\u0634\u062C',
  14947. '\uFD38': '\u0634\u062D',
  14948. '\uFD39': '\u0634\u062E',
  14949. '\uFD3A': '\u0637\u0645',
  14950. '\uFD3B': '\u0638\u0645',
  14951. '\uFD3C': '\u0627\u064B',
  14952. '\uFD3D': '\u0627\u064B',
  14953. '\uFD50': '\u062A\u062C\u0645',
  14954. '\uFD51': '\u062A\u062D\u062C',
  14955. '\uFD52': '\u062A\u062D\u062C',
  14956. '\uFD53': '\u062A\u062D\u0645',
  14957. '\uFD54': '\u062A\u062E\u0645',
  14958. '\uFD55': '\u062A\u0645\u062C',
  14959. '\uFD56': '\u062A\u0645\u062D',
  14960. '\uFD57': '\u062A\u0645\u062E',
  14961. '\uFD58': '\u062C\u0645\u062D',
  14962. '\uFD59': '\u062C\u0645\u062D',
  14963. '\uFD5A': '\u062D\u0645\u064A',
  14964. '\uFD5B': '\u062D\u0645\u0649',
  14965. '\uFD5C': '\u0633\u062D\u062C',
  14966. '\uFD5D': '\u0633\u062C\u062D',
  14967. '\uFD5E': '\u0633\u062C\u0649',
  14968. '\uFD5F': '\u0633\u0645\u062D',
  14969. '\uFD60': '\u0633\u0645\u062D',
  14970. '\uFD61': '\u0633\u0645\u062C',
  14971. '\uFD62': '\u0633\u0645\u0645',
  14972. '\uFD63': '\u0633\u0645\u0645',
  14973. '\uFD64': '\u0635\u062D\u062D',
  14974. '\uFD65': '\u0635\u062D\u062D',
  14975. '\uFD66': '\u0635\u0645\u0645',
  14976. '\uFD67': '\u0634\u062D\u0645',
  14977. '\uFD68': '\u0634\u062D\u0645',
  14978. '\uFD69': '\u0634\u062C\u064A',
  14979. '\uFD6A': '\u0634\u0645\u062E',
  14980. '\uFD6B': '\u0634\u0645\u062E',
  14981. '\uFD6C': '\u0634\u0645\u0645',
  14982. '\uFD6D': '\u0634\u0645\u0645',
  14983. '\uFD6E': '\u0636\u062D\u0649',
  14984. '\uFD6F': '\u0636\u062E\u0645',
  14985. '\uFD70': '\u0636\u062E\u0645',
  14986. '\uFD71': '\u0637\u0645\u062D',
  14987. '\uFD72': '\u0637\u0645\u062D',
  14988. '\uFD73': '\u0637\u0645\u0645',
  14989. '\uFD74': '\u0637\u0645\u064A',
  14990. '\uFD75': '\u0639\u062C\u0645',
  14991. '\uFD76': '\u0639\u0645\u0645',
  14992. '\uFD77': '\u0639\u0645\u0645',
  14993. '\uFD78': '\u0639\u0645\u0649',
  14994. '\uFD79': '\u063A\u0645\u0645',
  14995. '\uFD7A': '\u063A\u0645\u064A',
  14996. '\uFD7B': '\u063A\u0645\u0649',
  14997. '\uFD7C': '\u0641\u062E\u0645',
  14998. '\uFD7D': '\u0641\u062E\u0645',
  14999. '\uFD7E': '\u0642\u0645\u062D',
  15000. '\uFD7F': '\u0642\u0645\u0645',
  15001. '\uFD80': '\u0644\u062D\u0645',
  15002. '\uFD81': '\u0644\u062D\u064A',
  15003. '\uFD82': '\u0644\u062D\u0649',
  15004. '\uFD83': '\u0644\u062C\u062C',
  15005. '\uFD84': '\u0644\u062C\u062C',
  15006. '\uFD85': '\u0644\u062E\u0645',
  15007. '\uFD86': '\u0644\u062E\u0645',
  15008. '\uFD87': '\u0644\u0645\u062D',
  15009. '\uFD88': '\u0644\u0645\u062D',
  15010. '\uFD89': '\u0645\u062D\u062C',
  15011. '\uFD8A': '\u0645\u062D\u0645',
  15012. '\uFD8B': '\u0645\u062D\u064A',
  15013. '\uFD8C': '\u0645\u062C\u062D',
  15014. '\uFD8D': '\u0645\u062C\u0645',
  15015. '\uFD8E': '\u0645\u062E\u062C',
  15016. '\uFD8F': '\u0645\u062E\u0645',
  15017. '\uFD92': '\u0645\u062C\u062E',
  15018. '\uFD93': '\u0647\u0645\u062C',
  15019. '\uFD94': '\u0647\u0645\u0645',
  15020. '\uFD95': '\u0646\u062D\u0645',
  15021. '\uFD96': '\u0646\u062D\u0649',
  15022. '\uFD97': '\u0646\u062C\u0645',
  15023. '\uFD98': '\u0646\u062C\u0645',
  15024. '\uFD99': '\u0646\u062C\u0649',
  15025. '\uFD9A': '\u0646\u0645\u064A',
  15026. '\uFD9B': '\u0646\u0645\u0649',
  15027. '\uFD9C': '\u064A\u0645\u0645',
  15028. '\uFD9D': '\u064A\u0645\u0645',
  15029. '\uFD9E': '\u0628\u062E\u064A',
  15030. '\uFD9F': '\u062A\u062C\u064A',
  15031. '\uFDA0': '\u062A\u062C\u0649',
  15032. '\uFDA1': '\u062A\u062E\u064A',
  15033. '\uFDA2': '\u062A\u062E\u0649',
  15034. '\uFDA3': '\u062A\u0645\u064A',
  15035. '\uFDA4': '\u062A\u0645\u0649',
  15036. '\uFDA5': '\u062C\u0645\u064A',
  15037. '\uFDA6': '\u062C\u062D\u0649',
  15038. '\uFDA7': '\u062C\u0645\u0649',
  15039. '\uFDA8': '\u0633\u062E\u0649',
  15040. '\uFDA9': '\u0635\u062D\u064A',
  15041. '\uFDAA': '\u0634\u062D\u064A',
  15042. '\uFDAB': '\u0636\u062D\u064A',
  15043. '\uFDAC': '\u0644\u062C\u064A',
  15044. '\uFDAD': '\u0644\u0645\u064A',
  15045. '\uFDAE': '\u064A\u062D\u064A',
  15046. '\uFDAF': '\u064A\u062C\u064A',
  15047. '\uFDB0': '\u064A\u0645\u064A',
  15048. '\uFDB1': '\u0645\u0645\u064A',
  15049. '\uFDB2': '\u0642\u0645\u064A',
  15050. '\uFDB3': '\u0646\u062D\u064A',
  15051. '\uFDB4': '\u0642\u0645\u062D',
  15052. '\uFDB5': '\u0644\u062D\u0645',
  15053. '\uFDB6': '\u0639\u0645\u064A',
  15054. '\uFDB7': '\u0643\u0645\u064A',
  15055. '\uFDB8': '\u0646\u062C\u062D',
  15056. '\uFDB9': '\u0645\u062E\u064A',
  15057. '\uFDBA': '\u0644\u062C\u0645',
  15058. '\uFDBB': '\u0643\u0645\u0645',
  15059. '\uFDBC': '\u0644\u062C\u0645',
  15060. '\uFDBD': '\u0646\u062C\u062D',
  15061. '\uFDBE': '\u062C\u062D\u064A',
  15062. '\uFDBF': '\u062D\u062C\u064A',
  15063. '\uFDC0': '\u0645\u062C\u064A',
  15064. '\uFDC1': '\u0641\u0645\u064A',
  15065. '\uFDC2': '\u0628\u062D\u064A',
  15066. '\uFDC3': '\u0643\u0645\u0645',
  15067. '\uFDC4': '\u0639\u062C\u0645',
  15068. '\uFDC5': '\u0635\u0645\u0645',
  15069. '\uFDC6': '\u0633\u062E\u064A',
  15070. '\uFDC7': '\u0646\u062C\u064A',
  15071. '\uFE49': '\u203E',
  15072. '\uFE4A': '\u203E',
  15073. '\uFE4B': '\u203E',
  15074. '\uFE4C': '\u203E',
  15075. '\uFE4D': '\u005F',
  15076. '\uFE4E': '\u005F',
  15077. '\uFE4F': '\u005F',
  15078. '\uFE80': '\u0621',
  15079. '\uFE81': '\u0622',
  15080. '\uFE82': '\u0622',
  15081. '\uFE83': '\u0623',
  15082. '\uFE84': '\u0623',
  15083. '\uFE85': '\u0624',
  15084. '\uFE86': '\u0624',
  15085. '\uFE87': '\u0625',
  15086. '\uFE88': '\u0625',
  15087. '\uFE89': '\u0626',
  15088. '\uFE8A': '\u0626',
  15089. '\uFE8B': '\u0626',
  15090. '\uFE8C': '\u0626',
  15091. '\uFE8D': '\u0627',
  15092. '\uFE8E': '\u0627',
  15093. '\uFE8F': '\u0628',
  15094. '\uFE90': '\u0628',
  15095. '\uFE91': '\u0628',
  15096. '\uFE92': '\u0628',
  15097. '\uFE93': '\u0629',
  15098. '\uFE94': '\u0629',
  15099. '\uFE95': '\u062A',
  15100. '\uFE96': '\u062A',
  15101. '\uFE97': '\u062A',
  15102. '\uFE98': '\u062A',
  15103. '\uFE99': '\u062B',
  15104. '\uFE9A': '\u062B',
  15105. '\uFE9B': '\u062B',
  15106. '\uFE9C': '\u062B',
  15107. '\uFE9D': '\u062C',
  15108. '\uFE9E': '\u062C',
  15109. '\uFE9F': '\u062C',
  15110. '\uFEA0': '\u062C',
  15111. '\uFEA1': '\u062D',
  15112. '\uFEA2': '\u062D',
  15113. '\uFEA3': '\u062D',
  15114. '\uFEA4': '\u062D',
  15115. '\uFEA5': '\u062E',
  15116. '\uFEA6': '\u062E',
  15117. '\uFEA7': '\u062E',
  15118. '\uFEA8': '\u062E',
  15119. '\uFEA9': '\u062F',
  15120. '\uFEAA': '\u062F',
  15121. '\uFEAB': '\u0630',
  15122. '\uFEAC': '\u0630',
  15123. '\uFEAD': '\u0631',
  15124. '\uFEAE': '\u0631',
  15125. '\uFEAF': '\u0632',
  15126. '\uFEB0': '\u0632',
  15127. '\uFEB1': '\u0633',
  15128. '\uFEB2': '\u0633',
  15129. '\uFEB3': '\u0633',
  15130. '\uFEB4': '\u0633',
  15131. '\uFEB5': '\u0634',
  15132. '\uFEB6': '\u0634',
  15133. '\uFEB7': '\u0634',
  15134. '\uFEB8': '\u0634',
  15135. '\uFEB9': '\u0635',
  15136. '\uFEBA': '\u0635',
  15137. '\uFEBB': '\u0635',
  15138. '\uFEBC': '\u0635',
  15139. '\uFEBD': '\u0636',
  15140. '\uFEBE': '\u0636',
  15141. '\uFEBF': '\u0636',
  15142. '\uFEC0': '\u0636',
  15143. '\uFEC1': '\u0637',
  15144. '\uFEC2': '\u0637',
  15145. '\uFEC3': '\u0637',
  15146. '\uFEC4': '\u0637',
  15147. '\uFEC5': '\u0638',
  15148. '\uFEC6': '\u0638',
  15149. '\uFEC7': '\u0638',
  15150. '\uFEC8': '\u0638',
  15151. '\uFEC9': '\u0639',
  15152. '\uFECA': '\u0639',
  15153. '\uFECB': '\u0639',
  15154. '\uFECC': '\u0639',
  15155. '\uFECD': '\u063A',
  15156. '\uFECE': '\u063A',
  15157. '\uFECF': '\u063A',
  15158. '\uFED0': '\u063A',
  15159. '\uFED1': '\u0641',
  15160. '\uFED2': '\u0641',
  15161. '\uFED3': '\u0641',
  15162. '\uFED4': '\u0641',
  15163. '\uFED5': '\u0642',
  15164. '\uFED6': '\u0642',
  15165. '\uFED7': '\u0642',
  15166. '\uFED8': '\u0642',
  15167. '\uFED9': '\u0643',
  15168. '\uFEDA': '\u0643',
  15169. '\uFEDB': '\u0643',
  15170. '\uFEDC': '\u0643',
  15171. '\uFEDD': '\u0644',
  15172. '\uFEDE': '\u0644',
  15173. '\uFEDF': '\u0644',
  15174. '\uFEE0': '\u0644',
  15175. '\uFEE1': '\u0645',
  15176. '\uFEE2': '\u0645',
  15177. '\uFEE3': '\u0645',
  15178. '\uFEE4': '\u0645',
  15179. '\uFEE5': '\u0646',
  15180. '\uFEE6': '\u0646',
  15181. '\uFEE7': '\u0646',
  15182. '\uFEE8': '\u0646',
  15183. '\uFEE9': '\u0647',
  15184. '\uFEEA': '\u0647',
  15185. '\uFEEB': '\u0647',
  15186. '\uFEEC': '\u0647',
  15187. '\uFEED': '\u0648',
  15188. '\uFEEE': '\u0648',
  15189. '\uFEEF': '\u0649',
  15190. '\uFEF0': '\u0649',
  15191. '\uFEF1': '\u064A',
  15192. '\uFEF2': '\u064A',
  15193. '\uFEF3': '\u064A',
  15194. '\uFEF4': '\u064A',
  15195. '\uFEF5': '\u0644\u0622',
  15196. '\uFEF6': '\u0644\u0622',
  15197. '\uFEF7': '\u0644\u0623',
  15198. '\uFEF8': '\u0644\u0623',
  15199. '\uFEF9': '\u0644\u0625',
  15200. '\uFEFA': '\u0644\u0625',
  15201. '\uFEFB': '\u0644\u0627',
  15202. '\uFEFC': '\u0644\u0627'
  15203. };
  15204. function reverseIfRtl(chars) {
  15205. var charsLength = chars.length;
  15206. //reverse an arabic ligature
  15207. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  15208. return chars;
  15209. }
  15210. var s = '';
  15211. for (var ii = charsLength - 1; ii >= 0; ii--) {
  15212. s += chars[ii];
  15213. }
  15214. return s;
  15215. }
  15216. function adjustWidths(properties) {
  15217. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  15218. return;
  15219. }
  15220. // adjusting width to fontMatrix scale
  15221. var scale = 0.001 / properties.fontMatrix[0];
  15222. var glyphsWidths = properties.widths;
  15223. for (var glyph in glyphsWidths) {
  15224. glyphsWidths[glyph] *= scale;
  15225. }
  15226. properties.defaultWidth *= scale;
  15227. }
  15228. function getFontType(type, subtype) {
  15229. switch (type) {
  15230. case 'Type1':
  15231. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15232. case 'CIDFontType0':
  15233. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15234. FontType.CIDFONTTYPE0;
  15235. case 'OpenType':
  15236. return FontType.OPENTYPE;
  15237. case 'TrueType':
  15238. return FontType.TRUETYPE;
  15239. case 'CIDFontType2':
  15240. return FontType.CIDFONTTYPE2;
  15241. case 'MMType1':
  15242. return FontType.MMTYPE1;
  15243. case 'Type0':
  15244. return FontType.TYPE0;
  15245. default:
  15246. return FontType.UNKNOWN;
  15247. }
  15248. }
  15249. var Glyph = (function GlyphClosure() {
  15250. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15251. this.fontChar = fontChar;
  15252. this.unicode = unicode;
  15253. this.accent = accent;
  15254. this.width = width;
  15255. this.vmetric = vmetric;
  15256. this.operatorListId = operatorListId;
  15257. }
  15258. Glyph.prototype.matchesForCache =
  15259. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15260. return this.fontChar === fontChar &&
  15261. this.unicode === unicode &&
  15262. this.accent === accent &&
  15263. this.width === width &&
  15264. this.vmetric === vmetric &&
  15265. this.operatorListId === operatorListId;
  15266. };
  15267. return Glyph;
  15268. })();
  15269. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15270. function ToUnicodeMap(cmap) {
  15271. // The elements of this._map can be integers or strings, depending on how
  15272. // |cmap| was created.
  15273. this._map = cmap;
  15274. }
  15275. ToUnicodeMap.prototype = {
  15276. get length() {
  15277. return this._map.length;
  15278. },
  15279. forEach: function(callback) {
  15280. for (var charCode in this._map) {
  15281. callback(charCode, this._map[charCode].charCodeAt(0));
  15282. }
  15283. },
  15284. has: function(i) {
  15285. return this._map[i] !== undefined;
  15286. },
  15287. get: function(i) {
  15288. return this._map[i];
  15289. },
  15290. charCodeOf: function(v) {
  15291. return this._map.indexOf(v);
  15292. }
  15293. };
  15294. return ToUnicodeMap;
  15295. })();
  15296. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15297. function IdentityToUnicodeMap(firstChar, lastChar) {
  15298. this.firstChar = firstChar;
  15299. this.lastChar = lastChar;
  15300. }
  15301. IdentityToUnicodeMap.prototype = {
  15302. get length() {
  15303. return (this.lastChar + 1) - this.firstChar;
  15304. },
  15305. forEach: function (callback) {
  15306. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15307. callback(i, i);
  15308. }
  15309. },
  15310. has: function (i) {
  15311. return this.firstChar <= i && i <= this.lastChar;
  15312. },
  15313. get: function (i) {
  15314. if (this.firstChar <= i && i <= this.lastChar) {
  15315. return String.fromCharCode(i);
  15316. }
  15317. return undefined;
  15318. },
  15319. charCodeOf: function (v) {
  15320. error('should not call .charCodeOf');
  15321. }
  15322. };
  15323. return IdentityToUnicodeMap;
  15324. })();
  15325. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15326. function writeInt16(dest, offset, num) {
  15327. dest[offset] = (num >> 8) & 0xFF;
  15328. dest[offset + 1] = num & 0xFF;
  15329. }
  15330. function writeInt32(dest, offset, num) {
  15331. dest[offset] = (num >> 24) & 0xFF;
  15332. dest[offset + 1] = (num >> 16) & 0xFF;
  15333. dest[offset + 2] = (num >> 8) & 0xFF;
  15334. dest[offset + 3] = num & 0xFF;
  15335. }
  15336. function writeData(dest, offset, data) {
  15337. var i, ii;
  15338. if (data instanceof Uint8Array) {
  15339. dest.set(data, offset);
  15340. } else if (typeof data === 'string') {
  15341. for (i = 0, ii = data.length; i < ii; i++) {
  15342. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15343. }
  15344. } else {
  15345. // treating everything else as array
  15346. for (i = 0, ii = data.length; i < ii; i++) {
  15347. dest[offset++] = data[i] & 0xFF;
  15348. }
  15349. }
  15350. }
  15351. function OpenTypeFileBuilder(sfnt) {
  15352. this.sfnt = sfnt;
  15353. this.tables = Object.create(null);
  15354. }
  15355. OpenTypeFileBuilder.getSearchParams =
  15356. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15357. var maxPower2 = 1, log2 = 0;
  15358. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15359. maxPower2 <<= 1;
  15360. log2++;
  15361. }
  15362. var searchRange = maxPower2 * entrySize;
  15363. return {
  15364. range: searchRange,
  15365. entry: log2,
  15366. rangeShift: entrySize * entriesCount - searchRange
  15367. };
  15368. };
  15369. var OTF_HEADER_SIZE = 12;
  15370. var OTF_TABLE_ENTRY_SIZE = 16;
  15371. OpenTypeFileBuilder.prototype = {
  15372. toArray: function OpenTypeFileBuilder_toArray() {
  15373. var sfnt = this.sfnt;
  15374. // Tables needs to be written by ascendant alphabetic order
  15375. var tables = this.tables;
  15376. var tablesNames = Object.keys(tables);
  15377. tablesNames.sort();
  15378. var numTables = tablesNames.length;
  15379. var i, j, jj, table, tableName;
  15380. // layout the tables data
  15381. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15382. var tableOffsets = [offset];
  15383. for (i = 0; i < numTables; i++) {
  15384. table = tables[tablesNames[i]];
  15385. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15386. offset += paddedLength;
  15387. tableOffsets.push(offset);
  15388. }
  15389. var file = new Uint8Array(offset);
  15390. // write the table data first (mostly for checksum)
  15391. for (i = 0; i < numTables; i++) {
  15392. table = tables[tablesNames[i]];
  15393. writeData(file, tableOffsets[i], table);
  15394. }
  15395. // sfnt version (4 bytes)
  15396. if (sfnt === 'true') {
  15397. // Windows hates the Mac TrueType sfnt version number
  15398. sfnt = string32(0x00010000);
  15399. }
  15400. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15401. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15402. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15403. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15404. // numTables (2 bytes)
  15405. writeInt16(file, 4, numTables);
  15406. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15407. // searchRange (2 bytes)
  15408. writeInt16(file, 6, searchParams.range);
  15409. // entrySelector (2 bytes)
  15410. writeInt16(file, 8, searchParams.entry);
  15411. // rangeShift (2 bytes)
  15412. writeInt16(file, 10, searchParams.rangeShift);
  15413. offset = OTF_HEADER_SIZE;
  15414. // writing table entries
  15415. for (i = 0; i < numTables; i++) {
  15416. tableName = tablesNames[i];
  15417. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15418. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15419. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15420. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15421. // checksum
  15422. var checksum = 0;
  15423. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15424. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15425. (file[j + 2] << 8) + file[j + 3];
  15426. checksum = (checksum + quad) | 0;
  15427. }
  15428. writeInt32(file, offset + 4, checksum);
  15429. // offset
  15430. writeInt32(file, offset + 8, tableOffsets[i]);
  15431. // length
  15432. writeInt32(file, offset + 12, tables[tableName].length);
  15433. offset += OTF_TABLE_ENTRY_SIZE;
  15434. }
  15435. return file;
  15436. },
  15437. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15438. if (tag in this.tables) {
  15439. throw new Error('Table ' + tag + ' already exists');
  15440. }
  15441. this.tables[tag] = data;
  15442. }
  15443. };
  15444. return OpenTypeFileBuilder;
  15445. })();
  15446. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  15447. // issues when they are painted on the canvas, e.g. complex-script shaping or
  15448. // control/whitespace characters. The ranges are listed in pairs: the first item
  15449. // is a code of the first problematic code, the second one is the next
  15450. // non-problematic code. The ranges must be in sorted order.
  15451. var ProblematicCharRanges = new Int32Array([
  15452. // Control characters.
  15453. 0x0000, 0x0020,
  15454. 0x007F, 0x00A1,
  15455. 0x00AD, 0x00AE,
  15456. // Chars that is used in complex-script shaping.
  15457. 0x0600, 0x0780,
  15458. 0x08A0, 0x10A0,
  15459. 0x1780, 0x1800,
  15460. // General punctuation chars.
  15461. 0x2000, 0x2010,
  15462. 0x2011, 0x2012,
  15463. 0x2028, 0x2030,
  15464. 0x205F, 0x2070,
  15465. 0x25CC, 0x25CD,
  15466. // Chars that is used in complex-script shaping.
  15467. 0xAA60, 0xAA80,
  15468. // Specials Unicode block.
  15469. 0xFFF0, 0x10000
  15470. ]);
  15471. /**
  15472. * 'Font' is the class the outside world should use, it encapsulate all the font
  15473. * decoding logics whatever type it is (assuming the font type is supported).
  15474. *
  15475. * For example to read a Type1 font and to attach it to the document:
  15476. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15477. * type1Font.bind();
  15478. */
  15479. var Font = (function FontClosure() {
  15480. function Font(name, file, properties) {
  15481. var charCode, glyphName, fontChar;
  15482. this.name = name;
  15483. this.loadedName = properties.loadedName;
  15484. this.isType3Font = properties.isType3Font;
  15485. this.sizes = [];
  15486. this.glyphCache = {};
  15487. var names = name.split('+');
  15488. names = names.length > 1 ? names[1] : names[0];
  15489. names = names.split(/[-,_]/g)[0];
  15490. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15491. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15492. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15493. var type = properties.type;
  15494. var subtype = properties.subtype;
  15495. this.type = type;
  15496. this.fallbackName = (this.isMonospace ? 'monospace' :
  15497. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15498. this.differences = properties.differences;
  15499. this.widths = properties.widths;
  15500. this.defaultWidth = properties.defaultWidth;
  15501. this.composite = properties.composite;
  15502. this.wideChars = properties.wideChars;
  15503. this.cMap = properties.cMap;
  15504. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15505. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15506. this.fontMatrix = properties.fontMatrix;
  15507. this.bbox = properties.bbox;
  15508. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15509. this.toFontChar = [];
  15510. if (properties.type === 'Type3') {
  15511. for (charCode = 0; charCode < 256; charCode++) {
  15512. this.toFontChar[charCode] = (this.differences[charCode] ||
  15513. properties.defaultEncoding[charCode]);
  15514. }
  15515. this.fontType = FontType.TYPE3;
  15516. return;
  15517. }
  15518. this.cidEncoding = properties.cidEncoding;
  15519. this.vertical = properties.vertical;
  15520. if (this.vertical) {
  15521. this.vmetrics = properties.vmetrics;
  15522. this.defaultVMetrics = properties.defaultVMetrics;
  15523. }
  15524. if (!file || file.isEmpty) {
  15525. if (file) {
  15526. // Some bad PDF generators will include empty font files,
  15527. // attempting to recover by assuming that no file exists.
  15528. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15529. }
  15530. this.missingFile = true;
  15531. // The file data is not specified. Trying to fix the font name
  15532. // to be used with the canvas.font.
  15533. var fontName = name.replace(/[,_]/g, '-');
  15534. var isStandardFont = !!stdFontMap[fontName] ||
  15535. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15536. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15537. this.bold = (fontName.search(/bold/gi) !== -1);
  15538. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15539. (fontName.search(/italic/gi) !== -1));
  15540. // Use 'name' instead of 'fontName' here because the original
  15541. // name ArialBlack for example will be replaced by Helvetica.
  15542. this.black = (name.search(/Black/g) !== -1);
  15543. // if at least one width is present, remeasure all chars when exists
  15544. this.remeasure = Object.keys(this.widths).length > 0;
  15545. if (isStandardFont && type === 'CIDFontType2' &&
  15546. properties.cidEncoding.indexOf('Identity-') === 0) {
  15547. // Standard fonts might be embedded as CID font without glyph mapping.
  15548. // Building one based on GlyphMapForStandardFonts.
  15549. var map = [];
  15550. for (charCode in GlyphMapForStandardFonts) {
  15551. map[+charCode] = GlyphMapForStandardFonts[charCode];
  15552. }
  15553. if (/ArialBlack/i.test(name)) {
  15554. for (charCode in SupplementalGlyphMapForArialBlack) {
  15555. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  15556. }
  15557. }
  15558. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15559. if (!isIdentityUnicode) {
  15560. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15561. map[+charCode] = unicodeCharCode;
  15562. });
  15563. }
  15564. this.toFontChar = map;
  15565. this.toUnicode = new ToUnicodeMap(map);
  15566. } else if (/Symbol/i.test(fontName)) {
  15567. var symbols = Encodings.SymbolSetEncoding;
  15568. for (charCode in symbols) {
  15569. fontChar = GlyphsUnicode[symbols[charCode]];
  15570. if (!fontChar) {
  15571. continue;
  15572. }
  15573. this.toFontChar[charCode] = fontChar;
  15574. }
  15575. for (charCode in properties.differences) {
  15576. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15577. if (!fontChar) {
  15578. continue;
  15579. }
  15580. this.toFontChar[charCode] = fontChar;
  15581. }
  15582. } else if (/Dingbats/i.test(fontName)) {
  15583. if (/Wingdings/i.test(name)) {
  15584. warn('Wingdings font without embedded font file, ' +
  15585. 'falling back to the ZapfDingbats encoding.');
  15586. }
  15587. var dingbats = Encodings.ZapfDingbatsEncoding;
  15588. for (charCode in dingbats) {
  15589. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15590. if (!fontChar) {
  15591. continue;
  15592. }
  15593. this.toFontChar[charCode] = fontChar;
  15594. }
  15595. for (charCode in properties.differences) {
  15596. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15597. if (!fontChar) {
  15598. continue;
  15599. }
  15600. this.toFontChar[charCode] = fontChar;
  15601. }
  15602. } else if (isStandardFont) {
  15603. this.toFontChar = [];
  15604. for (charCode in properties.defaultEncoding) {
  15605. glyphName = (properties.differences[charCode] ||
  15606. properties.defaultEncoding[charCode]);
  15607. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15608. }
  15609. } else {
  15610. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15611. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15612. if (notCidFont) {
  15613. glyphName = (properties.differences[charCode] ||
  15614. properties.defaultEncoding[charCode]);
  15615. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15616. }
  15617. this.toFontChar[charCode] = unicodeCharCode;
  15618. }.bind(this));
  15619. }
  15620. this.loadedName = fontName.split('-')[0];
  15621. this.loading = false;
  15622. this.fontType = getFontType(type, subtype);
  15623. return;
  15624. }
  15625. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15626. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15627. // Some TrueType fonts by mistake claim Type1C
  15628. if (isTrueTypeFile(file)) {
  15629. subtype = 'TrueType';
  15630. } else {
  15631. type = 'Type1';
  15632. }
  15633. }
  15634. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15635. type = 'CIDFontType0';
  15636. }
  15637. if (subtype === 'OpenType') {
  15638. type = 'OpenType';
  15639. }
  15640. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15641. if (type === 'CIDFontType0') {
  15642. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15643. }
  15644. var data;
  15645. switch (type) {
  15646. case 'MMType1':
  15647. info('MMType1 font (' + name + '), falling back to Type1.');
  15648. /* falls through */
  15649. case 'Type1':
  15650. case 'CIDFontType0':
  15651. this.mimetype = 'font/opentype';
  15652. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15653. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15654. adjustWidths(properties);
  15655. // Wrap the CFF data inside an OTF font file
  15656. data = this.convert(name, cff, properties);
  15657. break;
  15658. case 'OpenType':
  15659. case 'TrueType':
  15660. case 'CIDFontType2':
  15661. this.mimetype = 'font/opentype';
  15662. // Repair the TrueType file. It is can be damaged in the point of
  15663. // view of the sanitizer
  15664. data = this.checkAndRepair(name, file, properties);
  15665. if (this.isOpenType) {
  15666. type = 'OpenType';
  15667. }
  15668. break;
  15669. default:
  15670. error('Font ' + type + ' is not supported');
  15671. break;
  15672. }
  15673. this.data = data;
  15674. this.fontType = getFontType(type, subtype);
  15675. // Transfer some properties again that could change during font conversion
  15676. this.fontMatrix = properties.fontMatrix;
  15677. this.widths = properties.widths;
  15678. this.defaultWidth = properties.defaultWidth;
  15679. this.encoding = properties.baseEncoding;
  15680. this.seacMap = properties.seacMap;
  15681. this.loading = true;
  15682. }
  15683. Font.getFontID = (function () {
  15684. var ID = 1;
  15685. return function Font_getFontID() {
  15686. return String(ID++);
  15687. };
  15688. })();
  15689. function int16(b0, b1) {
  15690. return (b0 << 8) + b1;
  15691. }
  15692. function int32(b0, b1, b2, b3) {
  15693. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15694. }
  15695. function string16(value) {
  15696. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15697. }
  15698. function safeString16(value) {
  15699. // clamp value to the 16-bit int range
  15700. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15701. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15702. }
  15703. function isTrueTypeFile(file) {
  15704. var header = file.peekBytes(4);
  15705. return readUint32(header, 0) === 0x00010000;
  15706. }
  15707. function isType1File(file) {
  15708. var header = file.peekBytes(2);
  15709. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15710. if (header[0] === 0x25 && header[1] === 0x21) {
  15711. return true;
  15712. }
  15713. // ... obviously some fonts violate that part of the specification,
  15714. // please refer to the comment in |Type1Font| below.
  15715. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15716. return true;
  15717. }
  15718. return false;
  15719. }
  15720. /**
  15721. * Helper function for |adjustMapping|.
  15722. * @return {boolean}
  15723. */
  15724. function isProblematicUnicodeLocation(code) {
  15725. // Using binary search to find a range start.
  15726. var i = 0, j = ProblematicCharRanges.length - 1;
  15727. while (i < j) {
  15728. var c = (i + j + 1) >> 1;
  15729. if (code < ProblematicCharRanges[c]) {
  15730. j = c - 1;
  15731. } else {
  15732. i = c;
  15733. }
  15734. }
  15735. // Even index means code in problematic range.
  15736. return !(i & 1);
  15737. }
  15738. /**
  15739. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15740. * with their unicode value. It also moves char codes that are in known
  15741. * problematic locations.
  15742. * @return {Object} Two properties:
  15743. * 'toFontChar' - maps original char codes(the value that will be read
  15744. * from commands such as show text) to the char codes that will be used in the
  15745. * font that we build
  15746. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15747. */
  15748. function adjustMapping(charCodeToGlyphId, properties) {
  15749. var toUnicode = properties.toUnicode;
  15750. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15751. var isIdentityUnicode =
  15752. properties.toUnicode instanceof IdentityToUnicodeMap;
  15753. var newMap = Object.create(null);
  15754. var toFontChar = [];
  15755. var usedFontCharCodes = [];
  15756. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15757. for (var originalCharCode in charCodeToGlyphId) {
  15758. originalCharCode |= 0;
  15759. var glyphId = charCodeToGlyphId[originalCharCode];
  15760. var fontCharCode = originalCharCode;
  15761. // First try to map the value to a unicode position if a non identity map
  15762. // was created.
  15763. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15764. var unicode = toUnicode.get(fontCharCode);
  15765. // TODO: Try to map ligatures to the correct spot.
  15766. if (unicode.length === 1) {
  15767. fontCharCode = unicode.charCodeAt(0);
  15768. }
  15769. }
  15770. // Try to move control characters, special characters and already mapped
  15771. // characters to the private use area since they will not be drawn by
  15772. // canvas if left in their current position. Also, move characters if the
  15773. // font was symbolic and there is only an identity unicode map since the
  15774. // characters probably aren't in the correct position (fixes an issue
  15775. // with firefox and thuluthfont).
  15776. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15777. isProblematicUnicodeLocation(fontCharCode) ||
  15778. (isSymbolic && isIdentityUnicode)) &&
  15779. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15780. // Loop to try and find a free spot in the private use area.
  15781. do {
  15782. fontCharCode = nextAvailableFontCharCode++;
  15783. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15784. fontCharCode = 0xF020;
  15785. nextAvailableFontCharCode = fontCharCode + 1;
  15786. }
  15787. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15788. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15789. }
  15790. newMap[fontCharCode] = glyphId;
  15791. toFontChar[originalCharCode] = fontCharCode;
  15792. usedFontCharCodes[fontCharCode] = true;
  15793. }
  15794. return {
  15795. toFontChar: toFontChar,
  15796. charCodeToGlyphId: newMap,
  15797. nextAvailableFontCharCode: nextAvailableFontCharCode
  15798. };
  15799. }
  15800. function getRanges(glyphs) {
  15801. // Array.sort() sorts by characters, not numerically, so convert to an
  15802. // array of characters.
  15803. var codes = [];
  15804. for (var charCode in glyphs) {
  15805. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15806. }
  15807. codes.sort(function fontGetRangesSort(a, b) {
  15808. return a.fontCharCode - b.fontCharCode;
  15809. });
  15810. // Split the sorted codes into ranges.
  15811. var ranges = [];
  15812. var length = codes.length;
  15813. for (var n = 0; n < length; ) {
  15814. var start = codes[n].fontCharCode;
  15815. var codeIndices = [codes[n].glyphId];
  15816. ++n;
  15817. var end = start;
  15818. while (n < length && end + 1 === codes[n].fontCharCode) {
  15819. codeIndices.push(codes[n].glyphId);
  15820. ++end;
  15821. ++n;
  15822. if (end === 0xFFFF) {
  15823. break;
  15824. }
  15825. }
  15826. ranges.push([start, end, codeIndices]);
  15827. }
  15828. return ranges;
  15829. }
  15830. function createCmapTable(glyphs) {
  15831. var ranges = getRanges(glyphs);
  15832. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15833. var cmap = '\x00\x00' + // version
  15834. string16(numTables) + // numTables
  15835. '\x00\x03' + // platformID
  15836. '\x00\x01' + // encodingID
  15837. string32(4 + numTables * 8); // start of the table record
  15838. var i, ii, j, jj;
  15839. for (i = ranges.length - 1; i >= 0; --i) {
  15840. if (ranges[i][0] <= 0xFFFF) { break; }
  15841. }
  15842. var bmpLength = i + 1;
  15843. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15844. ranges[i][1] = 0xFFFE;
  15845. }
  15846. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15847. var segCount = bmpLength + trailingRangesCount;
  15848. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15849. // Fill up the 4 parallel arrays describing the segments.
  15850. var startCount = '';
  15851. var endCount = '';
  15852. var idDeltas = '';
  15853. var idRangeOffsets = '';
  15854. var glyphsIds = '';
  15855. var bias = 0;
  15856. var range, start, end, codes;
  15857. for (i = 0, ii = bmpLength; i < ii; i++) {
  15858. range = ranges[i];
  15859. start = range[0];
  15860. end = range[1];
  15861. startCount += string16(start);
  15862. endCount += string16(end);
  15863. codes = range[2];
  15864. var contiguous = true;
  15865. for (j = 1, jj = codes.length; j < jj; ++j) {
  15866. if (codes[j] !== codes[j - 1] + 1) {
  15867. contiguous = false;
  15868. break;
  15869. }
  15870. }
  15871. if (!contiguous) {
  15872. var offset = (segCount - i) * 2 + bias * 2;
  15873. bias += (end - start + 1);
  15874. idDeltas += string16(0);
  15875. idRangeOffsets += string16(offset);
  15876. for (j = 0, jj = codes.length; j < jj; ++j) {
  15877. glyphsIds += string16(codes[j]);
  15878. }
  15879. } else {
  15880. var startCode = codes[0];
  15881. idDeltas += string16((startCode - start) & 0xFFFF);
  15882. idRangeOffsets += string16(0);
  15883. }
  15884. }
  15885. if (trailingRangesCount > 0) {
  15886. endCount += '\xFF\xFF';
  15887. startCount += '\xFF\xFF';
  15888. idDeltas += '\x00\x01';
  15889. idRangeOffsets += '\x00\x00';
  15890. }
  15891. var format314 = '\x00\x00' + // language
  15892. string16(2 * segCount) +
  15893. string16(searchParams.range) +
  15894. string16(searchParams.entry) +
  15895. string16(searchParams.rangeShift) +
  15896. endCount + '\x00\x00' + startCount +
  15897. idDeltas + idRangeOffsets + glyphsIds;
  15898. var format31012 = '';
  15899. var header31012 = '';
  15900. if (numTables > 1) {
  15901. cmap += '\x00\x03' + // platformID
  15902. '\x00\x0A' + // encodingID
  15903. string32(4 + numTables * 8 +
  15904. 4 + format314.length); // start of the table record
  15905. format31012 = '';
  15906. for (i = 0, ii = ranges.length; i < ii; i++) {
  15907. range = ranges[i];
  15908. start = range[0];
  15909. codes = range[2];
  15910. var code = codes[0];
  15911. for (j = 1, jj = codes.length; j < jj; ++j) {
  15912. if (codes[j] !== codes[j - 1] + 1) {
  15913. end = range[0] + j - 1;
  15914. format31012 += string32(start) + // startCharCode
  15915. string32(end) + // endCharCode
  15916. string32(code); // startGlyphID
  15917. start = end + 1;
  15918. code = codes[j];
  15919. }
  15920. }
  15921. format31012 += string32(start) + // startCharCode
  15922. string32(range[1]) + // endCharCode
  15923. string32(code); // startGlyphID
  15924. }
  15925. header31012 = '\x00\x0C' + // format
  15926. '\x00\x00' + // reserved
  15927. string32(format31012.length + 16) + // length
  15928. '\x00\x00\x00\x00' + // language
  15929. string32(format31012.length / 12); // nGroups
  15930. }
  15931. return cmap + '\x00\x04' + // format
  15932. string16(format314.length + 4) + // length
  15933. format314 + header31012 + format31012;
  15934. }
  15935. function validateOS2Table(os2) {
  15936. var stream = new Stream(os2.data);
  15937. var version = stream.getUint16();
  15938. // TODO verify all OS/2 tables fields, but currently we validate only those
  15939. // that give us issues
  15940. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15941. var selection = stream.getUint16();
  15942. if (version < 4 && (selection & 0x0300)) {
  15943. return false;
  15944. }
  15945. var firstChar = stream.getUint16();
  15946. var lastChar = stream.getUint16();
  15947. if (firstChar > lastChar) {
  15948. return false;
  15949. }
  15950. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15951. var usWinAscent = stream.getUint16();
  15952. if (usWinAscent === 0) { // makes font unreadable by windows
  15953. return false;
  15954. }
  15955. // OS/2 appears to be valid, resetting some fields
  15956. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15957. return true;
  15958. }
  15959. function createOS2Table(properties, charstrings, override) {
  15960. override = override || {
  15961. unitsPerEm: 0,
  15962. yMax: 0,
  15963. yMin: 0,
  15964. ascent: 0,
  15965. descent: 0
  15966. };
  15967. var ulUnicodeRange1 = 0;
  15968. var ulUnicodeRange2 = 0;
  15969. var ulUnicodeRange3 = 0;
  15970. var ulUnicodeRange4 = 0;
  15971. var firstCharIndex = null;
  15972. var lastCharIndex = 0;
  15973. if (charstrings) {
  15974. for (var code in charstrings) {
  15975. code |= 0;
  15976. if (firstCharIndex > code || !firstCharIndex) {
  15977. firstCharIndex = code;
  15978. }
  15979. if (lastCharIndex < code) {
  15980. lastCharIndex = code;
  15981. }
  15982. var position = getUnicodeRangeFor(code);
  15983. if (position < 32) {
  15984. ulUnicodeRange1 |= 1 << position;
  15985. } else if (position < 64) {
  15986. ulUnicodeRange2 |= 1 << position - 32;
  15987. } else if (position < 96) {
  15988. ulUnicodeRange3 |= 1 << position - 64;
  15989. } else if (position < 123) {
  15990. ulUnicodeRange4 |= 1 << position - 96;
  15991. } else {
  15992. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15993. }
  15994. }
  15995. } else {
  15996. // TODO
  15997. firstCharIndex = 0;
  15998. lastCharIndex = 255;
  15999. }
  16000. var bbox = properties.bbox || [0, 0, 0, 0];
  16001. var unitsPerEm = (override.unitsPerEm ||
  16002. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  16003. // if the font units differ to the PDF glyph space units
  16004. // then scale up the values
  16005. var scale = (properties.ascentScaled ? 1.0 :
  16006. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  16007. var typoAscent = (override.ascent ||
  16008. Math.round(scale * (properties.ascent || bbox[3])));
  16009. var typoDescent = (override.descent ||
  16010. Math.round(scale * (properties.descent || bbox[1])));
  16011. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  16012. typoDescent = -typoDescent; // fixing incorrect descent
  16013. }
  16014. var winAscent = override.yMax || typoAscent;
  16015. var winDescent = -override.yMin || -typoDescent;
  16016. return '\x00\x03' + // version
  16017. '\x02\x24' + // xAvgCharWidth
  16018. '\x01\xF4' + // usWeightClass
  16019. '\x00\x05' + // usWidthClass
  16020. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  16021. '\x02\x8A' + // ySubscriptXSize
  16022. '\x02\xBB' + // ySubscriptYSize
  16023. '\x00\x00' + // ySubscriptXOffset
  16024. '\x00\x8C' + // ySubscriptYOffset
  16025. '\x02\x8A' + // ySuperScriptXSize
  16026. '\x02\xBB' + // ySuperScriptYSize
  16027. '\x00\x00' + // ySuperScriptXOffset
  16028. '\x01\xDF' + // ySuperScriptYOffset
  16029. '\x00\x31' + // yStrikeOutSize
  16030. '\x01\x02' + // yStrikeOutPosition
  16031. '\x00\x00' + // sFamilyClass
  16032. '\x00\x00\x06' +
  16033. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  16034. '\x00\x00\x00\x00\x00\x00' + // Panose
  16035. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  16036. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  16037. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  16038. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  16039. '\x2A\x32\x31\x2A' + // achVendID
  16040. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  16041. string16(firstCharIndex ||
  16042. properties.firstChar) + // usFirstCharIndex
  16043. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  16044. string16(typoAscent) + // sTypoAscender
  16045. string16(typoDescent) + // sTypoDescender
  16046. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  16047. string16(winAscent) + // usWinAscent
  16048. string16(winDescent) + // usWinDescent
  16049. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  16050. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  16051. string16(properties.xHeight) + // sxHeight
  16052. string16(properties.capHeight) + // sCapHeight
  16053. string16(0) + // usDefaultChar
  16054. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  16055. '\x00\x03'; // usMaxContext
  16056. }
  16057. function createPostTable(properties) {
  16058. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  16059. return ('\x00\x03\x00\x00' + // Version number
  16060. string32(angle) + // italicAngle
  16061. '\x00\x00' + // underlinePosition
  16062. '\x00\x00' + // underlineThickness
  16063. string32(properties.fixedPitch) + // isFixedPitch
  16064. '\x00\x00\x00\x00' + // minMemType42
  16065. '\x00\x00\x00\x00' + // maxMemType42
  16066. '\x00\x00\x00\x00' + // minMemType1
  16067. '\x00\x00\x00\x00'); // maxMemType1
  16068. }
  16069. function createNameTable(name, proto) {
  16070. if (!proto) {
  16071. proto = [[], []]; // no strings and unicode strings
  16072. }
  16073. var strings = [
  16074. proto[0][0] || 'Original licence', // 0.Copyright
  16075. proto[0][1] || name, // 1.Font family
  16076. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  16077. proto[0][3] || 'uniqueID', // 3.Unique ID
  16078. proto[0][4] || name, // 4.Full font name
  16079. proto[0][5] || 'Version 0.11', // 5.Version
  16080. proto[0][6] || '', // 6.Postscript name
  16081. proto[0][7] || 'Unknown', // 7.Trademark
  16082. proto[0][8] || 'Unknown', // 8.Manufacturer
  16083. proto[0][9] || 'Unknown' // 9.Designer
  16084. ];
  16085. // Mac want 1-byte per character strings while Windows want
  16086. // 2-bytes per character, so duplicate the names table
  16087. var stringsUnicode = [];
  16088. var i, ii, j, jj, str;
  16089. for (i = 0, ii = strings.length; i < ii; i++) {
  16090. str = proto[1][i] || strings[i];
  16091. var strBufUnicode = [];
  16092. for (j = 0, jj = str.length; j < jj; j++) {
  16093. strBufUnicode.push(string16(str.charCodeAt(j)));
  16094. }
  16095. stringsUnicode.push(strBufUnicode.join(''));
  16096. }
  16097. var names = [strings, stringsUnicode];
  16098. var platforms = ['\x00\x01', '\x00\x03'];
  16099. var encodings = ['\x00\x00', '\x00\x01'];
  16100. var languages = ['\x00\x00', '\x04\x09'];
  16101. var namesRecordCount = strings.length * platforms.length;
  16102. var nameTable =
  16103. '\x00\x00' + // format
  16104. string16(namesRecordCount) + // Number of names Record
  16105. string16(namesRecordCount * 12 + 6); // Storage
  16106. // Build the name records field
  16107. var strOffset = 0;
  16108. for (i = 0, ii = platforms.length; i < ii; i++) {
  16109. var strs = names[i];
  16110. for (j = 0, jj = strs.length; j < jj; j++) {
  16111. str = strs[j];
  16112. var nameRecord =
  16113. platforms[i] + // platform ID
  16114. encodings[i] + // encoding ID
  16115. languages[i] + // language ID
  16116. string16(j) + // name ID
  16117. string16(str.length) +
  16118. string16(strOffset);
  16119. nameTable += nameRecord;
  16120. strOffset += str.length;
  16121. }
  16122. }
  16123. nameTable += strings.join('') + stringsUnicode.join('');
  16124. return nameTable;
  16125. }
  16126. Font.prototype = {
  16127. name: null,
  16128. font: null,
  16129. mimetype: null,
  16130. encoding: null,
  16131. get renderer() {
  16132. var renderer = FontRendererFactory.create(this);
  16133. return shadow(this, 'renderer', renderer);
  16134. },
  16135. exportData: function Font_exportData() {
  16136. var data = {};
  16137. for (var i in this) {
  16138. if (this.hasOwnProperty(i)) {
  16139. data[i] = this[i];
  16140. }
  16141. }
  16142. return data;
  16143. },
  16144. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  16145. function readTableEntry(file) {
  16146. var tag = bytesToString(file.getBytes(4));
  16147. var checksum = file.getInt32();
  16148. var offset = file.getInt32() >>> 0;
  16149. var length = file.getInt32() >>> 0;
  16150. // Read the table associated data
  16151. var previousPosition = file.pos;
  16152. file.pos = file.start ? file.start : 0;
  16153. file.skip(offset);
  16154. var data = file.getBytes(length);
  16155. file.pos = previousPosition;
  16156. if (tag === 'head') {
  16157. // clearing checksum adjustment
  16158. data[8] = data[9] = data[10] = data[11] = 0;
  16159. data[17] |= 0x20; //Set font optimized for cleartype flag
  16160. }
  16161. return {
  16162. tag: tag,
  16163. checksum: checksum,
  16164. length: length,
  16165. offset: offset,
  16166. data: data
  16167. };
  16168. }
  16169. function readOpenTypeHeader(ttf) {
  16170. return {
  16171. version: bytesToString(ttf.getBytes(4)),
  16172. numTables: ttf.getUint16(),
  16173. searchRange: ttf.getUint16(),
  16174. entrySelector: ttf.getUint16(),
  16175. rangeShift: ttf.getUint16()
  16176. };
  16177. }
  16178. /**
  16179. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  16180. * PDF spec
  16181. */
  16182. function readCmapTable(cmap, font, isSymbolicFont) {
  16183. var segment;
  16184. var start = (font.start ? font.start : 0) + cmap.offset;
  16185. font.pos = start;
  16186. var version = font.getUint16();
  16187. var numTables = font.getUint16();
  16188. var potentialTable;
  16189. var canBreak = false;
  16190. // There's an order of preference in terms of which cmap subtable to
  16191. // use:
  16192. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  16193. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  16194. // The following takes advantage of the fact that the tables are sorted
  16195. // to work.
  16196. for (var i = 0; i < numTables; i++) {
  16197. var platformId = font.getUint16();
  16198. var encodingId = font.getUint16();
  16199. var offset = font.getInt32() >>> 0;
  16200. var useTable = false;
  16201. if (platformId === 0 && encodingId === 0) {
  16202. useTable = true;
  16203. // Continue the loop since there still may be a higher priority
  16204. // table.
  16205. } else if (platformId === 1 && encodingId === 0) {
  16206. useTable = true;
  16207. // Continue the loop since there still may be a higher priority
  16208. // table.
  16209. } else if (platformId === 3 && encodingId === 1 &&
  16210. (!isSymbolicFont || !potentialTable)) {
  16211. useTable = true;
  16212. if (!isSymbolicFont) {
  16213. canBreak = true;
  16214. }
  16215. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  16216. useTable = true;
  16217. canBreak = true;
  16218. }
  16219. if (useTable) {
  16220. potentialTable = {
  16221. platformId: platformId,
  16222. encodingId: encodingId,
  16223. offset: offset
  16224. };
  16225. }
  16226. if (canBreak) {
  16227. break;
  16228. }
  16229. }
  16230. if (potentialTable) {
  16231. font.pos = start + potentialTable.offset;
  16232. }
  16233. if (!potentialTable || font.peekByte() === -1) {
  16234. warn('Could not find a preferred cmap table.');
  16235. return {
  16236. platformId: -1,
  16237. encodingId: -1,
  16238. mappings: [],
  16239. hasShortCmap: false
  16240. };
  16241. }
  16242. var format = font.getUint16();
  16243. var length = font.getUint16();
  16244. var language = font.getUint16();
  16245. var hasShortCmap = false;
  16246. var mappings = [];
  16247. var j, glyphId;
  16248. // TODO(mack): refactor this cmap subtable reading logic out
  16249. if (format === 0) {
  16250. for (j = 0; j < 256; j++) {
  16251. var index = font.getByte();
  16252. if (!index) {
  16253. continue;
  16254. }
  16255. mappings.push({
  16256. charCode: j,
  16257. glyphId: index
  16258. });
  16259. }
  16260. hasShortCmap = true;
  16261. } else if (format === 4) {
  16262. // re-creating the table in format 4 since the encoding
  16263. // might be changed
  16264. var segCount = (font.getUint16() >> 1);
  16265. font.getBytes(6); // skipping range fields
  16266. var segIndex, segments = [];
  16267. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16268. segments.push({ end: font.getUint16() });
  16269. }
  16270. font.getUint16();
  16271. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16272. segments[segIndex].start = font.getUint16();
  16273. }
  16274. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16275. segments[segIndex].delta = font.getUint16();
  16276. }
  16277. var offsetsCount = 0;
  16278. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16279. segment = segments[segIndex];
  16280. var rangeOffset = font.getUint16();
  16281. if (!rangeOffset) {
  16282. segment.offsetIndex = -1;
  16283. continue;
  16284. }
  16285. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16286. segment.offsetIndex = offsetIndex;
  16287. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16288. segment.end - segment.start + 1);
  16289. }
  16290. var offsets = [];
  16291. for (j = 0; j < offsetsCount; j++) {
  16292. offsets.push(font.getUint16());
  16293. }
  16294. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16295. segment = segments[segIndex];
  16296. start = segment.start;
  16297. var end = segment.end;
  16298. var delta = segment.delta;
  16299. offsetIndex = segment.offsetIndex;
  16300. for (j = start; j <= end; j++) {
  16301. if (j === 0xFFFF) {
  16302. continue;
  16303. }
  16304. glyphId = (offsetIndex < 0 ?
  16305. j : offsets[offsetIndex + j - start]);
  16306. glyphId = (glyphId + delta) & 0xFFFF;
  16307. if (glyphId === 0) {
  16308. continue;
  16309. }
  16310. mappings.push({
  16311. charCode: j,
  16312. glyphId: glyphId
  16313. });
  16314. }
  16315. }
  16316. } else if (format === 6) {
  16317. // Format 6 is a 2-bytes dense mapping, which means the font data
  16318. // lives glue together even if they are pretty far in the unicode
  16319. // table. (This looks weird, so I can have missed something), this
  16320. // works on Linux but seems to fails on Mac so let's rewrite the
  16321. // cmap table to a 3-1-4 style
  16322. var firstCode = font.getUint16();
  16323. var entryCount = font.getUint16();
  16324. for (j = 0; j < entryCount; j++) {
  16325. glyphId = font.getUint16();
  16326. var charCode = firstCode + j;
  16327. mappings.push({
  16328. charCode: charCode,
  16329. glyphId: glyphId
  16330. });
  16331. }
  16332. } else {
  16333. error('cmap table has unsupported format: ' + format);
  16334. }
  16335. // removing duplicate entries
  16336. mappings.sort(function (a, b) {
  16337. return a.charCode - b.charCode;
  16338. });
  16339. for (i = 1; i < mappings.length; i++) {
  16340. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16341. mappings.splice(i, 1);
  16342. i--;
  16343. }
  16344. }
  16345. return {
  16346. platformId: potentialTable.platformId,
  16347. encodingId: potentialTable.encodingId,
  16348. mappings: mappings,
  16349. hasShortCmap: hasShortCmap
  16350. };
  16351. }
  16352. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16353. if (!header) {
  16354. if (metrics) {
  16355. metrics.data = null;
  16356. }
  16357. return;
  16358. }
  16359. font.pos = (font.start ? font.start : 0) + header.offset;
  16360. font.pos += header.length - 2;
  16361. var numOfMetrics = font.getUint16();
  16362. if (numOfMetrics > numGlyphs) {
  16363. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16364. 'greater than the numGlyphs (' + numGlyphs + ')');
  16365. // Reduce numOfMetrics if it is greater than numGlyphs
  16366. numOfMetrics = numGlyphs;
  16367. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16368. header.data[35] = numOfMetrics & 0x00ff;
  16369. }
  16370. var numOfSidebearings = numGlyphs - numOfMetrics;
  16371. var numMissing = numOfSidebearings -
  16372. ((metrics.length - numOfMetrics * 4) >> 1);
  16373. if (numMissing > 0) {
  16374. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16375. // Since we need to add two properties for each glyph, this explains
  16376. // the use of |numMissing * 2| when initializing the typed array.
  16377. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16378. entries.set(metrics.data);
  16379. metrics.data = entries;
  16380. }
  16381. }
  16382. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16383. hintsValid) {
  16384. if (sourceEnd - sourceStart <= 12) {
  16385. // glyph with data less than 12 is invalid one
  16386. return 0;
  16387. }
  16388. var glyf = source.subarray(sourceStart, sourceEnd);
  16389. var contoursCount = (glyf[0] << 8) | glyf[1];
  16390. if (contoursCount & 0x8000) {
  16391. // complex glyph, writing as is
  16392. dest.set(glyf, destStart);
  16393. return glyf.length;
  16394. }
  16395. var i, j = 10, flagsCount = 0;
  16396. for (i = 0; i < contoursCount; i++) {
  16397. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16398. flagsCount = endPoint + 1;
  16399. j += 2;
  16400. }
  16401. // skipping instructions
  16402. var instructionsStart = j;
  16403. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16404. j += 2 + instructionsLength;
  16405. var instructionsEnd = j;
  16406. // validating flags
  16407. var coordinatesLength = 0;
  16408. for (i = 0; i < flagsCount; i++) {
  16409. var flag = glyf[j++];
  16410. if (flag & 0xC0) {
  16411. // reserved flags must be zero, cleaning up
  16412. glyf[j - 1] = flag & 0x3F;
  16413. }
  16414. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16415. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16416. coordinatesLength += xyLength;
  16417. if (flag & 8) {
  16418. var repeat = glyf[j++];
  16419. i += repeat;
  16420. coordinatesLength += repeat * xyLength;
  16421. }
  16422. }
  16423. // glyph without coordinates will be rejected
  16424. if (coordinatesLength === 0) {
  16425. return 0;
  16426. }
  16427. var glyphDataLength = j + coordinatesLength;
  16428. if (glyphDataLength > glyf.length) {
  16429. // not enough data for coordinates
  16430. return 0;
  16431. }
  16432. if (!hintsValid && instructionsLength > 0) {
  16433. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16434. dest.set([0, 0], destStart + instructionsStart);
  16435. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16436. destStart + instructionsStart + 2);
  16437. glyphDataLength -= instructionsLength;
  16438. if (glyf.length - glyphDataLength > 3) {
  16439. glyphDataLength = (glyphDataLength + 3) & ~3;
  16440. }
  16441. return glyphDataLength;
  16442. }
  16443. if (glyf.length - glyphDataLength > 3) {
  16444. // truncating and aligning to 4 bytes the long glyph data
  16445. glyphDataLength = (glyphDataLength + 3) & ~3;
  16446. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16447. return glyphDataLength;
  16448. }
  16449. // glyph data is fine
  16450. dest.set(glyf, destStart);
  16451. return glyf.length;
  16452. }
  16453. function sanitizeHead(head, numGlyphs, locaLength) {
  16454. var data = head.data;
  16455. // Validate version:
  16456. // Should always be 0x00010000
  16457. var version = int32(data[0], data[1], data[2], data[3]);
  16458. if (version >> 16 !== 1) {
  16459. info('Attempting to fix invalid version in head table: ' + version);
  16460. data[0] = 0;
  16461. data[1] = 1;
  16462. data[2] = 0;
  16463. data[3] = 0;
  16464. }
  16465. var indexToLocFormat = int16(data[50], data[51]);
  16466. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16467. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16468. indexToLocFormat);
  16469. // The value of indexToLocFormat should be 0 if the loca table
  16470. // consists of short offsets, and should be 1 if the loca table
  16471. // consists of long offsets.
  16472. //
  16473. // The number of entries in the loca table should be numGlyphs + 1.
  16474. //
  16475. // Using this information, we can work backwards to deduce if the
  16476. // size of each offset in the loca table, and thus figure out the
  16477. // appropriate value for indexToLocFormat.
  16478. var numGlyphsPlusOne = numGlyphs + 1;
  16479. if (locaLength === numGlyphsPlusOne << 1) {
  16480. // 0x0000 indicates the loca table consists of short offsets
  16481. data[50] = 0;
  16482. data[51] = 0;
  16483. } else if (locaLength === numGlyphsPlusOne << 2) {
  16484. // 0x0001 indicates the loca table consists of long offsets
  16485. data[50] = 0;
  16486. data[51] = 1;
  16487. } else {
  16488. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16489. }
  16490. }
  16491. }
  16492. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16493. isGlyphLocationsLong, hintsValid,
  16494. dupFirstEntry) {
  16495. var itemSize, itemDecode, itemEncode;
  16496. if (isGlyphLocationsLong) {
  16497. itemSize = 4;
  16498. itemDecode = function fontItemDecodeLong(data, offset) {
  16499. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16500. (data[offset + 2] << 8) | data[offset + 3];
  16501. };
  16502. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16503. data[offset] = (value >>> 24) & 0xFF;
  16504. data[offset + 1] = (value >> 16) & 0xFF;
  16505. data[offset + 2] = (value >> 8) & 0xFF;
  16506. data[offset + 3] = value & 0xFF;
  16507. };
  16508. } else {
  16509. itemSize = 2;
  16510. itemDecode = function fontItemDecode(data, offset) {
  16511. return (data[offset] << 9) | (data[offset + 1] << 1);
  16512. };
  16513. itemEncode = function fontItemEncode(data, offset, value) {
  16514. data[offset] = (value >> 9) & 0xFF;
  16515. data[offset + 1] = (value >> 1) & 0xFF;
  16516. };
  16517. }
  16518. var locaData = loca.data;
  16519. var locaDataSize = itemSize * (1 + numGlyphs);
  16520. // is loca.data too short or long?
  16521. if (locaData.length !== locaDataSize) {
  16522. locaData = new Uint8Array(locaDataSize);
  16523. locaData.set(loca.data.subarray(0, locaDataSize));
  16524. loca.data = locaData;
  16525. }
  16526. // removing the invalid glyphs
  16527. var oldGlyfData = glyf.data;
  16528. var oldGlyfDataLength = oldGlyfData.length;
  16529. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16530. var startOffset = itemDecode(locaData, 0);
  16531. var writeOffset = 0;
  16532. var missingGlyphData = {};
  16533. itemEncode(locaData, 0, writeOffset);
  16534. var i, j;
  16535. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16536. var endOffset = itemDecode(locaData, j);
  16537. if (endOffset > oldGlyfDataLength &&
  16538. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16539. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16540. // the glyf table size, which makes last glyph out of range.
  16541. endOffset = oldGlyfDataLength;
  16542. }
  16543. if (endOffset > oldGlyfDataLength) {
  16544. // glyph end offset points outside glyf data, rejecting the glyph
  16545. itemEncode(locaData, j, writeOffset);
  16546. startOffset = endOffset;
  16547. continue;
  16548. }
  16549. if (startOffset === endOffset) {
  16550. missingGlyphData[i] = true;
  16551. }
  16552. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16553. newGlyfData, writeOffset, hintsValid);
  16554. writeOffset += newLength;
  16555. itemEncode(locaData, j, writeOffset);
  16556. startOffset = endOffset;
  16557. }
  16558. if (writeOffset === 0) {
  16559. // glyf table cannot be empty -- redoing the glyf and loca tables
  16560. // to have single glyph with one point
  16561. var simpleGlyph = new Uint8Array(
  16562. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16563. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16564. itemEncode(locaData, j, simpleGlyph.length);
  16565. }
  16566. glyf.data = simpleGlyph;
  16567. return missingGlyphData;
  16568. }
  16569. if (dupFirstEntry) {
  16570. var firstEntryLength = itemDecode(locaData, itemSize);
  16571. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16572. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16573. } else {
  16574. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16575. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16576. }
  16577. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16578. itemEncode(loca.data, locaData.length - itemSize,
  16579. writeOffset + firstEntryLength);
  16580. } else {
  16581. glyf.data = newGlyfData.subarray(0, writeOffset);
  16582. }
  16583. return missingGlyphData;
  16584. }
  16585. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16586. var start = (font.start ? font.start : 0) + post.offset;
  16587. font.pos = start;
  16588. var length = post.length, end = start + length;
  16589. var version = font.getInt32();
  16590. // skip rest to the tables
  16591. font.getBytes(28);
  16592. var glyphNames;
  16593. var valid = true;
  16594. var i;
  16595. switch (version) {
  16596. case 0x00010000:
  16597. glyphNames = MacStandardGlyphOrdering;
  16598. break;
  16599. case 0x00020000:
  16600. var numGlyphs = font.getUint16();
  16601. if (numGlyphs !== maxpNumGlyphs) {
  16602. valid = false;
  16603. break;
  16604. }
  16605. var glyphNameIndexes = [];
  16606. for (i = 0; i < numGlyphs; ++i) {
  16607. var index = font.getUint16();
  16608. if (index >= 32768) {
  16609. valid = false;
  16610. break;
  16611. }
  16612. glyphNameIndexes.push(index);
  16613. }
  16614. if (!valid) {
  16615. break;
  16616. }
  16617. var customNames = [];
  16618. var strBuf = [];
  16619. while (font.pos < end) {
  16620. var stringLength = font.getByte();
  16621. strBuf.length = stringLength;
  16622. for (i = 0; i < stringLength; ++i) {
  16623. strBuf[i] = String.fromCharCode(font.getByte());
  16624. }
  16625. customNames.push(strBuf.join(''));
  16626. }
  16627. glyphNames = [];
  16628. for (i = 0; i < numGlyphs; ++i) {
  16629. var j = glyphNameIndexes[i];
  16630. if (j < 258) {
  16631. glyphNames.push(MacStandardGlyphOrdering[j]);
  16632. continue;
  16633. }
  16634. glyphNames.push(customNames[j - 258]);
  16635. }
  16636. break;
  16637. case 0x00030000:
  16638. break;
  16639. default:
  16640. warn('Unknown/unsupported post table version ' + version);
  16641. valid = false;
  16642. if (properties.defaultEncoding) {
  16643. glyphNames = properties.defaultEncoding;
  16644. }
  16645. break;
  16646. }
  16647. properties.glyphNames = glyphNames;
  16648. return valid;
  16649. }
  16650. function readNameTable(nameTable) {
  16651. var start = (font.start ? font.start : 0) + nameTable.offset;
  16652. font.pos = start;
  16653. var names = [[], []];
  16654. var length = nameTable.length, end = start + length;
  16655. var format = font.getUint16();
  16656. var FORMAT_0_HEADER_LENGTH = 6;
  16657. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16658. // unsupported name table format or table "too" small
  16659. return names;
  16660. }
  16661. var numRecords = font.getUint16();
  16662. var stringsStart = font.getUint16();
  16663. var records = [];
  16664. var NAME_RECORD_LENGTH = 12;
  16665. var i, ii;
  16666. for (i = 0; i < numRecords &&
  16667. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16668. var r = {
  16669. platform: font.getUint16(),
  16670. encoding: font.getUint16(),
  16671. language: font.getUint16(),
  16672. name: font.getUint16(),
  16673. length: font.getUint16(),
  16674. offset: font.getUint16()
  16675. };
  16676. // using only Macintosh and Windows platform/encoding names
  16677. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16678. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16679. records.push(r);
  16680. }
  16681. }
  16682. for (i = 0, ii = records.length; i < ii; i++) {
  16683. var record = records[i];
  16684. var pos = start + stringsStart + record.offset;
  16685. if (pos + record.length > end) {
  16686. continue; // outside of name table, ignoring
  16687. }
  16688. font.pos = pos;
  16689. var nameIndex = record.name;
  16690. if (record.encoding) {
  16691. // unicode
  16692. var str = '';
  16693. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16694. str += String.fromCharCode(font.getUint16());
  16695. }
  16696. names[1][nameIndex] = str;
  16697. } else {
  16698. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16699. }
  16700. }
  16701. return names;
  16702. }
  16703. var TTOpsStackDeltas = [
  16704. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16705. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16706. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16707. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16708. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16709. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16710. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16711. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16712. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16713. // 0xC0-DF == -1 and 0xE0-FF == -2
  16714. function sanitizeTTProgram(table, ttContext) {
  16715. var data = table.data;
  16716. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16717. var stack = [];
  16718. var callstack = [];
  16719. var functionsCalled = [];
  16720. var tooComplexToFollowFunctions =
  16721. ttContext.tooComplexToFollowFunctions;
  16722. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16723. for (var ii = data.length; i < ii;) {
  16724. var op = data[i++];
  16725. // The TrueType instruction set docs can be found at
  16726. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16727. if (op === 0x40) { // NPUSHB - pushes n bytes
  16728. n = data[i++];
  16729. if (inFDEF || inELSE) {
  16730. i += n;
  16731. } else {
  16732. for (j = 0; j < n; j++) {
  16733. stack.push(data[i++]);
  16734. }
  16735. }
  16736. } else if (op === 0x41) { // NPUSHW - pushes n words
  16737. n = data[i++];
  16738. if (inFDEF || inELSE) {
  16739. i += n * 2;
  16740. } else {
  16741. for (j = 0; j < n; j++) {
  16742. b = data[i++];
  16743. stack.push((b << 8) | data[i++]);
  16744. }
  16745. }
  16746. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16747. n = op - 0xB0 + 1;
  16748. if (inFDEF || inELSE) {
  16749. i += n;
  16750. } else {
  16751. for (j = 0; j < n; j++) {
  16752. stack.push(data[i++]);
  16753. }
  16754. }
  16755. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16756. n = op - 0xB8 + 1;
  16757. if (inFDEF || inELSE) {
  16758. i += n * 2;
  16759. } else {
  16760. for (j = 0; j < n; j++) {
  16761. b = data[i++];
  16762. stack.push((b << 8) | data[i++]);
  16763. }
  16764. }
  16765. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16766. if (!inFDEF && !inELSE) {
  16767. // collecting inforamtion about which functions are used
  16768. funcId = stack[stack.length - 1];
  16769. ttContext.functionsUsed[funcId] = true;
  16770. if (funcId in ttContext.functionsStackDeltas) {
  16771. stack.length += ttContext.functionsStackDeltas[funcId];
  16772. } else if (funcId in ttContext.functionsDefined &&
  16773. functionsCalled.indexOf(funcId) < 0) {
  16774. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16775. functionsCalled.push(funcId);
  16776. pc = ttContext.functionsDefined[funcId];
  16777. if (!pc) {
  16778. warn('TT: CALL non-existent function');
  16779. ttContext.hintsValid = false;
  16780. return;
  16781. }
  16782. data = pc.data;
  16783. i = pc.i;
  16784. }
  16785. }
  16786. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16787. if (inFDEF || inELSE) {
  16788. warn('TT: nested FDEFs not allowed');
  16789. tooComplexToFollowFunctions = true;
  16790. }
  16791. inFDEF = true;
  16792. // collecting inforamtion about which functions are defined
  16793. lastDeff = i;
  16794. funcId = stack.pop();
  16795. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16796. } else if (op === 0x2D) { // ENDF - end of function
  16797. if (inFDEF) {
  16798. inFDEF = false;
  16799. lastEndf = i;
  16800. } else {
  16801. pc = callstack.pop();
  16802. if (!pc) {
  16803. warn('TT: ENDF bad stack');
  16804. ttContext.hintsValid = false;
  16805. return;
  16806. }
  16807. funcId = functionsCalled.pop();
  16808. data = pc.data;
  16809. i = pc.i;
  16810. ttContext.functionsStackDeltas[funcId] =
  16811. stack.length - pc.stackTop;
  16812. }
  16813. } else if (op === 0x89) { // IDEF - instruction definition
  16814. if (inFDEF || inELSE) {
  16815. warn('TT: nested IDEFs not allowed');
  16816. tooComplexToFollowFunctions = true;
  16817. }
  16818. inFDEF = true;
  16819. // recording it as a function to track ENDF
  16820. lastDeff = i;
  16821. } else if (op === 0x58) { // IF
  16822. ++ifLevel;
  16823. } else if (op === 0x1B) { // ELSE
  16824. inELSE = ifLevel;
  16825. } else if (op === 0x59) { // EIF
  16826. if (inELSE === ifLevel) {
  16827. inELSE = 0;
  16828. }
  16829. --ifLevel;
  16830. } else if (op === 0x1C) { // JMPR
  16831. if (!inFDEF && !inELSE) {
  16832. var offset = stack[stack.length - 1];
  16833. // only jumping forward to prevent infinite loop
  16834. if (offset > 0) {
  16835. i += offset - 1;
  16836. }
  16837. }
  16838. }
  16839. // Adjusting stack not extactly, but just enough to get function id
  16840. if (!inFDEF && !inELSE) {
  16841. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16842. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16843. if (op >= 0x71 && op <= 0x75) {
  16844. n = stack.pop();
  16845. if (n === n) {
  16846. stackDelta = -n * 2;
  16847. }
  16848. }
  16849. while (stackDelta < 0 && stack.length > 0) {
  16850. stack.pop();
  16851. stackDelta++;
  16852. }
  16853. while (stackDelta > 0) {
  16854. stack.push(NaN); // pushing any number into stack
  16855. stackDelta--;
  16856. }
  16857. }
  16858. }
  16859. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16860. var content = [data];
  16861. if (i > data.length) {
  16862. content.push(new Uint8Array(i - data.length));
  16863. }
  16864. if (lastDeff > lastEndf) {
  16865. warn('TT: complementing a missing function tail');
  16866. // new function definition started, but not finished
  16867. // complete function by [CLEAR, ENDF]
  16868. content.push(new Uint8Array([0x22, 0x2D]));
  16869. }
  16870. foldTTTable(table, content);
  16871. }
  16872. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16873. if (ttContext.tooComplexToFollowFunctions) {
  16874. return;
  16875. }
  16876. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16877. warn('TT: more functions defined than expected');
  16878. ttContext.hintsValid = false;
  16879. return;
  16880. }
  16881. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16882. if (j > maxFunctionDefs) {
  16883. warn('TT: invalid function id: ' + j);
  16884. ttContext.hintsValid = false;
  16885. return;
  16886. }
  16887. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16888. warn('TT: undefined function: ' + j);
  16889. ttContext.hintsValid = false;
  16890. return;
  16891. }
  16892. }
  16893. }
  16894. function foldTTTable(table, content) {
  16895. if (content.length > 1) {
  16896. // concatenating the content items
  16897. var newLength = 0;
  16898. var j, jj;
  16899. for (j = 0, jj = content.length; j < jj; j++) {
  16900. newLength += content[j].length;
  16901. }
  16902. newLength = (newLength + 3) & ~3;
  16903. var result = new Uint8Array(newLength);
  16904. var pos = 0;
  16905. for (j = 0, jj = content.length; j < jj; j++) {
  16906. result.set(content[j], pos);
  16907. pos += content[j].length;
  16908. }
  16909. table.data = result;
  16910. table.length = newLength;
  16911. }
  16912. }
  16913. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16914. var ttContext = {
  16915. functionsDefined: [],
  16916. functionsUsed: [],
  16917. functionsStackDeltas: [],
  16918. tooComplexToFollowFunctions: false,
  16919. hintsValid: true
  16920. };
  16921. if (fpgm) {
  16922. sanitizeTTProgram(fpgm, ttContext);
  16923. }
  16924. if (prep) {
  16925. sanitizeTTProgram(prep, ttContext);
  16926. }
  16927. if (fpgm) {
  16928. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16929. }
  16930. if (cvt && (cvt.length & 1)) {
  16931. var cvtData = new Uint8Array(cvt.length + 1);
  16932. cvtData.set(cvt.data);
  16933. cvt.data = cvtData;
  16934. }
  16935. return ttContext.hintsValid;
  16936. }
  16937. // The following steps modify the original font data, making copy
  16938. font = new Stream(new Uint8Array(font.getBytes()));
  16939. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16940. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16941. var header = readOpenTypeHeader(font);
  16942. var numTables = header.numTables;
  16943. var cff, cffFile;
  16944. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16945. hmtx: null, maxp: null, name: null, post: null };
  16946. var table;
  16947. for (var i = 0; i < numTables; i++) {
  16948. table = readTableEntry(font);
  16949. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16950. continue; // skipping table if it's not a required or optional table
  16951. }
  16952. if (table.length === 0) {
  16953. continue; // skipping empty tables
  16954. }
  16955. tables[table.tag] = table;
  16956. }
  16957. var isTrueType = !tables['CFF '];
  16958. if (!isTrueType) {
  16959. // OpenType font
  16960. if (header.version === 'OTTO' ||
  16961. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16962. // no major tables: throwing everything at CFFFont
  16963. cffFile = new Stream(tables['CFF '].data);
  16964. cff = new CFFFont(cffFile, properties);
  16965. return this.convert(name, cff, properties);
  16966. }
  16967. delete tables.glyf;
  16968. delete tables.loca;
  16969. delete tables.fpgm;
  16970. delete tables.prep;
  16971. delete tables['cvt '];
  16972. this.isOpenType = true;
  16973. } else {
  16974. if (!tables.glyf || !tables.loca) {
  16975. error('Required "glyf" or "loca" tables are not found');
  16976. }
  16977. this.isOpenType = false;
  16978. }
  16979. if (!tables.maxp) {
  16980. error('Required "maxp" table is not found');
  16981. }
  16982. font.pos = (font.start || 0) + tables.maxp.offset;
  16983. var version = font.getInt32();
  16984. var numGlyphs = font.getUint16();
  16985. var maxFunctionDefs = 0;
  16986. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16987. // maxZones can be invalid
  16988. font.pos += 8;
  16989. var maxZones = font.getUint16();
  16990. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16991. tables.maxp.data[14] = 0;
  16992. tables.maxp.data[15] = 2;
  16993. }
  16994. font.pos += 4;
  16995. maxFunctionDefs = font.getUint16();
  16996. }
  16997. var dupFirstEntry = false;
  16998. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16999. properties.toUnicode.get(0) > '\u0000') {
  17000. // oracle's defect (see 3427), duplicating first entry
  17001. dupFirstEntry = true;
  17002. numGlyphs++;
  17003. tables.maxp.data[4] = numGlyphs >> 8;
  17004. tables.maxp.data[5] = numGlyphs & 255;
  17005. }
  17006. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  17007. tables['cvt '], maxFunctionDefs);
  17008. if (!hintsValid) {
  17009. delete tables.fpgm;
  17010. delete tables.prep;
  17011. delete tables['cvt '];
  17012. }
  17013. // Ensure the hmtx table contains the advance width and
  17014. // sidebearings information for numGlyphs in the maxp table
  17015. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  17016. if (!tables.head) {
  17017. error('Required "head" table is not found');
  17018. }
  17019. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  17020. var missingGlyphs = {};
  17021. if (isTrueType) {
  17022. var isGlyphLocationsLong = int16(tables.head.data[50],
  17023. tables.head.data[51]);
  17024. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  17025. numGlyphs, isGlyphLocationsLong,
  17026. hintsValid, dupFirstEntry);
  17027. }
  17028. if (!tables.hhea) {
  17029. error('Required "hhea" table is not found');
  17030. }
  17031. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  17032. // Sometimes it's 0. That needs to be fixed
  17033. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  17034. tables.hhea.data[10] = 0xFF;
  17035. tables.hhea.data[11] = 0xFF;
  17036. }
  17037. // The 'post' table has glyphs names.
  17038. if (tables.post) {
  17039. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  17040. if (!valid) {
  17041. tables.post = null;
  17042. }
  17043. }
  17044. var charCodeToGlyphId = [], charCode;
  17045. var toUnicode = properties.toUnicode, widths = properties.widths;
  17046. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  17047. toUnicode.length === 0x10000);
  17048. // Helper function to try to skip mapping of empty glyphs.
  17049. // Note: In some cases, just relying on the glyph data doesn't work,
  17050. // hence we also use a few heuristics to fix various PDF files.
  17051. function hasGlyph(glyphId, charCode, widthCode) {
  17052. if (!missingGlyphs[glyphId]) {
  17053. return true;
  17054. }
  17055. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  17056. return true;
  17057. }
  17058. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  17059. return true;
  17060. }
  17061. return false;
  17062. }
  17063. if (properties.type === 'CIDFontType2') {
  17064. var cidToGidMap = properties.cidToGidMap || [];
  17065. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  17066. properties.cMap.forEach(function(charCode, cid) {
  17067. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17068. var glyphId = -1;
  17069. if (isCidToGidMapEmpty) {
  17070. glyphId = charCode;
  17071. } else if (cidToGidMap[cid] !== undefined) {
  17072. glyphId = cidToGidMap[cid];
  17073. }
  17074. if (glyphId >= 0 && glyphId < numGlyphs &&
  17075. hasGlyph(glyphId, charCode, cid)) {
  17076. charCodeToGlyphId[charCode] = glyphId;
  17077. }
  17078. });
  17079. if (dupFirstEntry) {
  17080. charCodeToGlyphId[0] = numGlyphs - 1;
  17081. }
  17082. } else {
  17083. // Most of the following logic in this code branch is based on the
  17084. // 9.6.6.4 of the PDF spec.
  17085. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  17086. var cmapPlatformId = cmapTable.platformId;
  17087. var cmapEncodingId = cmapTable.encodingId;
  17088. var cmapMappings = cmapTable.mappings;
  17089. var cmapMappingsLength = cmapMappings.length;
  17090. var hasEncoding = properties.differences.length ||
  17091. !!properties.baseEncodingName;
  17092. // The spec seems to imply that if the font is symbolic the encoding
  17093. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  17094. // where the the font is symbolic and it has an encoding.
  17095. if (hasEncoding &&
  17096. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  17097. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  17098. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  17099. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  17100. // When no preferred cmap table was found and |baseEncodingName| is
  17101. // one of the predefined encodings, we seem to obtain a better
  17102. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  17103. // TODO: Note that this is a hack which should be removed as soon as
  17104. // we have proper support for more exotic cmap tables.
  17105. var baseEncoding = [];
  17106. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  17107. properties.baseEncodingName === 'WinAnsiEncoding') {
  17108. baseEncoding = Encodings[properties.baseEncodingName];
  17109. }
  17110. for (charCode = 0; charCode < 256; charCode++) {
  17111. var glyphName;
  17112. if (this.differences && charCode in this.differences) {
  17113. glyphName = this.differences[charCode];
  17114. } else if (charCode in baseEncoding &&
  17115. baseEncoding[charCode] !== '') {
  17116. glyphName = baseEncoding[charCode];
  17117. } else {
  17118. glyphName = Encodings.StandardEncoding[charCode];
  17119. }
  17120. if (!glyphName) {
  17121. continue;
  17122. }
  17123. var unicodeOrCharCode;
  17124. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  17125. unicodeOrCharCode = GlyphsUnicode[glyphName];
  17126. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  17127. // TODO: the encoding needs to be updated with mac os table.
  17128. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  17129. }
  17130. var found = false;
  17131. for (i = 0; i < cmapMappingsLength; ++i) {
  17132. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  17133. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode, -1)) {
  17134. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17135. found = true;
  17136. break;
  17137. }
  17138. }
  17139. if (!found && properties.glyphNames) {
  17140. // Try to map using the post table.
  17141. var glyphId = properties.glyphNames.indexOf(glyphName);
  17142. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  17143. charCodeToGlyphId[charCode] = glyphId;
  17144. } else {
  17145. charCodeToGlyphId[charCode] = 0; // notdef
  17146. }
  17147. }
  17148. }
  17149. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  17150. // Default Unicode semantics, use the charcodes as is.
  17151. for (i = 0; i < cmapMappingsLength; ++i) {
  17152. charCodeToGlyphId[cmapMappings[i].charCode] =
  17153. cmapMappings[i].glyphId;
  17154. }
  17155. } else {
  17156. // For (3, 0) cmap tables:
  17157. // The charcode key being stored in charCodeToGlyphId is the lower
  17158. // byte of the two-byte charcodes of the cmap table since according to
  17159. // the spec: 'each byte from the string shall be prepended with the
  17160. // high byte of the range [of charcodes in the cmap table], to form
  17161. // a two-byte character, which shall be used to select the
  17162. // associated glyph description from the subtable'.
  17163. //
  17164. // For (1, 0) cmap tables:
  17165. // 'single bytes from the string shall be used to look up the
  17166. // associated glyph descriptions from the subtable'. This means
  17167. // charcodes in the cmap will be single bytes, so no-op since
  17168. // glyph.charCode & 0xFF === glyph.charCode
  17169. for (i = 0; i < cmapMappingsLength; ++i) {
  17170. charCode = cmapMappings[i].charCode & 0xFF;
  17171. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17172. }
  17173. }
  17174. }
  17175. if (charCodeToGlyphId.length === 0) {
  17176. // defines at least one glyph
  17177. charCodeToGlyphId[0] = 0;
  17178. }
  17179. // Converting glyphs and ids into font's cmap table
  17180. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  17181. this.toFontChar = newMapping.toFontChar;
  17182. tables.cmap = {
  17183. tag: 'cmap',
  17184. data: createCmapTable(newMapping.charCodeToGlyphId)
  17185. };
  17186. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  17187. // extract some more font properties from the OpenType head and
  17188. // hhea tables; yMin and descent value are always negative
  17189. var override = {
  17190. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  17191. yMax: int16(tables.head.data[42], tables.head.data[43]),
  17192. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  17193. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  17194. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17195. };
  17196. tables['OS/2'] = {
  17197. tag: 'OS/2',
  17198. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  17199. override)
  17200. };
  17201. }
  17202. // Rewrite the 'post' table if needed
  17203. if (!tables.post) {
  17204. tables.post = {
  17205. tag: 'post',
  17206. data: createPostTable(properties)
  17207. };
  17208. }
  17209. if (!isTrueType) {
  17210. try {
  17211. // Trying to repair CFF file
  17212. cffFile = new Stream(tables['CFF '].data);
  17213. var parser = new CFFParser(cffFile, properties);
  17214. cff = parser.parse();
  17215. var compiler = new CFFCompiler(cff);
  17216. tables['CFF '].data = compiler.compile();
  17217. } catch (e) {
  17218. warn('Failed to compile font ' + properties.loadedName);
  17219. }
  17220. }
  17221. // Re-creating 'name' table
  17222. if (!tables.name) {
  17223. tables.name = {
  17224. tag: 'name',
  17225. data: createNameTable(this.name)
  17226. };
  17227. } else {
  17228. // ... using existing 'name' table as prototype
  17229. var namePrototype = readNameTable(tables.name);
  17230. tables.name.data = createNameTable(name, namePrototype);
  17231. }
  17232. var builder = new OpenTypeFileBuilder(header.version);
  17233. for (var tableTag in tables) {
  17234. builder.addTable(tableTag, tables[tableTag].data);
  17235. }
  17236. return builder.toArray();
  17237. },
  17238. convert: function Font_convert(fontName, font, properties) {
  17239. // TODO: Check the charstring widths to determine this.
  17240. properties.fixedPitch = false;
  17241. var mapping = font.getGlyphMapping(properties);
  17242. var newMapping = adjustMapping(mapping, properties);
  17243. this.toFontChar = newMapping.toFontChar;
  17244. var numGlyphs = font.numGlyphs;
  17245. function getCharCodes(charCodeToGlyphId, glyphId) {
  17246. var charCodes = null;
  17247. for (var charCode in charCodeToGlyphId) {
  17248. if (glyphId === charCodeToGlyphId[charCode]) {
  17249. if (!charCodes) {
  17250. charCodes = [];
  17251. }
  17252. charCodes.push(charCode | 0);
  17253. }
  17254. }
  17255. return charCodes;
  17256. }
  17257. function createCharCode(charCodeToGlyphId, glyphId) {
  17258. for (var charCode in charCodeToGlyphId) {
  17259. if (glyphId === charCodeToGlyphId[charCode]) {
  17260. return charCode | 0;
  17261. }
  17262. }
  17263. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17264. glyphId;
  17265. return newMapping.nextAvailableFontCharCode++;
  17266. }
  17267. var seacs = font.seacs;
  17268. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17269. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17270. var charset = font.getCharset();
  17271. var seacMap = Object.create(null);
  17272. for (var glyphId in seacs) {
  17273. glyphId |= 0;
  17274. var seac = seacs[glyphId];
  17275. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17276. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17277. var baseGlyphId = charset.indexOf(baseGlyphName);
  17278. var accentGlyphId = charset.indexOf(accentGlyphName);
  17279. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17280. continue;
  17281. }
  17282. var accentOffset = {
  17283. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17284. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17285. };
  17286. var charCodes = getCharCodes(mapping, glyphId);
  17287. if (!charCodes) {
  17288. // There's no point in mapping it if the char code was never mapped
  17289. // to begin with.
  17290. continue;
  17291. }
  17292. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17293. var charCode = charCodes[i];
  17294. // Find a fontCharCode that maps to the base and accent glyphs.
  17295. // If one doesn't exists, create it.
  17296. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17297. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17298. baseGlyphId);
  17299. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17300. accentGlyphId);
  17301. seacMap[charCode] = {
  17302. baseFontCharCode: baseFontCharCode,
  17303. accentFontCharCode: accentFontCharCode,
  17304. accentOffset: accentOffset
  17305. };
  17306. }
  17307. }
  17308. properties.seacMap = seacMap;
  17309. }
  17310. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17311. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17312. // PostScript Font Program
  17313. builder.addTable('CFF ', font.data);
  17314. // OS/2 and Windows Specific metrics
  17315. builder.addTable('OS/2', createOS2Table(properties,
  17316. newMapping.charCodeToGlyphId));
  17317. // Character to glyphs mapping
  17318. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17319. // Font header
  17320. builder.addTable('head',
  17321. '\x00\x01\x00\x00' + // Version number
  17322. '\x00\x00\x10\x00' + // fontRevision
  17323. '\x00\x00\x00\x00' + // checksumAdjustement
  17324. '\x5F\x0F\x3C\xF5' + // magicNumber
  17325. '\x00\x00' + // Flags
  17326. safeString16(unitsPerEm) + // unitsPerEM
  17327. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17328. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17329. '\x00\x00' + // xMin
  17330. safeString16(properties.descent) + // yMin
  17331. '\x0F\xFF' + // xMax
  17332. safeString16(properties.ascent) + // yMax
  17333. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17334. '\x00\x11' + // lowestRecPPEM
  17335. '\x00\x00' + // fontDirectionHint
  17336. '\x00\x00' + // indexToLocFormat
  17337. '\x00\x00'); // glyphDataFormat
  17338. // Horizontal header
  17339. builder.addTable('hhea',
  17340. '\x00\x01\x00\x00' + // Version number
  17341. safeString16(properties.ascent) + // Typographic Ascent
  17342. safeString16(properties.descent) + // Typographic Descent
  17343. '\x00\x00' + // Line Gap
  17344. '\xFF\xFF' + // advanceWidthMax
  17345. '\x00\x00' + // minLeftSidebearing
  17346. '\x00\x00' + // minRightSidebearing
  17347. '\x00\x00' + // xMaxExtent
  17348. safeString16(properties.capHeight) + // caretSlopeRise
  17349. safeString16(Math.tan(properties.italicAngle) *
  17350. properties.xHeight) + // caretSlopeRun
  17351. '\x00\x00' + // caretOffset
  17352. '\x00\x00' + // -reserved-
  17353. '\x00\x00' + // -reserved-
  17354. '\x00\x00' + // -reserved-
  17355. '\x00\x00' + // -reserved-
  17356. '\x00\x00' + // metricDataFormat
  17357. string16(numGlyphs)); // Number of HMetrics
  17358. // Horizontal metrics
  17359. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17360. var charstrings = font.charstrings;
  17361. var cffWidths = font.cff ? font.cff.widths : null;
  17362. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17363. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17364. var width = 0;
  17365. if (charstrings) {
  17366. var charstring = charstrings[i - 1];
  17367. width = 'width' in charstring ? charstring.width : 0;
  17368. } else if (cffWidths) {
  17369. width = Math.ceil(cffWidths[i] || 0);
  17370. }
  17371. hmtx += string16(width) + string16(0);
  17372. }
  17373. return hmtx;
  17374. })());
  17375. // Maximum profile
  17376. builder.addTable('maxp',
  17377. '\x00\x00\x50\x00' + // Version number
  17378. string16(numGlyphs)); // Num of glyphs
  17379. // Naming tables
  17380. builder.addTable('name', createNameTable(fontName));
  17381. // PostScript informations
  17382. builder.addTable('post', createPostTable(properties));
  17383. return builder.toArray();
  17384. },
  17385. /**
  17386. * Builds a char code to unicode map based on section 9.10 of the spec.
  17387. * @param {Object} properties Font properties object.
  17388. * @return {Object} A ToUnicodeMap object.
  17389. */
  17390. buildToUnicode: function Font_buildToUnicode(properties) {
  17391. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17392. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17393. return properties.toUnicode;
  17394. }
  17395. // According to the spec if the font is a simple font we should only map
  17396. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17397. // the differences array only contains adobe standard or symbol set names,
  17398. // in pratice it seems better to always try to create a toUnicode
  17399. // map based of the default encoding.
  17400. var toUnicode, charcode;
  17401. if (!properties.composite /* is simple font */) {
  17402. toUnicode = [];
  17403. var encoding = properties.defaultEncoding.slice();
  17404. var baseEncodingName = properties.baseEncodingName;
  17405. // Merge in the differences array.
  17406. var differences = properties.differences;
  17407. for (charcode in differences) {
  17408. encoding[charcode] = differences[charcode];
  17409. }
  17410. for (charcode in encoding) {
  17411. // a) Map the character code to a character name.
  17412. var glyphName = encoding[charcode];
  17413. // b) Look up the character name in the Adobe Glyph List (see the
  17414. // Bibliography) to obtain the corresponding Unicode value.
  17415. if (glyphName === '') {
  17416. continue;
  17417. } else if (GlyphsUnicode[glyphName] === undefined) {
  17418. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17419. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17420. var code = 0;
  17421. switch (glyphName[0]) {
  17422. case 'G': // Gxx glyph
  17423. if (glyphName.length === 3) {
  17424. code = parseInt(glyphName.substr(1), 16);
  17425. }
  17426. break;
  17427. case 'g': // g00xx glyph
  17428. if (glyphName.length === 5) {
  17429. code = parseInt(glyphName.substr(1), 16);
  17430. }
  17431. break;
  17432. case 'C': // Cddd glyph
  17433. case 'c': // cddd glyph
  17434. if (glyphName.length >= 3) {
  17435. code = +glyphName.substr(1);
  17436. }
  17437. break;
  17438. }
  17439. if (code) {
  17440. // If |baseEncodingName| is one the predefined encodings,
  17441. // and |code| equals |charcode|, using the glyph defined in the
  17442. // baseEncoding seems to yield a better |toUnicode| mapping
  17443. // (fixes issue 5070).
  17444. if (baseEncodingName && code === +charcode) {
  17445. var baseEncoding = Encodings[baseEncodingName];
  17446. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17447. toUnicode[charcode] =
  17448. String.fromCharCode(GlyphsUnicode[glyphName]);
  17449. continue;
  17450. }
  17451. }
  17452. toUnicode[charcode] = String.fromCharCode(code);
  17453. }
  17454. continue;
  17455. }
  17456. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17457. }
  17458. return new ToUnicodeMap(toUnicode);
  17459. }
  17460. // If the font is a composite font that uses one of the predefined CMaps
  17461. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17462. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17463. // Adobe-Korea1 character collection:
  17464. if (properties.composite && (
  17465. (properties.cMap.builtInCMap &&
  17466. !(properties.cMap instanceof IdentityCMap)) ||
  17467. (properties.cidSystemInfo.registry === 'Adobe' &&
  17468. (properties.cidSystemInfo.ordering === 'GB1' ||
  17469. properties.cidSystemInfo.ordering === 'CNS1' ||
  17470. properties.cidSystemInfo.ordering === 'Japan1' ||
  17471. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17472. // Then:
  17473. // a) Map the character code to a character identifier (CID) according
  17474. // to the font’s CMap.
  17475. // b) Obtain the registry and ordering of the character collection used
  17476. // by the font’s CMap (for example, Adobe and Japan1) from its
  17477. // CIDSystemInfo dictionary.
  17478. var registry = properties.cidSystemInfo.registry;
  17479. var ordering = properties.cidSystemInfo.ordering;
  17480. // c) Construct a second CMap name by concatenating the registry and
  17481. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17482. // (for example, Adobe–Japan1–UCS2).
  17483. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17484. // d) Obtain the CMap with the name constructed in step (c) (available
  17485. // from the ASN Web site; see the Bibliography).
  17486. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17487. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17488. var cMap = properties.cMap;
  17489. toUnicode = [];
  17490. cMap.forEach(function(charcode, cid) {
  17491. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17492. // e) Map the CID obtained in step (a) according to the CMap obtained
  17493. // in step (d), producing a Unicode value.
  17494. var ucs2 = ucs2CMap.lookup(cid);
  17495. if (ucs2) {
  17496. toUnicode[charcode] =
  17497. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17498. ucs2.charCodeAt(1));
  17499. }
  17500. });
  17501. return new ToUnicodeMap(toUnicode);
  17502. }
  17503. // The viewer's choice, just use an identity map.
  17504. return new IdentityToUnicodeMap(properties.firstChar,
  17505. properties.lastChar);
  17506. },
  17507. get spaceWidth() {
  17508. if ('_shadowWidth' in this) {
  17509. return this._shadowWidth;
  17510. }
  17511. // trying to estimate space character width
  17512. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17513. var width;
  17514. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17515. var glyphName = possibleSpaceReplacements[i];
  17516. // if possible, getting width by glyph name
  17517. if (glyphName in this.widths) {
  17518. width = this.widths[glyphName];
  17519. break;
  17520. }
  17521. var glyphUnicode = GlyphsUnicode[glyphName];
  17522. // finding the charcode via unicodeToCID map
  17523. var charcode = 0;
  17524. if (this.composite) {
  17525. if (this.cMap.contains(glyphUnicode)) {
  17526. charcode = this.cMap.lookup(glyphUnicode);
  17527. }
  17528. }
  17529. // ... via toUnicode map
  17530. if (!charcode && 'toUnicode' in this) {
  17531. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17532. }
  17533. // setting it to unicode if negative or undefined
  17534. if (charcode <= 0) {
  17535. charcode = glyphUnicode;
  17536. }
  17537. // trying to get width via charcode
  17538. width = this.widths[charcode];
  17539. if (width) {
  17540. break; // the non-zero width found
  17541. }
  17542. }
  17543. width = width || this.defaultWidth;
  17544. // Do not shadow the property here. See discussion:
  17545. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17546. this._shadowWidth = width;
  17547. return width;
  17548. },
  17549. charToGlyph: function Font_charToGlyph(charcode) {
  17550. var fontCharCode, width, operatorListId;
  17551. var widthCode = charcode;
  17552. if (this.cMap && this.cMap.contains(charcode)) {
  17553. widthCode = this.cMap.lookup(charcode);
  17554. }
  17555. width = this.widths[widthCode];
  17556. width = isNum(width) ? width : this.defaultWidth;
  17557. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17558. var unicode = this.toUnicode.get(charcode) || charcode;
  17559. if (typeof unicode === 'number') {
  17560. unicode = String.fromCharCode(unicode);
  17561. }
  17562. // First try the toFontChar map, if it's not there then try falling
  17563. // back to the char code.
  17564. fontCharCode = this.toFontChar[charcode] || charcode;
  17565. if (this.missingFile) {
  17566. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17567. }
  17568. if (this.isType3Font) {
  17569. // Font char code in this case is actually a glyph name.
  17570. operatorListId = fontCharCode;
  17571. }
  17572. var accent = null;
  17573. if (this.seacMap && this.seacMap[charcode]) {
  17574. var seac = this.seacMap[charcode];
  17575. fontCharCode = seac.baseFontCharCode;
  17576. accent = {
  17577. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17578. offset: seac.accentOffset
  17579. };
  17580. }
  17581. var fontChar = String.fromCharCode(fontCharCode);
  17582. var glyph = this.glyphCache[charcode];
  17583. if (!glyph ||
  17584. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17585. operatorListId)) {
  17586. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17587. operatorListId);
  17588. this.glyphCache[charcode] = glyph;
  17589. }
  17590. return glyph;
  17591. },
  17592. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17593. var charsCache = this.charsCache;
  17594. var glyphs, glyph, charcode;
  17595. // if we translated this string before, just grab it from the cache
  17596. if (charsCache) {
  17597. glyphs = charsCache[chars];
  17598. if (glyphs) {
  17599. return glyphs;
  17600. }
  17601. }
  17602. // lazily create the translation cache
  17603. if (!charsCache) {
  17604. charsCache = this.charsCache = Object.create(null);
  17605. }
  17606. glyphs = [];
  17607. var charsCacheKey = chars;
  17608. var i = 0, ii;
  17609. if (this.cMap) {
  17610. // composite fonts have multi-byte strings convert the string from
  17611. // single-byte to multi-byte
  17612. var c = {};
  17613. while (i < chars.length) {
  17614. this.cMap.readCharCode(chars, i, c);
  17615. charcode = c.charcode;
  17616. var length = c.length;
  17617. i += length;
  17618. glyph = this.charToGlyph(charcode);
  17619. glyphs.push(glyph);
  17620. // placing null after each word break charcode (ASCII SPACE)
  17621. // Ignore occurences of 0x20 in multiple-byte codes.
  17622. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17623. glyphs.push(null);
  17624. }
  17625. }
  17626. } else {
  17627. for (i = 0, ii = chars.length; i < ii; ++i) {
  17628. charcode = chars.charCodeAt(i);
  17629. glyph = this.charToGlyph(charcode);
  17630. glyphs.push(glyph);
  17631. if (charcode === 0x20) {
  17632. glyphs.push(null);
  17633. }
  17634. }
  17635. }
  17636. // Enter the translated string into the cache
  17637. return (charsCache[charsCacheKey] = glyphs);
  17638. }
  17639. };
  17640. return Font;
  17641. })();
  17642. var ErrorFont = (function ErrorFontClosure() {
  17643. function ErrorFont(error) {
  17644. this.error = error;
  17645. this.loadedName = 'g_font_error';
  17646. this.loading = false;
  17647. }
  17648. ErrorFont.prototype = {
  17649. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17650. return [];
  17651. },
  17652. exportData: function ErrorFont_exportData() {
  17653. return {error: this.error};
  17654. }
  17655. };
  17656. return ErrorFont;
  17657. })();
  17658. /**
  17659. * Shared logic for building a char code to glyph id mapping for Type1 and
  17660. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17661. * @param {Object} properties Font properties object.
  17662. * @param {Object} builtInEncoding The encoding contained within the actual font
  17663. * data.
  17664. * @param {Array} Array of glyph names where the index is the glyph ID.
  17665. * @returns {Object} A char code to glyph ID map.
  17666. */
  17667. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17668. var charCodeToGlyphId = Object.create(null);
  17669. var glyphId, charCode, baseEncoding;
  17670. if (properties.baseEncodingName) {
  17671. // If a valid base encoding name was used, the mapping is initialized with
  17672. // that.
  17673. baseEncoding = Encodings[properties.baseEncodingName];
  17674. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17675. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17676. if (glyphId >= 0) {
  17677. charCodeToGlyphId[charCode] = glyphId;
  17678. } else {
  17679. charCodeToGlyphId[charCode] = 0; // notdef
  17680. }
  17681. }
  17682. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17683. // For a symbolic font the encoding should be the fonts built-in
  17684. // encoding.
  17685. for (charCode in builtInEncoding) {
  17686. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17687. }
  17688. } else {
  17689. // For non-symbolic fonts that don't have a base encoding the standard
  17690. // encoding should be used.
  17691. baseEncoding = Encodings.StandardEncoding;
  17692. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17693. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17694. if (glyphId >= 0) {
  17695. charCodeToGlyphId[charCode] = glyphId;
  17696. } else {
  17697. charCodeToGlyphId[charCode] = 0; // notdef
  17698. }
  17699. }
  17700. }
  17701. // Lastly, merge in the differences.
  17702. var differences = properties.differences;
  17703. if (differences) {
  17704. for (charCode in differences) {
  17705. var glyphName = differences[charCode];
  17706. glyphId = glyphNames.indexOf(glyphName);
  17707. if (glyphId >= 0) {
  17708. charCodeToGlyphId[charCode] = glyphId;
  17709. } else {
  17710. charCodeToGlyphId[charCode] = 0; // notdef
  17711. }
  17712. }
  17713. }
  17714. return charCodeToGlyphId;
  17715. }
  17716. /*
  17717. * CharStrings are encoded following the the CharString Encoding sequence
  17718. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17719. * The value in a byte indicates a command, a number, or subsequent bytes
  17720. * that are to be interpreted in a special way.
  17721. *
  17722. * CharString Number Encoding:
  17723. * A CharString byte containing the values from 32 through 255 inclusive
  17724. * indicate an integer. These values are decoded in four ranges.
  17725. *
  17726. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17727. * indicate the integer v - 139. Thus, the integer values from -107 through
  17728. * 107 inclusive may be encoded in single byte.
  17729. *
  17730. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17731. * indicates an integer involving the next byte, w, according to the formula:
  17732. * [(v - 247) x 256] + w + 108
  17733. *
  17734. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17735. * indicates an integer involving the next byte, w, according to the formula:
  17736. * -[(v - 251) * 256] - w - 108
  17737. *
  17738. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17739. * are a two complement signed integer. The first of these bytes contains the
  17740. * highest order bits, the second byte contains the next higher order bits
  17741. * and the fourth byte contain the lowest order bits.
  17742. *
  17743. *
  17744. * CharString Command Encoding:
  17745. * CharStrings commands are encoded in 1 or 2 bytes.
  17746. *
  17747. * Single byte commands are encoded in 1 byte that contains a value between
  17748. * 0 and 31 inclusive.
  17749. * If a command byte contains the value 12, then the value in the next byte
  17750. * indicates a command. This "escape" mechanism allows many extra commands
  17751. * to be encoded and this encoding technique helps to minimize the length of
  17752. * the charStrings.
  17753. */
  17754. var Type1CharString = (function Type1CharStringClosure() {
  17755. var COMMAND_MAP = {
  17756. 'hstem': [1],
  17757. 'vstem': [3],
  17758. 'vmoveto': [4],
  17759. 'rlineto': [5],
  17760. 'hlineto': [6],
  17761. 'vlineto': [7],
  17762. 'rrcurveto': [8],
  17763. 'callsubr': [10],
  17764. 'flex': [12, 35],
  17765. 'drop' : [12, 18],
  17766. 'endchar': [14],
  17767. 'rmoveto': [21],
  17768. 'hmoveto': [22],
  17769. 'vhcurveto': [30],
  17770. 'hvcurveto': [31]
  17771. };
  17772. function Type1CharString() {
  17773. this.width = 0;
  17774. this.lsb = 0;
  17775. this.flexing = false;
  17776. this.output = [];
  17777. this.stack = [];
  17778. }
  17779. Type1CharString.prototype = {
  17780. convert: function Type1CharString_convert(encoded, subrs) {
  17781. var count = encoded.length;
  17782. var error = false;
  17783. var wx, sbx, subrNumber;
  17784. for (var i = 0; i < count; i++) {
  17785. var value = encoded[i];
  17786. if (value < 32) {
  17787. if (value === 12) {
  17788. value = (value << 8) + encoded[++i];
  17789. }
  17790. switch (value) {
  17791. case 1: // hstem
  17792. if (!HINTING_ENABLED) {
  17793. this.stack = [];
  17794. break;
  17795. }
  17796. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17797. break;
  17798. case 3: // vstem
  17799. if (!HINTING_ENABLED) {
  17800. this.stack = [];
  17801. break;
  17802. }
  17803. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17804. break;
  17805. case 4: // vmoveto
  17806. if (this.flexing) {
  17807. if (this.stack.length < 1) {
  17808. error = true;
  17809. break;
  17810. }
  17811. // Add the dx for flex and but also swap the values so they are
  17812. // the right order.
  17813. var dy = this.stack.pop();
  17814. this.stack.push(0, dy);
  17815. break;
  17816. }
  17817. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17818. break;
  17819. case 5: // rlineto
  17820. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17821. break;
  17822. case 6: // hlineto
  17823. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17824. break;
  17825. case 7: // vlineto
  17826. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17827. break;
  17828. case 8: // rrcurveto
  17829. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17830. break;
  17831. case 9: // closepath
  17832. // closepath is a Type1 command that does not take argument and is
  17833. // useless in Type2 and it can simply be ignored.
  17834. this.stack = [];
  17835. break;
  17836. case 10: // callsubr
  17837. if (this.stack.length < 1) {
  17838. error = true;
  17839. break;
  17840. }
  17841. subrNumber = this.stack.pop();
  17842. error = this.convert(subrs[subrNumber], subrs);
  17843. break;
  17844. case 11: // return
  17845. return error;
  17846. case 13: // hsbw
  17847. if (this.stack.length < 2) {
  17848. error = true;
  17849. break;
  17850. }
  17851. // To convert to type2 we have to move the width value to the
  17852. // first part of the charstring and then use hmoveto with lsb.
  17853. wx = this.stack.pop();
  17854. sbx = this.stack.pop();
  17855. this.lsb = sbx;
  17856. this.width = wx;
  17857. this.stack.push(wx, sbx);
  17858. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17859. break;
  17860. case 14: // endchar
  17861. this.output.push(COMMAND_MAP.endchar[0]);
  17862. break;
  17863. case 21: // rmoveto
  17864. if (this.flexing) {
  17865. break;
  17866. }
  17867. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17868. break;
  17869. case 22: // hmoveto
  17870. if (this.flexing) {
  17871. // Add the dy for flex.
  17872. this.stack.push(0);
  17873. break;
  17874. }
  17875. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17876. break;
  17877. case 30: // vhcurveto
  17878. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17879. break;
  17880. case 31: // hvcurveto
  17881. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17882. break;
  17883. case (12 << 8) + 0: // dotsection
  17884. // dotsection is a Type1 command to specify some hinting feature
  17885. // for dots that do not take a parameter and it can safely be
  17886. // ignored for Type2.
  17887. this.stack = [];
  17888. break;
  17889. case (12 << 8) + 1: // vstem3
  17890. if (!HINTING_ENABLED) {
  17891. this.stack = [];
  17892. break;
  17893. }
  17894. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17895. // multiple parameters, so instead of returning [vh]stem3 take a
  17896. // shortcut and return [vhstem] instead.
  17897. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17898. break;
  17899. case (12 << 8) + 2: // hstem3
  17900. if (!HINTING_ENABLED) {
  17901. this.stack = [];
  17902. break;
  17903. }
  17904. // See vstem3.
  17905. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17906. break;
  17907. case (12 << 8) + 6: // seac
  17908. // seac is like type 2's special endchar but it doesn't use the
  17909. // first argument asb, so remove it.
  17910. if (SEAC_ANALYSIS_ENABLED) {
  17911. this.seac = this.stack.splice(-4, 4);
  17912. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17913. } else {
  17914. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17915. }
  17916. break;
  17917. case (12 << 8) + 7: // sbw
  17918. if (this.stack.length < 4) {
  17919. error = true;
  17920. break;
  17921. }
  17922. // To convert to type2 we have to move the width value to the
  17923. // first part of the charstring and then use rmoveto with
  17924. // (dx, dy). The height argument will not be used for vmtx and
  17925. // vhea tables reconstruction -- ignoring it.
  17926. var wy = this.stack.pop();
  17927. wx = this.stack.pop();
  17928. var sby = this.stack.pop();
  17929. sbx = this.stack.pop();
  17930. this.lsb = sbx;
  17931. this.width = wx;
  17932. this.stack.push(wx, sbx, sby);
  17933. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17934. break;
  17935. case (12 << 8) + 12: // div
  17936. if (this.stack.length < 2) {
  17937. error = true;
  17938. break;
  17939. }
  17940. var num2 = this.stack.pop();
  17941. var num1 = this.stack.pop();
  17942. this.stack.push(num1 / num2);
  17943. break;
  17944. case (12 << 8) + 16: // callothersubr
  17945. if (this.stack.length < 2) {
  17946. error = true;
  17947. break;
  17948. }
  17949. subrNumber = this.stack.pop();
  17950. var numArgs = this.stack.pop();
  17951. if (subrNumber === 0 && numArgs === 3) {
  17952. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17953. this.stack.push(
  17954. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17955. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17956. flexArgs[4], // bcp2x
  17957. flexArgs[5], // bcp2y
  17958. flexArgs[6], // p2x
  17959. flexArgs[7], // p2y
  17960. flexArgs[8], // bcp3x
  17961. flexArgs[9], // bcp3y
  17962. flexArgs[10], // bcp4x
  17963. flexArgs[11], // bcp4y
  17964. flexArgs[12], // p3x
  17965. flexArgs[13], // p3y
  17966. flexArgs[14] // flexDepth
  17967. // 15 = finalx unused by flex
  17968. // 16 = finaly unused by flex
  17969. );
  17970. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17971. this.flexing = false;
  17972. this.stack.push(flexArgs[15], flexArgs[16]);
  17973. } else if (subrNumber === 1 && numArgs === 0) {
  17974. this.flexing = true;
  17975. }
  17976. break;
  17977. case (12 << 8) + 17: // pop
  17978. // Ignore this since it is only used with othersubr.
  17979. break;
  17980. case (12 << 8) + 33: // setcurrentpoint
  17981. // Ignore for now.
  17982. this.stack = [];
  17983. break;
  17984. default:
  17985. warn('Unknown type 1 charstring command of "' + value + '"');
  17986. break;
  17987. }
  17988. if (error) {
  17989. break;
  17990. }
  17991. continue;
  17992. } else if (value <= 246) {
  17993. value = value - 139;
  17994. } else if (value <= 250) {
  17995. value = ((value - 247) * 256) + encoded[++i] + 108;
  17996. } else if (value <= 254) {
  17997. value = -((value - 251) * 256) - encoded[++i] - 108;
  17998. } else {
  17999. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  18000. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  18001. }
  18002. this.stack.push(value);
  18003. }
  18004. return error;
  18005. },
  18006. executeCommand: function(howManyArgs, command, keepStack) {
  18007. var stackLength = this.stack.length;
  18008. if (howManyArgs > stackLength) {
  18009. return true;
  18010. }
  18011. var start = stackLength - howManyArgs;
  18012. for (var i = start; i < stackLength; i++) {
  18013. var value = this.stack[i];
  18014. if (value === (value | 0)) { // int
  18015. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  18016. } else { // fixed point
  18017. value = (65536 * value) | 0;
  18018. this.output.push(255,
  18019. (value >> 24) & 0xFF,
  18020. (value >> 16) & 0xFF,
  18021. (value >> 8) & 0xFF,
  18022. value & 0xFF);
  18023. }
  18024. }
  18025. this.output.push.apply(this.output, command);
  18026. if (keepStack) {
  18027. this.stack.splice(start, howManyArgs);
  18028. } else {
  18029. this.stack.length = 0;
  18030. }
  18031. return false;
  18032. }
  18033. };
  18034. return Type1CharString;
  18035. })();
  18036. /*
  18037. * Type1Parser encapsulate the needed code for parsing a Type1 font
  18038. * program. Some of its logic depends on the Type2 charstrings
  18039. * structure.
  18040. * Note: this doesn't really parse the font since that would require evaluation
  18041. * of PostScript, but it is possible in most cases to extract what we need
  18042. * without a full parse.
  18043. */
  18044. var Type1Parser = (function Type1ParserClosure() {
  18045. /*
  18046. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  18047. * of Plaintext Bytes. The function took a key as a parameter which can be
  18048. * for decrypting the eexec block of for decoding charStrings.
  18049. */
  18050. var EEXEC_ENCRYPT_KEY = 55665;
  18051. var CHAR_STRS_ENCRYPT_KEY = 4330;
  18052. function isHexDigit(code) {
  18053. return code >= 48 && code <= 57 || // '0'-'9'
  18054. code >= 65 && code <= 70 || // 'A'-'F'
  18055. code >= 97 && code <= 102; // 'a'-'f'
  18056. }
  18057. function decrypt(data, key, discardNumber) {
  18058. var r = key | 0, c1 = 52845, c2 = 22719;
  18059. var count = data.length;
  18060. var decrypted = new Uint8Array(count);
  18061. for (var i = 0; i < count; i++) {
  18062. var value = data[i];
  18063. decrypted[i] = value ^ (r >> 8);
  18064. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18065. }
  18066. return Array.prototype.slice.call(decrypted, discardNumber);
  18067. }
  18068. function decryptAscii(data, key, discardNumber) {
  18069. var r = key | 0, c1 = 52845, c2 = 22719;
  18070. var count = data.length, maybeLength = count >>> 1;
  18071. var decrypted = new Uint8Array(maybeLength);
  18072. var i, j;
  18073. for (i = 0, j = 0; i < count; i++) {
  18074. var digit1 = data[i];
  18075. if (!isHexDigit(digit1)) {
  18076. continue;
  18077. }
  18078. i++;
  18079. var digit2;
  18080. while (i < count && !isHexDigit(digit2 = data[i])) {
  18081. i++;
  18082. }
  18083. if (i < count) {
  18084. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  18085. decrypted[j++] = value ^ (r >> 8);
  18086. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18087. }
  18088. }
  18089. return Array.prototype.slice.call(decrypted, discardNumber, j);
  18090. }
  18091. function isSpecial(c) {
  18092. return c === 0x2F || // '/'
  18093. c === 0x5B || c === 0x5D || // '[', ']'
  18094. c === 0x7B || c === 0x7D || // '{', '}'
  18095. c === 0x28 || c === 0x29; // '(', ')'
  18096. }
  18097. function Type1Parser(stream, encrypted) {
  18098. if (encrypted) {
  18099. var data = stream.getBytes();
  18100. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  18101. isHexDigit(data[2]) && isHexDigit(data[3]));
  18102. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  18103. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  18104. }
  18105. this.stream = stream;
  18106. this.nextChar();
  18107. }
  18108. Type1Parser.prototype = {
  18109. readNumberArray: function Type1Parser_readNumberArray() {
  18110. this.getToken(); // read '[' or '{' (arrays can start with either)
  18111. var array = [];
  18112. while (true) {
  18113. var token = this.getToken();
  18114. if (token === null || token === ']' || token === '}') {
  18115. break;
  18116. }
  18117. array.push(parseFloat(token || 0));
  18118. }
  18119. return array;
  18120. },
  18121. readNumber: function Type1Parser_readNumber() {
  18122. var token = this.getToken();
  18123. return parseFloat(token || 0);
  18124. },
  18125. readInt: function Type1Parser_readInt() {
  18126. // Use '| 0' to prevent setting a double into length such as the double
  18127. // does not flow into the loop variable.
  18128. var token = this.getToken();
  18129. return parseInt(token || 0, 10) | 0;
  18130. },
  18131. readBoolean: function Type1Parser_readBoolean() {
  18132. var token = this.getToken();
  18133. // Use 1 and 0 since that's what type2 charstrings use.
  18134. return token === 'true' ? 1 : 0;
  18135. },
  18136. nextChar : function Type1_nextChar() {
  18137. return (this.currentChar = this.stream.getByte());
  18138. },
  18139. getToken: function Type1Parser_getToken() {
  18140. // Eat whitespace and comments.
  18141. var comment = false;
  18142. var ch = this.currentChar;
  18143. while (true) {
  18144. if (ch === -1) {
  18145. return null;
  18146. }
  18147. if (comment) {
  18148. if (ch === 0x0A || ch === 0x0D) {
  18149. comment = false;
  18150. }
  18151. } else if (ch === 0x25) { // '%'
  18152. comment = true;
  18153. } else if (!Lexer.isSpace(ch)) {
  18154. break;
  18155. }
  18156. ch = this.nextChar();
  18157. }
  18158. if (isSpecial(ch)) {
  18159. this.nextChar();
  18160. return String.fromCharCode(ch);
  18161. }
  18162. var token = '';
  18163. do {
  18164. token += String.fromCharCode(ch);
  18165. ch = this.nextChar();
  18166. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  18167. return token;
  18168. },
  18169. /*
  18170. * Returns an object containing a Subrs array and a CharStrings
  18171. * array extracted from and eexec encrypted block of data
  18172. */
  18173. extractFontProgram: function Type1Parser_extractFontProgram() {
  18174. var stream = this.stream;
  18175. var subrs = [], charstrings = [];
  18176. var program = {
  18177. subrs: [],
  18178. charstrings: [],
  18179. properties: {
  18180. 'privateData': {
  18181. 'lenIV': 4
  18182. }
  18183. }
  18184. };
  18185. var token, length, data, lenIV, encoded;
  18186. while ((token = this.getToken()) !== null) {
  18187. if (token !== '/') {
  18188. continue;
  18189. }
  18190. token = this.getToken();
  18191. switch (token) {
  18192. case 'CharStrings':
  18193. // The number immediately following CharStrings must be greater or
  18194. // equal to the number of CharStrings.
  18195. this.getToken();
  18196. this.getToken(); // read in 'dict'
  18197. this.getToken(); // read in 'dup'
  18198. this.getToken(); // read in 'begin'
  18199. while(true) {
  18200. token = this.getToken();
  18201. if (token === null || token === 'end') {
  18202. break;
  18203. }
  18204. if (token !== '/') {
  18205. continue;
  18206. }
  18207. var glyph = this.getToken();
  18208. length = this.readInt();
  18209. this.getToken(); // read in 'RD' or '-|'
  18210. data = stream.makeSubStream(stream.pos, length);
  18211. lenIV = program.properties.privateData['lenIV'];
  18212. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18213. // Skip past the required space and binary data.
  18214. stream.skip(length);
  18215. this.nextChar();
  18216. token = this.getToken(); // read in 'ND' or '|-'
  18217. if (token === 'noaccess') {
  18218. this.getToken(); // read in 'def'
  18219. }
  18220. charstrings.push({
  18221. glyph: glyph,
  18222. encoded: encoded
  18223. });
  18224. }
  18225. break;
  18226. case 'Subrs':
  18227. var num = this.readInt();
  18228. this.getToken(); // read in 'array'
  18229. while ((token = this.getToken()) === 'dup') {
  18230. var index = this.readInt();
  18231. length = this.readInt();
  18232. this.getToken(); // read in 'RD' or '-|'
  18233. data = stream.makeSubStream(stream.pos, length);
  18234. lenIV = program.properties.privateData['lenIV'];
  18235. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18236. // Skip past the required space and binary data.
  18237. stream.skip(length);
  18238. this.nextChar();
  18239. token = this.getToken(); // read in 'NP' or '|'
  18240. if (token === 'noaccess') {
  18241. this.getToken(); // read in 'put'
  18242. }
  18243. subrs[index] = encoded;
  18244. }
  18245. break;
  18246. case 'BlueValues':
  18247. case 'OtherBlues':
  18248. case 'FamilyBlues':
  18249. case 'FamilyOtherBlues':
  18250. var blueArray = this.readNumberArray();
  18251. // *Blue* values may contain invalid data: disables reading of
  18252. // those values when hinting is disabled.
  18253. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18254. HINTING_ENABLED) {
  18255. program.properties.privateData[token] = blueArray;
  18256. }
  18257. break;
  18258. case 'StemSnapH':
  18259. case 'StemSnapV':
  18260. program.properties.privateData[token] = this.readNumberArray();
  18261. break;
  18262. case 'StdHW':
  18263. case 'StdVW':
  18264. program.properties.privateData[token] =
  18265. this.readNumberArray()[0];
  18266. break;
  18267. case 'BlueShift':
  18268. case 'lenIV':
  18269. case 'BlueFuzz':
  18270. case 'BlueScale':
  18271. case 'LanguageGroup':
  18272. case 'ExpansionFactor':
  18273. program.properties.privateData[token] = this.readNumber();
  18274. break;
  18275. case 'ForceBold':
  18276. program.properties.privateData[token] = this.readBoolean();
  18277. break;
  18278. }
  18279. }
  18280. for (var i = 0; i < charstrings.length; i++) {
  18281. glyph = charstrings[i].glyph;
  18282. encoded = charstrings[i].encoded;
  18283. var charString = new Type1CharString();
  18284. var error = charString.convert(encoded, subrs);
  18285. var output = charString.output;
  18286. if (error) {
  18287. // It seems when FreeType encounters an error while evaluating a glyph
  18288. // that it completely ignores the glyph so we'll mimic that behaviour
  18289. // here and put an endchar to make the validator happy.
  18290. output = [14];
  18291. }
  18292. program.charstrings.push({
  18293. glyphName: glyph,
  18294. charstring: output,
  18295. width: charString.width,
  18296. lsb: charString.lsb,
  18297. seac: charString.seac
  18298. });
  18299. }
  18300. return program;
  18301. },
  18302. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18303. var token;
  18304. while ((token = this.getToken()) !== null) {
  18305. if (token !== '/') {
  18306. continue;
  18307. }
  18308. token = this.getToken();
  18309. switch (token) {
  18310. case 'FontMatrix':
  18311. var matrix = this.readNumberArray();
  18312. properties.fontMatrix = matrix;
  18313. break;
  18314. case 'Encoding':
  18315. var encodingArg = this.getToken();
  18316. var encoding;
  18317. if (!/^\d+$/.test(encodingArg)) {
  18318. // encoding name is specified
  18319. encoding = Encodings[encodingArg];
  18320. } else {
  18321. encoding = [];
  18322. var size = parseInt(encodingArg, 10) | 0;
  18323. this.getToken(); // read in 'array'
  18324. for (var j = 0; j < size; j++) {
  18325. token = this.getToken();
  18326. // skipping till first dup or def (e.g. ignoring for statement)
  18327. while (token !== 'dup' && token !== 'def') {
  18328. token = this.getToken();
  18329. if (token === null) {
  18330. return; // invalid header
  18331. }
  18332. }
  18333. if (token === 'def') {
  18334. break; // read all array data
  18335. }
  18336. var index = this.readInt();
  18337. this.getToken(); // read in '/'
  18338. var glyph = this.getToken();
  18339. encoding[index] = glyph;
  18340. this.getToken(); // read the in 'put'
  18341. }
  18342. }
  18343. properties.builtInEncoding = encoding;
  18344. break;
  18345. case 'FontBBox':
  18346. var fontBBox = this.readNumberArray();
  18347. // adjusting ascent/descent
  18348. properties.ascent = fontBBox[3];
  18349. properties.descent = fontBBox[1];
  18350. properties.ascentScaled = true;
  18351. break;
  18352. }
  18353. }
  18354. }
  18355. };
  18356. return Type1Parser;
  18357. })();
  18358. /**
  18359. * The CFF class takes a Type1 file and wrap it into a
  18360. * 'Compact Font Format' which itself embed Type2 charstrings.
  18361. */
  18362. var CFFStandardStrings = [
  18363. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18364. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18365. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18366. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18367. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18368. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18369. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18370. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18371. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18372. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18373. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18374. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18375. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18376. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18377. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18378. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18379. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18380. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18381. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18382. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18383. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18384. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18385. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18386. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18387. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18388. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18389. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18390. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18391. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18392. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18393. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18394. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18395. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18396. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18397. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18398. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18399. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18400. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18401. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18402. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18403. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18404. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18405. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18406. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18407. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18408. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18409. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18410. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18411. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18412. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18413. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18414. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18415. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18416. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18417. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18418. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18419. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18420. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18421. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18422. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18423. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18424. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18425. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18426. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18427. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18428. ];
  18429. // Type1Font is also a CIDFontType0.
  18430. var Type1Font = function Type1Font(name, file, properties) {
  18431. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18432. // Also, length1 and length2 might be off by 6 bytes as well.
  18433. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18434. var PFB_HEADER_SIZE = 6;
  18435. var headerBlockLength = properties.length1;
  18436. var eexecBlockLength = properties.length2;
  18437. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18438. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18439. if (pfbHeaderPresent) {
  18440. file.skip(PFB_HEADER_SIZE);
  18441. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18442. (pfbHeader[3] << 8) | pfbHeader[2];
  18443. }
  18444. // Get the data block containing glyphs and subrs informations
  18445. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18446. var headerBlockParser = new Type1Parser(headerBlock);
  18447. headerBlockParser.extractFontHeader(properties);
  18448. if (pfbHeaderPresent) {
  18449. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18450. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18451. (pfbHeader[3] << 8) | pfbHeader[2];
  18452. }
  18453. // Decrypt the data blocks and retrieve it's content
  18454. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18455. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18456. var data = eexecBlockParser.extractFontProgram();
  18457. for (var info in data.properties) {
  18458. properties[info] = data.properties[info];
  18459. }
  18460. var charstrings = data.charstrings;
  18461. var type2Charstrings = this.getType2Charstrings(charstrings);
  18462. var subrs = this.getType2Subrs(data.subrs);
  18463. this.charstrings = charstrings;
  18464. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18465. subrs, properties);
  18466. this.seacs = this.getSeacs(data.charstrings);
  18467. };
  18468. Type1Font.prototype = {
  18469. get numGlyphs() {
  18470. return this.charstrings.length + 1;
  18471. },
  18472. getCharset: function Type1Font_getCharset() {
  18473. var charset = ['.notdef'];
  18474. var charstrings = this.charstrings;
  18475. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18476. charset.push(charstrings[glyphId].glyphName);
  18477. }
  18478. return charset;
  18479. },
  18480. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18481. var charstrings = this.charstrings;
  18482. var glyphNames = ['.notdef'], glyphId;
  18483. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18484. glyphNames.push(charstrings[glyphId].glyphName);
  18485. }
  18486. var encoding = properties.builtInEncoding;
  18487. if (encoding) {
  18488. var builtInEncoding = {};
  18489. for (var charCode in encoding) {
  18490. glyphId = glyphNames.indexOf(encoding[charCode]);
  18491. if (glyphId >= 0) {
  18492. builtInEncoding[charCode] = glyphId;
  18493. }
  18494. }
  18495. }
  18496. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18497. },
  18498. getSeacs: function Type1Font_getSeacs(charstrings) {
  18499. var i, ii;
  18500. var seacMap = [];
  18501. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18502. var charstring = charstrings[i];
  18503. if (charstring.seac) {
  18504. // Offset by 1 for .notdef
  18505. seacMap[i + 1] = charstring.seac;
  18506. }
  18507. }
  18508. return seacMap;
  18509. },
  18510. getType2Charstrings: function Type1Font_getType2Charstrings(
  18511. type1Charstrings) {
  18512. var type2Charstrings = [];
  18513. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18514. type2Charstrings.push(type1Charstrings[i].charstring);
  18515. }
  18516. return type2Charstrings;
  18517. },
  18518. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18519. var bias = 0;
  18520. var count = type1Subrs.length;
  18521. if (count < 1133) {
  18522. bias = 107;
  18523. } else if (count < 33769) {
  18524. bias = 1131;
  18525. } else {
  18526. bias = 32768;
  18527. }
  18528. // Add a bunch of empty subrs to deal with the Type2 bias
  18529. var type2Subrs = [];
  18530. var i;
  18531. for (i = 0; i < bias; i++) {
  18532. type2Subrs.push([0x0B]);
  18533. }
  18534. for (i = 0; i < count; i++) {
  18535. type2Subrs.push(type1Subrs[i]);
  18536. }
  18537. return type2Subrs;
  18538. },
  18539. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18540. var cff = new CFF();
  18541. cff.header = new CFFHeader(1, 0, 4, 4);
  18542. cff.names = [name];
  18543. var topDict = new CFFTopDict();
  18544. // CFF strings IDs 0...390 are predefined names, so refering
  18545. // to entries in our own String INDEX starts at SID 391.
  18546. topDict.setByName('version', 391);
  18547. topDict.setByName('Notice', 392);
  18548. topDict.setByName('FullName', 393);
  18549. topDict.setByName('FamilyName', 394);
  18550. topDict.setByName('Weight', 395);
  18551. topDict.setByName('Encoding', null); // placeholder
  18552. topDict.setByName('FontMatrix', properties.fontMatrix);
  18553. topDict.setByName('FontBBox', properties.bbox);
  18554. topDict.setByName('charset', null); // placeholder
  18555. topDict.setByName('CharStrings', null); // placeholder
  18556. topDict.setByName('Private', null); // placeholder
  18557. cff.topDict = topDict;
  18558. var strings = new CFFStrings();
  18559. strings.add('Version 0.11'); // Version
  18560. strings.add('See original notice'); // Notice
  18561. strings.add(name); // FullName
  18562. strings.add(name); // FamilyName
  18563. strings.add('Medium'); // Weight
  18564. cff.strings = strings;
  18565. cff.globalSubrIndex = new CFFIndex();
  18566. var count = glyphs.length;
  18567. var charsetArray = [0];
  18568. var i, ii;
  18569. for (i = 0; i < count; i++) {
  18570. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18571. // TODO: Insert the string and correctly map it. Previously it was
  18572. // thought mapping names that aren't in the standard strings to .notdef
  18573. // was fine, however in issue818 when mapping them all to .notdef the
  18574. // adieresis glyph no longer worked.
  18575. if (index === -1) {
  18576. index = 0;
  18577. }
  18578. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18579. }
  18580. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18581. var charStringsIndex = new CFFIndex();
  18582. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18583. for (i = 0; i < count; i++) {
  18584. charStringsIndex.add(glyphs[i]);
  18585. }
  18586. cff.charStrings = charStringsIndex;
  18587. var privateDict = new CFFPrivateDict();
  18588. privateDict.setByName('Subrs', null); // placeholder
  18589. var fields = [
  18590. 'BlueValues',
  18591. 'OtherBlues',
  18592. 'FamilyBlues',
  18593. 'FamilyOtherBlues',
  18594. 'StemSnapH',
  18595. 'StemSnapV',
  18596. 'BlueShift',
  18597. 'BlueFuzz',
  18598. 'BlueScale',
  18599. 'LanguageGroup',
  18600. 'ExpansionFactor',
  18601. 'ForceBold',
  18602. 'StdHW',
  18603. 'StdVW'
  18604. ];
  18605. for (i = 0, ii = fields.length; i < ii; i++) {
  18606. var field = fields[i];
  18607. if (!properties.privateData.hasOwnProperty(field)) {
  18608. continue;
  18609. }
  18610. var value = properties.privateData[field];
  18611. if (isArray(value)) {
  18612. // All of the private dictionary array data in CFF must be stored as
  18613. // "delta-encoded" numbers.
  18614. for (var j = value.length - 1; j > 0; j--) {
  18615. value[j] -= value[j - 1]; // ... difference from previous value
  18616. }
  18617. }
  18618. privateDict.setByName(field, value);
  18619. }
  18620. cff.topDict.privateDict = privateDict;
  18621. var subrIndex = new CFFIndex();
  18622. for (i = 0, ii = subrs.length; i < ii; i++) {
  18623. subrIndex.add(subrs[i]);
  18624. }
  18625. privateDict.subrsIndex = subrIndex;
  18626. var compiler = new CFFCompiler(cff);
  18627. return compiler.compile();
  18628. }
  18629. };
  18630. var CFFFont = (function CFFFontClosure() {
  18631. function CFFFont(file, properties) {
  18632. this.properties = properties;
  18633. var parser = new CFFParser(file, properties);
  18634. this.cff = parser.parse();
  18635. var compiler = new CFFCompiler(this.cff);
  18636. this.seacs = this.cff.seacs;
  18637. try {
  18638. this.data = compiler.compile();
  18639. } catch (e) {
  18640. warn('Failed to compile font ' + properties.loadedName);
  18641. // There may have just been an issue with the compiler, set the data
  18642. // anyway and hope the font loaded.
  18643. this.data = file;
  18644. }
  18645. }
  18646. CFFFont.prototype = {
  18647. get numGlyphs() {
  18648. return this.cff.charStrings.count;
  18649. },
  18650. getCharset: function CFFFont_getCharset() {
  18651. return this.cff.charset.charset;
  18652. },
  18653. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18654. var cff = this.cff;
  18655. var properties = this.properties;
  18656. var charsets = cff.charset.charset;
  18657. var charCodeToGlyphId;
  18658. var glyphId;
  18659. if (properties.composite) {
  18660. charCodeToGlyphId = Object.create(null);
  18661. if (cff.isCIDFont) {
  18662. // If the font is actually a CID font then we should use the charset
  18663. // to map CIDs to GIDs.
  18664. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18665. var cid = charsets[glyphId];
  18666. var charCode = properties.cMap.charCodeOf(cid);
  18667. charCodeToGlyphId[charCode] = glyphId;
  18668. }
  18669. } else {
  18670. // If it is NOT actually a CID font then CIDs should be mapped
  18671. // directly to GIDs.
  18672. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18673. charCodeToGlyphId[glyphId] = glyphId;
  18674. }
  18675. }
  18676. return charCodeToGlyphId;
  18677. }
  18678. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18679. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18680. return charCodeToGlyphId;
  18681. }
  18682. };
  18683. return CFFFont;
  18684. })();
  18685. var CFFParser = (function CFFParserClosure() {
  18686. var CharstringValidationData = [
  18687. null,
  18688. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18689. null,
  18690. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18691. { id: 'vmoveto', min: 1, stackClearing: true },
  18692. { id: 'rlineto', min: 2, resetStack: true },
  18693. { id: 'hlineto', min: 1, resetStack: true },
  18694. { id: 'vlineto', min: 1, resetStack: true },
  18695. { id: 'rrcurveto', min: 6, resetStack: true },
  18696. null,
  18697. { id: 'callsubr', min: 1, undefStack: true },
  18698. { id: 'return', min: 0, undefStack: true },
  18699. null, // 12
  18700. null,
  18701. { id: 'endchar', min: 0, stackClearing: true },
  18702. null,
  18703. null,
  18704. null,
  18705. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18706. { id: 'hintmask', min: 0, stackClearing: true },
  18707. { id: 'cntrmask', min: 0, stackClearing: true },
  18708. { id: 'rmoveto', min: 2, stackClearing: true },
  18709. { id: 'hmoveto', min: 1, stackClearing: true },
  18710. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18711. { id: 'rcurveline', min: 8, resetStack: true },
  18712. { id: 'rlinecurve', min: 8, resetStack: true },
  18713. { id: 'vvcurveto', min: 4, resetStack: true },
  18714. { id: 'hhcurveto', min: 4, resetStack: true },
  18715. null, // shortint
  18716. { id: 'callgsubr', min: 1, undefStack: true },
  18717. { id: 'vhcurveto', min: 4, resetStack: true },
  18718. { id: 'hvcurveto', min: 4, resetStack: true }
  18719. ];
  18720. var CharstringValidationData12 = [
  18721. null,
  18722. null,
  18723. null,
  18724. { id: 'and', min: 2, stackDelta: -1 },
  18725. { id: 'or', min: 2, stackDelta: -1 },
  18726. { id: 'not', min: 1, stackDelta: 0 },
  18727. null,
  18728. null,
  18729. null,
  18730. { id: 'abs', min: 1, stackDelta: 0 },
  18731. { id: 'add', min: 2, stackDelta: -1,
  18732. stackFn: function stack_div(stack, index) {
  18733. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18734. }
  18735. },
  18736. { id: 'sub', min: 2, stackDelta: -1,
  18737. stackFn: function stack_div(stack, index) {
  18738. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18739. }
  18740. },
  18741. { id: 'div', min: 2, stackDelta: -1,
  18742. stackFn: function stack_div(stack, index) {
  18743. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18744. }
  18745. },
  18746. null,
  18747. { id: 'neg', min: 1, stackDelta: 0,
  18748. stackFn: function stack_div(stack, index) {
  18749. stack[index - 1] = -stack[index - 1];
  18750. }
  18751. },
  18752. { id: 'eq', min: 2, stackDelta: -1 },
  18753. null,
  18754. null,
  18755. { id: 'drop', min: 1, stackDelta: -1 },
  18756. null,
  18757. { id: 'put', min: 2, stackDelta: -2 },
  18758. { id: 'get', min: 1, stackDelta: 0 },
  18759. { id: 'ifelse', min: 4, stackDelta: -3 },
  18760. { id: 'random', min: 0, stackDelta: 1 },
  18761. { id: 'mul', min: 2, stackDelta: -1,
  18762. stackFn: function stack_div(stack, index) {
  18763. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18764. }
  18765. },
  18766. null,
  18767. { id: 'sqrt', min: 1, stackDelta: 0 },
  18768. { id: 'dup', min: 1, stackDelta: 1 },
  18769. { id: 'exch', min: 2, stackDelta: 0 },
  18770. { id: 'index', min: 2, stackDelta: 0 },
  18771. { id: 'roll', min: 3, stackDelta: -2 },
  18772. null,
  18773. null,
  18774. null,
  18775. { id: 'hflex', min: 7, resetStack: true },
  18776. { id: 'flex', min: 13, resetStack: true },
  18777. { id: 'hflex1', min: 9, resetStack: true },
  18778. { id: 'flex1', min: 11, resetStack: true }
  18779. ];
  18780. function CFFParser(file, properties) {
  18781. this.bytes = file.getBytes();
  18782. this.properties = properties;
  18783. }
  18784. CFFParser.prototype = {
  18785. parse: function CFFParser_parse() {
  18786. var properties = this.properties;
  18787. var cff = new CFF();
  18788. this.cff = cff;
  18789. // The first five sections must be in order, all the others are reached
  18790. // via offsets contained in one of the below.
  18791. var header = this.parseHeader();
  18792. var nameIndex = this.parseIndex(header.endPos);
  18793. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18794. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18795. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18796. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18797. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18798. cff.header = header.obj;
  18799. cff.names = this.parseNameIndex(nameIndex.obj);
  18800. cff.strings = this.parseStringIndex(stringIndex.obj);
  18801. cff.topDict = topDict;
  18802. cff.globalSubrIndex = globalSubrIndex.obj;
  18803. this.parsePrivateDict(cff.topDict);
  18804. cff.isCIDFont = topDict.hasName('ROS');
  18805. var charStringOffset = topDict.getByName('CharStrings');
  18806. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18807. cff.charStrings = charStringsAndSeacs.charStrings;
  18808. cff.seacs = charStringsAndSeacs.seacs;
  18809. cff.widths = charStringsAndSeacs.widths;
  18810. var fontMatrix = topDict.getByName('FontMatrix');
  18811. if (fontMatrix) {
  18812. properties.fontMatrix = fontMatrix;
  18813. }
  18814. var fontBBox = topDict.getByName('FontBBox');
  18815. if (fontBBox) {
  18816. // adjusting ascent/descent
  18817. properties.ascent = fontBBox[3];
  18818. properties.descent = fontBBox[1];
  18819. properties.ascentScaled = true;
  18820. }
  18821. var charset, encoding;
  18822. if (cff.isCIDFont) {
  18823. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18824. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18825. var dictRaw = fdArrayIndex.get(i);
  18826. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18827. cff.strings);
  18828. this.parsePrivateDict(fontDict);
  18829. cff.fdArray.push(fontDict);
  18830. }
  18831. // cid fonts don't have an encoding
  18832. encoding = null;
  18833. charset = this.parseCharsets(topDict.getByName('charset'),
  18834. cff.charStrings.count, cff.strings, true);
  18835. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18836. cff.charStrings.count);
  18837. } else {
  18838. charset = this.parseCharsets(topDict.getByName('charset'),
  18839. cff.charStrings.count, cff.strings, false);
  18840. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18841. properties,
  18842. cff.strings, charset.charset);
  18843. }
  18844. cff.charset = charset;
  18845. cff.encoding = encoding;
  18846. return cff;
  18847. },
  18848. parseHeader: function CFFParser_parseHeader() {
  18849. var bytes = this.bytes;
  18850. var bytesLength = bytes.length;
  18851. var offset = 0;
  18852. // Prevent an infinite loop, by checking that the offset is within the
  18853. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18854. while (offset < bytesLength && bytes[offset] !== 1) {
  18855. ++offset;
  18856. }
  18857. if (offset >= bytesLength) {
  18858. error('Invalid CFF header');
  18859. } else if (offset !== 0) {
  18860. info('cff data is shifted');
  18861. bytes = bytes.subarray(offset);
  18862. this.bytes = bytes;
  18863. }
  18864. var major = bytes[0];
  18865. var minor = bytes[1];
  18866. var hdrSize = bytes[2];
  18867. var offSize = bytes[3];
  18868. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18869. return { obj: header, endPos: hdrSize };
  18870. },
  18871. parseDict: function CFFParser_parseDict(dict) {
  18872. var pos = 0;
  18873. function parseOperand() {
  18874. var value = dict[pos++];
  18875. if (value === 30) {
  18876. return parseFloatOperand(pos);
  18877. } else if (value === 28) {
  18878. value = dict[pos++];
  18879. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18880. return value;
  18881. } else if (value === 29) {
  18882. value = dict[pos++];
  18883. value = (value << 8) | dict[pos++];
  18884. value = (value << 8) | dict[pos++];
  18885. value = (value << 8) | dict[pos++];
  18886. return value;
  18887. } else if (value >= 32 && value <= 246) {
  18888. return value - 139;
  18889. } else if (value >= 247 && value <= 250) {
  18890. return ((value - 247) * 256) + dict[pos++] + 108;
  18891. } else if (value >= 251 && value <= 254) {
  18892. return -((value - 251) * 256) - dict[pos++] - 108;
  18893. } else {
  18894. error('255 is not a valid DICT command');
  18895. }
  18896. return -1;
  18897. }
  18898. function parseFloatOperand() {
  18899. var str = '';
  18900. var eof = 15;
  18901. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18902. '9', '.', 'E', 'E-', null, '-'];
  18903. var length = dict.length;
  18904. while (pos < length) {
  18905. var b = dict[pos++];
  18906. var b1 = b >> 4;
  18907. var b2 = b & 15;
  18908. if (b1 === eof) {
  18909. break;
  18910. }
  18911. str += lookup[b1];
  18912. if (b2 === eof) {
  18913. break;
  18914. }
  18915. str += lookup[b2];
  18916. }
  18917. return parseFloat(str);
  18918. }
  18919. var operands = [];
  18920. var entries = [];
  18921. pos = 0;
  18922. var end = dict.length;
  18923. while (pos < end) {
  18924. var b = dict[pos];
  18925. if (b <= 21) {
  18926. if (b === 12) {
  18927. b = (b << 8) | dict[++pos];
  18928. }
  18929. entries.push([b, operands]);
  18930. operands = [];
  18931. ++pos;
  18932. } else {
  18933. operands.push(parseOperand());
  18934. }
  18935. }
  18936. return entries;
  18937. },
  18938. parseIndex: function CFFParser_parseIndex(pos) {
  18939. var cffIndex = new CFFIndex();
  18940. var bytes = this.bytes;
  18941. var count = (bytes[pos++] << 8) | bytes[pos++];
  18942. var offsets = [];
  18943. var end = pos;
  18944. var i, ii;
  18945. if (count !== 0) {
  18946. var offsetSize = bytes[pos++];
  18947. // add 1 for offset to determine size of last object
  18948. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18949. for (i = 0, ii = count + 1; i < ii; ++i) {
  18950. var offset = 0;
  18951. for (var j = 0; j < offsetSize; ++j) {
  18952. offset <<= 8;
  18953. offset += bytes[pos++];
  18954. }
  18955. offsets.push(startPos + offset);
  18956. }
  18957. end = offsets[count];
  18958. }
  18959. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18960. var offsetStart = offsets[i];
  18961. var offsetEnd = offsets[i + 1];
  18962. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18963. }
  18964. return {obj: cffIndex, endPos: end};
  18965. },
  18966. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18967. var names = [];
  18968. for (var i = 0, ii = index.count; i < ii; ++i) {
  18969. var name = index.get(i);
  18970. // OTS doesn't allow names to be over 127 characters.
  18971. var length = Math.min(name.length, 127);
  18972. var data = [];
  18973. // OTS also only permits certain characters in the name.
  18974. for (var j = 0; j < length; ++j) {
  18975. var c = name[j];
  18976. if (j === 0 && c === 0) {
  18977. data[j] = c;
  18978. continue;
  18979. }
  18980. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18981. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18982. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18983. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18984. data[j] = 95;
  18985. continue;
  18986. }
  18987. data[j] = c;
  18988. }
  18989. names.push(bytesToString(data));
  18990. }
  18991. return names;
  18992. },
  18993. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18994. var strings = new CFFStrings();
  18995. for (var i = 0, ii = index.count; i < ii; ++i) {
  18996. var data = index.get(i);
  18997. strings.add(bytesToString(data));
  18998. }
  18999. return strings;
  19000. },
  19001. createDict: function CFFParser_createDict(Type, dict, strings) {
  19002. var cffDict = new Type(strings);
  19003. for (var i = 0, ii = dict.length; i < ii; ++i) {
  19004. var pair = dict[i];
  19005. var key = pair[0];
  19006. var value = pair[1];
  19007. cffDict.setByKey(key, value);
  19008. }
  19009. return cffDict;
  19010. },
  19011. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  19012. var charStrings = this.parseIndex(charStringOffset).obj;
  19013. var seacs = [];
  19014. var widths = [];
  19015. var count = charStrings.count;
  19016. for (var i = 0; i < count; i++) {
  19017. var charstring = charStrings.get(i);
  19018. var stackSize = 0;
  19019. var stack = [];
  19020. var undefStack = true;
  19021. var hints = 0;
  19022. var valid = true;
  19023. var data = charstring;
  19024. var length = data.length;
  19025. var firstStackClearing = true;
  19026. for (var j = 0; j < length;) {
  19027. var value = data[j++];
  19028. var validationCommand = null;
  19029. if (value === 12) {
  19030. var q = data[j++];
  19031. if (q === 0) {
  19032. // The CFF specification state that the 'dotsection' command
  19033. // (12, 0) is deprecated and treated as a no-op, but all Type2
  19034. // charstrings processors should support them. Unfortunately
  19035. // the font sanitizer don't. As a workaround the sequence (12, 0)
  19036. // is replaced by a useless (0, hmoveto).
  19037. data[j - 2] = 139;
  19038. data[j - 1] = 22;
  19039. stackSize = 0;
  19040. } else {
  19041. validationCommand = CharstringValidationData12[q];
  19042. }
  19043. } else if (value === 28) { // number (16 bit)
  19044. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  19045. j += 2;
  19046. stackSize++;
  19047. } else if (value === 14) {
  19048. if (stackSize >= 4) {
  19049. stackSize -= 4;
  19050. if (SEAC_ANALYSIS_ENABLED) {
  19051. seacs[i] = stack.slice(stackSize, stackSize + 4);
  19052. valid = false;
  19053. }
  19054. }
  19055. validationCommand = CharstringValidationData[value];
  19056. } else if (value >= 32 && value <= 246) { // number
  19057. stack[stackSize] = value - 139;
  19058. stackSize++;
  19059. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  19060. stack[stackSize] = (value < 251 ?
  19061. ((value - 247) << 8) + data[j] + 108 :
  19062. -((value - 251) << 8) - data[j] - 108);
  19063. j++;
  19064. stackSize++;
  19065. } else if (value === 255) { // number (32 bit)
  19066. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  19067. (data[j + 2] << 8) | data[j + 3]) / 65536;
  19068. j += 4;
  19069. stackSize++;
  19070. } else if (value === 19 || value === 20) {
  19071. hints += stackSize >> 1;
  19072. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  19073. stackSize %= 2;
  19074. validationCommand = CharstringValidationData[value];
  19075. } else {
  19076. validationCommand = CharstringValidationData[value];
  19077. }
  19078. if (validationCommand) {
  19079. if (validationCommand.stem) {
  19080. hints += stackSize >> 1;
  19081. }
  19082. if ('min' in validationCommand) {
  19083. if (!undefStack && stackSize < validationCommand.min) {
  19084. warn('Not enough parameters for ' + validationCommand.id +
  19085. '; actual: ' + stackSize +
  19086. ', expected: ' + validationCommand.min);
  19087. valid = false;
  19088. break;
  19089. }
  19090. }
  19091. if (firstStackClearing && validationCommand.stackClearing) {
  19092. firstStackClearing = false;
  19093. // the optional character width can be found before the first
  19094. // stack-clearing command arguments
  19095. stackSize -= validationCommand.min;
  19096. if (stackSize >= 2 && validationCommand.stem) {
  19097. // there are even amount of arguments for stem commands
  19098. stackSize %= 2;
  19099. } else if (stackSize > 1) {
  19100. warn('Found too many parameters for stack-clearing command');
  19101. }
  19102. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  19103. widths[i] = stack[stackSize - 1];
  19104. }
  19105. }
  19106. if ('stackDelta' in validationCommand) {
  19107. if ('stackFn' in validationCommand) {
  19108. validationCommand.stackFn(stack, stackSize);
  19109. }
  19110. stackSize += validationCommand.stackDelta;
  19111. } else if (validationCommand.stackClearing) {
  19112. stackSize = 0;
  19113. } else if (validationCommand.resetStack) {
  19114. stackSize = 0;
  19115. undefStack = false;
  19116. } else if (validationCommand.undefStack) {
  19117. stackSize = 0;
  19118. undefStack = true;
  19119. firstStackClearing = false;
  19120. }
  19121. }
  19122. }
  19123. if (!valid) {
  19124. // resetting invalid charstring to single 'endchar'
  19125. charStrings.set(i, new Uint8Array([14]));
  19126. }
  19127. }
  19128. return { charStrings: charStrings, seacs: seacs, widths: widths };
  19129. },
  19130. emptyPrivateDictionary:
  19131. function CFFParser_emptyPrivateDictionary(parentDict) {
  19132. var privateDict = this.createDict(CFFPrivateDict, [],
  19133. parentDict.strings);
  19134. parentDict.setByKey(18, [0, 0]);
  19135. parentDict.privateDict = privateDict;
  19136. },
  19137. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  19138. // no private dict, do nothing
  19139. if (!parentDict.hasName('Private')) {
  19140. this.emptyPrivateDictionary(parentDict);
  19141. return;
  19142. }
  19143. var privateOffset = parentDict.getByName('Private');
  19144. // make sure the params are formatted correctly
  19145. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  19146. parentDict.removeByName('Private');
  19147. return;
  19148. }
  19149. var size = privateOffset[0];
  19150. var offset = privateOffset[1];
  19151. // remove empty dicts or ones that refer to invalid location
  19152. if (size === 0 || offset >= this.bytes.length) {
  19153. this.emptyPrivateDictionary(parentDict);
  19154. return;
  19155. }
  19156. var privateDictEnd = offset + size;
  19157. var dictData = this.bytes.subarray(offset, privateDictEnd);
  19158. var dict = this.parseDict(dictData);
  19159. var privateDict = this.createDict(CFFPrivateDict, dict,
  19160. parentDict.strings);
  19161. parentDict.privateDict = privateDict;
  19162. // Parse the Subrs index also since it's relative to the private dict.
  19163. if (!privateDict.getByName('Subrs')) {
  19164. return;
  19165. }
  19166. var subrsOffset = privateDict.getByName('Subrs');
  19167. var relativeOffset = offset + subrsOffset;
  19168. // Validate the offset.
  19169. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  19170. this.emptyPrivateDictionary(parentDict);
  19171. return;
  19172. }
  19173. var subrsIndex = this.parseIndex(relativeOffset);
  19174. privateDict.subrsIndex = subrsIndex.obj;
  19175. },
  19176. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  19177. if (pos === 0) {
  19178. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  19179. ISOAdobeCharset);
  19180. } else if (pos === 1) {
  19181. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  19182. ExpertCharset);
  19183. } else if (pos === 2) {
  19184. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  19185. ExpertSubsetCharset);
  19186. }
  19187. var bytes = this.bytes;
  19188. var start = pos;
  19189. var format = bytes[pos++];
  19190. var charset = ['.notdef'];
  19191. var id, count, i;
  19192. // subtract 1 for the .notdef glyph
  19193. length -= 1;
  19194. switch (format) {
  19195. case 0:
  19196. for (i = 0; i < length; i++) {
  19197. id = (bytes[pos++] << 8) | bytes[pos++];
  19198. charset.push(cid ? id : strings.get(id));
  19199. }
  19200. break;
  19201. case 1:
  19202. while (charset.length <= length) {
  19203. id = (bytes[pos++] << 8) | bytes[pos++];
  19204. count = bytes[pos++];
  19205. for (i = 0; i <= count; i++) {
  19206. charset.push(cid ? id++ : strings.get(id++));
  19207. }
  19208. }
  19209. break;
  19210. case 2:
  19211. while (charset.length <= length) {
  19212. id = (bytes[pos++] << 8) | bytes[pos++];
  19213. count = (bytes[pos++] << 8) | bytes[pos++];
  19214. for (i = 0; i <= count; i++) {
  19215. charset.push(cid ? id++ : strings.get(id++));
  19216. }
  19217. }
  19218. break;
  19219. default:
  19220. error('Unknown charset format');
  19221. }
  19222. // Raw won't be needed if we actually compile the charset.
  19223. var end = pos;
  19224. var raw = bytes.subarray(start, end);
  19225. return new CFFCharset(false, format, charset, raw);
  19226. },
  19227. parseEncoding: function CFFParser_parseEncoding(pos,
  19228. properties,
  19229. strings,
  19230. charset) {
  19231. var encoding = {};
  19232. var bytes = this.bytes;
  19233. var predefined = false;
  19234. var hasSupplement = false;
  19235. var format, i, ii;
  19236. var raw = null;
  19237. function readSupplement() {
  19238. var supplementsCount = bytes[pos++];
  19239. for (i = 0; i < supplementsCount; i++) {
  19240. var code = bytes[pos++];
  19241. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  19242. encoding[code] = charset.indexOf(strings.get(sid));
  19243. }
  19244. }
  19245. if (pos === 0 || pos === 1) {
  19246. predefined = true;
  19247. format = pos;
  19248. var baseEncoding = pos ? Encodings.ExpertEncoding :
  19249. Encodings.StandardEncoding;
  19250. for (i = 0, ii = charset.length; i < ii; i++) {
  19251. var index = baseEncoding.indexOf(charset[i]);
  19252. if (index !== -1) {
  19253. encoding[index] = i;
  19254. }
  19255. }
  19256. } else {
  19257. var dataStart = pos;
  19258. format = bytes[pos++];
  19259. switch (format & 0x7f) {
  19260. case 0:
  19261. var glyphsCount = bytes[pos++];
  19262. for (i = 1; i <= glyphsCount; i++) {
  19263. encoding[bytes[pos++]] = i;
  19264. }
  19265. break;
  19266. case 1:
  19267. var rangesCount = bytes[pos++];
  19268. var gid = 1;
  19269. for (i = 0; i < rangesCount; i++) {
  19270. var start = bytes[pos++];
  19271. var left = bytes[pos++];
  19272. for (var j = start; j <= start + left; j++) {
  19273. encoding[j] = gid++;
  19274. }
  19275. }
  19276. break;
  19277. default:
  19278. error('Unknow encoding format: ' + format + ' in CFF');
  19279. break;
  19280. }
  19281. var dataEnd = pos;
  19282. if (format & 0x80) {
  19283. // The font sanitizer does not support CFF encoding with a
  19284. // supplement, since the encoding is not really used to map
  19285. // between gid to glyph, let's overwrite what is declared in
  19286. // the top dictionary to let the sanitizer think the font use
  19287. // StandardEncoding, that's a lie but that's ok.
  19288. bytes[dataStart] &= 0x7f;
  19289. readSupplement();
  19290. hasSupplement = true;
  19291. }
  19292. raw = bytes.subarray(dataStart, dataEnd);
  19293. }
  19294. format = format & 0x7f;
  19295. return new CFFEncoding(predefined, format, encoding, raw);
  19296. },
  19297. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19298. var start = pos;
  19299. var bytes = this.bytes;
  19300. var format = bytes[pos++];
  19301. var fdSelect = [];
  19302. var i;
  19303. switch (format) {
  19304. case 0:
  19305. for (i = 0; i < length; ++i) {
  19306. var id = bytes[pos++];
  19307. fdSelect.push(id);
  19308. }
  19309. break;
  19310. case 3:
  19311. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19312. for (i = 0; i < rangesCount; ++i) {
  19313. var first = (bytes[pos++] << 8) | bytes[pos++];
  19314. var fdIndex = bytes[pos++];
  19315. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19316. for (var j = first; j < next; ++j) {
  19317. fdSelect.push(fdIndex);
  19318. }
  19319. }
  19320. // Advance past the sentinel(next).
  19321. pos += 2;
  19322. break;
  19323. default:
  19324. error('Unknown fdselect format ' + format);
  19325. break;
  19326. }
  19327. var end = pos;
  19328. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19329. }
  19330. };
  19331. return CFFParser;
  19332. })();
  19333. // Compact Font Format
  19334. var CFF = (function CFFClosure() {
  19335. function CFF() {
  19336. this.header = null;
  19337. this.names = [];
  19338. this.topDict = null;
  19339. this.strings = new CFFStrings();
  19340. this.globalSubrIndex = null;
  19341. // The following could really be per font, but since we only have one font
  19342. // store them here.
  19343. this.encoding = null;
  19344. this.charset = null;
  19345. this.charStrings = null;
  19346. this.fdArray = [];
  19347. this.fdSelect = null;
  19348. this.isCIDFont = false;
  19349. }
  19350. return CFF;
  19351. })();
  19352. var CFFHeader = (function CFFHeaderClosure() {
  19353. function CFFHeader(major, minor, hdrSize, offSize) {
  19354. this.major = major;
  19355. this.minor = minor;
  19356. this.hdrSize = hdrSize;
  19357. this.offSize = offSize;
  19358. }
  19359. return CFFHeader;
  19360. })();
  19361. var CFFStrings = (function CFFStringsClosure() {
  19362. function CFFStrings() {
  19363. this.strings = [];
  19364. }
  19365. CFFStrings.prototype = {
  19366. get: function CFFStrings_get(index) {
  19367. if (index >= 0 && index <= 390) {
  19368. return CFFStandardStrings[index];
  19369. }
  19370. if (index - 391 <= this.strings.length) {
  19371. return this.strings[index - 391];
  19372. }
  19373. return CFFStandardStrings[0];
  19374. },
  19375. add: function CFFStrings_add(value) {
  19376. this.strings.push(value);
  19377. },
  19378. get count() {
  19379. return this.strings.length;
  19380. }
  19381. };
  19382. return CFFStrings;
  19383. })();
  19384. var CFFIndex = (function CFFIndexClosure() {
  19385. function CFFIndex() {
  19386. this.objects = [];
  19387. this.length = 0;
  19388. }
  19389. CFFIndex.prototype = {
  19390. add: function CFFIndex_add(data) {
  19391. this.length += data.length;
  19392. this.objects.push(data);
  19393. },
  19394. set: function CFFIndex_set(index, data) {
  19395. this.length += data.length - this.objects[index].length;
  19396. this.objects[index] = data;
  19397. },
  19398. get: function CFFIndex_get(index) {
  19399. return this.objects[index];
  19400. },
  19401. get count() {
  19402. return this.objects.length;
  19403. }
  19404. };
  19405. return CFFIndex;
  19406. })();
  19407. var CFFDict = (function CFFDictClosure() {
  19408. function CFFDict(tables, strings) {
  19409. this.keyToNameMap = tables.keyToNameMap;
  19410. this.nameToKeyMap = tables.nameToKeyMap;
  19411. this.defaults = tables.defaults;
  19412. this.types = tables.types;
  19413. this.opcodes = tables.opcodes;
  19414. this.order = tables.order;
  19415. this.strings = strings;
  19416. this.values = {};
  19417. }
  19418. CFFDict.prototype = {
  19419. // value should always be an array
  19420. setByKey: function CFFDict_setByKey(key, value) {
  19421. if (!(key in this.keyToNameMap)) {
  19422. return false;
  19423. }
  19424. // ignore empty values
  19425. if (value.length === 0) {
  19426. return true;
  19427. }
  19428. var type = this.types[key];
  19429. // remove the array wrapping these types of values
  19430. if (type === 'num' || type === 'sid' || type === 'offset') {
  19431. value = value[0];
  19432. }
  19433. this.values[key] = value;
  19434. return true;
  19435. },
  19436. setByName: function CFFDict_setByName(name, value) {
  19437. if (!(name in this.nameToKeyMap)) {
  19438. error('Invalid dictionary name "' + name + '"');
  19439. }
  19440. this.values[this.nameToKeyMap[name]] = value;
  19441. },
  19442. hasName: function CFFDict_hasName(name) {
  19443. return this.nameToKeyMap[name] in this.values;
  19444. },
  19445. getByName: function CFFDict_getByName(name) {
  19446. if (!(name in this.nameToKeyMap)) {
  19447. error('Invalid dictionary name "' + name + '"');
  19448. }
  19449. var key = this.nameToKeyMap[name];
  19450. if (!(key in this.values)) {
  19451. return this.defaults[key];
  19452. }
  19453. return this.values[key];
  19454. },
  19455. removeByName: function CFFDict_removeByName(name) {
  19456. delete this.values[this.nameToKeyMap[name]];
  19457. }
  19458. };
  19459. CFFDict.createTables = function CFFDict_createTables(layout) {
  19460. var tables = {
  19461. keyToNameMap: {},
  19462. nameToKeyMap: {},
  19463. defaults: {},
  19464. types: {},
  19465. opcodes: {},
  19466. order: []
  19467. };
  19468. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19469. var entry = layout[i];
  19470. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19471. tables.keyToNameMap[key] = entry[1];
  19472. tables.nameToKeyMap[entry[1]] = key;
  19473. tables.types[key] = entry[2];
  19474. tables.defaults[key] = entry[3];
  19475. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19476. tables.order.push(key);
  19477. }
  19478. return tables;
  19479. };
  19480. return CFFDict;
  19481. })();
  19482. var CFFTopDict = (function CFFTopDictClosure() {
  19483. var layout = [
  19484. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19485. [[12, 20], 'SyntheticBase', 'num', null],
  19486. [0, 'version', 'sid', null],
  19487. [1, 'Notice', 'sid', null],
  19488. [[12, 0], 'Copyright', 'sid', null],
  19489. [2, 'FullName', 'sid', null],
  19490. [3, 'FamilyName', 'sid', null],
  19491. [4, 'Weight', 'sid', null],
  19492. [[12, 1], 'isFixedPitch', 'num', 0],
  19493. [[12, 2], 'ItalicAngle', 'num', 0],
  19494. [[12, 3], 'UnderlinePosition', 'num', -100],
  19495. [[12, 4], 'UnderlineThickness', 'num', 50],
  19496. [[12, 5], 'PaintType', 'num', 0],
  19497. [[12, 6], 'CharstringType', 'num', 2],
  19498. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19499. [0.001, 0, 0, 0.001, 0, 0]],
  19500. [13, 'UniqueID', 'num', null],
  19501. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19502. [[12, 8], 'StrokeWidth', 'num', 0],
  19503. [14, 'XUID', 'array', null],
  19504. [15, 'charset', 'offset', 0],
  19505. [16, 'Encoding', 'offset', 0],
  19506. [17, 'CharStrings', 'offset', 0],
  19507. [18, 'Private', ['offset', 'offset'], null],
  19508. [[12, 21], 'PostScript', 'sid', null],
  19509. [[12, 22], 'BaseFontName', 'sid', null],
  19510. [[12, 23], 'BaseFontBlend', 'delta', null],
  19511. [[12, 31], 'CIDFontVersion', 'num', 0],
  19512. [[12, 32], 'CIDFontRevision', 'num', 0],
  19513. [[12, 33], 'CIDFontType', 'num', 0],
  19514. [[12, 34], 'CIDCount', 'num', 8720],
  19515. [[12, 35], 'UIDBase', 'num', null],
  19516. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19517. // before FDArray.
  19518. [[12, 37], 'FDSelect', 'offset', null],
  19519. [[12, 36], 'FDArray', 'offset', null],
  19520. [[12, 38], 'FontName', 'sid', null]
  19521. ];
  19522. var tables = null;
  19523. function CFFTopDict(strings) {
  19524. if (tables === null) {
  19525. tables = CFFDict.createTables(layout);
  19526. }
  19527. CFFDict.call(this, tables, strings);
  19528. this.privateDict = null;
  19529. }
  19530. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19531. return CFFTopDict;
  19532. })();
  19533. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19534. var layout = [
  19535. [6, 'BlueValues', 'delta', null],
  19536. [7, 'OtherBlues', 'delta', null],
  19537. [8, 'FamilyBlues', 'delta', null],
  19538. [9, 'FamilyOtherBlues', 'delta', null],
  19539. [[12, 9], 'BlueScale', 'num', 0.039625],
  19540. [[12, 10], 'BlueShift', 'num', 7],
  19541. [[12, 11], 'BlueFuzz', 'num', 1],
  19542. [10, 'StdHW', 'num', null],
  19543. [11, 'StdVW', 'num', null],
  19544. [[12, 12], 'StemSnapH', 'delta', null],
  19545. [[12, 13], 'StemSnapV', 'delta', null],
  19546. [[12, 14], 'ForceBold', 'num', 0],
  19547. [[12, 17], 'LanguageGroup', 'num', 0],
  19548. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19549. [[12, 19], 'initialRandomSeed', 'num', 0],
  19550. [20, 'defaultWidthX', 'num', 0],
  19551. [21, 'nominalWidthX', 'num', 0],
  19552. [19, 'Subrs', 'offset', null]
  19553. ];
  19554. var tables = null;
  19555. function CFFPrivateDict(strings) {
  19556. if (tables === null) {
  19557. tables = CFFDict.createTables(layout);
  19558. }
  19559. CFFDict.call(this, tables, strings);
  19560. this.subrsIndex = null;
  19561. }
  19562. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19563. return CFFPrivateDict;
  19564. })();
  19565. var CFFCharsetPredefinedTypes = {
  19566. ISO_ADOBE: 0,
  19567. EXPERT: 1,
  19568. EXPERT_SUBSET: 2
  19569. };
  19570. var CFFCharset = (function CFFCharsetClosure() {
  19571. function CFFCharset(predefined, format, charset, raw) {
  19572. this.predefined = predefined;
  19573. this.format = format;
  19574. this.charset = charset;
  19575. this.raw = raw;
  19576. }
  19577. return CFFCharset;
  19578. })();
  19579. var CFFEncoding = (function CFFEncodingClosure() {
  19580. function CFFEncoding(predefined, format, encoding, raw) {
  19581. this.predefined = predefined;
  19582. this.format = format;
  19583. this.encoding = encoding;
  19584. this.raw = raw;
  19585. }
  19586. return CFFEncoding;
  19587. })();
  19588. var CFFFDSelect = (function CFFFDSelectClosure() {
  19589. function CFFFDSelect(fdSelect, raw) {
  19590. this.fdSelect = fdSelect;
  19591. this.raw = raw;
  19592. }
  19593. return CFFFDSelect;
  19594. })();
  19595. // Helper class to keep track of where an offset is within the data and helps
  19596. // filling in that offset once it's known.
  19597. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19598. function CFFOffsetTracker() {
  19599. this.offsets = {};
  19600. }
  19601. CFFOffsetTracker.prototype = {
  19602. isTracking: function CFFOffsetTracker_isTracking(key) {
  19603. return key in this.offsets;
  19604. },
  19605. track: function CFFOffsetTracker_track(key, location) {
  19606. if (key in this.offsets) {
  19607. error('Already tracking location of ' + key);
  19608. }
  19609. this.offsets[key] = location;
  19610. },
  19611. offset: function CFFOffsetTracker_offset(value) {
  19612. for (var key in this.offsets) {
  19613. this.offsets[key] += value;
  19614. }
  19615. },
  19616. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19617. values,
  19618. output) {
  19619. if (!(key in this.offsets)) {
  19620. error('Not tracking location of ' + key);
  19621. }
  19622. var data = output.data;
  19623. var dataOffset = this.offsets[key];
  19624. var size = 5;
  19625. for (var i = 0, ii = values.length; i < ii; ++i) {
  19626. var offset0 = i * size + dataOffset;
  19627. var offset1 = offset0 + 1;
  19628. var offset2 = offset0 + 2;
  19629. var offset3 = offset0 + 3;
  19630. var offset4 = offset0 + 4;
  19631. // It's easy to screw up offsets so perform this sanity check.
  19632. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19633. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19634. error('writing to an offset that is not empty');
  19635. }
  19636. var value = values[i];
  19637. data[offset0] = 0x1d;
  19638. data[offset1] = (value >> 24) & 0xFF;
  19639. data[offset2] = (value >> 16) & 0xFF;
  19640. data[offset3] = (value >> 8) & 0xFF;
  19641. data[offset4] = value & 0xFF;
  19642. }
  19643. }
  19644. };
  19645. return CFFOffsetTracker;
  19646. })();
  19647. // Takes a CFF and converts it to the binary representation.
  19648. var CFFCompiler = (function CFFCompilerClosure() {
  19649. function CFFCompiler(cff) {
  19650. this.cff = cff;
  19651. }
  19652. CFFCompiler.prototype = {
  19653. compile: function CFFCompiler_compile() {
  19654. var cff = this.cff;
  19655. var output = {
  19656. data: [],
  19657. length: 0,
  19658. add: function CFFCompiler_add(data) {
  19659. this.data = this.data.concat(data);
  19660. this.length = this.data.length;
  19661. }
  19662. };
  19663. // Compile the five entries that must be in order.
  19664. var header = this.compileHeader(cff.header);
  19665. output.add(header);
  19666. var nameIndex = this.compileNameIndex(cff.names);
  19667. output.add(nameIndex);
  19668. if (cff.isCIDFont) {
  19669. // The spec is unclear on how font matrices should relate to each other
  19670. // when there is one in the main top dict and the sub top dicts.
  19671. // Windows handles this differently than linux and osx so we have to
  19672. // normalize to work on all.
  19673. // Rules based off of some mailing list discussions:
  19674. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19675. // - If no main font matrix and there is a subfont matrix, use the
  19676. // subfont matrix.
  19677. // - If both have matrices, concat together.
  19678. // - If neither have matrices, use default.
  19679. // To make this work on all platforms we move the top matrix into each
  19680. // sub top dict and concat if necessary.
  19681. if (cff.topDict.hasName('FontMatrix')) {
  19682. var base = cff.topDict.getByName('FontMatrix');
  19683. cff.topDict.removeByName('FontMatrix');
  19684. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19685. var subDict = cff.fdArray[i];
  19686. var matrix = base.slice(0);
  19687. if (subDict.hasName('FontMatrix')) {
  19688. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19689. }
  19690. subDict.setByName('FontMatrix', matrix);
  19691. }
  19692. }
  19693. }
  19694. var compiled = this.compileTopDicts([cff.topDict],
  19695. output.length,
  19696. cff.isCIDFont);
  19697. output.add(compiled.output);
  19698. var topDictTracker = compiled.trackers[0];
  19699. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19700. output.add(stringIndex);
  19701. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19702. output.add(globalSubrIndex);
  19703. // Now start on the other entries that have no specfic order.
  19704. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19705. if (cff.encoding.predefined) {
  19706. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19707. output);
  19708. } else {
  19709. var encoding = this.compileEncoding(cff.encoding);
  19710. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19711. output.add(encoding);
  19712. }
  19713. }
  19714. if (cff.charset && cff.topDict.hasName('charset')) {
  19715. if (cff.charset.predefined) {
  19716. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19717. output);
  19718. } else {
  19719. var charset = this.compileCharset(cff.charset);
  19720. topDictTracker.setEntryLocation('charset', [output.length], output);
  19721. output.add(charset);
  19722. }
  19723. }
  19724. var charStrings = this.compileCharStrings(cff.charStrings);
  19725. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19726. output.add(charStrings);
  19727. if (cff.isCIDFont) {
  19728. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19729. // and linux don't seem to care.
  19730. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19731. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19732. output.add(fdSelect);
  19733. // It is unclear if the sub font dictionary can have CID related
  19734. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19735. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19736. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19737. output.add(compiled.output);
  19738. var fontDictTrackers = compiled.trackers;
  19739. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19740. }
  19741. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19742. // If the font data ends with INDEX whose object data is zero-length,
  19743. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19744. output.add([0]);
  19745. return output.data;
  19746. },
  19747. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19748. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19749. return this.encodeInteger(value);
  19750. } else {
  19751. return this.encodeFloat(value);
  19752. }
  19753. },
  19754. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19755. var value = num.toString();
  19756. // rounding inaccurate doubles
  19757. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19758. if (m) {
  19759. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19760. value = (Math.round(num * epsilon) / epsilon).toString();
  19761. }
  19762. var nibbles = '';
  19763. var i, ii;
  19764. for (i = 0, ii = value.length; i < ii; ++i) {
  19765. var a = value[i];
  19766. if (a === 'e') {
  19767. nibbles += value[++i] === '-' ? 'c' : 'b';
  19768. } else if (a === '.') {
  19769. nibbles += 'a';
  19770. } else if (a === '-') {
  19771. nibbles += 'e';
  19772. } else {
  19773. nibbles += a;
  19774. }
  19775. }
  19776. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19777. var out = [30];
  19778. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19779. out.push(parseInt(nibbles.substr(i, 2), 16));
  19780. }
  19781. return out;
  19782. },
  19783. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19784. var code;
  19785. if (value >= -107 && value <= 107) {
  19786. code = [value + 139];
  19787. } else if (value >= 108 && value <= 1131) {
  19788. value = [value - 108];
  19789. code = [(value >> 8) + 247, value & 0xFF];
  19790. } else if (value >= -1131 && value <= -108) {
  19791. value = -value - 108;
  19792. code = [(value >> 8) + 251, value & 0xFF];
  19793. } else if (value >= -32768 && value <= 32767) {
  19794. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19795. } else {
  19796. code = [0x1d,
  19797. (value >> 24) & 0xFF,
  19798. (value >> 16) & 0xFF,
  19799. (value >> 8) & 0xFF,
  19800. value & 0xFF];
  19801. }
  19802. return code;
  19803. },
  19804. compileHeader: function CFFCompiler_compileHeader(header) {
  19805. return [
  19806. header.major,
  19807. header.minor,
  19808. header.hdrSize,
  19809. header.offSize
  19810. ];
  19811. },
  19812. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19813. var nameIndex = new CFFIndex();
  19814. for (var i = 0, ii = names.length; i < ii; ++i) {
  19815. nameIndex.add(stringToBytes(names[i]));
  19816. }
  19817. return this.compileIndex(nameIndex);
  19818. },
  19819. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19820. length,
  19821. removeCidKeys) {
  19822. var fontDictTrackers = [];
  19823. var fdArrayIndex = new CFFIndex();
  19824. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19825. var fontDict = dicts[i];
  19826. if (removeCidKeys) {
  19827. fontDict.removeByName('CIDFontVersion');
  19828. fontDict.removeByName('CIDFontRevision');
  19829. fontDict.removeByName('CIDFontType');
  19830. fontDict.removeByName('CIDCount');
  19831. fontDict.removeByName('UIDBase');
  19832. }
  19833. var fontDictTracker = new CFFOffsetTracker();
  19834. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19835. fontDictTrackers.push(fontDictTracker);
  19836. fdArrayIndex.add(fontDictData);
  19837. fontDictTracker.offset(length);
  19838. }
  19839. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19840. return {
  19841. trackers: fontDictTrackers,
  19842. output: fdArrayIndex
  19843. };
  19844. },
  19845. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19846. trackers,
  19847. output) {
  19848. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19849. var fontDict = dicts[i];
  19850. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19851. 'There must be an private dictionary.');
  19852. var privateDict = fontDict.privateDict;
  19853. var privateDictTracker = new CFFOffsetTracker();
  19854. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19855. var outputLength = output.length;
  19856. privateDictTracker.offset(outputLength);
  19857. if (!privateDictData.length) {
  19858. // The private dictionary was empty, set the output length to zero to
  19859. // ensure the offset length isn't out of bounds in the eyes of the
  19860. // sanitizer.
  19861. outputLength = 0;
  19862. }
  19863. trackers[i].setEntryLocation('Private',
  19864. [privateDictData.length, outputLength],
  19865. output);
  19866. output.add(privateDictData);
  19867. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19868. var subrs = this.compileIndex(privateDict.subrsIndex);
  19869. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19870. output);
  19871. output.add(subrs);
  19872. }
  19873. }
  19874. },
  19875. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19876. var out = [];
  19877. // The dictionary keys must be in a certain order.
  19878. var order = dict.order;
  19879. for (var i = 0; i < order.length; ++i) {
  19880. var key = order[i];
  19881. if (!(key in dict.values)) {
  19882. continue;
  19883. }
  19884. var values = dict.values[key];
  19885. var types = dict.types[key];
  19886. if (!isArray(types)) {
  19887. types = [types];
  19888. }
  19889. if (!isArray(values)) {
  19890. values = [values];
  19891. }
  19892. // Remove any empty dict values.
  19893. if (values.length === 0) {
  19894. continue;
  19895. }
  19896. for (var j = 0, jj = types.length; j < jj; ++j) {
  19897. var type = types[j];
  19898. var value = values[j];
  19899. switch (type) {
  19900. case 'num':
  19901. case 'sid':
  19902. out = out.concat(this.encodeNumber(value));
  19903. break;
  19904. case 'offset':
  19905. // For offsets we just insert a 32bit integer so we don't have to
  19906. // deal with figuring out the length of the offset when it gets
  19907. // replaced later on by the compiler.
  19908. var name = dict.keyToNameMap[key];
  19909. // Some offsets have the offset and the length, so just record the
  19910. // position of the first one.
  19911. if (!offsetTracker.isTracking(name)) {
  19912. offsetTracker.track(name, out.length);
  19913. }
  19914. out = out.concat([0x1d, 0, 0, 0, 0]);
  19915. break;
  19916. case 'array':
  19917. case 'delta':
  19918. out = out.concat(this.encodeNumber(value));
  19919. for (var k = 1, kk = values.length; k < kk; ++k) {
  19920. out = out.concat(this.encodeNumber(values[k]));
  19921. }
  19922. break;
  19923. default:
  19924. error('Unknown data type of ' + type);
  19925. break;
  19926. }
  19927. }
  19928. out = out.concat(dict.opcodes[key]);
  19929. }
  19930. return out;
  19931. },
  19932. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19933. var stringIndex = new CFFIndex();
  19934. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19935. stringIndex.add(stringToBytes(strings[i]));
  19936. }
  19937. return this.compileIndex(stringIndex);
  19938. },
  19939. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19940. var globalSubrIndex = this.cff.globalSubrIndex;
  19941. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19942. },
  19943. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19944. return this.compileIndex(charStrings);
  19945. },
  19946. compileCharset: function CFFCompiler_compileCharset(charset) {
  19947. return this.compileTypedArray(charset.raw);
  19948. },
  19949. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19950. return this.compileTypedArray(encoding.raw);
  19951. },
  19952. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19953. return this.compileTypedArray(fdSelect);
  19954. },
  19955. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19956. var out = [];
  19957. for (var i = 0, ii = data.length; i < ii; ++i) {
  19958. out[i] = data[i];
  19959. }
  19960. return out;
  19961. },
  19962. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19963. trackers = trackers || [];
  19964. var objects = index.objects;
  19965. // First 2 bytes contains the number of objects contained into this index
  19966. var count = objects.length;
  19967. // If there is no object, just create an index. This technically
  19968. // should just be [0, 0] but OTS has an issue with that.
  19969. if (count === 0) {
  19970. return [0, 0, 0];
  19971. }
  19972. var data = [(count >> 8) & 0xFF, count & 0xff];
  19973. var lastOffset = 1, i;
  19974. for (i = 0; i < count; ++i) {
  19975. lastOffset += objects[i].length;
  19976. }
  19977. var offsetSize;
  19978. if (lastOffset < 0x100) {
  19979. offsetSize = 1;
  19980. } else if (lastOffset < 0x10000) {
  19981. offsetSize = 2;
  19982. } else if (lastOffset < 0x1000000) {
  19983. offsetSize = 3;
  19984. } else {
  19985. offsetSize = 4;
  19986. }
  19987. // Next byte contains the offset size use to reference object in the file
  19988. data.push(offsetSize);
  19989. // Add another offset after this one because we need a new offset
  19990. var relativeOffset = 1;
  19991. for (i = 0; i < count + 1; i++) {
  19992. if (offsetSize === 1) {
  19993. data.push(relativeOffset & 0xFF);
  19994. } else if (offsetSize === 2) {
  19995. data.push((relativeOffset >> 8) & 0xFF,
  19996. relativeOffset & 0xFF);
  19997. } else if (offsetSize === 3) {
  19998. data.push((relativeOffset >> 16) & 0xFF,
  19999. (relativeOffset >> 8) & 0xFF,
  20000. relativeOffset & 0xFF);
  20001. } else {
  20002. data.push((relativeOffset >>> 24) & 0xFF,
  20003. (relativeOffset >> 16) & 0xFF,
  20004. (relativeOffset >> 8) & 0xFF,
  20005. relativeOffset & 0xFF);
  20006. }
  20007. if (objects[i]) {
  20008. relativeOffset += objects[i].length;
  20009. }
  20010. }
  20011. for (i = 0; i < count; i++) {
  20012. // Notify the tracker where the object will be offset in the data.
  20013. if (trackers[i]) {
  20014. trackers[i].offset(data.length);
  20015. }
  20016. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  20017. data.push(objects[i][j]);
  20018. }
  20019. }
  20020. return data;
  20021. }
  20022. };
  20023. return CFFCompiler;
  20024. })();
  20025. // Workaround for seac on Windows.
  20026. (function checkSeacSupport() {
  20027. if (/Windows/.test(navigator.userAgent)) {
  20028. SEAC_ANALYSIS_ENABLED = true;
  20029. }
  20030. })();
  20031. // Workaround for Private Use Area characters in Chrome on Windows
  20032. // http://code.google.com/p/chromium/issues/detail?id=122465
  20033. // https://github.com/mozilla/pdf.js/issues/1689
  20034. (function checkChromeWindows() {
  20035. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  20036. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  20037. }
  20038. })();
  20039. var FontRendererFactory = (function FontRendererFactoryClosure() {
  20040. function getLong(data, offset) {
  20041. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20042. (data[offset + 2] << 8) | data[offset + 3];
  20043. }
  20044. function getUshort(data, offset) {
  20045. return (data[offset] << 8) | data[offset + 1];
  20046. }
  20047. function parseCmap(data, start, end) {
  20048. var offset = (getUshort(data, start + 2) === 1 ?
  20049. getLong(data, start + 8) : getLong(data, start + 16));
  20050. var format = getUshort(data, start + offset);
  20051. var length, ranges, p, i;
  20052. if (format === 4) {
  20053. length = getUshort(data, start + offset + 2);
  20054. var segCount = getUshort(data, start + offset + 6) >> 1;
  20055. p = start + offset + 14;
  20056. ranges = [];
  20057. for (i = 0; i < segCount; i++, p += 2) {
  20058. ranges[i] = {end: getUshort(data, p)};
  20059. }
  20060. p += 2;
  20061. for (i = 0; i < segCount; i++, p += 2) {
  20062. ranges[i].start = getUshort(data, p);
  20063. }
  20064. for (i = 0; i < segCount; i++, p += 2) {
  20065. ranges[i].idDelta = getUshort(data, p);
  20066. }
  20067. for (i = 0; i < segCount; i++, p += 2) {
  20068. var idOffset = getUshort(data, p);
  20069. if (idOffset === 0) {
  20070. continue;
  20071. }
  20072. ranges[i].ids = [];
  20073. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  20074. ranges[i].ids[j] = getUshort(data, p + idOffset);
  20075. idOffset += 2;
  20076. }
  20077. }
  20078. return ranges;
  20079. } else if (format === 12) {
  20080. length = getLong(data, start + offset + 4);
  20081. var groups = getLong(data, start + offset + 12);
  20082. p = start + offset + 16;
  20083. ranges = [];
  20084. for (i = 0; i < groups; i++) {
  20085. ranges.push({
  20086. start: getLong(data, p),
  20087. end: getLong(data, p + 4),
  20088. idDelta: getLong(data, p + 8) - getLong(data, p)
  20089. });
  20090. p += 12;
  20091. }
  20092. return ranges;
  20093. }
  20094. error('not supported cmap: ' + format);
  20095. }
  20096. function parseCff(data, start, end) {
  20097. var properties = {};
  20098. var parser = new CFFParser(new Stream(data, start, end - start),
  20099. properties);
  20100. var cff = parser.parse();
  20101. return {
  20102. glyphs: cff.charStrings.objects,
  20103. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  20104. cff.topDict.privateDict.subrsIndex.objects),
  20105. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  20106. };
  20107. }
  20108. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  20109. var itemSize, itemDecode;
  20110. if (isGlyphLocationsLong) {
  20111. itemSize = 4;
  20112. itemDecode = function fontItemDecodeLong(data, offset) {
  20113. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20114. (data[offset + 2] << 8) | data[offset + 3];
  20115. };
  20116. } else {
  20117. itemSize = 2;
  20118. itemDecode = function fontItemDecode(data, offset) {
  20119. return (data[offset] << 9) | (data[offset + 1] << 1);
  20120. };
  20121. }
  20122. var glyphs = [];
  20123. var startOffset = itemDecode(loca, 0);
  20124. for (var j = itemSize; j < loca.length; j += itemSize) {
  20125. var endOffset = itemDecode(loca, j);
  20126. glyphs.push(glyf.subarray(startOffset, endOffset));
  20127. startOffset = endOffset;
  20128. }
  20129. return glyphs;
  20130. }
  20131. function lookupCmap(ranges, unicode) {
  20132. var code = unicode.charCodeAt(0);
  20133. var l = 0, r = ranges.length - 1;
  20134. while (l < r) {
  20135. var c = (l + r + 1) >> 1;
  20136. if (code < ranges[c].start) {
  20137. r = c - 1;
  20138. } else {
  20139. l = c;
  20140. }
  20141. }
  20142. if (ranges[l].start <= code && code <= ranges[l].end) {
  20143. return (ranges[l].idDelta + (ranges[l].ids ?
  20144. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  20145. }
  20146. return 0;
  20147. }
  20148. function compileGlyf(code, js, font) {
  20149. function moveTo(x, y) {
  20150. js.push('c.moveTo(' + x + ',' + y + ');');
  20151. }
  20152. function lineTo(x, y) {
  20153. js.push('c.lineTo(' + x + ',' + y + ');');
  20154. }
  20155. function quadraticCurveTo(xa, ya, x, y) {
  20156. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  20157. x + ',' + y + ');');
  20158. }
  20159. var i = 0;
  20160. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20161. var flags;
  20162. var x = 0, y = 0;
  20163. i += 10;
  20164. if (numberOfContours < 0) {
  20165. // composite glyph
  20166. do {
  20167. flags = (code[i] << 8) | code[i + 1];
  20168. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  20169. i += 4;
  20170. var arg1, arg2;
  20171. if ((flags & 0x01)) {
  20172. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20173. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  20174. i += 4;
  20175. } else {
  20176. arg1 = code[i++]; arg2 = code[i++];
  20177. }
  20178. if ((flags & 0x02)) {
  20179. x = arg1;
  20180. y = arg2;
  20181. } else {
  20182. x = 0; y = 0; // TODO "they are points" ?
  20183. }
  20184. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  20185. if ((flags & 0x08)) {
  20186. scaleX =
  20187. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20188. i += 2;
  20189. } else if ((flags & 0x40)) {
  20190. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20191. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20192. i += 4;
  20193. } else if ((flags & 0x80)) {
  20194. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20195. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20196. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  20197. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  20198. i += 8;
  20199. }
  20200. var subglyph = font.glyphs[glyphIndex];
  20201. if (subglyph) {
  20202. js.push('c.save();');
  20203. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  20204. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  20205. compileGlyf(subglyph, js, font);
  20206. js.push('c.restore();');
  20207. }
  20208. } while ((flags & 0x20));
  20209. } else {
  20210. // simple glyph
  20211. var endPtsOfContours = [];
  20212. var j, jj;
  20213. for (j = 0; j < numberOfContours; j++) {
  20214. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  20215. i += 2;
  20216. }
  20217. var instructionLength = (code[i] << 8) | code[i + 1];
  20218. i += 2 + instructionLength; // skipping the instructions
  20219. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  20220. var points = [];
  20221. while (points.length < numberOfPoints) {
  20222. flags = code[i++];
  20223. var repeat = 1;
  20224. if ((flags & 0x08)) {
  20225. repeat += code[i++];
  20226. }
  20227. while (repeat-- > 0) {
  20228. points.push({flags: flags});
  20229. }
  20230. }
  20231. for (j = 0; j < numberOfPoints; j++) {
  20232. switch (points[j].flags & 0x12) {
  20233. case 0x00:
  20234. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20235. i += 2;
  20236. break;
  20237. case 0x02:
  20238. x -= code[i++];
  20239. break;
  20240. case 0x12:
  20241. x += code[i++];
  20242. break;
  20243. }
  20244. points[j].x = x;
  20245. }
  20246. for (j = 0; j < numberOfPoints; j++) {
  20247. switch (points[j].flags & 0x24) {
  20248. case 0x00:
  20249. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20250. i += 2;
  20251. break;
  20252. case 0x04:
  20253. y -= code[i++];
  20254. break;
  20255. case 0x24:
  20256. y += code[i++];
  20257. break;
  20258. }
  20259. points[j].y = y;
  20260. }
  20261. var startPoint = 0;
  20262. for (i = 0; i < numberOfContours; i++) {
  20263. var endPoint = endPtsOfContours[i];
  20264. // contours might have implicit points, which is located in the middle
  20265. // between two neighboring off-curve points
  20266. var contour = points.slice(startPoint, endPoint + 1);
  20267. if ((contour[0].flags & 1)) {
  20268. contour.push(contour[0]); // using start point at the contour end
  20269. } else if ((contour[contour.length - 1].flags & 1)) {
  20270. // first is off-curve point, trying to use one from the end
  20271. contour.unshift(contour[contour.length - 1]);
  20272. } else {
  20273. // start and end are off-curve points, creating implicit one
  20274. var p = {
  20275. flags: 1,
  20276. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20277. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20278. };
  20279. contour.unshift(p);
  20280. contour.push(p);
  20281. }
  20282. moveTo(contour[0].x, contour[0].y);
  20283. for (j = 1, jj = contour.length; j < jj; j++) {
  20284. if ((contour[j].flags & 1)) {
  20285. lineTo(contour[j].x, contour[j].y);
  20286. } else if ((contour[j + 1].flags & 1)){
  20287. quadraticCurveTo(contour[j].x, contour[j].y,
  20288. contour[j + 1].x, contour[j + 1].y);
  20289. j++;
  20290. } else {
  20291. quadraticCurveTo(contour[j].x, contour[j].y,
  20292. (contour[j].x + contour[j + 1].x) / 2,
  20293. (contour[j].y + contour[j + 1].y) / 2);
  20294. }
  20295. }
  20296. startPoint = endPoint + 1;
  20297. }
  20298. }
  20299. }
  20300. function compileCharString(code, js, font) {
  20301. var stack = [];
  20302. var x = 0, y = 0;
  20303. var stems = 0;
  20304. function moveTo(x, y) {
  20305. js.push('c.moveTo(' + x + ',' + y + ');');
  20306. }
  20307. function lineTo(x, y) {
  20308. js.push('c.lineTo(' + x + ',' + y + ');');
  20309. }
  20310. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20311. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  20312. x + ',' + y + ');');
  20313. }
  20314. function parse(code) {
  20315. var i = 0;
  20316. while (i < code.length) {
  20317. var stackClean = false;
  20318. var v = code[i++];
  20319. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20320. switch (v) {
  20321. case 1: // hstem
  20322. stems += stack.length >> 1;
  20323. stackClean = true;
  20324. break;
  20325. case 3: // vstem
  20326. stems += stack.length >> 1;
  20327. stackClean = true;
  20328. break;
  20329. case 4: // vmoveto
  20330. y += stack.pop();
  20331. moveTo(x, y);
  20332. stackClean = true;
  20333. break;
  20334. case 5: // rlineto
  20335. while (stack.length > 0) {
  20336. x += stack.shift();
  20337. y += stack.shift();
  20338. lineTo(x, y);
  20339. }
  20340. break;
  20341. case 6: // hlineto
  20342. while (stack.length > 0) {
  20343. x += stack.shift();
  20344. lineTo(x, y);
  20345. if (stack.length === 0) {
  20346. break;
  20347. }
  20348. y += stack.shift();
  20349. lineTo(x, y);
  20350. }
  20351. break;
  20352. case 7: // vlineto
  20353. while (stack.length > 0) {
  20354. y += stack.shift();
  20355. lineTo(x, y);
  20356. if (stack.length === 0) {
  20357. break;
  20358. }
  20359. x += stack.shift();
  20360. lineTo(x, y);
  20361. }
  20362. break;
  20363. case 8: // rrcurveto
  20364. while (stack.length > 0) {
  20365. xa = x + stack.shift(); ya = y + stack.shift();
  20366. xb = xa + stack.shift(); yb = ya + stack.shift();
  20367. x = xb + stack.shift(); y = yb + stack.shift();
  20368. bezierCurveTo(xa, ya, xb, yb, x, y);
  20369. }
  20370. break;
  20371. case 10: // callsubr
  20372. n = stack.pop() + font.subrsBias;
  20373. subrCode = font.subrs[n];
  20374. if (subrCode) {
  20375. parse(subrCode);
  20376. }
  20377. break;
  20378. case 11: // return
  20379. return;
  20380. case 12:
  20381. v = code[i++];
  20382. switch (v) {
  20383. case 34: // flex
  20384. xa = x + stack.shift();
  20385. xb = xa + stack.shift(); y1 = y + stack.shift();
  20386. x = xb + stack.shift();
  20387. bezierCurveTo(xa, y, xb, y1, x, y1);
  20388. xa = x + stack.shift();
  20389. xb = xa + stack.shift();
  20390. x = xb + stack.shift();
  20391. bezierCurveTo(xa, y1, xb, y, x, y);
  20392. break;
  20393. case 35: // flex
  20394. xa = x + stack.shift(); ya = y + stack.shift();
  20395. xb = xa + stack.shift(); yb = ya + stack.shift();
  20396. x = xb + stack.shift(); y = yb + stack.shift();
  20397. bezierCurveTo(xa, ya, xb, yb, x, y);
  20398. xa = x + stack.shift(); ya = y + stack.shift();
  20399. xb = xa + stack.shift(); yb = ya + stack.shift();
  20400. x = xb + stack.shift(); y = yb + stack.shift();
  20401. bezierCurveTo(xa, ya, xb, yb, x, y);
  20402. stack.pop(); // fd
  20403. break;
  20404. case 36: // hflex1
  20405. xa = x + stack.shift(); y1 = y + stack.shift();
  20406. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20407. x = xb + stack.shift();
  20408. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20409. xa = x + stack.shift();
  20410. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20411. x = xb + stack.shift();
  20412. bezierCurveTo(xa, y2, xb, y3, x, y);
  20413. break;
  20414. case 37: // flex1
  20415. var x0 = x, y0 = y;
  20416. xa = x + stack.shift(); ya = y + stack.shift();
  20417. xb = xa + stack.shift(); yb = ya + stack.shift();
  20418. x = xb + stack.shift(); y = yb + stack.shift();
  20419. bezierCurveTo(xa, ya, xb, yb, x, y);
  20420. xa = x + stack.shift(); ya = y + stack.shift();
  20421. xb = xa + stack.shift(); yb = ya + stack.shift();
  20422. x = xb; y = yb;
  20423. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20424. x += stack.shift();
  20425. } else {
  20426. y += stack.shift();
  20427. }
  20428. bezierCurveTo(xa, ya, xb, yb, x, y);
  20429. break;
  20430. default:
  20431. error('unknown operator: 12 ' + v);
  20432. }
  20433. break;
  20434. case 14: // endchar
  20435. if (stack.length >= 4) {
  20436. var achar = stack.pop();
  20437. var bchar = stack.pop();
  20438. y = stack.pop();
  20439. x = stack.pop();
  20440. js.push('c.save();');
  20441. js.push('c.translate('+ x + ',' + y + ');');
  20442. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20443. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20444. compileCharString(font.glyphs[gid], js, font);
  20445. js.push('c.restore();');
  20446. gid = lookupCmap(font.cmap, String.fromCharCode(
  20447. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20448. compileCharString(font.glyphs[gid], js, font);
  20449. }
  20450. return;
  20451. case 18: // hstemhm
  20452. stems += stack.length >> 1;
  20453. stackClean = true;
  20454. break;
  20455. case 19: // hintmask
  20456. stems += stack.length >> 1;
  20457. i += (stems + 7) >> 3;
  20458. stackClean = true;
  20459. break;
  20460. case 20: // cntrmask
  20461. stems += stack.length >> 1;
  20462. i += (stems + 7) >> 3;
  20463. stackClean = true;
  20464. break;
  20465. case 21: // rmoveto
  20466. y += stack.pop();
  20467. x += stack.pop();
  20468. moveTo(x, y);
  20469. stackClean = true;
  20470. break;
  20471. case 22: // hmoveto
  20472. x += stack.pop();
  20473. moveTo(x, y);
  20474. stackClean = true;
  20475. break;
  20476. case 23: // vstemhm
  20477. stems += stack.length >> 1;
  20478. stackClean = true;
  20479. break;
  20480. case 24: // rcurveline
  20481. while (stack.length > 2) {
  20482. xa = x + stack.shift(); ya = y + stack.shift();
  20483. xb = xa + stack.shift(); yb = ya + stack.shift();
  20484. x = xb + stack.shift(); y = yb + stack.shift();
  20485. bezierCurveTo(xa, ya, xb, yb, x, y);
  20486. }
  20487. x += stack.shift();
  20488. y += stack.shift();
  20489. lineTo(x, y);
  20490. break;
  20491. case 25: // rlinecurve
  20492. while (stack.length > 6) {
  20493. x += stack.shift();
  20494. y += stack.shift();
  20495. lineTo(x, y);
  20496. }
  20497. xa = x + stack.shift(); ya = y + stack.shift();
  20498. xb = xa + stack.shift(); yb = ya + stack.shift();
  20499. x = xb + stack.shift(); y = yb + stack.shift();
  20500. bezierCurveTo(xa, ya, xb, yb, x, y);
  20501. break;
  20502. case 26: // vvcurveto
  20503. if (stack.length % 2) {
  20504. x += stack.shift();
  20505. }
  20506. while (stack.length > 0) {
  20507. xa = x; ya = y + stack.shift();
  20508. xb = xa + stack.shift(); yb = ya + stack.shift();
  20509. x = xb; y = yb + stack.shift();
  20510. bezierCurveTo(xa, ya, xb, yb, x, y);
  20511. }
  20512. break;
  20513. case 27: // hhcurveto
  20514. if (stack.length % 2) {
  20515. y += stack.shift();
  20516. }
  20517. while (stack.length > 0) {
  20518. xa = x + stack.shift(); ya = y;
  20519. xb = xa + stack.shift(); yb = ya + stack.shift();
  20520. x = xb + stack.shift(); y = yb;
  20521. bezierCurveTo(xa, ya, xb, yb, x, y);
  20522. }
  20523. break;
  20524. case 28:
  20525. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20526. i += 2;
  20527. break;
  20528. case 29: // callgsubr
  20529. n = stack.pop() + font.gsubrsBias;
  20530. subrCode = font.gsubrs[n];
  20531. if (subrCode) {
  20532. parse(subrCode);
  20533. }
  20534. break;
  20535. case 30: // vhcurveto
  20536. while (stack.length > 0) {
  20537. xa = x; ya = y + stack.shift();
  20538. xb = xa + stack.shift(); yb = ya + stack.shift();
  20539. x = xb + stack.shift();
  20540. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20541. bezierCurveTo(xa, ya, xb, yb, x, y);
  20542. if (stack.length === 0) {
  20543. break;
  20544. }
  20545. xa = x + stack.shift(); ya = y;
  20546. xb = xa + stack.shift(); yb = ya + stack.shift();
  20547. y = yb + stack.shift();
  20548. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20549. bezierCurveTo(xa, ya, xb, yb, x, y);
  20550. }
  20551. break;
  20552. case 31: // hvcurveto
  20553. while (stack.length > 0) {
  20554. xa = x + stack.shift(); ya = y;
  20555. xb = xa + stack.shift(); yb = ya + stack.shift();
  20556. y = yb + stack.shift();
  20557. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20558. bezierCurveTo(xa, ya, xb, yb, x, y);
  20559. if (stack.length === 0) {
  20560. break;
  20561. }
  20562. xa = x; ya = y + stack.shift();
  20563. xb = xa + stack.shift(); yb = ya + stack.shift();
  20564. x = xb + stack.shift();
  20565. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20566. bezierCurveTo(xa, ya, xb, yb, x, y);
  20567. }
  20568. break;
  20569. default:
  20570. if (v < 32) {
  20571. error('unknown operator: ' + v);
  20572. }
  20573. if (v < 247) {
  20574. stack.push(v - 139);
  20575. } else if (v < 251) {
  20576. stack.push((v - 247) * 256 + code[i++] + 108);
  20577. } else if (v < 255) {
  20578. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20579. } else {
  20580. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20581. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20582. i += 4;
  20583. }
  20584. break;
  20585. }
  20586. if (stackClean) {
  20587. stack.length = 0;
  20588. }
  20589. }
  20590. }
  20591. parse(code);
  20592. }
  20593. var noop = '';
  20594. function CompiledFont(fontMatrix) {
  20595. this.compiledGlyphs = {};
  20596. this.fontMatrix = fontMatrix;
  20597. }
  20598. CompiledFont.prototype = {
  20599. getPathJs: function (unicode) {
  20600. var gid = lookupCmap(this.cmap, unicode);
  20601. var fn = this.compiledGlyphs[gid];
  20602. if (!fn) {
  20603. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20604. }
  20605. return fn;
  20606. },
  20607. compileGlyph: function (code) {
  20608. if (!code || code.length === 0 || code[0] === 14) {
  20609. return noop;
  20610. }
  20611. var js = [];
  20612. js.push('c.save();');
  20613. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20614. js.push('c.scale(size, -size);');
  20615. this.compileGlyphImpl(code, js);
  20616. js.push('c.restore();');
  20617. return js.join('\n');
  20618. },
  20619. compileGlyphImpl: function () {
  20620. error('Children classes should implement this.');
  20621. },
  20622. hasBuiltPath: function (unicode) {
  20623. var gid = lookupCmap(this.cmap, unicode);
  20624. return gid in this.compiledGlyphs;
  20625. }
  20626. };
  20627. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20628. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20629. CompiledFont.call(this, fontMatrix);
  20630. this.glyphs = glyphs;
  20631. this.cmap = cmap;
  20632. this.compiledGlyphs = [];
  20633. }
  20634. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20635. compileGlyphImpl: function (code, js) {
  20636. compileGlyf(code, js, this);
  20637. }
  20638. });
  20639. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20640. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20641. CompiledFont.call(this, fontMatrix);
  20642. this.glyphs = cffInfo.glyphs;
  20643. this.gsubrs = cffInfo.gsubrs || [];
  20644. this.subrs = cffInfo.subrs || [];
  20645. this.cmap = cmap;
  20646. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20647. this.compiledGlyphs = [];
  20648. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20649. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20650. this.subrsBias = (this.subrs.length < 1240 ?
  20651. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20652. }
  20653. Util.inherit(Type2Compiled, CompiledFont, {
  20654. compileGlyphImpl: function (code, js) {
  20655. compileCharString(code, js, this);
  20656. }
  20657. });
  20658. return {
  20659. create: function FontRendererFactory_create(font) {
  20660. var data = new Uint8Array(font.data);
  20661. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20662. var numTables = getUshort(data, 4);
  20663. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20664. var tag = bytesToString(data.subarray(p, p + 4));
  20665. var offset = getLong(data, p + 8);
  20666. var length = getLong(data, p + 12);
  20667. switch (tag) {
  20668. case 'cmap':
  20669. cmap = parseCmap(data, offset, offset + length);
  20670. break;
  20671. case 'glyf':
  20672. glyf = data.subarray(offset, offset + length);
  20673. break;
  20674. case 'loca':
  20675. loca = data.subarray(offset, offset + length);
  20676. break;
  20677. case 'head':
  20678. unitsPerEm = getUshort(data, offset + 18);
  20679. indexToLocFormat = getUshort(data, offset + 50);
  20680. break;
  20681. case 'CFF ':
  20682. cff = parseCff(data, offset, offset + length);
  20683. break;
  20684. }
  20685. }
  20686. if (glyf) {
  20687. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20688. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20689. return new TrueTypeCompiled(
  20690. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20691. } else {
  20692. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20693. }
  20694. }
  20695. };
  20696. })();
  20697. var GlyphsUnicode = {
  20698. A: 0x0041,
  20699. AE: 0x00C6,
  20700. AEacute: 0x01FC,
  20701. AEmacron: 0x01E2,
  20702. AEsmall: 0xF7E6,
  20703. Aacute: 0x00C1,
  20704. Aacutesmall: 0xF7E1,
  20705. Abreve: 0x0102,
  20706. Abreveacute: 0x1EAE,
  20707. Abrevecyrillic: 0x04D0,
  20708. Abrevedotbelow: 0x1EB6,
  20709. Abrevegrave: 0x1EB0,
  20710. Abrevehookabove: 0x1EB2,
  20711. Abrevetilde: 0x1EB4,
  20712. Acaron: 0x01CD,
  20713. Acircle: 0x24B6,
  20714. Acircumflex: 0x00C2,
  20715. Acircumflexacute: 0x1EA4,
  20716. Acircumflexdotbelow: 0x1EAC,
  20717. Acircumflexgrave: 0x1EA6,
  20718. Acircumflexhookabove: 0x1EA8,
  20719. Acircumflexsmall: 0xF7E2,
  20720. Acircumflextilde: 0x1EAA,
  20721. Acute: 0xF6C9,
  20722. Acutesmall: 0xF7B4,
  20723. Acyrillic: 0x0410,
  20724. Adblgrave: 0x0200,
  20725. Adieresis: 0x00C4,
  20726. Adieresiscyrillic: 0x04D2,
  20727. Adieresismacron: 0x01DE,
  20728. Adieresissmall: 0xF7E4,
  20729. Adotbelow: 0x1EA0,
  20730. Adotmacron: 0x01E0,
  20731. Agrave: 0x00C0,
  20732. Agravesmall: 0xF7E0,
  20733. Ahookabove: 0x1EA2,
  20734. Aiecyrillic: 0x04D4,
  20735. Ainvertedbreve: 0x0202,
  20736. Alpha: 0x0391,
  20737. Alphatonos: 0x0386,
  20738. Amacron: 0x0100,
  20739. Amonospace: 0xFF21,
  20740. Aogonek: 0x0104,
  20741. Aring: 0x00C5,
  20742. Aringacute: 0x01FA,
  20743. Aringbelow: 0x1E00,
  20744. Aringsmall: 0xF7E5,
  20745. Asmall: 0xF761,
  20746. Atilde: 0x00C3,
  20747. Atildesmall: 0xF7E3,
  20748. Aybarmenian: 0x0531,
  20749. B: 0x0042,
  20750. Bcircle: 0x24B7,
  20751. Bdotaccent: 0x1E02,
  20752. Bdotbelow: 0x1E04,
  20753. Becyrillic: 0x0411,
  20754. Benarmenian: 0x0532,
  20755. Beta: 0x0392,
  20756. Bhook: 0x0181,
  20757. Blinebelow: 0x1E06,
  20758. Bmonospace: 0xFF22,
  20759. Brevesmall: 0xF6F4,
  20760. Bsmall: 0xF762,
  20761. Btopbar: 0x0182,
  20762. C: 0x0043,
  20763. Caarmenian: 0x053E,
  20764. Cacute: 0x0106,
  20765. Caron: 0xF6CA,
  20766. Caronsmall: 0xF6F5,
  20767. Ccaron: 0x010C,
  20768. Ccedilla: 0x00C7,
  20769. Ccedillaacute: 0x1E08,
  20770. Ccedillasmall: 0xF7E7,
  20771. Ccircle: 0x24B8,
  20772. Ccircumflex: 0x0108,
  20773. Cdot: 0x010A,
  20774. Cdotaccent: 0x010A,
  20775. Cedillasmall: 0xF7B8,
  20776. Chaarmenian: 0x0549,
  20777. Cheabkhasiancyrillic: 0x04BC,
  20778. Checyrillic: 0x0427,
  20779. Chedescenderabkhasiancyrillic: 0x04BE,
  20780. Chedescendercyrillic: 0x04B6,
  20781. Chedieresiscyrillic: 0x04F4,
  20782. Cheharmenian: 0x0543,
  20783. Chekhakassiancyrillic: 0x04CB,
  20784. Cheverticalstrokecyrillic: 0x04B8,
  20785. Chi: 0x03A7,
  20786. Chook: 0x0187,
  20787. Circumflexsmall: 0xF6F6,
  20788. Cmonospace: 0xFF23,
  20789. Coarmenian: 0x0551,
  20790. Csmall: 0xF763,
  20791. D: 0x0044,
  20792. DZ: 0x01F1,
  20793. DZcaron: 0x01C4,
  20794. Daarmenian: 0x0534,
  20795. Dafrican: 0x0189,
  20796. Dcaron: 0x010E,
  20797. Dcedilla: 0x1E10,
  20798. Dcircle: 0x24B9,
  20799. Dcircumflexbelow: 0x1E12,
  20800. Dcroat: 0x0110,
  20801. Ddotaccent: 0x1E0A,
  20802. Ddotbelow: 0x1E0C,
  20803. Decyrillic: 0x0414,
  20804. Deicoptic: 0x03EE,
  20805. Delta: 0x2206,
  20806. Deltagreek: 0x0394,
  20807. Dhook: 0x018A,
  20808. Dieresis: 0xF6CB,
  20809. DieresisAcute: 0xF6CC,
  20810. DieresisGrave: 0xF6CD,
  20811. Dieresissmall: 0xF7A8,
  20812. Digammagreek: 0x03DC,
  20813. Djecyrillic: 0x0402,
  20814. Dlinebelow: 0x1E0E,
  20815. Dmonospace: 0xFF24,
  20816. Dotaccentsmall: 0xF6F7,
  20817. Dslash: 0x0110,
  20818. Dsmall: 0xF764,
  20819. Dtopbar: 0x018B,
  20820. Dz: 0x01F2,
  20821. Dzcaron: 0x01C5,
  20822. Dzeabkhasiancyrillic: 0x04E0,
  20823. Dzecyrillic: 0x0405,
  20824. Dzhecyrillic: 0x040F,
  20825. E: 0x0045,
  20826. Eacute: 0x00C9,
  20827. Eacutesmall: 0xF7E9,
  20828. Ebreve: 0x0114,
  20829. Ecaron: 0x011A,
  20830. Ecedillabreve: 0x1E1C,
  20831. Echarmenian: 0x0535,
  20832. Ecircle: 0x24BA,
  20833. Ecircumflex: 0x00CA,
  20834. Ecircumflexacute: 0x1EBE,
  20835. Ecircumflexbelow: 0x1E18,
  20836. Ecircumflexdotbelow: 0x1EC6,
  20837. Ecircumflexgrave: 0x1EC0,
  20838. Ecircumflexhookabove: 0x1EC2,
  20839. Ecircumflexsmall: 0xF7EA,
  20840. Ecircumflextilde: 0x1EC4,
  20841. Ecyrillic: 0x0404,
  20842. Edblgrave: 0x0204,
  20843. Edieresis: 0x00CB,
  20844. Edieresissmall: 0xF7EB,
  20845. Edot: 0x0116,
  20846. Edotaccent: 0x0116,
  20847. Edotbelow: 0x1EB8,
  20848. Efcyrillic: 0x0424,
  20849. Egrave: 0x00C8,
  20850. Egravesmall: 0xF7E8,
  20851. Eharmenian: 0x0537,
  20852. Ehookabove: 0x1EBA,
  20853. Eightroman: 0x2167,
  20854. Einvertedbreve: 0x0206,
  20855. Eiotifiedcyrillic: 0x0464,
  20856. Elcyrillic: 0x041B,
  20857. Elevenroman: 0x216A,
  20858. Emacron: 0x0112,
  20859. Emacronacute: 0x1E16,
  20860. Emacrongrave: 0x1E14,
  20861. Emcyrillic: 0x041C,
  20862. Emonospace: 0xFF25,
  20863. Encyrillic: 0x041D,
  20864. Endescendercyrillic: 0x04A2,
  20865. Eng: 0x014A,
  20866. Enghecyrillic: 0x04A4,
  20867. Enhookcyrillic: 0x04C7,
  20868. Eogonek: 0x0118,
  20869. Eopen: 0x0190,
  20870. Epsilon: 0x0395,
  20871. Epsilontonos: 0x0388,
  20872. Ercyrillic: 0x0420,
  20873. Ereversed: 0x018E,
  20874. Ereversedcyrillic: 0x042D,
  20875. Escyrillic: 0x0421,
  20876. Esdescendercyrillic: 0x04AA,
  20877. Esh: 0x01A9,
  20878. Esmall: 0xF765,
  20879. Eta: 0x0397,
  20880. Etarmenian: 0x0538,
  20881. Etatonos: 0x0389,
  20882. Eth: 0x00D0,
  20883. Ethsmall: 0xF7F0,
  20884. Etilde: 0x1EBC,
  20885. Etildebelow: 0x1E1A,
  20886. Euro: 0x20AC,
  20887. Ezh: 0x01B7,
  20888. Ezhcaron: 0x01EE,
  20889. Ezhreversed: 0x01B8,
  20890. F: 0x0046,
  20891. Fcircle: 0x24BB,
  20892. Fdotaccent: 0x1E1E,
  20893. Feharmenian: 0x0556,
  20894. Feicoptic: 0x03E4,
  20895. Fhook: 0x0191,
  20896. Fitacyrillic: 0x0472,
  20897. Fiveroman: 0x2164,
  20898. Fmonospace: 0xFF26,
  20899. Fourroman: 0x2163,
  20900. Fsmall: 0xF766,
  20901. G: 0x0047,
  20902. GBsquare: 0x3387,
  20903. Gacute: 0x01F4,
  20904. Gamma: 0x0393,
  20905. Gammaafrican: 0x0194,
  20906. Gangiacoptic: 0x03EA,
  20907. Gbreve: 0x011E,
  20908. Gcaron: 0x01E6,
  20909. Gcedilla: 0x0122,
  20910. Gcircle: 0x24BC,
  20911. Gcircumflex: 0x011C,
  20912. Gcommaaccent: 0x0122,
  20913. Gdot: 0x0120,
  20914. Gdotaccent: 0x0120,
  20915. Gecyrillic: 0x0413,
  20916. Ghadarmenian: 0x0542,
  20917. Ghemiddlehookcyrillic: 0x0494,
  20918. Ghestrokecyrillic: 0x0492,
  20919. Gheupturncyrillic: 0x0490,
  20920. Ghook: 0x0193,
  20921. Gimarmenian: 0x0533,
  20922. Gjecyrillic: 0x0403,
  20923. Gmacron: 0x1E20,
  20924. Gmonospace: 0xFF27,
  20925. Grave: 0xF6CE,
  20926. Gravesmall: 0xF760,
  20927. Gsmall: 0xF767,
  20928. Gsmallhook: 0x029B,
  20929. Gstroke: 0x01E4,
  20930. H: 0x0048,
  20931. H18533: 0x25CF,
  20932. H18543: 0x25AA,
  20933. H18551: 0x25AB,
  20934. H22073: 0x25A1,
  20935. HPsquare: 0x33CB,
  20936. Haabkhasiancyrillic: 0x04A8,
  20937. Hadescendercyrillic: 0x04B2,
  20938. Hardsigncyrillic: 0x042A,
  20939. Hbar: 0x0126,
  20940. Hbrevebelow: 0x1E2A,
  20941. Hcedilla: 0x1E28,
  20942. Hcircle: 0x24BD,
  20943. Hcircumflex: 0x0124,
  20944. Hdieresis: 0x1E26,
  20945. Hdotaccent: 0x1E22,
  20946. Hdotbelow: 0x1E24,
  20947. Hmonospace: 0xFF28,
  20948. Hoarmenian: 0x0540,
  20949. Horicoptic: 0x03E8,
  20950. Hsmall: 0xF768,
  20951. Hungarumlaut: 0xF6CF,
  20952. Hungarumlautsmall: 0xF6F8,
  20953. Hzsquare: 0x3390,
  20954. I: 0x0049,
  20955. IAcyrillic: 0x042F,
  20956. IJ: 0x0132,
  20957. IUcyrillic: 0x042E,
  20958. Iacute: 0x00CD,
  20959. Iacutesmall: 0xF7ED,
  20960. Ibreve: 0x012C,
  20961. Icaron: 0x01CF,
  20962. Icircle: 0x24BE,
  20963. Icircumflex: 0x00CE,
  20964. Icircumflexsmall: 0xF7EE,
  20965. Icyrillic: 0x0406,
  20966. Idblgrave: 0x0208,
  20967. Idieresis: 0x00CF,
  20968. Idieresisacute: 0x1E2E,
  20969. Idieresiscyrillic: 0x04E4,
  20970. Idieresissmall: 0xF7EF,
  20971. Idot: 0x0130,
  20972. Idotaccent: 0x0130,
  20973. Idotbelow: 0x1ECA,
  20974. Iebrevecyrillic: 0x04D6,
  20975. Iecyrillic: 0x0415,
  20976. Ifraktur: 0x2111,
  20977. Igrave: 0x00CC,
  20978. Igravesmall: 0xF7EC,
  20979. Ihookabove: 0x1EC8,
  20980. Iicyrillic: 0x0418,
  20981. Iinvertedbreve: 0x020A,
  20982. Iishortcyrillic: 0x0419,
  20983. Imacron: 0x012A,
  20984. Imacroncyrillic: 0x04E2,
  20985. Imonospace: 0xFF29,
  20986. Iniarmenian: 0x053B,
  20987. Iocyrillic: 0x0401,
  20988. Iogonek: 0x012E,
  20989. Iota: 0x0399,
  20990. Iotaafrican: 0x0196,
  20991. Iotadieresis: 0x03AA,
  20992. Iotatonos: 0x038A,
  20993. Ismall: 0xF769,
  20994. Istroke: 0x0197,
  20995. Itilde: 0x0128,
  20996. Itildebelow: 0x1E2C,
  20997. Izhitsacyrillic: 0x0474,
  20998. Izhitsadblgravecyrillic: 0x0476,
  20999. J: 0x004A,
  21000. Jaarmenian: 0x0541,
  21001. Jcircle: 0x24BF,
  21002. Jcircumflex: 0x0134,
  21003. Jecyrillic: 0x0408,
  21004. Jheharmenian: 0x054B,
  21005. Jmonospace: 0xFF2A,
  21006. Jsmall: 0xF76A,
  21007. K: 0x004B,
  21008. KBsquare: 0x3385,
  21009. KKsquare: 0x33CD,
  21010. Kabashkircyrillic: 0x04A0,
  21011. Kacute: 0x1E30,
  21012. Kacyrillic: 0x041A,
  21013. Kadescendercyrillic: 0x049A,
  21014. Kahookcyrillic: 0x04C3,
  21015. Kappa: 0x039A,
  21016. Kastrokecyrillic: 0x049E,
  21017. Kaverticalstrokecyrillic: 0x049C,
  21018. Kcaron: 0x01E8,
  21019. Kcedilla: 0x0136,
  21020. Kcircle: 0x24C0,
  21021. Kcommaaccent: 0x0136,
  21022. Kdotbelow: 0x1E32,
  21023. Keharmenian: 0x0554,
  21024. Kenarmenian: 0x053F,
  21025. Khacyrillic: 0x0425,
  21026. Kheicoptic: 0x03E6,
  21027. Khook: 0x0198,
  21028. Kjecyrillic: 0x040C,
  21029. Klinebelow: 0x1E34,
  21030. Kmonospace: 0xFF2B,
  21031. Koppacyrillic: 0x0480,
  21032. Koppagreek: 0x03DE,
  21033. Ksicyrillic: 0x046E,
  21034. Ksmall: 0xF76B,
  21035. L: 0x004C,
  21036. LJ: 0x01C7,
  21037. LL: 0xF6BF,
  21038. Lacute: 0x0139,
  21039. Lambda: 0x039B,
  21040. Lcaron: 0x013D,
  21041. Lcedilla: 0x013B,
  21042. Lcircle: 0x24C1,
  21043. Lcircumflexbelow: 0x1E3C,
  21044. Lcommaaccent: 0x013B,
  21045. Ldot: 0x013F,
  21046. Ldotaccent: 0x013F,
  21047. Ldotbelow: 0x1E36,
  21048. Ldotbelowmacron: 0x1E38,
  21049. Liwnarmenian: 0x053C,
  21050. Lj: 0x01C8,
  21051. Ljecyrillic: 0x0409,
  21052. Llinebelow: 0x1E3A,
  21053. Lmonospace: 0xFF2C,
  21054. Lslash: 0x0141,
  21055. Lslashsmall: 0xF6F9,
  21056. Lsmall: 0xF76C,
  21057. M: 0x004D,
  21058. MBsquare: 0x3386,
  21059. Macron: 0xF6D0,
  21060. Macronsmall: 0xF7AF,
  21061. Macute: 0x1E3E,
  21062. Mcircle: 0x24C2,
  21063. Mdotaccent: 0x1E40,
  21064. Mdotbelow: 0x1E42,
  21065. Menarmenian: 0x0544,
  21066. Mmonospace: 0xFF2D,
  21067. Msmall: 0xF76D,
  21068. Mturned: 0x019C,
  21069. Mu: 0x039C,
  21070. N: 0x004E,
  21071. NJ: 0x01CA,
  21072. Nacute: 0x0143,
  21073. Ncaron: 0x0147,
  21074. Ncedilla: 0x0145,
  21075. Ncircle: 0x24C3,
  21076. Ncircumflexbelow: 0x1E4A,
  21077. Ncommaaccent: 0x0145,
  21078. Ndotaccent: 0x1E44,
  21079. Ndotbelow: 0x1E46,
  21080. Nhookleft: 0x019D,
  21081. Nineroman: 0x2168,
  21082. Nj: 0x01CB,
  21083. Njecyrillic: 0x040A,
  21084. Nlinebelow: 0x1E48,
  21085. Nmonospace: 0xFF2E,
  21086. Nowarmenian: 0x0546,
  21087. Nsmall: 0xF76E,
  21088. Ntilde: 0x00D1,
  21089. Ntildesmall: 0xF7F1,
  21090. Nu: 0x039D,
  21091. O: 0x004F,
  21092. OE: 0x0152,
  21093. OEsmall: 0xF6FA,
  21094. Oacute: 0x00D3,
  21095. Oacutesmall: 0xF7F3,
  21096. Obarredcyrillic: 0x04E8,
  21097. Obarreddieresiscyrillic: 0x04EA,
  21098. Obreve: 0x014E,
  21099. Ocaron: 0x01D1,
  21100. Ocenteredtilde: 0x019F,
  21101. Ocircle: 0x24C4,
  21102. Ocircumflex: 0x00D4,
  21103. Ocircumflexacute: 0x1ED0,
  21104. Ocircumflexdotbelow: 0x1ED8,
  21105. Ocircumflexgrave: 0x1ED2,
  21106. Ocircumflexhookabove: 0x1ED4,
  21107. Ocircumflexsmall: 0xF7F4,
  21108. Ocircumflextilde: 0x1ED6,
  21109. Ocyrillic: 0x041E,
  21110. Odblacute: 0x0150,
  21111. Odblgrave: 0x020C,
  21112. Odieresis: 0x00D6,
  21113. Odieresiscyrillic: 0x04E6,
  21114. Odieresissmall: 0xF7F6,
  21115. Odotbelow: 0x1ECC,
  21116. Ogoneksmall: 0xF6FB,
  21117. Ograve: 0x00D2,
  21118. Ogravesmall: 0xF7F2,
  21119. Oharmenian: 0x0555,
  21120. Ohm: 0x2126,
  21121. Ohookabove: 0x1ECE,
  21122. Ohorn: 0x01A0,
  21123. Ohornacute: 0x1EDA,
  21124. Ohorndotbelow: 0x1EE2,
  21125. Ohorngrave: 0x1EDC,
  21126. Ohornhookabove: 0x1EDE,
  21127. Ohorntilde: 0x1EE0,
  21128. Ohungarumlaut: 0x0150,
  21129. Oi: 0x01A2,
  21130. Oinvertedbreve: 0x020E,
  21131. Omacron: 0x014C,
  21132. Omacronacute: 0x1E52,
  21133. Omacrongrave: 0x1E50,
  21134. Omega: 0x2126,
  21135. Omegacyrillic: 0x0460,
  21136. Omegagreek: 0x03A9,
  21137. Omegaroundcyrillic: 0x047A,
  21138. Omegatitlocyrillic: 0x047C,
  21139. Omegatonos: 0x038F,
  21140. Omicron: 0x039F,
  21141. Omicrontonos: 0x038C,
  21142. Omonospace: 0xFF2F,
  21143. Oneroman: 0x2160,
  21144. Oogonek: 0x01EA,
  21145. Oogonekmacron: 0x01EC,
  21146. Oopen: 0x0186,
  21147. Oslash: 0x00D8,
  21148. Oslashacute: 0x01FE,
  21149. Oslashsmall: 0xF7F8,
  21150. Osmall: 0xF76F,
  21151. Ostrokeacute: 0x01FE,
  21152. Otcyrillic: 0x047E,
  21153. Otilde: 0x00D5,
  21154. Otildeacute: 0x1E4C,
  21155. Otildedieresis: 0x1E4E,
  21156. Otildesmall: 0xF7F5,
  21157. P: 0x0050,
  21158. Pacute: 0x1E54,
  21159. Pcircle: 0x24C5,
  21160. Pdotaccent: 0x1E56,
  21161. Pecyrillic: 0x041F,
  21162. Peharmenian: 0x054A,
  21163. Pemiddlehookcyrillic: 0x04A6,
  21164. Phi: 0x03A6,
  21165. Phook: 0x01A4,
  21166. Pi: 0x03A0,
  21167. Piwrarmenian: 0x0553,
  21168. Pmonospace: 0xFF30,
  21169. Psi: 0x03A8,
  21170. Psicyrillic: 0x0470,
  21171. Psmall: 0xF770,
  21172. Q: 0x0051,
  21173. Qcircle: 0x24C6,
  21174. Qmonospace: 0xFF31,
  21175. Qsmall: 0xF771,
  21176. R: 0x0052,
  21177. Raarmenian: 0x054C,
  21178. Racute: 0x0154,
  21179. Rcaron: 0x0158,
  21180. Rcedilla: 0x0156,
  21181. Rcircle: 0x24C7,
  21182. Rcommaaccent: 0x0156,
  21183. Rdblgrave: 0x0210,
  21184. Rdotaccent: 0x1E58,
  21185. Rdotbelow: 0x1E5A,
  21186. Rdotbelowmacron: 0x1E5C,
  21187. Reharmenian: 0x0550,
  21188. Rfraktur: 0x211C,
  21189. Rho: 0x03A1,
  21190. Ringsmall: 0xF6FC,
  21191. Rinvertedbreve: 0x0212,
  21192. Rlinebelow: 0x1E5E,
  21193. Rmonospace: 0xFF32,
  21194. Rsmall: 0xF772,
  21195. Rsmallinverted: 0x0281,
  21196. Rsmallinvertedsuperior: 0x02B6,
  21197. S: 0x0053,
  21198. SF010000: 0x250C,
  21199. SF020000: 0x2514,
  21200. SF030000: 0x2510,
  21201. SF040000: 0x2518,
  21202. SF050000: 0x253C,
  21203. SF060000: 0x252C,
  21204. SF070000: 0x2534,
  21205. SF080000: 0x251C,
  21206. SF090000: 0x2524,
  21207. SF100000: 0x2500,
  21208. SF110000: 0x2502,
  21209. SF190000: 0x2561,
  21210. SF200000: 0x2562,
  21211. SF210000: 0x2556,
  21212. SF220000: 0x2555,
  21213. SF230000: 0x2563,
  21214. SF240000: 0x2551,
  21215. SF250000: 0x2557,
  21216. SF260000: 0x255D,
  21217. SF270000: 0x255C,
  21218. SF280000: 0x255B,
  21219. SF360000: 0x255E,
  21220. SF370000: 0x255F,
  21221. SF380000: 0x255A,
  21222. SF390000: 0x2554,
  21223. SF400000: 0x2569,
  21224. SF410000: 0x2566,
  21225. SF420000: 0x2560,
  21226. SF430000: 0x2550,
  21227. SF440000: 0x256C,
  21228. SF450000: 0x2567,
  21229. SF460000: 0x2568,
  21230. SF470000: 0x2564,
  21231. SF480000: 0x2565,
  21232. SF490000: 0x2559,
  21233. SF500000: 0x2558,
  21234. SF510000: 0x2552,
  21235. SF520000: 0x2553,
  21236. SF530000: 0x256B,
  21237. SF540000: 0x256A,
  21238. Sacute: 0x015A,
  21239. Sacutedotaccent: 0x1E64,
  21240. Sampigreek: 0x03E0,
  21241. Scaron: 0x0160,
  21242. Scarondotaccent: 0x1E66,
  21243. Scaronsmall: 0xF6FD,
  21244. Scedilla: 0x015E,
  21245. Schwa: 0x018F,
  21246. Schwacyrillic: 0x04D8,
  21247. Schwadieresiscyrillic: 0x04DA,
  21248. Scircle: 0x24C8,
  21249. Scircumflex: 0x015C,
  21250. Scommaaccent: 0x0218,
  21251. Sdotaccent: 0x1E60,
  21252. Sdotbelow: 0x1E62,
  21253. Sdotbelowdotaccent: 0x1E68,
  21254. Seharmenian: 0x054D,
  21255. Sevenroman: 0x2166,
  21256. Shaarmenian: 0x0547,
  21257. Shacyrillic: 0x0428,
  21258. Shchacyrillic: 0x0429,
  21259. Sheicoptic: 0x03E2,
  21260. Shhacyrillic: 0x04BA,
  21261. Shimacoptic: 0x03EC,
  21262. Sigma: 0x03A3,
  21263. Sixroman: 0x2165,
  21264. Smonospace: 0xFF33,
  21265. Softsigncyrillic: 0x042C,
  21266. Ssmall: 0xF773,
  21267. Stigmagreek: 0x03DA,
  21268. T: 0x0054,
  21269. Tau: 0x03A4,
  21270. Tbar: 0x0166,
  21271. Tcaron: 0x0164,
  21272. Tcedilla: 0x0162,
  21273. Tcircle: 0x24C9,
  21274. Tcircumflexbelow: 0x1E70,
  21275. Tcommaaccent: 0x0162,
  21276. Tdotaccent: 0x1E6A,
  21277. Tdotbelow: 0x1E6C,
  21278. Tecyrillic: 0x0422,
  21279. Tedescendercyrillic: 0x04AC,
  21280. Tenroman: 0x2169,
  21281. Tetsecyrillic: 0x04B4,
  21282. Theta: 0x0398,
  21283. Thook: 0x01AC,
  21284. Thorn: 0x00DE,
  21285. Thornsmall: 0xF7FE,
  21286. Threeroman: 0x2162,
  21287. Tildesmall: 0xF6FE,
  21288. Tiwnarmenian: 0x054F,
  21289. Tlinebelow: 0x1E6E,
  21290. Tmonospace: 0xFF34,
  21291. Toarmenian: 0x0539,
  21292. Tonefive: 0x01BC,
  21293. Tonesix: 0x0184,
  21294. Tonetwo: 0x01A7,
  21295. Tretroflexhook: 0x01AE,
  21296. Tsecyrillic: 0x0426,
  21297. Tshecyrillic: 0x040B,
  21298. Tsmall: 0xF774,
  21299. Twelveroman: 0x216B,
  21300. Tworoman: 0x2161,
  21301. U: 0x0055,
  21302. Uacute: 0x00DA,
  21303. Uacutesmall: 0xF7FA,
  21304. Ubreve: 0x016C,
  21305. Ucaron: 0x01D3,
  21306. Ucircle: 0x24CA,
  21307. Ucircumflex: 0x00DB,
  21308. Ucircumflexbelow: 0x1E76,
  21309. Ucircumflexsmall: 0xF7FB,
  21310. Ucyrillic: 0x0423,
  21311. Udblacute: 0x0170,
  21312. Udblgrave: 0x0214,
  21313. Udieresis: 0x00DC,
  21314. Udieresisacute: 0x01D7,
  21315. Udieresisbelow: 0x1E72,
  21316. Udieresiscaron: 0x01D9,
  21317. Udieresiscyrillic: 0x04F0,
  21318. Udieresisgrave: 0x01DB,
  21319. Udieresismacron: 0x01D5,
  21320. Udieresissmall: 0xF7FC,
  21321. Udotbelow: 0x1EE4,
  21322. Ugrave: 0x00D9,
  21323. Ugravesmall: 0xF7F9,
  21324. Uhookabove: 0x1EE6,
  21325. Uhorn: 0x01AF,
  21326. Uhornacute: 0x1EE8,
  21327. Uhorndotbelow: 0x1EF0,
  21328. Uhorngrave: 0x1EEA,
  21329. Uhornhookabove: 0x1EEC,
  21330. Uhorntilde: 0x1EEE,
  21331. Uhungarumlaut: 0x0170,
  21332. Uhungarumlautcyrillic: 0x04F2,
  21333. Uinvertedbreve: 0x0216,
  21334. Ukcyrillic: 0x0478,
  21335. Umacron: 0x016A,
  21336. Umacroncyrillic: 0x04EE,
  21337. Umacrondieresis: 0x1E7A,
  21338. Umonospace: 0xFF35,
  21339. Uogonek: 0x0172,
  21340. Upsilon: 0x03A5,
  21341. Upsilon1: 0x03D2,
  21342. Upsilonacutehooksymbolgreek: 0x03D3,
  21343. Upsilonafrican: 0x01B1,
  21344. Upsilondieresis: 0x03AB,
  21345. Upsilondieresishooksymbolgreek: 0x03D4,
  21346. Upsilonhooksymbol: 0x03D2,
  21347. Upsilontonos: 0x038E,
  21348. Uring: 0x016E,
  21349. Ushortcyrillic: 0x040E,
  21350. Usmall: 0xF775,
  21351. Ustraightcyrillic: 0x04AE,
  21352. Ustraightstrokecyrillic: 0x04B0,
  21353. Utilde: 0x0168,
  21354. Utildeacute: 0x1E78,
  21355. Utildebelow: 0x1E74,
  21356. V: 0x0056,
  21357. Vcircle: 0x24CB,
  21358. Vdotbelow: 0x1E7E,
  21359. Vecyrillic: 0x0412,
  21360. Vewarmenian: 0x054E,
  21361. Vhook: 0x01B2,
  21362. Vmonospace: 0xFF36,
  21363. Voarmenian: 0x0548,
  21364. Vsmall: 0xF776,
  21365. Vtilde: 0x1E7C,
  21366. W: 0x0057,
  21367. Wacute: 0x1E82,
  21368. Wcircle: 0x24CC,
  21369. Wcircumflex: 0x0174,
  21370. Wdieresis: 0x1E84,
  21371. Wdotaccent: 0x1E86,
  21372. Wdotbelow: 0x1E88,
  21373. Wgrave: 0x1E80,
  21374. Wmonospace: 0xFF37,
  21375. Wsmall: 0xF777,
  21376. X: 0x0058,
  21377. Xcircle: 0x24CD,
  21378. Xdieresis: 0x1E8C,
  21379. Xdotaccent: 0x1E8A,
  21380. Xeharmenian: 0x053D,
  21381. Xi: 0x039E,
  21382. Xmonospace: 0xFF38,
  21383. Xsmall: 0xF778,
  21384. Y: 0x0059,
  21385. Yacute: 0x00DD,
  21386. Yacutesmall: 0xF7FD,
  21387. Yatcyrillic: 0x0462,
  21388. Ycircle: 0x24CE,
  21389. Ycircumflex: 0x0176,
  21390. Ydieresis: 0x0178,
  21391. Ydieresissmall: 0xF7FF,
  21392. Ydotaccent: 0x1E8E,
  21393. Ydotbelow: 0x1EF4,
  21394. Yericyrillic: 0x042B,
  21395. Yerudieresiscyrillic: 0x04F8,
  21396. Ygrave: 0x1EF2,
  21397. Yhook: 0x01B3,
  21398. Yhookabove: 0x1EF6,
  21399. Yiarmenian: 0x0545,
  21400. Yicyrillic: 0x0407,
  21401. Yiwnarmenian: 0x0552,
  21402. Ymonospace: 0xFF39,
  21403. Ysmall: 0xF779,
  21404. Ytilde: 0x1EF8,
  21405. Yusbigcyrillic: 0x046A,
  21406. Yusbigiotifiedcyrillic: 0x046C,
  21407. Yuslittlecyrillic: 0x0466,
  21408. Yuslittleiotifiedcyrillic: 0x0468,
  21409. Z: 0x005A,
  21410. Zaarmenian: 0x0536,
  21411. Zacute: 0x0179,
  21412. Zcaron: 0x017D,
  21413. Zcaronsmall: 0xF6FF,
  21414. Zcircle: 0x24CF,
  21415. Zcircumflex: 0x1E90,
  21416. Zdot: 0x017B,
  21417. Zdotaccent: 0x017B,
  21418. Zdotbelow: 0x1E92,
  21419. Zecyrillic: 0x0417,
  21420. Zedescendercyrillic: 0x0498,
  21421. Zedieresiscyrillic: 0x04DE,
  21422. Zeta: 0x0396,
  21423. Zhearmenian: 0x053A,
  21424. Zhebrevecyrillic: 0x04C1,
  21425. Zhecyrillic: 0x0416,
  21426. Zhedescendercyrillic: 0x0496,
  21427. Zhedieresiscyrillic: 0x04DC,
  21428. Zlinebelow: 0x1E94,
  21429. Zmonospace: 0xFF3A,
  21430. Zsmall: 0xF77A,
  21431. Zstroke: 0x01B5,
  21432. a: 0x0061,
  21433. aabengali: 0x0986,
  21434. aacute: 0x00E1,
  21435. aadeva: 0x0906,
  21436. aagujarati: 0x0A86,
  21437. aagurmukhi: 0x0A06,
  21438. aamatragurmukhi: 0x0A3E,
  21439. aarusquare: 0x3303,
  21440. aavowelsignbengali: 0x09BE,
  21441. aavowelsigndeva: 0x093E,
  21442. aavowelsigngujarati: 0x0ABE,
  21443. abbreviationmarkarmenian: 0x055F,
  21444. abbreviationsigndeva: 0x0970,
  21445. abengali: 0x0985,
  21446. abopomofo: 0x311A,
  21447. abreve: 0x0103,
  21448. abreveacute: 0x1EAF,
  21449. abrevecyrillic: 0x04D1,
  21450. abrevedotbelow: 0x1EB7,
  21451. abrevegrave: 0x1EB1,
  21452. abrevehookabove: 0x1EB3,
  21453. abrevetilde: 0x1EB5,
  21454. acaron: 0x01CE,
  21455. acircle: 0x24D0,
  21456. acircumflex: 0x00E2,
  21457. acircumflexacute: 0x1EA5,
  21458. acircumflexdotbelow: 0x1EAD,
  21459. acircumflexgrave: 0x1EA7,
  21460. acircumflexhookabove: 0x1EA9,
  21461. acircumflextilde: 0x1EAB,
  21462. acute: 0x00B4,
  21463. acutebelowcmb: 0x0317,
  21464. acutecmb: 0x0301,
  21465. acutecomb: 0x0301,
  21466. acutedeva: 0x0954,
  21467. acutelowmod: 0x02CF,
  21468. acutetonecmb: 0x0341,
  21469. acyrillic: 0x0430,
  21470. adblgrave: 0x0201,
  21471. addakgurmukhi: 0x0A71,
  21472. adeva: 0x0905,
  21473. adieresis: 0x00E4,
  21474. adieresiscyrillic: 0x04D3,
  21475. adieresismacron: 0x01DF,
  21476. adotbelow: 0x1EA1,
  21477. adotmacron: 0x01E1,
  21478. ae: 0x00E6,
  21479. aeacute: 0x01FD,
  21480. aekorean: 0x3150,
  21481. aemacron: 0x01E3,
  21482. afii00208: 0x2015,
  21483. afii08941: 0x20A4,
  21484. afii10017: 0x0410,
  21485. afii10018: 0x0411,
  21486. afii10019: 0x0412,
  21487. afii10020: 0x0413,
  21488. afii10021: 0x0414,
  21489. afii10022: 0x0415,
  21490. afii10023: 0x0401,
  21491. afii10024: 0x0416,
  21492. afii10025: 0x0417,
  21493. afii10026: 0x0418,
  21494. afii10027: 0x0419,
  21495. afii10028: 0x041A,
  21496. afii10029: 0x041B,
  21497. afii10030: 0x041C,
  21498. afii10031: 0x041D,
  21499. afii10032: 0x041E,
  21500. afii10033: 0x041F,
  21501. afii10034: 0x0420,
  21502. afii10035: 0x0421,
  21503. afii10036: 0x0422,
  21504. afii10037: 0x0423,
  21505. afii10038: 0x0424,
  21506. afii10039: 0x0425,
  21507. afii10040: 0x0426,
  21508. afii10041: 0x0427,
  21509. afii10042: 0x0428,
  21510. afii10043: 0x0429,
  21511. afii10044: 0x042A,
  21512. afii10045: 0x042B,
  21513. afii10046: 0x042C,
  21514. afii10047: 0x042D,
  21515. afii10048: 0x042E,
  21516. afii10049: 0x042F,
  21517. afii10050: 0x0490,
  21518. afii10051: 0x0402,
  21519. afii10052: 0x0403,
  21520. afii10053: 0x0404,
  21521. afii10054: 0x0405,
  21522. afii10055: 0x0406,
  21523. afii10056: 0x0407,
  21524. afii10057: 0x0408,
  21525. afii10058: 0x0409,
  21526. afii10059: 0x040A,
  21527. afii10060: 0x040B,
  21528. afii10061: 0x040C,
  21529. afii10062: 0x040E,
  21530. afii10063: 0xF6C4,
  21531. afii10064: 0xF6C5,
  21532. afii10065: 0x0430,
  21533. afii10066: 0x0431,
  21534. afii10067: 0x0432,
  21535. afii10068: 0x0433,
  21536. afii10069: 0x0434,
  21537. afii10070: 0x0435,
  21538. afii10071: 0x0451,
  21539. afii10072: 0x0436,
  21540. afii10073: 0x0437,
  21541. afii10074: 0x0438,
  21542. afii10075: 0x0439,
  21543. afii10076: 0x043A,
  21544. afii10077: 0x043B,
  21545. afii10078: 0x043C,
  21546. afii10079: 0x043D,
  21547. afii10080: 0x043E,
  21548. afii10081: 0x043F,
  21549. afii10082: 0x0440,
  21550. afii10083: 0x0441,
  21551. afii10084: 0x0442,
  21552. afii10085: 0x0443,
  21553. afii10086: 0x0444,
  21554. afii10087: 0x0445,
  21555. afii10088: 0x0446,
  21556. afii10089: 0x0447,
  21557. afii10090: 0x0448,
  21558. afii10091: 0x0449,
  21559. afii10092: 0x044A,
  21560. afii10093: 0x044B,
  21561. afii10094: 0x044C,
  21562. afii10095: 0x044D,
  21563. afii10096: 0x044E,
  21564. afii10097: 0x044F,
  21565. afii10098: 0x0491,
  21566. afii10099: 0x0452,
  21567. afii10100: 0x0453,
  21568. afii10101: 0x0454,
  21569. afii10102: 0x0455,
  21570. afii10103: 0x0456,
  21571. afii10104: 0x0457,
  21572. afii10105: 0x0458,
  21573. afii10106: 0x0459,
  21574. afii10107: 0x045A,
  21575. afii10108: 0x045B,
  21576. afii10109: 0x045C,
  21577. afii10110: 0x045E,
  21578. afii10145: 0x040F,
  21579. afii10146: 0x0462,
  21580. afii10147: 0x0472,
  21581. afii10148: 0x0474,
  21582. afii10192: 0xF6C6,
  21583. afii10193: 0x045F,
  21584. afii10194: 0x0463,
  21585. afii10195: 0x0473,
  21586. afii10196: 0x0475,
  21587. afii10831: 0xF6C7,
  21588. afii10832: 0xF6C8,
  21589. afii10846: 0x04D9,
  21590. afii299: 0x200E,
  21591. afii300: 0x200F,
  21592. afii301: 0x200D,
  21593. afii57381: 0x066A,
  21594. afii57388: 0x060C,
  21595. afii57392: 0x0660,
  21596. afii57393: 0x0661,
  21597. afii57394: 0x0662,
  21598. afii57395: 0x0663,
  21599. afii57396: 0x0664,
  21600. afii57397: 0x0665,
  21601. afii57398: 0x0666,
  21602. afii57399: 0x0667,
  21603. afii57400: 0x0668,
  21604. afii57401: 0x0669,
  21605. afii57403: 0x061B,
  21606. afii57407: 0x061F,
  21607. afii57409: 0x0621,
  21608. afii57410: 0x0622,
  21609. afii57411: 0x0623,
  21610. afii57412: 0x0624,
  21611. afii57413: 0x0625,
  21612. afii57414: 0x0626,
  21613. afii57415: 0x0627,
  21614. afii57416: 0x0628,
  21615. afii57417: 0x0629,
  21616. afii57418: 0x062A,
  21617. afii57419: 0x062B,
  21618. afii57420: 0x062C,
  21619. afii57421: 0x062D,
  21620. afii57422: 0x062E,
  21621. afii57423: 0x062F,
  21622. afii57424: 0x0630,
  21623. afii57425: 0x0631,
  21624. afii57426: 0x0632,
  21625. afii57427: 0x0633,
  21626. afii57428: 0x0634,
  21627. afii57429: 0x0635,
  21628. afii57430: 0x0636,
  21629. afii57431: 0x0637,
  21630. afii57432: 0x0638,
  21631. afii57433: 0x0639,
  21632. afii57434: 0x063A,
  21633. afii57440: 0x0640,
  21634. afii57441: 0x0641,
  21635. afii57442: 0x0642,
  21636. afii57443: 0x0643,
  21637. afii57444: 0x0644,
  21638. afii57445: 0x0645,
  21639. afii57446: 0x0646,
  21640. afii57448: 0x0648,
  21641. afii57449: 0x0649,
  21642. afii57450: 0x064A,
  21643. afii57451: 0x064B,
  21644. afii57452: 0x064C,
  21645. afii57453: 0x064D,
  21646. afii57454: 0x064E,
  21647. afii57455: 0x064F,
  21648. afii57456: 0x0650,
  21649. afii57457: 0x0651,
  21650. afii57458: 0x0652,
  21651. afii57470: 0x0647,
  21652. afii57505: 0x06A4,
  21653. afii57506: 0x067E,
  21654. afii57507: 0x0686,
  21655. afii57508: 0x0698,
  21656. afii57509: 0x06AF,
  21657. afii57511: 0x0679,
  21658. afii57512: 0x0688,
  21659. afii57513: 0x0691,
  21660. afii57514: 0x06BA,
  21661. afii57519: 0x06D2,
  21662. afii57534: 0x06D5,
  21663. afii57636: 0x20AA,
  21664. afii57645: 0x05BE,
  21665. afii57658: 0x05C3,
  21666. afii57664: 0x05D0,
  21667. afii57665: 0x05D1,
  21668. afii57666: 0x05D2,
  21669. afii57667: 0x05D3,
  21670. afii57668: 0x05D4,
  21671. afii57669: 0x05D5,
  21672. afii57670: 0x05D6,
  21673. afii57671: 0x05D7,
  21674. afii57672: 0x05D8,
  21675. afii57673: 0x05D9,
  21676. afii57674: 0x05DA,
  21677. afii57675: 0x05DB,
  21678. afii57676: 0x05DC,
  21679. afii57677: 0x05DD,
  21680. afii57678: 0x05DE,
  21681. afii57679: 0x05DF,
  21682. afii57680: 0x05E0,
  21683. afii57681: 0x05E1,
  21684. afii57682: 0x05E2,
  21685. afii57683: 0x05E3,
  21686. afii57684: 0x05E4,
  21687. afii57685: 0x05E5,
  21688. afii57686: 0x05E6,
  21689. afii57687: 0x05E7,
  21690. afii57688: 0x05E8,
  21691. afii57689: 0x05E9,
  21692. afii57690: 0x05EA,
  21693. afii57694: 0xFB2A,
  21694. afii57695: 0xFB2B,
  21695. afii57700: 0xFB4B,
  21696. afii57705: 0xFB1F,
  21697. afii57716: 0x05F0,
  21698. afii57717: 0x05F1,
  21699. afii57718: 0x05F2,
  21700. afii57723: 0xFB35,
  21701. afii57793: 0x05B4,
  21702. afii57794: 0x05B5,
  21703. afii57795: 0x05B6,
  21704. afii57796: 0x05BB,
  21705. afii57797: 0x05B8,
  21706. afii57798: 0x05B7,
  21707. afii57799: 0x05B0,
  21708. afii57800: 0x05B2,
  21709. afii57801: 0x05B1,
  21710. afii57802: 0x05B3,
  21711. afii57803: 0x05C2,
  21712. afii57804: 0x05C1,
  21713. afii57806: 0x05B9,
  21714. afii57807: 0x05BC,
  21715. afii57839: 0x05BD,
  21716. afii57841: 0x05BF,
  21717. afii57842: 0x05C0,
  21718. afii57929: 0x02BC,
  21719. afii61248: 0x2105,
  21720. afii61289: 0x2113,
  21721. afii61352: 0x2116,
  21722. afii61573: 0x202C,
  21723. afii61574: 0x202D,
  21724. afii61575: 0x202E,
  21725. afii61664: 0x200C,
  21726. afii63167: 0x066D,
  21727. afii64937: 0x02BD,
  21728. agrave: 0x00E0,
  21729. agujarati: 0x0A85,
  21730. agurmukhi: 0x0A05,
  21731. ahiragana: 0x3042,
  21732. ahookabove: 0x1EA3,
  21733. aibengali: 0x0990,
  21734. aibopomofo: 0x311E,
  21735. aideva: 0x0910,
  21736. aiecyrillic: 0x04D5,
  21737. aigujarati: 0x0A90,
  21738. aigurmukhi: 0x0A10,
  21739. aimatragurmukhi: 0x0A48,
  21740. ainarabic: 0x0639,
  21741. ainfinalarabic: 0xFECA,
  21742. aininitialarabic: 0xFECB,
  21743. ainmedialarabic: 0xFECC,
  21744. ainvertedbreve: 0x0203,
  21745. aivowelsignbengali: 0x09C8,
  21746. aivowelsigndeva: 0x0948,
  21747. aivowelsigngujarati: 0x0AC8,
  21748. akatakana: 0x30A2,
  21749. akatakanahalfwidth: 0xFF71,
  21750. akorean: 0x314F,
  21751. alef: 0x05D0,
  21752. alefarabic: 0x0627,
  21753. alefdageshhebrew: 0xFB30,
  21754. aleffinalarabic: 0xFE8E,
  21755. alefhamzaabovearabic: 0x0623,
  21756. alefhamzaabovefinalarabic: 0xFE84,
  21757. alefhamzabelowarabic: 0x0625,
  21758. alefhamzabelowfinalarabic: 0xFE88,
  21759. alefhebrew: 0x05D0,
  21760. aleflamedhebrew: 0xFB4F,
  21761. alefmaddaabovearabic: 0x0622,
  21762. alefmaddaabovefinalarabic: 0xFE82,
  21763. alefmaksuraarabic: 0x0649,
  21764. alefmaksurafinalarabic: 0xFEF0,
  21765. alefmaksurainitialarabic: 0xFEF3,
  21766. alefmaksuramedialarabic: 0xFEF4,
  21767. alefpatahhebrew: 0xFB2E,
  21768. alefqamatshebrew: 0xFB2F,
  21769. aleph: 0x2135,
  21770. allequal: 0x224C,
  21771. alpha: 0x03B1,
  21772. alphatonos: 0x03AC,
  21773. amacron: 0x0101,
  21774. amonospace: 0xFF41,
  21775. ampersand: 0x0026,
  21776. ampersandmonospace: 0xFF06,
  21777. ampersandsmall: 0xF726,
  21778. amsquare: 0x33C2,
  21779. anbopomofo: 0x3122,
  21780. angbopomofo: 0x3124,
  21781. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21782. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21783. angkhankhuthai: 0x0E5A,
  21784. angle: 0x2220,
  21785. anglebracketleft: 0x3008,
  21786. anglebracketleftvertical: 0xFE3F,
  21787. anglebracketright: 0x3009,
  21788. anglebracketrightvertical: 0xFE40,
  21789. angleleft: 0x2329,
  21790. angleright: 0x232A,
  21791. angstrom: 0x212B,
  21792. anoteleia: 0x0387,
  21793. anudattadeva: 0x0952,
  21794. anusvarabengali: 0x0982,
  21795. anusvaradeva: 0x0902,
  21796. anusvaragujarati: 0x0A82,
  21797. aogonek: 0x0105,
  21798. apaatosquare: 0x3300,
  21799. aparen: 0x249C,
  21800. apostrophearmenian: 0x055A,
  21801. apostrophemod: 0x02BC,
  21802. apple: 0xF8FF,
  21803. approaches: 0x2250,
  21804. approxequal: 0x2248,
  21805. approxequalorimage: 0x2252,
  21806. approximatelyequal: 0x2245,
  21807. araeaekorean: 0x318E,
  21808. araeakorean: 0x318D,
  21809. arc: 0x2312,
  21810. arighthalfring: 0x1E9A,
  21811. aring: 0x00E5,
  21812. aringacute: 0x01FB,
  21813. aringbelow: 0x1E01,
  21814. arrowboth: 0x2194,
  21815. arrowdashdown: 0x21E3,
  21816. arrowdashleft: 0x21E0,
  21817. arrowdashright: 0x21E2,
  21818. arrowdashup: 0x21E1,
  21819. arrowdblboth: 0x21D4,
  21820. arrowdbldown: 0x21D3,
  21821. arrowdblleft: 0x21D0,
  21822. arrowdblright: 0x21D2,
  21823. arrowdblup: 0x21D1,
  21824. arrowdown: 0x2193,
  21825. arrowdownleft: 0x2199,
  21826. arrowdownright: 0x2198,
  21827. arrowdownwhite: 0x21E9,
  21828. arrowheaddownmod: 0x02C5,
  21829. arrowheadleftmod: 0x02C2,
  21830. arrowheadrightmod: 0x02C3,
  21831. arrowheadupmod: 0x02C4,
  21832. arrowhorizex: 0xF8E7,
  21833. arrowleft: 0x2190,
  21834. arrowleftdbl: 0x21D0,
  21835. arrowleftdblstroke: 0x21CD,
  21836. arrowleftoverright: 0x21C6,
  21837. arrowleftwhite: 0x21E6,
  21838. arrowright: 0x2192,
  21839. arrowrightdblstroke: 0x21CF,
  21840. arrowrightheavy: 0x279E,
  21841. arrowrightoverleft: 0x21C4,
  21842. arrowrightwhite: 0x21E8,
  21843. arrowtableft: 0x21E4,
  21844. arrowtabright: 0x21E5,
  21845. arrowup: 0x2191,
  21846. arrowupdn: 0x2195,
  21847. arrowupdnbse: 0x21A8,
  21848. arrowupdownbase: 0x21A8,
  21849. arrowupleft: 0x2196,
  21850. arrowupleftofdown: 0x21C5,
  21851. arrowupright: 0x2197,
  21852. arrowupwhite: 0x21E7,
  21853. arrowvertex: 0xF8E6,
  21854. asciicircum: 0x005E,
  21855. asciicircummonospace: 0xFF3E,
  21856. asciitilde: 0x007E,
  21857. asciitildemonospace: 0xFF5E,
  21858. ascript: 0x0251,
  21859. ascriptturned: 0x0252,
  21860. asmallhiragana: 0x3041,
  21861. asmallkatakana: 0x30A1,
  21862. asmallkatakanahalfwidth: 0xFF67,
  21863. asterisk: 0x002A,
  21864. asteriskaltonearabic: 0x066D,
  21865. asteriskarabic: 0x066D,
  21866. asteriskmath: 0x2217,
  21867. asteriskmonospace: 0xFF0A,
  21868. asterisksmall: 0xFE61,
  21869. asterism: 0x2042,
  21870. asuperior: 0xF6E9,
  21871. asymptoticallyequal: 0x2243,
  21872. at: 0x0040,
  21873. atilde: 0x00E3,
  21874. atmonospace: 0xFF20,
  21875. atsmall: 0xFE6B,
  21876. aturned: 0x0250,
  21877. aubengali: 0x0994,
  21878. aubopomofo: 0x3120,
  21879. audeva: 0x0914,
  21880. augujarati: 0x0A94,
  21881. augurmukhi: 0x0A14,
  21882. aulengthmarkbengali: 0x09D7,
  21883. aumatragurmukhi: 0x0A4C,
  21884. auvowelsignbengali: 0x09CC,
  21885. auvowelsigndeva: 0x094C,
  21886. auvowelsigngujarati: 0x0ACC,
  21887. avagrahadeva: 0x093D,
  21888. aybarmenian: 0x0561,
  21889. ayin: 0x05E2,
  21890. ayinaltonehebrew: 0xFB20,
  21891. ayinhebrew: 0x05E2,
  21892. b: 0x0062,
  21893. babengali: 0x09AC,
  21894. backslash: 0x005C,
  21895. backslashmonospace: 0xFF3C,
  21896. badeva: 0x092C,
  21897. bagujarati: 0x0AAC,
  21898. bagurmukhi: 0x0A2C,
  21899. bahiragana: 0x3070,
  21900. bahtthai: 0x0E3F,
  21901. bakatakana: 0x30D0,
  21902. bar: 0x007C,
  21903. barmonospace: 0xFF5C,
  21904. bbopomofo: 0x3105,
  21905. bcircle: 0x24D1,
  21906. bdotaccent: 0x1E03,
  21907. bdotbelow: 0x1E05,
  21908. beamedsixteenthnotes: 0x266C,
  21909. because: 0x2235,
  21910. becyrillic: 0x0431,
  21911. beharabic: 0x0628,
  21912. behfinalarabic: 0xFE90,
  21913. behinitialarabic: 0xFE91,
  21914. behiragana: 0x3079,
  21915. behmedialarabic: 0xFE92,
  21916. behmeeminitialarabic: 0xFC9F,
  21917. behmeemisolatedarabic: 0xFC08,
  21918. behnoonfinalarabic: 0xFC6D,
  21919. bekatakana: 0x30D9,
  21920. benarmenian: 0x0562,
  21921. bet: 0x05D1,
  21922. beta: 0x03B2,
  21923. betasymbolgreek: 0x03D0,
  21924. betdagesh: 0xFB31,
  21925. betdageshhebrew: 0xFB31,
  21926. bethebrew: 0x05D1,
  21927. betrafehebrew: 0xFB4C,
  21928. bhabengali: 0x09AD,
  21929. bhadeva: 0x092D,
  21930. bhagujarati: 0x0AAD,
  21931. bhagurmukhi: 0x0A2D,
  21932. bhook: 0x0253,
  21933. bihiragana: 0x3073,
  21934. bikatakana: 0x30D3,
  21935. bilabialclick: 0x0298,
  21936. bindigurmukhi: 0x0A02,
  21937. birusquare: 0x3331,
  21938. blackcircle: 0x25CF,
  21939. blackdiamond: 0x25C6,
  21940. blackdownpointingtriangle: 0x25BC,
  21941. blackleftpointingpointer: 0x25C4,
  21942. blackleftpointingtriangle: 0x25C0,
  21943. blacklenticularbracketleft: 0x3010,
  21944. blacklenticularbracketleftvertical: 0xFE3B,
  21945. blacklenticularbracketright: 0x3011,
  21946. blacklenticularbracketrightvertical: 0xFE3C,
  21947. blacklowerlefttriangle: 0x25E3,
  21948. blacklowerrighttriangle: 0x25E2,
  21949. blackrectangle: 0x25AC,
  21950. blackrightpointingpointer: 0x25BA,
  21951. blackrightpointingtriangle: 0x25B6,
  21952. blacksmallsquare: 0x25AA,
  21953. blacksmilingface: 0x263B,
  21954. blacksquare: 0x25A0,
  21955. blackstar: 0x2605,
  21956. blackupperlefttriangle: 0x25E4,
  21957. blackupperrighttriangle: 0x25E5,
  21958. blackuppointingsmalltriangle: 0x25B4,
  21959. blackuppointingtriangle: 0x25B2,
  21960. blank: 0x2423,
  21961. blinebelow: 0x1E07,
  21962. block: 0x2588,
  21963. bmonospace: 0xFF42,
  21964. bobaimaithai: 0x0E1A,
  21965. bohiragana: 0x307C,
  21966. bokatakana: 0x30DC,
  21967. bparen: 0x249D,
  21968. bqsquare: 0x33C3,
  21969. braceex: 0xF8F4,
  21970. braceleft: 0x007B,
  21971. braceleftbt: 0xF8F3,
  21972. braceleftmid: 0xF8F2,
  21973. braceleftmonospace: 0xFF5B,
  21974. braceleftsmall: 0xFE5B,
  21975. bracelefttp: 0xF8F1,
  21976. braceleftvertical: 0xFE37,
  21977. braceright: 0x007D,
  21978. bracerightbt: 0xF8FE,
  21979. bracerightmid: 0xF8FD,
  21980. bracerightmonospace: 0xFF5D,
  21981. bracerightsmall: 0xFE5C,
  21982. bracerighttp: 0xF8FC,
  21983. bracerightvertical: 0xFE38,
  21984. bracketleft: 0x005B,
  21985. bracketleftbt: 0xF8F0,
  21986. bracketleftex: 0xF8EF,
  21987. bracketleftmonospace: 0xFF3B,
  21988. bracketlefttp: 0xF8EE,
  21989. bracketright: 0x005D,
  21990. bracketrightbt: 0xF8FB,
  21991. bracketrightex: 0xF8FA,
  21992. bracketrightmonospace: 0xFF3D,
  21993. bracketrighttp: 0xF8F9,
  21994. breve: 0x02D8,
  21995. brevebelowcmb: 0x032E,
  21996. brevecmb: 0x0306,
  21997. breveinvertedbelowcmb: 0x032F,
  21998. breveinvertedcmb: 0x0311,
  21999. breveinverteddoublecmb: 0x0361,
  22000. bridgebelowcmb: 0x032A,
  22001. bridgeinvertedbelowcmb: 0x033A,
  22002. brokenbar: 0x00A6,
  22003. bstroke: 0x0180,
  22004. bsuperior: 0xF6EA,
  22005. btopbar: 0x0183,
  22006. buhiragana: 0x3076,
  22007. bukatakana: 0x30D6,
  22008. bullet: 0x2022,
  22009. bulletinverse: 0x25D8,
  22010. bulletoperator: 0x2219,
  22011. bullseye: 0x25CE,
  22012. c: 0x0063,
  22013. caarmenian: 0x056E,
  22014. cabengali: 0x099A,
  22015. cacute: 0x0107,
  22016. cadeva: 0x091A,
  22017. cagujarati: 0x0A9A,
  22018. cagurmukhi: 0x0A1A,
  22019. calsquare: 0x3388,
  22020. candrabindubengali: 0x0981,
  22021. candrabinducmb: 0x0310,
  22022. candrabindudeva: 0x0901,
  22023. candrabindugujarati: 0x0A81,
  22024. capslock: 0x21EA,
  22025. careof: 0x2105,
  22026. caron: 0x02C7,
  22027. caronbelowcmb: 0x032C,
  22028. caroncmb: 0x030C,
  22029. carriagereturn: 0x21B5,
  22030. cbopomofo: 0x3118,
  22031. ccaron: 0x010D,
  22032. ccedilla: 0x00E7,
  22033. ccedillaacute: 0x1E09,
  22034. ccircle: 0x24D2,
  22035. ccircumflex: 0x0109,
  22036. ccurl: 0x0255,
  22037. cdot: 0x010B,
  22038. cdotaccent: 0x010B,
  22039. cdsquare: 0x33C5,
  22040. cedilla: 0x00B8,
  22041. cedillacmb: 0x0327,
  22042. cent: 0x00A2,
  22043. centigrade: 0x2103,
  22044. centinferior: 0xF6DF,
  22045. centmonospace: 0xFFE0,
  22046. centoldstyle: 0xF7A2,
  22047. centsuperior: 0xF6E0,
  22048. chaarmenian: 0x0579,
  22049. chabengali: 0x099B,
  22050. chadeva: 0x091B,
  22051. chagujarati: 0x0A9B,
  22052. chagurmukhi: 0x0A1B,
  22053. chbopomofo: 0x3114,
  22054. cheabkhasiancyrillic: 0x04BD,
  22055. checkmark: 0x2713,
  22056. checyrillic: 0x0447,
  22057. chedescenderabkhasiancyrillic: 0x04BF,
  22058. chedescendercyrillic: 0x04B7,
  22059. chedieresiscyrillic: 0x04F5,
  22060. cheharmenian: 0x0573,
  22061. chekhakassiancyrillic: 0x04CC,
  22062. cheverticalstrokecyrillic: 0x04B9,
  22063. chi: 0x03C7,
  22064. chieuchacirclekorean: 0x3277,
  22065. chieuchaparenkorean: 0x3217,
  22066. chieuchcirclekorean: 0x3269,
  22067. chieuchkorean: 0x314A,
  22068. chieuchparenkorean: 0x3209,
  22069. chochangthai: 0x0E0A,
  22070. chochanthai: 0x0E08,
  22071. chochingthai: 0x0E09,
  22072. chochoethai: 0x0E0C,
  22073. chook: 0x0188,
  22074. cieucacirclekorean: 0x3276,
  22075. cieucaparenkorean: 0x3216,
  22076. cieuccirclekorean: 0x3268,
  22077. cieuckorean: 0x3148,
  22078. cieucparenkorean: 0x3208,
  22079. cieucuparenkorean: 0x321C,
  22080. circle: 0x25CB,
  22081. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  22082. circlemultiply: 0x2297,
  22083. circleot: 0x2299,
  22084. circleplus: 0x2295,
  22085. circlepostalmark: 0x3036,
  22086. circlewithlefthalfblack: 0x25D0,
  22087. circlewithrighthalfblack: 0x25D1,
  22088. circumflex: 0x02C6,
  22089. circumflexbelowcmb: 0x032D,
  22090. circumflexcmb: 0x0302,
  22091. clear: 0x2327,
  22092. clickalveolar: 0x01C2,
  22093. clickdental: 0x01C0,
  22094. clicklateral: 0x01C1,
  22095. clickretroflex: 0x01C3,
  22096. club: 0x2663,
  22097. clubsuitblack: 0x2663,
  22098. clubsuitwhite: 0x2667,
  22099. cmcubedsquare: 0x33A4,
  22100. cmonospace: 0xFF43,
  22101. cmsquaredsquare: 0x33A0,
  22102. coarmenian: 0x0581,
  22103. colon: 0x003A,
  22104. colonmonetary: 0x20A1,
  22105. colonmonospace: 0xFF1A,
  22106. colonsign: 0x20A1,
  22107. colonsmall: 0xFE55,
  22108. colontriangularhalfmod: 0x02D1,
  22109. colontriangularmod: 0x02D0,
  22110. comma: 0x002C,
  22111. commaabovecmb: 0x0313,
  22112. commaaboverightcmb: 0x0315,
  22113. commaaccent: 0xF6C3,
  22114. commaarabic: 0x060C,
  22115. commaarmenian: 0x055D,
  22116. commainferior: 0xF6E1,
  22117. commamonospace: 0xFF0C,
  22118. commareversedabovecmb: 0x0314,
  22119. commareversedmod: 0x02BD,
  22120. commasmall: 0xFE50,
  22121. commasuperior: 0xF6E2,
  22122. commaturnedabovecmb: 0x0312,
  22123. commaturnedmod: 0x02BB,
  22124. compass: 0x263C,
  22125. congruent: 0x2245,
  22126. contourintegral: 0x222E,
  22127. control: 0x2303,
  22128. controlACK: 0x0006,
  22129. controlBEL: 0x0007,
  22130. controlBS: 0x0008,
  22131. controlCAN: 0x0018,
  22132. controlCR: 0x000D,
  22133. controlDC1: 0x0011,
  22134. controlDC2: 0x0012,
  22135. controlDC3: 0x0013,
  22136. controlDC4: 0x0014,
  22137. controlDEL: 0x007F,
  22138. controlDLE: 0x0010,
  22139. controlEM: 0x0019,
  22140. controlENQ: 0x0005,
  22141. controlEOT: 0x0004,
  22142. controlESC: 0x001B,
  22143. controlETB: 0x0017,
  22144. controlETX: 0x0003,
  22145. controlFF: 0x000C,
  22146. controlFS: 0x001C,
  22147. controlGS: 0x001D,
  22148. controlHT: 0x0009,
  22149. controlLF: 0x000A,
  22150. controlNAK: 0x0015,
  22151. controlRS: 0x001E,
  22152. controlSI: 0x000F,
  22153. controlSO: 0x000E,
  22154. controlSOT: 0x0002,
  22155. controlSTX: 0x0001,
  22156. controlSUB: 0x001A,
  22157. controlSYN: 0x0016,
  22158. controlUS: 0x001F,
  22159. controlVT: 0x000B,
  22160. copyright: 0x00A9,
  22161. copyrightsans: 0xF8E9,
  22162. copyrightserif: 0xF6D9,
  22163. cornerbracketleft: 0x300C,
  22164. cornerbracketlefthalfwidth: 0xFF62,
  22165. cornerbracketleftvertical: 0xFE41,
  22166. cornerbracketright: 0x300D,
  22167. cornerbracketrighthalfwidth: 0xFF63,
  22168. cornerbracketrightvertical: 0xFE42,
  22169. corporationsquare: 0x337F,
  22170. cosquare: 0x33C7,
  22171. coverkgsquare: 0x33C6,
  22172. cparen: 0x249E,
  22173. cruzeiro: 0x20A2,
  22174. cstretched: 0x0297,
  22175. curlyand: 0x22CF,
  22176. curlyor: 0x22CE,
  22177. currency: 0x00A4,
  22178. cyrBreve: 0xF6D1,
  22179. cyrFlex: 0xF6D2,
  22180. cyrbreve: 0xF6D4,
  22181. cyrflex: 0xF6D5,
  22182. d: 0x0064,
  22183. daarmenian: 0x0564,
  22184. dabengali: 0x09A6,
  22185. dadarabic: 0x0636,
  22186. dadeva: 0x0926,
  22187. dadfinalarabic: 0xFEBE,
  22188. dadinitialarabic: 0xFEBF,
  22189. dadmedialarabic: 0xFEC0,
  22190. dagesh: 0x05BC,
  22191. dageshhebrew: 0x05BC,
  22192. dagger: 0x2020,
  22193. daggerdbl: 0x2021,
  22194. dagujarati: 0x0AA6,
  22195. dagurmukhi: 0x0A26,
  22196. dahiragana: 0x3060,
  22197. dakatakana: 0x30C0,
  22198. dalarabic: 0x062F,
  22199. dalet: 0x05D3,
  22200. daletdagesh: 0xFB33,
  22201. daletdageshhebrew: 0xFB33,
  22202. dalethebrew: 0x05D3,
  22203. dalfinalarabic: 0xFEAA,
  22204. dammaarabic: 0x064F,
  22205. dammalowarabic: 0x064F,
  22206. dammatanaltonearabic: 0x064C,
  22207. dammatanarabic: 0x064C,
  22208. danda: 0x0964,
  22209. dargahebrew: 0x05A7,
  22210. dargalefthebrew: 0x05A7,
  22211. dasiapneumatacyrilliccmb: 0x0485,
  22212. dblGrave: 0xF6D3,
  22213. dblanglebracketleft: 0x300A,
  22214. dblanglebracketleftvertical: 0xFE3D,
  22215. dblanglebracketright: 0x300B,
  22216. dblanglebracketrightvertical: 0xFE3E,
  22217. dblarchinvertedbelowcmb: 0x032B,
  22218. dblarrowleft: 0x21D4,
  22219. dblarrowright: 0x21D2,
  22220. dbldanda: 0x0965,
  22221. dblgrave: 0xF6D6,
  22222. dblgravecmb: 0x030F,
  22223. dblintegral: 0x222C,
  22224. dbllowline: 0x2017,
  22225. dbllowlinecmb: 0x0333,
  22226. dbloverlinecmb: 0x033F,
  22227. dblprimemod: 0x02BA,
  22228. dblverticalbar: 0x2016,
  22229. dblverticallineabovecmb: 0x030E,
  22230. dbopomofo: 0x3109,
  22231. dbsquare: 0x33C8,
  22232. dcaron: 0x010F,
  22233. dcedilla: 0x1E11,
  22234. dcircle: 0x24D3,
  22235. dcircumflexbelow: 0x1E13,
  22236. dcroat: 0x0111,
  22237. ddabengali: 0x09A1,
  22238. ddadeva: 0x0921,
  22239. ddagujarati: 0x0AA1,
  22240. ddagurmukhi: 0x0A21,
  22241. ddalarabic: 0x0688,
  22242. ddalfinalarabic: 0xFB89,
  22243. dddhadeva: 0x095C,
  22244. ddhabengali: 0x09A2,
  22245. ddhadeva: 0x0922,
  22246. ddhagujarati: 0x0AA2,
  22247. ddhagurmukhi: 0x0A22,
  22248. ddotaccent: 0x1E0B,
  22249. ddotbelow: 0x1E0D,
  22250. decimalseparatorarabic: 0x066B,
  22251. decimalseparatorpersian: 0x066B,
  22252. decyrillic: 0x0434,
  22253. degree: 0x00B0,
  22254. dehihebrew: 0x05AD,
  22255. dehiragana: 0x3067,
  22256. deicoptic: 0x03EF,
  22257. dekatakana: 0x30C7,
  22258. deleteleft: 0x232B,
  22259. deleteright: 0x2326,
  22260. delta: 0x03B4,
  22261. deltaturned: 0x018D,
  22262. denominatorminusonenumeratorbengali: 0x09F8,
  22263. dezh: 0x02A4,
  22264. dhabengali: 0x09A7,
  22265. dhadeva: 0x0927,
  22266. dhagujarati: 0x0AA7,
  22267. dhagurmukhi: 0x0A27,
  22268. dhook: 0x0257,
  22269. dialytikatonos: 0x0385,
  22270. dialytikatonoscmb: 0x0344,
  22271. diamond: 0x2666,
  22272. diamondsuitwhite: 0x2662,
  22273. dieresis: 0x00A8,
  22274. dieresisacute: 0xF6D7,
  22275. dieresisbelowcmb: 0x0324,
  22276. dieresiscmb: 0x0308,
  22277. dieresisgrave: 0xF6D8,
  22278. dieresistonos: 0x0385,
  22279. dihiragana: 0x3062,
  22280. dikatakana: 0x30C2,
  22281. dittomark: 0x3003,
  22282. divide: 0x00F7,
  22283. divides: 0x2223,
  22284. divisionslash: 0x2215,
  22285. djecyrillic: 0x0452,
  22286. dkshade: 0x2593,
  22287. dlinebelow: 0x1E0F,
  22288. dlsquare: 0x3397,
  22289. dmacron: 0x0111,
  22290. dmonospace: 0xFF44,
  22291. dnblock: 0x2584,
  22292. dochadathai: 0x0E0E,
  22293. dodekthai: 0x0E14,
  22294. dohiragana: 0x3069,
  22295. dokatakana: 0x30C9,
  22296. dollar: 0x0024,
  22297. dollarinferior: 0xF6E3,
  22298. dollarmonospace: 0xFF04,
  22299. dollaroldstyle: 0xF724,
  22300. dollarsmall: 0xFE69,
  22301. dollarsuperior: 0xF6E4,
  22302. dong: 0x20AB,
  22303. dorusquare: 0x3326,
  22304. dotaccent: 0x02D9,
  22305. dotaccentcmb: 0x0307,
  22306. dotbelowcmb: 0x0323,
  22307. dotbelowcomb: 0x0323,
  22308. dotkatakana: 0x30FB,
  22309. dotlessi: 0x0131,
  22310. dotlessj: 0xF6BE,
  22311. dotlessjstrokehook: 0x0284,
  22312. dotmath: 0x22C5,
  22313. dottedcircle: 0x25CC,
  22314. doubleyodpatah: 0xFB1F,
  22315. doubleyodpatahhebrew: 0xFB1F,
  22316. downtackbelowcmb: 0x031E,
  22317. downtackmod: 0x02D5,
  22318. dparen: 0x249F,
  22319. dsuperior: 0xF6EB,
  22320. dtail: 0x0256,
  22321. dtopbar: 0x018C,
  22322. duhiragana: 0x3065,
  22323. dukatakana: 0x30C5,
  22324. dz: 0x01F3,
  22325. dzaltone: 0x02A3,
  22326. dzcaron: 0x01C6,
  22327. dzcurl: 0x02A5,
  22328. dzeabkhasiancyrillic: 0x04E1,
  22329. dzecyrillic: 0x0455,
  22330. dzhecyrillic: 0x045F,
  22331. e: 0x0065,
  22332. eacute: 0x00E9,
  22333. earth: 0x2641,
  22334. ebengali: 0x098F,
  22335. ebopomofo: 0x311C,
  22336. ebreve: 0x0115,
  22337. ecandradeva: 0x090D,
  22338. ecandragujarati: 0x0A8D,
  22339. ecandravowelsigndeva: 0x0945,
  22340. ecandravowelsigngujarati: 0x0AC5,
  22341. ecaron: 0x011B,
  22342. ecedillabreve: 0x1E1D,
  22343. echarmenian: 0x0565,
  22344. echyiwnarmenian: 0x0587,
  22345. ecircle: 0x24D4,
  22346. ecircumflex: 0x00EA,
  22347. ecircumflexacute: 0x1EBF,
  22348. ecircumflexbelow: 0x1E19,
  22349. ecircumflexdotbelow: 0x1EC7,
  22350. ecircumflexgrave: 0x1EC1,
  22351. ecircumflexhookabove: 0x1EC3,
  22352. ecircumflextilde: 0x1EC5,
  22353. ecyrillic: 0x0454,
  22354. edblgrave: 0x0205,
  22355. edeva: 0x090F,
  22356. edieresis: 0x00EB,
  22357. edot: 0x0117,
  22358. edotaccent: 0x0117,
  22359. edotbelow: 0x1EB9,
  22360. eegurmukhi: 0x0A0F,
  22361. eematragurmukhi: 0x0A47,
  22362. efcyrillic: 0x0444,
  22363. egrave: 0x00E8,
  22364. egujarati: 0x0A8F,
  22365. eharmenian: 0x0567,
  22366. ehbopomofo: 0x311D,
  22367. ehiragana: 0x3048,
  22368. ehookabove: 0x1EBB,
  22369. eibopomofo: 0x311F,
  22370. eight: 0x0038,
  22371. eightarabic: 0x0668,
  22372. eightbengali: 0x09EE,
  22373. eightcircle: 0x2467,
  22374. eightcircleinversesansserif: 0x2791,
  22375. eightdeva: 0x096E,
  22376. eighteencircle: 0x2471,
  22377. eighteenparen: 0x2485,
  22378. eighteenperiod: 0x2499,
  22379. eightgujarati: 0x0AEE,
  22380. eightgurmukhi: 0x0A6E,
  22381. eighthackarabic: 0x0668,
  22382. eighthangzhou: 0x3028,
  22383. eighthnotebeamed: 0x266B,
  22384. eightideographicparen: 0x3227,
  22385. eightinferior: 0x2088,
  22386. eightmonospace: 0xFF18,
  22387. eightoldstyle: 0xF738,
  22388. eightparen: 0x247B,
  22389. eightperiod: 0x248F,
  22390. eightpersian: 0x06F8,
  22391. eightroman: 0x2177,
  22392. eightsuperior: 0x2078,
  22393. eightthai: 0x0E58,
  22394. einvertedbreve: 0x0207,
  22395. eiotifiedcyrillic: 0x0465,
  22396. ekatakana: 0x30A8,
  22397. ekatakanahalfwidth: 0xFF74,
  22398. ekonkargurmukhi: 0x0A74,
  22399. ekorean: 0x3154,
  22400. elcyrillic: 0x043B,
  22401. element: 0x2208,
  22402. elevencircle: 0x246A,
  22403. elevenparen: 0x247E,
  22404. elevenperiod: 0x2492,
  22405. elevenroman: 0x217A,
  22406. ellipsis: 0x2026,
  22407. ellipsisvertical: 0x22EE,
  22408. emacron: 0x0113,
  22409. emacronacute: 0x1E17,
  22410. emacrongrave: 0x1E15,
  22411. emcyrillic: 0x043C,
  22412. emdash: 0x2014,
  22413. emdashvertical: 0xFE31,
  22414. emonospace: 0xFF45,
  22415. emphasismarkarmenian: 0x055B,
  22416. emptyset: 0x2205,
  22417. enbopomofo: 0x3123,
  22418. encyrillic: 0x043D,
  22419. endash: 0x2013,
  22420. endashvertical: 0xFE32,
  22421. endescendercyrillic: 0x04A3,
  22422. eng: 0x014B,
  22423. engbopomofo: 0x3125,
  22424. enghecyrillic: 0x04A5,
  22425. enhookcyrillic: 0x04C8,
  22426. enspace: 0x2002,
  22427. eogonek: 0x0119,
  22428. eokorean: 0x3153,
  22429. eopen: 0x025B,
  22430. eopenclosed: 0x029A,
  22431. eopenreversed: 0x025C,
  22432. eopenreversedclosed: 0x025E,
  22433. eopenreversedhook: 0x025D,
  22434. eparen: 0x24A0,
  22435. epsilon: 0x03B5,
  22436. epsilontonos: 0x03AD,
  22437. equal: 0x003D,
  22438. equalmonospace: 0xFF1D,
  22439. equalsmall: 0xFE66,
  22440. equalsuperior: 0x207C,
  22441. equivalence: 0x2261,
  22442. erbopomofo: 0x3126,
  22443. ercyrillic: 0x0440,
  22444. ereversed: 0x0258,
  22445. ereversedcyrillic: 0x044D,
  22446. escyrillic: 0x0441,
  22447. esdescendercyrillic: 0x04AB,
  22448. esh: 0x0283,
  22449. eshcurl: 0x0286,
  22450. eshortdeva: 0x090E,
  22451. eshortvowelsigndeva: 0x0946,
  22452. eshreversedloop: 0x01AA,
  22453. eshsquatreversed: 0x0285,
  22454. esmallhiragana: 0x3047,
  22455. esmallkatakana: 0x30A7,
  22456. esmallkatakanahalfwidth: 0xFF6A,
  22457. estimated: 0x212E,
  22458. esuperior: 0xF6EC,
  22459. eta: 0x03B7,
  22460. etarmenian: 0x0568,
  22461. etatonos: 0x03AE,
  22462. eth: 0x00F0,
  22463. etilde: 0x1EBD,
  22464. etildebelow: 0x1E1B,
  22465. etnahtafoukhhebrew: 0x0591,
  22466. etnahtafoukhlefthebrew: 0x0591,
  22467. etnahtahebrew: 0x0591,
  22468. etnahtalefthebrew: 0x0591,
  22469. eturned: 0x01DD,
  22470. eukorean: 0x3161,
  22471. euro: 0x20AC,
  22472. evowelsignbengali: 0x09C7,
  22473. evowelsigndeva: 0x0947,
  22474. evowelsigngujarati: 0x0AC7,
  22475. exclam: 0x0021,
  22476. exclamarmenian: 0x055C,
  22477. exclamdbl: 0x203C,
  22478. exclamdown: 0x00A1,
  22479. exclamdownsmall: 0xF7A1,
  22480. exclammonospace: 0xFF01,
  22481. exclamsmall: 0xF721,
  22482. existential: 0x2203,
  22483. ezh: 0x0292,
  22484. ezhcaron: 0x01EF,
  22485. ezhcurl: 0x0293,
  22486. ezhreversed: 0x01B9,
  22487. ezhtail: 0x01BA,
  22488. f: 0x0066,
  22489. fadeva: 0x095E,
  22490. fagurmukhi: 0x0A5E,
  22491. fahrenheit: 0x2109,
  22492. fathaarabic: 0x064E,
  22493. fathalowarabic: 0x064E,
  22494. fathatanarabic: 0x064B,
  22495. fbopomofo: 0x3108,
  22496. fcircle: 0x24D5,
  22497. fdotaccent: 0x1E1F,
  22498. feharabic: 0x0641,
  22499. feharmenian: 0x0586,
  22500. fehfinalarabic: 0xFED2,
  22501. fehinitialarabic: 0xFED3,
  22502. fehmedialarabic: 0xFED4,
  22503. feicoptic: 0x03E5,
  22504. female: 0x2640,
  22505. ff: 0xFB00,
  22506. ffi: 0xFB03,
  22507. ffl: 0xFB04,
  22508. fi: 0xFB01,
  22509. fifteencircle: 0x246E,
  22510. fifteenparen: 0x2482,
  22511. fifteenperiod: 0x2496,
  22512. figuredash: 0x2012,
  22513. filledbox: 0x25A0,
  22514. filledrect: 0x25AC,
  22515. finalkaf: 0x05DA,
  22516. finalkafdagesh: 0xFB3A,
  22517. finalkafdageshhebrew: 0xFB3A,
  22518. finalkafhebrew: 0x05DA,
  22519. finalmem: 0x05DD,
  22520. finalmemhebrew: 0x05DD,
  22521. finalnun: 0x05DF,
  22522. finalnunhebrew: 0x05DF,
  22523. finalpe: 0x05E3,
  22524. finalpehebrew: 0x05E3,
  22525. finaltsadi: 0x05E5,
  22526. finaltsadihebrew: 0x05E5,
  22527. firsttonechinese: 0x02C9,
  22528. fisheye: 0x25C9,
  22529. fitacyrillic: 0x0473,
  22530. five: 0x0035,
  22531. fivearabic: 0x0665,
  22532. fivebengali: 0x09EB,
  22533. fivecircle: 0x2464,
  22534. fivecircleinversesansserif: 0x278E,
  22535. fivedeva: 0x096B,
  22536. fiveeighths: 0x215D,
  22537. fivegujarati: 0x0AEB,
  22538. fivegurmukhi: 0x0A6B,
  22539. fivehackarabic: 0x0665,
  22540. fivehangzhou: 0x3025,
  22541. fiveideographicparen: 0x3224,
  22542. fiveinferior: 0x2085,
  22543. fivemonospace: 0xFF15,
  22544. fiveoldstyle: 0xF735,
  22545. fiveparen: 0x2478,
  22546. fiveperiod: 0x248C,
  22547. fivepersian: 0x06F5,
  22548. fiveroman: 0x2174,
  22549. fivesuperior: 0x2075,
  22550. fivethai: 0x0E55,
  22551. fl: 0xFB02,
  22552. florin: 0x0192,
  22553. fmonospace: 0xFF46,
  22554. fmsquare: 0x3399,
  22555. fofanthai: 0x0E1F,
  22556. fofathai: 0x0E1D,
  22557. fongmanthai: 0x0E4F,
  22558. forall: 0x2200,
  22559. four: 0x0034,
  22560. fourarabic: 0x0664,
  22561. fourbengali: 0x09EA,
  22562. fourcircle: 0x2463,
  22563. fourcircleinversesansserif: 0x278D,
  22564. fourdeva: 0x096A,
  22565. fourgujarati: 0x0AEA,
  22566. fourgurmukhi: 0x0A6A,
  22567. fourhackarabic: 0x0664,
  22568. fourhangzhou: 0x3024,
  22569. fourideographicparen: 0x3223,
  22570. fourinferior: 0x2084,
  22571. fourmonospace: 0xFF14,
  22572. fournumeratorbengali: 0x09F7,
  22573. fouroldstyle: 0xF734,
  22574. fourparen: 0x2477,
  22575. fourperiod: 0x248B,
  22576. fourpersian: 0x06F4,
  22577. fourroman: 0x2173,
  22578. foursuperior: 0x2074,
  22579. fourteencircle: 0x246D,
  22580. fourteenparen: 0x2481,
  22581. fourteenperiod: 0x2495,
  22582. fourthai: 0x0E54,
  22583. fourthtonechinese: 0x02CB,
  22584. fparen: 0x24A1,
  22585. fraction: 0x2044,
  22586. franc: 0x20A3,
  22587. g: 0x0067,
  22588. gabengali: 0x0997,
  22589. gacute: 0x01F5,
  22590. gadeva: 0x0917,
  22591. gafarabic: 0x06AF,
  22592. gaffinalarabic: 0xFB93,
  22593. gafinitialarabic: 0xFB94,
  22594. gafmedialarabic: 0xFB95,
  22595. gagujarati: 0x0A97,
  22596. gagurmukhi: 0x0A17,
  22597. gahiragana: 0x304C,
  22598. gakatakana: 0x30AC,
  22599. gamma: 0x03B3,
  22600. gammalatinsmall: 0x0263,
  22601. gammasuperior: 0x02E0,
  22602. gangiacoptic: 0x03EB,
  22603. gbopomofo: 0x310D,
  22604. gbreve: 0x011F,
  22605. gcaron: 0x01E7,
  22606. gcedilla: 0x0123,
  22607. gcircle: 0x24D6,
  22608. gcircumflex: 0x011D,
  22609. gcommaaccent: 0x0123,
  22610. gdot: 0x0121,
  22611. gdotaccent: 0x0121,
  22612. gecyrillic: 0x0433,
  22613. gehiragana: 0x3052,
  22614. gekatakana: 0x30B2,
  22615. geometricallyequal: 0x2251,
  22616. gereshaccenthebrew: 0x059C,
  22617. gereshhebrew: 0x05F3,
  22618. gereshmuqdamhebrew: 0x059D,
  22619. germandbls: 0x00DF,
  22620. gershayimaccenthebrew: 0x059E,
  22621. gershayimhebrew: 0x05F4,
  22622. getamark: 0x3013,
  22623. ghabengali: 0x0998,
  22624. ghadarmenian: 0x0572,
  22625. ghadeva: 0x0918,
  22626. ghagujarati: 0x0A98,
  22627. ghagurmukhi: 0x0A18,
  22628. ghainarabic: 0x063A,
  22629. ghainfinalarabic: 0xFECE,
  22630. ghaininitialarabic: 0xFECF,
  22631. ghainmedialarabic: 0xFED0,
  22632. ghemiddlehookcyrillic: 0x0495,
  22633. ghestrokecyrillic: 0x0493,
  22634. gheupturncyrillic: 0x0491,
  22635. ghhadeva: 0x095A,
  22636. ghhagurmukhi: 0x0A5A,
  22637. ghook: 0x0260,
  22638. ghzsquare: 0x3393,
  22639. gihiragana: 0x304E,
  22640. gikatakana: 0x30AE,
  22641. gimarmenian: 0x0563,
  22642. gimel: 0x05D2,
  22643. gimeldagesh: 0xFB32,
  22644. gimeldageshhebrew: 0xFB32,
  22645. gimelhebrew: 0x05D2,
  22646. gjecyrillic: 0x0453,
  22647. glottalinvertedstroke: 0x01BE,
  22648. glottalstop: 0x0294,
  22649. glottalstopinverted: 0x0296,
  22650. glottalstopmod: 0x02C0,
  22651. glottalstopreversed: 0x0295,
  22652. glottalstopreversedmod: 0x02C1,
  22653. glottalstopreversedsuperior: 0x02E4,
  22654. glottalstopstroke: 0x02A1,
  22655. glottalstopstrokereversed: 0x02A2,
  22656. gmacron: 0x1E21,
  22657. gmonospace: 0xFF47,
  22658. gohiragana: 0x3054,
  22659. gokatakana: 0x30B4,
  22660. gparen: 0x24A2,
  22661. gpasquare: 0x33AC,
  22662. gradient: 0x2207,
  22663. grave: 0x0060,
  22664. gravebelowcmb: 0x0316,
  22665. gravecmb: 0x0300,
  22666. gravecomb: 0x0300,
  22667. gravedeva: 0x0953,
  22668. gravelowmod: 0x02CE,
  22669. gravemonospace: 0xFF40,
  22670. gravetonecmb: 0x0340,
  22671. greater: 0x003E,
  22672. greaterequal: 0x2265,
  22673. greaterequalorless: 0x22DB,
  22674. greatermonospace: 0xFF1E,
  22675. greaterorequivalent: 0x2273,
  22676. greaterorless: 0x2277,
  22677. greateroverequal: 0x2267,
  22678. greatersmall: 0xFE65,
  22679. gscript: 0x0261,
  22680. gstroke: 0x01E5,
  22681. guhiragana: 0x3050,
  22682. guillemotleft: 0x00AB,
  22683. guillemotright: 0x00BB,
  22684. guilsinglleft: 0x2039,
  22685. guilsinglright: 0x203A,
  22686. gukatakana: 0x30B0,
  22687. guramusquare: 0x3318,
  22688. gysquare: 0x33C9,
  22689. h: 0x0068,
  22690. haabkhasiancyrillic: 0x04A9,
  22691. haaltonearabic: 0x06C1,
  22692. habengali: 0x09B9,
  22693. hadescendercyrillic: 0x04B3,
  22694. hadeva: 0x0939,
  22695. hagujarati: 0x0AB9,
  22696. hagurmukhi: 0x0A39,
  22697. haharabic: 0x062D,
  22698. hahfinalarabic: 0xFEA2,
  22699. hahinitialarabic: 0xFEA3,
  22700. hahiragana: 0x306F,
  22701. hahmedialarabic: 0xFEA4,
  22702. haitusquare: 0x332A,
  22703. hakatakana: 0x30CF,
  22704. hakatakanahalfwidth: 0xFF8A,
  22705. halantgurmukhi: 0x0A4D,
  22706. hamzaarabic: 0x0621,
  22707. hamzalowarabic: 0x0621,
  22708. hangulfiller: 0x3164,
  22709. hardsigncyrillic: 0x044A,
  22710. harpoonleftbarbup: 0x21BC,
  22711. harpoonrightbarbup: 0x21C0,
  22712. hasquare: 0x33CA,
  22713. hatafpatah: 0x05B2,
  22714. hatafpatah16: 0x05B2,
  22715. hatafpatah23: 0x05B2,
  22716. hatafpatah2f: 0x05B2,
  22717. hatafpatahhebrew: 0x05B2,
  22718. hatafpatahnarrowhebrew: 0x05B2,
  22719. hatafpatahquarterhebrew: 0x05B2,
  22720. hatafpatahwidehebrew: 0x05B2,
  22721. hatafqamats: 0x05B3,
  22722. hatafqamats1b: 0x05B3,
  22723. hatafqamats28: 0x05B3,
  22724. hatafqamats34: 0x05B3,
  22725. hatafqamatshebrew: 0x05B3,
  22726. hatafqamatsnarrowhebrew: 0x05B3,
  22727. hatafqamatsquarterhebrew: 0x05B3,
  22728. hatafqamatswidehebrew: 0x05B3,
  22729. hatafsegol: 0x05B1,
  22730. hatafsegol17: 0x05B1,
  22731. hatafsegol24: 0x05B1,
  22732. hatafsegol30: 0x05B1,
  22733. hatafsegolhebrew: 0x05B1,
  22734. hatafsegolnarrowhebrew: 0x05B1,
  22735. hatafsegolquarterhebrew: 0x05B1,
  22736. hatafsegolwidehebrew: 0x05B1,
  22737. hbar: 0x0127,
  22738. hbopomofo: 0x310F,
  22739. hbrevebelow: 0x1E2B,
  22740. hcedilla: 0x1E29,
  22741. hcircle: 0x24D7,
  22742. hcircumflex: 0x0125,
  22743. hdieresis: 0x1E27,
  22744. hdotaccent: 0x1E23,
  22745. hdotbelow: 0x1E25,
  22746. he: 0x05D4,
  22747. heart: 0x2665,
  22748. heartsuitblack: 0x2665,
  22749. heartsuitwhite: 0x2661,
  22750. hedagesh: 0xFB34,
  22751. hedageshhebrew: 0xFB34,
  22752. hehaltonearabic: 0x06C1,
  22753. heharabic: 0x0647,
  22754. hehebrew: 0x05D4,
  22755. hehfinalaltonearabic: 0xFBA7,
  22756. hehfinalalttwoarabic: 0xFEEA,
  22757. hehfinalarabic: 0xFEEA,
  22758. hehhamzaabovefinalarabic: 0xFBA5,
  22759. hehhamzaaboveisolatedarabic: 0xFBA4,
  22760. hehinitialaltonearabic: 0xFBA8,
  22761. hehinitialarabic: 0xFEEB,
  22762. hehiragana: 0x3078,
  22763. hehmedialaltonearabic: 0xFBA9,
  22764. hehmedialarabic: 0xFEEC,
  22765. heiseierasquare: 0x337B,
  22766. hekatakana: 0x30D8,
  22767. hekatakanahalfwidth: 0xFF8D,
  22768. hekutaarusquare: 0x3336,
  22769. henghook: 0x0267,
  22770. herutusquare: 0x3339,
  22771. het: 0x05D7,
  22772. hethebrew: 0x05D7,
  22773. hhook: 0x0266,
  22774. hhooksuperior: 0x02B1,
  22775. hieuhacirclekorean: 0x327B,
  22776. hieuhaparenkorean: 0x321B,
  22777. hieuhcirclekorean: 0x326D,
  22778. hieuhkorean: 0x314E,
  22779. hieuhparenkorean: 0x320D,
  22780. hihiragana: 0x3072,
  22781. hikatakana: 0x30D2,
  22782. hikatakanahalfwidth: 0xFF8B,
  22783. hiriq: 0x05B4,
  22784. hiriq14: 0x05B4,
  22785. hiriq21: 0x05B4,
  22786. hiriq2d: 0x05B4,
  22787. hiriqhebrew: 0x05B4,
  22788. hiriqnarrowhebrew: 0x05B4,
  22789. hiriqquarterhebrew: 0x05B4,
  22790. hiriqwidehebrew: 0x05B4,
  22791. hlinebelow: 0x1E96,
  22792. hmonospace: 0xFF48,
  22793. hoarmenian: 0x0570,
  22794. hohipthai: 0x0E2B,
  22795. hohiragana: 0x307B,
  22796. hokatakana: 0x30DB,
  22797. hokatakanahalfwidth: 0xFF8E,
  22798. holam: 0x05B9,
  22799. holam19: 0x05B9,
  22800. holam26: 0x05B9,
  22801. holam32: 0x05B9,
  22802. holamhebrew: 0x05B9,
  22803. holamnarrowhebrew: 0x05B9,
  22804. holamquarterhebrew: 0x05B9,
  22805. holamwidehebrew: 0x05B9,
  22806. honokhukthai: 0x0E2E,
  22807. hookabovecomb: 0x0309,
  22808. hookcmb: 0x0309,
  22809. hookpalatalizedbelowcmb: 0x0321,
  22810. hookretroflexbelowcmb: 0x0322,
  22811. hoonsquare: 0x3342,
  22812. horicoptic: 0x03E9,
  22813. horizontalbar: 0x2015,
  22814. horncmb: 0x031B,
  22815. hotsprings: 0x2668,
  22816. house: 0x2302,
  22817. hparen: 0x24A3,
  22818. hsuperior: 0x02B0,
  22819. hturned: 0x0265,
  22820. huhiragana: 0x3075,
  22821. huiitosquare: 0x3333,
  22822. hukatakana: 0x30D5,
  22823. hukatakanahalfwidth: 0xFF8C,
  22824. hungarumlaut: 0x02DD,
  22825. hungarumlautcmb: 0x030B,
  22826. hv: 0x0195,
  22827. hyphen: 0x002D,
  22828. hypheninferior: 0xF6E5,
  22829. hyphenmonospace: 0xFF0D,
  22830. hyphensmall: 0xFE63,
  22831. hyphensuperior: 0xF6E6,
  22832. hyphentwo: 0x2010,
  22833. i: 0x0069,
  22834. iacute: 0x00ED,
  22835. iacyrillic: 0x044F,
  22836. ibengali: 0x0987,
  22837. ibopomofo: 0x3127,
  22838. ibreve: 0x012D,
  22839. icaron: 0x01D0,
  22840. icircle: 0x24D8,
  22841. icircumflex: 0x00EE,
  22842. icyrillic: 0x0456,
  22843. idblgrave: 0x0209,
  22844. ideographearthcircle: 0x328F,
  22845. ideographfirecircle: 0x328B,
  22846. ideographicallianceparen: 0x323F,
  22847. ideographiccallparen: 0x323A,
  22848. ideographiccentrecircle: 0x32A5,
  22849. ideographicclose: 0x3006,
  22850. ideographiccomma: 0x3001,
  22851. ideographiccommaleft: 0xFF64,
  22852. ideographiccongratulationparen: 0x3237,
  22853. ideographiccorrectcircle: 0x32A3,
  22854. ideographicearthparen: 0x322F,
  22855. ideographicenterpriseparen: 0x323D,
  22856. ideographicexcellentcircle: 0x329D,
  22857. ideographicfestivalparen: 0x3240,
  22858. ideographicfinancialcircle: 0x3296,
  22859. ideographicfinancialparen: 0x3236,
  22860. ideographicfireparen: 0x322B,
  22861. ideographichaveparen: 0x3232,
  22862. ideographichighcircle: 0x32A4,
  22863. ideographiciterationmark: 0x3005,
  22864. ideographiclaborcircle: 0x3298,
  22865. ideographiclaborparen: 0x3238,
  22866. ideographicleftcircle: 0x32A7,
  22867. ideographiclowcircle: 0x32A6,
  22868. ideographicmedicinecircle: 0x32A9,
  22869. ideographicmetalparen: 0x322E,
  22870. ideographicmoonparen: 0x322A,
  22871. ideographicnameparen: 0x3234,
  22872. ideographicperiod: 0x3002,
  22873. ideographicprintcircle: 0x329E,
  22874. ideographicreachparen: 0x3243,
  22875. ideographicrepresentparen: 0x3239,
  22876. ideographicresourceparen: 0x323E,
  22877. ideographicrightcircle: 0x32A8,
  22878. ideographicsecretcircle: 0x3299,
  22879. ideographicselfparen: 0x3242,
  22880. ideographicsocietyparen: 0x3233,
  22881. ideographicspace: 0x3000,
  22882. ideographicspecialparen: 0x3235,
  22883. ideographicstockparen: 0x3231,
  22884. ideographicstudyparen: 0x323B,
  22885. ideographicsunparen: 0x3230,
  22886. ideographicsuperviseparen: 0x323C,
  22887. ideographicwaterparen: 0x322C,
  22888. ideographicwoodparen: 0x322D,
  22889. ideographiczero: 0x3007,
  22890. ideographmetalcircle: 0x328E,
  22891. ideographmooncircle: 0x328A,
  22892. ideographnamecircle: 0x3294,
  22893. ideographsuncircle: 0x3290,
  22894. ideographwatercircle: 0x328C,
  22895. ideographwoodcircle: 0x328D,
  22896. ideva: 0x0907,
  22897. idieresis: 0x00EF,
  22898. idieresisacute: 0x1E2F,
  22899. idieresiscyrillic: 0x04E5,
  22900. idotbelow: 0x1ECB,
  22901. iebrevecyrillic: 0x04D7,
  22902. iecyrillic: 0x0435,
  22903. ieungacirclekorean: 0x3275,
  22904. ieungaparenkorean: 0x3215,
  22905. ieungcirclekorean: 0x3267,
  22906. ieungkorean: 0x3147,
  22907. ieungparenkorean: 0x3207,
  22908. igrave: 0x00EC,
  22909. igujarati: 0x0A87,
  22910. igurmukhi: 0x0A07,
  22911. ihiragana: 0x3044,
  22912. ihookabove: 0x1EC9,
  22913. iibengali: 0x0988,
  22914. iicyrillic: 0x0438,
  22915. iideva: 0x0908,
  22916. iigujarati: 0x0A88,
  22917. iigurmukhi: 0x0A08,
  22918. iimatragurmukhi: 0x0A40,
  22919. iinvertedbreve: 0x020B,
  22920. iishortcyrillic: 0x0439,
  22921. iivowelsignbengali: 0x09C0,
  22922. iivowelsigndeva: 0x0940,
  22923. iivowelsigngujarati: 0x0AC0,
  22924. ij: 0x0133,
  22925. ikatakana: 0x30A4,
  22926. ikatakanahalfwidth: 0xFF72,
  22927. ikorean: 0x3163,
  22928. ilde: 0x02DC,
  22929. iluyhebrew: 0x05AC,
  22930. imacron: 0x012B,
  22931. imacroncyrillic: 0x04E3,
  22932. imageorapproximatelyequal: 0x2253,
  22933. imatragurmukhi: 0x0A3F,
  22934. imonospace: 0xFF49,
  22935. increment: 0x2206,
  22936. infinity: 0x221E,
  22937. iniarmenian: 0x056B,
  22938. integral: 0x222B,
  22939. integralbottom: 0x2321,
  22940. integralbt: 0x2321,
  22941. integralex: 0xF8F5,
  22942. integraltop: 0x2320,
  22943. integraltp: 0x2320,
  22944. intersection: 0x2229,
  22945. intisquare: 0x3305,
  22946. invbullet: 0x25D8,
  22947. invcircle: 0x25D9,
  22948. invsmileface: 0x263B,
  22949. iocyrillic: 0x0451,
  22950. iogonek: 0x012F,
  22951. iota: 0x03B9,
  22952. iotadieresis: 0x03CA,
  22953. iotadieresistonos: 0x0390,
  22954. iotalatin: 0x0269,
  22955. iotatonos: 0x03AF,
  22956. iparen: 0x24A4,
  22957. irigurmukhi: 0x0A72,
  22958. ismallhiragana: 0x3043,
  22959. ismallkatakana: 0x30A3,
  22960. ismallkatakanahalfwidth: 0xFF68,
  22961. issharbengali: 0x09FA,
  22962. istroke: 0x0268,
  22963. isuperior: 0xF6ED,
  22964. iterationhiragana: 0x309D,
  22965. iterationkatakana: 0x30FD,
  22966. itilde: 0x0129,
  22967. itildebelow: 0x1E2D,
  22968. iubopomofo: 0x3129,
  22969. iucyrillic: 0x044E,
  22970. ivowelsignbengali: 0x09BF,
  22971. ivowelsigndeva: 0x093F,
  22972. ivowelsigngujarati: 0x0ABF,
  22973. izhitsacyrillic: 0x0475,
  22974. izhitsadblgravecyrillic: 0x0477,
  22975. j: 0x006A,
  22976. jaarmenian: 0x0571,
  22977. jabengali: 0x099C,
  22978. jadeva: 0x091C,
  22979. jagujarati: 0x0A9C,
  22980. jagurmukhi: 0x0A1C,
  22981. jbopomofo: 0x3110,
  22982. jcaron: 0x01F0,
  22983. jcircle: 0x24D9,
  22984. jcircumflex: 0x0135,
  22985. jcrossedtail: 0x029D,
  22986. jdotlessstroke: 0x025F,
  22987. jecyrillic: 0x0458,
  22988. jeemarabic: 0x062C,
  22989. jeemfinalarabic: 0xFE9E,
  22990. jeeminitialarabic: 0xFE9F,
  22991. jeemmedialarabic: 0xFEA0,
  22992. jeharabic: 0x0698,
  22993. jehfinalarabic: 0xFB8B,
  22994. jhabengali: 0x099D,
  22995. jhadeva: 0x091D,
  22996. jhagujarati: 0x0A9D,
  22997. jhagurmukhi: 0x0A1D,
  22998. jheharmenian: 0x057B,
  22999. jis: 0x3004,
  23000. jmonospace: 0xFF4A,
  23001. jparen: 0x24A5,
  23002. jsuperior: 0x02B2,
  23003. k: 0x006B,
  23004. kabashkircyrillic: 0x04A1,
  23005. kabengali: 0x0995,
  23006. kacute: 0x1E31,
  23007. kacyrillic: 0x043A,
  23008. kadescendercyrillic: 0x049B,
  23009. kadeva: 0x0915,
  23010. kaf: 0x05DB,
  23011. kafarabic: 0x0643,
  23012. kafdagesh: 0xFB3B,
  23013. kafdageshhebrew: 0xFB3B,
  23014. kaffinalarabic: 0xFEDA,
  23015. kafhebrew: 0x05DB,
  23016. kafinitialarabic: 0xFEDB,
  23017. kafmedialarabic: 0xFEDC,
  23018. kafrafehebrew: 0xFB4D,
  23019. kagujarati: 0x0A95,
  23020. kagurmukhi: 0x0A15,
  23021. kahiragana: 0x304B,
  23022. kahookcyrillic: 0x04C4,
  23023. kakatakana: 0x30AB,
  23024. kakatakanahalfwidth: 0xFF76,
  23025. kappa: 0x03BA,
  23026. kappasymbolgreek: 0x03F0,
  23027. kapyeounmieumkorean: 0x3171,
  23028. kapyeounphieuphkorean: 0x3184,
  23029. kapyeounpieupkorean: 0x3178,
  23030. kapyeounssangpieupkorean: 0x3179,
  23031. karoriisquare: 0x330D,
  23032. kashidaautoarabic: 0x0640,
  23033. kashidaautonosidebearingarabic: 0x0640,
  23034. kasmallkatakana: 0x30F5,
  23035. kasquare: 0x3384,
  23036. kasraarabic: 0x0650,
  23037. kasratanarabic: 0x064D,
  23038. kastrokecyrillic: 0x049F,
  23039. katahiraprolongmarkhalfwidth: 0xFF70,
  23040. kaverticalstrokecyrillic: 0x049D,
  23041. kbopomofo: 0x310E,
  23042. kcalsquare: 0x3389,
  23043. kcaron: 0x01E9,
  23044. kcedilla: 0x0137,
  23045. kcircle: 0x24DA,
  23046. kcommaaccent: 0x0137,
  23047. kdotbelow: 0x1E33,
  23048. keharmenian: 0x0584,
  23049. kehiragana: 0x3051,
  23050. kekatakana: 0x30B1,
  23051. kekatakanahalfwidth: 0xFF79,
  23052. kenarmenian: 0x056F,
  23053. kesmallkatakana: 0x30F6,
  23054. kgreenlandic: 0x0138,
  23055. khabengali: 0x0996,
  23056. khacyrillic: 0x0445,
  23057. khadeva: 0x0916,
  23058. khagujarati: 0x0A96,
  23059. khagurmukhi: 0x0A16,
  23060. khaharabic: 0x062E,
  23061. khahfinalarabic: 0xFEA6,
  23062. khahinitialarabic: 0xFEA7,
  23063. khahmedialarabic: 0xFEA8,
  23064. kheicoptic: 0x03E7,
  23065. khhadeva: 0x0959,
  23066. khhagurmukhi: 0x0A59,
  23067. khieukhacirclekorean: 0x3278,
  23068. khieukhaparenkorean: 0x3218,
  23069. khieukhcirclekorean: 0x326A,
  23070. khieukhkorean: 0x314B,
  23071. khieukhparenkorean: 0x320A,
  23072. khokhaithai: 0x0E02,
  23073. khokhonthai: 0x0E05,
  23074. khokhuatthai: 0x0E03,
  23075. khokhwaithai: 0x0E04,
  23076. khomutthai: 0x0E5B,
  23077. khook: 0x0199,
  23078. khorakhangthai: 0x0E06,
  23079. khzsquare: 0x3391,
  23080. kihiragana: 0x304D,
  23081. kikatakana: 0x30AD,
  23082. kikatakanahalfwidth: 0xFF77,
  23083. kiroguramusquare: 0x3315,
  23084. kiromeetorusquare: 0x3316,
  23085. kirosquare: 0x3314,
  23086. kiyeokacirclekorean: 0x326E,
  23087. kiyeokaparenkorean: 0x320E,
  23088. kiyeokcirclekorean: 0x3260,
  23089. kiyeokkorean: 0x3131,
  23090. kiyeokparenkorean: 0x3200,
  23091. kiyeoksioskorean: 0x3133,
  23092. kjecyrillic: 0x045C,
  23093. klinebelow: 0x1E35,
  23094. klsquare: 0x3398,
  23095. kmcubedsquare: 0x33A6,
  23096. kmonospace: 0xFF4B,
  23097. kmsquaredsquare: 0x33A2,
  23098. kohiragana: 0x3053,
  23099. kohmsquare: 0x33C0,
  23100. kokaithai: 0x0E01,
  23101. kokatakana: 0x30B3,
  23102. kokatakanahalfwidth: 0xFF7A,
  23103. kooposquare: 0x331E,
  23104. koppacyrillic: 0x0481,
  23105. koreanstandardsymbol: 0x327F,
  23106. koroniscmb: 0x0343,
  23107. kparen: 0x24A6,
  23108. kpasquare: 0x33AA,
  23109. ksicyrillic: 0x046F,
  23110. ktsquare: 0x33CF,
  23111. kturned: 0x029E,
  23112. kuhiragana: 0x304F,
  23113. kukatakana: 0x30AF,
  23114. kukatakanahalfwidth: 0xFF78,
  23115. kvsquare: 0x33B8,
  23116. kwsquare: 0x33BE,
  23117. l: 0x006C,
  23118. labengali: 0x09B2,
  23119. lacute: 0x013A,
  23120. ladeva: 0x0932,
  23121. lagujarati: 0x0AB2,
  23122. lagurmukhi: 0x0A32,
  23123. lakkhangyaothai: 0x0E45,
  23124. lamaleffinalarabic: 0xFEFC,
  23125. lamalefhamzaabovefinalarabic: 0xFEF8,
  23126. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  23127. lamalefhamzabelowfinalarabic: 0xFEFA,
  23128. lamalefhamzabelowisolatedarabic: 0xFEF9,
  23129. lamalefisolatedarabic: 0xFEFB,
  23130. lamalefmaddaabovefinalarabic: 0xFEF6,
  23131. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  23132. lamarabic: 0x0644,
  23133. lambda: 0x03BB,
  23134. lambdastroke: 0x019B,
  23135. lamed: 0x05DC,
  23136. lameddagesh: 0xFB3C,
  23137. lameddageshhebrew: 0xFB3C,
  23138. lamedhebrew: 0x05DC,
  23139. lamfinalarabic: 0xFEDE,
  23140. lamhahinitialarabic: 0xFCCA,
  23141. laminitialarabic: 0xFEDF,
  23142. lamjeeminitialarabic: 0xFCC9,
  23143. lamkhahinitialarabic: 0xFCCB,
  23144. lamlamhehisolatedarabic: 0xFDF2,
  23145. lammedialarabic: 0xFEE0,
  23146. lammeemhahinitialarabic: 0xFD88,
  23147. lammeeminitialarabic: 0xFCCC,
  23148. largecircle: 0x25EF,
  23149. lbar: 0x019A,
  23150. lbelt: 0x026C,
  23151. lbopomofo: 0x310C,
  23152. lcaron: 0x013E,
  23153. lcedilla: 0x013C,
  23154. lcircle: 0x24DB,
  23155. lcircumflexbelow: 0x1E3D,
  23156. lcommaaccent: 0x013C,
  23157. ldot: 0x0140,
  23158. ldotaccent: 0x0140,
  23159. ldotbelow: 0x1E37,
  23160. ldotbelowmacron: 0x1E39,
  23161. leftangleabovecmb: 0x031A,
  23162. lefttackbelowcmb: 0x0318,
  23163. less: 0x003C,
  23164. lessequal: 0x2264,
  23165. lessequalorgreater: 0x22DA,
  23166. lessmonospace: 0xFF1C,
  23167. lessorequivalent: 0x2272,
  23168. lessorgreater: 0x2276,
  23169. lessoverequal: 0x2266,
  23170. lesssmall: 0xFE64,
  23171. lezh: 0x026E,
  23172. lfblock: 0x258C,
  23173. lhookretroflex: 0x026D,
  23174. lira: 0x20A4,
  23175. liwnarmenian: 0x056C,
  23176. lj: 0x01C9,
  23177. ljecyrillic: 0x0459,
  23178. ll: 0xF6C0,
  23179. lladeva: 0x0933,
  23180. llagujarati: 0x0AB3,
  23181. llinebelow: 0x1E3B,
  23182. llladeva: 0x0934,
  23183. llvocalicbengali: 0x09E1,
  23184. llvocalicdeva: 0x0961,
  23185. llvocalicvowelsignbengali: 0x09E3,
  23186. llvocalicvowelsigndeva: 0x0963,
  23187. lmiddletilde: 0x026B,
  23188. lmonospace: 0xFF4C,
  23189. lmsquare: 0x33D0,
  23190. lochulathai: 0x0E2C,
  23191. logicaland: 0x2227,
  23192. logicalnot: 0x00AC,
  23193. logicalnotreversed: 0x2310,
  23194. logicalor: 0x2228,
  23195. lolingthai: 0x0E25,
  23196. longs: 0x017F,
  23197. lowlinecenterline: 0xFE4E,
  23198. lowlinecmb: 0x0332,
  23199. lowlinedashed: 0xFE4D,
  23200. lozenge: 0x25CA,
  23201. lparen: 0x24A7,
  23202. lslash: 0x0142,
  23203. lsquare: 0x2113,
  23204. lsuperior: 0xF6EE,
  23205. ltshade: 0x2591,
  23206. luthai: 0x0E26,
  23207. lvocalicbengali: 0x098C,
  23208. lvocalicdeva: 0x090C,
  23209. lvocalicvowelsignbengali: 0x09E2,
  23210. lvocalicvowelsigndeva: 0x0962,
  23211. lxsquare: 0x33D3,
  23212. m: 0x006D,
  23213. mabengali: 0x09AE,
  23214. macron: 0x00AF,
  23215. macronbelowcmb: 0x0331,
  23216. macroncmb: 0x0304,
  23217. macronlowmod: 0x02CD,
  23218. macronmonospace: 0xFFE3,
  23219. macute: 0x1E3F,
  23220. madeva: 0x092E,
  23221. magujarati: 0x0AAE,
  23222. magurmukhi: 0x0A2E,
  23223. mahapakhhebrew: 0x05A4,
  23224. mahapakhlefthebrew: 0x05A4,
  23225. mahiragana: 0x307E,
  23226. maichattawalowleftthai: 0xF895,
  23227. maichattawalowrightthai: 0xF894,
  23228. maichattawathai: 0x0E4B,
  23229. maichattawaupperleftthai: 0xF893,
  23230. maieklowleftthai: 0xF88C,
  23231. maieklowrightthai: 0xF88B,
  23232. maiekthai: 0x0E48,
  23233. maiekupperleftthai: 0xF88A,
  23234. maihanakatleftthai: 0xF884,
  23235. maihanakatthai: 0x0E31,
  23236. maitaikhuleftthai: 0xF889,
  23237. maitaikhuthai: 0x0E47,
  23238. maitholowleftthai: 0xF88F,
  23239. maitholowrightthai: 0xF88E,
  23240. maithothai: 0x0E49,
  23241. maithoupperleftthai: 0xF88D,
  23242. maitrilowleftthai: 0xF892,
  23243. maitrilowrightthai: 0xF891,
  23244. maitrithai: 0x0E4A,
  23245. maitriupperleftthai: 0xF890,
  23246. maiyamokthai: 0x0E46,
  23247. makatakana: 0x30DE,
  23248. makatakanahalfwidth: 0xFF8F,
  23249. male: 0x2642,
  23250. mansyonsquare: 0x3347,
  23251. maqafhebrew: 0x05BE,
  23252. mars: 0x2642,
  23253. masoracirclehebrew: 0x05AF,
  23254. masquare: 0x3383,
  23255. mbopomofo: 0x3107,
  23256. mbsquare: 0x33D4,
  23257. mcircle: 0x24DC,
  23258. mcubedsquare: 0x33A5,
  23259. mdotaccent: 0x1E41,
  23260. mdotbelow: 0x1E43,
  23261. meemarabic: 0x0645,
  23262. meemfinalarabic: 0xFEE2,
  23263. meeminitialarabic: 0xFEE3,
  23264. meemmedialarabic: 0xFEE4,
  23265. meemmeeminitialarabic: 0xFCD1,
  23266. meemmeemisolatedarabic: 0xFC48,
  23267. meetorusquare: 0x334D,
  23268. mehiragana: 0x3081,
  23269. meizierasquare: 0x337E,
  23270. mekatakana: 0x30E1,
  23271. mekatakanahalfwidth: 0xFF92,
  23272. mem: 0x05DE,
  23273. memdagesh: 0xFB3E,
  23274. memdageshhebrew: 0xFB3E,
  23275. memhebrew: 0x05DE,
  23276. menarmenian: 0x0574,
  23277. merkhahebrew: 0x05A5,
  23278. merkhakefulahebrew: 0x05A6,
  23279. merkhakefulalefthebrew: 0x05A6,
  23280. merkhalefthebrew: 0x05A5,
  23281. mhook: 0x0271,
  23282. mhzsquare: 0x3392,
  23283. middledotkatakanahalfwidth: 0xFF65,
  23284. middot: 0x00B7,
  23285. mieumacirclekorean: 0x3272,
  23286. mieumaparenkorean: 0x3212,
  23287. mieumcirclekorean: 0x3264,
  23288. mieumkorean: 0x3141,
  23289. mieumpansioskorean: 0x3170,
  23290. mieumparenkorean: 0x3204,
  23291. mieumpieupkorean: 0x316E,
  23292. mieumsioskorean: 0x316F,
  23293. mihiragana: 0x307F,
  23294. mikatakana: 0x30DF,
  23295. mikatakanahalfwidth: 0xFF90,
  23296. minus: 0x2212,
  23297. minusbelowcmb: 0x0320,
  23298. minuscircle: 0x2296,
  23299. minusmod: 0x02D7,
  23300. minusplus: 0x2213,
  23301. minute: 0x2032,
  23302. miribaarusquare: 0x334A,
  23303. mirisquare: 0x3349,
  23304. mlonglegturned: 0x0270,
  23305. mlsquare: 0x3396,
  23306. mmcubedsquare: 0x33A3,
  23307. mmonospace: 0xFF4D,
  23308. mmsquaredsquare: 0x339F,
  23309. mohiragana: 0x3082,
  23310. mohmsquare: 0x33C1,
  23311. mokatakana: 0x30E2,
  23312. mokatakanahalfwidth: 0xFF93,
  23313. molsquare: 0x33D6,
  23314. momathai: 0x0E21,
  23315. moverssquare: 0x33A7,
  23316. moverssquaredsquare: 0x33A8,
  23317. mparen: 0x24A8,
  23318. mpasquare: 0x33AB,
  23319. mssquare: 0x33B3,
  23320. msuperior: 0xF6EF,
  23321. mturned: 0x026F,
  23322. mu: 0x00B5,
  23323. mu1: 0x00B5,
  23324. muasquare: 0x3382,
  23325. muchgreater: 0x226B,
  23326. muchless: 0x226A,
  23327. mufsquare: 0x338C,
  23328. mugreek: 0x03BC,
  23329. mugsquare: 0x338D,
  23330. muhiragana: 0x3080,
  23331. mukatakana: 0x30E0,
  23332. mukatakanahalfwidth: 0xFF91,
  23333. mulsquare: 0x3395,
  23334. multiply: 0x00D7,
  23335. mumsquare: 0x339B,
  23336. munahhebrew: 0x05A3,
  23337. munahlefthebrew: 0x05A3,
  23338. musicalnote: 0x266A,
  23339. musicalnotedbl: 0x266B,
  23340. musicflatsign: 0x266D,
  23341. musicsharpsign: 0x266F,
  23342. mussquare: 0x33B2,
  23343. muvsquare: 0x33B6,
  23344. muwsquare: 0x33BC,
  23345. mvmegasquare: 0x33B9,
  23346. mvsquare: 0x33B7,
  23347. mwmegasquare: 0x33BF,
  23348. mwsquare: 0x33BD,
  23349. n: 0x006E,
  23350. nabengali: 0x09A8,
  23351. nabla: 0x2207,
  23352. nacute: 0x0144,
  23353. nadeva: 0x0928,
  23354. nagujarati: 0x0AA8,
  23355. nagurmukhi: 0x0A28,
  23356. nahiragana: 0x306A,
  23357. nakatakana: 0x30CA,
  23358. nakatakanahalfwidth: 0xFF85,
  23359. napostrophe: 0x0149,
  23360. nasquare: 0x3381,
  23361. nbopomofo: 0x310B,
  23362. nbspace: 0x00A0,
  23363. ncaron: 0x0148,
  23364. ncedilla: 0x0146,
  23365. ncircle: 0x24DD,
  23366. ncircumflexbelow: 0x1E4B,
  23367. ncommaaccent: 0x0146,
  23368. ndotaccent: 0x1E45,
  23369. ndotbelow: 0x1E47,
  23370. nehiragana: 0x306D,
  23371. nekatakana: 0x30CD,
  23372. nekatakanahalfwidth: 0xFF88,
  23373. newsheqelsign: 0x20AA,
  23374. nfsquare: 0x338B,
  23375. ngabengali: 0x0999,
  23376. ngadeva: 0x0919,
  23377. ngagujarati: 0x0A99,
  23378. ngagurmukhi: 0x0A19,
  23379. ngonguthai: 0x0E07,
  23380. nhiragana: 0x3093,
  23381. nhookleft: 0x0272,
  23382. nhookretroflex: 0x0273,
  23383. nieunacirclekorean: 0x326F,
  23384. nieunaparenkorean: 0x320F,
  23385. nieuncieuckorean: 0x3135,
  23386. nieuncirclekorean: 0x3261,
  23387. nieunhieuhkorean: 0x3136,
  23388. nieunkorean: 0x3134,
  23389. nieunpansioskorean: 0x3168,
  23390. nieunparenkorean: 0x3201,
  23391. nieunsioskorean: 0x3167,
  23392. nieuntikeutkorean: 0x3166,
  23393. nihiragana: 0x306B,
  23394. nikatakana: 0x30CB,
  23395. nikatakanahalfwidth: 0xFF86,
  23396. nikhahitleftthai: 0xF899,
  23397. nikhahitthai: 0x0E4D,
  23398. nine: 0x0039,
  23399. ninearabic: 0x0669,
  23400. ninebengali: 0x09EF,
  23401. ninecircle: 0x2468,
  23402. ninecircleinversesansserif: 0x2792,
  23403. ninedeva: 0x096F,
  23404. ninegujarati: 0x0AEF,
  23405. ninegurmukhi: 0x0A6F,
  23406. ninehackarabic: 0x0669,
  23407. ninehangzhou: 0x3029,
  23408. nineideographicparen: 0x3228,
  23409. nineinferior: 0x2089,
  23410. ninemonospace: 0xFF19,
  23411. nineoldstyle: 0xF739,
  23412. nineparen: 0x247C,
  23413. nineperiod: 0x2490,
  23414. ninepersian: 0x06F9,
  23415. nineroman: 0x2178,
  23416. ninesuperior: 0x2079,
  23417. nineteencircle: 0x2472,
  23418. nineteenparen: 0x2486,
  23419. nineteenperiod: 0x249A,
  23420. ninethai: 0x0E59,
  23421. nj: 0x01CC,
  23422. njecyrillic: 0x045A,
  23423. nkatakana: 0x30F3,
  23424. nkatakanahalfwidth: 0xFF9D,
  23425. nlegrightlong: 0x019E,
  23426. nlinebelow: 0x1E49,
  23427. nmonospace: 0xFF4E,
  23428. nmsquare: 0x339A,
  23429. nnabengali: 0x09A3,
  23430. nnadeva: 0x0923,
  23431. nnagujarati: 0x0AA3,
  23432. nnagurmukhi: 0x0A23,
  23433. nnnadeva: 0x0929,
  23434. nohiragana: 0x306E,
  23435. nokatakana: 0x30CE,
  23436. nokatakanahalfwidth: 0xFF89,
  23437. nonbreakingspace: 0x00A0,
  23438. nonenthai: 0x0E13,
  23439. nonuthai: 0x0E19,
  23440. noonarabic: 0x0646,
  23441. noonfinalarabic: 0xFEE6,
  23442. noonghunnaarabic: 0x06BA,
  23443. noonghunnafinalarabic: 0xFB9F,
  23444. nooninitialarabic: 0xFEE7,
  23445. noonjeeminitialarabic: 0xFCD2,
  23446. noonjeemisolatedarabic: 0xFC4B,
  23447. noonmedialarabic: 0xFEE8,
  23448. noonmeeminitialarabic: 0xFCD5,
  23449. noonmeemisolatedarabic: 0xFC4E,
  23450. noonnoonfinalarabic: 0xFC8D,
  23451. notcontains: 0x220C,
  23452. notelement: 0x2209,
  23453. notelementof: 0x2209,
  23454. notequal: 0x2260,
  23455. notgreater: 0x226F,
  23456. notgreaternorequal: 0x2271,
  23457. notgreaternorless: 0x2279,
  23458. notidentical: 0x2262,
  23459. notless: 0x226E,
  23460. notlessnorequal: 0x2270,
  23461. notparallel: 0x2226,
  23462. notprecedes: 0x2280,
  23463. notsubset: 0x2284,
  23464. notsucceeds: 0x2281,
  23465. notsuperset: 0x2285,
  23466. nowarmenian: 0x0576,
  23467. nparen: 0x24A9,
  23468. nssquare: 0x33B1,
  23469. nsuperior: 0x207F,
  23470. ntilde: 0x00F1,
  23471. nu: 0x03BD,
  23472. nuhiragana: 0x306C,
  23473. nukatakana: 0x30CC,
  23474. nukatakanahalfwidth: 0xFF87,
  23475. nuktabengali: 0x09BC,
  23476. nuktadeva: 0x093C,
  23477. nuktagujarati: 0x0ABC,
  23478. nuktagurmukhi: 0x0A3C,
  23479. numbersign: 0x0023,
  23480. numbersignmonospace: 0xFF03,
  23481. numbersignsmall: 0xFE5F,
  23482. numeralsigngreek: 0x0374,
  23483. numeralsignlowergreek: 0x0375,
  23484. numero: 0x2116,
  23485. nun: 0x05E0,
  23486. nundagesh: 0xFB40,
  23487. nundageshhebrew: 0xFB40,
  23488. nunhebrew: 0x05E0,
  23489. nvsquare: 0x33B5,
  23490. nwsquare: 0x33BB,
  23491. nyabengali: 0x099E,
  23492. nyadeva: 0x091E,
  23493. nyagujarati: 0x0A9E,
  23494. nyagurmukhi: 0x0A1E,
  23495. o: 0x006F,
  23496. oacute: 0x00F3,
  23497. oangthai: 0x0E2D,
  23498. obarred: 0x0275,
  23499. obarredcyrillic: 0x04E9,
  23500. obarreddieresiscyrillic: 0x04EB,
  23501. obengali: 0x0993,
  23502. obopomofo: 0x311B,
  23503. obreve: 0x014F,
  23504. ocandradeva: 0x0911,
  23505. ocandragujarati: 0x0A91,
  23506. ocandravowelsigndeva: 0x0949,
  23507. ocandravowelsigngujarati: 0x0AC9,
  23508. ocaron: 0x01D2,
  23509. ocircle: 0x24DE,
  23510. ocircumflex: 0x00F4,
  23511. ocircumflexacute: 0x1ED1,
  23512. ocircumflexdotbelow: 0x1ED9,
  23513. ocircumflexgrave: 0x1ED3,
  23514. ocircumflexhookabove: 0x1ED5,
  23515. ocircumflextilde: 0x1ED7,
  23516. ocyrillic: 0x043E,
  23517. odblacute: 0x0151,
  23518. odblgrave: 0x020D,
  23519. odeva: 0x0913,
  23520. odieresis: 0x00F6,
  23521. odieresiscyrillic: 0x04E7,
  23522. odotbelow: 0x1ECD,
  23523. oe: 0x0153,
  23524. oekorean: 0x315A,
  23525. ogonek: 0x02DB,
  23526. ogonekcmb: 0x0328,
  23527. ograve: 0x00F2,
  23528. ogujarati: 0x0A93,
  23529. oharmenian: 0x0585,
  23530. ohiragana: 0x304A,
  23531. ohookabove: 0x1ECF,
  23532. ohorn: 0x01A1,
  23533. ohornacute: 0x1EDB,
  23534. ohorndotbelow: 0x1EE3,
  23535. ohorngrave: 0x1EDD,
  23536. ohornhookabove: 0x1EDF,
  23537. ohorntilde: 0x1EE1,
  23538. ohungarumlaut: 0x0151,
  23539. oi: 0x01A3,
  23540. oinvertedbreve: 0x020F,
  23541. okatakana: 0x30AA,
  23542. okatakanahalfwidth: 0xFF75,
  23543. okorean: 0x3157,
  23544. olehebrew: 0x05AB,
  23545. omacron: 0x014D,
  23546. omacronacute: 0x1E53,
  23547. omacrongrave: 0x1E51,
  23548. omdeva: 0x0950,
  23549. omega: 0x03C9,
  23550. omega1: 0x03D6,
  23551. omegacyrillic: 0x0461,
  23552. omegalatinclosed: 0x0277,
  23553. omegaroundcyrillic: 0x047B,
  23554. omegatitlocyrillic: 0x047D,
  23555. omegatonos: 0x03CE,
  23556. omgujarati: 0x0AD0,
  23557. omicron: 0x03BF,
  23558. omicrontonos: 0x03CC,
  23559. omonospace: 0xFF4F,
  23560. one: 0x0031,
  23561. onearabic: 0x0661,
  23562. onebengali: 0x09E7,
  23563. onecircle: 0x2460,
  23564. onecircleinversesansserif: 0x278A,
  23565. onedeva: 0x0967,
  23566. onedotenleader: 0x2024,
  23567. oneeighth: 0x215B,
  23568. onefitted: 0xF6DC,
  23569. onegujarati: 0x0AE7,
  23570. onegurmukhi: 0x0A67,
  23571. onehackarabic: 0x0661,
  23572. onehalf: 0x00BD,
  23573. onehangzhou: 0x3021,
  23574. oneideographicparen: 0x3220,
  23575. oneinferior: 0x2081,
  23576. onemonospace: 0xFF11,
  23577. onenumeratorbengali: 0x09F4,
  23578. oneoldstyle: 0xF731,
  23579. oneparen: 0x2474,
  23580. oneperiod: 0x2488,
  23581. onepersian: 0x06F1,
  23582. onequarter: 0x00BC,
  23583. oneroman: 0x2170,
  23584. onesuperior: 0x00B9,
  23585. onethai: 0x0E51,
  23586. onethird: 0x2153,
  23587. oogonek: 0x01EB,
  23588. oogonekmacron: 0x01ED,
  23589. oogurmukhi: 0x0A13,
  23590. oomatragurmukhi: 0x0A4B,
  23591. oopen: 0x0254,
  23592. oparen: 0x24AA,
  23593. openbullet: 0x25E6,
  23594. option: 0x2325,
  23595. ordfeminine: 0x00AA,
  23596. ordmasculine: 0x00BA,
  23597. orthogonal: 0x221F,
  23598. oshortdeva: 0x0912,
  23599. oshortvowelsigndeva: 0x094A,
  23600. oslash: 0x00F8,
  23601. oslashacute: 0x01FF,
  23602. osmallhiragana: 0x3049,
  23603. osmallkatakana: 0x30A9,
  23604. osmallkatakanahalfwidth: 0xFF6B,
  23605. ostrokeacute: 0x01FF,
  23606. osuperior: 0xF6F0,
  23607. otcyrillic: 0x047F,
  23608. otilde: 0x00F5,
  23609. otildeacute: 0x1E4D,
  23610. otildedieresis: 0x1E4F,
  23611. oubopomofo: 0x3121,
  23612. overline: 0x203E,
  23613. overlinecenterline: 0xFE4A,
  23614. overlinecmb: 0x0305,
  23615. overlinedashed: 0xFE49,
  23616. overlinedblwavy: 0xFE4C,
  23617. overlinewavy: 0xFE4B,
  23618. overscore: 0x00AF,
  23619. ovowelsignbengali: 0x09CB,
  23620. ovowelsigndeva: 0x094B,
  23621. ovowelsigngujarati: 0x0ACB,
  23622. p: 0x0070,
  23623. paampssquare: 0x3380,
  23624. paasentosquare: 0x332B,
  23625. pabengali: 0x09AA,
  23626. pacute: 0x1E55,
  23627. padeva: 0x092A,
  23628. pagedown: 0x21DF,
  23629. pageup: 0x21DE,
  23630. pagujarati: 0x0AAA,
  23631. pagurmukhi: 0x0A2A,
  23632. pahiragana: 0x3071,
  23633. paiyannoithai: 0x0E2F,
  23634. pakatakana: 0x30D1,
  23635. palatalizationcyrilliccmb: 0x0484,
  23636. palochkacyrillic: 0x04C0,
  23637. pansioskorean: 0x317F,
  23638. paragraph: 0x00B6,
  23639. parallel: 0x2225,
  23640. parenleft: 0x0028,
  23641. parenleftaltonearabic: 0xFD3E,
  23642. parenleftbt: 0xF8ED,
  23643. parenleftex: 0xF8EC,
  23644. parenleftinferior: 0x208D,
  23645. parenleftmonospace: 0xFF08,
  23646. parenleftsmall: 0xFE59,
  23647. parenleftsuperior: 0x207D,
  23648. parenlefttp: 0xF8EB,
  23649. parenleftvertical: 0xFE35,
  23650. parenright: 0x0029,
  23651. parenrightaltonearabic: 0xFD3F,
  23652. parenrightbt: 0xF8F8,
  23653. parenrightex: 0xF8F7,
  23654. parenrightinferior: 0x208E,
  23655. parenrightmonospace: 0xFF09,
  23656. parenrightsmall: 0xFE5A,
  23657. parenrightsuperior: 0x207E,
  23658. parenrighttp: 0xF8F6,
  23659. parenrightvertical: 0xFE36,
  23660. partialdiff: 0x2202,
  23661. paseqhebrew: 0x05C0,
  23662. pashtahebrew: 0x0599,
  23663. pasquare: 0x33A9,
  23664. patah: 0x05B7,
  23665. patah11: 0x05B7,
  23666. patah1d: 0x05B7,
  23667. patah2a: 0x05B7,
  23668. patahhebrew: 0x05B7,
  23669. patahnarrowhebrew: 0x05B7,
  23670. patahquarterhebrew: 0x05B7,
  23671. patahwidehebrew: 0x05B7,
  23672. pazerhebrew: 0x05A1,
  23673. pbopomofo: 0x3106,
  23674. pcircle: 0x24DF,
  23675. pdotaccent: 0x1E57,
  23676. pe: 0x05E4,
  23677. pecyrillic: 0x043F,
  23678. pedagesh: 0xFB44,
  23679. pedageshhebrew: 0xFB44,
  23680. peezisquare: 0x333B,
  23681. pefinaldageshhebrew: 0xFB43,
  23682. peharabic: 0x067E,
  23683. peharmenian: 0x057A,
  23684. pehebrew: 0x05E4,
  23685. pehfinalarabic: 0xFB57,
  23686. pehinitialarabic: 0xFB58,
  23687. pehiragana: 0x307A,
  23688. pehmedialarabic: 0xFB59,
  23689. pekatakana: 0x30DA,
  23690. pemiddlehookcyrillic: 0x04A7,
  23691. perafehebrew: 0xFB4E,
  23692. percent: 0x0025,
  23693. percentarabic: 0x066A,
  23694. percentmonospace: 0xFF05,
  23695. percentsmall: 0xFE6A,
  23696. period: 0x002E,
  23697. periodarmenian: 0x0589,
  23698. periodcentered: 0x00B7,
  23699. periodhalfwidth: 0xFF61,
  23700. periodinferior: 0xF6E7,
  23701. periodmonospace: 0xFF0E,
  23702. periodsmall: 0xFE52,
  23703. periodsuperior: 0xF6E8,
  23704. perispomenigreekcmb: 0x0342,
  23705. perpendicular: 0x22A5,
  23706. perthousand: 0x2030,
  23707. peseta: 0x20A7,
  23708. pfsquare: 0x338A,
  23709. phabengali: 0x09AB,
  23710. phadeva: 0x092B,
  23711. phagujarati: 0x0AAB,
  23712. phagurmukhi: 0x0A2B,
  23713. phi: 0x03C6,
  23714. phi1: 0x03D5,
  23715. phieuphacirclekorean: 0x327A,
  23716. phieuphaparenkorean: 0x321A,
  23717. phieuphcirclekorean: 0x326C,
  23718. phieuphkorean: 0x314D,
  23719. phieuphparenkorean: 0x320C,
  23720. philatin: 0x0278,
  23721. phinthuthai: 0x0E3A,
  23722. phisymbolgreek: 0x03D5,
  23723. phook: 0x01A5,
  23724. phophanthai: 0x0E1E,
  23725. phophungthai: 0x0E1C,
  23726. phosamphaothai: 0x0E20,
  23727. pi: 0x03C0,
  23728. pieupacirclekorean: 0x3273,
  23729. pieupaparenkorean: 0x3213,
  23730. pieupcieuckorean: 0x3176,
  23731. pieupcirclekorean: 0x3265,
  23732. pieupkiyeokkorean: 0x3172,
  23733. pieupkorean: 0x3142,
  23734. pieupparenkorean: 0x3205,
  23735. pieupsioskiyeokkorean: 0x3174,
  23736. pieupsioskorean: 0x3144,
  23737. pieupsiostikeutkorean: 0x3175,
  23738. pieupthieuthkorean: 0x3177,
  23739. pieuptikeutkorean: 0x3173,
  23740. pihiragana: 0x3074,
  23741. pikatakana: 0x30D4,
  23742. pisymbolgreek: 0x03D6,
  23743. piwrarmenian: 0x0583,
  23744. plus: 0x002B,
  23745. plusbelowcmb: 0x031F,
  23746. pluscircle: 0x2295,
  23747. plusminus: 0x00B1,
  23748. plusmod: 0x02D6,
  23749. plusmonospace: 0xFF0B,
  23750. plussmall: 0xFE62,
  23751. plussuperior: 0x207A,
  23752. pmonospace: 0xFF50,
  23753. pmsquare: 0x33D8,
  23754. pohiragana: 0x307D,
  23755. pointingindexdownwhite: 0x261F,
  23756. pointingindexleftwhite: 0x261C,
  23757. pointingindexrightwhite: 0x261E,
  23758. pointingindexupwhite: 0x261D,
  23759. pokatakana: 0x30DD,
  23760. poplathai: 0x0E1B,
  23761. postalmark: 0x3012,
  23762. postalmarkface: 0x3020,
  23763. pparen: 0x24AB,
  23764. precedes: 0x227A,
  23765. prescription: 0x211E,
  23766. primemod: 0x02B9,
  23767. primereversed: 0x2035,
  23768. product: 0x220F,
  23769. projective: 0x2305,
  23770. prolongedkana: 0x30FC,
  23771. propellor: 0x2318,
  23772. propersubset: 0x2282,
  23773. propersuperset: 0x2283,
  23774. proportion: 0x2237,
  23775. proportional: 0x221D,
  23776. psi: 0x03C8,
  23777. psicyrillic: 0x0471,
  23778. psilipneumatacyrilliccmb: 0x0486,
  23779. pssquare: 0x33B0,
  23780. puhiragana: 0x3077,
  23781. pukatakana: 0x30D7,
  23782. pvsquare: 0x33B4,
  23783. pwsquare: 0x33BA,
  23784. q: 0x0071,
  23785. qadeva: 0x0958,
  23786. qadmahebrew: 0x05A8,
  23787. qafarabic: 0x0642,
  23788. qaffinalarabic: 0xFED6,
  23789. qafinitialarabic: 0xFED7,
  23790. qafmedialarabic: 0xFED8,
  23791. qamats: 0x05B8,
  23792. qamats10: 0x05B8,
  23793. qamats1a: 0x05B8,
  23794. qamats1c: 0x05B8,
  23795. qamats27: 0x05B8,
  23796. qamats29: 0x05B8,
  23797. qamats33: 0x05B8,
  23798. qamatsde: 0x05B8,
  23799. qamatshebrew: 0x05B8,
  23800. qamatsnarrowhebrew: 0x05B8,
  23801. qamatsqatanhebrew: 0x05B8,
  23802. qamatsqatannarrowhebrew: 0x05B8,
  23803. qamatsqatanquarterhebrew: 0x05B8,
  23804. qamatsqatanwidehebrew: 0x05B8,
  23805. qamatsquarterhebrew: 0x05B8,
  23806. qamatswidehebrew: 0x05B8,
  23807. qarneyparahebrew: 0x059F,
  23808. qbopomofo: 0x3111,
  23809. qcircle: 0x24E0,
  23810. qhook: 0x02A0,
  23811. qmonospace: 0xFF51,
  23812. qof: 0x05E7,
  23813. qofdagesh: 0xFB47,
  23814. qofdageshhebrew: 0xFB47,
  23815. qofhebrew: 0x05E7,
  23816. qparen: 0x24AC,
  23817. quarternote: 0x2669,
  23818. qubuts: 0x05BB,
  23819. qubuts18: 0x05BB,
  23820. qubuts25: 0x05BB,
  23821. qubuts31: 0x05BB,
  23822. qubutshebrew: 0x05BB,
  23823. qubutsnarrowhebrew: 0x05BB,
  23824. qubutsquarterhebrew: 0x05BB,
  23825. qubutswidehebrew: 0x05BB,
  23826. question: 0x003F,
  23827. questionarabic: 0x061F,
  23828. questionarmenian: 0x055E,
  23829. questiondown: 0x00BF,
  23830. questiondownsmall: 0xF7BF,
  23831. questiongreek: 0x037E,
  23832. questionmonospace: 0xFF1F,
  23833. questionsmall: 0xF73F,
  23834. quotedbl: 0x0022,
  23835. quotedblbase: 0x201E,
  23836. quotedblleft: 0x201C,
  23837. quotedblmonospace: 0xFF02,
  23838. quotedblprime: 0x301E,
  23839. quotedblprimereversed: 0x301D,
  23840. quotedblright: 0x201D,
  23841. quoteleft: 0x2018,
  23842. quoteleftreversed: 0x201B,
  23843. quotereversed: 0x201B,
  23844. quoteright: 0x2019,
  23845. quoterightn: 0x0149,
  23846. quotesinglbase: 0x201A,
  23847. quotesingle: 0x0027,
  23848. quotesinglemonospace: 0xFF07,
  23849. r: 0x0072,
  23850. raarmenian: 0x057C,
  23851. rabengali: 0x09B0,
  23852. racute: 0x0155,
  23853. radeva: 0x0930,
  23854. radical: 0x221A,
  23855. radicalex: 0xF8E5,
  23856. radoverssquare: 0x33AE,
  23857. radoverssquaredsquare: 0x33AF,
  23858. radsquare: 0x33AD,
  23859. rafe: 0x05BF,
  23860. rafehebrew: 0x05BF,
  23861. ragujarati: 0x0AB0,
  23862. ragurmukhi: 0x0A30,
  23863. rahiragana: 0x3089,
  23864. rakatakana: 0x30E9,
  23865. rakatakanahalfwidth: 0xFF97,
  23866. ralowerdiagonalbengali: 0x09F1,
  23867. ramiddlediagonalbengali: 0x09F0,
  23868. ramshorn: 0x0264,
  23869. ratio: 0x2236,
  23870. rbopomofo: 0x3116,
  23871. rcaron: 0x0159,
  23872. rcedilla: 0x0157,
  23873. rcircle: 0x24E1,
  23874. rcommaaccent: 0x0157,
  23875. rdblgrave: 0x0211,
  23876. rdotaccent: 0x1E59,
  23877. rdotbelow: 0x1E5B,
  23878. rdotbelowmacron: 0x1E5D,
  23879. referencemark: 0x203B,
  23880. reflexsubset: 0x2286,
  23881. reflexsuperset: 0x2287,
  23882. registered: 0x00AE,
  23883. registersans: 0xF8E8,
  23884. registerserif: 0xF6DA,
  23885. reharabic: 0x0631,
  23886. reharmenian: 0x0580,
  23887. rehfinalarabic: 0xFEAE,
  23888. rehiragana: 0x308C,
  23889. rekatakana: 0x30EC,
  23890. rekatakanahalfwidth: 0xFF9A,
  23891. resh: 0x05E8,
  23892. reshdageshhebrew: 0xFB48,
  23893. reshhebrew: 0x05E8,
  23894. reversedtilde: 0x223D,
  23895. reviahebrew: 0x0597,
  23896. reviamugrashhebrew: 0x0597,
  23897. revlogicalnot: 0x2310,
  23898. rfishhook: 0x027E,
  23899. rfishhookreversed: 0x027F,
  23900. rhabengali: 0x09DD,
  23901. rhadeva: 0x095D,
  23902. rho: 0x03C1,
  23903. rhook: 0x027D,
  23904. rhookturned: 0x027B,
  23905. rhookturnedsuperior: 0x02B5,
  23906. rhosymbolgreek: 0x03F1,
  23907. rhotichookmod: 0x02DE,
  23908. rieulacirclekorean: 0x3271,
  23909. rieulaparenkorean: 0x3211,
  23910. rieulcirclekorean: 0x3263,
  23911. rieulhieuhkorean: 0x3140,
  23912. rieulkiyeokkorean: 0x313A,
  23913. rieulkiyeoksioskorean: 0x3169,
  23914. rieulkorean: 0x3139,
  23915. rieulmieumkorean: 0x313B,
  23916. rieulpansioskorean: 0x316C,
  23917. rieulparenkorean: 0x3203,
  23918. rieulphieuphkorean: 0x313F,
  23919. rieulpieupkorean: 0x313C,
  23920. rieulpieupsioskorean: 0x316B,
  23921. rieulsioskorean: 0x313D,
  23922. rieulthieuthkorean: 0x313E,
  23923. rieultikeutkorean: 0x316A,
  23924. rieulyeorinhieuhkorean: 0x316D,
  23925. rightangle: 0x221F,
  23926. righttackbelowcmb: 0x0319,
  23927. righttriangle: 0x22BF,
  23928. rihiragana: 0x308A,
  23929. rikatakana: 0x30EA,
  23930. rikatakanahalfwidth: 0xFF98,
  23931. ring: 0x02DA,
  23932. ringbelowcmb: 0x0325,
  23933. ringcmb: 0x030A,
  23934. ringhalfleft: 0x02BF,
  23935. ringhalfleftarmenian: 0x0559,
  23936. ringhalfleftbelowcmb: 0x031C,
  23937. ringhalfleftcentered: 0x02D3,
  23938. ringhalfright: 0x02BE,
  23939. ringhalfrightbelowcmb: 0x0339,
  23940. ringhalfrightcentered: 0x02D2,
  23941. rinvertedbreve: 0x0213,
  23942. rittorusquare: 0x3351,
  23943. rlinebelow: 0x1E5F,
  23944. rlongleg: 0x027C,
  23945. rlonglegturned: 0x027A,
  23946. rmonospace: 0xFF52,
  23947. rohiragana: 0x308D,
  23948. rokatakana: 0x30ED,
  23949. rokatakanahalfwidth: 0xFF9B,
  23950. roruathai: 0x0E23,
  23951. rparen: 0x24AD,
  23952. rrabengali: 0x09DC,
  23953. rradeva: 0x0931,
  23954. rragurmukhi: 0x0A5C,
  23955. rreharabic: 0x0691,
  23956. rrehfinalarabic: 0xFB8D,
  23957. rrvocalicbengali: 0x09E0,
  23958. rrvocalicdeva: 0x0960,
  23959. rrvocalicgujarati: 0x0AE0,
  23960. rrvocalicvowelsignbengali: 0x09C4,
  23961. rrvocalicvowelsigndeva: 0x0944,
  23962. rrvocalicvowelsigngujarati: 0x0AC4,
  23963. rsuperior: 0xF6F1,
  23964. rtblock: 0x2590,
  23965. rturned: 0x0279,
  23966. rturnedsuperior: 0x02B4,
  23967. ruhiragana: 0x308B,
  23968. rukatakana: 0x30EB,
  23969. rukatakanahalfwidth: 0xFF99,
  23970. rupeemarkbengali: 0x09F2,
  23971. rupeesignbengali: 0x09F3,
  23972. rupiah: 0xF6DD,
  23973. ruthai: 0x0E24,
  23974. rvocalicbengali: 0x098B,
  23975. rvocalicdeva: 0x090B,
  23976. rvocalicgujarati: 0x0A8B,
  23977. rvocalicvowelsignbengali: 0x09C3,
  23978. rvocalicvowelsigndeva: 0x0943,
  23979. rvocalicvowelsigngujarati: 0x0AC3,
  23980. s: 0x0073,
  23981. sabengali: 0x09B8,
  23982. sacute: 0x015B,
  23983. sacutedotaccent: 0x1E65,
  23984. sadarabic: 0x0635,
  23985. sadeva: 0x0938,
  23986. sadfinalarabic: 0xFEBA,
  23987. sadinitialarabic: 0xFEBB,
  23988. sadmedialarabic: 0xFEBC,
  23989. sagujarati: 0x0AB8,
  23990. sagurmukhi: 0x0A38,
  23991. sahiragana: 0x3055,
  23992. sakatakana: 0x30B5,
  23993. sakatakanahalfwidth: 0xFF7B,
  23994. sallallahoualayhewasallamarabic: 0xFDFA,
  23995. samekh: 0x05E1,
  23996. samekhdagesh: 0xFB41,
  23997. samekhdageshhebrew: 0xFB41,
  23998. samekhhebrew: 0x05E1,
  23999. saraaathai: 0x0E32,
  24000. saraaethai: 0x0E41,
  24001. saraaimaimalaithai: 0x0E44,
  24002. saraaimaimuanthai: 0x0E43,
  24003. saraamthai: 0x0E33,
  24004. saraathai: 0x0E30,
  24005. saraethai: 0x0E40,
  24006. saraiileftthai: 0xF886,
  24007. saraiithai: 0x0E35,
  24008. saraileftthai: 0xF885,
  24009. saraithai: 0x0E34,
  24010. saraothai: 0x0E42,
  24011. saraueeleftthai: 0xF888,
  24012. saraueethai: 0x0E37,
  24013. saraueleftthai: 0xF887,
  24014. sarauethai: 0x0E36,
  24015. sarauthai: 0x0E38,
  24016. sarauuthai: 0x0E39,
  24017. sbopomofo: 0x3119,
  24018. scaron: 0x0161,
  24019. scarondotaccent: 0x1E67,
  24020. scedilla: 0x015F,
  24021. schwa: 0x0259,
  24022. schwacyrillic: 0x04D9,
  24023. schwadieresiscyrillic: 0x04DB,
  24024. schwahook: 0x025A,
  24025. scircle: 0x24E2,
  24026. scircumflex: 0x015D,
  24027. scommaaccent: 0x0219,
  24028. sdotaccent: 0x1E61,
  24029. sdotbelow: 0x1E63,
  24030. sdotbelowdotaccent: 0x1E69,
  24031. seagullbelowcmb: 0x033C,
  24032. second: 0x2033,
  24033. secondtonechinese: 0x02CA,
  24034. section: 0x00A7,
  24035. seenarabic: 0x0633,
  24036. seenfinalarabic: 0xFEB2,
  24037. seeninitialarabic: 0xFEB3,
  24038. seenmedialarabic: 0xFEB4,
  24039. segol: 0x05B6,
  24040. segol13: 0x05B6,
  24041. segol1f: 0x05B6,
  24042. segol2c: 0x05B6,
  24043. segolhebrew: 0x05B6,
  24044. segolnarrowhebrew: 0x05B6,
  24045. segolquarterhebrew: 0x05B6,
  24046. segoltahebrew: 0x0592,
  24047. segolwidehebrew: 0x05B6,
  24048. seharmenian: 0x057D,
  24049. sehiragana: 0x305B,
  24050. sekatakana: 0x30BB,
  24051. sekatakanahalfwidth: 0xFF7E,
  24052. semicolon: 0x003B,
  24053. semicolonarabic: 0x061B,
  24054. semicolonmonospace: 0xFF1B,
  24055. semicolonsmall: 0xFE54,
  24056. semivoicedmarkkana: 0x309C,
  24057. semivoicedmarkkanahalfwidth: 0xFF9F,
  24058. sentisquare: 0x3322,
  24059. sentosquare: 0x3323,
  24060. seven: 0x0037,
  24061. sevenarabic: 0x0667,
  24062. sevenbengali: 0x09ED,
  24063. sevencircle: 0x2466,
  24064. sevencircleinversesansserif: 0x2790,
  24065. sevendeva: 0x096D,
  24066. seveneighths: 0x215E,
  24067. sevengujarati: 0x0AED,
  24068. sevengurmukhi: 0x0A6D,
  24069. sevenhackarabic: 0x0667,
  24070. sevenhangzhou: 0x3027,
  24071. sevenideographicparen: 0x3226,
  24072. seveninferior: 0x2087,
  24073. sevenmonospace: 0xFF17,
  24074. sevenoldstyle: 0xF737,
  24075. sevenparen: 0x247A,
  24076. sevenperiod: 0x248E,
  24077. sevenpersian: 0x06F7,
  24078. sevenroman: 0x2176,
  24079. sevensuperior: 0x2077,
  24080. seventeencircle: 0x2470,
  24081. seventeenparen: 0x2484,
  24082. seventeenperiod: 0x2498,
  24083. seventhai: 0x0E57,
  24084. sfthyphen: 0x00AD,
  24085. shaarmenian: 0x0577,
  24086. shabengali: 0x09B6,
  24087. shacyrillic: 0x0448,
  24088. shaddaarabic: 0x0651,
  24089. shaddadammaarabic: 0xFC61,
  24090. shaddadammatanarabic: 0xFC5E,
  24091. shaddafathaarabic: 0xFC60,
  24092. shaddakasraarabic: 0xFC62,
  24093. shaddakasratanarabic: 0xFC5F,
  24094. shade: 0x2592,
  24095. shadedark: 0x2593,
  24096. shadelight: 0x2591,
  24097. shademedium: 0x2592,
  24098. shadeva: 0x0936,
  24099. shagujarati: 0x0AB6,
  24100. shagurmukhi: 0x0A36,
  24101. shalshelethebrew: 0x0593,
  24102. shbopomofo: 0x3115,
  24103. shchacyrillic: 0x0449,
  24104. sheenarabic: 0x0634,
  24105. sheenfinalarabic: 0xFEB6,
  24106. sheeninitialarabic: 0xFEB7,
  24107. sheenmedialarabic: 0xFEB8,
  24108. sheicoptic: 0x03E3,
  24109. sheqel: 0x20AA,
  24110. sheqelhebrew: 0x20AA,
  24111. sheva: 0x05B0,
  24112. sheva115: 0x05B0,
  24113. sheva15: 0x05B0,
  24114. sheva22: 0x05B0,
  24115. sheva2e: 0x05B0,
  24116. shevahebrew: 0x05B0,
  24117. shevanarrowhebrew: 0x05B0,
  24118. shevaquarterhebrew: 0x05B0,
  24119. shevawidehebrew: 0x05B0,
  24120. shhacyrillic: 0x04BB,
  24121. shimacoptic: 0x03ED,
  24122. shin: 0x05E9,
  24123. shindagesh: 0xFB49,
  24124. shindageshhebrew: 0xFB49,
  24125. shindageshshindot: 0xFB2C,
  24126. shindageshshindothebrew: 0xFB2C,
  24127. shindageshsindot: 0xFB2D,
  24128. shindageshsindothebrew: 0xFB2D,
  24129. shindothebrew: 0x05C1,
  24130. shinhebrew: 0x05E9,
  24131. shinshindot: 0xFB2A,
  24132. shinshindothebrew: 0xFB2A,
  24133. shinsindot: 0xFB2B,
  24134. shinsindothebrew: 0xFB2B,
  24135. shook: 0x0282,
  24136. sigma: 0x03C3,
  24137. sigma1: 0x03C2,
  24138. sigmafinal: 0x03C2,
  24139. sigmalunatesymbolgreek: 0x03F2,
  24140. sihiragana: 0x3057,
  24141. sikatakana: 0x30B7,
  24142. sikatakanahalfwidth: 0xFF7C,
  24143. siluqhebrew: 0x05BD,
  24144. siluqlefthebrew: 0x05BD,
  24145. similar: 0x223C,
  24146. sindothebrew: 0x05C2,
  24147. siosacirclekorean: 0x3274,
  24148. siosaparenkorean: 0x3214,
  24149. sioscieuckorean: 0x317E,
  24150. sioscirclekorean: 0x3266,
  24151. sioskiyeokkorean: 0x317A,
  24152. sioskorean: 0x3145,
  24153. siosnieunkorean: 0x317B,
  24154. siosparenkorean: 0x3206,
  24155. siospieupkorean: 0x317D,
  24156. siostikeutkorean: 0x317C,
  24157. six: 0x0036,
  24158. sixarabic: 0x0666,
  24159. sixbengali: 0x09EC,
  24160. sixcircle: 0x2465,
  24161. sixcircleinversesansserif: 0x278F,
  24162. sixdeva: 0x096C,
  24163. sixgujarati: 0x0AEC,
  24164. sixgurmukhi: 0x0A6C,
  24165. sixhackarabic: 0x0666,
  24166. sixhangzhou: 0x3026,
  24167. sixideographicparen: 0x3225,
  24168. sixinferior: 0x2086,
  24169. sixmonospace: 0xFF16,
  24170. sixoldstyle: 0xF736,
  24171. sixparen: 0x2479,
  24172. sixperiod: 0x248D,
  24173. sixpersian: 0x06F6,
  24174. sixroman: 0x2175,
  24175. sixsuperior: 0x2076,
  24176. sixteencircle: 0x246F,
  24177. sixteencurrencydenominatorbengali: 0x09F9,
  24178. sixteenparen: 0x2483,
  24179. sixteenperiod: 0x2497,
  24180. sixthai: 0x0E56,
  24181. slash: 0x002F,
  24182. slashmonospace: 0xFF0F,
  24183. slong: 0x017F,
  24184. slongdotaccent: 0x1E9B,
  24185. smileface: 0x263A,
  24186. smonospace: 0xFF53,
  24187. sofpasuqhebrew: 0x05C3,
  24188. softhyphen: 0x00AD,
  24189. softsigncyrillic: 0x044C,
  24190. sohiragana: 0x305D,
  24191. sokatakana: 0x30BD,
  24192. sokatakanahalfwidth: 0xFF7F,
  24193. soliduslongoverlaycmb: 0x0338,
  24194. solidusshortoverlaycmb: 0x0337,
  24195. sorusithai: 0x0E29,
  24196. sosalathai: 0x0E28,
  24197. sosothai: 0x0E0B,
  24198. sosuathai: 0x0E2A,
  24199. space: 0x0020,
  24200. spacehackarabic: 0x0020,
  24201. spade: 0x2660,
  24202. spadesuitblack: 0x2660,
  24203. spadesuitwhite: 0x2664,
  24204. sparen: 0x24AE,
  24205. squarebelowcmb: 0x033B,
  24206. squarecc: 0x33C4,
  24207. squarecm: 0x339D,
  24208. squarediagonalcrosshatchfill: 0x25A9,
  24209. squarehorizontalfill: 0x25A4,
  24210. squarekg: 0x338F,
  24211. squarekm: 0x339E,
  24212. squarekmcapital: 0x33CE,
  24213. squareln: 0x33D1,
  24214. squarelog: 0x33D2,
  24215. squaremg: 0x338E,
  24216. squaremil: 0x33D5,
  24217. squaremm: 0x339C,
  24218. squaremsquared: 0x33A1,
  24219. squareorthogonalcrosshatchfill: 0x25A6,
  24220. squareupperlefttolowerrightfill: 0x25A7,
  24221. squareupperrighttolowerleftfill: 0x25A8,
  24222. squareverticalfill: 0x25A5,
  24223. squarewhitewithsmallblack: 0x25A3,
  24224. srsquare: 0x33DB,
  24225. ssabengali: 0x09B7,
  24226. ssadeva: 0x0937,
  24227. ssagujarati: 0x0AB7,
  24228. ssangcieuckorean: 0x3149,
  24229. ssanghieuhkorean: 0x3185,
  24230. ssangieungkorean: 0x3180,
  24231. ssangkiyeokkorean: 0x3132,
  24232. ssangnieunkorean: 0x3165,
  24233. ssangpieupkorean: 0x3143,
  24234. ssangsioskorean: 0x3146,
  24235. ssangtikeutkorean: 0x3138,
  24236. ssuperior: 0xF6F2,
  24237. sterling: 0x00A3,
  24238. sterlingmonospace: 0xFFE1,
  24239. strokelongoverlaycmb: 0x0336,
  24240. strokeshortoverlaycmb: 0x0335,
  24241. subset: 0x2282,
  24242. subsetnotequal: 0x228A,
  24243. subsetorequal: 0x2286,
  24244. succeeds: 0x227B,
  24245. suchthat: 0x220B,
  24246. suhiragana: 0x3059,
  24247. sukatakana: 0x30B9,
  24248. sukatakanahalfwidth: 0xFF7D,
  24249. sukunarabic: 0x0652,
  24250. summation: 0x2211,
  24251. sun: 0x263C,
  24252. superset: 0x2283,
  24253. supersetnotequal: 0x228B,
  24254. supersetorequal: 0x2287,
  24255. svsquare: 0x33DC,
  24256. syouwaerasquare: 0x337C,
  24257. t: 0x0074,
  24258. tabengali: 0x09A4,
  24259. tackdown: 0x22A4,
  24260. tackleft: 0x22A3,
  24261. tadeva: 0x0924,
  24262. tagujarati: 0x0AA4,
  24263. tagurmukhi: 0x0A24,
  24264. taharabic: 0x0637,
  24265. tahfinalarabic: 0xFEC2,
  24266. tahinitialarabic: 0xFEC3,
  24267. tahiragana: 0x305F,
  24268. tahmedialarabic: 0xFEC4,
  24269. taisyouerasquare: 0x337D,
  24270. takatakana: 0x30BF,
  24271. takatakanahalfwidth: 0xFF80,
  24272. tatweelarabic: 0x0640,
  24273. tau: 0x03C4,
  24274. tav: 0x05EA,
  24275. tavdages: 0xFB4A,
  24276. tavdagesh: 0xFB4A,
  24277. tavdageshhebrew: 0xFB4A,
  24278. tavhebrew: 0x05EA,
  24279. tbar: 0x0167,
  24280. tbopomofo: 0x310A,
  24281. tcaron: 0x0165,
  24282. tccurl: 0x02A8,
  24283. tcedilla: 0x0163,
  24284. tcheharabic: 0x0686,
  24285. tchehfinalarabic: 0xFB7B,
  24286. tchehinitialarabic: 0xFB7C,
  24287. tchehmedialarabic: 0xFB7D,
  24288. tcircle: 0x24E3,
  24289. tcircumflexbelow: 0x1E71,
  24290. tcommaaccent: 0x0163,
  24291. tdieresis: 0x1E97,
  24292. tdotaccent: 0x1E6B,
  24293. tdotbelow: 0x1E6D,
  24294. tecyrillic: 0x0442,
  24295. tedescendercyrillic: 0x04AD,
  24296. teharabic: 0x062A,
  24297. tehfinalarabic: 0xFE96,
  24298. tehhahinitialarabic: 0xFCA2,
  24299. tehhahisolatedarabic: 0xFC0C,
  24300. tehinitialarabic: 0xFE97,
  24301. tehiragana: 0x3066,
  24302. tehjeeminitialarabic: 0xFCA1,
  24303. tehjeemisolatedarabic: 0xFC0B,
  24304. tehmarbutaarabic: 0x0629,
  24305. tehmarbutafinalarabic: 0xFE94,
  24306. tehmedialarabic: 0xFE98,
  24307. tehmeeminitialarabic: 0xFCA4,
  24308. tehmeemisolatedarabic: 0xFC0E,
  24309. tehnoonfinalarabic: 0xFC73,
  24310. tekatakana: 0x30C6,
  24311. tekatakanahalfwidth: 0xFF83,
  24312. telephone: 0x2121,
  24313. telephoneblack: 0x260E,
  24314. telishagedolahebrew: 0x05A0,
  24315. telishaqetanahebrew: 0x05A9,
  24316. tencircle: 0x2469,
  24317. tenideographicparen: 0x3229,
  24318. tenparen: 0x247D,
  24319. tenperiod: 0x2491,
  24320. tenroman: 0x2179,
  24321. tesh: 0x02A7,
  24322. tet: 0x05D8,
  24323. tetdagesh: 0xFB38,
  24324. tetdageshhebrew: 0xFB38,
  24325. tethebrew: 0x05D8,
  24326. tetsecyrillic: 0x04B5,
  24327. tevirhebrew: 0x059B,
  24328. tevirlefthebrew: 0x059B,
  24329. thabengali: 0x09A5,
  24330. thadeva: 0x0925,
  24331. thagujarati: 0x0AA5,
  24332. thagurmukhi: 0x0A25,
  24333. thalarabic: 0x0630,
  24334. thalfinalarabic: 0xFEAC,
  24335. thanthakhatlowleftthai: 0xF898,
  24336. thanthakhatlowrightthai: 0xF897,
  24337. thanthakhatthai: 0x0E4C,
  24338. thanthakhatupperleftthai: 0xF896,
  24339. theharabic: 0x062B,
  24340. thehfinalarabic: 0xFE9A,
  24341. thehinitialarabic: 0xFE9B,
  24342. thehmedialarabic: 0xFE9C,
  24343. thereexists: 0x2203,
  24344. therefore: 0x2234,
  24345. theta: 0x03B8,
  24346. theta1: 0x03D1,
  24347. thetasymbolgreek: 0x03D1,
  24348. thieuthacirclekorean: 0x3279,
  24349. thieuthaparenkorean: 0x3219,
  24350. thieuthcirclekorean: 0x326B,
  24351. thieuthkorean: 0x314C,
  24352. thieuthparenkorean: 0x320B,
  24353. thirteencircle: 0x246C,
  24354. thirteenparen: 0x2480,
  24355. thirteenperiod: 0x2494,
  24356. thonangmonthothai: 0x0E11,
  24357. thook: 0x01AD,
  24358. thophuthaothai: 0x0E12,
  24359. thorn: 0x00FE,
  24360. thothahanthai: 0x0E17,
  24361. thothanthai: 0x0E10,
  24362. thothongthai: 0x0E18,
  24363. thothungthai: 0x0E16,
  24364. thousandcyrillic: 0x0482,
  24365. thousandsseparatorarabic: 0x066C,
  24366. thousandsseparatorpersian: 0x066C,
  24367. three: 0x0033,
  24368. threearabic: 0x0663,
  24369. threebengali: 0x09E9,
  24370. threecircle: 0x2462,
  24371. threecircleinversesansserif: 0x278C,
  24372. threedeva: 0x0969,
  24373. threeeighths: 0x215C,
  24374. threegujarati: 0x0AE9,
  24375. threegurmukhi: 0x0A69,
  24376. threehackarabic: 0x0663,
  24377. threehangzhou: 0x3023,
  24378. threeideographicparen: 0x3222,
  24379. threeinferior: 0x2083,
  24380. threemonospace: 0xFF13,
  24381. threenumeratorbengali: 0x09F6,
  24382. threeoldstyle: 0xF733,
  24383. threeparen: 0x2476,
  24384. threeperiod: 0x248A,
  24385. threepersian: 0x06F3,
  24386. threequarters: 0x00BE,
  24387. threequartersemdash: 0xF6DE,
  24388. threeroman: 0x2172,
  24389. threesuperior: 0x00B3,
  24390. threethai: 0x0E53,
  24391. thzsquare: 0x3394,
  24392. tihiragana: 0x3061,
  24393. tikatakana: 0x30C1,
  24394. tikatakanahalfwidth: 0xFF81,
  24395. tikeutacirclekorean: 0x3270,
  24396. tikeutaparenkorean: 0x3210,
  24397. tikeutcirclekorean: 0x3262,
  24398. tikeutkorean: 0x3137,
  24399. tikeutparenkorean: 0x3202,
  24400. tilde: 0x02DC,
  24401. tildebelowcmb: 0x0330,
  24402. tildecmb: 0x0303,
  24403. tildecomb: 0x0303,
  24404. tildedoublecmb: 0x0360,
  24405. tildeoperator: 0x223C,
  24406. tildeoverlaycmb: 0x0334,
  24407. tildeverticalcmb: 0x033E,
  24408. timescircle: 0x2297,
  24409. tipehahebrew: 0x0596,
  24410. tipehalefthebrew: 0x0596,
  24411. tippigurmukhi: 0x0A70,
  24412. titlocyrilliccmb: 0x0483,
  24413. tiwnarmenian: 0x057F,
  24414. tlinebelow: 0x1E6F,
  24415. tmonospace: 0xFF54,
  24416. toarmenian: 0x0569,
  24417. tohiragana: 0x3068,
  24418. tokatakana: 0x30C8,
  24419. tokatakanahalfwidth: 0xFF84,
  24420. tonebarextrahighmod: 0x02E5,
  24421. tonebarextralowmod: 0x02E9,
  24422. tonebarhighmod: 0x02E6,
  24423. tonebarlowmod: 0x02E8,
  24424. tonebarmidmod: 0x02E7,
  24425. tonefive: 0x01BD,
  24426. tonesix: 0x0185,
  24427. tonetwo: 0x01A8,
  24428. tonos: 0x0384,
  24429. tonsquare: 0x3327,
  24430. topatakthai: 0x0E0F,
  24431. tortoiseshellbracketleft: 0x3014,
  24432. tortoiseshellbracketleftsmall: 0xFE5D,
  24433. tortoiseshellbracketleftvertical: 0xFE39,
  24434. tortoiseshellbracketright: 0x3015,
  24435. tortoiseshellbracketrightsmall: 0xFE5E,
  24436. tortoiseshellbracketrightvertical: 0xFE3A,
  24437. totaothai: 0x0E15,
  24438. tpalatalhook: 0x01AB,
  24439. tparen: 0x24AF,
  24440. trademark: 0x2122,
  24441. trademarksans: 0xF8EA,
  24442. trademarkserif: 0xF6DB,
  24443. tretroflexhook: 0x0288,
  24444. triagdn: 0x25BC,
  24445. triaglf: 0x25C4,
  24446. triagrt: 0x25BA,
  24447. triagup: 0x25B2,
  24448. ts: 0x02A6,
  24449. tsadi: 0x05E6,
  24450. tsadidagesh: 0xFB46,
  24451. tsadidageshhebrew: 0xFB46,
  24452. tsadihebrew: 0x05E6,
  24453. tsecyrillic: 0x0446,
  24454. tsere: 0x05B5,
  24455. tsere12: 0x05B5,
  24456. tsere1e: 0x05B5,
  24457. tsere2b: 0x05B5,
  24458. tserehebrew: 0x05B5,
  24459. tserenarrowhebrew: 0x05B5,
  24460. tserequarterhebrew: 0x05B5,
  24461. tserewidehebrew: 0x05B5,
  24462. tshecyrillic: 0x045B,
  24463. tsuperior: 0xF6F3,
  24464. ttabengali: 0x099F,
  24465. ttadeva: 0x091F,
  24466. ttagujarati: 0x0A9F,
  24467. ttagurmukhi: 0x0A1F,
  24468. tteharabic: 0x0679,
  24469. ttehfinalarabic: 0xFB67,
  24470. ttehinitialarabic: 0xFB68,
  24471. ttehmedialarabic: 0xFB69,
  24472. tthabengali: 0x09A0,
  24473. tthadeva: 0x0920,
  24474. tthagujarati: 0x0AA0,
  24475. tthagurmukhi: 0x0A20,
  24476. tturned: 0x0287,
  24477. tuhiragana: 0x3064,
  24478. tukatakana: 0x30C4,
  24479. tukatakanahalfwidth: 0xFF82,
  24480. tusmallhiragana: 0x3063,
  24481. tusmallkatakana: 0x30C3,
  24482. tusmallkatakanahalfwidth: 0xFF6F,
  24483. twelvecircle: 0x246B,
  24484. twelveparen: 0x247F,
  24485. twelveperiod: 0x2493,
  24486. twelveroman: 0x217B,
  24487. twentycircle: 0x2473,
  24488. twentyhangzhou: 0x5344,
  24489. twentyparen: 0x2487,
  24490. twentyperiod: 0x249B,
  24491. two: 0x0032,
  24492. twoarabic: 0x0662,
  24493. twobengali: 0x09E8,
  24494. twocircle: 0x2461,
  24495. twocircleinversesansserif: 0x278B,
  24496. twodeva: 0x0968,
  24497. twodotenleader: 0x2025,
  24498. twodotleader: 0x2025,
  24499. twodotleadervertical: 0xFE30,
  24500. twogujarati: 0x0AE8,
  24501. twogurmukhi: 0x0A68,
  24502. twohackarabic: 0x0662,
  24503. twohangzhou: 0x3022,
  24504. twoideographicparen: 0x3221,
  24505. twoinferior: 0x2082,
  24506. twomonospace: 0xFF12,
  24507. twonumeratorbengali: 0x09F5,
  24508. twooldstyle: 0xF732,
  24509. twoparen: 0x2475,
  24510. twoperiod: 0x2489,
  24511. twopersian: 0x06F2,
  24512. tworoman: 0x2171,
  24513. twostroke: 0x01BB,
  24514. twosuperior: 0x00B2,
  24515. twothai: 0x0E52,
  24516. twothirds: 0x2154,
  24517. u: 0x0075,
  24518. uacute: 0x00FA,
  24519. ubar: 0x0289,
  24520. ubengali: 0x0989,
  24521. ubopomofo: 0x3128,
  24522. ubreve: 0x016D,
  24523. ucaron: 0x01D4,
  24524. ucircle: 0x24E4,
  24525. ucircumflex: 0x00FB,
  24526. ucircumflexbelow: 0x1E77,
  24527. ucyrillic: 0x0443,
  24528. udattadeva: 0x0951,
  24529. udblacute: 0x0171,
  24530. udblgrave: 0x0215,
  24531. udeva: 0x0909,
  24532. udieresis: 0x00FC,
  24533. udieresisacute: 0x01D8,
  24534. udieresisbelow: 0x1E73,
  24535. udieresiscaron: 0x01DA,
  24536. udieresiscyrillic: 0x04F1,
  24537. udieresisgrave: 0x01DC,
  24538. udieresismacron: 0x01D6,
  24539. udotbelow: 0x1EE5,
  24540. ugrave: 0x00F9,
  24541. ugujarati: 0x0A89,
  24542. ugurmukhi: 0x0A09,
  24543. uhiragana: 0x3046,
  24544. uhookabove: 0x1EE7,
  24545. uhorn: 0x01B0,
  24546. uhornacute: 0x1EE9,
  24547. uhorndotbelow: 0x1EF1,
  24548. uhorngrave: 0x1EEB,
  24549. uhornhookabove: 0x1EED,
  24550. uhorntilde: 0x1EEF,
  24551. uhungarumlaut: 0x0171,
  24552. uhungarumlautcyrillic: 0x04F3,
  24553. uinvertedbreve: 0x0217,
  24554. ukatakana: 0x30A6,
  24555. ukatakanahalfwidth: 0xFF73,
  24556. ukcyrillic: 0x0479,
  24557. ukorean: 0x315C,
  24558. umacron: 0x016B,
  24559. umacroncyrillic: 0x04EF,
  24560. umacrondieresis: 0x1E7B,
  24561. umatragurmukhi: 0x0A41,
  24562. umonospace: 0xFF55,
  24563. underscore: 0x005F,
  24564. underscoredbl: 0x2017,
  24565. underscoremonospace: 0xFF3F,
  24566. underscorevertical: 0xFE33,
  24567. underscorewavy: 0xFE4F,
  24568. union: 0x222A,
  24569. universal: 0x2200,
  24570. uogonek: 0x0173,
  24571. uparen: 0x24B0,
  24572. upblock: 0x2580,
  24573. upperdothebrew: 0x05C4,
  24574. upsilon: 0x03C5,
  24575. upsilondieresis: 0x03CB,
  24576. upsilondieresistonos: 0x03B0,
  24577. upsilonlatin: 0x028A,
  24578. upsilontonos: 0x03CD,
  24579. uptackbelowcmb: 0x031D,
  24580. uptackmod: 0x02D4,
  24581. uragurmukhi: 0x0A73,
  24582. uring: 0x016F,
  24583. ushortcyrillic: 0x045E,
  24584. usmallhiragana: 0x3045,
  24585. usmallkatakana: 0x30A5,
  24586. usmallkatakanahalfwidth: 0xFF69,
  24587. ustraightcyrillic: 0x04AF,
  24588. ustraightstrokecyrillic: 0x04B1,
  24589. utilde: 0x0169,
  24590. utildeacute: 0x1E79,
  24591. utildebelow: 0x1E75,
  24592. uubengali: 0x098A,
  24593. uudeva: 0x090A,
  24594. uugujarati: 0x0A8A,
  24595. uugurmukhi: 0x0A0A,
  24596. uumatragurmukhi: 0x0A42,
  24597. uuvowelsignbengali: 0x09C2,
  24598. uuvowelsigndeva: 0x0942,
  24599. uuvowelsigngujarati: 0x0AC2,
  24600. uvowelsignbengali: 0x09C1,
  24601. uvowelsigndeva: 0x0941,
  24602. uvowelsigngujarati: 0x0AC1,
  24603. v: 0x0076,
  24604. vadeva: 0x0935,
  24605. vagujarati: 0x0AB5,
  24606. vagurmukhi: 0x0A35,
  24607. vakatakana: 0x30F7,
  24608. vav: 0x05D5,
  24609. vavdagesh: 0xFB35,
  24610. vavdagesh65: 0xFB35,
  24611. vavdageshhebrew: 0xFB35,
  24612. vavhebrew: 0x05D5,
  24613. vavholam: 0xFB4B,
  24614. vavholamhebrew: 0xFB4B,
  24615. vavvavhebrew: 0x05F0,
  24616. vavyodhebrew: 0x05F1,
  24617. vcircle: 0x24E5,
  24618. vdotbelow: 0x1E7F,
  24619. vecyrillic: 0x0432,
  24620. veharabic: 0x06A4,
  24621. vehfinalarabic: 0xFB6B,
  24622. vehinitialarabic: 0xFB6C,
  24623. vehmedialarabic: 0xFB6D,
  24624. vekatakana: 0x30F9,
  24625. venus: 0x2640,
  24626. verticalbar: 0x007C,
  24627. verticallineabovecmb: 0x030D,
  24628. verticallinebelowcmb: 0x0329,
  24629. verticallinelowmod: 0x02CC,
  24630. verticallinemod: 0x02C8,
  24631. vewarmenian: 0x057E,
  24632. vhook: 0x028B,
  24633. vikatakana: 0x30F8,
  24634. viramabengali: 0x09CD,
  24635. viramadeva: 0x094D,
  24636. viramagujarati: 0x0ACD,
  24637. visargabengali: 0x0983,
  24638. visargadeva: 0x0903,
  24639. visargagujarati: 0x0A83,
  24640. vmonospace: 0xFF56,
  24641. voarmenian: 0x0578,
  24642. voicediterationhiragana: 0x309E,
  24643. voicediterationkatakana: 0x30FE,
  24644. voicedmarkkana: 0x309B,
  24645. voicedmarkkanahalfwidth: 0xFF9E,
  24646. vokatakana: 0x30FA,
  24647. vparen: 0x24B1,
  24648. vtilde: 0x1E7D,
  24649. vturned: 0x028C,
  24650. vuhiragana: 0x3094,
  24651. vukatakana: 0x30F4,
  24652. w: 0x0077,
  24653. wacute: 0x1E83,
  24654. waekorean: 0x3159,
  24655. wahiragana: 0x308F,
  24656. wakatakana: 0x30EF,
  24657. wakatakanahalfwidth: 0xFF9C,
  24658. wakorean: 0x3158,
  24659. wasmallhiragana: 0x308E,
  24660. wasmallkatakana: 0x30EE,
  24661. wattosquare: 0x3357,
  24662. wavedash: 0x301C,
  24663. wavyunderscorevertical: 0xFE34,
  24664. wawarabic: 0x0648,
  24665. wawfinalarabic: 0xFEEE,
  24666. wawhamzaabovearabic: 0x0624,
  24667. wawhamzaabovefinalarabic: 0xFE86,
  24668. wbsquare: 0x33DD,
  24669. wcircle: 0x24E6,
  24670. wcircumflex: 0x0175,
  24671. wdieresis: 0x1E85,
  24672. wdotaccent: 0x1E87,
  24673. wdotbelow: 0x1E89,
  24674. wehiragana: 0x3091,
  24675. weierstrass: 0x2118,
  24676. wekatakana: 0x30F1,
  24677. wekorean: 0x315E,
  24678. weokorean: 0x315D,
  24679. wgrave: 0x1E81,
  24680. whitebullet: 0x25E6,
  24681. whitecircle: 0x25CB,
  24682. whitecircleinverse: 0x25D9,
  24683. whitecornerbracketleft: 0x300E,
  24684. whitecornerbracketleftvertical: 0xFE43,
  24685. whitecornerbracketright: 0x300F,
  24686. whitecornerbracketrightvertical: 0xFE44,
  24687. whitediamond: 0x25C7,
  24688. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24689. whitedownpointingsmalltriangle: 0x25BF,
  24690. whitedownpointingtriangle: 0x25BD,
  24691. whiteleftpointingsmalltriangle: 0x25C3,
  24692. whiteleftpointingtriangle: 0x25C1,
  24693. whitelenticularbracketleft: 0x3016,
  24694. whitelenticularbracketright: 0x3017,
  24695. whiterightpointingsmalltriangle: 0x25B9,
  24696. whiterightpointingtriangle: 0x25B7,
  24697. whitesmallsquare: 0x25AB,
  24698. whitesmilingface: 0x263A,
  24699. whitesquare: 0x25A1,
  24700. whitestar: 0x2606,
  24701. whitetelephone: 0x260F,
  24702. whitetortoiseshellbracketleft: 0x3018,
  24703. whitetortoiseshellbracketright: 0x3019,
  24704. whiteuppointingsmalltriangle: 0x25B5,
  24705. whiteuppointingtriangle: 0x25B3,
  24706. wihiragana: 0x3090,
  24707. wikatakana: 0x30F0,
  24708. wikorean: 0x315F,
  24709. wmonospace: 0xFF57,
  24710. wohiragana: 0x3092,
  24711. wokatakana: 0x30F2,
  24712. wokatakanahalfwidth: 0xFF66,
  24713. won: 0x20A9,
  24714. wonmonospace: 0xFFE6,
  24715. wowaenthai: 0x0E27,
  24716. wparen: 0x24B2,
  24717. wring: 0x1E98,
  24718. wsuperior: 0x02B7,
  24719. wturned: 0x028D,
  24720. wynn: 0x01BF,
  24721. x: 0x0078,
  24722. xabovecmb: 0x033D,
  24723. xbopomofo: 0x3112,
  24724. xcircle: 0x24E7,
  24725. xdieresis: 0x1E8D,
  24726. xdotaccent: 0x1E8B,
  24727. xeharmenian: 0x056D,
  24728. xi: 0x03BE,
  24729. xmonospace: 0xFF58,
  24730. xparen: 0x24B3,
  24731. xsuperior: 0x02E3,
  24732. y: 0x0079,
  24733. yaadosquare: 0x334E,
  24734. yabengali: 0x09AF,
  24735. yacute: 0x00FD,
  24736. yadeva: 0x092F,
  24737. yaekorean: 0x3152,
  24738. yagujarati: 0x0AAF,
  24739. yagurmukhi: 0x0A2F,
  24740. yahiragana: 0x3084,
  24741. yakatakana: 0x30E4,
  24742. yakatakanahalfwidth: 0xFF94,
  24743. yakorean: 0x3151,
  24744. yamakkanthai: 0x0E4E,
  24745. yasmallhiragana: 0x3083,
  24746. yasmallkatakana: 0x30E3,
  24747. yasmallkatakanahalfwidth: 0xFF6C,
  24748. yatcyrillic: 0x0463,
  24749. ycircle: 0x24E8,
  24750. ycircumflex: 0x0177,
  24751. ydieresis: 0x00FF,
  24752. ydotaccent: 0x1E8F,
  24753. ydotbelow: 0x1EF5,
  24754. yeharabic: 0x064A,
  24755. yehbarreearabic: 0x06D2,
  24756. yehbarreefinalarabic: 0xFBAF,
  24757. yehfinalarabic: 0xFEF2,
  24758. yehhamzaabovearabic: 0x0626,
  24759. yehhamzaabovefinalarabic: 0xFE8A,
  24760. yehhamzaaboveinitialarabic: 0xFE8B,
  24761. yehhamzaabovemedialarabic: 0xFE8C,
  24762. yehinitialarabic: 0xFEF3,
  24763. yehmedialarabic: 0xFEF4,
  24764. yehmeeminitialarabic: 0xFCDD,
  24765. yehmeemisolatedarabic: 0xFC58,
  24766. yehnoonfinalarabic: 0xFC94,
  24767. yehthreedotsbelowarabic: 0x06D1,
  24768. yekorean: 0x3156,
  24769. yen: 0x00A5,
  24770. yenmonospace: 0xFFE5,
  24771. yeokorean: 0x3155,
  24772. yeorinhieuhkorean: 0x3186,
  24773. yerahbenyomohebrew: 0x05AA,
  24774. yerahbenyomolefthebrew: 0x05AA,
  24775. yericyrillic: 0x044B,
  24776. yerudieresiscyrillic: 0x04F9,
  24777. yesieungkorean: 0x3181,
  24778. yesieungpansioskorean: 0x3183,
  24779. yesieungsioskorean: 0x3182,
  24780. yetivhebrew: 0x059A,
  24781. ygrave: 0x1EF3,
  24782. yhook: 0x01B4,
  24783. yhookabove: 0x1EF7,
  24784. yiarmenian: 0x0575,
  24785. yicyrillic: 0x0457,
  24786. yikorean: 0x3162,
  24787. yinyang: 0x262F,
  24788. yiwnarmenian: 0x0582,
  24789. ymonospace: 0xFF59,
  24790. yod: 0x05D9,
  24791. yoddagesh: 0xFB39,
  24792. yoddageshhebrew: 0xFB39,
  24793. yodhebrew: 0x05D9,
  24794. yodyodhebrew: 0x05F2,
  24795. yodyodpatahhebrew: 0xFB1F,
  24796. yohiragana: 0x3088,
  24797. yoikorean: 0x3189,
  24798. yokatakana: 0x30E8,
  24799. yokatakanahalfwidth: 0xFF96,
  24800. yokorean: 0x315B,
  24801. yosmallhiragana: 0x3087,
  24802. yosmallkatakana: 0x30E7,
  24803. yosmallkatakanahalfwidth: 0xFF6E,
  24804. yotgreek: 0x03F3,
  24805. yoyaekorean: 0x3188,
  24806. yoyakorean: 0x3187,
  24807. yoyakthai: 0x0E22,
  24808. yoyingthai: 0x0E0D,
  24809. yparen: 0x24B4,
  24810. ypogegrammeni: 0x037A,
  24811. ypogegrammenigreekcmb: 0x0345,
  24812. yr: 0x01A6,
  24813. yring: 0x1E99,
  24814. ysuperior: 0x02B8,
  24815. ytilde: 0x1EF9,
  24816. yturned: 0x028E,
  24817. yuhiragana: 0x3086,
  24818. yuikorean: 0x318C,
  24819. yukatakana: 0x30E6,
  24820. yukatakanahalfwidth: 0xFF95,
  24821. yukorean: 0x3160,
  24822. yusbigcyrillic: 0x046B,
  24823. yusbigiotifiedcyrillic: 0x046D,
  24824. yuslittlecyrillic: 0x0467,
  24825. yuslittleiotifiedcyrillic: 0x0469,
  24826. yusmallhiragana: 0x3085,
  24827. yusmallkatakana: 0x30E5,
  24828. yusmallkatakanahalfwidth: 0xFF6D,
  24829. yuyekorean: 0x318B,
  24830. yuyeokorean: 0x318A,
  24831. yyabengali: 0x09DF,
  24832. yyadeva: 0x095F,
  24833. z: 0x007A,
  24834. zaarmenian: 0x0566,
  24835. zacute: 0x017A,
  24836. zadeva: 0x095B,
  24837. zagurmukhi: 0x0A5B,
  24838. zaharabic: 0x0638,
  24839. zahfinalarabic: 0xFEC6,
  24840. zahinitialarabic: 0xFEC7,
  24841. zahiragana: 0x3056,
  24842. zahmedialarabic: 0xFEC8,
  24843. zainarabic: 0x0632,
  24844. zainfinalarabic: 0xFEB0,
  24845. zakatakana: 0x30B6,
  24846. zaqefgadolhebrew: 0x0595,
  24847. zaqefqatanhebrew: 0x0594,
  24848. zarqahebrew: 0x0598,
  24849. zayin: 0x05D6,
  24850. zayindagesh: 0xFB36,
  24851. zayindageshhebrew: 0xFB36,
  24852. zayinhebrew: 0x05D6,
  24853. zbopomofo: 0x3117,
  24854. zcaron: 0x017E,
  24855. zcircle: 0x24E9,
  24856. zcircumflex: 0x1E91,
  24857. zcurl: 0x0291,
  24858. zdot: 0x017C,
  24859. zdotaccent: 0x017C,
  24860. zdotbelow: 0x1E93,
  24861. zecyrillic: 0x0437,
  24862. zedescendercyrillic: 0x0499,
  24863. zedieresiscyrillic: 0x04DF,
  24864. zehiragana: 0x305C,
  24865. zekatakana: 0x30BC,
  24866. zero: 0x0030,
  24867. zeroarabic: 0x0660,
  24868. zerobengali: 0x09E6,
  24869. zerodeva: 0x0966,
  24870. zerogujarati: 0x0AE6,
  24871. zerogurmukhi: 0x0A66,
  24872. zerohackarabic: 0x0660,
  24873. zeroinferior: 0x2080,
  24874. zeromonospace: 0xFF10,
  24875. zerooldstyle: 0xF730,
  24876. zeropersian: 0x06F0,
  24877. zerosuperior: 0x2070,
  24878. zerothai: 0x0E50,
  24879. zerowidthjoiner: 0xFEFF,
  24880. zerowidthnonjoiner: 0x200C,
  24881. zerowidthspace: 0x200B,
  24882. zeta: 0x03B6,
  24883. zhbopomofo: 0x3113,
  24884. zhearmenian: 0x056A,
  24885. zhebrevecyrillic: 0x04C2,
  24886. zhecyrillic: 0x0436,
  24887. zhedescendercyrillic: 0x0497,
  24888. zhedieresiscyrillic: 0x04DD,
  24889. zihiragana: 0x3058,
  24890. zikatakana: 0x30B8,
  24891. zinorhebrew: 0x05AE,
  24892. zlinebelow: 0x1E95,
  24893. zmonospace: 0xFF5A,
  24894. zohiragana: 0x305E,
  24895. zokatakana: 0x30BE,
  24896. zparen: 0x24B5,
  24897. zretroflexhook: 0x0290,
  24898. zstroke: 0x01B6,
  24899. zuhiragana: 0x305A,
  24900. zukatakana: 0x30BA,
  24901. '.notdef': 0x0000
  24902. };
  24903. var DingbatsGlyphsUnicode = {
  24904. space: 0x0020,
  24905. a1: 0x2701,
  24906. a2: 0x2702,
  24907. a202: 0x2703,
  24908. a3: 0x2704,
  24909. a4: 0x260E,
  24910. a5: 0x2706,
  24911. a119: 0x2707,
  24912. a118: 0x2708,
  24913. a117: 0x2709,
  24914. a11: 0x261B,
  24915. a12: 0x261E,
  24916. a13: 0x270C,
  24917. a14: 0x270D,
  24918. a15: 0x270E,
  24919. a16: 0x270F,
  24920. a105: 0x2710,
  24921. a17: 0x2711,
  24922. a18: 0x2712,
  24923. a19: 0x2713,
  24924. a20: 0x2714,
  24925. a21: 0x2715,
  24926. a22: 0x2716,
  24927. a23: 0x2717,
  24928. a24: 0x2718,
  24929. a25: 0x2719,
  24930. a26: 0x271A,
  24931. a27: 0x271B,
  24932. a28: 0x271C,
  24933. a6: 0x271D,
  24934. a7: 0x271E,
  24935. a8: 0x271F,
  24936. a9: 0x2720,
  24937. a10: 0x2721,
  24938. a29: 0x2722,
  24939. a30: 0x2723,
  24940. a31: 0x2724,
  24941. a32: 0x2725,
  24942. a33: 0x2726,
  24943. a34: 0x2727,
  24944. a35: 0x2605,
  24945. a36: 0x2729,
  24946. a37: 0x272A,
  24947. a38: 0x272B,
  24948. a39: 0x272C,
  24949. a40: 0x272D,
  24950. a41: 0x272E,
  24951. a42: 0x272F,
  24952. a43: 0x2730,
  24953. a44: 0x2731,
  24954. a45: 0x2732,
  24955. a46: 0x2733,
  24956. a47: 0x2734,
  24957. a48: 0x2735,
  24958. a49: 0x2736,
  24959. a50: 0x2737,
  24960. a51: 0x2738,
  24961. a52: 0x2739,
  24962. a53: 0x273A,
  24963. a54: 0x273B,
  24964. a55: 0x273C,
  24965. a56: 0x273D,
  24966. a57: 0x273E,
  24967. a58: 0x273F,
  24968. a59: 0x2740,
  24969. a60: 0x2741,
  24970. a61: 0x2742,
  24971. a62: 0x2743,
  24972. a63: 0x2744,
  24973. a64: 0x2745,
  24974. a65: 0x2746,
  24975. a66: 0x2747,
  24976. a67: 0x2748,
  24977. a68: 0x2749,
  24978. a69: 0x274A,
  24979. a70: 0x274B,
  24980. a71: 0x25CF,
  24981. a72: 0x274D,
  24982. a73: 0x25A0,
  24983. a74: 0x274F,
  24984. a203: 0x2750,
  24985. a75: 0x2751,
  24986. a204: 0x2752,
  24987. a76: 0x25B2,
  24988. a77: 0x25BC,
  24989. a78: 0x25C6,
  24990. a79: 0x2756,
  24991. a81: 0x25D7,
  24992. a82: 0x2758,
  24993. a83: 0x2759,
  24994. a84: 0x275A,
  24995. a97: 0x275B,
  24996. a98: 0x275C,
  24997. a99: 0x275D,
  24998. a100: 0x275E,
  24999. a101: 0x2761,
  25000. a102: 0x2762,
  25001. a103: 0x2763,
  25002. a104: 0x2764,
  25003. a106: 0x2765,
  25004. a107: 0x2766,
  25005. a108: 0x2767,
  25006. a112: 0x2663,
  25007. a111: 0x2666,
  25008. a110: 0x2665,
  25009. a109: 0x2660,
  25010. a120: 0x2460,
  25011. a121: 0x2461,
  25012. a122: 0x2462,
  25013. a123: 0x2463,
  25014. a124: 0x2464,
  25015. a125: 0x2465,
  25016. a126: 0x2466,
  25017. a127: 0x2467,
  25018. a128: 0x2468,
  25019. a129: 0x2469,
  25020. a130: 0x2776,
  25021. a131: 0x2777,
  25022. a132: 0x2778,
  25023. a133: 0x2779,
  25024. a134: 0x277A,
  25025. a135: 0x277B,
  25026. a136: 0x277C,
  25027. a137: 0x277D,
  25028. a138: 0x277E,
  25029. a139: 0x277F,
  25030. a140: 0x2780,
  25031. a141: 0x2781,
  25032. a142: 0x2782,
  25033. a143: 0x2783,
  25034. a144: 0x2784,
  25035. a145: 0x2785,
  25036. a146: 0x2786,
  25037. a147: 0x2787,
  25038. a148: 0x2788,
  25039. a149: 0x2789,
  25040. a150: 0x278A,
  25041. a151: 0x278B,
  25042. a152: 0x278C,
  25043. a153: 0x278D,
  25044. a154: 0x278E,
  25045. a155: 0x278F,
  25046. a156: 0x2790,
  25047. a157: 0x2791,
  25048. a158: 0x2792,
  25049. a159: 0x2793,
  25050. a160: 0x2794,
  25051. a161: 0x2192,
  25052. a163: 0x2194,
  25053. a164: 0x2195,
  25054. a196: 0x2798,
  25055. a165: 0x2799,
  25056. a192: 0x279A,
  25057. a166: 0x279B,
  25058. a167: 0x279C,
  25059. a168: 0x279D,
  25060. a169: 0x279E,
  25061. a170: 0x279F,
  25062. a171: 0x27A0,
  25063. a172: 0x27A1,
  25064. a173: 0x27A2,
  25065. a162: 0x27A3,
  25066. a174: 0x27A4,
  25067. a175: 0x27A5,
  25068. a176: 0x27A6,
  25069. a177: 0x27A7,
  25070. a178: 0x27A8,
  25071. a179: 0x27A9,
  25072. a193: 0x27AA,
  25073. a180: 0x27AB,
  25074. a199: 0x27AC,
  25075. a181: 0x27AD,
  25076. a200: 0x27AE,
  25077. a182: 0x27AF,
  25078. a201: 0x27B1,
  25079. a183: 0x27B2,
  25080. a184: 0x27B3,
  25081. a197: 0x27B4,
  25082. a185: 0x27B5,
  25083. a194: 0x27B6,
  25084. a198: 0x27B7,
  25085. a186: 0x27B8,
  25086. a195: 0x27B9,
  25087. a187: 0x27BA,
  25088. a188: 0x27BB,
  25089. a189: 0x27BC,
  25090. a190: 0x27BD,
  25091. a191: 0x27BE,
  25092. a89: 0x2768, // 0xF8D7
  25093. a90: 0x2769, // 0xF8D8
  25094. a93: 0x276A, // 0xF8D9
  25095. a94: 0x276B, // 0xF8DA
  25096. a91: 0x276C, // 0xF8DB
  25097. a92: 0x276D, // 0xF8DC
  25098. a205: 0x276E, // 0xF8DD
  25099. a85: 0x276F, // 0xF8DE
  25100. a206: 0x2770, // 0xF8DF
  25101. a86: 0x2771, // 0xF8E0
  25102. a87: 0x2772, // 0xF8E1
  25103. a88: 0x2773, // 0xF8E2
  25104. a95: 0x2774, // 0xF8E3
  25105. a96: 0x2775, // 0xF8E4
  25106. '.notdef': 0x0000
  25107. };
  25108. var PDFImage = (function PDFImageClosure() {
  25109. /**
  25110. * Decode the image in the main thread if it supported. Resovles the promise
  25111. * when the image data is ready.
  25112. */
  25113. function handleImageData(handler, xref, res, image) {
  25114. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  25115. // For natively supported jpegs send them to the main thread for decoding.
  25116. var dict = image.dict;
  25117. var colorSpace = dict.get('ColorSpace', 'CS');
  25118. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25119. var numComps = colorSpace.numComps;
  25120. var decodePromise = handler.sendWithPromise('JpegDecode',
  25121. [image.getIR(), numComps]);
  25122. return decodePromise.then(function (message) {
  25123. var data = message.data;
  25124. return new Stream(data, 0, data.length, image.dict);
  25125. });
  25126. } else {
  25127. return Promise.resolve(image);
  25128. }
  25129. }
  25130. /**
  25131. * Decode and clamp a value. The formula is different from the spec because we
  25132. * don't decode to float range [0,1], we decode it in the [0,max] range.
  25133. */
  25134. function decodeAndClamp(value, addend, coefficient, max) {
  25135. value = addend + value * coefficient;
  25136. // Clamp the value to the range
  25137. return (value < 0 ? 0 : (value > max ? max : value));
  25138. }
  25139. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  25140. this.image = image;
  25141. var dict = image.dict;
  25142. if (dict.has('Filter')) {
  25143. var filter = dict.get('Filter').name;
  25144. if (filter === 'JPXDecode') {
  25145. var jpxImage = new JpxImage();
  25146. jpxImage.parseImageProperties(image.stream);
  25147. image.stream.reset();
  25148. image.bitsPerComponent = jpxImage.bitsPerComponent;
  25149. image.numComps = jpxImage.componentsCount;
  25150. } else if (filter === 'JBIG2Decode') {
  25151. image.bitsPerComponent = 1;
  25152. image.numComps = 1;
  25153. }
  25154. }
  25155. // TODO cache rendered images?
  25156. this.width = dict.get('Width', 'W');
  25157. this.height = dict.get('Height', 'H');
  25158. if (this.width < 1 || this.height < 1) {
  25159. error('Invalid image width: ' + this.width + ' or height: ' +
  25160. this.height);
  25161. }
  25162. this.interpolate = dict.get('Interpolate', 'I') || false;
  25163. this.imageMask = dict.get('ImageMask', 'IM') || false;
  25164. this.matte = dict.get('Matte') || false;
  25165. var bitsPerComponent = image.bitsPerComponent;
  25166. if (!bitsPerComponent) {
  25167. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  25168. if (!bitsPerComponent) {
  25169. if (this.imageMask) {
  25170. bitsPerComponent = 1;
  25171. } else {
  25172. error('Bits per component missing in image: ' + this.imageMask);
  25173. }
  25174. }
  25175. }
  25176. this.bpc = bitsPerComponent;
  25177. if (!this.imageMask) {
  25178. var colorSpace = dict.get('ColorSpace', 'CS');
  25179. if (!colorSpace) {
  25180. info('JPX images (which do not require color spaces)');
  25181. switch (image.numComps) {
  25182. case 1:
  25183. colorSpace = Name.get('DeviceGray');
  25184. break;
  25185. case 3:
  25186. colorSpace = Name.get('DeviceRGB');
  25187. break;
  25188. case 4:
  25189. colorSpace = Name.get('DeviceCMYK');
  25190. break;
  25191. default:
  25192. error('JPX images with ' + this.numComps +
  25193. ' color components not supported.');
  25194. }
  25195. }
  25196. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25197. this.numComps = this.colorSpace.numComps;
  25198. }
  25199. this.decode = dict.get('Decode', 'D');
  25200. this.needsDecode = false;
  25201. if (this.decode &&
  25202. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  25203. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  25204. this.needsDecode = true;
  25205. // Do some preprocessing to avoid more math.
  25206. var max = (1 << bitsPerComponent) - 1;
  25207. this.decodeCoefficients = [];
  25208. this.decodeAddends = [];
  25209. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  25210. var dmin = this.decode[i];
  25211. var dmax = this.decode[i + 1];
  25212. this.decodeCoefficients[j] = dmax - dmin;
  25213. this.decodeAddends[j] = max * dmin;
  25214. }
  25215. }
  25216. if (smask) {
  25217. this.smask = new PDFImage(xref, res, smask, false);
  25218. } else if (mask) {
  25219. if (isStream(mask)) {
  25220. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  25221. } else {
  25222. // Color key mask (just an array).
  25223. this.mask = mask;
  25224. }
  25225. }
  25226. }
  25227. /**
  25228. * Handles processing of image data and returns the Promise that is resolved
  25229. * with a PDFImage when the image is ready to be used.
  25230. */
  25231. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  25232. res, image, inline) {
  25233. var imagePromise = handleImageData(handler, xref, res, image);
  25234. var smaskPromise;
  25235. var maskPromise;
  25236. var smask = image.dict.get('SMask');
  25237. var mask = image.dict.get('Mask');
  25238. if (smask) {
  25239. smaskPromise = handleImageData(handler, xref, res, smask);
  25240. maskPromise = Promise.resolve(null);
  25241. } else {
  25242. smaskPromise = Promise.resolve(null);
  25243. if (mask) {
  25244. if (isStream(mask)) {
  25245. maskPromise = handleImageData(handler, xref, res, mask);
  25246. } else if (isArray(mask)) {
  25247. maskPromise = Promise.resolve(mask);
  25248. } else {
  25249. warn('Unsupported mask format.');
  25250. maskPromise = Promise.resolve(null);
  25251. }
  25252. } else {
  25253. maskPromise = Promise.resolve(null);
  25254. }
  25255. }
  25256. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25257. function(results) {
  25258. var imageData = results[0];
  25259. var smaskData = results[1];
  25260. var maskData = results[2];
  25261. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25262. });
  25263. };
  25264. /**
  25265. * Resize an image using the nearest neighbor algorithm. Currently only
  25266. * supports one and three component images.
  25267. * @param {TypedArray} pixels The original image with one component.
  25268. * @param {Number} bpc Number of bits per component.
  25269. * @param {Number} components Number of color components, 1 or 3 is supported.
  25270. * @param {Number} w1 Original width.
  25271. * @param {Number} h1 Original height.
  25272. * @param {Number} w2 New width.
  25273. * @param {Number} h2 New height.
  25274. * @param {TypedArray} dest (Optional) The destination buffer.
  25275. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25276. * @return {TypedArray} Resized image data.
  25277. */
  25278. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25279. w1, h1, w2, h2, dest, alpha01) {
  25280. if (components !== 1 && components !== 3) {
  25281. error('Unsupported component count for resizing.');
  25282. }
  25283. var length = w2 * h2 * components;
  25284. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25285. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25286. var xRatio = w1 / w2;
  25287. var yRatio = h1 / h2;
  25288. var i, j, py, newIndex = 0, oldIndex;
  25289. var xScaled = new Uint16Array(w2);
  25290. var w1Scanline = w1 * components;
  25291. if (alpha01 !== 1) {
  25292. alpha01 = 0;
  25293. }
  25294. for (j = 0; j < w2; j++) {
  25295. xScaled[j] = Math.floor(j * xRatio) * components;
  25296. }
  25297. if (components === 1) {
  25298. for (i = 0; i < h2; i++) {
  25299. py = Math.floor(i * yRatio) * w1Scanline;
  25300. for (j = 0; j < w2; j++) {
  25301. oldIndex = py + xScaled[j];
  25302. temp[newIndex++] = pixels[oldIndex];
  25303. }
  25304. }
  25305. } else if (components === 3) {
  25306. for (i = 0; i < h2; i++) {
  25307. py = Math.floor(i * yRatio) * w1Scanline;
  25308. for (j = 0; j < w2; j++) {
  25309. oldIndex = py + xScaled[j];
  25310. temp[newIndex++] = pixels[oldIndex++];
  25311. temp[newIndex++] = pixels[oldIndex++];
  25312. temp[newIndex++] = pixels[oldIndex++];
  25313. newIndex += alpha01;
  25314. }
  25315. }
  25316. }
  25317. return temp;
  25318. };
  25319. PDFImage.createMask =
  25320. function PDFImage_createMask(imgArray, width, height,
  25321. imageIsFromDecodeStream, inverseDecode) {
  25322. // |imgArray| might not contain full data for every pixel of the mask, so
  25323. // we need to distinguish between |computedLength| and |actualLength|.
  25324. // In particular, if inverseDecode is true, then the array we return must
  25325. // have a length of |computedLength|.
  25326. var computedLength = ((width + 7) >> 3) * height;
  25327. var actualLength = imgArray.byteLength;
  25328. var haveFullData = computedLength === actualLength;
  25329. var data, i;
  25330. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25331. // imgArray came from a DecodeStream and its data is in an appropriate
  25332. // form, so we can just transfer it.
  25333. data = imgArray;
  25334. } else if (!inverseDecode) {
  25335. data = new Uint8Array(actualLength);
  25336. data.set(imgArray);
  25337. } else {
  25338. data = new Uint8Array(computedLength);
  25339. data.set(imgArray);
  25340. for (i = actualLength; i < computedLength; i++) {
  25341. data[i] = 0xff;
  25342. }
  25343. }
  25344. // If necessary, invert the original mask data (but not any extra we might
  25345. // have added above). It's safe to modify the array -- whether it's the
  25346. // original or a copy, we're about to transfer it anyway, so nothing else
  25347. // in this thread can be relying on its contents.
  25348. if (inverseDecode) {
  25349. for (i = 0; i < actualLength; i++) {
  25350. data[i] = ~data[i];
  25351. }
  25352. }
  25353. return {data: data, width: width, height: height};
  25354. };
  25355. PDFImage.prototype = {
  25356. get drawWidth() {
  25357. return Math.max(this.width,
  25358. this.smask && this.smask.width || 0,
  25359. this.mask && this.mask.width || 0);
  25360. },
  25361. get drawHeight() {
  25362. return Math.max(this.height,
  25363. this.smask && this.smask.height || 0,
  25364. this.mask && this.mask.height || 0);
  25365. },
  25366. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25367. var bpc = this.bpc;
  25368. var numComps = this.numComps;
  25369. var decodeAddends = this.decodeAddends;
  25370. var decodeCoefficients = this.decodeCoefficients;
  25371. var max = (1 << bpc) - 1;
  25372. var i, ii;
  25373. if (bpc === 1) {
  25374. // If the buffer needed decode that means it just needs to be inverted.
  25375. for (i = 0, ii = buffer.length; i < ii; i++) {
  25376. buffer[i] = +!(buffer[i]);
  25377. }
  25378. return;
  25379. }
  25380. var index = 0;
  25381. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25382. for (var j = 0; j < numComps; j++) {
  25383. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25384. decodeCoefficients[j], max);
  25385. index++;
  25386. }
  25387. }
  25388. },
  25389. getComponents: function PDFImage_getComponents(buffer) {
  25390. var bpc = this.bpc;
  25391. // This image doesn't require any extra work.
  25392. if (bpc === 8) {
  25393. return buffer;
  25394. }
  25395. var width = this.width;
  25396. var height = this.height;
  25397. var numComps = this.numComps;
  25398. var length = width * height * numComps;
  25399. var bufferPos = 0;
  25400. var output = (bpc <= 8 ? new Uint8Array(length) :
  25401. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25402. var rowComps = width * numComps;
  25403. var max = (1 << bpc) - 1;
  25404. var i = 0, ii, buf;
  25405. if (bpc === 1) {
  25406. // Optimization for reading 1 bpc images.
  25407. var mask, loop1End, loop2End;
  25408. for (var j = 0; j < height; j++) {
  25409. loop1End = i + (rowComps & ~7);
  25410. loop2End = i + rowComps;
  25411. // unroll loop for all full bytes
  25412. while (i < loop1End) {
  25413. buf = buffer[bufferPos++];
  25414. output[i] = (buf >> 7) & 1;
  25415. output[i + 1] = (buf >> 6) & 1;
  25416. output[i + 2] = (buf >> 5) & 1;
  25417. output[i + 3] = (buf >> 4) & 1;
  25418. output[i + 4] = (buf >> 3) & 1;
  25419. output[i + 5] = (buf >> 2) & 1;
  25420. output[i + 6] = (buf >> 1) & 1;
  25421. output[i + 7] = buf & 1;
  25422. i += 8;
  25423. }
  25424. // handle remaing bits
  25425. if (i < loop2End) {
  25426. buf = buffer[bufferPos++];
  25427. mask = 128;
  25428. while (i < loop2End) {
  25429. output[i++] = +!!(buf & mask);
  25430. mask >>= 1;
  25431. }
  25432. }
  25433. }
  25434. } else {
  25435. // The general case that handles all other bpc values.
  25436. var bits = 0;
  25437. buf = 0;
  25438. for (i = 0, ii = length; i < ii; ++i) {
  25439. if (i % rowComps === 0) {
  25440. buf = 0;
  25441. bits = 0;
  25442. }
  25443. while (bits < bpc) {
  25444. buf = (buf << 8) | buffer[bufferPos++];
  25445. bits += 8;
  25446. }
  25447. var remainingBits = bits - bpc;
  25448. var value = buf >> remainingBits;
  25449. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25450. buf = buf & ((1 << remainingBits) - 1);
  25451. bits = remainingBits;
  25452. }
  25453. }
  25454. return output;
  25455. },
  25456. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25457. actualHeight, image) {
  25458. var smask = this.smask;
  25459. var mask = this.mask;
  25460. var alphaBuf, sw, sh, i, ii, j;
  25461. if (smask) {
  25462. sw = smask.width;
  25463. sh = smask.height;
  25464. alphaBuf = new Uint8Array(sw * sh);
  25465. smask.fillGrayBuffer(alphaBuf);
  25466. if (sw !== width || sh !== height) {
  25467. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25468. height);
  25469. }
  25470. } else if (mask) {
  25471. if (mask instanceof PDFImage) {
  25472. sw = mask.width;
  25473. sh = mask.height;
  25474. alphaBuf = new Uint8Array(sw * sh);
  25475. mask.numComps = 1;
  25476. mask.fillGrayBuffer(alphaBuf);
  25477. // Need to invert values in rgbaBuf
  25478. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25479. alphaBuf[i] = 255 - alphaBuf[i];
  25480. }
  25481. if (sw !== width || sh !== height) {
  25482. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25483. height);
  25484. }
  25485. } else if (isArray(mask)) {
  25486. // Color key mask: if any of the compontents are outside the range
  25487. // then they should be painted.
  25488. alphaBuf = new Uint8Array(width * height);
  25489. var numComps = this.numComps;
  25490. for (i = 0, ii = width * height; i < ii; ++i) {
  25491. var opacity = 0;
  25492. var imageOffset = i * numComps;
  25493. for (j = 0; j < numComps; ++j) {
  25494. var color = image[imageOffset + j];
  25495. var maskOffset = j * 2;
  25496. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25497. opacity = 255;
  25498. break;
  25499. }
  25500. }
  25501. alphaBuf[i] = opacity;
  25502. }
  25503. } else {
  25504. error('Unknown mask format.');
  25505. }
  25506. }
  25507. if (alphaBuf) {
  25508. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25509. rgbaBuf[j] = alphaBuf[i];
  25510. }
  25511. } else {
  25512. // No mask.
  25513. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25514. rgbaBuf[j] = 255;
  25515. }
  25516. }
  25517. },
  25518. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25519. var matte = this.smask && this.smask.matte;
  25520. if (!matte) {
  25521. return;
  25522. }
  25523. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25524. var matteR = matteRgb[0];
  25525. var matteG = matteRgb[1];
  25526. var matteB = matteRgb[2];
  25527. var length = width * height * 4;
  25528. var r, g, b;
  25529. for (var i = 0; i < length; i += 4) {
  25530. var alpha = buffer[i + 3];
  25531. if (alpha === 0) {
  25532. // according formula we have to get Infinity in all components
  25533. // making it white (typical paper color) should be okay
  25534. buffer[i] = 255;
  25535. buffer[i + 1] = 255;
  25536. buffer[i + 2] = 255;
  25537. continue;
  25538. }
  25539. var k = 255 / alpha;
  25540. r = (buffer[i] - matteR) * k + matteR;
  25541. g = (buffer[i + 1] - matteG) * k + matteG;
  25542. b = (buffer[i + 2] - matteB) * k + matteB;
  25543. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25544. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25545. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25546. }
  25547. },
  25548. createImageData: function PDFImage_createImageData(forceRGBA) {
  25549. var drawWidth = this.drawWidth;
  25550. var drawHeight = this.drawHeight;
  25551. var imgData = { // other fields are filled in below
  25552. width: drawWidth,
  25553. height: drawHeight
  25554. };
  25555. var numComps = this.numComps;
  25556. var originalWidth = this.width;
  25557. var originalHeight = this.height;
  25558. var bpc = this.bpc;
  25559. // Rows start at byte boundary.
  25560. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25561. var imgArray;
  25562. if (!forceRGBA) {
  25563. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25564. // without any complications, we pass a same-sized copy to the main
  25565. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25566. // of memory for many scanned documents. It's also much faster.
  25567. //
  25568. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25569. // complications, we avoid expanding by 1.333x to RGBA form.
  25570. var kind;
  25571. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25572. kind = ImageKind.GRAYSCALE_1BPP;
  25573. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25574. !this.needsDecode) {
  25575. kind = ImageKind.RGB_24BPP;
  25576. }
  25577. if (kind && !this.smask && !this.mask &&
  25578. drawWidth === originalWidth && drawHeight === originalHeight) {
  25579. imgData.kind = kind;
  25580. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25581. // If imgArray came from a DecodeStream, we're safe to transfer it
  25582. // (and thus neuter it) because it will constitute the entire
  25583. // DecodeStream's data. But if it came from a Stream, we need to
  25584. // copy it because it'll only be a portion of the Stream's data, and
  25585. // the rest will be read later on.
  25586. if (this.image instanceof DecodeStream) {
  25587. imgData.data = imgArray;
  25588. } else {
  25589. var newArray = new Uint8Array(imgArray.length);
  25590. newArray.set(imgArray);
  25591. imgData.data = newArray;
  25592. }
  25593. if (this.needsDecode) {
  25594. // Invert the buffer (which must be grayscale if we reached here).
  25595. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25596. var buffer = imgData.data;
  25597. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25598. buffer[i] ^= 0xff;
  25599. }
  25600. }
  25601. return imgData;
  25602. }
  25603. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25604. imgData.kind = ImageKind.RGB_24BPP;
  25605. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25606. drawWidth, drawHeight, true);
  25607. return imgData;
  25608. }
  25609. }
  25610. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25611. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25612. var actualHeight = 0 | (imgArray.length / rowBytes *
  25613. drawHeight / originalHeight);
  25614. var comps = this.getComponents(imgArray);
  25615. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25616. // more compact RGB_24BPP form if allowable.
  25617. var alpha01, maybeUndoPreblend;
  25618. if (!forceRGBA && !this.smask && !this.mask) {
  25619. imgData.kind = ImageKind.RGB_24BPP;
  25620. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25621. alpha01 = 0;
  25622. maybeUndoPreblend = false;
  25623. } else {
  25624. imgData.kind = ImageKind.RGBA_32BPP;
  25625. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25626. alpha01 = 1;
  25627. maybeUndoPreblend = true;
  25628. // Color key masking (opacity) must be performed before decoding.
  25629. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25630. comps);
  25631. }
  25632. if (this.needsDecode) {
  25633. this.decodeBuffer(comps);
  25634. }
  25635. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25636. drawWidth, drawHeight, actualHeight, bpc, comps,
  25637. alpha01);
  25638. if (maybeUndoPreblend) {
  25639. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25640. }
  25641. return imgData;
  25642. },
  25643. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25644. var numComps = this.numComps;
  25645. if (numComps !== 1) {
  25646. error('Reading gray scale from a color image: ' + numComps);
  25647. }
  25648. var width = this.width;
  25649. var height = this.height;
  25650. var bpc = this.bpc;
  25651. // rows start at byte boundary
  25652. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25653. var imgArray = this.getImageBytes(height * rowBytes);
  25654. var comps = this.getComponents(imgArray);
  25655. var i, length;
  25656. if (bpc === 1) {
  25657. // inline decoding (= inversion) for 1 bpc images
  25658. length = width * height;
  25659. if (this.needsDecode) {
  25660. // invert and scale to {0, 255}
  25661. for (i = 0; i < length; ++i) {
  25662. buffer[i] = (comps[i] - 1) & 255;
  25663. }
  25664. } else {
  25665. // scale to {0, 255}
  25666. for (i = 0; i < length; ++i) {
  25667. buffer[i] = (-comps[i]) & 255;
  25668. }
  25669. }
  25670. return;
  25671. }
  25672. if (this.needsDecode) {
  25673. this.decodeBuffer(comps);
  25674. }
  25675. length = width * height;
  25676. // we aren't using a colorspace so we need to scale the value
  25677. var scale = 255 / ((1 << bpc) - 1);
  25678. for (i = 0; i < length; ++i) {
  25679. buffer[i] = (scale * comps[i]) | 0;
  25680. }
  25681. },
  25682. getImageBytes: function PDFImage_getImageBytes(length,
  25683. drawWidth, drawHeight,
  25684. forceRGB) {
  25685. this.image.reset();
  25686. this.image.drawWidth = drawWidth || this.width;
  25687. this.image.drawHeight = drawHeight || this.height;
  25688. this.image.forceRGB = !!forceRGB;
  25689. return this.image.getBytes(length);
  25690. }
  25691. };
  25692. return PDFImage;
  25693. })();
  25694. // The Metrics object contains glyph widths (in glyph space units).
  25695. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25696. // space unit corresponds to 1/1000th of text space unit.
  25697. var Metrics = {
  25698. 'Courier': 600,
  25699. 'Courier-Bold': 600,
  25700. 'Courier-BoldOblique': 600,
  25701. 'Courier-Oblique': 600,
  25702. 'Helvetica' : {
  25703. 'space': 278,
  25704. 'exclam': 278,
  25705. 'quotedbl': 355,
  25706. 'numbersign': 556,
  25707. 'dollar': 556,
  25708. 'percent': 889,
  25709. 'ampersand': 667,
  25710. 'quoteright': 222,
  25711. 'parenleft': 333,
  25712. 'parenright': 333,
  25713. 'asterisk': 389,
  25714. 'plus': 584,
  25715. 'comma': 278,
  25716. 'hyphen': 333,
  25717. 'period': 278,
  25718. 'slash': 278,
  25719. 'zero': 556,
  25720. 'one': 556,
  25721. 'two': 556,
  25722. 'three': 556,
  25723. 'four': 556,
  25724. 'five': 556,
  25725. 'six': 556,
  25726. 'seven': 556,
  25727. 'eight': 556,
  25728. 'nine': 556,
  25729. 'colon': 278,
  25730. 'semicolon': 278,
  25731. 'less': 584,
  25732. 'equal': 584,
  25733. 'greater': 584,
  25734. 'question': 556,
  25735. 'at': 1015,
  25736. 'A': 667,
  25737. 'B': 667,
  25738. 'C': 722,
  25739. 'D': 722,
  25740. 'E': 667,
  25741. 'F': 611,
  25742. 'G': 778,
  25743. 'H': 722,
  25744. 'I': 278,
  25745. 'J': 500,
  25746. 'K': 667,
  25747. 'L': 556,
  25748. 'M': 833,
  25749. 'N': 722,
  25750. 'O': 778,
  25751. 'P': 667,
  25752. 'Q': 778,
  25753. 'R': 722,
  25754. 'S': 667,
  25755. 'T': 611,
  25756. 'U': 722,
  25757. 'V': 667,
  25758. 'W': 944,
  25759. 'X': 667,
  25760. 'Y': 667,
  25761. 'Z': 611,
  25762. 'bracketleft': 278,
  25763. 'backslash': 278,
  25764. 'bracketright': 278,
  25765. 'asciicircum': 469,
  25766. 'underscore': 556,
  25767. 'quoteleft': 222,
  25768. 'a': 556,
  25769. 'b': 556,
  25770. 'c': 500,
  25771. 'd': 556,
  25772. 'e': 556,
  25773. 'f': 278,
  25774. 'g': 556,
  25775. 'h': 556,
  25776. 'i': 222,
  25777. 'j': 222,
  25778. 'k': 500,
  25779. 'l': 222,
  25780. 'm': 833,
  25781. 'n': 556,
  25782. 'o': 556,
  25783. 'p': 556,
  25784. 'q': 556,
  25785. 'r': 333,
  25786. 's': 500,
  25787. 't': 278,
  25788. 'u': 556,
  25789. 'v': 500,
  25790. 'w': 722,
  25791. 'x': 500,
  25792. 'y': 500,
  25793. 'z': 500,
  25794. 'braceleft': 334,
  25795. 'bar': 260,
  25796. 'braceright': 334,
  25797. 'asciitilde': 584,
  25798. 'exclamdown': 333,
  25799. 'cent': 556,
  25800. 'sterling': 556,
  25801. 'fraction': 167,
  25802. 'yen': 556,
  25803. 'florin': 556,
  25804. 'section': 556,
  25805. 'currency': 556,
  25806. 'quotesingle': 191,
  25807. 'quotedblleft': 333,
  25808. 'guillemotleft': 556,
  25809. 'guilsinglleft': 333,
  25810. 'guilsinglright': 333,
  25811. 'fi': 500,
  25812. 'fl': 500,
  25813. 'endash': 556,
  25814. 'dagger': 556,
  25815. 'daggerdbl': 556,
  25816. 'periodcentered': 278,
  25817. 'paragraph': 537,
  25818. 'bullet': 350,
  25819. 'quotesinglbase': 222,
  25820. 'quotedblbase': 333,
  25821. 'quotedblright': 333,
  25822. 'guillemotright': 556,
  25823. 'ellipsis': 1000,
  25824. 'perthousand': 1000,
  25825. 'questiondown': 611,
  25826. 'grave': 333,
  25827. 'acute': 333,
  25828. 'circumflex': 333,
  25829. 'tilde': 333,
  25830. 'macron': 333,
  25831. 'breve': 333,
  25832. 'dotaccent': 333,
  25833. 'dieresis': 333,
  25834. 'ring': 333,
  25835. 'cedilla': 333,
  25836. 'hungarumlaut': 333,
  25837. 'ogonek': 333,
  25838. 'caron': 333,
  25839. 'emdash': 1000,
  25840. 'AE': 1000,
  25841. 'ordfeminine': 370,
  25842. 'Lslash': 556,
  25843. 'Oslash': 778,
  25844. 'OE': 1000,
  25845. 'ordmasculine': 365,
  25846. 'ae': 889,
  25847. 'dotlessi': 278,
  25848. 'lslash': 222,
  25849. 'oslash': 611,
  25850. 'oe': 944,
  25851. 'germandbls': 611,
  25852. 'Idieresis': 278,
  25853. 'eacute': 556,
  25854. 'abreve': 556,
  25855. 'uhungarumlaut': 556,
  25856. 'ecaron': 556,
  25857. 'Ydieresis': 667,
  25858. 'divide': 584,
  25859. 'Yacute': 667,
  25860. 'Acircumflex': 667,
  25861. 'aacute': 556,
  25862. 'Ucircumflex': 722,
  25863. 'yacute': 500,
  25864. 'scommaaccent': 500,
  25865. 'ecircumflex': 556,
  25866. 'Uring': 722,
  25867. 'Udieresis': 722,
  25868. 'aogonek': 556,
  25869. 'Uacute': 722,
  25870. 'uogonek': 556,
  25871. 'Edieresis': 667,
  25872. 'Dcroat': 722,
  25873. 'commaaccent': 250,
  25874. 'copyright': 737,
  25875. 'Emacron': 667,
  25876. 'ccaron': 500,
  25877. 'aring': 556,
  25878. 'Ncommaaccent': 722,
  25879. 'lacute': 222,
  25880. 'agrave': 556,
  25881. 'Tcommaaccent': 611,
  25882. 'Cacute': 722,
  25883. 'atilde': 556,
  25884. 'Edotaccent': 667,
  25885. 'scaron': 500,
  25886. 'scedilla': 500,
  25887. 'iacute': 278,
  25888. 'lozenge': 471,
  25889. 'Rcaron': 722,
  25890. 'Gcommaaccent': 778,
  25891. 'ucircumflex': 556,
  25892. 'acircumflex': 556,
  25893. 'Amacron': 667,
  25894. 'rcaron': 333,
  25895. 'ccedilla': 500,
  25896. 'Zdotaccent': 611,
  25897. 'Thorn': 667,
  25898. 'Omacron': 778,
  25899. 'Racute': 722,
  25900. 'Sacute': 667,
  25901. 'dcaron': 643,
  25902. 'Umacron': 722,
  25903. 'uring': 556,
  25904. 'threesuperior': 333,
  25905. 'Ograve': 778,
  25906. 'Agrave': 667,
  25907. 'Abreve': 667,
  25908. 'multiply': 584,
  25909. 'uacute': 556,
  25910. 'Tcaron': 611,
  25911. 'partialdiff': 476,
  25912. 'ydieresis': 500,
  25913. 'Nacute': 722,
  25914. 'icircumflex': 278,
  25915. 'Ecircumflex': 667,
  25916. 'adieresis': 556,
  25917. 'edieresis': 556,
  25918. 'cacute': 500,
  25919. 'nacute': 556,
  25920. 'umacron': 556,
  25921. 'Ncaron': 722,
  25922. 'Iacute': 278,
  25923. 'plusminus': 584,
  25924. 'brokenbar': 260,
  25925. 'registered': 737,
  25926. 'Gbreve': 778,
  25927. 'Idotaccent': 278,
  25928. 'summation': 600,
  25929. 'Egrave': 667,
  25930. 'racute': 333,
  25931. 'omacron': 556,
  25932. 'Zacute': 611,
  25933. 'Zcaron': 611,
  25934. 'greaterequal': 549,
  25935. 'Eth': 722,
  25936. 'Ccedilla': 722,
  25937. 'lcommaaccent': 222,
  25938. 'tcaron': 317,
  25939. 'eogonek': 556,
  25940. 'Uogonek': 722,
  25941. 'Aacute': 667,
  25942. 'Adieresis': 667,
  25943. 'egrave': 556,
  25944. 'zacute': 500,
  25945. 'iogonek': 222,
  25946. 'Oacute': 778,
  25947. 'oacute': 556,
  25948. 'amacron': 556,
  25949. 'sacute': 500,
  25950. 'idieresis': 278,
  25951. 'Ocircumflex': 778,
  25952. 'Ugrave': 722,
  25953. 'Delta': 612,
  25954. 'thorn': 556,
  25955. 'twosuperior': 333,
  25956. 'Odieresis': 778,
  25957. 'mu': 556,
  25958. 'igrave': 278,
  25959. 'ohungarumlaut': 556,
  25960. 'Eogonek': 667,
  25961. 'dcroat': 556,
  25962. 'threequarters': 834,
  25963. 'Scedilla': 667,
  25964. 'lcaron': 299,
  25965. 'Kcommaaccent': 667,
  25966. 'Lacute': 556,
  25967. 'trademark': 1000,
  25968. 'edotaccent': 556,
  25969. 'Igrave': 278,
  25970. 'Imacron': 278,
  25971. 'Lcaron': 556,
  25972. 'onehalf': 834,
  25973. 'lessequal': 549,
  25974. 'ocircumflex': 556,
  25975. 'ntilde': 556,
  25976. 'Uhungarumlaut': 722,
  25977. 'Eacute': 667,
  25978. 'emacron': 556,
  25979. 'gbreve': 556,
  25980. 'onequarter': 834,
  25981. 'Scaron': 667,
  25982. 'Scommaaccent': 667,
  25983. 'Ohungarumlaut': 778,
  25984. 'degree': 400,
  25985. 'ograve': 556,
  25986. 'Ccaron': 722,
  25987. 'ugrave': 556,
  25988. 'radical': 453,
  25989. 'Dcaron': 722,
  25990. 'rcommaaccent': 333,
  25991. 'Ntilde': 722,
  25992. 'otilde': 556,
  25993. 'Rcommaaccent': 722,
  25994. 'Lcommaaccent': 556,
  25995. 'Atilde': 667,
  25996. 'Aogonek': 667,
  25997. 'Aring': 667,
  25998. 'Otilde': 778,
  25999. 'zdotaccent': 500,
  26000. 'Ecaron': 667,
  26001. 'Iogonek': 278,
  26002. 'kcommaaccent': 500,
  26003. 'minus': 584,
  26004. 'Icircumflex': 278,
  26005. 'ncaron': 556,
  26006. 'tcommaaccent': 278,
  26007. 'logicalnot': 584,
  26008. 'odieresis': 556,
  26009. 'udieresis': 556,
  26010. 'notequal': 549,
  26011. 'gcommaaccent': 556,
  26012. 'eth': 556,
  26013. 'zcaron': 500,
  26014. 'ncommaaccent': 556,
  26015. 'onesuperior': 333,
  26016. 'imacron': 278,
  26017. 'Euro': 556
  26018. },
  26019. 'Helvetica-Bold': {
  26020. 'space': 278,
  26021. 'exclam': 333,
  26022. 'quotedbl': 474,
  26023. 'numbersign': 556,
  26024. 'dollar': 556,
  26025. 'percent': 889,
  26026. 'ampersand': 722,
  26027. 'quoteright': 278,
  26028. 'parenleft': 333,
  26029. 'parenright': 333,
  26030. 'asterisk': 389,
  26031. 'plus': 584,
  26032. 'comma': 278,
  26033. 'hyphen': 333,
  26034. 'period': 278,
  26035. 'slash': 278,
  26036. 'zero': 556,
  26037. 'one': 556,
  26038. 'two': 556,
  26039. 'three': 556,
  26040. 'four': 556,
  26041. 'five': 556,
  26042. 'six': 556,
  26043. 'seven': 556,
  26044. 'eight': 556,
  26045. 'nine': 556,
  26046. 'colon': 333,
  26047. 'semicolon': 333,
  26048. 'less': 584,
  26049. 'equal': 584,
  26050. 'greater': 584,
  26051. 'question': 611,
  26052. 'at': 975,
  26053. 'A': 722,
  26054. 'B': 722,
  26055. 'C': 722,
  26056. 'D': 722,
  26057. 'E': 667,
  26058. 'F': 611,
  26059. 'G': 778,
  26060. 'H': 722,
  26061. 'I': 278,
  26062. 'J': 556,
  26063. 'K': 722,
  26064. 'L': 611,
  26065. 'M': 833,
  26066. 'N': 722,
  26067. 'O': 778,
  26068. 'P': 667,
  26069. 'Q': 778,
  26070. 'R': 722,
  26071. 'S': 667,
  26072. 'T': 611,
  26073. 'U': 722,
  26074. 'V': 667,
  26075. 'W': 944,
  26076. 'X': 667,
  26077. 'Y': 667,
  26078. 'Z': 611,
  26079. 'bracketleft': 333,
  26080. 'backslash': 278,
  26081. 'bracketright': 333,
  26082. 'asciicircum': 584,
  26083. 'underscore': 556,
  26084. 'quoteleft': 278,
  26085. 'a': 556,
  26086. 'b': 611,
  26087. 'c': 556,
  26088. 'd': 611,
  26089. 'e': 556,
  26090. 'f': 333,
  26091. 'g': 611,
  26092. 'h': 611,
  26093. 'i': 278,
  26094. 'j': 278,
  26095. 'k': 556,
  26096. 'l': 278,
  26097. 'm': 889,
  26098. 'n': 611,
  26099. 'o': 611,
  26100. 'p': 611,
  26101. 'q': 611,
  26102. 'r': 389,
  26103. 's': 556,
  26104. 't': 333,
  26105. 'u': 611,
  26106. 'v': 556,
  26107. 'w': 778,
  26108. 'x': 556,
  26109. 'y': 556,
  26110. 'z': 500,
  26111. 'braceleft': 389,
  26112. 'bar': 280,
  26113. 'braceright': 389,
  26114. 'asciitilde': 584,
  26115. 'exclamdown': 333,
  26116. 'cent': 556,
  26117. 'sterling': 556,
  26118. 'fraction': 167,
  26119. 'yen': 556,
  26120. 'florin': 556,
  26121. 'section': 556,
  26122. 'currency': 556,
  26123. 'quotesingle': 238,
  26124. 'quotedblleft': 500,
  26125. 'guillemotleft': 556,
  26126. 'guilsinglleft': 333,
  26127. 'guilsinglright': 333,
  26128. 'fi': 611,
  26129. 'fl': 611,
  26130. 'endash': 556,
  26131. 'dagger': 556,
  26132. 'daggerdbl': 556,
  26133. 'periodcentered': 278,
  26134. 'paragraph': 556,
  26135. 'bullet': 350,
  26136. 'quotesinglbase': 278,
  26137. 'quotedblbase': 500,
  26138. 'quotedblright': 500,
  26139. 'guillemotright': 556,
  26140. 'ellipsis': 1000,
  26141. 'perthousand': 1000,
  26142. 'questiondown': 611,
  26143. 'grave': 333,
  26144. 'acute': 333,
  26145. 'circumflex': 333,
  26146. 'tilde': 333,
  26147. 'macron': 333,
  26148. 'breve': 333,
  26149. 'dotaccent': 333,
  26150. 'dieresis': 333,
  26151. 'ring': 333,
  26152. 'cedilla': 333,
  26153. 'hungarumlaut': 333,
  26154. 'ogonek': 333,
  26155. 'caron': 333,
  26156. 'emdash': 1000,
  26157. 'AE': 1000,
  26158. 'ordfeminine': 370,
  26159. 'Lslash': 611,
  26160. 'Oslash': 778,
  26161. 'OE': 1000,
  26162. 'ordmasculine': 365,
  26163. 'ae': 889,
  26164. 'dotlessi': 278,
  26165. 'lslash': 278,
  26166. 'oslash': 611,
  26167. 'oe': 944,
  26168. 'germandbls': 611,
  26169. 'Idieresis': 278,
  26170. 'eacute': 556,
  26171. 'abreve': 556,
  26172. 'uhungarumlaut': 611,
  26173. 'ecaron': 556,
  26174. 'Ydieresis': 667,
  26175. 'divide': 584,
  26176. 'Yacute': 667,
  26177. 'Acircumflex': 722,
  26178. 'aacute': 556,
  26179. 'Ucircumflex': 722,
  26180. 'yacute': 556,
  26181. 'scommaaccent': 556,
  26182. 'ecircumflex': 556,
  26183. 'Uring': 722,
  26184. 'Udieresis': 722,
  26185. 'aogonek': 556,
  26186. 'Uacute': 722,
  26187. 'uogonek': 611,
  26188. 'Edieresis': 667,
  26189. 'Dcroat': 722,
  26190. 'commaaccent': 250,
  26191. 'copyright': 737,
  26192. 'Emacron': 667,
  26193. 'ccaron': 556,
  26194. 'aring': 556,
  26195. 'Ncommaaccent': 722,
  26196. 'lacute': 278,
  26197. 'agrave': 556,
  26198. 'Tcommaaccent': 611,
  26199. 'Cacute': 722,
  26200. 'atilde': 556,
  26201. 'Edotaccent': 667,
  26202. 'scaron': 556,
  26203. 'scedilla': 556,
  26204. 'iacute': 278,
  26205. 'lozenge': 494,
  26206. 'Rcaron': 722,
  26207. 'Gcommaaccent': 778,
  26208. 'ucircumflex': 611,
  26209. 'acircumflex': 556,
  26210. 'Amacron': 722,
  26211. 'rcaron': 389,
  26212. 'ccedilla': 556,
  26213. 'Zdotaccent': 611,
  26214. 'Thorn': 667,
  26215. 'Omacron': 778,
  26216. 'Racute': 722,
  26217. 'Sacute': 667,
  26218. 'dcaron': 743,
  26219. 'Umacron': 722,
  26220. 'uring': 611,
  26221. 'threesuperior': 333,
  26222. 'Ograve': 778,
  26223. 'Agrave': 722,
  26224. 'Abreve': 722,
  26225. 'multiply': 584,
  26226. 'uacute': 611,
  26227. 'Tcaron': 611,
  26228. 'partialdiff': 494,
  26229. 'ydieresis': 556,
  26230. 'Nacute': 722,
  26231. 'icircumflex': 278,
  26232. 'Ecircumflex': 667,
  26233. 'adieresis': 556,
  26234. 'edieresis': 556,
  26235. 'cacute': 556,
  26236. 'nacute': 611,
  26237. 'umacron': 611,
  26238. 'Ncaron': 722,
  26239. 'Iacute': 278,
  26240. 'plusminus': 584,
  26241. 'brokenbar': 280,
  26242. 'registered': 737,
  26243. 'Gbreve': 778,
  26244. 'Idotaccent': 278,
  26245. 'summation': 600,
  26246. 'Egrave': 667,
  26247. 'racute': 389,
  26248. 'omacron': 611,
  26249. 'Zacute': 611,
  26250. 'Zcaron': 611,
  26251. 'greaterequal': 549,
  26252. 'Eth': 722,
  26253. 'Ccedilla': 722,
  26254. 'lcommaaccent': 278,
  26255. 'tcaron': 389,
  26256. 'eogonek': 556,
  26257. 'Uogonek': 722,
  26258. 'Aacute': 722,
  26259. 'Adieresis': 722,
  26260. 'egrave': 556,
  26261. 'zacute': 500,
  26262. 'iogonek': 278,
  26263. 'Oacute': 778,
  26264. 'oacute': 611,
  26265. 'amacron': 556,
  26266. 'sacute': 556,
  26267. 'idieresis': 278,
  26268. 'Ocircumflex': 778,
  26269. 'Ugrave': 722,
  26270. 'Delta': 612,
  26271. 'thorn': 611,
  26272. 'twosuperior': 333,
  26273. 'Odieresis': 778,
  26274. 'mu': 611,
  26275. 'igrave': 278,
  26276. 'ohungarumlaut': 611,
  26277. 'Eogonek': 667,
  26278. 'dcroat': 611,
  26279. 'threequarters': 834,
  26280. 'Scedilla': 667,
  26281. 'lcaron': 400,
  26282. 'Kcommaaccent': 722,
  26283. 'Lacute': 611,
  26284. 'trademark': 1000,
  26285. 'edotaccent': 556,
  26286. 'Igrave': 278,
  26287. 'Imacron': 278,
  26288. 'Lcaron': 611,
  26289. 'onehalf': 834,
  26290. 'lessequal': 549,
  26291. 'ocircumflex': 611,
  26292. 'ntilde': 611,
  26293. 'Uhungarumlaut': 722,
  26294. 'Eacute': 667,
  26295. 'emacron': 556,
  26296. 'gbreve': 611,
  26297. 'onequarter': 834,
  26298. 'Scaron': 667,
  26299. 'Scommaaccent': 667,
  26300. 'Ohungarumlaut': 778,
  26301. 'degree': 400,
  26302. 'ograve': 611,
  26303. 'Ccaron': 722,
  26304. 'ugrave': 611,
  26305. 'radical': 549,
  26306. 'Dcaron': 722,
  26307. 'rcommaaccent': 389,
  26308. 'Ntilde': 722,
  26309. 'otilde': 611,
  26310. 'Rcommaaccent': 722,
  26311. 'Lcommaaccent': 611,
  26312. 'Atilde': 722,
  26313. 'Aogonek': 722,
  26314. 'Aring': 722,
  26315. 'Otilde': 778,
  26316. 'zdotaccent': 500,
  26317. 'Ecaron': 667,
  26318. 'Iogonek': 278,
  26319. 'kcommaaccent': 556,
  26320. 'minus': 584,
  26321. 'Icircumflex': 278,
  26322. 'ncaron': 611,
  26323. 'tcommaaccent': 333,
  26324. 'logicalnot': 584,
  26325. 'odieresis': 611,
  26326. 'udieresis': 611,
  26327. 'notequal': 549,
  26328. 'gcommaaccent': 611,
  26329. 'eth': 611,
  26330. 'zcaron': 500,
  26331. 'ncommaaccent': 611,
  26332. 'onesuperior': 333,
  26333. 'imacron': 278,
  26334. 'Euro': 556
  26335. },
  26336. 'Helvetica-BoldOblique': {
  26337. 'space': 278,
  26338. 'exclam': 333,
  26339. 'quotedbl': 474,
  26340. 'numbersign': 556,
  26341. 'dollar': 556,
  26342. 'percent': 889,
  26343. 'ampersand': 722,
  26344. 'quoteright': 278,
  26345. 'parenleft': 333,
  26346. 'parenright': 333,
  26347. 'asterisk': 389,
  26348. 'plus': 584,
  26349. 'comma': 278,
  26350. 'hyphen': 333,
  26351. 'period': 278,
  26352. 'slash': 278,
  26353. 'zero': 556,
  26354. 'one': 556,
  26355. 'two': 556,
  26356. 'three': 556,
  26357. 'four': 556,
  26358. 'five': 556,
  26359. 'six': 556,
  26360. 'seven': 556,
  26361. 'eight': 556,
  26362. 'nine': 556,
  26363. 'colon': 333,
  26364. 'semicolon': 333,
  26365. 'less': 584,
  26366. 'equal': 584,
  26367. 'greater': 584,
  26368. 'question': 611,
  26369. 'at': 975,
  26370. 'A': 722,
  26371. 'B': 722,
  26372. 'C': 722,
  26373. 'D': 722,
  26374. 'E': 667,
  26375. 'F': 611,
  26376. 'G': 778,
  26377. 'H': 722,
  26378. 'I': 278,
  26379. 'J': 556,
  26380. 'K': 722,
  26381. 'L': 611,
  26382. 'M': 833,
  26383. 'N': 722,
  26384. 'O': 778,
  26385. 'P': 667,
  26386. 'Q': 778,
  26387. 'R': 722,
  26388. 'S': 667,
  26389. 'T': 611,
  26390. 'U': 722,
  26391. 'V': 667,
  26392. 'W': 944,
  26393. 'X': 667,
  26394. 'Y': 667,
  26395. 'Z': 611,
  26396. 'bracketleft': 333,
  26397. 'backslash': 278,
  26398. 'bracketright': 333,
  26399. 'asciicircum': 584,
  26400. 'underscore': 556,
  26401. 'quoteleft': 278,
  26402. 'a': 556,
  26403. 'b': 611,
  26404. 'c': 556,
  26405. 'd': 611,
  26406. 'e': 556,
  26407. 'f': 333,
  26408. 'g': 611,
  26409. 'h': 611,
  26410. 'i': 278,
  26411. 'j': 278,
  26412. 'k': 556,
  26413. 'l': 278,
  26414. 'm': 889,
  26415. 'n': 611,
  26416. 'o': 611,
  26417. 'p': 611,
  26418. 'q': 611,
  26419. 'r': 389,
  26420. 's': 556,
  26421. 't': 333,
  26422. 'u': 611,
  26423. 'v': 556,
  26424. 'w': 778,
  26425. 'x': 556,
  26426. 'y': 556,
  26427. 'z': 500,
  26428. 'braceleft': 389,
  26429. 'bar': 280,
  26430. 'braceright': 389,
  26431. 'asciitilde': 584,
  26432. 'exclamdown': 333,
  26433. 'cent': 556,
  26434. 'sterling': 556,
  26435. 'fraction': 167,
  26436. 'yen': 556,
  26437. 'florin': 556,
  26438. 'section': 556,
  26439. 'currency': 556,
  26440. 'quotesingle': 238,
  26441. 'quotedblleft': 500,
  26442. 'guillemotleft': 556,
  26443. 'guilsinglleft': 333,
  26444. 'guilsinglright': 333,
  26445. 'fi': 611,
  26446. 'fl': 611,
  26447. 'endash': 556,
  26448. 'dagger': 556,
  26449. 'daggerdbl': 556,
  26450. 'periodcentered': 278,
  26451. 'paragraph': 556,
  26452. 'bullet': 350,
  26453. 'quotesinglbase': 278,
  26454. 'quotedblbase': 500,
  26455. 'quotedblright': 500,
  26456. 'guillemotright': 556,
  26457. 'ellipsis': 1000,
  26458. 'perthousand': 1000,
  26459. 'questiondown': 611,
  26460. 'grave': 333,
  26461. 'acute': 333,
  26462. 'circumflex': 333,
  26463. 'tilde': 333,
  26464. 'macron': 333,
  26465. 'breve': 333,
  26466. 'dotaccent': 333,
  26467. 'dieresis': 333,
  26468. 'ring': 333,
  26469. 'cedilla': 333,
  26470. 'hungarumlaut': 333,
  26471. 'ogonek': 333,
  26472. 'caron': 333,
  26473. 'emdash': 1000,
  26474. 'AE': 1000,
  26475. 'ordfeminine': 370,
  26476. 'Lslash': 611,
  26477. 'Oslash': 778,
  26478. 'OE': 1000,
  26479. 'ordmasculine': 365,
  26480. 'ae': 889,
  26481. 'dotlessi': 278,
  26482. 'lslash': 278,
  26483. 'oslash': 611,
  26484. 'oe': 944,
  26485. 'germandbls': 611,
  26486. 'Idieresis': 278,
  26487. 'eacute': 556,
  26488. 'abreve': 556,
  26489. 'uhungarumlaut': 611,
  26490. 'ecaron': 556,
  26491. 'Ydieresis': 667,
  26492. 'divide': 584,
  26493. 'Yacute': 667,
  26494. 'Acircumflex': 722,
  26495. 'aacute': 556,
  26496. 'Ucircumflex': 722,
  26497. 'yacute': 556,
  26498. 'scommaaccent': 556,
  26499. 'ecircumflex': 556,
  26500. 'Uring': 722,
  26501. 'Udieresis': 722,
  26502. 'aogonek': 556,
  26503. 'Uacute': 722,
  26504. 'uogonek': 611,
  26505. 'Edieresis': 667,
  26506. 'Dcroat': 722,
  26507. 'commaaccent': 250,
  26508. 'copyright': 737,
  26509. 'Emacron': 667,
  26510. 'ccaron': 556,
  26511. 'aring': 556,
  26512. 'Ncommaaccent': 722,
  26513. 'lacute': 278,
  26514. 'agrave': 556,
  26515. 'Tcommaaccent': 611,
  26516. 'Cacute': 722,
  26517. 'atilde': 556,
  26518. 'Edotaccent': 667,
  26519. 'scaron': 556,
  26520. 'scedilla': 556,
  26521. 'iacute': 278,
  26522. 'lozenge': 494,
  26523. 'Rcaron': 722,
  26524. 'Gcommaaccent': 778,
  26525. 'ucircumflex': 611,
  26526. 'acircumflex': 556,
  26527. 'Amacron': 722,
  26528. 'rcaron': 389,
  26529. 'ccedilla': 556,
  26530. 'Zdotaccent': 611,
  26531. 'Thorn': 667,
  26532. 'Omacron': 778,
  26533. 'Racute': 722,
  26534. 'Sacute': 667,
  26535. 'dcaron': 743,
  26536. 'Umacron': 722,
  26537. 'uring': 611,
  26538. 'threesuperior': 333,
  26539. 'Ograve': 778,
  26540. 'Agrave': 722,
  26541. 'Abreve': 722,
  26542. 'multiply': 584,
  26543. 'uacute': 611,
  26544. 'Tcaron': 611,
  26545. 'partialdiff': 494,
  26546. 'ydieresis': 556,
  26547. 'Nacute': 722,
  26548. 'icircumflex': 278,
  26549. 'Ecircumflex': 667,
  26550. 'adieresis': 556,
  26551. 'edieresis': 556,
  26552. 'cacute': 556,
  26553. 'nacute': 611,
  26554. 'umacron': 611,
  26555. 'Ncaron': 722,
  26556. 'Iacute': 278,
  26557. 'plusminus': 584,
  26558. 'brokenbar': 280,
  26559. 'registered': 737,
  26560. 'Gbreve': 778,
  26561. 'Idotaccent': 278,
  26562. 'summation': 600,
  26563. 'Egrave': 667,
  26564. 'racute': 389,
  26565. 'omacron': 611,
  26566. 'Zacute': 611,
  26567. 'Zcaron': 611,
  26568. 'greaterequal': 549,
  26569. 'Eth': 722,
  26570. 'Ccedilla': 722,
  26571. 'lcommaaccent': 278,
  26572. 'tcaron': 389,
  26573. 'eogonek': 556,
  26574. 'Uogonek': 722,
  26575. 'Aacute': 722,
  26576. 'Adieresis': 722,
  26577. 'egrave': 556,
  26578. 'zacute': 500,
  26579. 'iogonek': 278,
  26580. 'Oacute': 778,
  26581. 'oacute': 611,
  26582. 'amacron': 556,
  26583. 'sacute': 556,
  26584. 'idieresis': 278,
  26585. 'Ocircumflex': 778,
  26586. 'Ugrave': 722,
  26587. 'Delta': 612,
  26588. 'thorn': 611,
  26589. 'twosuperior': 333,
  26590. 'Odieresis': 778,
  26591. 'mu': 611,
  26592. 'igrave': 278,
  26593. 'ohungarumlaut': 611,
  26594. 'Eogonek': 667,
  26595. 'dcroat': 611,
  26596. 'threequarters': 834,
  26597. 'Scedilla': 667,
  26598. 'lcaron': 400,
  26599. 'Kcommaaccent': 722,
  26600. 'Lacute': 611,
  26601. 'trademark': 1000,
  26602. 'edotaccent': 556,
  26603. 'Igrave': 278,
  26604. 'Imacron': 278,
  26605. 'Lcaron': 611,
  26606. 'onehalf': 834,
  26607. 'lessequal': 549,
  26608. 'ocircumflex': 611,
  26609. 'ntilde': 611,
  26610. 'Uhungarumlaut': 722,
  26611. 'Eacute': 667,
  26612. 'emacron': 556,
  26613. 'gbreve': 611,
  26614. 'onequarter': 834,
  26615. 'Scaron': 667,
  26616. 'Scommaaccent': 667,
  26617. 'Ohungarumlaut': 778,
  26618. 'degree': 400,
  26619. 'ograve': 611,
  26620. 'Ccaron': 722,
  26621. 'ugrave': 611,
  26622. 'radical': 549,
  26623. 'Dcaron': 722,
  26624. 'rcommaaccent': 389,
  26625. 'Ntilde': 722,
  26626. 'otilde': 611,
  26627. 'Rcommaaccent': 722,
  26628. 'Lcommaaccent': 611,
  26629. 'Atilde': 722,
  26630. 'Aogonek': 722,
  26631. 'Aring': 722,
  26632. 'Otilde': 778,
  26633. 'zdotaccent': 500,
  26634. 'Ecaron': 667,
  26635. 'Iogonek': 278,
  26636. 'kcommaaccent': 556,
  26637. 'minus': 584,
  26638. 'Icircumflex': 278,
  26639. 'ncaron': 611,
  26640. 'tcommaaccent': 333,
  26641. 'logicalnot': 584,
  26642. 'odieresis': 611,
  26643. 'udieresis': 611,
  26644. 'notequal': 549,
  26645. 'gcommaaccent': 611,
  26646. 'eth': 611,
  26647. 'zcaron': 500,
  26648. 'ncommaaccent': 611,
  26649. 'onesuperior': 333,
  26650. 'imacron': 278,
  26651. 'Euro': 556
  26652. },
  26653. 'Helvetica-Oblique' : {
  26654. 'space': 278,
  26655. 'exclam': 278,
  26656. 'quotedbl': 355,
  26657. 'numbersign': 556,
  26658. 'dollar': 556,
  26659. 'percent': 889,
  26660. 'ampersand': 667,
  26661. 'quoteright': 222,
  26662. 'parenleft': 333,
  26663. 'parenright': 333,
  26664. 'asterisk': 389,
  26665. 'plus': 584,
  26666. 'comma': 278,
  26667. 'hyphen': 333,
  26668. 'period': 278,
  26669. 'slash': 278,
  26670. 'zero': 556,
  26671. 'one': 556,
  26672. 'two': 556,
  26673. 'three': 556,
  26674. 'four': 556,
  26675. 'five': 556,
  26676. 'six': 556,
  26677. 'seven': 556,
  26678. 'eight': 556,
  26679. 'nine': 556,
  26680. 'colon': 278,
  26681. 'semicolon': 278,
  26682. 'less': 584,
  26683. 'equal': 584,
  26684. 'greater': 584,
  26685. 'question': 556,
  26686. 'at': 1015,
  26687. 'A': 667,
  26688. 'B': 667,
  26689. 'C': 722,
  26690. 'D': 722,
  26691. 'E': 667,
  26692. 'F': 611,
  26693. 'G': 778,
  26694. 'H': 722,
  26695. 'I': 278,
  26696. 'J': 500,
  26697. 'K': 667,
  26698. 'L': 556,
  26699. 'M': 833,
  26700. 'N': 722,
  26701. 'O': 778,
  26702. 'P': 667,
  26703. 'Q': 778,
  26704. 'R': 722,
  26705. 'S': 667,
  26706. 'T': 611,
  26707. 'U': 722,
  26708. 'V': 667,
  26709. 'W': 944,
  26710. 'X': 667,
  26711. 'Y': 667,
  26712. 'Z': 611,
  26713. 'bracketleft': 278,
  26714. 'backslash': 278,
  26715. 'bracketright': 278,
  26716. 'asciicircum': 469,
  26717. 'underscore': 556,
  26718. 'quoteleft': 222,
  26719. 'a': 556,
  26720. 'b': 556,
  26721. 'c': 500,
  26722. 'd': 556,
  26723. 'e': 556,
  26724. 'f': 278,
  26725. 'g': 556,
  26726. 'h': 556,
  26727. 'i': 222,
  26728. 'j': 222,
  26729. 'k': 500,
  26730. 'l': 222,
  26731. 'm': 833,
  26732. 'n': 556,
  26733. 'o': 556,
  26734. 'p': 556,
  26735. 'q': 556,
  26736. 'r': 333,
  26737. 's': 500,
  26738. 't': 278,
  26739. 'u': 556,
  26740. 'v': 500,
  26741. 'w': 722,
  26742. 'x': 500,
  26743. 'y': 500,
  26744. 'z': 500,
  26745. 'braceleft': 334,
  26746. 'bar': 260,
  26747. 'braceright': 334,
  26748. 'asciitilde': 584,
  26749. 'exclamdown': 333,
  26750. 'cent': 556,
  26751. 'sterling': 556,
  26752. 'fraction': 167,
  26753. 'yen': 556,
  26754. 'florin': 556,
  26755. 'section': 556,
  26756. 'currency': 556,
  26757. 'quotesingle': 191,
  26758. 'quotedblleft': 333,
  26759. 'guillemotleft': 556,
  26760. 'guilsinglleft': 333,
  26761. 'guilsinglright': 333,
  26762. 'fi': 500,
  26763. 'fl': 500,
  26764. 'endash': 556,
  26765. 'dagger': 556,
  26766. 'daggerdbl': 556,
  26767. 'periodcentered': 278,
  26768. 'paragraph': 537,
  26769. 'bullet': 350,
  26770. 'quotesinglbase': 222,
  26771. 'quotedblbase': 333,
  26772. 'quotedblright': 333,
  26773. 'guillemotright': 556,
  26774. 'ellipsis': 1000,
  26775. 'perthousand': 1000,
  26776. 'questiondown': 611,
  26777. 'grave': 333,
  26778. 'acute': 333,
  26779. 'circumflex': 333,
  26780. 'tilde': 333,
  26781. 'macron': 333,
  26782. 'breve': 333,
  26783. 'dotaccent': 333,
  26784. 'dieresis': 333,
  26785. 'ring': 333,
  26786. 'cedilla': 333,
  26787. 'hungarumlaut': 333,
  26788. 'ogonek': 333,
  26789. 'caron': 333,
  26790. 'emdash': 1000,
  26791. 'AE': 1000,
  26792. 'ordfeminine': 370,
  26793. 'Lslash': 556,
  26794. 'Oslash': 778,
  26795. 'OE': 1000,
  26796. 'ordmasculine': 365,
  26797. 'ae': 889,
  26798. 'dotlessi': 278,
  26799. 'lslash': 222,
  26800. 'oslash': 611,
  26801. 'oe': 944,
  26802. 'germandbls': 611,
  26803. 'Idieresis': 278,
  26804. 'eacute': 556,
  26805. 'abreve': 556,
  26806. 'uhungarumlaut': 556,
  26807. 'ecaron': 556,
  26808. 'Ydieresis': 667,
  26809. 'divide': 584,
  26810. 'Yacute': 667,
  26811. 'Acircumflex': 667,
  26812. 'aacute': 556,
  26813. 'Ucircumflex': 722,
  26814. 'yacute': 500,
  26815. 'scommaaccent': 500,
  26816. 'ecircumflex': 556,
  26817. 'Uring': 722,
  26818. 'Udieresis': 722,
  26819. 'aogonek': 556,
  26820. 'Uacute': 722,
  26821. 'uogonek': 556,
  26822. 'Edieresis': 667,
  26823. 'Dcroat': 722,
  26824. 'commaaccent': 250,
  26825. 'copyright': 737,
  26826. 'Emacron': 667,
  26827. 'ccaron': 500,
  26828. 'aring': 556,
  26829. 'Ncommaaccent': 722,
  26830. 'lacute': 222,
  26831. 'agrave': 556,
  26832. 'Tcommaaccent': 611,
  26833. 'Cacute': 722,
  26834. 'atilde': 556,
  26835. 'Edotaccent': 667,
  26836. 'scaron': 500,
  26837. 'scedilla': 500,
  26838. 'iacute': 278,
  26839. 'lozenge': 471,
  26840. 'Rcaron': 722,
  26841. 'Gcommaaccent': 778,
  26842. 'ucircumflex': 556,
  26843. 'acircumflex': 556,
  26844. 'Amacron': 667,
  26845. 'rcaron': 333,
  26846. 'ccedilla': 500,
  26847. 'Zdotaccent': 611,
  26848. 'Thorn': 667,
  26849. 'Omacron': 778,
  26850. 'Racute': 722,
  26851. 'Sacute': 667,
  26852. 'dcaron': 643,
  26853. 'Umacron': 722,
  26854. 'uring': 556,
  26855. 'threesuperior': 333,
  26856. 'Ograve': 778,
  26857. 'Agrave': 667,
  26858. 'Abreve': 667,
  26859. 'multiply': 584,
  26860. 'uacute': 556,
  26861. 'Tcaron': 611,
  26862. 'partialdiff': 476,
  26863. 'ydieresis': 500,
  26864. 'Nacute': 722,
  26865. 'icircumflex': 278,
  26866. 'Ecircumflex': 667,
  26867. 'adieresis': 556,
  26868. 'edieresis': 556,
  26869. 'cacute': 500,
  26870. 'nacute': 556,
  26871. 'umacron': 556,
  26872. 'Ncaron': 722,
  26873. 'Iacute': 278,
  26874. 'plusminus': 584,
  26875. 'brokenbar': 260,
  26876. 'registered': 737,
  26877. 'Gbreve': 778,
  26878. 'Idotaccent': 278,
  26879. 'summation': 600,
  26880. 'Egrave': 667,
  26881. 'racute': 333,
  26882. 'omacron': 556,
  26883. 'Zacute': 611,
  26884. 'Zcaron': 611,
  26885. 'greaterequal': 549,
  26886. 'Eth': 722,
  26887. 'Ccedilla': 722,
  26888. 'lcommaaccent': 222,
  26889. 'tcaron': 317,
  26890. 'eogonek': 556,
  26891. 'Uogonek': 722,
  26892. 'Aacute': 667,
  26893. 'Adieresis': 667,
  26894. 'egrave': 556,
  26895. 'zacute': 500,
  26896. 'iogonek': 222,
  26897. 'Oacute': 778,
  26898. 'oacute': 556,
  26899. 'amacron': 556,
  26900. 'sacute': 500,
  26901. 'idieresis': 278,
  26902. 'Ocircumflex': 778,
  26903. 'Ugrave': 722,
  26904. 'Delta': 612,
  26905. 'thorn': 556,
  26906. 'twosuperior': 333,
  26907. 'Odieresis': 778,
  26908. 'mu': 556,
  26909. 'igrave': 278,
  26910. 'ohungarumlaut': 556,
  26911. 'Eogonek': 667,
  26912. 'dcroat': 556,
  26913. 'threequarters': 834,
  26914. 'Scedilla': 667,
  26915. 'lcaron': 299,
  26916. 'Kcommaaccent': 667,
  26917. 'Lacute': 556,
  26918. 'trademark': 1000,
  26919. 'edotaccent': 556,
  26920. 'Igrave': 278,
  26921. 'Imacron': 278,
  26922. 'Lcaron': 556,
  26923. 'onehalf': 834,
  26924. 'lessequal': 549,
  26925. 'ocircumflex': 556,
  26926. 'ntilde': 556,
  26927. 'Uhungarumlaut': 722,
  26928. 'Eacute': 667,
  26929. 'emacron': 556,
  26930. 'gbreve': 556,
  26931. 'onequarter': 834,
  26932. 'Scaron': 667,
  26933. 'Scommaaccent': 667,
  26934. 'Ohungarumlaut': 778,
  26935. 'degree': 400,
  26936. 'ograve': 556,
  26937. 'Ccaron': 722,
  26938. 'ugrave': 556,
  26939. 'radical': 453,
  26940. 'Dcaron': 722,
  26941. 'rcommaaccent': 333,
  26942. 'Ntilde': 722,
  26943. 'otilde': 556,
  26944. 'Rcommaaccent': 722,
  26945. 'Lcommaaccent': 556,
  26946. 'Atilde': 667,
  26947. 'Aogonek': 667,
  26948. 'Aring': 667,
  26949. 'Otilde': 778,
  26950. 'zdotaccent': 500,
  26951. 'Ecaron': 667,
  26952. 'Iogonek': 278,
  26953. 'kcommaaccent': 500,
  26954. 'minus': 584,
  26955. 'Icircumflex': 278,
  26956. 'ncaron': 556,
  26957. 'tcommaaccent': 278,
  26958. 'logicalnot': 584,
  26959. 'odieresis': 556,
  26960. 'udieresis': 556,
  26961. 'notequal': 549,
  26962. 'gcommaaccent': 556,
  26963. 'eth': 556,
  26964. 'zcaron': 500,
  26965. 'ncommaaccent': 556,
  26966. 'onesuperior': 333,
  26967. 'imacron': 278,
  26968. 'Euro': 556
  26969. },
  26970. 'Symbol': {
  26971. 'space': 250,
  26972. 'exclam': 333,
  26973. 'universal': 713,
  26974. 'numbersign': 500,
  26975. 'existential': 549,
  26976. 'percent': 833,
  26977. 'ampersand': 778,
  26978. 'suchthat': 439,
  26979. 'parenleft': 333,
  26980. 'parenright': 333,
  26981. 'asteriskmath': 500,
  26982. 'plus': 549,
  26983. 'comma': 250,
  26984. 'minus': 549,
  26985. 'period': 250,
  26986. 'slash': 278,
  26987. 'zero': 500,
  26988. 'one': 500,
  26989. 'two': 500,
  26990. 'three': 500,
  26991. 'four': 500,
  26992. 'five': 500,
  26993. 'six': 500,
  26994. 'seven': 500,
  26995. 'eight': 500,
  26996. 'nine': 500,
  26997. 'colon': 278,
  26998. 'semicolon': 278,
  26999. 'less': 549,
  27000. 'equal': 549,
  27001. 'greater': 549,
  27002. 'question': 444,
  27003. 'congruent': 549,
  27004. 'Alpha': 722,
  27005. 'Beta': 667,
  27006. 'Chi': 722,
  27007. 'Delta': 612,
  27008. 'Epsilon': 611,
  27009. 'Phi': 763,
  27010. 'Gamma': 603,
  27011. 'Eta': 722,
  27012. 'Iota': 333,
  27013. 'theta1': 631,
  27014. 'Kappa': 722,
  27015. 'Lambda': 686,
  27016. 'Mu': 889,
  27017. 'Nu': 722,
  27018. 'Omicron': 722,
  27019. 'Pi': 768,
  27020. 'Theta': 741,
  27021. 'Rho': 556,
  27022. 'Sigma': 592,
  27023. 'Tau': 611,
  27024. 'Upsilon': 690,
  27025. 'sigma1': 439,
  27026. 'Omega': 768,
  27027. 'Xi': 645,
  27028. 'Psi': 795,
  27029. 'Zeta': 611,
  27030. 'bracketleft': 333,
  27031. 'therefore': 863,
  27032. 'bracketright': 333,
  27033. 'perpendicular': 658,
  27034. 'underscore': 500,
  27035. 'radicalex': 500,
  27036. 'alpha': 631,
  27037. 'beta': 549,
  27038. 'chi': 549,
  27039. 'delta': 494,
  27040. 'epsilon': 439,
  27041. 'phi': 521,
  27042. 'gamma': 411,
  27043. 'eta': 603,
  27044. 'iota': 329,
  27045. 'phi1': 603,
  27046. 'kappa': 549,
  27047. 'lambda': 549,
  27048. 'mu': 576,
  27049. 'nu': 521,
  27050. 'omicron': 549,
  27051. 'pi': 549,
  27052. 'theta': 521,
  27053. 'rho': 549,
  27054. 'sigma': 603,
  27055. 'tau': 439,
  27056. 'upsilon': 576,
  27057. 'omega1': 713,
  27058. 'omega': 686,
  27059. 'xi': 493,
  27060. 'psi': 686,
  27061. 'zeta': 494,
  27062. 'braceleft': 480,
  27063. 'bar': 200,
  27064. 'braceright': 480,
  27065. 'similar': 549,
  27066. 'Euro': 750,
  27067. 'Upsilon1': 620,
  27068. 'minute': 247,
  27069. 'lessequal': 549,
  27070. 'fraction': 167,
  27071. 'infinity': 713,
  27072. 'florin': 500,
  27073. 'club': 753,
  27074. 'diamond': 753,
  27075. 'heart': 753,
  27076. 'spade': 753,
  27077. 'arrowboth': 1042,
  27078. 'arrowleft': 987,
  27079. 'arrowup': 603,
  27080. 'arrowright': 987,
  27081. 'arrowdown': 603,
  27082. 'degree': 400,
  27083. 'plusminus': 549,
  27084. 'second': 411,
  27085. 'greaterequal': 549,
  27086. 'multiply': 549,
  27087. 'proportional': 713,
  27088. 'partialdiff': 494,
  27089. 'bullet': 460,
  27090. 'divide': 549,
  27091. 'notequal': 549,
  27092. 'equivalence': 549,
  27093. 'approxequal': 549,
  27094. 'ellipsis': 1000,
  27095. 'arrowvertex': 603,
  27096. 'arrowhorizex': 1000,
  27097. 'carriagereturn': 658,
  27098. 'aleph': 823,
  27099. 'Ifraktur': 686,
  27100. 'Rfraktur': 795,
  27101. 'weierstrass': 987,
  27102. 'circlemultiply': 768,
  27103. 'circleplus': 768,
  27104. 'emptyset': 823,
  27105. 'intersection': 768,
  27106. 'union': 768,
  27107. 'propersuperset': 713,
  27108. 'reflexsuperset': 713,
  27109. 'notsubset': 713,
  27110. 'propersubset': 713,
  27111. 'reflexsubset': 713,
  27112. 'element': 713,
  27113. 'notelement': 713,
  27114. 'angle': 768,
  27115. 'gradient': 713,
  27116. 'registerserif': 790,
  27117. 'copyrightserif': 790,
  27118. 'trademarkserif': 890,
  27119. 'product': 823,
  27120. 'radical': 549,
  27121. 'dotmath': 250,
  27122. 'logicalnot': 713,
  27123. 'logicaland': 603,
  27124. 'logicalor': 603,
  27125. 'arrowdblboth': 1042,
  27126. 'arrowdblleft': 987,
  27127. 'arrowdblup': 603,
  27128. 'arrowdblright': 987,
  27129. 'arrowdbldown': 603,
  27130. 'lozenge': 494,
  27131. 'angleleft': 329,
  27132. 'registersans': 790,
  27133. 'copyrightsans': 790,
  27134. 'trademarksans': 786,
  27135. 'summation': 713,
  27136. 'parenlefttp': 384,
  27137. 'parenleftex': 384,
  27138. 'parenleftbt': 384,
  27139. 'bracketlefttp': 384,
  27140. 'bracketleftex': 384,
  27141. 'bracketleftbt': 384,
  27142. 'bracelefttp': 494,
  27143. 'braceleftmid': 494,
  27144. 'braceleftbt': 494,
  27145. 'braceex': 494,
  27146. 'angleright': 329,
  27147. 'integral': 274,
  27148. 'integraltp': 686,
  27149. 'integralex': 686,
  27150. 'integralbt': 686,
  27151. 'parenrighttp': 384,
  27152. 'parenrightex': 384,
  27153. 'parenrightbt': 384,
  27154. 'bracketrighttp': 384,
  27155. 'bracketrightex': 384,
  27156. 'bracketrightbt': 384,
  27157. 'bracerighttp': 494,
  27158. 'bracerightmid': 494,
  27159. 'bracerightbt': 494,
  27160. 'apple': 790
  27161. },
  27162. 'Times-Roman': {
  27163. 'space': 250,
  27164. 'exclam': 333,
  27165. 'quotedbl': 408,
  27166. 'numbersign': 500,
  27167. 'dollar': 500,
  27168. 'percent': 833,
  27169. 'ampersand': 778,
  27170. 'quoteright': 333,
  27171. 'parenleft': 333,
  27172. 'parenright': 333,
  27173. 'asterisk': 500,
  27174. 'plus': 564,
  27175. 'comma': 250,
  27176. 'hyphen': 333,
  27177. 'period': 250,
  27178. 'slash': 278,
  27179. 'zero': 500,
  27180. 'one': 500,
  27181. 'two': 500,
  27182. 'three': 500,
  27183. 'four': 500,
  27184. 'five': 500,
  27185. 'six': 500,
  27186. 'seven': 500,
  27187. 'eight': 500,
  27188. 'nine': 500,
  27189. 'colon': 278,
  27190. 'semicolon': 278,
  27191. 'less': 564,
  27192. 'equal': 564,
  27193. 'greater': 564,
  27194. 'question': 444,
  27195. 'at': 921,
  27196. 'A': 722,
  27197. 'B': 667,
  27198. 'C': 667,
  27199. 'D': 722,
  27200. 'E': 611,
  27201. 'F': 556,
  27202. 'G': 722,
  27203. 'H': 722,
  27204. 'I': 333,
  27205. 'J': 389,
  27206. 'K': 722,
  27207. 'L': 611,
  27208. 'M': 889,
  27209. 'N': 722,
  27210. 'O': 722,
  27211. 'P': 556,
  27212. 'Q': 722,
  27213. 'R': 667,
  27214. 'S': 556,
  27215. 'T': 611,
  27216. 'U': 722,
  27217. 'V': 722,
  27218. 'W': 944,
  27219. 'X': 722,
  27220. 'Y': 722,
  27221. 'Z': 611,
  27222. 'bracketleft': 333,
  27223. 'backslash': 278,
  27224. 'bracketright': 333,
  27225. 'asciicircum': 469,
  27226. 'underscore': 500,
  27227. 'quoteleft': 333,
  27228. 'a': 444,
  27229. 'b': 500,
  27230. 'c': 444,
  27231. 'd': 500,
  27232. 'e': 444,
  27233. 'f': 333,
  27234. 'g': 500,
  27235. 'h': 500,
  27236. 'i': 278,
  27237. 'j': 278,
  27238. 'k': 500,
  27239. 'l': 278,
  27240. 'm': 778,
  27241. 'n': 500,
  27242. 'o': 500,
  27243. 'p': 500,
  27244. 'q': 500,
  27245. 'r': 333,
  27246. 's': 389,
  27247. 't': 278,
  27248. 'u': 500,
  27249. 'v': 500,
  27250. 'w': 722,
  27251. 'x': 500,
  27252. 'y': 500,
  27253. 'z': 444,
  27254. 'braceleft': 480,
  27255. 'bar': 200,
  27256. 'braceright': 480,
  27257. 'asciitilde': 541,
  27258. 'exclamdown': 333,
  27259. 'cent': 500,
  27260. 'sterling': 500,
  27261. 'fraction': 167,
  27262. 'yen': 500,
  27263. 'florin': 500,
  27264. 'section': 500,
  27265. 'currency': 500,
  27266. 'quotesingle': 180,
  27267. 'quotedblleft': 444,
  27268. 'guillemotleft': 500,
  27269. 'guilsinglleft': 333,
  27270. 'guilsinglright': 333,
  27271. 'fi': 556,
  27272. 'fl': 556,
  27273. 'endash': 500,
  27274. 'dagger': 500,
  27275. 'daggerdbl': 500,
  27276. 'periodcentered': 250,
  27277. 'paragraph': 453,
  27278. 'bullet': 350,
  27279. 'quotesinglbase': 333,
  27280. 'quotedblbase': 444,
  27281. 'quotedblright': 444,
  27282. 'guillemotright': 500,
  27283. 'ellipsis': 1000,
  27284. 'perthousand': 1000,
  27285. 'questiondown': 444,
  27286. 'grave': 333,
  27287. 'acute': 333,
  27288. 'circumflex': 333,
  27289. 'tilde': 333,
  27290. 'macron': 333,
  27291. 'breve': 333,
  27292. 'dotaccent': 333,
  27293. 'dieresis': 333,
  27294. 'ring': 333,
  27295. 'cedilla': 333,
  27296. 'hungarumlaut': 333,
  27297. 'ogonek': 333,
  27298. 'caron': 333,
  27299. 'emdash': 1000,
  27300. 'AE': 889,
  27301. 'ordfeminine': 276,
  27302. 'Lslash': 611,
  27303. 'Oslash': 722,
  27304. 'OE': 889,
  27305. 'ordmasculine': 310,
  27306. 'ae': 667,
  27307. 'dotlessi': 278,
  27308. 'lslash': 278,
  27309. 'oslash': 500,
  27310. 'oe': 722,
  27311. 'germandbls': 500,
  27312. 'Idieresis': 333,
  27313. 'eacute': 444,
  27314. 'abreve': 444,
  27315. 'uhungarumlaut': 500,
  27316. 'ecaron': 444,
  27317. 'Ydieresis': 722,
  27318. 'divide': 564,
  27319. 'Yacute': 722,
  27320. 'Acircumflex': 722,
  27321. 'aacute': 444,
  27322. 'Ucircumflex': 722,
  27323. 'yacute': 500,
  27324. 'scommaaccent': 389,
  27325. 'ecircumflex': 444,
  27326. 'Uring': 722,
  27327. 'Udieresis': 722,
  27328. 'aogonek': 444,
  27329. 'Uacute': 722,
  27330. 'uogonek': 500,
  27331. 'Edieresis': 611,
  27332. 'Dcroat': 722,
  27333. 'commaaccent': 250,
  27334. 'copyright': 760,
  27335. 'Emacron': 611,
  27336. 'ccaron': 444,
  27337. 'aring': 444,
  27338. 'Ncommaaccent': 722,
  27339. 'lacute': 278,
  27340. 'agrave': 444,
  27341. 'Tcommaaccent': 611,
  27342. 'Cacute': 667,
  27343. 'atilde': 444,
  27344. 'Edotaccent': 611,
  27345. 'scaron': 389,
  27346. 'scedilla': 389,
  27347. 'iacute': 278,
  27348. 'lozenge': 471,
  27349. 'Rcaron': 667,
  27350. 'Gcommaaccent': 722,
  27351. 'ucircumflex': 500,
  27352. 'acircumflex': 444,
  27353. 'Amacron': 722,
  27354. 'rcaron': 333,
  27355. 'ccedilla': 444,
  27356. 'Zdotaccent': 611,
  27357. 'Thorn': 556,
  27358. 'Omacron': 722,
  27359. 'Racute': 667,
  27360. 'Sacute': 556,
  27361. 'dcaron': 588,
  27362. 'Umacron': 722,
  27363. 'uring': 500,
  27364. 'threesuperior': 300,
  27365. 'Ograve': 722,
  27366. 'Agrave': 722,
  27367. 'Abreve': 722,
  27368. 'multiply': 564,
  27369. 'uacute': 500,
  27370. 'Tcaron': 611,
  27371. 'partialdiff': 476,
  27372. 'ydieresis': 500,
  27373. 'Nacute': 722,
  27374. 'icircumflex': 278,
  27375. 'Ecircumflex': 611,
  27376. 'adieresis': 444,
  27377. 'edieresis': 444,
  27378. 'cacute': 444,
  27379. 'nacute': 500,
  27380. 'umacron': 500,
  27381. 'Ncaron': 722,
  27382. 'Iacute': 333,
  27383. 'plusminus': 564,
  27384. 'brokenbar': 200,
  27385. 'registered': 760,
  27386. 'Gbreve': 722,
  27387. 'Idotaccent': 333,
  27388. 'summation': 600,
  27389. 'Egrave': 611,
  27390. 'racute': 333,
  27391. 'omacron': 500,
  27392. 'Zacute': 611,
  27393. 'Zcaron': 611,
  27394. 'greaterequal': 549,
  27395. 'Eth': 722,
  27396. 'Ccedilla': 667,
  27397. 'lcommaaccent': 278,
  27398. 'tcaron': 326,
  27399. 'eogonek': 444,
  27400. 'Uogonek': 722,
  27401. 'Aacute': 722,
  27402. 'Adieresis': 722,
  27403. 'egrave': 444,
  27404. 'zacute': 444,
  27405. 'iogonek': 278,
  27406. 'Oacute': 722,
  27407. 'oacute': 500,
  27408. 'amacron': 444,
  27409. 'sacute': 389,
  27410. 'idieresis': 278,
  27411. 'Ocircumflex': 722,
  27412. 'Ugrave': 722,
  27413. 'Delta': 612,
  27414. 'thorn': 500,
  27415. 'twosuperior': 300,
  27416. 'Odieresis': 722,
  27417. 'mu': 500,
  27418. 'igrave': 278,
  27419. 'ohungarumlaut': 500,
  27420. 'Eogonek': 611,
  27421. 'dcroat': 500,
  27422. 'threequarters': 750,
  27423. 'Scedilla': 556,
  27424. 'lcaron': 344,
  27425. 'Kcommaaccent': 722,
  27426. 'Lacute': 611,
  27427. 'trademark': 980,
  27428. 'edotaccent': 444,
  27429. 'Igrave': 333,
  27430. 'Imacron': 333,
  27431. 'Lcaron': 611,
  27432. 'onehalf': 750,
  27433. 'lessequal': 549,
  27434. 'ocircumflex': 500,
  27435. 'ntilde': 500,
  27436. 'Uhungarumlaut': 722,
  27437. 'Eacute': 611,
  27438. 'emacron': 444,
  27439. 'gbreve': 500,
  27440. 'onequarter': 750,
  27441. 'Scaron': 556,
  27442. 'Scommaaccent': 556,
  27443. 'Ohungarumlaut': 722,
  27444. 'degree': 400,
  27445. 'ograve': 500,
  27446. 'Ccaron': 667,
  27447. 'ugrave': 500,
  27448. 'radical': 453,
  27449. 'Dcaron': 722,
  27450. 'rcommaaccent': 333,
  27451. 'Ntilde': 722,
  27452. 'otilde': 500,
  27453. 'Rcommaaccent': 667,
  27454. 'Lcommaaccent': 611,
  27455. 'Atilde': 722,
  27456. 'Aogonek': 722,
  27457. 'Aring': 722,
  27458. 'Otilde': 722,
  27459. 'zdotaccent': 444,
  27460. 'Ecaron': 611,
  27461. 'Iogonek': 333,
  27462. 'kcommaaccent': 500,
  27463. 'minus': 564,
  27464. 'Icircumflex': 333,
  27465. 'ncaron': 500,
  27466. 'tcommaaccent': 278,
  27467. 'logicalnot': 564,
  27468. 'odieresis': 500,
  27469. 'udieresis': 500,
  27470. 'notequal': 549,
  27471. 'gcommaaccent': 500,
  27472. 'eth': 500,
  27473. 'zcaron': 444,
  27474. 'ncommaaccent': 500,
  27475. 'onesuperior': 300,
  27476. 'imacron': 278,
  27477. 'Euro': 500
  27478. },
  27479. 'Times-Bold': {
  27480. 'space': 250,
  27481. 'exclam': 333,
  27482. 'quotedbl': 555,
  27483. 'numbersign': 500,
  27484. 'dollar': 500,
  27485. 'percent': 1000,
  27486. 'ampersand': 833,
  27487. 'quoteright': 333,
  27488. 'parenleft': 333,
  27489. 'parenright': 333,
  27490. 'asterisk': 500,
  27491. 'plus': 570,
  27492. 'comma': 250,
  27493. 'hyphen': 333,
  27494. 'period': 250,
  27495. 'slash': 278,
  27496. 'zero': 500,
  27497. 'one': 500,
  27498. 'two': 500,
  27499. 'three': 500,
  27500. 'four': 500,
  27501. 'five': 500,
  27502. 'six': 500,
  27503. 'seven': 500,
  27504. 'eight': 500,
  27505. 'nine': 500,
  27506. 'colon': 333,
  27507. 'semicolon': 333,
  27508. 'less': 570,
  27509. 'equal': 570,
  27510. 'greater': 570,
  27511. 'question': 500,
  27512. 'at': 930,
  27513. 'A': 722,
  27514. 'B': 667,
  27515. 'C': 722,
  27516. 'D': 722,
  27517. 'E': 667,
  27518. 'F': 611,
  27519. 'G': 778,
  27520. 'H': 778,
  27521. 'I': 389,
  27522. 'J': 500,
  27523. 'K': 778,
  27524. 'L': 667,
  27525. 'M': 944,
  27526. 'N': 722,
  27527. 'O': 778,
  27528. 'P': 611,
  27529. 'Q': 778,
  27530. 'R': 722,
  27531. 'S': 556,
  27532. 'T': 667,
  27533. 'U': 722,
  27534. 'V': 722,
  27535. 'W': 1000,
  27536. 'X': 722,
  27537. 'Y': 722,
  27538. 'Z': 667,
  27539. 'bracketleft': 333,
  27540. 'backslash': 278,
  27541. 'bracketright': 333,
  27542. 'asciicircum': 581,
  27543. 'underscore': 500,
  27544. 'quoteleft': 333,
  27545. 'a': 500,
  27546. 'b': 556,
  27547. 'c': 444,
  27548. 'd': 556,
  27549. 'e': 444,
  27550. 'f': 333,
  27551. 'g': 500,
  27552. 'h': 556,
  27553. 'i': 278,
  27554. 'j': 333,
  27555. 'k': 556,
  27556. 'l': 278,
  27557. 'm': 833,
  27558. 'n': 556,
  27559. 'o': 500,
  27560. 'p': 556,
  27561. 'q': 556,
  27562. 'r': 444,
  27563. 's': 389,
  27564. 't': 333,
  27565. 'u': 556,
  27566. 'v': 500,
  27567. 'w': 722,
  27568. 'x': 500,
  27569. 'y': 500,
  27570. 'z': 444,
  27571. 'braceleft': 394,
  27572. 'bar': 220,
  27573. 'braceright': 394,
  27574. 'asciitilde': 520,
  27575. 'exclamdown': 333,
  27576. 'cent': 500,
  27577. 'sterling': 500,
  27578. 'fraction': 167,
  27579. 'yen': 500,
  27580. 'florin': 500,
  27581. 'section': 500,
  27582. 'currency': 500,
  27583. 'quotesingle': 278,
  27584. 'quotedblleft': 500,
  27585. 'guillemotleft': 500,
  27586. 'guilsinglleft': 333,
  27587. 'guilsinglright': 333,
  27588. 'fi': 556,
  27589. 'fl': 556,
  27590. 'endash': 500,
  27591. 'dagger': 500,
  27592. 'daggerdbl': 500,
  27593. 'periodcentered': 250,
  27594. 'paragraph': 540,
  27595. 'bullet': 350,
  27596. 'quotesinglbase': 333,
  27597. 'quotedblbase': 500,
  27598. 'quotedblright': 500,
  27599. 'guillemotright': 500,
  27600. 'ellipsis': 1000,
  27601. 'perthousand': 1000,
  27602. 'questiondown': 500,
  27603. 'grave': 333,
  27604. 'acute': 333,
  27605. 'circumflex': 333,
  27606. 'tilde': 333,
  27607. 'macron': 333,
  27608. 'breve': 333,
  27609. 'dotaccent': 333,
  27610. 'dieresis': 333,
  27611. 'ring': 333,
  27612. 'cedilla': 333,
  27613. 'hungarumlaut': 333,
  27614. 'ogonek': 333,
  27615. 'caron': 333,
  27616. 'emdash': 1000,
  27617. 'AE': 1000,
  27618. 'ordfeminine': 300,
  27619. 'Lslash': 667,
  27620. 'Oslash': 778,
  27621. 'OE': 1000,
  27622. 'ordmasculine': 330,
  27623. 'ae': 722,
  27624. 'dotlessi': 278,
  27625. 'lslash': 278,
  27626. 'oslash': 500,
  27627. 'oe': 722,
  27628. 'germandbls': 556,
  27629. 'Idieresis': 389,
  27630. 'eacute': 444,
  27631. 'abreve': 500,
  27632. 'uhungarumlaut': 556,
  27633. 'ecaron': 444,
  27634. 'Ydieresis': 722,
  27635. 'divide': 570,
  27636. 'Yacute': 722,
  27637. 'Acircumflex': 722,
  27638. 'aacute': 500,
  27639. 'Ucircumflex': 722,
  27640. 'yacute': 500,
  27641. 'scommaaccent': 389,
  27642. 'ecircumflex': 444,
  27643. 'Uring': 722,
  27644. 'Udieresis': 722,
  27645. 'aogonek': 500,
  27646. 'Uacute': 722,
  27647. 'uogonek': 556,
  27648. 'Edieresis': 667,
  27649. 'Dcroat': 722,
  27650. 'commaaccent': 250,
  27651. 'copyright': 747,
  27652. 'Emacron': 667,
  27653. 'ccaron': 444,
  27654. 'aring': 500,
  27655. 'Ncommaaccent': 722,
  27656. 'lacute': 278,
  27657. 'agrave': 500,
  27658. 'Tcommaaccent': 667,
  27659. 'Cacute': 722,
  27660. 'atilde': 500,
  27661. 'Edotaccent': 667,
  27662. 'scaron': 389,
  27663. 'scedilla': 389,
  27664. 'iacute': 278,
  27665. 'lozenge': 494,
  27666. 'Rcaron': 722,
  27667. 'Gcommaaccent': 778,
  27668. 'ucircumflex': 556,
  27669. 'acircumflex': 500,
  27670. 'Amacron': 722,
  27671. 'rcaron': 444,
  27672. 'ccedilla': 444,
  27673. 'Zdotaccent': 667,
  27674. 'Thorn': 611,
  27675. 'Omacron': 778,
  27676. 'Racute': 722,
  27677. 'Sacute': 556,
  27678. 'dcaron': 672,
  27679. 'Umacron': 722,
  27680. 'uring': 556,
  27681. 'threesuperior': 300,
  27682. 'Ograve': 778,
  27683. 'Agrave': 722,
  27684. 'Abreve': 722,
  27685. 'multiply': 570,
  27686. 'uacute': 556,
  27687. 'Tcaron': 667,
  27688. 'partialdiff': 494,
  27689. 'ydieresis': 500,
  27690. 'Nacute': 722,
  27691. 'icircumflex': 278,
  27692. 'Ecircumflex': 667,
  27693. 'adieresis': 500,
  27694. 'edieresis': 444,
  27695. 'cacute': 444,
  27696. 'nacute': 556,
  27697. 'umacron': 556,
  27698. 'Ncaron': 722,
  27699. 'Iacute': 389,
  27700. 'plusminus': 570,
  27701. 'brokenbar': 220,
  27702. 'registered': 747,
  27703. 'Gbreve': 778,
  27704. 'Idotaccent': 389,
  27705. 'summation': 600,
  27706. 'Egrave': 667,
  27707. 'racute': 444,
  27708. 'omacron': 500,
  27709. 'Zacute': 667,
  27710. 'Zcaron': 667,
  27711. 'greaterequal': 549,
  27712. 'Eth': 722,
  27713. 'Ccedilla': 722,
  27714. 'lcommaaccent': 278,
  27715. 'tcaron': 416,
  27716. 'eogonek': 444,
  27717. 'Uogonek': 722,
  27718. 'Aacute': 722,
  27719. 'Adieresis': 722,
  27720. 'egrave': 444,
  27721. 'zacute': 444,
  27722. 'iogonek': 278,
  27723. 'Oacute': 778,
  27724. 'oacute': 500,
  27725. 'amacron': 500,
  27726. 'sacute': 389,
  27727. 'idieresis': 278,
  27728. 'Ocircumflex': 778,
  27729. 'Ugrave': 722,
  27730. 'Delta': 612,
  27731. 'thorn': 556,
  27732. 'twosuperior': 300,
  27733. 'Odieresis': 778,
  27734. 'mu': 556,
  27735. 'igrave': 278,
  27736. 'ohungarumlaut': 500,
  27737. 'Eogonek': 667,
  27738. 'dcroat': 556,
  27739. 'threequarters': 750,
  27740. 'Scedilla': 556,
  27741. 'lcaron': 394,
  27742. 'Kcommaaccent': 778,
  27743. 'Lacute': 667,
  27744. 'trademark': 1000,
  27745. 'edotaccent': 444,
  27746. 'Igrave': 389,
  27747. 'Imacron': 389,
  27748. 'Lcaron': 667,
  27749. 'onehalf': 750,
  27750. 'lessequal': 549,
  27751. 'ocircumflex': 500,
  27752. 'ntilde': 556,
  27753. 'Uhungarumlaut': 722,
  27754. 'Eacute': 667,
  27755. 'emacron': 444,
  27756. 'gbreve': 500,
  27757. 'onequarter': 750,
  27758. 'Scaron': 556,
  27759. 'Scommaaccent': 556,
  27760. 'Ohungarumlaut': 778,
  27761. 'degree': 400,
  27762. 'ograve': 500,
  27763. 'Ccaron': 722,
  27764. 'ugrave': 556,
  27765. 'radical': 549,
  27766. 'Dcaron': 722,
  27767. 'rcommaaccent': 444,
  27768. 'Ntilde': 722,
  27769. 'otilde': 500,
  27770. 'Rcommaaccent': 722,
  27771. 'Lcommaaccent': 667,
  27772. 'Atilde': 722,
  27773. 'Aogonek': 722,
  27774. 'Aring': 722,
  27775. 'Otilde': 778,
  27776. 'zdotaccent': 444,
  27777. 'Ecaron': 667,
  27778. 'Iogonek': 389,
  27779. 'kcommaaccent': 556,
  27780. 'minus': 570,
  27781. 'Icircumflex': 389,
  27782. 'ncaron': 556,
  27783. 'tcommaaccent': 333,
  27784. 'logicalnot': 570,
  27785. 'odieresis': 500,
  27786. 'udieresis': 556,
  27787. 'notequal': 549,
  27788. 'gcommaaccent': 500,
  27789. 'eth': 500,
  27790. 'zcaron': 444,
  27791. 'ncommaaccent': 556,
  27792. 'onesuperior': 300,
  27793. 'imacron': 278,
  27794. 'Euro': 500
  27795. },
  27796. 'Times-BoldItalic': {
  27797. 'space': 250,
  27798. 'exclam': 389,
  27799. 'quotedbl': 555,
  27800. 'numbersign': 500,
  27801. 'dollar': 500,
  27802. 'percent': 833,
  27803. 'ampersand': 778,
  27804. 'quoteright': 333,
  27805. 'parenleft': 333,
  27806. 'parenright': 333,
  27807. 'asterisk': 500,
  27808. 'plus': 570,
  27809. 'comma': 250,
  27810. 'hyphen': 333,
  27811. 'period': 250,
  27812. 'slash': 278,
  27813. 'zero': 500,
  27814. 'one': 500,
  27815. 'two': 500,
  27816. 'three': 500,
  27817. 'four': 500,
  27818. 'five': 500,
  27819. 'six': 500,
  27820. 'seven': 500,
  27821. 'eight': 500,
  27822. 'nine': 500,
  27823. 'colon': 333,
  27824. 'semicolon': 333,
  27825. 'less': 570,
  27826. 'equal': 570,
  27827. 'greater': 570,
  27828. 'question': 500,
  27829. 'at': 832,
  27830. 'A': 667,
  27831. 'B': 667,
  27832. 'C': 667,
  27833. 'D': 722,
  27834. 'E': 667,
  27835. 'F': 667,
  27836. 'G': 722,
  27837. 'H': 778,
  27838. 'I': 389,
  27839. 'J': 500,
  27840. 'K': 667,
  27841. 'L': 611,
  27842. 'M': 889,
  27843. 'N': 722,
  27844. 'O': 722,
  27845. 'P': 611,
  27846. 'Q': 722,
  27847. 'R': 667,
  27848. 'S': 556,
  27849. 'T': 611,
  27850. 'U': 722,
  27851. 'V': 667,
  27852. 'W': 889,
  27853. 'X': 667,
  27854. 'Y': 611,
  27855. 'Z': 611,
  27856. 'bracketleft': 333,
  27857. 'backslash': 278,
  27858. 'bracketright': 333,
  27859. 'asciicircum': 570,
  27860. 'underscore': 500,
  27861. 'quoteleft': 333,
  27862. 'a': 500,
  27863. 'b': 500,
  27864. 'c': 444,
  27865. 'd': 500,
  27866. 'e': 444,
  27867. 'f': 333,
  27868. 'g': 500,
  27869. 'h': 556,
  27870. 'i': 278,
  27871. 'j': 278,
  27872. 'k': 500,
  27873. 'l': 278,
  27874. 'm': 778,
  27875. 'n': 556,
  27876. 'o': 500,
  27877. 'p': 500,
  27878. 'q': 500,
  27879. 'r': 389,
  27880. 's': 389,
  27881. 't': 278,
  27882. 'u': 556,
  27883. 'v': 444,
  27884. 'w': 667,
  27885. 'x': 500,
  27886. 'y': 444,
  27887. 'z': 389,
  27888. 'braceleft': 348,
  27889. 'bar': 220,
  27890. 'braceright': 348,
  27891. 'asciitilde': 570,
  27892. 'exclamdown': 389,
  27893. 'cent': 500,
  27894. 'sterling': 500,
  27895. 'fraction': 167,
  27896. 'yen': 500,
  27897. 'florin': 500,
  27898. 'section': 500,
  27899. 'currency': 500,
  27900. 'quotesingle': 278,
  27901. 'quotedblleft': 500,
  27902. 'guillemotleft': 500,
  27903. 'guilsinglleft': 333,
  27904. 'guilsinglright': 333,
  27905. 'fi': 556,
  27906. 'fl': 556,
  27907. 'endash': 500,
  27908. 'dagger': 500,
  27909. 'daggerdbl': 500,
  27910. 'periodcentered': 250,
  27911. 'paragraph': 500,
  27912. 'bullet': 350,
  27913. 'quotesinglbase': 333,
  27914. 'quotedblbase': 500,
  27915. 'quotedblright': 500,
  27916. 'guillemotright': 500,
  27917. 'ellipsis': 1000,
  27918. 'perthousand': 1000,
  27919. 'questiondown': 500,
  27920. 'grave': 333,
  27921. 'acute': 333,
  27922. 'circumflex': 333,
  27923. 'tilde': 333,
  27924. 'macron': 333,
  27925. 'breve': 333,
  27926. 'dotaccent': 333,
  27927. 'dieresis': 333,
  27928. 'ring': 333,
  27929. 'cedilla': 333,
  27930. 'hungarumlaut': 333,
  27931. 'ogonek': 333,
  27932. 'caron': 333,
  27933. 'emdash': 1000,
  27934. 'AE': 944,
  27935. 'ordfeminine': 266,
  27936. 'Lslash': 611,
  27937. 'Oslash': 722,
  27938. 'OE': 944,
  27939. 'ordmasculine': 300,
  27940. 'ae': 722,
  27941. 'dotlessi': 278,
  27942. 'lslash': 278,
  27943. 'oslash': 500,
  27944. 'oe': 722,
  27945. 'germandbls': 500,
  27946. 'Idieresis': 389,
  27947. 'eacute': 444,
  27948. 'abreve': 500,
  27949. 'uhungarumlaut': 556,
  27950. 'ecaron': 444,
  27951. 'Ydieresis': 611,
  27952. 'divide': 570,
  27953. 'Yacute': 611,
  27954. 'Acircumflex': 667,
  27955. 'aacute': 500,
  27956. 'Ucircumflex': 722,
  27957. 'yacute': 444,
  27958. 'scommaaccent': 389,
  27959. 'ecircumflex': 444,
  27960. 'Uring': 722,
  27961. 'Udieresis': 722,
  27962. 'aogonek': 500,
  27963. 'Uacute': 722,
  27964. 'uogonek': 556,
  27965. 'Edieresis': 667,
  27966. 'Dcroat': 722,
  27967. 'commaaccent': 250,
  27968. 'copyright': 747,
  27969. 'Emacron': 667,
  27970. 'ccaron': 444,
  27971. 'aring': 500,
  27972. 'Ncommaaccent': 722,
  27973. 'lacute': 278,
  27974. 'agrave': 500,
  27975. 'Tcommaaccent': 611,
  27976. 'Cacute': 667,
  27977. 'atilde': 500,
  27978. 'Edotaccent': 667,
  27979. 'scaron': 389,
  27980. 'scedilla': 389,
  27981. 'iacute': 278,
  27982. 'lozenge': 494,
  27983. 'Rcaron': 667,
  27984. 'Gcommaaccent': 722,
  27985. 'ucircumflex': 556,
  27986. 'acircumflex': 500,
  27987. 'Amacron': 667,
  27988. 'rcaron': 389,
  27989. 'ccedilla': 444,
  27990. 'Zdotaccent': 611,
  27991. 'Thorn': 611,
  27992. 'Omacron': 722,
  27993. 'Racute': 667,
  27994. 'Sacute': 556,
  27995. 'dcaron': 608,
  27996. 'Umacron': 722,
  27997. 'uring': 556,
  27998. 'threesuperior': 300,
  27999. 'Ograve': 722,
  28000. 'Agrave': 667,
  28001. 'Abreve': 667,
  28002. 'multiply': 570,
  28003. 'uacute': 556,
  28004. 'Tcaron': 611,
  28005. 'partialdiff': 494,
  28006. 'ydieresis': 444,
  28007. 'Nacute': 722,
  28008. 'icircumflex': 278,
  28009. 'Ecircumflex': 667,
  28010. 'adieresis': 500,
  28011. 'edieresis': 444,
  28012. 'cacute': 444,
  28013. 'nacute': 556,
  28014. 'umacron': 556,
  28015. 'Ncaron': 722,
  28016. 'Iacute': 389,
  28017. 'plusminus': 570,
  28018. 'brokenbar': 220,
  28019. 'registered': 747,
  28020. 'Gbreve': 722,
  28021. 'Idotaccent': 389,
  28022. 'summation': 600,
  28023. 'Egrave': 667,
  28024. 'racute': 389,
  28025. 'omacron': 500,
  28026. 'Zacute': 611,
  28027. 'Zcaron': 611,
  28028. 'greaterequal': 549,
  28029. 'Eth': 722,
  28030. 'Ccedilla': 667,
  28031. 'lcommaaccent': 278,
  28032. 'tcaron': 366,
  28033. 'eogonek': 444,
  28034. 'Uogonek': 722,
  28035. 'Aacute': 667,
  28036. 'Adieresis': 667,
  28037. 'egrave': 444,
  28038. 'zacute': 389,
  28039. 'iogonek': 278,
  28040. 'Oacute': 722,
  28041. 'oacute': 500,
  28042. 'amacron': 500,
  28043. 'sacute': 389,
  28044. 'idieresis': 278,
  28045. 'Ocircumflex': 722,
  28046. 'Ugrave': 722,
  28047. 'Delta': 612,
  28048. 'thorn': 500,
  28049. 'twosuperior': 300,
  28050. 'Odieresis': 722,
  28051. 'mu': 576,
  28052. 'igrave': 278,
  28053. 'ohungarumlaut': 500,
  28054. 'Eogonek': 667,
  28055. 'dcroat': 500,
  28056. 'threequarters': 750,
  28057. 'Scedilla': 556,
  28058. 'lcaron': 382,
  28059. 'Kcommaaccent': 667,
  28060. 'Lacute': 611,
  28061. 'trademark': 1000,
  28062. 'edotaccent': 444,
  28063. 'Igrave': 389,
  28064. 'Imacron': 389,
  28065. 'Lcaron': 611,
  28066. 'onehalf': 750,
  28067. 'lessequal': 549,
  28068. 'ocircumflex': 500,
  28069. 'ntilde': 556,
  28070. 'Uhungarumlaut': 722,
  28071. 'Eacute': 667,
  28072. 'emacron': 444,
  28073. 'gbreve': 500,
  28074. 'onequarter': 750,
  28075. 'Scaron': 556,
  28076. 'Scommaaccent': 556,
  28077. 'Ohungarumlaut': 722,
  28078. 'degree': 400,
  28079. 'ograve': 500,
  28080. 'Ccaron': 667,
  28081. 'ugrave': 556,
  28082. 'radical': 549,
  28083. 'Dcaron': 722,
  28084. 'rcommaaccent': 389,
  28085. 'Ntilde': 722,
  28086. 'otilde': 500,
  28087. 'Rcommaaccent': 667,
  28088. 'Lcommaaccent': 611,
  28089. 'Atilde': 667,
  28090. 'Aogonek': 667,
  28091. 'Aring': 667,
  28092. 'Otilde': 722,
  28093. 'zdotaccent': 389,
  28094. 'Ecaron': 667,
  28095. 'Iogonek': 389,
  28096. 'kcommaaccent': 500,
  28097. 'minus': 606,
  28098. 'Icircumflex': 389,
  28099. 'ncaron': 556,
  28100. 'tcommaaccent': 278,
  28101. 'logicalnot': 606,
  28102. 'odieresis': 500,
  28103. 'udieresis': 556,
  28104. 'notequal': 549,
  28105. 'gcommaaccent': 500,
  28106. 'eth': 500,
  28107. 'zcaron': 389,
  28108. 'ncommaaccent': 556,
  28109. 'onesuperior': 300,
  28110. 'imacron': 278,
  28111. 'Euro': 500
  28112. },
  28113. 'Times-Italic': {
  28114. 'space': 250,
  28115. 'exclam': 333,
  28116. 'quotedbl': 420,
  28117. 'numbersign': 500,
  28118. 'dollar': 500,
  28119. 'percent': 833,
  28120. 'ampersand': 778,
  28121. 'quoteright': 333,
  28122. 'parenleft': 333,
  28123. 'parenright': 333,
  28124. 'asterisk': 500,
  28125. 'plus': 675,
  28126. 'comma': 250,
  28127. 'hyphen': 333,
  28128. 'period': 250,
  28129. 'slash': 278,
  28130. 'zero': 500,
  28131. 'one': 500,
  28132. 'two': 500,
  28133. 'three': 500,
  28134. 'four': 500,
  28135. 'five': 500,
  28136. 'six': 500,
  28137. 'seven': 500,
  28138. 'eight': 500,
  28139. 'nine': 500,
  28140. 'colon': 333,
  28141. 'semicolon': 333,
  28142. 'less': 675,
  28143. 'equal': 675,
  28144. 'greater': 675,
  28145. 'question': 500,
  28146. 'at': 920,
  28147. 'A': 611,
  28148. 'B': 611,
  28149. 'C': 667,
  28150. 'D': 722,
  28151. 'E': 611,
  28152. 'F': 611,
  28153. 'G': 722,
  28154. 'H': 722,
  28155. 'I': 333,
  28156. 'J': 444,
  28157. 'K': 667,
  28158. 'L': 556,
  28159. 'M': 833,
  28160. 'N': 667,
  28161. 'O': 722,
  28162. 'P': 611,
  28163. 'Q': 722,
  28164. 'R': 611,
  28165. 'S': 500,
  28166. 'T': 556,
  28167. 'U': 722,
  28168. 'V': 611,
  28169. 'W': 833,
  28170. 'X': 611,
  28171. 'Y': 556,
  28172. 'Z': 556,
  28173. 'bracketleft': 389,
  28174. 'backslash': 278,
  28175. 'bracketright': 389,
  28176. 'asciicircum': 422,
  28177. 'underscore': 500,
  28178. 'quoteleft': 333,
  28179. 'a': 500,
  28180. 'b': 500,
  28181. 'c': 444,
  28182. 'd': 500,
  28183. 'e': 444,
  28184. 'f': 278,
  28185. 'g': 500,
  28186. 'h': 500,
  28187. 'i': 278,
  28188. 'j': 278,
  28189. 'k': 444,
  28190. 'l': 278,
  28191. 'm': 722,
  28192. 'n': 500,
  28193. 'o': 500,
  28194. 'p': 500,
  28195. 'q': 500,
  28196. 'r': 389,
  28197. 's': 389,
  28198. 't': 278,
  28199. 'u': 500,
  28200. 'v': 444,
  28201. 'w': 667,
  28202. 'x': 444,
  28203. 'y': 444,
  28204. 'z': 389,
  28205. 'braceleft': 400,
  28206. 'bar': 275,
  28207. 'braceright': 400,
  28208. 'asciitilde': 541,
  28209. 'exclamdown': 389,
  28210. 'cent': 500,
  28211. 'sterling': 500,
  28212. 'fraction': 167,
  28213. 'yen': 500,
  28214. 'florin': 500,
  28215. 'section': 500,
  28216. 'currency': 500,
  28217. 'quotesingle': 214,
  28218. 'quotedblleft': 556,
  28219. 'guillemotleft': 500,
  28220. 'guilsinglleft': 333,
  28221. 'guilsinglright': 333,
  28222. 'fi': 500,
  28223. 'fl': 500,
  28224. 'endash': 500,
  28225. 'dagger': 500,
  28226. 'daggerdbl': 500,
  28227. 'periodcentered': 250,
  28228. 'paragraph': 523,
  28229. 'bullet': 350,
  28230. 'quotesinglbase': 333,
  28231. 'quotedblbase': 556,
  28232. 'quotedblright': 556,
  28233. 'guillemotright': 500,
  28234. 'ellipsis': 889,
  28235. 'perthousand': 1000,
  28236. 'questiondown': 500,
  28237. 'grave': 333,
  28238. 'acute': 333,
  28239. 'circumflex': 333,
  28240. 'tilde': 333,
  28241. 'macron': 333,
  28242. 'breve': 333,
  28243. 'dotaccent': 333,
  28244. 'dieresis': 333,
  28245. 'ring': 333,
  28246. 'cedilla': 333,
  28247. 'hungarumlaut': 333,
  28248. 'ogonek': 333,
  28249. 'caron': 333,
  28250. 'emdash': 889,
  28251. 'AE': 889,
  28252. 'ordfeminine': 276,
  28253. 'Lslash': 556,
  28254. 'Oslash': 722,
  28255. 'OE': 944,
  28256. 'ordmasculine': 310,
  28257. 'ae': 667,
  28258. 'dotlessi': 278,
  28259. 'lslash': 278,
  28260. 'oslash': 500,
  28261. 'oe': 667,
  28262. 'germandbls': 500,
  28263. 'Idieresis': 333,
  28264. 'eacute': 444,
  28265. 'abreve': 500,
  28266. 'uhungarumlaut': 500,
  28267. 'ecaron': 444,
  28268. 'Ydieresis': 556,
  28269. 'divide': 675,
  28270. 'Yacute': 556,
  28271. 'Acircumflex': 611,
  28272. 'aacute': 500,
  28273. 'Ucircumflex': 722,
  28274. 'yacute': 444,
  28275. 'scommaaccent': 389,
  28276. 'ecircumflex': 444,
  28277. 'Uring': 722,
  28278. 'Udieresis': 722,
  28279. 'aogonek': 500,
  28280. 'Uacute': 722,
  28281. 'uogonek': 500,
  28282. 'Edieresis': 611,
  28283. 'Dcroat': 722,
  28284. 'commaaccent': 250,
  28285. 'copyright': 760,
  28286. 'Emacron': 611,
  28287. 'ccaron': 444,
  28288. 'aring': 500,
  28289. 'Ncommaaccent': 667,
  28290. 'lacute': 278,
  28291. 'agrave': 500,
  28292. 'Tcommaaccent': 556,
  28293. 'Cacute': 667,
  28294. 'atilde': 500,
  28295. 'Edotaccent': 611,
  28296. 'scaron': 389,
  28297. 'scedilla': 389,
  28298. 'iacute': 278,
  28299. 'lozenge': 471,
  28300. 'Rcaron': 611,
  28301. 'Gcommaaccent': 722,
  28302. 'ucircumflex': 500,
  28303. 'acircumflex': 500,
  28304. 'Amacron': 611,
  28305. 'rcaron': 389,
  28306. 'ccedilla': 444,
  28307. 'Zdotaccent': 556,
  28308. 'Thorn': 611,
  28309. 'Omacron': 722,
  28310. 'Racute': 611,
  28311. 'Sacute': 500,
  28312. 'dcaron': 544,
  28313. 'Umacron': 722,
  28314. 'uring': 500,
  28315. 'threesuperior': 300,
  28316. 'Ograve': 722,
  28317. 'Agrave': 611,
  28318. 'Abreve': 611,
  28319. 'multiply': 675,
  28320. 'uacute': 500,
  28321. 'Tcaron': 556,
  28322. 'partialdiff': 476,
  28323. 'ydieresis': 444,
  28324. 'Nacute': 667,
  28325. 'icircumflex': 278,
  28326. 'Ecircumflex': 611,
  28327. 'adieresis': 500,
  28328. 'edieresis': 444,
  28329. 'cacute': 444,
  28330. 'nacute': 500,
  28331. 'umacron': 500,
  28332. 'Ncaron': 667,
  28333. 'Iacute': 333,
  28334. 'plusminus': 675,
  28335. 'brokenbar': 275,
  28336. 'registered': 760,
  28337. 'Gbreve': 722,
  28338. 'Idotaccent': 333,
  28339. 'summation': 600,
  28340. 'Egrave': 611,
  28341. 'racute': 389,
  28342. 'omacron': 500,
  28343. 'Zacute': 556,
  28344. 'Zcaron': 556,
  28345. 'greaterequal': 549,
  28346. 'Eth': 722,
  28347. 'Ccedilla': 667,
  28348. 'lcommaaccent': 278,
  28349. 'tcaron': 300,
  28350. 'eogonek': 444,
  28351. 'Uogonek': 722,
  28352. 'Aacute': 611,
  28353. 'Adieresis': 611,
  28354. 'egrave': 444,
  28355. 'zacute': 389,
  28356. 'iogonek': 278,
  28357. 'Oacute': 722,
  28358. 'oacute': 500,
  28359. 'amacron': 500,
  28360. 'sacute': 389,
  28361. 'idieresis': 278,
  28362. 'Ocircumflex': 722,
  28363. 'Ugrave': 722,
  28364. 'Delta': 612,
  28365. 'thorn': 500,
  28366. 'twosuperior': 300,
  28367. 'Odieresis': 722,
  28368. 'mu': 500,
  28369. 'igrave': 278,
  28370. 'ohungarumlaut': 500,
  28371. 'Eogonek': 611,
  28372. 'dcroat': 500,
  28373. 'threequarters': 750,
  28374. 'Scedilla': 500,
  28375. 'lcaron': 300,
  28376. 'Kcommaaccent': 667,
  28377. 'Lacute': 556,
  28378. 'trademark': 980,
  28379. 'edotaccent': 444,
  28380. 'Igrave': 333,
  28381. 'Imacron': 333,
  28382. 'Lcaron': 611,
  28383. 'onehalf': 750,
  28384. 'lessequal': 549,
  28385. 'ocircumflex': 500,
  28386. 'ntilde': 500,
  28387. 'Uhungarumlaut': 722,
  28388. 'Eacute': 611,
  28389. 'emacron': 444,
  28390. 'gbreve': 500,
  28391. 'onequarter': 750,
  28392. 'Scaron': 500,
  28393. 'Scommaaccent': 500,
  28394. 'Ohungarumlaut': 722,
  28395. 'degree': 400,
  28396. 'ograve': 500,
  28397. 'Ccaron': 667,
  28398. 'ugrave': 500,
  28399. 'radical': 453,
  28400. 'Dcaron': 722,
  28401. 'rcommaaccent': 389,
  28402. 'Ntilde': 667,
  28403. 'otilde': 500,
  28404. 'Rcommaaccent': 611,
  28405. 'Lcommaaccent': 556,
  28406. 'Atilde': 611,
  28407. 'Aogonek': 611,
  28408. 'Aring': 611,
  28409. 'Otilde': 722,
  28410. 'zdotaccent': 389,
  28411. 'Ecaron': 611,
  28412. 'Iogonek': 333,
  28413. 'kcommaaccent': 444,
  28414. 'minus': 675,
  28415. 'Icircumflex': 333,
  28416. 'ncaron': 500,
  28417. 'tcommaaccent': 278,
  28418. 'logicalnot': 675,
  28419. 'odieresis': 500,
  28420. 'udieresis': 500,
  28421. 'notequal': 549,
  28422. 'gcommaaccent': 500,
  28423. 'eth': 500,
  28424. 'zcaron': 389,
  28425. 'ncommaaccent': 500,
  28426. 'onesuperior': 300,
  28427. 'imacron': 278,
  28428. 'Euro': 500
  28429. },
  28430. 'ZapfDingbats': {
  28431. 'space': 278,
  28432. 'a1': 974,
  28433. 'a2': 961,
  28434. 'a202': 974,
  28435. 'a3': 980,
  28436. 'a4': 719,
  28437. 'a5': 789,
  28438. 'a119': 790,
  28439. 'a118': 791,
  28440. 'a117': 690,
  28441. 'a11': 960,
  28442. 'a12': 939,
  28443. 'a13': 549,
  28444. 'a14': 855,
  28445. 'a15': 911,
  28446. 'a16': 933,
  28447. 'a105': 911,
  28448. 'a17': 945,
  28449. 'a18': 974,
  28450. 'a19': 755,
  28451. 'a20': 846,
  28452. 'a21': 762,
  28453. 'a22': 761,
  28454. 'a23': 571,
  28455. 'a24': 677,
  28456. 'a25': 763,
  28457. 'a26': 760,
  28458. 'a27': 759,
  28459. 'a28': 754,
  28460. 'a6': 494,
  28461. 'a7': 552,
  28462. 'a8': 537,
  28463. 'a9': 577,
  28464. 'a10': 692,
  28465. 'a29': 786,
  28466. 'a30': 788,
  28467. 'a31': 788,
  28468. 'a32': 790,
  28469. 'a33': 793,
  28470. 'a34': 794,
  28471. 'a35': 816,
  28472. 'a36': 823,
  28473. 'a37': 789,
  28474. 'a38': 841,
  28475. 'a39': 823,
  28476. 'a40': 833,
  28477. 'a41': 816,
  28478. 'a42': 831,
  28479. 'a43': 923,
  28480. 'a44': 744,
  28481. 'a45': 723,
  28482. 'a46': 749,
  28483. 'a47': 790,
  28484. 'a48': 792,
  28485. 'a49': 695,
  28486. 'a50': 776,
  28487. 'a51': 768,
  28488. 'a52': 792,
  28489. 'a53': 759,
  28490. 'a54': 707,
  28491. 'a55': 708,
  28492. 'a56': 682,
  28493. 'a57': 701,
  28494. 'a58': 826,
  28495. 'a59': 815,
  28496. 'a60': 789,
  28497. 'a61': 789,
  28498. 'a62': 707,
  28499. 'a63': 687,
  28500. 'a64': 696,
  28501. 'a65': 689,
  28502. 'a66': 786,
  28503. 'a67': 787,
  28504. 'a68': 713,
  28505. 'a69': 791,
  28506. 'a70': 785,
  28507. 'a71': 791,
  28508. 'a72': 873,
  28509. 'a73': 761,
  28510. 'a74': 762,
  28511. 'a203': 762,
  28512. 'a75': 759,
  28513. 'a204': 759,
  28514. 'a76': 892,
  28515. 'a77': 892,
  28516. 'a78': 788,
  28517. 'a79': 784,
  28518. 'a81': 438,
  28519. 'a82': 138,
  28520. 'a83': 277,
  28521. 'a84': 415,
  28522. 'a97': 392,
  28523. 'a98': 392,
  28524. 'a99': 668,
  28525. 'a100': 668,
  28526. 'a89': 390,
  28527. 'a90': 390,
  28528. 'a93': 317,
  28529. 'a94': 317,
  28530. 'a91': 276,
  28531. 'a92': 276,
  28532. 'a205': 509,
  28533. 'a85': 509,
  28534. 'a206': 410,
  28535. 'a86': 410,
  28536. 'a87': 234,
  28537. 'a88': 234,
  28538. 'a95': 334,
  28539. 'a96': 334,
  28540. 'a101': 732,
  28541. 'a102': 544,
  28542. 'a103': 544,
  28543. 'a104': 910,
  28544. 'a106': 667,
  28545. 'a107': 760,
  28546. 'a108': 760,
  28547. 'a112': 776,
  28548. 'a111': 595,
  28549. 'a110': 694,
  28550. 'a109': 626,
  28551. 'a120': 788,
  28552. 'a121': 788,
  28553. 'a122': 788,
  28554. 'a123': 788,
  28555. 'a124': 788,
  28556. 'a125': 788,
  28557. 'a126': 788,
  28558. 'a127': 788,
  28559. 'a128': 788,
  28560. 'a129': 788,
  28561. 'a130': 788,
  28562. 'a131': 788,
  28563. 'a132': 788,
  28564. 'a133': 788,
  28565. 'a134': 788,
  28566. 'a135': 788,
  28567. 'a136': 788,
  28568. 'a137': 788,
  28569. 'a138': 788,
  28570. 'a139': 788,
  28571. 'a140': 788,
  28572. 'a141': 788,
  28573. 'a142': 788,
  28574. 'a143': 788,
  28575. 'a144': 788,
  28576. 'a145': 788,
  28577. 'a146': 788,
  28578. 'a147': 788,
  28579. 'a148': 788,
  28580. 'a149': 788,
  28581. 'a150': 788,
  28582. 'a151': 788,
  28583. 'a152': 788,
  28584. 'a153': 788,
  28585. 'a154': 788,
  28586. 'a155': 788,
  28587. 'a156': 788,
  28588. 'a157': 788,
  28589. 'a158': 788,
  28590. 'a159': 788,
  28591. 'a160': 894,
  28592. 'a161': 838,
  28593. 'a163': 1016,
  28594. 'a164': 458,
  28595. 'a196': 748,
  28596. 'a165': 924,
  28597. 'a192': 748,
  28598. 'a166': 918,
  28599. 'a167': 927,
  28600. 'a168': 928,
  28601. 'a169': 928,
  28602. 'a170': 834,
  28603. 'a171': 873,
  28604. 'a172': 828,
  28605. 'a173': 924,
  28606. 'a162': 924,
  28607. 'a174': 917,
  28608. 'a175': 930,
  28609. 'a176': 931,
  28610. 'a177': 463,
  28611. 'a178': 883,
  28612. 'a179': 836,
  28613. 'a193': 836,
  28614. 'a180': 867,
  28615. 'a199': 867,
  28616. 'a181': 696,
  28617. 'a200': 696,
  28618. 'a182': 874,
  28619. 'a201': 874,
  28620. 'a183': 760,
  28621. 'a184': 946,
  28622. 'a197': 771,
  28623. 'a185': 865,
  28624. 'a194': 771,
  28625. 'a198': 888,
  28626. 'a186': 967,
  28627. 'a195': 888,
  28628. 'a187': 831,
  28629. 'a188': 873,
  28630. 'a189': 927,
  28631. 'a190': 970,
  28632. 'a191': 918
  28633. }
  28634. };
  28635. var EOF = {};
  28636. function isEOF(v) {
  28637. return (v === EOF);
  28638. }
  28639. var MAX_LENGTH_TO_CACHE = 1000;
  28640. var Parser = (function ParserClosure() {
  28641. function Parser(lexer, allowStreams, xref) {
  28642. this.lexer = lexer;
  28643. this.allowStreams = allowStreams;
  28644. this.xref = xref;
  28645. this.imageCache = {};
  28646. this.refill();
  28647. }
  28648. Parser.prototype = {
  28649. refill: function Parser_refill() {
  28650. this.buf1 = this.lexer.getObj();
  28651. this.buf2 = this.lexer.getObj();
  28652. },
  28653. shift: function Parser_shift() {
  28654. if (isCmd(this.buf2, 'ID')) {
  28655. this.buf1 = this.buf2;
  28656. this.buf2 = null;
  28657. } else {
  28658. this.buf1 = this.buf2;
  28659. this.buf2 = this.lexer.getObj();
  28660. }
  28661. },
  28662. getObj: function Parser_getObj(cipherTransform) {
  28663. var buf1 = this.buf1;
  28664. this.shift();
  28665. if (buf1 instanceof Cmd) {
  28666. switch (buf1.cmd) {
  28667. case 'BI': // inline image
  28668. return this.makeInlineImage(cipherTransform);
  28669. case '[': // array
  28670. var array = [];
  28671. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28672. array.push(this.getObj(cipherTransform));
  28673. }
  28674. if (isEOF(this.buf1)) {
  28675. error('End of file inside array');
  28676. }
  28677. this.shift();
  28678. return array;
  28679. case '<<': // dictionary or stream
  28680. var dict = new Dict(this.xref);
  28681. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28682. if (!isName(this.buf1)) {
  28683. info('Malformed dictionary: key must be a name object');
  28684. this.shift();
  28685. continue;
  28686. }
  28687. var key = this.buf1.name;
  28688. this.shift();
  28689. if (isEOF(this.buf1)) {
  28690. break;
  28691. }
  28692. dict.set(key, this.getObj(cipherTransform));
  28693. }
  28694. if (isEOF(this.buf1)) {
  28695. error('End of file inside dictionary');
  28696. }
  28697. // Stream objects are not allowed inside content streams or
  28698. // object streams.
  28699. if (isCmd(this.buf2, 'stream')) {
  28700. return (this.allowStreams ?
  28701. this.makeStream(dict, cipherTransform) : dict);
  28702. }
  28703. this.shift();
  28704. return dict;
  28705. default: // simple object
  28706. return buf1;
  28707. }
  28708. }
  28709. if (isInt(buf1)) { // indirect reference or integer
  28710. var num = buf1;
  28711. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28712. var ref = new Ref(num, this.buf1);
  28713. this.shift();
  28714. this.shift();
  28715. return ref;
  28716. }
  28717. return num;
  28718. }
  28719. if (isString(buf1)) { // string
  28720. var str = buf1;
  28721. if (cipherTransform) {
  28722. str = cipherTransform.decryptString(str);
  28723. }
  28724. return str;
  28725. }
  28726. // simple object
  28727. return buf1;
  28728. },
  28729. /**
  28730. * Find the end of the stream by searching for the /EI\s/.
  28731. * @returns {number} The inline stream length.
  28732. */
  28733. findDefaultInlineStreamEnd:
  28734. function Parser_findDefaultInlineStreamEnd(stream) {
  28735. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28736. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28737. while ((ch = stream.getByte()) !== -1) {
  28738. if (state === 0) {
  28739. state = (ch === E) ? 1 : 0;
  28740. } else if (state === 1) {
  28741. state = (ch === I) ? 2 : 0;
  28742. } else {
  28743. assert(state === 2);
  28744. if (ch === SPACE || ch === LF || ch === CR) {
  28745. // Let's check the next five bytes are ASCII... just be sure.
  28746. n = 5;
  28747. followingBytes = stream.peekBytes(n);
  28748. for (i = 0; i < n; i++) {
  28749. ch = followingBytes[i];
  28750. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28751. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28752. // it's binary stuff. Resetting the state.
  28753. state = 0;
  28754. break;
  28755. }
  28756. }
  28757. if (state === 2) {
  28758. break; // Finished!
  28759. }
  28760. } else {
  28761. state = 0;
  28762. }
  28763. }
  28764. }
  28765. return ((stream.pos - 4) - startPos);
  28766. },
  28767. /**
  28768. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28769. * @returns {number} The inline stream length.
  28770. */
  28771. findDCTDecodeInlineStreamEnd:
  28772. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28773. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28774. while ((b = stream.getByte()) !== -1) {
  28775. if (b !== 0xFF) { // Not a valid marker.
  28776. continue;
  28777. }
  28778. switch (stream.getByte()) {
  28779. case 0x00: // Byte stuffing.
  28780. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28781. break;
  28782. case 0xFF: // Fill byte.
  28783. // Avoid skipping a valid marker, resetting the stream position.
  28784. stream.skip(-1);
  28785. break;
  28786. case 0xD9: // EOI
  28787. foundEOI = true;
  28788. break;
  28789. case 0xC0: // SOF0
  28790. case 0xC1: // SOF1
  28791. case 0xC2: // SOF2
  28792. case 0xC3: // SOF3
  28793. case 0xC5: // SOF5
  28794. case 0xC6: // SOF6
  28795. case 0xC7: // SOF7
  28796. case 0xC9: // SOF9
  28797. case 0xCA: // SOF10
  28798. case 0xCB: // SOF11
  28799. case 0xCD: // SOF13
  28800. case 0xCE: // SOF14
  28801. case 0xCF: // SOF15
  28802. case 0xC4: // DHT
  28803. case 0xCC: // DAC
  28804. case 0xDA: // SOS
  28805. case 0xDB: // DQT
  28806. case 0xDC: // DNL
  28807. case 0xDD: // DRI
  28808. case 0xDE: // DHP
  28809. case 0xDF: // EXP
  28810. case 0xE0: // APP0
  28811. case 0xE1: // APP1
  28812. case 0xE2: // APP2
  28813. case 0xE3: // APP3
  28814. case 0xE4: // APP4
  28815. case 0xE5: // APP5
  28816. case 0xE6: // APP6
  28817. case 0xE7: // APP7
  28818. case 0xE8: // APP8
  28819. case 0xE9: // APP9
  28820. case 0xEA: // APP10
  28821. case 0xEB: // APP11
  28822. case 0xEC: // APP12
  28823. case 0xED: // APP13
  28824. case 0xEE: // APP14
  28825. case 0xEF: // APP15
  28826. case 0xFE: // COM
  28827. // The marker should be followed by the length of the segment.
  28828. markerLength = stream.getUint16();
  28829. if (markerLength > 2) {
  28830. // |markerLength| contains the byte length of the marker segment,
  28831. // including its own length (2 bytes) and excluding the marker.
  28832. stream.skip(markerLength - 2); // Jump to the next marker.
  28833. } else {
  28834. // The marker length is invalid, resetting the stream position.
  28835. stream.skip(-2);
  28836. }
  28837. break;
  28838. }
  28839. if (foundEOI) {
  28840. break;
  28841. }
  28842. }
  28843. length = stream.pos - startPos;
  28844. if (b === -1) {
  28845. warn('Inline DCTDecode image stream: ' +
  28846. 'EOI marker not found, searching for /EI/ instead.');
  28847. stream.skip(-length); // Reset the stream position.
  28848. return this.findDefaultInlineStreamEnd(stream);
  28849. }
  28850. this.inlineStreamSkipEI(stream);
  28851. return length;
  28852. },
  28853. /**
  28854. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28855. * @returns {number} The inline stream length.
  28856. */
  28857. findASCII85DecodeInlineStreamEnd:
  28858. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28859. var TILDE = 0x7E, GT = 0x3E;
  28860. var startPos = stream.pos, ch, length;
  28861. while ((ch = stream.getByte()) !== -1) {
  28862. if (ch === TILDE && stream.peekByte() === GT) {
  28863. stream.skip();
  28864. break;
  28865. }
  28866. }
  28867. length = stream.pos - startPos;
  28868. if (ch === -1) {
  28869. warn('Inline ASCII85Decode image stream: ' +
  28870. 'EOD marker not found, searching for /EI/ instead.');
  28871. stream.skip(-length); // Reset the stream position.
  28872. return this.findDefaultInlineStreamEnd(stream);
  28873. }
  28874. this.inlineStreamSkipEI(stream);
  28875. return length;
  28876. },
  28877. /**
  28878. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28879. * @returns {number} The inline stream length.
  28880. */
  28881. findASCIIHexDecodeInlineStreamEnd:
  28882. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28883. var GT = 0x3E;
  28884. var startPos = stream.pos, ch, length;
  28885. while ((ch = stream.getByte()) !== -1) {
  28886. if (ch === GT) {
  28887. break;
  28888. }
  28889. }
  28890. length = stream.pos - startPos;
  28891. if (ch === -1) {
  28892. warn('Inline ASCIIHexDecode image stream: ' +
  28893. 'EOD marker not found, searching for /EI/ instead.');
  28894. stream.skip(-length); // Reset the stream position.
  28895. return this.findDefaultInlineStreamEnd(stream);
  28896. }
  28897. this.inlineStreamSkipEI(stream);
  28898. return length;
  28899. },
  28900. /**
  28901. * Skip over the /EI/ for streams where we search for an EOD marker.
  28902. */
  28903. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28904. var E = 0x45, I = 0x49;
  28905. var state = 0, ch;
  28906. while ((ch = stream.getByte()) !== -1) {
  28907. if (state === 0) {
  28908. state = (ch === E) ? 1 : 0;
  28909. } else if (state === 1) {
  28910. state = (ch === I) ? 2 : 0;
  28911. } else if (state === 2) {
  28912. break;
  28913. }
  28914. }
  28915. },
  28916. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28917. var lexer = this.lexer;
  28918. var stream = lexer.stream;
  28919. // Parse dictionary.
  28920. var dict = new Dict(null);
  28921. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28922. if (!isName(this.buf1)) {
  28923. error('Dictionary key must be a name object');
  28924. }
  28925. var key = this.buf1.name;
  28926. this.shift();
  28927. if (isEOF(this.buf1)) {
  28928. break;
  28929. }
  28930. dict.set(key, this.getObj(cipherTransform));
  28931. }
  28932. // Extract the name of the first (i.e. the current) image filter.
  28933. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28934. if (isName(filter)) {
  28935. filterName = filter.name;
  28936. } else if (isArray(filter) && isName(filter[0])) {
  28937. filterName = filter[0].name;
  28938. }
  28939. // Parse image stream.
  28940. var startPos = stream.pos, length, i, ii;
  28941. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28942. length = this.findDCTDecodeInlineStreamEnd(stream);
  28943. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28944. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28945. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28946. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28947. } else {
  28948. length = this.findDefaultInlineStreamEnd(stream);
  28949. }
  28950. var imageStream = stream.makeSubStream(startPos, length, dict);
  28951. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28952. // adler32 checksum.
  28953. var adler32;
  28954. if (length < MAX_LENGTH_TO_CACHE) {
  28955. var imageBytes = imageStream.getBytes();
  28956. imageStream.reset();
  28957. var a = 1;
  28958. var b = 0;
  28959. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28960. // No modulo required in the loop if imageBytes.length < 5552.
  28961. a += imageBytes[i] & 0xff;
  28962. b += a;
  28963. }
  28964. adler32 = ((b % 65521) << 16) | (a % 65521);
  28965. if (this.imageCache.adler32 === adler32) {
  28966. this.buf2 = Cmd.get('EI');
  28967. this.shift();
  28968. this.imageCache[adler32].reset();
  28969. return this.imageCache[adler32];
  28970. }
  28971. }
  28972. if (cipherTransform) {
  28973. imageStream = cipherTransform.createStream(imageStream, length);
  28974. }
  28975. imageStream = this.filter(imageStream, dict, length);
  28976. imageStream.dict = dict;
  28977. if (adler32 !== undefined) {
  28978. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28979. this.imageCache[adler32] = imageStream;
  28980. }
  28981. this.buf2 = Cmd.get('EI');
  28982. this.shift();
  28983. return imageStream;
  28984. },
  28985. fetchIfRef: function Parser_fetchIfRef(obj) {
  28986. // not relying on the xref.fetchIfRef -- xref might not be set
  28987. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28988. },
  28989. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28990. var lexer = this.lexer;
  28991. var stream = lexer.stream;
  28992. // get stream start position
  28993. lexer.skipToNextLine();
  28994. var pos = stream.pos - 1;
  28995. // get length
  28996. var length = this.fetchIfRef(dict.get('Length'));
  28997. if (!isInt(length)) {
  28998. info('Bad ' + length + ' attribute in stream');
  28999. length = 0;
  29000. }
  29001. // skip over the stream data
  29002. stream.pos = pos + length;
  29003. lexer.nextChar();
  29004. this.shift(); // '>>'
  29005. this.shift(); // 'stream'
  29006. if (!isCmd(this.buf1, 'endstream')) {
  29007. // bad stream length, scanning for endstream
  29008. stream.pos = pos;
  29009. var SCAN_BLOCK_SIZE = 2048;
  29010. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  29011. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  29012. 0x61, 0x6D];
  29013. var skipped = 0, found = false, i, j;
  29014. while (stream.pos < stream.end) {
  29015. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  29016. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  29017. if (scanLength <= 0) {
  29018. break;
  29019. }
  29020. found = false;
  29021. for (i = 0, j = 0; i < scanLength; i++) {
  29022. var b = scanBytes[i];
  29023. if (b !== ENDSTREAM_SIGNATURE[j]) {
  29024. i -= j;
  29025. j = 0;
  29026. } else {
  29027. j++;
  29028. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  29029. i++;
  29030. found = true;
  29031. break;
  29032. }
  29033. }
  29034. }
  29035. if (found) {
  29036. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  29037. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  29038. break;
  29039. }
  29040. skipped += scanLength;
  29041. stream.pos += scanLength;
  29042. }
  29043. if (!found) {
  29044. error('Missing endstream');
  29045. }
  29046. length = skipped;
  29047. lexer.nextChar();
  29048. this.shift();
  29049. this.shift();
  29050. }
  29051. this.shift(); // 'endstream'
  29052. stream = stream.makeSubStream(pos, length, dict);
  29053. if (cipherTransform) {
  29054. stream = cipherTransform.createStream(stream, length);
  29055. }
  29056. stream = this.filter(stream, dict, length);
  29057. stream.dict = dict;
  29058. return stream;
  29059. },
  29060. filter: function Parser_filter(stream, dict, length) {
  29061. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  29062. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  29063. if (isName(filter)) {
  29064. return this.makeFilter(stream, filter.name, length, params);
  29065. }
  29066. var maybeLength = length;
  29067. if (isArray(filter)) {
  29068. var filterArray = filter;
  29069. var paramsArray = params;
  29070. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  29071. filter = filterArray[i];
  29072. if (!isName(filter)) {
  29073. error('Bad filter name: ' + filter);
  29074. }
  29075. params = null;
  29076. if (isArray(paramsArray) && (i in paramsArray)) {
  29077. params = paramsArray[i];
  29078. }
  29079. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  29080. // after the first stream the length variable is invalid
  29081. maybeLength = null;
  29082. }
  29083. }
  29084. return stream;
  29085. },
  29086. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  29087. if (stream.dict.get('Length') === 0) {
  29088. return new NullStream(stream);
  29089. }
  29090. try {
  29091. if (params) {
  29092. params = this.fetchIfRef(params);
  29093. }
  29094. var xrefStreamStats = this.xref.stats.streamTypes;
  29095. if (name === 'FlateDecode' || name === 'Fl') {
  29096. xrefStreamStats[StreamType.FLATE] = true;
  29097. if (params) {
  29098. return new PredictorStream(new FlateStream(stream, maybeLength),
  29099. maybeLength, params);
  29100. }
  29101. return new FlateStream(stream, maybeLength);
  29102. }
  29103. if (name === 'LZWDecode' || name === 'LZW') {
  29104. xrefStreamStats[StreamType.LZW] = true;
  29105. var earlyChange = 1;
  29106. if (params) {
  29107. if (params.has('EarlyChange')) {
  29108. earlyChange = params.get('EarlyChange');
  29109. }
  29110. return new PredictorStream(
  29111. new LZWStream(stream, maybeLength, earlyChange),
  29112. maybeLength, params);
  29113. }
  29114. return new LZWStream(stream, maybeLength, earlyChange);
  29115. }
  29116. if (name === 'DCTDecode' || name === 'DCT') {
  29117. xrefStreamStats[StreamType.DCT] = true;
  29118. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  29119. }
  29120. if (name === 'JPXDecode' || name === 'JPX') {
  29121. xrefStreamStats[StreamType.JPX] = true;
  29122. return new JpxStream(stream, maybeLength, stream.dict);
  29123. }
  29124. if (name === 'ASCII85Decode' || name === 'A85') {
  29125. xrefStreamStats[StreamType.A85] = true;
  29126. return new Ascii85Stream(stream, maybeLength);
  29127. }
  29128. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  29129. xrefStreamStats[StreamType.AHX] = true;
  29130. return new AsciiHexStream(stream, maybeLength);
  29131. }
  29132. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  29133. xrefStreamStats[StreamType.CCF] = true;
  29134. return new CCITTFaxStream(stream, maybeLength, params);
  29135. }
  29136. if (name === 'RunLengthDecode' || name === 'RL') {
  29137. xrefStreamStats[StreamType.RL] = true;
  29138. return new RunLengthStream(stream, maybeLength);
  29139. }
  29140. if (name === 'JBIG2Decode') {
  29141. xrefStreamStats[StreamType.JBIG] = true;
  29142. return new Jbig2Stream(stream, maybeLength, stream.dict);
  29143. }
  29144. warn('filter "' + name + '" not supported yet');
  29145. return stream;
  29146. } catch (ex) {
  29147. if (ex instanceof MissingDataException) {
  29148. throw ex;
  29149. }
  29150. warn('Invalid stream: \"' + ex + '\"');
  29151. return new NullStream(stream);
  29152. }
  29153. }
  29154. };
  29155. return Parser;
  29156. })();
  29157. var Lexer = (function LexerClosure() {
  29158. function Lexer(stream, knownCommands) {
  29159. this.stream = stream;
  29160. this.nextChar();
  29161. // While lexing, we build up many strings one char at a time. Using += for
  29162. // this can result in lots of garbage strings. It's better to build an
  29163. // array of single-char strings and then join() them together at the end.
  29164. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  29165. // purpose uses less memory than using a new array for each string.
  29166. this.strBuf = [];
  29167. // The PDFs might have "glued" commands with other commands, operands or
  29168. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  29169. // commands and their prefixes. The prefixes are built the following way:
  29170. // if there a command that is a prefix of the other valid command or
  29171. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  29172. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  29173. // other commands or literals as a prefix. The knowCommands is optional.
  29174. this.knownCommands = knownCommands;
  29175. }
  29176. Lexer.isSpace = function Lexer_isSpace(ch) {
  29177. // Space is one of the following characters: SPACE, TAB, CR or LF.
  29178. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  29179. };
  29180. // A '1' in this array means the character is white space. A '1' or
  29181. // '2' means the character ends a name or command.
  29182. var specialChars = [
  29183. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  29184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  29185. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  29186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  29187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  29188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  29189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  29190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  29191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  29192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  29193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  29194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  29195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  29196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  29197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  29198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  29199. ];
  29200. function toHexDigit(ch) {
  29201. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29202. return ch & 0x0F;
  29203. }
  29204. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29205. // 'A'-'F', 'a'-'f'
  29206. return (ch & 0x0F) + 9;
  29207. }
  29208. return -1;
  29209. }
  29210. Lexer.prototype = {
  29211. nextChar: function Lexer_nextChar() {
  29212. return (this.currentChar = this.stream.getByte());
  29213. },
  29214. peekChar: function Lexer_peekChar() {
  29215. return this.stream.peekByte();
  29216. },
  29217. getNumber: function Lexer_getNumber() {
  29218. var ch = this.currentChar;
  29219. var eNotation = false;
  29220. var divideBy = 0; // different from 0 if it's a floating point value
  29221. var sign = 1;
  29222. if (ch === 0x2D) { // '-'
  29223. sign = -1;
  29224. ch = this.nextChar();
  29225. } else if (ch === 0x2B) { // '+'
  29226. ch = this.nextChar();
  29227. }
  29228. if (ch === 0x2E) { // '.'
  29229. divideBy = 10;
  29230. ch = this.nextChar();
  29231. }
  29232. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29233. error('Invalid number: ' + String.fromCharCode(ch));
  29234. return 0;
  29235. }
  29236. var baseValue = ch - 0x30; // '0'
  29237. var powerValue = 0;
  29238. var powerValueSign = 1;
  29239. while ((ch = this.nextChar()) >= 0) {
  29240. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  29241. var currentDigit = ch - 0x30; // '0'
  29242. if (eNotation) { // We are after an 'e' or 'E'
  29243. powerValue = powerValue * 10 + currentDigit;
  29244. } else {
  29245. if (divideBy !== 0) { // We are after a point
  29246. divideBy *= 10;
  29247. }
  29248. baseValue = baseValue * 10 + currentDigit;
  29249. }
  29250. } else if (ch === 0x2E) { // '.'
  29251. if (divideBy === 0) {
  29252. divideBy = 1;
  29253. } else {
  29254. // A number can have only one '.'
  29255. break;
  29256. }
  29257. } else if (ch === 0x2D) { // '-'
  29258. // ignore minus signs in the middle of numbers to match
  29259. // Adobe's behavior
  29260. warn('Badly formated number');
  29261. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29262. // 'E' can be either a scientific notation or the beginning of a new
  29263. // operator
  29264. ch = this.peekChar();
  29265. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29266. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29267. this.nextChar(); // Consume the sign character
  29268. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29269. // The 'E' must be the beginning of a new operator
  29270. break;
  29271. }
  29272. eNotation = true;
  29273. } else {
  29274. // the last character doesn't belong to us
  29275. break;
  29276. }
  29277. }
  29278. if (divideBy !== 0) {
  29279. baseValue /= divideBy;
  29280. }
  29281. if (eNotation) {
  29282. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29283. }
  29284. return sign * baseValue;
  29285. },
  29286. getString: function Lexer_getString() {
  29287. var numParen = 1;
  29288. var done = false;
  29289. var strBuf = this.strBuf;
  29290. strBuf.length = 0;
  29291. var ch = this.nextChar();
  29292. while (true) {
  29293. var charBuffered = false;
  29294. switch (ch | 0) {
  29295. case -1:
  29296. warn('Unterminated string');
  29297. done = true;
  29298. break;
  29299. case 0x28: // '('
  29300. ++numParen;
  29301. strBuf.push('(');
  29302. break;
  29303. case 0x29: // ')'
  29304. if (--numParen === 0) {
  29305. this.nextChar(); // consume strings ')'
  29306. done = true;
  29307. } else {
  29308. strBuf.push(')');
  29309. }
  29310. break;
  29311. case 0x5C: // '\\'
  29312. ch = this.nextChar();
  29313. switch (ch) {
  29314. case -1:
  29315. warn('Unterminated string');
  29316. done = true;
  29317. break;
  29318. case 0x6E: // 'n'
  29319. strBuf.push('\n');
  29320. break;
  29321. case 0x72: // 'r'
  29322. strBuf.push('\r');
  29323. break;
  29324. case 0x74: // 't'
  29325. strBuf.push('\t');
  29326. break;
  29327. case 0x62: // 'b'
  29328. strBuf.push('\b');
  29329. break;
  29330. case 0x66: // 'f'
  29331. strBuf.push('\f');
  29332. break;
  29333. case 0x5C: // '\'
  29334. case 0x28: // '('
  29335. case 0x29: // ')'
  29336. strBuf.push(String.fromCharCode(ch));
  29337. break;
  29338. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29339. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29340. var x = ch & 0x0F;
  29341. ch = this.nextChar();
  29342. charBuffered = true;
  29343. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29344. x = (x << 3) + (ch & 0x0F);
  29345. ch = this.nextChar();
  29346. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29347. charBuffered = false;
  29348. x = (x << 3) + (ch & 0x0F);
  29349. }
  29350. }
  29351. strBuf.push(String.fromCharCode(x));
  29352. break;
  29353. case 0x0D: // CR
  29354. if (this.peekChar() === 0x0A) { // LF
  29355. this.nextChar();
  29356. }
  29357. break;
  29358. case 0x0A: // LF
  29359. break;
  29360. default:
  29361. strBuf.push(String.fromCharCode(ch));
  29362. break;
  29363. }
  29364. break;
  29365. default:
  29366. strBuf.push(String.fromCharCode(ch));
  29367. break;
  29368. }
  29369. if (done) {
  29370. break;
  29371. }
  29372. if (!charBuffered) {
  29373. ch = this.nextChar();
  29374. }
  29375. }
  29376. return strBuf.join('');
  29377. },
  29378. getName: function Lexer_getName() {
  29379. var ch;
  29380. var strBuf = this.strBuf;
  29381. strBuf.length = 0;
  29382. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29383. if (ch === 0x23) { // '#'
  29384. ch = this.nextChar();
  29385. var x = toHexDigit(ch);
  29386. if (x !== -1) {
  29387. var x2 = toHexDigit(this.nextChar());
  29388. if (x2 === -1) {
  29389. error('Illegal digit in hex char in name: ' + x2);
  29390. }
  29391. strBuf.push(String.fromCharCode((x << 4) | x2));
  29392. } else {
  29393. strBuf.push('#', String.fromCharCode(ch));
  29394. }
  29395. } else {
  29396. strBuf.push(String.fromCharCode(ch));
  29397. }
  29398. }
  29399. if (strBuf.length > 127) {
  29400. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  29401. }
  29402. return Name.get(strBuf.join(''));
  29403. },
  29404. getHexString: function Lexer_getHexString() {
  29405. var strBuf = this.strBuf;
  29406. strBuf.length = 0;
  29407. var ch = this.currentChar;
  29408. var isFirstHex = true;
  29409. var firstDigit;
  29410. var secondDigit;
  29411. while (true) {
  29412. if (ch < 0) {
  29413. warn('Unterminated hex string');
  29414. break;
  29415. } else if (ch === 0x3E) { // '>'
  29416. this.nextChar();
  29417. break;
  29418. } else if (specialChars[ch] === 1) {
  29419. ch = this.nextChar();
  29420. continue;
  29421. } else {
  29422. if (isFirstHex) {
  29423. firstDigit = toHexDigit(ch);
  29424. if (firstDigit === -1) {
  29425. warn('Ignoring invalid character "' + ch + '" in hex string');
  29426. ch = this.nextChar();
  29427. continue;
  29428. }
  29429. } else {
  29430. secondDigit = toHexDigit(ch);
  29431. if (secondDigit === -1) {
  29432. warn('Ignoring invalid character "' + ch + '" in hex string');
  29433. ch = this.nextChar();
  29434. continue;
  29435. }
  29436. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29437. }
  29438. isFirstHex = !isFirstHex;
  29439. ch = this.nextChar();
  29440. }
  29441. }
  29442. return strBuf.join('');
  29443. },
  29444. getObj: function Lexer_getObj() {
  29445. // skip whitespace and comments
  29446. var comment = false;
  29447. var ch = this.currentChar;
  29448. while (true) {
  29449. if (ch < 0) {
  29450. return EOF;
  29451. }
  29452. if (comment) {
  29453. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29454. comment = false;
  29455. }
  29456. } else if (ch === 0x25) { // '%'
  29457. comment = true;
  29458. } else if (specialChars[ch] !== 1) {
  29459. break;
  29460. }
  29461. ch = this.nextChar();
  29462. }
  29463. // start reading token
  29464. switch (ch | 0) {
  29465. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29466. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29467. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29468. return this.getNumber();
  29469. case 0x28: // '('
  29470. return this.getString();
  29471. case 0x2F: // '/'
  29472. return this.getName();
  29473. // array punctuation
  29474. case 0x5B: // '['
  29475. this.nextChar();
  29476. return Cmd.get('[');
  29477. case 0x5D: // ']'
  29478. this.nextChar();
  29479. return Cmd.get(']');
  29480. // hex string or dict punctuation
  29481. case 0x3C: // '<'
  29482. ch = this.nextChar();
  29483. if (ch === 0x3C) {
  29484. // dict punctuation
  29485. this.nextChar();
  29486. return Cmd.get('<<');
  29487. }
  29488. return this.getHexString();
  29489. // dict punctuation
  29490. case 0x3E: // '>'
  29491. ch = this.nextChar();
  29492. if (ch === 0x3E) {
  29493. this.nextChar();
  29494. return Cmd.get('>>');
  29495. }
  29496. return Cmd.get('>');
  29497. case 0x7B: // '{'
  29498. this.nextChar();
  29499. return Cmd.get('{');
  29500. case 0x7D: // '}'
  29501. this.nextChar();
  29502. return Cmd.get('}');
  29503. case 0x29: // ')'
  29504. error('Illegal character: ' + ch);
  29505. break;
  29506. }
  29507. // command
  29508. var str = String.fromCharCode(ch);
  29509. var knownCommands = this.knownCommands;
  29510. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29511. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29512. // stop if known command is found and next character does not make
  29513. // the str a command
  29514. var possibleCommand = str + String.fromCharCode(ch);
  29515. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29516. break;
  29517. }
  29518. if (str.length === 128) {
  29519. error('Command token too long: ' + str.length);
  29520. }
  29521. str = possibleCommand;
  29522. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29523. }
  29524. if (str === 'true') {
  29525. return true;
  29526. }
  29527. if (str === 'false') {
  29528. return false;
  29529. }
  29530. if (str === 'null') {
  29531. return null;
  29532. }
  29533. return Cmd.get(str);
  29534. },
  29535. skipToNextLine: function Lexer_skipToNextLine() {
  29536. var ch = this.currentChar;
  29537. while (ch >= 0) {
  29538. if (ch === 0x0D) { // CR
  29539. ch = this.nextChar();
  29540. if (ch === 0x0A) { // LF
  29541. this.nextChar();
  29542. }
  29543. break;
  29544. } else if (ch === 0x0A) { // LF
  29545. this.nextChar();
  29546. break;
  29547. }
  29548. ch = this.nextChar();
  29549. }
  29550. }
  29551. };
  29552. return Lexer;
  29553. })();
  29554. var Linearization = {
  29555. create: function LinearizationCreate(stream) {
  29556. function getInt(name, allowZeroValue) {
  29557. var obj = linDict.get(name);
  29558. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29559. return obj;
  29560. }
  29561. throw new Error('The "' + name + '" parameter in the linearization ' +
  29562. 'dictionary is invalid.');
  29563. }
  29564. function getHints() {
  29565. var hints = linDict.get('H'), hintsLength, item;
  29566. if (isArray(hints) &&
  29567. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29568. for (var index = 0; index < hintsLength; index++) {
  29569. if (!(isInt(item = hints[index]) && item > 0)) {
  29570. throw new Error('Hint (' + index +
  29571. ') in the linearization dictionary is invalid.');
  29572. }
  29573. }
  29574. return hints;
  29575. }
  29576. throw new Error('Hint array in the linearization dictionary is invalid.');
  29577. }
  29578. var parser = new Parser(new Lexer(stream), false, null);
  29579. var obj1 = parser.getObj();
  29580. var obj2 = parser.getObj();
  29581. var obj3 = parser.getObj();
  29582. var linDict = parser.getObj();
  29583. var obj, length;
  29584. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29585. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29586. return null; // No valid linearization dictionary found.
  29587. } else if ((length = getInt('L')) !== stream.length) {
  29588. throw new Error('The "L" parameter in the linearization dictionary ' +
  29589. 'does not equal the stream length.');
  29590. }
  29591. return {
  29592. length: length,
  29593. hints: getHints(),
  29594. objectNumberFirst: getInt('O'),
  29595. endFirst: getInt('E'),
  29596. numPages: getInt('N'),
  29597. mainXRefEntriesOffset: getInt('T'),
  29598. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29599. };
  29600. }
  29601. };
  29602. var PostScriptParser = (function PostScriptParserClosure() {
  29603. function PostScriptParser(lexer) {
  29604. this.lexer = lexer;
  29605. this.operators = [];
  29606. this.token = null;
  29607. this.prev = null;
  29608. }
  29609. PostScriptParser.prototype = {
  29610. nextToken: function PostScriptParser_nextToken() {
  29611. this.prev = this.token;
  29612. this.token = this.lexer.getToken();
  29613. },
  29614. accept: function PostScriptParser_accept(type) {
  29615. if (this.token.type === type) {
  29616. this.nextToken();
  29617. return true;
  29618. }
  29619. return false;
  29620. },
  29621. expect: function PostScriptParser_expect(type) {
  29622. if (this.accept(type)) {
  29623. return true;
  29624. }
  29625. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29626. type + '.');
  29627. },
  29628. parse: function PostScriptParser_parse() {
  29629. this.nextToken();
  29630. this.expect(PostScriptTokenTypes.LBRACE);
  29631. this.parseBlock();
  29632. this.expect(PostScriptTokenTypes.RBRACE);
  29633. return this.operators;
  29634. },
  29635. parseBlock: function PostScriptParser_parseBlock() {
  29636. while (true) {
  29637. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29638. this.operators.push(this.prev.value);
  29639. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29640. this.operators.push(this.prev.value);
  29641. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29642. this.parseCondition();
  29643. } else {
  29644. return;
  29645. }
  29646. }
  29647. },
  29648. parseCondition: function PostScriptParser_parseCondition() {
  29649. // Add two place holders that will be updated later
  29650. var conditionLocation = this.operators.length;
  29651. this.operators.push(null, null);
  29652. this.parseBlock();
  29653. this.expect(PostScriptTokenTypes.RBRACE);
  29654. if (this.accept(PostScriptTokenTypes.IF)) {
  29655. // The true block is right after the 'if' so it just falls through on
  29656. // true else it jumps and skips the true block.
  29657. this.operators[conditionLocation] = this.operators.length;
  29658. this.operators[conditionLocation + 1] = 'jz';
  29659. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29660. var jumpLocation = this.operators.length;
  29661. this.operators.push(null, null);
  29662. var endOfTrue = this.operators.length;
  29663. this.parseBlock();
  29664. this.expect(PostScriptTokenTypes.RBRACE);
  29665. this.expect(PostScriptTokenTypes.IFELSE);
  29666. // The jump is added at the end of the true block to skip the false
  29667. // block.
  29668. this.operators[jumpLocation] = this.operators.length;
  29669. this.operators[jumpLocation + 1] = 'j';
  29670. this.operators[conditionLocation] = endOfTrue;
  29671. this.operators[conditionLocation + 1] = 'jz';
  29672. } else {
  29673. error('PS Function: error parsing conditional.');
  29674. }
  29675. }
  29676. };
  29677. return PostScriptParser;
  29678. })();
  29679. var PostScriptTokenTypes = {
  29680. LBRACE: 0,
  29681. RBRACE: 1,
  29682. NUMBER: 2,
  29683. OPERATOR: 3,
  29684. IF: 4,
  29685. IFELSE: 5
  29686. };
  29687. var PostScriptToken = (function PostScriptTokenClosure() {
  29688. function PostScriptToken(type, value) {
  29689. this.type = type;
  29690. this.value = value;
  29691. }
  29692. var opCache = {};
  29693. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29694. var opValue = opCache[op];
  29695. if (opValue) {
  29696. return opValue;
  29697. }
  29698. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29699. };
  29700. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29701. '{');
  29702. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29703. '}');
  29704. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29705. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29706. 'IFELSE');
  29707. return PostScriptToken;
  29708. })();
  29709. var PostScriptLexer = (function PostScriptLexerClosure() {
  29710. function PostScriptLexer(stream) {
  29711. this.stream = stream;
  29712. this.nextChar();
  29713. this.strBuf = [];
  29714. }
  29715. PostScriptLexer.prototype = {
  29716. nextChar: function PostScriptLexer_nextChar() {
  29717. return (this.currentChar = this.stream.getByte());
  29718. },
  29719. getToken: function PostScriptLexer_getToken() {
  29720. var comment = false;
  29721. var ch = this.currentChar;
  29722. // skip comments
  29723. while (true) {
  29724. if (ch < 0) {
  29725. return EOF;
  29726. }
  29727. if (comment) {
  29728. if (ch === 0x0A || ch === 0x0D) {
  29729. comment = false;
  29730. }
  29731. } else if (ch === 0x25) { // '%'
  29732. comment = true;
  29733. } else if (!Lexer.isSpace(ch)) {
  29734. break;
  29735. }
  29736. ch = this.nextChar();
  29737. }
  29738. switch (ch | 0) {
  29739. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29740. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29741. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29742. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29743. this.getNumber());
  29744. case 0x7B: // '{'
  29745. this.nextChar();
  29746. return PostScriptToken.LBRACE;
  29747. case 0x7D: // '}'
  29748. this.nextChar();
  29749. return PostScriptToken.RBRACE;
  29750. }
  29751. // operator
  29752. var strBuf = this.strBuf;
  29753. strBuf.length = 0;
  29754. strBuf[0] = String.fromCharCode(ch);
  29755. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29756. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29757. strBuf.push(String.fromCharCode(ch));
  29758. }
  29759. var str = strBuf.join('');
  29760. switch (str.toLowerCase()) {
  29761. case 'if':
  29762. return PostScriptToken.IF;
  29763. case 'ifelse':
  29764. return PostScriptToken.IFELSE;
  29765. default:
  29766. return PostScriptToken.getOperator(str);
  29767. }
  29768. },
  29769. getNumber: function PostScriptLexer_getNumber() {
  29770. var ch = this.currentChar;
  29771. var strBuf = this.strBuf;
  29772. strBuf.length = 0;
  29773. strBuf[0] = String.fromCharCode(ch);
  29774. while ((ch = this.nextChar()) >= 0) {
  29775. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29776. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29777. strBuf.push(String.fromCharCode(ch));
  29778. } else {
  29779. break;
  29780. }
  29781. }
  29782. var value = parseFloat(strBuf.join(''));
  29783. if (isNaN(value)) {
  29784. error('Invalid floating point number: ' + value);
  29785. }
  29786. return value;
  29787. }
  29788. };
  29789. return PostScriptLexer;
  29790. })();
  29791. var Stream = (function StreamClosure() {
  29792. function Stream(arrayBuffer, start, length, dict) {
  29793. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29794. arrayBuffer : new Uint8Array(arrayBuffer));
  29795. this.start = start || 0;
  29796. this.pos = this.start;
  29797. this.end = (start + length) || this.bytes.length;
  29798. this.dict = dict;
  29799. }
  29800. // required methods for a stream. if a particular stream does not
  29801. // implement these, an error should be thrown
  29802. Stream.prototype = {
  29803. get length() {
  29804. return this.end - this.start;
  29805. },
  29806. get isEmpty() {
  29807. return this.length === 0;
  29808. },
  29809. getByte: function Stream_getByte() {
  29810. if (this.pos >= this.end) {
  29811. return -1;
  29812. }
  29813. return this.bytes[this.pos++];
  29814. },
  29815. getUint16: function Stream_getUint16() {
  29816. var b0 = this.getByte();
  29817. var b1 = this.getByte();
  29818. if (b0 === -1 || b1 === -1) {
  29819. return -1;
  29820. }
  29821. return (b0 << 8) + b1;
  29822. },
  29823. getInt32: function Stream_getInt32() {
  29824. var b0 = this.getByte();
  29825. var b1 = this.getByte();
  29826. var b2 = this.getByte();
  29827. var b3 = this.getByte();
  29828. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29829. },
  29830. // returns subarray of original buffer
  29831. // should only be read
  29832. getBytes: function Stream_getBytes(length) {
  29833. var bytes = this.bytes;
  29834. var pos = this.pos;
  29835. var strEnd = this.end;
  29836. if (!length) {
  29837. return bytes.subarray(pos, strEnd);
  29838. }
  29839. var end = pos + length;
  29840. if (end > strEnd) {
  29841. end = strEnd;
  29842. }
  29843. this.pos = end;
  29844. return bytes.subarray(pos, end);
  29845. },
  29846. peekByte: function Stream_peekByte() {
  29847. var peekedByte = this.getByte();
  29848. this.pos--;
  29849. return peekedByte;
  29850. },
  29851. peekBytes: function Stream_peekBytes(length) {
  29852. var bytes = this.getBytes(length);
  29853. this.pos -= bytes.length;
  29854. return bytes;
  29855. },
  29856. skip: function Stream_skip(n) {
  29857. if (!n) {
  29858. n = 1;
  29859. }
  29860. this.pos += n;
  29861. },
  29862. reset: function Stream_reset() {
  29863. this.pos = this.start;
  29864. },
  29865. moveStart: function Stream_moveStart() {
  29866. this.start = this.pos;
  29867. },
  29868. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29869. return new Stream(this.bytes.buffer, start, length, dict);
  29870. },
  29871. isStream: true
  29872. };
  29873. return Stream;
  29874. })();
  29875. var StringStream = (function StringStreamClosure() {
  29876. function StringStream(str) {
  29877. var length = str.length;
  29878. var bytes = new Uint8Array(length);
  29879. for (var n = 0; n < length; ++n) {
  29880. bytes[n] = str.charCodeAt(n);
  29881. }
  29882. Stream.call(this, bytes);
  29883. }
  29884. StringStream.prototype = Stream.prototype;
  29885. return StringStream;
  29886. })();
  29887. // super class for the decoding streams
  29888. var DecodeStream = (function DecodeStreamClosure() {
  29889. // Lots of DecodeStreams are created whose buffers are never used. For these
  29890. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29891. // having special cases that would be required if we used |null| for an empty
  29892. // buffer.
  29893. var emptyBuffer = new Uint8Array(0);
  29894. function DecodeStream(maybeMinBufferLength) {
  29895. this.pos = 0;
  29896. this.bufferLength = 0;
  29897. this.eof = false;
  29898. this.buffer = emptyBuffer;
  29899. this.minBufferLength = 512;
  29900. if (maybeMinBufferLength) {
  29901. // Compute the first power of two that is as big as maybeMinBufferLength.
  29902. while (this.minBufferLength < maybeMinBufferLength) {
  29903. this.minBufferLength *= 2;
  29904. }
  29905. }
  29906. }
  29907. DecodeStream.prototype = {
  29908. get isEmpty() {
  29909. while (!this.eof && this.bufferLength === 0) {
  29910. this.readBlock();
  29911. }
  29912. return this.bufferLength === 0;
  29913. },
  29914. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29915. var buffer = this.buffer;
  29916. if (requested <= buffer.byteLength) {
  29917. return buffer;
  29918. }
  29919. var size = this.minBufferLength;
  29920. while (size < requested) {
  29921. size *= 2;
  29922. }
  29923. var buffer2 = new Uint8Array(size);
  29924. buffer2.set(buffer);
  29925. return (this.buffer = buffer2);
  29926. },
  29927. getByte: function DecodeStream_getByte() {
  29928. var pos = this.pos;
  29929. while (this.bufferLength <= pos) {
  29930. if (this.eof) {
  29931. return -1;
  29932. }
  29933. this.readBlock();
  29934. }
  29935. return this.buffer[this.pos++];
  29936. },
  29937. getUint16: function DecodeStream_getUint16() {
  29938. var b0 = this.getByte();
  29939. var b1 = this.getByte();
  29940. if (b0 === -1 || b1 === -1) {
  29941. return -1;
  29942. }
  29943. return (b0 << 8) + b1;
  29944. },
  29945. getInt32: function DecodeStream_getInt32() {
  29946. var b0 = this.getByte();
  29947. var b1 = this.getByte();
  29948. var b2 = this.getByte();
  29949. var b3 = this.getByte();
  29950. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29951. },
  29952. getBytes: function DecodeStream_getBytes(length) {
  29953. var end, pos = this.pos;
  29954. if (length) {
  29955. this.ensureBuffer(pos + length);
  29956. end = pos + length;
  29957. while (!this.eof && this.bufferLength < end) {
  29958. this.readBlock();
  29959. }
  29960. var bufEnd = this.bufferLength;
  29961. if (end > bufEnd) {
  29962. end = bufEnd;
  29963. }
  29964. } else {
  29965. while (!this.eof) {
  29966. this.readBlock();
  29967. }
  29968. end = this.bufferLength;
  29969. }
  29970. this.pos = end;
  29971. return this.buffer.subarray(pos, end);
  29972. },
  29973. peekByte: function DecodeStream_peekByte() {
  29974. var peekedByte = this.getByte();
  29975. this.pos--;
  29976. return peekedByte;
  29977. },
  29978. peekBytes: function DecodeStream_peekBytes(length) {
  29979. var bytes = this.getBytes(length);
  29980. this.pos -= bytes.length;
  29981. return bytes;
  29982. },
  29983. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29984. var end = start + length;
  29985. while (this.bufferLength <= end && !this.eof) {
  29986. this.readBlock();
  29987. }
  29988. return new Stream(this.buffer, start, length, dict);
  29989. },
  29990. skip: function DecodeStream_skip(n) {
  29991. if (!n) {
  29992. n = 1;
  29993. }
  29994. this.pos += n;
  29995. },
  29996. reset: function DecodeStream_reset() {
  29997. this.pos = 0;
  29998. },
  29999. getBaseStreams: function DecodeStream_getBaseStreams() {
  30000. if (this.str && this.str.getBaseStreams) {
  30001. return this.str.getBaseStreams();
  30002. }
  30003. return [];
  30004. }
  30005. };
  30006. return DecodeStream;
  30007. })();
  30008. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  30009. function StreamsSequenceStream(streams) {
  30010. this.streams = streams;
  30011. DecodeStream.call(this, /* maybeLength = */ null);
  30012. }
  30013. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  30014. StreamsSequenceStream.prototype.readBlock =
  30015. function streamSequenceStreamReadBlock() {
  30016. var streams = this.streams;
  30017. if (streams.length === 0) {
  30018. this.eof = true;
  30019. return;
  30020. }
  30021. var stream = streams.shift();
  30022. var chunk = stream.getBytes();
  30023. var bufferLength = this.bufferLength;
  30024. var newLength = bufferLength + chunk.length;
  30025. var buffer = this.ensureBuffer(newLength);
  30026. buffer.set(chunk, bufferLength);
  30027. this.bufferLength = newLength;
  30028. };
  30029. StreamsSequenceStream.prototype.getBaseStreams =
  30030. function StreamsSequenceStream_getBaseStreams() {
  30031. var baseStreams = [];
  30032. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  30033. var stream = this.streams[i];
  30034. if (stream.getBaseStreams) {
  30035. Util.appendToArray(baseStreams, stream.getBaseStreams());
  30036. }
  30037. }
  30038. return baseStreams;
  30039. };
  30040. return StreamsSequenceStream;
  30041. })();
  30042. var FlateStream = (function FlateStreamClosure() {
  30043. var codeLenCodeMap = new Int32Array([
  30044. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  30045. ]);
  30046. var lengthDecode = new Int32Array([
  30047. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  30048. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  30049. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  30050. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  30051. ]);
  30052. var distDecode = new Int32Array([
  30053. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  30054. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  30055. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  30056. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  30057. ]);
  30058. var fixedLitCodeTab = [new Int32Array([
  30059. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  30060. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  30061. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  30062. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  30063. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  30064. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  30065. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  30066. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  30067. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  30068. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  30069. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  30070. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  30071. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  30072. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  30073. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  30074. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  30075. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  30076. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  30077. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  30078. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  30079. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  30080. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  30081. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  30082. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  30083. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  30084. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  30085. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  30086. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  30087. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  30088. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  30089. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  30090. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  30091. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  30092. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  30093. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  30094. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  30095. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  30096. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  30097. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  30098. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  30099. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  30100. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  30101. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  30102. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  30103. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  30104. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  30105. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  30106. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  30107. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  30108. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  30109. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  30110. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  30111. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  30112. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  30113. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  30114. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  30115. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  30116. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  30117. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  30118. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  30119. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  30120. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  30121. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  30122. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  30123. ]), 9];
  30124. var fixedDistCodeTab = [new Int32Array([
  30125. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  30126. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  30127. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  30128. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  30129. ]), 5];
  30130. function FlateStream(str, maybeLength) {
  30131. this.str = str;
  30132. this.dict = str.dict;
  30133. var cmf = str.getByte();
  30134. var flg = str.getByte();
  30135. if (cmf === -1 || flg === -1) {
  30136. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  30137. }
  30138. if ((cmf & 0x0f) !== 0x08) {
  30139. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  30140. }
  30141. if ((((cmf << 8) + flg) % 31) !== 0) {
  30142. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  30143. }
  30144. if (flg & 0x20) {
  30145. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  30146. }
  30147. this.codeSize = 0;
  30148. this.codeBuf = 0;
  30149. DecodeStream.call(this, maybeLength);
  30150. }
  30151. FlateStream.prototype = Object.create(DecodeStream.prototype);
  30152. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  30153. var str = this.str;
  30154. var codeSize = this.codeSize;
  30155. var codeBuf = this.codeBuf;
  30156. var b;
  30157. while (codeSize < bits) {
  30158. if ((b = str.getByte()) === -1) {
  30159. error('Bad encoding in flate stream');
  30160. }
  30161. codeBuf |= b << codeSize;
  30162. codeSize += 8;
  30163. }
  30164. b = codeBuf & ((1 << bits) - 1);
  30165. this.codeBuf = codeBuf >> bits;
  30166. this.codeSize = codeSize -= bits;
  30167. return b;
  30168. };
  30169. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  30170. var str = this.str;
  30171. var codes = table[0];
  30172. var maxLen = table[1];
  30173. var codeSize = this.codeSize;
  30174. var codeBuf = this.codeBuf;
  30175. var b;
  30176. while (codeSize < maxLen) {
  30177. if ((b = str.getByte()) === -1) {
  30178. // premature end of stream. code might however still be valid.
  30179. // codeSize < codeLen check below guards against incomplete codeVal.
  30180. break;
  30181. }
  30182. codeBuf |= (b << codeSize);
  30183. codeSize += 8;
  30184. }
  30185. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  30186. var codeLen = code >> 16;
  30187. var codeVal = code & 0xffff;
  30188. if (codeLen < 1 || codeSize < codeLen) {
  30189. error('Bad encoding in flate stream');
  30190. }
  30191. this.codeBuf = (codeBuf >> codeLen);
  30192. this.codeSize = (codeSize - codeLen);
  30193. return codeVal;
  30194. };
  30195. FlateStream.prototype.generateHuffmanTable =
  30196. function flateStreamGenerateHuffmanTable(lengths) {
  30197. var n = lengths.length;
  30198. // find max code length
  30199. var maxLen = 0;
  30200. var i;
  30201. for (i = 0; i < n; ++i) {
  30202. if (lengths[i] > maxLen) {
  30203. maxLen = lengths[i];
  30204. }
  30205. }
  30206. // build the table
  30207. var size = 1 << maxLen;
  30208. var codes = new Int32Array(size);
  30209. for (var len = 1, code = 0, skip = 2;
  30210. len <= maxLen;
  30211. ++len, code <<= 1, skip <<= 1) {
  30212. for (var val = 0; val < n; ++val) {
  30213. if (lengths[val] === len) {
  30214. // bit-reverse the code
  30215. var code2 = 0;
  30216. var t = code;
  30217. for (i = 0; i < len; ++i) {
  30218. code2 = (code2 << 1) | (t & 1);
  30219. t >>= 1;
  30220. }
  30221. // fill the table entries
  30222. for (i = code2; i < size; i += skip) {
  30223. codes[i] = (len << 16) | val;
  30224. }
  30225. ++code;
  30226. }
  30227. }
  30228. }
  30229. return [codes, maxLen];
  30230. };
  30231. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  30232. var buffer, len;
  30233. var str = this.str;
  30234. // read block header
  30235. var hdr = this.getBits(3);
  30236. if (hdr & 1) {
  30237. this.eof = true;
  30238. }
  30239. hdr >>= 1;
  30240. if (hdr === 0) { // uncompressed block
  30241. var b;
  30242. if ((b = str.getByte()) === -1) {
  30243. error('Bad block header in flate stream');
  30244. }
  30245. var blockLen = b;
  30246. if ((b = str.getByte()) === -1) {
  30247. error('Bad block header in flate stream');
  30248. }
  30249. blockLen |= (b << 8);
  30250. if ((b = str.getByte()) === -1) {
  30251. error('Bad block header in flate stream');
  30252. }
  30253. var check = b;
  30254. if ((b = str.getByte()) === -1) {
  30255. error('Bad block header in flate stream');
  30256. }
  30257. check |= (b << 8);
  30258. if (check !== (~blockLen & 0xffff) &&
  30259. (blockLen !== 0 || check !== 0)) {
  30260. // Ignoring error for bad "empty" block (see issue 1277)
  30261. error('Bad uncompressed block length in flate stream');
  30262. }
  30263. this.codeBuf = 0;
  30264. this.codeSize = 0;
  30265. var bufferLength = this.bufferLength;
  30266. buffer = this.ensureBuffer(bufferLength + blockLen);
  30267. var end = bufferLength + blockLen;
  30268. this.bufferLength = end;
  30269. if (blockLen === 0) {
  30270. if (str.peekByte() === -1) {
  30271. this.eof = true;
  30272. }
  30273. } else {
  30274. for (var n = bufferLength; n < end; ++n) {
  30275. if ((b = str.getByte()) === -1) {
  30276. this.eof = true;
  30277. break;
  30278. }
  30279. buffer[n] = b;
  30280. }
  30281. }
  30282. return;
  30283. }
  30284. var litCodeTable;
  30285. var distCodeTable;
  30286. if (hdr === 1) { // compressed block, fixed codes
  30287. litCodeTable = fixedLitCodeTab;
  30288. distCodeTable = fixedDistCodeTab;
  30289. } else if (hdr === 2) { // compressed block, dynamic codes
  30290. var numLitCodes = this.getBits(5) + 257;
  30291. var numDistCodes = this.getBits(5) + 1;
  30292. var numCodeLenCodes = this.getBits(4) + 4;
  30293. // build the code lengths code table
  30294. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30295. var i;
  30296. for (i = 0; i < numCodeLenCodes; ++i) {
  30297. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30298. }
  30299. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30300. // build the literal and distance code tables
  30301. len = 0;
  30302. i = 0;
  30303. var codes = numLitCodes + numDistCodes;
  30304. var codeLengths = new Uint8Array(codes);
  30305. var bitsLength, bitsOffset, what;
  30306. while (i < codes) {
  30307. var code = this.getCode(codeLenCodeTab);
  30308. if (code === 16) {
  30309. bitsLength = 2; bitsOffset = 3; what = len;
  30310. } else if (code === 17) {
  30311. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30312. } else if (code === 18) {
  30313. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30314. } else {
  30315. codeLengths[i++] = len = code;
  30316. continue;
  30317. }
  30318. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30319. while (repeatLength-- > 0) {
  30320. codeLengths[i++] = what;
  30321. }
  30322. }
  30323. litCodeTable =
  30324. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30325. distCodeTable =
  30326. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30327. } else {
  30328. error('Unknown block type in flate stream');
  30329. }
  30330. buffer = this.buffer;
  30331. var limit = buffer ? buffer.length : 0;
  30332. var pos = this.bufferLength;
  30333. while (true) {
  30334. var code1 = this.getCode(litCodeTable);
  30335. if (code1 < 256) {
  30336. if (pos + 1 >= limit) {
  30337. buffer = this.ensureBuffer(pos + 1);
  30338. limit = buffer.length;
  30339. }
  30340. buffer[pos++] = code1;
  30341. continue;
  30342. }
  30343. if (code1 === 256) {
  30344. this.bufferLength = pos;
  30345. return;
  30346. }
  30347. code1 -= 257;
  30348. code1 = lengthDecode[code1];
  30349. var code2 = code1 >> 16;
  30350. if (code2 > 0) {
  30351. code2 = this.getBits(code2);
  30352. }
  30353. len = (code1 & 0xffff) + code2;
  30354. code1 = this.getCode(distCodeTable);
  30355. code1 = distDecode[code1];
  30356. code2 = code1 >> 16;
  30357. if (code2 > 0) {
  30358. code2 = this.getBits(code2);
  30359. }
  30360. var dist = (code1 & 0xffff) + code2;
  30361. if (pos + len >= limit) {
  30362. buffer = this.ensureBuffer(pos + len);
  30363. limit = buffer.length;
  30364. }
  30365. for (var k = 0; k < len; ++k, ++pos) {
  30366. buffer[pos] = buffer[pos - dist];
  30367. }
  30368. }
  30369. };
  30370. return FlateStream;
  30371. })();
  30372. var PredictorStream = (function PredictorStreamClosure() {
  30373. function PredictorStream(str, maybeLength, params) {
  30374. var predictor = this.predictor = params.get('Predictor') || 1;
  30375. if (predictor <= 1) {
  30376. return str; // no prediction
  30377. }
  30378. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30379. error('Unsupported predictor: ' + predictor);
  30380. }
  30381. if (predictor === 2) {
  30382. this.readBlock = this.readBlockTiff;
  30383. } else {
  30384. this.readBlock = this.readBlockPng;
  30385. }
  30386. this.str = str;
  30387. this.dict = str.dict;
  30388. var colors = this.colors = params.get('Colors') || 1;
  30389. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30390. var columns = this.columns = params.get('Columns') || 1;
  30391. this.pixBytes = (colors * bits + 7) >> 3;
  30392. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30393. DecodeStream.call(this, maybeLength);
  30394. return this;
  30395. }
  30396. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30397. PredictorStream.prototype.readBlockTiff =
  30398. function predictorStreamReadBlockTiff() {
  30399. var rowBytes = this.rowBytes;
  30400. var bufferLength = this.bufferLength;
  30401. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30402. var bits = this.bits;
  30403. var colors = this.colors;
  30404. var rawBytes = this.str.getBytes(rowBytes);
  30405. this.eof = !rawBytes.length;
  30406. if (this.eof) {
  30407. return;
  30408. }
  30409. var inbuf = 0, outbuf = 0;
  30410. var inbits = 0, outbits = 0;
  30411. var pos = bufferLength;
  30412. var i;
  30413. if (bits === 1) {
  30414. for (i = 0; i < rowBytes; ++i) {
  30415. var c = rawBytes[i];
  30416. inbuf = (inbuf << 8) | c;
  30417. // bitwise addition is exclusive or
  30418. // first shift inbuf and then add
  30419. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30420. // truncate inbuf (assumes colors < 16)
  30421. inbuf &= 0xFFFF;
  30422. }
  30423. } else if (bits === 8) {
  30424. for (i = 0; i < colors; ++i) {
  30425. buffer[pos++] = rawBytes[i];
  30426. }
  30427. for (; i < rowBytes; ++i) {
  30428. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30429. pos++;
  30430. }
  30431. } else {
  30432. var compArray = new Uint8Array(colors + 1);
  30433. var bitMask = (1 << bits) - 1;
  30434. var j = 0, k = bufferLength;
  30435. var columns = this.columns;
  30436. for (i = 0; i < columns; ++i) {
  30437. for (var kk = 0; kk < colors; ++kk) {
  30438. if (inbits < bits) {
  30439. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30440. inbits += 8;
  30441. }
  30442. compArray[kk] = (compArray[kk] +
  30443. (inbuf >> (inbits - bits))) & bitMask;
  30444. inbits -= bits;
  30445. outbuf = (outbuf << bits) | compArray[kk];
  30446. outbits += bits;
  30447. if (outbits >= 8) {
  30448. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30449. outbits -= 8;
  30450. }
  30451. }
  30452. }
  30453. if (outbits > 0) {
  30454. buffer[k++] = (outbuf << (8 - outbits)) +
  30455. (inbuf & ((1 << (8 - outbits)) - 1));
  30456. }
  30457. }
  30458. this.bufferLength += rowBytes;
  30459. };
  30460. PredictorStream.prototype.readBlockPng =
  30461. function predictorStreamReadBlockPng() {
  30462. var rowBytes = this.rowBytes;
  30463. var pixBytes = this.pixBytes;
  30464. var predictor = this.str.getByte();
  30465. var rawBytes = this.str.getBytes(rowBytes);
  30466. this.eof = !rawBytes.length;
  30467. if (this.eof) {
  30468. return;
  30469. }
  30470. var bufferLength = this.bufferLength;
  30471. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30472. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30473. if (prevRow.length === 0) {
  30474. prevRow = new Uint8Array(rowBytes);
  30475. }
  30476. var i, j = bufferLength, up, c;
  30477. switch (predictor) {
  30478. case 0:
  30479. for (i = 0; i < rowBytes; ++i) {
  30480. buffer[j++] = rawBytes[i];
  30481. }
  30482. break;
  30483. case 1:
  30484. for (i = 0; i < pixBytes; ++i) {
  30485. buffer[j++] = rawBytes[i];
  30486. }
  30487. for (; i < rowBytes; ++i) {
  30488. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30489. j++;
  30490. }
  30491. break;
  30492. case 2:
  30493. for (i = 0; i < rowBytes; ++i) {
  30494. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30495. }
  30496. break;
  30497. case 3:
  30498. for (i = 0; i < pixBytes; ++i) {
  30499. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30500. }
  30501. for (; i < rowBytes; ++i) {
  30502. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30503. rawBytes[i]) & 0xFF;
  30504. j++;
  30505. }
  30506. break;
  30507. case 4:
  30508. // we need to save the up left pixels values. the simplest way
  30509. // is to create a new buffer
  30510. for (i = 0; i < pixBytes; ++i) {
  30511. up = prevRow[i];
  30512. c = rawBytes[i];
  30513. buffer[j++] = up + c;
  30514. }
  30515. for (; i < rowBytes; ++i) {
  30516. up = prevRow[i];
  30517. var upLeft = prevRow[i - pixBytes];
  30518. var left = buffer[j - pixBytes];
  30519. var p = left + up - upLeft;
  30520. var pa = p - left;
  30521. if (pa < 0) {
  30522. pa = -pa;
  30523. }
  30524. var pb = p - up;
  30525. if (pb < 0) {
  30526. pb = -pb;
  30527. }
  30528. var pc = p - upLeft;
  30529. if (pc < 0) {
  30530. pc = -pc;
  30531. }
  30532. c = rawBytes[i];
  30533. if (pa <= pb && pa <= pc) {
  30534. buffer[j++] = left + c;
  30535. } else if (pb <= pc) {
  30536. buffer[j++] = up + c;
  30537. } else {
  30538. buffer[j++] = upLeft + c;
  30539. }
  30540. }
  30541. break;
  30542. default:
  30543. error('Unsupported predictor: ' + predictor);
  30544. }
  30545. this.bufferLength += rowBytes;
  30546. };
  30547. return PredictorStream;
  30548. })();
  30549. /**
  30550. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30551. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30552. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30553. * a library to decode these images and the stream behaves like all the other
  30554. * DecodeStreams.
  30555. */
  30556. var JpegStream = (function JpegStreamClosure() {
  30557. function JpegStream(stream, maybeLength, dict, xref) {
  30558. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30559. // Note: this seems to mainly affect inline images.
  30560. var ch;
  30561. while ((ch = stream.getByte()) !== -1) {
  30562. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30563. stream.skip(-1); // Reset the stream position to the SOI.
  30564. break;
  30565. }
  30566. }
  30567. this.stream = stream;
  30568. this.maybeLength = maybeLength;
  30569. this.dict = dict;
  30570. DecodeStream.call(this, maybeLength);
  30571. }
  30572. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30573. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30574. get: function JpegStream_bytes() {
  30575. // If this.maybeLength is null, we'll get the entire stream.
  30576. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30577. },
  30578. configurable: true
  30579. });
  30580. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30581. if (this.bufferLength) {
  30582. return;
  30583. }
  30584. try {
  30585. var jpegImage = new JpegImage();
  30586. // checking if values needs to be transformed before conversion
  30587. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30588. var decodeArr = this.dict.get('Decode');
  30589. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30590. var decodeArrLength = decodeArr.length;
  30591. var transform = new Int32Array(decodeArrLength);
  30592. var transformNeeded = false;
  30593. var maxValue = (1 << bitsPerComponent) - 1;
  30594. for (var i = 0; i < decodeArrLength; i += 2) {
  30595. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30596. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30597. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30598. transformNeeded = true;
  30599. }
  30600. }
  30601. if (transformNeeded) {
  30602. jpegImage.decodeTransform = transform;
  30603. }
  30604. }
  30605. jpegImage.parse(this.bytes);
  30606. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30607. this.forceRGB);
  30608. this.buffer = data;
  30609. this.bufferLength = data.length;
  30610. this.eof = true;
  30611. } catch (e) {
  30612. error('JPEG error: ' + e);
  30613. }
  30614. };
  30615. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30616. this.ensureBuffer();
  30617. return this.buffer;
  30618. };
  30619. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30620. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30621. };
  30622. /**
  30623. * Checks if the image can be decoded and displayed by the browser without any
  30624. * further processing such as color space conversions.
  30625. */
  30626. JpegStream.prototype.isNativelySupported =
  30627. function JpegStream_isNativelySupported(xref, res) {
  30628. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30629. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30630. };
  30631. /**
  30632. * Checks if the image can be decoded by the browser.
  30633. */
  30634. JpegStream.prototype.isNativelyDecodable =
  30635. function JpegStream_isNativelyDecodable(xref, res) {
  30636. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30637. var numComps = cs.numComps;
  30638. return numComps === 1 || numComps === 3;
  30639. };
  30640. return JpegStream;
  30641. })();
  30642. /**
  30643. * For JPEG 2000's we use a library to decode these images and
  30644. * the stream behaves like all the other DecodeStreams.
  30645. */
  30646. var JpxStream = (function JpxStreamClosure() {
  30647. function JpxStream(stream, maybeLength, dict) {
  30648. this.stream = stream;
  30649. this.maybeLength = maybeLength;
  30650. this.dict = dict;
  30651. DecodeStream.call(this, maybeLength);
  30652. }
  30653. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30654. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30655. get: function JpxStream_bytes() {
  30656. // If this.maybeLength is null, we'll get the entire stream.
  30657. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30658. },
  30659. configurable: true
  30660. });
  30661. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30662. if (this.bufferLength) {
  30663. return;
  30664. }
  30665. var jpxImage = new JpxImage();
  30666. jpxImage.parse(this.bytes);
  30667. var width = jpxImage.width;
  30668. var height = jpxImage.height;
  30669. var componentsCount = jpxImage.componentsCount;
  30670. var tileCount = jpxImage.tiles.length;
  30671. if (tileCount === 1) {
  30672. this.buffer = jpxImage.tiles[0].items;
  30673. } else {
  30674. var data = new Uint8Array(width * height * componentsCount);
  30675. for (var k = 0; k < tileCount; k++) {
  30676. var tileComponents = jpxImage.tiles[k];
  30677. var tileWidth = tileComponents.width;
  30678. var tileHeight = tileComponents.height;
  30679. var tileLeft = tileComponents.left;
  30680. var tileTop = tileComponents.top;
  30681. var src = tileComponents.items;
  30682. var srcPosition = 0;
  30683. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30684. var imgRowSize = width * componentsCount;
  30685. var tileRowSize = tileWidth * componentsCount;
  30686. for (var j = 0; j < tileHeight; j++) {
  30687. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30688. data.set(rowBytes, dataPosition);
  30689. srcPosition += tileRowSize;
  30690. dataPosition += imgRowSize;
  30691. }
  30692. }
  30693. this.buffer = data;
  30694. }
  30695. this.bufferLength = this.buffer.length;
  30696. this.eof = true;
  30697. };
  30698. return JpxStream;
  30699. })();
  30700. /**
  30701. * For JBIG2's we use a library to decode these images and
  30702. * the stream behaves like all the other DecodeStreams.
  30703. */
  30704. var Jbig2Stream = (function Jbig2StreamClosure() {
  30705. function Jbig2Stream(stream, maybeLength, dict) {
  30706. this.stream = stream;
  30707. this.maybeLength = maybeLength;
  30708. this.dict = dict;
  30709. DecodeStream.call(this, maybeLength);
  30710. }
  30711. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30712. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30713. get: function Jbig2Stream_bytes() {
  30714. // If this.maybeLength is null, we'll get the entire stream.
  30715. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30716. },
  30717. configurable: true
  30718. });
  30719. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30720. if (this.bufferLength) {
  30721. return;
  30722. }
  30723. var jbig2Image = new Jbig2Image();
  30724. var chunks = [], xref = this.dict.xref;
  30725. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30726. // According to the PDF specification, DecodeParms can be either
  30727. // a dictionary, or an array whose elements are dictionaries.
  30728. if (isArray(decodeParams)) {
  30729. if (decodeParams.length > 1) {
  30730. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30731. 'not supported.');
  30732. }
  30733. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30734. }
  30735. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30736. var globalsStream = decodeParams.get('JBIG2Globals');
  30737. var globals = globalsStream.getBytes();
  30738. chunks.push({data: globals, start: 0, end: globals.length});
  30739. }
  30740. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30741. var data = jbig2Image.parseChunks(chunks);
  30742. var dataLength = data.length;
  30743. // JBIG2 had black as 1 and white as 0, inverting the colors
  30744. for (var i = 0; i < dataLength; i++) {
  30745. data[i] ^= 0xFF;
  30746. }
  30747. this.buffer = data;
  30748. this.bufferLength = dataLength;
  30749. this.eof = true;
  30750. };
  30751. return Jbig2Stream;
  30752. })();
  30753. var DecryptStream = (function DecryptStreamClosure() {
  30754. function DecryptStream(str, maybeLength, decrypt) {
  30755. this.str = str;
  30756. this.dict = str.dict;
  30757. this.decrypt = decrypt;
  30758. this.nextChunk = null;
  30759. this.initialized = false;
  30760. DecodeStream.call(this, maybeLength);
  30761. }
  30762. var chunkSize = 512;
  30763. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30764. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30765. var chunk;
  30766. if (this.initialized) {
  30767. chunk = this.nextChunk;
  30768. } else {
  30769. chunk = this.str.getBytes(chunkSize);
  30770. this.initialized = true;
  30771. }
  30772. if (!chunk || chunk.length === 0) {
  30773. this.eof = true;
  30774. return;
  30775. }
  30776. this.nextChunk = this.str.getBytes(chunkSize);
  30777. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30778. var decrypt = this.decrypt;
  30779. chunk = decrypt(chunk, !hasMoreData);
  30780. var bufferLength = this.bufferLength;
  30781. var i, n = chunk.length;
  30782. var buffer = this.ensureBuffer(bufferLength + n);
  30783. for (i = 0; i < n; i++) {
  30784. buffer[bufferLength++] = chunk[i];
  30785. }
  30786. this.bufferLength = bufferLength;
  30787. };
  30788. return DecryptStream;
  30789. })();
  30790. var Ascii85Stream = (function Ascii85StreamClosure() {
  30791. function Ascii85Stream(str, maybeLength) {
  30792. this.str = str;
  30793. this.dict = str.dict;
  30794. this.input = new Uint8Array(5);
  30795. // Most streams increase in size when decoded, but Ascii85 streams
  30796. // typically shrink by ~20%.
  30797. if (maybeLength) {
  30798. maybeLength = 0.8 * maybeLength;
  30799. }
  30800. DecodeStream.call(this, maybeLength);
  30801. }
  30802. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30803. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30804. var TILDA_CHAR = 0x7E; // '~'
  30805. var Z_LOWER_CHAR = 0x7A; // 'z'
  30806. var EOF = -1;
  30807. var str = this.str;
  30808. var c = str.getByte();
  30809. while (Lexer.isSpace(c)) {
  30810. c = str.getByte();
  30811. }
  30812. if (c === EOF || c === TILDA_CHAR) {
  30813. this.eof = true;
  30814. return;
  30815. }
  30816. var bufferLength = this.bufferLength, buffer;
  30817. var i;
  30818. // special code for z
  30819. if (c === Z_LOWER_CHAR) {
  30820. buffer = this.ensureBuffer(bufferLength + 4);
  30821. for (i = 0; i < 4; ++i) {
  30822. buffer[bufferLength + i] = 0;
  30823. }
  30824. this.bufferLength += 4;
  30825. } else {
  30826. var input = this.input;
  30827. input[0] = c;
  30828. for (i = 1; i < 5; ++i) {
  30829. c = str.getByte();
  30830. while (Lexer.isSpace(c)) {
  30831. c = str.getByte();
  30832. }
  30833. input[i] = c;
  30834. if (c === EOF || c === TILDA_CHAR) {
  30835. break;
  30836. }
  30837. }
  30838. buffer = this.ensureBuffer(bufferLength + i - 1);
  30839. this.bufferLength += i - 1;
  30840. // partial ending;
  30841. if (i < 5) {
  30842. for (; i < 5; ++i) {
  30843. input[i] = 0x21 + 84;
  30844. }
  30845. this.eof = true;
  30846. }
  30847. var t = 0;
  30848. for (i = 0; i < 5; ++i) {
  30849. t = t * 85 + (input[i] - 0x21);
  30850. }
  30851. for (i = 3; i >= 0; --i) {
  30852. buffer[bufferLength + i] = t & 0xFF;
  30853. t >>= 8;
  30854. }
  30855. }
  30856. };
  30857. return Ascii85Stream;
  30858. })();
  30859. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30860. function AsciiHexStream(str, maybeLength) {
  30861. this.str = str;
  30862. this.dict = str.dict;
  30863. this.firstDigit = -1;
  30864. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30865. // by 50%.
  30866. if (maybeLength) {
  30867. maybeLength = 0.5 * maybeLength;
  30868. }
  30869. DecodeStream.call(this, maybeLength);
  30870. }
  30871. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30872. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30873. var UPSTREAM_BLOCK_SIZE = 8000;
  30874. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30875. if (!bytes.length) {
  30876. this.eof = true;
  30877. return;
  30878. }
  30879. var maxDecodeLength = (bytes.length + 1) >> 1;
  30880. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30881. var bufferLength = this.bufferLength;
  30882. var firstDigit = this.firstDigit;
  30883. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30884. var ch = bytes[i], digit;
  30885. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30886. digit = ch & 0x0F;
  30887. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30888. // 'A'-'Z', 'a'-'z'
  30889. digit = (ch & 0x0F) + 9;
  30890. } else if (ch === 0x3E) { // '>'
  30891. this.eof = true;
  30892. break;
  30893. } else { // probably whitespace
  30894. continue; // ignoring
  30895. }
  30896. if (firstDigit < 0) {
  30897. firstDigit = digit;
  30898. } else {
  30899. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30900. firstDigit = -1;
  30901. }
  30902. }
  30903. if (firstDigit >= 0 && this.eof) {
  30904. // incomplete byte
  30905. buffer[bufferLength++] = (firstDigit << 4);
  30906. firstDigit = -1;
  30907. }
  30908. this.firstDigit = firstDigit;
  30909. this.bufferLength = bufferLength;
  30910. };
  30911. return AsciiHexStream;
  30912. })();
  30913. var RunLengthStream = (function RunLengthStreamClosure() {
  30914. function RunLengthStream(str, maybeLength) {
  30915. this.str = str;
  30916. this.dict = str.dict;
  30917. DecodeStream.call(this, maybeLength);
  30918. }
  30919. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30920. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30921. // The repeatHeader has following format. The first byte defines type of run
  30922. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30923. // (in addition to the second byte from the header), n = 129 through 255 -
  30924. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30925. var repeatHeader = this.str.getBytes(2);
  30926. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30927. this.eof = true;
  30928. return;
  30929. }
  30930. var buffer;
  30931. var bufferLength = this.bufferLength;
  30932. var n = repeatHeader[0];
  30933. if (n < 128) {
  30934. // copy n bytes
  30935. buffer = this.ensureBuffer(bufferLength + n + 1);
  30936. buffer[bufferLength++] = repeatHeader[1];
  30937. if (n > 0) {
  30938. var source = this.str.getBytes(n);
  30939. buffer.set(source, bufferLength);
  30940. bufferLength += n;
  30941. }
  30942. } else {
  30943. n = 257 - n;
  30944. var b = repeatHeader[1];
  30945. buffer = this.ensureBuffer(bufferLength + n + 1);
  30946. for (var i = 0; i < n; i++) {
  30947. buffer[bufferLength++] = b;
  30948. }
  30949. }
  30950. this.bufferLength = bufferLength;
  30951. };
  30952. return RunLengthStream;
  30953. })();
  30954. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30955. var ccittEOL = -2;
  30956. var twoDimPass = 0;
  30957. var twoDimHoriz = 1;
  30958. var twoDimVert0 = 2;
  30959. var twoDimVertR1 = 3;
  30960. var twoDimVertL1 = 4;
  30961. var twoDimVertR2 = 5;
  30962. var twoDimVertL2 = 6;
  30963. var twoDimVertR3 = 7;
  30964. var twoDimVertL3 = 8;
  30965. var twoDimTable = [
  30966. [-1, -1], [-1, -1], // 000000x
  30967. [7, twoDimVertL3], // 0000010
  30968. [7, twoDimVertR3], // 0000011
  30969. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30970. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30971. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30972. [4, twoDimPass], [4, twoDimPass],
  30973. [4, twoDimPass], [4, twoDimPass],
  30974. [4, twoDimPass], [4, twoDimPass],
  30975. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30976. [3, twoDimHoriz], [3, twoDimHoriz],
  30977. [3, twoDimHoriz], [3, twoDimHoriz],
  30978. [3, twoDimHoriz], [3, twoDimHoriz],
  30979. [3, twoDimHoriz], [3, twoDimHoriz],
  30980. [3, twoDimHoriz], [3, twoDimHoriz],
  30981. [3, twoDimHoriz], [3, twoDimHoriz],
  30982. [3, twoDimHoriz], [3, twoDimHoriz],
  30983. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30984. [3, twoDimVertL1], [3, twoDimVertL1],
  30985. [3, twoDimVertL1], [3, twoDimVertL1],
  30986. [3, twoDimVertL1], [3, twoDimVertL1],
  30987. [3, twoDimVertL1], [3, twoDimVertL1],
  30988. [3, twoDimVertL1], [3, twoDimVertL1],
  30989. [3, twoDimVertL1], [3, twoDimVertL1],
  30990. [3, twoDimVertL1], [3, twoDimVertL1],
  30991. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30992. [3, twoDimVertR1], [3, twoDimVertR1],
  30993. [3, twoDimVertR1], [3, twoDimVertR1],
  30994. [3, twoDimVertR1], [3, twoDimVertR1],
  30995. [3, twoDimVertR1], [3, twoDimVertR1],
  30996. [3, twoDimVertR1], [3, twoDimVertR1],
  30997. [3, twoDimVertR1], [3, twoDimVertR1],
  30998. [3, twoDimVertR1], [3, twoDimVertR1],
  30999. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  31000. [1, twoDimVert0], [1, twoDimVert0],
  31001. [1, twoDimVert0], [1, twoDimVert0],
  31002. [1, twoDimVert0], [1, twoDimVert0],
  31003. [1, twoDimVert0], [1, twoDimVert0],
  31004. [1, twoDimVert0], [1, twoDimVert0],
  31005. [1, twoDimVert0], [1, twoDimVert0],
  31006. [1, twoDimVert0], [1, twoDimVert0],
  31007. [1, twoDimVert0], [1, twoDimVert0],
  31008. [1, twoDimVert0], [1, twoDimVert0],
  31009. [1, twoDimVert0], [1, twoDimVert0],
  31010. [1, twoDimVert0], [1, twoDimVert0],
  31011. [1, twoDimVert0], [1, twoDimVert0],
  31012. [1, twoDimVert0], [1, twoDimVert0],
  31013. [1, twoDimVert0], [1, twoDimVert0],
  31014. [1, twoDimVert0], [1, twoDimVert0],
  31015. [1, twoDimVert0], [1, twoDimVert0],
  31016. [1, twoDimVert0], [1, twoDimVert0],
  31017. [1, twoDimVert0], [1, twoDimVert0],
  31018. [1, twoDimVert0], [1, twoDimVert0],
  31019. [1, twoDimVert0], [1, twoDimVert0],
  31020. [1, twoDimVert0], [1, twoDimVert0],
  31021. [1, twoDimVert0], [1, twoDimVert0],
  31022. [1, twoDimVert0], [1, twoDimVert0],
  31023. [1, twoDimVert0], [1, twoDimVert0],
  31024. [1, twoDimVert0], [1, twoDimVert0],
  31025. [1, twoDimVert0], [1, twoDimVert0],
  31026. [1, twoDimVert0], [1, twoDimVert0],
  31027. [1, twoDimVert0], [1, twoDimVert0],
  31028. [1, twoDimVert0], [1, twoDimVert0],
  31029. [1, twoDimVert0], [1, twoDimVert0],
  31030. [1, twoDimVert0], [1, twoDimVert0]
  31031. ];
  31032. var whiteTable1 = [
  31033. [-1, -1], // 00000
  31034. [12, ccittEOL], // 00001
  31035. [-1, -1], [-1, -1], // 0001x
  31036. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  31037. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  31038. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  31039. [11, 1792], [11, 1792], // 1000x
  31040. [12, 1984], // 10010
  31041. [12, 2048], // 10011
  31042. [12, 2112], // 10100
  31043. [12, 2176], // 10101
  31044. [12, 2240], // 10110
  31045. [12, 2304], // 10111
  31046. [11, 1856], [11, 1856], // 1100x
  31047. [11, 1920], [11, 1920], // 1101x
  31048. [12, 2368], // 11100
  31049. [12, 2432], // 11101
  31050. [12, 2496], // 11110
  31051. [12, 2560] // 11111
  31052. ];
  31053. var whiteTable2 = [
  31054. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  31055. [8, 29], [8, 29], // 00000010x
  31056. [8, 30], [8, 30], // 00000011x
  31057. [8, 45], [8, 45], // 00000100x
  31058. [8, 46], [8, 46], // 00000101x
  31059. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  31060. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  31061. [8, 47], [8, 47], // 00001010x
  31062. [8, 48], [8, 48], // 00001011x
  31063. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  31064. [6, 13], [6, 13], [6, 13], [6, 13],
  31065. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  31066. [8, 33], [8, 33], // 00010010x
  31067. [8, 34], [8, 34], // 00010011x
  31068. [8, 35], [8, 35], // 00010100x
  31069. [8, 36], [8, 36], // 00010101x
  31070. [8, 37], [8, 37], // 00010110x
  31071. [8, 38], [8, 38], // 00010111x
  31072. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  31073. [8, 31], [8, 31], // 00011010x
  31074. [8, 32], [8, 32], // 00011011x
  31075. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  31076. [6, 1], [6, 1], [6, 1], [6, 1],
  31077. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  31078. [6, 12], [6, 12], [6, 12], [6, 12],
  31079. [8, 53], [8, 53], // 00100100x
  31080. [8, 54], [8, 54], // 00100101x
  31081. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  31082. [8, 39], [8, 39], // 00101000x
  31083. [8, 40], [8, 40], // 00101001x
  31084. [8, 41], [8, 41], // 00101010x
  31085. [8, 42], [8, 42], // 00101011x
  31086. [8, 43], [8, 43], // 00101100x
  31087. [8, 44], [8, 44], // 00101101x
  31088. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  31089. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  31090. [8, 61], [8, 61], // 00110010x
  31091. [8, 62], [8, 62], // 00110011x
  31092. [8, 63], [8, 63], // 00110100x
  31093. [8, 0], [8, 0], // 00110101x
  31094. [8, 320], [8, 320], // 00110110x
  31095. [8, 384], [8, 384], // 00110111x
  31096. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  31097. [5, 10], [5, 10], [5, 10], [5, 10],
  31098. [5, 10], [5, 10], [5, 10], [5, 10],
  31099. [5, 10], [5, 10], [5, 10], [5, 10],
  31100. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  31101. [5, 11], [5, 11], [5, 11], [5, 11],
  31102. [5, 11], [5, 11], [5, 11], [5, 11],
  31103. [5, 11], [5, 11], [5, 11], [5, 11],
  31104. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  31105. [8, 59], [8, 59], // 01001010x
  31106. [8, 60], [8, 60], // 01001011x
  31107. [9, 1472], // 010011000
  31108. [9, 1536], // 010011001
  31109. [9, 1600], // 010011010
  31110. [9, 1728], // 010011011
  31111. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  31112. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  31113. [8, 49], [8, 49], // 01010010x
  31114. [8, 50], [8, 50], // 01010011x
  31115. [8, 51], [8, 51], // 01010100x
  31116. [8, 52], [8, 52], // 01010101x
  31117. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  31118. [8, 55], [8, 55], // 01011000x
  31119. [8, 56], [8, 56], // 01011001x
  31120. [8, 57], [8, 57], // 01011010x
  31121. [8, 58], [8, 58], // 01011011x
  31122. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  31123. [6, 192], [6, 192], [6, 192], [6, 192],
  31124. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  31125. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  31126. [8, 448], [8, 448], // 01100100x
  31127. [8, 512], [8, 512], // 01100101x
  31128. [9, 704], // 011001100
  31129. [9, 768], // 011001101
  31130. [8, 640], [8, 640], // 01100111x
  31131. [8, 576], [8, 576], // 01101000x
  31132. [9, 832], // 011010010
  31133. [9, 896], // 011010011
  31134. [9, 960], // 011010100
  31135. [9, 1024], // 011010101
  31136. [9, 1088], // 011010110
  31137. [9, 1152], // 011010111
  31138. [9, 1216], // 011011000
  31139. [9, 1280], // 011011001
  31140. [9, 1344], // 011011010
  31141. [9, 1408], // 011011011
  31142. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  31143. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  31144. [4, 2], [4, 2], [4, 2], [4, 2],
  31145. [4, 2], [4, 2], [4, 2], [4, 2],
  31146. [4, 2], [4, 2], [4, 2], [4, 2],
  31147. [4, 2], [4, 2], [4, 2], [4, 2],
  31148. [4, 2], [4, 2], [4, 2], [4, 2],
  31149. [4, 2], [4, 2], [4, 2], [4, 2],
  31150. [4, 2], [4, 2], [4, 2], [4, 2],
  31151. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  31152. [4, 3], [4, 3], [4, 3], [4, 3],
  31153. [4, 3], [4, 3], [4, 3], [4, 3],
  31154. [4, 3], [4, 3], [4, 3], [4, 3],
  31155. [4, 3], [4, 3], [4, 3], [4, 3],
  31156. [4, 3], [4, 3], [4, 3], [4, 3],
  31157. [4, 3], [4, 3], [4, 3], [4, 3],
  31158. [4, 3], [4, 3], [4, 3], [4, 3],
  31159. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  31160. [5, 128], [5, 128], [5, 128], [5, 128],
  31161. [5, 128], [5, 128], [5, 128], [5, 128],
  31162. [5, 128], [5, 128], [5, 128], [5, 128],
  31163. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  31164. [5, 8], [5, 8], [5, 8], [5, 8],
  31165. [5, 8], [5, 8], [5, 8], [5, 8],
  31166. [5, 8], [5, 8], [5, 8], [5, 8],
  31167. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  31168. [5, 9], [5, 9], [5, 9], [5, 9],
  31169. [5, 9], [5, 9], [5, 9], [5, 9],
  31170. [5, 9], [5, 9], [5, 9], [5, 9],
  31171. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  31172. [6, 16], [6, 16], [6, 16], [6, 16],
  31173. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  31174. [6, 17], [6, 17], [6, 17], [6, 17],
  31175. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  31176. [4, 4], [4, 4], [4, 4], [4, 4],
  31177. [4, 4], [4, 4], [4, 4], [4, 4],
  31178. [4, 4], [4, 4], [4, 4], [4, 4],
  31179. [4, 4], [4, 4], [4, 4], [4, 4],
  31180. [4, 4], [4, 4], [4, 4], [4, 4],
  31181. [4, 4], [4, 4], [4, 4], [4, 4],
  31182. [4, 4], [4, 4], [4, 4], [4, 4],
  31183. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  31184. [4, 5], [4, 5], [4, 5], [4, 5],
  31185. [4, 5], [4, 5], [4, 5], [4, 5],
  31186. [4, 5], [4, 5], [4, 5], [4, 5],
  31187. [4, 5], [4, 5], [4, 5], [4, 5],
  31188. [4, 5], [4, 5], [4, 5], [4, 5],
  31189. [4, 5], [4, 5], [4, 5], [4, 5],
  31190. [4, 5], [4, 5], [4, 5], [4, 5],
  31191. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  31192. [6, 14], [6, 14], [6, 14], [6, 14],
  31193. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  31194. [6, 15], [6, 15], [6, 15], [6, 15],
  31195. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  31196. [5, 64], [5, 64], [5, 64], [5, 64],
  31197. [5, 64], [5, 64], [5, 64], [5, 64],
  31198. [5, 64], [5, 64], [5, 64], [5, 64],
  31199. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  31200. [4, 6], [4, 6], [4, 6], [4, 6],
  31201. [4, 6], [4, 6], [4, 6], [4, 6],
  31202. [4, 6], [4, 6], [4, 6], [4, 6],
  31203. [4, 6], [4, 6], [4, 6], [4, 6],
  31204. [4, 6], [4, 6], [4, 6], [4, 6],
  31205. [4, 6], [4, 6], [4, 6], [4, 6],
  31206. [4, 6], [4, 6], [4, 6], [4, 6],
  31207. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  31208. [4, 7], [4, 7], [4, 7], [4, 7],
  31209. [4, 7], [4, 7], [4, 7], [4, 7],
  31210. [4, 7], [4, 7], [4, 7], [4, 7],
  31211. [4, 7], [4, 7], [4, 7], [4, 7],
  31212. [4, 7], [4, 7], [4, 7], [4, 7],
  31213. [4, 7], [4, 7], [4, 7], [4, 7],
  31214. [4, 7], [4, 7], [4, 7], [4, 7]
  31215. ];
  31216. var blackTable1 = [
  31217. [-1, -1], [-1, -1], // 000000000000x
  31218. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  31219. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  31220. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  31221. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  31222. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  31223. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  31224. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  31225. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  31226. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  31227. [12, 1984], [12, 1984], // 000000010010x
  31228. [12, 2048], [12, 2048], // 000000010011x
  31229. [12, 2112], [12, 2112], // 000000010100x
  31230. [12, 2176], [12, 2176], // 000000010101x
  31231. [12, 2240], [12, 2240], // 000000010110x
  31232. [12, 2304], [12, 2304], // 000000010111x
  31233. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  31234. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  31235. [12, 2368], [12, 2368], // 000000011100x
  31236. [12, 2432], [12, 2432], // 000000011101x
  31237. [12, 2496], [12, 2496], // 000000011110x
  31238. [12, 2560], [12, 2560], // 000000011111x
  31239. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  31240. [10, 18], [10, 18], [10, 18], [10, 18],
  31241. [12, 52], [12, 52], // 000000100100x
  31242. [13, 640], // 0000001001010
  31243. [13, 704], // 0000001001011
  31244. [13, 768], // 0000001001100
  31245. [13, 832], // 0000001001101
  31246. [12, 55], [12, 55], // 000000100111x
  31247. [12, 56], [12, 56], // 000000101000x
  31248. [13, 1280], // 0000001010010
  31249. [13, 1344], // 0000001010011
  31250. [13, 1408], // 0000001010100
  31251. [13, 1472], // 0000001010101
  31252. [12, 59], [12, 59], // 000000101011x
  31253. [12, 60], [12, 60], // 000000101100x
  31254. [13, 1536], // 0000001011010
  31255. [13, 1600], // 0000001011011
  31256. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31257. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31258. [13, 1664], // 0000001100100
  31259. [13, 1728], // 0000001100101
  31260. [12, 320], [12, 320], // 000000110011x
  31261. [12, 384], [12, 384], // 000000110100x
  31262. [12, 448], [12, 448], // 000000110101x
  31263. [13, 512], // 0000001101100
  31264. [13, 576], // 0000001101101
  31265. [12, 53], [12, 53], // 000000110111x
  31266. [12, 54], [12, 54], // 000000111000x
  31267. [13, 896], // 0000001110010
  31268. [13, 960], // 0000001110011
  31269. [13, 1024], // 0000001110100
  31270. [13, 1088], // 0000001110101
  31271. [13, 1152], // 0000001110110
  31272. [13, 1216], // 0000001110111
  31273. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31274. [10, 64], [10, 64], [10, 64], [10, 64]
  31275. ];
  31276. var blackTable2 = [
  31277. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31278. [8, 13], [8, 13], [8, 13], [8, 13],
  31279. [8, 13], [8, 13], [8, 13], [8, 13],
  31280. [8, 13], [8, 13], [8, 13], [8, 13],
  31281. [11, 23], [11, 23], // 00000101000x
  31282. [12, 50], // 000001010010
  31283. [12, 51], // 000001010011
  31284. [12, 44], // 000001010100
  31285. [12, 45], // 000001010101
  31286. [12, 46], // 000001010110
  31287. [12, 47], // 000001010111
  31288. [12, 57], // 000001011000
  31289. [12, 58], // 000001011001
  31290. [12, 61], // 000001011010
  31291. [12, 256], // 000001011011
  31292. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31293. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31294. [12, 48], // 000001100100
  31295. [12, 49], // 000001100101
  31296. [12, 62], // 000001100110
  31297. [12, 63], // 000001100111
  31298. [12, 30], // 000001101000
  31299. [12, 31], // 000001101001
  31300. [12, 32], // 000001101010
  31301. [12, 33], // 000001101011
  31302. [12, 40], // 000001101100
  31303. [12, 41], // 000001101101
  31304. [11, 22], [11, 22], // 00000110111x
  31305. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31306. [8, 14], [8, 14], [8, 14], [8, 14],
  31307. [8, 14], [8, 14], [8, 14], [8, 14],
  31308. [8, 14], [8, 14], [8, 14], [8, 14],
  31309. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31310. [7, 10], [7, 10], [7, 10], [7, 10],
  31311. [7, 10], [7, 10], [7, 10], [7, 10],
  31312. [7, 10], [7, 10], [7, 10], [7, 10],
  31313. [7, 10], [7, 10], [7, 10], [7, 10],
  31314. [7, 10], [7, 10], [7, 10], [7, 10],
  31315. [7, 10], [7, 10], [7, 10], [7, 10],
  31316. [7, 10], [7, 10], [7, 10], [7, 10],
  31317. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31318. [7, 11], [7, 11], [7, 11], [7, 11],
  31319. [7, 11], [7, 11], [7, 11], [7, 11],
  31320. [7, 11], [7, 11], [7, 11], [7, 11],
  31321. [7, 11], [7, 11], [7, 11], [7, 11],
  31322. [7, 11], [7, 11], [7, 11], [7, 11],
  31323. [7, 11], [7, 11], [7, 11], [7, 11],
  31324. [7, 11], [7, 11], [7, 11], [7, 11],
  31325. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31326. [9, 15], [9, 15], [9, 15], [9, 15],
  31327. [12, 128], // 000011001000
  31328. [12, 192], // 000011001001
  31329. [12, 26], // 000011001010
  31330. [12, 27], // 000011001011
  31331. [12, 28], // 000011001100
  31332. [12, 29], // 000011001101
  31333. [11, 19], [11, 19], // 00001100111x
  31334. [11, 20], [11, 20], // 00001101000x
  31335. [12, 34], // 000011010010
  31336. [12, 35], // 000011010011
  31337. [12, 36], // 000011010100
  31338. [12, 37], // 000011010101
  31339. [12, 38], // 000011010110
  31340. [12, 39], // 000011010111
  31341. [11, 21], [11, 21], // 00001101100x
  31342. [12, 42], // 000011011010
  31343. [12, 43], // 000011011011
  31344. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31345. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31346. [7, 12], [7, 12], [7, 12], [7, 12],
  31347. [7, 12], [7, 12], [7, 12], [7, 12],
  31348. [7, 12], [7, 12], [7, 12], [7, 12],
  31349. [7, 12], [7, 12], [7, 12], [7, 12],
  31350. [7, 12], [7, 12], [7, 12], [7, 12],
  31351. [7, 12], [7, 12], [7, 12], [7, 12],
  31352. [7, 12], [7, 12], [7, 12], [7, 12]
  31353. ];
  31354. var blackTable3 = [
  31355. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31356. [6, 9], // 000100
  31357. [6, 8], // 000101
  31358. [5, 7], [5, 7], // 00011x
  31359. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31360. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31361. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31362. [3, 1], [3, 1], [3, 1], [3, 1],
  31363. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31364. [3, 4], [3, 4], [3, 4], [3, 4],
  31365. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31366. [2, 3], [2, 3], [2, 3], [2, 3],
  31367. [2, 3], [2, 3], [2, 3], [2, 3],
  31368. [2, 3], [2, 3], [2, 3], [2, 3],
  31369. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31370. [2, 2], [2, 2], [2, 2], [2, 2],
  31371. [2, 2], [2, 2], [2, 2], [2, 2],
  31372. [2, 2], [2, 2], [2, 2], [2, 2]
  31373. ];
  31374. function CCITTFaxStream(str, maybeLength, params) {
  31375. this.str = str;
  31376. this.dict = str.dict;
  31377. params = params || Dict.empty;
  31378. this.encoding = params.get('K') || 0;
  31379. this.eoline = params.get('EndOfLine') || false;
  31380. this.byteAlign = params.get('EncodedByteAlign') || false;
  31381. this.columns = params.get('Columns') || 1728;
  31382. this.rows = params.get('Rows') || 0;
  31383. var eoblock = params.get('EndOfBlock');
  31384. if (eoblock === null || eoblock === undefined) {
  31385. eoblock = true;
  31386. }
  31387. this.eoblock = eoblock;
  31388. this.black = params.get('BlackIs1') || false;
  31389. this.codingLine = new Uint32Array(this.columns + 1);
  31390. this.refLine = new Uint32Array(this.columns + 2);
  31391. this.codingLine[0] = this.columns;
  31392. this.codingPos = 0;
  31393. this.row = 0;
  31394. this.nextLine2D = this.encoding < 0;
  31395. this.inputBits = 0;
  31396. this.inputBuf = 0;
  31397. this.outputBits = 0;
  31398. var code1;
  31399. while ((code1 = this.lookBits(12)) === 0) {
  31400. this.eatBits(1);
  31401. }
  31402. if (code1 === 1) {
  31403. this.eatBits(12);
  31404. }
  31405. if (this.encoding > 0) {
  31406. this.nextLine2D = !this.lookBits(1);
  31407. this.eatBits(1);
  31408. }
  31409. DecodeStream.call(this, maybeLength);
  31410. }
  31411. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31412. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31413. while (!this.eof) {
  31414. var c = this.lookChar();
  31415. this.ensureBuffer(this.bufferLength + 1);
  31416. this.buffer[this.bufferLength++] = c;
  31417. }
  31418. };
  31419. CCITTFaxStream.prototype.addPixels =
  31420. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31421. var codingLine = this.codingLine;
  31422. var codingPos = this.codingPos;
  31423. if (a1 > codingLine[codingPos]) {
  31424. if (a1 > this.columns) {
  31425. info('row is wrong length');
  31426. this.err = true;
  31427. a1 = this.columns;
  31428. }
  31429. if ((codingPos & 1) ^ blackPixels) {
  31430. ++codingPos;
  31431. }
  31432. codingLine[codingPos] = a1;
  31433. }
  31434. this.codingPos = codingPos;
  31435. };
  31436. CCITTFaxStream.prototype.addPixelsNeg =
  31437. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31438. var codingLine = this.codingLine;
  31439. var codingPos = this.codingPos;
  31440. if (a1 > codingLine[codingPos]) {
  31441. if (a1 > this.columns) {
  31442. info('row is wrong length');
  31443. this.err = true;
  31444. a1 = this.columns;
  31445. }
  31446. if ((codingPos & 1) ^ blackPixels) {
  31447. ++codingPos;
  31448. }
  31449. codingLine[codingPos] = a1;
  31450. } else if (a1 < codingLine[codingPos]) {
  31451. if (a1 < 0) {
  31452. info('invalid code');
  31453. this.err = true;
  31454. a1 = 0;
  31455. }
  31456. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31457. --codingPos;
  31458. }
  31459. codingLine[codingPos] = a1;
  31460. }
  31461. this.codingPos = codingPos;
  31462. };
  31463. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31464. var refLine = this.refLine;
  31465. var codingLine = this.codingLine;
  31466. var columns = this.columns;
  31467. var refPos, blackPixels, bits, i;
  31468. if (this.outputBits === 0) {
  31469. if (this.eof) {
  31470. return null;
  31471. }
  31472. this.err = false;
  31473. var code1, code2, code3;
  31474. if (this.nextLine2D) {
  31475. for (i = 0; codingLine[i] < columns; ++i) {
  31476. refLine[i] = codingLine[i];
  31477. }
  31478. refLine[i++] = columns;
  31479. refLine[i] = columns;
  31480. codingLine[0] = 0;
  31481. this.codingPos = 0;
  31482. refPos = 0;
  31483. blackPixels = 0;
  31484. while (codingLine[this.codingPos] < columns) {
  31485. code1 = this.getTwoDimCode();
  31486. switch (code1) {
  31487. case twoDimPass:
  31488. this.addPixels(refLine[refPos + 1], blackPixels);
  31489. if (refLine[refPos + 1] < columns) {
  31490. refPos += 2;
  31491. }
  31492. break;
  31493. case twoDimHoriz:
  31494. code1 = code2 = 0;
  31495. if (blackPixels) {
  31496. do {
  31497. code1 += (code3 = this.getBlackCode());
  31498. } while (code3 >= 64);
  31499. do {
  31500. code2 += (code3 = this.getWhiteCode());
  31501. } while (code3 >= 64);
  31502. } else {
  31503. do {
  31504. code1 += (code3 = this.getWhiteCode());
  31505. } while (code3 >= 64);
  31506. do {
  31507. code2 += (code3 = this.getBlackCode());
  31508. } while (code3 >= 64);
  31509. }
  31510. this.addPixels(codingLine[this.codingPos] +
  31511. code1, blackPixels);
  31512. if (codingLine[this.codingPos] < columns) {
  31513. this.addPixels(codingLine[this.codingPos] + code2,
  31514. blackPixels ^ 1);
  31515. }
  31516. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31517. refLine[refPos] < columns) {
  31518. refPos += 2;
  31519. }
  31520. break;
  31521. case twoDimVertR3:
  31522. this.addPixels(refLine[refPos] + 3, blackPixels);
  31523. blackPixels ^= 1;
  31524. if (codingLine[this.codingPos] < columns) {
  31525. ++refPos;
  31526. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31527. refLine[refPos] < columns) {
  31528. refPos += 2;
  31529. }
  31530. }
  31531. break;
  31532. case twoDimVertR2:
  31533. this.addPixels(refLine[refPos] + 2, blackPixels);
  31534. blackPixels ^= 1;
  31535. if (codingLine[this.codingPos] < columns) {
  31536. ++refPos;
  31537. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31538. refLine[refPos] < columns) {
  31539. refPos += 2;
  31540. }
  31541. }
  31542. break;
  31543. case twoDimVertR1:
  31544. this.addPixels(refLine[refPos] + 1, blackPixels);
  31545. blackPixels ^= 1;
  31546. if (codingLine[this.codingPos] < columns) {
  31547. ++refPos;
  31548. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31549. refLine[refPos] < columns) {
  31550. refPos += 2;
  31551. }
  31552. }
  31553. break;
  31554. case twoDimVert0:
  31555. this.addPixels(refLine[refPos], blackPixels);
  31556. blackPixels ^= 1;
  31557. if (codingLine[this.codingPos] < columns) {
  31558. ++refPos;
  31559. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31560. refLine[refPos] < columns) {
  31561. refPos += 2;
  31562. }
  31563. }
  31564. break;
  31565. case twoDimVertL3:
  31566. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31567. blackPixels ^= 1;
  31568. if (codingLine[this.codingPos] < columns) {
  31569. if (refPos > 0) {
  31570. --refPos;
  31571. } else {
  31572. ++refPos;
  31573. }
  31574. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31575. refLine[refPos] < columns) {
  31576. refPos += 2;
  31577. }
  31578. }
  31579. break;
  31580. case twoDimVertL2:
  31581. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31582. blackPixels ^= 1;
  31583. if (codingLine[this.codingPos] < columns) {
  31584. if (refPos > 0) {
  31585. --refPos;
  31586. } else {
  31587. ++refPos;
  31588. }
  31589. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31590. refLine[refPos] < columns) {
  31591. refPos += 2;
  31592. }
  31593. }
  31594. break;
  31595. case twoDimVertL1:
  31596. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31597. blackPixels ^= 1;
  31598. if (codingLine[this.codingPos] < columns) {
  31599. if (refPos > 0) {
  31600. --refPos;
  31601. } else {
  31602. ++refPos;
  31603. }
  31604. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31605. refLine[refPos] < columns) {
  31606. refPos += 2;
  31607. }
  31608. }
  31609. break;
  31610. case EOF:
  31611. this.addPixels(columns, 0);
  31612. this.eof = true;
  31613. break;
  31614. default:
  31615. info('bad 2d code');
  31616. this.addPixels(columns, 0);
  31617. this.err = true;
  31618. }
  31619. }
  31620. } else {
  31621. codingLine[0] = 0;
  31622. this.codingPos = 0;
  31623. blackPixels = 0;
  31624. while (codingLine[this.codingPos] < columns) {
  31625. code1 = 0;
  31626. if (blackPixels) {
  31627. do {
  31628. code1 += (code3 = this.getBlackCode());
  31629. } while (code3 >= 64);
  31630. } else {
  31631. do {
  31632. code1 += (code3 = this.getWhiteCode());
  31633. } while (code3 >= 64);
  31634. }
  31635. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31636. blackPixels ^= 1;
  31637. }
  31638. }
  31639. var gotEOL = false;
  31640. if (this.byteAlign) {
  31641. this.inputBits &= ~7;
  31642. }
  31643. if (!this.eoblock && this.row === this.rows - 1) {
  31644. this.eof = true;
  31645. } else {
  31646. code1 = this.lookBits(12);
  31647. if (this.eoline) {
  31648. while (code1 !== EOF && code1 !== 1) {
  31649. this.eatBits(1);
  31650. code1 = this.lookBits(12);
  31651. }
  31652. } else {
  31653. while (code1 === 0) {
  31654. this.eatBits(1);
  31655. code1 = this.lookBits(12);
  31656. }
  31657. }
  31658. if (code1 === 1) {
  31659. this.eatBits(12);
  31660. gotEOL = true;
  31661. } else if (code1 === EOF) {
  31662. this.eof = true;
  31663. }
  31664. }
  31665. if (!this.eof && this.encoding > 0) {
  31666. this.nextLine2D = !this.lookBits(1);
  31667. this.eatBits(1);
  31668. }
  31669. if (this.eoblock && gotEOL && this.byteAlign) {
  31670. code1 = this.lookBits(12);
  31671. if (code1 === 1) {
  31672. this.eatBits(12);
  31673. if (this.encoding > 0) {
  31674. this.lookBits(1);
  31675. this.eatBits(1);
  31676. }
  31677. if (this.encoding >= 0) {
  31678. for (i = 0; i < 4; ++i) {
  31679. code1 = this.lookBits(12);
  31680. if (code1 !== 1) {
  31681. info('bad rtc code: ' + code1);
  31682. }
  31683. this.eatBits(12);
  31684. if (this.encoding > 0) {
  31685. this.lookBits(1);
  31686. this.eatBits(1);
  31687. }
  31688. }
  31689. }
  31690. this.eof = true;
  31691. }
  31692. } else if (this.err && this.eoline) {
  31693. while (true) {
  31694. code1 = this.lookBits(13);
  31695. if (code1 === EOF) {
  31696. this.eof = true;
  31697. return null;
  31698. }
  31699. if ((code1 >> 1) === 1) {
  31700. break;
  31701. }
  31702. this.eatBits(1);
  31703. }
  31704. this.eatBits(12);
  31705. if (this.encoding > 0) {
  31706. this.eatBits(1);
  31707. this.nextLine2D = !(code1 & 1);
  31708. }
  31709. }
  31710. if (codingLine[0] > 0) {
  31711. this.outputBits = codingLine[this.codingPos = 0];
  31712. } else {
  31713. this.outputBits = codingLine[this.codingPos = 1];
  31714. }
  31715. this.row++;
  31716. }
  31717. var c;
  31718. if (this.outputBits >= 8) {
  31719. c = (this.codingPos & 1) ? 0 : 0xFF;
  31720. this.outputBits -= 8;
  31721. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31722. this.codingPos++;
  31723. this.outputBits = (codingLine[this.codingPos] -
  31724. codingLine[this.codingPos - 1]);
  31725. }
  31726. } else {
  31727. bits = 8;
  31728. c = 0;
  31729. do {
  31730. if (this.outputBits > bits) {
  31731. c <<= bits;
  31732. if (!(this.codingPos & 1)) {
  31733. c |= 0xFF >> (8 - bits);
  31734. }
  31735. this.outputBits -= bits;
  31736. bits = 0;
  31737. } else {
  31738. c <<= this.outputBits;
  31739. if (!(this.codingPos & 1)) {
  31740. c |= 0xFF >> (8 - this.outputBits);
  31741. }
  31742. bits -= this.outputBits;
  31743. this.outputBits = 0;
  31744. if (codingLine[this.codingPos] < columns) {
  31745. this.codingPos++;
  31746. this.outputBits = (codingLine[this.codingPos] -
  31747. codingLine[this.codingPos - 1]);
  31748. } else if (bits > 0) {
  31749. c <<= bits;
  31750. bits = 0;
  31751. }
  31752. }
  31753. } while (bits);
  31754. }
  31755. if (this.black) {
  31756. c ^= 0xFF;
  31757. }
  31758. return c;
  31759. };
  31760. // This functions returns the code found from the table.
  31761. // The start and end parameters set the boundaries for searching the table.
  31762. // The limit parameter is optional. Function returns an array with three
  31763. // values. The first array element indicates whether a valid code is being
  31764. // returned. The second array element is the actual code. The third array
  31765. // element indicates whether EOF was reached.
  31766. CCITTFaxStream.prototype.findTableCode =
  31767. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31768. var limitValue = limit || 0;
  31769. for (var i = start; i <= end; ++i) {
  31770. var code = this.lookBits(i);
  31771. if (code === EOF) {
  31772. return [true, 1, false];
  31773. }
  31774. if (i < end) {
  31775. code <<= end - i;
  31776. }
  31777. if (!limitValue || code >= limitValue) {
  31778. var p = table[code - limitValue];
  31779. if (p[0] === i) {
  31780. this.eatBits(i);
  31781. return [true, p[1], true];
  31782. }
  31783. }
  31784. }
  31785. return [false, 0, false];
  31786. };
  31787. CCITTFaxStream.prototype.getTwoDimCode =
  31788. function ccittFaxStreamGetTwoDimCode() {
  31789. var code = 0;
  31790. var p;
  31791. if (this.eoblock) {
  31792. code = this.lookBits(7);
  31793. p = twoDimTable[code];
  31794. if (p && p[0] > 0) {
  31795. this.eatBits(p[0]);
  31796. return p[1];
  31797. }
  31798. } else {
  31799. var result = this.findTableCode(1, 7, twoDimTable);
  31800. if (result[0] && result[2]) {
  31801. return result[1];
  31802. }
  31803. }
  31804. info('Bad two dim code');
  31805. return EOF;
  31806. };
  31807. CCITTFaxStream.prototype.getWhiteCode =
  31808. function ccittFaxStreamGetWhiteCode() {
  31809. var code = 0;
  31810. var p;
  31811. if (this.eoblock) {
  31812. code = this.lookBits(12);
  31813. if (code === EOF) {
  31814. return 1;
  31815. }
  31816. if ((code >> 5) === 0) {
  31817. p = whiteTable1[code];
  31818. } else {
  31819. p = whiteTable2[code >> 3];
  31820. }
  31821. if (p[0] > 0) {
  31822. this.eatBits(p[0]);
  31823. return p[1];
  31824. }
  31825. } else {
  31826. var result = this.findTableCode(1, 9, whiteTable2);
  31827. if (result[0]) {
  31828. return result[1];
  31829. }
  31830. result = this.findTableCode(11, 12, whiteTable1);
  31831. if (result[0]) {
  31832. return result[1];
  31833. }
  31834. }
  31835. info('bad white code');
  31836. this.eatBits(1);
  31837. return 1;
  31838. };
  31839. CCITTFaxStream.prototype.getBlackCode =
  31840. function ccittFaxStreamGetBlackCode() {
  31841. var code, p;
  31842. if (this.eoblock) {
  31843. code = this.lookBits(13);
  31844. if (code === EOF) {
  31845. return 1;
  31846. }
  31847. if ((code >> 7) === 0) {
  31848. p = blackTable1[code];
  31849. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31850. p = blackTable2[(code >> 1) - 64];
  31851. } else {
  31852. p = blackTable3[code >> 7];
  31853. }
  31854. if (p[0] > 0) {
  31855. this.eatBits(p[0]);
  31856. return p[1];
  31857. }
  31858. } else {
  31859. var result = this.findTableCode(2, 6, blackTable3);
  31860. if (result[0]) {
  31861. return result[1];
  31862. }
  31863. result = this.findTableCode(7, 12, blackTable2, 64);
  31864. if (result[0]) {
  31865. return result[1];
  31866. }
  31867. result = this.findTableCode(10, 13, blackTable1);
  31868. if (result[0]) {
  31869. return result[1];
  31870. }
  31871. }
  31872. info('bad black code');
  31873. this.eatBits(1);
  31874. return 1;
  31875. };
  31876. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31877. var c;
  31878. while (this.inputBits < n) {
  31879. if ((c = this.str.getByte()) === -1) {
  31880. if (this.inputBits === 0) {
  31881. return EOF;
  31882. }
  31883. return ((this.inputBuf << (n - this.inputBits)) &
  31884. (0xFFFF >> (16 - n)));
  31885. }
  31886. this.inputBuf = (this.inputBuf << 8) + c;
  31887. this.inputBits += 8;
  31888. }
  31889. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31890. };
  31891. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31892. if ((this.inputBits -= n) < 0) {
  31893. this.inputBits = 0;
  31894. }
  31895. };
  31896. return CCITTFaxStream;
  31897. })();
  31898. var LZWStream = (function LZWStreamClosure() {
  31899. function LZWStream(str, maybeLength, earlyChange) {
  31900. this.str = str;
  31901. this.dict = str.dict;
  31902. this.cachedData = 0;
  31903. this.bitsCached = 0;
  31904. var maxLzwDictionarySize = 4096;
  31905. var lzwState = {
  31906. earlyChange: earlyChange,
  31907. codeLength: 9,
  31908. nextCode: 258,
  31909. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31910. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31911. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31912. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31913. currentSequenceLength: 0
  31914. };
  31915. for (var i = 0; i < 256; ++i) {
  31916. lzwState.dictionaryValues[i] = i;
  31917. lzwState.dictionaryLengths[i] = 1;
  31918. }
  31919. this.lzwState = lzwState;
  31920. DecodeStream.call(this, maybeLength);
  31921. }
  31922. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31923. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31924. var bitsCached = this.bitsCached;
  31925. var cachedData = this.cachedData;
  31926. while (bitsCached < n) {
  31927. var c = this.str.getByte();
  31928. if (c === -1) {
  31929. this.eof = true;
  31930. return null;
  31931. }
  31932. cachedData = (cachedData << 8) | c;
  31933. bitsCached += 8;
  31934. }
  31935. this.bitsCached = (bitsCached -= n);
  31936. this.cachedData = cachedData;
  31937. this.lastCode = null;
  31938. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31939. };
  31940. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31941. var blockSize = 512;
  31942. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31943. var i, j, q;
  31944. var lzwState = this.lzwState;
  31945. if (!lzwState) {
  31946. return; // eof was found
  31947. }
  31948. var earlyChange = lzwState.earlyChange;
  31949. var nextCode = lzwState.nextCode;
  31950. var dictionaryValues = lzwState.dictionaryValues;
  31951. var dictionaryLengths = lzwState.dictionaryLengths;
  31952. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31953. var codeLength = lzwState.codeLength;
  31954. var prevCode = lzwState.prevCode;
  31955. var currentSequence = lzwState.currentSequence;
  31956. var currentSequenceLength = lzwState.currentSequenceLength;
  31957. var decodedLength = 0;
  31958. var currentBufferLength = this.bufferLength;
  31959. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31960. for (i = 0; i < blockSize; i++) {
  31961. var code = this.readBits(codeLength);
  31962. var hasPrev = currentSequenceLength > 0;
  31963. if (code < 256) {
  31964. currentSequence[0] = code;
  31965. currentSequenceLength = 1;
  31966. } else if (code >= 258) {
  31967. if (code < nextCode) {
  31968. currentSequenceLength = dictionaryLengths[code];
  31969. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31970. currentSequence[j] = dictionaryValues[q];
  31971. q = dictionaryPrevCodes[q];
  31972. }
  31973. } else {
  31974. currentSequence[currentSequenceLength++] = currentSequence[0];
  31975. }
  31976. } else if (code === 256) {
  31977. codeLength = 9;
  31978. nextCode = 258;
  31979. currentSequenceLength = 0;
  31980. continue;
  31981. } else {
  31982. this.eof = true;
  31983. delete this.lzwState;
  31984. break;
  31985. }
  31986. if (hasPrev) {
  31987. dictionaryPrevCodes[nextCode] = prevCode;
  31988. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31989. dictionaryValues[nextCode] = currentSequence[0];
  31990. nextCode++;
  31991. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31992. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31993. 0.6931471805599453 + 1, 12) | 0;
  31994. }
  31995. prevCode = code;
  31996. decodedLength += currentSequenceLength;
  31997. if (estimatedDecodedSize < decodedLength) {
  31998. do {
  31999. estimatedDecodedSize += decodedSizeDelta;
  32000. } while (estimatedDecodedSize < decodedLength);
  32001. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32002. }
  32003. for (j = 0; j < currentSequenceLength; j++) {
  32004. buffer[currentBufferLength++] = currentSequence[j];
  32005. }
  32006. }
  32007. lzwState.nextCode = nextCode;
  32008. lzwState.codeLength = codeLength;
  32009. lzwState.prevCode = prevCode;
  32010. lzwState.currentSequenceLength = currentSequenceLength;
  32011. this.bufferLength = currentBufferLength;
  32012. };
  32013. return LZWStream;
  32014. })();
  32015. var NullStream = (function NullStreamClosure() {
  32016. function NullStream() {
  32017. Stream.call(this, new Uint8Array(0));
  32018. }
  32019. NullStream.prototype = Stream.prototype;
  32020. return NullStream;
  32021. })();
  32022. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  32023. setup: function wphSetup(handler) {
  32024. var pdfManager;
  32025. function loadDocument(recoveryMode) {
  32026. var loadDocumentCapability = createPromiseCapability();
  32027. var parseSuccess = function parseSuccess() {
  32028. var numPagesPromise = pdfManager.ensureDoc('numPages');
  32029. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  32030. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  32031. Promise.all([numPagesPromise, fingerprintPromise,
  32032. encryptedPromise]).then(function onDocReady(results) {
  32033. var doc = {
  32034. numPages: results[0],
  32035. fingerprint: results[1],
  32036. encrypted: !!results[2],
  32037. };
  32038. loadDocumentCapability.resolve(doc);
  32039. },
  32040. parseFailure);
  32041. };
  32042. var parseFailure = function parseFailure(e) {
  32043. loadDocumentCapability.reject(e);
  32044. };
  32045. pdfManager.ensureDoc('checkHeader', []).then(function() {
  32046. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  32047. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  32048. parseSuccess, parseFailure);
  32049. }, parseFailure);
  32050. }, parseFailure);
  32051. return loadDocumentCapability.promise;
  32052. }
  32053. function getPdfManager(data) {
  32054. var pdfManagerCapability = createPromiseCapability();
  32055. var source = data.source;
  32056. var disableRange = data.disableRange;
  32057. if (source.data) {
  32058. try {
  32059. pdfManager = new LocalPdfManager(source.data, source.password);
  32060. pdfManagerCapability.resolve();
  32061. } catch (ex) {
  32062. pdfManagerCapability.reject(ex);
  32063. }
  32064. return pdfManagerCapability.promise;
  32065. } else if (source.chunkedViewerLoading) {
  32066. try {
  32067. pdfManager = new NetworkPdfManager(source, handler);
  32068. pdfManagerCapability.resolve();
  32069. } catch (ex) {
  32070. pdfManagerCapability.reject(ex);
  32071. }
  32072. return pdfManagerCapability.promise;
  32073. }
  32074. var networkManager = new NetworkManager(source.url, {
  32075. httpHeaders: source.httpHeaders,
  32076. withCredentials: source.withCredentials
  32077. });
  32078. var cachedChunks = [];
  32079. var fullRequestXhrId = networkManager.requestFull({
  32080. onHeadersReceived: function onHeadersReceived() {
  32081. if (disableRange) {
  32082. return;
  32083. }
  32084. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  32085. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  32086. return;
  32087. }
  32088. var contentEncoding =
  32089. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  32090. if (contentEncoding !== 'identity') {
  32091. return;
  32092. }
  32093. var length = fullRequestXhr.getResponseHeader('Content-Length');
  32094. length = parseInt(length, 10);
  32095. if (!isInt(length)) {
  32096. return;
  32097. }
  32098. source.length = length;
  32099. if (length <= 2 * RANGE_CHUNK_SIZE) {
  32100. // The file size is smaller than the size of two chunks, so it does
  32101. // not make any sense to abort the request and retry with a range
  32102. // request.
  32103. return;
  32104. }
  32105. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  32106. // We can continue fetching when progressive loading is enabled,
  32107. // and we don't need the autoFetch feature.
  32108. source.disableAutoFetch = true;
  32109. } else {
  32110. // NOTE: by cancelling the full request, and then issuing range
  32111. // requests, there will be an issue for sites where you can only
  32112. // request the pdf once. However, if this is the case, then the
  32113. // server should not be returning that it can support range
  32114. // requests.
  32115. networkManager.abortRequest(fullRequestXhrId);
  32116. }
  32117. try {
  32118. pdfManager = new NetworkPdfManager(source, handler);
  32119. pdfManagerCapability.resolve(pdfManager);
  32120. } catch (ex) {
  32121. pdfManagerCapability.reject(ex);
  32122. }
  32123. },
  32124. onProgressiveData: source.disableStream ? null :
  32125. function onProgressiveData(chunk) {
  32126. if (!pdfManager) {
  32127. cachedChunks.push(chunk);
  32128. return;
  32129. }
  32130. pdfManager.sendProgressiveData(chunk);
  32131. },
  32132. onDone: function onDone(args) {
  32133. if (pdfManager) {
  32134. return; // already processed
  32135. }
  32136. var pdfFile;
  32137. if (args === null) {
  32138. // TODO add some streaming manager, e.g. for unknown length files.
  32139. // The data was returned in the onProgressiveData, combining...
  32140. var pdfFileLength = 0, pos = 0;
  32141. cachedChunks.forEach(function (chunk) {
  32142. pdfFileLength += chunk.byteLength;
  32143. });
  32144. if (source.length && pdfFileLength !== source.length) {
  32145. warn('reported HTTP length is different from actual');
  32146. }
  32147. var pdfFileArray = new Uint8Array(pdfFileLength);
  32148. cachedChunks.forEach(function (chunk) {
  32149. pdfFileArray.set(new Uint8Array(chunk), pos);
  32150. pos += chunk.byteLength;
  32151. });
  32152. pdfFile = pdfFileArray.buffer;
  32153. } else {
  32154. pdfFile = args.chunk;
  32155. }
  32156. // the data is array, instantiating directly from it
  32157. try {
  32158. pdfManager = new LocalPdfManager(pdfFile, source.password);
  32159. pdfManagerCapability.resolve();
  32160. } catch (ex) {
  32161. pdfManagerCapability.reject(ex);
  32162. }
  32163. },
  32164. onError: function onError(status) {
  32165. var exception;
  32166. if (status === 404) {
  32167. exception = new MissingPDFException('Missing PDF "' +
  32168. source.url + '".');
  32169. handler.send('MissingPDF', exception);
  32170. } else {
  32171. exception = new UnexpectedResponseException(
  32172. 'Unexpected server response (' + status +
  32173. ') while retrieving PDF "' + source.url + '".', status);
  32174. handler.send('UnexpectedResponse', exception);
  32175. }
  32176. },
  32177. onProgress: function onProgress(evt) {
  32178. handler.send('DocProgress', {
  32179. loaded: evt.loaded,
  32180. total: evt.lengthComputable ? evt.total : source.length
  32181. });
  32182. }
  32183. });
  32184. return pdfManagerCapability.promise;
  32185. }
  32186. handler.on('test', function wphSetupTest(data) {
  32187. // check if Uint8Array can be sent to worker
  32188. if (!(data instanceof Uint8Array)) {
  32189. handler.send('test', false);
  32190. return;
  32191. }
  32192. // making sure postMessage transfers are working
  32193. var supportTransfers = data[0] === 255;
  32194. handler.postMessageTransfers = supportTransfers;
  32195. // check if the response property is supported by xhr
  32196. var xhr = new XMLHttpRequest();
  32197. var responseExists = 'response' in xhr;
  32198. // check if the property is actually implemented
  32199. try {
  32200. var dummy = xhr.responseType;
  32201. } catch (e) {
  32202. responseExists = false;
  32203. }
  32204. if (!responseExists) {
  32205. handler.send('test', false);
  32206. return;
  32207. }
  32208. handler.send('test', {
  32209. supportTypedArray: true,
  32210. supportTransfers: supportTransfers
  32211. });
  32212. });
  32213. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32214. var onSuccess = function(doc) {
  32215. handler.send('GetDoc', { pdfInfo: doc });
  32216. };
  32217. var onFailure = function(e) {
  32218. if (e instanceof PasswordException) {
  32219. if (e.code === PasswordResponses.NEED_PASSWORD) {
  32220. handler.send('NeedPassword', e);
  32221. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  32222. handler.send('IncorrectPassword', e);
  32223. }
  32224. } else if (e instanceof InvalidPDFException) {
  32225. handler.send('InvalidPDF', e);
  32226. } else if (e instanceof MissingPDFException) {
  32227. handler.send('MissingPDF', e);
  32228. } else if (e instanceof UnexpectedResponseException) {
  32229. handler.send('UnexpectedResponse', e);
  32230. } else {
  32231. handler.send('UnknownError',
  32232. new UnknownErrorException(e.message, e.toString()));
  32233. }
  32234. };
  32235. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  32236. -1 : data.maxImageSize;
  32237. PDFJS.disableFontFace = data.disableFontFace;
  32238. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  32239. PDFJS.verbosity = data.verbosity;
  32240. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  32241. null : data.cMapUrl;
  32242. PDFJS.cMapPacked = data.cMapPacked === true;
  32243. getPdfManager(data).then(function () {
  32244. handler.send('PDFManagerReady', null);
  32245. pdfManager.onLoadedStream().then(function(stream) {
  32246. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  32247. });
  32248. }).then(function pdfManagerReady() {
  32249. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32250. // Try again with recoveryMode == true
  32251. if (!(ex instanceof XRefParseException)) {
  32252. if (ex instanceof PasswordException) {
  32253. // after password exception prepare to receive a new password
  32254. // to repeat loading
  32255. pdfManager.passwordChanged().then(pdfManagerReady);
  32256. }
  32257. onFailure(ex);
  32258. return;
  32259. }
  32260. pdfManager.requestLoadedStream();
  32261. pdfManager.onLoadedStream().then(function() {
  32262. loadDocument(true).then(onSuccess, onFailure);
  32263. });
  32264. }, onFailure);
  32265. }, onFailure);
  32266. });
  32267. handler.on('GetPage', function wphSetupGetPage(data) {
  32268. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32269. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32270. var refPromise = pdfManager.ensure(page, 'ref');
  32271. var viewPromise = pdfManager.ensure(page, 'view');
  32272. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32273. function(results) {
  32274. return {
  32275. rotate: results[0],
  32276. ref: results[1],
  32277. view: results[2]
  32278. };
  32279. });
  32280. });
  32281. });
  32282. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32283. var ref = new Ref(data.ref.num, data.ref.gen);
  32284. var catalog = pdfManager.pdfDocument.catalog;
  32285. return catalog.getPageIndex(ref);
  32286. });
  32287. handler.on('GetDestinations',
  32288. function wphSetupGetDestinations(data) {
  32289. return pdfManager.ensureCatalog('destinations');
  32290. }
  32291. );
  32292. handler.on('GetDestination',
  32293. function wphSetupGetDestination(data) {
  32294. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32295. }
  32296. );
  32297. handler.on('GetAttachments',
  32298. function wphSetupGetAttachments(data) {
  32299. return pdfManager.ensureCatalog('attachments');
  32300. }
  32301. );
  32302. handler.on('GetJavaScript',
  32303. function wphSetupGetJavaScript(data) {
  32304. return pdfManager.ensureCatalog('javaScript');
  32305. }
  32306. );
  32307. handler.on('GetOutline',
  32308. function wphSetupGetOutline(data) {
  32309. return pdfManager.ensureCatalog('documentOutline');
  32310. }
  32311. );
  32312. handler.on('GetMetadata',
  32313. function wphSetupGetMetadata(data) {
  32314. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32315. pdfManager.ensureCatalog('metadata')]);
  32316. }
  32317. );
  32318. handler.on('GetData', function wphSetupGetData(data) {
  32319. pdfManager.requestLoadedStream();
  32320. return pdfManager.onLoadedStream().then(function(stream) {
  32321. return stream.bytes;
  32322. });
  32323. });
  32324. handler.on('GetStats',
  32325. function wphSetupGetStats(data) {
  32326. return pdfManager.pdfDocument.xref.stats;
  32327. }
  32328. );
  32329. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32330. pdfManager.updatePassword(data);
  32331. });
  32332. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32333. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32334. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32335. });
  32336. });
  32337. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32338. pdfManager.getPage(data.pageIndex).then(function(page) {
  32339. var pageNum = data.pageIndex + 1;
  32340. var start = Date.now();
  32341. // Pre compile the pdf page and fetch the fonts/images.
  32342. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  32343. info('page=' + pageNum + ' - getOperatorList: time=' +
  32344. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  32345. }, function(e) {
  32346. var minimumStackMessage =
  32347. 'worker.js: while trying to getPage() and getOperatorList()';
  32348. var wrappedException;
  32349. // Turn the error into an obj that can be serialized
  32350. if (typeof e === 'string') {
  32351. wrappedException = {
  32352. message: e,
  32353. stack: minimumStackMessage
  32354. };
  32355. } else if (typeof e === 'object') {
  32356. wrappedException = {
  32357. message: e.message || e.toString(),
  32358. stack: e.stack || minimumStackMessage
  32359. };
  32360. } else {
  32361. wrappedException = {
  32362. message: 'Unknown exception type: ' + (typeof e),
  32363. stack: minimumStackMessage
  32364. };
  32365. }
  32366. handler.send('PageError', {
  32367. pageNum: pageNum,
  32368. error: wrappedException,
  32369. intent: data.intent
  32370. });
  32371. });
  32372. });
  32373. }, this);
  32374. handler.on('GetTextContent', function wphExtractText(data) {
  32375. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32376. var pageNum = data.pageIndex + 1;
  32377. var start = Date.now();
  32378. return page.extractTextContent().then(function(textContent) {
  32379. info('text indexing: page=' + pageNum + ' - time=' +
  32380. (Date.now() - start) + 'ms');
  32381. return textContent;
  32382. });
  32383. });
  32384. });
  32385. handler.on('Cleanup', function wphCleanup(data) {
  32386. return pdfManager.cleanup();
  32387. });
  32388. handler.on('Terminate', function wphTerminate(data) {
  32389. pdfManager.terminate();
  32390. });
  32391. }
  32392. };
  32393. var consoleTimer = {};
  32394. var workerConsole = {
  32395. log: function log() {
  32396. var args = Array.prototype.slice.call(arguments);
  32397. globalScope.postMessage({
  32398. action: 'console_log',
  32399. data: args
  32400. });
  32401. },
  32402. error: function error() {
  32403. var args = Array.prototype.slice.call(arguments);
  32404. globalScope.postMessage({
  32405. action: 'console_error',
  32406. data: args
  32407. });
  32408. throw 'pdf.js execution error';
  32409. },
  32410. time: function time(name) {
  32411. consoleTimer[name] = Date.now();
  32412. },
  32413. timeEnd: function timeEnd(name) {
  32414. var time = consoleTimer[name];
  32415. if (!time) {
  32416. error('Unknown timer name ' + name);
  32417. }
  32418. this.log('Timer:', name, Date.now() - time);
  32419. }
  32420. };
  32421. // Worker thread?
  32422. if (typeof window === 'undefined') {
  32423. if (!('console' in globalScope)) {
  32424. globalScope.console = workerConsole;
  32425. }
  32426. // Listen for unsupported features so we can pass them on to the main thread.
  32427. PDFJS.UnsupportedManager.listen(function (msg) {
  32428. globalScope.postMessage({
  32429. action: '_unsupported_feature',
  32430. data: msg
  32431. });
  32432. });
  32433. var handler = new MessageHandler('worker_processor', this);
  32434. WorkerMessageHandler.setup(handler);
  32435. }
  32436. /* This class implements the QM Coder decoding as defined in
  32437. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32438. * Annex C.3 Arithmetic decoding procedure
  32439. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32440. *
  32441. * The arithmetic decoder is used in conjunction with context models to decode
  32442. * JPEG2000 and JBIG2 streams.
  32443. */
  32444. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32445. // Table C-2
  32446. var QeTable = [
  32447. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32448. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32449. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32450. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32451. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32452. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32453. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32454. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32455. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32456. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32457. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32458. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32459. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32460. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32461. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32462. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32463. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32464. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32465. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32466. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32467. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32468. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32469. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32470. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32471. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32472. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32473. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32474. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32475. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32476. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32477. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32478. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32479. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32480. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32481. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32482. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32483. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32484. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32485. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32486. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32487. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32488. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32489. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32490. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32491. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32492. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32493. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32494. ];
  32495. // C.3.5 Initialisation of the decoder (INITDEC)
  32496. function ArithmeticDecoder(data, start, end) {
  32497. this.data = data;
  32498. this.bp = start;
  32499. this.dataEnd = end;
  32500. this.chigh = data[start];
  32501. this.clow = 0;
  32502. this.byteIn();
  32503. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32504. this.clow = (this.clow << 7) & 0xFFFF;
  32505. this.ct -= 7;
  32506. this.a = 0x8000;
  32507. }
  32508. ArithmeticDecoder.prototype = {
  32509. // C.3.4 Compressed data input (BYTEIN)
  32510. byteIn: function ArithmeticDecoder_byteIn() {
  32511. var data = this.data;
  32512. var bp = this.bp;
  32513. if (data[bp] === 0xFF) {
  32514. var b1 = data[bp + 1];
  32515. if (b1 > 0x8F) {
  32516. this.clow += 0xFF00;
  32517. this.ct = 8;
  32518. } else {
  32519. bp++;
  32520. this.clow += (data[bp] << 9);
  32521. this.ct = 7;
  32522. this.bp = bp;
  32523. }
  32524. } else {
  32525. bp++;
  32526. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32527. this.ct = 8;
  32528. this.bp = bp;
  32529. }
  32530. if (this.clow > 0xFFFF) {
  32531. this.chigh += (this.clow >> 16);
  32532. this.clow &= 0xFFFF;
  32533. }
  32534. },
  32535. // C.3.2 Decoding a decision (DECODE)
  32536. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32537. // contexts are packed into 1 byte:
  32538. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32539. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32540. var qeTableIcx = QeTable[cx_index];
  32541. var qeIcx = qeTableIcx.qe;
  32542. var d;
  32543. var a = this.a - qeIcx;
  32544. if (this.chigh < qeIcx) {
  32545. // exchangeLps
  32546. if (a < qeIcx) {
  32547. a = qeIcx;
  32548. d = cx_mps;
  32549. cx_index = qeTableIcx.nmps;
  32550. } else {
  32551. a = qeIcx;
  32552. d = 1 ^ cx_mps;
  32553. if (qeTableIcx.switchFlag === 1) {
  32554. cx_mps = d;
  32555. }
  32556. cx_index = qeTableIcx.nlps;
  32557. }
  32558. } else {
  32559. this.chigh -= qeIcx;
  32560. if ((a & 0x8000) !== 0) {
  32561. this.a = a;
  32562. return cx_mps;
  32563. }
  32564. // exchangeMps
  32565. if (a < qeIcx) {
  32566. d = 1 ^ cx_mps;
  32567. if (qeTableIcx.switchFlag === 1) {
  32568. cx_mps = d;
  32569. }
  32570. cx_index = qeTableIcx.nlps;
  32571. } else {
  32572. d = cx_mps;
  32573. cx_index = qeTableIcx.nmps;
  32574. }
  32575. }
  32576. // C.3.3 renormD;
  32577. do {
  32578. if (this.ct === 0) {
  32579. this.byteIn();
  32580. }
  32581. a <<= 1;
  32582. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32583. this.clow = (this.clow << 1) & 0xFFFF;
  32584. this.ct--;
  32585. } while ((a & 0x8000) === 0);
  32586. this.a = a;
  32587. contexts[pos] = cx_index << 1 | cx_mps;
  32588. return d;
  32589. }
  32590. };
  32591. return ArithmeticDecoder;
  32592. })();
  32593. var JpegImage = (function jpegImage() {
  32594. var dctZigZag = new Uint8Array([
  32595. 0,
  32596. 1, 8,
  32597. 16, 9, 2,
  32598. 3, 10, 17, 24,
  32599. 32, 25, 18, 11, 4,
  32600. 5, 12, 19, 26, 33, 40,
  32601. 48, 41, 34, 27, 20, 13, 6,
  32602. 7, 14, 21, 28, 35, 42, 49, 56,
  32603. 57, 50, 43, 36, 29, 22, 15,
  32604. 23, 30, 37, 44, 51, 58,
  32605. 59, 52, 45, 38, 31,
  32606. 39, 46, 53, 60,
  32607. 61, 54, 47,
  32608. 55, 62,
  32609. 63
  32610. ]);
  32611. var dctCos1 = 4017; // cos(pi/16)
  32612. var dctSin1 = 799; // sin(pi/16)
  32613. var dctCos3 = 3406; // cos(3*pi/16)
  32614. var dctSin3 = 2276; // sin(3*pi/16)
  32615. var dctCos6 = 1567; // cos(6*pi/16)
  32616. var dctSin6 = 3784; // sin(6*pi/16)
  32617. var dctSqrt2 = 5793; // sqrt(2)
  32618. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32619. function constructor() {
  32620. }
  32621. function buildHuffmanTable(codeLengths, values) {
  32622. var k = 0, code = [], i, j, length = 16;
  32623. while (length > 0 && !codeLengths[length - 1]) {
  32624. length--;
  32625. }
  32626. code.push({children: [], index: 0});
  32627. var p = code[0], q;
  32628. for (i = 0; i < length; i++) {
  32629. for (j = 0; j < codeLengths[i]; j++) {
  32630. p = code.pop();
  32631. p.children[p.index] = values[k];
  32632. while (p.index > 0) {
  32633. p = code.pop();
  32634. }
  32635. p.index++;
  32636. code.push(p);
  32637. while (code.length <= i) {
  32638. code.push(q = {children: [], index: 0});
  32639. p.children[p.index] = q.children;
  32640. p = q;
  32641. }
  32642. k++;
  32643. }
  32644. if (i + 1 < length) {
  32645. // p here points to last code
  32646. code.push(q = {children: [], index: 0});
  32647. p.children[p.index] = q.children;
  32648. p = q;
  32649. }
  32650. }
  32651. return code[0].children;
  32652. }
  32653. function getBlockBufferOffset(component, row, col) {
  32654. return 64 * ((component.blocksPerLine + 1) * row + col);
  32655. }
  32656. function decodeScan(data, offset, frame, components, resetInterval,
  32657. spectralStart, spectralEnd, successivePrev, successive) {
  32658. var precision = frame.precision;
  32659. var samplesPerLine = frame.samplesPerLine;
  32660. var scanLines = frame.scanLines;
  32661. var mcusPerLine = frame.mcusPerLine;
  32662. var progressive = frame.progressive;
  32663. var maxH = frame.maxH, maxV = frame.maxV;
  32664. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32665. function readBit() {
  32666. if (bitsCount > 0) {
  32667. bitsCount--;
  32668. return (bitsData >> bitsCount) & 1;
  32669. }
  32670. bitsData = data[offset++];
  32671. if (bitsData === 0xFF) {
  32672. var nextByte = data[offset++];
  32673. if (nextByte) {
  32674. throw 'unexpected marker: ' +
  32675. ((bitsData << 8) | nextByte).toString(16);
  32676. }
  32677. // unstuff 0
  32678. }
  32679. bitsCount = 7;
  32680. return bitsData >>> 7;
  32681. }
  32682. function decodeHuffman(tree) {
  32683. var node = tree;
  32684. while (true) {
  32685. node = node[readBit()];
  32686. if (typeof node === 'number') {
  32687. return node;
  32688. }
  32689. if (typeof node !== 'object') {
  32690. throw 'invalid huffman sequence';
  32691. }
  32692. }
  32693. }
  32694. function receive(length) {
  32695. var n = 0;
  32696. while (length > 0) {
  32697. n = (n << 1) | readBit();
  32698. length--;
  32699. }
  32700. return n;
  32701. }
  32702. function receiveAndExtend(length) {
  32703. if (length === 1) {
  32704. return readBit() === 1 ? 1 : -1;
  32705. }
  32706. var n = receive(length);
  32707. if (n >= 1 << (length - 1)) {
  32708. return n;
  32709. }
  32710. return n + (-1 << length) + 1;
  32711. }
  32712. function decodeBaseline(component, offset) {
  32713. var t = decodeHuffman(component.huffmanTableDC);
  32714. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32715. component.blockData[offset] = (component.pred += diff);
  32716. var k = 1;
  32717. while (k < 64) {
  32718. var rs = decodeHuffman(component.huffmanTableAC);
  32719. var s = rs & 15, r = rs >> 4;
  32720. if (s === 0) {
  32721. if (r < 15) {
  32722. break;
  32723. }
  32724. k += 16;
  32725. continue;
  32726. }
  32727. k += r;
  32728. var z = dctZigZag[k];
  32729. component.blockData[offset + z] = receiveAndExtend(s);
  32730. k++;
  32731. }
  32732. }
  32733. function decodeDCFirst(component, offset) {
  32734. var t = decodeHuffman(component.huffmanTableDC);
  32735. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32736. component.blockData[offset] = (component.pred += diff);
  32737. }
  32738. function decodeDCSuccessive(component, offset) {
  32739. component.blockData[offset] |= readBit() << successive;
  32740. }
  32741. var eobrun = 0;
  32742. function decodeACFirst(component, offset) {
  32743. if (eobrun > 0) {
  32744. eobrun--;
  32745. return;
  32746. }
  32747. var k = spectralStart, e = spectralEnd;
  32748. while (k <= e) {
  32749. var rs = decodeHuffman(component.huffmanTableAC);
  32750. var s = rs & 15, r = rs >> 4;
  32751. if (s === 0) {
  32752. if (r < 15) {
  32753. eobrun = receive(r) + (1 << r) - 1;
  32754. break;
  32755. }
  32756. k += 16;
  32757. continue;
  32758. }
  32759. k += r;
  32760. var z = dctZigZag[k];
  32761. component.blockData[offset + z] =
  32762. receiveAndExtend(s) * (1 << successive);
  32763. k++;
  32764. }
  32765. }
  32766. var successiveACState = 0, successiveACNextValue;
  32767. function decodeACSuccessive(component, offset) {
  32768. var k = spectralStart;
  32769. var e = spectralEnd;
  32770. var r = 0;
  32771. var s;
  32772. var rs;
  32773. while (k <= e) {
  32774. var z = dctZigZag[k];
  32775. switch (successiveACState) {
  32776. case 0: // initial state
  32777. rs = decodeHuffman(component.huffmanTableAC);
  32778. s = rs & 15;
  32779. r = rs >> 4;
  32780. if (s === 0) {
  32781. if (r < 15) {
  32782. eobrun = receive(r) + (1 << r);
  32783. successiveACState = 4;
  32784. } else {
  32785. r = 16;
  32786. successiveACState = 1;
  32787. }
  32788. } else {
  32789. if (s !== 1) {
  32790. throw 'invalid ACn encoding';
  32791. }
  32792. successiveACNextValue = receiveAndExtend(s);
  32793. successiveACState = r ? 2 : 3;
  32794. }
  32795. continue;
  32796. case 1: // skipping r zero items
  32797. case 2:
  32798. if (component.blockData[offset + z]) {
  32799. component.blockData[offset + z] += (readBit() << successive);
  32800. } else {
  32801. r--;
  32802. if (r === 0) {
  32803. successiveACState = successiveACState === 2 ? 3 : 0;
  32804. }
  32805. }
  32806. break;
  32807. case 3: // set value for a zero item
  32808. if (component.blockData[offset + z]) {
  32809. component.blockData[offset + z] += (readBit() << successive);
  32810. } else {
  32811. component.blockData[offset + z] =
  32812. successiveACNextValue << successive;
  32813. successiveACState = 0;
  32814. }
  32815. break;
  32816. case 4: // eob
  32817. if (component.blockData[offset + z]) {
  32818. component.blockData[offset + z] += (readBit() << successive);
  32819. }
  32820. break;
  32821. }
  32822. k++;
  32823. }
  32824. if (successiveACState === 4) {
  32825. eobrun--;
  32826. if (eobrun === 0) {
  32827. successiveACState = 0;
  32828. }
  32829. }
  32830. }
  32831. function decodeMcu(component, decode, mcu, row, col) {
  32832. var mcuRow = (mcu / mcusPerLine) | 0;
  32833. var mcuCol = mcu % mcusPerLine;
  32834. var blockRow = mcuRow * component.v + row;
  32835. var blockCol = mcuCol * component.h + col;
  32836. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32837. decode(component, offset);
  32838. }
  32839. function decodeBlock(component, decode, mcu) {
  32840. var blockRow = (mcu / component.blocksPerLine) | 0;
  32841. var blockCol = mcu % component.blocksPerLine;
  32842. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32843. decode(component, offset);
  32844. }
  32845. var componentsLength = components.length;
  32846. var component, i, j, k, n;
  32847. var decodeFn;
  32848. if (progressive) {
  32849. if (spectralStart === 0) {
  32850. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32851. } else {
  32852. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32853. }
  32854. } else {
  32855. decodeFn = decodeBaseline;
  32856. }
  32857. var mcu = 0, marker;
  32858. var mcuExpected;
  32859. if (componentsLength === 1) {
  32860. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32861. } else {
  32862. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32863. }
  32864. if (!resetInterval) {
  32865. resetInterval = mcuExpected;
  32866. }
  32867. var h, v;
  32868. while (mcu < mcuExpected) {
  32869. // reset interval stuff
  32870. for (i = 0; i < componentsLength; i++) {
  32871. components[i].pred = 0;
  32872. }
  32873. eobrun = 0;
  32874. if (componentsLength === 1) {
  32875. component = components[0];
  32876. for (n = 0; n < resetInterval; n++) {
  32877. decodeBlock(component, decodeFn, mcu);
  32878. mcu++;
  32879. }
  32880. } else {
  32881. for (n = 0; n < resetInterval; n++) {
  32882. for (i = 0; i < componentsLength; i++) {
  32883. component = components[i];
  32884. h = component.h;
  32885. v = component.v;
  32886. for (j = 0; j < v; j++) {
  32887. for (k = 0; k < h; k++) {
  32888. decodeMcu(component, decodeFn, mcu, j, k);
  32889. }
  32890. }
  32891. }
  32892. mcu++;
  32893. }
  32894. }
  32895. // find marker
  32896. bitsCount = 0;
  32897. marker = (data[offset] << 8) | data[offset + 1];
  32898. if (marker <= 0xFF00) {
  32899. throw 'marker was not found';
  32900. }
  32901. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32902. offset += 2;
  32903. } else {
  32904. break;
  32905. }
  32906. }
  32907. return offset - startOffset;
  32908. }
  32909. // A port of poppler's IDCT method which in turn is taken from:
  32910. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32911. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32912. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32913. // 988-991.
  32914. function quantizeAndInverse(component, blockBufferOffset, p) {
  32915. var qt = component.quantizationTable, blockData = component.blockData;
  32916. var v0, v1, v2, v3, v4, v5, v6, v7;
  32917. var p0, p1, p2, p3, p4, p5, p6, p7;
  32918. var t;
  32919. // inverse DCT on rows
  32920. for (var row = 0; row < 64; row += 8) {
  32921. // gather block data
  32922. p0 = blockData[blockBufferOffset + row];
  32923. p1 = blockData[blockBufferOffset + row + 1];
  32924. p2 = blockData[blockBufferOffset + row + 2];
  32925. p3 = blockData[blockBufferOffset + row + 3];
  32926. p4 = blockData[blockBufferOffset + row + 4];
  32927. p5 = blockData[blockBufferOffset + row + 5];
  32928. p6 = blockData[blockBufferOffset + row + 6];
  32929. p7 = blockData[blockBufferOffset + row + 7];
  32930. // dequant p0
  32931. p0 *= qt[row];
  32932. // check for all-zero AC coefficients
  32933. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32934. t = (dctSqrt2 * p0 + 512) >> 10;
  32935. p[row] = t;
  32936. p[row + 1] = t;
  32937. p[row + 2] = t;
  32938. p[row + 3] = t;
  32939. p[row + 4] = t;
  32940. p[row + 5] = t;
  32941. p[row + 6] = t;
  32942. p[row + 7] = t;
  32943. continue;
  32944. }
  32945. // dequant p1 ... p7
  32946. p1 *= qt[row + 1];
  32947. p2 *= qt[row + 2];
  32948. p3 *= qt[row + 3];
  32949. p4 *= qt[row + 4];
  32950. p5 *= qt[row + 5];
  32951. p6 *= qt[row + 6];
  32952. p7 *= qt[row + 7];
  32953. // stage 4
  32954. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32955. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32956. v2 = p2;
  32957. v3 = p6;
  32958. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32959. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32960. v5 = p3 << 4;
  32961. v6 = p5 << 4;
  32962. // stage 3
  32963. v0 = (v0 + v1 + 1) >> 1;
  32964. v1 = v0 - v1;
  32965. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32966. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32967. v3 = t;
  32968. v4 = (v4 + v6 + 1) >> 1;
  32969. v6 = v4 - v6;
  32970. v7 = (v7 + v5 + 1) >> 1;
  32971. v5 = v7 - v5;
  32972. // stage 2
  32973. v0 = (v0 + v3 + 1) >> 1;
  32974. v3 = v0 - v3;
  32975. v1 = (v1 + v2 + 1) >> 1;
  32976. v2 = v1 - v2;
  32977. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32978. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32979. v7 = t;
  32980. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32981. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32982. v6 = t;
  32983. // stage 1
  32984. p[row] = v0 + v7;
  32985. p[row + 7] = v0 - v7;
  32986. p[row + 1] = v1 + v6;
  32987. p[row + 6] = v1 - v6;
  32988. p[row + 2] = v2 + v5;
  32989. p[row + 5] = v2 - v5;
  32990. p[row + 3] = v3 + v4;
  32991. p[row + 4] = v3 - v4;
  32992. }
  32993. // inverse DCT on columns
  32994. for (var col = 0; col < 8; ++col) {
  32995. p0 = p[col];
  32996. p1 = p[col + 8];
  32997. p2 = p[col + 16];
  32998. p3 = p[col + 24];
  32999. p4 = p[col + 32];
  33000. p5 = p[col + 40];
  33001. p6 = p[col + 48];
  33002. p7 = p[col + 56];
  33003. // check for all-zero AC coefficients
  33004. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33005. t = (dctSqrt2 * p0 + 8192) >> 14;
  33006. // convert to 8 bit
  33007. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  33008. blockData[blockBufferOffset + col] = t;
  33009. blockData[blockBufferOffset + col + 8] = t;
  33010. blockData[blockBufferOffset + col + 16] = t;
  33011. blockData[blockBufferOffset + col + 24] = t;
  33012. blockData[blockBufferOffset + col + 32] = t;
  33013. blockData[blockBufferOffset + col + 40] = t;
  33014. blockData[blockBufferOffset + col + 48] = t;
  33015. blockData[blockBufferOffset + col + 56] = t;
  33016. continue;
  33017. }
  33018. // stage 4
  33019. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  33020. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  33021. v2 = p2;
  33022. v3 = p6;
  33023. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  33024. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  33025. v5 = p3;
  33026. v6 = p5;
  33027. // stage 3
  33028. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  33029. // converting to UInt8 range later.
  33030. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  33031. v1 = v0 - v1;
  33032. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  33033. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  33034. v3 = t;
  33035. v4 = (v4 + v6 + 1) >> 1;
  33036. v6 = v4 - v6;
  33037. v7 = (v7 + v5 + 1) >> 1;
  33038. v5 = v7 - v5;
  33039. // stage 2
  33040. v0 = (v0 + v3 + 1) >> 1;
  33041. v3 = v0 - v3;
  33042. v1 = (v1 + v2 + 1) >> 1;
  33043. v2 = v1 - v2;
  33044. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33045. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33046. v7 = t;
  33047. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33048. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33049. v6 = t;
  33050. // stage 1
  33051. p0 = v0 + v7;
  33052. p7 = v0 - v7;
  33053. p1 = v1 + v6;
  33054. p6 = v1 - v6;
  33055. p2 = v2 + v5;
  33056. p5 = v2 - v5;
  33057. p3 = v3 + v4;
  33058. p4 = v3 - v4;
  33059. // convert to 8-bit integers
  33060. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  33061. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  33062. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  33063. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  33064. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  33065. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  33066. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  33067. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  33068. // store block data
  33069. blockData[blockBufferOffset + col] = p0;
  33070. blockData[blockBufferOffset + col + 8] = p1;
  33071. blockData[blockBufferOffset + col + 16] = p2;
  33072. blockData[blockBufferOffset + col + 24] = p3;
  33073. blockData[blockBufferOffset + col + 32] = p4;
  33074. blockData[blockBufferOffset + col + 40] = p5;
  33075. blockData[blockBufferOffset + col + 48] = p6;
  33076. blockData[blockBufferOffset + col + 56] = p7;
  33077. }
  33078. }
  33079. function buildComponentData(frame, component) {
  33080. var blocksPerLine = component.blocksPerLine;
  33081. var blocksPerColumn = component.blocksPerColumn;
  33082. var computationBuffer = new Int16Array(64);
  33083. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  33084. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  33085. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33086. quantizeAndInverse(component, offset, computationBuffer);
  33087. }
  33088. }
  33089. return component.blockData;
  33090. }
  33091. function clamp0to255(a) {
  33092. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  33093. }
  33094. constructor.prototype = {
  33095. parse: function parse(data) {
  33096. function readUint16() {
  33097. var value = (data[offset] << 8) | data[offset + 1];
  33098. offset += 2;
  33099. return value;
  33100. }
  33101. function readDataBlock() {
  33102. var length = readUint16();
  33103. var array = data.subarray(offset, offset + length - 2);
  33104. offset += array.length;
  33105. return array;
  33106. }
  33107. function prepareComponents(frame) {
  33108. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  33109. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  33110. for (var i = 0; i < frame.components.length; i++) {
  33111. component = frame.components[i];
  33112. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  33113. component.h / frame.maxH);
  33114. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  33115. component.v / frame.maxV);
  33116. var blocksPerLineForMcu = mcusPerLine * component.h;
  33117. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  33118. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  33119. (blocksPerLineForMcu + 1);
  33120. component.blockData = new Int16Array(blocksBufferSize);
  33121. component.blocksPerLine = blocksPerLine;
  33122. component.blocksPerColumn = blocksPerColumn;
  33123. }
  33124. frame.mcusPerLine = mcusPerLine;
  33125. frame.mcusPerColumn = mcusPerColumn;
  33126. }
  33127. var offset = 0, length = data.length;
  33128. var jfif = null;
  33129. var adobe = null;
  33130. var pixels = null;
  33131. var frame, resetInterval;
  33132. var quantizationTables = [];
  33133. var huffmanTablesAC = [], huffmanTablesDC = [];
  33134. var fileMarker = readUint16();
  33135. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  33136. throw 'SOI not found';
  33137. }
  33138. fileMarker = readUint16();
  33139. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  33140. var i, j, l;
  33141. switch(fileMarker) {
  33142. case 0xFFE0: // APP0 (Application Specific)
  33143. case 0xFFE1: // APP1
  33144. case 0xFFE2: // APP2
  33145. case 0xFFE3: // APP3
  33146. case 0xFFE4: // APP4
  33147. case 0xFFE5: // APP5
  33148. case 0xFFE6: // APP6
  33149. case 0xFFE7: // APP7
  33150. case 0xFFE8: // APP8
  33151. case 0xFFE9: // APP9
  33152. case 0xFFEA: // APP10
  33153. case 0xFFEB: // APP11
  33154. case 0xFFEC: // APP12
  33155. case 0xFFED: // APP13
  33156. case 0xFFEE: // APP14
  33157. case 0xFFEF: // APP15
  33158. case 0xFFFE: // COM (Comment)
  33159. var appData = readDataBlock();
  33160. if (fileMarker === 0xFFE0) {
  33161. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  33162. appData[2] === 0x49 && appData[3] === 0x46 &&
  33163. appData[4] === 0) { // 'JFIF\x00'
  33164. jfif = {
  33165. version: { major: appData[5], minor: appData[6] },
  33166. densityUnits: appData[7],
  33167. xDensity: (appData[8] << 8) | appData[9],
  33168. yDensity: (appData[10] << 8) | appData[11],
  33169. thumbWidth: appData[12],
  33170. thumbHeight: appData[13],
  33171. thumbData: appData.subarray(14, 14 +
  33172. 3 * appData[12] * appData[13])
  33173. };
  33174. }
  33175. }
  33176. // TODO APP1 - Exif
  33177. if (fileMarker === 0xFFEE) {
  33178. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  33179. appData[2] === 0x6F && appData[3] === 0x62 &&
  33180. appData[4] === 0x65) { // 'Adobe'
  33181. adobe = {
  33182. version: (appData[5] << 8) | appData[6],
  33183. flags0: (appData[7] << 8) | appData[8],
  33184. flags1: (appData[9] << 8) | appData[10],
  33185. transformCode: appData[11]
  33186. };
  33187. }
  33188. }
  33189. break;
  33190. case 0xFFDB: // DQT (Define Quantization Tables)
  33191. var quantizationTablesLength = readUint16();
  33192. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  33193. var z;
  33194. while (offset < quantizationTablesEnd) {
  33195. var quantizationTableSpec = data[offset++];
  33196. var tableData = new Uint16Array(64);
  33197. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  33198. for (j = 0; j < 64; j++) {
  33199. z = dctZigZag[j];
  33200. tableData[z] = data[offset++];
  33201. }
  33202. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  33203. for (j = 0; j < 64; j++) {
  33204. z = dctZigZag[j];
  33205. tableData[z] = readUint16();
  33206. }
  33207. } else {
  33208. throw 'DQT: invalid table spec';
  33209. }
  33210. quantizationTables[quantizationTableSpec & 15] = tableData;
  33211. }
  33212. break;
  33213. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  33214. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  33215. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  33216. if (frame) {
  33217. throw 'Only single frame JPEGs supported';
  33218. }
  33219. readUint16(); // skip data length
  33220. frame = {};
  33221. frame.extended = (fileMarker === 0xFFC1);
  33222. frame.progressive = (fileMarker === 0xFFC2);
  33223. frame.precision = data[offset++];
  33224. frame.scanLines = readUint16();
  33225. frame.samplesPerLine = readUint16();
  33226. frame.components = [];
  33227. frame.componentIds = {};
  33228. var componentsCount = data[offset++], componentId;
  33229. var maxH = 0, maxV = 0;
  33230. for (i = 0; i < componentsCount; i++) {
  33231. componentId = data[offset];
  33232. var h = data[offset + 1] >> 4;
  33233. var v = data[offset + 1] & 15;
  33234. if (maxH < h) {
  33235. maxH = h;
  33236. }
  33237. if (maxV < v) {
  33238. maxV = v;
  33239. }
  33240. var qId = data[offset + 2];
  33241. l = frame.components.push({
  33242. h: h,
  33243. v: v,
  33244. quantizationTable: quantizationTables[qId]
  33245. });
  33246. frame.componentIds[componentId] = l - 1;
  33247. offset += 3;
  33248. }
  33249. frame.maxH = maxH;
  33250. frame.maxV = maxV;
  33251. prepareComponents(frame);
  33252. break;
  33253. case 0xFFC4: // DHT (Define Huffman Tables)
  33254. var huffmanLength = readUint16();
  33255. for (i = 2; i < huffmanLength;) {
  33256. var huffmanTableSpec = data[offset++];
  33257. var codeLengths = new Uint8Array(16);
  33258. var codeLengthSum = 0;
  33259. for (j = 0; j < 16; j++, offset++) {
  33260. codeLengthSum += (codeLengths[j] = data[offset]);
  33261. }
  33262. var huffmanValues = new Uint8Array(codeLengthSum);
  33263. for (j = 0; j < codeLengthSum; j++, offset++) {
  33264. huffmanValues[j] = data[offset];
  33265. }
  33266. i += 17 + codeLengthSum;
  33267. ((huffmanTableSpec >> 4) === 0 ?
  33268. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33269. buildHuffmanTable(codeLengths, huffmanValues);
  33270. }
  33271. break;
  33272. case 0xFFDD: // DRI (Define Restart Interval)
  33273. readUint16(); // skip data length
  33274. resetInterval = readUint16();
  33275. break;
  33276. case 0xFFDA: // SOS (Start of Scan)
  33277. var scanLength = readUint16();
  33278. var selectorsCount = data[offset++];
  33279. var components = [], component;
  33280. for (i = 0; i < selectorsCount; i++) {
  33281. var componentIndex = frame.componentIds[data[offset++]];
  33282. component = frame.components[componentIndex];
  33283. var tableSpec = data[offset++];
  33284. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33285. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33286. components.push(component);
  33287. }
  33288. var spectralStart = data[offset++];
  33289. var spectralEnd = data[offset++];
  33290. var successiveApproximation = data[offset++];
  33291. var processed = decodeScan(data, offset,
  33292. frame, components, resetInterval,
  33293. spectralStart, spectralEnd,
  33294. successiveApproximation >> 4, successiveApproximation & 15);
  33295. offset += processed;
  33296. break;
  33297. case 0xFFFF: // Fill bytes
  33298. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33299. offset--;
  33300. }
  33301. break;
  33302. default:
  33303. if (data[offset - 3] === 0xFF &&
  33304. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33305. // could be incorrect encoding -- last 0xFF byte of the previous
  33306. // block was eaten by the encoder
  33307. offset -= 3;
  33308. break;
  33309. }
  33310. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33311. }
  33312. fileMarker = readUint16();
  33313. }
  33314. this.width = frame.samplesPerLine;
  33315. this.height = frame.scanLines;
  33316. this.jfif = jfif;
  33317. this.adobe = adobe;
  33318. this.components = [];
  33319. for (i = 0; i < frame.components.length; i++) {
  33320. component = frame.components[i];
  33321. this.components.push({
  33322. output: buildComponentData(frame, component),
  33323. scaleX: component.h / frame.maxH,
  33324. scaleY: component.v / frame.maxV,
  33325. blocksPerLine: component.blocksPerLine,
  33326. blocksPerColumn: component.blocksPerColumn
  33327. });
  33328. }
  33329. this.numComponents = this.components.length;
  33330. },
  33331. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33332. var scaleX = this.width / width, scaleY = this.height / height;
  33333. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33334. var x, y, i, j, k;
  33335. var index;
  33336. var offset = 0;
  33337. var output;
  33338. var numComponents = this.components.length;
  33339. var dataLength = width * height * numComponents;
  33340. var data = new Uint8Array(dataLength);
  33341. var xScaleBlockOffset = new Uint32Array(width);
  33342. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33343. for (i = 0; i < numComponents; i++) {
  33344. component = this.components[i];
  33345. componentScaleX = component.scaleX * scaleX;
  33346. componentScaleY = component.scaleY * scaleY;
  33347. offset = i;
  33348. output = component.output;
  33349. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33350. // precalculate the xScaleBlockOffset
  33351. for (x = 0; x < width; x++) {
  33352. j = 0 | (x * componentScaleX);
  33353. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33354. }
  33355. // linearize the blocks of the component
  33356. for (y = 0; y < height; y++) {
  33357. j = 0 | (y * componentScaleY);
  33358. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33359. for (x = 0; x < width; x++) {
  33360. data[offset] = output[index + xScaleBlockOffset[x]];
  33361. offset += numComponents;
  33362. }
  33363. }
  33364. }
  33365. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33366. var transform = this.decodeTransform;
  33367. if (transform) {
  33368. for (i = 0; i < dataLength;) {
  33369. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33370. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33371. }
  33372. }
  33373. }
  33374. return data;
  33375. },
  33376. _isColorConversionNeeded: function isColorConversionNeeded() {
  33377. if (this.adobe && this.adobe.transformCode) {
  33378. // The adobe transform marker overrides any previous setting
  33379. return true;
  33380. } else if (this.numComponents === 3) {
  33381. return true;
  33382. } else {
  33383. return false;
  33384. }
  33385. },
  33386. _convertYccToRgb: function convertYccToRgb(data) {
  33387. var Y, Cb, Cr;
  33388. for (var i = 0, length = data.length; i < length; i += 3) {
  33389. Y = data[i ];
  33390. Cb = data[i + 1];
  33391. Cr = data[i + 2];
  33392. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33393. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33394. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33395. }
  33396. return data;
  33397. },
  33398. _convertYcckToRgb: function convertYcckToRgb(data) {
  33399. var Y, Cb, Cr, k;
  33400. var offset = 0;
  33401. for (var i = 0, length = data.length; i < length; i += 4) {
  33402. Y = data[i];
  33403. Cb = data[i + 1];
  33404. Cr = data[i + 2];
  33405. k = data[i + 3];
  33406. var r = -122.67195406894 +
  33407. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33408. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33409. 0.154362151871126) +
  33410. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33411. 0.00477271405408747 * k + 1.53380253221734) +
  33412. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33413. 0.48357088451265) +
  33414. k * (-0.000336197177618394 * k + 0.484791561490776);
  33415. var g = 107.268039397724 +
  33416. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33417. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33418. 0.176491792462875) +
  33419. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33420. 0.000770482631801132 * k - 0.151051492775562) +
  33421. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33422. 0.25802910206845) +
  33423. k * (-0.000318913117588328 * k - 0.213742400323665);
  33424. var b = -20.810012546947 +
  33425. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33426. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33427. 0.814272968359295) +
  33428. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33429. 0.000560833691242812 * k - 0.195152027534049) +
  33430. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33431. 0.116935020465145) +
  33432. k * (-0.000343531996510555 * k + 0.24165260232407);
  33433. data[offset++] = clamp0to255(r);
  33434. data[offset++] = clamp0to255(g);
  33435. data[offset++] = clamp0to255(b);
  33436. }
  33437. return data;
  33438. },
  33439. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33440. var Y, Cb, Cr;
  33441. for (var i = 0, length = data.length; i < length; i += 4) {
  33442. Y = data[i];
  33443. Cb = data[i + 1];
  33444. Cr = data[i + 2];
  33445. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33446. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33447. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33448. // K in data[i + 3] is unchanged
  33449. }
  33450. return data;
  33451. },
  33452. _convertCmykToRgb: function convertCmykToRgb(data) {
  33453. var c, m, y, k;
  33454. var offset = 0;
  33455. var min = -255 * 255 * 255;
  33456. var scale = 1 / 255 / 255;
  33457. for (var i = 0, length = data.length; i < length; i += 4) {
  33458. c = data[i];
  33459. m = data[i + 1];
  33460. y = data[i + 2];
  33461. k = data[i + 3];
  33462. var r =
  33463. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33464. 18.82290502165302 * y + 212.25662451639585 * k -
  33465. 72734.4411664936) +
  33466. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33467. 17.873870861415444 * k - 1401.7366389350734) +
  33468. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33469. 4465.541406466231) -
  33470. k * (21.86122147463605 * k + 48317.86113160301);
  33471. var g =
  33472. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33473. 6.871425592049007 * y + 31.159100130055922 * k -
  33474. 20220.756542821975) +
  33475. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33476. 131.35250912493976 * k - 48691.05921601825) +
  33477. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33478. 6341.191035517494) -
  33479. k * (20.737325471181034 * k + 47890.15695978492);
  33480. var b =
  33481. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33482. 30.89978309703729 * y - 0.23883238689178934 * k -
  33483. 3616.812083916688) +
  33484. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33485. 50.606957656360734 * k - 28620.90484698408) +
  33486. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33487. 49363.43385999684) -
  33488. k * (22.33816807309886 * k + 45932.16563550634);
  33489. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33490. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33491. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33492. }
  33493. return data;
  33494. },
  33495. getData: function getData(width, height, forceRGBoutput) {
  33496. if (this.numComponents > 4) {
  33497. throw 'Unsupported color mode';
  33498. }
  33499. // type of data: Uint8Array(width * height * numComponents)
  33500. var data = this._getLinearizedBlockData(width, height);
  33501. if (this.numComponents === 3) {
  33502. return this._convertYccToRgb(data);
  33503. } else if (this.numComponents === 4) {
  33504. if (this._isColorConversionNeeded()) {
  33505. if (forceRGBoutput) {
  33506. return this._convertYcckToRgb(data);
  33507. } else {
  33508. return this._convertYcckToCmyk(data);
  33509. }
  33510. } else if (forceRGBoutput) {
  33511. return this._convertCmykToRgb(data);
  33512. }
  33513. }
  33514. return data;
  33515. }
  33516. };
  33517. return constructor;
  33518. })();
  33519. var JpxImage = (function JpxImageClosure() {
  33520. // Table E.1
  33521. var SubbandsGainLog2 = {
  33522. 'LL': 0,
  33523. 'LH': 1,
  33524. 'HL': 1,
  33525. 'HH': 2
  33526. };
  33527. function JpxImage() {
  33528. this.failOnCorruptedImage = false;
  33529. }
  33530. JpxImage.prototype = {
  33531. parse: function JpxImage_parse(data) {
  33532. var head = readUint16(data, 0);
  33533. // No box header, immediate start of codestream (SOC)
  33534. if (head === 0xFF4F) {
  33535. this.parseCodestream(data, 0, data.length);
  33536. return;
  33537. }
  33538. var position = 0, length = data.length;
  33539. while (position < length) {
  33540. var headerSize = 8;
  33541. var lbox = readUint32(data, position);
  33542. var tbox = readUint32(data, position + 4);
  33543. position += headerSize;
  33544. if (lbox === 1) {
  33545. // XLBox: read UInt64 according to spec.
  33546. // JavaScript's int precision of 53 bit should be sufficient here.
  33547. lbox = readUint32(data, position) * 4294967296 +
  33548. readUint32(data, position + 4);
  33549. position += 8;
  33550. headerSize += 8;
  33551. }
  33552. if (lbox === 0) {
  33553. lbox = length - position + headerSize;
  33554. }
  33555. if (lbox < headerSize) {
  33556. throw new Error('JPX Error: Invalid box field size');
  33557. }
  33558. var dataLength = lbox - headerSize;
  33559. var jumpDataLength = true;
  33560. switch (tbox) {
  33561. case 0x6A703268: // 'jp2h'
  33562. jumpDataLength = false; // parsing child boxes
  33563. break;
  33564. case 0x636F6C72: // 'colr'
  33565. // Colorspaces are not used, the CS from the PDF is used.
  33566. var method = data[position];
  33567. var precedence = data[position + 1];
  33568. var approximation = data[position + 2];
  33569. if (method === 1) {
  33570. // enumerated colorspace
  33571. var colorspace = readUint32(data, position + 3);
  33572. switch (colorspace) {
  33573. case 16: // this indicates a sRGB colorspace
  33574. case 17: // this indicates a grayscale colorspace
  33575. case 18: // this indicates a YUV colorspace
  33576. break;
  33577. default:
  33578. warn('Unknown colorspace ' + colorspace);
  33579. break;
  33580. }
  33581. } else if (method === 2) {
  33582. info('ICC profile not supported');
  33583. }
  33584. break;
  33585. case 0x6A703263: // 'jp2c'
  33586. this.parseCodestream(data, position, position + dataLength);
  33587. break;
  33588. case 0x6A502020: // 'jP\024\024'
  33589. if (0x0d0a870a !== readUint32(data, position)) {
  33590. warn('Invalid JP2 signature');
  33591. }
  33592. break;
  33593. // The following header types are valid but currently not used:
  33594. case 0x6A501A1A: // 'jP\032\032'
  33595. case 0x66747970: // 'ftyp'
  33596. case 0x72726571: // 'rreq'
  33597. case 0x72657320: // 'res '
  33598. case 0x69686472: // 'ihdr'
  33599. break;
  33600. default:
  33601. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33602. (tbox >> 16) & 0xFF,
  33603. (tbox >> 8) & 0xFF,
  33604. tbox & 0xFF);
  33605. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33606. break;
  33607. }
  33608. if (jumpDataLength) {
  33609. position += dataLength;
  33610. }
  33611. }
  33612. },
  33613. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33614. var newByte = stream.getByte();
  33615. while (newByte >= 0) {
  33616. var oldByte = newByte;
  33617. newByte = stream.getByte();
  33618. var code = (oldByte << 8) | newByte;
  33619. // Image and tile size (SIZ)
  33620. if (code === 0xFF51) {
  33621. stream.skip(4);
  33622. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33623. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33624. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33625. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33626. stream.skip(16);
  33627. var Csiz = stream.getUint16(); // Byte 36
  33628. this.width = Xsiz - XOsiz;
  33629. this.height = Ysiz - YOsiz;
  33630. this.componentsCount = Csiz;
  33631. // Results are always returned as Uint8Arrays
  33632. this.bitsPerComponent = 8;
  33633. return;
  33634. }
  33635. }
  33636. throw new Error('JPX Error: No size marker found in JPX stream');
  33637. },
  33638. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33639. var context = {};
  33640. try {
  33641. var doNotRecover = false;
  33642. var position = start;
  33643. while (position + 1 < end) {
  33644. var code = readUint16(data, position);
  33645. position += 2;
  33646. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33647. switch (code) {
  33648. case 0xFF4F: // Start of codestream (SOC)
  33649. context.mainHeader = true;
  33650. break;
  33651. case 0xFFD9: // End of codestream (EOC)
  33652. break;
  33653. case 0xFF51: // Image and tile size (SIZ)
  33654. length = readUint16(data, position);
  33655. var siz = {};
  33656. siz.Xsiz = readUint32(data, position + 4);
  33657. siz.Ysiz = readUint32(data, position + 8);
  33658. siz.XOsiz = readUint32(data, position + 12);
  33659. siz.YOsiz = readUint32(data, position + 16);
  33660. siz.XTsiz = readUint32(data, position + 20);
  33661. siz.YTsiz = readUint32(data, position + 24);
  33662. siz.XTOsiz = readUint32(data, position + 28);
  33663. siz.YTOsiz = readUint32(data, position + 32);
  33664. var componentsCount = readUint16(data, position + 36);
  33665. siz.Csiz = componentsCount;
  33666. var components = [];
  33667. j = position + 38;
  33668. for (var i = 0; i < componentsCount; i++) {
  33669. var component = {
  33670. precision: (data[j] & 0x7F) + 1,
  33671. isSigned: !!(data[j] & 0x80),
  33672. XRsiz: data[j + 1],
  33673. YRsiz: data[j + 1]
  33674. };
  33675. calculateComponentDimensions(component, siz);
  33676. components.push(component);
  33677. }
  33678. context.SIZ = siz;
  33679. context.components = components;
  33680. calculateTileGrids(context, components);
  33681. context.QCC = [];
  33682. context.COC = [];
  33683. break;
  33684. case 0xFF5C: // Quantization default (QCD)
  33685. length = readUint16(data, position);
  33686. var qcd = {};
  33687. j = position + 2;
  33688. sqcd = data[j++];
  33689. switch (sqcd & 0x1F) {
  33690. case 0:
  33691. spqcdSize = 8;
  33692. scalarExpounded = true;
  33693. break;
  33694. case 1:
  33695. spqcdSize = 16;
  33696. scalarExpounded = false;
  33697. break;
  33698. case 2:
  33699. spqcdSize = 16;
  33700. scalarExpounded = true;
  33701. break;
  33702. default:
  33703. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33704. }
  33705. qcd.noQuantization = (spqcdSize === 8);
  33706. qcd.scalarExpounded = scalarExpounded;
  33707. qcd.guardBits = sqcd >> 5;
  33708. spqcds = [];
  33709. while (j < length + position) {
  33710. var spqcd = {};
  33711. if (spqcdSize === 8) {
  33712. spqcd.epsilon = data[j++] >> 3;
  33713. spqcd.mu = 0;
  33714. } else {
  33715. spqcd.epsilon = data[j] >> 3;
  33716. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33717. j += 2;
  33718. }
  33719. spqcds.push(spqcd);
  33720. }
  33721. qcd.SPqcds = spqcds;
  33722. if (context.mainHeader) {
  33723. context.QCD = qcd;
  33724. } else {
  33725. context.currentTile.QCD = qcd;
  33726. context.currentTile.QCC = [];
  33727. }
  33728. break;
  33729. case 0xFF5D: // Quantization component (QCC)
  33730. length = readUint16(data, position);
  33731. var qcc = {};
  33732. j = position + 2;
  33733. var cqcc;
  33734. if (context.SIZ.Csiz < 257) {
  33735. cqcc = data[j++];
  33736. } else {
  33737. cqcc = readUint16(data, j);
  33738. j += 2;
  33739. }
  33740. sqcd = data[j++];
  33741. switch (sqcd & 0x1F) {
  33742. case 0:
  33743. spqcdSize = 8;
  33744. scalarExpounded = true;
  33745. break;
  33746. case 1:
  33747. spqcdSize = 16;
  33748. scalarExpounded = false;
  33749. break;
  33750. case 2:
  33751. spqcdSize = 16;
  33752. scalarExpounded = true;
  33753. break;
  33754. default:
  33755. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33756. }
  33757. qcc.noQuantization = (spqcdSize === 8);
  33758. qcc.scalarExpounded = scalarExpounded;
  33759. qcc.guardBits = sqcd >> 5;
  33760. spqcds = [];
  33761. while (j < (length + position)) {
  33762. spqcd = {};
  33763. if (spqcdSize === 8) {
  33764. spqcd.epsilon = data[j++] >> 3;
  33765. spqcd.mu = 0;
  33766. } else {
  33767. spqcd.epsilon = data[j] >> 3;
  33768. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33769. j += 2;
  33770. }
  33771. spqcds.push(spqcd);
  33772. }
  33773. qcc.SPqcds = spqcds;
  33774. if (context.mainHeader) {
  33775. context.QCC[cqcc] = qcc;
  33776. } else {
  33777. context.currentTile.QCC[cqcc] = qcc;
  33778. }
  33779. break;
  33780. case 0xFF52: // Coding style default (COD)
  33781. length = readUint16(data, position);
  33782. var cod = {};
  33783. j = position + 2;
  33784. var scod = data[j++];
  33785. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33786. cod.sopMarkerUsed = !!(scod & 2);
  33787. cod.ephMarkerUsed = !!(scod & 4);
  33788. cod.progressionOrder = data[j++];
  33789. cod.layersCount = readUint16(data, j);
  33790. j += 2;
  33791. cod.multipleComponentTransform = data[j++];
  33792. cod.decompositionLevelsCount = data[j++];
  33793. cod.xcb = (data[j++] & 0xF) + 2;
  33794. cod.ycb = (data[j++] & 0xF) + 2;
  33795. var blockStyle = data[j++];
  33796. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33797. cod.resetContextProbabilities = !!(blockStyle & 2);
  33798. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33799. cod.verticalyStripe = !!(blockStyle & 8);
  33800. cod.predictableTermination = !!(blockStyle & 16);
  33801. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33802. cod.reversibleTransformation = data[j++];
  33803. if (cod.entropyCoderWithCustomPrecincts) {
  33804. var precinctsSizes = [];
  33805. while (j < length + position) {
  33806. var precinctsSize = data[j++];
  33807. precinctsSizes.push({
  33808. PPx: precinctsSize & 0xF,
  33809. PPy: precinctsSize >> 4
  33810. });
  33811. }
  33812. cod.precinctsSizes = precinctsSizes;
  33813. }
  33814. var unsupported = [];
  33815. if (cod.selectiveArithmeticCodingBypass) {
  33816. unsupported.push('selectiveArithmeticCodingBypass');
  33817. }
  33818. if (cod.resetContextProbabilities) {
  33819. unsupported.push('resetContextProbabilities');
  33820. }
  33821. if (cod.terminationOnEachCodingPass) {
  33822. unsupported.push('terminationOnEachCodingPass');
  33823. }
  33824. if (cod.verticalyStripe) {
  33825. unsupported.push('verticalyStripe');
  33826. }
  33827. if (cod.predictableTermination) {
  33828. unsupported.push('predictableTermination');
  33829. }
  33830. if (unsupported.length > 0) {
  33831. doNotRecover = true;
  33832. throw new Error('JPX Error: Unsupported COD options (' +
  33833. unsupported.join(', ') + ')');
  33834. }
  33835. if (context.mainHeader) {
  33836. context.COD = cod;
  33837. } else {
  33838. context.currentTile.COD = cod;
  33839. context.currentTile.COC = [];
  33840. }
  33841. break;
  33842. case 0xFF90: // Start of tile-part (SOT)
  33843. length = readUint16(data, position);
  33844. tile = {};
  33845. tile.index = readUint16(data, position + 2);
  33846. tile.length = readUint32(data, position + 4);
  33847. tile.dataEnd = tile.length + position - 2;
  33848. tile.partIndex = data[position + 8];
  33849. tile.partsCount = data[position + 9];
  33850. context.mainHeader = false;
  33851. if (tile.partIndex === 0) {
  33852. // reset component specific settings
  33853. tile.COD = context.COD;
  33854. tile.COC = context.COC.slice(0); // clone of the global COC
  33855. tile.QCD = context.QCD;
  33856. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33857. }
  33858. context.currentTile = tile;
  33859. break;
  33860. case 0xFF93: // Start of data (SOD)
  33861. tile = context.currentTile;
  33862. if (tile.partIndex === 0) {
  33863. initializeTile(context, tile.index);
  33864. buildPackets(context);
  33865. }
  33866. // moving to the end of the data
  33867. length = tile.dataEnd - position;
  33868. parseTilePackets(context, data, position, length);
  33869. break;
  33870. case 0xFF55: // Tile-part lengths, main header (TLM)
  33871. case 0xFF57: // Packet length, main header (PLM)
  33872. case 0xFF58: // Packet length, tile-part header (PLT)
  33873. case 0xFF64: // Comment (COM)
  33874. length = readUint16(data, position);
  33875. // skipping content
  33876. break;
  33877. case 0xFF53: // Coding style component (COC)
  33878. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33879. 'not implemented');
  33880. default:
  33881. throw new Error('JPX Error: Unknown codestream code: ' +
  33882. code.toString(16));
  33883. }
  33884. position += length;
  33885. }
  33886. } catch (e) {
  33887. if (doNotRecover || this.failOnCorruptedImage) {
  33888. throw e;
  33889. } else {
  33890. warn('Trying to recover from ' + e.message);
  33891. }
  33892. }
  33893. this.tiles = transformComponents(context);
  33894. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33895. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33896. this.componentsCount = context.SIZ.Csiz;
  33897. }
  33898. };
  33899. function calculateComponentDimensions(component, siz) {
  33900. // Section B.2 Component mapping
  33901. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33902. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33903. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33904. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33905. component.width = component.x1 - component.x0;
  33906. component.height = component.y1 - component.y0;
  33907. }
  33908. function calculateTileGrids(context, components) {
  33909. var siz = context.SIZ;
  33910. // Section B.3 Division into tile and tile-components
  33911. var tile, tiles = [];
  33912. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33913. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33914. for (var q = 0; q < numYtiles; q++) {
  33915. for (var p = 0; p < numXtiles; p++) {
  33916. tile = {};
  33917. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33918. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33919. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33920. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33921. tile.width = tile.tx1 - tile.tx0;
  33922. tile.height = tile.ty1 - tile.ty0;
  33923. tile.components = [];
  33924. tiles.push(tile);
  33925. }
  33926. }
  33927. context.tiles = tiles;
  33928. var componentsCount = siz.Csiz;
  33929. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33930. var component = components[i];
  33931. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33932. var tileComponent = {};
  33933. tile = tiles[j];
  33934. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33935. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33936. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33937. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33938. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33939. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33940. tile.components[i] = tileComponent;
  33941. }
  33942. }
  33943. }
  33944. function getBlocksDimensions(context, component, r) {
  33945. var codOrCoc = component.codingStyleParameters;
  33946. var result = {};
  33947. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33948. result.PPx = 15;
  33949. result.PPy = 15;
  33950. } else {
  33951. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33952. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33953. }
  33954. // calculate codeblock size as described in section B.7
  33955. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33956. Math.min(codOrCoc.xcb, result.PPx));
  33957. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33958. Math.min(codOrCoc.ycb, result.PPy));
  33959. return result;
  33960. }
  33961. function buildPrecincts(context, resolution, dimensions) {
  33962. // Section B.6 Division resolution to precincts
  33963. var precinctWidth = 1 << dimensions.PPx;
  33964. var precinctHeight = 1 << dimensions.PPy;
  33965. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33966. // to precincts. Precinct partition divides a resolution according to width
  33967. // and height parameters. The subband that belongs to the resolution level
  33968. // has a different size than the level, unless it is the zero resolution.
  33969. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33970. // The precinct partitioning for a particular subband is derived from a
  33971. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33972. // resolution level)... The LL band associated with each resolution level is
  33973. // divided into precincts... Each of the resulting precinct regions is then
  33974. // mapped into its child subbands (if any) at the next lower resolution
  33975. // level. This is accomplished by using the coordinate transformation
  33976. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33977. // coordinates of a point in the LL band and child subband, respectively.
  33978. var isZeroRes = resolution.resLevel === 0;
  33979. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33980. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33981. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33982. Math.ceil(resolution.trx1 / precinctWidth) -
  33983. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33984. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33985. Math.ceil(resolution.try1 / precinctHeight) -
  33986. Math.floor(resolution.try0 / precinctHeight) : 0);
  33987. var numprecincts = numprecinctswide * numprecinctshigh;
  33988. resolution.precinctParameters = {
  33989. precinctWidth: precinctWidth,
  33990. precinctHeight: precinctHeight,
  33991. numprecinctswide: numprecinctswide,
  33992. numprecinctshigh: numprecinctshigh,
  33993. numprecincts: numprecincts,
  33994. precinctWidthInSubband: precinctWidthInSubband,
  33995. precinctHeightInSubband: precinctHeightInSubband
  33996. };
  33997. }
  33998. function buildCodeblocks(context, subband, dimensions) {
  33999. // Section B.7 Division sub-band into code-blocks
  34000. var xcb_ = dimensions.xcb_;
  34001. var ycb_ = dimensions.ycb_;
  34002. var codeblockWidth = 1 << xcb_;
  34003. var codeblockHeight = 1 << ycb_;
  34004. var cbx0 = subband.tbx0 >> xcb_;
  34005. var cby0 = subband.tby0 >> ycb_;
  34006. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  34007. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  34008. var precinctParameters = subband.resolution.precinctParameters;
  34009. var codeblocks = [];
  34010. var precincts = [];
  34011. var i, j, codeblock, precinctNumber;
  34012. for (j = cby0; j < cby1; j++) {
  34013. for (i = cbx0; i < cbx1; i++) {
  34014. codeblock = {
  34015. cbx: i,
  34016. cby: j,
  34017. tbx0: codeblockWidth * i,
  34018. tby0: codeblockHeight * j,
  34019. tbx1: codeblockWidth * (i + 1),
  34020. tby1: codeblockHeight * (j + 1)
  34021. };
  34022. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  34023. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  34024. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  34025. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  34026. // Calculate precinct number for this codeblock, codeblock position
  34027. // should be relative to its subband, use actual dimension and position
  34028. // See comment about codeblock group width and height
  34029. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  34030. precinctParameters.precinctWidthInSubband);
  34031. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  34032. precinctParameters.precinctHeightInSubband);
  34033. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  34034. codeblock.precinctNumber = precinctNumber;
  34035. codeblock.subbandType = subband.type;
  34036. codeblock.Lblock = 3;
  34037. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  34038. codeblock.tby1_ <= codeblock.tby0_) {
  34039. continue;
  34040. }
  34041. codeblocks.push(codeblock);
  34042. // building precinct for the sub-band
  34043. var precinct = precincts[precinctNumber];
  34044. if (precinct !== undefined) {
  34045. if (i < precinct.cbxMin) {
  34046. precinct.cbxMin = i;
  34047. } else if (i > precinct.cbxMax) {
  34048. precinct.cbxMax = i;
  34049. }
  34050. if (j < precinct.cbyMin) {
  34051. precinct.cbxMin = j;
  34052. } else if (j > precinct.cbyMax) {
  34053. precinct.cbyMax = j;
  34054. }
  34055. } else {
  34056. precincts[precinctNumber] = precinct = {
  34057. cbxMin: i,
  34058. cbyMin: j,
  34059. cbxMax: i,
  34060. cbyMax: j
  34061. };
  34062. }
  34063. codeblock.precinct = precinct;
  34064. }
  34065. }
  34066. subband.codeblockParameters = {
  34067. codeblockWidth: xcb_,
  34068. codeblockHeight: ycb_,
  34069. numcodeblockwide: cbx1 - cbx0 + 1,
  34070. numcodeblockhigh: cby1 - cby0 + 1
  34071. };
  34072. subband.codeblocks = codeblocks;
  34073. subband.precincts = precincts;
  34074. }
  34075. function createPacket(resolution, precinctNumber, layerNumber) {
  34076. var precinctCodeblocks = [];
  34077. // Section B.10.8 Order of info in packet
  34078. var subbands = resolution.subbands;
  34079. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  34080. for (var i = 0, ii = subbands.length; i < ii; i++) {
  34081. var subband = subbands[i];
  34082. var codeblocks = subband.codeblocks;
  34083. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  34084. var codeblock = codeblocks[j];
  34085. if (codeblock.precinctNumber !== precinctNumber) {
  34086. continue;
  34087. }
  34088. precinctCodeblocks.push(codeblock);
  34089. }
  34090. }
  34091. return {
  34092. layerNumber: layerNumber,
  34093. codeblocks: precinctCodeblocks
  34094. };
  34095. }
  34096. function LayerResolutionComponentPositionIterator(context) {
  34097. var siz = context.SIZ;
  34098. var tileIndex = context.currentTile.index;
  34099. var tile = context.tiles[tileIndex];
  34100. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34101. var componentsCount = siz.Csiz;
  34102. var maxDecompositionLevelsCount = 0;
  34103. for (var q = 0; q < componentsCount; q++) {
  34104. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34105. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34106. }
  34107. var l = 0, r = 0, i = 0, k = 0;
  34108. this.nextPacket = function JpxImage_nextPacket() {
  34109. // Section B.12.1.1 Layer-resolution-component-position
  34110. for (; l < layersCount; l++) {
  34111. for (; r <= maxDecompositionLevelsCount; r++) {
  34112. for (; i < componentsCount; i++) {
  34113. var component = tile.components[i];
  34114. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34115. continue;
  34116. }
  34117. var resolution = component.resolutions[r];
  34118. var numprecincts = resolution.precinctParameters.numprecincts;
  34119. for (; k < numprecincts;) {
  34120. var packet = createPacket(resolution, k, l);
  34121. k++;
  34122. return packet;
  34123. }
  34124. k = 0;
  34125. }
  34126. i = 0;
  34127. }
  34128. r = 0;
  34129. }
  34130. throw new Error('JPX Error: Out of packets');
  34131. };
  34132. }
  34133. function ResolutionLayerComponentPositionIterator(context) {
  34134. var siz = context.SIZ;
  34135. var tileIndex = context.currentTile.index;
  34136. var tile = context.tiles[tileIndex];
  34137. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34138. var componentsCount = siz.Csiz;
  34139. var maxDecompositionLevelsCount = 0;
  34140. for (var q = 0; q < componentsCount; q++) {
  34141. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34142. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34143. }
  34144. var r = 0, l = 0, i = 0, k = 0;
  34145. this.nextPacket = function JpxImage_nextPacket() {
  34146. // Section B.12.1.2 Resolution-layer-component-position
  34147. for (; r <= maxDecompositionLevelsCount; r++) {
  34148. for (; l < layersCount; l++) {
  34149. for (; i < componentsCount; i++) {
  34150. var component = tile.components[i];
  34151. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34152. continue;
  34153. }
  34154. var resolution = component.resolutions[r];
  34155. var numprecincts = resolution.precinctParameters.numprecincts;
  34156. for (; k < numprecincts;) {
  34157. var packet = createPacket(resolution, k, l);
  34158. k++;
  34159. return packet;
  34160. }
  34161. k = 0;
  34162. }
  34163. i = 0;
  34164. }
  34165. l = 0;
  34166. }
  34167. throw new Error('JPX Error: Out of packets');
  34168. };
  34169. }
  34170. function ResolutionPositionComponentLayerIterator(context) {
  34171. var siz = context.SIZ;
  34172. var tileIndex = context.currentTile.index;
  34173. var tile = context.tiles[tileIndex];
  34174. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34175. var componentsCount = siz.Csiz;
  34176. var l, r, c, p;
  34177. var maxDecompositionLevelsCount = 0;
  34178. for (c = 0; c < componentsCount; c++) {
  34179. var component = tile.components[c];
  34180. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34181. component.codingStyleParameters.decompositionLevelsCount);
  34182. }
  34183. var maxNumPrecinctsInLevel = new Int32Array(
  34184. maxDecompositionLevelsCount + 1);
  34185. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  34186. var maxNumPrecincts = 0;
  34187. for (c = 0; c < componentsCount; ++c) {
  34188. var resolutions = tile.components[c].resolutions;
  34189. if (r < resolutions.length) {
  34190. maxNumPrecincts = Math.max(maxNumPrecincts,
  34191. resolutions[r].precinctParameters.numprecincts);
  34192. }
  34193. }
  34194. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  34195. }
  34196. l = 0;
  34197. r = 0;
  34198. c = 0;
  34199. p = 0;
  34200. this.nextPacket = function JpxImage_nextPacket() {
  34201. // Section B.12.1.3 Resolution-position-component-layer
  34202. for (; r <= maxDecompositionLevelsCount; r++) {
  34203. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  34204. for (; c < componentsCount; c++) {
  34205. var component = tile.components[c];
  34206. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34207. continue;
  34208. }
  34209. var resolution = component.resolutions[r];
  34210. var numprecincts = resolution.precinctParameters.numprecincts;
  34211. if (p >= numprecincts) {
  34212. continue;
  34213. }
  34214. for (; l < layersCount;) {
  34215. var packet = createPacket(resolution, p, l);
  34216. l++;
  34217. return packet;
  34218. }
  34219. l = 0;
  34220. }
  34221. c = 0;
  34222. }
  34223. p = 0;
  34224. }
  34225. throw new Error('JPX Error: Out of packets');
  34226. };
  34227. }
  34228. function PositionComponentResolutionLayerIterator(context) {
  34229. var siz = context.SIZ;
  34230. var tileIndex = context.currentTile.index;
  34231. var tile = context.tiles[tileIndex];
  34232. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34233. var componentsCount = siz.Csiz;
  34234. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34235. var precinctsIterationSizes = precinctsSizes;
  34236. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34237. this.nextPacket = function JpxImage_nextPacket() {
  34238. // Section B.12.1.4 Position-component-resolution-layer
  34239. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34240. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34241. for (; c < componentsCount; c++) {
  34242. var component = tile.components[c];
  34243. var decompositionLevelsCount =
  34244. component.codingStyleParameters.decompositionLevelsCount;
  34245. for (; r <= decompositionLevelsCount; r++) {
  34246. var resolution = component.resolutions[r];
  34247. var sizeInImageScale =
  34248. precinctsSizes.components[c].resolutions[r];
  34249. var k = getPrecinctIndexIfExist(
  34250. px,
  34251. py,
  34252. sizeInImageScale,
  34253. precinctsIterationSizes,
  34254. resolution);
  34255. if (k === null) {
  34256. continue;
  34257. }
  34258. for (; l < layersCount;) {
  34259. var packet = createPacket(resolution, k, l);
  34260. l++;
  34261. return packet;
  34262. }
  34263. l = 0;
  34264. }
  34265. r = 0;
  34266. }
  34267. c = 0;
  34268. }
  34269. px = 0;
  34270. }
  34271. throw new Error('JPX Error: Out of packets');
  34272. };
  34273. }
  34274. function ComponentPositionResolutionLayerIterator(context) {
  34275. var siz = context.SIZ;
  34276. var tileIndex = context.currentTile.index;
  34277. var tile = context.tiles[tileIndex];
  34278. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34279. var componentsCount = siz.Csiz;
  34280. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34281. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34282. this.nextPacket = function JpxImage_nextPacket() {
  34283. // Section B.12.1.5 Component-position-resolution-layer
  34284. for (; c < componentsCount; ++c) {
  34285. var component = tile.components[c];
  34286. var precinctsIterationSizes = precinctsSizes.components[c];
  34287. var decompositionLevelsCount =
  34288. component.codingStyleParameters.decompositionLevelsCount;
  34289. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34290. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34291. for (; r <= decompositionLevelsCount; r++) {
  34292. var resolution = component.resolutions[r];
  34293. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34294. var k = getPrecinctIndexIfExist(
  34295. px,
  34296. py,
  34297. sizeInImageScale,
  34298. precinctsIterationSizes,
  34299. resolution);
  34300. if (k === null) {
  34301. continue;
  34302. }
  34303. for (; l < layersCount;) {
  34304. var packet = createPacket(resolution, k, l);
  34305. l++;
  34306. return packet;
  34307. }
  34308. l = 0;
  34309. }
  34310. r = 0;
  34311. }
  34312. px = 0;
  34313. }
  34314. py = 0;
  34315. }
  34316. throw new Error('JPX Error: Out of packets');
  34317. };
  34318. }
  34319. function getPrecinctIndexIfExist(
  34320. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34321. var posX = pxIndex * precinctIterationSizes.minWidth;
  34322. var posY = pyIndex * precinctIterationSizes.minHeight;
  34323. if (posX % sizeInImageScale.width !== 0 ||
  34324. posY % sizeInImageScale.height !== 0) {
  34325. return null;
  34326. }
  34327. var startPrecinctRowIndex =
  34328. (posY / sizeInImageScale.width) *
  34329. resolution.precinctParameters.numprecinctswide;
  34330. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34331. }
  34332. function getPrecinctSizesInImageScale(tile) {
  34333. var componentsCount = tile.components.length;
  34334. var minWidth = Number.MAX_VALUE;
  34335. var minHeight = Number.MAX_VALUE;
  34336. var maxNumWide = 0;
  34337. var maxNumHigh = 0;
  34338. var sizePerComponent = new Array(componentsCount);
  34339. for (var c = 0; c < componentsCount; c++) {
  34340. var component = tile.components[c];
  34341. var decompositionLevelsCount =
  34342. component.codingStyleParameters.decompositionLevelsCount;
  34343. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34344. var minWidthCurrentComponent = Number.MAX_VALUE;
  34345. var minHeightCurrentComponent = Number.MAX_VALUE;
  34346. var maxNumWideCurrentComponent = 0;
  34347. var maxNumHighCurrentComponent = 0;
  34348. var scale = 1;
  34349. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34350. var resolution = component.resolutions[r];
  34351. var widthCurrentResolution =
  34352. scale * resolution.precinctParameters.precinctWidth;
  34353. var heightCurrentResolution =
  34354. scale * resolution.precinctParameters.precinctHeight;
  34355. minWidthCurrentComponent = Math.min(
  34356. minWidthCurrentComponent,
  34357. widthCurrentResolution);
  34358. minHeightCurrentComponent = Math.min(
  34359. minHeightCurrentComponent,
  34360. heightCurrentResolution);
  34361. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34362. resolution.precinctParameters.numprecinctswide);
  34363. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34364. resolution.precinctParameters.numprecinctshigh);
  34365. sizePerResolution[r] = {
  34366. width: widthCurrentResolution,
  34367. height: heightCurrentResolution
  34368. };
  34369. scale <<= 1;
  34370. }
  34371. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34372. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34373. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34374. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34375. sizePerComponent[c] = {
  34376. resolutions: sizePerResolution,
  34377. minWidth: minWidthCurrentComponent,
  34378. minHeight: minHeightCurrentComponent,
  34379. maxNumWide: maxNumWideCurrentComponent,
  34380. maxNumHigh: maxNumHighCurrentComponent
  34381. };
  34382. }
  34383. return {
  34384. components: sizePerComponent,
  34385. minWidth: minWidth,
  34386. minHeight: minHeight,
  34387. maxNumWide: maxNumWide,
  34388. maxNumHigh: maxNumHigh
  34389. };
  34390. }
  34391. function buildPackets(context) {
  34392. var siz = context.SIZ;
  34393. var tileIndex = context.currentTile.index;
  34394. var tile = context.tiles[tileIndex];
  34395. var componentsCount = siz.Csiz;
  34396. // Creating resolutions and sub-bands for each component
  34397. for (var c = 0; c < componentsCount; c++) {
  34398. var component = tile.components[c];
  34399. var decompositionLevelsCount =
  34400. component.codingStyleParameters.decompositionLevelsCount;
  34401. // Section B.5 Resolution levels and sub-bands
  34402. var resolutions = [];
  34403. var subbands = [];
  34404. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34405. var blocksDimensions = getBlocksDimensions(context, component, r);
  34406. var resolution = {};
  34407. var scale = 1 << (decompositionLevelsCount - r);
  34408. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34409. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34410. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34411. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34412. resolution.resLevel = r;
  34413. buildPrecincts(context, resolution, blocksDimensions);
  34414. resolutions.push(resolution);
  34415. var subband;
  34416. if (r === 0) {
  34417. // one sub-band (LL) with last decomposition
  34418. subband = {};
  34419. subband.type = 'LL';
  34420. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34421. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34422. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34423. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34424. subband.resolution = resolution;
  34425. buildCodeblocks(context, subband, blocksDimensions);
  34426. subbands.push(subband);
  34427. resolution.subbands = [subband];
  34428. } else {
  34429. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34430. var resolutionSubbands = [];
  34431. // three sub-bands (HL, LH and HH) with rest of decompositions
  34432. subband = {};
  34433. subband.type = 'HL';
  34434. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34435. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34436. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34437. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34438. subband.resolution = resolution;
  34439. buildCodeblocks(context, subband, blocksDimensions);
  34440. subbands.push(subband);
  34441. resolutionSubbands.push(subband);
  34442. subband = {};
  34443. subband.type = 'LH';
  34444. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34445. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34446. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34447. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34448. subband.resolution = resolution;
  34449. buildCodeblocks(context, subband, blocksDimensions);
  34450. subbands.push(subband);
  34451. resolutionSubbands.push(subband);
  34452. subband = {};
  34453. subband.type = 'HH';
  34454. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34455. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34456. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34457. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34458. subband.resolution = resolution;
  34459. buildCodeblocks(context, subband, blocksDimensions);
  34460. subbands.push(subband);
  34461. resolutionSubbands.push(subband);
  34462. resolution.subbands = resolutionSubbands;
  34463. }
  34464. }
  34465. component.resolutions = resolutions;
  34466. component.subbands = subbands;
  34467. }
  34468. // Generate the packets sequence
  34469. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34470. switch (progressionOrder) {
  34471. case 0:
  34472. tile.packetsIterator =
  34473. new LayerResolutionComponentPositionIterator(context);
  34474. break;
  34475. case 1:
  34476. tile.packetsIterator =
  34477. new ResolutionLayerComponentPositionIterator(context);
  34478. break;
  34479. case 2:
  34480. tile.packetsIterator =
  34481. new ResolutionPositionComponentLayerIterator(context);
  34482. break;
  34483. case 3:
  34484. tile.packetsIterator =
  34485. new PositionComponentResolutionLayerIterator(context);
  34486. break;
  34487. case 4:
  34488. tile.packetsIterator =
  34489. new ComponentPositionResolutionLayerIterator(context);
  34490. break;
  34491. default:
  34492. throw new Error('JPX Error: Unsupported progression order ' +
  34493. progressionOrder);
  34494. }
  34495. }
  34496. function parseTilePackets(context, data, offset, dataLength) {
  34497. var position = 0;
  34498. var buffer, bufferSize = 0, skipNextBit = false;
  34499. function readBits(count) {
  34500. while (bufferSize < count) {
  34501. var b = data[offset + position];
  34502. position++;
  34503. if (skipNextBit) {
  34504. buffer = (buffer << 7) | b;
  34505. bufferSize += 7;
  34506. skipNextBit = false;
  34507. } else {
  34508. buffer = (buffer << 8) | b;
  34509. bufferSize += 8;
  34510. }
  34511. if (b === 0xFF) {
  34512. skipNextBit = true;
  34513. }
  34514. }
  34515. bufferSize -= count;
  34516. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34517. }
  34518. function skipMarkerIfEqual(value) {
  34519. if (data[offset + position - 1] === 0xFF &&
  34520. data[offset + position] === value) {
  34521. skipBytes(1);
  34522. return true;
  34523. } else if (data[offset + position] === 0xFF &&
  34524. data[offset + position + 1] === value) {
  34525. skipBytes(2);
  34526. return true;
  34527. }
  34528. return false;
  34529. }
  34530. function skipBytes(count) {
  34531. position += count;
  34532. }
  34533. function alignToByte() {
  34534. bufferSize = 0;
  34535. if (skipNextBit) {
  34536. position++;
  34537. skipNextBit = false;
  34538. }
  34539. }
  34540. function readCodingpasses() {
  34541. if (readBits(1) === 0) {
  34542. return 1;
  34543. }
  34544. if (readBits(1) === 0) {
  34545. return 2;
  34546. }
  34547. var value = readBits(2);
  34548. if (value < 3) {
  34549. return value + 3;
  34550. }
  34551. value = readBits(5);
  34552. if (value < 31) {
  34553. return value + 6;
  34554. }
  34555. value = readBits(7);
  34556. return value + 37;
  34557. }
  34558. var tileIndex = context.currentTile.index;
  34559. var tile = context.tiles[tileIndex];
  34560. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34561. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34562. var packetsIterator = tile.packetsIterator;
  34563. while (position < dataLength) {
  34564. alignToByte();
  34565. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34566. // Skip also marker segment length and packet sequence ID
  34567. skipBytes(4);
  34568. }
  34569. var packet = packetsIterator.nextPacket();
  34570. if (!readBits(1)) {
  34571. continue;
  34572. }
  34573. var layerNumber = packet.layerNumber;
  34574. var queue = [], codeblock;
  34575. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34576. codeblock = packet.codeblocks[i];
  34577. var precinct = codeblock.precinct;
  34578. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34579. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34580. var codeblockIncluded = false;
  34581. var firstTimeInclusion = false;
  34582. var valueReady;
  34583. if (codeblock['included'] !== undefined) {
  34584. codeblockIncluded = !!readBits(1);
  34585. } else {
  34586. // reading inclusion tree
  34587. precinct = codeblock.precinct;
  34588. var inclusionTree, zeroBitPlanesTree;
  34589. if (precinct['inclusionTree'] !== undefined) {
  34590. inclusionTree = precinct.inclusionTree;
  34591. } else {
  34592. // building inclusion and zero bit-planes trees
  34593. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34594. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34595. inclusionTree = new InclusionTree(width, height, layerNumber);
  34596. zeroBitPlanesTree = new TagTree(width, height);
  34597. precinct.inclusionTree = inclusionTree;
  34598. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34599. }
  34600. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34601. while (true) {
  34602. if (readBits(1)) {
  34603. valueReady = !inclusionTree.nextLevel();
  34604. if (valueReady) {
  34605. codeblock.included = true;
  34606. codeblockIncluded = firstTimeInclusion = true;
  34607. break;
  34608. }
  34609. } else {
  34610. inclusionTree.incrementValue(layerNumber);
  34611. break;
  34612. }
  34613. }
  34614. }
  34615. }
  34616. if (!codeblockIncluded) {
  34617. continue;
  34618. }
  34619. if (firstTimeInclusion) {
  34620. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34621. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34622. while (true) {
  34623. if (readBits(1)) {
  34624. valueReady = !zeroBitPlanesTree.nextLevel();
  34625. if (valueReady) {
  34626. break;
  34627. }
  34628. } else {
  34629. zeroBitPlanesTree.incrementValue();
  34630. }
  34631. }
  34632. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34633. }
  34634. var codingpasses = readCodingpasses();
  34635. while (readBits(1)) {
  34636. codeblock.Lblock++;
  34637. }
  34638. var codingpassesLog2 = log2(codingpasses);
  34639. // rounding down log2
  34640. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34641. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34642. var codedDataLength = readBits(bits);
  34643. queue.push({
  34644. codeblock: codeblock,
  34645. codingpasses: codingpasses,
  34646. dataLength: codedDataLength
  34647. });
  34648. }
  34649. alignToByte();
  34650. if (ephMarkerUsed) {
  34651. skipMarkerIfEqual(0x92);
  34652. }
  34653. while (queue.length > 0) {
  34654. var packetItem = queue.shift();
  34655. codeblock = packetItem.codeblock;
  34656. if (codeblock['data'] === undefined) {
  34657. codeblock.data = [];
  34658. }
  34659. codeblock.data.push({
  34660. data: data,
  34661. start: offset + position,
  34662. end: offset + position + packetItem.dataLength,
  34663. codingpasses: packetItem.codingpasses
  34664. });
  34665. position += packetItem.dataLength;
  34666. }
  34667. }
  34668. return position;
  34669. }
  34670. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34671. delta, mb, reversible, segmentationSymbolUsed) {
  34672. var x0 = subband.tbx0;
  34673. var y0 = subband.tby0;
  34674. var width = subband.tbx1 - subband.tbx0;
  34675. var codeblocks = subband.codeblocks;
  34676. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34677. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34678. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34679. var codeblock = codeblocks[i];
  34680. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34681. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34682. if (blockWidth === 0 || blockHeight === 0) {
  34683. continue;
  34684. }
  34685. if (codeblock['data'] === undefined) {
  34686. continue;
  34687. }
  34688. var bitModel, currentCodingpassType;
  34689. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34690. codeblock.zeroBitPlanes, mb);
  34691. currentCodingpassType = 2; // first bit plane starts from cleanup
  34692. // collect data
  34693. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34694. var j, jj, dataItem;
  34695. for (j = 0, jj = data.length; j < jj; j++) {
  34696. dataItem = data[j];
  34697. totalLength += dataItem.end - dataItem.start;
  34698. codingpasses += dataItem.codingpasses;
  34699. }
  34700. var encodedData = new Uint8Array(totalLength);
  34701. var position = 0;
  34702. for (j = 0, jj = data.length; j < jj; j++) {
  34703. dataItem = data[j];
  34704. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34705. encodedData.set(chunk, position);
  34706. position += chunk.length;
  34707. }
  34708. // decoding the item
  34709. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34710. bitModel.setDecoder(decoder);
  34711. for (j = 0; j < codingpasses; j++) {
  34712. switch (currentCodingpassType) {
  34713. case 0:
  34714. bitModel.runSignificancePropogationPass();
  34715. break;
  34716. case 1:
  34717. bitModel.runMagnitudeRefinementPass();
  34718. break;
  34719. case 2:
  34720. bitModel.runCleanupPass();
  34721. if (segmentationSymbolUsed) {
  34722. bitModel.checkSegmentationSymbol();
  34723. }
  34724. break;
  34725. }
  34726. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34727. }
  34728. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34729. var sign = bitModel.coefficentsSign;
  34730. var magnitude = bitModel.coefficentsMagnitude;
  34731. var bitsDecoded = bitModel.bitsDecoded;
  34732. var magnitudeCorrection = reversible ? 0 : 0.5;
  34733. var k, n, nb;
  34734. position = 0;
  34735. // Do the interleaving of Section F.3.3 here, so we do not need
  34736. // to copy later. LL level is not interleaved, just copied.
  34737. var interleave = (subband.type !== 'LL');
  34738. for (j = 0; j < blockHeight; j++) {
  34739. var row = (offset / width) | 0; // row in the non-interleaved subband
  34740. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34741. for (k = 0; k < blockWidth; k++) {
  34742. n = magnitude[position];
  34743. if (n !== 0) {
  34744. n = (n + magnitudeCorrection) * delta;
  34745. if (sign[position] !== 0) {
  34746. n = -n;
  34747. }
  34748. nb = bitsDecoded[position];
  34749. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34750. if (reversible && (nb >= mb)) {
  34751. coefficients[pos] = n;
  34752. } else {
  34753. coefficients[pos] = n * (1 << (mb - nb));
  34754. }
  34755. }
  34756. offset++;
  34757. position++;
  34758. }
  34759. offset += width - blockWidth;
  34760. }
  34761. }
  34762. }
  34763. function transformTile(context, tile, c) {
  34764. var component = tile.components[c];
  34765. var codingStyleParameters = component.codingStyleParameters;
  34766. var quantizationParameters = component.quantizationParameters;
  34767. var decompositionLevelsCount =
  34768. codingStyleParameters.decompositionLevelsCount;
  34769. var spqcds = quantizationParameters.SPqcds;
  34770. var scalarExpounded = quantizationParameters.scalarExpounded;
  34771. var guardBits = quantizationParameters.guardBits;
  34772. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34773. var precision = context.components[c].precision;
  34774. var reversible = codingStyleParameters.reversibleTransformation;
  34775. var transform = (reversible ? new ReversibleTransform() :
  34776. new IrreversibleTransform());
  34777. var subbandCoefficients = [];
  34778. var b = 0;
  34779. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34780. var resolution = component.resolutions[i];
  34781. var width = resolution.trx1 - resolution.trx0;
  34782. var height = resolution.try1 - resolution.try0;
  34783. // Allocate space for the whole sublevel.
  34784. var coefficients = new Float32Array(width * height);
  34785. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34786. var mu, epsilon;
  34787. if (!scalarExpounded) {
  34788. // formula E-5
  34789. mu = spqcds[0].mu;
  34790. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34791. } else {
  34792. mu = spqcds[b].mu;
  34793. epsilon = spqcds[b].epsilon;
  34794. b++;
  34795. }
  34796. var subband = resolution.subbands[j];
  34797. var gainLog2 = SubbandsGainLog2[subband.type];
  34798. // calulate quantization coefficient (Section E.1.1.1)
  34799. var delta = (reversible ? 1 :
  34800. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34801. var mb = (guardBits + epsilon - 1);
  34802. // In the first resolution level, copyCoefficients will fill the
  34803. // whole array with coefficients. In the succeding passes,
  34804. // copyCoefficients will consecutively fill in the values that belong
  34805. // to the interleaved positions of the HL, LH, and HH coefficients.
  34806. // The LL coefficients will then be interleaved in Transform.iterate().
  34807. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34808. reversible, segmentationSymbolUsed);
  34809. }
  34810. subbandCoefficients.push({
  34811. width: width,
  34812. height: height,
  34813. items: coefficients
  34814. });
  34815. }
  34816. var result = transform.calculate(subbandCoefficients,
  34817. component.tcx0, component.tcy0);
  34818. return {
  34819. left: component.tcx0,
  34820. top: component.tcy0,
  34821. width: result.width,
  34822. height: result.height,
  34823. items: result.items
  34824. };
  34825. }
  34826. function transformComponents(context) {
  34827. var siz = context.SIZ;
  34828. var components = context.components;
  34829. var componentsCount = siz.Csiz;
  34830. var resultImages = [];
  34831. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34832. var tile = context.tiles[i];
  34833. var transformedTiles = [];
  34834. var c;
  34835. for (c = 0; c < componentsCount; c++) {
  34836. transformedTiles[c] = transformTile(context, tile, c);
  34837. }
  34838. var tile0 = transformedTiles[0];
  34839. var out = new Uint8Array(tile0.items.length * componentsCount);
  34840. var result = {
  34841. left: tile0.left,
  34842. top: tile0.top,
  34843. width: tile0.width,
  34844. height: tile0.height,
  34845. items: out
  34846. };
  34847. // Section G.2.2 Inverse multi component transform
  34848. var shift, offset, max, min, maxK;
  34849. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34850. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34851. var fourComponents = componentsCount === 4;
  34852. var y0items = transformedTiles[0].items;
  34853. var y1items = transformedTiles[1].items;
  34854. var y2items = transformedTiles[2].items;
  34855. var y3items = fourComponents ? transformedTiles[3].items : null;
  34856. // HACK: The multiple component transform formulas below assume that
  34857. // all components have the same precision. With this in mind, we
  34858. // compute shift and offset only once.
  34859. shift = components[0].precision - 8;
  34860. offset = (128 << shift) + 0.5;
  34861. max = 255 * (1 << shift);
  34862. maxK = max * 0.5;
  34863. min = -maxK;
  34864. var component0 = tile.components[0];
  34865. var alpha01 = componentsCount - 3;
  34866. jj = y0items.length;
  34867. if (!component0.codingStyleParameters.reversibleTransformation) {
  34868. // inverse irreversible multiple component transform
  34869. for (j = 0; j < jj; j++, pos += alpha01) {
  34870. y0 = y0items[j] + offset;
  34871. y1 = y1items[j];
  34872. y2 = y2items[j];
  34873. r = y0 + 1.402 * y2;
  34874. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34875. b = y0 + 1.772 * y1;
  34876. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34877. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34878. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34879. }
  34880. } else {
  34881. // inverse reversible multiple component transform
  34882. for (j = 0; j < jj; j++, pos += alpha01) {
  34883. y0 = y0items[j] + offset;
  34884. y1 = y1items[j];
  34885. y2 = y2items[j];
  34886. g = y0 - ((y2 + y1) >> 2);
  34887. r = g + y2;
  34888. b = g + y1;
  34889. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34890. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34891. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34892. }
  34893. }
  34894. if (fourComponents) {
  34895. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34896. k = y3items[j];
  34897. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34898. }
  34899. }
  34900. } else { // no multi-component transform
  34901. for (c = 0; c < componentsCount; c++) {
  34902. var items = transformedTiles[c].items;
  34903. shift = components[c].precision - 8;
  34904. offset = (128 << shift) + 0.5;
  34905. max = (127.5 * (1 << shift));
  34906. min = -max;
  34907. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34908. val = items[j];
  34909. out[pos] = val <= min ? 0 :
  34910. val >= max ? 255 : (val + offset) >> shift;
  34911. pos += componentsCount;
  34912. }
  34913. }
  34914. }
  34915. resultImages.push(result);
  34916. }
  34917. return resultImages;
  34918. }
  34919. function initializeTile(context, tileIndex) {
  34920. var siz = context.SIZ;
  34921. var componentsCount = siz.Csiz;
  34922. var tile = context.tiles[tileIndex];
  34923. for (var c = 0; c < componentsCount; c++) {
  34924. var component = tile.components[c];
  34925. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34926. context.currentTile.QCC[c] : context.currentTile.QCD);
  34927. component.quantizationParameters = qcdOrQcc;
  34928. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34929. context.currentTile.COC[c] : context.currentTile.COD);
  34930. component.codingStyleParameters = codOrCoc;
  34931. }
  34932. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34933. }
  34934. // Section B.10.2 Tag trees
  34935. var TagTree = (function TagTreeClosure() {
  34936. function TagTree(width, height) {
  34937. var levelsLength = log2(Math.max(width, height)) + 1;
  34938. this.levels = [];
  34939. for (var i = 0; i < levelsLength; i++) {
  34940. var level = {
  34941. width: width,
  34942. height: height,
  34943. items: []
  34944. };
  34945. this.levels.push(level);
  34946. width = Math.ceil(width / 2);
  34947. height = Math.ceil(height / 2);
  34948. }
  34949. }
  34950. TagTree.prototype = {
  34951. reset: function TagTree_reset(i, j) {
  34952. var currentLevel = 0, value = 0, level;
  34953. while (currentLevel < this.levels.length) {
  34954. level = this.levels[currentLevel];
  34955. var index = i + j * level.width;
  34956. if (level.items[index] !== undefined) {
  34957. value = level.items[index];
  34958. break;
  34959. }
  34960. level.index = index;
  34961. i >>= 1;
  34962. j >>= 1;
  34963. currentLevel++;
  34964. }
  34965. currentLevel--;
  34966. level = this.levels[currentLevel];
  34967. level.items[level.index] = value;
  34968. this.currentLevel = currentLevel;
  34969. delete this.value;
  34970. },
  34971. incrementValue: function TagTree_incrementValue() {
  34972. var level = this.levels[this.currentLevel];
  34973. level.items[level.index]++;
  34974. },
  34975. nextLevel: function TagTree_nextLevel() {
  34976. var currentLevel = this.currentLevel;
  34977. var level = this.levels[currentLevel];
  34978. var value = level.items[level.index];
  34979. currentLevel--;
  34980. if (currentLevel < 0) {
  34981. this.value = value;
  34982. return false;
  34983. }
  34984. this.currentLevel = currentLevel;
  34985. level = this.levels[currentLevel];
  34986. level.items[level.index] = value;
  34987. return true;
  34988. }
  34989. };
  34990. return TagTree;
  34991. })();
  34992. var InclusionTree = (function InclusionTreeClosure() {
  34993. function InclusionTree(width, height, defaultValue) {
  34994. var levelsLength = log2(Math.max(width, height)) + 1;
  34995. this.levels = [];
  34996. for (var i = 0; i < levelsLength; i++) {
  34997. var items = new Uint8Array(width * height);
  34998. for (var j = 0, jj = items.length; j < jj; j++) {
  34999. items[j] = defaultValue;
  35000. }
  35001. var level = {
  35002. width: width,
  35003. height: height,
  35004. items: items
  35005. };
  35006. this.levels.push(level);
  35007. width = Math.ceil(width / 2);
  35008. height = Math.ceil(height / 2);
  35009. }
  35010. }
  35011. InclusionTree.prototype = {
  35012. reset: function InclusionTree_reset(i, j, stopValue) {
  35013. var currentLevel = 0;
  35014. while (currentLevel < this.levels.length) {
  35015. var level = this.levels[currentLevel];
  35016. var index = i + j * level.width;
  35017. level.index = index;
  35018. var value = level.items[index];
  35019. if (value === 0xFF) {
  35020. break;
  35021. }
  35022. if (value > stopValue) {
  35023. this.currentLevel = currentLevel;
  35024. // already know about this one, propagating the value to top levels
  35025. this.propagateValues();
  35026. return false;
  35027. }
  35028. i >>= 1;
  35029. j >>= 1;
  35030. currentLevel++;
  35031. }
  35032. this.currentLevel = currentLevel - 1;
  35033. return true;
  35034. },
  35035. incrementValue: function InclusionTree_incrementValue(stopValue) {
  35036. var level = this.levels[this.currentLevel];
  35037. level.items[level.index] = stopValue + 1;
  35038. this.propagateValues();
  35039. },
  35040. propagateValues: function InclusionTree_propagateValues() {
  35041. var levelIndex = this.currentLevel;
  35042. var level = this.levels[levelIndex];
  35043. var currentValue = level.items[level.index];
  35044. while (--levelIndex >= 0) {
  35045. level = this.levels[levelIndex];
  35046. level.items[level.index] = currentValue;
  35047. }
  35048. },
  35049. nextLevel: function InclusionTree_nextLevel() {
  35050. var currentLevel = this.currentLevel;
  35051. var level = this.levels[currentLevel];
  35052. var value = level.items[level.index];
  35053. level.items[level.index] = 0xFF;
  35054. currentLevel--;
  35055. if (currentLevel < 0) {
  35056. return false;
  35057. }
  35058. this.currentLevel = currentLevel;
  35059. level = this.levels[currentLevel];
  35060. level.items[level.index] = value;
  35061. return true;
  35062. }
  35063. };
  35064. return InclusionTree;
  35065. })();
  35066. // Section D. Coefficient bit modeling
  35067. var BitModel = (function BitModelClosure() {
  35068. var UNIFORM_CONTEXT = 17;
  35069. var RUNLENGTH_CONTEXT = 18;
  35070. // Table D-1
  35071. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  35072. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  35073. var LLAndLHContextsLabel = new Uint8Array([
  35074. 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4,
  35075. 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6,
  35076. 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8
  35077. ]);
  35078. var HLContextLabel = new Uint8Array([
  35079. 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8,
  35080. 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3,
  35081. 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8
  35082. ]);
  35083. var HHContextLabel = new Uint8Array([
  35084. 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5,
  35085. 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8,
  35086. 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8
  35087. ]);
  35088. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  35089. this.width = width;
  35090. this.height = height;
  35091. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  35092. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  35093. var coefficientCount = width * height;
  35094. // coefficients outside the encoding region treated as insignificant
  35095. // add border state cells for significanceState
  35096. this.neighborsSignificance = new Uint8Array(coefficientCount);
  35097. this.coefficentsSign = new Uint8Array(coefficientCount);
  35098. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  35099. mb > 6 ? new Uint16Array(coefficientCount) :
  35100. new Uint8Array(coefficientCount);
  35101. this.processingFlags = new Uint8Array(coefficientCount);
  35102. var bitsDecoded = new Uint8Array(coefficientCount);
  35103. if (zeroBitPlanes !== 0) {
  35104. for (var i = 0; i < coefficientCount; i++) {
  35105. bitsDecoded[i] = zeroBitPlanes;
  35106. }
  35107. }
  35108. this.bitsDecoded = bitsDecoded;
  35109. this.reset();
  35110. }
  35111. BitModel.prototype = {
  35112. setDecoder: function BitModel_setDecoder(decoder) {
  35113. this.decoder = decoder;
  35114. },
  35115. reset: function BitModel_reset() {
  35116. // We have 17 contexts that are accessed via context labels,
  35117. // plus the uniform and runlength context.
  35118. this.contexts = new Int8Array(19);
  35119. // Contexts are packed into 1 byte:
  35120. // highest 7 bits carry the index, lowest bit carries mps
  35121. this.contexts[0] = (4 << 1) | 0;
  35122. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  35123. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  35124. },
  35125. setNeighborsSignificance:
  35126. function BitModel_setNeighborsSignificance(row, column, index) {
  35127. var neighborsSignificance = this.neighborsSignificance;
  35128. var width = this.width, height = this.height;
  35129. var left = (column > 0);
  35130. var right = (column + 1 < width);
  35131. var i;
  35132. if (row > 0) {
  35133. i = index - width;
  35134. if (left) {
  35135. neighborsSignificance[i - 1] += 0x10;
  35136. }
  35137. if (right) {
  35138. neighborsSignificance[i + 1] += 0x10;
  35139. }
  35140. neighborsSignificance[i] += 0x04;
  35141. }
  35142. if (row + 1 < height) {
  35143. i = index + width;
  35144. if (left) {
  35145. neighborsSignificance[i - 1] += 0x10;
  35146. }
  35147. if (right) {
  35148. neighborsSignificance[i + 1] += 0x10;
  35149. }
  35150. neighborsSignificance[i] += 0x04;
  35151. }
  35152. if (left) {
  35153. neighborsSignificance[index - 1] += 0x01;
  35154. }
  35155. if (right) {
  35156. neighborsSignificance[index + 1] += 0x01;
  35157. }
  35158. neighborsSignificance[index] |= 0x80;
  35159. },
  35160. runSignificancePropogationPass:
  35161. function BitModel_runSignificancePropogationPass() {
  35162. var decoder = this.decoder;
  35163. var width = this.width, height = this.height;
  35164. var coefficentsMagnitude = this.coefficentsMagnitude;
  35165. var coefficentsSign = this.coefficentsSign;
  35166. var neighborsSignificance = this.neighborsSignificance;
  35167. var processingFlags = this.processingFlags;
  35168. var contexts = this.contexts;
  35169. var labels = this.contextLabelTable;
  35170. var bitsDecoded = this.bitsDecoded;
  35171. var processedInverseMask = ~1;
  35172. var processedMask = 1;
  35173. var firstMagnitudeBitMask = 2;
  35174. for (var i0 = 0; i0 < height; i0 += 4) {
  35175. for (var j = 0; j < width; j++) {
  35176. var index = i0 * width + j;
  35177. for (var i1 = 0; i1 < 4; i1++, index += width) {
  35178. var i = i0 + i1;
  35179. if (i >= height) {
  35180. break;
  35181. }
  35182. // clear processed flag first
  35183. processingFlags[index] &= processedInverseMask;
  35184. if (coefficentsMagnitude[index] ||
  35185. !neighborsSignificance[index]) {
  35186. continue;
  35187. }
  35188. var contextLabel = labels[neighborsSignificance[index]];
  35189. var decision = decoder.readBit(contexts, contextLabel);
  35190. if (decision) {
  35191. var sign = this.decodeSignBit(i, j, index);
  35192. coefficentsSign[index] = sign;
  35193. coefficentsMagnitude[index] = 1;
  35194. this.setNeighborsSignificance(i, j, index);
  35195. processingFlags[index] |= firstMagnitudeBitMask;
  35196. }
  35197. bitsDecoded[index]++;
  35198. processingFlags[index] |= processedMask;
  35199. }
  35200. }
  35201. }
  35202. },
  35203. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  35204. var width = this.width, height = this.height;
  35205. var coefficentsMagnitude = this.coefficentsMagnitude;
  35206. var coefficentsSign = this.coefficentsSign;
  35207. var contribution, sign0, sign1, significance1;
  35208. var contextLabel, decoded;
  35209. // calculate horizontal contribution
  35210. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  35211. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  35212. sign1 = coefficentsSign[index + 1];
  35213. if (significance1) {
  35214. sign0 = coefficentsSign[index - 1];
  35215. contribution = 1 - sign1 - sign0;
  35216. } else {
  35217. contribution = 1 - sign1 - sign1;
  35218. }
  35219. } else if (significance1) {
  35220. sign0 = coefficentsSign[index - 1];
  35221. contribution = 1 - sign0 - sign0;
  35222. } else {
  35223. contribution = 0;
  35224. }
  35225. var horizontalContribution = 3 * contribution;
  35226. // calculate vertical contribution and combine with the horizontal
  35227. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  35228. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  35229. sign1 = coefficentsSign[index + width];
  35230. if (significance1) {
  35231. sign0 = coefficentsSign[index - width];
  35232. contribution = 1 - sign1 - sign0 + horizontalContribution;
  35233. } else {
  35234. contribution = 1 - sign1 - sign1 + horizontalContribution;
  35235. }
  35236. } else if (significance1) {
  35237. sign0 = coefficentsSign[index - width];
  35238. contribution = 1 - sign0 - sign0 + horizontalContribution;
  35239. } else {
  35240. contribution = horizontalContribution;
  35241. }
  35242. if (contribution >= 0) {
  35243. contextLabel = 9 + contribution;
  35244. decoded = this.decoder.readBit(this.contexts, contextLabel);
  35245. } else {
  35246. contextLabel = 9 - contribution;
  35247. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  35248. }
  35249. return decoded;
  35250. },
  35251. runMagnitudeRefinementPass:
  35252. function BitModel_runMagnitudeRefinementPass() {
  35253. var decoder = this.decoder;
  35254. var width = this.width, height = this.height;
  35255. var coefficentsMagnitude = this.coefficentsMagnitude;
  35256. var neighborsSignificance = this.neighborsSignificance;
  35257. var contexts = this.contexts;
  35258. var bitsDecoded = this.bitsDecoded;
  35259. var processingFlags = this.processingFlags;
  35260. var processedMask = 1;
  35261. var firstMagnitudeBitMask = 2;
  35262. var length = width * height;
  35263. var width4 = width * 4;
  35264. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35265. indexNext = Math.min(length, index0 + width4);
  35266. for (var j = 0; j < width; j++) {
  35267. for (var index = index0 + j; index < indexNext; index += width) {
  35268. // significant but not those that have just become
  35269. if (!coefficentsMagnitude[index] ||
  35270. (processingFlags[index] & processedMask) !== 0) {
  35271. continue;
  35272. }
  35273. var contextLabel = 16;
  35274. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35275. processingFlags[index] ^= firstMagnitudeBitMask;
  35276. // first refinement
  35277. var significance = neighborsSignificance[index] & 127;
  35278. contextLabel = significance === 0 ? 15 : 14;
  35279. }
  35280. var bit = decoder.readBit(contexts, contextLabel);
  35281. coefficentsMagnitude[index] =
  35282. (coefficentsMagnitude[index] << 1) | bit;
  35283. bitsDecoded[index]++;
  35284. processingFlags[index] |= processedMask;
  35285. }
  35286. }
  35287. }
  35288. },
  35289. runCleanupPass: function BitModel_runCleanupPass() {
  35290. var decoder = this.decoder;
  35291. var width = this.width, height = this.height;
  35292. var neighborsSignificance = this.neighborsSignificance;
  35293. var coefficentsMagnitude = this.coefficentsMagnitude;
  35294. var coefficentsSign = this.coefficentsSign;
  35295. var contexts = this.contexts;
  35296. var labels = this.contextLabelTable;
  35297. var bitsDecoded = this.bitsDecoded;
  35298. var processingFlags = this.processingFlags;
  35299. var processedMask = 1;
  35300. var firstMagnitudeBitMask = 2;
  35301. var oneRowDown = width;
  35302. var twoRowsDown = width * 2;
  35303. var threeRowsDown = width * 3;
  35304. var iNext;
  35305. for (var i0 = 0; i0 < height; i0 = iNext) {
  35306. iNext = Math.min(i0 + 4, height);
  35307. var indexBase = i0 * width;
  35308. var checkAllEmpty = i0 + 3 < height;
  35309. for (var j = 0; j < width; j++) {
  35310. var index0 = indexBase + j;
  35311. // using the property: labels[neighborsSignificance[index]] === 0
  35312. // when neighborsSignificance[index] === 0
  35313. var allEmpty = (checkAllEmpty &&
  35314. processingFlags[index0] === 0 &&
  35315. processingFlags[index0 + oneRowDown] === 0 &&
  35316. processingFlags[index0 + twoRowsDown] === 0 &&
  35317. processingFlags[index0 + threeRowsDown] === 0 &&
  35318. neighborsSignificance[index0] === 0 &&
  35319. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35320. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35321. neighborsSignificance[index0 + threeRowsDown] === 0);
  35322. var i1 = 0, index = index0;
  35323. var i = i0, sign;
  35324. if (allEmpty) {
  35325. var hasSignificantCoefficent =
  35326. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35327. if (!hasSignificantCoefficent) {
  35328. bitsDecoded[index0]++;
  35329. bitsDecoded[index0 + oneRowDown]++;
  35330. bitsDecoded[index0 + twoRowsDown]++;
  35331. bitsDecoded[index0 + threeRowsDown]++;
  35332. continue; // next column
  35333. }
  35334. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35335. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35336. if (i1 !== 0) {
  35337. i = i0 + i1;
  35338. index += i1 * width;
  35339. }
  35340. sign = this.decodeSignBit(i, j, index);
  35341. coefficentsSign[index] = sign;
  35342. coefficentsMagnitude[index] = 1;
  35343. this.setNeighborsSignificance(i, j, index);
  35344. processingFlags[index] |= firstMagnitudeBitMask;
  35345. index = index0;
  35346. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35347. bitsDecoded[index]++;
  35348. }
  35349. i1++;
  35350. }
  35351. for (i = i0 + i1; i < iNext; i++, index += width) {
  35352. if (coefficentsMagnitude[index] ||
  35353. (processingFlags[index] & processedMask) !== 0) {
  35354. continue;
  35355. }
  35356. var contextLabel = labels[neighborsSignificance[index]];
  35357. var decision = decoder.readBit(contexts, contextLabel);
  35358. if (decision === 1) {
  35359. sign = this.decodeSignBit(i, j, index);
  35360. coefficentsSign[index] = sign;
  35361. coefficentsMagnitude[index] = 1;
  35362. this.setNeighborsSignificance(i, j, index);
  35363. processingFlags[index] |= firstMagnitudeBitMask;
  35364. }
  35365. bitsDecoded[index]++;
  35366. }
  35367. }
  35368. }
  35369. },
  35370. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35371. var decoder = this.decoder;
  35372. var contexts = this.contexts;
  35373. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35374. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35375. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35376. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35377. if (symbol !== 0xA) {
  35378. throw new Error('JPX Error: Invalid segmentation symbol');
  35379. }
  35380. }
  35381. };
  35382. return BitModel;
  35383. })();
  35384. // Section F, Discrete wavelet transformation
  35385. var Transform = (function TransformClosure() {
  35386. function Transform() {}
  35387. Transform.prototype.calculate =
  35388. function transformCalculate(subbands, u0, v0) {
  35389. var ll = subbands[0];
  35390. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35391. ll = this.iterate(ll, subbands[i], u0, v0);
  35392. }
  35393. return ll;
  35394. };
  35395. Transform.prototype.extend = function extend(buffer, offset, size) {
  35396. // Section F.3.7 extending... using max extension of 4
  35397. var i1 = offset - 1, j1 = offset + 1;
  35398. var i2 = offset + size - 2, j2 = offset + size;
  35399. buffer[i1--] = buffer[j1++];
  35400. buffer[j2++] = buffer[i2--];
  35401. buffer[i1--] = buffer[j1++];
  35402. buffer[j2++] = buffer[i2--];
  35403. buffer[i1--] = buffer[j1++];
  35404. buffer[j2++] = buffer[i2--];
  35405. buffer[i1] = buffer[j1];
  35406. buffer[j2] = buffer[i2];
  35407. };
  35408. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35409. u0, v0) {
  35410. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35411. var width = hl_lh_hh.width;
  35412. var height = hl_lh_hh.height;
  35413. var items = hl_lh_hh.items;
  35414. var i, j, k, l, u, v;
  35415. // Interleave LL according to Section F.3.3
  35416. for (k = 0, i = 0; i < llHeight; i++) {
  35417. l = i * 2 * width;
  35418. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35419. items[l] = llItems[k];
  35420. }
  35421. }
  35422. // The LL band is not needed anymore.
  35423. llItems = ll.items = null;
  35424. var bufferPadding = 4;
  35425. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35426. // Section F.3.4 HOR_SR
  35427. if (width === 1) {
  35428. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35429. if ((u0 & 1) !== 0) {
  35430. for (v = 0, k = 0; v < height; v++, k += width) {
  35431. items[k] *= 0.5;
  35432. }
  35433. }
  35434. } else {
  35435. for (v = 0, k = 0; v < height; v++, k += width) {
  35436. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35437. this.extend(rowBuffer, bufferPadding, width);
  35438. this.filter(rowBuffer, bufferPadding, width);
  35439. items.set(
  35440. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35441. k);
  35442. }
  35443. }
  35444. // Accesses to the items array can take long, because it may not fit into
  35445. // CPU cache and has to be fetched from main memory. Since subsequent
  35446. // accesses to the items array are not local when reading columns, we
  35447. // have a cache miss every time. To reduce cache misses, get up to
  35448. // 'numBuffers' items at a time and store them into the individual
  35449. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35450. var numBuffers = 16;
  35451. var colBuffers = [];
  35452. for (i = 0; i < numBuffers; i++) {
  35453. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35454. }
  35455. var b, currentBuffer = 0;
  35456. ll = bufferPadding + height;
  35457. // Section F.3.5 VER_SR
  35458. if (height === 1) {
  35459. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35460. if ((v0 & 1) !== 0) {
  35461. for (u = 0; u < width; u++) {
  35462. items[u] *= 0.5;
  35463. }
  35464. }
  35465. } else {
  35466. for (u = 0; u < width; u++) {
  35467. // if we ran out of buffers, copy several image columns at once
  35468. if (currentBuffer === 0) {
  35469. numBuffers = Math.min(width - u, numBuffers);
  35470. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35471. for (b = 0; b < numBuffers; b++) {
  35472. colBuffers[b][l] = items[k + b];
  35473. }
  35474. }
  35475. currentBuffer = numBuffers;
  35476. }
  35477. currentBuffer--;
  35478. var buffer = colBuffers[currentBuffer];
  35479. this.extend(buffer, bufferPadding, height);
  35480. this.filter(buffer, bufferPadding, height);
  35481. // If this is last buffer in this group of buffers, flush all buffers.
  35482. if (currentBuffer === 0) {
  35483. k = u - numBuffers + 1;
  35484. for (l = bufferPadding; l < ll; k += width, l++) {
  35485. for (b = 0; b < numBuffers; b++) {
  35486. items[k + b] = colBuffers[b][l];
  35487. }
  35488. }
  35489. }
  35490. }
  35491. }
  35492. return {
  35493. width: width,
  35494. height: height,
  35495. items: items
  35496. };
  35497. };
  35498. return Transform;
  35499. })();
  35500. // Section 3.8.2 Irreversible 9-7 filter
  35501. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35502. function IrreversibleTransform() {
  35503. Transform.call(this);
  35504. }
  35505. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35506. IrreversibleTransform.prototype.filter =
  35507. function irreversibleTransformFilter(x, offset, length) {
  35508. var len = length >> 1;
  35509. offset = offset | 0;
  35510. var j, n, current, next;
  35511. var alpha = -1.586134342059924;
  35512. var beta = -0.052980118572961;
  35513. var gamma = 0.882911075530934;
  35514. var delta = 0.443506852043971;
  35515. var K = 1.230174104914001;
  35516. var K_ = 1 / K;
  35517. // step 1 is combined with step 3
  35518. // step 2
  35519. j = offset - 3;
  35520. for (n = len + 4; n--; j += 2) {
  35521. x[j] *= K_;
  35522. }
  35523. // step 1 & 3
  35524. j = offset - 2;
  35525. current = delta * x[j -1];
  35526. for (n = len + 3; n--; j += 2) {
  35527. next = delta * x[j + 1];
  35528. x[j] = K * x[j] - current - next;
  35529. if (n--) {
  35530. j += 2;
  35531. current = delta * x[j + 1];
  35532. x[j] = K * x[j] - current - next;
  35533. } else {
  35534. break;
  35535. }
  35536. }
  35537. // step 4
  35538. j = offset - 1;
  35539. current = gamma * x[j - 1];
  35540. for (n = len + 2; n--; j += 2) {
  35541. next = gamma * x[j + 1];
  35542. x[j] -= current + next;
  35543. if (n--) {
  35544. j += 2;
  35545. current = gamma * x[j + 1];
  35546. x[j] -= current + next;
  35547. } else {
  35548. break;
  35549. }
  35550. }
  35551. // step 5
  35552. j = offset;
  35553. current = beta * x[j - 1];
  35554. for (n = len + 1; n--; j += 2) {
  35555. next = beta * x[j + 1];
  35556. x[j] -= current + next;
  35557. if (n--) {
  35558. j += 2;
  35559. current = beta * x[j + 1];
  35560. x[j] -= current + next;
  35561. } else {
  35562. break;
  35563. }
  35564. }
  35565. // step 6
  35566. if (len !== 0) {
  35567. j = offset + 1;
  35568. current = alpha * x[j - 1];
  35569. for (n = len; n--; j += 2) {
  35570. next = alpha * x[j + 1];
  35571. x[j] -= current + next;
  35572. if (n--) {
  35573. j += 2;
  35574. current = alpha * x[j + 1];
  35575. x[j] -= current + next;
  35576. } else {
  35577. break;
  35578. }
  35579. }
  35580. }
  35581. };
  35582. return IrreversibleTransform;
  35583. })();
  35584. // Section 3.8.1 Reversible 5-3 filter
  35585. var ReversibleTransform = (function ReversibleTransformClosure() {
  35586. function ReversibleTransform() {
  35587. Transform.call(this);
  35588. }
  35589. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35590. ReversibleTransform.prototype.filter =
  35591. function reversibleTransformFilter(x, offset, length) {
  35592. var len = length >> 1;
  35593. offset = offset | 0;
  35594. var j, n;
  35595. for (j = offset, n = len + 1; n--; j += 2) {
  35596. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35597. }
  35598. for (j = offset + 1, n = len; n--; j += 2) {
  35599. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35600. }
  35601. };
  35602. return ReversibleTransform;
  35603. })();
  35604. return JpxImage;
  35605. })();
  35606. var Jbig2Image = (function Jbig2ImageClosure() {
  35607. // Utility data structures
  35608. function ContextCache() {}
  35609. ContextCache.prototype = {
  35610. getContexts: function(id) {
  35611. if (id in this) {
  35612. return this[id];
  35613. }
  35614. return (this[id] = new Int8Array(1 << 16));
  35615. }
  35616. };
  35617. function DecodingContext(data, start, end) {
  35618. this.data = data;
  35619. this.start = start;
  35620. this.end = end;
  35621. }
  35622. DecodingContext.prototype = {
  35623. get decoder() {
  35624. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35625. return shadow(this, 'decoder', decoder);
  35626. },
  35627. get contextCache() {
  35628. var cache = new ContextCache();
  35629. return shadow(this, 'contextCache', cache);
  35630. }
  35631. };
  35632. // Annex A. Arithmetic Integer Decoding Procedure
  35633. // A.2 Procedure for decoding values
  35634. function decodeInteger(contextCache, procedure, decoder) {
  35635. var contexts = contextCache.getContexts(procedure);
  35636. var prev = 1;
  35637. function readBits(length) {
  35638. var v = 0;
  35639. for (var i = 0; i < length; i++) {
  35640. var bit = decoder.readBit(contexts, prev);
  35641. prev = (prev < 256 ? (prev << 1) | bit :
  35642. (((prev << 1) | bit) & 511) | 256);
  35643. v = (v << 1) | bit;
  35644. }
  35645. return v >>> 0;
  35646. }
  35647. var sign = readBits(1);
  35648. var value = readBits(1) ?
  35649. (readBits(1) ?
  35650. (readBits(1) ?
  35651. (readBits(1) ?
  35652. (readBits(1) ?
  35653. (readBits(32) + 4436) :
  35654. readBits(12) + 340) :
  35655. readBits(8) + 84) :
  35656. readBits(6) + 20) :
  35657. readBits(4) + 4) :
  35658. readBits(2);
  35659. return (sign === 0 ? value : (value > 0 ? -value : null));
  35660. }
  35661. // A.3 The IAID decoding procedure
  35662. function decodeIAID(contextCache, decoder, codeLength) {
  35663. var contexts = contextCache.getContexts('IAID');
  35664. var prev = 1;
  35665. for (var i = 0; i < codeLength; i++) {
  35666. var bit = decoder.readBit(contexts, prev);
  35667. prev = (prev << 1) | bit;
  35668. }
  35669. if (codeLength < 31) {
  35670. return prev & ((1 << codeLength) - 1);
  35671. }
  35672. return prev & 0x7FFFFFFF;
  35673. }
  35674. // 7.3 Segment types
  35675. var SegmentTypes = [
  35676. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35677. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35678. null, null, null, null, null, 'patternDictionary', null, null, null,
  35679. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35680. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35681. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35682. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35683. 'IntermediateGenericRefinementRegion', null,
  35684. 'ImmediateGenericRefinementRegion',
  35685. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35686. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35687. 'Tables', null, null, null, null, null, null, null, null,
  35688. 'Extension'
  35689. ];
  35690. var CodingTemplates = [
  35691. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35692. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35693. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35694. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35695. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35696. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35697. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35698. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35699. {x: -1, y: 0}],
  35700. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35701. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35702. ];
  35703. var RefinementTemplates = [
  35704. {
  35705. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35706. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35707. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35708. },
  35709. {
  35710. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35711. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35712. {x: 0, y: 1}, {x: 1, y: 1}]
  35713. }
  35714. ];
  35715. // See 6.2.5.7 Decoding the bitmap.
  35716. var ReusedContexts = [
  35717. 0x9B25, // 10011 0110010 0101
  35718. 0x0795, // 0011 110010 101
  35719. 0x00E5, // 001 11001 01
  35720. 0x0195 // 011001 0101
  35721. ];
  35722. var RefinementReusedContexts = [
  35723. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35724. 0x0008 // '0000' + '001000'
  35725. ];
  35726. function decodeBitmapTemplate0(width, height, decodingContext) {
  35727. var decoder = decodingContext.decoder;
  35728. var contexts = decodingContext.contextCache.getContexts('GB');
  35729. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35730. // ...ooooo....
  35731. // ..ooooooo... Context template for current pixel (X)
  35732. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35733. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35734. for (i = 0; i < height; i++) {
  35735. row = bitmap[i] = new Uint8Array(width);
  35736. row1 = (i < 1) ? row : bitmap[i - 1];
  35737. row2 = (i < 2) ? row : bitmap[i - 2];
  35738. // At the beginning of each row:
  35739. // Fill contextLabel with pixels that are above/right of (X)
  35740. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35741. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35742. (row1[3] << 4);
  35743. for (j = 0; j < width; j++) {
  35744. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35745. // At each pixel: Clear contextLabel pixels that are shifted
  35746. // out of the context, then add new ones.
  35747. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35748. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35749. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35750. }
  35751. }
  35752. return bitmap;
  35753. }
  35754. // 6.2 Generic Region Decoding Procedure
  35755. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35756. decodingContext) {
  35757. if (mmr) {
  35758. error('JBIG2 error: MMR encoding is not supported');
  35759. }
  35760. // Use optimized version for the most common case
  35761. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35762. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35763. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35764. return decodeBitmapTemplate0(width, height, decodingContext);
  35765. }
  35766. var useskip = !!skip;
  35767. var template = CodingTemplates[templateIndex].concat(at);
  35768. // Sorting is non-standard, and it is not required. But sorting increases
  35769. // the number of template bits that can be reused from the previous
  35770. // contextLabel in the main loop.
  35771. template.sort(function (a, b) {
  35772. return (a.y - b.y) || (a.x - b.x);
  35773. });
  35774. var templateLength = template.length;
  35775. var templateX = new Int8Array(templateLength);
  35776. var templateY = new Int8Array(templateLength);
  35777. var changingTemplateEntries = [];
  35778. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35779. var c, k;
  35780. for (k = 0; k < templateLength; k++) {
  35781. templateX[k] = template[k].x;
  35782. templateY[k] = template[k].y;
  35783. minX = Math.min(minX, template[k].x);
  35784. maxX = Math.max(maxX, template[k].x);
  35785. minY = Math.min(minY, template[k].y);
  35786. // Check if the template pixel appears in two consecutive context labels,
  35787. // so it can be reused. Otherwise, we add it to the list of changing
  35788. // template entries.
  35789. if (k < templateLength - 1 &&
  35790. template[k].y === template[k + 1].y &&
  35791. template[k].x === template[k + 1].x - 1) {
  35792. reuseMask |= 1 << (templateLength - 1 - k);
  35793. } else {
  35794. changingTemplateEntries.push(k);
  35795. }
  35796. }
  35797. var changingEntriesLength = changingTemplateEntries.length;
  35798. var changingTemplateX = new Int8Array(changingEntriesLength);
  35799. var changingTemplateY = new Int8Array(changingEntriesLength);
  35800. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35801. for (c = 0; c < changingEntriesLength; c++) {
  35802. k = changingTemplateEntries[c];
  35803. changingTemplateX[c] = template[k].x;
  35804. changingTemplateY[c] = template[k].y;
  35805. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35806. }
  35807. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35808. var sbb_left = -minX;
  35809. var sbb_top = -minY;
  35810. var sbb_right = width - maxX;
  35811. var pseudoPixelContext = ReusedContexts[templateIndex];
  35812. var row = new Uint8Array(width);
  35813. var bitmap = [];
  35814. var decoder = decodingContext.decoder;
  35815. var contexts = decodingContext.contextCache.getContexts('GB');
  35816. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35817. for (var i = 0; i < height; i++) {
  35818. if (prediction) {
  35819. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35820. ltp ^= sltp;
  35821. if (ltp) {
  35822. bitmap.push(row); // duplicate previous row
  35823. continue;
  35824. }
  35825. }
  35826. row = new Uint8Array(row);
  35827. bitmap.push(row);
  35828. for (j = 0; j < width; j++) {
  35829. if (useskip && skip[i][j]) {
  35830. row[j] = 0;
  35831. continue;
  35832. }
  35833. // Are we in the middle of a scanline, so we can reuse contextLabel
  35834. // bits?
  35835. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35836. // If yes, we can just shift the bits that are reusable and only
  35837. // fetch the remaining ones.
  35838. contextLabel = (contextLabel << 1) & reuseMask;
  35839. for (k = 0; k < changingEntriesLength; k++) {
  35840. i0 = i + changingTemplateY[k];
  35841. j0 = j + changingTemplateX[k];
  35842. bit = bitmap[i0][j0];
  35843. if (bit) {
  35844. bit = changingTemplateBit[k];
  35845. contextLabel |= bit;
  35846. }
  35847. }
  35848. } else {
  35849. // compute the contextLabel from scratch
  35850. contextLabel = 0;
  35851. shift = templateLength - 1;
  35852. for (k = 0; k < templateLength; k++, shift--) {
  35853. j0 = j + templateX[k];
  35854. if (j0 >= 0 && j0 < width) {
  35855. i0 = i + templateY[k];
  35856. if (i0 >= 0) {
  35857. bit = bitmap[i0][j0];
  35858. if (bit) {
  35859. contextLabel |= bit << shift;
  35860. }
  35861. }
  35862. }
  35863. }
  35864. }
  35865. var pixel = decoder.readBit(contexts, contextLabel);
  35866. row[j] = pixel;
  35867. }
  35868. }
  35869. return bitmap;
  35870. }
  35871. // 6.3.2 Generic Refinement Region Decoding Procedure
  35872. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35873. offsetX, offsetY, prediction, at,
  35874. decodingContext) {
  35875. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35876. if (templateIndex === 0) {
  35877. codingTemplate = codingTemplate.concat([at[0]]);
  35878. }
  35879. var codingTemplateLength = codingTemplate.length;
  35880. var codingTemplateX = new Int32Array(codingTemplateLength);
  35881. var codingTemplateY = new Int32Array(codingTemplateLength);
  35882. var k;
  35883. for (k = 0; k < codingTemplateLength; k++) {
  35884. codingTemplateX[k] = codingTemplate[k].x;
  35885. codingTemplateY[k] = codingTemplate[k].y;
  35886. }
  35887. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35888. if (templateIndex === 0) {
  35889. referenceTemplate = referenceTemplate.concat([at[1]]);
  35890. }
  35891. var referenceTemplateLength = referenceTemplate.length;
  35892. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35893. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35894. for (k = 0; k < referenceTemplateLength; k++) {
  35895. referenceTemplateX[k] = referenceTemplate[k].x;
  35896. referenceTemplateY[k] = referenceTemplate[k].y;
  35897. }
  35898. var referenceWidth = referenceBitmap[0].length;
  35899. var referenceHeight = referenceBitmap.length;
  35900. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35901. var bitmap = [];
  35902. var decoder = decodingContext.decoder;
  35903. var contexts = decodingContext.contextCache.getContexts('GR');
  35904. var ltp = 0;
  35905. for (var i = 0; i < height; i++) {
  35906. if (prediction) {
  35907. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35908. ltp ^= sltp;
  35909. if (ltp) {
  35910. error('JBIG2 error: prediction is not supported');
  35911. }
  35912. }
  35913. var row = new Uint8Array(width);
  35914. bitmap.push(row);
  35915. for (var j = 0; j < width; j++) {
  35916. var i0, j0;
  35917. var contextLabel = 0;
  35918. for (k = 0; k < codingTemplateLength; k++) {
  35919. i0 = i + codingTemplateY[k];
  35920. j0 = j + codingTemplateX[k];
  35921. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35922. contextLabel <<= 1; // out of bound pixel
  35923. } else {
  35924. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35925. }
  35926. }
  35927. for (k = 0; k < referenceTemplateLength; k++) {
  35928. i0 = i + referenceTemplateY[k] + offsetY;
  35929. j0 = j + referenceTemplateX[k] + offsetX;
  35930. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35931. j0 >= referenceWidth) {
  35932. contextLabel <<= 1; // out of bound pixel
  35933. } else {
  35934. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35935. }
  35936. }
  35937. var pixel = decoder.readBit(contexts, contextLabel);
  35938. row[j] = pixel;
  35939. }
  35940. }
  35941. return bitmap;
  35942. }
  35943. // 6.5.5 Decoding the symbol dictionary
  35944. function decodeSymbolDictionary(huffman, refinement, symbols,
  35945. numberOfNewSymbols, numberOfExportedSymbols,
  35946. huffmanTables, templateIndex, at,
  35947. refinementTemplateIndex, refinementAt,
  35948. decodingContext) {
  35949. if (huffman) {
  35950. error('JBIG2 error: huffman is not supported');
  35951. }
  35952. var newSymbols = [];
  35953. var currentHeight = 0;
  35954. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35955. var decoder = decodingContext.decoder;
  35956. var contextCache = decodingContext.contextCache;
  35957. while (newSymbols.length < numberOfNewSymbols) {
  35958. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35959. currentHeight += deltaHeight;
  35960. var currentWidth = 0;
  35961. var totalWidth = 0;
  35962. while (true) {
  35963. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35964. if (deltaWidth === null) {
  35965. break; // OOB
  35966. }
  35967. currentWidth += deltaWidth;
  35968. totalWidth += currentWidth;
  35969. var bitmap;
  35970. if (refinement) {
  35971. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35972. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35973. if (numberOfInstances > 1) {
  35974. bitmap = decodeTextRegion(huffman, refinement,
  35975. currentWidth, currentHeight, 0,
  35976. numberOfInstances, 1, //strip size
  35977. symbols.concat(newSymbols),
  35978. symbolCodeLength,
  35979. 0, //transposed
  35980. 0, //ds offset
  35981. 1, //top left 7.4.3.1.1
  35982. 0, //OR operator
  35983. huffmanTables,
  35984. refinementTemplateIndex, refinementAt,
  35985. decodingContext);
  35986. } else {
  35987. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35988. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35989. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35990. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35991. newSymbols[symbolId - symbols.length]);
  35992. bitmap = decodeRefinement(currentWidth, currentHeight,
  35993. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35994. decodingContext);
  35995. }
  35996. } else {
  35997. // 6.5.8.1 Direct-coded symbol bitmap
  35998. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35999. templateIndex, false, null, at, decodingContext);
  36000. }
  36001. newSymbols.push(bitmap);
  36002. }
  36003. }
  36004. // 6.5.10 Exported symbols
  36005. var exportedSymbols = [];
  36006. var flags = [], currentFlag = false;
  36007. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  36008. while (flags.length < totalSymbolsLength) {
  36009. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  36010. while (runLength--) {
  36011. flags.push(currentFlag);
  36012. }
  36013. currentFlag = !currentFlag;
  36014. }
  36015. for (var i = 0, ii = symbols.length; i < ii; i++) {
  36016. if (flags[i]) {
  36017. exportedSymbols.push(symbols[i]);
  36018. }
  36019. }
  36020. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  36021. if (flags[i]) {
  36022. exportedSymbols.push(newSymbols[j]);
  36023. }
  36024. }
  36025. return exportedSymbols;
  36026. }
  36027. function decodeTextRegion(huffman, refinement, width, height,
  36028. defaultPixelValue, numberOfSymbolInstances,
  36029. stripSize, inputSymbols, symbolCodeLength,
  36030. transposed, dsOffset, referenceCorner,
  36031. combinationOperator, huffmanTables,
  36032. refinementTemplateIndex, refinementAt,
  36033. decodingContext) {
  36034. if (huffman) {
  36035. error('JBIG2 error: huffman is not supported');
  36036. }
  36037. // Prepare bitmap
  36038. var bitmap = [];
  36039. var i, row;
  36040. for (i = 0; i < height; i++) {
  36041. row = new Uint8Array(width);
  36042. if (defaultPixelValue) {
  36043. for (var j = 0; j < width; j++) {
  36044. row[j] = defaultPixelValue;
  36045. }
  36046. }
  36047. bitmap.push(row);
  36048. }
  36049. var decoder = decodingContext.decoder;
  36050. var contextCache = decodingContext.contextCache;
  36051. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36052. var firstS = 0;
  36053. i = 0;
  36054. while (i < numberOfSymbolInstances) {
  36055. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36056. stripT += deltaT;
  36057. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  36058. firstS += deltaFirstS;
  36059. var currentS = firstS;
  36060. do {
  36061. var currentT = (stripSize === 1 ? 0 :
  36062. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  36063. var t = stripSize * stripT + currentT;
  36064. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36065. var applyRefinement = (refinement &&
  36066. decodeInteger(contextCache, 'IARI', decoder));
  36067. var symbolBitmap = inputSymbols[symbolId];
  36068. var symbolWidth = symbolBitmap[0].length;
  36069. var symbolHeight = symbolBitmap.length;
  36070. if (applyRefinement) {
  36071. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  36072. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  36073. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36074. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36075. symbolWidth += rdw;
  36076. symbolHeight += rdh;
  36077. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  36078. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  36079. (rdh >> 1) + rdy, false, refinementAt,
  36080. decodingContext);
  36081. }
  36082. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  36083. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  36084. var s2, t2, symbolRow;
  36085. if (transposed) {
  36086. // Place Symbol Bitmap from T1,S1
  36087. for (s2 = 0; s2 < symbolHeight; s2++) {
  36088. row = bitmap[offsetS + s2];
  36089. if (!row) {
  36090. continue;
  36091. }
  36092. symbolRow = symbolBitmap[s2];
  36093. // To ignore Parts of Symbol bitmap which goes
  36094. // outside bitmap region
  36095. var maxWidth = Math.min(width - offsetT, symbolWidth);
  36096. switch (combinationOperator) {
  36097. case 0: // OR
  36098. for (t2 = 0; t2 < maxWidth; t2++) {
  36099. row[offsetT + t2] |= symbolRow[t2];
  36100. }
  36101. break;
  36102. case 2: // XOR
  36103. for (t2 = 0; t2 < maxWidth; t2++) {
  36104. row[offsetT + t2] ^= symbolRow[t2];
  36105. }
  36106. break;
  36107. default:
  36108. error('JBIG2 error: operator ' + combinationOperator +
  36109. ' is not supported');
  36110. }
  36111. }
  36112. currentS += symbolHeight - 1;
  36113. } else {
  36114. for (t2 = 0; t2 < symbolHeight; t2++) {
  36115. row = bitmap[offsetT + t2];
  36116. if (!row) {
  36117. continue;
  36118. }
  36119. symbolRow = symbolBitmap[t2];
  36120. switch (combinationOperator) {
  36121. case 0: // OR
  36122. for (s2 = 0; s2 < symbolWidth; s2++) {
  36123. row[offsetS + s2] |= symbolRow[s2];
  36124. }
  36125. break;
  36126. case 2: // XOR
  36127. for (s2 = 0; s2 < symbolWidth; s2++) {
  36128. row[offsetS + s2] ^= symbolRow[s2];
  36129. }
  36130. break;
  36131. default:
  36132. error('JBIG2 error: operator ' + combinationOperator +
  36133. ' is not supported');
  36134. }
  36135. }
  36136. currentS += symbolWidth - 1;
  36137. }
  36138. i++;
  36139. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  36140. if (deltaS === null) {
  36141. break; // OOB
  36142. }
  36143. currentS += deltaS + dsOffset;
  36144. } while (true);
  36145. }
  36146. return bitmap;
  36147. }
  36148. function readSegmentHeader(data, start) {
  36149. var segmentHeader = {};
  36150. segmentHeader.number = readUint32(data, start);
  36151. var flags = data[start + 4];
  36152. var segmentType = flags & 0x3F;
  36153. if (!SegmentTypes[segmentType]) {
  36154. error('JBIG2 error: invalid segment type: ' + segmentType);
  36155. }
  36156. segmentHeader.type = segmentType;
  36157. segmentHeader.typeName = SegmentTypes[segmentType];
  36158. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  36159. var pageAssociationFieldSize = !!(flags & 0x40);
  36160. var referredFlags = data[start + 5];
  36161. var referredToCount = (referredFlags >> 5) & 7;
  36162. var retainBits = [referredFlags & 31];
  36163. var position = start + 6;
  36164. if (referredFlags === 7) {
  36165. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  36166. position += 3;
  36167. var bytes = (referredToCount + 7) >> 3;
  36168. retainBits[0] = data[position++];
  36169. while (--bytes > 0) {
  36170. retainBits.push(data[position++]);
  36171. }
  36172. } else if (referredFlags === 5 || referredFlags === 6) {
  36173. error('JBIG2 error: invalid referred-to flags');
  36174. }
  36175. segmentHeader.retainBits = retainBits;
  36176. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  36177. (segmentHeader.number <= 65536 ? 2 : 4));
  36178. var referredTo = [];
  36179. var i, ii;
  36180. for (i = 0; i < referredToCount; i++) {
  36181. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  36182. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  36183. readUint32(data, position)));
  36184. referredTo.push(number);
  36185. position += referredToSegmentNumberSize;
  36186. }
  36187. segmentHeader.referredTo = referredTo;
  36188. if (!pageAssociationFieldSize) {
  36189. segmentHeader.pageAssociation = data[position++];
  36190. } else {
  36191. segmentHeader.pageAssociation = readUint32(data, position);
  36192. position += 4;
  36193. }
  36194. segmentHeader.length = readUint32(data, position);
  36195. position += 4;
  36196. if (segmentHeader.length === 0xFFFFFFFF) {
  36197. // 7.2.7 Segment data length, unknown segment length
  36198. if (segmentType === 38) { // ImmediateGenericRegion
  36199. var genericRegionInfo = readRegionSegmentInformation(data, position);
  36200. var genericRegionSegmentFlags = data[position +
  36201. RegionSegmentInformationFieldLength];
  36202. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  36203. // searching for the segment end
  36204. var searchPatternLength = 6;
  36205. var searchPattern = new Uint8Array(searchPatternLength);
  36206. if (!genericRegionMmr) {
  36207. searchPattern[0] = 0xFF;
  36208. searchPattern[1] = 0xAC;
  36209. }
  36210. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  36211. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  36212. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  36213. searchPattern[5] = genericRegionInfo.height & 0xFF;
  36214. for (i = position, ii = data.length; i < ii; i++) {
  36215. var j = 0;
  36216. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  36217. j++;
  36218. }
  36219. if (j === searchPatternLength) {
  36220. segmentHeader.length = i + searchPatternLength;
  36221. break;
  36222. }
  36223. }
  36224. if (segmentHeader.length === 0xFFFFFFFF) {
  36225. error('JBIG2 error: segment end was not found');
  36226. }
  36227. } else {
  36228. error('JBIG2 error: invalid unknown segment length');
  36229. }
  36230. }
  36231. segmentHeader.headerEnd = position;
  36232. return segmentHeader;
  36233. }
  36234. function readSegments(header, data, start, end) {
  36235. var segments = [];
  36236. var position = start;
  36237. while (position < end) {
  36238. var segmentHeader = readSegmentHeader(data, position);
  36239. position = segmentHeader.headerEnd;
  36240. var segment = {
  36241. header: segmentHeader,
  36242. data: data
  36243. };
  36244. if (!header.randomAccess) {
  36245. segment.start = position;
  36246. position += segmentHeader.length;
  36247. segment.end = position;
  36248. }
  36249. segments.push(segment);
  36250. if (segmentHeader.type === 51) {
  36251. break; // end of file is found
  36252. }
  36253. }
  36254. if (header.randomAccess) {
  36255. for (var i = 0, ii = segments.length; i < ii; i++) {
  36256. segments[i].start = position;
  36257. position += segments[i].header.length;
  36258. segments[i].end = position;
  36259. }
  36260. }
  36261. return segments;
  36262. }
  36263. // 7.4.1 Region segment information field
  36264. function readRegionSegmentInformation(data, start) {
  36265. return {
  36266. width: readUint32(data, start),
  36267. height: readUint32(data, start + 4),
  36268. x: readUint32(data, start + 8),
  36269. y: readUint32(data, start + 12),
  36270. combinationOperator: data[start + 16] & 7
  36271. };
  36272. }
  36273. var RegionSegmentInformationFieldLength = 17;
  36274. function processSegment(segment, visitor) {
  36275. var header = segment.header;
  36276. var data = segment.data, position = segment.start, end = segment.end;
  36277. var args, at, i, atLength;
  36278. switch (header.type) {
  36279. case 0: // SymbolDictionary
  36280. // 7.4.2 Symbol dictionary segment syntax
  36281. var dictionary = {};
  36282. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36283. dictionary.huffman = !!(dictionaryFlags & 1);
  36284. dictionary.refinement = !!(dictionaryFlags & 2);
  36285. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36286. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36287. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36288. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36289. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36290. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36291. dictionary.template = (dictionaryFlags >> 10) & 3;
  36292. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36293. position += 2;
  36294. if (!dictionary.huffman) {
  36295. atLength = dictionary.template === 0 ? 4 : 1;
  36296. at = [];
  36297. for (i = 0; i < atLength; i++) {
  36298. at.push({
  36299. x: readInt8(data, position),
  36300. y: readInt8(data, position + 1)
  36301. });
  36302. position += 2;
  36303. }
  36304. dictionary.at = at;
  36305. }
  36306. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36307. at = [];
  36308. for (i = 0; i < 2; i++) {
  36309. at.push({
  36310. x: readInt8(data, position),
  36311. y: readInt8(data, position + 1)
  36312. });
  36313. position += 2;
  36314. }
  36315. dictionary.refinementAt = at;
  36316. }
  36317. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36318. position += 4;
  36319. dictionary.numberOfNewSymbols = readUint32(data, position);
  36320. position += 4;
  36321. args = [dictionary, header.number, header.referredTo,
  36322. data, position, end];
  36323. break;
  36324. case 6: // ImmediateTextRegion
  36325. case 7: // ImmediateLosslessTextRegion
  36326. var textRegion = {};
  36327. textRegion.info = readRegionSegmentInformation(data, position);
  36328. position += RegionSegmentInformationFieldLength;
  36329. var textRegionSegmentFlags = readUint16(data, position);
  36330. position += 2;
  36331. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36332. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36333. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36334. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36335. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36336. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36337. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36338. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36339. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36340. if (textRegion.huffman) {
  36341. var textRegionHuffmanFlags = readUint16(data, position);
  36342. position += 2;
  36343. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36344. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36345. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36346. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36347. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36348. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36349. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36350. textRegion.huffmanRefinementSizeSelector =
  36351. !!(textRegionHuffmanFlags & 14);
  36352. }
  36353. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36354. at = [];
  36355. for (i = 0; i < 2; i++) {
  36356. at.push({
  36357. x: readInt8(data, position),
  36358. y: readInt8(data, position + 1)
  36359. });
  36360. position += 2;
  36361. }
  36362. textRegion.refinementAt = at;
  36363. }
  36364. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36365. position += 4;
  36366. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36367. if (textRegion.huffman) {
  36368. error('JBIG2 error: huffman is not supported');
  36369. }
  36370. args = [textRegion, header.referredTo, data, position, end];
  36371. break;
  36372. case 38: // ImmediateGenericRegion
  36373. case 39: // ImmediateLosslessGenericRegion
  36374. var genericRegion = {};
  36375. genericRegion.info = readRegionSegmentInformation(data, position);
  36376. position += RegionSegmentInformationFieldLength;
  36377. var genericRegionSegmentFlags = data[position++];
  36378. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36379. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36380. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36381. if (!genericRegion.mmr) {
  36382. atLength = genericRegion.template === 0 ? 4 : 1;
  36383. at = [];
  36384. for (i = 0; i < atLength; i++) {
  36385. at.push({
  36386. x: readInt8(data, position),
  36387. y: readInt8(data, position + 1)
  36388. });
  36389. position += 2;
  36390. }
  36391. genericRegion.at = at;
  36392. }
  36393. args = [genericRegion, data, position, end];
  36394. break;
  36395. case 48: // PageInformation
  36396. var pageInfo = {
  36397. width: readUint32(data, position),
  36398. height: readUint32(data, position + 4),
  36399. resolutionX: readUint32(data, position + 8),
  36400. resolutionY: readUint32(data, position + 12)
  36401. };
  36402. if (pageInfo.height === 0xFFFFFFFF) {
  36403. delete pageInfo.height;
  36404. }
  36405. var pageSegmentFlags = data[position + 16];
  36406. var pageStripingInformatiom = readUint16(data, position + 17);
  36407. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36408. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36409. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36410. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36411. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36412. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36413. args = [pageInfo];
  36414. break;
  36415. case 49: // EndOfPage
  36416. break;
  36417. case 50: // EndOfStripe
  36418. break;
  36419. case 51: // EndOfFile
  36420. break;
  36421. case 62: // 7.4.15 defines 2 extension types which
  36422. // are comments and can be ignored.
  36423. break;
  36424. default:
  36425. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36426. header.type + ') is not implemented');
  36427. }
  36428. var callbackName = 'on' + header.typeName;
  36429. if (callbackName in visitor) {
  36430. visitor[callbackName].apply(visitor, args);
  36431. }
  36432. }
  36433. function processSegments(segments, visitor) {
  36434. for (var i = 0, ii = segments.length; i < ii; i++) {
  36435. processSegment(segments[i], visitor);
  36436. }
  36437. }
  36438. function parseJbig2(data, start, end) {
  36439. var position = start;
  36440. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36441. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36442. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36443. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36444. error('JBIG2 error: invalid header');
  36445. }
  36446. var header = {};
  36447. position += 8;
  36448. var flags = data[position++];
  36449. header.randomAccess = !(flags & 1);
  36450. if (!(flags & 2)) {
  36451. header.numberOfPages = readUint32(data, position);
  36452. position += 4;
  36453. }
  36454. var segments = readSegments(header, data, position, end);
  36455. error('Not implemented');
  36456. // processSegments(segments, new SimpleSegmentVisitor());
  36457. }
  36458. function parseJbig2Chunks(chunks) {
  36459. var visitor = new SimpleSegmentVisitor();
  36460. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36461. var chunk = chunks[i];
  36462. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36463. processSegments(segments, visitor);
  36464. }
  36465. return visitor.buffer;
  36466. }
  36467. function SimpleSegmentVisitor() {}
  36468. SimpleSegmentVisitor.prototype = {
  36469. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36470. this.currentPageInfo = info;
  36471. var rowSize = (info.width + 7) >> 3;
  36472. var buffer = new Uint8Array(rowSize * info.height);
  36473. // The contents of ArrayBuffers are initialized to 0.
  36474. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36475. if (info.defaultPixelValue) {
  36476. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36477. buffer[i] = 0xFF;
  36478. }
  36479. }
  36480. this.buffer = buffer;
  36481. },
  36482. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36483. var pageInfo = this.currentPageInfo;
  36484. var width = regionInfo.width, height = regionInfo.height;
  36485. var rowSize = (pageInfo.width + 7) >> 3;
  36486. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36487. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36488. var buffer = this.buffer;
  36489. var mask0 = 128 >> (regionInfo.x & 7);
  36490. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36491. var i, j, mask, offset;
  36492. switch (combinationOperator) {
  36493. case 0: // OR
  36494. for (i = 0; i < height; i++) {
  36495. mask = mask0;
  36496. offset = offset0;
  36497. for (j = 0; j < width; j++) {
  36498. if (bitmap[i][j]) {
  36499. buffer[offset] |= mask;
  36500. }
  36501. mask >>= 1;
  36502. if (!mask) {
  36503. mask = 128;
  36504. offset++;
  36505. }
  36506. }
  36507. offset0 += rowSize;
  36508. }
  36509. break;
  36510. case 2: // XOR
  36511. for (i = 0; i < height; i++) {
  36512. mask = mask0;
  36513. offset = offset0;
  36514. for (j = 0; j < width; j++) {
  36515. if (bitmap[i][j]) {
  36516. buffer[offset] ^= mask;
  36517. }
  36518. mask >>= 1;
  36519. if (!mask) {
  36520. mask = 128;
  36521. offset++;
  36522. }
  36523. }
  36524. offset0 += rowSize;
  36525. }
  36526. break;
  36527. default:
  36528. error('JBIG2 error: operator ' + combinationOperator +
  36529. ' is not supported');
  36530. }
  36531. },
  36532. onImmediateGenericRegion:
  36533. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36534. start, end) {
  36535. var regionInfo = region.info;
  36536. var decodingContext = new DecodingContext(data, start, end);
  36537. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36538. region.template, region.prediction, null,
  36539. region.at, decodingContext);
  36540. this.drawBitmap(regionInfo, bitmap);
  36541. },
  36542. onImmediateLosslessGenericRegion:
  36543. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36544. this.onImmediateGenericRegion.apply(this, arguments);
  36545. },
  36546. onSymbolDictionary:
  36547. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36548. currentSegment,
  36549. referredSegments,
  36550. data, start, end) {
  36551. var huffmanTables;
  36552. if (dictionary.huffman) {
  36553. error('JBIG2 error: huffman is not supported');
  36554. }
  36555. // Combines exported symbols from all referred segments
  36556. var symbols = this.symbols;
  36557. if (!symbols) {
  36558. this.symbols = symbols = {};
  36559. }
  36560. var inputSymbols = [];
  36561. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36562. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36563. }
  36564. var decodingContext = new DecodingContext(data, start, end);
  36565. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36566. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36567. dictionary.numberOfExportedSymbols, huffmanTables,
  36568. dictionary.template, dictionary.at,
  36569. dictionary.refinementTemplate, dictionary.refinementAt,
  36570. decodingContext);
  36571. },
  36572. onImmediateTextRegion:
  36573. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36574. referredSegments,
  36575. data, start, end) {
  36576. var regionInfo = region.info;
  36577. var huffmanTables;
  36578. // Combines exported symbols from all referred segments
  36579. var symbols = this.symbols;
  36580. var inputSymbols = [];
  36581. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36582. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36583. }
  36584. var symbolCodeLength = log2(inputSymbols.length);
  36585. var decodingContext = new DecodingContext(data, start, end);
  36586. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36587. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36588. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36589. symbolCodeLength, region.transposed, region.dsOffset,
  36590. region.referenceCorner, region.combinationOperator, huffmanTables,
  36591. region.refinementTemplate, region.refinementAt, decodingContext);
  36592. this.drawBitmap(regionInfo, bitmap);
  36593. },
  36594. onImmediateLosslessTextRegion:
  36595. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36596. this.onImmediateTextRegion.apply(this, arguments);
  36597. }
  36598. };
  36599. function Jbig2Image() {}
  36600. Jbig2Image.prototype = {
  36601. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36602. return parseJbig2Chunks(chunks);
  36603. }
  36604. };
  36605. return Jbig2Image;
  36606. })();
  36607. var bidi = PDFJS.bidi = (function bidiClosure() {
  36608. // Character types for symbols from 0000 to 00FF.
  36609. var baseTypes = [
  36610. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36611. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36612. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36613. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36614. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36615. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36616. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36617. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36618. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36619. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36620. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36621. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36622. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36623. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36624. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36625. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36626. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36627. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36628. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36629. ];
  36630. // Character types for symbols from 0600 to 06FF
  36631. var arabicTypes = [
  36632. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36633. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36634. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36635. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36636. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36637. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36638. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36639. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36640. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36641. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36642. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36643. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36644. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36645. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36646. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36647. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36648. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36649. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36650. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36651. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36652. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36653. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36654. ];
  36655. function isOdd(i) {
  36656. return (i & 1) !== 0;
  36657. }
  36658. function isEven(i) {
  36659. return (i & 1) === 0;
  36660. }
  36661. function findUnequal(arr, start, value) {
  36662. for (var j = start, jj = arr.length; j < jj; ++j) {
  36663. if (arr[j] !== value) {
  36664. return j;
  36665. }
  36666. }
  36667. return j;
  36668. }
  36669. function setValues(arr, start, end, value) {
  36670. for (var j = start; j < end; ++j) {
  36671. arr[j] = value;
  36672. }
  36673. }
  36674. function reverseValues(arr, start, end) {
  36675. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36676. var temp = arr[i];
  36677. arr[i] = arr[j];
  36678. arr[j] = temp;
  36679. }
  36680. }
  36681. function createBidiText(str, isLTR, vertical) {
  36682. return {
  36683. str: str,
  36684. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36685. };
  36686. }
  36687. // These are used in bidi(), which is called frequently. We re-use them on
  36688. // each call to avoid unnecessary allocations.
  36689. var chars = [];
  36690. var types = [];
  36691. function bidi(str, startLevel, vertical) {
  36692. var isLTR = true;
  36693. var strLength = str.length;
  36694. if (strLength === 0 || vertical) {
  36695. return createBidiText(str, isLTR, vertical);
  36696. }
  36697. // Get types and fill arrays
  36698. chars.length = strLength;
  36699. types.length = strLength;
  36700. var numBidi = 0;
  36701. var i, ii;
  36702. for (i = 0; i < strLength; ++i) {
  36703. chars[i] = str.charAt(i);
  36704. var charCode = str.charCodeAt(i);
  36705. var charType = 'L';
  36706. if (charCode <= 0x00ff) {
  36707. charType = baseTypes[charCode];
  36708. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36709. charType = 'R';
  36710. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36711. charType = arabicTypes[charCode & 0xff];
  36712. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36713. charType = 'AL';
  36714. }
  36715. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36716. numBidi++;
  36717. }
  36718. types[i] = charType;
  36719. }
  36720. // Detect the bidi method
  36721. // - If there are no rtl characters then no bidi needed
  36722. // - If less than 30% chars are rtl then string is primarily ltr
  36723. // - If more than 30% chars are rtl then string is primarily rtl
  36724. if (numBidi === 0) {
  36725. isLTR = true;
  36726. return createBidiText(str, isLTR);
  36727. }
  36728. if (startLevel === -1) {
  36729. if ((strLength / numBidi) < 0.3) {
  36730. isLTR = true;
  36731. startLevel = 0;
  36732. } else {
  36733. isLTR = false;
  36734. startLevel = 1;
  36735. }
  36736. }
  36737. var levels = [];
  36738. for (i = 0; i < strLength; ++i) {
  36739. levels[i] = startLevel;
  36740. }
  36741. /*
  36742. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36743. */
  36744. var e = (isOdd(startLevel) ? 'R' : 'L');
  36745. var sor = e;
  36746. var eor = sor;
  36747. /*
  36748. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36749. type of the NSM to the type of the previous character. If the NSM is at the
  36750. start of the level run, it will get the type of sor.
  36751. */
  36752. var lastType = sor;
  36753. for (i = 0; i < strLength; ++i) {
  36754. if (types[i] === 'NSM') {
  36755. types[i] = lastType;
  36756. } else {
  36757. lastType = types[i];
  36758. }
  36759. }
  36760. /*
  36761. W2. Search backwards from each instance of a European number until the
  36762. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36763. the type of the European number to Arabic number.
  36764. */
  36765. lastType = sor;
  36766. var t;
  36767. for (i = 0; i < strLength; ++i) {
  36768. t = types[i];
  36769. if (t === 'EN') {
  36770. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36771. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36772. lastType = t;
  36773. }
  36774. }
  36775. /*
  36776. W3. Change all ALs to R.
  36777. */
  36778. for (i = 0; i < strLength; ++i) {
  36779. t = types[i];
  36780. if (t === 'AL') {
  36781. types[i] = 'R';
  36782. }
  36783. }
  36784. /*
  36785. W4. A single European separator between two European numbers changes to a
  36786. European number. A single common separator between two numbers of the same
  36787. type changes to that type:
  36788. */
  36789. for (i = 1; i < strLength - 1; ++i) {
  36790. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36791. types[i] = 'EN';
  36792. }
  36793. if (types[i] === 'CS' &&
  36794. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36795. types[i + 1] === types[i - 1]) {
  36796. types[i] = types[i - 1];
  36797. }
  36798. }
  36799. /*
  36800. W5. A sequence of European terminators adjacent to European numbers changes
  36801. to all European numbers:
  36802. */
  36803. for (i = 0; i < strLength; ++i) {
  36804. if (types[i] === 'EN') {
  36805. // do before
  36806. var j;
  36807. for (j = i - 1; j >= 0; --j) {
  36808. if (types[j] !== 'ET') {
  36809. break;
  36810. }
  36811. types[j] = 'EN';
  36812. }
  36813. // do after
  36814. for (j = i + 1; j < strLength; --j) {
  36815. if (types[j] !== 'ET') {
  36816. break;
  36817. }
  36818. types[j] = 'EN';
  36819. }
  36820. }
  36821. }
  36822. /*
  36823. W6. Otherwise, separators and terminators change to Other Neutral:
  36824. */
  36825. for (i = 0; i < strLength; ++i) {
  36826. t = types[i];
  36827. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36828. types[i] = 'ON';
  36829. }
  36830. }
  36831. /*
  36832. W7. Search backwards from each instance of a European number until the
  36833. first strong type (R, L, or sor) is found. If an L is found, then change
  36834. the type of the European number to L.
  36835. */
  36836. lastType = sor;
  36837. for (i = 0; i < strLength; ++i) {
  36838. t = types[i];
  36839. if (t === 'EN') {
  36840. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36841. } else if (t === 'R' || t === 'L') {
  36842. lastType = t;
  36843. }
  36844. }
  36845. /*
  36846. N1. A sequence of neutrals takes the direction of the surrounding strong
  36847. text if the text on both sides has the same direction. European and Arabic
  36848. numbers are treated as though they were R. Start-of-level-run (sor) and
  36849. end-of-level-run (eor) are used at level run boundaries.
  36850. */
  36851. for (i = 0; i < strLength; ++i) {
  36852. if (types[i] === 'ON') {
  36853. var end = findUnequal(types, i + 1, 'ON');
  36854. var before = sor;
  36855. if (i > 0) {
  36856. before = types[i - 1];
  36857. }
  36858. var after = eor;
  36859. if (end + 1 < strLength) {
  36860. after = types[end + 1];
  36861. }
  36862. if (before !== 'L') {
  36863. before = 'R';
  36864. }
  36865. if (after !== 'L') {
  36866. after = 'R';
  36867. }
  36868. if (before === after) {
  36869. setValues(types, i, end, before);
  36870. }
  36871. i = end - 1; // reset to end (-1 so next iteration is ok)
  36872. }
  36873. }
  36874. /*
  36875. N2. Any remaining neutrals take the embedding direction.
  36876. */
  36877. for (i = 0; i < strLength; ++i) {
  36878. if (types[i] === 'ON') {
  36879. types[i] = e;
  36880. }
  36881. }
  36882. /*
  36883. I1. For all characters with an even (left-to-right) embedding direction,
  36884. those of type R go up one level and those of type AN or EN go up two
  36885. levels.
  36886. I2. For all characters with an odd (right-to-left) embedding direction,
  36887. those of type L, EN or AN go up one level.
  36888. */
  36889. for (i = 0; i < strLength; ++i) {
  36890. t = types[i];
  36891. if (isEven(levels[i])) {
  36892. if (t === 'R') {
  36893. levels[i] += 1;
  36894. } else if (t === 'AN' || t === 'EN') {
  36895. levels[i] += 2;
  36896. }
  36897. } else { // isOdd
  36898. if (t === 'L' || t === 'AN' || t === 'EN') {
  36899. levels[i] += 1;
  36900. }
  36901. }
  36902. }
  36903. /*
  36904. L1. On each line, reset the embedding level of the following characters to
  36905. the paragraph embedding level:
  36906. segment separators,
  36907. paragraph separators,
  36908. any sequence of whitespace characters preceding a segment separator or
  36909. paragraph separator, and any sequence of white space characters at the end
  36910. of the line.
  36911. */
  36912. // don't bother as text is only single line
  36913. /*
  36914. L2. From the highest level found in the text to the lowest odd level on
  36915. each line, reverse any contiguous sequence of characters that are at that
  36916. level or higher.
  36917. */
  36918. // find highest level & lowest odd level
  36919. var highestLevel = -1;
  36920. var lowestOddLevel = 99;
  36921. var level;
  36922. for (i = 0, ii = levels.length; i < ii; ++i) {
  36923. level = levels[i];
  36924. if (highestLevel < level) {
  36925. highestLevel = level;
  36926. }
  36927. if (lowestOddLevel > level && isOdd(level)) {
  36928. lowestOddLevel = level;
  36929. }
  36930. }
  36931. // now reverse between those limits
  36932. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36933. // find segments to reverse
  36934. var start = -1;
  36935. for (i = 0, ii = levels.length; i < ii; ++i) {
  36936. if (levels[i] < level) {
  36937. if (start >= 0) {
  36938. reverseValues(chars, start, i);
  36939. start = -1;
  36940. }
  36941. } else if (start < 0) {
  36942. start = i;
  36943. }
  36944. }
  36945. if (start >= 0) {
  36946. reverseValues(chars, start, levels.length);
  36947. }
  36948. }
  36949. /*
  36950. L3. Combining marks applied to a right-to-left base character will at this
  36951. point precede their base character. If the rendering engine expects them to
  36952. follow the base characters in the final display process, then the ordering
  36953. of the marks and the base character must be reversed.
  36954. */
  36955. // don't bother for now
  36956. /*
  36957. L4. A character that possesses the mirrored property as specified by
  36958. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36959. directionality of that character is R.
  36960. */
  36961. // don't mirror as characters are already mirrored in the pdf
  36962. // Finally, return string
  36963. var result = '';
  36964. for (i = 0, ii = chars.length; i < ii; ++i) {
  36965. var ch = chars[i];
  36966. if (ch !== '<' && ch !== '>') {
  36967. result += ch;
  36968. }
  36969. }
  36970. return createBidiText(result, isLTR);
  36971. }
  36972. return bidi;
  36973. })();
  36974. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36975. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36976. /* Copyright 2014 Opera Software ASA
  36977. *
  36978. * Licensed under the Apache License, Version 2.0 (the "License");
  36979. * you may not use this file except in compliance with the License.
  36980. * You may obtain a copy of the License at
  36981. *
  36982. * http://www.apache.org/licenses/LICENSE-2.0
  36983. *
  36984. * Unless required by applicable law or agreed to in writing, software
  36985. * distributed under the License is distributed on an "AS IS" BASIS,
  36986. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36987. * See the License for the specific language governing permissions and
  36988. * limitations under the License.
  36989. *
  36990. *
  36991. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36992. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36993. */
  36994. /* globals Uint32ArrayView */
  36995. 'use strict';
  36996. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36997. // Workaround for missing math precison in JS.
  36998. var MASK_HIGH = 0xffff0000;
  36999. var MASK_LOW = 0xffff;
  37000. function MurmurHash3_64 (seed) {
  37001. var SEED = 0xc3d2e1f0;
  37002. this.h1 = seed ? seed & 0xffffffff : SEED;
  37003. this.h2 = seed ? seed & 0xffffffff : SEED;
  37004. }
  37005. var alwaysUseUint32ArrayView = false;
  37006. // old webkits have issues with non-aligned arrays
  37007. try {
  37008. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  37009. } catch (e) {
  37010. alwaysUseUint32ArrayView = true;
  37011. }
  37012. MurmurHash3_64.prototype = {
  37013. update: function MurmurHash3_64_update(input) {
  37014. var useUint32ArrayView = alwaysUseUint32ArrayView;
  37015. var i;
  37016. if (typeof input === 'string') {
  37017. var data = new Uint8Array(input.length * 2);
  37018. var length = 0;
  37019. for (i = 0; i < input.length; i++) {
  37020. var code = input.charCodeAt(i);
  37021. if (code <= 0xff) {
  37022. data[length++] = code;
  37023. }
  37024. else {
  37025. data[length++] = code >>> 8;
  37026. data[length++] = code & 0xff;
  37027. }
  37028. }
  37029. } else if (input instanceof Uint8Array) {
  37030. data = input;
  37031. length = data.length;
  37032. } else if (typeof input === 'object' && ('length' in input)) {
  37033. // processing regular arrays as well, e.g. for IE9
  37034. data = input;
  37035. length = data.length;
  37036. useUint32ArrayView = true;
  37037. } else {
  37038. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  37039. 'Input must be a string or array.');
  37040. }
  37041. var blockCounts = length >> 2;
  37042. var tailLength = length - blockCounts * 4;
  37043. // we don't care about endianness here
  37044. var dataUint32 = useUint32ArrayView ?
  37045. new Uint32ArrayView(data, blockCounts) :
  37046. new Uint32Array(data.buffer, 0, blockCounts);
  37047. var k1 = 0;
  37048. var k2 = 0;
  37049. var h1 = this.h1;
  37050. var h2 = this.h2;
  37051. var C1 = 0xcc9e2d51;
  37052. var C2 = 0x1b873593;
  37053. var C1_LOW = C1 & MASK_LOW;
  37054. var C2_LOW = C2 & MASK_LOW;
  37055. for (i = 0; i < blockCounts; i++) {
  37056. if (i & 1) {
  37057. k1 = dataUint32[i];
  37058. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37059. k1 = k1 << 15 | k1 >>> 17;
  37060. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37061. h1 ^= k1;
  37062. h1 = h1 << 13 | h1 >>> 19;
  37063. h1 = h1 * 5 + 0xe6546b64;
  37064. } else {
  37065. k2 = dataUint32[i];
  37066. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  37067. k2 = k2 << 15 | k2 >>> 17;
  37068. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  37069. h2 ^= k2;
  37070. h2 = h2 << 13 | h2 >>> 19;
  37071. h2 = h2 * 5 + 0xe6546b64;
  37072. }
  37073. }
  37074. k1 = 0;
  37075. switch (tailLength) {
  37076. case 3:
  37077. k1 ^= data[blockCounts * 4 + 2] << 16;
  37078. /* falls through */
  37079. case 2:
  37080. k1 ^= data[blockCounts * 4 + 1] << 8;
  37081. /* falls through */
  37082. case 1:
  37083. k1 ^= data[blockCounts * 4];
  37084. /* falls through */
  37085. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37086. k1 = k1 << 15 | k1 >>> 17;
  37087. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37088. if (blockCounts & 1) {
  37089. h1 ^= k1;
  37090. } else {
  37091. h2 ^= k1;
  37092. }
  37093. }
  37094. this.h1 = h1;
  37095. this.h2 = h2;
  37096. return this;
  37097. },
  37098. hexdigest: function MurmurHash3_64_hexdigest () {
  37099. var h1 = this.h1;
  37100. var h2 = this.h2;
  37101. h1 ^= h2 >>> 1;
  37102. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  37103. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  37104. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  37105. h1 ^= h2 >>> 1;
  37106. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  37107. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  37108. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  37109. h1 ^= h2 >>> 1;
  37110. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  37111. var hex = (arr[i] >>> 0).toString(16);
  37112. while (hex.length < 8) {
  37113. hex = '0' + hex;
  37114. }
  37115. str += hex;
  37116. }
  37117. return str;
  37118. }
  37119. };
  37120. return MurmurHash3_64;
  37121. })();
  37122. }).call((typeof window === 'undefined') ? this : window);
  37123. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  37124. // workerSrc is not set -- using last script url to define default location
  37125. PDFJS.workerSrc = (function () {
  37126. 'use strict';
  37127. var scriptTagContainer = document.body ||
  37128. document.getElementsByTagName('head')[0];
  37129. var pdfjsSrc = scriptTagContainer.lastChild.src;
  37130. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  37131. })();
  37132. }