pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078
  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.0.1029';
  24. PDFJS.build = '50fe7c8';
  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 StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  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. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. PDFJS.PasswordException = PasswordException;
  346. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  347. function UnknownErrorException(msg, details) {
  348. this.name = 'UnknownErrorException';
  349. this.message = msg;
  350. this.details = details;
  351. }
  352. UnknownErrorException.prototype = new Error();
  353. UnknownErrorException.constructor = UnknownErrorException;
  354. return UnknownErrorException;
  355. })();
  356. PDFJS.UnknownErrorException = UnknownErrorException;
  357. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  358. function InvalidPDFException(msg) {
  359. this.name = 'InvalidPDFException';
  360. this.message = msg;
  361. }
  362. InvalidPDFException.prototype = new Error();
  363. InvalidPDFException.constructor = InvalidPDFException;
  364. return InvalidPDFException;
  365. })();
  366. PDFJS.InvalidPDFException = InvalidPDFException;
  367. var MissingPDFException = (function MissingPDFExceptionClosure() {
  368. function MissingPDFException(msg) {
  369. this.name = 'MissingPDFException';
  370. this.message = msg;
  371. }
  372. MissingPDFException.prototype = new Error();
  373. MissingPDFException.constructor = MissingPDFException;
  374. return MissingPDFException;
  375. })();
  376. PDFJS.MissingPDFException = MissingPDFException;
  377. var UnexpectedResponseException =
  378. (function UnexpectedResponseExceptionClosure() {
  379. function UnexpectedResponseException(msg, status) {
  380. this.name = 'UnexpectedResponseException';
  381. this.message = msg;
  382. this.status = status;
  383. }
  384. UnexpectedResponseException.prototype = new Error();
  385. UnexpectedResponseException.constructor = UnexpectedResponseException;
  386. return UnexpectedResponseException;
  387. })();
  388. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  389. var NotImplementedException = (function NotImplementedExceptionClosure() {
  390. function NotImplementedException(msg) {
  391. this.message = msg;
  392. }
  393. NotImplementedException.prototype = new Error();
  394. NotImplementedException.prototype.name = 'NotImplementedException';
  395. NotImplementedException.constructor = NotImplementedException;
  396. return NotImplementedException;
  397. })();
  398. var MissingDataException = (function MissingDataExceptionClosure() {
  399. function MissingDataException(begin, end) {
  400. this.begin = begin;
  401. this.end = end;
  402. this.message = 'Missing data [' + begin + ', ' + end + ')';
  403. }
  404. MissingDataException.prototype = new Error();
  405. MissingDataException.prototype.name = 'MissingDataException';
  406. MissingDataException.constructor = MissingDataException;
  407. return MissingDataException;
  408. })();
  409. var XRefParseException = (function XRefParseExceptionClosure() {
  410. function XRefParseException(msg) {
  411. this.message = msg;
  412. }
  413. XRefParseException.prototype = new Error();
  414. XRefParseException.prototype.name = 'XRefParseException';
  415. XRefParseException.constructor = XRefParseException;
  416. return XRefParseException;
  417. })();
  418. function bytesToString(bytes) {
  419. var length = bytes.length;
  420. var MAX_ARGUMENT_COUNT = 8192;
  421. if (length < MAX_ARGUMENT_COUNT) {
  422. return String.fromCharCode.apply(null, bytes);
  423. }
  424. var strBuf = [];
  425. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  426. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  427. var chunk = bytes.subarray(i, chunkEnd);
  428. strBuf.push(String.fromCharCode.apply(null, chunk));
  429. }
  430. return strBuf.join('');
  431. }
  432. function stringToBytes(str) {
  433. var length = str.length;
  434. var bytes = new Uint8Array(length);
  435. for (var i = 0; i < length; ++i) {
  436. bytes[i] = str.charCodeAt(i) & 0xFF;
  437. }
  438. return bytes;
  439. }
  440. function string32(value) {
  441. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  442. (value >> 8) & 0xff, value & 0xff);
  443. }
  444. function log2(x) {
  445. var n = 1, i = 0;
  446. while (x > n) {
  447. n <<= 1;
  448. i++;
  449. }
  450. return i;
  451. }
  452. function readInt8(data, start) {
  453. return (data[start] << 24) >> 24;
  454. }
  455. function readUint16(data, offset) {
  456. return (data[offset] << 8) | data[offset + 1];
  457. }
  458. function readUint32(data, offset) {
  459. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  460. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  461. }
  462. // Lazy test the endianness of the platform
  463. // NOTE: This will be 'true' for simulated TypedArrays
  464. function isLittleEndian() {
  465. var buffer8 = new Uint8Array(2);
  466. buffer8[0] = 1;
  467. var buffer16 = new Uint16Array(buffer8.buffer);
  468. return (buffer16[0] === 1);
  469. }
  470. Object.defineProperty(PDFJS, 'isLittleEndian', {
  471. configurable: true,
  472. get: function PDFJS_isLittleEndian() {
  473. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  474. }
  475. });
  476. // Lazy test if the userAgant support CanvasTypedArrays
  477. function hasCanvasTypedArrays() {
  478. var canvas = document.createElement('canvas');
  479. canvas.width = canvas.height = 1;
  480. var ctx = canvas.getContext('2d');
  481. var imageData = ctx.createImageData(1, 1);
  482. return (typeof imageData.data.buffer !== 'undefined');
  483. }
  484. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  485. configurable: true,
  486. get: function PDFJS_hasCanvasTypedArrays() {
  487. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  488. }
  489. });
  490. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  491. function Uint32ArrayView(buffer, length) {
  492. this.buffer = buffer;
  493. this.byteLength = buffer.length;
  494. this.length = length === undefined ? (this.byteLength >> 2) : length;
  495. ensureUint32ArrayViewProps(this.length);
  496. }
  497. Uint32ArrayView.prototype = Object.create(null);
  498. var uint32ArrayViewSetters = 0;
  499. function createUint32ArrayProp(index) {
  500. return {
  501. get: function () {
  502. var buffer = this.buffer, offset = index << 2;
  503. return (buffer[offset] | (buffer[offset + 1] << 8) |
  504. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  505. },
  506. set: function (value) {
  507. var buffer = this.buffer, offset = index << 2;
  508. buffer[offset] = value & 255;
  509. buffer[offset + 1] = (value >> 8) & 255;
  510. buffer[offset + 2] = (value >> 16) & 255;
  511. buffer[offset + 3] = (value >>> 24) & 255;
  512. }
  513. };
  514. }
  515. function ensureUint32ArrayViewProps(length) {
  516. while (uint32ArrayViewSetters < length) {
  517. Object.defineProperty(Uint32ArrayView.prototype,
  518. uint32ArrayViewSetters,
  519. createUint32ArrayProp(uint32ArrayViewSetters));
  520. uint32ArrayViewSetters++;
  521. }
  522. }
  523. return Uint32ArrayView;
  524. })();
  525. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  526. var Util = PDFJS.Util = (function UtilClosure() {
  527. function Util() {}
  528. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  529. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  530. // creating many intermediate strings.
  531. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  532. rgbBuf[1] = r;
  533. rgbBuf[3] = g;
  534. rgbBuf[5] = b;
  535. return rgbBuf.join('');
  536. };
  537. // Concatenates two transformation matrices together and returns the result.
  538. Util.transform = function Util_transform(m1, m2) {
  539. return [
  540. m1[0] * m2[0] + m1[2] * m2[1],
  541. m1[1] * m2[0] + m1[3] * m2[1],
  542. m1[0] * m2[2] + m1[2] * m2[3],
  543. m1[1] * m2[2] + m1[3] * m2[3],
  544. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  545. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  546. ];
  547. };
  548. // For 2d affine transforms
  549. Util.applyTransform = function Util_applyTransform(p, m) {
  550. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  551. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  552. return [xt, yt];
  553. };
  554. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  555. var d = m[0] * m[3] - m[1] * m[2];
  556. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  557. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  558. return [xt, yt];
  559. };
  560. // Applies the transform to the rectangle and finds the minimum axially
  561. // aligned bounding box.
  562. Util.getAxialAlignedBoundingBox =
  563. function Util_getAxialAlignedBoundingBox(r, m) {
  564. var p1 = Util.applyTransform(r, m);
  565. var p2 = Util.applyTransform(r.slice(2, 4), m);
  566. var p3 = Util.applyTransform([r[0], r[3]], m);
  567. var p4 = Util.applyTransform([r[2], r[1]], m);
  568. return [
  569. Math.min(p1[0], p2[0], p3[0], p4[0]),
  570. Math.min(p1[1], p2[1], p3[1], p4[1]),
  571. Math.max(p1[0], p2[0], p3[0], p4[0]),
  572. Math.max(p1[1], p2[1], p3[1], p4[1])
  573. ];
  574. };
  575. Util.inverseTransform = function Util_inverseTransform(m) {
  576. var d = m[0] * m[3] - m[1] * m[2];
  577. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  578. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  579. };
  580. // Apply a generic 3d matrix M on a 3-vector v:
  581. // | a b c | | X |
  582. // | d e f | x | Y |
  583. // | g h i | | Z |
  584. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  585. // with v as [X,Y,Z]
  586. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  587. return [
  588. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  589. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  590. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  591. ];
  592. };
  593. // This calculation uses Singular Value Decomposition.
  594. // The SVD can be represented with formula A = USV. We are interested in the
  595. // matrix S here because it represents the scale values.
  596. Util.singularValueDecompose2dScale =
  597. function Util_singularValueDecompose2dScale(m) {
  598. var transpose = [m[0], m[2], m[1], m[3]];
  599. // Multiply matrix m with its transpose.
  600. var a = m[0] * transpose[0] + m[1] * transpose[2];
  601. var b = m[0] * transpose[1] + m[1] * transpose[3];
  602. var c = m[2] * transpose[0] + m[3] * transpose[2];
  603. var d = m[2] * transpose[1] + m[3] * transpose[3];
  604. // Solve the second degree polynomial to get roots.
  605. var first = (a + d) / 2;
  606. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  607. var sx = first + second || 1;
  608. var sy = first - second || 1;
  609. // Scale values are the square roots of the eigenvalues.
  610. return [Math.sqrt(sx), Math.sqrt(sy)];
  611. };
  612. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  613. // For coordinate systems whose origin lies in the bottom-left, this
  614. // means normalization to (BL,TR) ordering. For systems with origin in the
  615. // top-left, this means (TL,BR) ordering.
  616. Util.normalizeRect = function Util_normalizeRect(rect) {
  617. var r = rect.slice(0); // clone rect
  618. if (rect[0] > rect[2]) {
  619. r[0] = rect[2];
  620. r[2] = rect[0];
  621. }
  622. if (rect[1] > rect[3]) {
  623. r[1] = rect[3];
  624. r[3] = rect[1];
  625. }
  626. return r;
  627. };
  628. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  629. // intersection of rect1 and rect2. If no intersection, returns 'false'
  630. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  631. Util.intersect = function Util_intersect(rect1, rect2) {
  632. function compare(a, b) {
  633. return a - b;
  634. }
  635. // Order points along the axes
  636. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  637. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  638. result = [];
  639. rect1 = Util.normalizeRect(rect1);
  640. rect2 = Util.normalizeRect(rect2);
  641. // X: first and second points belong to different rectangles?
  642. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  643. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  644. // Intersection must be between second and third points
  645. result[0] = orderedX[1];
  646. result[2] = orderedX[2];
  647. } else {
  648. return false;
  649. }
  650. // Y: first and second points belong to different rectangles?
  651. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  652. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  653. // Intersection must be between second and third points
  654. result[1] = orderedY[1];
  655. result[3] = orderedY[2];
  656. } else {
  657. return false;
  658. }
  659. return result;
  660. };
  661. Util.sign = function Util_sign(num) {
  662. return num < 0 ? -1 : 1;
  663. };
  664. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  665. Array.prototype.push.apply(arr1, arr2);
  666. };
  667. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  668. Array.prototype.unshift.apply(arr1, arr2);
  669. };
  670. Util.extendObj = function extendObj(obj1, obj2) {
  671. for (var key in obj2) {
  672. obj1[key] = obj2[key];
  673. }
  674. };
  675. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  676. name) {
  677. while (dict && !dict.has(name)) {
  678. dict = dict.get('Parent');
  679. }
  680. if (!dict) {
  681. return null;
  682. }
  683. return dict.get(name);
  684. };
  685. Util.inherit = function Util_inherit(sub, base, prototype) {
  686. sub.prototype = Object.create(base.prototype);
  687. sub.prototype.constructor = sub;
  688. for (var prop in prototype) {
  689. sub.prototype[prop] = prototype[prop];
  690. }
  691. };
  692. Util.loadScript = function Util_loadScript(src, callback) {
  693. var script = document.createElement('script');
  694. var loaded = false;
  695. script.setAttribute('src', src);
  696. if (callback) {
  697. script.onload = function() {
  698. if (!loaded) {
  699. callback();
  700. }
  701. loaded = true;
  702. };
  703. }
  704. document.getElementsByTagName('head')[0].appendChild(script);
  705. };
  706. return Util;
  707. })();
  708. /**
  709. * PDF page viewport created based on scale, rotation and offset.
  710. * @class
  711. * @alias PDFJS.PageViewport
  712. */
  713. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  714. /**
  715. * @constructor
  716. * @private
  717. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  718. * @param scale {number} scale of the viewport.
  719. * @param rotation {number} rotations of the viewport in degrees.
  720. * @param offsetX {number} offset X
  721. * @param offsetY {number} offset Y
  722. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  723. */
  724. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  725. this.viewBox = viewBox;
  726. this.scale = scale;
  727. this.rotation = rotation;
  728. this.offsetX = offsetX;
  729. this.offsetY = offsetY;
  730. // creating transform to convert pdf coordinate system to the normal
  731. // canvas like coordinates taking in account scale and rotation
  732. var centerX = (viewBox[2] + viewBox[0]) / 2;
  733. var centerY = (viewBox[3] + viewBox[1]) / 2;
  734. var rotateA, rotateB, rotateC, rotateD;
  735. rotation = rotation % 360;
  736. rotation = rotation < 0 ? rotation + 360 : rotation;
  737. switch (rotation) {
  738. case 180:
  739. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  740. break;
  741. case 90:
  742. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  743. break;
  744. case 270:
  745. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  746. break;
  747. //case 0:
  748. default:
  749. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  750. break;
  751. }
  752. if (dontFlip) {
  753. rotateC = -rotateC; rotateD = -rotateD;
  754. }
  755. var offsetCanvasX, offsetCanvasY;
  756. var width, height;
  757. if (rotateA === 0) {
  758. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  759. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  760. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  761. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  762. } else {
  763. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  765. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  766. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  767. }
  768. // creating transform for the following operations:
  769. // translate(-centerX, -centerY), rotate and flip vertically,
  770. // scale, and translate(offsetCanvasX, offsetCanvasY)
  771. this.transform = [
  772. rotateA * scale,
  773. rotateB * scale,
  774. rotateC * scale,
  775. rotateD * scale,
  776. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  777. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  778. ];
  779. this.width = width;
  780. this.height = height;
  781. this.fontScale = scale;
  782. }
  783. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  784. /**
  785. * Clones viewport with additional properties.
  786. * @param args {Object} (optional) If specified, may contain the 'scale' or
  787. * 'rotation' properties to override the corresponding properties in
  788. * the cloned viewport.
  789. * @returns {PDFJS.PageViewport} Cloned viewport.
  790. */
  791. clone: function PageViewPort_clone(args) {
  792. args = args || {};
  793. var scale = 'scale' in args ? args.scale : this.scale;
  794. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  795. return new PageViewport(this.viewBox.slice(), scale, rotation,
  796. this.offsetX, this.offsetY, args.dontFlip);
  797. },
  798. /**
  799. * Converts PDF point to the viewport coordinates. For examples, useful for
  800. * converting PDF location into canvas pixel coordinates.
  801. * @param x {number} X coordinate.
  802. * @param y {number} Y coordinate.
  803. * @returns {Object} Object that contains 'x' and 'y' properties of the
  804. * point in the viewport coordinate space.
  805. * @see {@link convertToPdfPoint}
  806. * @see {@link convertToViewportRectangle}
  807. */
  808. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  809. return Util.applyTransform([x, y], this.transform);
  810. },
  811. /**
  812. * Converts PDF rectangle to the viewport coordinates.
  813. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  814. * @returns {Array} Contains corresponding coordinates of the rectangle
  815. * in the viewport coordinate space.
  816. * @see {@link convertToViewportPoint}
  817. */
  818. convertToViewportRectangle:
  819. function PageViewport_convertToViewportRectangle(rect) {
  820. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  821. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  822. return [tl[0], tl[1], br[0], br[1]];
  823. },
  824. /**
  825. * Converts viewport coordinates to the PDF location. For examples, useful
  826. * for converting canvas pixel location into PDF one.
  827. * @param x {number} X coordinate.
  828. * @param y {number} Y coordinate.
  829. * @returns {Object} Object that contains 'x' and 'y' properties of the
  830. * point in the PDF coordinate space.
  831. * @see {@link convertToViewportPoint}
  832. */
  833. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  834. return Util.applyInverseTransform([x, y], this.transform);
  835. }
  836. };
  837. return PageViewport;
  838. })();
  839. var PDFStringTranslateTable = [
  840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  841. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  842. 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,
  843. 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,
  844. 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,
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  846. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  847. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  848. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  849. ];
  850. function stringToPDFString(str) {
  851. var i, n = str.length, strBuf = [];
  852. if (str[0] === '\xFE' && str[1] === '\xFF') {
  853. // UTF16BE BOM
  854. for (i = 2; i < n; i += 2) {
  855. strBuf.push(String.fromCharCode(
  856. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  857. }
  858. } else {
  859. for (i = 0; i < n; ++i) {
  860. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  861. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  862. }
  863. }
  864. return strBuf.join('');
  865. }
  866. function stringToUTF8String(str) {
  867. return decodeURIComponent(escape(str));
  868. }
  869. function isEmptyObj(obj) {
  870. for (var key in obj) {
  871. return false;
  872. }
  873. return true;
  874. }
  875. function isBool(v) {
  876. return typeof v === 'boolean';
  877. }
  878. function isInt(v) {
  879. return typeof v === 'number' && ((v | 0) === v);
  880. }
  881. function isNum(v) {
  882. return typeof v === 'number';
  883. }
  884. function isString(v) {
  885. return typeof v === 'string';
  886. }
  887. function isNull(v) {
  888. return v === null;
  889. }
  890. function isName(v) {
  891. return v instanceof Name;
  892. }
  893. function isCmd(v, cmd) {
  894. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  895. }
  896. function isDict(v, type) {
  897. if (!(v instanceof Dict)) {
  898. return false;
  899. }
  900. if (!type) {
  901. return true;
  902. }
  903. var dictType = v.get('Type');
  904. return isName(dictType) && dictType.name === type;
  905. }
  906. function isArray(v) {
  907. return v instanceof Array;
  908. }
  909. function isStream(v) {
  910. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  911. }
  912. function isArrayBuffer(v) {
  913. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  914. }
  915. function isRef(v) {
  916. return v instanceof Ref;
  917. }
  918. /**
  919. * Promise Capability object.
  920. *
  921. * @typedef {Object} PromiseCapability
  922. * @property {Promise} promise - A promise object.
  923. * @property {function} resolve - Fullfills the promise.
  924. * @property {function} reject - Rejects the promise.
  925. */
  926. /**
  927. * Creates a promise capability object.
  928. * @alias PDFJS.createPromiseCapability
  929. *
  930. * @return {PromiseCapability} A capability object contains:
  931. * - a Promise, resolve and reject methods.
  932. */
  933. function createPromiseCapability() {
  934. var capability = {};
  935. capability.promise = new Promise(function (resolve, reject) {
  936. capability.resolve = resolve;
  937. capability.reject = reject;
  938. });
  939. return capability;
  940. }
  941. PDFJS.createPromiseCapability = createPromiseCapability;
  942. /**
  943. * Polyfill for Promises:
  944. * The following promise implementation tries to generally implement the
  945. * Promise/A+ spec. Some notable differences from other promise libaries are:
  946. * - There currently isn't a seperate deferred and promise object.
  947. * - Unhandled rejections eventually show an error if they aren't handled.
  948. *
  949. * Based off of the work in:
  950. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  951. */
  952. (function PromiseClosure() {
  953. if (globalScope.Promise) {
  954. // Promises existing in the DOM/Worker, checking presence of all/resolve
  955. if (typeof globalScope.Promise.all !== 'function') {
  956. globalScope.Promise.all = function (iterable) {
  957. var count = 0, results = [], resolve, reject;
  958. var promise = new globalScope.Promise(function (resolve_, reject_) {
  959. resolve = resolve_;
  960. reject = reject_;
  961. });
  962. iterable.forEach(function (p, i) {
  963. count++;
  964. p.then(function (result) {
  965. results[i] = result;
  966. count--;
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. }, reject);
  971. });
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. return promise;
  976. };
  977. }
  978. if (typeof globalScope.Promise.resolve !== 'function') {
  979. globalScope.Promise.resolve = function (value) {
  980. return new globalScope.Promise(function (resolve) { resolve(value); });
  981. };
  982. }
  983. if (typeof globalScope.Promise.reject !== 'function') {
  984. globalScope.Promise.reject = function (reason) {
  985. return new globalScope.Promise(function (resolve, reject) {
  986. reject(reason);
  987. });
  988. };
  989. }
  990. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  991. globalScope.Promise.prototype.catch = function (onReject) {
  992. return globalScope.Promise.prototype.then(undefined, onReject);
  993. };
  994. }
  995. return;
  996. }
  997. var STATUS_PENDING = 0;
  998. var STATUS_RESOLVED = 1;
  999. var STATUS_REJECTED = 2;
  1000. // In an attempt to avoid silent exceptions, unhandled rejections are
  1001. // tracked and if they aren't handled in a certain amount of time an
  1002. // error is logged.
  1003. var REJECTION_TIMEOUT = 500;
  1004. var HandlerManager = {
  1005. handlers: [],
  1006. running: false,
  1007. unhandledRejections: [],
  1008. pendingRejectionCheck: false,
  1009. scheduleHandlers: function scheduleHandlers(promise) {
  1010. if (promise._status === STATUS_PENDING) {
  1011. return;
  1012. }
  1013. this.handlers = this.handlers.concat(promise._handlers);
  1014. promise._handlers = [];
  1015. if (this.running) {
  1016. return;
  1017. }
  1018. this.running = true;
  1019. setTimeout(this.runHandlers.bind(this), 0);
  1020. },
  1021. runHandlers: function runHandlers() {
  1022. var RUN_TIMEOUT = 1; // ms
  1023. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1024. while (this.handlers.length > 0) {
  1025. var handler = this.handlers.shift();
  1026. var nextStatus = handler.thisPromise._status;
  1027. var nextValue = handler.thisPromise._value;
  1028. try {
  1029. if (nextStatus === STATUS_RESOLVED) {
  1030. if (typeof handler.onResolve === 'function') {
  1031. nextValue = handler.onResolve(nextValue);
  1032. }
  1033. } else if (typeof handler.onReject === 'function') {
  1034. nextValue = handler.onReject(nextValue);
  1035. nextStatus = STATUS_RESOLVED;
  1036. if (handler.thisPromise._unhandledRejection) {
  1037. this.removeUnhandeledRejection(handler.thisPromise);
  1038. }
  1039. }
  1040. } catch (ex) {
  1041. nextStatus = STATUS_REJECTED;
  1042. nextValue = ex;
  1043. }
  1044. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1045. if (Date.now() >= timeoutAt) {
  1046. break;
  1047. }
  1048. }
  1049. if (this.handlers.length > 0) {
  1050. setTimeout(this.runHandlers.bind(this), 0);
  1051. return;
  1052. }
  1053. this.running = false;
  1054. },
  1055. addUnhandledRejection: function addUnhandledRejection(promise) {
  1056. this.unhandledRejections.push({
  1057. promise: promise,
  1058. time: Date.now()
  1059. });
  1060. this.scheduleRejectionCheck();
  1061. },
  1062. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1063. promise._unhandledRejection = false;
  1064. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1065. if (this.unhandledRejections[i].promise === promise) {
  1066. this.unhandledRejections.splice(i);
  1067. i--;
  1068. }
  1069. }
  1070. },
  1071. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1072. if (this.pendingRejectionCheck) {
  1073. return;
  1074. }
  1075. this.pendingRejectionCheck = true;
  1076. setTimeout(function rejectionCheck() {
  1077. this.pendingRejectionCheck = false;
  1078. var now = Date.now();
  1079. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1080. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1081. var unhandled = this.unhandledRejections[i].promise._value;
  1082. var msg = 'Unhandled rejection: ' + unhandled;
  1083. if (unhandled.stack) {
  1084. msg += '\n' + unhandled.stack;
  1085. }
  1086. warn(msg);
  1087. this.unhandledRejections.splice(i);
  1088. i--;
  1089. }
  1090. }
  1091. if (this.unhandledRejections.length) {
  1092. this.scheduleRejectionCheck();
  1093. }
  1094. }.bind(this), REJECTION_TIMEOUT);
  1095. }
  1096. };
  1097. function Promise(resolver) {
  1098. this._status = STATUS_PENDING;
  1099. this._handlers = [];
  1100. try {
  1101. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1102. } catch (e) {
  1103. this._reject(e);
  1104. }
  1105. }
  1106. /**
  1107. * Builds a promise that is resolved when all the passed in promises are
  1108. * resolved.
  1109. * @param {array} array of data and/or promises to wait for.
  1110. * @return {Promise} New dependant promise.
  1111. */
  1112. Promise.all = function Promise_all(promises) {
  1113. var resolveAll, rejectAll;
  1114. var deferred = new Promise(function (resolve, reject) {
  1115. resolveAll = resolve;
  1116. rejectAll = reject;
  1117. });
  1118. var unresolved = promises.length;
  1119. var results = [];
  1120. if (unresolved === 0) {
  1121. resolveAll(results);
  1122. return deferred;
  1123. }
  1124. function reject(reason) {
  1125. if (deferred._status === STATUS_REJECTED) {
  1126. return;
  1127. }
  1128. results = [];
  1129. rejectAll(reason);
  1130. }
  1131. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1132. var promise = promises[i];
  1133. var resolve = (function(i) {
  1134. return function(value) {
  1135. if (deferred._status === STATUS_REJECTED) {
  1136. return;
  1137. }
  1138. results[i] = value;
  1139. unresolved--;
  1140. if (unresolved === 0) {
  1141. resolveAll(results);
  1142. }
  1143. };
  1144. })(i);
  1145. if (Promise.isPromise(promise)) {
  1146. promise.then(resolve, reject);
  1147. } else {
  1148. resolve(promise);
  1149. }
  1150. }
  1151. return deferred;
  1152. };
  1153. /**
  1154. * Checks if the value is likely a promise (has a 'then' function).
  1155. * @return {boolean} true if value is thenable
  1156. */
  1157. Promise.isPromise = function Promise_isPromise(value) {
  1158. return value && typeof value.then === 'function';
  1159. };
  1160. /**
  1161. * Creates resolved promise
  1162. * @param value resolve value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.resolve = function Promise_resolve(value) {
  1166. return new Promise(function (resolve) { resolve(value); });
  1167. };
  1168. /**
  1169. * Creates rejected promise
  1170. * @param reason rejection value
  1171. * @returns {Promise}
  1172. */
  1173. Promise.reject = function Promise_reject(reason) {
  1174. return new Promise(function (resolve, reject) { reject(reason); });
  1175. };
  1176. Promise.prototype = {
  1177. _status: null,
  1178. _value: null,
  1179. _handlers: null,
  1180. _unhandledRejection: null,
  1181. _updateStatus: function Promise__updateStatus(status, value) {
  1182. if (this._status === STATUS_RESOLVED ||
  1183. this._status === STATUS_REJECTED) {
  1184. return;
  1185. }
  1186. if (status === STATUS_RESOLVED &&
  1187. Promise.isPromise(value)) {
  1188. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1189. this._updateStatus.bind(this, STATUS_REJECTED));
  1190. return;
  1191. }
  1192. this._status = status;
  1193. this._value = value;
  1194. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1195. this._unhandledRejection = true;
  1196. HandlerManager.addUnhandledRejection(this);
  1197. }
  1198. HandlerManager.scheduleHandlers(this);
  1199. },
  1200. _resolve: function Promise_resolve(value) {
  1201. this._updateStatus(STATUS_RESOLVED, value);
  1202. },
  1203. _reject: function Promise_reject(reason) {
  1204. this._updateStatus(STATUS_REJECTED, reason);
  1205. },
  1206. then: function Promise_then(onResolve, onReject) {
  1207. var nextPromise = new Promise(function (resolve, reject) {
  1208. this.resolve = resolve;
  1209. this.reject = reject;
  1210. });
  1211. this._handlers.push({
  1212. thisPromise: this,
  1213. onResolve: onResolve,
  1214. onReject: onReject,
  1215. nextPromise: nextPromise
  1216. });
  1217. HandlerManager.scheduleHandlers(this);
  1218. return nextPromise;
  1219. },
  1220. catch: function Promise_catch(onReject) {
  1221. return this.then(undefined, onReject);
  1222. }
  1223. };
  1224. globalScope.Promise = Promise;
  1225. })();
  1226. var StatTimer = (function StatTimerClosure() {
  1227. function rpad(str, pad, length) {
  1228. while (str.length < length) {
  1229. str += pad;
  1230. }
  1231. return str;
  1232. }
  1233. function StatTimer() {
  1234. this.started = {};
  1235. this.times = [];
  1236. this.enabled = true;
  1237. }
  1238. StatTimer.prototype = {
  1239. time: function StatTimer_time(name) {
  1240. if (!this.enabled) {
  1241. return;
  1242. }
  1243. if (name in this.started) {
  1244. warn('Timer is already running for ' + name);
  1245. }
  1246. this.started[name] = Date.now();
  1247. },
  1248. timeEnd: function StatTimer_timeEnd(name) {
  1249. if (!this.enabled) {
  1250. return;
  1251. }
  1252. if (!(name in this.started)) {
  1253. warn('Timer has not been started for ' + name);
  1254. }
  1255. this.times.push({
  1256. 'name': name,
  1257. 'start': this.started[name],
  1258. 'end': Date.now()
  1259. });
  1260. // Remove timer from started so it can be called again.
  1261. delete this.started[name];
  1262. },
  1263. toString: function StatTimer_toString() {
  1264. var i, ii;
  1265. var times = this.times;
  1266. var out = '';
  1267. // Find the longest name for padding purposes.
  1268. var longest = 0;
  1269. for (i = 0, ii = times.length; i < ii; ++i) {
  1270. var name = times[i]['name'];
  1271. if (name.length > longest) {
  1272. longest = name.length;
  1273. }
  1274. }
  1275. for (i = 0, ii = times.length; i < ii; ++i) {
  1276. var span = times[i];
  1277. var duration = span.end - span.start;
  1278. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1279. }
  1280. return out;
  1281. }
  1282. };
  1283. return StatTimer;
  1284. })();
  1285. PDFJS.createBlob = function createBlob(data, contentType) {
  1286. if (typeof Blob !== 'undefined') {
  1287. return new Blob([data], { type: contentType });
  1288. }
  1289. // Blob builder is deprecated in FF14 and removed in FF18.
  1290. var bb = new MozBlobBuilder();
  1291. bb.append(data);
  1292. return bb.getBlob(contentType);
  1293. };
  1294. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1295. // Blob/createObjectURL is not available, falling back to data schema.
  1296. var digits =
  1297. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1298. return function createObjectURL(data, contentType) {
  1299. if (!PDFJS.disableCreateObjectURL &&
  1300. typeof URL !== 'undefined' && URL.createObjectURL) {
  1301. var blob = PDFJS.createBlob(data, contentType);
  1302. return URL.createObjectURL(blob);
  1303. }
  1304. var buffer = 'data:' + contentType + ';base64,';
  1305. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1306. var b1 = data[i] & 0xFF;
  1307. var b2 = data[i + 1] & 0xFF;
  1308. var b3 = data[i + 2] & 0xFF;
  1309. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1310. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1311. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1312. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1313. }
  1314. return buffer;
  1315. };
  1316. })();
  1317. function MessageHandler(name, comObj) {
  1318. this.name = name;
  1319. this.comObj = comObj;
  1320. this.callbackIndex = 1;
  1321. this.postMessageTransfers = true;
  1322. var callbacksCapabilities = this.callbacksCapabilities = {};
  1323. var ah = this.actionHandler = {};
  1324. ah['console_log'] = [function ahConsoleLog(data) {
  1325. console.log.apply(console, data);
  1326. }];
  1327. ah['console_error'] = [function ahConsoleError(data) {
  1328. console.error.apply(console, data);
  1329. }];
  1330. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1331. UnsupportedManager.notify(data);
  1332. }];
  1333. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1334. var data = event.data;
  1335. if (data.isReply) {
  1336. var callbackId = data.callbackId;
  1337. if (data.callbackId in callbacksCapabilities) {
  1338. var callback = callbacksCapabilities[callbackId];
  1339. delete callbacksCapabilities[callbackId];
  1340. if ('error' in data) {
  1341. callback.reject(data.error);
  1342. } else {
  1343. callback.resolve(data.data);
  1344. }
  1345. } else {
  1346. error('Cannot resolve callback ' + callbackId);
  1347. }
  1348. } else if (data.action in ah) {
  1349. var action = ah[data.action];
  1350. if (data.callbackId) {
  1351. Promise.resolve().then(function () {
  1352. return action[0].call(action[1], data.data);
  1353. }).then(function (result) {
  1354. comObj.postMessage({
  1355. isReply: true,
  1356. callbackId: data.callbackId,
  1357. data: result
  1358. });
  1359. }, function (reason) {
  1360. comObj.postMessage({
  1361. isReply: true,
  1362. callbackId: data.callbackId,
  1363. error: reason
  1364. });
  1365. });
  1366. } else {
  1367. action[0].call(action[1], data.data);
  1368. }
  1369. } else {
  1370. error('Unknown action from worker: ' + data.action);
  1371. }
  1372. };
  1373. }
  1374. MessageHandler.prototype = {
  1375. on: function messageHandlerOn(actionName, handler, scope) {
  1376. var ah = this.actionHandler;
  1377. if (ah[actionName]) {
  1378. error('There is already an actionName called "' + actionName + '"');
  1379. }
  1380. ah[actionName] = [handler, scope];
  1381. },
  1382. /**
  1383. * Sends a message to the comObj to invoke the action with the supplied data.
  1384. * @param {String} actionName Action to call.
  1385. * @param {JSON} data JSON data to send.
  1386. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1387. */
  1388. send: function messageHandlerSend(actionName, data, transfers) {
  1389. var message = {
  1390. action: actionName,
  1391. data: data
  1392. };
  1393. this.postMessage(message, transfers);
  1394. },
  1395. /**
  1396. * Sends a message to the comObj to invoke the action with the supplied data.
  1397. * Expects that other side will callback with the response.
  1398. * @param {String} actionName Action to call.
  1399. * @param {JSON} data JSON data to send.
  1400. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1401. * @returns {Promise} Promise to be resolved with response data.
  1402. */
  1403. sendWithPromise:
  1404. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1405. var callbackId = this.callbackIndex++;
  1406. var message = {
  1407. action: actionName,
  1408. data: data,
  1409. callbackId: callbackId
  1410. };
  1411. var capability = createPromiseCapability();
  1412. this.callbacksCapabilities[callbackId] = capability;
  1413. try {
  1414. this.postMessage(message, transfers);
  1415. } catch (e) {
  1416. capability.reject(e);
  1417. }
  1418. return capability.promise;
  1419. },
  1420. /**
  1421. * Sends raw message to the comObj.
  1422. * @private
  1423. * @param message {Object} Raw message.
  1424. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1425. */
  1426. postMessage: function (message, transfers) {
  1427. if (transfers && this.postMessageTransfers) {
  1428. this.comObj.postMessage(message, transfers);
  1429. } else {
  1430. this.comObj.postMessage(message);
  1431. }
  1432. }
  1433. };
  1434. function loadJpegStream(id, imageUrl, objs) {
  1435. var img = new Image();
  1436. img.onload = (function loadJpegStream_onloadClosure() {
  1437. objs.resolve(id, img);
  1438. });
  1439. img.onerror = (function loadJpegStream_onerrorClosure() {
  1440. objs.resolve(id, null);
  1441. warn('Error during JPEG image loading');
  1442. });
  1443. img.src = imageUrl;
  1444. }
  1445. var NetworkManager = (function NetworkManagerClosure() {
  1446. var OK_RESPONSE = 200;
  1447. var PARTIAL_CONTENT_RESPONSE = 206;
  1448. function NetworkManager(url, args) {
  1449. this.url = url;
  1450. args = args || {};
  1451. this.isHttp = /^https?:/i.test(url);
  1452. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1453. this.withCredentials = args.withCredentials || false;
  1454. this.getXhr = args.getXhr ||
  1455. function NetworkManager_getXhr() {
  1456. return new XMLHttpRequest();
  1457. };
  1458. this.currXhrId = 0;
  1459. this.pendingRequests = {};
  1460. this.loadedRequests = {};
  1461. }
  1462. function getArrayBuffer(xhr) {
  1463. var data = xhr.response;
  1464. if (typeof data !== 'string') {
  1465. return data;
  1466. }
  1467. var length = data.length;
  1468. var array = new Uint8Array(length);
  1469. for (var i = 0; i < length; i++) {
  1470. array[i] = data.charCodeAt(i) & 0xFF;
  1471. }
  1472. return array.buffer;
  1473. }
  1474. NetworkManager.prototype = {
  1475. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1476. var args = {
  1477. begin: begin,
  1478. end: end
  1479. };
  1480. for (var prop in listeners) {
  1481. args[prop] = listeners[prop];
  1482. }
  1483. return this.request(args);
  1484. },
  1485. requestFull: function NetworkManager_requestFull(listeners) {
  1486. return this.request(listeners);
  1487. },
  1488. request: function NetworkManager_request(args) {
  1489. var xhr = this.getXhr();
  1490. var xhrId = this.currXhrId++;
  1491. var pendingRequest = this.pendingRequests[xhrId] = {
  1492. xhr: xhr
  1493. };
  1494. xhr.open('GET', this.url);
  1495. xhr.withCredentials = this.withCredentials;
  1496. for (var property in this.httpHeaders) {
  1497. var value = this.httpHeaders[property];
  1498. if (typeof value === 'undefined') {
  1499. continue;
  1500. }
  1501. xhr.setRequestHeader(property, value);
  1502. }
  1503. if (this.isHttp && 'begin' in args && 'end' in args) {
  1504. var rangeStr = args.begin + '-' + (args.end - 1);
  1505. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1506. pendingRequest.expectedStatus = 206;
  1507. } else {
  1508. pendingRequest.expectedStatus = 200;
  1509. }
  1510. if (args.onProgressiveData) {
  1511. // Some legacy browsers might throw an exception.
  1512. try {
  1513. xhr.responseType = 'moz-chunked-arraybuffer';
  1514. } catch(e) {}
  1515. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1516. pendingRequest.onProgressiveData = args.onProgressiveData;
  1517. pendingRequest.mozChunked = true;
  1518. } else {
  1519. xhr.responseType = 'arraybuffer';
  1520. }
  1521. } else {
  1522. xhr.responseType = 'arraybuffer';
  1523. }
  1524. if (args.onError) {
  1525. xhr.onerror = function(evt) {
  1526. args.onError(xhr.status);
  1527. };
  1528. }
  1529. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1530. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1531. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1532. pendingRequest.onDone = args.onDone;
  1533. pendingRequest.onError = args.onError;
  1534. pendingRequest.onProgress = args.onProgress;
  1535. xhr.send(null);
  1536. return xhrId;
  1537. },
  1538. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1539. var pendingRequest = this.pendingRequests[xhrId];
  1540. if (!pendingRequest) {
  1541. // Maybe abortRequest was called...
  1542. return;
  1543. }
  1544. if (pendingRequest.mozChunked) {
  1545. var chunk = getArrayBuffer(pendingRequest.xhr);
  1546. pendingRequest.onProgressiveData(chunk);
  1547. }
  1548. var onProgress = pendingRequest.onProgress;
  1549. if (onProgress) {
  1550. onProgress(evt);
  1551. }
  1552. },
  1553. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1554. var pendingRequest = this.pendingRequests[xhrId];
  1555. if (!pendingRequest) {
  1556. // Maybe abortRequest was called...
  1557. return;
  1558. }
  1559. var xhr = pendingRequest.xhr;
  1560. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1561. pendingRequest.onHeadersReceived();
  1562. delete pendingRequest.onHeadersReceived;
  1563. }
  1564. if (xhr.readyState !== 4) {
  1565. return;
  1566. }
  1567. if (!(xhrId in this.pendingRequests)) {
  1568. // The XHR request might have been aborted in onHeadersReceived()
  1569. // callback, in which case we should abort request
  1570. return;
  1571. }
  1572. delete this.pendingRequests[xhrId];
  1573. // success status == 0 can be on ftp, file and other protocols
  1574. if (xhr.status === 0 && this.isHttp) {
  1575. if (pendingRequest.onError) {
  1576. pendingRequest.onError(xhr.status);
  1577. }
  1578. return;
  1579. }
  1580. var xhrStatus = xhr.status || OK_RESPONSE;
  1581. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1582. // "A server MAY ignore the Range header". This means it's possible to
  1583. // get a 200 rather than a 206 response from a range request.
  1584. var ok_response_on_range_request =
  1585. xhrStatus === OK_RESPONSE &&
  1586. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1587. if (!ok_response_on_range_request &&
  1588. xhrStatus !== pendingRequest.expectedStatus) {
  1589. if (pendingRequest.onError) {
  1590. pendingRequest.onError(xhr.status);
  1591. }
  1592. return;
  1593. }
  1594. this.loadedRequests[xhrId] = true;
  1595. var chunk = getArrayBuffer(xhr);
  1596. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1597. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1598. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1599. var begin = parseInt(matches[1], 10);
  1600. pendingRequest.onDone({
  1601. begin: begin,
  1602. chunk: chunk
  1603. });
  1604. } else if (pendingRequest.onProgressiveData) {
  1605. pendingRequest.onDone(null);
  1606. } else {
  1607. pendingRequest.onDone({
  1608. begin: 0,
  1609. chunk: chunk
  1610. });
  1611. }
  1612. },
  1613. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1614. for (var xhrId in this.pendingRequests) {
  1615. return true;
  1616. }
  1617. return false;
  1618. },
  1619. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1620. return this.pendingRequests[xhrId].xhr;
  1621. },
  1622. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1623. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1624. },
  1625. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1626. return xhrId in this.pendingRequests;
  1627. },
  1628. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1629. return xhrId in this.loadedRequests;
  1630. },
  1631. abortAllRequests: function NetworkManager_abortAllRequests() {
  1632. for (var xhrId in this.pendingRequests) {
  1633. this.abortRequest(xhrId | 0);
  1634. }
  1635. },
  1636. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1637. var xhr = this.pendingRequests[xhrId].xhr;
  1638. delete this.pendingRequests[xhrId];
  1639. xhr.abort();
  1640. }
  1641. };
  1642. return NetworkManager;
  1643. })();
  1644. var ChunkedStream = (function ChunkedStreamClosure() {
  1645. function ChunkedStream(length, chunkSize, manager) {
  1646. this.bytes = new Uint8Array(length);
  1647. this.start = 0;
  1648. this.pos = 0;
  1649. this.end = length;
  1650. this.chunkSize = chunkSize;
  1651. this.loadedChunks = [];
  1652. this.numChunksLoaded = 0;
  1653. this.numChunks = Math.ceil(length / chunkSize);
  1654. this.manager = manager;
  1655. this.progressiveDataLength = 0;
  1656. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1657. }
  1658. // required methods for a stream. if a particular stream does not
  1659. // implement these, an error should be thrown
  1660. ChunkedStream.prototype = {
  1661. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1662. var chunks = [];
  1663. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1664. if (!this.loadedChunks[chunk]) {
  1665. chunks.push(chunk);
  1666. }
  1667. }
  1668. return chunks;
  1669. },
  1670. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1671. return [this];
  1672. },
  1673. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1674. return this.numChunksLoaded === this.numChunks;
  1675. },
  1676. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1677. var end = begin + chunk.byteLength;
  1678. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1679. // Using this.length is inaccurate here since this.start can be moved
  1680. // See ChunkedStream.moveStart()
  1681. var length = this.bytes.length;
  1682. assert(end % this.chunkSize === 0 || end === length,
  1683. 'Bad end offset: ' + end);
  1684. this.bytes.set(new Uint8Array(chunk), begin);
  1685. var chunkSize = this.chunkSize;
  1686. var beginChunk = Math.floor(begin / chunkSize);
  1687. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1688. var curChunk;
  1689. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1690. if (!this.loadedChunks[curChunk]) {
  1691. this.loadedChunks[curChunk] = true;
  1692. ++this.numChunksLoaded;
  1693. }
  1694. }
  1695. },
  1696. onReceiveProgressiveData:
  1697. function ChunkedStream_onReceiveProgressiveData(data) {
  1698. var position = this.progressiveDataLength;
  1699. var beginChunk = Math.floor(position / this.chunkSize);
  1700. this.bytes.set(new Uint8Array(data), position);
  1701. position += data.byteLength;
  1702. this.progressiveDataLength = position;
  1703. var endChunk = position >= this.end ? this.numChunks :
  1704. Math.floor(position / this.chunkSize);
  1705. var curChunk;
  1706. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1707. if (!this.loadedChunks[curChunk]) {
  1708. this.loadedChunks[curChunk] = true;
  1709. ++this.numChunksLoaded;
  1710. }
  1711. }
  1712. },
  1713. ensureByte: function ChunkedStream_ensureByte(pos) {
  1714. var chunk = Math.floor(pos / this.chunkSize);
  1715. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1716. return;
  1717. }
  1718. if (!this.loadedChunks[chunk]) {
  1719. throw new MissingDataException(pos, pos + 1);
  1720. }
  1721. this.lastSuccessfulEnsureByteChunk = chunk;
  1722. },
  1723. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1724. if (begin >= end) {
  1725. return;
  1726. }
  1727. if (end <= this.progressiveDataLength) {
  1728. return;
  1729. }
  1730. var chunkSize = this.chunkSize;
  1731. var beginChunk = Math.floor(begin / chunkSize);
  1732. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1733. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1734. if (!this.loadedChunks[chunk]) {
  1735. throw new MissingDataException(begin, end);
  1736. }
  1737. }
  1738. },
  1739. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1740. var chunk, n;
  1741. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1742. if (!this.loadedChunks[chunk]) {
  1743. return chunk;
  1744. }
  1745. }
  1746. // Wrap around to beginning
  1747. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1748. if (!this.loadedChunks[chunk]) {
  1749. return chunk;
  1750. }
  1751. }
  1752. return null;
  1753. },
  1754. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1755. return !!this.loadedChunks[chunk];
  1756. },
  1757. get length() {
  1758. return this.end - this.start;
  1759. },
  1760. get isEmpty() {
  1761. return this.length === 0;
  1762. },
  1763. getByte: function ChunkedStream_getByte() {
  1764. var pos = this.pos;
  1765. if (pos >= this.end) {
  1766. return -1;
  1767. }
  1768. this.ensureByte(pos);
  1769. return this.bytes[this.pos++];
  1770. },
  1771. getUint16: function ChunkedStream_getUint16() {
  1772. var b0 = this.getByte();
  1773. var b1 = this.getByte();
  1774. return (b0 << 8) + b1;
  1775. },
  1776. getInt32: function ChunkedStream_getInt32() {
  1777. var b0 = this.getByte();
  1778. var b1 = this.getByte();
  1779. var b2 = this.getByte();
  1780. var b3 = this.getByte();
  1781. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1782. },
  1783. // returns subarray of original buffer
  1784. // should only be read
  1785. getBytes: function ChunkedStream_getBytes(length) {
  1786. var bytes = this.bytes;
  1787. var pos = this.pos;
  1788. var strEnd = this.end;
  1789. if (!length) {
  1790. this.ensureRange(pos, strEnd);
  1791. return bytes.subarray(pos, strEnd);
  1792. }
  1793. var end = pos + length;
  1794. if (end > strEnd) {
  1795. end = strEnd;
  1796. }
  1797. this.ensureRange(pos, end);
  1798. this.pos = end;
  1799. return bytes.subarray(pos, end);
  1800. },
  1801. peekByte: function ChunkedStream_peekByte() {
  1802. var peekedByte = this.getByte();
  1803. this.pos--;
  1804. return peekedByte;
  1805. },
  1806. peekBytes: function ChunkedStream_peekBytes(length) {
  1807. var bytes = this.getBytes(length);
  1808. this.pos -= bytes.length;
  1809. return bytes;
  1810. },
  1811. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1812. this.ensureRange(begin, end);
  1813. return this.bytes.subarray(begin, end);
  1814. },
  1815. skip: function ChunkedStream_skip(n) {
  1816. if (!n) {
  1817. n = 1;
  1818. }
  1819. this.pos += n;
  1820. },
  1821. reset: function ChunkedStream_reset() {
  1822. this.pos = this.start;
  1823. },
  1824. moveStart: function ChunkedStream_moveStart() {
  1825. this.start = this.pos;
  1826. },
  1827. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1828. this.ensureRange(start, start + length);
  1829. function ChunkedStreamSubstream() {}
  1830. ChunkedStreamSubstream.prototype = Object.create(this);
  1831. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1832. var chunkSize = this.chunkSize;
  1833. var beginChunk = Math.floor(this.start / chunkSize);
  1834. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1835. var missingChunks = [];
  1836. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1837. if (!this.loadedChunks[chunk]) {
  1838. missingChunks.push(chunk);
  1839. }
  1840. }
  1841. return missingChunks;
  1842. };
  1843. var subStream = new ChunkedStreamSubstream();
  1844. subStream.pos = subStream.start = start;
  1845. subStream.end = start + length || this.end;
  1846. subStream.dict = dict;
  1847. return subStream;
  1848. },
  1849. isStream: true
  1850. };
  1851. return ChunkedStream;
  1852. })();
  1853. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1854. function ChunkedStreamManager(length, chunkSize, url, args) {
  1855. this.stream = new ChunkedStream(length, chunkSize, this);
  1856. this.length = length;
  1857. this.chunkSize = chunkSize;
  1858. this.url = url;
  1859. this.disableAutoFetch = args.disableAutoFetch;
  1860. var msgHandler = this.msgHandler = args.msgHandler;
  1861. if (args.chunkedViewerLoading) {
  1862. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1863. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1864. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1865. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1866. };
  1867. } else {
  1868. var getXhr = function getXhr() {
  1869. return new XMLHttpRequest();
  1870. };
  1871. this.networkManager = new NetworkManager(this.url, {
  1872. getXhr: getXhr,
  1873. httpHeaders: args.httpHeaders,
  1874. withCredentials: args.withCredentials
  1875. });
  1876. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1877. this.networkManager.requestRange(begin, end, {
  1878. onDone: this.onReceiveData.bind(this),
  1879. onProgress: this.onProgress.bind(this)
  1880. });
  1881. };
  1882. }
  1883. this.currRequestId = 0;
  1884. this.chunksNeededByRequest = {};
  1885. this.requestsByChunk = {};
  1886. this.callbacksByRequest = {};
  1887. this.progressiveDataLength = 0;
  1888. this._loadedStreamCapability = createPromiseCapability();
  1889. if (args.initialData) {
  1890. this.onReceiveData({chunk: args.initialData});
  1891. }
  1892. }
  1893. ChunkedStreamManager.prototype = {
  1894. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1895. return this._loadedStreamCapability.promise;
  1896. },
  1897. // Get all the chunks that are not yet loaded and groups them into
  1898. // contiguous ranges to load in as few requests as possible
  1899. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1900. var missingChunks = this.stream.getMissingChunks();
  1901. this.requestChunks(missingChunks);
  1902. return this._loadedStreamCapability.promise;
  1903. },
  1904. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1905. callback) {
  1906. var requestId = this.currRequestId++;
  1907. var chunksNeeded;
  1908. var i, ii;
  1909. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1910. for (i = 0, ii = chunks.length; i < ii; i++) {
  1911. if (!this.stream.hasChunk(chunks[i])) {
  1912. chunksNeeded[chunks[i]] = true;
  1913. }
  1914. }
  1915. if (isEmptyObj(chunksNeeded)) {
  1916. if (callback) {
  1917. callback();
  1918. }
  1919. return;
  1920. }
  1921. this.callbacksByRequest[requestId] = callback;
  1922. var chunksToRequest = [];
  1923. for (var chunk in chunksNeeded) {
  1924. chunk = chunk | 0;
  1925. if (!(chunk in this.requestsByChunk)) {
  1926. this.requestsByChunk[chunk] = [];
  1927. chunksToRequest.push(chunk);
  1928. }
  1929. this.requestsByChunk[chunk].push(requestId);
  1930. }
  1931. if (!chunksToRequest.length) {
  1932. return;
  1933. }
  1934. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1935. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1936. var groupedChunk = groupedChunksToRequest[i];
  1937. var begin = groupedChunk.beginChunk * this.chunkSize;
  1938. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1939. this.sendRequest(begin, end);
  1940. }
  1941. },
  1942. getStream: function ChunkedStreamManager_getStream() {
  1943. return this.stream;
  1944. },
  1945. // Loads any chunks in the requested range that are not yet loaded
  1946. requestRange: function ChunkedStreamManager_requestRange(
  1947. begin, end, callback) {
  1948. end = Math.min(end, this.length);
  1949. var beginChunk = this.getBeginChunk(begin);
  1950. var endChunk = this.getEndChunk(end);
  1951. var chunks = [];
  1952. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1953. chunks.push(chunk);
  1954. }
  1955. this.requestChunks(chunks, callback);
  1956. },
  1957. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1958. callback) {
  1959. ranges = ranges || [];
  1960. var chunksToRequest = [];
  1961. for (var i = 0; i < ranges.length; i++) {
  1962. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1963. var endChunk = this.getEndChunk(ranges[i].end);
  1964. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1965. if (chunksToRequest.indexOf(chunk) < 0) {
  1966. chunksToRequest.push(chunk);
  1967. }
  1968. }
  1969. }
  1970. chunksToRequest.sort(function(a, b) { return a - b; });
  1971. this.requestChunks(chunksToRequest, callback);
  1972. },
  1973. // Groups a sorted array of chunks into as few continguous larger
  1974. // chunks as possible
  1975. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1976. var groupedChunks = [];
  1977. var beginChunk = -1;
  1978. var prevChunk = -1;
  1979. for (var i = 0; i < chunks.length; ++i) {
  1980. var chunk = chunks[i];
  1981. if (beginChunk < 0) {
  1982. beginChunk = chunk;
  1983. }
  1984. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1985. groupedChunks.push({ beginChunk: beginChunk,
  1986. endChunk: prevChunk + 1 });
  1987. beginChunk = chunk;
  1988. }
  1989. if (i + 1 === chunks.length) {
  1990. groupedChunks.push({ beginChunk: beginChunk,
  1991. endChunk: chunk + 1 });
  1992. }
  1993. prevChunk = chunk;
  1994. }
  1995. return groupedChunks;
  1996. },
  1997. onProgress: function ChunkedStreamManager_onProgress(args) {
  1998. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1999. args.loaded);
  2000. this.msgHandler.send('DocProgress', {
  2001. loaded: bytesLoaded,
  2002. total: this.length
  2003. });
  2004. },
  2005. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2006. var chunk = args.chunk;
  2007. var isProgressive = args.begin === undefined;
  2008. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2009. var end = begin + chunk.byteLength;
  2010. var beginChunk = Math.floor(begin / this.chunkSize);
  2011. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2012. Math.ceil(end / this.chunkSize);
  2013. if (isProgressive) {
  2014. this.stream.onReceiveProgressiveData(chunk);
  2015. this.progressiveDataLength = end;
  2016. } else {
  2017. this.stream.onReceiveData(begin, chunk);
  2018. }
  2019. if (this.stream.allChunksLoaded()) {
  2020. this._loadedStreamCapability.resolve(this.stream);
  2021. }
  2022. var loadedRequests = [];
  2023. var i, requestId;
  2024. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2025. // The server might return more chunks than requested
  2026. var requestIds = this.requestsByChunk[chunk] || [];
  2027. delete this.requestsByChunk[chunk];
  2028. for (i = 0; i < requestIds.length; ++i) {
  2029. requestId = requestIds[i];
  2030. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2031. if (chunk in chunksNeeded) {
  2032. delete chunksNeeded[chunk];
  2033. }
  2034. if (!isEmptyObj(chunksNeeded)) {
  2035. continue;
  2036. }
  2037. loadedRequests.push(requestId);
  2038. }
  2039. }
  2040. // If there are no pending requests, automatically fetch the next
  2041. // unfetched chunk of the PDF
  2042. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2043. var nextEmptyChunk;
  2044. if (this.stream.numChunksLoaded === 1) {
  2045. // This is a special optimization so that after fetching the first
  2046. // chunk, rather than fetching the second chunk, we fetch the last
  2047. // chunk.
  2048. var lastChunk = this.stream.numChunks - 1;
  2049. if (!this.stream.hasChunk(lastChunk)) {
  2050. nextEmptyChunk = lastChunk;
  2051. }
  2052. } else {
  2053. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2054. }
  2055. if (isInt(nextEmptyChunk)) {
  2056. this.requestChunks([nextEmptyChunk]);
  2057. }
  2058. }
  2059. for (i = 0; i < loadedRequests.length; ++i) {
  2060. requestId = loadedRequests[i];
  2061. var callback = this.callbacksByRequest[requestId];
  2062. delete this.callbacksByRequest[requestId];
  2063. if (callback) {
  2064. callback();
  2065. }
  2066. }
  2067. this.msgHandler.send('DocProgress', {
  2068. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2069. total: this.length
  2070. });
  2071. },
  2072. onError: function ChunkedStreamManager_onError(err) {
  2073. this._loadedStreamCapability.reject(err);
  2074. },
  2075. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2076. var chunk = Math.floor(begin / this.chunkSize);
  2077. return chunk;
  2078. },
  2079. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2080. if (end % this.chunkSize === 0) {
  2081. return end / this.chunkSize;
  2082. }
  2083. // 0 -> 0
  2084. // 1 -> 1
  2085. // 99 -> 1
  2086. // 100 -> 1
  2087. // 101 -> 2
  2088. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2089. return chunk;
  2090. }
  2091. };
  2092. return ChunkedStreamManager;
  2093. })();
  2094. // The maximum number of bytes fetched per range request
  2095. var RANGE_CHUNK_SIZE = 65536;
  2096. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2097. var BasePdfManager = (function BasePdfManagerClosure() {
  2098. function BasePdfManager() {
  2099. throw new Error('Cannot initialize BaseManagerManager');
  2100. }
  2101. BasePdfManager.prototype = {
  2102. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2103. throw new NotImplementedException();
  2104. },
  2105. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2106. return this.ensure(this.pdfDocument, prop, args);
  2107. },
  2108. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2109. return this.ensure(this.pdfDocument.xref, prop, args);
  2110. },
  2111. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2112. return this.ensure(this.pdfDocument.catalog, prop, args);
  2113. },
  2114. getPage: function BasePdfManager_pagePage(pageIndex) {
  2115. return this.pdfDocument.getPage(pageIndex);
  2116. },
  2117. cleanup: function BasePdfManager_cleanup() {
  2118. return this.pdfDocument.cleanup();
  2119. },
  2120. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2121. return new NotImplementedException();
  2122. },
  2123. requestRange: function BasePdfManager_ensure(begin, end) {
  2124. return new NotImplementedException();
  2125. },
  2126. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2127. return new NotImplementedException();
  2128. },
  2129. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2130. return new NotImplementedException();
  2131. },
  2132. updatePassword: function BasePdfManager_updatePassword(password) {
  2133. this.pdfDocument.xref.password = this.password = password;
  2134. if (this._passwordChangedCapability) {
  2135. this._passwordChangedCapability.resolve();
  2136. }
  2137. },
  2138. passwordChanged: function BasePdfManager_passwordChanged() {
  2139. this._passwordChangedCapability = createPromiseCapability();
  2140. return this._passwordChangedCapability.promise;
  2141. },
  2142. terminate: function BasePdfManager_terminate() {
  2143. return new NotImplementedException();
  2144. }
  2145. };
  2146. return BasePdfManager;
  2147. })();
  2148. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2149. function LocalPdfManager(data, password) {
  2150. var stream = new Stream(data);
  2151. this.pdfDocument = new PDFDocument(this, stream, password);
  2152. this._loadedStreamCapability = createPromiseCapability();
  2153. this._loadedStreamCapability.resolve(stream);
  2154. }
  2155. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2156. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2157. LocalPdfManager.prototype.ensure =
  2158. function LocalPdfManager_ensure(obj, prop, args) {
  2159. return new Promise(function (resolve, reject) {
  2160. try {
  2161. var value = obj[prop];
  2162. var result;
  2163. if (typeof value === 'function') {
  2164. result = value.apply(obj, args);
  2165. } else {
  2166. result = value;
  2167. }
  2168. resolve(result);
  2169. } catch (e) {
  2170. reject(e);
  2171. }
  2172. });
  2173. };
  2174. LocalPdfManager.prototype.requestRange =
  2175. function LocalPdfManager_requestRange(begin, end) {
  2176. return Promise.resolve();
  2177. };
  2178. LocalPdfManager.prototype.requestLoadedStream =
  2179. function LocalPdfManager_requestLoadedStream() {
  2180. };
  2181. LocalPdfManager.prototype.onLoadedStream =
  2182. function LocalPdfManager_getLoadedStream() {
  2183. return this._loadedStreamCapability.promise;
  2184. };
  2185. LocalPdfManager.prototype.terminate =
  2186. function LocalPdfManager_terminate() {
  2187. return;
  2188. };
  2189. return LocalPdfManager;
  2190. })();
  2191. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2192. function NetworkPdfManager(args, msgHandler) {
  2193. this.msgHandler = msgHandler;
  2194. var params = {
  2195. msgHandler: msgHandler,
  2196. httpHeaders: args.httpHeaders,
  2197. withCredentials: args.withCredentials,
  2198. chunkedViewerLoading: args.chunkedViewerLoading,
  2199. disableAutoFetch: args.disableAutoFetch,
  2200. initialData: args.initialData
  2201. };
  2202. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2203. args.url, params);
  2204. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2205. args.password);
  2206. }
  2207. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2208. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2209. NetworkPdfManager.prototype.ensure =
  2210. function NetworkPdfManager_ensure(obj, prop, args) {
  2211. var pdfManager = this;
  2212. return new Promise(function (resolve, reject) {
  2213. function ensureHelper() {
  2214. try {
  2215. var result;
  2216. var value = obj[prop];
  2217. if (typeof value === 'function') {
  2218. result = value.apply(obj, args);
  2219. } else {
  2220. result = value;
  2221. }
  2222. resolve(result);
  2223. } catch(e) {
  2224. if (!(e instanceof MissingDataException)) {
  2225. reject(e);
  2226. return;
  2227. }
  2228. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2229. }
  2230. }
  2231. ensureHelper();
  2232. });
  2233. };
  2234. NetworkPdfManager.prototype.requestRange =
  2235. function NetworkPdfManager_requestRange(begin, end) {
  2236. return new Promise(function (resolve) {
  2237. this.streamManager.requestRange(begin, end, function() {
  2238. resolve();
  2239. });
  2240. }.bind(this));
  2241. };
  2242. NetworkPdfManager.prototype.requestLoadedStream =
  2243. function NetworkPdfManager_requestLoadedStream() {
  2244. this.streamManager.requestAllChunks();
  2245. };
  2246. NetworkPdfManager.prototype.sendProgressiveData =
  2247. function NetworkPdfManager_sendProgressiveData(chunk) {
  2248. this.streamManager.onReceiveData({ chunk: chunk });
  2249. };
  2250. NetworkPdfManager.prototype.onLoadedStream =
  2251. function NetworkPdfManager_getLoadedStream() {
  2252. return this.streamManager.onLoadedStream();
  2253. };
  2254. NetworkPdfManager.prototype.terminate =
  2255. function NetworkPdfManager_terminate() {
  2256. this.streamManager.networkManager.abortAllRequests();
  2257. };
  2258. return NetworkPdfManager;
  2259. })();
  2260. var Page = (function PageClosure() {
  2261. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2262. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2263. this.pdfManager = pdfManager;
  2264. this.pageIndex = pageIndex;
  2265. this.pageDict = pageDict;
  2266. this.xref = xref;
  2267. this.ref = ref;
  2268. this.fontCache = fontCache;
  2269. this.idCounters = {
  2270. obj: 0
  2271. };
  2272. this.resourcesPromise = null;
  2273. }
  2274. Page.prototype = {
  2275. getPageProp: function Page_getPageProp(key) {
  2276. return this.pageDict.get(key);
  2277. },
  2278. getInheritedPageProp: function Page_inheritPageProp(key) {
  2279. var dict = this.pageDict;
  2280. var value = dict.get(key);
  2281. while (value === undefined) {
  2282. dict = dict.get('Parent');
  2283. if (!dict) {
  2284. break;
  2285. }
  2286. value = dict.get(key);
  2287. }
  2288. return value;
  2289. },
  2290. get content() {
  2291. return this.getPageProp('Contents');
  2292. },
  2293. get resources() {
  2294. var value = this.getInheritedPageProp('Resources');
  2295. // For robustness: The spec states that a \Resources entry has to be
  2296. // present, but can be empty. Some document omit it still. In this case
  2297. // return an empty dictionary:
  2298. if (value === undefined) {
  2299. value = Dict.empty;
  2300. }
  2301. return shadow(this, 'resources', value);
  2302. },
  2303. get mediaBox() {
  2304. var obj = this.getInheritedPageProp('MediaBox');
  2305. // Reset invalid media box to letter size.
  2306. if (!isArray(obj) || obj.length !== 4) {
  2307. obj = LETTER_SIZE_MEDIABOX;
  2308. }
  2309. return shadow(this, 'mediaBox', obj);
  2310. },
  2311. get view() {
  2312. var mediaBox = this.mediaBox;
  2313. var cropBox = this.getInheritedPageProp('CropBox');
  2314. if (!isArray(cropBox) || cropBox.length !== 4) {
  2315. return shadow(this, 'view', mediaBox);
  2316. }
  2317. // From the spec, 6th ed., p.963:
  2318. // "The crop, bleed, trim, and art boxes should not ordinarily
  2319. // extend beyond the boundaries of the media box. If they do, they are
  2320. // effectively reduced to their intersection with the media box."
  2321. cropBox = Util.intersect(cropBox, mediaBox);
  2322. if (!cropBox) {
  2323. return shadow(this, 'view', mediaBox);
  2324. }
  2325. return shadow(this, 'view', cropBox);
  2326. },
  2327. get annotationRefs() {
  2328. return shadow(this, 'annotationRefs',
  2329. this.getInheritedPageProp('Annots'));
  2330. },
  2331. get rotate() {
  2332. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2333. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2334. if (rotate % 90 !== 0) {
  2335. rotate = 0;
  2336. } else if (rotate >= 360) {
  2337. rotate = rotate % 360;
  2338. } else if (rotate < 0) {
  2339. // The spec doesn't cover negatives, assume its counterclockwise
  2340. // rotation. The following is the other implementation of modulo.
  2341. rotate = ((rotate % 360) + 360) % 360;
  2342. }
  2343. return shadow(this, 'rotate', rotate);
  2344. },
  2345. getContentStream: function Page_getContentStream() {
  2346. var content = this.content;
  2347. var stream;
  2348. if (isArray(content)) {
  2349. // fetching items
  2350. var xref = this.xref;
  2351. var i, n = content.length;
  2352. var streams = [];
  2353. for (i = 0; i < n; ++i) {
  2354. streams.push(xref.fetchIfRef(content[i]));
  2355. }
  2356. stream = new StreamsSequenceStream(streams);
  2357. } else if (isStream(content)) {
  2358. stream = content;
  2359. } else {
  2360. // replacing non-existent page content with empty one
  2361. stream = new NullStream();
  2362. }
  2363. return stream;
  2364. },
  2365. loadResources: function Page_loadResources(keys) {
  2366. if (!this.resourcesPromise) {
  2367. // TODO: add async getInheritedPageProp and remove this.
  2368. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2369. }
  2370. return this.resourcesPromise.then(function resourceSuccess() {
  2371. var objectLoader = new ObjectLoader(this.resources.map,
  2372. keys,
  2373. this.xref);
  2374. return objectLoader.load();
  2375. }.bind(this));
  2376. },
  2377. getOperatorList: function Page_getOperatorList(handler, intent) {
  2378. var self = this;
  2379. var pdfManager = this.pdfManager;
  2380. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2381. []);
  2382. var resourcesPromise = this.loadResources([
  2383. 'ExtGState',
  2384. 'ColorSpace',
  2385. 'Pattern',
  2386. 'Shading',
  2387. 'XObject',
  2388. 'Font'
  2389. // ProcSet
  2390. // Properties
  2391. ]);
  2392. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2393. handler, this.pageIndex,
  2394. 'p' + this.pageIndex + '_',
  2395. this.idCounters,
  2396. this.fontCache);
  2397. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2398. var pageListPromise = dataPromises.then(function(data) {
  2399. var contentStream = data[0];
  2400. var opList = new OperatorList(intent, handler, self.pageIndex);
  2401. handler.send('StartRenderPage', {
  2402. transparency: partialEvaluator.hasBlendModes(self.resources),
  2403. pageIndex: self.pageIndex,
  2404. intent: intent
  2405. });
  2406. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2407. opList).then(function () {
  2408. return opList;
  2409. });
  2410. });
  2411. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2412. return Promise.all([pageListPromise, annotationsPromise]).then(
  2413. function(datas) {
  2414. var pageOpList = datas[0];
  2415. var annotations = datas[1];
  2416. if (annotations.length === 0) {
  2417. pageOpList.flush(true);
  2418. return pageOpList;
  2419. }
  2420. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2421. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2422. return annotationsReadyPromise.then(function () {
  2423. pageOpList.flush(true);
  2424. return pageOpList;
  2425. });
  2426. });
  2427. },
  2428. extractTextContent: function Page_extractTextContent() {
  2429. var handler = {
  2430. on: function nullHandlerOn() {},
  2431. send: function nullHandlerSend() {}
  2432. };
  2433. var self = this;
  2434. var pdfManager = this.pdfManager;
  2435. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2436. []);
  2437. var resourcesPromise = this.loadResources([
  2438. 'ExtGState',
  2439. 'XObject',
  2440. 'Font'
  2441. ]);
  2442. var dataPromises = Promise.all([contentStreamPromise,
  2443. resourcesPromise]);
  2444. return dataPromises.then(function(data) {
  2445. var contentStream = data[0];
  2446. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2447. handler, self.pageIndex,
  2448. 'p' + self.pageIndex + '_',
  2449. self.idCounters,
  2450. self.fontCache);
  2451. return partialEvaluator.getTextContent(contentStream,
  2452. self.resources);
  2453. });
  2454. },
  2455. getAnnotationsData: function Page_getAnnotationsData() {
  2456. var annotations = this.annotations;
  2457. var annotationsData = [];
  2458. for (var i = 0, n = annotations.length; i < n; ++i) {
  2459. annotationsData.push(annotations[i].getData());
  2460. }
  2461. return annotationsData;
  2462. },
  2463. get annotations() {
  2464. var annotations = [];
  2465. var annotationRefs = (this.annotationRefs || []);
  2466. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2467. var annotationRef = annotationRefs[i];
  2468. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2469. if (annotation) {
  2470. annotations.push(annotation);
  2471. }
  2472. }
  2473. return shadow(this, 'annotations', annotations);
  2474. }
  2475. };
  2476. return Page;
  2477. })();
  2478. /**
  2479. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2480. * `PDFDoc`, this one doesn't have any job management code.
  2481. * Right now there exists one PDFDocument on the main thread + one object
  2482. * for each worker. If there is no worker support enabled, there are two
  2483. * `PDFDocument` objects on the main thread created.
  2484. */
  2485. var PDFDocument = (function PDFDocumentClosure() {
  2486. var FINGERPRINT_FIRST_BYTES = 1024;
  2487. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2488. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2489. function PDFDocument(pdfManager, arg, password) {
  2490. if (isStream(arg)) {
  2491. init.call(this, pdfManager, arg, password);
  2492. } else if (isArrayBuffer(arg)) {
  2493. init.call(this, pdfManager, new Stream(arg), password);
  2494. } else {
  2495. error('PDFDocument: Unknown argument type');
  2496. }
  2497. }
  2498. function init(pdfManager, stream, password) {
  2499. assert(stream.length > 0, 'stream must have data');
  2500. this.pdfManager = pdfManager;
  2501. this.stream = stream;
  2502. var xref = new XRef(this.stream, password, pdfManager);
  2503. this.xref = xref;
  2504. }
  2505. function find(stream, needle, limit, backwards) {
  2506. var pos = stream.pos;
  2507. var end = stream.end;
  2508. var strBuf = [];
  2509. if (pos + limit > end) {
  2510. limit = end - pos;
  2511. }
  2512. for (var n = 0; n < limit; ++n) {
  2513. strBuf.push(String.fromCharCode(stream.getByte()));
  2514. }
  2515. var str = strBuf.join('');
  2516. stream.pos = pos;
  2517. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2518. if (index === -1) {
  2519. return false; /* not found */
  2520. }
  2521. stream.pos += index;
  2522. return true; /* found */
  2523. }
  2524. var DocumentInfoValidators = {
  2525. get entries() {
  2526. // Lazily build this since all the validation functions below are not
  2527. // defined until after this file loads.
  2528. return shadow(this, 'entries', {
  2529. Title: isString,
  2530. Author: isString,
  2531. Subject: isString,
  2532. Keywords: isString,
  2533. Creator: isString,
  2534. Producer: isString,
  2535. CreationDate: isString,
  2536. ModDate: isString,
  2537. Trapped: isName
  2538. });
  2539. }
  2540. };
  2541. PDFDocument.prototype = {
  2542. parse: function PDFDocument_parse(recoveryMode) {
  2543. this.setup(recoveryMode);
  2544. try {
  2545. // checking if AcroForm is present
  2546. this.acroForm = this.catalog.catDict.get('AcroForm');
  2547. if (this.acroForm) {
  2548. this.xfa = this.acroForm.get('XFA');
  2549. var fields = this.acroForm.get('Fields');
  2550. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2551. !this.xfa) {
  2552. // no fields and no XFA -- not a form (?)
  2553. this.acroForm = null;
  2554. }
  2555. }
  2556. } catch (ex) {
  2557. info('Something wrong with AcroForm entry');
  2558. this.acroForm = null;
  2559. }
  2560. },
  2561. get linearization() {
  2562. var linearization = null;
  2563. if (this.stream.length) {
  2564. try {
  2565. linearization = Linearization.create(this.stream);
  2566. } catch (err) {
  2567. if (err instanceof MissingDataException) {
  2568. throw err;
  2569. }
  2570. info(err);
  2571. }
  2572. }
  2573. // shadow the prototype getter with a data property
  2574. return shadow(this, 'linearization', linearization);
  2575. },
  2576. get startXRef() {
  2577. var stream = this.stream;
  2578. var startXRef = 0;
  2579. var linearization = this.linearization;
  2580. if (linearization) {
  2581. // Find end of first obj.
  2582. stream.reset();
  2583. if (find(stream, 'endobj', 1024)) {
  2584. startXRef = stream.pos + 6;
  2585. }
  2586. } else {
  2587. // Find startxref by jumping backward from the end of the file.
  2588. var step = 1024;
  2589. var found = false, pos = stream.end;
  2590. while (!found && pos > 0) {
  2591. pos -= step - 'startxref'.length;
  2592. if (pos < 0) {
  2593. pos = 0;
  2594. }
  2595. stream.pos = pos;
  2596. found = find(stream, 'startxref', step, true);
  2597. }
  2598. if (found) {
  2599. stream.skip(9);
  2600. var ch;
  2601. do {
  2602. ch = stream.getByte();
  2603. } while (Lexer.isSpace(ch));
  2604. var str = '';
  2605. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2606. str += String.fromCharCode(ch);
  2607. ch = stream.getByte();
  2608. }
  2609. startXRef = parseInt(str, 10);
  2610. if (isNaN(startXRef)) {
  2611. startXRef = 0;
  2612. }
  2613. }
  2614. }
  2615. // shadow the prototype getter with a data property
  2616. return shadow(this, 'startXRef', startXRef);
  2617. },
  2618. get mainXRefEntriesOffset() {
  2619. var mainXRefEntriesOffset = 0;
  2620. var linearization = this.linearization;
  2621. if (linearization) {
  2622. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2623. }
  2624. // shadow the prototype getter with a data property
  2625. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2626. },
  2627. // Find the header, remove leading garbage and setup the stream
  2628. // starting from the header.
  2629. checkHeader: function PDFDocument_checkHeader() {
  2630. var stream = this.stream;
  2631. stream.reset();
  2632. if (find(stream, '%PDF-', 1024)) {
  2633. // Found the header, trim off any garbage before it.
  2634. stream.moveStart();
  2635. // Reading file format version
  2636. var MAX_VERSION_LENGTH = 12;
  2637. var version = '', ch;
  2638. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2639. if (version.length >= MAX_VERSION_LENGTH) {
  2640. break;
  2641. }
  2642. version += String.fromCharCode(ch);
  2643. }
  2644. // removing "%PDF-"-prefix
  2645. this.pdfFormatVersion = version.substring(5);
  2646. return;
  2647. }
  2648. // May not be a PDF file, continue anyway.
  2649. },
  2650. parseStartXRef: function PDFDocument_parseStartXRef() {
  2651. var startXRef = this.startXRef;
  2652. this.xref.setStartXRef(startXRef);
  2653. },
  2654. setup: function PDFDocument_setup(recoveryMode) {
  2655. this.xref.parse(recoveryMode);
  2656. this.catalog = new Catalog(this.pdfManager, this.xref);
  2657. },
  2658. get numPages() {
  2659. var linearization = this.linearization;
  2660. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2661. // shadow the prototype getter
  2662. return shadow(this, 'numPages', num);
  2663. },
  2664. get documentInfo() {
  2665. var docInfo = {
  2666. PDFFormatVersion: this.pdfFormatVersion,
  2667. IsAcroFormPresent: !!this.acroForm,
  2668. IsXFAPresent: !!this.xfa
  2669. };
  2670. var infoDict;
  2671. try {
  2672. infoDict = this.xref.trailer.get('Info');
  2673. } catch (err) {
  2674. info('The document information dictionary is invalid.');
  2675. }
  2676. if (infoDict) {
  2677. var validEntries = DocumentInfoValidators.entries;
  2678. // Only fill the document info with valid entries from the spec.
  2679. for (var key in validEntries) {
  2680. if (infoDict.has(key)) {
  2681. var value = infoDict.get(key);
  2682. // Make sure the value conforms to the spec.
  2683. if (validEntries[key](value)) {
  2684. docInfo[key] = (typeof value !== 'string' ?
  2685. value : stringToPDFString(value));
  2686. } else {
  2687. info('Bad value in document info for "' + key + '"');
  2688. }
  2689. }
  2690. }
  2691. }
  2692. return shadow(this, 'documentInfo', docInfo);
  2693. },
  2694. get fingerprint() {
  2695. var xref = this.xref, hash, fileID = '';
  2696. if (xref.trailer.has('ID') &&
  2697. xref.trailer.get('ID')[0] !== EMPTY_FINGERPRINT) {
  2698. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2699. } else {
  2700. if (this.stream.ensureRange) {
  2701. this.stream.ensureRange(0,
  2702. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2703. }
  2704. hash = calculateMD5(this.stream.bytes.subarray(0,
  2705. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2706. }
  2707. for (var i = 0, n = hash.length; i < n; i++) {
  2708. var hex = hash[i].toString(16);
  2709. fileID += hex.length === 1 ? '0' + hex : hex;
  2710. }
  2711. return shadow(this, 'fingerprint', fileID);
  2712. },
  2713. getPage: function PDFDocument_getPage(pageIndex) {
  2714. return this.catalog.getPage(pageIndex);
  2715. },
  2716. cleanup: function PDFDocument_cleanup() {
  2717. return this.catalog.cleanup();
  2718. }
  2719. };
  2720. return PDFDocument;
  2721. })();
  2722. var Name = (function NameClosure() {
  2723. function Name(name) {
  2724. this.name = name;
  2725. }
  2726. Name.prototype = {};
  2727. var nameCache = {};
  2728. Name.get = function Name_get(name) {
  2729. var nameValue = nameCache[name];
  2730. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2731. };
  2732. return Name;
  2733. })();
  2734. var Cmd = (function CmdClosure() {
  2735. function Cmd(cmd) {
  2736. this.cmd = cmd;
  2737. }
  2738. Cmd.prototype = {};
  2739. var cmdCache = {};
  2740. Cmd.get = function Cmd_get(cmd) {
  2741. var cmdValue = cmdCache[cmd];
  2742. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2743. };
  2744. return Cmd;
  2745. })();
  2746. var Dict = (function DictClosure() {
  2747. var nonSerializable = function nonSerializableClosure() {
  2748. return nonSerializable; // creating closure on some variable
  2749. };
  2750. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2751. 'Background': true,
  2752. 'ExtGState': true,
  2753. 'Halftone': true,
  2754. 'Layout': true,
  2755. 'Mask': true,
  2756. 'Pagination': true,
  2757. 'Printing': true
  2758. };
  2759. function isRecursionAllowedFor(dict) {
  2760. if (!isName(dict.Type)) {
  2761. return true;
  2762. }
  2763. var dictType = dict.Type.name;
  2764. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2765. }
  2766. // xref is optional
  2767. function Dict(xref) {
  2768. // Map should only be used internally, use functions below to access.
  2769. this.map = Object.create(null);
  2770. this.xref = xref;
  2771. this.objId = null;
  2772. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2773. }
  2774. Dict.prototype = {
  2775. assignXref: function Dict_assignXref(newXref) {
  2776. this.xref = newXref;
  2777. },
  2778. // automatically dereferences Ref objects
  2779. get: function Dict_get(key1, key2, key3) {
  2780. var value;
  2781. var xref = this.xref;
  2782. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2783. typeof key2 === 'undefined') {
  2784. return xref ? xref.fetchIfRef(value) : value;
  2785. }
  2786. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2787. typeof key3 === 'undefined') {
  2788. return xref ? xref.fetchIfRef(value) : value;
  2789. }
  2790. value = this.map[key3] || null;
  2791. return xref ? xref.fetchIfRef(value) : value;
  2792. },
  2793. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2794. getAsync: function Dict_getAsync(key1, key2, key3) {
  2795. var value;
  2796. var xref = this.xref;
  2797. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2798. typeof key2 === 'undefined') {
  2799. if (xref) {
  2800. return xref.fetchIfRefAsync(value);
  2801. }
  2802. return Promise.resolve(value);
  2803. }
  2804. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2805. typeof key3 === 'undefined') {
  2806. if (xref) {
  2807. return xref.fetchIfRefAsync(value);
  2808. }
  2809. return Promise.resolve(value);
  2810. }
  2811. value = this.map[key3] || null;
  2812. if (xref) {
  2813. return xref.fetchIfRefAsync(value);
  2814. }
  2815. return Promise.resolve(value);
  2816. },
  2817. // no dereferencing
  2818. getRaw: function Dict_getRaw(key) {
  2819. return this.map[key];
  2820. },
  2821. // creates new map and dereferences all Refs
  2822. getAll: function Dict_getAll() {
  2823. var all = Object.create(null);
  2824. var queue = null;
  2825. var key, obj;
  2826. for (key in this.map) {
  2827. obj = this.get(key);
  2828. if (obj instanceof Dict) {
  2829. if (isRecursionAllowedFor(obj)) {
  2830. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2831. } else {
  2832. all[key] = this.getRaw(key);
  2833. }
  2834. } else {
  2835. all[key] = obj;
  2836. }
  2837. }
  2838. if (!queue) {
  2839. return all;
  2840. }
  2841. // trying to take cyclic references into the account
  2842. var processed = Object.create(null);
  2843. while (queue.length > 0) {
  2844. var item = queue.shift();
  2845. var itemObj = item.obj;
  2846. var objId = itemObj.objId;
  2847. if (objId && objId in processed) {
  2848. item.target[item.key] = processed[objId];
  2849. continue;
  2850. }
  2851. var dereferenced = Object.create(null);
  2852. for (key in itemObj.map) {
  2853. obj = itemObj.get(key);
  2854. if (obj instanceof Dict) {
  2855. if (isRecursionAllowedFor(obj)) {
  2856. queue.push({target: dereferenced, key: key, obj: obj});
  2857. } else {
  2858. dereferenced[key] = itemObj.getRaw(key);
  2859. }
  2860. } else {
  2861. dereferenced[key] = obj;
  2862. }
  2863. }
  2864. if (objId) {
  2865. processed[objId] = dereferenced;
  2866. }
  2867. item.target[item.key] = dereferenced;
  2868. }
  2869. return all;
  2870. },
  2871. set: function Dict_set(key, value) {
  2872. this.map[key] = value;
  2873. },
  2874. has: function Dict_has(key) {
  2875. return key in this.map;
  2876. },
  2877. forEach: function Dict_forEach(callback) {
  2878. for (var key in this.map) {
  2879. callback(key, this.get(key));
  2880. }
  2881. }
  2882. };
  2883. Dict.empty = new Dict(null);
  2884. return Dict;
  2885. })();
  2886. var Ref = (function RefClosure() {
  2887. function Ref(num, gen) {
  2888. this.num = num;
  2889. this.gen = gen;
  2890. }
  2891. Ref.prototype = {
  2892. toString: function Ref_toString() {
  2893. // This function is hot, so we make the string as compact as possible.
  2894. // |this.gen| is almost always zero, so we treat that case specially.
  2895. var str = this.num + 'R';
  2896. if (this.gen !== 0) {
  2897. str += this.gen;
  2898. }
  2899. return str;
  2900. }
  2901. };
  2902. return Ref;
  2903. })();
  2904. // The reference is identified by number and generation.
  2905. // This structure stores only one instance of the reference.
  2906. var RefSet = (function RefSetClosure() {
  2907. function RefSet() {
  2908. this.dict = {};
  2909. }
  2910. RefSet.prototype = {
  2911. has: function RefSet_has(ref) {
  2912. return ref.toString() in this.dict;
  2913. },
  2914. put: function RefSet_put(ref) {
  2915. this.dict[ref.toString()] = true;
  2916. },
  2917. remove: function RefSet_remove(ref) {
  2918. delete this.dict[ref.toString()];
  2919. }
  2920. };
  2921. return RefSet;
  2922. })();
  2923. var RefSetCache = (function RefSetCacheClosure() {
  2924. function RefSetCache() {
  2925. this.dict = Object.create(null);
  2926. }
  2927. RefSetCache.prototype = {
  2928. get: function RefSetCache_get(ref) {
  2929. return this.dict[ref.toString()];
  2930. },
  2931. has: function RefSetCache_has(ref) {
  2932. return ref.toString() in this.dict;
  2933. },
  2934. put: function RefSetCache_put(ref, obj) {
  2935. this.dict[ref.toString()] = obj;
  2936. },
  2937. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2938. this.dict[ref.toString()] = this.get(aliasRef);
  2939. },
  2940. forEach: function RefSetCache_forEach(fn, thisArg) {
  2941. for (var i in this.dict) {
  2942. fn.call(thisArg, this.dict[i]);
  2943. }
  2944. },
  2945. clear: function RefSetCache_clear() {
  2946. this.dict = Object.create(null);
  2947. }
  2948. };
  2949. return RefSetCache;
  2950. })();
  2951. var Catalog = (function CatalogClosure() {
  2952. function Catalog(pdfManager, xref) {
  2953. this.pdfManager = pdfManager;
  2954. this.xref = xref;
  2955. this.catDict = xref.getCatalogObj();
  2956. this.fontCache = new RefSetCache();
  2957. assert(isDict(this.catDict),
  2958. 'catalog object is not a dictionary');
  2959. this.pagePromises = [];
  2960. }
  2961. Catalog.prototype = {
  2962. get metadata() {
  2963. var streamRef = this.catDict.getRaw('Metadata');
  2964. if (!isRef(streamRef)) {
  2965. return shadow(this, 'metadata', null);
  2966. }
  2967. var encryptMetadata = (!this.xref.encrypt ? false :
  2968. this.xref.encrypt.encryptMetadata);
  2969. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2970. var metadata;
  2971. if (stream && isDict(stream.dict)) {
  2972. var type = stream.dict.get('Type');
  2973. var subtype = stream.dict.get('Subtype');
  2974. if (isName(type) && isName(subtype) &&
  2975. type.name === 'Metadata' && subtype.name === 'XML') {
  2976. // XXX: This should examine the charset the XML document defines,
  2977. // however since there are currently no real means to decode
  2978. // arbitrary charsets, let's just hope that the author of the PDF
  2979. // was reasonable enough to stick with the XML default charset,
  2980. // which is UTF-8.
  2981. try {
  2982. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2983. } catch (e) {
  2984. info('Skipping invalid metadata.');
  2985. }
  2986. }
  2987. }
  2988. return shadow(this, 'metadata', metadata);
  2989. },
  2990. get toplevelPagesDict() {
  2991. var pagesObj = this.catDict.get('Pages');
  2992. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2993. // shadow the prototype getter
  2994. return shadow(this, 'toplevelPagesDict', pagesObj);
  2995. },
  2996. get documentOutline() {
  2997. var obj = null;
  2998. try {
  2999. obj = this.readDocumentOutline();
  3000. } catch (ex) {
  3001. if (ex instanceof MissingDataException) {
  3002. throw ex;
  3003. }
  3004. warn('Unable to read document outline');
  3005. }
  3006. return shadow(this, 'documentOutline', obj);
  3007. },
  3008. readDocumentOutline: function Catalog_readDocumentOutline() {
  3009. var xref = this.xref;
  3010. var obj = this.catDict.get('Outlines');
  3011. var root = { items: [] };
  3012. if (isDict(obj)) {
  3013. obj = obj.getRaw('First');
  3014. var processed = new RefSet();
  3015. if (isRef(obj)) {
  3016. var queue = [{obj: obj, parent: root}];
  3017. // to avoid recursion keeping track of the items
  3018. // in the processed dictionary
  3019. processed.put(obj);
  3020. while (queue.length > 0) {
  3021. var i = queue.shift();
  3022. var outlineDict = xref.fetchIfRef(i.obj);
  3023. if (outlineDict === null) {
  3024. continue;
  3025. }
  3026. if (!outlineDict.has('Title')) {
  3027. error('Invalid outline item');
  3028. }
  3029. var dest = outlineDict.get('A');
  3030. if (dest) {
  3031. dest = dest.get('D');
  3032. } else if (outlineDict.has('Dest')) {
  3033. dest = outlineDict.getRaw('Dest');
  3034. if (isName(dest)) {
  3035. dest = dest.name;
  3036. }
  3037. }
  3038. var title = outlineDict.get('Title');
  3039. var outlineItem = {
  3040. dest: dest,
  3041. title: stringToPDFString(title),
  3042. color: outlineDict.get('C') || [0, 0, 0],
  3043. count: outlineDict.get('Count'),
  3044. bold: !!(outlineDict.get('F') & 2),
  3045. italic: !!(outlineDict.get('F') & 1),
  3046. items: []
  3047. };
  3048. i.parent.items.push(outlineItem);
  3049. obj = outlineDict.getRaw('First');
  3050. if (isRef(obj) && !processed.has(obj)) {
  3051. queue.push({obj: obj, parent: outlineItem});
  3052. processed.put(obj);
  3053. }
  3054. obj = outlineDict.getRaw('Next');
  3055. if (isRef(obj) && !processed.has(obj)) {
  3056. queue.push({obj: obj, parent: i.parent});
  3057. processed.put(obj);
  3058. }
  3059. }
  3060. }
  3061. }
  3062. return (root.items.length > 0 ? root.items : null);
  3063. },
  3064. get numPages() {
  3065. var obj = this.toplevelPagesDict.get('Count');
  3066. assert(
  3067. isInt(obj),
  3068. 'page count in top level pages object is not an integer'
  3069. );
  3070. // shadow the prototype getter
  3071. return shadow(this, 'num', obj);
  3072. },
  3073. get destinations() {
  3074. function fetchDestination(dest) {
  3075. return isDict(dest) ? dest.get('D') : dest;
  3076. }
  3077. var xref = this.xref;
  3078. var dests = {}, nameTreeRef, nameDictionaryRef;
  3079. var obj = this.catDict.get('Names');
  3080. if (obj && obj.has('Dests')) {
  3081. nameTreeRef = obj.getRaw('Dests');
  3082. } else if (this.catDict.has('Dests')) {
  3083. nameDictionaryRef = this.catDict.get('Dests');
  3084. }
  3085. if (nameDictionaryRef) {
  3086. // reading simple destination dictionary
  3087. obj = nameDictionaryRef;
  3088. obj.forEach(function catalogForEach(key, value) {
  3089. if (!value) {
  3090. return;
  3091. }
  3092. dests[key] = fetchDestination(value);
  3093. });
  3094. }
  3095. if (nameTreeRef) {
  3096. var nameTree = new NameTree(nameTreeRef, xref);
  3097. var names = nameTree.getAll();
  3098. for (var name in names) {
  3099. if (!names.hasOwnProperty(name)) {
  3100. continue;
  3101. }
  3102. dests[name] = fetchDestination(names[name]);
  3103. }
  3104. }
  3105. return shadow(this, 'destinations', dests);
  3106. },
  3107. getDestination: function Catalog_getDestination(destinationId) {
  3108. function fetchDestination(dest) {
  3109. return isDict(dest) ? dest.get('D') : dest;
  3110. }
  3111. var xref = this.xref;
  3112. var dest, nameTreeRef, nameDictionaryRef;
  3113. var obj = this.catDict.get('Names');
  3114. if (obj && obj.has('Dests')) {
  3115. nameTreeRef = obj.getRaw('Dests');
  3116. } else if (this.catDict.has('Dests')) {
  3117. nameDictionaryRef = this.catDict.get('Dests');
  3118. }
  3119. if (nameDictionaryRef) {
  3120. // reading simple destination dictionary
  3121. obj = nameDictionaryRef;
  3122. obj.forEach(function catalogForEach(key, value) {
  3123. if (!value) {
  3124. return;
  3125. }
  3126. if (key === destinationId) {
  3127. dest = fetchDestination(value);
  3128. }
  3129. });
  3130. }
  3131. if (nameTreeRef) {
  3132. var nameTree = new NameTree(nameTreeRef, xref);
  3133. dest = fetchDestination(nameTree.get(destinationId));
  3134. }
  3135. return dest;
  3136. },
  3137. get attachments() {
  3138. var xref = this.xref;
  3139. var attachments = null, nameTreeRef;
  3140. var obj = this.catDict.get('Names');
  3141. if (obj) {
  3142. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3143. }
  3144. if (nameTreeRef) {
  3145. var nameTree = new NameTree(nameTreeRef, xref);
  3146. var names = nameTree.getAll();
  3147. for (var name in names) {
  3148. if (!names.hasOwnProperty(name)) {
  3149. continue;
  3150. }
  3151. var fs = new FileSpec(names[name], xref);
  3152. if (!attachments) {
  3153. attachments = {};
  3154. }
  3155. attachments[stringToPDFString(name)] = fs.serializable;
  3156. }
  3157. }
  3158. return shadow(this, 'attachments', attachments);
  3159. },
  3160. get javaScript() {
  3161. var xref = this.xref;
  3162. var obj = this.catDict.get('Names');
  3163. var javaScript = [];
  3164. if (obj && obj.has('JavaScript')) {
  3165. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3166. var names = nameTree.getAll();
  3167. for (var name in names) {
  3168. if (!names.hasOwnProperty(name)) {
  3169. continue;
  3170. }
  3171. // We don't really use the JavaScript right now. This code is
  3172. // defensive so we don't cause errors on document load.
  3173. var jsDict = names[name];
  3174. if (!isDict(jsDict)) {
  3175. continue;
  3176. }
  3177. var type = jsDict.get('S');
  3178. if (!isName(type) || type.name !== 'JavaScript') {
  3179. continue;
  3180. }
  3181. var js = jsDict.get('JS');
  3182. if (!isString(js) && !isStream(js)) {
  3183. continue;
  3184. }
  3185. if (isStream(js)) {
  3186. js = bytesToString(js.getBytes());
  3187. }
  3188. javaScript.push(stringToPDFString(js));
  3189. }
  3190. }
  3191. // Append OpenAction actions to javaScript array
  3192. var openactionDict = this.catDict.get('OpenAction');
  3193. if (isDict(openactionDict)) {
  3194. var objType = openactionDict.get('Type');
  3195. var actionType = openactionDict.get('S');
  3196. var action = openactionDict.get('N');
  3197. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3198. isName(actionType) && actionType.name === 'Named' &&
  3199. isName(action) && action.name === 'Print');
  3200. if (isPrintAction) {
  3201. javaScript.push('print(true);');
  3202. }
  3203. }
  3204. return shadow(this, 'javaScript', javaScript);
  3205. },
  3206. cleanup: function Catalog_cleanup() {
  3207. var promises = [];
  3208. this.fontCache.forEach(function (promise) {
  3209. promises.push(promise);
  3210. });
  3211. return Promise.all(promises).then(function (translatedFonts) {
  3212. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3213. var font = translatedFonts[i].dict;
  3214. delete font.translated;
  3215. }
  3216. this.fontCache.clear();
  3217. }.bind(this));
  3218. },
  3219. getPage: function Catalog_getPage(pageIndex) {
  3220. if (!(pageIndex in this.pagePromises)) {
  3221. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3222. function (a) {
  3223. var dict = a[0];
  3224. var ref = a[1];
  3225. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3226. this.fontCache);
  3227. }.bind(this)
  3228. );
  3229. }
  3230. return this.pagePromises[pageIndex];
  3231. },
  3232. getPageDict: function Catalog_getPageDict(pageIndex) {
  3233. var capability = createPromiseCapability();
  3234. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3235. var currentPageIndex = 0;
  3236. var xref = this.xref;
  3237. function next() {
  3238. while (nodesToVisit.length) {
  3239. var currentNode = nodesToVisit.pop();
  3240. if (isRef(currentNode)) {
  3241. xref.fetchAsync(currentNode).then(function (obj) {
  3242. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3243. if (pageIndex === currentPageIndex) {
  3244. capability.resolve([obj, currentNode]);
  3245. } else {
  3246. currentPageIndex++;
  3247. next();
  3248. }
  3249. return;
  3250. }
  3251. nodesToVisit.push(obj);
  3252. next();
  3253. }, capability.reject);
  3254. return;
  3255. }
  3256. // must be a child page dictionary
  3257. assert(
  3258. isDict(currentNode),
  3259. 'page dictionary kid reference points to wrong type of object'
  3260. );
  3261. var count = currentNode.get('Count');
  3262. // Skip nodes where the page can't be.
  3263. if (currentPageIndex + count <= pageIndex) {
  3264. currentPageIndex += count;
  3265. continue;
  3266. }
  3267. var kids = currentNode.get('Kids');
  3268. assert(isArray(kids), 'page dictionary kids object is not an array');
  3269. if (count === kids.length) {
  3270. // Nodes that don't have the page have been skipped and this is the
  3271. // bottom of the tree which means the page requested must be a
  3272. // descendant of this pages node. Ideally we would just resolve the
  3273. // promise with the page ref here, but there is the case where more
  3274. // pages nodes could link to single a page (see issue 3666 pdf). To
  3275. // handle this push it back on the queue so if it is a pages node it
  3276. // will be descended into.
  3277. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3278. currentPageIndex = pageIndex;
  3279. continue;
  3280. } else {
  3281. for (var last = kids.length - 1; last >= 0; last--) {
  3282. nodesToVisit.push(kids[last]);
  3283. }
  3284. }
  3285. }
  3286. capability.reject('Page index ' + pageIndex + ' not found.');
  3287. }
  3288. next();
  3289. return capability.promise;
  3290. },
  3291. getPageIndex: function Catalog_getPageIndex(ref) {
  3292. // The page tree nodes have the count of all the leaves below them. To get
  3293. // how many pages are before we just have to walk up the tree and keep
  3294. // adding the count of siblings to the left of the node.
  3295. var xref = this.xref;
  3296. function pagesBeforeRef(kidRef) {
  3297. var total = 0;
  3298. var parentRef;
  3299. return xref.fetchAsync(kidRef).then(function (node) {
  3300. if (!node) {
  3301. return null;
  3302. }
  3303. parentRef = node.getRaw('Parent');
  3304. return node.getAsync('Parent');
  3305. }).then(function (parent) {
  3306. if (!parent) {
  3307. return null;
  3308. }
  3309. return parent.getAsync('Kids');
  3310. }).then(function (kids) {
  3311. if (!kids) {
  3312. return null;
  3313. }
  3314. var kidPromises = [];
  3315. var found = false;
  3316. for (var i = 0; i < kids.length; i++) {
  3317. var kid = kids[i];
  3318. assert(isRef(kid), 'kids must be a ref');
  3319. if (kid.num === kidRef.num) {
  3320. found = true;
  3321. break;
  3322. }
  3323. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3324. if (kid.has('Count')) {
  3325. var count = kid.get('Count');
  3326. total += count;
  3327. } else { // page leaf node
  3328. total++;
  3329. }
  3330. }));
  3331. }
  3332. if (!found) {
  3333. error('kid ref not found in parents kids');
  3334. }
  3335. return Promise.all(kidPromises).then(function () {
  3336. return [total, parentRef];
  3337. });
  3338. });
  3339. }
  3340. var total = 0;
  3341. function next(ref) {
  3342. return pagesBeforeRef(ref).then(function (args) {
  3343. if (!args) {
  3344. return total;
  3345. }
  3346. var count = args[0];
  3347. var parentRef = args[1];
  3348. total += count;
  3349. return next(parentRef);
  3350. });
  3351. }
  3352. return next(ref);
  3353. }
  3354. };
  3355. return Catalog;
  3356. })();
  3357. var XRef = (function XRefClosure() {
  3358. function XRef(stream, password) {
  3359. this.stream = stream;
  3360. this.entries = [];
  3361. this.xrefstms = {};
  3362. // prepare the XRef cache
  3363. this.cache = [];
  3364. this.password = password;
  3365. this.stats = {
  3366. streamTypes: [],
  3367. fontTypes: []
  3368. };
  3369. }
  3370. XRef.prototype = {
  3371. setStartXRef: function XRef_setStartXRef(startXRef) {
  3372. // Store the starting positions of xref tables as we process them
  3373. // so we can recover from missing data errors
  3374. this.startXRefQueue = [startXRef];
  3375. },
  3376. parse: function XRef_parse(recoveryMode) {
  3377. var trailerDict;
  3378. if (!recoveryMode) {
  3379. trailerDict = this.readXRef();
  3380. } else {
  3381. warn('Indexing all PDF objects');
  3382. trailerDict = this.indexObjects();
  3383. }
  3384. trailerDict.assignXref(this);
  3385. this.trailer = trailerDict;
  3386. var encrypt = trailerDict.get('Encrypt');
  3387. if (encrypt) {
  3388. var ids = trailerDict.get('ID');
  3389. var fileId = (ids && ids.length) ? ids[0] : '';
  3390. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3391. this.password);
  3392. }
  3393. // get the root dictionary (catalog) object
  3394. if (!(this.root = trailerDict.get('Root'))) {
  3395. error('Invalid root reference');
  3396. }
  3397. },
  3398. processXRefTable: function XRef_processXRefTable(parser) {
  3399. if (!('tableState' in this)) {
  3400. // Stores state of the table as we process it so we can resume
  3401. // from middle of table in case of missing data error
  3402. this.tableState = {
  3403. entryNum: 0,
  3404. streamPos: parser.lexer.stream.pos,
  3405. parserBuf1: parser.buf1,
  3406. parserBuf2: parser.buf2
  3407. };
  3408. }
  3409. var obj = this.readXRefTable(parser);
  3410. // Sanity check
  3411. if (!isCmd(obj, 'trailer')) {
  3412. error('Invalid XRef table: could not find trailer dictionary');
  3413. }
  3414. // Read trailer dictionary, e.g.
  3415. // trailer
  3416. // << /Size 22
  3417. // /Root 20R
  3418. // /Info 10R
  3419. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3420. // >>
  3421. // The parser goes through the entire stream << ... >> and provides
  3422. // a getter interface for the key-value table
  3423. var dict = parser.getObj();
  3424. // The pdflib PDF generator can generate a nested trailer dictionary
  3425. if (!isDict(dict) && dict.dict) {
  3426. dict = dict.dict;
  3427. }
  3428. if (!isDict(dict)) {
  3429. error('Invalid XRef table: could not parse trailer dictionary');
  3430. }
  3431. delete this.tableState;
  3432. return dict;
  3433. },
  3434. readXRefTable: function XRef_readXRefTable(parser) {
  3435. // Example of cross-reference table:
  3436. // xref
  3437. // 0 1 <-- subsection header (first obj #, obj count)
  3438. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3439. // 23 2 <-- subsection header ... and so on ...
  3440. // 0000025518 00002 n
  3441. // 0000025635 00000 n
  3442. // trailer
  3443. // ...
  3444. var stream = parser.lexer.stream;
  3445. var tableState = this.tableState;
  3446. stream.pos = tableState.streamPos;
  3447. parser.buf1 = tableState.parserBuf1;
  3448. parser.buf2 = tableState.parserBuf2;
  3449. // Outer loop is over subsection headers
  3450. var obj;
  3451. while (true) {
  3452. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3453. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3454. break;
  3455. }
  3456. tableState.firstEntryNum = obj;
  3457. tableState.entryCount = parser.getObj();
  3458. }
  3459. var first = tableState.firstEntryNum;
  3460. var count = tableState.entryCount;
  3461. if (!isInt(first) || !isInt(count)) {
  3462. error('Invalid XRef table: wrong types in subsection header');
  3463. }
  3464. // Inner loop is over objects themselves
  3465. for (var i = tableState.entryNum; i < count; i++) {
  3466. tableState.streamPos = stream.pos;
  3467. tableState.entryNum = i;
  3468. tableState.parserBuf1 = parser.buf1;
  3469. tableState.parserBuf2 = parser.buf2;
  3470. var entry = {};
  3471. entry.offset = parser.getObj();
  3472. entry.gen = parser.getObj();
  3473. var type = parser.getObj();
  3474. if (isCmd(type, 'f')) {
  3475. entry.free = true;
  3476. } else if (isCmd(type, 'n')) {
  3477. entry.uncompressed = true;
  3478. }
  3479. // Validate entry obj
  3480. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3481. !(entry.free || entry.uncompressed)) {
  3482. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3483. }
  3484. if (!this.entries[i + first]) {
  3485. this.entries[i + first] = entry;
  3486. }
  3487. }
  3488. tableState.entryNum = 0;
  3489. tableState.streamPos = stream.pos;
  3490. tableState.parserBuf1 = parser.buf1;
  3491. tableState.parserBuf2 = parser.buf2;
  3492. delete tableState.firstEntryNum;
  3493. delete tableState.entryCount;
  3494. }
  3495. // Per issue 3248: hp scanners generate bad XRef
  3496. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3497. // shifting the entries
  3498. this.entries.shift();
  3499. }
  3500. // Sanity check: as per spec, first object must be free
  3501. if (this.entries[0] && !this.entries[0].free) {
  3502. error('Invalid XRef table: unexpected first object');
  3503. }
  3504. return obj;
  3505. },
  3506. processXRefStream: function XRef_processXRefStream(stream) {
  3507. if (!('streamState' in this)) {
  3508. // Stores state of the stream as we process it so we can resume
  3509. // from middle of stream in case of missing data error
  3510. var streamParameters = stream.dict;
  3511. var byteWidths = streamParameters.get('W');
  3512. var range = streamParameters.get('Index');
  3513. if (!range) {
  3514. range = [0, streamParameters.get('Size')];
  3515. }
  3516. this.streamState = {
  3517. entryRanges: range,
  3518. byteWidths: byteWidths,
  3519. entryNum: 0,
  3520. streamPos: stream.pos
  3521. };
  3522. }
  3523. this.readXRefStream(stream);
  3524. delete this.streamState;
  3525. return stream.dict;
  3526. },
  3527. readXRefStream: function XRef_readXRefStream(stream) {
  3528. var i, j;
  3529. var streamState = this.streamState;
  3530. stream.pos = streamState.streamPos;
  3531. var byteWidths = streamState.byteWidths;
  3532. var typeFieldWidth = byteWidths[0];
  3533. var offsetFieldWidth = byteWidths[1];
  3534. var generationFieldWidth = byteWidths[2];
  3535. var entryRanges = streamState.entryRanges;
  3536. while (entryRanges.length > 0) {
  3537. var first = entryRanges[0];
  3538. var n = entryRanges[1];
  3539. if (!isInt(first) || !isInt(n)) {
  3540. error('Invalid XRef range fields: ' + first + ', ' + n);
  3541. }
  3542. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3543. !isInt(generationFieldWidth)) {
  3544. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3545. }
  3546. for (i = streamState.entryNum; i < n; ++i) {
  3547. streamState.entryNum = i;
  3548. streamState.streamPos = stream.pos;
  3549. var type = 0, offset = 0, generation = 0;
  3550. for (j = 0; j < typeFieldWidth; ++j) {
  3551. type = (type << 8) | stream.getByte();
  3552. }
  3553. // if type field is absent, its default value is 1
  3554. if (typeFieldWidth === 0) {
  3555. type = 1;
  3556. }
  3557. for (j = 0; j < offsetFieldWidth; ++j) {
  3558. offset = (offset << 8) | stream.getByte();
  3559. }
  3560. for (j = 0; j < generationFieldWidth; ++j) {
  3561. generation = (generation << 8) | stream.getByte();
  3562. }
  3563. var entry = {};
  3564. entry.offset = offset;
  3565. entry.gen = generation;
  3566. switch (type) {
  3567. case 0:
  3568. entry.free = true;
  3569. break;
  3570. case 1:
  3571. entry.uncompressed = true;
  3572. break;
  3573. case 2:
  3574. break;
  3575. default:
  3576. error('Invalid XRef entry type: ' + type);
  3577. }
  3578. if (!this.entries[first + i]) {
  3579. this.entries[first + i] = entry;
  3580. }
  3581. }
  3582. streamState.entryNum = 0;
  3583. streamState.streamPos = stream.pos;
  3584. entryRanges.splice(0, 2);
  3585. }
  3586. },
  3587. indexObjects: function XRef_indexObjects() {
  3588. // Simple scan through the PDF content to find objects,
  3589. // trailers and XRef streams.
  3590. function readToken(data, offset) {
  3591. var token = '', ch = data[offset];
  3592. while (ch !== 13 && ch !== 10) {
  3593. if (++offset >= data.length) {
  3594. break;
  3595. }
  3596. token += String.fromCharCode(ch);
  3597. ch = data[offset];
  3598. }
  3599. return token;
  3600. }
  3601. function skipUntil(data, offset, what) {
  3602. var length = what.length, dataLength = data.length;
  3603. var skipped = 0;
  3604. // finding byte sequence
  3605. while (offset < dataLength) {
  3606. var i = 0;
  3607. while (i < length && data[offset + i] === what[i]) {
  3608. ++i;
  3609. }
  3610. if (i >= length) {
  3611. break; // sequence found
  3612. }
  3613. offset++;
  3614. skipped++;
  3615. }
  3616. return skipped;
  3617. }
  3618. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3619. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3620. 101, 102]);
  3621. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3622. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3623. var stream = this.stream;
  3624. stream.pos = 0;
  3625. var buffer = stream.getBytes();
  3626. var position = stream.start, length = buffer.length;
  3627. var trailers = [], xrefStms = [];
  3628. while (position < length) {
  3629. var ch = buffer[position];
  3630. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3631. ++position;
  3632. continue;
  3633. }
  3634. if (ch === 37) { // %-comment
  3635. do {
  3636. ++position;
  3637. if (position >= length) {
  3638. break;
  3639. }
  3640. ch = buffer[position];
  3641. } while (ch !== 13 && ch !== 10);
  3642. continue;
  3643. }
  3644. var token = readToken(buffer, position);
  3645. var m;
  3646. if (token === 'xref') {
  3647. position += skipUntil(buffer, position, trailerBytes);
  3648. trailers.push(position);
  3649. position += skipUntil(buffer, position, startxrefBytes);
  3650. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3651. this.entries[m[1]] = {
  3652. offset: position,
  3653. gen: m[2] | 0,
  3654. uncompressed: true
  3655. };
  3656. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3657. var content = buffer.subarray(position, position + contentLength);
  3658. // checking XRef stream suspect
  3659. // (it shall have '/XRef' and next char is not a letter)
  3660. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3661. if (xrefTagOffset < contentLength &&
  3662. content[xrefTagOffset + 5] < 64) {
  3663. xrefStms.push(position);
  3664. this.xrefstms[position] = 1; // don't read it recursively
  3665. }
  3666. position += contentLength;
  3667. } else {
  3668. position += token.length + 1;
  3669. }
  3670. }
  3671. // reading XRef streams
  3672. var i, ii;
  3673. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3674. this.startXRefQueue.push(xrefStms[i]);
  3675. this.readXRef(/* recoveryMode */ true);
  3676. }
  3677. // finding main trailer
  3678. var dict;
  3679. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3680. stream.pos = trailers[i];
  3681. var parser = new Parser(new Lexer(stream), true, this);
  3682. var obj = parser.getObj();
  3683. if (!isCmd(obj, 'trailer')) {
  3684. continue;
  3685. }
  3686. // read the trailer dictionary
  3687. if (!isDict(dict = parser.getObj())) {
  3688. continue;
  3689. }
  3690. // taking the first one with 'ID'
  3691. if (dict.has('ID')) {
  3692. return dict;
  3693. }
  3694. }
  3695. // no tailer with 'ID', taking last one (if exists)
  3696. if (dict) {
  3697. return dict;
  3698. }
  3699. // nothing helps
  3700. // calling error() would reject worker with an UnknownErrorException.
  3701. throw new InvalidPDFException('Invalid PDF structure');
  3702. },
  3703. readXRef: function XRef_readXRef(recoveryMode) {
  3704. var stream = this.stream;
  3705. try {
  3706. while (this.startXRefQueue.length) {
  3707. var startXRef = this.startXRefQueue[0];
  3708. stream.pos = startXRef + stream.start;
  3709. var parser = new Parser(new Lexer(stream), true, this);
  3710. var obj = parser.getObj();
  3711. var dict;
  3712. // Get dictionary
  3713. if (isCmd(obj, 'xref')) {
  3714. // Parse end-of-file XRef
  3715. dict = this.processXRefTable(parser);
  3716. if (!this.topDict) {
  3717. this.topDict = dict;
  3718. }
  3719. // Recursively get other XRefs 'XRefStm', if any
  3720. obj = dict.get('XRefStm');
  3721. if (isInt(obj)) {
  3722. var pos = obj;
  3723. // ignore previously loaded xref streams
  3724. // (possible infinite recursion)
  3725. if (!(pos in this.xrefstms)) {
  3726. this.xrefstms[pos] = 1;
  3727. this.startXRefQueue.push(pos);
  3728. }
  3729. }
  3730. } else if (isInt(obj)) {
  3731. // Parse in-stream XRef
  3732. if (!isInt(parser.getObj()) ||
  3733. !isCmd(parser.getObj(), 'obj') ||
  3734. !isStream(obj = parser.getObj())) {
  3735. error('Invalid XRef stream');
  3736. }
  3737. dict = this.processXRefStream(obj);
  3738. if (!this.topDict) {
  3739. this.topDict = dict;
  3740. }
  3741. if (!dict) {
  3742. error('Failed to read XRef stream');
  3743. }
  3744. } else {
  3745. error('Invalid XRef stream header');
  3746. }
  3747. // Recursively get previous dictionary, if any
  3748. obj = dict.get('Prev');
  3749. if (isInt(obj)) {
  3750. this.startXRefQueue.push(obj);
  3751. } else if (isRef(obj)) {
  3752. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3753. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3754. this.startXRefQueue.push(obj.num);
  3755. }
  3756. this.startXRefQueue.shift();
  3757. }
  3758. return this.topDict;
  3759. } catch (e) {
  3760. if (e instanceof MissingDataException) {
  3761. throw e;
  3762. }
  3763. info('(while reading XRef): ' + e);
  3764. }
  3765. if (recoveryMode) {
  3766. return;
  3767. }
  3768. throw new XRefParseException();
  3769. },
  3770. getEntry: function XRef_getEntry(i) {
  3771. var xrefEntry = this.entries[i];
  3772. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3773. return xrefEntry;
  3774. }
  3775. return null;
  3776. },
  3777. fetchIfRef: function XRef_fetchIfRef(obj) {
  3778. if (!isRef(obj)) {
  3779. return obj;
  3780. }
  3781. return this.fetch(obj);
  3782. },
  3783. fetch: function XRef_fetch(ref, suppressEncryption) {
  3784. assert(isRef(ref), 'ref object is not a reference');
  3785. var num = ref.num;
  3786. if (num in this.cache) {
  3787. var cacheEntry = this.cache[num];
  3788. return cacheEntry;
  3789. }
  3790. var xrefEntry = this.getEntry(num);
  3791. // the referenced entry can be free
  3792. if (xrefEntry === null) {
  3793. return (this.cache[num] = null);
  3794. }
  3795. if (xrefEntry.uncompressed) {
  3796. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3797. } else {
  3798. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3799. }
  3800. if (isDict(xrefEntry)){
  3801. xrefEntry.objId = ref.toString();
  3802. } else if (isStream(xrefEntry)) {
  3803. xrefEntry.dict.objId = ref.toString();
  3804. }
  3805. return xrefEntry;
  3806. },
  3807. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3808. suppressEncryption) {
  3809. var gen = ref.gen;
  3810. var num = ref.num;
  3811. if (xrefEntry.gen !== gen) {
  3812. error('inconsistent generation in XRef');
  3813. }
  3814. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3815. this.stream.start);
  3816. var parser = new Parser(new Lexer(stream), true, this);
  3817. var obj1 = parser.getObj();
  3818. var obj2 = parser.getObj();
  3819. var obj3 = parser.getObj();
  3820. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3821. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3822. !isCmd(obj3)) {
  3823. error('bad XRef entry');
  3824. }
  3825. if (!isCmd(obj3, 'obj')) {
  3826. // some bad PDFs use "obj1234" and really mean 1234
  3827. if (obj3.cmd.indexOf('obj') === 0) {
  3828. num = parseInt(obj3.cmd.substring(3), 10);
  3829. if (!isNaN(num)) {
  3830. return num;
  3831. }
  3832. }
  3833. error('bad XRef entry');
  3834. }
  3835. if (this.encrypt && !suppressEncryption) {
  3836. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3837. } else {
  3838. xrefEntry = parser.getObj();
  3839. }
  3840. if (!isStream(xrefEntry)) {
  3841. this.cache[num] = xrefEntry;
  3842. }
  3843. return xrefEntry;
  3844. },
  3845. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3846. suppressEncryption) {
  3847. var tableOffset = xrefEntry.offset;
  3848. var stream = this.fetch(new Ref(tableOffset, 0));
  3849. if (!isStream(stream)) {
  3850. error('bad ObjStm stream');
  3851. }
  3852. var first = stream.dict.get('First');
  3853. var n = stream.dict.get('N');
  3854. if (!isInt(first) || !isInt(n)) {
  3855. error('invalid first and n parameters for ObjStm stream');
  3856. }
  3857. var parser = new Parser(new Lexer(stream), false, this);
  3858. parser.allowStreams = true;
  3859. var i, entries = [], num, nums = [];
  3860. // read the object numbers to populate cache
  3861. for (i = 0; i < n; ++i) {
  3862. num = parser.getObj();
  3863. if (!isInt(num)) {
  3864. error('invalid object number in the ObjStm stream: ' + num);
  3865. }
  3866. nums.push(num);
  3867. var offset = parser.getObj();
  3868. if (!isInt(offset)) {
  3869. error('invalid object offset in the ObjStm stream: ' + offset);
  3870. }
  3871. }
  3872. // read stream objects for cache
  3873. for (i = 0; i < n; ++i) {
  3874. entries.push(parser.getObj());
  3875. num = nums[i];
  3876. var entry = this.entries[num];
  3877. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3878. this.cache[num] = entries[i];
  3879. }
  3880. }
  3881. xrefEntry = entries[xrefEntry.gen];
  3882. if (xrefEntry === undefined) {
  3883. error('bad XRef entry for compressed object');
  3884. }
  3885. return xrefEntry;
  3886. },
  3887. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3888. if (!isRef(obj)) {
  3889. return Promise.resolve(obj);
  3890. }
  3891. return this.fetchAsync(obj);
  3892. },
  3893. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3894. var streamManager = this.stream.manager;
  3895. var xref = this;
  3896. return new Promise(function tryFetch(resolve, reject) {
  3897. try {
  3898. resolve(xref.fetch(ref, suppressEncryption));
  3899. } catch (e) {
  3900. if (e instanceof MissingDataException) {
  3901. streamManager.requestRange(e.begin, e.end, function () {
  3902. tryFetch(resolve, reject);
  3903. });
  3904. return;
  3905. }
  3906. reject(e);
  3907. }
  3908. });
  3909. },
  3910. getCatalogObj: function XRef_getCatalogObj() {
  3911. return this.root;
  3912. }
  3913. };
  3914. return XRef;
  3915. })();
  3916. /**
  3917. * A NameTree is like a Dict but has some advantageous properties, see the
  3918. * spec (7.9.6) for more details.
  3919. * TODO: implement all the Dict functions and make this more efficent.
  3920. */
  3921. var NameTree = (function NameTreeClosure() {
  3922. function NameTree(root, xref) {
  3923. this.root = root;
  3924. this.xref = xref;
  3925. }
  3926. NameTree.prototype = {
  3927. getAll: function NameTree_getAll() {
  3928. var dict = {};
  3929. if (!this.root) {
  3930. return dict;
  3931. }
  3932. var xref = this.xref;
  3933. // reading name tree
  3934. var processed = new RefSet();
  3935. processed.put(this.root);
  3936. var queue = [this.root];
  3937. while (queue.length > 0) {
  3938. var i, n;
  3939. var obj = xref.fetchIfRef(queue.shift());
  3940. if (!isDict(obj)) {
  3941. continue;
  3942. }
  3943. if (obj.has('Kids')) {
  3944. var kids = obj.get('Kids');
  3945. for (i = 0, n = kids.length; i < n; i++) {
  3946. var kid = kids[i];
  3947. if (processed.has(kid)) {
  3948. error('invalid destinations');
  3949. }
  3950. queue.push(kid);
  3951. processed.put(kid);
  3952. }
  3953. continue;
  3954. }
  3955. var names = obj.get('Names');
  3956. if (names) {
  3957. for (i = 0, n = names.length; i < n; i += 2) {
  3958. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3959. }
  3960. }
  3961. }
  3962. return dict;
  3963. },
  3964. get: function NameTree_get(destinationId) {
  3965. if (!this.root) {
  3966. return null;
  3967. }
  3968. var xref = this.xref;
  3969. var kidsOrNames = xref.fetchIfRef(this.root);
  3970. var loopCount = 0;
  3971. var MAX_NAMES_LEVELS = 10;
  3972. var l, r, m;
  3973. // Perform a binary search to quickly find the entry that
  3974. // contains the named destination we are looking for.
  3975. while (kidsOrNames.has('Kids')) {
  3976. loopCount++;
  3977. if (loopCount > MAX_NAMES_LEVELS) {
  3978. warn('Search depth limit for named destionations has been reached.');
  3979. return null;
  3980. }
  3981. var kids = kidsOrNames.get('Kids');
  3982. if (!isArray(kids)) {
  3983. return null;
  3984. }
  3985. l = 0;
  3986. r = kids.length - 1;
  3987. while (l <= r) {
  3988. m = (l + r) >> 1;
  3989. var kid = xref.fetchIfRef(kids[m]);
  3990. var limits = kid.get('Limits');
  3991. if (destinationId < limits[0]) {
  3992. r = m - 1;
  3993. } else if (destinationId > limits[1]) {
  3994. l = m + 1;
  3995. } else {
  3996. kidsOrNames = xref.fetchIfRef(kids[m]);
  3997. break;
  3998. }
  3999. }
  4000. if (l > r) {
  4001. return null;
  4002. }
  4003. }
  4004. // If we get here, then we have found the right entry. Now
  4005. // go through the named destinations in the Named dictionary
  4006. // until we find the exact destination we're looking for.
  4007. var names = kidsOrNames.get('Names');
  4008. if (isArray(names)) {
  4009. // Perform a binary search to reduce the lookup time.
  4010. l = 0;
  4011. r = names.length - 2;
  4012. while (l <= r) {
  4013. // Check only even indices (0, 2, 4, ...) because the
  4014. // odd indices contain the actual D array.
  4015. m = (l + r) & ~1;
  4016. if (destinationId < names[m]) {
  4017. r = m - 2;
  4018. } else if (destinationId > names[m]) {
  4019. l = m + 2;
  4020. } else {
  4021. return xref.fetchIfRef(names[m + 1]);
  4022. }
  4023. }
  4024. }
  4025. return null;
  4026. }
  4027. };
  4028. return NameTree;
  4029. })();
  4030. /**
  4031. * "A PDF file can refer to the contents of another file by using a File
  4032. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4033. * NOTE: Only embedded files are supported (as part of the attachments support)
  4034. * TODO: support the 'URL' file system (with caching if !/V), portable
  4035. * collections attributes and related files (/RF)
  4036. */
  4037. var FileSpec = (function FileSpecClosure() {
  4038. function FileSpec(root, xref) {
  4039. if (!root || !isDict(root)) {
  4040. return;
  4041. }
  4042. this.xref = xref;
  4043. this.root = root;
  4044. if (root.has('FS')) {
  4045. this.fs = root.get('FS');
  4046. }
  4047. this.description = root.has('Desc') ?
  4048. stringToPDFString(root.get('Desc')) :
  4049. '';
  4050. if (root.has('RF')) {
  4051. warn('Related file specifications are not supported');
  4052. }
  4053. this.contentAvailable = true;
  4054. if (!root.has('EF')) {
  4055. this.contentAvailable = false;
  4056. warn('Non-embedded file specifications are not supported');
  4057. }
  4058. }
  4059. function pickPlatformItem(dict) {
  4060. // Look for the filename in this order:
  4061. // UF, F, Unix, Mac, DOS
  4062. if (dict.has('UF')) {
  4063. return dict.get('UF');
  4064. } else if (dict.has('F')) {
  4065. return dict.get('F');
  4066. } else if (dict.has('Unix')) {
  4067. return dict.get('Unix');
  4068. } else if (dict.has('Mac')) {
  4069. return dict.get('Mac');
  4070. } else if (dict.has('DOS')) {
  4071. return dict.get('DOS');
  4072. } else {
  4073. return null;
  4074. }
  4075. }
  4076. FileSpec.prototype = {
  4077. get filename() {
  4078. if (!this._filename && this.root) {
  4079. var filename = pickPlatformItem(this.root) || 'unnamed';
  4080. this._filename = stringToPDFString(filename).
  4081. replace(/\\\\/g, '\\').
  4082. replace(/\\\//g, '/').
  4083. replace(/\\/g, '/');
  4084. }
  4085. return this._filename;
  4086. },
  4087. get content() {
  4088. if (!this.contentAvailable) {
  4089. return null;
  4090. }
  4091. if (!this.contentRef && this.root) {
  4092. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4093. }
  4094. var content = null;
  4095. if (this.contentRef) {
  4096. var xref = this.xref;
  4097. var fileObj = xref.fetchIfRef(this.contentRef);
  4098. if (fileObj && isStream(fileObj)) {
  4099. content = fileObj.getBytes();
  4100. } else {
  4101. warn('Embedded file specification points to non-existing/invalid ' +
  4102. 'content');
  4103. }
  4104. } else {
  4105. warn('Embedded file specification does not have a content');
  4106. }
  4107. return content;
  4108. },
  4109. get serializable() {
  4110. return {
  4111. filename: this.filename,
  4112. content: this.content
  4113. };
  4114. }
  4115. };
  4116. return FileSpec;
  4117. })();
  4118. /**
  4119. * A helper for loading missing data in object graphs. It traverses the graph
  4120. * depth first and queues up any objects that have missing data. Once it has
  4121. * has traversed as many objects that are available it attempts to bundle the
  4122. * missing data requests and then resume from the nodes that weren't ready.
  4123. *
  4124. * NOTE: It provides protection from circular references by keeping track of
  4125. * of loaded references. However, you must be careful not to load any graphs
  4126. * that have references to the catalog or other pages since that will cause the
  4127. * entire PDF document object graph to be traversed.
  4128. */
  4129. var ObjectLoader = (function() {
  4130. function mayHaveChildren(value) {
  4131. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4132. }
  4133. function addChildren(node, nodesToVisit) {
  4134. var value;
  4135. if (isDict(node) || isStream(node)) {
  4136. var map;
  4137. if (isDict(node)) {
  4138. map = node.map;
  4139. } else {
  4140. map = node.dict.map;
  4141. }
  4142. for (var key in map) {
  4143. value = map[key];
  4144. if (mayHaveChildren(value)) {
  4145. nodesToVisit.push(value);
  4146. }
  4147. }
  4148. } else if (isArray(node)) {
  4149. for (var i = 0, ii = node.length; i < ii; i++) {
  4150. value = node[i];
  4151. if (mayHaveChildren(value)) {
  4152. nodesToVisit.push(value);
  4153. }
  4154. }
  4155. }
  4156. }
  4157. function ObjectLoader(obj, keys, xref) {
  4158. this.obj = obj;
  4159. this.keys = keys;
  4160. this.xref = xref;
  4161. this.refSet = null;
  4162. }
  4163. ObjectLoader.prototype = {
  4164. load: function ObjectLoader_load() {
  4165. var keys = this.keys;
  4166. this.capability = createPromiseCapability();
  4167. // Don't walk the graph if all the data is already loaded.
  4168. if (!(this.xref.stream instanceof ChunkedStream) ||
  4169. this.xref.stream.getMissingChunks().length === 0) {
  4170. this.capability.resolve();
  4171. return this.capability.promise;
  4172. }
  4173. this.refSet = new RefSet();
  4174. // Setup the initial nodes to visit.
  4175. var nodesToVisit = [];
  4176. for (var i = 0; i < keys.length; i++) {
  4177. nodesToVisit.push(this.obj[keys[i]]);
  4178. }
  4179. this.walk(nodesToVisit);
  4180. return this.capability.promise;
  4181. },
  4182. walk: function ObjectLoader_walk(nodesToVisit) {
  4183. var nodesToRevisit = [];
  4184. var pendingRequests = [];
  4185. // DFS walk of the object graph.
  4186. while (nodesToVisit.length) {
  4187. var currentNode = nodesToVisit.pop();
  4188. // Only references or chunked streams can cause missing data exceptions.
  4189. if (isRef(currentNode)) {
  4190. // Skip nodes that have already been visited.
  4191. if (this.refSet.has(currentNode)) {
  4192. continue;
  4193. }
  4194. try {
  4195. var ref = currentNode;
  4196. this.refSet.put(ref);
  4197. currentNode = this.xref.fetch(currentNode);
  4198. } catch (e) {
  4199. if (!(e instanceof MissingDataException)) {
  4200. throw e;
  4201. }
  4202. nodesToRevisit.push(currentNode);
  4203. pendingRequests.push({ begin: e.begin, end: e.end });
  4204. }
  4205. }
  4206. if (currentNode && currentNode.getBaseStreams) {
  4207. var baseStreams = currentNode.getBaseStreams();
  4208. var foundMissingData = false;
  4209. for (var i = 0; i < baseStreams.length; i++) {
  4210. var stream = baseStreams[i];
  4211. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4212. foundMissingData = true;
  4213. pendingRequests.push({
  4214. begin: stream.start,
  4215. end: stream.end
  4216. });
  4217. }
  4218. }
  4219. if (foundMissingData) {
  4220. nodesToRevisit.push(currentNode);
  4221. }
  4222. }
  4223. addChildren(currentNode, nodesToVisit);
  4224. }
  4225. if (pendingRequests.length) {
  4226. this.xref.stream.manager.requestRanges(pendingRequests,
  4227. function pendingRequestCallback() {
  4228. nodesToVisit = nodesToRevisit;
  4229. for (var i = 0; i < nodesToRevisit.length; i++) {
  4230. var node = nodesToRevisit[i];
  4231. // Remove any reference nodes from the currrent refset so they
  4232. // aren't skipped when we revist them.
  4233. if (isRef(node)) {
  4234. this.refSet.remove(node);
  4235. }
  4236. }
  4237. this.walk(nodesToVisit);
  4238. }.bind(this));
  4239. return;
  4240. }
  4241. // Everything is loaded.
  4242. this.refSet = null;
  4243. this.capability.resolve();
  4244. }
  4245. };
  4246. return ObjectLoader;
  4247. })();
  4248. var ISOAdobeCharset = [
  4249. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4250. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4251. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4252. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4253. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4254. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4255. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4256. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4257. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4258. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4259. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4260. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4261. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4262. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4263. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4264. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4265. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4266. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4267. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4268. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4269. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4270. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4271. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4272. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4273. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4274. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4275. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4276. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4277. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4278. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4279. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4280. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4281. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4282. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4283. ];
  4284. var ExpertCharset = [
  4285. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4286. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4287. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4288. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4289. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4290. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4291. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4292. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4293. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4294. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4295. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4296. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4297. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4298. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4299. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4300. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4301. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4302. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4303. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4304. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4305. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4306. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4307. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4308. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4309. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4310. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4311. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4312. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4313. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4314. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4315. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4316. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4317. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4318. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4319. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4320. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4321. 'Ydieresissmall'
  4322. ];
  4323. var ExpertSubsetCharset = [
  4324. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4325. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4326. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4327. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4328. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4329. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4330. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4331. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4332. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4333. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4334. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4335. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4336. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4337. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4338. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4339. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4340. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4341. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4342. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4343. 'periodinferior', 'commainferior'
  4344. ];
  4345. var DEFAULT_ICON_SIZE = 22; // px
  4346. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4347. var Annotation = (function AnnotationClosure() {
  4348. // 12.5.5: Algorithm: Appearance streams
  4349. function getTransformMatrix(rect, bbox, matrix) {
  4350. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4351. var minX = bounds[0];
  4352. var minY = bounds[1];
  4353. var maxX = bounds[2];
  4354. var maxY = bounds[3];
  4355. if (minX === maxX || minY === maxY) {
  4356. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4357. // just apply the transform for rect
  4358. return [1, 0, 0, 1, rect[0], rect[1]];
  4359. }
  4360. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4361. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4362. return [
  4363. xRatio,
  4364. 0,
  4365. 0,
  4366. yRatio,
  4367. rect[0] - minX * xRatio,
  4368. rect[1] - minY * yRatio
  4369. ];
  4370. }
  4371. function getDefaultAppearance(dict) {
  4372. var appearanceState = dict.get('AP');
  4373. if (!isDict(appearanceState)) {
  4374. return;
  4375. }
  4376. var appearance;
  4377. var appearances = appearanceState.get('N');
  4378. if (isDict(appearances)) {
  4379. var as = dict.get('AS');
  4380. if (as && appearances.has(as.name)) {
  4381. appearance = appearances.get(as.name);
  4382. }
  4383. } else {
  4384. appearance = appearances;
  4385. }
  4386. return appearance;
  4387. }
  4388. function Annotation(params) {
  4389. var dict = params.dict;
  4390. var data = this.data = {};
  4391. data.subtype = dict.get('Subtype').name;
  4392. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4393. data.rect = Util.normalizeRect(rect);
  4394. data.annotationFlags = dict.get('F');
  4395. var color = dict.get('C');
  4396. if (!color) {
  4397. // The PDF spec does not mention how a missing color array is interpreted.
  4398. // Adobe Reader seems to default to black in this case.
  4399. data.color = [0, 0, 0];
  4400. } else if (isArray(color)) {
  4401. switch (color.length) {
  4402. case 0:
  4403. // Empty array denotes transparent border.
  4404. data.color = null;
  4405. break;
  4406. case 1:
  4407. // TODO: implement DeviceGray
  4408. break;
  4409. case 3:
  4410. data.color = color;
  4411. break;
  4412. case 4:
  4413. // TODO: implement DeviceCMYK
  4414. break;
  4415. }
  4416. }
  4417. // Some types of annotations have border style dict which has more
  4418. // info than the border array
  4419. if (dict.has('BS')) {
  4420. var borderStyle = dict.get('BS');
  4421. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4422. } else {
  4423. var borderArray = dict.get('Border') || [0, 0, 1];
  4424. data.borderWidth = borderArray[2] || 0;
  4425. // TODO: implement proper support for annotations with line dash patterns.
  4426. var dashArray = borderArray[3];
  4427. if (data.borderWidth > 0 && dashArray) {
  4428. if (!isArray(dashArray)) {
  4429. // Ignore the border if dashArray is not actually an array,
  4430. // this is consistent with the behaviour in Adobe Reader.
  4431. data.borderWidth = 0;
  4432. } else {
  4433. var dashArrayLength = dashArray.length;
  4434. if (dashArrayLength > 0) {
  4435. // According to the PDF specification: the elements in a dashArray
  4436. // shall be numbers that are nonnegative and not all equal to zero.
  4437. var isInvalid = false;
  4438. var numPositive = 0;
  4439. for (var i = 0; i < dashArrayLength; i++) {
  4440. var validNumber = (+dashArray[i] >= 0);
  4441. if (!validNumber) {
  4442. isInvalid = true;
  4443. break;
  4444. } else if (dashArray[i] > 0) {
  4445. numPositive++;
  4446. }
  4447. }
  4448. if (isInvalid || numPositive === 0) {
  4449. data.borderWidth = 0;
  4450. }
  4451. }
  4452. }
  4453. }
  4454. }
  4455. this.appearance = getDefaultAppearance(dict);
  4456. data.hasAppearance = !!this.appearance;
  4457. data.id = params.ref.num;
  4458. }
  4459. Annotation.prototype = {
  4460. getData: function Annotation_getData() {
  4461. return this.data;
  4462. },
  4463. isInvisible: function Annotation_isInvisible() {
  4464. var data = this.data;
  4465. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4466. return false;
  4467. } else {
  4468. return !!(data &&
  4469. data.annotationFlags && // Default: not invisible
  4470. data.annotationFlags & 0x1); // Invisible
  4471. }
  4472. },
  4473. isViewable: function Annotation_isViewable() {
  4474. var data = this.data;
  4475. return !!(!this.isInvisible() &&
  4476. data &&
  4477. (!data.annotationFlags ||
  4478. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4479. data.rect); // rectangle is necessary
  4480. },
  4481. isPrintable: function Annotation_isPrintable() {
  4482. var data = this.data;
  4483. return !!(!this.isInvisible() &&
  4484. data &&
  4485. data.annotationFlags && // Default: not printable
  4486. data.annotationFlags & 0x4 && // Print
  4487. !(data.annotationFlags & 0x2) && // Hidden
  4488. data.rect); // rectangle is necessary
  4489. },
  4490. loadResources: function Annotation_loadResources(keys) {
  4491. return new Promise(function (resolve, reject) {
  4492. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4493. if (!resources) {
  4494. resolve();
  4495. return;
  4496. }
  4497. var objectLoader = new ObjectLoader(resources.map,
  4498. keys,
  4499. resources.xref);
  4500. objectLoader.load().then(function() {
  4501. resolve(resources);
  4502. }, reject);
  4503. }, reject);
  4504. }.bind(this));
  4505. },
  4506. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4507. if (!this.appearance) {
  4508. return Promise.resolve(new OperatorList());
  4509. }
  4510. var data = this.data;
  4511. var appearanceDict = this.appearance.dict;
  4512. var resourcesPromise = this.loadResources([
  4513. 'ExtGState',
  4514. 'ColorSpace',
  4515. 'Pattern',
  4516. 'Shading',
  4517. 'XObject',
  4518. 'Font'
  4519. // ProcSet
  4520. // Properties
  4521. ]);
  4522. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4523. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4524. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4525. var self = this;
  4526. return resourcesPromise.then(function(resources) {
  4527. var opList = new OperatorList();
  4528. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4529. return evaluator.getOperatorList(self.appearance, resources, opList).
  4530. then(function () {
  4531. opList.addOp(OPS.endAnnotation, []);
  4532. self.appearance.reset();
  4533. return opList;
  4534. });
  4535. });
  4536. }
  4537. };
  4538. Annotation.getConstructor =
  4539. function Annotation_getConstructor(subtype, fieldType) {
  4540. if (!subtype) {
  4541. return;
  4542. }
  4543. // TODO(mack): Implement FreeText annotations
  4544. if (subtype === 'Link') {
  4545. return LinkAnnotation;
  4546. } else if (subtype === 'Text') {
  4547. return TextAnnotation;
  4548. } else if (subtype === 'Widget') {
  4549. if (!fieldType) {
  4550. return;
  4551. }
  4552. if (fieldType === 'Tx') {
  4553. return TextWidgetAnnotation;
  4554. } else {
  4555. return WidgetAnnotation;
  4556. }
  4557. } else {
  4558. return Annotation;
  4559. }
  4560. };
  4561. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4562. var dict = xref.fetchIfRef(ref);
  4563. if (!isDict(dict)) {
  4564. return;
  4565. }
  4566. var subtype = dict.get('Subtype');
  4567. subtype = isName(subtype) ? subtype.name : '';
  4568. if (!subtype) {
  4569. return;
  4570. }
  4571. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4572. fieldType = isName(fieldType) ? fieldType.name : '';
  4573. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4574. if (!Constructor) {
  4575. return;
  4576. }
  4577. var params = {
  4578. dict: dict,
  4579. ref: ref,
  4580. };
  4581. var annotation = new Constructor(params);
  4582. if (annotation.isViewable() || annotation.isPrintable()) {
  4583. return annotation;
  4584. } else {
  4585. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4586. warn('unimplemented annotation type: ' + subtype);
  4587. }
  4588. }
  4589. };
  4590. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4591. annotations, opList, pdfManager, partialEvaluator, intent) {
  4592. function reject(e) {
  4593. annotationsReadyCapability.reject(e);
  4594. }
  4595. var annotationsReadyCapability = createPromiseCapability();
  4596. var annotationPromises = [];
  4597. for (var i = 0, n = annotations.length; i < n; ++i) {
  4598. if (intent === 'display' && annotations[i].isViewable() ||
  4599. intent === 'print' && annotations[i].isPrintable()) {
  4600. annotationPromises.push(
  4601. annotations[i].getOperatorList(partialEvaluator));
  4602. }
  4603. }
  4604. Promise.all(annotationPromises).then(function(datas) {
  4605. opList.addOp(OPS.beginAnnotations, []);
  4606. for (var i = 0, n = datas.length; i < n; ++i) {
  4607. var annotOpList = datas[i];
  4608. opList.addOpList(annotOpList);
  4609. }
  4610. opList.addOp(OPS.endAnnotations, []);
  4611. annotationsReadyCapability.resolve();
  4612. }, reject);
  4613. return annotationsReadyCapability.promise;
  4614. };
  4615. return Annotation;
  4616. })();
  4617. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4618. function WidgetAnnotation(params) {
  4619. Annotation.call(this, params);
  4620. var dict = params.dict;
  4621. var data = this.data;
  4622. data.fieldValue = stringToPDFString(
  4623. Util.getInheritableProperty(dict, 'V') || '');
  4624. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4625. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4626. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4627. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4628. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4629. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4630. // Building the full field name by collecting the field and
  4631. // its ancestors 'T' data and joining them using '.'.
  4632. var fieldName = [];
  4633. var namedItem = dict;
  4634. var ref = params.ref;
  4635. while (namedItem) {
  4636. var parent = namedItem.get('Parent');
  4637. var parentRef = namedItem.getRaw('Parent');
  4638. var name = namedItem.get('T');
  4639. if (name) {
  4640. fieldName.unshift(stringToPDFString(name));
  4641. } else if (parent && ref) {
  4642. // The field name is absent, that means more than one field
  4643. // with the same name may exist. Replacing the empty name
  4644. // with the '`' plus index in the parent's 'Kids' array.
  4645. // This is not in the PDF spec but necessary to id the
  4646. // the input controls.
  4647. var kids = parent.get('Kids');
  4648. var j, jj;
  4649. for (j = 0, jj = kids.length; j < jj; j++) {
  4650. var kidRef = kids[j];
  4651. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4652. break;
  4653. }
  4654. }
  4655. fieldName.unshift('`' + j);
  4656. }
  4657. namedItem = parent;
  4658. ref = parentRef;
  4659. }
  4660. data.fullName = fieldName.join('.');
  4661. }
  4662. var parent = Annotation.prototype;
  4663. Util.inherit(WidgetAnnotation, Annotation, {
  4664. isViewable: function WidgetAnnotation_isViewable() {
  4665. if (this.data.fieldType === 'Sig') {
  4666. warn('unimplemented annotation type: Widget signature');
  4667. return false;
  4668. }
  4669. return parent.isViewable.call(this);
  4670. }
  4671. });
  4672. return WidgetAnnotation;
  4673. })();
  4674. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4675. function TextWidgetAnnotation(params) {
  4676. WidgetAnnotation.call(this, params);
  4677. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4678. this.data.annotationType = AnnotationType.WIDGET;
  4679. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4680. }
  4681. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4682. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4683. if (this.appearance) {
  4684. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4685. }
  4686. var opList = new OperatorList();
  4687. var data = this.data;
  4688. // Even if there is an appearance stream, ignore it. This is the
  4689. // behaviour used by Adobe Reader.
  4690. if (!data.defaultAppearance) {
  4691. return Promise.resolve(opList);
  4692. }
  4693. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4694. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4695. then(function () {
  4696. return opList;
  4697. });
  4698. }
  4699. });
  4700. return TextWidgetAnnotation;
  4701. })();
  4702. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4703. function InteractiveAnnotation(params) {
  4704. Annotation.call(this, params);
  4705. this.data.hasHtml = true;
  4706. }
  4707. Util.inherit(InteractiveAnnotation, Annotation, { });
  4708. return InteractiveAnnotation;
  4709. })();
  4710. var TextAnnotation = (function TextAnnotationClosure() {
  4711. function TextAnnotation(params) {
  4712. InteractiveAnnotation.call(this, params);
  4713. var dict = params.dict;
  4714. var data = this.data;
  4715. var content = dict.get('Contents');
  4716. var title = dict.get('T');
  4717. data.annotationType = AnnotationType.TEXT;
  4718. data.content = stringToPDFString(content || '');
  4719. data.title = stringToPDFString(title || '');
  4720. if (data.hasAppearance) {
  4721. data.name = 'NoIcon';
  4722. } else {
  4723. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4724. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4725. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4726. }
  4727. if (dict.has('C')) {
  4728. data.hasBgColor = true;
  4729. }
  4730. }
  4731. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4732. return TextAnnotation;
  4733. })();
  4734. var LinkAnnotation = (function LinkAnnotationClosure() {
  4735. function LinkAnnotation(params) {
  4736. InteractiveAnnotation.call(this, params);
  4737. var dict = params.dict;
  4738. var data = this.data;
  4739. data.annotationType = AnnotationType.LINK;
  4740. var action = dict.get('A');
  4741. if (action) {
  4742. var linkType = action.get('S').name;
  4743. if (linkType === 'URI') {
  4744. var url = action.get('URI');
  4745. if (isName(url)) {
  4746. // Some bad PDFs do not put parentheses around relative URLs.
  4747. url = '/' + url.name;
  4748. } else if (url) {
  4749. url = addDefaultProtocolToUrl(url);
  4750. }
  4751. // TODO: pdf spec mentions urls can be relative to a Base
  4752. // entry in the dictionary.
  4753. if (!isValidUrl(url, false)) {
  4754. url = '';
  4755. }
  4756. data.url = url;
  4757. } else if (linkType === 'GoTo') {
  4758. data.dest = action.get('D');
  4759. } else if (linkType === 'GoToR') {
  4760. var urlDict = action.get('F');
  4761. if (isDict(urlDict)) {
  4762. // We assume that the 'url' is a Filspec dictionary
  4763. // and fetch the url without checking any further
  4764. url = urlDict.get('F') || '';
  4765. }
  4766. // TODO: pdf reference says that GoToR
  4767. // can also have 'NewWindow' attribute
  4768. if (!isValidUrl(url, false)) {
  4769. url = '';
  4770. }
  4771. data.url = url;
  4772. data.dest = action.get('D');
  4773. } else if (linkType === 'Named') {
  4774. data.action = action.get('N').name;
  4775. } else {
  4776. warn('unrecognized link type: ' + linkType);
  4777. }
  4778. } else if (dict.has('Dest')) {
  4779. // simple destination link
  4780. var dest = dict.get('Dest');
  4781. data.dest = isName(dest) ? dest.name : dest;
  4782. }
  4783. }
  4784. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4785. function addDefaultProtocolToUrl(url) {
  4786. if (url && url.indexOf('www.') === 0) {
  4787. return ('http://' + url);
  4788. }
  4789. return url;
  4790. }
  4791. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4792. return LinkAnnotation;
  4793. })();
  4794. var PDFFunction = (function PDFFunctionClosure() {
  4795. var CONSTRUCT_SAMPLED = 0;
  4796. var CONSTRUCT_INTERPOLATED = 2;
  4797. var CONSTRUCT_STICHED = 3;
  4798. var CONSTRUCT_POSTSCRIPT = 4;
  4799. return {
  4800. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4801. str) {
  4802. var i, ii;
  4803. var length = 1;
  4804. for (i = 0, ii = size.length; i < ii; i++) {
  4805. length *= size[i];
  4806. }
  4807. length *= outputSize;
  4808. var array = new Array(length);
  4809. var codeSize = 0;
  4810. var codeBuf = 0;
  4811. // 32 is a valid bps so shifting won't work
  4812. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4813. var strBytes = str.getBytes((length * bps + 7) / 8);
  4814. var strIdx = 0;
  4815. for (i = 0; i < length; i++) {
  4816. while (codeSize < bps) {
  4817. codeBuf <<= 8;
  4818. codeBuf |= strBytes[strIdx++];
  4819. codeSize += 8;
  4820. }
  4821. codeSize -= bps;
  4822. array[i] = (codeBuf >> codeSize) * sampleMul;
  4823. codeBuf &= (1 << codeSize) - 1;
  4824. }
  4825. return array;
  4826. },
  4827. getIR: function PDFFunction_getIR(xref, fn) {
  4828. var dict = fn.dict;
  4829. if (!dict) {
  4830. dict = fn;
  4831. }
  4832. var types = [this.constructSampled,
  4833. null,
  4834. this.constructInterpolated,
  4835. this.constructStiched,
  4836. this.constructPostScript];
  4837. var typeNum = dict.get('FunctionType');
  4838. var typeFn = types[typeNum];
  4839. if (!typeFn) {
  4840. error('Unknown type of function');
  4841. }
  4842. return typeFn.call(this, fn, dict, xref);
  4843. },
  4844. fromIR: function PDFFunction_fromIR(IR) {
  4845. var type = IR[0];
  4846. switch (type) {
  4847. case CONSTRUCT_SAMPLED:
  4848. return this.constructSampledFromIR(IR);
  4849. case CONSTRUCT_INTERPOLATED:
  4850. return this.constructInterpolatedFromIR(IR);
  4851. case CONSTRUCT_STICHED:
  4852. return this.constructStichedFromIR(IR);
  4853. //case CONSTRUCT_POSTSCRIPT:
  4854. default:
  4855. return this.constructPostScriptFromIR(IR);
  4856. }
  4857. },
  4858. parse: function PDFFunction_parse(xref, fn) {
  4859. var IR = this.getIR(xref, fn);
  4860. return this.fromIR(IR);
  4861. },
  4862. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4863. if (!isArray(fnObj)) {
  4864. // not an array -- parsing as regular function
  4865. return this.parse(xref, fnObj);
  4866. }
  4867. var fnArray = [];
  4868. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4869. var obj = xref.fetchIfRef(fnObj[j]);
  4870. fnArray.push(PDFFunction.parse(xref, obj));
  4871. }
  4872. return function (src, srcOffset, dest, destOffset) {
  4873. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4874. fnArray[i](src, srcOffset, dest, destOffset + i);
  4875. }
  4876. };
  4877. },
  4878. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4879. function toMultiArray(arr) {
  4880. var inputLength = arr.length;
  4881. var out = [];
  4882. var index = 0;
  4883. for (var i = 0; i < inputLength; i += 2) {
  4884. out[index] = [arr[i], arr[i + 1]];
  4885. ++index;
  4886. }
  4887. return out;
  4888. }
  4889. var domain = dict.get('Domain');
  4890. var range = dict.get('Range');
  4891. if (!domain || !range) {
  4892. error('No domain or range');
  4893. }
  4894. var inputSize = domain.length / 2;
  4895. var outputSize = range.length / 2;
  4896. domain = toMultiArray(domain);
  4897. range = toMultiArray(range);
  4898. var size = dict.get('Size');
  4899. var bps = dict.get('BitsPerSample');
  4900. var order = dict.get('Order') || 1;
  4901. if (order !== 1) {
  4902. // No description how cubic spline interpolation works in PDF32000:2008
  4903. // As in poppler, ignoring order, linear interpolation may work as good
  4904. info('No support for cubic spline interpolation: ' + order);
  4905. }
  4906. var encode = dict.get('Encode');
  4907. if (!encode) {
  4908. encode = [];
  4909. for (var i = 0; i < inputSize; ++i) {
  4910. encode.push(0);
  4911. encode.push(size[i] - 1);
  4912. }
  4913. }
  4914. encode = toMultiArray(encode);
  4915. var decode = dict.get('Decode');
  4916. if (!decode) {
  4917. decode = range;
  4918. } else {
  4919. decode = toMultiArray(decode);
  4920. }
  4921. var samples = this.getSampleArray(size, outputSize, bps, str);
  4922. return [
  4923. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4924. outputSize, Math.pow(2, bps) - 1, range
  4925. ];
  4926. },
  4927. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4928. // See chapter 3, page 109 of the PDF reference
  4929. function interpolate(x, xmin, xmax, ymin, ymax) {
  4930. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4931. }
  4932. return function constructSampledFromIRResult(src, srcOffset,
  4933. dest, destOffset) {
  4934. // See chapter 3, page 110 of the PDF reference.
  4935. var m = IR[1];
  4936. var domain = IR[2];
  4937. var encode = IR[3];
  4938. var decode = IR[4];
  4939. var samples = IR[5];
  4940. var size = IR[6];
  4941. var n = IR[7];
  4942. //var mask = IR[8];
  4943. var range = IR[9];
  4944. // Building the cube vertices: its part and sample index
  4945. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4946. var cubeVertices = 1 << m;
  4947. var cubeN = new Float64Array(cubeVertices);
  4948. var cubeVertex = new Uint32Array(cubeVertices);
  4949. var i, j;
  4950. for (j = 0; j < cubeVertices; j++) {
  4951. cubeN[j] = 1;
  4952. }
  4953. var k = n, pos = 1;
  4954. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4955. for (i = 0; i < m; ++i) {
  4956. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4957. var domain_2i = domain[i][0];
  4958. var domain_2i_1 = domain[i][1];
  4959. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4960. domain_2i_1);
  4961. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4962. // Encode_2i, Encode_2i+1)
  4963. var e = interpolate(xi, domain_2i, domain_2i_1,
  4964. encode[i][0], encode[i][1]);
  4965. // e_i' = min(max(e_i, 0), Size_i - 1)
  4966. var size_i = size[i];
  4967. e = Math.min(Math.max(e, 0), size_i - 1);
  4968. // Adjusting the cube: N and vertex sample index
  4969. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4970. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4971. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4972. var offset0 = e0 * k;
  4973. var offset1 = offset0 + k; // e1 * k
  4974. for (j = 0; j < cubeVertices; j++) {
  4975. if (j & pos) {
  4976. cubeN[j] *= n1;
  4977. cubeVertex[j] += offset1;
  4978. } else {
  4979. cubeN[j] *= n0;
  4980. cubeVertex[j] += offset0;
  4981. }
  4982. }
  4983. k *= size_i;
  4984. pos <<= 1;
  4985. }
  4986. for (j = 0; j < n; ++j) {
  4987. // Sum all cube vertices' samples portions
  4988. var rj = 0;
  4989. for (i = 0; i < cubeVertices; i++) {
  4990. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4991. }
  4992. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4993. // Decode_2j, Decode_2j+1)
  4994. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4995. // y_j = min(max(r_j, range_2j), range_2j+1)
  4996. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  4997. range[j][1]);
  4998. }
  4999. };
  5000. },
  5001. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5002. dict) {
  5003. var c0 = dict.get('C0') || [0];
  5004. var c1 = dict.get('C1') || [1];
  5005. var n = dict.get('N');
  5006. if (!isArray(c0) || !isArray(c1)) {
  5007. error('Illegal dictionary for interpolated function');
  5008. }
  5009. var length = c0.length;
  5010. var diff = [];
  5011. for (var i = 0; i < length; ++i) {
  5012. diff.push(c1[i] - c0[i]);
  5013. }
  5014. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5015. },
  5016. constructInterpolatedFromIR:
  5017. function PDFFunction_constructInterpolatedFromIR(IR) {
  5018. var c0 = IR[1];
  5019. var diff = IR[2];
  5020. var n = IR[3];
  5021. var length = diff.length;
  5022. return function constructInterpolatedFromIRResult(src, srcOffset,
  5023. dest, destOffset) {
  5024. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5025. for (var j = 0; j < length; ++j) {
  5026. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5027. }
  5028. };
  5029. },
  5030. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5031. var domain = dict.get('Domain');
  5032. if (!domain) {
  5033. error('No domain');
  5034. }
  5035. var inputSize = domain.length / 2;
  5036. if (inputSize !== 1) {
  5037. error('Bad domain for stiched function');
  5038. }
  5039. var fnRefs = dict.get('Functions');
  5040. var fns = [];
  5041. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5042. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5043. }
  5044. var bounds = dict.get('Bounds');
  5045. var encode = dict.get('Encode');
  5046. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5047. },
  5048. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5049. var domain = IR[1];
  5050. var bounds = IR[2];
  5051. var encode = IR[3];
  5052. var fnsIR = IR[4];
  5053. var fns = [];
  5054. var tmpBuf = new Float32Array(1);
  5055. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5056. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5057. }
  5058. return function constructStichedFromIRResult(src, srcOffset,
  5059. dest, destOffset) {
  5060. var clip = function constructStichedFromIRClip(v, min, max) {
  5061. if (v > max) {
  5062. v = max;
  5063. } else if (v < min) {
  5064. v = min;
  5065. }
  5066. return v;
  5067. };
  5068. // clip to domain
  5069. var v = clip(src[srcOffset], domain[0], domain[1]);
  5070. // calulate which bound the value is in
  5071. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5072. if (v < bounds[i]) {
  5073. break;
  5074. }
  5075. }
  5076. // encode value into domain of function
  5077. var dmin = domain[0];
  5078. if (i > 0) {
  5079. dmin = bounds[i - 1];
  5080. }
  5081. var dmax = domain[1];
  5082. if (i < bounds.length) {
  5083. dmax = bounds[i];
  5084. }
  5085. var rmin = encode[2 * i];
  5086. var rmax = encode[2 * i + 1];
  5087. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5088. // call the appropriate function
  5089. fns[i](tmpBuf, 0, dest, destOffset);
  5090. };
  5091. },
  5092. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5093. xref) {
  5094. var domain = dict.get('Domain');
  5095. var range = dict.get('Range');
  5096. if (!domain) {
  5097. error('No domain.');
  5098. }
  5099. if (!range) {
  5100. error('No range.');
  5101. }
  5102. var lexer = new PostScriptLexer(fn);
  5103. var parser = new PostScriptParser(lexer);
  5104. var code = parser.parse();
  5105. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5106. },
  5107. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5108. IR) {
  5109. var domain = IR[1];
  5110. var range = IR[2];
  5111. var code = IR[3];
  5112. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5113. if (compiled) {
  5114. // Compiled function consists of simple expressions such as addition,
  5115. // subtraction, Math.max, and also contains 'var' and 'return'
  5116. // statements. See the generation in the PostScriptCompiler below.
  5117. /*jshint -W054 */
  5118. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5119. }
  5120. info('Unable to compile PS function');
  5121. var numOutputs = range.length >> 1;
  5122. var numInputs = domain.length >> 1;
  5123. var evaluator = new PostScriptEvaluator(code);
  5124. // Cache the values for a big speed up, the cache size is limited though
  5125. // since the number of possible values can be huge from a PS function.
  5126. var cache = {};
  5127. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5128. // seen in our tests.
  5129. var MAX_CACHE_SIZE = 2048 * 4;
  5130. var cache_available = MAX_CACHE_SIZE;
  5131. var tmpBuf = new Float32Array(numInputs);
  5132. return function constructPostScriptFromIRResult(src, srcOffset,
  5133. dest, destOffset) {
  5134. var i, value;
  5135. var key = '';
  5136. var input = tmpBuf;
  5137. for (i = 0; i < numInputs; i++) {
  5138. value = src[srcOffset + i];
  5139. input[i] = value;
  5140. key += value + '_';
  5141. }
  5142. var cachedValue = cache[key];
  5143. if (cachedValue !== undefined) {
  5144. dest.set(cachedValue, destOffset);
  5145. return;
  5146. }
  5147. var output = new Float32Array(numOutputs);
  5148. var stack = evaluator.execute(input);
  5149. var stackIndex = stack.length - numOutputs;
  5150. for (i = 0; i < numOutputs; i++) {
  5151. value = stack[stackIndex + i];
  5152. var bound = range[i * 2];
  5153. if (value < bound) {
  5154. value = bound;
  5155. } else {
  5156. bound = range[i * 2 +1];
  5157. if (value > bound) {
  5158. value = bound;
  5159. }
  5160. }
  5161. output[i] = value;
  5162. }
  5163. if (cache_available > 0) {
  5164. cache_available--;
  5165. cache[key] = output;
  5166. }
  5167. dest.set(output, destOffset);
  5168. };
  5169. }
  5170. };
  5171. })();
  5172. function isPDFFunction(v) {
  5173. var fnDict;
  5174. if (typeof v !== 'object') {
  5175. return false;
  5176. } else if (isDict(v)) {
  5177. fnDict = v;
  5178. } else if (isStream(v)) {
  5179. fnDict = v.dict;
  5180. } else {
  5181. return false;
  5182. }
  5183. return fnDict.has('FunctionType');
  5184. }
  5185. var PostScriptStack = (function PostScriptStackClosure() {
  5186. var MAX_STACK_SIZE = 100;
  5187. function PostScriptStack(initialStack) {
  5188. this.stack = !initialStack ? [] :
  5189. Array.prototype.slice.call(initialStack, 0);
  5190. }
  5191. PostScriptStack.prototype = {
  5192. push: function PostScriptStack_push(value) {
  5193. if (this.stack.length >= MAX_STACK_SIZE) {
  5194. error('PostScript function stack overflow.');
  5195. }
  5196. this.stack.push(value);
  5197. },
  5198. pop: function PostScriptStack_pop() {
  5199. if (this.stack.length <= 0) {
  5200. error('PostScript function stack underflow.');
  5201. }
  5202. return this.stack.pop();
  5203. },
  5204. copy: function PostScriptStack_copy(n) {
  5205. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5206. error('PostScript function stack overflow.');
  5207. }
  5208. var stack = this.stack;
  5209. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5210. stack.push(stack[i]);
  5211. }
  5212. },
  5213. index: function PostScriptStack_index(n) {
  5214. this.push(this.stack[this.stack.length - n - 1]);
  5215. },
  5216. // rotate the last n stack elements p times
  5217. roll: function PostScriptStack_roll(n, p) {
  5218. var stack = this.stack;
  5219. var l = stack.length - n;
  5220. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5221. for (i = l, j = r; i < j; i++, j--) {
  5222. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5223. }
  5224. for (i = l, j = c - 1; i < j; i++, j--) {
  5225. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5226. }
  5227. for (i = c, j = r; i < j; i++, j--) {
  5228. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5229. }
  5230. }
  5231. };
  5232. return PostScriptStack;
  5233. })();
  5234. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5235. function PostScriptEvaluator(operators) {
  5236. this.operators = operators;
  5237. }
  5238. PostScriptEvaluator.prototype = {
  5239. execute: function PostScriptEvaluator_execute(initialStack) {
  5240. var stack = new PostScriptStack(initialStack);
  5241. var counter = 0;
  5242. var operators = this.operators;
  5243. var length = operators.length;
  5244. var operator, a, b;
  5245. while (counter < length) {
  5246. operator = operators[counter++];
  5247. if (typeof operator === 'number') {
  5248. // Operator is really an operand and should be pushed to the stack.
  5249. stack.push(operator);
  5250. continue;
  5251. }
  5252. switch (operator) {
  5253. // non standard ps operators
  5254. case 'jz': // jump if false
  5255. b = stack.pop();
  5256. a = stack.pop();
  5257. if (!a) {
  5258. counter = b;
  5259. }
  5260. break;
  5261. case 'j': // jump
  5262. a = stack.pop();
  5263. counter = a;
  5264. break;
  5265. // all ps operators in alphabetical order (excluding if/ifelse)
  5266. case 'abs':
  5267. a = stack.pop();
  5268. stack.push(Math.abs(a));
  5269. break;
  5270. case 'add':
  5271. b = stack.pop();
  5272. a = stack.pop();
  5273. stack.push(a + b);
  5274. break;
  5275. case 'and':
  5276. b = stack.pop();
  5277. a = stack.pop();
  5278. if (isBool(a) && isBool(b)) {
  5279. stack.push(a && b);
  5280. } else {
  5281. stack.push(a & b);
  5282. }
  5283. break;
  5284. case 'atan':
  5285. a = stack.pop();
  5286. stack.push(Math.atan(a));
  5287. break;
  5288. case 'bitshift':
  5289. b = stack.pop();
  5290. a = stack.pop();
  5291. if (a > 0) {
  5292. stack.push(a << b);
  5293. } else {
  5294. stack.push(a >> b);
  5295. }
  5296. break;
  5297. case 'ceiling':
  5298. a = stack.pop();
  5299. stack.push(Math.ceil(a));
  5300. break;
  5301. case 'copy':
  5302. a = stack.pop();
  5303. stack.copy(a);
  5304. break;
  5305. case 'cos':
  5306. a = stack.pop();
  5307. stack.push(Math.cos(a));
  5308. break;
  5309. case 'cvi':
  5310. a = stack.pop() | 0;
  5311. stack.push(a);
  5312. break;
  5313. case 'cvr':
  5314. // noop
  5315. break;
  5316. case 'div':
  5317. b = stack.pop();
  5318. a = stack.pop();
  5319. stack.push(a / b);
  5320. break;
  5321. case 'dup':
  5322. stack.copy(1);
  5323. break;
  5324. case 'eq':
  5325. b = stack.pop();
  5326. a = stack.pop();
  5327. stack.push(a === b);
  5328. break;
  5329. case 'exch':
  5330. stack.roll(2, 1);
  5331. break;
  5332. case 'exp':
  5333. b = stack.pop();
  5334. a = stack.pop();
  5335. stack.push(Math.pow(a, b));
  5336. break;
  5337. case 'false':
  5338. stack.push(false);
  5339. break;
  5340. case 'floor':
  5341. a = stack.pop();
  5342. stack.push(Math.floor(a));
  5343. break;
  5344. case 'ge':
  5345. b = stack.pop();
  5346. a = stack.pop();
  5347. stack.push(a >= b);
  5348. break;
  5349. case 'gt':
  5350. b = stack.pop();
  5351. a = stack.pop();
  5352. stack.push(a > b);
  5353. break;
  5354. case 'idiv':
  5355. b = stack.pop();
  5356. a = stack.pop();
  5357. stack.push((a / b) | 0);
  5358. break;
  5359. case 'index':
  5360. a = stack.pop();
  5361. stack.index(a);
  5362. break;
  5363. case 'le':
  5364. b = stack.pop();
  5365. a = stack.pop();
  5366. stack.push(a <= b);
  5367. break;
  5368. case 'ln':
  5369. a = stack.pop();
  5370. stack.push(Math.log(a));
  5371. break;
  5372. case 'log':
  5373. a = stack.pop();
  5374. stack.push(Math.log(a) / Math.LN10);
  5375. break;
  5376. case 'lt':
  5377. b = stack.pop();
  5378. a = stack.pop();
  5379. stack.push(a < b);
  5380. break;
  5381. case 'mod':
  5382. b = stack.pop();
  5383. a = stack.pop();
  5384. stack.push(a % b);
  5385. break;
  5386. case 'mul':
  5387. b = stack.pop();
  5388. a = stack.pop();
  5389. stack.push(a * b);
  5390. break;
  5391. case 'ne':
  5392. b = stack.pop();
  5393. a = stack.pop();
  5394. stack.push(a !== b);
  5395. break;
  5396. case 'neg':
  5397. a = stack.pop();
  5398. stack.push(-a);
  5399. break;
  5400. case 'not':
  5401. a = stack.pop();
  5402. if (isBool(a)) {
  5403. stack.push(!a);
  5404. } else {
  5405. stack.push(~a);
  5406. }
  5407. break;
  5408. case 'or':
  5409. b = stack.pop();
  5410. a = stack.pop();
  5411. if (isBool(a) && isBool(b)) {
  5412. stack.push(a || b);
  5413. } else {
  5414. stack.push(a | b);
  5415. }
  5416. break;
  5417. case 'pop':
  5418. stack.pop();
  5419. break;
  5420. case 'roll':
  5421. b = stack.pop();
  5422. a = stack.pop();
  5423. stack.roll(a, b);
  5424. break;
  5425. case 'round':
  5426. a = stack.pop();
  5427. stack.push(Math.round(a));
  5428. break;
  5429. case 'sin':
  5430. a = stack.pop();
  5431. stack.push(Math.sin(a));
  5432. break;
  5433. case 'sqrt':
  5434. a = stack.pop();
  5435. stack.push(Math.sqrt(a));
  5436. break;
  5437. case 'sub':
  5438. b = stack.pop();
  5439. a = stack.pop();
  5440. stack.push(a - b);
  5441. break;
  5442. case 'true':
  5443. stack.push(true);
  5444. break;
  5445. case 'truncate':
  5446. a = stack.pop();
  5447. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5448. stack.push(a);
  5449. break;
  5450. case 'xor':
  5451. b = stack.pop();
  5452. a = stack.pop();
  5453. if (isBool(a) && isBool(b)) {
  5454. stack.push(a !== b);
  5455. } else {
  5456. stack.push(a ^ b);
  5457. }
  5458. break;
  5459. default:
  5460. error('Unknown operator ' + operator);
  5461. break;
  5462. }
  5463. }
  5464. return stack.stack;
  5465. }
  5466. };
  5467. return PostScriptEvaluator;
  5468. })();
  5469. // Most of the PDFs functions consist of simple operations such as:
  5470. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5471. //
  5472. // We can compile most of such programs, and at the same moment, we can
  5473. // optimize some expressions using basic math properties. Keeping track of
  5474. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5475. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5476. function AstNode(type) {
  5477. this.type = type;
  5478. }
  5479. AstNode.prototype.visit = function (visitor) {
  5480. throw new Error('abstract method');
  5481. };
  5482. function AstArgument(index, min, max) {
  5483. AstNode.call(this, 'args');
  5484. this.index = index;
  5485. this.min = min;
  5486. this.max = max;
  5487. }
  5488. AstArgument.prototype = Object.create(AstNode.prototype);
  5489. AstArgument.prototype.visit = function (visitor) {
  5490. visitor.visitArgument(this);
  5491. };
  5492. function AstLiteral(number) {
  5493. AstNode.call(this, 'literal');
  5494. this.number = number;
  5495. this.min = number;
  5496. this.max = number;
  5497. }
  5498. AstLiteral.prototype = Object.create(AstNode.prototype);
  5499. AstLiteral.prototype.visit = function (visitor) {
  5500. visitor.visitLiteral(this);
  5501. };
  5502. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5503. AstNode.call(this, 'binary');
  5504. this.op = op;
  5505. this.arg1 = arg1;
  5506. this.arg2 = arg2;
  5507. this.min = min;
  5508. this.max = max;
  5509. }
  5510. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5511. AstBinaryOperation.prototype.visit = function (visitor) {
  5512. visitor.visitBinaryOperation(this);
  5513. };
  5514. function AstMin(arg, max) {
  5515. AstNode.call(this, 'max');
  5516. this.arg = arg;
  5517. this.min = arg.min;
  5518. this.max = max;
  5519. }
  5520. AstMin.prototype = Object.create(AstNode.prototype);
  5521. AstMin.prototype.visit = function (visitor) {
  5522. visitor.visitMin(this);
  5523. };
  5524. function AstVariable(index, min, max) {
  5525. AstNode.call(this, 'var');
  5526. this.index = index;
  5527. this.min = min;
  5528. this.max = max;
  5529. }
  5530. AstVariable.prototype = Object.create(AstNode.prototype);
  5531. AstVariable.prototype.visit = function (visitor) {
  5532. visitor.visitVariable(this);
  5533. };
  5534. function AstVariableDefinition(variable, arg) {
  5535. AstNode.call(this, 'definition');
  5536. this.variable = variable;
  5537. this.arg = arg;
  5538. }
  5539. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5540. AstVariableDefinition.prototype.visit = function (visitor) {
  5541. visitor.visitVariableDefinition(this);
  5542. };
  5543. function ExpressionBuilderVisitor() {
  5544. this.parts = [];
  5545. }
  5546. ExpressionBuilderVisitor.prototype = {
  5547. visitArgument: function (arg) {
  5548. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5549. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5550. },
  5551. visitVariable: function (variable) {
  5552. this.parts.push('v', variable.index);
  5553. },
  5554. visitLiteral: function (literal) {
  5555. this.parts.push(literal.number);
  5556. },
  5557. visitBinaryOperation: function (operation) {
  5558. this.parts.push('(');
  5559. operation.arg1.visit(this);
  5560. this.parts.push(' ', operation.op, ' ');
  5561. operation.arg2.visit(this);
  5562. this.parts.push(')');
  5563. },
  5564. visitVariableDefinition: function (definition) {
  5565. this.parts.push('var ');
  5566. definition.variable.visit(this);
  5567. this.parts.push(' = ');
  5568. definition.arg.visit(this);
  5569. this.parts.push(';');
  5570. },
  5571. visitMin: function (max) {
  5572. this.parts.push('Math.min(');
  5573. max.arg.visit(this);
  5574. this.parts.push(', ', max.max, ')');
  5575. },
  5576. toString: function () {
  5577. return this.parts.join('');
  5578. }
  5579. };
  5580. function buildAddOperation(num1, num2) {
  5581. if (num2.type === 'literal' && num2.number === 0) {
  5582. // optimization: second operand is 0
  5583. return num1;
  5584. }
  5585. if (num1.type === 'literal' && num1.number === 0) {
  5586. // optimization: first operand is 0
  5587. return num2;
  5588. }
  5589. if (num2.type === 'literal' && num1.type === 'literal') {
  5590. // optimization: operands operand are literals
  5591. return new AstLiteral(num1.number + num2.number);
  5592. }
  5593. return new AstBinaryOperation('+', num1, num2,
  5594. num1.min + num2.min, num1.max + num2.max);
  5595. }
  5596. function buildMulOperation(num1, num2) {
  5597. if (num2.type === 'literal') {
  5598. // optimization: second operands is a literal...
  5599. if (num2.number === 0) {
  5600. return new AstLiteral(0); // and it's 0
  5601. } else if (num2.number === 1) {
  5602. return num1; // and it's 1
  5603. } else if (num1.type === 'literal') {
  5604. // ... and first operands is a literal too
  5605. return new AstLiteral(num1.number * num2.number);
  5606. }
  5607. }
  5608. if (num1.type === 'literal') {
  5609. // optimization: first operands is a literal...
  5610. if (num1.number === 0) {
  5611. return new AstLiteral(0); // and it's 0
  5612. } else if (num1.number === 1) {
  5613. return num2; // and it's 1
  5614. }
  5615. }
  5616. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5617. num1.max * num2.min, num1.max * num2.max);
  5618. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5619. num1.max * num2.min, num1.max * num2.max);
  5620. return new AstBinaryOperation('*', num1, num2, min, max);
  5621. }
  5622. function buildSubOperation(num1, num2) {
  5623. if (num2.type === 'literal') {
  5624. // optimization: second operands is a literal...
  5625. if (num2.number === 0) {
  5626. return num1; // ... and it's 0
  5627. } else if (num1.type === 'literal') {
  5628. // ... and first operands is a literal too
  5629. return new AstLiteral(num1.number - num2.number);
  5630. }
  5631. }
  5632. if (num2.type === 'binary' && num2.op === '-' &&
  5633. num1.type === 'literal' && num1.number === 1 &&
  5634. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5635. // optimization for case: 1 - (1 - x)
  5636. return num2.arg2;
  5637. }
  5638. return new AstBinaryOperation('-', num1, num2,
  5639. num1.min - num2.max, num1.max - num2.min);
  5640. }
  5641. function buildMinOperation(num1, max) {
  5642. if (num1.min >= max) {
  5643. // optimization: num1 min value is not less than required max
  5644. return new AstLiteral(max); // just returning max
  5645. } else if (num1.max <= max) {
  5646. // optimization: num1 max value is not greater than required max
  5647. return num1; // just returning an argument
  5648. }
  5649. return new AstMin(num1, max);
  5650. }
  5651. function PostScriptCompiler() {}
  5652. PostScriptCompiler.prototype = {
  5653. compile: function PostScriptCompiler_compile(code, domain, range) {
  5654. var stack = [];
  5655. var i, ii;
  5656. var instructions = [];
  5657. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5658. var lastRegister = 0;
  5659. var n, j, min, max;
  5660. var num1, num2, ast1, ast2, tmpVar, item;
  5661. for (i = 0; i < inputSize; i++) {
  5662. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5663. }
  5664. for (i = 0, ii = code.length; i < ii; i++) {
  5665. item = code[i];
  5666. if (typeof item === 'number') {
  5667. stack.push(new AstLiteral(item));
  5668. continue;
  5669. }
  5670. switch (item) {
  5671. case 'add':
  5672. if (stack.length < 2) {
  5673. return null;
  5674. }
  5675. num2 = stack.pop();
  5676. num1 = stack.pop();
  5677. stack.push(buildAddOperation(num1, num2));
  5678. break;
  5679. case 'cvr':
  5680. if (stack.length < 1) {
  5681. return null;
  5682. }
  5683. break;
  5684. case 'mul':
  5685. if (stack.length < 2) {
  5686. return null;
  5687. }
  5688. num2 = stack.pop();
  5689. num1 = stack.pop();
  5690. stack.push(buildMulOperation(num1, num2));
  5691. break;
  5692. case 'sub':
  5693. if (stack.length < 2) {
  5694. return null;
  5695. }
  5696. num2 = stack.pop();
  5697. num1 = stack.pop();
  5698. stack.push(buildSubOperation(num1, num2));
  5699. break;
  5700. case 'exch':
  5701. if (stack.length < 2) {
  5702. return null;
  5703. }
  5704. ast1 = stack.pop(); ast2 = stack.pop();
  5705. stack.push(ast1, ast2);
  5706. break;
  5707. case 'pop':
  5708. if (stack.length < 1) {
  5709. return null;
  5710. }
  5711. stack.pop();
  5712. break;
  5713. case 'index':
  5714. if (stack.length < 1) {
  5715. return null;
  5716. }
  5717. num1 = stack.pop();
  5718. if (num1.type !== 'literal') {
  5719. return null;
  5720. }
  5721. n = num1.number;
  5722. if (n < 0 || (n|0) !== n || stack.length < n) {
  5723. return null;
  5724. }
  5725. ast1 = stack[stack.length - n - 1];
  5726. if (ast1.type === 'literal' || ast1.type === 'var') {
  5727. stack.push(ast1);
  5728. break;
  5729. }
  5730. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5731. stack[stack.length - n - 1] = tmpVar;
  5732. stack.push(tmpVar);
  5733. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5734. break;
  5735. case 'dup':
  5736. if (stack.length < 1) {
  5737. return null;
  5738. }
  5739. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5740. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5741. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5742. // special case of the commands sequence for the min operation
  5743. num1 = stack.pop();
  5744. stack.push(buildMinOperation(num1, code[i + 1]));
  5745. i += 6;
  5746. break;
  5747. }
  5748. ast1 = stack[stack.length - 1];
  5749. if (ast1.type === 'literal' || ast1.type === 'var') {
  5750. // we don't have to save into intermediate variable a literal or
  5751. // variable.
  5752. stack.push(ast1);
  5753. break;
  5754. }
  5755. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5756. stack[stack.length - 1] = tmpVar;
  5757. stack.push(tmpVar);
  5758. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5759. break;
  5760. case 'roll':
  5761. if (stack.length < 2) {
  5762. return null;
  5763. }
  5764. num2 = stack.pop();
  5765. num1 = stack.pop();
  5766. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5767. // both roll operands must be numbers
  5768. return null;
  5769. }
  5770. j = num2.number;
  5771. n = num1.number;
  5772. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5773. // ... and integers
  5774. return null;
  5775. }
  5776. j = ((j % n) + n) % n;
  5777. if (j === 0) {
  5778. break; // just skipping -- there are nothing to rotate
  5779. }
  5780. Array.prototype.push.apply(stack,
  5781. stack.splice(stack.length - n, n - j));
  5782. break;
  5783. default:
  5784. return null; // unsupported operator
  5785. }
  5786. }
  5787. if (stack.length !== outputSize) {
  5788. return null;
  5789. }
  5790. var result = [];
  5791. instructions.forEach(function (instruction) {
  5792. var statementBuilder = new ExpressionBuilderVisitor();
  5793. instruction.visit(statementBuilder);
  5794. result.push(statementBuilder.toString());
  5795. });
  5796. stack.forEach(function (expr, i) {
  5797. var statementBuilder = new ExpressionBuilderVisitor();
  5798. expr.visit(statementBuilder);
  5799. var min = range[i * 2], max = range[i * 2 + 1];
  5800. var out = [statementBuilder.toString()];
  5801. if (min > expr.min) {
  5802. out.unshift('Math.max(', min, ', ');
  5803. out.push(')');
  5804. }
  5805. if (max < expr.max) {
  5806. out.unshift('Math.min(', max, ', ');
  5807. out.push(')');
  5808. }
  5809. out.unshift('dest[destOffset + ', i, '] = ');
  5810. out.push(';');
  5811. result.push(out.join(''));
  5812. });
  5813. return result.join('\n');
  5814. }
  5815. };
  5816. return PostScriptCompiler;
  5817. })();
  5818. var ColorSpace = (function ColorSpaceClosure() {
  5819. // Constructor should define this.numComps, this.defaultColor, this.name
  5820. function ColorSpace() {
  5821. error('should not call ColorSpace constructor');
  5822. }
  5823. ColorSpace.prototype = {
  5824. /**
  5825. * Converts the color value to the RGB color. The color components are
  5826. * located in the src array starting from the srcOffset. Returns the array
  5827. * of the rgb components, each value ranging from [0,255].
  5828. */
  5829. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5830. var rgb = new Uint8Array(3);
  5831. this.getRgbItem(src, srcOffset, rgb, 0);
  5832. return rgb;
  5833. },
  5834. /**
  5835. * Converts the color value to the RGB color, similar to the getRgb method.
  5836. * The result placed into the dest array starting from the destOffset.
  5837. */
  5838. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5839. dest, destOffset) {
  5840. error('Should not call ColorSpace.getRgbItem');
  5841. },
  5842. /**
  5843. * Converts the specified number of the color values to the RGB colors.
  5844. * The colors are located in the src array starting from the srcOffset.
  5845. * The result is placed into the dest array starting from the destOffset.
  5846. * The src array items shall be in [0,2^bits) range, the dest array items
  5847. * will be in [0,255] range. alpha01 indicates how many alpha components
  5848. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5849. * array).
  5850. */
  5851. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5852. dest, destOffset, bits,
  5853. alpha01) {
  5854. error('Should not call ColorSpace.getRgbBuffer');
  5855. },
  5856. /**
  5857. * Determines the number of bytes required to store the result of the
  5858. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5859. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5860. */
  5861. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5862. alpha01) {
  5863. error('Should not call ColorSpace.getOutputLength');
  5864. },
  5865. /**
  5866. * Returns true if source data will be equal the result/output data.
  5867. */
  5868. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5869. return false;
  5870. },
  5871. /**
  5872. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5873. * how many alpha components there are in the dest array; it will be either
  5874. * 0 (RGB array) or 1 (RGBA array).
  5875. */
  5876. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5877. originalHeight, width, height,
  5878. actualHeight, bpc, comps, alpha01) {
  5879. var count = originalWidth * originalHeight;
  5880. var rgbBuf = null;
  5881. var numComponentColors = 1 << bpc;
  5882. var needsResizing = originalHeight !== height || originalWidth !== width;
  5883. var i, ii;
  5884. if (this.isPassthrough(bpc)) {
  5885. rgbBuf = comps;
  5886. } else if (this.numComps === 1 && count > numComponentColors &&
  5887. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5888. // Optimization: create a color map when there is just one component and
  5889. // we are converting more colors than the size of the color map. We
  5890. // don't build the map if the colorspace is gray or rgb since those
  5891. // methods are faster than building a map. This mainly offers big speed
  5892. // ups for indexed and alternate colorspaces.
  5893. //
  5894. // TODO it may be worth while to cache the color map. While running
  5895. // testing I never hit a cache so I will leave that out for now (perhaps
  5896. // we are reparsing colorspaces too much?).
  5897. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5898. new Uint16Array(numComponentColors);
  5899. var key;
  5900. for (i = 0; i < numComponentColors; i++) {
  5901. allColors[i] = i;
  5902. }
  5903. var colorMap = new Uint8Array(numComponentColors * 3);
  5904. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5905. /* alpha01 = */ 0);
  5906. var destPos, rgbPos;
  5907. if (!needsResizing) {
  5908. // Fill in the RGB values directly into |dest|.
  5909. destPos = 0;
  5910. for (i = 0; i < count; ++i) {
  5911. key = comps[i] * 3;
  5912. dest[destPos++] = colorMap[key];
  5913. dest[destPos++] = colorMap[key + 1];
  5914. dest[destPos++] = colorMap[key + 2];
  5915. destPos += alpha01;
  5916. }
  5917. } else {
  5918. rgbBuf = new Uint8Array(count * 3);
  5919. rgbPos = 0;
  5920. for (i = 0; i < count; ++i) {
  5921. key = comps[i] * 3;
  5922. rgbBuf[rgbPos++] = colorMap[key];
  5923. rgbBuf[rgbPos++] = colorMap[key + 1];
  5924. rgbBuf[rgbPos++] = colorMap[key + 2];
  5925. }
  5926. }
  5927. } else {
  5928. if (!needsResizing) {
  5929. // Fill in the RGB values directly into |dest|.
  5930. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5931. alpha01);
  5932. } else {
  5933. rgbBuf = new Uint8Array(count * 3);
  5934. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5935. /* alpha01 = */ 0);
  5936. }
  5937. }
  5938. if (rgbBuf) {
  5939. if (needsResizing) {
  5940. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5941. height, dest, alpha01);
  5942. } else {
  5943. rgbPos = 0;
  5944. destPos = 0;
  5945. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5946. dest[destPos++] = rgbBuf[rgbPos++];
  5947. dest[destPos++] = rgbBuf[rgbPos++];
  5948. dest[destPos++] = rgbBuf[rgbPos++];
  5949. destPos += alpha01;
  5950. }
  5951. }
  5952. }
  5953. },
  5954. /**
  5955. * True if the colorspace has components in the default range of [0, 1].
  5956. * This should be true for all colorspaces except for lab color spaces
  5957. * which are [0,100], [-128, 127], [-128, 127].
  5958. */
  5959. usesZeroToOneRange: true
  5960. };
  5961. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5962. var IR = ColorSpace.parseToIR(cs, xref, res);
  5963. if (IR instanceof AlternateCS) {
  5964. return IR;
  5965. }
  5966. return ColorSpace.fromIR(IR);
  5967. };
  5968. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5969. var name = isArray(IR) ? IR[0] : IR;
  5970. var whitePoint, blackPoint, gamma;
  5971. switch (name) {
  5972. case 'DeviceGrayCS':
  5973. return this.singletons.gray;
  5974. case 'DeviceRgbCS':
  5975. return this.singletons.rgb;
  5976. case 'DeviceCmykCS':
  5977. return this.singletons.cmyk;
  5978. case 'CalGrayCS':
  5979. whitePoint = IR[1].WhitePoint;
  5980. blackPoint = IR[1].BlackPoint;
  5981. gamma = IR[1].Gamma;
  5982. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5983. case 'CalRGBCS':
  5984. whitePoint = IR[1].WhitePoint;
  5985. blackPoint = IR[1].BlackPoint;
  5986. gamma = IR[1].Gamma;
  5987. var matrix = IR[1].Matrix;
  5988. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5989. case 'PatternCS':
  5990. var basePatternCS = IR[1];
  5991. if (basePatternCS) {
  5992. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5993. }
  5994. return new PatternCS(basePatternCS);
  5995. case 'IndexedCS':
  5996. var baseIndexedCS = IR[1];
  5997. var hiVal = IR[2];
  5998. var lookup = IR[3];
  5999. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6000. case 'AlternateCS':
  6001. var numComps = IR[1];
  6002. var alt = IR[2];
  6003. var tintFnIR = IR[3];
  6004. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6005. PDFFunction.fromIR(tintFnIR));
  6006. case 'LabCS':
  6007. whitePoint = IR[1].WhitePoint;
  6008. blackPoint = IR[1].BlackPoint;
  6009. var range = IR[1].Range;
  6010. return new LabCS(whitePoint, blackPoint, range);
  6011. default:
  6012. error('Unknown name ' + name);
  6013. }
  6014. return null;
  6015. };
  6016. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6017. if (isName(cs)) {
  6018. var colorSpaces = res.get('ColorSpace');
  6019. if (isDict(colorSpaces)) {
  6020. var refcs = colorSpaces.get(cs.name);
  6021. if (refcs) {
  6022. cs = refcs;
  6023. }
  6024. }
  6025. }
  6026. cs = xref.fetchIfRef(cs);
  6027. var mode;
  6028. if (isName(cs)) {
  6029. mode = cs.name;
  6030. this.mode = mode;
  6031. switch (mode) {
  6032. case 'DeviceGray':
  6033. case 'G':
  6034. return 'DeviceGrayCS';
  6035. case 'DeviceRGB':
  6036. case 'RGB':
  6037. return 'DeviceRgbCS';
  6038. case 'DeviceCMYK':
  6039. case 'CMYK':
  6040. return 'DeviceCmykCS';
  6041. case 'Pattern':
  6042. return ['PatternCS', null];
  6043. default:
  6044. error('unrecognized colorspace ' + mode);
  6045. }
  6046. } else if (isArray(cs)) {
  6047. mode = cs[0].name;
  6048. this.mode = mode;
  6049. var numComps, params;
  6050. switch (mode) {
  6051. case 'DeviceGray':
  6052. case 'G':
  6053. return 'DeviceGrayCS';
  6054. case 'DeviceRGB':
  6055. case 'RGB':
  6056. return 'DeviceRgbCS';
  6057. case 'DeviceCMYK':
  6058. case 'CMYK':
  6059. return 'DeviceCmykCS';
  6060. case 'CalGray':
  6061. params = cs[1].getAll();
  6062. return ['CalGrayCS', params];
  6063. case 'CalRGB':
  6064. params = cs[1].getAll();
  6065. return ['CalRGBCS', params];
  6066. case 'ICCBased':
  6067. var stream = xref.fetchIfRef(cs[1]);
  6068. var dict = stream.dict;
  6069. numComps = dict.get('N');
  6070. if (numComps === 1) {
  6071. return 'DeviceGrayCS';
  6072. } else if (numComps === 3) {
  6073. return 'DeviceRgbCS';
  6074. } else if (numComps === 4) {
  6075. return 'DeviceCmykCS';
  6076. }
  6077. break;
  6078. case 'Pattern':
  6079. var basePatternCS = cs[1];
  6080. if (basePatternCS) {
  6081. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6082. }
  6083. return ['PatternCS', basePatternCS];
  6084. case 'Indexed':
  6085. case 'I':
  6086. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6087. var hiVal = cs[2] + 1;
  6088. var lookup = xref.fetchIfRef(cs[3]);
  6089. if (isStream(lookup)) {
  6090. lookup = lookup.getBytes();
  6091. }
  6092. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6093. case 'Separation':
  6094. case 'DeviceN':
  6095. var name = cs[1];
  6096. numComps = 1;
  6097. if (isName(name)) {
  6098. numComps = 1;
  6099. } else if (isArray(name)) {
  6100. numComps = name.length;
  6101. }
  6102. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6103. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6104. return ['AlternateCS', numComps, alt, tintFnIR];
  6105. case 'Lab':
  6106. params = cs[1].getAll();
  6107. return ['LabCS', params];
  6108. default:
  6109. error('unimplemented color space object "' + mode + '"');
  6110. }
  6111. } else {
  6112. error('unrecognized color space object: "' + cs + '"');
  6113. }
  6114. return null;
  6115. };
  6116. /**
  6117. * Checks if a decode map matches the default decode map for a color space.
  6118. * This handles the general decode maps where there are two values per
  6119. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6120. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6121. * slightly different.
  6122. * @param {Array} decode Decode map (usually from an image).
  6123. * @param {Number} n Number of components the color space has.
  6124. */
  6125. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6126. if (!decode) {
  6127. return true;
  6128. }
  6129. if (n * 2 !== decode.length) {
  6130. warn('The decode map is not the correct length');
  6131. return true;
  6132. }
  6133. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6134. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6135. return false;
  6136. }
  6137. }
  6138. return true;
  6139. };
  6140. ColorSpace.singletons = {
  6141. get gray() {
  6142. return shadow(this, 'gray', new DeviceGrayCS());
  6143. },
  6144. get rgb() {
  6145. return shadow(this, 'rgb', new DeviceRgbCS());
  6146. },
  6147. get cmyk() {
  6148. return shadow(this, 'cmyk', new DeviceCmykCS());
  6149. }
  6150. };
  6151. return ColorSpace;
  6152. })();
  6153. /**
  6154. * Alternate color space handles both Separation and DeviceN color spaces. A
  6155. * Separation color space is actually just a DeviceN with one color component.
  6156. * Both color spaces use a tinting function to convert colors to a base color
  6157. * space.
  6158. */
  6159. var AlternateCS = (function AlternateCSClosure() {
  6160. function AlternateCS(numComps, base, tintFn) {
  6161. this.name = 'Alternate';
  6162. this.numComps = numComps;
  6163. this.defaultColor = new Float32Array(numComps);
  6164. for (var i = 0; i < numComps; ++i) {
  6165. this.defaultColor[i] = 1;
  6166. }
  6167. this.base = base;
  6168. this.tintFn = tintFn;
  6169. this.tmpBuf = new Float32Array(base.numComps);
  6170. }
  6171. AlternateCS.prototype = {
  6172. getRgb: ColorSpace.prototype.getRgb,
  6173. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6174. dest, destOffset) {
  6175. var tmpBuf = this.tmpBuf;
  6176. this.tintFn(src, srcOffset, tmpBuf, 0);
  6177. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6178. },
  6179. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6180. dest, destOffset, bits,
  6181. alpha01) {
  6182. var tintFn = this.tintFn;
  6183. var base = this.base;
  6184. var scale = 1 / ((1 << bits) - 1);
  6185. var baseNumComps = base.numComps;
  6186. var usesZeroToOneRange = base.usesZeroToOneRange;
  6187. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6188. alpha01 === 0;
  6189. var pos = isPassthrough ? destOffset : 0;
  6190. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6191. var numComps = this.numComps;
  6192. var scaled = new Float32Array(numComps);
  6193. var tinted = new Float32Array(baseNumComps);
  6194. var i, j;
  6195. if (usesZeroToOneRange) {
  6196. for (i = 0; i < count; i++) {
  6197. for (j = 0; j < numComps; j++) {
  6198. scaled[j] = src[srcOffset++] * scale;
  6199. }
  6200. tintFn(scaled, 0, tinted, 0);
  6201. for (j = 0; j < baseNumComps; j++) {
  6202. baseBuf[pos++] = tinted[j] * 255;
  6203. }
  6204. }
  6205. } else {
  6206. for (i = 0; i < count; i++) {
  6207. for (j = 0; j < numComps; j++) {
  6208. scaled[j] = src[srcOffset++] * scale;
  6209. }
  6210. tintFn(scaled, 0, tinted, 0);
  6211. base.getRgbItem(tinted, 0, baseBuf, pos);
  6212. pos += baseNumComps;
  6213. }
  6214. }
  6215. if (!isPassthrough) {
  6216. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6217. }
  6218. },
  6219. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6220. alpha01) {
  6221. return this.base.getOutputLength(inputLength *
  6222. this.base.numComps / this.numComps,
  6223. alpha01);
  6224. },
  6225. isPassthrough: ColorSpace.prototype.isPassthrough,
  6226. fillRgb: ColorSpace.prototype.fillRgb,
  6227. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6228. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6229. },
  6230. usesZeroToOneRange: true
  6231. };
  6232. return AlternateCS;
  6233. })();
  6234. var PatternCS = (function PatternCSClosure() {
  6235. function PatternCS(baseCS) {
  6236. this.name = 'Pattern';
  6237. this.base = baseCS;
  6238. }
  6239. PatternCS.prototype = {};
  6240. return PatternCS;
  6241. })();
  6242. var IndexedCS = (function IndexedCSClosure() {
  6243. function IndexedCS(base, highVal, lookup) {
  6244. this.name = 'Indexed';
  6245. this.numComps = 1;
  6246. this.defaultColor = new Uint8Array([0]);
  6247. this.base = base;
  6248. this.highVal = highVal;
  6249. var baseNumComps = base.numComps;
  6250. var length = baseNumComps * highVal;
  6251. var lookupArray;
  6252. if (isStream(lookup)) {
  6253. lookupArray = new Uint8Array(length);
  6254. var bytes = lookup.getBytes(length);
  6255. lookupArray.set(bytes);
  6256. } else if (isString(lookup)) {
  6257. lookupArray = new Uint8Array(length);
  6258. for (var i = 0; i < length; ++i) {
  6259. lookupArray[i] = lookup.charCodeAt(i);
  6260. }
  6261. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6262. lookupArray = lookup;
  6263. } else {
  6264. error('Unrecognized lookup table: ' + lookup);
  6265. }
  6266. this.lookup = lookupArray;
  6267. }
  6268. IndexedCS.prototype = {
  6269. getRgb: ColorSpace.prototype.getRgb,
  6270. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6271. dest, destOffset) {
  6272. var numComps = this.base.numComps;
  6273. var start = src[srcOffset] * numComps;
  6274. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6275. },
  6276. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6277. dest, destOffset, bits,
  6278. alpha01) {
  6279. var base = this.base;
  6280. var numComps = base.numComps;
  6281. var outputDelta = base.getOutputLength(numComps, alpha01);
  6282. var lookup = this.lookup;
  6283. for (var i = 0; i < count; ++i) {
  6284. var lookupPos = src[srcOffset++] * numComps;
  6285. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6286. destOffset += outputDelta;
  6287. }
  6288. },
  6289. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6290. return this.base.getOutputLength(inputLength * this.base.numComps,
  6291. alpha01);
  6292. },
  6293. isPassthrough: ColorSpace.prototype.isPassthrough,
  6294. fillRgb: ColorSpace.prototype.fillRgb,
  6295. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6296. // indexed color maps shouldn't be changed
  6297. return true;
  6298. },
  6299. usesZeroToOneRange: true
  6300. };
  6301. return IndexedCS;
  6302. })();
  6303. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6304. function DeviceGrayCS() {
  6305. this.name = 'DeviceGray';
  6306. this.numComps = 1;
  6307. this.defaultColor = new Float32Array([0]);
  6308. }
  6309. DeviceGrayCS.prototype = {
  6310. getRgb: ColorSpace.prototype.getRgb,
  6311. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6312. dest, destOffset) {
  6313. var c = (src[srcOffset] * 255) | 0;
  6314. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6315. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6316. },
  6317. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6318. dest, destOffset, bits,
  6319. alpha01) {
  6320. var scale = 255 / ((1 << bits) - 1);
  6321. var j = srcOffset, q = destOffset;
  6322. for (var i = 0; i < count; ++i) {
  6323. var c = (scale * src[j++]) | 0;
  6324. dest[q++] = c;
  6325. dest[q++] = c;
  6326. dest[q++] = c;
  6327. q += alpha01;
  6328. }
  6329. },
  6330. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6331. alpha01) {
  6332. return inputLength * (3 + alpha01);
  6333. },
  6334. isPassthrough: ColorSpace.prototype.isPassthrough,
  6335. fillRgb: ColorSpace.prototype.fillRgb,
  6336. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6337. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6338. },
  6339. usesZeroToOneRange: true
  6340. };
  6341. return DeviceGrayCS;
  6342. })();
  6343. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6344. function DeviceRgbCS() {
  6345. this.name = 'DeviceRGB';
  6346. this.numComps = 3;
  6347. this.defaultColor = new Float32Array([0, 0, 0]);
  6348. }
  6349. DeviceRgbCS.prototype = {
  6350. getRgb: ColorSpace.prototype.getRgb,
  6351. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6352. dest, destOffset) {
  6353. var r = (src[srcOffset] * 255) | 0;
  6354. var g = (src[srcOffset + 1] * 255) | 0;
  6355. var b = (src[srcOffset + 2] * 255) | 0;
  6356. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6357. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6358. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6359. },
  6360. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6361. dest, destOffset, bits,
  6362. alpha01) {
  6363. if (bits === 8 && alpha01 === 0) {
  6364. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6365. return;
  6366. }
  6367. var scale = 255 / ((1 << bits) - 1);
  6368. var j = srcOffset, q = destOffset;
  6369. for (var i = 0; i < count; ++i) {
  6370. dest[q++] = (scale * src[j++]) | 0;
  6371. dest[q++] = (scale * src[j++]) | 0;
  6372. dest[q++] = (scale * src[j++]) | 0;
  6373. q += alpha01;
  6374. }
  6375. },
  6376. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6377. alpha01) {
  6378. return (inputLength * (3 + alpha01) / 3) | 0;
  6379. },
  6380. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6381. return bits === 8;
  6382. },
  6383. fillRgb: ColorSpace.prototype.fillRgb,
  6384. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6385. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6386. },
  6387. usesZeroToOneRange: true
  6388. };
  6389. return DeviceRgbCS;
  6390. })();
  6391. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6392. // The coefficients below was found using numerical analysis: the method of
  6393. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6394. // where color_value is the tabular value from the table of sampled RGB colors
  6395. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6396. // CMYK color conversion using the estimation below:
  6397. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6398. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6399. var c = src[srcOffset + 0] * srcScale;
  6400. var m = src[srcOffset + 1] * srcScale;
  6401. var y = src[srcOffset + 2] * srcScale;
  6402. var k = src[srcOffset + 3] * srcScale;
  6403. var r =
  6404. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6405. 18.82290502165302 * y + 212.25662451639585 * k +
  6406. -285.2331026137004) +
  6407. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6408. -17.873870861415444 * k - 5.497006427196366) +
  6409. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6410. 17.5119270841813) +
  6411. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6412. var g =
  6413. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6414. 6.871425592049007 * y + 31.159100130055922 * k +
  6415. -79.2970844816548) +
  6416. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6417. 131.35250912493976 * k - 190.9453302588951) +
  6418. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6419. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6420. var b =
  6421. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6422. 30.89978309703729 * y - 0.23883238689178934 * k +
  6423. -14.183576799673286) +
  6424. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6425. 50.606957656360734 * k - 112.23884253719248) +
  6426. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6427. -193.58209356861505) +
  6428. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6429. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6430. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6431. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6432. }
  6433. function DeviceCmykCS() {
  6434. this.name = 'DeviceCMYK';
  6435. this.numComps = 4;
  6436. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6437. }
  6438. DeviceCmykCS.prototype = {
  6439. getRgb: ColorSpace.prototype.getRgb,
  6440. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6441. dest, destOffset) {
  6442. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6443. },
  6444. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6445. dest, destOffset, bits,
  6446. alpha01) {
  6447. var scale = 1 / ((1 << bits) - 1);
  6448. for (var i = 0; i < count; i++) {
  6449. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6450. srcOffset += 4;
  6451. destOffset += 3 + alpha01;
  6452. }
  6453. },
  6454. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6455. alpha01) {
  6456. return (inputLength / 4 * (3 + alpha01)) | 0;
  6457. },
  6458. isPassthrough: ColorSpace.prototype.isPassthrough,
  6459. fillRgb: ColorSpace.prototype.fillRgb,
  6460. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6461. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6462. },
  6463. usesZeroToOneRange: true
  6464. };
  6465. return DeviceCmykCS;
  6466. })();
  6467. //
  6468. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6469. //
  6470. var CalGrayCS = (function CalGrayCSClosure() {
  6471. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6472. this.name = 'CalGray';
  6473. this.numComps = 1;
  6474. this.defaultColor = new Float32Array([0]);
  6475. if (!whitePoint) {
  6476. error('WhitePoint missing - required for color space CalGray');
  6477. }
  6478. blackPoint = blackPoint || [0, 0, 0];
  6479. gamma = gamma || 1;
  6480. // Translate arguments to spec variables.
  6481. this.XW = whitePoint[0];
  6482. this.YW = whitePoint[1];
  6483. this.ZW = whitePoint[2];
  6484. this.XB = blackPoint[0];
  6485. this.YB = blackPoint[1];
  6486. this.ZB = blackPoint[2];
  6487. this.G = gamma;
  6488. // Validate variables as per spec.
  6489. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6490. error('Invalid WhitePoint components for ' + this.name +
  6491. ', no fallback available');
  6492. }
  6493. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6494. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6495. this.XB = this.YB = this.ZB = 0;
  6496. }
  6497. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6498. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6499. ', ZB: ' + this.ZB + ', only default values are supported.');
  6500. }
  6501. if (this.G < 1) {
  6502. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6503. ', falling back to default');
  6504. this.G = 1;
  6505. }
  6506. }
  6507. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6508. // A represents a gray component of a calibrated gray space.
  6509. // A <---> AG in the spec
  6510. var A = src[srcOffset] * scale;
  6511. var AG = Math.pow(A, cs.G);
  6512. // Computes L as per spec. ( = cs.YW * AG )
  6513. // Except if other than default BlackPoint values are used.
  6514. var L = cs.YW * AG;
  6515. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6516. // Convert values to rgb range [0, 255].
  6517. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6518. dest[destOffset] = val;
  6519. dest[destOffset + 1] = val;
  6520. dest[destOffset + 2] = val;
  6521. }
  6522. CalGrayCS.prototype = {
  6523. getRgb: ColorSpace.prototype.getRgb,
  6524. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6525. dest, destOffset) {
  6526. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6527. },
  6528. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6529. dest, destOffset, bits,
  6530. alpha01) {
  6531. var scale = 1 / ((1 << bits) - 1);
  6532. for (var i = 0; i < count; ++i) {
  6533. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6534. srcOffset += 1;
  6535. destOffset += 3 + alpha01;
  6536. }
  6537. },
  6538. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6539. return inputLength * (3 + alpha01);
  6540. },
  6541. isPassthrough: ColorSpace.prototype.isPassthrough,
  6542. fillRgb: ColorSpace.prototype.fillRgb,
  6543. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6544. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6545. },
  6546. usesZeroToOneRange: true
  6547. };
  6548. return CalGrayCS;
  6549. })();
  6550. //
  6551. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6552. //
  6553. var CalRGBCS = (function CalRGBCSClosure() {
  6554. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6555. // matrices.
  6556. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6557. 0.8951, 0.2664, -0.1614,
  6558. -0.7502, 1.7135, 0.0367,
  6559. 0.0389, -0.0685, 1.0296]);
  6560. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6561. 0.9869929, -0.1470543, 0.1599627,
  6562. 0.4323053, 0.5183603, 0.0492912,
  6563. -0.0085287, 0.0400428, 0.9684867]);
  6564. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6565. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6566. 3.2404542, -1.5371385, -0.4985314,
  6567. -0.9692660, 1.8760108, 0.0415560,
  6568. 0.0556434, -0.2040259, 1.0572252]);
  6569. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6570. var tempNormalizeMatrix = new Float32Array(3);
  6571. var tempConvertMatrix1 = new Float32Array(3);
  6572. var tempConvertMatrix2 = new Float32Array(3);
  6573. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6574. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6575. this.name = 'CalRGB';
  6576. this.numComps = 3;
  6577. this.defaultColor = new Float32Array(3);
  6578. if (!whitePoint) {
  6579. error('WhitePoint missing - required for color space CalRGB');
  6580. }
  6581. blackPoint = blackPoint || new Float32Array(3);
  6582. gamma = gamma || new Float32Array([1, 1, 1]);
  6583. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6584. // Translate arguments to spec variables.
  6585. var XW = whitePoint[0];
  6586. var YW = whitePoint[1];
  6587. var ZW = whitePoint[2];
  6588. this.whitePoint = whitePoint;
  6589. var XB = blackPoint[0];
  6590. var YB = blackPoint[1];
  6591. var ZB = blackPoint[2];
  6592. this.blackPoint = blackPoint;
  6593. this.GR = gamma[0];
  6594. this.GG = gamma[1];
  6595. this.GB = gamma[2];
  6596. this.MXA = matrix[0];
  6597. this.MYA = matrix[1];
  6598. this.MZA = matrix[2];
  6599. this.MXB = matrix[3];
  6600. this.MYB = matrix[4];
  6601. this.MZB = matrix[5];
  6602. this.MXC = matrix[6];
  6603. this.MYC = matrix[7];
  6604. this.MZC = matrix[8];
  6605. // Validate variables as per spec.
  6606. if (XW < 0 || ZW < 0 || YW !== 1) {
  6607. error('Invalid WhitePoint components for ' + this.name +
  6608. ', no fallback available');
  6609. }
  6610. if (XB < 0 || YB < 0 || ZB < 0) {
  6611. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6612. ', ' + ZB + '], falling back to default');
  6613. this.blackPoint = new Float32Array(3);
  6614. }
  6615. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6616. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6617. '] for ' + this.name + ', falling back to default');
  6618. this.GR = this.GG = this.GB = 1;
  6619. }
  6620. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6621. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6622. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6623. info('Invalid Matrix for ' + this.name + ' [' +
  6624. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6625. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6626. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6627. '], falling back to default');
  6628. this.MXA = this.MYB = this.MZC = 1;
  6629. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6630. }
  6631. }
  6632. function matrixProduct(a, b, result) {
  6633. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6634. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6635. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6636. }
  6637. function convertToFlat(sourceWhitePoint, LMS, result) {
  6638. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6639. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6640. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6641. }
  6642. function convertToD65(sourceWhitePoint, LMS, result) {
  6643. var D65X = 0.95047;
  6644. var D65Y = 1;
  6645. var D65Z = 1.08883;
  6646. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6647. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6648. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6649. }
  6650. function sRGBTransferFunction(color) {
  6651. // See http://en.wikipedia.org/wiki/SRGB.
  6652. if (color <= 0.0031308){
  6653. return adjustToRange(0, 1, 12.92 * color);
  6654. }
  6655. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6656. }
  6657. function adjustToRange(min, max, value) {
  6658. return Math.max(min, Math.min(max, value));
  6659. }
  6660. function decodeL(L) {
  6661. if (L < 0) {
  6662. return -decodeL(-L);
  6663. }
  6664. if (L > 8.0) {
  6665. return Math.pow(((L + 16) / 116), 3);
  6666. }
  6667. return L * DECODE_L_CONSTANT;
  6668. }
  6669. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6670. // In case the blackPoint is already the default blackPoint then there is
  6671. // no need to do compensation.
  6672. if (sourceBlackPoint[0] === 0 &&
  6673. sourceBlackPoint[1] === 0 &&
  6674. sourceBlackPoint[2] === 0) {
  6675. result[0] = XYZ_Flat[0];
  6676. result[1] = XYZ_Flat[1];
  6677. result[2] = XYZ_Flat[2];
  6678. return;
  6679. }
  6680. // For the blackPoint calculation details, please see
  6681. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6682. // AdobeBPC.pdf.
  6683. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6684. var zeroDecodeL = decodeL(0);
  6685. var X_DST = zeroDecodeL;
  6686. var X_SRC = decodeL(sourceBlackPoint[0]);
  6687. var Y_DST = zeroDecodeL;
  6688. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6689. var Z_DST = zeroDecodeL;
  6690. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6691. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6692. var X_Offset = 1 - X_Scale;
  6693. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6694. var Y_Offset = 1 - Y_Scale;
  6695. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6696. var Z_Offset = 1 - Z_Scale;
  6697. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6698. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6699. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6700. }
  6701. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6702. // In case the whitePoint is already flat then there is no need to do
  6703. // normalization.
  6704. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6705. result[0] = XYZ_In[0];
  6706. result[1] = XYZ_In[1];
  6707. result[2] = XYZ_In[2];
  6708. return;
  6709. }
  6710. var LMS = result;
  6711. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6712. var LMS_Flat = tempNormalizeMatrix;
  6713. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6714. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6715. }
  6716. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6717. var LMS = result;
  6718. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6719. var LMS_D65 = tempNormalizeMatrix;
  6720. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6721. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6722. }
  6723. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6724. // A, B and C represent a red, green and blue components of a calibrated
  6725. // rgb space.
  6726. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6727. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6728. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6729. // A <---> AGR in the spec
  6730. // B <---> BGG in the spec
  6731. // C <---> CGB in the spec
  6732. var AGR = Math.pow(A, cs.GR);
  6733. var BGG = Math.pow(B, cs.GG);
  6734. var CGB = Math.pow(C, cs.GB);
  6735. // Computes intermediate variables L, M, N as per spec.
  6736. // To decode X, Y, Z values map L, M, N directly to them.
  6737. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6738. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6739. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6740. // The following calculations are based on this document:
  6741. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6742. // AdobeBPC.pdf.
  6743. var XYZ = tempConvertMatrix1;
  6744. XYZ[0] = X;
  6745. XYZ[1] = Y;
  6746. XYZ[2] = Z;
  6747. var XYZ_Flat = tempConvertMatrix2;
  6748. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6749. var XYZ_Black = tempConvertMatrix1;
  6750. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6751. var XYZ_D65 = tempConvertMatrix2;
  6752. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6753. var SRGB = tempConvertMatrix1;
  6754. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6755. var sR = sRGBTransferFunction(SRGB[0]);
  6756. var sG = sRGBTransferFunction(SRGB[1]);
  6757. var sB = sRGBTransferFunction(SRGB[2]);
  6758. // Convert the values to rgb range [0, 255].
  6759. dest[destOffset] = Math.round(sR * 255);
  6760. dest[destOffset + 1] = Math.round(sG * 255);
  6761. dest[destOffset + 2] = Math.round(sB * 255);
  6762. }
  6763. CalRGBCS.prototype = {
  6764. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6765. var rgb = new Uint8Array(3);
  6766. this.getRgbItem(src, srcOffset, rgb, 0);
  6767. return rgb;
  6768. },
  6769. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6770. dest, destOffset) {
  6771. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6772. },
  6773. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6774. dest, destOffset, bits,
  6775. alpha01) {
  6776. var scale = 1 / ((1 << bits) - 1);
  6777. for (var i = 0; i < count; ++i) {
  6778. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6779. srcOffset += 3;
  6780. destOffset += 3 + alpha01;
  6781. }
  6782. },
  6783. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6784. return (inputLength * (3 + alpha01) / 3) | 0;
  6785. },
  6786. isPassthrough: ColorSpace.prototype.isPassthrough,
  6787. fillRgb: ColorSpace.prototype.fillRgb,
  6788. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6789. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6790. },
  6791. usesZeroToOneRange: true
  6792. };
  6793. return CalRGBCS;
  6794. })();
  6795. //
  6796. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6797. //
  6798. var LabCS = (function LabCSClosure() {
  6799. function LabCS(whitePoint, blackPoint, range) {
  6800. this.name = 'Lab';
  6801. this.numComps = 3;
  6802. this.defaultColor = new Float32Array([0, 0, 0]);
  6803. if (!whitePoint) {
  6804. error('WhitePoint missing - required for color space Lab');
  6805. }
  6806. blackPoint = blackPoint || [0, 0, 0];
  6807. range = range || [-100, 100, -100, 100];
  6808. // Translate args to spec variables
  6809. this.XW = whitePoint[0];
  6810. this.YW = whitePoint[1];
  6811. this.ZW = whitePoint[2];
  6812. this.amin = range[0];
  6813. this.amax = range[1];
  6814. this.bmin = range[2];
  6815. this.bmax = range[3];
  6816. // These are here just for completeness - the spec doesn't offer any
  6817. // formulas that use BlackPoint in Lab
  6818. this.XB = blackPoint[0];
  6819. this.YB = blackPoint[1];
  6820. this.ZB = blackPoint[2];
  6821. // Validate vars as per spec
  6822. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6823. error('Invalid WhitePoint components, no fallback available');
  6824. }
  6825. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6826. info('Invalid BlackPoint, falling back to default');
  6827. this.XB = this.YB = this.ZB = 0;
  6828. }
  6829. if (this.amin > this.amax || this.bmin > this.bmax) {
  6830. info('Invalid Range, falling back to defaults');
  6831. this.amin = -100;
  6832. this.amax = 100;
  6833. this.bmin = -100;
  6834. this.bmax = 100;
  6835. }
  6836. }
  6837. // Function g(x) from spec
  6838. function fn_g(x) {
  6839. if (x >= 6 / 29) {
  6840. return x * x * x;
  6841. } else {
  6842. return (108 / 841) * (x - 4 / 29);
  6843. }
  6844. }
  6845. function decode(value, high1, low2, high2) {
  6846. return low2 + (value) * (high2 - low2) / (high1);
  6847. }
  6848. // If decoding is needed maxVal should be 2^bits per component - 1.
  6849. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6850. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6851. // not the usual [0, 1]. If a command like setFillColor is used the src
  6852. // values will already be within the correct range. However, if we are
  6853. // converting an image we have to map the values to the correct range given
  6854. // above.
  6855. // Ls,as,bs <---> L*,a*,b* in the spec
  6856. var Ls = src[srcOffset];
  6857. var as = src[srcOffset + 1];
  6858. var bs = src[srcOffset + 2];
  6859. if (maxVal !== false) {
  6860. Ls = decode(Ls, maxVal, 0, 100);
  6861. as = decode(as, maxVal, cs.amin, cs.amax);
  6862. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6863. }
  6864. // Adjust limits of 'as' and 'bs'
  6865. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6866. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6867. // Computes intermediate variables X,Y,Z as per spec
  6868. var M = (Ls + 16) / 116;
  6869. var L = M + (as / 500);
  6870. var N = M - (bs / 200);
  6871. var X = cs.XW * fn_g(L);
  6872. var Y = cs.YW * fn_g(M);
  6873. var Z = cs.ZW * fn_g(N);
  6874. var r, g, b;
  6875. // Using different conversions for D50 and D65 white points,
  6876. // per http://www.color.org/srgb.pdf
  6877. if (cs.ZW < 1) {
  6878. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6879. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6880. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6881. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6882. } else {
  6883. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6884. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6885. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6886. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6887. }
  6888. // clamp color values to [0,1] range then convert to [0,255] range.
  6889. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6890. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6891. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6892. }
  6893. LabCS.prototype = {
  6894. getRgb: ColorSpace.prototype.getRgb,
  6895. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6896. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6897. },
  6898. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6899. dest, destOffset, bits,
  6900. alpha01) {
  6901. var maxVal = (1 << bits) - 1;
  6902. for (var i = 0; i < count; i++) {
  6903. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6904. srcOffset += 3;
  6905. destOffset += 3 + alpha01;
  6906. }
  6907. },
  6908. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6909. return (inputLength * (3 + alpha01) / 3) | 0;
  6910. },
  6911. isPassthrough: ColorSpace.prototype.isPassthrough,
  6912. fillRgb: ColorSpace.prototype.fillRgb,
  6913. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6914. // XXX: Decoding is handled with the lab conversion because of the strange
  6915. // ranges that are used.
  6916. return true;
  6917. },
  6918. usesZeroToOneRange: false
  6919. };
  6920. return LabCS;
  6921. })();
  6922. var ARCFourCipher = (function ARCFourCipherClosure() {
  6923. function ARCFourCipher(key) {
  6924. this.a = 0;
  6925. this.b = 0;
  6926. var s = new Uint8Array(256);
  6927. var i, j = 0, tmp, keyLength = key.length;
  6928. for (i = 0; i < 256; ++i) {
  6929. s[i] = i;
  6930. }
  6931. for (i = 0; i < 256; ++i) {
  6932. tmp = s[i];
  6933. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6934. s[i] = s[j];
  6935. s[j] = tmp;
  6936. }
  6937. this.s = s;
  6938. }
  6939. ARCFourCipher.prototype = {
  6940. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6941. var i, n = data.length, tmp, tmp2;
  6942. var a = this.a, b = this.b, s = this.s;
  6943. var output = new Uint8Array(n);
  6944. for (i = 0; i < n; ++i) {
  6945. a = (a + 1) & 0xFF;
  6946. tmp = s[a];
  6947. b = (b + tmp) & 0xFF;
  6948. tmp2 = s[b];
  6949. s[a] = tmp2;
  6950. s[b] = tmp;
  6951. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6952. }
  6953. this.a = a;
  6954. this.b = b;
  6955. return output;
  6956. }
  6957. };
  6958. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6959. return ARCFourCipher;
  6960. })();
  6961. var calculateMD5 = (function calculateMD5Closure() {
  6962. var r = new Uint8Array([
  6963. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6964. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6965. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6966. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6967. var k = new Int32Array([
  6968. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6969. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6970. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6971. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6972. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6973. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6974. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6975. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6976. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6977. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6978. -145523070, -1120210379, 718787259, -343485551]);
  6979. function hash(data, offset, length) {
  6980. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6981. // pre-processing
  6982. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6983. var padded = new Uint8Array(paddedLength);
  6984. var i, j, n;
  6985. for (i = 0; i < length; ++i) {
  6986. padded[i] = data[offset++];
  6987. }
  6988. padded[i++] = 0x80;
  6989. n = paddedLength - 8;
  6990. while (i < n) {
  6991. padded[i++] = 0;
  6992. }
  6993. padded[i++] = (length << 3) & 0xFF;
  6994. padded[i++] = (length >> 5) & 0xFF;
  6995. padded[i++] = (length >> 13) & 0xFF;
  6996. padded[i++] = (length >> 21) & 0xFF;
  6997. padded[i++] = (length >>> 29) & 0xFF;
  6998. padded[i++] = 0;
  6999. padded[i++] = 0;
  7000. padded[i++] = 0;
  7001. var w = new Int32Array(16);
  7002. for (i = 0; i < paddedLength;) {
  7003. for (j = 0; j < 16; ++j, i += 4) {
  7004. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7005. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7006. }
  7007. var a = h0, b = h1, c = h2, d = h3, f, g;
  7008. for (j = 0; j < 64; ++j) {
  7009. if (j < 16) {
  7010. f = (b & c) | ((~b) & d);
  7011. g = j;
  7012. } else if (j < 32) {
  7013. f = (d & b) | ((~d) & c);
  7014. g = (5 * j + 1) & 15;
  7015. } else if (j < 48) {
  7016. f = b ^ c ^ d;
  7017. g = (3 * j + 5) & 15;
  7018. } else {
  7019. f = c ^ (b | (~d));
  7020. g = (7 * j) & 15;
  7021. }
  7022. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7023. d = c;
  7024. c = b;
  7025. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7026. a = tmp;
  7027. }
  7028. h0 = (h0 + a) | 0;
  7029. h1 = (h1 + b) | 0;
  7030. h2 = (h2 + c) | 0;
  7031. h3 = (h3 + d) | 0;
  7032. }
  7033. return new Uint8Array([
  7034. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7035. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7036. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7037. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7038. ]);
  7039. }
  7040. return hash;
  7041. })();
  7042. var Word64 = (function Word64Closure() {
  7043. function Word64(highInteger, lowInteger) {
  7044. this.high = highInteger | 0;
  7045. this.low = lowInteger | 0;
  7046. }
  7047. Word64.prototype = {
  7048. and: function Word64_and(word) {
  7049. this.high &= word.high;
  7050. this.low &= word.low;
  7051. },
  7052. xor: function Word64_xor(word) {
  7053. this.high ^= word.high;
  7054. this.low ^= word.low;
  7055. },
  7056. or: function Word64_or(word) {
  7057. this.high |= word.high;
  7058. this.low |= word.low;
  7059. },
  7060. shiftRight: function Word64_shiftRight(places) {
  7061. if (places >= 32) {
  7062. this.low = (this.high >>> (places - 32)) | 0;
  7063. this.high = 0;
  7064. } else {
  7065. this.low = (this.low >>> places) | (this.high << (32 - places));
  7066. this.high = (this.high >>> places) | 0;
  7067. }
  7068. },
  7069. shiftLeft: function Word64_shiftLeft(places) {
  7070. if (places >= 32) {
  7071. this.high = this.low << (places - 32);
  7072. this.low = 0;
  7073. } else {
  7074. this.high = (this.high << places) | (this.low >>> (32 - places));
  7075. this.low = this.low << places;
  7076. }
  7077. },
  7078. rotateRight: function Word64_rotateRight(places) {
  7079. var low, high;
  7080. if (places & 32) {
  7081. high = this.low;
  7082. low = this.high;
  7083. } else {
  7084. low = this.low;
  7085. high = this.high;
  7086. }
  7087. places &= 31;
  7088. this.low = (low >>> places) | (high << (32 - places));
  7089. this.high = (high >>> places) | (low << (32 - places));
  7090. },
  7091. not: function Word64_not() {
  7092. this.high = ~this.high;
  7093. this.low = ~this.low;
  7094. },
  7095. add: function Word64_add(word) {
  7096. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7097. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7098. if (lowAdd > 0xFFFFFFFF) {
  7099. highAdd += 1;
  7100. }
  7101. this.low = lowAdd | 0;
  7102. this.high = highAdd | 0;
  7103. },
  7104. copyTo: function Word64_copyTo(bytes, offset) {
  7105. bytes[offset] = (this.high >>> 24) & 0xFF;
  7106. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7107. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7108. bytes[offset + 3] = this.high & 0xFF;
  7109. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7110. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7111. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7112. bytes[offset + 7] = this.low & 0xFF;
  7113. },
  7114. assign: function Word64_assign(word) {
  7115. this.high = word.high;
  7116. this.low = word.low;
  7117. }
  7118. };
  7119. return Word64;
  7120. })();
  7121. var calculateSHA256 = (function calculateSHA256Closure() {
  7122. function rotr(x, n) {
  7123. return (x >>> n) | (x << 32 - n);
  7124. }
  7125. function ch(x, y, z) {
  7126. return (x & y) ^ (~x & z);
  7127. }
  7128. function maj(x, y, z) {
  7129. return (x & y) ^ (x & z) ^ (y & z);
  7130. }
  7131. function sigma(x) {
  7132. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7133. }
  7134. function sigmaPrime(x) {
  7135. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7136. }
  7137. function littleSigma(x) {
  7138. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7139. }
  7140. function littleSigmaPrime(x) {
  7141. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7142. }
  7143. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7144. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7145. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7146. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7147. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7148. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7149. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7150. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7151. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7152. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7153. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7154. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7155. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7156. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7157. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7158. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7159. function hash(data, offset, length) {
  7160. // initial hash values
  7161. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7162. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7163. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7164. // pre-processing
  7165. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7166. var padded = new Uint8Array(paddedLength);
  7167. var i, j, n;
  7168. for (i = 0; i < length; ++i) {
  7169. padded[i] = data[offset++];
  7170. }
  7171. padded[i++] = 0x80;
  7172. n = paddedLength - 8;
  7173. while (i < n) {
  7174. padded[i++] = 0;
  7175. }
  7176. padded[i++] = 0;
  7177. padded[i++] = 0;
  7178. padded[i++] = 0;
  7179. padded[i++] = (length >>> 29) & 0xFF;
  7180. padded[i++] = (length >> 21) & 0xFF;
  7181. padded[i++] = (length >> 13) & 0xFF;
  7182. padded[i++] = (length >> 5) & 0xFF;
  7183. padded[i++] = (length << 3) & 0xFF;
  7184. var w = new Uint32Array(64);
  7185. // for each 512 bit block
  7186. for (i = 0; i < paddedLength;) {
  7187. for (j = 0; j < 16; ++j) {
  7188. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7189. (padded[i + 2] << 8) | (padded[i + 3]));
  7190. i += 4;
  7191. }
  7192. for (j = 16; j < 64; ++j) {
  7193. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7194. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7195. }
  7196. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7197. f = h5, g = h6, h = h7, t1, t2;
  7198. for (j = 0; j < 64; ++j) {
  7199. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7200. t2 = sigma(a) + maj(a, b, c);
  7201. h = g;
  7202. g = f;
  7203. f = e;
  7204. e = (d + t1) | 0;
  7205. d = c;
  7206. c = b;
  7207. b = a;
  7208. a = (t1 + t2) | 0;
  7209. }
  7210. h0 = (h0 + a) | 0;
  7211. h1 = (h1 + b) | 0;
  7212. h2 = (h2 + c) | 0;
  7213. h3 = (h3 + d) | 0;
  7214. h4 = (h4 + e) | 0;
  7215. h5 = (h5 + f) | 0;
  7216. h6 = (h6 + g) | 0;
  7217. h7 = (h7 + h) | 0;
  7218. }
  7219. return new Uint8Array([
  7220. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7221. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7222. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7223. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7224. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7225. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7226. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7227. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7228. ]);
  7229. }
  7230. return hash;
  7231. })();
  7232. var calculateSHA512 = (function calculateSHA512Closure() {
  7233. function ch(result, x, y, z, tmp) {
  7234. result.assign(x);
  7235. result.and(y);
  7236. tmp.assign(x);
  7237. tmp.not();
  7238. tmp.and(z);
  7239. result.xor(tmp);
  7240. }
  7241. function maj(result, x, y, z, tmp) {
  7242. result.assign(x);
  7243. result.and(y);
  7244. tmp.assign(x);
  7245. tmp.and(z);
  7246. result.xor(tmp);
  7247. tmp.assign(y);
  7248. tmp.and(z);
  7249. result.xor(tmp);
  7250. }
  7251. function sigma(result, x, tmp) {
  7252. result.assign(x);
  7253. result.rotateRight(28);
  7254. tmp.assign(x);
  7255. tmp.rotateRight(34);
  7256. result.xor(tmp);
  7257. tmp.assign(x);
  7258. tmp.rotateRight(39);
  7259. result.xor(tmp);
  7260. }
  7261. function sigmaPrime(result, x, tmp) {
  7262. result.assign(x);
  7263. result.rotateRight(14);
  7264. tmp.assign(x);
  7265. tmp.rotateRight(18);
  7266. result.xor(tmp);
  7267. tmp.assign(x);
  7268. tmp.rotateRight(41);
  7269. result.xor(tmp);
  7270. }
  7271. function littleSigma(result, x, tmp) {
  7272. result.assign(x);
  7273. result.rotateRight(1);
  7274. tmp.assign(x);
  7275. tmp.rotateRight(8);
  7276. result.xor(tmp);
  7277. tmp.assign(x);
  7278. tmp.shiftRight(7);
  7279. result.xor(tmp);
  7280. }
  7281. function littleSigmaPrime(result, x, tmp) {
  7282. result.assign(x);
  7283. result.rotateRight(19);
  7284. tmp.assign(x);
  7285. tmp.rotateRight(61);
  7286. result.xor(tmp);
  7287. tmp.assign(x);
  7288. tmp.shiftRight(6);
  7289. result.xor(tmp);
  7290. }
  7291. var k = [
  7292. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7293. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7294. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7295. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7296. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7297. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7298. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7299. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7300. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7301. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7302. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7303. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7304. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7305. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7306. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7307. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7308. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7309. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7310. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7311. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7312. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7313. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7314. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7315. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7316. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7317. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7318. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7319. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7320. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7321. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7322. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7323. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7324. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7325. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7326. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7327. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7328. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7329. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7330. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7331. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7332. function hash(data, offset, length, mode384) {
  7333. mode384 = !!mode384;
  7334. // initial hash values
  7335. var h0, h1, h2, h3, h4, h5, h6, h7;
  7336. if (!mode384) {
  7337. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7338. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7339. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7340. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7341. h4 = new Word64(0x510e527f, 0xade682d1);
  7342. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7343. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7344. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7345. }
  7346. else {
  7347. // SHA384 is exactly the same
  7348. // except with different starting values and a trimmed result
  7349. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7350. h1 = new Word64(0x629a292a, 0x367cd507);
  7351. h2 = new Word64(0x9159015a, 0x3070dd17);
  7352. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7353. h4 = new Word64(0x67332667, 0xffc00b31);
  7354. h5 = new Word64(0x8eb44a87, 0x68581511);
  7355. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7356. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7357. }
  7358. // pre-processing
  7359. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7360. var padded = new Uint8Array(paddedLength);
  7361. var i, j, n;
  7362. for (i = 0; i < length; ++i) {
  7363. padded[i] = data[offset++];
  7364. }
  7365. padded[i++] = 0x80;
  7366. n = paddedLength - 16;
  7367. while (i < n) {
  7368. padded[i++] = 0;
  7369. }
  7370. padded[i++] = 0;
  7371. padded[i++] = 0;
  7372. padded[i++] = 0;
  7373. padded[i++] = 0;
  7374. padded[i++] = 0;
  7375. padded[i++] = 0;
  7376. padded[i++] = 0;
  7377. padded[i++] = 0;
  7378. padded[i++] = 0;
  7379. padded[i++] = 0;
  7380. padded[i++] = 0;
  7381. padded[i++] = (length >>> 29) & 0xFF;
  7382. padded[i++] = (length >> 21) & 0xFF;
  7383. padded[i++] = (length >> 13) & 0xFF;
  7384. padded[i++] = (length >> 5) & 0xFF;
  7385. padded[i++] = (length << 3) & 0xFF;
  7386. var w = new Array(80);
  7387. for (i = 0; i < 80; i++) {
  7388. w[i] = new Word64(0, 0);
  7389. }
  7390. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7391. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7392. var g = new Word64(0, 0), h = new Word64(0, 0);
  7393. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7394. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7395. // for each 1024 bit block
  7396. for (i = 0; i < paddedLength;) {
  7397. for (j = 0; j < 16; ++j) {
  7398. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7399. (padded[i + 2] << 8) | (padded[i + 3]);
  7400. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7401. (padded[i + 6]) << 8 | (padded[i + 7]);
  7402. i += 8;
  7403. }
  7404. for (j = 16; j < 80; ++j) {
  7405. tmp3 = w[j];
  7406. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7407. tmp3.add(w[j - 7]);
  7408. littleSigma(tmp1, w[j - 15], tmp2);
  7409. tmp3.add(tmp1);
  7410. tmp3.add(w[j - 16]);
  7411. }
  7412. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7413. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7414. for (j = 0; j < 80; ++j) {
  7415. t1.assign(h);
  7416. sigmaPrime(tmp1, e, tmp2);
  7417. t1.add(tmp1);
  7418. ch(tmp1, e, f, g, tmp2);
  7419. t1.add(tmp1);
  7420. t1.add(k[j]);
  7421. t1.add(w[j]);
  7422. sigma(t2, a, tmp2);
  7423. maj(tmp1, a, b, c, tmp2);
  7424. t2.add(tmp1);
  7425. tmp3 = h;
  7426. h = g;
  7427. g = f;
  7428. f = e;
  7429. d.add(t1);
  7430. e = d;
  7431. d = c;
  7432. c = b;
  7433. b = a;
  7434. tmp3.assign(t1);
  7435. tmp3.add(t2);
  7436. a = tmp3;
  7437. }
  7438. h0.add(a);
  7439. h1.add(b);
  7440. h2.add(c);
  7441. h3.add(d);
  7442. h4.add(e);
  7443. h5.add(f);
  7444. h6.add(g);
  7445. h7.add(h);
  7446. }
  7447. var result;
  7448. if (!mode384) {
  7449. result = new Uint8Array(64);
  7450. h0.copyTo(result,0);
  7451. h1.copyTo(result,8);
  7452. h2.copyTo(result,16);
  7453. h3.copyTo(result,24);
  7454. h4.copyTo(result,32);
  7455. h5.copyTo(result,40);
  7456. h6.copyTo(result,48);
  7457. h7.copyTo(result,56);
  7458. }
  7459. else {
  7460. result = new Uint8Array(48);
  7461. h0.copyTo(result,0);
  7462. h1.copyTo(result,8);
  7463. h2.copyTo(result,16);
  7464. h3.copyTo(result,24);
  7465. h4.copyTo(result,32);
  7466. h5.copyTo(result,40);
  7467. }
  7468. return result;
  7469. }
  7470. return hash;
  7471. })();
  7472. var calculateSHA384 = (function calculateSHA384Closure() {
  7473. function hash(data, offset, length) {
  7474. return calculateSHA512(data, offset, length, true);
  7475. }
  7476. return hash;
  7477. })();
  7478. var NullCipher = (function NullCipherClosure() {
  7479. function NullCipher() {
  7480. }
  7481. NullCipher.prototype = {
  7482. decryptBlock: function NullCipher_decryptBlock(data) {
  7483. return data;
  7484. }
  7485. };
  7486. return NullCipher;
  7487. })();
  7488. var AES128Cipher = (function AES128CipherClosure() {
  7489. var rcon = new Uint8Array([
  7490. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7491. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7492. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7493. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7494. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7495. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7496. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7497. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7498. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7499. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7500. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7501. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7502. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7503. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7504. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7505. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7506. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7507. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7508. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7509. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7510. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7511. 0x74, 0xe8, 0xcb, 0x8d]);
  7512. var s = new Uint8Array([
  7513. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7514. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7515. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7516. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7517. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7518. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7519. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7520. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7521. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7522. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7523. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7524. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7525. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7526. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7527. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7528. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7529. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7530. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7531. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7532. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7533. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7534. 0xb0, 0x54, 0xbb, 0x16]);
  7535. var inv_s = new Uint8Array([
  7536. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7537. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7538. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7539. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7540. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7541. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7542. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7543. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7544. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7545. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7546. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7547. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7548. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7549. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7550. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7551. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7552. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7553. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7554. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7555. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7556. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7557. 0x55, 0x21, 0x0c, 0x7d]);
  7558. var mixCol = new Uint8Array(256);
  7559. for (var i = 0; i < 256; i++) {
  7560. if (i < 128) {
  7561. mixCol[i] = i << 1;
  7562. } else {
  7563. mixCol[i] = (i << 1) ^ 0x1b;
  7564. }
  7565. }
  7566. var mix = new Uint32Array([
  7567. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7568. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7569. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7570. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7571. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7572. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7573. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7574. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7575. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7576. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7577. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7578. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7579. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7580. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7581. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7582. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7583. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7584. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7585. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7586. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7587. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7588. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7589. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7590. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7591. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7592. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7593. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7594. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7595. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7596. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7597. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7598. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7599. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7600. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7601. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7602. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7603. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7604. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7605. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7606. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7607. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7608. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7609. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7610. function expandKey128(cipherKey) {
  7611. var b = 176, result = new Uint8Array(b);
  7612. result.set(cipherKey);
  7613. for (var j = 16, i = 1; j < b; ++i) {
  7614. // RotWord
  7615. var t1 = result[j - 3], t2 = result[j - 2],
  7616. t3 = result[j - 1], t4 = result[j - 4];
  7617. // SubWord
  7618. t1 = s[t1];
  7619. t2 = s[t2];
  7620. t3 = s[t3];
  7621. t4 = s[t4];
  7622. // Rcon
  7623. t1 = t1 ^ rcon[i];
  7624. for (var n = 0; n < 4; ++n) {
  7625. result[j] = (t1 ^= result[j - 16]);
  7626. j++;
  7627. result[j] = (t2 ^= result[j - 16]);
  7628. j++;
  7629. result[j] = (t3 ^= result[j - 16]);
  7630. j++;
  7631. result[j] = (t4 ^= result[j - 16]);
  7632. j++;
  7633. }
  7634. }
  7635. return result;
  7636. }
  7637. function decrypt128(input, key) {
  7638. var state = new Uint8Array(16);
  7639. state.set(input);
  7640. var i, j, k;
  7641. var t, u, v;
  7642. // AddRoundKey
  7643. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7644. state[j] ^= key[k];
  7645. }
  7646. for (i = 9; i >= 1; --i) {
  7647. // InvShiftRows
  7648. t = state[13];
  7649. state[13] = state[9];
  7650. state[9] = state[5];
  7651. state[5] = state[1];
  7652. state[1] = t;
  7653. t = state[14];
  7654. u = state[10];
  7655. state[14] = state[6];
  7656. state[10] = state[2];
  7657. state[6] = t;
  7658. state[2] = u;
  7659. t = state[15];
  7660. u = state[11];
  7661. v = state[7];
  7662. state[15] = state[3];
  7663. state[11] = t;
  7664. state[7] = u;
  7665. state[3] = v;
  7666. // InvSubBytes
  7667. for (j = 0; j < 16; ++j) {
  7668. state[j] = inv_s[state[j]];
  7669. }
  7670. // AddRoundKey
  7671. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7672. state[j] ^= key[k];
  7673. }
  7674. // InvMixColumns
  7675. for (j = 0; j < 16; j += 4) {
  7676. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7677. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7678. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7679. (s3 >>> 24) ^ (s3 << 8));
  7680. state[j] = (t >>> 24) & 0xFF;
  7681. state[j + 1] = (t >> 16) & 0xFF;
  7682. state[j + 2] = (t >> 8) & 0xFF;
  7683. state[j + 3] = t & 0xFF;
  7684. }
  7685. }
  7686. // InvShiftRows
  7687. t = state[13];
  7688. state[13] = state[9];
  7689. state[9] = state[5];
  7690. state[5] = state[1];
  7691. state[1] = t;
  7692. t = state[14];
  7693. u = state[10];
  7694. state[14] = state[6];
  7695. state[10] = state[2];
  7696. state[6] = t;
  7697. state[2] = u;
  7698. t = state[15];
  7699. u = state[11];
  7700. v = state[7];
  7701. state[15] = state[3];
  7702. state[11] = t;
  7703. state[7] = u;
  7704. state[3] = v;
  7705. for (j = 0; j < 16; ++j) {
  7706. // InvSubBytes
  7707. state[j] = inv_s[state[j]];
  7708. // AddRoundKey
  7709. state[j] ^= key[j];
  7710. }
  7711. return state;
  7712. }
  7713. function encrypt128(input, key) {
  7714. var t, u, v, k;
  7715. var state = new Uint8Array(16);
  7716. state.set(input);
  7717. for (j = 0; j < 16; ++j) {
  7718. // AddRoundKey
  7719. state[j] ^= key[j];
  7720. }
  7721. for (i = 1; i < 10; i++) {
  7722. //SubBytes
  7723. for (j = 0; j < 16; ++j) {
  7724. state[j] = s[state[j]];
  7725. }
  7726. //ShiftRows
  7727. v = state[1];
  7728. state[1] = state[5];
  7729. state[5] = state[9];
  7730. state[9] = state[13];
  7731. state[13] = v;
  7732. v = state[2];
  7733. u = state[6];
  7734. state[2] = state[10];
  7735. state[6] = state[14];
  7736. state[10] = v;
  7737. state[14] = u;
  7738. v = state[3];
  7739. u = state[7];
  7740. t = state[11];
  7741. state[3] = state[15];
  7742. state[7] = v;
  7743. state[11] = u;
  7744. state[15] = t;
  7745. //MixColumns
  7746. for (var j = 0; j < 16; j += 4) {
  7747. var s0 = state[j + 0], s1 = state[j + 1];
  7748. var s2 = state[j + 2], s3 = state[j + 3];
  7749. t = s0 ^ s1 ^ s2 ^ s3;
  7750. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7751. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7752. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7753. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7754. }
  7755. //AddRoundKey
  7756. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7757. state[j] ^= key[k];
  7758. }
  7759. }
  7760. //SubBytes
  7761. for (j = 0; j < 16; ++j) {
  7762. state[j] = s[state[j]];
  7763. }
  7764. //ShiftRows
  7765. v = state[1];
  7766. state[1] = state[5];
  7767. state[5] = state[9];
  7768. state[9] = state[13];
  7769. state[13] = v;
  7770. v = state[2];
  7771. u = state[6];
  7772. state[2] = state[10];
  7773. state[6] = state[14];
  7774. state[10] = v;
  7775. state[14] = u;
  7776. v = state[3];
  7777. u = state[7];
  7778. t = state[11];
  7779. state[3] = state[15];
  7780. state[7] = v;
  7781. state[11] = u;
  7782. state[15] = t;
  7783. //AddRoundKey
  7784. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7785. state[j] ^= key[k];
  7786. }
  7787. return state;
  7788. }
  7789. function AES128Cipher(key) {
  7790. this.key = expandKey128(key);
  7791. this.buffer = new Uint8Array(16);
  7792. this.bufferPosition = 0;
  7793. }
  7794. function decryptBlock2(data, finalize) {
  7795. var i, j, ii, sourceLength = data.length,
  7796. buffer = this.buffer, bufferLength = this.bufferPosition,
  7797. result = [], iv = this.iv;
  7798. for (i = 0; i < sourceLength; ++i) {
  7799. buffer[bufferLength] = data[i];
  7800. ++bufferLength;
  7801. if (bufferLength < 16) {
  7802. continue;
  7803. }
  7804. // buffer is full, decrypting
  7805. var plain = decrypt128(buffer, this.key);
  7806. // xor-ing the IV vector to get plain text
  7807. for (j = 0; j < 16; ++j) {
  7808. plain[j] ^= iv[j];
  7809. }
  7810. iv = buffer;
  7811. result.push(plain);
  7812. buffer = new Uint8Array(16);
  7813. bufferLength = 0;
  7814. }
  7815. // saving incomplete buffer
  7816. this.buffer = buffer;
  7817. this.bufferLength = bufferLength;
  7818. this.iv = iv;
  7819. if (result.length === 0) {
  7820. return new Uint8Array([]);
  7821. }
  7822. // combining plain text blocks into one
  7823. var outputLength = 16 * result.length;
  7824. if (finalize) {
  7825. // undo a padding that is described in RFC 2898
  7826. var lastBlock = result[result.length - 1];
  7827. var psLen = lastBlock[15];
  7828. if (psLen <= 16) {
  7829. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7830. if (lastBlock[i] !== psLen) {
  7831. // Invalid padding, assume that the block has no padding.
  7832. psLen = 0;
  7833. break;
  7834. }
  7835. }
  7836. outputLength -= psLen;
  7837. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7838. }
  7839. }
  7840. var output = new Uint8Array(outputLength);
  7841. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7842. output.set(result[i], j);
  7843. }
  7844. return output;
  7845. }
  7846. AES128Cipher.prototype = {
  7847. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7848. var i, sourceLength = data.length;
  7849. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7850. // waiting for IV values -- they are at the start of the stream
  7851. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7852. buffer[bufferLength] = data[i];
  7853. }
  7854. if (bufferLength < 16) {
  7855. // need more data
  7856. this.bufferLength = bufferLength;
  7857. return new Uint8Array([]);
  7858. }
  7859. this.iv = buffer;
  7860. this.buffer = new Uint8Array(16);
  7861. this.bufferLength = 0;
  7862. // starting decryption
  7863. this.decryptBlock = decryptBlock2;
  7864. return this.decryptBlock(data.subarray(16), finalize);
  7865. },
  7866. encrypt: function AES128Cipher_encrypt(data, iv) {
  7867. var i, j, ii, sourceLength = data.length,
  7868. buffer = this.buffer, bufferLength = this.bufferPosition,
  7869. result = [];
  7870. if (!iv) {
  7871. iv = new Uint8Array(16);
  7872. }
  7873. for (i = 0; i < sourceLength; ++i) {
  7874. buffer[bufferLength] = data[i];
  7875. ++bufferLength;
  7876. if (bufferLength < 16) {
  7877. continue;
  7878. }
  7879. for (j = 0; j < 16; ++j) {
  7880. buffer[j] ^= iv[j];
  7881. }
  7882. // buffer is full, encrypting
  7883. var cipher = encrypt128(buffer, this.key);
  7884. iv = cipher;
  7885. result.push(cipher);
  7886. buffer = new Uint8Array(16);
  7887. bufferLength = 0;
  7888. }
  7889. // saving incomplete buffer
  7890. this.buffer = buffer;
  7891. this.bufferLength = bufferLength;
  7892. this.iv = iv;
  7893. if (result.length === 0) {
  7894. return new Uint8Array([]);
  7895. }
  7896. // combining plain text blocks into one
  7897. var outputLength = 16 * result.length;
  7898. var output = new Uint8Array(outputLength);
  7899. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7900. output.set(result[i], j);
  7901. }
  7902. return output;
  7903. }
  7904. };
  7905. return AES128Cipher;
  7906. })();
  7907. var AES256Cipher = (function AES256CipherClosure() {
  7908. var rcon = new Uint8Array([
  7909. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7910. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7911. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7912. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7913. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7914. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7915. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7916. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7917. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7918. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7919. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7920. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7921. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7922. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7923. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7924. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7925. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7926. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7927. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7928. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7929. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7930. 0x74, 0xe8, 0xcb, 0x8d]);
  7931. var s = new Uint8Array([
  7932. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7933. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7934. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7935. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7936. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7937. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7938. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7939. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7940. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7941. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7942. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7943. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7944. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7945. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7946. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7947. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7948. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7949. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7950. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7951. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7952. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7953. 0xb0, 0x54, 0xbb, 0x16]);
  7954. var inv_s = new Uint8Array([
  7955. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7956. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7957. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7958. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7959. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7960. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7961. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7962. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7963. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7964. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7965. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7966. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7967. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7968. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7969. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7970. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7971. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7972. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7973. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7974. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7975. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7976. 0x55, 0x21, 0x0c, 0x7d]);
  7977. var mixCol = new Uint8Array(256);
  7978. for (var i = 0; i < 256; i++) {
  7979. if (i < 128) {
  7980. mixCol[i] = i << 1;
  7981. } else {
  7982. mixCol[i] = (i << 1) ^ 0x1b;
  7983. }
  7984. }
  7985. var mix = new Uint32Array([
  7986. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7987. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7988. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7989. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7990. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7991. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7992. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7993. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7994. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7995. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7996. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7997. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7998. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7999. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8000. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8001. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8002. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8003. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8004. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8005. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8006. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8007. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8008. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8009. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8010. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8011. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8012. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8013. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8014. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8015. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8016. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8017. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8018. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8019. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8020. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8021. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8022. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8023. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8024. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8025. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8026. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8027. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8028. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8029. function expandKey256(cipherKey) {
  8030. var b = 240, result = new Uint8Array(b);
  8031. var r = 1;
  8032. result.set(cipherKey);
  8033. for (var j = 32, i = 1; j < b; ++i) {
  8034. if (j % 32 === 16) {
  8035. t1 = s[t1];
  8036. t2 = s[t2];
  8037. t3 = s[t3];
  8038. t4 = s[t4];
  8039. } else if (j % 32 === 0) {
  8040. // RotWord
  8041. var t1 = result[j - 3], t2 = result[j - 2],
  8042. t3 = result[j - 1], t4 = result[j - 4];
  8043. // SubWord
  8044. t1 = s[t1];
  8045. t2 = s[t2];
  8046. t3 = s[t3];
  8047. t4 = s[t4];
  8048. // Rcon
  8049. t1 = t1 ^ r;
  8050. if ((r <<= 1) >= 256) {
  8051. r = (r ^ 0x1b) & 0xFF;
  8052. }
  8053. }
  8054. for (var n = 0; n < 4; ++n) {
  8055. result[j] = (t1 ^= result[j - 32]);
  8056. j++;
  8057. result[j] = (t2 ^= result[j - 32]);
  8058. j++;
  8059. result[j] = (t3 ^= result[j - 32]);
  8060. j++;
  8061. result[j] = (t4 ^= result[j - 32]);
  8062. j++;
  8063. }
  8064. }
  8065. return result;
  8066. }
  8067. function decrypt256(input, key) {
  8068. var state = new Uint8Array(16);
  8069. state.set(input);
  8070. var i, j, k;
  8071. var t, u, v;
  8072. // AddRoundKey
  8073. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8074. state[j] ^= key[k];
  8075. }
  8076. for (i = 13; i >= 1; --i) {
  8077. // InvShiftRows
  8078. t = state[13];
  8079. state[13] = state[9];
  8080. state[9] = state[5];
  8081. state[5] = state[1];
  8082. state[1] = t;
  8083. t = state[14];
  8084. u = state[10];
  8085. state[14] = state[6];
  8086. state[10] = state[2];
  8087. state[6] = t;
  8088. state[2] = u;
  8089. t = state[15];
  8090. u = state[11];
  8091. v = state[7];
  8092. state[15] = state[3];
  8093. state[11] = t;
  8094. state[7] = u;
  8095. state[3] = v;
  8096. // InvSubBytes
  8097. for (j = 0; j < 16; ++j) {
  8098. state[j] = inv_s[state[j]];
  8099. }
  8100. // AddRoundKey
  8101. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8102. state[j] ^= key[k];
  8103. }
  8104. // InvMixColumns
  8105. for (j = 0; j < 16; j += 4) {
  8106. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8107. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8108. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8109. (s3 >>> 24) ^ (s3 << 8));
  8110. state[j] = (t >>> 24) & 0xFF;
  8111. state[j + 1] = (t >> 16) & 0xFF;
  8112. state[j + 2] = (t >> 8) & 0xFF;
  8113. state[j + 3] = t & 0xFF;
  8114. }
  8115. }
  8116. // InvShiftRows
  8117. t = state[13];
  8118. state[13] = state[9];
  8119. state[9] = state[5];
  8120. state[5] = state[1];
  8121. state[1] = t;
  8122. t = state[14];
  8123. u = state[10];
  8124. state[14] = state[6];
  8125. state[10] = state[2];
  8126. state[6] = t;
  8127. state[2] = u;
  8128. t = state[15];
  8129. u = state[11];
  8130. v = state[7];
  8131. state[15] = state[3];
  8132. state[11] = t;
  8133. state[7] = u;
  8134. state[3] = v;
  8135. for (j = 0; j < 16; ++j) {
  8136. // InvSubBytes
  8137. state[j] = inv_s[state[j]];
  8138. // AddRoundKey
  8139. state[j] ^= key[j];
  8140. }
  8141. return state;
  8142. }
  8143. function encrypt256(input, key) {
  8144. var t, u, v, k;
  8145. var state = new Uint8Array(16);
  8146. state.set(input);
  8147. for (j = 0; j < 16; ++j) {
  8148. // AddRoundKey
  8149. state[j] ^= key[j];
  8150. }
  8151. for (i = 1; i < 14; i++) {
  8152. //SubBytes
  8153. for (j = 0; j < 16; ++j) {
  8154. state[j] = s[state[j]];
  8155. }
  8156. //ShiftRows
  8157. v = state[1];
  8158. state[1] = state[5];
  8159. state[5] = state[9];
  8160. state[9] = state[13];
  8161. state[13] = v;
  8162. v = state[2];
  8163. u = state[6];
  8164. state[2] = state[10];
  8165. state[6] = state[14];
  8166. state[10] = v;
  8167. state[14] = u;
  8168. v = state[3];
  8169. u = state[7];
  8170. t = state[11];
  8171. state[3] = state[15];
  8172. state[7] = v;
  8173. state[11] = u;
  8174. state[15] = t;
  8175. //MixColumns
  8176. for (var j = 0; j < 16; j += 4) {
  8177. var s0 = state[j + 0], s1 = state[j + 1];
  8178. var s2 = state[j + 2], s3 = state[j + 3];
  8179. t = s0 ^ s1 ^ s2 ^ s3;
  8180. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8181. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8182. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8183. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8184. }
  8185. //AddRoundKey
  8186. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8187. state[j] ^= key[k];
  8188. }
  8189. }
  8190. //SubBytes
  8191. for (j = 0; j < 16; ++j) {
  8192. state[j] = s[state[j]];
  8193. }
  8194. //ShiftRows
  8195. v = state[1];
  8196. state[1] = state[5];
  8197. state[5] = state[9];
  8198. state[9] = state[13];
  8199. state[13] = v;
  8200. v = state[2];
  8201. u = state[6];
  8202. state[2] = state[10];
  8203. state[6] = state[14];
  8204. state[10] = v;
  8205. state[14] = u;
  8206. v = state[3];
  8207. u = state[7];
  8208. t = state[11];
  8209. state[3] = state[15];
  8210. state[7] = v;
  8211. state[11] = u;
  8212. state[15] = t;
  8213. //AddRoundKey
  8214. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8215. state[j] ^= key[k];
  8216. }
  8217. return state;
  8218. }
  8219. function AES256Cipher(key) {
  8220. this.key = expandKey256(key);
  8221. this.buffer = new Uint8Array(16);
  8222. this.bufferPosition = 0;
  8223. }
  8224. function decryptBlock2(data, finalize) {
  8225. var i, j, ii, sourceLength = data.length,
  8226. buffer = this.buffer, bufferLength = this.bufferPosition,
  8227. result = [], iv = this.iv;
  8228. for (i = 0; i < sourceLength; ++i) {
  8229. buffer[bufferLength] = data[i];
  8230. ++bufferLength;
  8231. if (bufferLength < 16) {
  8232. continue;
  8233. }
  8234. // buffer is full, decrypting
  8235. var plain = decrypt256(buffer, this.key);
  8236. // xor-ing the IV vector to get plain text
  8237. for (j = 0; j < 16; ++j) {
  8238. plain[j] ^= iv[j];
  8239. }
  8240. iv = buffer;
  8241. result.push(plain);
  8242. buffer = new Uint8Array(16);
  8243. bufferLength = 0;
  8244. }
  8245. // saving incomplete buffer
  8246. this.buffer = buffer;
  8247. this.bufferLength = bufferLength;
  8248. this.iv = iv;
  8249. if (result.length === 0) {
  8250. return new Uint8Array([]);
  8251. }
  8252. // combining plain text blocks into one
  8253. var outputLength = 16 * result.length;
  8254. if (finalize) {
  8255. // undo a padding that is described in RFC 2898
  8256. var lastBlock = result[result.length - 1];
  8257. var psLen = lastBlock[15];
  8258. if (psLen <= 16) {
  8259. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8260. if (lastBlock[i] !== psLen) {
  8261. // Invalid padding, assume that the block has no padding.
  8262. psLen = 0;
  8263. break;
  8264. }
  8265. }
  8266. outputLength -= psLen;
  8267. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8268. }
  8269. }
  8270. var output = new Uint8Array(outputLength);
  8271. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8272. output.set(result[i], j);
  8273. }
  8274. return output;
  8275. }
  8276. AES256Cipher.prototype = {
  8277. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8278. var i, sourceLength = data.length;
  8279. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8280. // if not supplied an IV wait for IV values
  8281. // they are at the start of the stream
  8282. if (iv) {
  8283. this.iv = iv;
  8284. } else {
  8285. for (i = 0; bufferLength < 16 &&
  8286. i < sourceLength; ++i, ++bufferLength) {
  8287. buffer[bufferLength] = data[i];
  8288. }
  8289. if (bufferLength < 16) {
  8290. //need more data
  8291. this.bufferLength = bufferLength;
  8292. return new Uint8Array([]);
  8293. }
  8294. this.iv = buffer;
  8295. data = data.subarray(16);
  8296. }
  8297. this.buffer = new Uint8Array(16);
  8298. this.bufferLength = 0;
  8299. // starting decryption
  8300. this.decryptBlock = decryptBlock2;
  8301. return this.decryptBlock(data, finalize);
  8302. },
  8303. encrypt: function AES256Cipher_encrypt(data, iv) {
  8304. var i, j, ii, sourceLength = data.length,
  8305. buffer = this.buffer, bufferLength = this.bufferPosition,
  8306. result = [];
  8307. if (!iv) {
  8308. iv = new Uint8Array(16);
  8309. }
  8310. for (i = 0; i < sourceLength; ++i) {
  8311. buffer[bufferLength] = data[i];
  8312. ++bufferLength;
  8313. if (bufferLength < 16) {
  8314. continue;
  8315. }
  8316. for (j = 0; j < 16; ++j) {
  8317. buffer[j] ^= iv[j];
  8318. }
  8319. // buffer is full, encrypting
  8320. var cipher = encrypt256(buffer, this.key);
  8321. this.iv = cipher;
  8322. result.push(cipher);
  8323. buffer = new Uint8Array(16);
  8324. bufferLength = 0;
  8325. }
  8326. // saving incomplete buffer
  8327. this.buffer = buffer;
  8328. this.bufferLength = bufferLength;
  8329. this.iv = iv;
  8330. if (result.length === 0) {
  8331. return new Uint8Array([]);
  8332. }
  8333. // combining plain text blocks into one
  8334. var outputLength = 16 * result.length;
  8335. var output = new Uint8Array(outputLength);
  8336. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8337. output.set(result[i], j);
  8338. }
  8339. return output;
  8340. }
  8341. };
  8342. return AES256Cipher;
  8343. })();
  8344. var PDF17 = (function PDF17Closure() {
  8345. function compareByteArrays(array1, array2) {
  8346. if (array1.length !== array2.length) {
  8347. return false;
  8348. }
  8349. for (var i = 0; i < array1.length; i++) {
  8350. if (array1[i] !== array2[i]) {
  8351. return false;
  8352. }
  8353. }
  8354. return true;
  8355. }
  8356. function PDF17() {
  8357. }
  8358. PDF17.prototype = {
  8359. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8360. ownerValidationSalt,
  8361. userBytes,
  8362. ownerPassword) {
  8363. var hashData = new Uint8Array(password.length + 56);
  8364. hashData.set(password, 0);
  8365. hashData.set(ownerValidationSalt, password.length);
  8366. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8367. var result = calculateSHA256(hashData, 0, hashData.length);
  8368. return compareByteArrays(result, ownerPassword);
  8369. },
  8370. checkUserPassword: function PDF17_checkUserPassword(password,
  8371. userValidationSalt,
  8372. userPassword) {
  8373. var hashData = new Uint8Array(password.length + 8);
  8374. hashData.set(password, 0);
  8375. hashData.set(userValidationSalt, password.length);
  8376. var result = calculateSHA256(hashData, 0, hashData.length);
  8377. return compareByteArrays(result, userPassword);
  8378. },
  8379. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8380. ownerEncryption) {
  8381. var hashData = new Uint8Array(password.length + 56);
  8382. hashData.set(password, 0);
  8383. hashData.set(ownerKeySalt, password.length);
  8384. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8385. var key = calculateSHA256(hashData, 0, hashData.length);
  8386. var cipher = new AES256Cipher(key);
  8387. return cipher.decryptBlock(ownerEncryption,
  8388. false,
  8389. new Uint8Array(16));
  8390. },
  8391. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8392. userEncryption) {
  8393. var hashData = new Uint8Array(password.length + 8);
  8394. hashData.set(password, 0);
  8395. hashData.set(userKeySalt, password.length);
  8396. //key is the decryption key for the UE string
  8397. var key = calculateSHA256(hashData, 0, hashData.length);
  8398. var cipher = new AES256Cipher(key);
  8399. return cipher.decryptBlock(userEncryption,
  8400. false,
  8401. new Uint8Array(16));
  8402. }
  8403. };
  8404. return PDF17;
  8405. })();
  8406. var PDF20 = (function PDF20Closure() {
  8407. function concatArrays(array1, array2) {
  8408. var t = new Uint8Array(array1.length + array2.length);
  8409. t.set(array1, 0);
  8410. t.set(array2, array1.length);
  8411. return t;
  8412. }
  8413. function calculatePDF20Hash(password, input, userBytes) {
  8414. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8415. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8416. var e = [0];
  8417. var i = 0;
  8418. while (i < 64 || e[e.length - 1] > i - 32) {
  8419. var arrayLength = password.length + k.length + userBytes.length;
  8420. var k1 = new Uint8Array(arrayLength * 64);
  8421. var array = concatArrays(password, k);
  8422. array = concatArrays(array, userBytes);
  8423. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8424. k1.set(array, pos);
  8425. }
  8426. //AES128 CBC NO PADDING with
  8427. //first 16 bytes of k as the key and the second 16 as the iv.
  8428. var cipher = new AES128Cipher(k.subarray(0, 16));
  8429. e = cipher.encrypt(k1, k.subarray(16, 32));
  8430. //Now we have to take the first 16 bytes of an unsigned
  8431. //big endian integer... and compute the remainder
  8432. //modulo 3.... That is a fairly large number and
  8433. //JavaScript isn't going to handle that well...
  8434. //So we're using a trick that allows us to perform
  8435. //modulo math byte by byte
  8436. var remainder = 0;
  8437. for (var z = 0; z < 16; z++) {
  8438. remainder *= (256 % 3);
  8439. remainder %= 3;
  8440. remainder += ((e[z] >>> 0) % 3);
  8441. remainder %= 3;
  8442. }
  8443. if (remainder === 0) {
  8444. k = calculateSHA256(e, 0, e.length);
  8445. }
  8446. else if (remainder === 1) {
  8447. k = calculateSHA384(e, 0, e.length);
  8448. }
  8449. else if (remainder === 2) {
  8450. k = calculateSHA512(e, 0, e.length);
  8451. }
  8452. i++;
  8453. }
  8454. return k.subarray(0, 32);
  8455. }
  8456. function PDF20() {
  8457. }
  8458. function compareByteArrays(array1, array2) {
  8459. if (array1.length !== array2.length) {
  8460. return false;
  8461. }
  8462. for (var i = 0; i < array1.length; i++) {
  8463. if (array1[i] !== array2[i]) {
  8464. return false;
  8465. }
  8466. }
  8467. return true;
  8468. }
  8469. PDF20.prototype = {
  8470. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8471. return calculatePDF20Hash(password, concatBytes, userBytes);
  8472. },
  8473. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8474. ownerValidationSalt,
  8475. userBytes,
  8476. ownerPassword) {
  8477. var hashData = new Uint8Array(password.length + 56);
  8478. hashData.set(password, 0);
  8479. hashData.set(ownerValidationSalt, password.length);
  8480. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8481. var result = calculatePDF20Hash(password, hashData, userBytes);
  8482. return compareByteArrays(result, ownerPassword);
  8483. },
  8484. checkUserPassword: function PDF20_checkUserPassword(password,
  8485. userValidationSalt,
  8486. userPassword) {
  8487. var hashData = new Uint8Array(password.length + 8);
  8488. hashData.set(password, 0);
  8489. hashData.set(userValidationSalt, password.length);
  8490. var result = calculatePDF20Hash(password, hashData, []);
  8491. return compareByteArrays(result, userPassword);
  8492. },
  8493. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8494. ownerEncryption) {
  8495. var hashData = new Uint8Array(password.length + 56);
  8496. hashData.set(password, 0);
  8497. hashData.set(ownerKeySalt, password.length);
  8498. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8499. var key = calculatePDF20Hash(password, hashData, userBytes);
  8500. var cipher = new AES256Cipher(key);
  8501. return cipher.decryptBlock(ownerEncryption,
  8502. false,
  8503. new Uint8Array(16));
  8504. },
  8505. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8506. userEncryption) {
  8507. var hashData = new Uint8Array(password.length + 8);
  8508. hashData.set(password, 0);
  8509. hashData.set(userKeySalt, password.length);
  8510. //key is the decryption key for the UE string
  8511. var key = calculatePDF20Hash(password, hashData, []);
  8512. var cipher = new AES256Cipher(key);
  8513. return cipher.decryptBlock(userEncryption,
  8514. false,
  8515. new Uint8Array(16));
  8516. }
  8517. };
  8518. return PDF20;
  8519. })();
  8520. var CipherTransform = (function CipherTransformClosure() {
  8521. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8522. this.stringCipherConstructor = stringCipherConstructor;
  8523. this.streamCipherConstructor = streamCipherConstructor;
  8524. }
  8525. CipherTransform.prototype = {
  8526. createStream: function CipherTransform_createStream(stream, length) {
  8527. var cipher = new this.streamCipherConstructor();
  8528. return new DecryptStream(stream, length,
  8529. function cipherTransformDecryptStream(data, finalize) {
  8530. return cipher.decryptBlock(data, finalize);
  8531. }
  8532. );
  8533. },
  8534. decryptString: function CipherTransform_decryptString(s) {
  8535. var cipher = new this.stringCipherConstructor();
  8536. var data = stringToBytes(s);
  8537. data = cipher.decryptBlock(data, true);
  8538. return bytesToString(data);
  8539. }
  8540. };
  8541. return CipherTransform;
  8542. })();
  8543. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8544. var defaultPasswordBytes = new Uint8Array([
  8545. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8546. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8547. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8548. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8549. function createEncryptionKey20(revision, password, ownerPassword,
  8550. ownerValidationSalt, ownerKeySalt, uBytes,
  8551. userPassword, userValidationSalt, userKeySalt,
  8552. ownerEncryption, userEncryption, perms) {
  8553. if (password) {
  8554. var passwordLength = Math.min(127, password.length);
  8555. password = password.subarray(0, passwordLength);
  8556. } else {
  8557. password = [];
  8558. }
  8559. var pdfAlgorithm;
  8560. if (revision === 6) {
  8561. pdfAlgorithm = new PDF20();
  8562. } else {
  8563. pdfAlgorithm = new PDF17();
  8564. }
  8565. if (pdfAlgorithm) {
  8566. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8567. userPassword)) {
  8568. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8569. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8570. uBytes,
  8571. ownerPassword)) {
  8572. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8573. ownerEncryption);
  8574. }
  8575. }
  8576. return null;
  8577. }
  8578. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8579. flags, revision, keyLength, encryptMetadata) {
  8580. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8581. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8582. if (password) {
  8583. n = Math.min(32, password.length);
  8584. for (; i < n; ++i) {
  8585. hashData[i] = password[i];
  8586. }
  8587. }
  8588. j = 0;
  8589. while (i < 32) {
  8590. hashData[i++] = defaultPasswordBytes[j++];
  8591. }
  8592. // as now the padded password in the hashData[0..i]
  8593. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8594. hashData[i++] = ownerPassword[j];
  8595. }
  8596. hashData[i++] = flags & 0xFF;
  8597. hashData[i++] = (flags >> 8) & 0xFF;
  8598. hashData[i++] = (flags >> 16) & 0xFF;
  8599. hashData[i++] = (flags >>> 24) & 0xFF;
  8600. for (j = 0, n = fileId.length; j < n; ++j) {
  8601. hashData[i++] = fileId[j];
  8602. }
  8603. if (revision >= 4 && !encryptMetadata) {
  8604. hashData[i++] = 0xFF;
  8605. hashData[i++] = 0xFF;
  8606. hashData[i++] = 0xFF;
  8607. hashData[i++] = 0xFF;
  8608. }
  8609. var hash = calculateMD5(hashData, 0, i);
  8610. var keyLengthInBytes = keyLength >> 3;
  8611. if (revision >= 3) {
  8612. for (j = 0; j < 50; ++j) {
  8613. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8614. }
  8615. }
  8616. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8617. var cipher, checkData;
  8618. if (revision >= 3) {
  8619. for (i = 0; i < 32; ++i) {
  8620. hashData[i] = defaultPasswordBytes[i];
  8621. }
  8622. for (j = 0, n = fileId.length; j < n; ++j) {
  8623. hashData[i++] = fileId[j];
  8624. }
  8625. cipher = new ARCFourCipher(encryptionKey);
  8626. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8627. n = encryptionKey.length;
  8628. var derivedKey = new Uint8Array(n), k;
  8629. for (j = 1; j <= 19; ++j) {
  8630. for (k = 0; k < n; ++k) {
  8631. derivedKey[k] = encryptionKey[k] ^ j;
  8632. }
  8633. cipher = new ARCFourCipher(derivedKey);
  8634. checkData = cipher.encryptBlock(checkData);
  8635. }
  8636. for (j = 0, n = checkData.length; j < n; ++j) {
  8637. if (userPassword[j] !== checkData[j]) {
  8638. return null;
  8639. }
  8640. }
  8641. } else {
  8642. cipher = new ARCFourCipher(encryptionKey);
  8643. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8644. for (j = 0, n = checkData.length; j < n; ++j) {
  8645. if (userPassword[j] !== checkData[j]) {
  8646. return null;
  8647. }
  8648. }
  8649. }
  8650. return encryptionKey;
  8651. }
  8652. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8653. var hashData = new Uint8Array(32), i = 0, j, n;
  8654. n = Math.min(32, password.length);
  8655. for (; i < n; ++i) {
  8656. hashData[i] = password[i];
  8657. }
  8658. j = 0;
  8659. while (i < 32) {
  8660. hashData[i++] = defaultPasswordBytes[j++];
  8661. }
  8662. var hash = calculateMD5(hashData, 0, i);
  8663. var keyLengthInBytes = keyLength >> 3;
  8664. if (revision >= 3) {
  8665. for (j = 0; j < 50; ++j) {
  8666. hash = calculateMD5(hash, 0, hash.length);
  8667. }
  8668. }
  8669. var cipher, userPassword;
  8670. if (revision >= 3) {
  8671. userPassword = ownerPassword;
  8672. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8673. for (j = 19; j >= 0; j--) {
  8674. for (k = 0; k < keyLengthInBytes; ++k) {
  8675. derivedKey[k] = hash[k] ^ j;
  8676. }
  8677. cipher = new ARCFourCipher(derivedKey);
  8678. userPassword = cipher.encryptBlock(userPassword);
  8679. }
  8680. } else {
  8681. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8682. userPassword = cipher.encryptBlock(ownerPassword);
  8683. }
  8684. return userPassword;
  8685. }
  8686. var identityName = Name.get('Identity');
  8687. function CipherTransformFactory(dict, fileId, password) {
  8688. var filter = dict.get('Filter');
  8689. if (!isName(filter) || filter.name !== 'Standard') {
  8690. error('unknown encryption method');
  8691. }
  8692. this.dict = dict;
  8693. var algorithm = dict.get('V');
  8694. if (!isInt(algorithm) ||
  8695. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8696. algorithm !== 5)) {
  8697. error('unsupported encryption algorithm');
  8698. }
  8699. this.algorithm = algorithm;
  8700. var keyLength = dict.get('Length') || 40;
  8701. if (!isInt(keyLength) ||
  8702. keyLength < 40 || (keyLength % 8) !== 0) {
  8703. error('invalid key length');
  8704. }
  8705. // prepare keys
  8706. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8707. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8708. var flags = dict.get('P');
  8709. var revision = dict.get('R');
  8710. // meaningful when V is 4 or 5
  8711. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8712. dict.get('EncryptMetadata') !== false);
  8713. this.encryptMetadata = encryptMetadata;
  8714. var fileIdBytes = stringToBytes(fileId);
  8715. var passwordBytes;
  8716. if (password) {
  8717. passwordBytes = stringToBytes(password);
  8718. }
  8719. var encryptionKey;
  8720. if (algorithm !== 5) {
  8721. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8722. ownerPassword, userPassword, flags,
  8723. revision, keyLength, encryptMetadata);
  8724. }
  8725. else {
  8726. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8727. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8728. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8729. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8730. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8731. var ownerEncryption = stringToBytes(dict.get('OE'));
  8732. var userEncryption = stringToBytes(dict.get('UE'));
  8733. var perms = stringToBytes(dict.get('Perms'));
  8734. encryptionKey =
  8735. createEncryptionKey20(revision, passwordBytes,
  8736. ownerPassword, ownerValidationSalt,
  8737. ownerKeySalt, uBytes,
  8738. userPassword, userValidationSalt,
  8739. userKeySalt, ownerEncryption,
  8740. userEncryption, perms);
  8741. }
  8742. if (!encryptionKey && !password) {
  8743. throw new PasswordException('No password given',
  8744. PasswordResponses.NEED_PASSWORD);
  8745. } else if (!encryptionKey && password) {
  8746. // Attempting use the password as an owner password
  8747. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8748. revision, keyLength);
  8749. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8750. ownerPassword, userPassword, flags,
  8751. revision, keyLength, encryptMetadata);
  8752. }
  8753. if (!encryptionKey) {
  8754. throw new PasswordException('Incorrect Password',
  8755. PasswordResponses.INCORRECT_PASSWORD);
  8756. }
  8757. this.encryptionKey = encryptionKey;
  8758. if (algorithm >= 4) {
  8759. this.cf = dict.get('CF');
  8760. this.stmf = dict.get('StmF') || identityName;
  8761. this.strf = dict.get('StrF') || identityName;
  8762. this.eff = dict.get('EFF') || this.strf;
  8763. }
  8764. }
  8765. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8766. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8767. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8768. key[i] = encryptionKey[i];
  8769. }
  8770. key[i++] = num & 0xFF;
  8771. key[i++] = (num >> 8) & 0xFF;
  8772. key[i++] = (num >> 16) & 0xFF;
  8773. key[i++] = gen & 0xFF;
  8774. key[i++] = (gen >> 8) & 0xFF;
  8775. if (isAes) {
  8776. key[i++] = 0x73;
  8777. key[i++] = 0x41;
  8778. key[i++] = 0x6C;
  8779. key[i++] = 0x54;
  8780. }
  8781. var hash = calculateMD5(key, 0, i);
  8782. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8783. }
  8784. function buildCipherConstructor(cf, name, num, gen, key) {
  8785. var cryptFilter = cf.get(name.name);
  8786. var cfm;
  8787. if (cryptFilter !== null && cryptFilter !== undefined) {
  8788. cfm = cryptFilter.get('CFM');
  8789. }
  8790. if (!cfm || cfm.name === 'None') {
  8791. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8792. return new NullCipher();
  8793. };
  8794. }
  8795. if ('V2' === cfm.name) {
  8796. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8797. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8798. };
  8799. }
  8800. if ('AESV2' === cfm.name) {
  8801. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8802. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8803. };
  8804. }
  8805. if ('AESV3' === cfm.name) {
  8806. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8807. return new AES256Cipher(key);
  8808. };
  8809. }
  8810. error('Unknown crypto method');
  8811. }
  8812. CipherTransformFactory.prototype = {
  8813. createCipherTransform:
  8814. function CipherTransformFactory_createCipherTransform(num, gen) {
  8815. if (this.algorithm === 4 || this.algorithm === 5) {
  8816. return new CipherTransform(
  8817. buildCipherConstructor(this.cf, this.stmf,
  8818. num, gen, this.encryptionKey),
  8819. buildCipherConstructor(this.cf, this.strf,
  8820. num, gen, this.encryptionKey));
  8821. }
  8822. // algorithms 1 and 2
  8823. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8824. var cipherConstructor = function buildCipherCipherConstructor() {
  8825. return new ARCFourCipher(key);
  8826. };
  8827. return new CipherTransform(cipherConstructor, cipherConstructor);
  8828. }
  8829. };
  8830. return CipherTransformFactory;
  8831. })();
  8832. var PatternType = {
  8833. FUNCTION_BASED: 1,
  8834. AXIAL: 2,
  8835. RADIAL: 3,
  8836. FREE_FORM_MESH: 4,
  8837. LATTICE_FORM_MESH: 5,
  8838. COONS_PATCH_MESH: 6,
  8839. TENSOR_PATCH_MESH: 7
  8840. };
  8841. var Pattern = (function PatternClosure() {
  8842. // Constructor should define this.getPattern
  8843. function Pattern() {
  8844. error('should not call Pattern constructor');
  8845. }
  8846. Pattern.prototype = {
  8847. // Input: current Canvas context
  8848. // Output: the appropriate fillStyle or strokeStyle
  8849. getPattern: function Pattern_getPattern(ctx) {
  8850. error('Should not call Pattern.getStyle: ' + ctx);
  8851. }
  8852. };
  8853. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8854. res) {
  8855. var dict = isStream(shading) ? shading.dict : shading;
  8856. var type = dict.get('ShadingType');
  8857. try {
  8858. switch (type) {
  8859. case PatternType.AXIAL:
  8860. case PatternType.RADIAL:
  8861. // Both radial and axial shadings are handled by RadialAxial shading.
  8862. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8863. case PatternType.FREE_FORM_MESH:
  8864. case PatternType.LATTICE_FORM_MESH:
  8865. case PatternType.COONS_PATCH_MESH:
  8866. case PatternType.TENSOR_PATCH_MESH:
  8867. return new Shadings.Mesh(shading, matrix, xref, res);
  8868. default:
  8869. throw new Error('Unknown PatternType: ' + type);
  8870. }
  8871. } catch (ex) {
  8872. if (ex instanceof MissingDataException) {
  8873. throw ex;
  8874. }
  8875. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8876. warn(ex);
  8877. return new Shadings.Dummy();
  8878. }
  8879. };
  8880. return Pattern;
  8881. })();
  8882. var Shadings = {};
  8883. // A small number to offset the first/last color stops so we can insert ones to
  8884. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8885. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8886. // internally so we have to go bigger.
  8887. Shadings.SMALL_NUMBER = 1e-2;
  8888. // Radial and axial shading have very similar implementations
  8889. // If needed, the implementations can be broken into two classes
  8890. Shadings.RadialAxial = (function RadialAxialClosure() {
  8891. function RadialAxial(dict, matrix, xref, res) {
  8892. this.matrix = matrix;
  8893. this.coordsArr = dict.get('Coords');
  8894. this.shadingType = dict.get('ShadingType');
  8895. this.type = 'Pattern';
  8896. var cs = dict.get('ColorSpace', 'CS');
  8897. cs = ColorSpace.parse(cs, xref, res);
  8898. this.cs = cs;
  8899. var t0 = 0.0, t1 = 1.0;
  8900. if (dict.has('Domain')) {
  8901. var domainArr = dict.get('Domain');
  8902. t0 = domainArr[0];
  8903. t1 = domainArr[1];
  8904. }
  8905. var extendStart = false, extendEnd = false;
  8906. if (dict.has('Extend')) {
  8907. var extendArr = dict.get('Extend');
  8908. extendStart = extendArr[0];
  8909. extendEnd = extendArr[1];
  8910. }
  8911. if (this.shadingType === PatternType.RADIAL &&
  8912. (!extendStart || !extendEnd)) {
  8913. // Radial gradient only currently works if either circle is fully within
  8914. // the other circle.
  8915. var x1 = this.coordsArr[0];
  8916. var y1 = this.coordsArr[1];
  8917. var r1 = this.coordsArr[2];
  8918. var x2 = this.coordsArr[3];
  8919. var y2 = this.coordsArr[4];
  8920. var r2 = this.coordsArr[5];
  8921. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8922. if (r1 <= r2 + distance &&
  8923. r2 <= r1 + distance) {
  8924. warn('Unsupported radial gradient.');
  8925. }
  8926. }
  8927. this.extendStart = extendStart;
  8928. this.extendEnd = extendEnd;
  8929. var fnObj = dict.get('Function');
  8930. var fn = PDFFunction.parseArray(xref, fnObj);
  8931. // 10 samples seems good enough for now, but probably won't work
  8932. // if there are sharp color changes. Ideally, we would implement
  8933. // the spec faithfully and add lossless optimizations.
  8934. var diff = t1 - t0;
  8935. var step = diff / 10;
  8936. var colorStops = this.colorStops = [];
  8937. // Protect against bad domains so we don't end up in an infinte loop below.
  8938. if (t0 >= t1 || step <= 0) {
  8939. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8940. // now.
  8941. info('Bad shading domain.');
  8942. return;
  8943. }
  8944. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8945. var rgbColor;
  8946. for (var i = t0; i <= t1; i += step) {
  8947. ratio[0] = i;
  8948. fn(ratio, 0, color, 0);
  8949. rgbColor = cs.getRgb(color, 0);
  8950. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8951. colorStops.push([(i - t0) / diff, cssColor]);
  8952. }
  8953. var background = 'transparent';
  8954. if (dict.has('Background')) {
  8955. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8956. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8957. }
  8958. if (!extendStart) {
  8959. // Insert a color stop at the front and offset the first real color stop
  8960. // so it doesn't conflict with the one we insert.
  8961. colorStops.unshift([0, background]);
  8962. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8963. }
  8964. if (!extendEnd) {
  8965. // Same idea as above in extendStart but for the end.
  8966. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8967. colorStops.push([1, background]);
  8968. }
  8969. this.colorStops = colorStops;
  8970. }
  8971. RadialAxial.prototype = {
  8972. getIR: function RadialAxial_getIR() {
  8973. var coordsArr = this.coordsArr;
  8974. var shadingType = this.shadingType;
  8975. var type, p0, p1, r0, r1;
  8976. if (shadingType === PatternType.AXIAL) {
  8977. p0 = [coordsArr[0], coordsArr[1]];
  8978. p1 = [coordsArr[2], coordsArr[3]];
  8979. r0 = null;
  8980. r1 = null;
  8981. type = 'axial';
  8982. } else if (shadingType === PatternType.RADIAL) {
  8983. p0 = [coordsArr[0], coordsArr[1]];
  8984. p1 = [coordsArr[3], coordsArr[4]];
  8985. r0 = coordsArr[2];
  8986. r1 = coordsArr[5];
  8987. type = 'radial';
  8988. } else {
  8989. error('getPattern type unknown: ' + shadingType);
  8990. }
  8991. var matrix = this.matrix;
  8992. if (matrix) {
  8993. p0 = Util.applyTransform(p0, matrix);
  8994. p1 = Util.applyTransform(p1, matrix);
  8995. }
  8996. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8997. }
  8998. };
  8999. return RadialAxial;
  9000. })();
  9001. // All mesh shading. For now, they will be presented as set of the triangles
  9002. // to be drawn on the canvas and rgb color for each vertex.
  9003. Shadings.Mesh = (function MeshClosure() {
  9004. function MeshStreamReader(stream, context) {
  9005. this.stream = stream;
  9006. this.context = context;
  9007. this.buffer = 0;
  9008. this.bufferLength = 0;
  9009. var numComps = context.numComps;
  9010. this.tmpCompsBuf = new Float32Array(numComps);
  9011. var csNumComps = context.colorSpace;
  9012. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9013. this.tmpCompsBuf;
  9014. }
  9015. MeshStreamReader.prototype = {
  9016. get hasData() {
  9017. if (this.stream.end) {
  9018. return this.stream.pos < this.stream.end;
  9019. }
  9020. if (this.bufferLength > 0) {
  9021. return true;
  9022. }
  9023. var nextByte = this.stream.getByte();
  9024. if (nextByte < 0) {
  9025. return false;
  9026. }
  9027. this.buffer = nextByte;
  9028. this.bufferLength = 8;
  9029. return true;
  9030. },
  9031. readBits: function MeshStreamReader_readBits(n) {
  9032. var buffer = this.buffer;
  9033. var bufferLength = this.bufferLength;
  9034. if (n === 32) {
  9035. if (bufferLength === 0) {
  9036. return ((this.stream.getByte() << 24) |
  9037. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9038. this.stream.getByte()) >>> 0;
  9039. }
  9040. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9041. (this.stream.getByte() << 8) | this.stream.getByte();
  9042. var nextByte = this.stream.getByte();
  9043. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9044. return ((buffer << (8 - bufferLength)) |
  9045. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9046. }
  9047. if (n === 8 && bufferLength === 0) {
  9048. return this.stream.getByte();
  9049. }
  9050. while (bufferLength < n) {
  9051. buffer = (buffer << 8) | this.stream.getByte();
  9052. bufferLength += 8;
  9053. }
  9054. bufferLength -= n;
  9055. this.bufferLength = bufferLength;
  9056. this.buffer = buffer & ((1 << bufferLength) - 1);
  9057. return buffer >> bufferLength;
  9058. },
  9059. align: function MeshStreamReader_align() {
  9060. this.buffer = 0;
  9061. this.bufferLength = 0;
  9062. },
  9063. readFlag: function MeshStreamReader_readFlag() {
  9064. return this.readBits(this.context.bitsPerFlag);
  9065. },
  9066. readCoordinate: function MeshStreamReader_readCoordinate() {
  9067. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9068. var xi = this.readBits(bitsPerCoordinate);
  9069. var yi = this.readBits(bitsPerCoordinate);
  9070. var decode = this.context.decode;
  9071. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9072. 2.3283064365386963e-10; // 2 ^ -32
  9073. return [
  9074. xi * scale * (decode[1] - decode[0]) + decode[0],
  9075. yi * scale * (decode[3] - decode[2]) + decode[2]
  9076. ];
  9077. },
  9078. readComponents: function MeshStreamReader_readComponents() {
  9079. var numComps = this.context.numComps;
  9080. var bitsPerComponent = this.context.bitsPerComponent;
  9081. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9082. 2.3283064365386963e-10; // 2 ^ -32
  9083. var decode = this.context.decode;
  9084. var components = this.tmpCompsBuf;
  9085. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9086. var ci = this.readBits(bitsPerComponent);
  9087. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9088. }
  9089. var color = this.tmpCsCompsBuf;
  9090. if (this.context.colorFn) {
  9091. this.context.colorFn(components, 0, color, 0);
  9092. }
  9093. return this.context.colorSpace.getRgb(color, 0);
  9094. }
  9095. };
  9096. function decodeType4Shading(mesh, reader) {
  9097. var coords = mesh.coords;
  9098. var colors = mesh.colors;
  9099. var operators = [];
  9100. var ps = []; // not maintaining cs since that will match ps
  9101. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9102. while (reader.hasData) {
  9103. var f = reader.readFlag();
  9104. var coord = reader.readCoordinate();
  9105. var color = reader.readComponents();
  9106. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9107. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9108. switch (f) {
  9109. case 0:
  9110. verticesLeft = 3;
  9111. break;
  9112. case 1:
  9113. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9114. verticesLeft = 1;
  9115. break;
  9116. case 2:
  9117. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9118. verticesLeft = 1;
  9119. break;
  9120. }
  9121. operators.push(f);
  9122. }
  9123. ps.push(coords.length);
  9124. coords.push(coord);
  9125. colors.push(color);
  9126. verticesLeft--;
  9127. reader.align();
  9128. }
  9129. var psPacked = new Int32Array(ps);
  9130. mesh.figures.push({
  9131. type: 'triangles',
  9132. coords: psPacked,
  9133. colors: psPacked
  9134. });
  9135. }
  9136. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9137. var coords = mesh.coords;
  9138. var colors = mesh.colors;
  9139. var ps = []; // not maintaining cs since that will match ps
  9140. while (reader.hasData) {
  9141. var coord = reader.readCoordinate();
  9142. var color = reader.readComponents();
  9143. ps.push(coords.length);
  9144. coords.push(coord);
  9145. colors.push(color);
  9146. }
  9147. var psPacked = new Int32Array(ps);
  9148. mesh.figures.push({
  9149. type: 'lattice',
  9150. coords: psPacked,
  9151. colors: psPacked,
  9152. verticesPerRow: verticesPerRow
  9153. });
  9154. }
  9155. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9156. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9157. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9158. var getB = (function getBClosure() {
  9159. function buildB(count) {
  9160. var lut = [];
  9161. for (var i = 0; i <= count; i++) {
  9162. var t = i / count, t_ = 1 - t;
  9163. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9164. 3 * t * t * t_, t * t * t]));
  9165. }
  9166. return lut;
  9167. }
  9168. var cache = [];
  9169. return function getB(count) {
  9170. if (!cache[count]) {
  9171. cache[count] = buildB(count);
  9172. }
  9173. return cache[count];
  9174. };
  9175. })();
  9176. function buildFigureFromPatch(mesh, index) {
  9177. var figure = mesh.figures[index];
  9178. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9179. var coords = mesh.coords, colors = mesh.colors;
  9180. var pi = figure.coords;
  9181. var ci = figure.colors;
  9182. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9183. coords[pi[12]][0], coords[pi[15]][0]);
  9184. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9185. coords[pi[12]][1], coords[pi[15]][1]);
  9186. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9187. coords[pi[12]][0], coords[pi[15]][0]);
  9188. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9189. coords[pi[12]][1], coords[pi[15]][1]);
  9190. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9191. (mesh.bounds[2] - mesh.bounds[0]));
  9192. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9193. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9194. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9195. (mesh.bounds[3] - mesh.bounds[1]));
  9196. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9197. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9198. var verticesPerRow = splitXBy + 1;
  9199. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9200. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9201. var k = 0;
  9202. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9203. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9204. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9205. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9206. for (var row = 0; row <= splitYBy; row++) {
  9207. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9208. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9209. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9210. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9211. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9212. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9213. for (var col = 0; col <= splitXBy; col++, k++) {
  9214. if ((row === 0 || row === splitYBy) &&
  9215. (col === 0 || col === splitXBy)) {
  9216. continue;
  9217. }
  9218. var x = 0, y = 0;
  9219. var q = 0;
  9220. for (var i = 0; i <= 3; i++) {
  9221. for (var j = 0; j <= 3; j++, q++) {
  9222. var m = bRow[row][i] * bCol[col][j];
  9223. x += coords[pi[q]][0] * m;
  9224. y += coords[pi[q]][1] * m;
  9225. }
  9226. }
  9227. figureCoords[k] = coords.length;
  9228. coords.push([x, y]);
  9229. figureColors[k] = colors.length;
  9230. var newColor = new Uint8Array(3);
  9231. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9232. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9233. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9234. colors.push(newColor);
  9235. }
  9236. }
  9237. figureCoords[0] = pi[0];
  9238. figureColors[0] = ci[0];
  9239. figureCoords[splitXBy] = pi[3];
  9240. figureColors[splitXBy] = ci[1];
  9241. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9242. figureColors[verticesPerRow * splitYBy] = ci[2];
  9243. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9244. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9245. mesh.figures[index] = {
  9246. type: 'lattice',
  9247. coords: figureCoords,
  9248. colors: figureColors,
  9249. verticesPerRow: verticesPerRow
  9250. };
  9251. }
  9252. function decodeType6Shading(mesh, reader) {
  9253. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9254. var coords = mesh.coords;
  9255. var colors = mesh.colors;
  9256. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9257. var cs = new Int32Array(4); // c00, c30, c03, c33
  9258. while (reader.hasData) {
  9259. var f = reader.readFlag();
  9260. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9261. var i, ii;
  9262. var pi = coords.length;
  9263. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9264. coords.push(reader.readCoordinate());
  9265. }
  9266. var ci = colors.length;
  9267. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9268. colors.push(reader.readComponents());
  9269. }
  9270. var tmp1, tmp2, tmp3, tmp4;
  9271. switch (f) {
  9272. case 0:
  9273. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9274. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9275. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9276. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9277. cs[2] = ci + 1; cs[3] = ci + 2;
  9278. cs[0] = ci; cs[1] = ci + 3;
  9279. break;
  9280. case 1:
  9281. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9282. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9283. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9284. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9285. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9286. tmp1 = cs[2]; tmp2 = cs[3];
  9287. cs[2] = ci + 1; cs[3] = ci;
  9288. cs[0] = tmp1; cs[1] = tmp2;
  9289. break;
  9290. case 2:
  9291. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9292. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9293. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9294. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9295. cs[2] = cs[3]; cs[3] = ci + 1;
  9296. cs[0] = cs[1]; cs[1] = ci;
  9297. break;
  9298. case 3:
  9299. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9300. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9301. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9302. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9303. cs[2] = cs[0]; cs[3] = cs[1];
  9304. cs[0] = ci; cs[1] = ci + 1;
  9305. break;
  9306. }
  9307. // set p11, p12, p21, p22
  9308. ps[5] = coords.length;
  9309. coords.push([
  9310. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9311. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9312. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9313. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9314. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9315. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9316. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9317. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9318. ]);
  9319. ps[6] = coords.length;
  9320. coords.push([
  9321. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9322. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9323. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9324. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9325. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9326. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9327. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9328. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9329. ]);
  9330. ps[9] = coords.length;
  9331. coords.push([
  9332. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9333. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9334. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9335. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9336. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9337. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9338. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9339. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9340. ]);
  9341. ps[10] = coords.length;
  9342. coords.push([
  9343. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9344. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9345. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9346. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9347. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9348. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9349. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9350. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9351. ]);
  9352. mesh.figures.push({
  9353. type: 'patch',
  9354. coords: new Int32Array(ps), // making copies of ps and cs
  9355. colors: new Int32Array(cs)
  9356. });
  9357. }
  9358. }
  9359. function decodeType7Shading(mesh, reader) {
  9360. var coords = mesh.coords;
  9361. var colors = mesh.colors;
  9362. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9363. var cs = new Int32Array(4); // c00, c30, c03, c33
  9364. while (reader.hasData) {
  9365. var f = reader.readFlag();
  9366. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9367. var i, ii;
  9368. var pi = coords.length;
  9369. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9370. coords.push(reader.readCoordinate());
  9371. }
  9372. var ci = colors.length;
  9373. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9374. colors.push(reader.readComponents());
  9375. }
  9376. var tmp1, tmp2, tmp3, tmp4;
  9377. switch (f) {
  9378. case 0:
  9379. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9380. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9381. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9382. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9383. cs[2] = ci + 1; cs[3] = ci + 2;
  9384. cs[0] = ci; cs[1] = ci + 3;
  9385. break;
  9386. case 1:
  9387. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9388. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9389. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9390. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9391. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9392. tmp1 = cs[2]; tmp2 = cs[3];
  9393. cs[2] = ci + 1; cs[3] = ci;
  9394. cs[0] = tmp1; cs[1] = tmp2;
  9395. break;
  9396. case 2:
  9397. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9398. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9399. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9400. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9401. cs[2] = cs[3]; cs[3] = ci + 1;
  9402. cs[0] = cs[1]; cs[1] = ci;
  9403. break;
  9404. case 3:
  9405. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9406. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9407. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9408. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9409. cs[2] = cs[0]; cs[3] = cs[1];
  9410. cs[0] = ci; cs[1] = ci + 1;
  9411. break;
  9412. }
  9413. mesh.figures.push({
  9414. type: 'patch',
  9415. coords: new Int32Array(ps), // making copies of ps and cs
  9416. colors: new Int32Array(cs)
  9417. });
  9418. }
  9419. }
  9420. function updateBounds(mesh) {
  9421. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9422. maxX = minX, maxY = minY;
  9423. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9424. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9425. minX = minX > x ? x : minX;
  9426. minY = minY > y ? y : minY;
  9427. maxX = maxX < x ? x : maxX;
  9428. maxY = maxY < y ? y : maxY;
  9429. }
  9430. mesh.bounds = [minX, minY, maxX, maxY];
  9431. }
  9432. function packData(mesh) {
  9433. var i, ii, j, jj;
  9434. var coords = mesh.coords;
  9435. var coordsPacked = new Float32Array(coords.length * 2);
  9436. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9437. var xy = coords[i];
  9438. coordsPacked[j++] = xy[0];
  9439. coordsPacked[j++] = xy[1];
  9440. }
  9441. mesh.coords = coordsPacked;
  9442. var colors = mesh.colors;
  9443. var colorsPacked = new Uint8Array(colors.length * 3);
  9444. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9445. var c = colors[i];
  9446. colorsPacked[j++] = c[0];
  9447. colorsPacked[j++] = c[1];
  9448. colorsPacked[j++] = c[2];
  9449. }
  9450. mesh.colors = colorsPacked;
  9451. var figures = mesh.figures;
  9452. for (i = 0, ii = figures.length; i < ii; i++) {
  9453. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9454. for (j = 0, jj = ps.length; j < jj; j++) {
  9455. ps[j] *= 2;
  9456. cs[j] *= 3;
  9457. }
  9458. }
  9459. }
  9460. function Mesh(stream, matrix, xref, res) {
  9461. assert(isStream(stream), 'Mesh data is not a stream');
  9462. var dict = stream.dict;
  9463. this.matrix = matrix;
  9464. this.shadingType = dict.get('ShadingType');
  9465. this.type = 'Pattern';
  9466. this.bbox = dict.get('BBox');
  9467. var cs = dict.get('ColorSpace', 'CS');
  9468. cs = ColorSpace.parse(cs, xref, res);
  9469. this.cs = cs;
  9470. this.background = dict.has('Background') ?
  9471. cs.getRgb(dict.get('Background'), 0) : null;
  9472. var fnObj = dict.get('Function');
  9473. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9474. this.coords = [];
  9475. this.colors = [];
  9476. this.figures = [];
  9477. var decodeContext = {
  9478. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9479. bitsPerComponent: dict.get('BitsPerComponent'),
  9480. bitsPerFlag: dict.get('BitsPerFlag'),
  9481. decode: dict.get('Decode'),
  9482. colorFn: fn,
  9483. colorSpace: cs,
  9484. numComps: fn ? 1 : cs.numComps
  9485. };
  9486. var reader = new MeshStreamReader(stream, decodeContext);
  9487. var patchMesh = false;
  9488. switch (this.shadingType) {
  9489. case PatternType.FREE_FORM_MESH:
  9490. decodeType4Shading(this, reader);
  9491. break;
  9492. case PatternType.LATTICE_FORM_MESH:
  9493. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9494. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9495. decodeType5Shading(this, reader, verticesPerRow);
  9496. break;
  9497. case PatternType.COONS_PATCH_MESH:
  9498. decodeType6Shading(this, reader);
  9499. patchMesh = true;
  9500. break;
  9501. case PatternType.TENSOR_PATCH_MESH:
  9502. decodeType7Shading(this, reader);
  9503. patchMesh = true;
  9504. break;
  9505. default:
  9506. error('Unsupported mesh type.');
  9507. break;
  9508. }
  9509. if (patchMesh) {
  9510. // dirty bounds calculation for determining, how dense shall be triangles
  9511. updateBounds(this);
  9512. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9513. buildFigureFromPatch(this, i);
  9514. }
  9515. }
  9516. // calculate bounds
  9517. updateBounds(this);
  9518. packData(this);
  9519. }
  9520. Mesh.prototype = {
  9521. getIR: function Mesh_getIR() {
  9522. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9523. this.bounds, this.matrix, this.bbox, this.background];
  9524. }
  9525. };
  9526. return Mesh;
  9527. })();
  9528. Shadings.Dummy = (function DummyClosure() {
  9529. function Dummy() {
  9530. this.type = 'Pattern';
  9531. }
  9532. Dummy.prototype = {
  9533. getIR: function Dummy_getIR() {
  9534. return ['Dummy'];
  9535. }
  9536. };
  9537. return Dummy;
  9538. })();
  9539. function getTilingPatternIR(operatorList, dict, args) {
  9540. var matrix = dict.get('Matrix');
  9541. var bbox = dict.get('BBox');
  9542. var xstep = dict.get('XStep');
  9543. var ystep = dict.get('YStep');
  9544. var paintType = dict.get('PaintType');
  9545. var tilingType = dict.get('TilingType');
  9546. return [
  9547. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9548. paintType, tilingType
  9549. ];
  9550. }
  9551. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9552. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9553. uniquePrefix, idCounters, fontCache) {
  9554. this.pdfManager = pdfManager;
  9555. this.xref = xref;
  9556. this.handler = handler;
  9557. this.pageIndex = pageIndex;
  9558. this.uniquePrefix = uniquePrefix;
  9559. this.idCounters = idCounters;
  9560. this.fontCache = fontCache;
  9561. }
  9562. // Trying to minimize Date.now() usage and check every 100 time
  9563. var TIME_SLOT_DURATION_MS = 20;
  9564. var CHECK_TIME_EVERY = 100;
  9565. function TimeSlotManager() {
  9566. this.reset();
  9567. }
  9568. TimeSlotManager.prototype = {
  9569. check: function TimeSlotManager_check() {
  9570. if (++this.checked < CHECK_TIME_EVERY) {
  9571. return false;
  9572. }
  9573. this.checked = 0;
  9574. return this.endTime <= Date.now();
  9575. },
  9576. reset: function TimeSlotManager_reset() {
  9577. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9578. this.checked = 0;
  9579. }
  9580. };
  9581. var deferred = Promise.resolve();
  9582. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9583. PartialEvaluator.prototype = {
  9584. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9585. if (!isDict(resources)) {
  9586. return false;
  9587. }
  9588. var processed = Object.create(null);
  9589. if (resources.objId) {
  9590. processed[resources.objId] = true;
  9591. }
  9592. var nodes = [resources];
  9593. while (nodes.length) {
  9594. var key;
  9595. var node = nodes.shift();
  9596. // First check the current resources for blend modes.
  9597. var graphicStates = node.get('ExtGState');
  9598. if (isDict(graphicStates)) {
  9599. graphicStates = graphicStates.getAll();
  9600. for (key in graphicStates) {
  9601. var graphicState = graphicStates[key];
  9602. var bm = graphicState['BM'];
  9603. if (isName(bm) && bm.name !== 'Normal') {
  9604. return true;
  9605. }
  9606. }
  9607. }
  9608. // Descend into the XObjects to look for more resources and blend modes.
  9609. var xObjects = node.get('XObject');
  9610. if (!isDict(xObjects)) {
  9611. continue;
  9612. }
  9613. xObjects = xObjects.getAll();
  9614. for (key in xObjects) {
  9615. var xObject = xObjects[key];
  9616. if (!isStream(xObject)) {
  9617. continue;
  9618. }
  9619. if (xObject.dict.objId) {
  9620. if (processed[xObject.dict.objId]) {
  9621. // stream has objId and is processed already
  9622. continue;
  9623. }
  9624. processed[xObject.dict.objId] = true;
  9625. }
  9626. var xResources = xObject.dict.get('Resources');
  9627. // Checking objId to detect an infinite loop.
  9628. if (isDict(xResources) &&
  9629. (!xResources.objId || !processed[xResources.objId])) {
  9630. nodes.push(xResources);
  9631. if (xResources.objId) {
  9632. processed[xResources.objId] = true;
  9633. }
  9634. }
  9635. }
  9636. }
  9637. return false;
  9638. },
  9639. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9640. xobj, smask,
  9641. operatorList,
  9642. initialState) {
  9643. var matrix = xobj.dict.get('Matrix');
  9644. var bbox = xobj.dict.get('BBox');
  9645. var group = xobj.dict.get('Group');
  9646. if (group) {
  9647. var groupOptions = {
  9648. matrix: matrix,
  9649. bbox: bbox,
  9650. smask: smask,
  9651. isolated: false,
  9652. knockout: false
  9653. };
  9654. var groupSubtype = group.get('S');
  9655. var colorSpace;
  9656. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9657. groupOptions.isolated = (group.get('I') || false);
  9658. groupOptions.knockout = (group.get('K') || false);
  9659. colorSpace = (group.has('CS') ?
  9660. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9661. }
  9662. if (smask && smask.backdrop) {
  9663. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9664. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9665. }
  9666. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9667. }
  9668. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9669. return this.getOperatorList(xobj,
  9670. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9671. then(function () {
  9672. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9673. if (group) {
  9674. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9675. }
  9676. });
  9677. },
  9678. buildPaintImageXObject:
  9679. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9680. inline, operatorList,
  9681. cacheKey, imageCache) {
  9682. var self = this;
  9683. var dict = image.dict;
  9684. var w = dict.get('Width', 'W');
  9685. var h = dict.get('Height', 'H');
  9686. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9687. warn('Image dimensions are missing, or not numbers.');
  9688. return;
  9689. }
  9690. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9691. warn('Image exceeded maximum allowed size and was removed.');
  9692. return;
  9693. }
  9694. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9695. var imgData, args;
  9696. if (imageMask) {
  9697. // This depends on a tmpCanvas being filled with the
  9698. // current fillStyle, such that processing the pixel
  9699. // data can't be done here. Instead of creating a
  9700. // complete PDFImage, only read the information needed
  9701. // for later.
  9702. var width = dict.get('Width', 'W');
  9703. var height = dict.get('Height', 'H');
  9704. var bitStrideLength = (width + 7) >> 3;
  9705. var imgArray = image.getBytes(bitStrideLength * height);
  9706. var decode = dict.get('Decode', 'D');
  9707. var inverseDecode = (!!decode && decode[0] > 0);
  9708. imgData = PDFImage.createMask(imgArray, width, height,
  9709. image instanceof DecodeStream,
  9710. inverseDecode);
  9711. imgData.cached = true;
  9712. args = [imgData];
  9713. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9714. if (cacheKey) {
  9715. imageCache[cacheKey] = {
  9716. fn: OPS.paintImageMaskXObject,
  9717. args: args
  9718. };
  9719. }
  9720. return;
  9721. }
  9722. var softMask = (dict.get('SMask', 'SM') || false);
  9723. var mask = (dict.get('Mask') || false);
  9724. var SMALL_IMAGE_DIMENSIONS = 200;
  9725. // Inlining small images into the queue as RGB data
  9726. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9727. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9728. var imageObj = new PDFImage(this.xref, resources, image,
  9729. inline, null, null);
  9730. // We force the use of RGBA_32BPP images here, because we can't handle
  9731. // any other kind.
  9732. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9733. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9734. return;
  9735. }
  9736. // If there is no imageMask, create the PDFImage and a lot
  9737. // of image processing can be done here.
  9738. var uniquePrefix = (this.uniquePrefix || '');
  9739. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9740. operatorList.addDependency(objId);
  9741. args = [objId, w, h];
  9742. if (!softMask && !mask && image instanceof JpegStream &&
  9743. image.isNativelySupported(this.xref, resources)) {
  9744. // These JPEGs don't need any more processing so we can just send it.
  9745. operatorList.addOp(OPS.paintJpegXObject, args);
  9746. this.handler.send('obj',
  9747. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9748. return;
  9749. }
  9750. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9751. then(function(imageObj) {
  9752. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9753. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9754. [imgData.data.buffer]);
  9755. }).then(undefined, function (reason) {
  9756. warn('Unable to decode image: ' + reason);
  9757. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9758. });
  9759. operatorList.addOp(OPS.paintImageXObject, args);
  9760. if (cacheKey) {
  9761. imageCache[cacheKey] = {
  9762. fn: OPS.paintImageXObject,
  9763. args: args
  9764. };
  9765. }
  9766. },
  9767. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9768. operatorList,
  9769. stateManager) {
  9770. var smaskContent = smask.get('G');
  9771. var smaskOptions = {
  9772. subtype: smask.get('S').name,
  9773. backdrop: smask.get('BC')
  9774. };
  9775. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9776. operatorList, stateManager.state.clone());
  9777. },
  9778. handleTilingType:
  9779. function PartialEvaluator_handleTilingType(fn, args, resources,
  9780. pattern, patternDict,
  9781. operatorList) {
  9782. // Create an IR of the pattern code.
  9783. var tilingOpList = new OperatorList();
  9784. return this.getOperatorList(pattern,
  9785. (patternDict.get('Resources') || resources), tilingOpList).
  9786. then(function () {
  9787. // Add the dependencies to the parent operator list so they are
  9788. // resolved before sub operator list is executed synchronously.
  9789. operatorList.addDependencies(tilingOpList.dependencies);
  9790. operatorList.addOp(fn, getTilingPatternIR({
  9791. fnArray: tilingOpList.fnArray,
  9792. argsArray: tilingOpList.argsArray
  9793. }, patternDict, args));
  9794. });
  9795. },
  9796. handleSetFont:
  9797. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9798. operatorList, state) {
  9799. // TODO(mack): Not needed?
  9800. var fontName;
  9801. if (fontArgs) {
  9802. fontArgs = fontArgs.slice();
  9803. fontName = fontArgs[0].name;
  9804. }
  9805. var self = this;
  9806. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9807. function (translated) {
  9808. if (!translated.font.isType3Font) {
  9809. return translated;
  9810. }
  9811. return translated.loadType3Data(self, resources, operatorList).then(
  9812. function () {
  9813. return translated;
  9814. });
  9815. }).then(function (translated) {
  9816. state.font = translated.font;
  9817. translated.send(self.handler);
  9818. return translated.loadedName;
  9819. });
  9820. },
  9821. handleText: function PartialEvaluator_handleText(chars, state) {
  9822. var font = state.font;
  9823. var glyphs = font.charsToGlyphs(chars);
  9824. var isAddToPathSet = !!(state.textRenderingMode &
  9825. TextRenderingMode.ADD_TO_PATH_FLAG);
  9826. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9827. var buildPath = function (fontChar) {
  9828. if (!font.renderer.hasBuiltPath(fontChar)) {
  9829. var path = font.renderer.getPathJs(fontChar);
  9830. this.handler.send('commonobj', [
  9831. font.loadedName + '_path_' + fontChar,
  9832. 'FontPath',
  9833. path
  9834. ]);
  9835. }
  9836. }.bind(this);
  9837. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9838. var glyph = glyphs[i];
  9839. if (glyph === null) {
  9840. continue;
  9841. }
  9842. buildPath(glyph.fontChar);
  9843. // If the glyph has an accent we need to build a path for its
  9844. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9845. var accent = glyph.accent;
  9846. if (accent && accent.fontChar) {
  9847. buildPath(accent.fontChar);
  9848. }
  9849. }
  9850. }
  9851. return glyphs;
  9852. },
  9853. setGState: function PartialEvaluator_setGState(resources, gState,
  9854. operatorList, xref,
  9855. stateManager) {
  9856. // This array holds the converted/processed state data.
  9857. var gStateObj = [];
  9858. var gStateMap = gState.map;
  9859. var self = this;
  9860. var promise = Promise.resolve();
  9861. for (var key in gStateMap) {
  9862. var value = gStateMap[key];
  9863. switch (key) {
  9864. case 'Type':
  9865. break;
  9866. case 'LW':
  9867. case 'LC':
  9868. case 'LJ':
  9869. case 'ML':
  9870. case 'D':
  9871. case 'RI':
  9872. case 'FL':
  9873. case 'CA':
  9874. case 'ca':
  9875. gStateObj.push([key, value]);
  9876. break;
  9877. case 'Font':
  9878. promise = promise.then(function () {
  9879. return self.handleSetFont(resources, null, value[0],
  9880. operatorList, stateManager.state).
  9881. then(function (loadedName) {
  9882. operatorList.addDependency(loadedName);
  9883. gStateObj.push([key, [loadedName, value[1]]]);
  9884. });
  9885. });
  9886. break;
  9887. case 'BM':
  9888. gStateObj.push([key, value]);
  9889. break;
  9890. case 'SMask':
  9891. if (isName(value) && value.name === 'None') {
  9892. gStateObj.push([key, false]);
  9893. break;
  9894. }
  9895. var dict = xref.fetchIfRef(value);
  9896. if (isDict(dict)) {
  9897. promise = promise.then(function () {
  9898. return self.handleSMask(dict, resources, operatorList,
  9899. stateManager);
  9900. });
  9901. gStateObj.push([key, true]);
  9902. } else {
  9903. warn('Unsupported SMask type');
  9904. }
  9905. break;
  9906. // Only generate info log messages for the following since
  9907. // they are unlikely to have a big impact on the rendering.
  9908. case 'OP':
  9909. case 'op':
  9910. case 'OPM':
  9911. case 'BG':
  9912. case 'BG2':
  9913. case 'UCR':
  9914. case 'UCR2':
  9915. case 'TR':
  9916. case 'TR2':
  9917. case 'HT':
  9918. case 'SM':
  9919. case 'SA':
  9920. case 'AIS':
  9921. case 'TK':
  9922. // TODO implement these operators.
  9923. info('graphic state operator ' + key);
  9924. break;
  9925. default:
  9926. info('Unknown graphic state operator ' + key);
  9927. break;
  9928. }
  9929. }
  9930. return promise.then(function () {
  9931. if (gStateObj.length >= 0) {
  9932. operatorList.addOp(OPS.setGState, [gStateObj]);
  9933. }
  9934. });
  9935. },
  9936. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9937. resources) {
  9938. function errorFont() {
  9939. return Promise.resolve(new TranslatedFont('g_font_error',
  9940. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9941. }
  9942. var fontRef;
  9943. if (font) { // Loading by ref.
  9944. assert(isRef(font));
  9945. fontRef = font;
  9946. } else { // Loading by name.
  9947. var fontRes = resources.get('Font');
  9948. if (fontRes) {
  9949. fontRef = fontRes.getRaw(fontName);
  9950. } else {
  9951. warn('fontRes not available');
  9952. return errorFont();
  9953. }
  9954. }
  9955. if (!fontRef) {
  9956. warn('fontRef not available');
  9957. return errorFont();
  9958. }
  9959. if (this.fontCache.has(fontRef)) {
  9960. return this.fontCache.get(fontRef);
  9961. }
  9962. font = xref.fetchIfRef(fontRef);
  9963. if (!isDict(font)) {
  9964. return errorFont();
  9965. }
  9966. // We are holding font.translated references just for fontRef that are not
  9967. // dictionaries (Dict). See explanation below.
  9968. if (font.translated) {
  9969. return font.translated;
  9970. }
  9971. var fontCapability = createPromiseCapability();
  9972. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9973. var descriptor = preEvaluatedFont.descriptor;
  9974. var fontID = fontRef.num + '_' + fontRef.gen;
  9975. if (isDict(descriptor)) {
  9976. if (!descriptor.fontAliases) {
  9977. descriptor.fontAliases = Object.create(null);
  9978. }
  9979. var fontAliases = descriptor.fontAliases;
  9980. var hash = preEvaluatedFont.hash;
  9981. if (fontAliases[hash]) {
  9982. var aliasFontRef = fontAliases[hash].aliasRef;
  9983. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9984. this.fontCache.putAlias(fontRef, aliasFontRef);
  9985. return this.fontCache.get(fontRef);
  9986. }
  9987. }
  9988. if (!fontAliases[hash]) {
  9989. fontAliases[hash] = {
  9990. fontID: Font.getFontID()
  9991. };
  9992. }
  9993. fontAliases[hash].aliasRef = fontRef;
  9994. fontID = fontAliases[hash].fontID;
  9995. }
  9996. // Workaround for bad PDF generators that don't reference fonts
  9997. // properly, i.e. by not using an object identifier.
  9998. // Check if the fontRef is a Dict (as opposed to a standard object),
  9999. // in which case we don't cache the font and instead reference it by
  10000. // fontName in font.loadedName below.
  10001. var fontRefIsDict = isDict(fontRef);
  10002. if (!fontRefIsDict) {
  10003. this.fontCache.put(fontRef, fontCapability.promise);
  10004. }
  10005. // Keep track of each font we translated so the caller can
  10006. // load them asynchronously before calling display on a page.
  10007. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10008. fontName.replace(/\W/g, '') : fontID);
  10009. font.translated = fontCapability.promise;
  10010. // TODO move promises into translate font
  10011. var translatedPromise;
  10012. try {
  10013. translatedPromise = Promise.resolve(
  10014. this.translateFont(preEvaluatedFont, xref));
  10015. } catch (e) {
  10016. translatedPromise = Promise.reject(e);
  10017. }
  10018. translatedPromise.then(function (translatedFont) {
  10019. if (translatedFont.fontType !== undefined) {
  10020. var xrefFontStats = xref.stats.fontTypes;
  10021. xrefFontStats[translatedFont.fontType] = true;
  10022. }
  10023. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10024. translatedFont, font));
  10025. }, function (reason) {
  10026. // TODO fontCapability.reject?
  10027. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10028. try {
  10029. // error, but it's still nice to have font type reported
  10030. var descriptor = preEvaluatedFont.descriptor;
  10031. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10032. var subtype = fontFile3 && fontFile3.get('Subtype');
  10033. var fontType = getFontType(preEvaluatedFont.type,
  10034. subtype && subtype.name);
  10035. var xrefFontStats = xref.stats.fontTypes;
  10036. xrefFontStats[fontType] = true;
  10037. } catch (ex) { }
  10038. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10039. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10040. font));
  10041. });
  10042. return fontCapability.promise;
  10043. },
  10044. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10045. var lastIndex = operatorList.length - 1;
  10046. if (!args) {
  10047. args = [];
  10048. }
  10049. if (lastIndex < 0 ||
  10050. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10051. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10052. } else {
  10053. var opArgs = operatorList.argsArray[lastIndex];
  10054. opArgs[0].push(fn);
  10055. Array.prototype.push.apply(opArgs[1], args);
  10056. }
  10057. },
  10058. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10059. cs, patterns, resources, xref) {
  10060. // compile tiling patterns
  10061. var patternName = args[args.length - 1];
  10062. // SCN/scn applies patterns along with normal colors
  10063. var pattern;
  10064. if (isName(patternName) &&
  10065. (pattern = patterns.get(patternName.name))) {
  10066. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10067. var typeNum = dict.get('PatternType');
  10068. if (typeNum === TILING_PATTERN) {
  10069. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10070. return this.handleTilingType(fn, color, resources, pattern,
  10071. dict, operatorList);
  10072. } else if (typeNum === SHADING_PATTERN) {
  10073. var shading = dict.get('Shading');
  10074. var matrix = dict.get('Matrix');
  10075. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10076. operatorList.addOp(fn, pattern.getIR());
  10077. return Promise.resolve();
  10078. } else {
  10079. return Promise.reject('Unknown PatternType: ' + typeNum);
  10080. }
  10081. }
  10082. // TODO shall we fail here?
  10083. operatorList.addOp(fn, args);
  10084. return Promise.resolve();
  10085. },
  10086. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10087. resources,
  10088. operatorList,
  10089. initialState) {
  10090. var self = this;
  10091. var xref = this.xref;
  10092. var imageCache = {};
  10093. assert(operatorList);
  10094. resources = (resources || Dict.empty);
  10095. var xobjs = (resources.get('XObject') || Dict.empty);
  10096. var patterns = (resources.get('Pattern') || Dict.empty);
  10097. var stateManager = new StateManager(initialState || new EvalState());
  10098. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10099. var timeSlotManager = new TimeSlotManager();
  10100. return new Promise(function next(resolve, reject) {
  10101. timeSlotManager.reset();
  10102. var stop, operation = {}, i, ii, cs;
  10103. while (!(stop = timeSlotManager.check())) {
  10104. // The arguments parsed by read() are used beyond this loop, so we
  10105. // cannot reuse the same array on each iteration. Therefore we pass
  10106. // in |null| as the initial value (see the comment on
  10107. // EvaluatorPreprocessor_read() for why).
  10108. operation.args = null;
  10109. if (!(preprocessor.read(operation))) {
  10110. break;
  10111. }
  10112. var args = operation.args;
  10113. var fn = operation.fn;
  10114. switch (fn | 0) {
  10115. case OPS.paintXObject:
  10116. if (args[0].code) {
  10117. break;
  10118. }
  10119. // eagerly compile XForm objects
  10120. var name = args[0].name;
  10121. if (imageCache[name] !== undefined) {
  10122. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10123. args = null;
  10124. continue;
  10125. }
  10126. var xobj = xobjs.get(name);
  10127. if (xobj) {
  10128. assert(isStream(xobj), 'XObject should be a stream');
  10129. var type = xobj.dict.get('Subtype');
  10130. assert(isName(type),
  10131. 'XObject should have a Name subtype');
  10132. if (type.name === 'Form') {
  10133. stateManager.save();
  10134. return self.buildFormXObject(resources, xobj, null,
  10135. operatorList,
  10136. stateManager.state.clone()).
  10137. then(function () {
  10138. stateManager.restore();
  10139. next(resolve, reject);
  10140. }, reject);
  10141. } else if (type.name === 'Image') {
  10142. self.buildPaintImageXObject(resources, xobj, false,
  10143. operatorList, name, imageCache);
  10144. args = null;
  10145. continue;
  10146. } else if (type.name === 'PS') {
  10147. // PostScript XObjects are unused when viewing documents.
  10148. // See section 4.7.1 of Adobe's PDF reference.
  10149. info('Ignored XObject subtype PS');
  10150. continue;
  10151. } else {
  10152. error('Unhandled XObject subtype ' + type.name);
  10153. }
  10154. }
  10155. break;
  10156. case OPS.setFont:
  10157. var fontSize = args[1];
  10158. // eagerly collect all fonts
  10159. return self.handleSetFont(resources, args, null,
  10160. operatorList, stateManager.state).
  10161. then(function (loadedName) {
  10162. operatorList.addDependency(loadedName);
  10163. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10164. next(resolve, reject);
  10165. }, reject);
  10166. case OPS.endInlineImage:
  10167. var cacheKey = args[0].cacheKey;
  10168. if (cacheKey) {
  10169. var cacheEntry = imageCache[cacheKey];
  10170. if (cacheEntry !== undefined) {
  10171. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10172. args = null;
  10173. continue;
  10174. }
  10175. }
  10176. self.buildPaintImageXObject(resources, args[0], true,
  10177. operatorList, cacheKey, imageCache);
  10178. args = null;
  10179. continue;
  10180. case OPS.showText:
  10181. args[0] = self.handleText(args[0], stateManager.state);
  10182. break;
  10183. case OPS.showSpacedText:
  10184. var arr = args[0];
  10185. var combinedGlyphs = [];
  10186. var arrLength = arr.length;
  10187. for (i = 0; i < arrLength; ++i) {
  10188. var arrItem = arr[i];
  10189. if (isString(arrItem)) {
  10190. Array.prototype.push.apply(combinedGlyphs,
  10191. self.handleText(arrItem, stateManager.state));
  10192. } else if (isNum(arrItem)) {
  10193. combinedGlyphs.push(arrItem);
  10194. }
  10195. }
  10196. args[0] = combinedGlyphs;
  10197. fn = OPS.showText;
  10198. break;
  10199. case OPS.nextLineShowText:
  10200. operatorList.addOp(OPS.nextLine);
  10201. args[0] = self.handleText(args[0], stateManager.state);
  10202. fn = OPS.showText;
  10203. break;
  10204. case OPS.nextLineSetSpacingShowText:
  10205. operatorList.addOp(OPS.nextLine);
  10206. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10207. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10208. args[0] = self.handleText(args[0], stateManager.state);
  10209. fn = OPS.showText;
  10210. break;
  10211. case OPS.setTextRenderingMode:
  10212. stateManager.state.textRenderingMode = args[0];
  10213. break;
  10214. case OPS.setFillColorSpace:
  10215. stateManager.state.fillColorSpace =
  10216. ColorSpace.parse(args[0], xref, resources);
  10217. continue;
  10218. case OPS.setStrokeColorSpace:
  10219. stateManager.state.strokeColorSpace =
  10220. ColorSpace.parse(args[0], xref, resources);
  10221. continue;
  10222. case OPS.setFillColor:
  10223. cs = stateManager.state.fillColorSpace;
  10224. args = cs.getRgb(args, 0);
  10225. fn = OPS.setFillRGBColor;
  10226. break;
  10227. case OPS.setStrokeColor:
  10228. cs = stateManager.state.strokeColorSpace;
  10229. args = cs.getRgb(args, 0);
  10230. fn = OPS.setStrokeRGBColor;
  10231. break;
  10232. case OPS.setFillGray:
  10233. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10234. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10235. fn = OPS.setFillRGBColor;
  10236. break;
  10237. case OPS.setStrokeGray:
  10238. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10239. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10240. fn = OPS.setStrokeRGBColor;
  10241. break;
  10242. case OPS.setFillCMYKColor:
  10243. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10244. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10245. fn = OPS.setFillRGBColor;
  10246. break;
  10247. case OPS.setStrokeCMYKColor:
  10248. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10249. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10250. fn = OPS.setStrokeRGBColor;
  10251. break;
  10252. case OPS.setFillRGBColor:
  10253. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10254. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10255. break;
  10256. case OPS.setStrokeRGBColor:
  10257. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10258. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10259. break;
  10260. case OPS.setFillColorN:
  10261. cs = stateManager.state.fillColorSpace;
  10262. if (cs.name === 'Pattern') {
  10263. return self.handleColorN(operatorList, OPS.setFillColorN,
  10264. args, cs, patterns, resources, xref).then(function() {
  10265. next(resolve, reject);
  10266. }, reject);
  10267. }
  10268. args = cs.getRgb(args, 0);
  10269. fn = OPS.setFillRGBColor;
  10270. break;
  10271. case OPS.setStrokeColorN:
  10272. cs = stateManager.state.strokeColorSpace;
  10273. if (cs.name === 'Pattern') {
  10274. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10275. args, cs, patterns, resources, xref).then(function() {
  10276. next(resolve, reject);
  10277. }, reject);
  10278. }
  10279. args = cs.getRgb(args, 0);
  10280. fn = OPS.setStrokeRGBColor;
  10281. break;
  10282. case OPS.shadingFill:
  10283. var shadingRes = resources.get('Shading');
  10284. if (!shadingRes) {
  10285. error('No shading resource found');
  10286. }
  10287. var shading = shadingRes.get(args[0].name);
  10288. if (!shading) {
  10289. error('No shading object found');
  10290. }
  10291. var shadingFill = Pattern.parseShading(shading, null, xref,
  10292. resources);
  10293. var patternIR = shadingFill.getIR();
  10294. args = [patternIR];
  10295. fn = OPS.shadingFill;
  10296. break;
  10297. case OPS.setGState:
  10298. var dictName = args[0];
  10299. var extGState = resources.get('ExtGState');
  10300. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10301. break;
  10302. }
  10303. var gState = extGState.get(dictName.name);
  10304. return self.setGState(resources, gState, operatorList, xref,
  10305. stateManager).then(function() {
  10306. next(resolve, reject);
  10307. }, reject);
  10308. case OPS.moveTo:
  10309. case OPS.lineTo:
  10310. case OPS.curveTo:
  10311. case OPS.curveTo2:
  10312. case OPS.curveTo3:
  10313. case OPS.closePath:
  10314. self.buildPath(operatorList, fn, args);
  10315. continue;
  10316. case OPS.rectangle:
  10317. self.buildPath(operatorList, fn, args);
  10318. continue;
  10319. }
  10320. operatorList.addOp(fn, args);
  10321. }
  10322. if (stop) {
  10323. deferred.then(function () {
  10324. next(resolve, reject);
  10325. });
  10326. return;
  10327. }
  10328. // Some PDFs don't close all restores inside object/form.
  10329. // Closing those for them.
  10330. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10331. operatorList.addOp(OPS.restore, []);
  10332. }
  10333. resolve();
  10334. });
  10335. },
  10336. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10337. stateManager) {
  10338. stateManager = (stateManager || new StateManager(new TextState()));
  10339. var textContent = {
  10340. items: [],
  10341. styles: Object.create(null)
  10342. };
  10343. var bidiTexts = textContent.items;
  10344. var SPACE_FACTOR = 0.35;
  10345. var MULTI_SPACE_FACTOR = 1.5;
  10346. var self = this;
  10347. var xref = this.xref;
  10348. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10349. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10350. var xobjs = null;
  10351. var xobjsCache = {};
  10352. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10353. var textState;
  10354. function newTextChunk() {
  10355. var font = textState.font;
  10356. if (!(font.loadedName in textContent.styles)) {
  10357. textContent.styles[font.loadedName] = {
  10358. fontFamily: font.fallbackName,
  10359. ascent: font.ascent,
  10360. descent: font.descent,
  10361. vertical: font.vertical
  10362. };
  10363. }
  10364. return {
  10365. // |str| is initially an array which we push individual chars to, and
  10366. // then runBidi() overwrites it with the final string.
  10367. str: [],
  10368. dir: null,
  10369. width: 0,
  10370. height: 0,
  10371. transform: null,
  10372. fontName: font.loadedName
  10373. };
  10374. }
  10375. function runBidi(textChunk) {
  10376. var str = textChunk.str.join('');
  10377. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10378. textChunk.str = bidiResult.str;
  10379. textChunk.dir = bidiResult.dir;
  10380. return textChunk;
  10381. }
  10382. function handleSetFont(fontName, fontRef) {
  10383. return self.loadFont(fontName, fontRef, xref, resources).
  10384. then(function (translated) {
  10385. textState.font = translated.font;
  10386. textState.fontMatrix = translated.font.fontMatrix ||
  10387. FONT_IDENTITY_MATRIX;
  10388. });
  10389. }
  10390. function buildTextGeometry(chars, textChunk) {
  10391. var font = textState.font;
  10392. textChunk = textChunk || newTextChunk();
  10393. if (!textChunk.transform) {
  10394. // 9.4.4 Text Space Details
  10395. var tsm = [textState.fontSize * textState.textHScale, 0,
  10396. 0, textState.fontSize,
  10397. 0, textState.textRise];
  10398. var trm = textChunk.transform = Util.transform(textState.ctm,
  10399. Util.transform(textState.textMatrix, tsm));
  10400. if (!font.vertical) {
  10401. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10402. } else {
  10403. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10404. }
  10405. }
  10406. var width = 0;
  10407. var height = 0;
  10408. var glyphs = font.charsToGlyphs(chars);
  10409. var defaultVMetrics = font.defaultVMetrics;
  10410. for (var i = 0; i < glyphs.length; i++) {
  10411. var glyph = glyphs[i];
  10412. if (!glyph) { // Previous glyph was a space.
  10413. width += textState.wordSpacing * textState.textHScale;
  10414. continue;
  10415. }
  10416. var vMetricX = null;
  10417. var vMetricY = null;
  10418. var glyphWidth = null;
  10419. if (font.vertical) {
  10420. if (glyph.vmetric) {
  10421. glyphWidth = glyph.vmetric[0];
  10422. vMetricX = glyph.vmetric[1];
  10423. vMetricY = glyph.vmetric[2];
  10424. } else {
  10425. glyphWidth = glyph.width;
  10426. vMetricX = glyph.width * 0.5;
  10427. vMetricY = defaultVMetrics[2];
  10428. }
  10429. } else {
  10430. glyphWidth = glyph.width;
  10431. }
  10432. var glyphUnicode = glyph.unicode;
  10433. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10434. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10435. }
  10436. glyphUnicode = reverseIfRtl(glyphUnicode);
  10437. // The following will calculate the x and y of the individual glyphs.
  10438. // if (font.vertical) {
  10439. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10440. // textState.fontMatrix[0];
  10441. // tsm[5] -= vMetricY * textState.fontSize *
  10442. // textState.fontMatrix[0];
  10443. // }
  10444. // var trm = Util.transform(textState.textMatrix, tsm);
  10445. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10446. // var x = pt[0];
  10447. // var y = pt[1];
  10448. var tx = 0;
  10449. var ty = 0;
  10450. if (!font.vertical) {
  10451. var w0 = glyphWidth * textState.fontMatrix[0];
  10452. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10453. textState.textHScale;
  10454. width += tx;
  10455. } else {
  10456. var w1 = glyphWidth * textState.fontMatrix[0];
  10457. ty = w1 * textState.fontSize + textState.charSpacing;
  10458. height += ty;
  10459. }
  10460. textState.translateTextMatrix(tx, ty);
  10461. textChunk.str.push(glyphUnicode);
  10462. }
  10463. var a = textState.textLineMatrix[0];
  10464. var b = textState.textLineMatrix[1];
  10465. var scaleLineX = Math.sqrt(a * a + b * b);
  10466. a = textState.ctm[0];
  10467. b = textState.ctm[1];
  10468. var scaleCtmX = Math.sqrt(a * a + b * b);
  10469. if (!font.vertical) {
  10470. textChunk.width += width * scaleCtmX * scaleLineX;
  10471. } else {
  10472. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10473. }
  10474. return textChunk;
  10475. }
  10476. var timeSlotManager = new TimeSlotManager();
  10477. return new Promise(function next(resolve, reject) {
  10478. timeSlotManager.reset();
  10479. var stop, operation = {}, args = [];
  10480. while (!(stop = timeSlotManager.check())) {
  10481. // The arguments parsed by read() are not used beyond this loop, so
  10482. // we can reuse the same array on every iteration, thus avoiding
  10483. // unnecessary allocations.
  10484. args.length = 0;
  10485. operation.args = args;
  10486. if (!(preprocessor.read(operation))) {
  10487. break;
  10488. }
  10489. textState = stateManager.state;
  10490. var fn = operation.fn;
  10491. args = operation.args;
  10492. switch (fn | 0) {
  10493. case OPS.setFont:
  10494. textState.fontSize = args[1];
  10495. return handleSetFont(args[0].name).then(function() {
  10496. next(resolve, reject);
  10497. }, reject);
  10498. case OPS.setTextRise:
  10499. textState.textRise = args[0];
  10500. break;
  10501. case OPS.setHScale:
  10502. textState.textHScale = args[0] / 100;
  10503. break;
  10504. case OPS.setLeading:
  10505. textState.leading = args[0];
  10506. break;
  10507. case OPS.moveText:
  10508. textState.translateTextLineMatrix(args[0], args[1]);
  10509. textState.textMatrix = textState.textLineMatrix.slice();
  10510. break;
  10511. case OPS.setLeadingMoveText:
  10512. textState.leading = -args[1];
  10513. textState.translateTextLineMatrix(args[0], args[1]);
  10514. textState.textMatrix = textState.textLineMatrix.slice();
  10515. break;
  10516. case OPS.nextLine:
  10517. textState.carriageReturn();
  10518. break;
  10519. case OPS.setTextMatrix:
  10520. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10521. args[4], args[5]);
  10522. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10523. args[4], args[5]);
  10524. break;
  10525. case OPS.setCharSpacing:
  10526. textState.charSpacing = args[0];
  10527. break;
  10528. case OPS.setWordSpacing:
  10529. textState.wordSpacing = args[0];
  10530. break;
  10531. case OPS.beginText:
  10532. textState.textMatrix = IDENTITY_MATRIX.slice();
  10533. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10534. break;
  10535. case OPS.showSpacedText:
  10536. var items = args[0];
  10537. var textChunk = newTextChunk();
  10538. var offset;
  10539. for (var j = 0, jj = items.length; j < jj; j++) {
  10540. if (typeof items[j] === 'string') {
  10541. buildTextGeometry(items[j], textChunk);
  10542. } else {
  10543. var val = items[j] / 1000;
  10544. if (!textState.font.vertical) {
  10545. offset = -val * textState.fontSize * textState.textHScale *
  10546. textState.textMatrix[0];
  10547. textState.translateTextMatrix(offset, 0);
  10548. textChunk.width += offset;
  10549. } else {
  10550. offset = -val * textState.fontSize *
  10551. textState.textMatrix[3];
  10552. textState.translateTextMatrix(0, offset);
  10553. textChunk.height += offset;
  10554. }
  10555. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10556. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10557. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10558. fakeSpaces = Math.round(fakeSpaces);
  10559. while (fakeSpaces--) {
  10560. textChunk.str.push(' ');
  10561. }
  10562. } else if (fakeSpaces > SPACE_FACTOR) {
  10563. textChunk.str.push(' ');
  10564. }
  10565. }
  10566. }
  10567. }
  10568. bidiTexts.push(runBidi(textChunk));
  10569. break;
  10570. case OPS.showText:
  10571. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10572. break;
  10573. case OPS.nextLineShowText:
  10574. textState.carriageReturn();
  10575. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10576. break;
  10577. case OPS.nextLineSetSpacingShowText:
  10578. textState.wordSpacing = args[0];
  10579. textState.charSpacing = args[1];
  10580. textState.carriageReturn();
  10581. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10582. break;
  10583. case OPS.paintXObject:
  10584. if (args[0].code) {
  10585. break;
  10586. }
  10587. if (!xobjs) {
  10588. xobjs = (resources.get('XObject') || Dict.empty);
  10589. }
  10590. var name = args[0].name;
  10591. if (xobjsCache.key === name) {
  10592. if (xobjsCache.texts) {
  10593. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10594. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10595. }
  10596. break;
  10597. }
  10598. var xobj = xobjs.get(name);
  10599. if (!xobj) {
  10600. break;
  10601. }
  10602. assert(isStream(xobj), 'XObject should be a stream');
  10603. var type = xobj.dict.get('Subtype');
  10604. assert(isName(type),
  10605. 'XObject should have a Name subtype');
  10606. if ('Form' !== type.name) {
  10607. xobjsCache.key = name;
  10608. xobjsCache.texts = null;
  10609. break;
  10610. }
  10611. stateManager.save();
  10612. var matrix = xobj.dict.get('Matrix');
  10613. if (isArray(matrix) && matrix.length === 6) {
  10614. stateManager.transform(matrix);
  10615. }
  10616. return self.getTextContent(xobj,
  10617. xobj.dict.get('Resources') || resources, stateManager).
  10618. then(function (formTextContent) {
  10619. Util.appendToArray(bidiTexts, formTextContent.items);
  10620. Util.extendObj(textContent.styles, formTextContent.styles);
  10621. stateManager.restore();
  10622. xobjsCache.key = name;
  10623. xobjsCache.texts = formTextContent;
  10624. next(resolve, reject);
  10625. }, reject);
  10626. case OPS.setGState:
  10627. var dictName = args[0];
  10628. var extGState = resources.get('ExtGState');
  10629. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10630. break;
  10631. }
  10632. var gsStateMap = extGState.get(dictName.name);
  10633. var gsStateFont = null;
  10634. for (var key in gsStateMap) {
  10635. if (key === 'Font') {
  10636. assert(!gsStateFont);
  10637. gsStateFont = gsStateMap[key];
  10638. }
  10639. }
  10640. if (gsStateFont) {
  10641. textState.fontSize = gsStateFont[1];
  10642. return handleSetFont(gsStateFont[0]).then(function() {
  10643. next(resolve, reject);
  10644. }, reject);
  10645. }
  10646. break;
  10647. } // switch
  10648. } // while
  10649. if (stop) {
  10650. deferred.then(function () {
  10651. next(resolve, reject);
  10652. });
  10653. return;
  10654. }
  10655. resolve(textContent);
  10656. });
  10657. },
  10658. extractDataStructures: function
  10659. partialEvaluatorExtractDataStructures(dict, baseDict,
  10660. xref, properties) {
  10661. // 9.10.2
  10662. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10663. if (toUnicode) {
  10664. properties.toUnicode = this.readToUnicode(toUnicode);
  10665. }
  10666. if (properties.composite) {
  10667. // CIDSystemInfo helps to match CID to glyphs
  10668. var cidSystemInfo = dict.get('CIDSystemInfo');
  10669. if (isDict(cidSystemInfo)) {
  10670. properties.cidSystemInfo = {
  10671. registry: cidSystemInfo.get('Registry'),
  10672. ordering: cidSystemInfo.get('Ordering'),
  10673. supplement: cidSystemInfo.get('Supplement')
  10674. };
  10675. }
  10676. var cidToGidMap = dict.get('CIDToGIDMap');
  10677. if (isStream(cidToGidMap)) {
  10678. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10679. }
  10680. }
  10681. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10682. // and depends on the font type. The base encoding and differences are
  10683. // read here, but the encoding that is actually used is chosen during
  10684. // glyph mapping in the font.
  10685. // TODO: Loading the built in encoding in the font would allow the
  10686. // differences to be merged in here not require us to hold on to it.
  10687. var differences = [];
  10688. var baseEncodingName = null;
  10689. var encoding;
  10690. if (dict.has('Encoding')) {
  10691. encoding = dict.get('Encoding');
  10692. if (isDict(encoding)) {
  10693. baseEncodingName = encoding.get('BaseEncoding');
  10694. baseEncodingName = (isName(baseEncodingName) ?
  10695. baseEncodingName.name : null);
  10696. // Load the differences between the base and original
  10697. if (encoding.has('Differences')) {
  10698. var diffEncoding = encoding.get('Differences');
  10699. var index = 0;
  10700. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10701. var data = diffEncoding[j];
  10702. if (isNum(data)) {
  10703. index = data;
  10704. } else {
  10705. differences[index++] = data.name;
  10706. }
  10707. }
  10708. }
  10709. } else if (isName(encoding)) {
  10710. baseEncodingName = encoding.name;
  10711. } else {
  10712. error('Encoding is not a Name nor a Dict');
  10713. }
  10714. // According to table 114 if the encoding is a named encoding it must be
  10715. // one of these predefined encodings.
  10716. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10717. baseEncodingName !== 'MacExpertEncoding' &&
  10718. baseEncodingName !== 'WinAnsiEncoding')) {
  10719. baseEncodingName = null;
  10720. }
  10721. }
  10722. if (baseEncodingName) {
  10723. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10724. } else {
  10725. encoding = (properties.type === 'TrueType' ?
  10726. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10727. // The Symbolic attribute can be misused for regular fonts
  10728. // Heuristic: we have to check if the font is a standard one also
  10729. if (!!(properties.flags & FontFlags.Symbolic)) {
  10730. encoding = Encodings.MacRomanEncoding;
  10731. if (!properties.file) {
  10732. if (/Symbol/i.test(properties.name)) {
  10733. encoding = Encodings.SymbolSetEncoding;
  10734. } else if (/Dingbats/i.test(properties.name)) {
  10735. encoding = Encodings.ZapfDingbatsEncoding;
  10736. }
  10737. }
  10738. }
  10739. properties.defaultEncoding = encoding;
  10740. }
  10741. properties.differences = differences;
  10742. properties.baseEncodingName = baseEncodingName;
  10743. properties.dict = dict;
  10744. },
  10745. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10746. var cmap, cmapObj = toUnicode;
  10747. if (isName(cmapObj)) {
  10748. cmap = CMapFactory.create(cmapObj,
  10749. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10750. return new ToUnicodeMap(cmap);
  10751. } else if (isStream(cmapObj)) {
  10752. cmap = CMapFactory.create(cmapObj,
  10753. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10754. // Convert UTF-16BE
  10755. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10756. // to iterate over all keys.
  10757. cmap.forEach(function(token, i) {
  10758. var str = [];
  10759. for (var k = 0; k < token.length; k += 2) {
  10760. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10761. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10762. str.push(w1);
  10763. continue;
  10764. }
  10765. k += 2;
  10766. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10767. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10768. }
  10769. cmap[i] = String.fromCharCode.apply(String, str);
  10770. });
  10771. return new ToUnicodeMap(cmap);
  10772. }
  10773. return null;
  10774. },
  10775. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10776. // Extract the encoding from the CIDToGIDMap
  10777. var glyphsData = cidToGidStream.getBytes();
  10778. // Set encoding 0 to later verify the font has an encoding
  10779. var result = [];
  10780. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10781. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10782. if (glyphID === 0) {
  10783. continue;
  10784. }
  10785. var code = j >> 1;
  10786. result[code] = glyphID;
  10787. }
  10788. return result;
  10789. },
  10790. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10791. descriptor,
  10792. properties) {
  10793. var glyphsWidths = [];
  10794. var defaultWidth = 0;
  10795. var glyphsVMetrics = [];
  10796. var defaultVMetrics;
  10797. var i, ii, j, jj, start, code, widths;
  10798. if (properties.composite) {
  10799. defaultWidth = dict.get('DW') || 1000;
  10800. widths = dict.get('W');
  10801. if (widths) {
  10802. for (i = 0, ii = widths.length; i < ii; i++) {
  10803. start = widths[i++];
  10804. code = xref.fetchIfRef(widths[i]);
  10805. if (isArray(code)) {
  10806. for (j = 0, jj = code.length; j < jj; j++) {
  10807. glyphsWidths[start++] = code[j];
  10808. }
  10809. } else {
  10810. var width = widths[++i];
  10811. for (j = start; j <= code; j++) {
  10812. glyphsWidths[j] = width;
  10813. }
  10814. }
  10815. }
  10816. }
  10817. if (properties.vertical) {
  10818. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10819. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10820. vmetrics = dict.get('W2');
  10821. if (vmetrics) {
  10822. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10823. start = vmetrics[i++];
  10824. code = xref.fetchIfRef(vmetrics[i]);
  10825. if (isArray(code)) {
  10826. for (j = 0, jj = code.length; j < jj; j++) {
  10827. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10828. }
  10829. } else {
  10830. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10831. for (j = start; j <= code; j++) {
  10832. glyphsVMetrics[j] = vmetric;
  10833. }
  10834. }
  10835. }
  10836. }
  10837. }
  10838. } else {
  10839. var firstChar = properties.firstChar;
  10840. widths = dict.get('Widths');
  10841. if (widths) {
  10842. j = firstChar;
  10843. for (i = 0, ii = widths.length; i < ii; i++) {
  10844. glyphsWidths[j++] = widths[i];
  10845. }
  10846. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10847. } else {
  10848. // Trying get the BaseFont metrics (see comment above).
  10849. var baseFontName = dict.get('BaseFont');
  10850. if (isName(baseFontName)) {
  10851. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10852. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10853. properties);
  10854. defaultWidth = metrics.defaultWidth;
  10855. }
  10856. }
  10857. }
  10858. // Heuristic: detection of monospace font by checking all non-zero widths
  10859. var isMonospace = true;
  10860. var firstWidth = defaultWidth;
  10861. for (var glyph in glyphsWidths) {
  10862. var glyphWidth = glyphsWidths[glyph];
  10863. if (!glyphWidth) {
  10864. continue;
  10865. }
  10866. if (!firstWidth) {
  10867. firstWidth = glyphWidth;
  10868. continue;
  10869. }
  10870. if (firstWidth !== glyphWidth) {
  10871. isMonospace = false;
  10872. break;
  10873. }
  10874. }
  10875. if (isMonospace) {
  10876. properties.flags |= FontFlags.FixedPitch;
  10877. }
  10878. properties.defaultWidth = defaultWidth;
  10879. properties.widths = glyphsWidths;
  10880. properties.defaultVMetrics = defaultVMetrics;
  10881. properties.vmetrics = glyphsVMetrics;
  10882. },
  10883. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10884. // Simulating descriptor flags attribute
  10885. var fontNameWoStyle = baseFontName.split('-')[0];
  10886. return (fontNameWoStyle in serifFonts) ||
  10887. (fontNameWoStyle.search(/serif/gi) !== -1);
  10888. },
  10889. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10890. var defaultWidth = 0;
  10891. var widths = [];
  10892. var monospace = false;
  10893. var lookupName = (stdFontMap[name] || name);
  10894. if (!(lookupName in Metrics)) {
  10895. // Use default fonts for looking up font metrics if the passed
  10896. // font is not a base font
  10897. if (this.isSerifFont(name)) {
  10898. lookupName = 'Times-Roman';
  10899. } else {
  10900. lookupName = 'Helvetica';
  10901. }
  10902. }
  10903. var glyphWidths = Metrics[lookupName];
  10904. if (isNum(glyphWidths)) {
  10905. defaultWidth = glyphWidths;
  10906. monospace = true;
  10907. } else {
  10908. widths = glyphWidths;
  10909. }
  10910. return {
  10911. defaultWidth: defaultWidth,
  10912. monospace: monospace,
  10913. widths: widths
  10914. };
  10915. },
  10916. buildCharCodeToWidth:
  10917. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10918. properties) {
  10919. var widths = Object.create(null);
  10920. var differences = properties.differences;
  10921. var encoding = properties.defaultEncoding;
  10922. for (var charCode = 0; charCode < 256; charCode++) {
  10923. if (charCode in differences &&
  10924. widthsByGlyphName[differences[charCode]]) {
  10925. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10926. continue;
  10927. }
  10928. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10929. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10930. continue;
  10931. }
  10932. }
  10933. return widths;
  10934. },
  10935. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10936. var baseDict = dict;
  10937. var type = dict.get('Subtype');
  10938. assert(isName(type), 'invalid font Subtype');
  10939. var composite = false;
  10940. var uint8array;
  10941. if (type.name === 'Type0') {
  10942. // If font is a composite
  10943. // - get the descendant font
  10944. // - set the type according to the descendant font
  10945. // - get the FontDescriptor from the descendant font
  10946. var df = dict.get('DescendantFonts');
  10947. if (!df) {
  10948. error('Descendant fonts are not specified');
  10949. }
  10950. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10951. type = dict.get('Subtype');
  10952. assert(isName(type), 'invalid font Subtype');
  10953. composite = true;
  10954. }
  10955. var descriptor = dict.get('FontDescriptor');
  10956. if (descriptor) {
  10957. var hash = new MurmurHash3_64();
  10958. var encoding = baseDict.getRaw('Encoding');
  10959. if (isName(encoding)) {
  10960. hash.update(encoding.name);
  10961. } else if (isRef(encoding)) {
  10962. hash.update(encoding.num + '_' + encoding.gen);
  10963. }
  10964. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10965. if (isStream(toUnicode)) {
  10966. var stream = toUnicode.str || toUnicode;
  10967. uint8array = stream.buffer ?
  10968. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10969. new Uint8Array(stream.bytes.buffer,
  10970. stream.start, stream.end - stream.start);
  10971. hash.update(uint8array);
  10972. } else if (isName(toUnicode)) {
  10973. hash.update(toUnicode.name);
  10974. }
  10975. var widths = dict.get('Widths') || baseDict.get('Widths');
  10976. if (widths) {
  10977. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10978. hash.update(uint8array);
  10979. }
  10980. }
  10981. return {
  10982. descriptor: descriptor,
  10983. dict: dict,
  10984. baseDict: baseDict,
  10985. composite: composite,
  10986. type: type.name,
  10987. hash: hash ? hash.hexdigest() : ''
  10988. };
  10989. },
  10990. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10991. xref) {
  10992. var baseDict = preEvaluatedFont.baseDict;
  10993. var dict = preEvaluatedFont.dict;
  10994. var composite = preEvaluatedFont.composite;
  10995. var descriptor = preEvaluatedFont.descriptor;
  10996. var type = preEvaluatedFont.type;
  10997. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10998. var properties;
  10999. if (!descriptor) {
  11000. if (type === 'Type3') {
  11001. // FontDescriptor is only required for Type3 fonts when the document
  11002. // is a tagged pdf. Create a barbebones one to get by.
  11003. descriptor = new Dict(null);
  11004. descriptor.set('FontName', Name.get(type));
  11005. } else {
  11006. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11007. // FontDescriptor was not required.
  11008. // This case is here for compatibility.
  11009. var baseFontName = dict.get('BaseFont');
  11010. if (!isName(baseFontName)) {
  11011. error('Base font is not specified');
  11012. }
  11013. // Using base font name as a font name.
  11014. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11015. var metrics = this.getBaseFontMetrics(baseFontName);
  11016. // Simulating descriptor flags attribute
  11017. var fontNameWoStyle = baseFontName.split('-')[0];
  11018. var flags =
  11019. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11020. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11021. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11022. FontFlags.Nonsymbolic);
  11023. properties = {
  11024. type: type,
  11025. name: baseFontName,
  11026. widths: metrics.widths,
  11027. defaultWidth: metrics.defaultWidth,
  11028. flags: flags,
  11029. firstChar: 0,
  11030. lastChar: maxCharIndex
  11031. };
  11032. this.extractDataStructures(dict, dict, xref, properties);
  11033. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11034. properties);
  11035. return new Font(baseFontName, null, properties);
  11036. }
  11037. }
  11038. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11039. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11040. // to ignore this rule when a variant of a standart font is used.
  11041. // TODO Fill the width array depending on which of the base font this is
  11042. // a variant.
  11043. var firstChar = (dict.get('FirstChar') || 0);
  11044. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11045. var fontName = descriptor.get('FontName');
  11046. var baseFont = dict.get('BaseFont');
  11047. // Some bad PDFs have a string as the font name.
  11048. if (isString(fontName)) {
  11049. fontName = Name.get(fontName);
  11050. }
  11051. if (isString(baseFont)) {
  11052. baseFont = Name.get(baseFont);
  11053. }
  11054. if (type !== 'Type3') {
  11055. var fontNameStr = fontName && fontName.name;
  11056. var baseFontStr = baseFont && baseFont.name;
  11057. if (fontNameStr !== baseFontStr) {
  11058. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11059. '" but should be the same as the Font\'s BaseFont "' +
  11060. baseFontStr + '"');
  11061. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11062. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11063. if (fontNameStr && baseFontStr &&
  11064. baseFontStr.indexOf(fontNameStr) === 0) {
  11065. fontName = baseFont;
  11066. }
  11067. }
  11068. }
  11069. fontName = (fontName || baseFont);
  11070. assert(isName(fontName), 'invalid font name');
  11071. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11072. if (fontFile) {
  11073. if (fontFile.dict) {
  11074. var subtype = fontFile.dict.get('Subtype');
  11075. if (subtype) {
  11076. subtype = subtype.name;
  11077. }
  11078. var length1 = fontFile.dict.get('Length1');
  11079. var length2 = fontFile.dict.get('Length2');
  11080. }
  11081. }
  11082. properties = {
  11083. type: type,
  11084. name: fontName.name,
  11085. subtype: subtype,
  11086. file: fontFile,
  11087. length1: length1,
  11088. length2: length2,
  11089. loadedName: baseDict.loadedName,
  11090. composite: composite,
  11091. wideChars: composite,
  11092. fixedPitch: false,
  11093. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11094. firstChar: firstChar || 0,
  11095. lastChar: (lastChar || maxCharIndex),
  11096. bbox: descriptor.get('FontBBox'),
  11097. ascent: descriptor.get('Ascent'),
  11098. descent: descriptor.get('Descent'),
  11099. xHeight: descriptor.get('XHeight'),
  11100. capHeight: descriptor.get('CapHeight'),
  11101. flags: descriptor.get('Flags'),
  11102. italicAngle: descriptor.get('ItalicAngle'),
  11103. coded: false
  11104. };
  11105. if (composite) {
  11106. var cidEncoding = baseDict.get('Encoding');
  11107. if (isName(cidEncoding)) {
  11108. properties.cidEncoding = cidEncoding.name;
  11109. }
  11110. properties.cMap = CMapFactory.create(cidEncoding,
  11111. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11112. properties.vertical = properties.cMap.vertical;
  11113. }
  11114. this.extractDataStructures(dict, baseDict, xref, properties);
  11115. this.extractWidths(dict, xref, descriptor, properties);
  11116. if (type === 'Type3') {
  11117. properties.isType3Font = true;
  11118. }
  11119. return new Font(fontName.name, fontFile, properties);
  11120. }
  11121. };
  11122. return PartialEvaluator;
  11123. })();
  11124. var TranslatedFont = (function TranslatedFontClosure() {
  11125. function TranslatedFont(loadedName, font, dict) {
  11126. this.loadedName = loadedName;
  11127. this.font = font;
  11128. this.dict = dict;
  11129. this.type3Loaded = null;
  11130. this.sent = false;
  11131. }
  11132. TranslatedFont.prototype = {
  11133. send: function (handler) {
  11134. if (this.sent) {
  11135. return;
  11136. }
  11137. var fontData = this.font.exportData();
  11138. handler.send('commonobj', [
  11139. this.loadedName,
  11140. 'Font',
  11141. fontData
  11142. ]);
  11143. this.sent = true;
  11144. },
  11145. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11146. assert(this.font.isType3Font);
  11147. if (this.type3Loaded) {
  11148. return this.type3Loaded;
  11149. }
  11150. var translatedFont = this.font;
  11151. var loadCharProcsPromise = Promise.resolve();
  11152. var charProcs = this.dict.get('CharProcs').getAll();
  11153. var fontResources = this.dict.get('Resources') || resources;
  11154. var charProcKeys = Object.keys(charProcs);
  11155. var charProcOperatorList = {};
  11156. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11157. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11158. var glyphStream = charProcs[key];
  11159. var operatorList = new OperatorList();
  11160. return evaluator.getOperatorList(glyphStream, fontResources,
  11161. operatorList).then(function () {
  11162. charProcOperatorList[key] = operatorList.getIR();
  11163. // Add the dependencies to the parent operator list so they are
  11164. // resolved before sub operator list is executed synchronously.
  11165. parentOperatorList.addDependencies(operatorList.dependencies);
  11166. }, function (reason) {
  11167. warn('Type3 font resource \"' + key + '\" is not available');
  11168. var operatorList = new OperatorList();
  11169. charProcOperatorList[key] = operatorList.getIR();
  11170. });
  11171. }.bind(this, charProcKeys[i]));
  11172. }
  11173. this.type3Loaded = loadCharProcsPromise.then(function () {
  11174. translatedFont.charProcOperatorList = charProcOperatorList;
  11175. });
  11176. return this.type3Loaded;
  11177. }
  11178. };
  11179. return TranslatedFont;
  11180. })();
  11181. var OperatorList = (function OperatorListClosure() {
  11182. var CHUNK_SIZE = 1000;
  11183. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11184. function getTransfers(queue) {
  11185. var transfers = [];
  11186. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11187. for (var i = 0, ii = queue.length; i < ii; i++) {
  11188. switch (fnArray[i]) {
  11189. case OPS.paintInlineImageXObject:
  11190. case OPS.paintInlineImageXObjectGroup:
  11191. case OPS.paintImageMaskXObject:
  11192. var arg = argsArray[i][0]; // first param in imgData
  11193. if (!arg.cached) {
  11194. transfers.push(arg.data.buffer);
  11195. }
  11196. break;
  11197. }
  11198. }
  11199. return transfers;
  11200. }
  11201. function OperatorList(intent, messageHandler, pageIndex) {
  11202. this.messageHandler = messageHandler;
  11203. this.fnArray = [];
  11204. this.argsArray = [];
  11205. this.dependencies = {};
  11206. this.pageIndex = pageIndex;
  11207. this.intent = intent;
  11208. }
  11209. OperatorList.prototype = {
  11210. get length() {
  11211. return this.argsArray.length;
  11212. },
  11213. addOp: function(fn, args) {
  11214. this.fnArray.push(fn);
  11215. this.argsArray.push(args);
  11216. if (this.messageHandler) {
  11217. if (this.fnArray.length >= CHUNK_SIZE) {
  11218. this.flush();
  11219. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11220. (fn === OPS.restore || fn === OPS.endText)) {
  11221. // heuristic to flush on boundary of restore or endText
  11222. this.flush();
  11223. }
  11224. }
  11225. },
  11226. addDependency: function(dependency) {
  11227. if (dependency in this.dependencies) {
  11228. return;
  11229. }
  11230. this.dependencies[dependency] = true;
  11231. this.addOp(OPS.dependency, [dependency]);
  11232. },
  11233. addDependencies: function(dependencies) {
  11234. for (var key in dependencies) {
  11235. this.addDependency(key);
  11236. }
  11237. },
  11238. addOpList: function(opList) {
  11239. Util.extendObj(this.dependencies, opList.dependencies);
  11240. for (var i = 0, ii = opList.length; i < ii; i++) {
  11241. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11242. }
  11243. },
  11244. getIR: function() {
  11245. return {
  11246. fnArray: this.fnArray,
  11247. argsArray: this.argsArray,
  11248. length: this.length
  11249. };
  11250. },
  11251. flush: function(lastChunk) {
  11252. if (this.intent !== 'oplist') {
  11253. new QueueOptimizer().optimize(this);
  11254. }
  11255. var transfers = getTransfers(this);
  11256. this.messageHandler.send('RenderPageChunk', {
  11257. operatorList: {
  11258. fnArray: this.fnArray,
  11259. argsArray: this.argsArray,
  11260. lastChunk: lastChunk,
  11261. length: this.length
  11262. },
  11263. pageIndex: this.pageIndex,
  11264. intent: this.intent
  11265. }, transfers);
  11266. this.dependencies = {};
  11267. this.fnArray.length = 0;
  11268. this.argsArray.length = 0;
  11269. }
  11270. };
  11271. return OperatorList;
  11272. })();
  11273. var StateManager = (function StateManagerClosure() {
  11274. function StateManager(initialState) {
  11275. this.state = initialState;
  11276. this.stateStack = [];
  11277. }
  11278. StateManager.prototype = {
  11279. save: function () {
  11280. var old = this.state;
  11281. this.stateStack.push(this.state);
  11282. this.state = old.clone();
  11283. },
  11284. restore: function () {
  11285. var prev = this.stateStack.pop();
  11286. if (prev) {
  11287. this.state = prev;
  11288. }
  11289. },
  11290. transform: function (args) {
  11291. this.state.ctm = Util.transform(this.state.ctm, args);
  11292. }
  11293. };
  11294. return StateManager;
  11295. })();
  11296. var TextState = (function TextStateClosure() {
  11297. function TextState() {
  11298. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11299. this.fontSize = 0;
  11300. this.font = null;
  11301. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11302. this.textMatrix = IDENTITY_MATRIX.slice();
  11303. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11304. this.charSpacing = 0;
  11305. this.wordSpacing = 0;
  11306. this.leading = 0;
  11307. this.textHScale = 1;
  11308. this.textRise = 0;
  11309. }
  11310. TextState.prototype = {
  11311. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11312. var m = this.textMatrix;
  11313. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11314. },
  11315. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11316. var m = this.textLineMatrix;
  11317. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11318. },
  11319. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11320. var m = this.textMatrix;
  11321. m[4] = m[0] * x + m[2] * y + m[4];
  11322. m[5] = m[1] * x + m[3] * y + m[5];
  11323. },
  11324. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11325. var m = this.textLineMatrix;
  11326. m[4] = m[0] * x + m[2] * y + m[4];
  11327. m[5] = m[1] * x + m[3] * y + m[5];
  11328. },
  11329. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11330. // 9.4.4 Text Space Details
  11331. var tsm = [this.fontSize * this.textHScale, 0,
  11332. 0, this.fontSize,
  11333. 0, this.textRise];
  11334. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11335. },
  11336. carriageReturn: function TextState_carriageReturn() {
  11337. this.translateTextLineMatrix(0, -this.leading);
  11338. this.textMatrix = this.textLineMatrix.slice();
  11339. },
  11340. clone: function TextState_clone() {
  11341. var clone = Object.create(this);
  11342. clone.textMatrix = this.textMatrix.slice();
  11343. clone.textLineMatrix = this.textLineMatrix.slice();
  11344. clone.fontMatrix = this.fontMatrix.slice();
  11345. return clone;
  11346. }
  11347. };
  11348. return TextState;
  11349. })();
  11350. var EvalState = (function EvalStateClosure() {
  11351. function EvalState() {
  11352. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11353. this.font = null;
  11354. this.textRenderingMode = TextRenderingMode.FILL;
  11355. this.fillColorSpace = ColorSpace.singletons.gray;
  11356. this.strokeColorSpace = ColorSpace.singletons.gray;
  11357. }
  11358. EvalState.prototype = {
  11359. clone: function CanvasExtraState_clone() {
  11360. return Object.create(this);
  11361. },
  11362. };
  11363. return EvalState;
  11364. })();
  11365. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11366. // Specifies properties for each command
  11367. //
  11368. // If variableArgs === true: [0, `numArgs`] expected
  11369. // If variableArgs === false: exactly `numArgs` expected
  11370. var OP_MAP = {
  11371. // Graphic state
  11372. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11373. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11374. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11375. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11376. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11377. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11378. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11379. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11380. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11381. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11382. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11383. // Path
  11384. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11385. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11386. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11387. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11388. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11389. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11390. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11391. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11392. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11393. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11394. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11395. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11396. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11397. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11398. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11399. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11400. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11401. // Clipping
  11402. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11403. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11404. // Text
  11405. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11406. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11407. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11408. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11409. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11410. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11411. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11412. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11413. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11414. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11415. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11416. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11417. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11418. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11419. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11420. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11421. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11422. variableArgs: false },
  11423. // Type3 fonts
  11424. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11425. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11426. // Color
  11427. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11428. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11429. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11430. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11431. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11432. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11433. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11434. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11435. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11436. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11437. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11438. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11439. // Shading
  11440. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11441. // Images
  11442. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11443. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11444. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11445. // XObjects
  11446. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11447. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11448. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11449. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11450. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11451. variableArgs: false },
  11452. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11453. // Compatibility
  11454. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11455. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11456. // (reserved partial commands for the lexer)
  11457. BM: null,
  11458. BD: null,
  11459. 'true': null,
  11460. fa: null,
  11461. fal: null,
  11462. fals: null,
  11463. 'false': null,
  11464. nu: null,
  11465. nul: null,
  11466. 'null': null
  11467. };
  11468. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11469. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11470. // dictionary
  11471. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11472. this.stateManager = stateManager;
  11473. this.nonProcessedArgs = [];
  11474. }
  11475. EvaluatorPreprocessor.prototype = {
  11476. get savedStatesDepth() {
  11477. return this.stateManager.stateStack.length;
  11478. },
  11479. // |operation| is an object with two fields:
  11480. //
  11481. // - |fn| is an out param.
  11482. //
  11483. // - |args| is an inout param. On entry, it should have one of two values.
  11484. //
  11485. // - An empty array. This indicates that the caller is providing the
  11486. // array in which the args will be stored in. The caller should use
  11487. // this value if it can reuse a single array for each call to read().
  11488. //
  11489. // - |null|. This indicates that the caller needs this function to create
  11490. // the array in which any args are stored in. If there are zero args,
  11491. // this function will leave |operation.args| as |null| (thus avoiding
  11492. // allocations that would occur if we used an empty array to represent
  11493. // zero arguments). Otherwise, it will replace |null| with a new array
  11494. // containing the arguments. The caller should use this value if it
  11495. // cannot reuse an array for each call to read().
  11496. //
  11497. // These two modes are present because this function is very hot and so
  11498. // avoiding allocations where possible is worthwhile.
  11499. //
  11500. read: function EvaluatorPreprocessor_read(operation) {
  11501. var args = operation.args;
  11502. while (true) {
  11503. var obj = this.parser.getObj();
  11504. if (isCmd(obj)) {
  11505. var cmd = obj.cmd;
  11506. // Check that the command is valid
  11507. var opSpec = OP_MAP[cmd];
  11508. if (!opSpec) {
  11509. warn('Unknown command "' + cmd + '"');
  11510. continue;
  11511. }
  11512. var fn = opSpec.id;
  11513. var numArgs = opSpec.numArgs;
  11514. var argsLength = args !== null ? args.length : 0;
  11515. if (!opSpec.variableArgs) {
  11516. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11517. if (argsLength !== numArgs) {
  11518. var nonProcessedArgs = this.nonProcessedArgs;
  11519. while (argsLength > numArgs) {
  11520. nonProcessedArgs.push(args.shift());
  11521. argsLength--;
  11522. }
  11523. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11524. if (!args) {
  11525. args = [];
  11526. }
  11527. args.unshift(nonProcessedArgs.pop());
  11528. argsLength++;
  11529. }
  11530. }
  11531. if (argsLength < numArgs) {
  11532. // If we receive too few args, it's not possible to possible
  11533. // to execute the command, so skip the command
  11534. info('Command ' + fn + ': because expected ' +
  11535. numArgs + ' args, but received ' + argsLength +
  11536. ' args; skipping');
  11537. args = null;
  11538. continue;
  11539. }
  11540. } else if (argsLength > numArgs) {
  11541. info('Command ' + fn + ': expected [0,' + numArgs +
  11542. '] args, but received ' + argsLength + ' args');
  11543. }
  11544. // TODO figure out how to type-check vararg functions
  11545. this.preprocessCommand(fn, args);
  11546. operation.fn = fn;
  11547. operation.args = args;
  11548. return true;
  11549. } else {
  11550. if (isEOF(obj)) {
  11551. return false; // no more commands
  11552. }
  11553. // argument
  11554. if (obj !== null) {
  11555. if (!args) {
  11556. args = [];
  11557. }
  11558. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11559. assert(args.length <= 33, 'Too many arguments');
  11560. }
  11561. }
  11562. }
  11563. },
  11564. preprocessCommand:
  11565. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11566. switch (fn | 0) {
  11567. case OPS.save:
  11568. this.stateManager.save();
  11569. break;
  11570. case OPS.restore:
  11571. this.stateManager.restore();
  11572. break;
  11573. case OPS.transform:
  11574. this.stateManager.transform(args);
  11575. break;
  11576. }
  11577. }
  11578. };
  11579. return EvaluatorPreprocessor;
  11580. })();
  11581. var QueueOptimizer = (function QueueOptimizerClosure() {
  11582. function addState(parentState, pattern, fn) {
  11583. var state = parentState;
  11584. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11585. var item = pattern[i];
  11586. state = (state[item] || (state[item] = []));
  11587. }
  11588. state[pattern[pattern.length - 1]] = fn;
  11589. }
  11590. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11591. argsArray) {
  11592. // Handles special case of mainly LaTeX documents which use image masks to
  11593. // draw lines with the current fill style.
  11594. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11595. // have been found at iFirstSave.
  11596. var iFirstPIMXO = iFirstSave + 2;
  11597. for (var i = 0; i < count; i++) {
  11598. var arg = argsArray[iFirstPIMXO + 4 * i];
  11599. var imageMask = arg.length === 1 && arg[0];
  11600. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11601. (!imageMask.data.length ||
  11602. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11603. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11604. continue;
  11605. }
  11606. break;
  11607. }
  11608. return count - i;
  11609. }
  11610. var InitialState = [];
  11611. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11612. // sequences with one |paintInlineImageXObjectGroup| operation.
  11613. addState(InitialState,
  11614. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11615. function foundInlineImageGroup(context) {
  11616. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11617. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11618. var MAX_WIDTH = 1000;
  11619. var IMAGE_PADDING = 1;
  11620. var fnArray = context.fnArray, argsArray = context.argsArray;
  11621. var curr = context.iCurr;
  11622. var iFirstSave = curr - 3;
  11623. var iFirstTransform = curr - 2;
  11624. var iFirstPIIXO = curr - 1;
  11625. // Look for the quartets.
  11626. var i = iFirstSave + 4;
  11627. var ii = fnArray.length;
  11628. while (i + 3 < ii) {
  11629. if (fnArray[i] !== OPS.save ||
  11630. fnArray[i + 1] !== OPS.transform ||
  11631. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11632. fnArray[i + 3] !== OPS.restore) {
  11633. break; // ops don't match
  11634. }
  11635. i += 4;
  11636. }
  11637. // At this point, i is the index of the first op past the last valid
  11638. // quartet.
  11639. var count = Math.min((i - iFirstSave) / 4,
  11640. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11641. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11642. return i;
  11643. }
  11644. // assuming that heights of those image is too small (~1 pixel)
  11645. // packing as much as possible by lines
  11646. var maxX = 0;
  11647. var map = [], maxLineHeight = 0;
  11648. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11649. var q;
  11650. for (q = 0; q < count; q++) {
  11651. var transform = argsArray[iFirstTransform + (q << 2)];
  11652. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11653. if (currentX + img.width > MAX_WIDTH) {
  11654. // starting new line
  11655. maxX = Math.max(maxX, currentX);
  11656. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11657. currentX = 0;
  11658. maxLineHeight = 0;
  11659. }
  11660. map.push({
  11661. transform: transform,
  11662. x: currentX, y: currentY,
  11663. w: img.width, h: img.height
  11664. });
  11665. currentX += img.width + 2 * IMAGE_PADDING;
  11666. maxLineHeight = Math.max(maxLineHeight, img.height);
  11667. }
  11668. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11669. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11670. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11671. var imgRowSize = imgWidth << 2;
  11672. for (q = 0; q < count; q++) {
  11673. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11674. // Copy image by lines and extends pixels into padding.
  11675. var rowSize = map[q].w << 2;
  11676. var dataOffset = 0;
  11677. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11678. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11679. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11680. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11681. dataOffset += rowSize;
  11682. offset += imgRowSize;
  11683. }
  11684. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11685. while (offset >= 0) {
  11686. data[offset - 4] = data[offset];
  11687. data[offset - 3] = data[offset + 1];
  11688. data[offset - 2] = data[offset + 2];
  11689. data[offset - 1] = data[offset + 3];
  11690. data[offset + rowSize] = data[offset + rowSize - 4];
  11691. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11692. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11693. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11694. offset -= imgRowSize;
  11695. }
  11696. }
  11697. // Replace queue items.
  11698. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11699. argsArray.splice(iFirstSave, count * 4,
  11700. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11701. data: imgData }, map]);
  11702. return iFirstSave + 1;
  11703. });
  11704. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11705. // sequences with one |paintImageMaskXObjectGroup| or one
  11706. // |paintImageMaskXObjectRepeat| operation.
  11707. addState(InitialState,
  11708. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11709. function foundImageMaskGroup(context) {
  11710. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11711. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11712. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11713. var fnArray = context.fnArray, argsArray = context.argsArray;
  11714. var curr = context.iCurr;
  11715. var iFirstSave = curr - 3;
  11716. var iFirstTransform = curr - 2;
  11717. var iFirstPIMXO = curr - 1;
  11718. // Look for the quartets.
  11719. var i = iFirstSave + 4;
  11720. var ii = fnArray.length;
  11721. while (i + 3 < ii) {
  11722. if (fnArray[i] !== OPS.save ||
  11723. fnArray[i + 1] !== OPS.transform ||
  11724. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11725. fnArray[i + 3] !== OPS.restore) {
  11726. break; // ops don't match
  11727. }
  11728. i += 4;
  11729. }
  11730. // At this point, i is the index of the first op past the last valid
  11731. // quartet.
  11732. var count = (i - iFirstSave) / 4;
  11733. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11734. argsArray);
  11735. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11736. return i;
  11737. }
  11738. var q;
  11739. var isSameImage = false;
  11740. var iTransform, transformArgs;
  11741. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11742. if (argsArray[iFirstTransform][1] === 0 &&
  11743. argsArray[iFirstTransform][2] === 0) {
  11744. isSameImage = true;
  11745. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11746. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11747. iTransform = iFirstTransform + 4;
  11748. var iPIMXO = iFirstPIMXO + 4;
  11749. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11750. transformArgs = argsArray[iTransform];
  11751. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11752. transformArgs[0] !== firstTransformArg0 ||
  11753. transformArgs[1] !== 0 ||
  11754. transformArgs[2] !== 0 ||
  11755. transformArgs[3] !== firstTransformArg3) {
  11756. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11757. isSameImage = false;
  11758. } else {
  11759. count = q;
  11760. }
  11761. break; // different image or transform
  11762. }
  11763. }
  11764. }
  11765. if (isSameImage) {
  11766. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11767. var positions = new Float32Array(count * 2);
  11768. iTransform = iFirstTransform;
  11769. for (q = 0; q < count; q++, iTransform += 4) {
  11770. transformArgs = argsArray[iTransform];
  11771. positions[(q << 1)] = transformArgs[4];
  11772. positions[(q << 1) + 1] = transformArgs[5];
  11773. }
  11774. // Replace queue items.
  11775. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11776. argsArray.splice(iFirstSave, count * 4,
  11777. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11778. } else {
  11779. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11780. var images = [];
  11781. for (q = 0; q < count; q++) {
  11782. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11783. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11784. images.push({ data: maskParams.data, width: maskParams.width,
  11785. height: maskParams.height,
  11786. transform: transformArgs });
  11787. }
  11788. // Replace queue items.
  11789. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11790. argsArray.splice(iFirstSave, count * 4, [images]);
  11791. }
  11792. return iFirstSave + 1;
  11793. });
  11794. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11795. // with one paintImageXObjectRepeat operation, if the |transform| and
  11796. // |paintImageXObjectRepeat| ops are appropriate.
  11797. addState(InitialState,
  11798. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11799. function (context) {
  11800. var MIN_IMAGES_IN_BLOCK = 3;
  11801. var MAX_IMAGES_IN_BLOCK = 1000;
  11802. var fnArray = context.fnArray, argsArray = context.argsArray;
  11803. var curr = context.iCurr;
  11804. var iFirstSave = curr - 3;
  11805. var iFirstTransform = curr - 2;
  11806. var iFirstPIXO = curr - 1;
  11807. var iFirstRestore = curr;
  11808. if (argsArray[iFirstTransform][1] !== 0 ||
  11809. argsArray[iFirstTransform][2] !== 0) {
  11810. return iFirstRestore + 1; // transform has the wrong form
  11811. }
  11812. // Look for the quartets.
  11813. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11814. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11815. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11816. var i = iFirstSave + 4;
  11817. var ii = fnArray.length;
  11818. while (i + 3 < ii) {
  11819. if (fnArray[i] !== OPS.save ||
  11820. fnArray[i + 1] !== OPS.transform ||
  11821. fnArray[i + 2] !== OPS.paintImageXObject ||
  11822. fnArray[i + 3] !== OPS.restore) {
  11823. break; // ops don't match
  11824. }
  11825. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11826. argsArray[i + 1][1] !== 0 ||
  11827. argsArray[i + 1][2] !== 0 ||
  11828. argsArray[i + 1][3] !== firstTransformArg3) {
  11829. break; // transforms don't match
  11830. }
  11831. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11832. break; // images don't match
  11833. }
  11834. i += 4;
  11835. }
  11836. // At this point, i is the index of the first op past the last valid
  11837. // quartet.
  11838. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11839. if (count < MIN_IMAGES_IN_BLOCK) {
  11840. return i;
  11841. }
  11842. // Extract the (x,y) positions from all of the matching transforms.
  11843. var positions = new Float32Array(count * 2);
  11844. var iTransform = iFirstTransform;
  11845. for (var q = 0; q < count; q++, iTransform += 4) {
  11846. var transformArgs = argsArray[iTransform];
  11847. positions[(q << 1)] = transformArgs[4];
  11848. positions[(q << 1) + 1] = transformArgs[5];
  11849. }
  11850. // Replace queue items.
  11851. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11852. positions];
  11853. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11854. argsArray.splice(iFirstSave, count * 4, args);
  11855. return iFirstSave + 1;
  11856. });
  11857. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11858. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11859. // sequences, if the font for each one is the same.
  11860. addState(InitialState,
  11861. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11862. function (context) {
  11863. var MIN_CHARS_IN_BLOCK = 3;
  11864. var MAX_CHARS_IN_BLOCK = 1000;
  11865. var fnArray = context.fnArray, argsArray = context.argsArray;
  11866. var curr = context.iCurr;
  11867. var iFirstBeginText = curr - 4;
  11868. var iFirstSetFont = curr - 3;
  11869. var iFirstSetTextMatrix = curr - 2;
  11870. var iFirstShowText = curr - 1;
  11871. var iFirstEndText = curr;
  11872. // Look for the quintets.
  11873. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11874. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11875. var i = iFirstBeginText + 5;
  11876. var ii = fnArray.length;
  11877. while (i + 4 < ii) {
  11878. if (fnArray[i] !== OPS.beginText ||
  11879. fnArray[i + 1] !== OPS.setFont ||
  11880. fnArray[i + 2] !== OPS.setTextMatrix ||
  11881. fnArray[i + 3] !== OPS.showText ||
  11882. fnArray[i + 4] !== OPS.endText) {
  11883. break; // ops don't match
  11884. }
  11885. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11886. argsArray[i + 1][1] !== firstSetFontArg1) {
  11887. break; // fonts don't match
  11888. }
  11889. i += 5;
  11890. }
  11891. // At this point, i is the index of the first op past the last valid
  11892. // quintet.
  11893. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11894. if (count < MIN_CHARS_IN_BLOCK) {
  11895. return i;
  11896. }
  11897. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11898. // showText, endText), include that as well. (E.g. <something> might be
  11899. // |dependency|.)
  11900. var iFirst = iFirstBeginText;
  11901. if (iFirstBeginText >= 4 &&
  11902. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11903. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11904. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11905. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11906. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11907. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11908. count++;
  11909. iFirst -= 5;
  11910. }
  11911. // Remove (endText, beginText, setFont) trios.
  11912. var iEndText = iFirst + 4;
  11913. for (var q = 1; q < count; q++) {
  11914. fnArray.splice(iEndText, 3);
  11915. argsArray.splice(iEndText, 3);
  11916. iEndText += 2;
  11917. }
  11918. return iEndText + 1;
  11919. });
  11920. function QueueOptimizer() {}
  11921. QueueOptimizer.prototype = {
  11922. optimize: function QueueOptimizer_optimize(queue) {
  11923. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11924. var context = {
  11925. iCurr: 0,
  11926. fnArray: fnArray,
  11927. argsArray: argsArray
  11928. };
  11929. var state;
  11930. var i = 0, ii = fnArray.length;
  11931. while (i < ii) {
  11932. state = (state || InitialState)[fnArray[i]];
  11933. if (typeof state === 'function') { // we found some handler
  11934. context.iCurr = i;
  11935. // state() returns the index of the first non-matching op (if we
  11936. // didn't match) or the first op past the modified ops (if we did
  11937. // match and replace).
  11938. i = state(context);
  11939. state = undefined; // reset the state machine
  11940. ii = context.fnArray.length;
  11941. } else {
  11942. i++;
  11943. }
  11944. }
  11945. }
  11946. };
  11947. return QueueOptimizer;
  11948. })();
  11949. var BUILT_IN_CMAPS = [
  11950. // << Start unicode maps.
  11951. 'Adobe-GB1-UCS2',
  11952. 'Adobe-CNS1-UCS2',
  11953. 'Adobe-Japan1-UCS2',
  11954. 'Adobe-Korea1-UCS2',
  11955. // >> End unicode maps.
  11956. '78-EUC-H',
  11957. '78-EUC-V',
  11958. '78-H',
  11959. '78-RKSJ-H',
  11960. '78-RKSJ-V',
  11961. '78-V',
  11962. '78ms-RKSJ-H',
  11963. '78ms-RKSJ-V',
  11964. '83pv-RKSJ-H',
  11965. '90ms-RKSJ-H',
  11966. '90ms-RKSJ-V',
  11967. '90msp-RKSJ-H',
  11968. '90msp-RKSJ-V',
  11969. '90pv-RKSJ-H',
  11970. '90pv-RKSJ-V',
  11971. 'Add-H',
  11972. 'Add-RKSJ-H',
  11973. 'Add-RKSJ-V',
  11974. 'Add-V',
  11975. 'Adobe-CNS1-0',
  11976. 'Adobe-CNS1-1',
  11977. 'Adobe-CNS1-2',
  11978. 'Adobe-CNS1-3',
  11979. 'Adobe-CNS1-4',
  11980. 'Adobe-CNS1-5',
  11981. 'Adobe-CNS1-6',
  11982. 'Adobe-GB1-0',
  11983. 'Adobe-GB1-1',
  11984. 'Adobe-GB1-2',
  11985. 'Adobe-GB1-3',
  11986. 'Adobe-GB1-4',
  11987. 'Adobe-GB1-5',
  11988. 'Adobe-Japan1-0',
  11989. 'Adobe-Japan1-1',
  11990. 'Adobe-Japan1-2',
  11991. 'Adobe-Japan1-3',
  11992. 'Adobe-Japan1-4',
  11993. 'Adobe-Japan1-5',
  11994. 'Adobe-Japan1-6',
  11995. 'Adobe-Korea1-0',
  11996. 'Adobe-Korea1-1',
  11997. 'Adobe-Korea1-2',
  11998. 'B5-H',
  11999. 'B5-V',
  12000. 'B5pc-H',
  12001. 'B5pc-V',
  12002. 'CNS-EUC-H',
  12003. 'CNS-EUC-V',
  12004. 'CNS1-H',
  12005. 'CNS1-V',
  12006. 'CNS2-H',
  12007. 'CNS2-V',
  12008. 'ETHK-B5-H',
  12009. 'ETHK-B5-V',
  12010. 'ETen-B5-H',
  12011. 'ETen-B5-V',
  12012. 'ETenms-B5-H',
  12013. 'ETenms-B5-V',
  12014. 'EUC-H',
  12015. 'EUC-V',
  12016. 'Ext-H',
  12017. 'Ext-RKSJ-H',
  12018. 'Ext-RKSJ-V',
  12019. 'Ext-V',
  12020. 'GB-EUC-H',
  12021. 'GB-EUC-V',
  12022. 'GB-H',
  12023. 'GB-V',
  12024. 'GBK-EUC-H',
  12025. 'GBK-EUC-V',
  12026. 'GBK2K-H',
  12027. 'GBK2K-V',
  12028. 'GBKp-EUC-H',
  12029. 'GBKp-EUC-V',
  12030. 'GBT-EUC-H',
  12031. 'GBT-EUC-V',
  12032. 'GBT-H',
  12033. 'GBT-V',
  12034. 'GBTpc-EUC-H',
  12035. 'GBTpc-EUC-V',
  12036. 'GBpc-EUC-H',
  12037. 'GBpc-EUC-V',
  12038. 'H',
  12039. 'HKdla-B5-H',
  12040. 'HKdla-B5-V',
  12041. 'HKdlb-B5-H',
  12042. 'HKdlb-B5-V',
  12043. 'HKgccs-B5-H',
  12044. 'HKgccs-B5-V',
  12045. 'HKm314-B5-H',
  12046. 'HKm314-B5-V',
  12047. 'HKm471-B5-H',
  12048. 'HKm471-B5-V',
  12049. 'HKscs-B5-H',
  12050. 'HKscs-B5-V',
  12051. 'Hankaku',
  12052. 'Hiragana',
  12053. 'KSC-EUC-H',
  12054. 'KSC-EUC-V',
  12055. 'KSC-H',
  12056. 'KSC-Johab-H',
  12057. 'KSC-Johab-V',
  12058. 'KSC-V',
  12059. 'KSCms-UHC-H',
  12060. 'KSCms-UHC-HW-H',
  12061. 'KSCms-UHC-HW-V',
  12062. 'KSCms-UHC-V',
  12063. 'KSCpc-EUC-H',
  12064. 'KSCpc-EUC-V',
  12065. 'Katakana',
  12066. 'NWP-H',
  12067. 'NWP-V',
  12068. 'RKSJ-H',
  12069. 'RKSJ-V',
  12070. 'Roman',
  12071. 'UniCNS-UCS2-H',
  12072. 'UniCNS-UCS2-V',
  12073. 'UniCNS-UTF16-H',
  12074. 'UniCNS-UTF16-V',
  12075. 'UniCNS-UTF32-H',
  12076. 'UniCNS-UTF32-V',
  12077. 'UniCNS-UTF8-H',
  12078. 'UniCNS-UTF8-V',
  12079. 'UniGB-UCS2-H',
  12080. 'UniGB-UCS2-V',
  12081. 'UniGB-UTF16-H',
  12082. 'UniGB-UTF16-V',
  12083. 'UniGB-UTF32-H',
  12084. 'UniGB-UTF32-V',
  12085. 'UniGB-UTF8-H',
  12086. 'UniGB-UTF8-V',
  12087. 'UniJIS-UCS2-H',
  12088. 'UniJIS-UCS2-HW-H',
  12089. 'UniJIS-UCS2-HW-V',
  12090. 'UniJIS-UCS2-V',
  12091. 'UniJIS-UTF16-H',
  12092. 'UniJIS-UTF16-V',
  12093. 'UniJIS-UTF32-H',
  12094. 'UniJIS-UTF32-V',
  12095. 'UniJIS-UTF8-H',
  12096. 'UniJIS-UTF8-V',
  12097. 'UniJIS2004-UTF16-H',
  12098. 'UniJIS2004-UTF16-V',
  12099. 'UniJIS2004-UTF32-H',
  12100. 'UniJIS2004-UTF32-V',
  12101. 'UniJIS2004-UTF8-H',
  12102. 'UniJIS2004-UTF8-V',
  12103. 'UniJISPro-UCS2-HW-V',
  12104. 'UniJISPro-UCS2-V',
  12105. 'UniJISPro-UTF8-V',
  12106. 'UniJISX0213-UTF32-H',
  12107. 'UniJISX0213-UTF32-V',
  12108. 'UniJISX02132004-UTF32-H',
  12109. 'UniJISX02132004-UTF32-V',
  12110. 'UniKS-UCS2-H',
  12111. 'UniKS-UCS2-V',
  12112. 'UniKS-UTF16-H',
  12113. 'UniKS-UTF16-V',
  12114. 'UniKS-UTF32-H',
  12115. 'UniKS-UTF32-V',
  12116. 'UniKS-UTF8-H',
  12117. 'UniKS-UTF8-V',
  12118. 'V',
  12119. 'WP-Symbol'];
  12120. // CMap, not to be confused with TrueType's cmap.
  12121. var CMap = (function CMapClosure() {
  12122. function CMap(builtInCMap) {
  12123. // Codespace ranges are stored as follows:
  12124. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12125. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12126. this.codespaceRanges = [[], [], [], []];
  12127. this.numCodespaceRanges = 0;
  12128. // Map entries have one of two forms.
  12129. // - cid chars are 16-bit unsigned integers, stored as integers.
  12130. // - bf chars are variable-length byte sequences, stored as strings, with
  12131. // one byte per character.
  12132. this._map = [];
  12133. this.vertical = false;
  12134. this.useCMap = null;
  12135. this.builtInCMap = builtInCMap;
  12136. }
  12137. CMap.prototype = {
  12138. addCodespaceRange: function(n, low, high) {
  12139. this.codespaceRanges[n - 1].push(low, high);
  12140. this.numCodespaceRanges++;
  12141. },
  12142. mapCidRange: function(low, high, dstLow) {
  12143. while (low <= high) {
  12144. this._map[low++] = dstLow++;
  12145. }
  12146. },
  12147. mapBfRange: function(low, high, dstLow) {
  12148. var lastByte = dstLow.length - 1;
  12149. while (low <= high) {
  12150. this._map[low++] = dstLow;
  12151. // Only the last byte has to be incremented.
  12152. dstLow = dstLow.substr(0, lastByte) +
  12153. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12154. }
  12155. },
  12156. mapBfRangeToArray: function(low, high, array) {
  12157. var i = 0, ii = array.length;
  12158. while (low <= high && i < ii) {
  12159. this._map[low] = array[i++];
  12160. ++low;
  12161. }
  12162. },
  12163. // This is used for both bf and cid chars.
  12164. mapOne: function(src, dst) {
  12165. this._map[src] = dst;
  12166. },
  12167. lookup: function(code) {
  12168. return this._map[code];
  12169. },
  12170. contains: function(code) {
  12171. return this._map[code] !== undefined;
  12172. },
  12173. forEach: function(callback) {
  12174. // Most maps have fewer than 65536 entries, and for those we use normal
  12175. // array iteration. But really sparse tables are possible -- e.g. with
  12176. // indices in the *billions*. For such tables we use for..in, which isn't
  12177. // ideal because it stringifies the indices for all present elements, but
  12178. // it does avoid iterating over every undefined entry.
  12179. var map = this._map;
  12180. var length = map.length;
  12181. var i;
  12182. if (length <= 0x10000) {
  12183. for (i = 0; i < length; i++) {
  12184. if (map[i] !== undefined) {
  12185. callback(i, map[i]);
  12186. }
  12187. }
  12188. } else {
  12189. for (i in this._map) {
  12190. callback(i, map[i]);
  12191. }
  12192. }
  12193. },
  12194. charCodeOf: function(value) {
  12195. return this._map.indexOf(value);
  12196. },
  12197. getMap: function() {
  12198. return this._map;
  12199. },
  12200. readCharCode: function(str, offset, out) {
  12201. var c = 0;
  12202. var codespaceRanges = this.codespaceRanges;
  12203. var codespaceRangesLen = this.codespaceRanges.length;
  12204. // 9.7.6.2 CMap Mapping
  12205. // The code length is at most 4.
  12206. for (var n = 0; n < codespaceRangesLen; n++) {
  12207. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12208. // Check each codespace range to see if it falls within.
  12209. var codespaceRange = codespaceRanges[n];
  12210. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12211. var low = codespaceRange[k++];
  12212. var high = codespaceRange[k++];
  12213. if (c >= low && c <= high) {
  12214. out.charcode = c;
  12215. out.length = n + 1;
  12216. return;
  12217. }
  12218. }
  12219. }
  12220. out.charcode = 0;
  12221. out.length = 1;
  12222. }
  12223. };
  12224. return CMap;
  12225. })();
  12226. // A special case of CMap, where the _map array implicitly has a length of
  12227. // 65535 and each element is equal to its index.
  12228. var IdentityCMap = (function IdentityCMapClosure() {
  12229. function IdentityCMap(vertical, n) {
  12230. CMap.call(this);
  12231. this.vertical = vertical;
  12232. this.addCodespaceRange(n, 0, 0xffff);
  12233. }
  12234. Util.inherit(IdentityCMap, CMap, {});
  12235. IdentityCMap.prototype = {
  12236. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12237. mapCidRange: function(low, high, dstLow) {
  12238. error('should not call mapCidRange');
  12239. },
  12240. mapBfRange: function(low, high, dstLow) {
  12241. error('should not call mapBfRange');
  12242. },
  12243. mapBfRangeToArray: function(low, high, array) {
  12244. error('should not call mapBfRangeToArray');
  12245. },
  12246. mapOne: function(src, dst) {
  12247. error('should not call mapCidOne');
  12248. },
  12249. lookup: function(code) {
  12250. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12251. },
  12252. contains: function(code) {
  12253. return isInt(code) && code <= 0xffff;
  12254. },
  12255. forEach: function(callback) {
  12256. for (var i = 0; i <= 0xffff; i++) {
  12257. callback(i, i);
  12258. }
  12259. },
  12260. charCodeOf: function(value) {
  12261. return (isInt(value) && value <= 0xffff) ? value : -1;
  12262. },
  12263. getMap: function() {
  12264. // Sometimes identity maps must be instantiated, but it's rare.
  12265. var map = new Array(0x10000);
  12266. for (var i = 0; i <= 0xffff; i++) {
  12267. map[i] = i;
  12268. }
  12269. return map;
  12270. },
  12271. readCharCode: CMap.prototype.readCharCode
  12272. };
  12273. return IdentityCMap;
  12274. })();
  12275. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12276. function fetchBinaryData(url) {
  12277. var nonBinaryRequest = PDFJS.disableWorker;
  12278. var request = new XMLHttpRequest();
  12279. request.open('GET', url, false);
  12280. if (!nonBinaryRequest) {
  12281. try {
  12282. request.responseType = 'arraybuffer';
  12283. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12284. } catch (e) {
  12285. nonBinaryRequest = true;
  12286. }
  12287. }
  12288. if (nonBinaryRequest && request.overrideMimeType) {
  12289. request.overrideMimeType('text/plain; charset=x-user-defined');
  12290. }
  12291. request.send(null);
  12292. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12293. error('Unable to get binary cMap at: ' + url);
  12294. }
  12295. if (nonBinaryRequest) {
  12296. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12297. return ch.charCodeAt(0) & 255;
  12298. });
  12299. return new Uint8Array(data);
  12300. }
  12301. return new Uint8Array(request.response);
  12302. }
  12303. function hexToInt(a, size) {
  12304. var n = 0;
  12305. for (var i = 0; i <= size; i++) {
  12306. n = (n << 8) | a[i];
  12307. }
  12308. return n >>> 0;
  12309. }
  12310. function hexToStr(a, size) {
  12311. // This code is hot. Special-case some common values to avoid creating an
  12312. // object with subarray().
  12313. if (size === 1) {
  12314. return String.fromCharCode(a[0], a[1]);
  12315. }
  12316. if (size === 3) {
  12317. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12318. }
  12319. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12320. }
  12321. function addHex(a, b, size) {
  12322. var c = 0;
  12323. for (var i = size; i >= 0; i--) {
  12324. c += a[i] + b[i];
  12325. a[i] = c & 255;
  12326. c >>= 8;
  12327. }
  12328. }
  12329. function incHex(a, size) {
  12330. var c = 1;
  12331. for (var i = size; i >= 0 && c > 0; i--) {
  12332. c += a[i];
  12333. a[i] = c & 255;
  12334. c >>= 8;
  12335. }
  12336. }
  12337. var MAX_NUM_SIZE = 16;
  12338. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12339. function BinaryCMapStream(data) {
  12340. this.buffer = data;
  12341. this.pos = 0;
  12342. this.end = data.length;
  12343. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12344. }
  12345. BinaryCMapStream.prototype = {
  12346. readByte: function () {
  12347. if (this.pos >= this.end) {
  12348. return -1;
  12349. }
  12350. return this.buffer[this.pos++];
  12351. },
  12352. readNumber: function () {
  12353. var n = 0;
  12354. var last;
  12355. do {
  12356. var b = this.readByte();
  12357. if (b < 0) {
  12358. error('unexpected EOF in bcmap');
  12359. }
  12360. last = !(b & 0x80);
  12361. n = (n << 7) | (b & 0x7F);
  12362. } while (!last);
  12363. return n;
  12364. },
  12365. readSigned: function () {
  12366. var n = this.readNumber();
  12367. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12368. },
  12369. readHex: function (num, size) {
  12370. num.set(this.buffer.subarray(this.pos,
  12371. this.pos + size + 1));
  12372. this.pos += size + 1;
  12373. },
  12374. readHexNumber: function (num, size) {
  12375. var last;
  12376. var stack = this.tmpBuf, sp = 0;
  12377. do {
  12378. var b = this.readByte();
  12379. if (b < 0) {
  12380. error('unexpected EOF in bcmap');
  12381. }
  12382. last = !(b & 0x80);
  12383. stack[sp++] = b & 0x7F;
  12384. } while (!last);
  12385. var i = size, buffer = 0, bufferSize = 0;
  12386. while (i >= 0) {
  12387. while (bufferSize < 8 && stack.length > 0) {
  12388. buffer = (stack[--sp] << bufferSize) | buffer;
  12389. bufferSize += 7;
  12390. }
  12391. num[i] = buffer & 255;
  12392. i--;
  12393. buffer >>= 8;
  12394. bufferSize -= 8;
  12395. }
  12396. },
  12397. readHexSigned: function (num, size) {
  12398. this.readHexNumber(num, size);
  12399. var sign = num[size] & 1 ? 255 : 0;
  12400. var c = 0;
  12401. for (var i = 0; i <= size; i++) {
  12402. c = ((c & 1) << 8) | num[i];
  12403. num[i] = (c >> 1) ^ sign;
  12404. }
  12405. },
  12406. readString: function () {
  12407. var len = this.readNumber();
  12408. var s = '';
  12409. for (var i = 0; i < len; i++) {
  12410. s += String.fromCharCode(this.readNumber());
  12411. }
  12412. return s;
  12413. }
  12414. };
  12415. function processBinaryCMap(url, cMap, extend) {
  12416. var data = fetchBinaryData(url);
  12417. var stream = new BinaryCMapStream(data);
  12418. var header = stream.readByte();
  12419. cMap.vertical = !!(header & 1);
  12420. var useCMap = null;
  12421. var start = new Uint8Array(MAX_NUM_SIZE);
  12422. var end = new Uint8Array(MAX_NUM_SIZE);
  12423. var char = new Uint8Array(MAX_NUM_SIZE);
  12424. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12425. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12426. var code;
  12427. var b;
  12428. while ((b = stream.readByte()) >= 0) {
  12429. var type = b >> 5;
  12430. if (type === 7) { // metadata, e.g. comment or usecmap
  12431. switch (b & 0x1F) {
  12432. case 0:
  12433. stream.readString(); // skipping comment
  12434. break;
  12435. case 1:
  12436. useCMap = stream.readString();
  12437. break;
  12438. }
  12439. continue;
  12440. }
  12441. var sequence = !!(b & 0x10);
  12442. var dataSize = b & 15;
  12443. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12444. var ucs2DataSize = 1;
  12445. var subitemsCount = stream.readNumber();
  12446. var i;
  12447. switch (type) {
  12448. case 0: // codespacerange
  12449. stream.readHex(start, dataSize);
  12450. stream.readHexNumber(end, dataSize);
  12451. addHex(end, start, dataSize);
  12452. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12453. hexToInt(end, dataSize));
  12454. for (i = 1; i < subitemsCount; i++) {
  12455. incHex(end, dataSize);
  12456. stream.readHexNumber(start, dataSize);
  12457. addHex(start, end, dataSize);
  12458. stream.readHexNumber(end, dataSize);
  12459. addHex(end, start, dataSize);
  12460. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12461. hexToInt(end, dataSize));
  12462. }
  12463. break;
  12464. case 1: // notdefrange
  12465. stream.readHex(start, dataSize);
  12466. stream.readHexNumber(end, dataSize);
  12467. addHex(end, start, dataSize);
  12468. code = stream.readNumber();
  12469. // undefined range, skipping
  12470. for (i = 1; i < subitemsCount; i++) {
  12471. incHex(end, dataSize);
  12472. stream.readHexNumber(start, dataSize);
  12473. addHex(start, end, dataSize);
  12474. stream.readHexNumber(end, dataSize);
  12475. addHex(end, start, dataSize);
  12476. code = stream.readNumber();
  12477. // nop
  12478. }
  12479. break;
  12480. case 2: // cidchar
  12481. stream.readHex(char, dataSize);
  12482. code = stream.readNumber();
  12483. cMap.mapOne(hexToInt(char, dataSize), code);
  12484. for (i = 1; i < subitemsCount; i++) {
  12485. incHex(char, dataSize);
  12486. if (!sequence) {
  12487. stream.readHexNumber(tmp, dataSize);
  12488. addHex(char, tmp, dataSize);
  12489. }
  12490. code = stream.readSigned() + (code + 1);
  12491. cMap.mapOne(hexToInt(char, dataSize), code);
  12492. }
  12493. break;
  12494. case 3: // cidrange
  12495. stream.readHex(start, dataSize);
  12496. stream.readHexNumber(end, dataSize);
  12497. addHex(end, start, dataSize);
  12498. code = stream.readNumber();
  12499. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12500. code);
  12501. for (i = 1; i < subitemsCount; i++) {
  12502. incHex(end, dataSize);
  12503. if (!sequence) {
  12504. stream.readHexNumber(start, dataSize);
  12505. addHex(start, end, dataSize);
  12506. } else {
  12507. start.set(end);
  12508. }
  12509. stream.readHexNumber(end, dataSize);
  12510. addHex(end, start, dataSize);
  12511. code = stream.readNumber();
  12512. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12513. code);
  12514. }
  12515. break;
  12516. case 4: // bfchar
  12517. stream.readHex(char, ucs2DataSize);
  12518. stream.readHex(charCode, dataSize);
  12519. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12520. hexToStr(charCode, dataSize));
  12521. for (i = 1; i < subitemsCount; i++) {
  12522. incHex(char, ucs2DataSize);
  12523. if (!sequence) {
  12524. stream.readHexNumber(tmp, ucs2DataSize);
  12525. addHex(char, tmp, ucs2DataSize);
  12526. }
  12527. incHex(charCode, dataSize);
  12528. stream.readHexSigned(tmp, dataSize);
  12529. addHex(charCode, tmp, dataSize);
  12530. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12531. hexToStr(charCode, dataSize));
  12532. }
  12533. break;
  12534. case 5: // bfrange
  12535. stream.readHex(start, ucs2DataSize);
  12536. stream.readHexNumber(end, ucs2DataSize);
  12537. addHex(end, start, ucs2DataSize);
  12538. stream.readHex(charCode, dataSize);
  12539. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12540. hexToInt(end, ucs2DataSize),
  12541. hexToStr(charCode, dataSize));
  12542. for (i = 1; i < subitemsCount; i++) {
  12543. incHex(end, ucs2DataSize);
  12544. if (!sequence) {
  12545. stream.readHexNumber(start, ucs2DataSize);
  12546. addHex(start, end, ucs2DataSize);
  12547. } else {
  12548. start.set(end);
  12549. }
  12550. stream.readHexNumber(end, ucs2DataSize);
  12551. addHex(end, start, ucs2DataSize);
  12552. stream.readHex(charCode, dataSize);
  12553. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12554. hexToInt(end, ucs2DataSize),
  12555. hexToStr(charCode, dataSize));
  12556. }
  12557. break;
  12558. default:
  12559. error('Unknown type: ' + type);
  12560. break;
  12561. }
  12562. }
  12563. if (useCMap) {
  12564. extend(useCMap);
  12565. }
  12566. return cMap;
  12567. }
  12568. function BinaryCMapReader() {}
  12569. BinaryCMapReader.prototype = {
  12570. read: processBinaryCMap
  12571. };
  12572. return BinaryCMapReader;
  12573. })();
  12574. var CMapFactory = (function CMapFactoryClosure() {
  12575. function strToInt(str) {
  12576. var a = 0;
  12577. for (var i = 0; i < str.length; i++) {
  12578. a = (a << 8) | str.charCodeAt(i);
  12579. }
  12580. return a >>> 0;
  12581. }
  12582. function expectString(obj) {
  12583. if (!isString(obj)) {
  12584. error('Malformed CMap: expected string.');
  12585. }
  12586. }
  12587. function expectInt(obj) {
  12588. if (!isInt(obj)) {
  12589. error('Malformed CMap: expected int.');
  12590. }
  12591. }
  12592. function parseBfChar(cMap, lexer) {
  12593. while (true) {
  12594. var obj = lexer.getObj();
  12595. if (isEOF(obj)) {
  12596. break;
  12597. }
  12598. if (isCmd(obj, 'endbfchar')) {
  12599. return;
  12600. }
  12601. expectString(obj);
  12602. var src = strToInt(obj);
  12603. obj = lexer.getObj();
  12604. // TODO are /dstName used?
  12605. expectString(obj);
  12606. var dst = obj;
  12607. cMap.mapOne(src, dst);
  12608. }
  12609. }
  12610. function parseBfRange(cMap, lexer) {
  12611. while (true) {
  12612. var obj = lexer.getObj();
  12613. if (isEOF(obj)) {
  12614. break;
  12615. }
  12616. if (isCmd(obj, 'endbfrange')) {
  12617. return;
  12618. }
  12619. expectString(obj);
  12620. var low = strToInt(obj);
  12621. obj = lexer.getObj();
  12622. expectString(obj);
  12623. var high = strToInt(obj);
  12624. obj = lexer.getObj();
  12625. if (isInt(obj) || isString(obj)) {
  12626. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12627. cMap.mapBfRange(low, high, dstLow);
  12628. } else if (isCmd(obj, '[')) {
  12629. obj = lexer.getObj();
  12630. var array = [];
  12631. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12632. array.push(obj);
  12633. obj = lexer.getObj();
  12634. }
  12635. cMap.mapBfRangeToArray(low, high, array);
  12636. } else {
  12637. break;
  12638. }
  12639. }
  12640. error('Invalid bf range.');
  12641. }
  12642. function parseCidChar(cMap, lexer) {
  12643. while (true) {
  12644. var obj = lexer.getObj();
  12645. if (isEOF(obj)) {
  12646. break;
  12647. }
  12648. if (isCmd(obj, 'endcidchar')) {
  12649. return;
  12650. }
  12651. expectString(obj);
  12652. var src = strToInt(obj);
  12653. obj = lexer.getObj();
  12654. expectInt(obj);
  12655. var dst = obj;
  12656. cMap.mapOne(src, dst);
  12657. }
  12658. }
  12659. function parseCidRange(cMap, lexer) {
  12660. while (true) {
  12661. var obj = lexer.getObj();
  12662. if (isEOF(obj)) {
  12663. break;
  12664. }
  12665. if (isCmd(obj, 'endcidrange')) {
  12666. return;
  12667. }
  12668. expectString(obj);
  12669. var low = strToInt(obj);
  12670. obj = lexer.getObj();
  12671. expectString(obj);
  12672. var high = strToInt(obj);
  12673. obj = lexer.getObj();
  12674. expectInt(obj);
  12675. var dstLow = obj;
  12676. cMap.mapCidRange(low, high, dstLow);
  12677. }
  12678. }
  12679. function parseCodespaceRange(cMap, lexer) {
  12680. while (true) {
  12681. var obj = lexer.getObj();
  12682. if (isEOF(obj)) {
  12683. break;
  12684. }
  12685. if (isCmd(obj, 'endcodespacerange')) {
  12686. return;
  12687. }
  12688. if (!isString(obj)) {
  12689. break;
  12690. }
  12691. var low = strToInt(obj);
  12692. obj = lexer.getObj();
  12693. if (!isString(obj)) {
  12694. break;
  12695. }
  12696. var high = strToInt(obj);
  12697. cMap.addCodespaceRange(obj.length, low, high);
  12698. }
  12699. error('Invalid codespace range.');
  12700. }
  12701. function parseWMode(cMap, lexer) {
  12702. var obj = lexer.getObj();
  12703. if (isInt(obj)) {
  12704. cMap.vertical = !!obj;
  12705. }
  12706. }
  12707. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12708. var previous;
  12709. var embededUseCMap;
  12710. objLoop: while (true) {
  12711. var obj = lexer.getObj();
  12712. if (isEOF(obj)) {
  12713. break;
  12714. } else if (isName(obj)) {
  12715. if (obj.name === 'WMode') {
  12716. parseWMode(cMap, lexer);
  12717. }
  12718. previous = obj;
  12719. } else if (isCmd(obj)) {
  12720. switch (obj.cmd) {
  12721. case 'endcmap':
  12722. break objLoop;
  12723. case 'usecmap':
  12724. if (isName(previous)) {
  12725. embededUseCMap = previous.name;
  12726. }
  12727. break;
  12728. case 'begincodespacerange':
  12729. parseCodespaceRange(cMap, lexer);
  12730. break;
  12731. case 'beginbfchar':
  12732. parseBfChar(cMap, lexer);
  12733. break;
  12734. case 'begincidchar':
  12735. parseCidChar(cMap, lexer);
  12736. break;
  12737. case 'beginbfrange':
  12738. parseBfRange(cMap, lexer);
  12739. break;
  12740. case 'begincidrange':
  12741. parseCidRange(cMap, lexer);
  12742. break;
  12743. }
  12744. }
  12745. }
  12746. if (!useCMap && embededUseCMap) {
  12747. // Load the usecmap definition from the file only if there wasn't one
  12748. // specified.
  12749. useCMap = embededUseCMap;
  12750. }
  12751. if (useCMap) {
  12752. extendCMap(cMap, builtInCMapParams, useCMap);
  12753. }
  12754. }
  12755. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12756. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12757. // If there aren't any code space ranges defined clone all the parent ones
  12758. // into this cMap.
  12759. if (cMap.numCodespaceRanges === 0) {
  12760. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12761. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12762. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12763. }
  12764. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12765. }
  12766. // Merge the map into the current one, making sure not to override
  12767. // any previously defined entries.
  12768. cMap.useCMap.forEach(function(key, value) {
  12769. if (!cMap.contains(key)) {
  12770. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12771. }
  12772. });
  12773. }
  12774. function parseBinaryCMap(name, builtInCMapParams) {
  12775. var url = builtInCMapParams.url + name + '.bcmap';
  12776. var cMap = new CMap(true);
  12777. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12778. extendCMap(cMap, builtInCMapParams, useCMap);
  12779. });
  12780. return cMap;
  12781. }
  12782. function createBuiltInCMap(name, builtInCMapParams) {
  12783. if (name === 'Identity-H') {
  12784. return new IdentityCMap(false, 2);
  12785. } else if (name === 'Identity-V') {
  12786. return new IdentityCMap(true, 2);
  12787. }
  12788. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12789. error('Unknown cMap name: ' + name);
  12790. }
  12791. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12792. if (builtInCMapParams.packed) {
  12793. return parseBinaryCMap(name, builtInCMapParams);
  12794. }
  12795. var request = new XMLHttpRequest();
  12796. var url = builtInCMapParams.url + name;
  12797. request.open('GET', url, false);
  12798. request.send(null);
  12799. if (!request.responseText) {
  12800. error('Unable to get cMap at: ' + url);
  12801. }
  12802. var cMap = new CMap(true);
  12803. var lexer = new Lexer(new StringStream(request.responseText));
  12804. parseCMap(cMap, lexer, builtInCMapParams, null);
  12805. return cMap;
  12806. }
  12807. return {
  12808. create: function (encoding, builtInCMapParams, useCMap) {
  12809. if (isName(encoding)) {
  12810. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12811. } else if (isStream(encoding)) {
  12812. var cMap = new CMap();
  12813. var lexer = new Lexer(encoding);
  12814. try {
  12815. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12816. } catch (e) {
  12817. warn('Invalid CMap data. ' + e);
  12818. }
  12819. return cMap;
  12820. }
  12821. error('Encoding required.');
  12822. }
  12823. };
  12824. })();
  12825. // Unicode Private Use Area
  12826. var PRIVATE_USE_OFFSET_START = 0xE000;
  12827. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12828. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12829. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12830. // except for Type 3 fonts
  12831. var PDF_GLYPH_SPACE_UNITS = 1000;
  12832. // Hinting is currently disabled due to unknown problems on windows
  12833. // in tracemonkey and various other pdfs with type1 fonts.
  12834. var HINTING_ENABLED = false;
  12835. // Accented charactars are not displayed properly on windows, using this flag
  12836. // to control analysis of seac charstrings.
  12837. var SEAC_ANALYSIS_ENABLED = false;
  12838. var FontFlags = {
  12839. FixedPitch: 1,
  12840. Serif: 2,
  12841. Symbolic: 4,
  12842. Script: 8,
  12843. Nonsymbolic: 32,
  12844. Italic: 64,
  12845. AllCap: 65536,
  12846. SmallCap: 131072,
  12847. ForceBold: 262144
  12848. };
  12849. var Encodings = {
  12850. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12851. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12852. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12853. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12854. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12855. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12856. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12857. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12858. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12859. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12860. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12861. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12862. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12863. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12864. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12865. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12866. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12867. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12868. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12869. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12870. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12871. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12872. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12873. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12874. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12875. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12876. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12877. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12878. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12879. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12880. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12881. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12882. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12883. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12884. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12885. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12886. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12887. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12888. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12889. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12890. 'Ydieresissmall'],
  12891. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12892. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12893. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12894. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12895. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12896. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12897. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12898. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12899. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12900. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12901. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12902. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12903. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12904. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12905. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12906. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12907. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12908. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12909. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12910. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12911. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12912. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12913. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12914. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12915. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12916. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12917. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12918. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12919. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12920. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12921. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12922. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12923. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12924. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12925. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12926. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12927. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12928. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12929. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12930. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12931. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12932. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12933. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12934. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12935. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12936. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12937. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12938. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12939. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12940. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12941. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12942. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12943. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12944. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12945. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12946. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12947. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12948. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12949. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12950. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12951. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12952. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12953. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12954. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12955. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12956. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12957. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12958. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12959. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12960. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12961. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12962. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12963. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12964. 'ogonek', 'caron'],
  12965. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12966. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12967. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12968. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12969. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12970. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12971. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12972. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12973. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12974. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12975. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12976. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12977. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12978. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12979. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12980. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12981. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12982. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12983. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12984. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12985. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12986. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12987. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12988. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12989. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12990. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12991. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12992. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12993. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12994. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12995. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12996. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12997. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12998. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12999. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13000. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13001. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13002. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13003. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13004. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13005. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13006. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13007. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13008. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13009. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13010. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13011. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13012. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13013. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13014. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13015. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13016. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13017. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13018. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13019. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13020. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13021. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13022. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13023. 'ydieresis'],
  13024. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13025. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13026. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13027. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13028. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13029. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13030. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13031. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13032. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13033. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13034. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13035. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13036. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13037. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13038. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13039. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13040. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13041. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13042. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13043. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13044. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13045. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13046. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13047. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13048. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13049. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13050. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13051. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13052. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13053. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13054. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13055. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13056. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13057. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13058. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13059. 'bracerightbt'],
  13060. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13061. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13062. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13063. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13064. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13065. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13066. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13067. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13068. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13069. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13070. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13071. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13072. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13073. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13074. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13075. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13076. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13077. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13078. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13079. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13080. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13081. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13082. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13083. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13084. };
  13085. /**
  13086. * Hold a map of decoded fonts and of the standard fourteen Type1
  13087. * fonts and their acronyms.
  13088. */
  13089. var stdFontMap = {
  13090. 'ArialNarrow': 'Helvetica',
  13091. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13092. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13093. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13094. 'ArialBlack': 'Helvetica',
  13095. 'ArialBlack-Bold': 'Helvetica-Bold',
  13096. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13097. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13098. 'Arial': 'Helvetica',
  13099. 'Arial-Bold': 'Helvetica-Bold',
  13100. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13101. 'Arial-Italic': 'Helvetica-Oblique',
  13102. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13103. 'Arial-BoldMT': 'Helvetica-Bold',
  13104. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13105. 'ArialMT': 'Helvetica',
  13106. 'Courier-Bold': 'Courier-Bold',
  13107. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13108. 'Courier-Italic': 'Courier-Oblique',
  13109. 'CourierNew': 'Courier',
  13110. 'CourierNew-Bold': 'Courier-Bold',
  13111. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13112. 'CourierNew-Italic': 'Courier-Oblique',
  13113. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13114. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13115. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13116. 'CourierNewPSMT': 'Courier',
  13117. 'Helvetica': 'Helvetica',
  13118. 'Helvetica-Bold': 'Helvetica-Bold',
  13119. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13120. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13121. 'Helvetica-Italic': 'Helvetica-Oblique',
  13122. 'Helvetica-Oblique':'Helvetica-Oblique',
  13123. 'Symbol-Bold': 'Symbol',
  13124. 'Symbol-BoldItalic': 'Symbol',
  13125. 'Symbol-Italic': 'Symbol',
  13126. 'TimesNewRoman': 'Times-Roman',
  13127. 'TimesNewRoman-Bold': 'Times-Bold',
  13128. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13129. 'TimesNewRoman-Italic': 'Times-Italic',
  13130. 'TimesNewRomanPS': 'Times-Roman',
  13131. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13132. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13133. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13134. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13135. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13136. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13137. 'TimesNewRomanPSMT': 'Times-Roman',
  13138. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13139. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13140. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13141. };
  13142. /**
  13143. * Holds the map of the non-standard fonts that might be included as a standard
  13144. * fonts without glyph data.
  13145. */
  13146. var nonStdFontMap = {
  13147. 'CenturyGothic': 'Helvetica',
  13148. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13149. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13150. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13151. 'ComicSansMS': 'Comic Sans MS',
  13152. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13153. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13154. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13155. 'LucidaConsole': 'Courier',
  13156. 'LucidaConsole-Bold': 'Courier-Bold',
  13157. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13158. 'LucidaConsole-Italic': 'Courier-Oblique',
  13159. 'MS-Gothic': 'MS Gothic',
  13160. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13161. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13162. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13163. 'MS-Mincho': 'MS Mincho',
  13164. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13165. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13166. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13167. 'MS-PGothic': 'MS PGothic',
  13168. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13169. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13170. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13171. 'MS-PMincho': 'MS PMincho',
  13172. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13173. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13174. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13175. 'Wingdings': 'ZapfDingbats'
  13176. };
  13177. var serifFonts = {
  13178. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13179. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13180. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13181. 'Arno': true, 'Aster': true, 'Aurora': true,
  13182. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13183. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13184. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13185. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13186. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13187. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13188. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13189. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13190. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13191. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13192. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13193. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13194. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13195. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13196. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13197. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13198. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13199. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13200. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13201. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13202. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13203. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13204. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13205. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13206. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13207. 'Miller': true, 'Minion': true, 'Modern': true,
  13208. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13209. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13210. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13211. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13212. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13213. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13214. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13215. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13216. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13217. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13218. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13219. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13220. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13221. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13222. };
  13223. var symbolsFonts = {
  13224. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13225. };
  13226. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13227. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13228. // glyphs, but common for some set of the standard fonts.
  13229. var GlyphMapForStandardFonts = {
  13230. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13231. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13232. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13233. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13234. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13235. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13236. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13237. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13238. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13239. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13240. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13241. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13242. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13243. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13244. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13245. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13246. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13247. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13248. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13249. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13250. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13251. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13252. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13253. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13254. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13255. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13256. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13257. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13258. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13259. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13260. '298': 380, '305': 963,
  13261. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13262. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13263. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13264. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13265. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13266. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13267. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13268. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13269. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13270. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13271. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13272. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13273. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13274. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13275. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13276. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13277. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13278. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13279. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13280. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13281. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13282. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13283. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13284. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13285. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13286. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13287. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13288. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13289. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13290. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13291. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13292. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13293. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13294. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13295. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13296. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13297. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13298. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13299. };
  13300. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13301. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13302. // to the similar equivalents in the normal characters range.
  13303. var SpecialPUASymbols = {
  13304. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13305. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13306. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13307. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13308. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13309. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13310. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13311. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13312. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13313. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13314. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13315. '63742': 0x23AD, // bracerightmid (0xF8FE)
  13316. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13317. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13318. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13319. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13320. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13321. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13322. '63723': 0x239B, // parenlefttp (0xF8EB)
  13323. '63724': 0x239C, // parenleftex (0xF8EC)
  13324. '63725': 0x239D, // parenleftbt (0xF8ED)
  13325. '63734': 0x239E, // parenrighttp (0xF8F6)
  13326. '63735': 0x239F, // parenrightex (0xF8F7)
  13327. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13328. };
  13329. function mapSpecialUnicodeValues(code) {
  13330. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13331. return 0;
  13332. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13333. return (SpecialPUASymbols[code] || code);
  13334. }
  13335. return code;
  13336. }
  13337. var UnicodeRanges = [
  13338. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13339. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13340. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13341. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13342. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13343. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13344. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13345. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13346. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13347. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13348. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13349. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13350. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13351. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13352. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13353. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13354. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13355. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13356. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13357. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13358. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13359. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13360. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13361. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13362. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13363. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13364. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13365. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13366. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13367. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13368. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13369. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13370. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13371. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13372. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13373. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13374. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13375. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13376. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13377. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13378. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13379. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13380. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13381. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13382. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13383. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13384. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13385. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13386. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13387. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13388. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13389. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13390. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13391. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13392. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13393. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13394. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13395. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13396. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13397. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13398. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13399. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13400. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13401. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13402. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13403. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13404. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13405. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13406. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13407. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13408. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13409. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13410. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13411. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13412. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13413. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13414. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13415. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13416. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13417. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13418. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13419. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13420. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13421. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13422. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13423. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13424. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13425. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13426. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13427. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13428. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13429. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13430. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13431. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13432. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13433. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13434. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13435. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13436. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13437. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13438. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13439. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13440. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13441. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13442. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13443. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13444. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13445. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13446. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13447. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13448. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13449. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13450. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13451. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13452. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13453. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13454. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13455. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13456. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13457. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13458. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13459. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13460. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13461. ];
  13462. var MacStandardGlyphOrdering = [
  13463. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13464. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13465. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13466. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13467. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13468. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13469. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13470. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13471. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13472. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13473. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13474. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13475. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13476. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13477. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13478. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13479. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13480. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13481. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13482. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13483. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13484. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13485. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13486. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13487. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13488. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13489. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13490. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13491. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13492. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13493. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13494. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13495. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13496. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13497. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13498. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13499. function getUnicodeRangeFor(value) {
  13500. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13501. var range = UnicodeRanges[i];
  13502. if (value >= range.begin && value < range.end) {
  13503. return i;
  13504. }
  13505. }
  13506. return -1;
  13507. }
  13508. function isRTLRangeFor(value) {
  13509. var range = UnicodeRanges[13];
  13510. if (value >= range.begin && value < range.end) {
  13511. return true;
  13512. }
  13513. range = UnicodeRanges[11];
  13514. if (value >= range.begin && value < range.end) {
  13515. return true;
  13516. }
  13517. return false;
  13518. }
  13519. // The normalization table is obtained by filtering the Unicode characters
  13520. // database with <compat> entries.
  13521. var NormalizedUnicodes = {
  13522. '\u00A8': '\u0020\u0308',
  13523. '\u00AF': '\u0020\u0304',
  13524. '\u00B4': '\u0020\u0301',
  13525. '\u00B5': '\u03BC',
  13526. '\u00B8': '\u0020\u0327',
  13527. '\u0132': '\u0049\u004A',
  13528. '\u0133': '\u0069\u006A',
  13529. '\u013F': '\u004C\u00B7',
  13530. '\u0140': '\u006C\u00B7',
  13531. '\u0149': '\u02BC\u006E',
  13532. '\u017F': '\u0073',
  13533. '\u01C4': '\u0044\u017D',
  13534. '\u01C5': '\u0044\u017E',
  13535. '\u01C6': '\u0064\u017E',
  13536. '\u01C7': '\u004C\u004A',
  13537. '\u01C8': '\u004C\u006A',
  13538. '\u01C9': '\u006C\u006A',
  13539. '\u01CA': '\u004E\u004A',
  13540. '\u01CB': '\u004E\u006A',
  13541. '\u01CC': '\u006E\u006A',
  13542. '\u01F1': '\u0044\u005A',
  13543. '\u01F2': '\u0044\u007A',
  13544. '\u01F3': '\u0064\u007A',
  13545. '\u02D8': '\u0020\u0306',
  13546. '\u02D9': '\u0020\u0307',
  13547. '\u02DA': '\u0020\u030A',
  13548. '\u02DB': '\u0020\u0328',
  13549. '\u02DC': '\u0020\u0303',
  13550. '\u02DD': '\u0020\u030B',
  13551. '\u037A': '\u0020\u0345',
  13552. '\u0384': '\u0020\u0301',
  13553. '\u03D0': '\u03B2',
  13554. '\u03D1': '\u03B8',
  13555. '\u03D2': '\u03A5',
  13556. '\u03D5': '\u03C6',
  13557. '\u03D6': '\u03C0',
  13558. '\u03F0': '\u03BA',
  13559. '\u03F1': '\u03C1',
  13560. '\u03F2': '\u03C2',
  13561. '\u03F4': '\u0398',
  13562. '\u03F5': '\u03B5',
  13563. '\u03F9': '\u03A3',
  13564. '\u0587': '\u0565\u0582',
  13565. '\u0675': '\u0627\u0674',
  13566. '\u0676': '\u0648\u0674',
  13567. '\u0677': '\u06C7\u0674',
  13568. '\u0678': '\u064A\u0674',
  13569. '\u0E33': '\u0E4D\u0E32',
  13570. '\u0EB3': '\u0ECD\u0EB2',
  13571. '\u0EDC': '\u0EAB\u0E99',
  13572. '\u0EDD': '\u0EAB\u0EA1',
  13573. '\u0F77': '\u0FB2\u0F81',
  13574. '\u0F79': '\u0FB3\u0F81',
  13575. '\u1E9A': '\u0061\u02BE',
  13576. '\u1FBD': '\u0020\u0313',
  13577. '\u1FBF': '\u0020\u0313',
  13578. '\u1FC0': '\u0020\u0342',
  13579. '\u1FFE': '\u0020\u0314',
  13580. '\u2002': '\u0020',
  13581. '\u2003': '\u0020',
  13582. '\u2004': '\u0020',
  13583. '\u2005': '\u0020',
  13584. '\u2006': '\u0020',
  13585. '\u2008': '\u0020',
  13586. '\u2009': '\u0020',
  13587. '\u200A': '\u0020',
  13588. '\u2017': '\u0020\u0333',
  13589. '\u2024': '\u002E',
  13590. '\u2025': '\u002E\u002E',
  13591. '\u2026': '\u002E\u002E\u002E',
  13592. '\u2033': '\u2032\u2032',
  13593. '\u2034': '\u2032\u2032\u2032',
  13594. '\u2036': '\u2035\u2035',
  13595. '\u2037': '\u2035\u2035\u2035',
  13596. '\u203C': '\u0021\u0021',
  13597. '\u203E': '\u0020\u0305',
  13598. '\u2047': '\u003F\u003F',
  13599. '\u2048': '\u003F\u0021',
  13600. '\u2049': '\u0021\u003F',
  13601. '\u2057': '\u2032\u2032\u2032\u2032',
  13602. '\u205F': '\u0020',
  13603. '\u20A8': '\u0052\u0073',
  13604. '\u2100': '\u0061\u002F\u0063',
  13605. '\u2101': '\u0061\u002F\u0073',
  13606. '\u2103': '\u00B0\u0043',
  13607. '\u2105': '\u0063\u002F\u006F',
  13608. '\u2106': '\u0063\u002F\u0075',
  13609. '\u2107': '\u0190',
  13610. '\u2109': '\u00B0\u0046',
  13611. '\u2116': '\u004E\u006F',
  13612. '\u2121': '\u0054\u0045\u004C',
  13613. '\u2135': '\u05D0',
  13614. '\u2136': '\u05D1',
  13615. '\u2137': '\u05D2',
  13616. '\u2138': '\u05D3',
  13617. '\u213B': '\u0046\u0041\u0058',
  13618. '\u2160': '\u0049',
  13619. '\u2161': '\u0049\u0049',
  13620. '\u2162': '\u0049\u0049\u0049',
  13621. '\u2163': '\u0049\u0056',
  13622. '\u2164': '\u0056',
  13623. '\u2165': '\u0056\u0049',
  13624. '\u2166': '\u0056\u0049\u0049',
  13625. '\u2167': '\u0056\u0049\u0049\u0049',
  13626. '\u2168': '\u0049\u0058',
  13627. '\u2169': '\u0058',
  13628. '\u216A': '\u0058\u0049',
  13629. '\u216B': '\u0058\u0049\u0049',
  13630. '\u216C': '\u004C',
  13631. '\u216D': '\u0043',
  13632. '\u216E': '\u0044',
  13633. '\u216F': '\u004D',
  13634. '\u2170': '\u0069',
  13635. '\u2171': '\u0069\u0069',
  13636. '\u2172': '\u0069\u0069\u0069',
  13637. '\u2173': '\u0069\u0076',
  13638. '\u2174': '\u0076',
  13639. '\u2175': '\u0076\u0069',
  13640. '\u2176': '\u0076\u0069\u0069',
  13641. '\u2177': '\u0076\u0069\u0069\u0069',
  13642. '\u2178': '\u0069\u0078',
  13643. '\u2179': '\u0078',
  13644. '\u217A': '\u0078\u0069',
  13645. '\u217B': '\u0078\u0069\u0069',
  13646. '\u217C': '\u006C',
  13647. '\u217D': '\u0063',
  13648. '\u217E': '\u0064',
  13649. '\u217F': '\u006D',
  13650. '\u222C': '\u222B\u222B',
  13651. '\u222D': '\u222B\u222B\u222B',
  13652. '\u222F': '\u222E\u222E',
  13653. '\u2230': '\u222E\u222E\u222E',
  13654. '\u2474': '\u0028\u0031\u0029',
  13655. '\u2475': '\u0028\u0032\u0029',
  13656. '\u2476': '\u0028\u0033\u0029',
  13657. '\u2477': '\u0028\u0034\u0029',
  13658. '\u2478': '\u0028\u0035\u0029',
  13659. '\u2479': '\u0028\u0036\u0029',
  13660. '\u247A': '\u0028\u0037\u0029',
  13661. '\u247B': '\u0028\u0038\u0029',
  13662. '\u247C': '\u0028\u0039\u0029',
  13663. '\u247D': '\u0028\u0031\u0030\u0029',
  13664. '\u247E': '\u0028\u0031\u0031\u0029',
  13665. '\u247F': '\u0028\u0031\u0032\u0029',
  13666. '\u2480': '\u0028\u0031\u0033\u0029',
  13667. '\u2481': '\u0028\u0031\u0034\u0029',
  13668. '\u2482': '\u0028\u0031\u0035\u0029',
  13669. '\u2483': '\u0028\u0031\u0036\u0029',
  13670. '\u2484': '\u0028\u0031\u0037\u0029',
  13671. '\u2485': '\u0028\u0031\u0038\u0029',
  13672. '\u2486': '\u0028\u0031\u0039\u0029',
  13673. '\u2487': '\u0028\u0032\u0030\u0029',
  13674. '\u2488': '\u0031\u002E',
  13675. '\u2489': '\u0032\u002E',
  13676. '\u248A': '\u0033\u002E',
  13677. '\u248B': '\u0034\u002E',
  13678. '\u248C': '\u0035\u002E',
  13679. '\u248D': '\u0036\u002E',
  13680. '\u248E': '\u0037\u002E',
  13681. '\u248F': '\u0038\u002E',
  13682. '\u2490': '\u0039\u002E',
  13683. '\u2491': '\u0031\u0030\u002E',
  13684. '\u2492': '\u0031\u0031\u002E',
  13685. '\u2493': '\u0031\u0032\u002E',
  13686. '\u2494': '\u0031\u0033\u002E',
  13687. '\u2495': '\u0031\u0034\u002E',
  13688. '\u2496': '\u0031\u0035\u002E',
  13689. '\u2497': '\u0031\u0036\u002E',
  13690. '\u2498': '\u0031\u0037\u002E',
  13691. '\u2499': '\u0031\u0038\u002E',
  13692. '\u249A': '\u0031\u0039\u002E',
  13693. '\u249B': '\u0032\u0030\u002E',
  13694. '\u249C': '\u0028\u0061\u0029',
  13695. '\u249D': '\u0028\u0062\u0029',
  13696. '\u249E': '\u0028\u0063\u0029',
  13697. '\u249F': '\u0028\u0064\u0029',
  13698. '\u24A0': '\u0028\u0065\u0029',
  13699. '\u24A1': '\u0028\u0066\u0029',
  13700. '\u24A2': '\u0028\u0067\u0029',
  13701. '\u24A3': '\u0028\u0068\u0029',
  13702. '\u24A4': '\u0028\u0069\u0029',
  13703. '\u24A5': '\u0028\u006A\u0029',
  13704. '\u24A6': '\u0028\u006B\u0029',
  13705. '\u24A7': '\u0028\u006C\u0029',
  13706. '\u24A8': '\u0028\u006D\u0029',
  13707. '\u24A9': '\u0028\u006E\u0029',
  13708. '\u24AA': '\u0028\u006F\u0029',
  13709. '\u24AB': '\u0028\u0070\u0029',
  13710. '\u24AC': '\u0028\u0071\u0029',
  13711. '\u24AD': '\u0028\u0072\u0029',
  13712. '\u24AE': '\u0028\u0073\u0029',
  13713. '\u24AF': '\u0028\u0074\u0029',
  13714. '\u24B0': '\u0028\u0075\u0029',
  13715. '\u24B1': '\u0028\u0076\u0029',
  13716. '\u24B2': '\u0028\u0077\u0029',
  13717. '\u24B3': '\u0028\u0078\u0029',
  13718. '\u24B4': '\u0028\u0079\u0029',
  13719. '\u24B5': '\u0028\u007A\u0029',
  13720. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13721. '\u2A74': '\u003A\u003A\u003D',
  13722. '\u2A75': '\u003D\u003D',
  13723. '\u2A76': '\u003D\u003D\u003D',
  13724. '\u2E9F': '\u6BCD',
  13725. '\u2EF3': '\u9F9F',
  13726. '\u2F00': '\u4E00',
  13727. '\u2F01': '\u4E28',
  13728. '\u2F02': '\u4E36',
  13729. '\u2F03': '\u4E3F',
  13730. '\u2F04': '\u4E59',
  13731. '\u2F05': '\u4E85',
  13732. '\u2F06': '\u4E8C',
  13733. '\u2F07': '\u4EA0',
  13734. '\u2F08': '\u4EBA',
  13735. '\u2F09': '\u513F',
  13736. '\u2F0A': '\u5165',
  13737. '\u2F0B': '\u516B',
  13738. '\u2F0C': '\u5182',
  13739. '\u2F0D': '\u5196',
  13740. '\u2F0E': '\u51AB',
  13741. '\u2F0F': '\u51E0',
  13742. '\u2F10': '\u51F5',
  13743. '\u2F11': '\u5200',
  13744. '\u2F12': '\u529B',
  13745. '\u2F13': '\u52F9',
  13746. '\u2F14': '\u5315',
  13747. '\u2F15': '\u531A',
  13748. '\u2F16': '\u5338',
  13749. '\u2F17': '\u5341',
  13750. '\u2F18': '\u535C',
  13751. '\u2F19': '\u5369',
  13752. '\u2F1A': '\u5382',
  13753. '\u2F1B': '\u53B6',
  13754. '\u2F1C': '\u53C8',
  13755. '\u2F1D': '\u53E3',
  13756. '\u2F1E': '\u56D7',
  13757. '\u2F1F': '\u571F',
  13758. '\u2F20': '\u58EB',
  13759. '\u2F21': '\u5902',
  13760. '\u2F22': '\u590A',
  13761. '\u2F23': '\u5915',
  13762. '\u2F24': '\u5927',
  13763. '\u2F25': '\u5973',
  13764. '\u2F26': '\u5B50',
  13765. '\u2F27': '\u5B80',
  13766. '\u2F28': '\u5BF8',
  13767. '\u2F29': '\u5C0F',
  13768. '\u2F2A': '\u5C22',
  13769. '\u2F2B': '\u5C38',
  13770. '\u2F2C': '\u5C6E',
  13771. '\u2F2D': '\u5C71',
  13772. '\u2F2E': '\u5DDB',
  13773. '\u2F2F': '\u5DE5',
  13774. '\u2F30': '\u5DF1',
  13775. '\u2F31': '\u5DFE',
  13776. '\u2F32': '\u5E72',
  13777. '\u2F33': '\u5E7A',
  13778. '\u2F34': '\u5E7F',
  13779. '\u2F35': '\u5EF4',
  13780. '\u2F36': '\u5EFE',
  13781. '\u2F37': '\u5F0B',
  13782. '\u2F38': '\u5F13',
  13783. '\u2F39': '\u5F50',
  13784. '\u2F3A': '\u5F61',
  13785. '\u2F3B': '\u5F73',
  13786. '\u2F3C': '\u5FC3',
  13787. '\u2F3D': '\u6208',
  13788. '\u2F3E': '\u6236',
  13789. '\u2F3F': '\u624B',
  13790. '\u2F40': '\u652F',
  13791. '\u2F41': '\u6534',
  13792. '\u2F42': '\u6587',
  13793. '\u2F43': '\u6597',
  13794. '\u2F44': '\u65A4',
  13795. '\u2F45': '\u65B9',
  13796. '\u2F46': '\u65E0',
  13797. '\u2F47': '\u65E5',
  13798. '\u2F48': '\u66F0',
  13799. '\u2F49': '\u6708',
  13800. '\u2F4A': '\u6728',
  13801. '\u2F4B': '\u6B20',
  13802. '\u2F4C': '\u6B62',
  13803. '\u2F4D': '\u6B79',
  13804. '\u2F4E': '\u6BB3',
  13805. '\u2F4F': '\u6BCB',
  13806. '\u2F50': '\u6BD4',
  13807. '\u2F51': '\u6BDB',
  13808. '\u2F52': '\u6C0F',
  13809. '\u2F53': '\u6C14',
  13810. '\u2F54': '\u6C34',
  13811. '\u2F55': '\u706B',
  13812. '\u2F56': '\u722A',
  13813. '\u2F57': '\u7236',
  13814. '\u2F58': '\u723B',
  13815. '\u2F59': '\u723F',
  13816. '\u2F5A': '\u7247',
  13817. '\u2F5B': '\u7259',
  13818. '\u2F5C': '\u725B',
  13819. '\u2F5D': '\u72AC',
  13820. '\u2F5E': '\u7384',
  13821. '\u2F5F': '\u7389',
  13822. '\u2F60': '\u74DC',
  13823. '\u2F61': '\u74E6',
  13824. '\u2F62': '\u7518',
  13825. '\u2F63': '\u751F',
  13826. '\u2F64': '\u7528',
  13827. '\u2F65': '\u7530',
  13828. '\u2F66': '\u758B',
  13829. '\u2F67': '\u7592',
  13830. '\u2F68': '\u7676',
  13831. '\u2F69': '\u767D',
  13832. '\u2F6A': '\u76AE',
  13833. '\u2F6B': '\u76BF',
  13834. '\u2F6C': '\u76EE',
  13835. '\u2F6D': '\u77DB',
  13836. '\u2F6E': '\u77E2',
  13837. '\u2F6F': '\u77F3',
  13838. '\u2F70': '\u793A',
  13839. '\u2F71': '\u79B8',
  13840. '\u2F72': '\u79BE',
  13841. '\u2F73': '\u7A74',
  13842. '\u2F74': '\u7ACB',
  13843. '\u2F75': '\u7AF9',
  13844. '\u2F76': '\u7C73',
  13845. '\u2F77': '\u7CF8',
  13846. '\u2F78': '\u7F36',
  13847. '\u2F79': '\u7F51',
  13848. '\u2F7A': '\u7F8A',
  13849. '\u2F7B': '\u7FBD',
  13850. '\u2F7C': '\u8001',
  13851. '\u2F7D': '\u800C',
  13852. '\u2F7E': '\u8012',
  13853. '\u2F7F': '\u8033',
  13854. '\u2F80': '\u807F',
  13855. '\u2F81': '\u8089',
  13856. '\u2F82': '\u81E3',
  13857. '\u2F83': '\u81EA',
  13858. '\u2F84': '\u81F3',
  13859. '\u2F85': '\u81FC',
  13860. '\u2F86': '\u820C',
  13861. '\u2F87': '\u821B',
  13862. '\u2F88': '\u821F',
  13863. '\u2F89': '\u826E',
  13864. '\u2F8A': '\u8272',
  13865. '\u2F8B': '\u8278',
  13866. '\u2F8C': '\u864D',
  13867. '\u2F8D': '\u866B',
  13868. '\u2F8E': '\u8840',
  13869. '\u2F8F': '\u884C',
  13870. '\u2F90': '\u8863',
  13871. '\u2F91': '\u897E',
  13872. '\u2F92': '\u898B',
  13873. '\u2F93': '\u89D2',
  13874. '\u2F94': '\u8A00',
  13875. '\u2F95': '\u8C37',
  13876. '\u2F96': '\u8C46',
  13877. '\u2F97': '\u8C55',
  13878. '\u2F98': '\u8C78',
  13879. '\u2F99': '\u8C9D',
  13880. '\u2F9A': '\u8D64',
  13881. '\u2F9B': '\u8D70',
  13882. '\u2F9C': '\u8DB3',
  13883. '\u2F9D': '\u8EAB',
  13884. '\u2F9E': '\u8ECA',
  13885. '\u2F9F': '\u8F9B',
  13886. '\u2FA0': '\u8FB0',
  13887. '\u2FA1': '\u8FB5',
  13888. '\u2FA2': '\u9091',
  13889. '\u2FA3': '\u9149',
  13890. '\u2FA4': '\u91C6',
  13891. '\u2FA5': '\u91CC',
  13892. '\u2FA6': '\u91D1',
  13893. '\u2FA7': '\u9577',
  13894. '\u2FA8': '\u9580',
  13895. '\u2FA9': '\u961C',
  13896. '\u2FAA': '\u96B6',
  13897. '\u2FAB': '\u96B9',
  13898. '\u2FAC': '\u96E8',
  13899. '\u2FAD': '\u9751',
  13900. '\u2FAE': '\u975E',
  13901. '\u2FAF': '\u9762',
  13902. '\u2FB0': '\u9769',
  13903. '\u2FB1': '\u97CB',
  13904. '\u2FB2': '\u97ED',
  13905. '\u2FB3': '\u97F3',
  13906. '\u2FB4': '\u9801',
  13907. '\u2FB5': '\u98A8',
  13908. '\u2FB6': '\u98DB',
  13909. '\u2FB7': '\u98DF',
  13910. '\u2FB8': '\u9996',
  13911. '\u2FB9': '\u9999',
  13912. '\u2FBA': '\u99AC',
  13913. '\u2FBB': '\u9AA8',
  13914. '\u2FBC': '\u9AD8',
  13915. '\u2FBD': '\u9ADF',
  13916. '\u2FBE': '\u9B25',
  13917. '\u2FBF': '\u9B2F',
  13918. '\u2FC0': '\u9B32',
  13919. '\u2FC1': '\u9B3C',
  13920. '\u2FC2': '\u9B5A',
  13921. '\u2FC3': '\u9CE5',
  13922. '\u2FC4': '\u9E75',
  13923. '\u2FC5': '\u9E7F',
  13924. '\u2FC6': '\u9EA5',
  13925. '\u2FC7': '\u9EBB',
  13926. '\u2FC8': '\u9EC3',
  13927. '\u2FC9': '\u9ECD',
  13928. '\u2FCA': '\u9ED1',
  13929. '\u2FCB': '\u9EF9',
  13930. '\u2FCC': '\u9EFD',
  13931. '\u2FCD': '\u9F0E',
  13932. '\u2FCE': '\u9F13',
  13933. '\u2FCF': '\u9F20',
  13934. '\u2FD0': '\u9F3B',
  13935. '\u2FD1': '\u9F4A',
  13936. '\u2FD2': '\u9F52',
  13937. '\u2FD3': '\u9F8D',
  13938. '\u2FD4': '\u9F9C',
  13939. '\u2FD5': '\u9FA0',
  13940. '\u3036': '\u3012',
  13941. '\u3038': '\u5341',
  13942. '\u3039': '\u5344',
  13943. '\u303A': '\u5345',
  13944. '\u309B': '\u0020\u3099',
  13945. '\u309C': '\u0020\u309A',
  13946. '\u3131': '\u1100',
  13947. '\u3132': '\u1101',
  13948. '\u3133': '\u11AA',
  13949. '\u3134': '\u1102',
  13950. '\u3135': '\u11AC',
  13951. '\u3136': '\u11AD',
  13952. '\u3137': '\u1103',
  13953. '\u3138': '\u1104',
  13954. '\u3139': '\u1105',
  13955. '\u313A': '\u11B0',
  13956. '\u313B': '\u11B1',
  13957. '\u313C': '\u11B2',
  13958. '\u313D': '\u11B3',
  13959. '\u313E': '\u11B4',
  13960. '\u313F': '\u11B5',
  13961. '\u3140': '\u111A',
  13962. '\u3141': '\u1106',
  13963. '\u3142': '\u1107',
  13964. '\u3143': '\u1108',
  13965. '\u3144': '\u1121',
  13966. '\u3145': '\u1109',
  13967. '\u3146': '\u110A',
  13968. '\u3147': '\u110B',
  13969. '\u3148': '\u110C',
  13970. '\u3149': '\u110D',
  13971. '\u314A': '\u110E',
  13972. '\u314B': '\u110F',
  13973. '\u314C': '\u1110',
  13974. '\u314D': '\u1111',
  13975. '\u314E': '\u1112',
  13976. '\u314F': '\u1161',
  13977. '\u3150': '\u1162',
  13978. '\u3151': '\u1163',
  13979. '\u3152': '\u1164',
  13980. '\u3153': '\u1165',
  13981. '\u3154': '\u1166',
  13982. '\u3155': '\u1167',
  13983. '\u3156': '\u1168',
  13984. '\u3157': '\u1169',
  13985. '\u3158': '\u116A',
  13986. '\u3159': '\u116B',
  13987. '\u315A': '\u116C',
  13988. '\u315B': '\u116D',
  13989. '\u315C': '\u116E',
  13990. '\u315D': '\u116F',
  13991. '\u315E': '\u1170',
  13992. '\u315F': '\u1171',
  13993. '\u3160': '\u1172',
  13994. '\u3161': '\u1173',
  13995. '\u3162': '\u1174',
  13996. '\u3163': '\u1175',
  13997. '\u3164': '\u1160',
  13998. '\u3165': '\u1114',
  13999. '\u3166': '\u1115',
  14000. '\u3167': '\u11C7',
  14001. '\u3168': '\u11C8',
  14002. '\u3169': '\u11CC',
  14003. '\u316A': '\u11CE',
  14004. '\u316B': '\u11D3',
  14005. '\u316C': '\u11D7',
  14006. '\u316D': '\u11D9',
  14007. '\u316E': '\u111C',
  14008. '\u316F': '\u11DD',
  14009. '\u3170': '\u11DF',
  14010. '\u3171': '\u111D',
  14011. '\u3172': '\u111E',
  14012. '\u3173': '\u1120',
  14013. '\u3174': '\u1122',
  14014. '\u3175': '\u1123',
  14015. '\u3176': '\u1127',
  14016. '\u3177': '\u1129',
  14017. '\u3178': '\u112B',
  14018. '\u3179': '\u112C',
  14019. '\u317A': '\u112D',
  14020. '\u317B': '\u112E',
  14021. '\u317C': '\u112F',
  14022. '\u317D': '\u1132',
  14023. '\u317E': '\u1136',
  14024. '\u317F': '\u1140',
  14025. '\u3180': '\u1147',
  14026. '\u3181': '\u114C',
  14027. '\u3182': '\u11F1',
  14028. '\u3183': '\u11F2',
  14029. '\u3184': '\u1157',
  14030. '\u3185': '\u1158',
  14031. '\u3186': '\u1159',
  14032. '\u3187': '\u1184',
  14033. '\u3188': '\u1185',
  14034. '\u3189': '\u1188',
  14035. '\u318A': '\u1191',
  14036. '\u318B': '\u1192',
  14037. '\u318C': '\u1194',
  14038. '\u318D': '\u119E',
  14039. '\u318E': '\u11A1',
  14040. '\u3200': '\u0028\u1100\u0029',
  14041. '\u3201': '\u0028\u1102\u0029',
  14042. '\u3202': '\u0028\u1103\u0029',
  14043. '\u3203': '\u0028\u1105\u0029',
  14044. '\u3204': '\u0028\u1106\u0029',
  14045. '\u3205': '\u0028\u1107\u0029',
  14046. '\u3206': '\u0028\u1109\u0029',
  14047. '\u3207': '\u0028\u110B\u0029',
  14048. '\u3208': '\u0028\u110C\u0029',
  14049. '\u3209': '\u0028\u110E\u0029',
  14050. '\u320A': '\u0028\u110F\u0029',
  14051. '\u320B': '\u0028\u1110\u0029',
  14052. '\u320C': '\u0028\u1111\u0029',
  14053. '\u320D': '\u0028\u1112\u0029',
  14054. '\u320E': '\u0028\u1100\u1161\u0029',
  14055. '\u320F': '\u0028\u1102\u1161\u0029',
  14056. '\u3210': '\u0028\u1103\u1161\u0029',
  14057. '\u3211': '\u0028\u1105\u1161\u0029',
  14058. '\u3212': '\u0028\u1106\u1161\u0029',
  14059. '\u3213': '\u0028\u1107\u1161\u0029',
  14060. '\u3214': '\u0028\u1109\u1161\u0029',
  14061. '\u3215': '\u0028\u110B\u1161\u0029',
  14062. '\u3216': '\u0028\u110C\u1161\u0029',
  14063. '\u3217': '\u0028\u110E\u1161\u0029',
  14064. '\u3218': '\u0028\u110F\u1161\u0029',
  14065. '\u3219': '\u0028\u1110\u1161\u0029',
  14066. '\u321A': '\u0028\u1111\u1161\u0029',
  14067. '\u321B': '\u0028\u1112\u1161\u0029',
  14068. '\u321C': '\u0028\u110C\u116E\u0029',
  14069. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14070. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14071. '\u3220': '\u0028\u4E00\u0029',
  14072. '\u3221': '\u0028\u4E8C\u0029',
  14073. '\u3222': '\u0028\u4E09\u0029',
  14074. '\u3223': '\u0028\u56DB\u0029',
  14075. '\u3224': '\u0028\u4E94\u0029',
  14076. '\u3225': '\u0028\u516D\u0029',
  14077. '\u3226': '\u0028\u4E03\u0029',
  14078. '\u3227': '\u0028\u516B\u0029',
  14079. '\u3228': '\u0028\u4E5D\u0029',
  14080. '\u3229': '\u0028\u5341\u0029',
  14081. '\u322A': '\u0028\u6708\u0029',
  14082. '\u322B': '\u0028\u706B\u0029',
  14083. '\u322C': '\u0028\u6C34\u0029',
  14084. '\u322D': '\u0028\u6728\u0029',
  14085. '\u322E': '\u0028\u91D1\u0029',
  14086. '\u322F': '\u0028\u571F\u0029',
  14087. '\u3230': '\u0028\u65E5\u0029',
  14088. '\u3231': '\u0028\u682A\u0029',
  14089. '\u3232': '\u0028\u6709\u0029',
  14090. '\u3233': '\u0028\u793E\u0029',
  14091. '\u3234': '\u0028\u540D\u0029',
  14092. '\u3235': '\u0028\u7279\u0029',
  14093. '\u3236': '\u0028\u8CA1\u0029',
  14094. '\u3237': '\u0028\u795D\u0029',
  14095. '\u3238': '\u0028\u52B4\u0029',
  14096. '\u3239': '\u0028\u4EE3\u0029',
  14097. '\u323A': '\u0028\u547C\u0029',
  14098. '\u323B': '\u0028\u5B66\u0029',
  14099. '\u323C': '\u0028\u76E3\u0029',
  14100. '\u323D': '\u0028\u4F01\u0029',
  14101. '\u323E': '\u0028\u8CC7\u0029',
  14102. '\u323F': '\u0028\u5354\u0029',
  14103. '\u3240': '\u0028\u796D\u0029',
  14104. '\u3241': '\u0028\u4F11\u0029',
  14105. '\u3242': '\u0028\u81EA\u0029',
  14106. '\u3243': '\u0028\u81F3\u0029',
  14107. '\u32C0': '\u0031\u6708',
  14108. '\u32C1': '\u0032\u6708',
  14109. '\u32C2': '\u0033\u6708',
  14110. '\u32C3': '\u0034\u6708',
  14111. '\u32C4': '\u0035\u6708',
  14112. '\u32C5': '\u0036\u6708',
  14113. '\u32C6': '\u0037\u6708',
  14114. '\u32C7': '\u0038\u6708',
  14115. '\u32C8': '\u0039\u6708',
  14116. '\u32C9': '\u0031\u0030\u6708',
  14117. '\u32CA': '\u0031\u0031\u6708',
  14118. '\u32CB': '\u0031\u0032\u6708',
  14119. '\u3358': '\u0030\u70B9',
  14120. '\u3359': '\u0031\u70B9',
  14121. '\u335A': '\u0032\u70B9',
  14122. '\u335B': '\u0033\u70B9',
  14123. '\u335C': '\u0034\u70B9',
  14124. '\u335D': '\u0035\u70B9',
  14125. '\u335E': '\u0036\u70B9',
  14126. '\u335F': '\u0037\u70B9',
  14127. '\u3360': '\u0038\u70B9',
  14128. '\u3361': '\u0039\u70B9',
  14129. '\u3362': '\u0031\u0030\u70B9',
  14130. '\u3363': '\u0031\u0031\u70B9',
  14131. '\u3364': '\u0031\u0032\u70B9',
  14132. '\u3365': '\u0031\u0033\u70B9',
  14133. '\u3366': '\u0031\u0034\u70B9',
  14134. '\u3367': '\u0031\u0035\u70B9',
  14135. '\u3368': '\u0031\u0036\u70B9',
  14136. '\u3369': '\u0031\u0037\u70B9',
  14137. '\u336A': '\u0031\u0038\u70B9',
  14138. '\u336B': '\u0031\u0039\u70B9',
  14139. '\u336C': '\u0032\u0030\u70B9',
  14140. '\u336D': '\u0032\u0031\u70B9',
  14141. '\u336E': '\u0032\u0032\u70B9',
  14142. '\u336F': '\u0032\u0033\u70B9',
  14143. '\u3370': '\u0032\u0034\u70B9',
  14144. '\u33E0': '\u0031\u65E5',
  14145. '\u33E1': '\u0032\u65E5',
  14146. '\u33E2': '\u0033\u65E5',
  14147. '\u33E3': '\u0034\u65E5',
  14148. '\u33E4': '\u0035\u65E5',
  14149. '\u33E5': '\u0036\u65E5',
  14150. '\u33E6': '\u0037\u65E5',
  14151. '\u33E7': '\u0038\u65E5',
  14152. '\u33E8': '\u0039\u65E5',
  14153. '\u33E9': '\u0031\u0030\u65E5',
  14154. '\u33EA': '\u0031\u0031\u65E5',
  14155. '\u33EB': '\u0031\u0032\u65E5',
  14156. '\u33EC': '\u0031\u0033\u65E5',
  14157. '\u33ED': '\u0031\u0034\u65E5',
  14158. '\u33EE': '\u0031\u0035\u65E5',
  14159. '\u33EF': '\u0031\u0036\u65E5',
  14160. '\u33F0': '\u0031\u0037\u65E5',
  14161. '\u33F1': '\u0031\u0038\u65E5',
  14162. '\u33F2': '\u0031\u0039\u65E5',
  14163. '\u33F3': '\u0032\u0030\u65E5',
  14164. '\u33F4': '\u0032\u0031\u65E5',
  14165. '\u33F5': '\u0032\u0032\u65E5',
  14166. '\u33F6': '\u0032\u0033\u65E5',
  14167. '\u33F7': '\u0032\u0034\u65E5',
  14168. '\u33F8': '\u0032\u0035\u65E5',
  14169. '\u33F9': '\u0032\u0036\u65E5',
  14170. '\u33FA': '\u0032\u0037\u65E5',
  14171. '\u33FB': '\u0032\u0038\u65E5',
  14172. '\u33FC': '\u0032\u0039\u65E5',
  14173. '\u33FD': '\u0033\u0030\u65E5',
  14174. '\u33FE': '\u0033\u0031\u65E5',
  14175. '\uFB00': '\u0066\u0066',
  14176. '\uFB01': '\u0066\u0069',
  14177. '\uFB02': '\u0066\u006C',
  14178. '\uFB03': '\u0066\u0066\u0069',
  14179. '\uFB04': '\u0066\u0066\u006C',
  14180. '\uFB05': '\u017F\u0074',
  14181. '\uFB06': '\u0073\u0074',
  14182. '\uFB13': '\u0574\u0576',
  14183. '\uFB14': '\u0574\u0565',
  14184. '\uFB15': '\u0574\u056B',
  14185. '\uFB16': '\u057E\u0576',
  14186. '\uFB17': '\u0574\u056D',
  14187. '\uFB4F': '\u05D0\u05DC',
  14188. '\uFB50': '\u0671',
  14189. '\uFB51': '\u0671',
  14190. '\uFB52': '\u067B',
  14191. '\uFB53': '\u067B',
  14192. '\uFB54': '\u067B',
  14193. '\uFB55': '\u067B',
  14194. '\uFB56': '\u067E',
  14195. '\uFB57': '\u067E',
  14196. '\uFB58': '\u067E',
  14197. '\uFB59': '\u067E',
  14198. '\uFB5A': '\u0680',
  14199. '\uFB5B': '\u0680',
  14200. '\uFB5C': '\u0680',
  14201. '\uFB5D': '\u0680',
  14202. '\uFB5E': '\u067A',
  14203. '\uFB5F': '\u067A',
  14204. '\uFB60': '\u067A',
  14205. '\uFB61': '\u067A',
  14206. '\uFB62': '\u067F',
  14207. '\uFB63': '\u067F',
  14208. '\uFB64': '\u067F',
  14209. '\uFB65': '\u067F',
  14210. '\uFB66': '\u0679',
  14211. '\uFB67': '\u0679',
  14212. '\uFB68': '\u0679',
  14213. '\uFB69': '\u0679',
  14214. '\uFB6A': '\u06A4',
  14215. '\uFB6B': '\u06A4',
  14216. '\uFB6C': '\u06A4',
  14217. '\uFB6D': '\u06A4',
  14218. '\uFB6E': '\u06A6',
  14219. '\uFB6F': '\u06A6',
  14220. '\uFB70': '\u06A6',
  14221. '\uFB71': '\u06A6',
  14222. '\uFB72': '\u0684',
  14223. '\uFB73': '\u0684',
  14224. '\uFB74': '\u0684',
  14225. '\uFB75': '\u0684',
  14226. '\uFB76': '\u0683',
  14227. '\uFB77': '\u0683',
  14228. '\uFB78': '\u0683',
  14229. '\uFB79': '\u0683',
  14230. '\uFB7A': '\u0686',
  14231. '\uFB7B': '\u0686',
  14232. '\uFB7C': '\u0686',
  14233. '\uFB7D': '\u0686',
  14234. '\uFB7E': '\u0687',
  14235. '\uFB7F': '\u0687',
  14236. '\uFB80': '\u0687',
  14237. '\uFB81': '\u0687',
  14238. '\uFB82': '\u068D',
  14239. '\uFB83': '\u068D',
  14240. '\uFB84': '\u068C',
  14241. '\uFB85': '\u068C',
  14242. '\uFB86': '\u068E',
  14243. '\uFB87': '\u068E',
  14244. '\uFB88': '\u0688',
  14245. '\uFB89': '\u0688',
  14246. '\uFB8A': '\u0698',
  14247. '\uFB8B': '\u0698',
  14248. '\uFB8C': '\u0691',
  14249. '\uFB8D': '\u0691',
  14250. '\uFB8E': '\u06A9',
  14251. '\uFB8F': '\u06A9',
  14252. '\uFB90': '\u06A9',
  14253. '\uFB91': '\u06A9',
  14254. '\uFB92': '\u06AF',
  14255. '\uFB93': '\u06AF',
  14256. '\uFB94': '\u06AF',
  14257. '\uFB95': '\u06AF',
  14258. '\uFB96': '\u06B3',
  14259. '\uFB97': '\u06B3',
  14260. '\uFB98': '\u06B3',
  14261. '\uFB99': '\u06B3',
  14262. '\uFB9A': '\u06B1',
  14263. '\uFB9B': '\u06B1',
  14264. '\uFB9C': '\u06B1',
  14265. '\uFB9D': '\u06B1',
  14266. '\uFB9E': '\u06BA',
  14267. '\uFB9F': '\u06BA',
  14268. '\uFBA0': '\u06BB',
  14269. '\uFBA1': '\u06BB',
  14270. '\uFBA2': '\u06BB',
  14271. '\uFBA3': '\u06BB',
  14272. '\uFBA4': '\u06C0',
  14273. '\uFBA5': '\u06C0',
  14274. '\uFBA6': '\u06C1',
  14275. '\uFBA7': '\u06C1',
  14276. '\uFBA8': '\u06C1',
  14277. '\uFBA9': '\u06C1',
  14278. '\uFBAA': '\u06BE',
  14279. '\uFBAB': '\u06BE',
  14280. '\uFBAC': '\u06BE',
  14281. '\uFBAD': '\u06BE',
  14282. '\uFBAE': '\u06D2',
  14283. '\uFBAF': '\u06D2',
  14284. '\uFBB0': '\u06D3',
  14285. '\uFBB1': '\u06D3',
  14286. '\uFBD3': '\u06AD',
  14287. '\uFBD4': '\u06AD',
  14288. '\uFBD5': '\u06AD',
  14289. '\uFBD6': '\u06AD',
  14290. '\uFBD7': '\u06C7',
  14291. '\uFBD8': '\u06C7',
  14292. '\uFBD9': '\u06C6',
  14293. '\uFBDA': '\u06C6',
  14294. '\uFBDB': '\u06C8',
  14295. '\uFBDC': '\u06C8',
  14296. '\uFBDD': '\u0677',
  14297. '\uFBDE': '\u06CB',
  14298. '\uFBDF': '\u06CB',
  14299. '\uFBE0': '\u06C5',
  14300. '\uFBE1': '\u06C5',
  14301. '\uFBE2': '\u06C9',
  14302. '\uFBE3': '\u06C9',
  14303. '\uFBE4': '\u06D0',
  14304. '\uFBE5': '\u06D0',
  14305. '\uFBE6': '\u06D0',
  14306. '\uFBE7': '\u06D0',
  14307. '\uFBE8': '\u0649',
  14308. '\uFBE9': '\u0649',
  14309. '\uFBEA': '\u0626\u0627',
  14310. '\uFBEB': '\u0626\u0627',
  14311. '\uFBEC': '\u0626\u06D5',
  14312. '\uFBED': '\u0626\u06D5',
  14313. '\uFBEE': '\u0626\u0648',
  14314. '\uFBEF': '\u0626\u0648',
  14315. '\uFBF0': '\u0626\u06C7',
  14316. '\uFBF1': '\u0626\u06C7',
  14317. '\uFBF2': '\u0626\u06C6',
  14318. '\uFBF3': '\u0626\u06C6',
  14319. '\uFBF4': '\u0626\u06C8',
  14320. '\uFBF5': '\u0626\u06C8',
  14321. '\uFBF6': '\u0626\u06D0',
  14322. '\uFBF7': '\u0626\u06D0',
  14323. '\uFBF8': '\u0626\u06D0',
  14324. '\uFBF9': '\u0626\u0649',
  14325. '\uFBFA': '\u0626\u0649',
  14326. '\uFBFB': '\u0626\u0649',
  14327. '\uFBFC': '\u06CC',
  14328. '\uFBFD': '\u06CC',
  14329. '\uFBFE': '\u06CC',
  14330. '\uFBFF': '\u06CC',
  14331. '\uFC00': '\u0626\u062C',
  14332. '\uFC01': '\u0626\u062D',
  14333. '\uFC02': '\u0626\u0645',
  14334. '\uFC03': '\u0626\u0649',
  14335. '\uFC04': '\u0626\u064A',
  14336. '\uFC05': '\u0628\u062C',
  14337. '\uFC06': '\u0628\u062D',
  14338. '\uFC07': '\u0628\u062E',
  14339. '\uFC08': '\u0628\u0645',
  14340. '\uFC09': '\u0628\u0649',
  14341. '\uFC0A': '\u0628\u064A',
  14342. '\uFC0B': '\u062A\u062C',
  14343. '\uFC0C': '\u062A\u062D',
  14344. '\uFC0D': '\u062A\u062E',
  14345. '\uFC0E': '\u062A\u0645',
  14346. '\uFC0F': '\u062A\u0649',
  14347. '\uFC10': '\u062A\u064A',
  14348. '\uFC11': '\u062B\u062C',
  14349. '\uFC12': '\u062B\u0645',
  14350. '\uFC13': '\u062B\u0649',
  14351. '\uFC14': '\u062B\u064A',
  14352. '\uFC15': '\u062C\u062D',
  14353. '\uFC16': '\u062C\u0645',
  14354. '\uFC17': '\u062D\u062C',
  14355. '\uFC18': '\u062D\u0645',
  14356. '\uFC19': '\u062E\u062C',
  14357. '\uFC1A': '\u062E\u062D',
  14358. '\uFC1B': '\u062E\u0645',
  14359. '\uFC1C': '\u0633\u062C',
  14360. '\uFC1D': '\u0633\u062D',
  14361. '\uFC1E': '\u0633\u062E',
  14362. '\uFC1F': '\u0633\u0645',
  14363. '\uFC20': '\u0635\u062D',
  14364. '\uFC21': '\u0635\u0645',
  14365. '\uFC22': '\u0636\u062C',
  14366. '\uFC23': '\u0636\u062D',
  14367. '\uFC24': '\u0636\u062E',
  14368. '\uFC25': '\u0636\u0645',
  14369. '\uFC26': '\u0637\u062D',
  14370. '\uFC27': '\u0637\u0645',
  14371. '\uFC28': '\u0638\u0645',
  14372. '\uFC29': '\u0639\u062C',
  14373. '\uFC2A': '\u0639\u0645',
  14374. '\uFC2B': '\u063A\u062C',
  14375. '\uFC2C': '\u063A\u0645',
  14376. '\uFC2D': '\u0641\u062C',
  14377. '\uFC2E': '\u0641\u062D',
  14378. '\uFC2F': '\u0641\u062E',
  14379. '\uFC30': '\u0641\u0645',
  14380. '\uFC31': '\u0641\u0649',
  14381. '\uFC32': '\u0641\u064A',
  14382. '\uFC33': '\u0642\u062D',
  14383. '\uFC34': '\u0642\u0645',
  14384. '\uFC35': '\u0642\u0649',
  14385. '\uFC36': '\u0642\u064A',
  14386. '\uFC37': '\u0643\u0627',
  14387. '\uFC38': '\u0643\u062C',
  14388. '\uFC39': '\u0643\u062D',
  14389. '\uFC3A': '\u0643\u062E',
  14390. '\uFC3B': '\u0643\u0644',
  14391. '\uFC3C': '\u0643\u0645',
  14392. '\uFC3D': '\u0643\u0649',
  14393. '\uFC3E': '\u0643\u064A',
  14394. '\uFC3F': '\u0644\u062C',
  14395. '\uFC40': '\u0644\u062D',
  14396. '\uFC41': '\u0644\u062E',
  14397. '\uFC42': '\u0644\u0645',
  14398. '\uFC43': '\u0644\u0649',
  14399. '\uFC44': '\u0644\u064A',
  14400. '\uFC45': '\u0645\u062C',
  14401. '\uFC46': '\u0645\u062D',
  14402. '\uFC47': '\u0645\u062E',
  14403. '\uFC48': '\u0645\u0645',
  14404. '\uFC49': '\u0645\u0649',
  14405. '\uFC4A': '\u0645\u064A',
  14406. '\uFC4B': '\u0646\u062C',
  14407. '\uFC4C': '\u0646\u062D',
  14408. '\uFC4D': '\u0646\u062E',
  14409. '\uFC4E': '\u0646\u0645',
  14410. '\uFC4F': '\u0646\u0649',
  14411. '\uFC50': '\u0646\u064A',
  14412. '\uFC51': '\u0647\u062C',
  14413. '\uFC52': '\u0647\u0645',
  14414. '\uFC53': '\u0647\u0649',
  14415. '\uFC54': '\u0647\u064A',
  14416. '\uFC55': '\u064A\u062C',
  14417. '\uFC56': '\u064A\u062D',
  14418. '\uFC57': '\u064A\u062E',
  14419. '\uFC58': '\u064A\u0645',
  14420. '\uFC59': '\u064A\u0649',
  14421. '\uFC5A': '\u064A\u064A',
  14422. '\uFC5B': '\u0630\u0670',
  14423. '\uFC5C': '\u0631\u0670',
  14424. '\uFC5D': '\u0649\u0670',
  14425. '\uFC5E': '\u0020\u064C\u0651',
  14426. '\uFC5F': '\u0020\u064D\u0651',
  14427. '\uFC60': '\u0020\u064E\u0651',
  14428. '\uFC61': '\u0020\u064F\u0651',
  14429. '\uFC62': '\u0020\u0650\u0651',
  14430. '\uFC63': '\u0020\u0651\u0670',
  14431. '\uFC64': '\u0626\u0631',
  14432. '\uFC65': '\u0626\u0632',
  14433. '\uFC66': '\u0626\u0645',
  14434. '\uFC67': '\u0626\u0646',
  14435. '\uFC68': '\u0626\u0649',
  14436. '\uFC69': '\u0626\u064A',
  14437. '\uFC6A': '\u0628\u0631',
  14438. '\uFC6B': '\u0628\u0632',
  14439. '\uFC6C': '\u0628\u0645',
  14440. '\uFC6D': '\u0628\u0646',
  14441. '\uFC6E': '\u0628\u0649',
  14442. '\uFC6F': '\u0628\u064A',
  14443. '\uFC70': '\u062A\u0631',
  14444. '\uFC71': '\u062A\u0632',
  14445. '\uFC72': '\u062A\u0645',
  14446. '\uFC73': '\u062A\u0646',
  14447. '\uFC74': '\u062A\u0649',
  14448. '\uFC75': '\u062A\u064A',
  14449. '\uFC76': '\u062B\u0631',
  14450. '\uFC77': '\u062B\u0632',
  14451. '\uFC78': '\u062B\u0645',
  14452. '\uFC79': '\u062B\u0646',
  14453. '\uFC7A': '\u062B\u0649',
  14454. '\uFC7B': '\u062B\u064A',
  14455. '\uFC7C': '\u0641\u0649',
  14456. '\uFC7D': '\u0641\u064A',
  14457. '\uFC7E': '\u0642\u0649',
  14458. '\uFC7F': '\u0642\u064A',
  14459. '\uFC80': '\u0643\u0627',
  14460. '\uFC81': '\u0643\u0644',
  14461. '\uFC82': '\u0643\u0645',
  14462. '\uFC83': '\u0643\u0649',
  14463. '\uFC84': '\u0643\u064A',
  14464. '\uFC85': '\u0644\u0645',
  14465. '\uFC86': '\u0644\u0649',
  14466. '\uFC87': '\u0644\u064A',
  14467. '\uFC88': '\u0645\u0627',
  14468. '\uFC89': '\u0645\u0645',
  14469. '\uFC8A': '\u0646\u0631',
  14470. '\uFC8B': '\u0646\u0632',
  14471. '\uFC8C': '\u0646\u0645',
  14472. '\uFC8D': '\u0646\u0646',
  14473. '\uFC8E': '\u0646\u0649',
  14474. '\uFC8F': '\u0646\u064A',
  14475. '\uFC90': '\u0649\u0670',
  14476. '\uFC91': '\u064A\u0631',
  14477. '\uFC92': '\u064A\u0632',
  14478. '\uFC93': '\u064A\u0645',
  14479. '\uFC94': '\u064A\u0646',
  14480. '\uFC95': '\u064A\u0649',
  14481. '\uFC96': '\u064A\u064A',
  14482. '\uFC97': '\u0626\u062C',
  14483. '\uFC98': '\u0626\u062D',
  14484. '\uFC99': '\u0626\u062E',
  14485. '\uFC9A': '\u0626\u0645',
  14486. '\uFC9B': '\u0626\u0647',
  14487. '\uFC9C': '\u0628\u062C',
  14488. '\uFC9D': '\u0628\u062D',
  14489. '\uFC9E': '\u0628\u062E',
  14490. '\uFC9F': '\u0628\u0645',
  14491. '\uFCA0': '\u0628\u0647',
  14492. '\uFCA1': '\u062A\u062C',
  14493. '\uFCA2': '\u062A\u062D',
  14494. '\uFCA3': '\u062A\u062E',
  14495. '\uFCA4': '\u062A\u0645',
  14496. '\uFCA5': '\u062A\u0647',
  14497. '\uFCA6': '\u062B\u0645',
  14498. '\uFCA7': '\u062C\u062D',
  14499. '\uFCA8': '\u062C\u0645',
  14500. '\uFCA9': '\u062D\u062C',
  14501. '\uFCAA': '\u062D\u0645',
  14502. '\uFCAB': '\u062E\u062C',
  14503. '\uFCAC': '\u062E\u0645',
  14504. '\uFCAD': '\u0633\u062C',
  14505. '\uFCAE': '\u0633\u062D',
  14506. '\uFCAF': '\u0633\u062E',
  14507. '\uFCB0': '\u0633\u0645',
  14508. '\uFCB1': '\u0635\u062D',
  14509. '\uFCB2': '\u0635\u062E',
  14510. '\uFCB3': '\u0635\u0645',
  14511. '\uFCB4': '\u0636\u062C',
  14512. '\uFCB5': '\u0636\u062D',
  14513. '\uFCB6': '\u0636\u062E',
  14514. '\uFCB7': '\u0636\u0645',
  14515. '\uFCB8': '\u0637\u062D',
  14516. '\uFCB9': '\u0638\u0645',
  14517. '\uFCBA': '\u0639\u062C',
  14518. '\uFCBB': '\u0639\u0645',
  14519. '\uFCBC': '\u063A\u062C',
  14520. '\uFCBD': '\u063A\u0645',
  14521. '\uFCBE': '\u0641\u062C',
  14522. '\uFCBF': '\u0641\u062D',
  14523. '\uFCC0': '\u0641\u062E',
  14524. '\uFCC1': '\u0641\u0645',
  14525. '\uFCC2': '\u0642\u062D',
  14526. '\uFCC3': '\u0642\u0645',
  14527. '\uFCC4': '\u0643\u062C',
  14528. '\uFCC5': '\u0643\u062D',
  14529. '\uFCC6': '\u0643\u062E',
  14530. '\uFCC7': '\u0643\u0644',
  14531. '\uFCC8': '\u0643\u0645',
  14532. '\uFCC9': '\u0644\u062C',
  14533. '\uFCCA': '\u0644\u062D',
  14534. '\uFCCB': '\u0644\u062E',
  14535. '\uFCCC': '\u0644\u0645',
  14536. '\uFCCD': '\u0644\u0647',
  14537. '\uFCCE': '\u0645\u062C',
  14538. '\uFCCF': '\u0645\u062D',
  14539. '\uFCD0': '\u0645\u062E',
  14540. '\uFCD1': '\u0645\u0645',
  14541. '\uFCD2': '\u0646\u062C',
  14542. '\uFCD3': '\u0646\u062D',
  14543. '\uFCD4': '\u0646\u062E',
  14544. '\uFCD5': '\u0646\u0645',
  14545. '\uFCD6': '\u0646\u0647',
  14546. '\uFCD7': '\u0647\u062C',
  14547. '\uFCD8': '\u0647\u0645',
  14548. '\uFCD9': '\u0647\u0670',
  14549. '\uFCDA': '\u064A\u062C',
  14550. '\uFCDB': '\u064A\u062D',
  14551. '\uFCDC': '\u064A\u062E',
  14552. '\uFCDD': '\u064A\u0645',
  14553. '\uFCDE': '\u064A\u0647',
  14554. '\uFCDF': '\u0626\u0645',
  14555. '\uFCE0': '\u0626\u0647',
  14556. '\uFCE1': '\u0628\u0645',
  14557. '\uFCE2': '\u0628\u0647',
  14558. '\uFCE3': '\u062A\u0645',
  14559. '\uFCE4': '\u062A\u0647',
  14560. '\uFCE5': '\u062B\u0645',
  14561. '\uFCE6': '\u062B\u0647',
  14562. '\uFCE7': '\u0633\u0645',
  14563. '\uFCE8': '\u0633\u0647',
  14564. '\uFCE9': '\u0634\u0645',
  14565. '\uFCEA': '\u0634\u0647',
  14566. '\uFCEB': '\u0643\u0644',
  14567. '\uFCEC': '\u0643\u0645',
  14568. '\uFCED': '\u0644\u0645',
  14569. '\uFCEE': '\u0646\u0645',
  14570. '\uFCEF': '\u0646\u0647',
  14571. '\uFCF0': '\u064A\u0645',
  14572. '\uFCF1': '\u064A\u0647',
  14573. '\uFCF2': '\u0640\u064E\u0651',
  14574. '\uFCF3': '\u0640\u064F\u0651',
  14575. '\uFCF4': '\u0640\u0650\u0651',
  14576. '\uFCF5': '\u0637\u0649',
  14577. '\uFCF6': '\u0637\u064A',
  14578. '\uFCF7': '\u0639\u0649',
  14579. '\uFCF8': '\u0639\u064A',
  14580. '\uFCF9': '\u063A\u0649',
  14581. '\uFCFA': '\u063A\u064A',
  14582. '\uFCFB': '\u0633\u0649',
  14583. '\uFCFC': '\u0633\u064A',
  14584. '\uFCFD': '\u0634\u0649',
  14585. '\uFCFE': '\u0634\u064A',
  14586. '\uFCFF': '\u062D\u0649',
  14587. '\uFD00': '\u062D\u064A',
  14588. '\uFD01': '\u062C\u0649',
  14589. '\uFD02': '\u062C\u064A',
  14590. '\uFD03': '\u062E\u0649',
  14591. '\uFD04': '\u062E\u064A',
  14592. '\uFD05': '\u0635\u0649',
  14593. '\uFD06': '\u0635\u064A',
  14594. '\uFD07': '\u0636\u0649',
  14595. '\uFD08': '\u0636\u064A',
  14596. '\uFD09': '\u0634\u062C',
  14597. '\uFD0A': '\u0634\u062D',
  14598. '\uFD0B': '\u0634\u062E',
  14599. '\uFD0C': '\u0634\u0645',
  14600. '\uFD0D': '\u0634\u0631',
  14601. '\uFD0E': '\u0633\u0631',
  14602. '\uFD0F': '\u0635\u0631',
  14603. '\uFD10': '\u0636\u0631',
  14604. '\uFD11': '\u0637\u0649',
  14605. '\uFD12': '\u0637\u064A',
  14606. '\uFD13': '\u0639\u0649',
  14607. '\uFD14': '\u0639\u064A',
  14608. '\uFD15': '\u063A\u0649',
  14609. '\uFD16': '\u063A\u064A',
  14610. '\uFD17': '\u0633\u0649',
  14611. '\uFD18': '\u0633\u064A',
  14612. '\uFD19': '\u0634\u0649',
  14613. '\uFD1A': '\u0634\u064A',
  14614. '\uFD1B': '\u062D\u0649',
  14615. '\uFD1C': '\u062D\u064A',
  14616. '\uFD1D': '\u062C\u0649',
  14617. '\uFD1E': '\u062C\u064A',
  14618. '\uFD1F': '\u062E\u0649',
  14619. '\uFD20': '\u062E\u064A',
  14620. '\uFD21': '\u0635\u0649',
  14621. '\uFD22': '\u0635\u064A',
  14622. '\uFD23': '\u0636\u0649',
  14623. '\uFD24': '\u0636\u064A',
  14624. '\uFD25': '\u0634\u062C',
  14625. '\uFD26': '\u0634\u062D',
  14626. '\uFD27': '\u0634\u062E',
  14627. '\uFD28': '\u0634\u0645',
  14628. '\uFD29': '\u0634\u0631',
  14629. '\uFD2A': '\u0633\u0631',
  14630. '\uFD2B': '\u0635\u0631',
  14631. '\uFD2C': '\u0636\u0631',
  14632. '\uFD2D': '\u0634\u062C',
  14633. '\uFD2E': '\u0634\u062D',
  14634. '\uFD2F': '\u0634\u062E',
  14635. '\uFD30': '\u0634\u0645',
  14636. '\uFD31': '\u0633\u0647',
  14637. '\uFD32': '\u0634\u0647',
  14638. '\uFD33': '\u0637\u0645',
  14639. '\uFD34': '\u0633\u062C',
  14640. '\uFD35': '\u0633\u062D',
  14641. '\uFD36': '\u0633\u062E',
  14642. '\uFD37': '\u0634\u062C',
  14643. '\uFD38': '\u0634\u062D',
  14644. '\uFD39': '\u0634\u062E',
  14645. '\uFD3A': '\u0637\u0645',
  14646. '\uFD3B': '\u0638\u0645',
  14647. '\uFD3C': '\u0627\u064B',
  14648. '\uFD3D': '\u0627\u064B',
  14649. '\uFD50': '\u062A\u062C\u0645',
  14650. '\uFD51': '\u062A\u062D\u062C',
  14651. '\uFD52': '\u062A\u062D\u062C',
  14652. '\uFD53': '\u062A\u062D\u0645',
  14653. '\uFD54': '\u062A\u062E\u0645',
  14654. '\uFD55': '\u062A\u0645\u062C',
  14655. '\uFD56': '\u062A\u0645\u062D',
  14656. '\uFD57': '\u062A\u0645\u062E',
  14657. '\uFD58': '\u062C\u0645\u062D',
  14658. '\uFD59': '\u062C\u0645\u062D',
  14659. '\uFD5A': '\u062D\u0645\u064A',
  14660. '\uFD5B': '\u062D\u0645\u0649',
  14661. '\uFD5C': '\u0633\u062D\u062C',
  14662. '\uFD5D': '\u0633\u062C\u062D',
  14663. '\uFD5E': '\u0633\u062C\u0649',
  14664. '\uFD5F': '\u0633\u0645\u062D',
  14665. '\uFD60': '\u0633\u0645\u062D',
  14666. '\uFD61': '\u0633\u0645\u062C',
  14667. '\uFD62': '\u0633\u0645\u0645',
  14668. '\uFD63': '\u0633\u0645\u0645',
  14669. '\uFD64': '\u0635\u062D\u062D',
  14670. '\uFD65': '\u0635\u062D\u062D',
  14671. '\uFD66': '\u0635\u0645\u0645',
  14672. '\uFD67': '\u0634\u062D\u0645',
  14673. '\uFD68': '\u0634\u062D\u0645',
  14674. '\uFD69': '\u0634\u062C\u064A',
  14675. '\uFD6A': '\u0634\u0645\u062E',
  14676. '\uFD6B': '\u0634\u0645\u062E',
  14677. '\uFD6C': '\u0634\u0645\u0645',
  14678. '\uFD6D': '\u0634\u0645\u0645',
  14679. '\uFD6E': '\u0636\u062D\u0649',
  14680. '\uFD6F': '\u0636\u062E\u0645',
  14681. '\uFD70': '\u0636\u062E\u0645',
  14682. '\uFD71': '\u0637\u0645\u062D',
  14683. '\uFD72': '\u0637\u0645\u062D',
  14684. '\uFD73': '\u0637\u0645\u0645',
  14685. '\uFD74': '\u0637\u0645\u064A',
  14686. '\uFD75': '\u0639\u062C\u0645',
  14687. '\uFD76': '\u0639\u0645\u0645',
  14688. '\uFD77': '\u0639\u0645\u0645',
  14689. '\uFD78': '\u0639\u0645\u0649',
  14690. '\uFD79': '\u063A\u0645\u0645',
  14691. '\uFD7A': '\u063A\u0645\u064A',
  14692. '\uFD7B': '\u063A\u0645\u0649',
  14693. '\uFD7C': '\u0641\u062E\u0645',
  14694. '\uFD7D': '\u0641\u062E\u0645',
  14695. '\uFD7E': '\u0642\u0645\u062D',
  14696. '\uFD7F': '\u0642\u0645\u0645',
  14697. '\uFD80': '\u0644\u062D\u0645',
  14698. '\uFD81': '\u0644\u062D\u064A',
  14699. '\uFD82': '\u0644\u062D\u0649',
  14700. '\uFD83': '\u0644\u062C\u062C',
  14701. '\uFD84': '\u0644\u062C\u062C',
  14702. '\uFD85': '\u0644\u062E\u0645',
  14703. '\uFD86': '\u0644\u062E\u0645',
  14704. '\uFD87': '\u0644\u0645\u062D',
  14705. '\uFD88': '\u0644\u0645\u062D',
  14706. '\uFD89': '\u0645\u062D\u062C',
  14707. '\uFD8A': '\u0645\u062D\u0645',
  14708. '\uFD8B': '\u0645\u062D\u064A',
  14709. '\uFD8C': '\u0645\u062C\u062D',
  14710. '\uFD8D': '\u0645\u062C\u0645',
  14711. '\uFD8E': '\u0645\u062E\u062C',
  14712. '\uFD8F': '\u0645\u062E\u0645',
  14713. '\uFD92': '\u0645\u062C\u062E',
  14714. '\uFD93': '\u0647\u0645\u062C',
  14715. '\uFD94': '\u0647\u0645\u0645',
  14716. '\uFD95': '\u0646\u062D\u0645',
  14717. '\uFD96': '\u0646\u062D\u0649',
  14718. '\uFD97': '\u0646\u062C\u0645',
  14719. '\uFD98': '\u0646\u062C\u0645',
  14720. '\uFD99': '\u0646\u062C\u0649',
  14721. '\uFD9A': '\u0646\u0645\u064A',
  14722. '\uFD9B': '\u0646\u0645\u0649',
  14723. '\uFD9C': '\u064A\u0645\u0645',
  14724. '\uFD9D': '\u064A\u0645\u0645',
  14725. '\uFD9E': '\u0628\u062E\u064A',
  14726. '\uFD9F': '\u062A\u062C\u064A',
  14727. '\uFDA0': '\u062A\u062C\u0649',
  14728. '\uFDA1': '\u062A\u062E\u064A',
  14729. '\uFDA2': '\u062A\u062E\u0649',
  14730. '\uFDA3': '\u062A\u0645\u064A',
  14731. '\uFDA4': '\u062A\u0645\u0649',
  14732. '\uFDA5': '\u062C\u0645\u064A',
  14733. '\uFDA6': '\u062C\u062D\u0649',
  14734. '\uFDA7': '\u062C\u0645\u0649',
  14735. '\uFDA8': '\u0633\u062E\u0649',
  14736. '\uFDA9': '\u0635\u062D\u064A',
  14737. '\uFDAA': '\u0634\u062D\u064A',
  14738. '\uFDAB': '\u0636\u062D\u064A',
  14739. '\uFDAC': '\u0644\u062C\u064A',
  14740. '\uFDAD': '\u0644\u0645\u064A',
  14741. '\uFDAE': '\u064A\u062D\u064A',
  14742. '\uFDAF': '\u064A\u062C\u064A',
  14743. '\uFDB0': '\u064A\u0645\u064A',
  14744. '\uFDB1': '\u0645\u0645\u064A',
  14745. '\uFDB2': '\u0642\u0645\u064A',
  14746. '\uFDB3': '\u0646\u062D\u064A',
  14747. '\uFDB4': '\u0642\u0645\u062D',
  14748. '\uFDB5': '\u0644\u062D\u0645',
  14749. '\uFDB6': '\u0639\u0645\u064A',
  14750. '\uFDB7': '\u0643\u0645\u064A',
  14751. '\uFDB8': '\u0646\u062C\u062D',
  14752. '\uFDB9': '\u0645\u062E\u064A',
  14753. '\uFDBA': '\u0644\u062C\u0645',
  14754. '\uFDBB': '\u0643\u0645\u0645',
  14755. '\uFDBC': '\u0644\u062C\u0645',
  14756. '\uFDBD': '\u0646\u062C\u062D',
  14757. '\uFDBE': '\u062C\u062D\u064A',
  14758. '\uFDBF': '\u062D\u062C\u064A',
  14759. '\uFDC0': '\u0645\u062C\u064A',
  14760. '\uFDC1': '\u0641\u0645\u064A',
  14761. '\uFDC2': '\u0628\u062D\u064A',
  14762. '\uFDC3': '\u0643\u0645\u0645',
  14763. '\uFDC4': '\u0639\u062C\u0645',
  14764. '\uFDC5': '\u0635\u0645\u0645',
  14765. '\uFDC6': '\u0633\u062E\u064A',
  14766. '\uFDC7': '\u0646\u062C\u064A',
  14767. '\uFE49': '\u203E',
  14768. '\uFE4A': '\u203E',
  14769. '\uFE4B': '\u203E',
  14770. '\uFE4C': '\u203E',
  14771. '\uFE4D': '\u005F',
  14772. '\uFE4E': '\u005F',
  14773. '\uFE4F': '\u005F',
  14774. '\uFE80': '\u0621',
  14775. '\uFE81': '\u0622',
  14776. '\uFE82': '\u0622',
  14777. '\uFE83': '\u0623',
  14778. '\uFE84': '\u0623',
  14779. '\uFE85': '\u0624',
  14780. '\uFE86': '\u0624',
  14781. '\uFE87': '\u0625',
  14782. '\uFE88': '\u0625',
  14783. '\uFE89': '\u0626',
  14784. '\uFE8A': '\u0626',
  14785. '\uFE8B': '\u0626',
  14786. '\uFE8C': '\u0626',
  14787. '\uFE8D': '\u0627',
  14788. '\uFE8E': '\u0627',
  14789. '\uFE8F': '\u0628',
  14790. '\uFE90': '\u0628',
  14791. '\uFE91': '\u0628',
  14792. '\uFE92': '\u0628',
  14793. '\uFE93': '\u0629',
  14794. '\uFE94': '\u0629',
  14795. '\uFE95': '\u062A',
  14796. '\uFE96': '\u062A',
  14797. '\uFE97': '\u062A',
  14798. '\uFE98': '\u062A',
  14799. '\uFE99': '\u062B',
  14800. '\uFE9A': '\u062B',
  14801. '\uFE9B': '\u062B',
  14802. '\uFE9C': '\u062B',
  14803. '\uFE9D': '\u062C',
  14804. '\uFE9E': '\u062C',
  14805. '\uFE9F': '\u062C',
  14806. '\uFEA0': '\u062C',
  14807. '\uFEA1': '\u062D',
  14808. '\uFEA2': '\u062D',
  14809. '\uFEA3': '\u062D',
  14810. '\uFEA4': '\u062D',
  14811. '\uFEA5': '\u062E',
  14812. '\uFEA6': '\u062E',
  14813. '\uFEA7': '\u062E',
  14814. '\uFEA8': '\u062E',
  14815. '\uFEA9': '\u062F',
  14816. '\uFEAA': '\u062F',
  14817. '\uFEAB': '\u0630',
  14818. '\uFEAC': '\u0630',
  14819. '\uFEAD': '\u0631',
  14820. '\uFEAE': '\u0631',
  14821. '\uFEAF': '\u0632',
  14822. '\uFEB0': '\u0632',
  14823. '\uFEB1': '\u0633',
  14824. '\uFEB2': '\u0633',
  14825. '\uFEB3': '\u0633',
  14826. '\uFEB4': '\u0633',
  14827. '\uFEB5': '\u0634',
  14828. '\uFEB6': '\u0634',
  14829. '\uFEB7': '\u0634',
  14830. '\uFEB8': '\u0634',
  14831. '\uFEB9': '\u0635',
  14832. '\uFEBA': '\u0635',
  14833. '\uFEBB': '\u0635',
  14834. '\uFEBC': '\u0635',
  14835. '\uFEBD': '\u0636',
  14836. '\uFEBE': '\u0636',
  14837. '\uFEBF': '\u0636',
  14838. '\uFEC0': '\u0636',
  14839. '\uFEC1': '\u0637',
  14840. '\uFEC2': '\u0637',
  14841. '\uFEC3': '\u0637',
  14842. '\uFEC4': '\u0637',
  14843. '\uFEC5': '\u0638',
  14844. '\uFEC6': '\u0638',
  14845. '\uFEC7': '\u0638',
  14846. '\uFEC8': '\u0638',
  14847. '\uFEC9': '\u0639',
  14848. '\uFECA': '\u0639',
  14849. '\uFECB': '\u0639',
  14850. '\uFECC': '\u0639',
  14851. '\uFECD': '\u063A',
  14852. '\uFECE': '\u063A',
  14853. '\uFECF': '\u063A',
  14854. '\uFED0': '\u063A',
  14855. '\uFED1': '\u0641',
  14856. '\uFED2': '\u0641',
  14857. '\uFED3': '\u0641',
  14858. '\uFED4': '\u0641',
  14859. '\uFED5': '\u0642',
  14860. '\uFED6': '\u0642',
  14861. '\uFED7': '\u0642',
  14862. '\uFED8': '\u0642',
  14863. '\uFED9': '\u0643',
  14864. '\uFEDA': '\u0643',
  14865. '\uFEDB': '\u0643',
  14866. '\uFEDC': '\u0643',
  14867. '\uFEDD': '\u0644',
  14868. '\uFEDE': '\u0644',
  14869. '\uFEDF': '\u0644',
  14870. '\uFEE0': '\u0644',
  14871. '\uFEE1': '\u0645',
  14872. '\uFEE2': '\u0645',
  14873. '\uFEE3': '\u0645',
  14874. '\uFEE4': '\u0645',
  14875. '\uFEE5': '\u0646',
  14876. '\uFEE6': '\u0646',
  14877. '\uFEE7': '\u0646',
  14878. '\uFEE8': '\u0646',
  14879. '\uFEE9': '\u0647',
  14880. '\uFEEA': '\u0647',
  14881. '\uFEEB': '\u0647',
  14882. '\uFEEC': '\u0647',
  14883. '\uFEED': '\u0648',
  14884. '\uFEEE': '\u0648',
  14885. '\uFEEF': '\u0649',
  14886. '\uFEF0': '\u0649',
  14887. '\uFEF1': '\u064A',
  14888. '\uFEF2': '\u064A',
  14889. '\uFEF3': '\u064A',
  14890. '\uFEF4': '\u064A',
  14891. '\uFEF5': '\u0644\u0622',
  14892. '\uFEF6': '\u0644\u0622',
  14893. '\uFEF7': '\u0644\u0623',
  14894. '\uFEF8': '\u0644\u0623',
  14895. '\uFEF9': '\u0644\u0625',
  14896. '\uFEFA': '\u0644\u0625',
  14897. '\uFEFB': '\u0644\u0627',
  14898. '\uFEFC': '\u0644\u0627'
  14899. };
  14900. function reverseIfRtl(chars) {
  14901. var charsLength = chars.length;
  14902. //reverse an arabic ligature
  14903. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14904. return chars;
  14905. }
  14906. var s = '';
  14907. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14908. s += chars[ii];
  14909. }
  14910. return s;
  14911. }
  14912. function adjustWidths(properties) {
  14913. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14914. return;
  14915. }
  14916. // adjusting width to fontMatrix scale
  14917. var scale = 0.001 / properties.fontMatrix[0];
  14918. var glyphsWidths = properties.widths;
  14919. for (var glyph in glyphsWidths) {
  14920. glyphsWidths[glyph] *= scale;
  14921. }
  14922. properties.defaultWidth *= scale;
  14923. }
  14924. function getFontType(type, subtype) {
  14925. switch (type) {
  14926. case 'Type1':
  14927. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14928. case 'CIDFontType0':
  14929. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14930. FontType.CIDFONTTYPE0;
  14931. case 'OpenType':
  14932. return FontType.OPENTYPE;
  14933. case 'TrueType':
  14934. return FontType.TRUETYPE;
  14935. case 'CIDFontType2':
  14936. return FontType.CIDFONTTYPE2;
  14937. case 'MMType1':
  14938. return FontType.MMTYPE1;
  14939. case 'Type0':
  14940. return FontType.TYPE0;
  14941. default:
  14942. return FontType.UNKNOWN;
  14943. }
  14944. }
  14945. var Glyph = (function GlyphClosure() {
  14946. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14947. this.fontChar = fontChar;
  14948. this.unicode = unicode;
  14949. this.accent = accent;
  14950. this.width = width;
  14951. this.vmetric = vmetric;
  14952. this.operatorListId = operatorListId;
  14953. }
  14954. Glyph.prototype.matchesForCache =
  14955. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14956. return this.fontChar === fontChar &&
  14957. this.unicode === unicode &&
  14958. this.accent === accent &&
  14959. this.width === width &&
  14960. this.vmetric === vmetric &&
  14961. this.operatorListId === operatorListId;
  14962. };
  14963. return Glyph;
  14964. })();
  14965. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14966. function ToUnicodeMap(cmap) {
  14967. // The elements of this._map can be integers or strings, depending on how
  14968. // |cmap| was created.
  14969. this._map = cmap;
  14970. }
  14971. ToUnicodeMap.prototype = {
  14972. get length() {
  14973. return this._map.length;
  14974. },
  14975. forEach: function(callback) {
  14976. for (var charCode in this._map) {
  14977. callback(charCode, this._map[charCode].charCodeAt(0));
  14978. }
  14979. },
  14980. get: function(i) {
  14981. return this._map[i];
  14982. },
  14983. charCodeOf: function(v) {
  14984. return this._map.indexOf(v);
  14985. }
  14986. };
  14987. return ToUnicodeMap;
  14988. })();
  14989. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14990. function IdentityToUnicodeMap(firstChar, lastChar) {
  14991. this.firstChar = firstChar;
  14992. this.lastChar = lastChar;
  14993. }
  14994. IdentityToUnicodeMap.prototype = {
  14995. get length() {
  14996. error('should not access .length');
  14997. },
  14998. forEach: function (callback) {
  14999. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15000. callback(i, i);
  15001. }
  15002. },
  15003. get: function (i) {
  15004. if (this.firstChar <= i && i <= this.lastChar) {
  15005. return String.fromCharCode(i);
  15006. }
  15007. return undefined;
  15008. },
  15009. charCodeOf: function (v) {
  15010. error('should not call .charCodeOf');
  15011. }
  15012. };
  15013. return IdentityToUnicodeMap;
  15014. })();
  15015. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15016. function writeInt16(dest, offset, num) {
  15017. dest[offset] = (num >> 8) & 0xFF;
  15018. dest[offset + 1] = num & 0xFF;
  15019. }
  15020. function writeInt32(dest, offset, num) {
  15021. dest[offset] = (num >> 24) & 0xFF;
  15022. dest[offset + 1] = (num >> 16) & 0xFF;
  15023. dest[offset + 2] = (num >> 8) & 0xFF;
  15024. dest[offset + 3] = num & 0xFF;
  15025. }
  15026. function writeData(dest, offset, data) {
  15027. var i, ii;
  15028. if (data instanceof Uint8Array) {
  15029. dest.set(data, offset);
  15030. } else if (typeof data === 'string') {
  15031. for (i = 0, ii = data.length; i < ii; i++) {
  15032. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15033. }
  15034. } else {
  15035. // treating everything else as array
  15036. for (i = 0, ii = data.length; i < ii; i++) {
  15037. dest[offset++] = data[i] & 0xFF;
  15038. }
  15039. }
  15040. }
  15041. function OpenTypeFileBuilder(sfnt) {
  15042. this.sfnt = sfnt;
  15043. this.tables = Object.create(null);
  15044. }
  15045. OpenTypeFileBuilder.getSearchParams =
  15046. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15047. var maxPower2 = 1, log2 = 0;
  15048. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15049. maxPower2 <<= 1;
  15050. log2++;
  15051. }
  15052. var searchRange = maxPower2 * entrySize;
  15053. return {
  15054. range: searchRange,
  15055. entry: log2,
  15056. rangeShift: entrySize * entriesCount - searchRange
  15057. };
  15058. };
  15059. var OTF_HEADER_SIZE = 12;
  15060. var OTF_TABLE_ENTRY_SIZE = 16;
  15061. OpenTypeFileBuilder.prototype = {
  15062. toArray: function OpenTypeFileBuilder_toArray() {
  15063. var sfnt = this.sfnt;
  15064. // Tables needs to be written by ascendant alphabetic order
  15065. var tables = this.tables;
  15066. var tablesNames = Object.keys(tables);
  15067. tablesNames.sort();
  15068. var numTables = tablesNames.length;
  15069. var i, j, jj, table, tableName;
  15070. // layout the tables data
  15071. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15072. var tableOffsets = [offset];
  15073. for (i = 0; i < numTables; i++) {
  15074. table = tables[tablesNames[i]];
  15075. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15076. offset += paddedLength;
  15077. tableOffsets.push(offset);
  15078. }
  15079. var file = new Uint8Array(offset);
  15080. // write the table data first (mostly for checksum)
  15081. for (i = 0; i < numTables; i++) {
  15082. table = tables[tablesNames[i]];
  15083. writeData(file, tableOffsets[i], table);
  15084. }
  15085. // sfnt version (4 bytes)
  15086. if (sfnt === 'true') {
  15087. // Windows hates the Mac TrueType sfnt version number
  15088. sfnt = string32(0x00010000);
  15089. }
  15090. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15091. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15092. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15093. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15094. // numTables (2 bytes)
  15095. writeInt16(file, 4, numTables);
  15096. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15097. // searchRange (2 bytes)
  15098. writeInt16(file, 6, searchParams.range);
  15099. // entrySelector (2 bytes)
  15100. writeInt16(file, 8, searchParams.entry);
  15101. // rangeShift (2 bytes)
  15102. writeInt16(file, 10, searchParams.rangeShift);
  15103. offset = OTF_HEADER_SIZE;
  15104. // writing table entries
  15105. for (i = 0; i < numTables; i++) {
  15106. tableName = tablesNames[i];
  15107. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15108. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15109. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15110. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15111. // checksum
  15112. var checksum = 0;
  15113. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15114. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15115. (file[j + 2] << 8) + file[j + 3];
  15116. checksum = (checksum + quad) | 0;
  15117. }
  15118. writeInt32(file, offset + 4, checksum);
  15119. // offset
  15120. writeInt32(file, offset + 8, tableOffsets[i]);
  15121. // length
  15122. writeInt32(file, offset + 12, tables[tableName].length);
  15123. offset += OTF_TABLE_ENTRY_SIZE;
  15124. }
  15125. return file;
  15126. },
  15127. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15128. if (tag in this.tables) {
  15129. throw new Error('Table ' + tag + ' already exists');
  15130. }
  15131. this.tables[tag] = data;
  15132. }
  15133. };
  15134. return OpenTypeFileBuilder;
  15135. })();
  15136. /**
  15137. * 'Font' is the class the outside world should use, it encapsulate all the font
  15138. * decoding logics whatever type it is (assuming the font type is supported).
  15139. *
  15140. * For example to read a Type1 font and to attach it to the document:
  15141. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15142. * type1Font.bind();
  15143. */
  15144. var Font = (function FontClosure() {
  15145. function Font(name, file, properties) {
  15146. var charCode, glyphName, fontChar;
  15147. this.name = name;
  15148. this.loadedName = properties.loadedName;
  15149. this.isType3Font = properties.isType3Font;
  15150. this.sizes = [];
  15151. this.glyphCache = {};
  15152. var names = name.split('+');
  15153. names = names.length > 1 ? names[1] : names[0];
  15154. names = names.split(/[-,_]/g)[0];
  15155. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15156. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15157. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15158. var type = properties.type;
  15159. var subtype = properties.subtype;
  15160. this.type = type;
  15161. this.fallbackName = (this.isMonospace ? 'monospace' :
  15162. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15163. this.differences = properties.differences;
  15164. this.widths = properties.widths;
  15165. this.defaultWidth = properties.defaultWidth;
  15166. this.composite = properties.composite;
  15167. this.wideChars = properties.wideChars;
  15168. this.cMap = properties.cMap;
  15169. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15170. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15171. this.fontMatrix = properties.fontMatrix;
  15172. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15173. this.toFontChar = [];
  15174. if (properties.type === 'Type3') {
  15175. for (charCode = 0; charCode < 256; charCode++) {
  15176. this.toFontChar[charCode] = (this.differences[charCode] ||
  15177. properties.defaultEncoding[charCode]);
  15178. }
  15179. this.fontType = FontType.TYPE3;
  15180. return;
  15181. }
  15182. this.cidEncoding = properties.cidEncoding;
  15183. this.vertical = properties.vertical;
  15184. if (this.vertical) {
  15185. this.vmetrics = properties.vmetrics;
  15186. this.defaultVMetrics = properties.defaultVMetrics;
  15187. }
  15188. if (!file || file.isEmpty) {
  15189. if (file) {
  15190. // Some bad PDF generators will include empty font files,
  15191. // attempting to recover by assuming that no file exists.
  15192. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15193. }
  15194. this.missingFile = true;
  15195. // The file data is not specified. Trying to fix the font name
  15196. // to be used with the canvas.font.
  15197. var fontName = name.replace(/[,_]/g, '-');
  15198. var isStandardFont = !!stdFontMap[fontName] ||
  15199. (nonStdFontMap[fontName] && !!stdFontMap[nonStdFontMap[fontName]]);
  15200. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15201. this.bold = (fontName.search(/bold/gi) !== -1);
  15202. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15203. (fontName.search(/italic/gi) !== -1));
  15204. // Use 'name' instead of 'fontName' here because the original
  15205. // name ArialBlack for example will be replaced by Helvetica.
  15206. this.black = (name.search(/Black/g) !== -1);
  15207. // if at least one width is present, remeasure all chars when exists
  15208. this.remeasure = Object.keys(this.widths).length > 0;
  15209. if (isStandardFont && type === 'CIDFontType2' &&
  15210. properties.cidEncoding.indexOf('Identity-') === 0) {
  15211. // Standard fonts might be embedded as CID font without glyph mapping.
  15212. // Building one based on GlyphMapForStandardFonts.
  15213. var map = [];
  15214. for (var code in GlyphMapForStandardFonts) {
  15215. map[+code] = GlyphMapForStandardFonts[code];
  15216. }
  15217. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15218. if (!isIdentityUnicode) {
  15219. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15220. map[+charCode] = unicodeCharCode;
  15221. });
  15222. }
  15223. this.toFontChar = map;
  15224. this.toUnicode = new ToUnicodeMap(map);
  15225. } else if (/Symbol/i.test(fontName)) {
  15226. var symbols = Encodings.SymbolSetEncoding;
  15227. for (charCode in symbols) {
  15228. fontChar = GlyphsUnicode[symbols[charCode]];
  15229. if (!fontChar) {
  15230. continue;
  15231. }
  15232. this.toFontChar[charCode] = fontChar;
  15233. }
  15234. for (charCode in properties.differences) {
  15235. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15236. if (!fontChar) {
  15237. continue;
  15238. }
  15239. this.toFontChar[charCode] = fontChar;
  15240. }
  15241. } else if (/Dingbats/i.test(fontName)) {
  15242. if (/Wingdings/i.test(name)) {
  15243. warn('Wingdings font without embedded font file, ' +
  15244. 'falling back to the ZapfDingbats encoding.');
  15245. }
  15246. var dingbats = Encodings.ZapfDingbatsEncoding;
  15247. for (charCode in dingbats) {
  15248. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15249. if (!fontChar) {
  15250. continue;
  15251. }
  15252. this.toFontChar[charCode] = fontChar;
  15253. }
  15254. for (charCode in properties.differences) {
  15255. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15256. if (!fontChar) {
  15257. continue;
  15258. }
  15259. this.toFontChar[charCode] = fontChar;
  15260. }
  15261. } else if (isStandardFont) {
  15262. this.toFontChar = [];
  15263. for (charCode in properties.defaultEncoding) {
  15264. glyphName = (properties.differences[charCode] ||
  15265. properties.defaultEncoding[charCode]);
  15266. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15267. }
  15268. } else {
  15269. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15270. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15271. if (notCidFont) {
  15272. glyphName = (properties.differences[charCode] ||
  15273. properties.defaultEncoding[charCode]);
  15274. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15275. }
  15276. this.toFontChar[charCode] = unicodeCharCode;
  15277. }.bind(this));
  15278. }
  15279. this.loadedName = fontName.split('-')[0];
  15280. this.loading = false;
  15281. this.fontType = getFontType(type, subtype);
  15282. return;
  15283. }
  15284. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15285. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15286. // Some TrueType fonts by mistake claim Type1C
  15287. if (isTrueTypeFile(file)) {
  15288. subtype = 'TrueType';
  15289. } else {
  15290. type = 'Type1';
  15291. }
  15292. }
  15293. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15294. type = 'CIDFontType0';
  15295. }
  15296. // XXX: Temporarily change the type for open type so we trigger a warning.
  15297. // This should be removed when we add support for open type.
  15298. if (subtype === 'OpenType') {
  15299. type = 'OpenType';
  15300. }
  15301. var data;
  15302. switch (type) {
  15303. case 'MMType1':
  15304. info('MMType1 font (' + name + '), falling back to Type1.');
  15305. /* falls through */
  15306. case 'Type1':
  15307. case 'CIDFontType0':
  15308. this.mimetype = 'font/opentype';
  15309. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15310. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15311. adjustWidths(properties);
  15312. // Wrap the CFF data inside an OTF font file
  15313. data = this.convert(name, cff, properties);
  15314. break;
  15315. case 'OpenType':
  15316. case 'TrueType':
  15317. case 'CIDFontType2':
  15318. this.mimetype = 'font/opentype';
  15319. // Repair the TrueType file. It is can be damaged in the point of
  15320. // view of the sanitizer
  15321. data = this.checkAndRepair(name, file, properties);
  15322. if (this.isOpenType) {
  15323. type = 'OpenType';
  15324. }
  15325. break;
  15326. default:
  15327. error('Font ' + type + ' is not supported');
  15328. break;
  15329. }
  15330. this.data = data;
  15331. this.fontType = getFontType(type, subtype);
  15332. // Transfer some properties again that could change during font conversion
  15333. this.fontMatrix = properties.fontMatrix;
  15334. this.widths = properties.widths;
  15335. this.defaultWidth = properties.defaultWidth;
  15336. this.encoding = properties.baseEncoding;
  15337. this.seacMap = properties.seacMap;
  15338. this.loading = true;
  15339. }
  15340. Font.getFontID = (function () {
  15341. var ID = 1;
  15342. return function Font_getFontID() {
  15343. return String(ID++);
  15344. };
  15345. })();
  15346. function int16(b0, b1) {
  15347. return (b0 << 8) + b1;
  15348. }
  15349. function int32(b0, b1, b2, b3) {
  15350. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15351. }
  15352. function string16(value) {
  15353. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15354. }
  15355. function safeString16(value) {
  15356. // clamp value to the 16-bit int range
  15357. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15358. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15359. }
  15360. function isTrueTypeFile(file) {
  15361. var header = file.peekBytes(4);
  15362. return readUint32(header, 0) === 0x00010000;
  15363. }
  15364. /**
  15365. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15366. * with their unicode value. It also moves char codes that are in known
  15367. * problematic locations.
  15368. * @return {Object} Two properties:
  15369. * 'toFontChar' - maps original char codes(the value that will be read
  15370. * from commands such as show text) to the char codes that will be used in the
  15371. * font that we build
  15372. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15373. */
  15374. function adjustMapping(charCodeToGlyphId, properties) {
  15375. var toUnicode = properties.toUnicode;
  15376. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15377. var isIdentityUnicode =
  15378. properties.toUnicode instanceof IdentityToUnicodeMap;
  15379. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15380. var newMap = Object.create(null);
  15381. var toFontChar = [];
  15382. var usedFontCharCodes = [];
  15383. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15384. for (var originalCharCode in charCodeToGlyphId) {
  15385. originalCharCode |= 0;
  15386. var glyphId = charCodeToGlyphId[originalCharCode];
  15387. var fontCharCode = originalCharCode;
  15388. // First try to map the value to a unicode position if a non identity map
  15389. // was created.
  15390. if (!isIdentityUnicode) {
  15391. if (toUnicode.get(originalCharCode) !== undefined) {
  15392. var unicode = toUnicode.get(fontCharCode);
  15393. // TODO: Try to map ligatures to the correct spot.
  15394. if (unicode.length === 1) {
  15395. fontCharCode = unicode.charCodeAt(0);
  15396. }
  15397. } else if (isCidFontType2) {
  15398. // For CIDFontType2, move characters not present in toUnicode
  15399. // to the private use area (fixes bug 1028735 and issue 4881).
  15400. fontCharCode = nextAvailableFontCharCode;
  15401. }
  15402. }
  15403. // Try to move control characters, special characters and already mapped
  15404. // characters to the private use area since they will not be drawn by
  15405. // canvas if left in their current position. Also, move characters if the
  15406. // font was symbolic and there is only an identity unicode map since the
  15407. // characters probably aren't in the correct position (fixes an issue
  15408. // with firefox and thuluthfont).
  15409. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15410. fontCharCode <= 0x1f || // Control chars
  15411. fontCharCode === 0x7F || // Control char
  15412. fontCharCode === 0xAD || // Soft hyphen
  15413. fontCharCode === 0xA0 || // Non breaking space
  15414. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15415. // Prevent drawing characters in the specials unicode block.
  15416. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15417. (isSymbolic && isIdentityUnicode)) &&
  15418. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15419. // Loop to try and find a free spot in the private use area.
  15420. do {
  15421. fontCharCode = nextAvailableFontCharCode++;
  15422. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15423. fontCharCode = 0xF020;
  15424. nextAvailableFontCharCode = fontCharCode + 1;
  15425. }
  15426. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15427. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15428. }
  15429. newMap[fontCharCode] = glyphId;
  15430. toFontChar[originalCharCode] = fontCharCode;
  15431. usedFontCharCodes[fontCharCode] = true;
  15432. }
  15433. return {
  15434. toFontChar: toFontChar,
  15435. charCodeToGlyphId: newMap,
  15436. nextAvailableFontCharCode: nextAvailableFontCharCode
  15437. };
  15438. }
  15439. function getRanges(glyphs) {
  15440. // Array.sort() sorts by characters, not numerically, so convert to an
  15441. // array of characters.
  15442. var codes = [];
  15443. for (var charCode in glyphs) {
  15444. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15445. }
  15446. codes.sort(function fontGetRangesSort(a, b) {
  15447. return a.fontCharCode - b.fontCharCode;
  15448. });
  15449. // Split the sorted codes into ranges.
  15450. var ranges = [];
  15451. var length = codes.length;
  15452. for (var n = 0; n < length; ) {
  15453. var start = codes[n].fontCharCode;
  15454. var codeIndices = [codes[n].glyphId];
  15455. ++n;
  15456. var end = start;
  15457. while (n < length && end + 1 === codes[n].fontCharCode) {
  15458. codeIndices.push(codes[n].glyphId);
  15459. ++end;
  15460. ++n;
  15461. if (end === 0xFFFF) {
  15462. break;
  15463. }
  15464. }
  15465. ranges.push([start, end, codeIndices]);
  15466. }
  15467. return ranges;
  15468. }
  15469. function createCmapTable(glyphs) {
  15470. var ranges = getRanges(glyphs);
  15471. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15472. var cmap = '\x00\x00' + // version
  15473. string16(numTables) + // numTables
  15474. '\x00\x03' + // platformID
  15475. '\x00\x01' + // encodingID
  15476. string32(4 + numTables * 8); // start of the table record
  15477. var i, ii, j, jj;
  15478. for (i = ranges.length - 1; i >= 0; --i) {
  15479. if (ranges[i][0] <= 0xFFFF) { break; }
  15480. }
  15481. var bmpLength = i + 1;
  15482. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15483. ranges[i][1] = 0xFFFE;
  15484. }
  15485. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15486. var segCount = bmpLength + trailingRangesCount;
  15487. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15488. // Fill up the 4 parallel arrays describing the segments.
  15489. var startCount = '';
  15490. var endCount = '';
  15491. var idDeltas = '';
  15492. var idRangeOffsets = '';
  15493. var glyphsIds = '';
  15494. var bias = 0;
  15495. var range, start, end, codes;
  15496. for (i = 0, ii = bmpLength; i < ii; i++) {
  15497. range = ranges[i];
  15498. start = range[0];
  15499. end = range[1];
  15500. startCount += string16(start);
  15501. endCount += string16(end);
  15502. codes = range[2];
  15503. var contiguous = true;
  15504. for (j = 1, jj = codes.length; j < jj; ++j) {
  15505. if (codes[j] !== codes[j - 1] + 1) {
  15506. contiguous = false;
  15507. break;
  15508. }
  15509. }
  15510. if (!contiguous) {
  15511. var offset = (segCount - i) * 2 + bias * 2;
  15512. bias += (end - start + 1);
  15513. idDeltas += string16(0);
  15514. idRangeOffsets += string16(offset);
  15515. for (j = 0, jj = codes.length; j < jj; ++j) {
  15516. glyphsIds += string16(codes[j]);
  15517. }
  15518. } else {
  15519. var startCode = codes[0];
  15520. idDeltas += string16((startCode - start) & 0xFFFF);
  15521. idRangeOffsets += string16(0);
  15522. }
  15523. }
  15524. if (trailingRangesCount > 0) {
  15525. endCount += '\xFF\xFF';
  15526. startCount += '\xFF\xFF';
  15527. idDeltas += '\x00\x01';
  15528. idRangeOffsets += '\x00\x00';
  15529. }
  15530. var format314 = '\x00\x00' + // language
  15531. string16(2 * segCount) +
  15532. string16(searchParams.range) +
  15533. string16(searchParams.entry) +
  15534. string16(searchParams.rangeShift) +
  15535. endCount + '\x00\x00' + startCount +
  15536. idDeltas + idRangeOffsets + glyphsIds;
  15537. var format31012 = '';
  15538. var header31012 = '';
  15539. if (numTables > 1) {
  15540. cmap += '\x00\x03' + // platformID
  15541. '\x00\x0A' + // encodingID
  15542. string32(4 + numTables * 8 +
  15543. 4 + format314.length); // start of the table record
  15544. format31012 = '';
  15545. for (i = 0, ii = ranges.length; i < ii; i++) {
  15546. range = ranges[i];
  15547. start = range[0];
  15548. codes = range[2];
  15549. var code = codes[0];
  15550. for (j = 1, jj = codes.length; j < jj; ++j) {
  15551. if (codes[j] !== codes[j - 1] + 1) {
  15552. end = range[0] + j - 1;
  15553. format31012 += string32(start) + // startCharCode
  15554. string32(end) + // endCharCode
  15555. string32(code); // startGlyphID
  15556. start = end + 1;
  15557. code = codes[j];
  15558. }
  15559. }
  15560. format31012 += string32(start) + // startCharCode
  15561. string32(range[1]) + // endCharCode
  15562. string32(code); // startGlyphID
  15563. }
  15564. header31012 = '\x00\x0C' + // format
  15565. '\x00\x00' + // reserved
  15566. string32(format31012.length + 16) + // length
  15567. '\x00\x00\x00\x00' + // language
  15568. string32(format31012.length / 12); // nGroups
  15569. }
  15570. return cmap + '\x00\x04' + // format
  15571. string16(format314.length + 4) + // length
  15572. format314 + header31012 + format31012;
  15573. }
  15574. function validateOS2Table(os2) {
  15575. var stream = new Stream(os2.data);
  15576. var version = stream.getUint16();
  15577. // TODO verify all OS/2 tables fields, but currently we validate only those
  15578. // that give us issues
  15579. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15580. var selection = stream.getUint16();
  15581. if (version < 4 && (selection & 0x0300)) {
  15582. return false;
  15583. }
  15584. var firstChar = stream.getUint16();
  15585. var lastChar = stream.getUint16();
  15586. if (firstChar > lastChar) {
  15587. return false;
  15588. }
  15589. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15590. var usWinAscent = stream.getUint16();
  15591. if (usWinAscent === 0) { // makes font unreadable by windows
  15592. return false;
  15593. }
  15594. // OS/2 appears to be valid, resetting some fields
  15595. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15596. return true;
  15597. }
  15598. function createOS2Table(properties, charstrings, override) {
  15599. override = override || {
  15600. unitsPerEm: 0,
  15601. yMax: 0,
  15602. yMin: 0,
  15603. ascent: 0,
  15604. descent: 0
  15605. };
  15606. var ulUnicodeRange1 = 0;
  15607. var ulUnicodeRange2 = 0;
  15608. var ulUnicodeRange3 = 0;
  15609. var ulUnicodeRange4 = 0;
  15610. var firstCharIndex = null;
  15611. var lastCharIndex = 0;
  15612. if (charstrings) {
  15613. for (var code in charstrings) {
  15614. code |= 0;
  15615. if (firstCharIndex > code || !firstCharIndex) {
  15616. firstCharIndex = code;
  15617. }
  15618. if (lastCharIndex < code) {
  15619. lastCharIndex = code;
  15620. }
  15621. var position = getUnicodeRangeFor(code);
  15622. if (position < 32) {
  15623. ulUnicodeRange1 |= 1 << position;
  15624. } else if (position < 64) {
  15625. ulUnicodeRange2 |= 1 << position - 32;
  15626. } else if (position < 96) {
  15627. ulUnicodeRange3 |= 1 << position - 64;
  15628. } else if (position < 123) {
  15629. ulUnicodeRange4 |= 1 << position - 96;
  15630. } else {
  15631. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15632. }
  15633. }
  15634. } else {
  15635. // TODO
  15636. firstCharIndex = 0;
  15637. lastCharIndex = 255;
  15638. }
  15639. var bbox = properties.bbox || [0, 0, 0, 0];
  15640. var unitsPerEm = (override.unitsPerEm ||
  15641. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15642. // if the font units differ to the PDF glyph space units
  15643. // then scale up the values
  15644. var scale = (properties.ascentScaled ? 1.0 :
  15645. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15646. var typoAscent = (override.ascent ||
  15647. Math.round(scale * (properties.ascent || bbox[3])));
  15648. var typoDescent = (override.descent ||
  15649. Math.round(scale * (properties.descent || bbox[1])));
  15650. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15651. typoDescent = -typoDescent; // fixing incorrect descent
  15652. }
  15653. var winAscent = override.yMax || typoAscent;
  15654. var winDescent = -override.yMin || -typoDescent;
  15655. return '\x00\x03' + // version
  15656. '\x02\x24' + // xAvgCharWidth
  15657. '\x01\xF4' + // usWeightClass
  15658. '\x00\x05' + // usWidthClass
  15659. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15660. '\x02\x8A' + // ySubscriptXSize
  15661. '\x02\xBB' + // ySubscriptYSize
  15662. '\x00\x00' + // ySubscriptXOffset
  15663. '\x00\x8C' + // ySubscriptYOffset
  15664. '\x02\x8A' + // ySuperScriptXSize
  15665. '\x02\xBB' + // ySuperScriptYSize
  15666. '\x00\x00' + // ySuperScriptXOffset
  15667. '\x01\xDF' + // ySuperScriptYOffset
  15668. '\x00\x31' + // yStrikeOutSize
  15669. '\x01\x02' + // yStrikeOutPosition
  15670. '\x00\x00' + // sFamilyClass
  15671. '\x00\x00\x06' +
  15672. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15673. '\x00\x00\x00\x00\x00\x00' + // Panose
  15674. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15675. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15676. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15677. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15678. '\x2A\x32\x31\x2A' + // achVendID
  15679. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15680. string16(firstCharIndex ||
  15681. properties.firstChar) + // usFirstCharIndex
  15682. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15683. string16(typoAscent) + // sTypoAscender
  15684. string16(typoDescent) + // sTypoDescender
  15685. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15686. string16(winAscent) + // usWinAscent
  15687. string16(winDescent) + // usWinDescent
  15688. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15689. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15690. string16(properties.xHeight) + // sxHeight
  15691. string16(properties.capHeight) + // sCapHeight
  15692. string16(0) + // usDefaultChar
  15693. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15694. '\x00\x03'; // usMaxContext
  15695. }
  15696. function createPostTable(properties) {
  15697. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15698. return ('\x00\x03\x00\x00' + // Version number
  15699. string32(angle) + // italicAngle
  15700. '\x00\x00' + // underlinePosition
  15701. '\x00\x00' + // underlineThickness
  15702. string32(properties.fixedPitch) + // isFixedPitch
  15703. '\x00\x00\x00\x00' + // minMemType42
  15704. '\x00\x00\x00\x00' + // maxMemType42
  15705. '\x00\x00\x00\x00' + // minMemType1
  15706. '\x00\x00\x00\x00'); // maxMemType1
  15707. }
  15708. function createNameTable(name, proto) {
  15709. if (!proto) {
  15710. proto = [[], []]; // no strings and unicode strings
  15711. }
  15712. var strings = [
  15713. proto[0][0] || 'Original licence', // 0.Copyright
  15714. proto[0][1] || name, // 1.Font family
  15715. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15716. proto[0][3] || 'uniqueID', // 3.Unique ID
  15717. proto[0][4] || name, // 4.Full font name
  15718. proto[0][5] || 'Version 0.11', // 5.Version
  15719. proto[0][6] || '', // 6.Postscript name
  15720. proto[0][7] || 'Unknown', // 7.Trademark
  15721. proto[0][8] || 'Unknown', // 8.Manufacturer
  15722. proto[0][9] || 'Unknown' // 9.Designer
  15723. ];
  15724. // Mac want 1-byte per character strings while Windows want
  15725. // 2-bytes per character, so duplicate the names table
  15726. var stringsUnicode = [];
  15727. var i, ii, j, jj, str;
  15728. for (i = 0, ii = strings.length; i < ii; i++) {
  15729. str = proto[1][i] || strings[i];
  15730. var strBufUnicode = [];
  15731. for (j = 0, jj = str.length; j < jj; j++) {
  15732. strBufUnicode.push(string16(str.charCodeAt(j)));
  15733. }
  15734. stringsUnicode.push(strBufUnicode.join(''));
  15735. }
  15736. var names = [strings, stringsUnicode];
  15737. var platforms = ['\x00\x01', '\x00\x03'];
  15738. var encodings = ['\x00\x00', '\x00\x01'];
  15739. var languages = ['\x00\x00', '\x04\x09'];
  15740. var namesRecordCount = strings.length * platforms.length;
  15741. var nameTable =
  15742. '\x00\x00' + // format
  15743. string16(namesRecordCount) + // Number of names Record
  15744. string16(namesRecordCount * 12 + 6); // Storage
  15745. // Build the name records field
  15746. var strOffset = 0;
  15747. for (i = 0, ii = platforms.length; i < ii; i++) {
  15748. var strs = names[i];
  15749. for (j = 0, jj = strs.length; j < jj; j++) {
  15750. str = strs[j];
  15751. var nameRecord =
  15752. platforms[i] + // platform ID
  15753. encodings[i] + // encoding ID
  15754. languages[i] + // language ID
  15755. string16(j) + // name ID
  15756. string16(str.length) +
  15757. string16(strOffset);
  15758. nameTable += nameRecord;
  15759. strOffset += str.length;
  15760. }
  15761. }
  15762. nameTable += strings.join('') + stringsUnicode.join('');
  15763. return nameTable;
  15764. }
  15765. Font.prototype = {
  15766. name: null,
  15767. font: null,
  15768. mimetype: null,
  15769. encoding: null,
  15770. get renderer() {
  15771. var renderer = FontRendererFactory.create(this);
  15772. return shadow(this, 'renderer', renderer);
  15773. },
  15774. exportData: function Font_exportData() {
  15775. var data = {};
  15776. for (var i in this) {
  15777. if (this.hasOwnProperty(i)) {
  15778. data[i] = this[i];
  15779. }
  15780. }
  15781. return data;
  15782. },
  15783. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15784. function readTableEntry(file) {
  15785. var tag = bytesToString(file.getBytes(4));
  15786. var checksum = file.getInt32();
  15787. var offset = file.getInt32() >>> 0;
  15788. var length = file.getInt32() >>> 0;
  15789. // Read the table associated data
  15790. var previousPosition = file.pos;
  15791. file.pos = file.start ? file.start : 0;
  15792. file.skip(offset);
  15793. var data = file.getBytes(length);
  15794. file.pos = previousPosition;
  15795. if (tag === 'head') {
  15796. // clearing checksum adjustment
  15797. data[8] = data[9] = data[10] = data[11] = 0;
  15798. data[17] |= 0x20; //Set font optimized for cleartype flag
  15799. }
  15800. return {
  15801. tag: tag,
  15802. checksum: checksum,
  15803. length: length,
  15804. offset: offset,
  15805. data: data
  15806. };
  15807. }
  15808. function readOpenTypeHeader(ttf) {
  15809. return {
  15810. version: bytesToString(ttf.getBytes(4)),
  15811. numTables: ttf.getUint16(),
  15812. searchRange: ttf.getUint16(),
  15813. entrySelector: ttf.getUint16(),
  15814. rangeShift: ttf.getUint16()
  15815. };
  15816. }
  15817. /**
  15818. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15819. * PDF spec
  15820. */
  15821. function readCmapTable(cmap, font, isSymbolicFont) {
  15822. var segment;
  15823. var start = (font.start ? font.start : 0) + cmap.offset;
  15824. font.pos = start;
  15825. var version = font.getUint16();
  15826. var numTables = font.getUint16();
  15827. var potentialTable;
  15828. var canBreak = false;
  15829. // There's an order of preference in terms of which cmap subtable to
  15830. // use:
  15831. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15832. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15833. // The following takes advantage of the fact that the tables are sorted
  15834. // to work.
  15835. for (var i = 0; i < numTables; i++) {
  15836. var platformId = font.getUint16();
  15837. var encodingId = font.getUint16();
  15838. var offset = font.getInt32() >>> 0;
  15839. var useTable = false;
  15840. if (platformId === 1 && encodingId === 0) {
  15841. useTable = true;
  15842. // Continue the loop since there still may be a higher priority
  15843. // table.
  15844. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15845. useTable = true;
  15846. canBreak = true;
  15847. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15848. useTable = true;
  15849. canBreak = true;
  15850. }
  15851. if (useTable) {
  15852. potentialTable = {
  15853. platformId: platformId,
  15854. encodingId: encodingId,
  15855. offset: offset
  15856. };
  15857. }
  15858. if (canBreak) {
  15859. break;
  15860. }
  15861. }
  15862. if (!potentialTable) {
  15863. warn('Could not find a preferred cmap table.');
  15864. return {
  15865. platformId: -1,
  15866. encodingId: -1,
  15867. mappings: [],
  15868. hasShortCmap: false
  15869. };
  15870. }
  15871. font.pos = start + potentialTable.offset;
  15872. var format = font.getUint16();
  15873. var length = font.getUint16();
  15874. var language = font.getUint16();
  15875. var hasShortCmap = false;
  15876. var mappings = [];
  15877. var j, glyphId;
  15878. // TODO(mack): refactor this cmap subtable reading logic out
  15879. if (format === 0) {
  15880. for (j = 0; j < 256; j++) {
  15881. var index = font.getByte();
  15882. if (!index) {
  15883. continue;
  15884. }
  15885. mappings.push({
  15886. charCode: j,
  15887. glyphId: index
  15888. });
  15889. }
  15890. hasShortCmap = true;
  15891. } else if (format === 4) {
  15892. // re-creating the table in format 4 since the encoding
  15893. // might be changed
  15894. var segCount = (font.getUint16() >> 1);
  15895. font.getBytes(6); // skipping range fields
  15896. var segIndex, segments = [];
  15897. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15898. segments.push({ end: font.getUint16() });
  15899. }
  15900. font.getUint16();
  15901. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15902. segments[segIndex].start = font.getUint16();
  15903. }
  15904. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15905. segments[segIndex].delta = font.getUint16();
  15906. }
  15907. var offsetsCount = 0;
  15908. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15909. segment = segments[segIndex];
  15910. var rangeOffset = font.getUint16();
  15911. if (!rangeOffset) {
  15912. segment.offsetIndex = -1;
  15913. continue;
  15914. }
  15915. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15916. segment.offsetIndex = offsetIndex;
  15917. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15918. segment.end - segment.start + 1);
  15919. }
  15920. var offsets = [];
  15921. for (j = 0; j < offsetsCount; j++) {
  15922. offsets.push(font.getUint16());
  15923. }
  15924. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15925. segment = segments[segIndex];
  15926. start = segment.start;
  15927. var end = segment.end;
  15928. var delta = segment.delta;
  15929. offsetIndex = segment.offsetIndex;
  15930. for (j = start; j <= end; j++) {
  15931. if (j === 0xFFFF) {
  15932. continue;
  15933. }
  15934. glyphId = (offsetIndex < 0 ?
  15935. j : offsets[offsetIndex + j - start]);
  15936. glyphId = (glyphId + delta) & 0xFFFF;
  15937. if (glyphId === 0) {
  15938. continue;
  15939. }
  15940. mappings.push({
  15941. charCode: j,
  15942. glyphId: glyphId
  15943. });
  15944. }
  15945. }
  15946. } else if (format === 6) {
  15947. // Format 6 is a 2-bytes dense mapping, which means the font data
  15948. // lives glue together even if they are pretty far in the unicode
  15949. // table. (This looks weird, so I can have missed something), this
  15950. // works on Linux but seems to fails on Mac so let's rewrite the
  15951. // cmap table to a 3-1-4 style
  15952. var firstCode = font.getUint16();
  15953. var entryCount = font.getUint16();
  15954. for (j = 0; j < entryCount; j++) {
  15955. glyphId = font.getUint16();
  15956. var charCode = firstCode + j;
  15957. mappings.push({
  15958. charCode: charCode,
  15959. glyphId: glyphId
  15960. });
  15961. }
  15962. } else {
  15963. error('cmap table has unsupported format: ' + format);
  15964. }
  15965. // removing duplicate entries
  15966. mappings.sort(function (a, b) {
  15967. return a.charCode - b.charCode;
  15968. });
  15969. for (i = 1; i < mappings.length; i++) {
  15970. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15971. mappings.splice(i, 1);
  15972. i--;
  15973. }
  15974. }
  15975. return {
  15976. platformId: potentialTable.platformId,
  15977. encodingId: potentialTable.encodingId,
  15978. mappings: mappings,
  15979. hasShortCmap: hasShortCmap
  15980. };
  15981. }
  15982. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15983. if (!header) {
  15984. if (metrics) {
  15985. metrics.data = null;
  15986. }
  15987. return;
  15988. }
  15989. font.pos = (font.start ? font.start : 0) + header.offset;
  15990. font.pos += header.length - 2;
  15991. var numOfMetrics = font.getUint16();
  15992. if (numOfMetrics > numGlyphs) {
  15993. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15994. 'greater than the numGlyphs (' + numGlyphs + ')');
  15995. // Reduce numOfMetrics if it is greater than numGlyphs
  15996. numOfMetrics = numGlyphs;
  15997. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  15998. header.data[35] = numOfMetrics & 0x00ff;
  15999. }
  16000. var numOfSidebearings = numGlyphs - numOfMetrics;
  16001. var numMissing = numOfSidebearings -
  16002. ((metrics.length - numOfMetrics * 4) >> 1);
  16003. if (numMissing > 0) {
  16004. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16005. // Since we need to add two properties for each glyph, this explains
  16006. // the use of |numMissing * 2| when initializing the typed array.
  16007. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16008. entries.set(metrics.data);
  16009. metrics.data = entries;
  16010. }
  16011. }
  16012. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16013. hintsValid) {
  16014. if (sourceEnd - sourceStart <= 12) {
  16015. // glyph with data less than 12 is invalid one
  16016. return 0;
  16017. }
  16018. var glyf = source.subarray(sourceStart, sourceEnd);
  16019. var contoursCount = (glyf[0] << 8) | glyf[1];
  16020. if (contoursCount & 0x8000) {
  16021. // complex glyph, writing as is
  16022. dest.set(glyf, destStart);
  16023. return glyf.length;
  16024. }
  16025. var i, j = 10, flagsCount = 0;
  16026. for (i = 0; i < contoursCount; i++) {
  16027. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16028. flagsCount = endPoint + 1;
  16029. j += 2;
  16030. }
  16031. // skipping instructions
  16032. var instructionsStart = j;
  16033. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16034. j += 2 + instructionsLength;
  16035. var instructionsEnd = j;
  16036. // validating flags
  16037. var coordinatesLength = 0;
  16038. for (i = 0; i < flagsCount; i++) {
  16039. var flag = glyf[j++];
  16040. if (flag & 0xC0) {
  16041. // reserved flags must be zero, cleaning up
  16042. glyf[j - 1] = flag & 0x3F;
  16043. }
  16044. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16045. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16046. coordinatesLength += xyLength;
  16047. if (flag & 8) {
  16048. var repeat = glyf[j++];
  16049. i += repeat;
  16050. coordinatesLength += repeat * xyLength;
  16051. }
  16052. }
  16053. // glyph without coordinates will be rejected
  16054. if (coordinatesLength === 0) {
  16055. return 0;
  16056. }
  16057. var glyphDataLength = j + coordinatesLength;
  16058. if (glyphDataLength > glyf.length) {
  16059. // not enough data for coordinates
  16060. return 0;
  16061. }
  16062. if (!hintsValid && instructionsLength > 0) {
  16063. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16064. dest.set([0, 0], destStart + instructionsStart);
  16065. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16066. destStart + instructionsStart + 2);
  16067. glyphDataLength -= instructionsLength;
  16068. if (glyf.length - glyphDataLength > 3) {
  16069. glyphDataLength = (glyphDataLength + 3) & ~3;
  16070. }
  16071. return glyphDataLength;
  16072. }
  16073. if (glyf.length - glyphDataLength > 3) {
  16074. // truncating and aligning to 4 bytes the long glyph data
  16075. glyphDataLength = (glyphDataLength + 3) & ~3;
  16076. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16077. return glyphDataLength;
  16078. }
  16079. // glyph data is fine
  16080. dest.set(glyf, destStart);
  16081. return glyf.length;
  16082. }
  16083. function sanitizeHead(head, numGlyphs, locaLength) {
  16084. var data = head.data;
  16085. // Validate version:
  16086. // Should always be 0x00010000
  16087. var version = int32(data[0], data[1], data[2], data[3]);
  16088. if (version >> 16 !== 1) {
  16089. info('Attempting to fix invalid version in head table: ' + version);
  16090. data[0] = 0;
  16091. data[1] = 1;
  16092. data[2] = 0;
  16093. data[3] = 0;
  16094. }
  16095. var indexToLocFormat = int16(data[50], data[51]);
  16096. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16097. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16098. indexToLocFormat);
  16099. // The value of indexToLocFormat should be 0 if the loca table
  16100. // consists of short offsets, and should be 1 if the loca table
  16101. // consists of long offsets.
  16102. //
  16103. // The number of entries in the loca table should be numGlyphs + 1.
  16104. //
  16105. // Using this information, we can work backwards to deduce if the
  16106. // size of each offset in the loca table, and thus figure out the
  16107. // appropriate value for indexToLocFormat.
  16108. var numGlyphsPlusOne = numGlyphs + 1;
  16109. if (locaLength === numGlyphsPlusOne << 1) {
  16110. // 0x0000 indicates the loca table consists of short offsets
  16111. data[50] = 0;
  16112. data[51] = 0;
  16113. } else if (locaLength === numGlyphsPlusOne << 2) {
  16114. // 0x0001 indicates the loca table consists of long offsets
  16115. data[50] = 0;
  16116. data[51] = 1;
  16117. } else {
  16118. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16119. }
  16120. }
  16121. }
  16122. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16123. isGlyphLocationsLong, hintsValid,
  16124. dupFirstEntry) {
  16125. var itemSize, itemDecode, itemEncode;
  16126. if (isGlyphLocationsLong) {
  16127. itemSize = 4;
  16128. itemDecode = function fontItemDecodeLong(data, offset) {
  16129. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16130. (data[offset + 2] << 8) | data[offset + 3];
  16131. };
  16132. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16133. data[offset] = (value >>> 24) & 0xFF;
  16134. data[offset + 1] = (value >> 16) & 0xFF;
  16135. data[offset + 2] = (value >> 8) & 0xFF;
  16136. data[offset + 3] = value & 0xFF;
  16137. };
  16138. } else {
  16139. itemSize = 2;
  16140. itemDecode = function fontItemDecode(data, offset) {
  16141. return (data[offset] << 9) | (data[offset + 1] << 1);
  16142. };
  16143. itemEncode = function fontItemEncode(data, offset, value) {
  16144. data[offset] = (value >> 9) & 0xFF;
  16145. data[offset + 1] = (value >> 1) & 0xFF;
  16146. };
  16147. }
  16148. var locaData = loca.data;
  16149. var locaDataSize = itemSize * (1 + numGlyphs);
  16150. // is loca.data too short or long?
  16151. if (locaData.length !== locaDataSize) {
  16152. locaData = new Uint8Array(locaDataSize);
  16153. locaData.set(loca.data.subarray(0, locaDataSize));
  16154. loca.data = locaData;
  16155. }
  16156. // removing the invalid glyphs
  16157. var oldGlyfData = glyf.data;
  16158. var oldGlyfDataLength = oldGlyfData.length;
  16159. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16160. var startOffset = itemDecode(locaData, 0);
  16161. var writeOffset = 0;
  16162. itemEncode(locaData, 0, writeOffset);
  16163. var i, j;
  16164. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16165. var endOffset = itemDecode(locaData, j);
  16166. if (endOffset > oldGlyfDataLength &&
  16167. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16168. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16169. // the glyf table size, which makes last glyph out of range.
  16170. endOffset = oldGlyfDataLength;
  16171. }
  16172. if (endOffset > oldGlyfDataLength) {
  16173. // glyph end offset points outside glyf data, rejecting the glyph
  16174. itemEncode(locaData, j, writeOffset);
  16175. startOffset = endOffset;
  16176. continue;
  16177. }
  16178. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16179. newGlyfData, writeOffset, hintsValid);
  16180. writeOffset += newLength;
  16181. itemEncode(locaData, j, writeOffset);
  16182. startOffset = endOffset;
  16183. }
  16184. if (writeOffset === 0) {
  16185. // glyf table cannot be empty -- redoing the glyf and loca tables
  16186. // to have single glyph with one point
  16187. var simpleGlyph = new Uint8Array(
  16188. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16189. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16190. itemEncode(locaData, j, simpleGlyph.length);
  16191. }
  16192. glyf.data = simpleGlyph;
  16193. return;
  16194. }
  16195. if (dupFirstEntry) {
  16196. var firstEntryLength = itemDecode(locaData, itemSize);
  16197. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16198. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16199. } else {
  16200. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16201. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16202. }
  16203. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16204. itemEncode(loca.data, locaData.length - itemSize,
  16205. writeOffset + firstEntryLength);
  16206. } else {
  16207. glyf.data = newGlyfData.subarray(0, writeOffset);
  16208. }
  16209. }
  16210. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16211. var start = (font.start ? font.start : 0) + post.offset;
  16212. font.pos = start;
  16213. var length = post.length, end = start + length;
  16214. var version = font.getInt32();
  16215. // skip rest to the tables
  16216. font.getBytes(28);
  16217. var glyphNames;
  16218. var valid = true;
  16219. var i;
  16220. switch (version) {
  16221. case 0x00010000:
  16222. glyphNames = MacStandardGlyphOrdering;
  16223. break;
  16224. case 0x00020000:
  16225. var numGlyphs = font.getUint16();
  16226. if (numGlyphs !== maxpNumGlyphs) {
  16227. valid = false;
  16228. break;
  16229. }
  16230. var glyphNameIndexes = [];
  16231. for (i = 0; i < numGlyphs; ++i) {
  16232. var index = font.getUint16();
  16233. if (index >= 32768) {
  16234. valid = false;
  16235. break;
  16236. }
  16237. glyphNameIndexes.push(index);
  16238. }
  16239. if (!valid) {
  16240. break;
  16241. }
  16242. var customNames = [];
  16243. var strBuf = [];
  16244. while (font.pos < end) {
  16245. var stringLength = font.getByte();
  16246. strBuf.length = stringLength;
  16247. for (i = 0; i < stringLength; ++i) {
  16248. strBuf[i] = String.fromCharCode(font.getByte());
  16249. }
  16250. customNames.push(strBuf.join(''));
  16251. }
  16252. glyphNames = [];
  16253. for (i = 0; i < numGlyphs; ++i) {
  16254. var j = glyphNameIndexes[i];
  16255. if (j < 258) {
  16256. glyphNames.push(MacStandardGlyphOrdering[j]);
  16257. continue;
  16258. }
  16259. glyphNames.push(customNames[j - 258]);
  16260. }
  16261. break;
  16262. case 0x00030000:
  16263. break;
  16264. default:
  16265. warn('Unknown/unsupported post table version ' + version);
  16266. valid = false;
  16267. break;
  16268. }
  16269. properties.glyphNames = glyphNames;
  16270. return valid;
  16271. }
  16272. function readNameTable(nameTable) {
  16273. var start = (font.start ? font.start : 0) + nameTable.offset;
  16274. font.pos = start;
  16275. var names = [[], []];
  16276. var length = nameTable.length, end = start + length;
  16277. var format = font.getUint16();
  16278. var FORMAT_0_HEADER_LENGTH = 6;
  16279. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16280. // unsupported name table format or table "too" small
  16281. return names;
  16282. }
  16283. var numRecords = font.getUint16();
  16284. var stringsStart = font.getUint16();
  16285. var records = [];
  16286. var NAME_RECORD_LENGTH = 12;
  16287. var i, ii;
  16288. for (i = 0; i < numRecords &&
  16289. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16290. var r = {
  16291. platform: font.getUint16(),
  16292. encoding: font.getUint16(),
  16293. language: font.getUint16(),
  16294. name: font.getUint16(),
  16295. length: font.getUint16(),
  16296. offset: font.getUint16()
  16297. };
  16298. // using only Macintosh and Windows platform/encoding names
  16299. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16300. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16301. records.push(r);
  16302. }
  16303. }
  16304. for (i = 0, ii = records.length; i < ii; i++) {
  16305. var record = records[i];
  16306. var pos = start + stringsStart + record.offset;
  16307. if (pos + record.length > end) {
  16308. continue; // outside of name table, ignoring
  16309. }
  16310. font.pos = pos;
  16311. var nameIndex = record.name;
  16312. if (record.encoding) {
  16313. // unicode
  16314. var str = '';
  16315. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16316. str += String.fromCharCode(font.getUint16());
  16317. }
  16318. names[1][nameIndex] = str;
  16319. } else {
  16320. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16321. }
  16322. }
  16323. return names;
  16324. }
  16325. var TTOpsStackDeltas = [
  16326. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16327. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16328. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16329. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16330. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16331. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16332. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16333. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16334. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16335. // 0xC0-DF == -1 and 0xE0-FF == -2
  16336. function sanitizeTTProgram(table, ttContext) {
  16337. var data = table.data;
  16338. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16339. var stack = [];
  16340. var callstack = [];
  16341. var functionsCalled = [];
  16342. var tooComplexToFollowFunctions =
  16343. ttContext.tooComplexToFollowFunctions;
  16344. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16345. for (var ii = data.length; i < ii;) {
  16346. var op = data[i++];
  16347. // The TrueType instruction set docs can be found at
  16348. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16349. if (op === 0x40) { // NPUSHB - pushes n bytes
  16350. n = data[i++];
  16351. if (inFDEF || inELSE) {
  16352. i += n;
  16353. } else {
  16354. for (j = 0; j < n; j++) {
  16355. stack.push(data[i++]);
  16356. }
  16357. }
  16358. } else if (op === 0x41) { // NPUSHW - pushes n words
  16359. n = data[i++];
  16360. if (inFDEF || inELSE) {
  16361. i += n * 2;
  16362. } else {
  16363. for (j = 0; j < n; j++) {
  16364. b = data[i++];
  16365. stack.push((b << 8) | data[i++]);
  16366. }
  16367. }
  16368. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16369. n = op - 0xB0 + 1;
  16370. if (inFDEF || inELSE) {
  16371. i += n;
  16372. } else {
  16373. for (j = 0; j < n; j++) {
  16374. stack.push(data[i++]);
  16375. }
  16376. }
  16377. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16378. n = op - 0xB8 + 1;
  16379. if (inFDEF || inELSE) {
  16380. i += n * 2;
  16381. } else {
  16382. for (j = 0; j < n; j++) {
  16383. b = data[i++];
  16384. stack.push((b << 8) | data[i++]);
  16385. }
  16386. }
  16387. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16388. if (!inFDEF && !inELSE) {
  16389. // collecting inforamtion about which functions are used
  16390. funcId = stack[stack.length - 1];
  16391. ttContext.functionsUsed[funcId] = true;
  16392. if (funcId in ttContext.functionsStackDeltas) {
  16393. stack.length += ttContext.functionsStackDeltas[funcId];
  16394. } else if (funcId in ttContext.functionsDefined &&
  16395. functionsCalled.indexOf(funcId) < 0) {
  16396. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16397. functionsCalled.push(funcId);
  16398. pc = ttContext.functionsDefined[funcId];
  16399. if (!pc) {
  16400. warn('TT: CALL non-existent function');
  16401. ttContext.hintsValid = false;
  16402. return;
  16403. }
  16404. data = pc.data;
  16405. i = pc.i;
  16406. }
  16407. }
  16408. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16409. if (inFDEF || inELSE) {
  16410. warn('TT: nested FDEFs not allowed');
  16411. tooComplexToFollowFunctions = true;
  16412. }
  16413. inFDEF = true;
  16414. // collecting inforamtion about which functions are defined
  16415. lastDeff = i;
  16416. funcId = stack.pop();
  16417. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16418. } else if (op === 0x2D) { // ENDF - end of function
  16419. if (inFDEF) {
  16420. inFDEF = false;
  16421. lastEndf = i;
  16422. } else {
  16423. pc = callstack.pop();
  16424. if (!pc) {
  16425. warn('TT: ENDF bad stack');
  16426. ttContext.hintsValid = false;
  16427. return;
  16428. }
  16429. funcId = functionsCalled.pop();
  16430. data = pc.data;
  16431. i = pc.i;
  16432. ttContext.functionsStackDeltas[funcId] =
  16433. stack.length - pc.stackTop;
  16434. }
  16435. } else if (op === 0x89) { // IDEF - instruction definition
  16436. if (inFDEF || inELSE) {
  16437. warn('TT: nested IDEFs not allowed');
  16438. tooComplexToFollowFunctions = true;
  16439. }
  16440. inFDEF = true;
  16441. // recording it as a function to track ENDF
  16442. lastDeff = i;
  16443. } else if (op === 0x58) { // IF
  16444. ++ifLevel;
  16445. } else if (op === 0x1B) { // ELSE
  16446. inELSE = ifLevel;
  16447. } else if (op === 0x59) { // EIF
  16448. if (inELSE === ifLevel) {
  16449. inELSE = 0;
  16450. }
  16451. --ifLevel;
  16452. } else if (op === 0x1C) { // JMPR
  16453. if (!inFDEF && !inELSE) {
  16454. var offset = stack[stack.length - 1];
  16455. // only jumping forward to prevent infinite loop
  16456. if (offset > 0) {
  16457. i += offset - 1;
  16458. }
  16459. }
  16460. }
  16461. // Adjusting stack not extactly, but just enough to get function id
  16462. if (!inFDEF && !inELSE) {
  16463. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16464. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16465. if (op >= 0x71 && op <= 0x75) {
  16466. n = stack.pop();
  16467. if (n === n) {
  16468. stackDelta = -n * 2;
  16469. }
  16470. }
  16471. while (stackDelta < 0 && stack.length > 0) {
  16472. stack.pop();
  16473. stackDelta++;
  16474. }
  16475. while (stackDelta > 0) {
  16476. stack.push(NaN); // pushing any number into stack
  16477. stackDelta--;
  16478. }
  16479. }
  16480. }
  16481. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16482. var content = [data];
  16483. if (i > data.length) {
  16484. content.push(new Uint8Array(i - data.length));
  16485. }
  16486. if (lastDeff > lastEndf) {
  16487. warn('TT: complementing a missing function tail');
  16488. // new function definition started, but not finished
  16489. // complete function by [CLEAR, ENDF]
  16490. content.push(new Uint8Array([0x22, 0x2D]));
  16491. }
  16492. foldTTTable(table, content);
  16493. }
  16494. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16495. if (ttContext.tooComplexToFollowFunctions) {
  16496. return;
  16497. }
  16498. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16499. warn('TT: more functions defined than expected');
  16500. ttContext.hintsValid = false;
  16501. return;
  16502. }
  16503. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16504. if (j > maxFunctionDefs) {
  16505. warn('TT: invalid function id: ' + j);
  16506. ttContext.hintsValid = false;
  16507. return;
  16508. }
  16509. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16510. warn('TT: undefined function: ' + j);
  16511. ttContext.hintsValid = false;
  16512. return;
  16513. }
  16514. }
  16515. }
  16516. function foldTTTable(table, content) {
  16517. if (content.length > 1) {
  16518. // concatenating the content items
  16519. var newLength = 0;
  16520. var j, jj;
  16521. for (j = 0, jj = content.length; j < jj; j++) {
  16522. newLength += content[j].length;
  16523. }
  16524. newLength = (newLength + 3) & ~3;
  16525. var result = new Uint8Array(newLength);
  16526. var pos = 0;
  16527. for (j = 0, jj = content.length; j < jj; j++) {
  16528. result.set(content[j], pos);
  16529. pos += content[j].length;
  16530. }
  16531. table.data = result;
  16532. table.length = newLength;
  16533. }
  16534. }
  16535. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16536. var ttContext = {
  16537. functionsDefined: [],
  16538. functionsUsed: [],
  16539. functionsStackDeltas: [],
  16540. tooComplexToFollowFunctions: false,
  16541. hintsValid: true
  16542. };
  16543. if (fpgm) {
  16544. sanitizeTTProgram(fpgm, ttContext);
  16545. }
  16546. if (prep) {
  16547. sanitizeTTProgram(prep, ttContext);
  16548. }
  16549. if (fpgm) {
  16550. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16551. }
  16552. if (cvt && (cvt.length & 1)) {
  16553. var cvtData = new Uint8Array(cvt.length + 1);
  16554. cvtData.set(cvt.data);
  16555. cvt.data = cvtData;
  16556. }
  16557. return ttContext.hintsValid;
  16558. }
  16559. // The following steps modify the original font data, making copy
  16560. font = new Stream(new Uint8Array(font.getBytes()));
  16561. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16562. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16563. var header = readOpenTypeHeader(font);
  16564. var numTables = header.numTables;
  16565. var cff, cffFile;
  16566. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16567. hmtx: null, maxp: null, name: null, post: null };
  16568. var table;
  16569. for (var i = 0; i < numTables; i++) {
  16570. table = readTableEntry(font);
  16571. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16572. continue; // skipping table if it's not a required or optional table
  16573. }
  16574. if (table.length === 0) {
  16575. continue; // skipping empty tables
  16576. }
  16577. tables[table.tag] = table;
  16578. }
  16579. var isTrueType = !tables['CFF '];
  16580. if (!isTrueType) {
  16581. // OpenType font
  16582. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16583. // no major tables: throwing everything at CFFFont
  16584. cffFile = new Stream(tables['CFF '].data);
  16585. cff = new CFFFont(cffFile, properties);
  16586. return this.convert(name, cff, properties);
  16587. }
  16588. delete tables.glyf;
  16589. delete tables.loca;
  16590. delete tables.fpgm;
  16591. delete tables.prep;
  16592. delete tables['cvt '];
  16593. this.isOpenType = true;
  16594. } else {
  16595. if (!tables.glyf || !tables.loca) {
  16596. error('Required "glyf" or "loca" tables are not found');
  16597. }
  16598. this.isOpenType = false;
  16599. }
  16600. if (!tables.maxp) {
  16601. error('Required "maxp" table is not found');
  16602. }
  16603. font.pos = (font.start || 0) + tables.maxp.offset;
  16604. var version = font.getInt32();
  16605. var numGlyphs = font.getUint16();
  16606. var maxFunctionDefs = 0;
  16607. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16608. // maxZones can be invalid
  16609. font.pos += 8;
  16610. var maxZones = font.getUint16();
  16611. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16612. tables.maxp.data[14] = 0;
  16613. tables.maxp.data[15] = 2;
  16614. }
  16615. font.pos += 4;
  16616. maxFunctionDefs = font.getUint16();
  16617. }
  16618. var dupFirstEntry = false;
  16619. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16620. properties.toUnicode.get(0) > '\u0000') {
  16621. // oracle's defect (see 3427), duplicating first entry
  16622. dupFirstEntry = true;
  16623. numGlyphs++;
  16624. tables.maxp.data[4] = numGlyphs >> 8;
  16625. tables.maxp.data[5] = numGlyphs & 255;
  16626. }
  16627. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16628. tables['cvt '], maxFunctionDefs);
  16629. if (!hintsValid) {
  16630. delete tables.fpgm;
  16631. delete tables.prep;
  16632. delete tables['cvt '];
  16633. }
  16634. // Ensure the hmtx table contains the advance width and
  16635. // sidebearings information for numGlyphs in the maxp table
  16636. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16637. if (!tables.head) {
  16638. error('Required "head" table is not found');
  16639. }
  16640. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16641. if (isTrueType) {
  16642. var isGlyphLocationsLong = int16(tables.head.data[50],
  16643. tables.head.data[51]);
  16644. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16645. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16646. }
  16647. if (!tables.hhea) {
  16648. error('Required "hhea" table is not found');
  16649. }
  16650. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16651. // Sometimes it's 0. That needs to be fixed
  16652. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16653. tables.hhea.data[10] = 0xFF;
  16654. tables.hhea.data[11] = 0xFF;
  16655. }
  16656. // The 'post' table has glyphs names.
  16657. if (tables.post) {
  16658. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16659. if (!valid) {
  16660. tables.post = null;
  16661. }
  16662. }
  16663. var charCodeToGlyphId = [], charCode;
  16664. if (properties.type === 'CIDFontType2') {
  16665. var cidToGidMap = properties.cidToGidMap || [];
  16666. var cidToGidMapLength = cidToGidMap.length;
  16667. properties.cMap.forEach(function(charCode, cid) {
  16668. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16669. var glyphId = -1;
  16670. if (cidToGidMapLength === 0) {
  16671. glyphId = charCode;
  16672. } else if (cidToGidMap[cid] !== undefined) {
  16673. glyphId = cidToGidMap[cid];
  16674. }
  16675. if (glyphId >= 0 && glyphId < numGlyphs) {
  16676. charCodeToGlyphId[charCode] = glyphId;
  16677. }
  16678. });
  16679. if (dupFirstEntry) {
  16680. charCodeToGlyphId[0] = numGlyphs - 1;
  16681. }
  16682. } else {
  16683. // Most of the following logic in this code branch is based on the
  16684. // 9.6.6.4 of the PDF spec.
  16685. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16686. var cmapPlatformId = cmapTable.platformId;
  16687. var cmapEncodingId = cmapTable.encodingId;
  16688. var cmapMappings = cmapTable.mappings;
  16689. var cmapMappingsLength = cmapMappings.length;
  16690. var hasEncoding = properties.differences.length ||
  16691. !!properties.baseEncodingName;
  16692. // The spec seems to imply that if the font is symbolic the encoding
  16693. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16694. // where the the font is symbolic and it has an encoding.
  16695. if (hasEncoding &&
  16696. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16697. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16698. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16699. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16700. // When no preferred cmap table was found and |baseEncodingName| is
  16701. // one of the predefined encodings, we seem to obtain a better
  16702. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16703. // TODO: Note that this is a hack which should be removed as soon as
  16704. // we have proper support for more exotic cmap tables.
  16705. var baseEncoding = [];
  16706. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16707. properties.baseEncodingName === 'WinAnsiEncoding') {
  16708. baseEncoding = Encodings[properties.baseEncodingName];
  16709. }
  16710. for (charCode = 0; charCode < 256; charCode++) {
  16711. var glyphName;
  16712. if (this.differences && charCode in this.differences) {
  16713. glyphName = this.differences[charCode];
  16714. } else if (charCode in baseEncoding &&
  16715. baseEncoding[charCode] !== '') {
  16716. glyphName = baseEncoding[charCode];
  16717. } else {
  16718. glyphName = Encodings.StandardEncoding[charCode];
  16719. }
  16720. if (!glyphName) {
  16721. continue;
  16722. }
  16723. var unicodeOrCharCode;
  16724. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16725. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16726. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16727. // TODO: the encoding needs to be updated with mac os table.
  16728. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16729. }
  16730. var found = false;
  16731. for (i = 0; i < cmapMappingsLength; ++i) {
  16732. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16733. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16734. found = true;
  16735. break;
  16736. }
  16737. }
  16738. if (!found && properties.glyphNames) {
  16739. // Try to map using the post table. There are currently no known
  16740. // pdfs that this fixes.
  16741. var glyphId = properties.glyphNames.indexOf(glyphName);
  16742. if (glyphId > 0) {
  16743. charCodeToGlyphId[charCode] = glyphId;
  16744. }
  16745. }
  16746. }
  16747. } else {
  16748. // For (3, 0) cmap tables:
  16749. // The charcode key being stored in charCodeToGlyphId is the lower
  16750. // byte of the two-byte charcodes of the cmap table since according to
  16751. // the spec: 'each byte from the string shall be prepended with the
  16752. // high byte of the range [of charcodes in the cmap table], to form
  16753. // a two-byte character, which shall be used to select the
  16754. // associated glyph description from the subtable'.
  16755. //
  16756. // For (1, 0) cmap tables:
  16757. // 'single bytes from the string shall be used to look up the
  16758. // associated glyph descriptions from the subtable'. This means
  16759. // charcodes in the cmap will be single bytes, so no-op since
  16760. // glyph.charCode & 0xFF === glyph.charCode
  16761. for (i = 0; i < cmapMappingsLength; ++i) {
  16762. charCode = cmapMappings[i].charCode & 0xFF;
  16763. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16764. }
  16765. }
  16766. }
  16767. if (charCodeToGlyphId.length === 0) {
  16768. // defines at least one glyph
  16769. charCodeToGlyphId[0] = 0;
  16770. }
  16771. // Converting glyphs and ids into font's cmap table
  16772. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16773. this.toFontChar = newMapping.toFontChar;
  16774. tables.cmap = {
  16775. tag: 'cmap',
  16776. data: createCmapTable(newMapping.charCodeToGlyphId)
  16777. };
  16778. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16779. // extract some more font properties from the OpenType head and
  16780. // hhea tables; yMin and descent value are always negative
  16781. var override = {
  16782. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16783. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16784. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16785. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16786. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16787. };
  16788. tables['OS/2'] = {
  16789. tag: 'OS/2',
  16790. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16791. override)
  16792. };
  16793. }
  16794. // Rewrite the 'post' table if needed
  16795. if (!tables.post) {
  16796. tables.post = {
  16797. tag: 'post',
  16798. data: createPostTable(properties)
  16799. };
  16800. }
  16801. if (!isTrueType) {
  16802. try {
  16803. // Trying to repair CFF file
  16804. cffFile = new Stream(tables['CFF '].data);
  16805. var parser = new CFFParser(cffFile, properties);
  16806. cff = parser.parse();
  16807. var compiler = new CFFCompiler(cff);
  16808. tables['CFF '].data = compiler.compile();
  16809. } catch (e) {
  16810. warn('Failed to compile font ' + properties.loadedName);
  16811. }
  16812. }
  16813. // Re-creating 'name' table
  16814. if (!tables.name) {
  16815. tables.name = {
  16816. tag: 'name',
  16817. data: createNameTable(this.name)
  16818. };
  16819. } else {
  16820. // ... using existing 'name' table as prototype
  16821. var namePrototype = readNameTable(tables.name);
  16822. tables.name.data = createNameTable(name, namePrototype);
  16823. }
  16824. var builder = new OpenTypeFileBuilder(header.version);
  16825. for (var tableTag in tables) {
  16826. builder.addTable(tableTag, tables[tableTag].data);
  16827. }
  16828. return builder.toArray();
  16829. },
  16830. convert: function Font_convert(fontName, font, properties) {
  16831. // TODO: Check the charstring widths to determine this.
  16832. properties.fixedPitch = false;
  16833. var mapping = font.getGlyphMapping(properties);
  16834. var newMapping = adjustMapping(mapping, properties);
  16835. this.toFontChar = newMapping.toFontChar;
  16836. var numGlyphs = font.numGlyphs;
  16837. function getCharCodes(charCodeToGlyphId, glyphId) {
  16838. var charCodes = null;
  16839. for (var charCode in charCodeToGlyphId) {
  16840. if (glyphId === charCodeToGlyphId[charCode]) {
  16841. if (!charCodes) {
  16842. charCodes = [];
  16843. }
  16844. charCodes.push(charCode | 0);
  16845. }
  16846. }
  16847. return charCodes;
  16848. }
  16849. function createCharCode(charCodeToGlyphId, glyphId) {
  16850. for (var charCode in charCodeToGlyphId) {
  16851. if (glyphId === charCodeToGlyphId[charCode]) {
  16852. return charCode | 0;
  16853. }
  16854. }
  16855. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16856. glyphId;
  16857. return newMapping.nextAvailableFontCharCode++;
  16858. }
  16859. var seacs = font.seacs;
  16860. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16861. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16862. var charset = font.getCharset();
  16863. var seacMap = Object.create(null);
  16864. for (var glyphId in seacs) {
  16865. glyphId |= 0;
  16866. var seac = seacs[glyphId];
  16867. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16868. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16869. var baseGlyphId = charset.indexOf(baseGlyphName);
  16870. var accentGlyphId = charset.indexOf(accentGlyphName);
  16871. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16872. continue;
  16873. }
  16874. var accentOffset = {
  16875. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16876. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16877. };
  16878. var charCodes = getCharCodes(mapping, glyphId);
  16879. if (!charCodes) {
  16880. // There's no point in mapping it if the char code was never mapped
  16881. // to begin with.
  16882. continue;
  16883. }
  16884. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16885. var charCode = charCodes[i];
  16886. // Find a fontCharCode that maps to the base and accent glyphs.
  16887. // If one doesn't exists, create it.
  16888. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16889. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16890. baseGlyphId);
  16891. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16892. accentGlyphId);
  16893. seacMap[charCode] = {
  16894. baseFontCharCode: baseFontCharCode,
  16895. accentFontCharCode: accentFontCharCode,
  16896. accentOffset: accentOffset
  16897. };
  16898. }
  16899. }
  16900. properties.seacMap = seacMap;
  16901. }
  16902. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16903. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16904. // PostScript Font Program
  16905. builder.addTable('CFF ', font.data);
  16906. // OS/2 and Windows Specific metrics
  16907. builder.addTable('OS/2', createOS2Table(properties,
  16908. newMapping.charCodeToGlyphId));
  16909. // Character to glyphs mapping
  16910. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16911. // Font header
  16912. builder.addTable('head',
  16913. '\x00\x01\x00\x00' + // Version number
  16914. '\x00\x00\x10\x00' + // fontRevision
  16915. '\x00\x00\x00\x00' + // checksumAdjustement
  16916. '\x5F\x0F\x3C\xF5' + // magicNumber
  16917. '\x00\x00' + // Flags
  16918. safeString16(unitsPerEm) + // unitsPerEM
  16919. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16920. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16921. '\x00\x00' + // xMin
  16922. safeString16(properties.descent) + // yMin
  16923. '\x0F\xFF' + // xMax
  16924. safeString16(properties.ascent) + // yMax
  16925. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16926. '\x00\x11' + // lowestRecPPEM
  16927. '\x00\x00' + // fontDirectionHint
  16928. '\x00\x00' + // indexToLocFormat
  16929. '\x00\x00'); // glyphDataFormat
  16930. // Horizontal header
  16931. builder.addTable('hhea',
  16932. '\x00\x01\x00\x00' + // Version number
  16933. safeString16(properties.ascent) + // Typographic Ascent
  16934. safeString16(properties.descent) + // Typographic Descent
  16935. '\x00\x00' + // Line Gap
  16936. '\xFF\xFF' + // advanceWidthMax
  16937. '\x00\x00' + // minLeftSidebearing
  16938. '\x00\x00' + // minRightSidebearing
  16939. '\x00\x00' + // xMaxExtent
  16940. safeString16(properties.capHeight) + // caretSlopeRise
  16941. safeString16(Math.tan(properties.italicAngle) *
  16942. properties.xHeight) + // caretSlopeRun
  16943. '\x00\x00' + // caretOffset
  16944. '\x00\x00' + // -reserved-
  16945. '\x00\x00' + // -reserved-
  16946. '\x00\x00' + // -reserved-
  16947. '\x00\x00' + // -reserved-
  16948. '\x00\x00' + // metricDataFormat
  16949. string16(numGlyphs)); // Number of HMetrics
  16950. // Horizontal metrics
  16951. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16952. var charstrings = font.charstrings;
  16953. var cffWidths = font.cff ? font.cff.widths : null;
  16954. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16955. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16956. var width = 0;
  16957. if (charstrings) {
  16958. var charstring = charstrings[i - 1];
  16959. width = 'width' in charstring ? charstring.width : 0;
  16960. } else if (cffWidths) {
  16961. width = Math.ceil(cffWidths[i] || 0);
  16962. }
  16963. hmtx += string16(width) + string16(0);
  16964. }
  16965. return hmtx;
  16966. })());
  16967. // Maximum profile
  16968. builder.addTable('maxp',
  16969. '\x00\x00\x50\x00' + // Version number
  16970. string16(numGlyphs)); // Num of glyphs
  16971. // Naming tables
  16972. builder.addTable('name', createNameTable(fontName));
  16973. // PostScript informations
  16974. builder.addTable('post', createPostTable(properties));
  16975. return builder.toArray();
  16976. },
  16977. /**
  16978. * Builds a char code to unicode map based on section 9.10 of the spec.
  16979. * @param {Object} properties Font properties object.
  16980. * @return {Object} A ToUnicodeMap object.
  16981. */
  16982. buildToUnicode: function Font_buildToUnicode(properties) {
  16983. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16984. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16985. return properties.toUnicode;
  16986. }
  16987. // According to the spec if the font is a simple font we should only map
  16988. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16989. // the differences array only contains adobe standard or symbol set names,
  16990. // in pratice it seems better to always try to create a toUnicode
  16991. // map based of the default encoding.
  16992. var toUnicode, charcode;
  16993. if (!properties.composite /* is simple font */) {
  16994. toUnicode = [];
  16995. var encoding = properties.defaultEncoding.slice();
  16996. var baseEncodingName = properties.baseEncodingName;
  16997. // Merge in the differences array.
  16998. var differences = properties.differences;
  16999. for (charcode in differences) {
  17000. encoding[charcode] = differences[charcode];
  17001. }
  17002. for (charcode in encoding) {
  17003. // a) Map the character code to a character name.
  17004. var glyphName = encoding[charcode];
  17005. // b) Look up the character name in the Adobe Glyph List (see the
  17006. // Bibliography) to obtain the corresponding Unicode value.
  17007. if (glyphName === '') {
  17008. continue;
  17009. } else if (GlyphsUnicode[glyphName] === undefined) {
  17010. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17011. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17012. var code = 0;
  17013. switch (glyphName[0]) {
  17014. case 'G': // Gxx glyph
  17015. if (glyphName.length === 3) {
  17016. code = parseInt(glyphName.substr(1), 16);
  17017. }
  17018. break;
  17019. case 'g': // g00xx glyph
  17020. if (glyphName.length === 5) {
  17021. code = parseInt(glyphName.substr(1), 16);
  17022. }
  17023. break;
  17024. case 'C': // Cddd glyph
  17025. case 'c': // cddd glyph
  17026. if (glyphName.length >= 3) {
  17027. code = +glyphName.substr(1);
  17028. }
  17029. break;
  17030. }
  17031. if (code) {
  17032. // If |baseEncodingName| is one the predefined encodings,
  17033. // and |code| equals |charcode|, using the glyph defined in the
  17034. // baseEncoding seems to yield a better |toUnicode| mapping
  17035. // (fixes issue 5070).
  17036. if (baseEncodingName && code === +charcode) {
  17037. var baseEncoding = Encodings[baseEncodingName];
  17038. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17039. toUnicode[charcode] =
  17040. String.fromCharCode(GlyphsUnicode[glyphName]);
  17041. continue;
  17042. }
  17043. }
  17044. toUnicode[charcode] = String.fromCharCode(code);
  17045. }
  17046. continue;
  17047. }
  17048. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17049. }
  17050. return new ToUnicodeMap(toUnicode);
  17051. }
  17052. // If the font is a composite font that uses one of the predefined CMaps
  17053. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17054. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17055. // Adobe-Korea1 character collection:
  17056. if (properties.composite && (
  17057. (properties.cMap.builtInCMap &&
  17058. !(properties.cMap instanceof IdentityCMap)) ||
  17059. (properties.cidSystemInfo.registry === 'Adobe' &&
  17060. (properties.cidSystemInfo.ordering === 'GB1' ||
  17061. properties.cidSystemInfo.ordering === 'CNS1' ||
  17062. properties.cidSystemInfo.ordering === 'Japan1' ||
  17063. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17064. // Then:
  17065. // a) Map the character code to a character identifier (CID) according
  17066. // to the font’s CMap.
  17067. // b) Obtain the registry and ordering of the character collection used
  17068. // by the font’s CMap (for example, Adobe and Japan1) from its
  17069. // CIDSystemInfo dictionary.
  17070. var registry = properties.cidSystemInfo.registry;
  17071. var ordering = properties.cidSystemInfo.ordering;
  17072. // c) Construct a second CMap name by concatenating the registry and
  17073. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17074. // (for example, Adobe–Japan1–UCS2).
  17075. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17076. // d) Obtain the CMap with the name constructed in step (c) (available
  17077. // from the ASN Web site; see the Bibliography).
  17078. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17079. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17080. var cMap = properties.cMap;
  17081. toUnicode = [];
  17082. cMap.forEach(function(charcode, cid) {
  17083. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17084. // e) Map the CID obtained in step (a) according to the CMap obtained
  17085. // in step (d), producing a Unicode value.
  17086. var ucs2 = ucs2CMap.lookup(cid);
  17087. if (ucs2) {
  17088. toUnicode[charcode] =
  17089. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17090. ucs2.charCodeAt(1));
  17091. }
  17092. });
  17093. return new ToUnicodeMap(toUnicode);
  17094. }
  17095. // The viewer's choice, just use an identity map.
  17096. return new IdentityToUnicodeMap(properties.firstChar,
  17097. properties.lastChar);
  17098. },
  17099. get spaceWidth() {
  17100. if ('_shadowWidth' in this) {
  17101. return this._shadowWidth;
  17102. }
  17103. // trying to estimate space character width
  17104. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17105. var width;
  17106. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17107. var glyphName = possibleSpaceReplacements[i];
  17108. // if possible, getting width by glyph name
  17109. if (glyphName in this.widths) {
  17110. width = this.widths[glyphName];
  17111. break;
  17112. }
  17113. var glyphUnicode = GlyphsUnicode[glyphName];
  17114. // finding the charcode via unicodeToCID map
  17115. var charcode = 0;
  17116. if (this.composite) {
  17117. if (this.cMap.contains(glyphUnicode)) {
  17118. charcode = this.cMap.lookup(glyphUnicode);
  17119. }
  17120. }
  17121. // ... via toUnicode map
  17122. if (!charcode && 'toUnicode' in this) {
  17123. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17124. }
  17125. // setting it to unicode if negative or undefined
  17126. if (charcode <= 0) {
  17127. charcode = glyphUnicode;
  17128. }
  17129. // trying to get width via charcode
  17130. width = this.widths[charcode];
  17131. if (width) {
  17132. break; // the non-zero width found
  17133. }
  17134. }
  17135. width = width || this.defaultWidth;
  17136. // Do not shadow the property here. See discussion:
  17137. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17138. this._shadowWidth = width;
  17139. return width;
  17140. },
  17141. charToGlyph: function Font_charToGlyph(charcode) {
  17142. var fontCharCode, width, operatorListId;
  17143. var widthCode = charcode;
  17144. if (this.cMap && this.cMap.contains(charcode)) {
  17145. widthCode = this.cMap.lookup(charcode);
  17146. }
  17147. width = this.widths[widthCode];
  17148. width = isNum(width) ? width : this.defaultWidth;
  17149. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17150. var unicode = this.toUnicode.get(charcode) || charcode;
  17151. if (typeof unicode === 'number') {
  17152. unicode = String.fromCharCode(unicode);
  17153. }
  17154. // First try the toFontChar map, if it's not there then try falling
  17155. // back to the char code.
  17156. fontCharCode = this.toFontChar[charcode] || charcode;
  17157. if (this.missingFile) {
  17158. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17159. }
  17160. if (this.isType3Font) {
  17161. // Font char code in this case is actually a glyph name.
  17162. operatorListId = fontCharCode;
  17163. }
  17164. var accent = null;
  17165. if (this.seacMap && this.seacMap[charcode]) {
  17166. var seac = this.seacMap[charcode];
  17167. fontCharCode = seac.baseFontCharCode;
  17168. accent = {
  17169. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17170. offset: seac.accentOffset
  17171. };
  17172. }
  17173. var fontChar = String.fromCharCode(fontCharCode);
  17174. var glyph = this.glyphCache[charcode];
  17175. if (!glyph ||
  17176. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17177. operatorListId)) {
  17178. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17179. operatorListId);
  17180. this.glyphCache[charcode] = glyph;
  17181. }
  17182. return glyph;
  17183. },
  17184. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17185. var charsCache = this.charsCache;
  17186. var glyphs, glyph, charcode;
  17187. // if we translated this string before, just grab it from the cache
  17188. if (charsCache) {
  17189. glyphs = charsCache[chars];
  17190. if (glyphs) {
  17191. return glyphs;
  17192. }
  17193. }
  17194. // lazily create the translation cache
  17195. if (!charsCache) {
  17196. charsCache = this.charsCache = Object.create(null);
  17197. }
  17198. glyphs = [];
  17199. var charsCacheKey = chars;
  17200. var i = 0, ii;
  17201. if (this.cMap) {
  17202. // composite fonts have multi-byte strings convert the string from
  17203. // single-byte to multi-byte
  17204. var c = {};
  17205. while (i < chars.length) {
  17206. this.cMap.readCharCode(chars, i, c);
  17207. charcode = c.charcode;
  17208. var length = c.length;
  17209. i += length;
  17210. glyph = this.charToGlyph(charcode);
  17211. glyphs.push(glyph);
  17212. // placing null after each word break charcode (ASCII SPACE)
  17213. // Ignore occurences of 0x20 in multiple-byte codes.
  17214. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17215. glyphs.push(null);
  17216. }
  17217. }
  17218. } else {
  17219. for (i = 0, ii = chars.length; i < ii; ++i) {
  17220. charcode = chars.charCodeAt(i);
  17221. glyph = this.charToGlyph(charcode);
  17222. glyphs.push(glyph);
  17223. if (charcode === 0x20) {
  17224. glyphs.push(null);
  17225. }
  17226. }
  17227. }
  17228. // Enter the translated string into the cache
  17229. return (charsCache[charsCacheKey] = glyphs);
  17230. }
  17231. };
  17232. return Font;
  17233. })();
  17234. var ErrorFont = (function ErrorFontClosure() {
  17235. function ErrorFont(error) {
  17236. this.error = error;
  17237. this.loadedName = 'g_font_error';
  17238. this.loading = false;
  17239. }
  17240. ErrorFont.prototype = {
  17241. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17242. return [];
  17243. },
  17244. exportData: function ErrorFont_exportData() {
  17245. return {error: this.error};
  17246. }
  17247. };
  17248. return ErrorFont;
  17249. })();
  17250. /**
  17251. * Shared logic for building a char code to glyph id mapping for Type1 and
  17252. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17253. * @param {Object} properties Font properties object.
  17254. * @param {Object} builtInEncoding The encoding contained within the actual font
  17255. * data.
  17256. * @param {Array} Array of glyph names where the index is the glyph ID.
  17257. * @returns {Object} A char code to glyph ID map.
  17258. */
  17259. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17260. var charCodeToGlyphId = Object.create(null);
  17261. var glyphId, charCode, baseEncoding;
  17262. if (properties.baseEncodingName) {
  17263. // If a valid base encoding name was used, the mapping is initialized with
  17264. // that.
  17265. baseEncoding = Encodings[properties.baseEncodingName];
  17266. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17267. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17268. if (glyphId >= 0) {
  17269. charCodeToGlyphId[charCode] = glyphId;
  17270. } else {
  17271. charCodeToGlyphId[charCode] = 0; // notdef
  17272. }
  17273. }
  17274. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17275. // For a symbolic font the encoding should be the fonts built-in
  17276. // encoding.
  17277. for (charCode in builtInEncoding) {
  17278. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17279. }
  17280. } else {
  17281. // For non-symbolic fonts that don't have a base encoding the standard
  17282. // encoding should be used.
  17283. baseEncoding = Encodings.StandardEncoding;
  17284. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17285. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17286. if (glyphId >= 0) {
  17287. charCodeToGlyphId[charCode] = glyphId;
  17288. } else {
  17289. charCodeToGlyphId[charCode] = 0; // notdef
  17290. }
  17291. }
  17292. }
  17293. // Lastly, merge in the differences.
  17294. var differences = properties.differences;
  17295. if (differences) {
  17296. for (charCode in differences) {
  17297. var glyphName = differences[charCode];
  17298. glyphId = glyphNames.indexOf(glyphName);
  17299. if (glyphId >= 0) {
  17300. charCodeToGlyphId[charCode] = glyphId;
  17301. } else {
  17302. charCodeToGlyphId[charCode] = 0; // notdef
  17303. }
  17304. }
  17305. }
  17306. return charCodeToGlyphId;
  17307. }
  17308. /*
  17309. * CharStrings are encoded following the the CharString Encoding sequence
  17310. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17311. * The value in a byte indicates a command, a number, or subsequent bytes
  17312. * that are to be interpreted in a special way.
  17313. *
  17314. * CharString Number Encoding:
  17315. * A CharString byte containing the values from 32 through 255 inclusive
  17316. * indicate an integer. These values are decoded in four ranges.
  17317. *
  17318. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17319. * indicate the integer v - 139. Thus, the integer values from -107 through
  17320. * 107 inclusive may be encoded in single byte.
  17321. *
  17322. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17323. * indicates an integer involving the next byte, w, according to the formula:
  17324. * [(v - 247) x 256] + w + 108
  17325. *
  17326. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17327. * indicates an integer involving the next byte, w, according to the formula:
  17328. * -[(v - 251) * 256] - w - 108
  17329. *
  17330. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17331. * are a two complement signed integer. The first of these bytes contains the
  17332. * highest order bits, the second byte contains the next higher order bits
  17333. * and the fourth byte contain the lowest order bits.
  17334. *
  17335. *
  17336. * CharString Command Encoding:
  17337. * CharStrings commands are encoded in 1 or 2 bytes.
  17338. *
  17339. * Single byte commands are encoded in 1 byte that contains a value between
  17340. * 0 and 31 inclusive.
  17341. * If a command byte contains the value 12, then the value in the next byte
  17342. * indicates a command. This "escape" mechanism allows many extra commands
  17343. * to be encoded and this encoding technique helps to minimize the length of
  17344. * the charStrings.
  17345. */
  17346. var Type1CharString = (function Type1CharStringClosure() {
  17347. var COMMAND_MAP = {
  17348. 'hstem': [1],
  17349. 'vstem': [3],
  17350. 'vmoveto': [4],
  17351. 'rlineto': [5],
  17352. 'hlineto': [6],
  17353. 'vlineto': [7],
  17354. 'rrcurveto': [8],
  17355. 'callsubr': [10],
  17356. 'flex': [12, 35],
  17357. 'drop' : [12, 18],
  17358. 'endchar': [14],
  17359. 'rmoveto': [21],
  17360. 'hmoveto': [22],
  17361. 'vhcurveto': [30],
  17362. 'hvcurveto': [31]
  17363. };
  17364. function Type1CharString() {
  17365. this.width = 0;
  17366. this.lsb = 0;
  17367. this.flexing = false;
  17368. this.output = [];
  17369. this.stack = [];
  17370. }
  17371. Type1CharString.prototype = {
  17372. convert: function Type1CharString_convert(encoded, subrs) {
  17373. var count = encoded.length;
  17374. var error = false;
  17375. var wx, sbx, subrNumber;
  17376. for (var i = 0; i < count; i++) {
  17377. var value = encoded[i];
  17378. if (value < 32) {
  17379. if (value === 12) {
  17380. value = (value << 8) + encoded[++i];
  17381. }
  17382. switch (value) {
  17383. case 1: // hstem
  17384. if (!HINTING_ENABLED) {
  17385. this.stack = [];
  17386. break;
  17387. }
  17388. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17389. break;
  17390. case 3: // vstem
  17391. if (!HINTING_ENABLED) {
  17392. this.stack = [];
  17393. break;
  17394. }
  17395. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17396. break;
  17397. case 4: // vmoveto
  17398. if (this.flexing) {
  17399. if (this.stack.length < 1) {
  17400. error = true;
  17401. break;
  17402. }
  17403. // Add the dx for flex and but also swap the values so they are
  17404. // the right order.
  17405. var dy = this.stack.pop();
  17406. this.stack.push(0, dy);
  17407. break;
  17408. }
  17409. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17410. break;
  17411. case 5: // rlineto
  17412. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17413. break;
  17414. case 6: // hlineto
  17415. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17416. break;
  17417. case 7: // vlineto
  17418. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17419. break;
  17420. case 8: // rrcurveto
  17421. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17422. break;
  17423. case 9: // closepath
  17424. // closepath is a Type1 command that does not take argument and is
  17425. // useless in Type2 and it can simply be ignored.
  17426. this.stack = [];
  17427. break;
  17428. case 10: // callsubr
  17429. if (this.stack.length < 1) {
  17430. error = true;
  17431. break;
  17432. }
  17433. subrNumber = this.stack.pop();
  17434. error = this.convert(subrs[subrNumber], subrs);
  17435. break;
  17436. case 11: // return
  17437. return error;
  17438. case 13: // hsbw
  17439. if (this.stack.length < 2) {
  17440. error = true;
  17441. break;
  17442. }
  17443. // To convert to type2 we have to move the width value to the
  17444. // first part of the charstring and then use hmoveto with lsb.
  17445. wx = this.stack.pop();
  17446. sbx = this.stack.pop();
  17447. this.lsb = sbx;
  17448. this.width = wx;
  17449. this.stack.push(wx, sbx);
  17450. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17451. break;
  17452. case 14: // endchar
  17453. this.output.push(COMMAND_MAP.endchar[0]);
  17454. break;
  17455. case 21: // rmoveto
  17456. if (this.flexing) {
  17457. break;
  17458. }
  17459. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17460. break;
  17461. case 22: // hmoveto
  17462. if (this.flexing) {
  17463. // Add the dy for flex.
  17464. this.stack.push(0);
  17465. break;
  17466. }
  17467. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17468. break;
  17469. case 30: // vhcurveto
  17470. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17471. break;
  17472. case 31: // hvcurveto
  17473. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17474. break;
  17475. case (12 << 8) + 0: // dotsection
  17476. // dotsection is a Type1 command to specify some hinting feature
  17477. // for dots that do not take a parameter and it can safely be
  17478. // ignored for Type2.
  17479. this.stack = [];
  17480. break;
  17481. case (12 << 8) + 1: // vstem3
  17482. if (!HINTING_ENABLED) {
  17483. this.stack = [];
  17484. break;
  17485. }
  17486. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17487. // multiple parameters, so instead of returning [vh]stem3 take a
  17488. // shortcut and return [vhstem] instead.
  17489. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17490. break;
  17491. case (12 << 8) + 2: // hstem3
  17492. if (!HINTING_ENABLED) {
  17493. this.stack = [];
  17494. break;
  17495. }
  17496. // See vstem3.
  17497. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17498. break;
  17499. case (12 << 8) + 6: // seac
  17500. // seac is like type 2's special endchar but it doesn't use the
  17501. // first argument asb, so remove it.
  17502. if (SEAC_ANALYSIS_ENABLED) {
  17503. this.seac = this.stack.splice(-4, 4);
  17504. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17505. } else {
  17506. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17507. }
  17508. break;
  17509. case (12 << 8) + 7: // sbw
  17510. if (this.stack.length < 4) {
  17511. error = true;
  17512. break;
  17513. }
  17514. // To convert to type2 we have to move the width value to the
  17515. // first part of the charstring and then use rmoveto with
  17516. // (dx, dy). The height argument will not be used for vmtx and
  17517. // vhea tables reconstruction -- ignoring it.
  17518. var wy = this.stack.pop();
  17519. wx = this.stack.pop();
  17520. var sby = this.stack.pop();
  17521. sbx = this.stack.pop();
  17522. this.lsb = sbx;
  17523. this.width = wx;
  17524. this.stack.push(wx, sbx, sby);
  17525. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17526. break;
  17527. case (12 << 8) + 12: // div
  17528. if (this.stack.length < 2) {
  17529. error = true;
  17530. break;
  17531. }
  17532. var num2 = this.stack.pop();
  17533. var num1 = this.stack.pop();
  17534. this.stack.push(num1 / num2);
  17535. break;
  17536. case (12 << 8) + 16: // callothersubr
  17537. if (this.stack.length < 2) {
  17538. error = true;
  17539. break;
  17540. }
  17541. subrNumber = this.stack.pop();
  17542. var numArgs = this.stack.pop();
  17543. if (subrNumber === 0 && numArgs === 3) {
  17544. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17545. this.stack.push(
  17546. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17547. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17548. flexArgs[4], // bcp2x
  17549. flexArgs[5], // bcp2y
  17550. flexArgs[6], // p2x
  17551. flexArgs[7], // p2y
  17552. flexArgs[8], // bcp3x
  17553. flexArgs[9], // bcp3y
  17554. flexArgs[10], // bcp4x
  17555. flexArgs[11], // bcp4y
  17556. flexArgs[12], // p3x
  17557. flexArgs[13], // p3y
  17558. flexArgs[14] // flexDepth
  17559. // 15 = finalx unused by flex
  17560. // 16 = finaly unused by flex
  17561. );
  17562. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17563. this.flexing = false;
  17564. this.stack.push(flexArgs[15], flexArgs[16]);
  17565. } else if (subrNumber === 1 && numArgs === 0) {
  17566. this.flexing = true;
  17567. }
  17568. break;
  17569. case (12 << 8) + 17: // pop
  17570. // Ignore this since it is only used with othersubr.
  17571. break;
  17572. case (12 << 8) + 33: // setcurrentpoint
  17573. // Ignore for now.
  17574. this.stack = [];
  17575. break;
  17576. default:
  17577. warn('Unknown type 1 charstring command of "' + value + '"');
  17578. break;
  17579. }
  17580. if (error) {
  17581. break;
  17582. }
  17583. continue;
  17584. } else if (value <= 246) {
  17585. value = value - 139;
  17586. } else if (value <= 250) {
  17587. value = ((value - 247) * 256) + encoded[++i] + 108;
  17588. } else if (value <= 254) {
  17589. value = -((value - 251) * 256) - encoded[++i] - 108;
  17590. } else {
  17591. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17592. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17593. }
  17594. this.stack.push(value);
  17595. }
  17596. return error;
  17597. },
  17598. executeCommand: function(howManyArgs, command, keepStack) {
  17599. var stackLength = this.stack.length;
  17600. if (howManyArgs > stackLength) {
  17601. return true;
  17602. }
  17603. var start = stackLength - howManyArgs;
  17604. for (var i = start; i < stackLength; i++) {
  17605. var value = this.stack[i];
  17606. if (value === (value | 0)) { // int
  17607. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17608. } else { // fixed point
  17609. value = (65536 * value) | 0;
  17610. this.output.push(255,
  17611. (value >> 24) & 0xFF,
  17612. (value >> 16) & 0xFF,
  17613. (value >> 8) & 0xFF,
  17614. value & 0xFF);
  17615. }
  17616. }
  17617. this.output.push.apply(this.output, command);
  17618. if (keepStack) {
  17619. this.stack.splice(start, howManyArgs);
  17620. } else {
  17621. this.stack.length = 0;
  17622. }
  17623. return false;
  17624. }
  17625. };
  17626. return Type1CharString;
  17627. })();
  17628. /*
  17629. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17630. * program. Some of its logic depends on the Type2 charstrings
  17631. * structure.
  17632. * Note: this doesn't really parse the font since that would require evaluation
  17633. * of PostScript, but it is possible in most cases to extract what we need
  17634. * without a full parse.
  17635. */
  17636. var Type1Parser = (function Type1ParserClosure() {
  17637. /*
  17638. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17639. * of Plaintext Bytes. The function took a key as a parameter which can be
  17640. * for decrypting the eexec block of for decoding charStrings.
  17641. */
  17642. var EEXEC_ENCRYPT_KEY = 55665;
  17643. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17644. function isHexDigit(code) {
  17645. return code >= 48 && code <= 57 || // '0'-'9'
  17646. code >= 65 && code <= 70 || // 'A'-'F'
  17647. code >= 97 && code <= 102; // 'a'-'f'
  17648. }
  17649. function decrypt(data, key, discardNumber) {
  17650. var r = key | 0, c1 = 52845, c2 = 22719;
  17651. var count = data.length;
  17652. var decrypted = new Uint8Array(count);
  17653. for (var i = 0; i < count; i++) {
  17654. var value = data[i];
  17655. decrypted[i] = value ^ (r >> 8);
  17656. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17657. }
  17658. return Array.prototype.slice.call(decrypted, discardNumber);
  17659. }
  17660. function decryptAscii(data, key, discardNumber) {
  17661. var r = key | 0, c1 = 52845, c2 = 22719;
  17662. var count = data.length, maybeLength = count >>> 1;
  17663. var decrypted = new Uint8Array(maybeLength);
  17664. var i, j;
  17665. for (i = 0, j = 0; i < count; i++) {
  17666. var digit1 = data[i];
  17667. if (!isHexDigit(digit1)) {
  17668. continue;
  17669. }
  17670. i++;
  17671. var digit2;
  17672. while (i < count && !isHexDigit(digit2 = data[i])) {
  17673. i++;
  17674. }
  17675. if (i < count) {
  17676. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17677. decrypted[j++] = value ^ (r >> 8);
  17678. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17679. }
  17680. }
  17681. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17682. }
  17683. function isSpecial(c) {
  17684. return c === 0x2F || // '/'
  17685. c === 0x5B || c === 0x5D || // '[', ']'
  17686. c === 0x7B || c === 0x7D || // '{', '}'
  17687. c === 0x28 || c === 0x29; // '(', ')'
  17688. }
  17689. function Type1Parser(stream, encrypted) {
  17690. if (encrypted) {
  17691. var data = stream.getBytes();
  17692. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17693. isHexDigit(data[2]) && isHexDigit(data[3]));
  17694. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17695. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17696. }
  17697. this.stream = stream;
  17698. this.nextChar();
  17699. }
  17700. Type1Parser.prototype = {
  17701. readNumberArray: function Type1Parser_readNumberArray() {
  17702. this.getToken(); // read '[' or '{' (arrays can start with either)
  17703. var array = [];
  17704. while (true) {
  17705. var token = this.getToken();
  17706. if (token === null || token === ']' || token === '}') {
  17707. break;
  17708. }
  17709. array.push(parseFloat(token || 0));
  17710. }
  17711. return array;
  17712. },
  17713. readNumber: function Type1Parser_readNumber() {
  17714. var token = this.getToken();
  17715. return parseFloat(token || 0);
  17716. },
  17717. readInt: function Type1Parser_readInt() {
  17718. // Use '| 0' to prevent setting a double into length such as the double
  17719. // does not flow into the loop variable.
  17720. var token = this.getToken();
  17721. return parseInt(token || 0, 10) | 0;
  17722. },
  17723. readBoolean: function Type1Parser_readBoolean() {
  17724. var token = this.getToken();
  17725. // Use 1 and 0 since that's what type2 charstrings use.
  17726. return token === 'true' ? 1 : 0;
  17727. },
  17728. nextChar : function Type1_nextChar() {
  17729. return (this.currentChar = this.stream.getByte());
  17730. },
  17731. getToken: function Type1Parser_getToken() {
  17732. // Eat whitespace and comments.
  17733. var comment = false;
  17734. var ch = this.currentChar;
  17735. while (true) {
  17736. if (ch === -1) {
  17737. return null;
  17738. }
  17739. if (comment) {
  17740. if (ch === 0x0A || ch === 0x0D) {
  17741. comment = false;
  17742. }
  17743. } else if (ch === 0x25) { // '%'
  17744. comment = true;
  17745. } else if (!Lexer.isSpace(ch)) {
  17746. break;
  17747. }
  17748. ch = this.nextChar();
  17749. }
  17750. if (isSpecial(ch)) {
  17751. this.nextChar();
  17752. return String.fromCharCode(ch);
  17753. }
  17754. var token = '';
  17755. do {
  17756. token += String.fromCharCode(ch);
  17757. ch = this.nextChar();
  17758. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17759. return token;
  17760. },
  17761. /*
  17762. * Returns an object containing a Subrs array and a CharStrings
  17763. * array extracted from and eexec encrypted block of data
  17764. */
  17765. extractFontProgram: function Type1Parser_extractFontProgram() {
  17766. var stream = this.stream;
  17767. var subrs = [], charstrings = [];
  17768. var program = {
  17769. subrs: [],
  17770. charstrings: [],
  17771. properties: {
  17772. 'privateData': {
  17773. 'lenIV': 4
  17774. }
  17775. }
  17776. };
  17777. var token, length, data, lenIV, encoded;
  17778. while ((token = this.getToken()) !== null) {
  17779. if (token !== '/') {
  17780. continue;
  17781. }
  17782. token = this.getToken();
  17783. switch (token) {
  17784. case 'CharStrings':
  17785. // The number immediately following CharStrings must be greater or
  17786. // equal to the number of CharStrings.
  17787. this.getToken();
  17788. this.getToken(); // read in 'dict'
  17789. this.getToken(); // read in 'dup'
  17790. this.getToken(); // read in 'begin'
  17791. while(true) {
  17792. token = this.getToken();
  17793. if (token === null || token === 'end') {
  17794. break;
  17795. }
  17796. if (token !== '/') {
  17797. continue;
  17798. }
  17799. var glyph = this.getToken();
  17800. length = this.readInt();
  17801. this.getToken(); // read in 'RD' or '-|'
  17802. data = stream.makeSubStream(stream.pos, length);
  17803. lenIV = program.properties.privateData['lenIV'];
  17804. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17805. // Skip past the required space and binary data.
  17806. stream.skip(length);
  17807. this.nextChar();
  17808. token = this.getToken(); // read in 'ND' or '|-'
  17809. if (token === 'noaccess') {
  17810. this.getToken(); // read in 'def'
  17811. }
  17812. charstrings.push({
  17813. glyph: glyph,
  17814. encoded: encoded
  17815. });
  17816. }
  17817. break;
  17818. case 'Subrs':
  17819. var num = this.readInt();
  17820. this.getToken(); // read in 'array'
  17821. while ((token = this.getToken()) === 'dup') {
  17822. var index = this.readInt();
  17823. length = this.readInt();
  17824. this.getToken(); // read in 'RD' or '-|'
  17825. data = stream.makeSubStream(stream.pos, length);
  17826. lenIV = program.properties.privateData['lenIV'];
  17827. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17828. // Skip past the required space and binary data.
  17829. stream.skip(length);
  17830. this.nextChar();
  17831. token = this.getToken(); // read in 'NP' or '|'
  17832. if (token === 'noaccess') {
  17833. this.getToken(); // read in 'put'
  17834. }
  17835. subrs[index] = encoded;
  17836. }
  17837. break;
  17838. case 'BlueValues':
  17839. case 'OtherBlues':
  17840. case 'FamilyBlues':
  17841. case 'FamilyOtherBlues':
  17842. var blueArray = this.readNumberArray();
  17843. // *Blue* values may contain invalid data: disables reading of
  17844. // those values when hinting is disabled.
  17845. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17846. HINTING_ENABLED) {
  17847. program.properties.privateData[token] = blueArray;
  17848. }
  17849. break;
  17850. case 'StemSnapH':
  17851. case 'StemSnapV':
  17852. program.properties.privateData[token] = this.readNumberArray();
  17853. break;
  17854. case 'StdHW':
  17855. case 'StdVW':
  17856. program.properties.privateData[token] =
  17857. this.readNumberArray()[0];
  17858. break;
  17859. case 'BlueShift':
  17860. case 'lenIV':
  17861. case 'BlueFuzz':
  17862. case 'BlueScale':
  17863. case 'LanguageGroup':
  17864. case 'ExpansionFactor':
  17865. program.properties.privateData[token] = this.readNumber();
  17866. break;
  17867. case 'ForceBold':
  17868. program.properties.privateData[token] = this.readBoolean();
  17869. break;
  17870. }
  17871. }
  17872. for (var i = 0; i < charstrings.length; i++) {
  17873. glyph = charstrings[i].glyph;
  17874. encoded = charstrings[i].encoded;
  17875. var charString = new Type1CharString();
  17876. var error = charString.convert(encoded, subrs);
  17877. var output = charString.output;
  17878. if (error) {
  17879. // It seems when FreeType encounters an error while evaluating a glyph
  17880. // that it completely ignores the glyph so we'll mimic that behaviour
  17881. // here and put an endchar to make the validator happy.
  17882. output = [14];
  17883. }
  17884. program.charstrings.push({
  17885. glyphName: glyph,
  17886. charstring: output,
  17887. width: charString.width,
  17888. lsb: charString.lsb,
  17889. seac: charString.seac
  17890. });
  17891. }
  17892. return program;
  17893. },
  17894. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17895. var token;
  17896. while ((token = this.getToken()) !== null) {
  17897. if (token !== '/') {
  17898. continue;
  17899. }
  17900. token = this.getToken();
  17901. switch (token) {
  17902. case 'FontMatrix':
  17903. var matrix = this.readNumberArray();
  17904. properties.fontMatrix = matrix;
  17905. break;
  17906. case 'Encoding':
  17907. var encodingArg = this.getToken();
  17908. var encoding;
  17909. if (!/^\d+$/.test(encodingArg)) {
  17910. // encoding name is specified
  17911. encoding = Encodings[encodingArg];
  17912. } else {
  17913. encoding = [];
  17914. var size = parseInt(encodingArg, 10) | 0;
  17915. this.getToken(); // read in 'array'
  17916. for (var j = 0; j < size; j++) {
  17917. token = this.getToken();
  17918. // skipping till first dup or def (e.g. ignoring for statement)
  17919. while (token !== 'dup' && token !== 'def') {
  17920. token = this.getToken();
  17921. if (token === null) {
  17922. return; // invalid header
  17923. }
  17924. }
  17925. if (token === 'def') {
  17926. break; // read all array data
  17927. }
  17928. var index = this.readInt();
  17929. this.getToken(); // read in '/'
  17930. var glyph = this.getToken();
  17931. encoding[index] = glyph;
  17932. this.getToken(); // read the in 'put'
  17933. }
  17934. }
  17935. properties.builtInEncoding = encoding;
  17936. break;
  17937. case 'FontBBox':
  17938. var fontBBox = this.readNumberArray();
  17939. // adjusting ascent/descent
  17940. properties.ascent = fontBBox[3];
  17941. properties.descent = fontBBox[1];
  17942. properties.ascentScaled = true;
  17943. break;
  17944. }
  17945. }
  17946. }
  17947. };
  17948. return Type1Parser;
  17949. })();
  17950. /**
  17951. * The CFF class takes a Type1 file and wrap it into a
  17952. * 'Compact Font Format' which itself embed Type2 charstrings.
  17953. */
  17954. var CFFStandardStrings = [
  17955. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17956. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17957. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17958. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17959. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17960. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17961. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17962. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17963. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17964. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17965. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17966. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17967. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17968. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17969. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17970. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17971. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17972. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17973. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17974. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17975. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17976. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17977. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17978. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17979. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17980. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17981. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17982. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17983. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17984. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17985. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17986. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17987. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17988. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17989. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17990. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17991. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17992. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17993. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17994. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  17995. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  17996. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  17997. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17998. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17999. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18000. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18001. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18002. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18003. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18004. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18005. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18006. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18007. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18008. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18009. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18010. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18011. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18012. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18013. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18014. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18015. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18016. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18017. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18018. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18019. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18020. ];
  18021. // Type1Font is also a CIDFontType0.
  18022. var Type1Font = function Type1Font(name, file, properties) {
  18023. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18024. // Also, length1 and length2 might be off by 6 bytes as well.
  18025. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18026. var PFB_HEADER_SIZE = 6;
  18027. var headerBlockLength = properties.length1;
  18028. var eexecBlockLength = properties.length2;
  18029. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18030. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18031. if (pfbHeaderPresent) {
  18032. file.skip(PFB_HEADER_SIZE);
  18033. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18034. (pfbHeader[3] << 8) | pfbHeader[2];
  18035. }
  18036. // Get the data block containing glyphs and subrs informations
  18037. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18038. var headerBlockParser = new Type1Parser(headerBlock);
  18039. headerBlockParser.extractFontHeader(properties);
  18040. if (pfbHeaderPresent) {
  18041. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18042. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18043. (pfbHeader[3] << 8) | pfbHeader[2];
  18044. }
  18045. // Decrypt the data blocks and retrieve it's content
  18046. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18047. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18048. var data = eexecBlockParser.extractFontProgram();
  18049. for (var info in data.properties) {
  18050. properties[info] = data.properties[info];
  18051. }
  18052. var charstrings = data.charstrings;
  18053. var type2Charstrings = this.getType2Charstrings(charstrings);
  18054. var subrs = this.getType2Subrs(data.subrs);
  18055. this.charstrings = charstrings;
  18056. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18057. subrs, properties);
  18058. this.seacs = this.getSeacs(data.charstrings);
  18059. };
  18060. Type1Font.prototype = {
  18061. get numGlyphs() {
  18062. return this.charstrings.length + 1;
  18063. },
  18064. getCharset: function Type1Font_getCharset() {
  18065. var charset = ['.notdef'];
  18066. var charstrings = this.charstrings;
  18067. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18068. charset.push(charstrings[glyphId].glyphName);
  18069. }
  18070. return charset;
  18071. },
  18072. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18073. var charstrings = this.charstrings;
  18074. var glyphNames = ['.notdef'], glyphId;
  18075. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18076. glyphNames.push(charstrings[glyphId].glyphName);
  18077. }
  18078. var encoding = properties.builtInEncoding;
  18079. if (encoding) {
  18080. var builtInEncoding = {};
  18081. for (var charCode in encoding) {
  18082. glyphId = glyphNames.indexOf(encoding[charCode]);
  18083. if (glyphId >= 0) {
  18084. builtInEncoding[charCode] = glyphId;
  18085. }
  18086. }
  18087. }
  18088. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18089. },
  18090. getSeacs: function Type1Font_getSeacs(charstrings) {
  18091. var i, ii;
  18092. var seacMap = [];
  18093. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18094. var charstring = charstrings[i];
  18095. if (charstring.seac) {
  18096. // Offset by 1 for .notdef
  18097. seacMap[i + 1] = charstring.seac;
  18098. }
  18099. }
  18100. return seacMap;
  18101. },
  18102. getType2Charstrings: function Type1Font_getType2Charstrings(
  18103. type1Charstrings) {
  18104. var type2Charstrings = [];
  18105. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18106. type2Charstrings.push(type1Charstrings[i].charstring);
  18107. }
  18108. return type2Charstrings;
  18109. },
  18110. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18111. var bias = 0;
  18112. var count = type1Subrs.length;
  18113. if (count < 1133) {
  18114. bias = 107;
  18115. } else if (count < 33769) {
  18116. bias = 1131;
  18117. } else {
  18118. bias = 32768;
  18119. }
  18120. // Add a bunch of empty subrs to deal with the Type2 bias
  18121. var type2Subrs = [];
  18122. var i;
  18123. for (i = 0; i < bias; i++) {
  18124. type2Subrs.push([0x0B]);
  18125. }
  18126. for (i = 0; i < count; i++) {
  18127. type2Subrs.push(type1Subrs[i]);
  18128. }
  18129. return type2Subrs;
  18130. },
  18131. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18132. var cff = new CFF();
  18133. cff.header = new CFFHeader(1, 0, 4, 4);
  18134. cff.names = [name];
  18135. var topDict = new CFFTopDict();
  18136. // CFF strings IDs 0...390 are predefined names, so refering
  18137. // to entries in our own String INDEX starts at SID 391.
  18138. topDict.setByName('version', 391);
  18139. topDict.setByName('Notice', 392);
  18140. topDict.setByName('FullName', 393);
  18141. topDict.setByName('FamilyName', 394);
  18142. topDict.setByName('Weight', 395);
  18143. topDict.setByName('Encoding', null); // placeholder
  18144. topDict.setByName('FontMatrix', properties.fontMatrix);
  18145. topDict.setByName('FontBBox', properties.bbox);
  18146. topDict.setByName('charset', null); // placeholder
  18147. topDict.setByName('CharStrings', null); // placeholder
  18148. topDict.setByName('Private', null); // placeholder
  18149. cff.topDict = topDict;
  18150. var strings = new CFFStrings();
  18151. strings.add('Version 0.11'); // Version
  18152. strings.add('See original notice'); // Notice
  18153. strings.add(name); // FullName
  18154. strings.add(name); // FamilyName
  18155. strings.add('Medium'); // Weight
  18156. cff.strings = strings;
  18157. cff.globalSubrIndex = new CFFIndex();
  18158. var count = glyphs.length;
  18159. var charsetArray = [0];
  18160. var i, ii;
  18161. for (i = 0; i < count; i++) {
  18162. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18163. // TODO: Insert the string and correctly map it. Previously it was
  18164. // thought mapping names that aren't in the standard strings to .notdef
  18165. // was fine, however in issue818 when mapping them all to .notdef the
  18166. // adieresis glyph no longer worked.
  18167. if (index === -1) {
  18168. index = 0;
  18169. }
  18170. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18171. }
  18172. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18173. var charStringsIndex = new CFFIndex();
  18174. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18175. for (i = 0; i < count; i++) {
  18176. charStringsIndex.add(glyphs[i]);
  18177. }
  18178. cff.charStrings = charStringsIndex;
  18179. var privateDict = new CFFPrivateDict();
  18180. privateDict.setByName('Subrs', null); // placeholder
  18181. var fields = [
  18182. 'BlueValues',
  18183. 'OtherBlues',
  18184. 'FamilyBlues',
  18185. 'FamilyOtherBlues',
  18186. 'StemSnapH',
  18187. 'StemSnapV',
  18188. 'BlueShift',
  18189. 'BlueFuzz',
  18190. 'BlueScale',
  18191. 'LanguageGroup',
  18192. 'ExpansionFactor',
  18193. 'ForceBold',
  18194. 'StdHW',
  18195. 'StdVW'
  18196. ];
  18197. for (i = 0, ii = fields.length; i < ii; i++) {
  18198. var field = fields[i];
  18199. if (!properties.privateData.hasOwnProperty(field)) {
  18200. continue;
  18201. }
  18202. var value = properties.privateData[field];
  18203. if (isArray(value)) {
  18204. // All of the private dictionary array data in CFF must be stored as
  18205. // "delta-encoded" numbers.
  18206. for (var j = value.length - 1; j > 0; j--) {
  18207. value[j] -= value[j - 1]; // ... difference from previous value
  18208. }
  18209. }
  18210. privateDict.setByName(field, value);
  18211. }
  18212. cff.topDict.privateDict = privateDict;
  18213. var subrIndex = new CFFIndex();
  18214. for (i = 0, ii = subrs.length; i < ii; i++) {
  18215. subrIndex.add(subrs[i]);
  18216. }
  18217. privateDict.subrsIndex = subrIndex;
  18218. var compiler = new CFFCompiler(cff);
  18219. return compiler.compile();
  18220. }
  18221. };
  18222. var CFFFont = (function CFFFontClosure() {
  18223. function CFFFont(file, properties) {
  18224. this.properties = properties;
  18225. var parser = new CFFParser(file, properties);
  18226. this.cff = parser.parse();
  18227. var compiler = new CFFCompiler(this.cff);
  18228. this.seacs = this.cff.seacs;
  18229. try {
  18230. this.data = compiler.compile();
  18231. } catch (e) {
  18232. warn('Failed to compile font ' + properties.loadedName);
  18233. // There may have just been an issue with the compiler, set the data
  18234. // anyway and hope the font loaded.
  18235. this.data = file;
  18236. }
  18237. }
  18238. CFFFont.prototype = {
  18239. get numGlyphs() {
  18240. return this.cff.charStrings.count;
  18241. },
  18242. getCharset: function CFFFont_getCharset() {
  18243. return this.cff.charset.charset;
  18244. },
  18245. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18246. var cff = this.cff;
  18247. var properties = this.properties;
  18248. var charsets = cff.charset.charset;
  18249. var charCodeToGlyphId;
  18250. var glyphId;
  18251. if (properties.composite) {
  18252. charCodeToGlyphId = Object.create(null);
  18253. if (cff.isCIDFont) {
  18254. // If the font is actually a CID font then we should use the charset
  18255. // to map CIDs to GIDs.
  18256. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18257. var cid = charsets[glyphId];
  18258. var charCode = properties.cMap.charCodeOf(cid);
  18259. charCodeToGlyphId[charCode] = glyphId;
  18260. }
  18261. } else {
  18262. // If it is NOT actually a CID font then CIDs should be mapped
  18263. // directly to GIDs.
  18264. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18265. charCodeToGlyphId[glyphId] = glyphId;
  18266. }
  18267. }
  18268. return charCodeToGlyphId;
  18269. }
  18270. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18271. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18272. return charCodeToGlyphId;
  18273. }
  18274. };
  18275. return CFFFont;
  18276. })();
  18277. var CFFParser = (function CFFParserClosure() {
  18278. var CharstringValidationData = [
  18279. null,
  18280. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18281. null,
  18282. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18283. { id: 'vmoveto', min: 1, stackClearing: true },
  18284. { id: 'rlineto', min: 2, resetStack: true },
  18285. { id: 'hlineto', min: 1, resetStack: true },
  18286. { id: 'vlineto', min: 1, resetStack: true },
  18287. { id: 'rrcurveto', min: 6, resetStack: true },
  18288. null,
  18289. { id: 'callsubr', min: 1, undefStack: true },
  18290. { id: 'return', min: 0, undefStack: true },
  18291. null, // 12
  18292. null,
  18293. { id: 'endchar', min: 0, stackClearing: true },
  18294. null,
  18295. null,
  18296. null,
  18297. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18298. { id: 'hintmask', min: 0, stackClearing: true },
  18299. { id: 'cntrmask', min: 0, stackClearing: true },
  18300. { id: 'rmoveto', min: 2, stackClearing: true },
  18301. { id: 'hmoveto', min: 1, stackClearing: true },
  18302. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18303. { id: 'rcurveline', min: 8, resetStack: true },
  18304. { id: 'rlinecurve', min: 8, resetStack: true },
  18305. { id: 'vvcurveto', min: 4, resetStack: true },
  18306. { id: 'hhcurveto', min: 4, resetStack: true },
  18307. null, // shortint
  18308. { id: 'callgsubr', min: 1, undefStack: true },
  18309. { id: 'vhcurveto', min: 4, resetStack: true },
  18310. { id: 'hvcurveto', min: 4, resetStack: true }
  18311. ];
  18312. var CharstringValidationData12 = [
  18313. null,
  18314. null,
  18315. null,
  18316. { id: 'and', min: 2, stackDelta: -1 },
  18317. { id: 'or', min: 2, stackDelta: -1 },
  18318. { id: 'not', min: 1, stackDelta: 0 },
  18319. null,
  18320. null,
  18321. null,
  18322. { id: 'abs', min: 1, stackDelta: 0 },
  18323. { id: 'add', min: 2, stackDelta: -1,
  18324. stackFn: function stack_div(stack, index) {
  18325. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18326. }
  18327. },
  18328. { id: 'sub', min: 2, stackDelta: -1,
  18329. stackFn: function stack_div(stack, index) {
  18330. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18331. }
  18332. },
  18333. { id: 'div', min: 2, stackDelta: -1,
  18334. stackFn: function stack_div(stack, index) {
  18335. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18336. }
  18337. },
  18338. null,
  18339. { id: 'neg', min: 1, stackDelta: 0,
  18340. stackFn: function stack_div(stack, index) {
  18341. stack[index - 1] = -stack[index - 1];
  18342. }
  18343. },
  18344. { id: 'eq', min: 2, stackDelta: -1 },
  18345. null,
  18346. null,
  18347. { id: 'drop', min: 1, stackDelta: -1 },
  18348. null,
  18349. { id: 'put', min: 2, stackDelta: -2 },
  18350. { id: 'get', min: 1, stackDelta: 0 },
  18351. { id: 'ifelse', min: 4, stackDelta: -3 },
  18352. { id: 'random', min: 0, stackDelta: 1 },
  18353. { id: 'mul', min: 2, stackDelta: -1,
  18354. stackFn: function stack_div(stack, index) {
  18355. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18356. }
  18357. },
  18358. null,
  18359. { id: 'sqrt', min: 1, stackDelta: 0 },
  18360. { id: 'dup', min: 1, stackDelta: 1 },
  18361. { id: 'exch', min: 2, stackDelta: 0 },
  18362. { id: 'index', min: 2, stackDelta: 0 },
  18363. { id: 'roll', min: 3, stackDelta: -2 },
  18364. null,
  18365. null,
  18366. null,
  18367. { id: 'hflex', min: 7, resetStack: true },
  18368. { id: 'flex', min: 13, resetStack: true },
  18369. { id: 'hflex1', min: 9, resetStack: true },
  18370. { id: 'flex1', min: 11, resetStack: true }
  18371. ];
  18372. function CFFParser(file, properties) {
  18373. this.bytes = file.getBytes();
  18374. this.properties = properties;
  18375. }
  18376. CFFParser.prototype = {
  18377. parse: function CFFParser_parse() {
  18378. var properties = this.properties;
  18379. var cff = new CFF();
  18380. this.cff = cff;
  18381. // The first five sections must be in order, all the others are reached
  18382. // via offsets contained in one of the below.
  18383. var header = this.parseHeader();
  18384. var nameIndex = this.parseIndex(header.endPos);
  18385. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18386. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18387. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18388. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18389. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18390. cff.header = header.obj;
  18391. cff.names = this.parseNameIndex(nameIndex.obj);
  18392. cff.strings = this.parseStringIndex(stringIndex.obj);
  18393. cff.topDict = topDict;
  18394. cff.globalSubrIndex = globalSubrIndex.obj;
  18395. this.parsePrivateDict(cff.topDict);
  18396. cff.isCIDFont = topDict.hasName('ROS');
  18397. var charStringOffset = topDict.getByName('CharStrings');
  18398. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18399. cff.charStrings = charStringsAndSeacs.charStrings;
  18400. cff.seacs = charStringsAndSeacs.seacs;
  18401. cff.widths = charStringsAndSeacs.widths;
  18402. var fontMatrix = topDict.getByName('FontMatrix');
  18403. if (fontMatrix) {
  18404. properties.fontMatrix = fontMatrix;
  18405. }
  18406. var fontBBox = topDict.getByName('FontBBox');
  18407. if (fontBBox) {
  18408. // adjusting ascent/descent
  18409. properties.ascent = fontBBox[3];
  18410. properties.descent = fontBBox[1];
  18411. properties.ascentScaled = true;
  18412. }
  18413. var charset, encoding;
  18414. if (cff.isCIDFont) {
  18415. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18416. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18417. var dictRaw = fdArrayIndex.get(i);
  18418. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18419. cff.strings);
  18420. this.parsePrivateDict(fontDict);
  18421. cff.fdArray.push(fontDict);
  18422. }
  18423. // cid fonts don't have an encoding
  18424. encoding = null;
  18425. charset = this.parseCharsets(topDict.getByName('charset'),
  18426. cff.charStrings.count, cff.strings, true);
  18427. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18428. cff.charStrings.count);
  18429. } else {
  18430. charset = this.parseCharsets(topDict.getByName('charset'),
  18431. cff.charStrings.count, cff.strings, false);
  18432. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18433. properties,
  18434. cff.strings, charset.charset);
  18435. }
  18436. cff.charset = charset;
  18437. cff.encoding = encoding;
  18438. return cff;
  18439. },
  18440. parseHeader: function CFFParser_parseHeader() {
  18441. var bytes = this.bytes;
  18442. var bytesLength = bytes.length;
  18443. var offset = 0;
  18444. // Prevent an infinite loop, by checking that the offset is within the
  18445. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18446. while (offset < bytesLength && bytes[offset] !== 1) {
  18447. ++offset;
  18448. }
  18449. if (offset >= bytesLength) {
  18450. error('Invalid CFF header');
  18451. } else if (offset !== 0) {
  18452. info('cff data is shifted');
  18453. bytes = bytes.subarray(offset);
  18454. this.bytes = bytes;
  18455. }
  18456. var major = bytes[0];
  18457. var minor = bytes[1];
  18458. var hdrSize = bytes[2];
  18459. var offSize = bytes[3];
  18460. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18461. return { obj: header, endPos: hdrSize };
  18462. },
  18463. parseDict: function CFFParser_parseDict(dict) {
  18464. var pos = 0;
  18465. function parseOperand() {
  18466. var value = dict[pos++];
  18467. if (value === 30) {
  18468. return parseFloatOperand(pos);
  18469. } else if (value === 28) {
  18470. value = dict[pos++];
  18471. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18472. return value;
  18473. } else if (value === 29) {
  18474. value = dict[pos++];
  18475. value = (value << 8) | dict[pos++];
  18476. value = (value << 8) | dict[pos++];
  18477. value = (value << 8) | dict[pos++];
  18478. return value;
  18479. } else if (value >= 32 && value <= 246) {
  18480. return value - 139;
  18481. } else if (value >= 247 && value <= 250) {
  18482. return ((value - 247) * 256) + dict[pos++] + 108;
  18483. } else if (value >= 251 && value <= 254) {
  18484. return -((value - 251) * 256) - dict[pos++] - 108;
  18485. } else {
  18486. error('255 is not a valid DICT command');
  18487. }
  18488. return -1;
  18489. }
  18490. function parseFloatOperand() {
  18491. var str = '';
  18492. var eof = 15;
  18493. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18494. '9', '.', 'E', 'E-', null, '-'];
  18495. var length = dict.length;
  18496. while (pos < length) {
  18497. var b = dict[pos++];
  18498. var b1 = b >> 4;
  18499. var b2 = b & 15;
  18500. if (b1 === eof) {
  18501. break;
  18502. }
  18503. str += lookup[b1];
  18504. if (b2 === eof) {
  18505. break;
  18506. }
  18507. str += lookup[b2];
  18508. }
  18509. return parseFloat(str);
  18510. }
  18511. var operands = [];
  18512. var entries = [];
  18513. pos = 0;
  18514. var end = dict.length;
  18515. while (pos < end) {
  18516. var b = dict[pos];
  18517. if (b <= 21) {
  18518. if (b === 12) {
  18519. b = (b << 8) | dict[++pos];
  18520. }
  18521. entries.push([b, operands]);
  18522. operands = [];
  18523. ++pos;
  18524. } else {
  18525. operands.push(parseOperand());
  18526. }
  18527. }
  18528. return entries;
  18529. },
  18530. parseIndex: function CFFParser_parseIndex(pos) {
  18531. var cffIndex = new CFFIndex();
  18532. var bytes = this.bytes;
  18533. var count = (bytes[pos++] << 8) | bytes[pos++];
  18534. var offsets = [];
  18535. var end = pos;
  18536. var i, ii;
  18537. if (count !== 0) {
  18538. var offsetSize = bytes[pos++];
  18539. // add 1 for offset to determine size of last object
  18540. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18541. for (i = 0, ii = count + 1; i < ii; ++i) {
  18542. var offset = 0;
  18543. for (var j = 0; j < offsetSize; ++j) {
  18544. offset <<= 8;
  18545. offset += bytes[pos++];
  18546. }
  18547. offsets.push(startPos + offset);
  18548. }
  18549. end = offsets[count];
  18550. }
  18551. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18552. var offsetStart = offsets[i];
  18553. var offsetEnd = offsets[i + 1];
  18554. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18555. }
  18556. return {obj: cffIndex, endPos: end};
  18557. },
  18558. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18559. var names = [];
  18560. for (var i = 0, ii = index.count; i < ii; ++i) {
  18561. var name = index.get(i);
  18562. // OTS doesn't allow names to be over 127 characters.
  18563. var length = Math.min(name.length, 127);
  18564. var data = [];
  18565. // OTS also only permits certain characters in the name.
  18566. for (var j = 0; j < length; ++j) {
  18567. var c = name[j];
  18568. if (j === 0 && c === 0) {
  18569. data[j] = c;
  18570. continue;
  18571. }
  18572. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18573. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18574. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18575. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18576. data[j] = 95;
  18577. continue;
  18578. }
  18579. data[j] = c;
  18580. }
  18581. names.push(bytesToString(data));
  18582. }
  18583. return names;
  18584. },
  18585. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18586. var strings = new CFFStrings();
  18587. for (var i = 0, ii = index.count; i < ii; ++i) {
  18588. var data = index.get(i);
  18589. strings.add(bytesToString(data));
  18590. }
  18591. return strings;
  18592. },
  18593. createDict: function CFFParser_createDict(Type, dict, strings) {
  18594. var cffDict = new Type(strings);
  18595. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18596. var pair = dict[i];
  18597. var key = pair[0];
  18598. var value = pair[1];
  18599. cffDict.setByKey(key, value);
  18600. }
  18601. return cffDict;
  18602. },
  18603. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18604. var charStrings = this.parseIndex(charStringOffset).obj;
  18605. var seacs = [];
  18606. var widths = [];
  18607. var count = charStrings.count;
  18608. for (var i = 0; i < count; i++) {
  18609. var charstring = charStrings.get(i);
  18610. var stackSize = 0;
  18611. var stack = [];
  18612. var undefStack = true;
  18613. var hints = 0;
  18614. var valid = true;
  18615. var data = charstring;
  18616. var length = data.length;
  18617. var firstStackClearing = true;
  18618. for (var j = 0; j < length;) {
  18619. var value = data[j++];
  18620. var validationCommand = null;
  18621. if (value === 12) {
  18622. var q = data[j++];
  18623. if (q === 0) {
  18624. // The CFF specification state that the 'dotsection' command
  18625. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18626. // charstrings processors should support them. Unfortunately
  18627. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18628. // is replaced by a useless (0, hmoveto).
  18629. data[j - 2] = 139;
  18630. data[j - 1] = 22;
  18631. stackSize = 0;
  18632. } else {
  18633. validationCommand = CharstringValidationData12[q];
  18634. }
  18635. } else if (value === 28) { // number (16 bit)
  18636. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18637. j += 2;
  18638. stackSize++;
  18639. } else if (value === 14) {
  18640. if (stackSize >= 4) {
  18641. stackSize -= 4;
  18642. if (SEAC_ANALYSIS_ENABLED) {
  18643. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18644. valid = false;
  18645. }
  18646. }
  18647. validationCommand = CharstringValidationData[value];
  18648. } else if (value >= 32 && value <= 246) { // number
  18649. stack[stackSize] = value - 139;
  18650. stackSize++;
  18651. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18652. stack[stackSize] = (value < 251 ?
  18653. ((value - 247) << 8) + data[j] + 108 :
  18654. -((value - 251) << 8) - data[j] - 108);
  18655. j++;
  18656. stackSize++;
  18657. } else if (value === 255) { // number (32 bit)
  18658. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18659. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18660. j += 4;
  18661. stackSize++;
  18662. } else if (value === 19 || value === 20) {
  18663. hints += stackSize >> 1;
  18664. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18665. stackSize %= 2;
  18666. validationCommand = CharstringValidationData[value];
  18667. } else {
  18668. validationCommand = CharstringValidationData[value];
  18669. }
  18670. if (validationCommand) {
  18671. if (validationCommand.stem) {
  18672. hints += stackSize >> 1;
  18673. }
  18674. if ('min' in validationCommand) {
  18675. if (!undefStack && stackSize < validationCommand.min) {
  18676. warn('Not enough parameters for ' + validationCommand.id +
  18677. '; actual: ' + stackSize +
  18678. ', expected: ' + validationCommand.min);
  18679. valid = false;
  18680. break;
  18681. }
  18682. }
  18683. if (firstStackClearing && validationCommand.stackClearing) {
  18684. firstStackClearing = false;
  18685. // the optional character width can be found before the first
  18686. // stack-clearing command arguments
  18687. stackSize -= validationCommand.min;
  18688. if (stackSize >= 2 && validationCommand.stem) {
  18689. // there are even amount of arguments for stem commands
  18690. stackSize %= 2;
  18691. } else if (stackSize > 1) {
  18692. warn('Found too many parameters for stack-clearing command');
  18693. }
  18694. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18695. widths[i] = stack[stackSize - 1];
  18696. }
  18697. }
  18698. if ('stackDelta' in validationCommand) {
  18699. if ('stackFn' in validationCommand) {
  18700. validationCommand.stackFn(stack, stackSize);
  18701. }
  18702. stackSize += validationCommand.stackDelta;
  18703. } else if (validationCommand.stackClearing) {
  18704. stackSize = 0;
  18705. } else if (validationCommand.resetStack) {
  18706. stackSize = 0;
  18707. undefStack = false;
  18708. } else if (validationCommand.undefStack) {
  18709. stackSize = 0;
  18710. undefStack = true;
  18711. firstStackClearing = false;
  18712. }
  18713. }
  18714. }
  18715. if (!valid) {
  18716. // resetting invalid charstring to single 'endchar'
  18717. charStrings.set(i, new Uint8Array([14]));
  18718. }
  18719. }
  18720. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18721. },
  18722. emptyPrivateDictionary:
  18723. function CFFParser_emptyPrivateDictionary(parentDict) {
  18724. var privateDict = this.createDict(CFFPrivateDict, [],
  18725. parentDict.strings);
  18726. parentDict.setByKey(18, [0, 0]);
  18727. parentDict.privateDict = privateDict;
  18728. },
  18729. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18730. // no private dict, do nothing
  18731. if (!parentDict.hasName('Private')) {
  18732. this.emptyPrivateDictionary(parentDict);
  18733. return;
  18734. }
  18735. var privateOffset = parentDict.getByName('Private');
  18736. // make sure the params are formatted correctly
  18737. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18738. parentDict.removeByName('Private');
  18739. return;
  18740. }
  18741. var size = privateOffset[0];
  18742. var offset = privateOffset[1];
  18743. // remove empty dicts or ones that refer to invalid location
  18744. if (size === 0 || offset >= this.bytes.length) {
  18745. this.emptyPrivateDictionary(parentDict);
  18746. return;
  18747. }
  18748. var privateDictEnd = offset + size;
  18749. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18750. var dict = this.parseDict(dictData);
  18751. var privateDict = this.createDict(CFFPrivateDict, dict,
  18752. parentDict.strings);
  18753. parentDict.privateDict = privateDict;
  18754. // Parse the Subrs index also since it's relative to the private dict.
  18755. if (!privateDict.getByName('Subrs')) {
  18756. return;
  18757. }
  18758. var subrsOffset = privateDict.getByName('Subrs');
  18759. var relativeOffset = offset + subrsOffset;
  18760. // Validate the offset.
  18761. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18762. this.emptyPrivateDictionary(parentDict);
  18763. return;
  18764. }
  18765. var subrsIndex = this.parseIndex(relativeOffset);
  18766. privateDict.subrsIndex = subrsIndex.obj;
  18767. },
  18768. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18769. if (pos === 0) {
  18770. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18771. ISOAdobeCharset);
  18772. } else if (pos === 1) {
  18773. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18774. ExpertCharset);
  18775. } else if (pos === 2) {
  18776. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18777. ExpertSubsetCharset);
  18778. }
  18779. var bytes = this.bytes;
  18780. var start = pos;
  18781. var format = bytes[pos++];
  18782. var charset = ['.notdef'];
  18783. var id, count, i;
  18784. // subtract 1 for the .notdef glyph
  18785. length -= 1;
  18786. switch (format) {
  18787. case 0:
  18788. for (i = 0; i < length; i++) {
  18789. id = (bytes[pos++] << 8) | bytes[pos++];
  18790. charset.push(cid ? id : strings.get(id));
  18791. }
  18792. break;
  18793. case 1:
  18794. while (charset.length <= length) {
  18795. id = (bytes[pos++] << 8) | bytes[pos++];
  18796. count = bytes[pos++];
  18797. for (i = 0; i <= count; i++) {
  18798. charset.push(cid ? id++ : strings.get(id++));
  18799. }
  18800. }
  18801. break;
  18802. case 2:
  18803. while (charset.length <= length) {
  18804. id = (bytes[pos++] << 8) | bytes[pos++];
  18805. count = (bytes[pos++] << 8) | bytes[pos++];
  18806. for (i = 0; i <= count; i++) {
  18807. charset.push(cid ? id++ : strings.get(id++));
  18808. }
  18809. }
  18810. break;
  18811. default:
  18812. error('Unknown charset format');
  18813. }
  18814. // Raw won't be needed if we actually compile the charset.
  18815. var end = pos;
  18816. var raw = bytes.subarray(start, end);
  18817. return new CFFCharset(false, format, charset, raw);
  18818. },
  18819. parseEncoding: function CFFParser_parseEncoding(pos,
  18820. properties,
  18821. strings,
  18822. charset) {
  18823. var encoding = {};
  18824. var bytes = this.bytes;
  18825. var predefined = false;
  18826. var hasSupplement = false;
  18827. var format, i, ii;
  18828. var raw = null;
  18829. function readSupplement() {
  18830. var supplementsCount = bytes[pos++];
  18831. for (i = 0; i < supplementsCount; i++) {
  18832. var code = bytes[pos++];
  18833. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18834. encoding[code] = charset.indexOf(strings.get(sid));
  18835. }
  18836. }
  18837. if (pos === 0 || pos === 1) {
  18838. predefined = true;
  18839. format = pos;
  18840. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18841. Encodings.StandardEncoding;
  18842. for (i = 0, ii = charset.length; i < ii; i++) {
  18843. var index = baseEncoding.indexOf(charset[i]);
  18844. if (index !== -1) {
  18845. encoding[index] = i;
  18846. }
  18847. }
  18848. } else {
  18849. var dataStart = pos;
  18850. format = bytes[pos++];
  18851. switch (format & 0x7f) {
  18852. case 0:
  18853. var glyphsCount = bytes[pos++];
  18854. for (i = 1; i <= glyphsCount; i++) {
  18855. encoding[bytes[pos++]] = i;
  18856. }
  18857. break;
  18858. case 1:
  18859. var rangesCount = bytes[pos++];
  18860. var gid = 1;
  18861. for (i = 0; i < rangesCount; i++) {
  18862. var start = bytes[pos++];
  18863. var left = bytes[pos++];
  18864. for (var j = start; j <= start + left; j++) {
  18865. encoding[j] = gid++;
  18866. }
  18867. }
  18868. break;
  18869. default:
  18870. error('Unknow encoding format: ' + format + ' in CFF');
  18871. break;
  18872. }
  18873. var dataEnd = pos;
  18874. if (format & 0x80) {
  18875. // The font sanitizer does not support CFF encoding with a
  18876. // supplement, since the encoding is not really used to map
  18877. // between gid to glyph, let's overwrite what is declared in
  18878. // the top dictionary to let the sanitizer think the font use
  18879. // StandardEncoding, that's a lie but that's ok.
  18880. bytes[dataStart] &= 0x7f;
  18881. readSupplement();
  18882. hasSupplement = true;
  18883. }
  18884. raw = bytes.subarray(dataStart, dataEnd);
  18885. }
  18886. format = format & 0x7f;
  18887. return new CFFEncoding(predefined, format, encoding, raw);
  18888. },
  18889. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18890. var start = pos;
  18891. var bytes = this.bytes;
  18892. var format = bytes[pos++];
  18893. var fdSelect = [];
  18894. var i;
  18895. switch (format) {
  18896. case 0:
  18897. for (i = 0; i < length; ++i) {
  18898. var id = bytes[pos++];
  18899. fdSelect.push(id);
  18900. }
  18901. break;
  18902. case 3:
  18903. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18904. for (i = 0; i < rangesCount; ++i) {
  18905. var first = (bytes[pos++] << 8) | bytes[pos++];
  18906. var fdIndex = bytes[pos++];
  18907. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18908. for (var j = first; j < next; ++j) {
  18909. fdSelect.push(fdIndex);
  18910. }
  18911. }
  18912. // Advance past the sentinel(next).
  18913. pos += 2;
  18914. break;
  18915. default:
  18916. error('Unknown fdselect format ' + format);
  18917. break;
  18918. }
  18919. var end = pos;
  18920. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18921. }
  18922. };
  18923. return CFFParser;
  18924. })();
  18925. // Compact Font Format
  18926. var CFF = (function CFFClosure() {
  18927. function CFF() {
  18928. this.header = null;
  18929. this.names = [];
  18930. this.topDict = null;
  18931. this.strings = new CFFStrings();
  18932. this.globalSubrIndex = null;
  18933. // The following could really be per font, but since we only have one font
  18934. // store them here.
  18935. this.encoding = null;
  18936. this.charset = null;
  18937. this.charStrings = null;
  18938. this.fdArray = [];
  18939. this.fdSelect = null;
  18940. this.isCIDFont = false;
  18941. }
  18942. return CFF;
  18943. })();
  18944. var CFFHeader = (function CFFHeaderClosure() {
  18945. function CFFHeader(major, minor, hdrSize, offSize) {
  18946. this.major = major;
  18947. this.minor = minor;
  18948. this.hdrSize = hdrSize;
  18949. this.offSize = offSize;
  18950. }
  18951. return CFFHeader;
  18952. })();
  18953. var CFFStrings = (function CFFStringsClosure() {
  18954. function CFFStrings() {
  18955. this.strings = [];
  18956. }
  18957. CFFStrings.prototype = {
  18958. get: function CFFStrings_get(index) {
  18959. if (index >= 0 && index <= 390) {
  18960. return CFFStandardStrings[index];
  18961. }
  18962. if (index - 391 <= this.strings.length) {
  18963. return this.strings[index - 391];
  18964. }
  18965. return CFFStandardStrings[0];
  18966. },
  18967. add: function CFFStrings_add(value) {
  18968. this.strings.push(value);
  18969. },
  18970. get count() {
  18971. return this.strings.length;
  18972. }
  18973. };
  18974. return CFFStrings;
  18975. })();
  18976. var CFFIndex = (function CFFIndexClosure() {
  18977. function CFFIndex() {
  18978. this.objects = [];
  18979. this.length = 0;
  18980. }
  18981. CFFIndex.prototype = {
  18982. add: function CFFIndex_add(data) {
  18983. this.length += data.length;
  18984. this.objects.push(data);
  18985. },
  18986. set: function CFFIndex_set(index, data) {
  18987. this.length += data.length - this.objects[index].length;
  18988. this.objects[index] = data;
  18989. },
  18990. get: function CFFIndex_get(index) {
  18991. return this.objects[index];
  18992. },
  18993. get count() {
  18994. return this.objects.length;
  18995. }
  18996. };
  18997. return CFFIndex;
  18998. })();
  18999. var CFFDict = (function CFFDictClosure() {
  19000. function CFFDict(tables, strings) {
  19001. this.keyToNameMap = tables.keyToNameMap;
  19002. this.nameToKeyMap = tables.nameToKeyMap;
  19003. this.defaults = tables.defaults;
  19004. this.types = tables.types;
  19005. this.opcodes = tables.opcodes;
  19006. this.order = tables.order;
  19007. this.strings = strings;
  19008. this.values = {};
  19009. }
  19010. CFFDict.prototype = {
  19011. // value should always be an array
  19012. setByKey: function CFFDict_setByKey(key, value) {
  19013. if (!(key in this.keyToNameMap)) {
  19014. return false;
  19015. }
  19016. // ignore empty values
  19017. if (value.length === 0) {
  19018. return true;
  19019. }
  19020. var type = this.types[key];
  19021. // remove the array wrapping these types of values
  19022. if (type === 'num' || type === 'sid' || type === 'offset') {
  19023. value = value[0];
  19024. }
  19025. this.values[key] = value;
  19026. return true;
  19027. },
  19028. setByName: function CFFDict_setByName(name, value) {
  19029. if (!(name in this.nameToKeyMap)) {
  19030. error('Invalid dictionary name "' + name + '"');
  19031. }
  19032. this.values[this.nameToKeyMap[name]] = value;
  19033. },
  19034. hasName: function CFFDict_hasName(name) {
  19035. return this.nameToKeyMap[name] in this.values;
  19036. },
  19037. getByName: function CFFDict_getByName(name) {
  19038. if (!(name in this.nameToKeyMap)) {
  19039. error('Invalid dictionary name "' + name + '"');
  19040. }
  19041. var key = this.nameToKeyMap[name];
  19042. if (!(key in this.values)) {
  19043. return this.defaults[key];
  19044. }
  19045. return this.values[key];
  19046. },
  19047. removeByName: function CFFDict_removeByName(name) {
  19048. delete this.values[this.nameToKeyMap[name]];
  19049. }
  19050. };
  19051. CFFDict.createTables = function CFFDict_createTables(layout) {
  19052. var tables = {
  19053. keyToNameMap: {},
  19054. nameToKeyMap: {},
  19055. defaults: {},
  19056. types: {},
  19057. opcodes: {},
  19058. order: []
  19059. };
  19060. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19061. var entry = layout[i];
  19062. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19063. tables.keyToNameMap[key] = entry[1];
  19064. tables.nameToKeyMap[entry[1]] = key;
  19065. tables.types[key] = entry[2];
  19066. tables.defaults[key] = entry[3];
  19067. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19068. tables.order.push(key);
  19069. }
  19070. return tables;
  19071. };
  19072. return CFFDict;
  19073. })();
  19074. var CFFTopDict = (function CFFTopDictClosure() {
  19075. var layout = [
  19076. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19077. [[12, 20], 'SyntheticBase', 'num', null],
  19078. [0, 'version', 'sid', null],
  19079. [1, 'Notice', 'sid', null],
  19080. [[12, 0], 'Copyright', 'sid', null],
  19081. [2, 'FullName', 'sid', null],
  19082. [3, 'FamilyName', 'sid', null],
  19083. [4, 'Weight', 'sid', null],
  19084. [[12, 1], 'isFixedPitch', 'num', 0],
  19085. [[12, 2], 'ItalicAngle', 'num', 0],
  19086. [[12, 3], 'UnderlinePosition', 'num', -100],
  19087. [[12, 4], 'UnderlineThickness', 'num', 50],
  19088. [[12, 5], 'PaintType', 'num', 0],
  19089. [[12, 6], 'CharstringType', 'num', 2],
  19090. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19091. [0.001, 0, 0, 0.001, 0, 0]],
  19092. [13, 'UniqueID', 'num', null],
  19093. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19094. [[12, 8], 'StrokeWidth', 'num', 0],
  19095. [14, 'XUID', 'array', null],
  19096. [15, 'charset', 'offset', 0],
  19097. [16, 'Encoding', 'offset', 0],
  19098. [17, 'CharStrings', 'offset', 0],
  19099. [18, 'Private', ['offset', 'offset'], null],
  19100. [[12, 21], 'PostScript', 'sid', null],
  19101. [[12, 22], 'BaseFontName', 'sid', null],
  19102. [[12, 23], 'BaseFontBlend', 'delta', null],
  19103. [[12, 31], 'CIDFontVersion', 'num', 0],
  19104. [[12, 32], 'CIDFontRevision', 'num', 0],
  19105. [[12, 33], 'CIDFontType', 'num', 0],
  19106. [[12, 34], 'CIDCount', 'num', 8720],
  19107. [[12, 35], 'UIDBase', 'num', null],
  19108. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19109. // before FDArray.
  19110. [[12, 37], 'FDSelect', 'offset', null],
  19111. [[12, 36], 'FDArray', 'offset', null],
  19112. [[12, 38], 'FontName', 'sid', null]
  19113. ];
  19114. var tables = null;
  19115. function CFFTopDict(strings) {
  19116. if (tables === null) {
  19117. tables = CFFDict.createTables(layout);
  19118. }
  19119. CFFDict.call(this, tables, strings);
  19120. this.privateDict = null;
  19121. }
  19122. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19123. return CFFTopDict;
  19124. })();
  19125. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19126. var layout = [
  19127. [6, 'BlueValues', 'delta', null],
  19128. [7, 'OtherBlues', 'delta', null],
  19129. [8, 'FamilyBlues', 'delta', null],
  19130. [9, 'FamilyOtherBlues', 'delta', null],
  19131. [[12, 9], 'BlueScale', 'num', 0.039625],
  19132. [[12, 10], 'BlueShift', 'num', 7],
  19133. [[12, 11], 'BlueFuzz', 'num', 1],
  19134. [10, 'StdHW', 'num', null],
  19135. [11, 'StdVW', 'num', null],
  19136. [[12, 12], 'StemSnapH', 'delta', null],
  19137. [[12, 13], 'StemSnapV', 'delta', null],
  19138. [[12, 14], 'ForceBold', 'num', 0],
  19139. [[12, 17], 'LanguageGroup', 'num', 0],
  19140. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19141. [[12, 19], 'initialRandomSeed', 'num', 0],
  19142. [20, 'defaultWidthX', 'num', 0],
  19143. [21, 'nominalWidthX', 'num', 0],
  19144. [19, 'Subrs', 'offset', null]
  19145. ];
  19146. var tables = null;
  19147. function CFFPrivateDict(strings) {
  19148. if (tables === null) {
  19149. tables = CFFDict.createTables(layout);
  19150. }
  19151. CFFDict.call(this, tables, strings);
  19152. this.subrsIndex = null;
  19153. }
  19154. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19155. return CFFPrivateDict;
  19156. })();
  19157. var CFFCharsetPredefinedTypes = {
  19158. ISO_ADOBE: 0,
  19159. EXPERT: 1,
  19160. EXPERT_SUBSET: 2
  19161. };
  19162. var CFFCharset = (function CFFCharsetClosure() {
  19163. function CFFCharset(predefined, format, charset, raw) {
  19164. this.predefined = predefined;
  19165. this.format = format;
  19166. this.charset = charset;
  19167. this.raw = raw;
  19168. }
  19169. return CFFCharset;
  19170. })();
  19171. var CFFEncoding = (function CFFEncodingClosure() {
  19172. function CFFEncoding(predefined, format, encoding, raw) {
  19173. this.predefined = predefined;
  19174. this.format = format;
  19175. this.encoding = encoding;
  19176. this.raw = raw;
  19177. }
  19178. return CFFEncoding;
  19179. })();
  19180. var CFFFDSelect = (function CFFFDSelectClosure() {
  19181. function CFFFDSelect(fdSelect, raw) {
  19182. this.fdSelect = fdSelect;
  19183. this.raw = raw;
  19184. }
  19185. return CFFFDSelect;
  19186. })();
  19187. // Helper class to keep track of where an offset is within the data and helps
  19188. // filling in that offset once it's known.
  19189. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19190. function CFFOffsetTracker() {
  19191. this.offsets = {};
  19192. }
  19193. CFFOffsetTracker.prototype = {
  19194. isTracking: function CFFOffsetTracker_isTracking(key) {
  19195. return key in this.offsets;
  19196. },
  19197. track: function CFFOffsetTracker_track(key, location) {
  19198. if (key in this.offsets) {
  19199. error('Already tracking location of ' + key);
  19200. }
  19201. this.offsets[key] = location;
  19202. },
  19203. offset: function CFFOffsetTracker_offset(value) {
  19204. for (var key in this.offsets) {
  19205. this.offsets[key] += value;
  19206. }
  19207. },
  19208. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19209. values,
  19210. output) {
  19211. if (!(key in this.offsets)) {
  19212. error('Not tracking location of ' + key);
  19213. }
  19214. var data = output.data;
  19215. var dataOffset = this.offsets[key];
  19216. var size = 5;
  19217. for (var i = 0, ii = values.length; i < ii; ++i) {
  19218. var offset0 = i * size + dataOffset;
  19219. var offset1 = offset0 + 1;
  19220. var offset2 = offset0 + 2;
  19221. var offset3 = offset0 + 3;
  19222. var offset4 = offset0 + 4;
  19223. // It's easy to screw up offsets so perform this sanity check.
  19224. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19225. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19226. error('writing to an offset that is not empty');
  19227. }
  19228. var value = values[i];
  19229. data[offset0] = 0x1d;
  19230. data[offset1] = (value >> 24) & 0xFF;
  19231. data[offset2] = (value >> 16) & 0xFF;
  19232. data[offset3] = (value >> 8) & 0xFF;
  19233. data[offset4] = value & 0xFF;
  19234. }
  19235. }
  19236. };
  19237. return CFFOffsetTracker;
  19238. })();
  19239. // Takes a CFF and converts it to the binary representation.
  19240. var CFFCompiler = (function CFFCompilerClosure() {
  19241. function CFFCompiler(cff) {
  19242. this.cff = cff;
  19243. }
  19244. CFFCompiler.prototype = {
  19245. compile: function CFFCompiler_compile() {
  19246. var cff = this.cff;
  19247. var output = {
  19248. data: [],
  19249. length: 0,
  19250. add: function CFFCompiler_add(data) {
  19251. this.data = this.data.concat(data);
  19252. this.length = this.data.length;
  19253. }
  19254. };
  19255. // Compile the five entries that must be in order.
  19256. var header = this.compileHeader(cff.header);
  19257. output.add(header);
  19258. var nameIndex = this.compileNameIndex(cff.names);
  19259. output.add(nameIndex);
  19260. if (cff.isCIDFont) {
  19261. // The spec is unclear on how font matrices should relate to each other
  19262. // when there is one in the main top dict and the sub top dicts.
  19263. // Windows handles this differently than linux and osx so we have to
  19264. // normalize to work on all.
  19265. // Rules based off of some mailing list discussions:
  19266. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19267. // - If no main font matrix and there is a subfont matrix, use the
  19268. // subfont matrix.
  19269. // - If both have matrices, concat together.
  19270. // - If neither have matrices, use default.
  19271. // To make this work on all platforms we move the top matrix into each
  19272. // sub top dict and concat if necessary.
  19273. if (cff.topDict.hasName('FontMatrix')) {
  19274. var base = cff.topDict.getByName('FontMatrix');
  19275. cff.topDict.removeByName('FontMatrix');
  19276. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19277. var subDict = cff.fdArray[i];
  19278. var matrix = base.slice(0);
  19279. if (subDict.hasName('FontMatrix')) {
  19280. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19281. }
  19282. subDict.setByName('FontMatrix', matrix);
  19283. }
  19284. }
  19285. }
  19286. var compiled = this.compileTopDicts([cff.topDict],
  19287. output.length,
  19288. cff.isCIDFont);
  19289. output.add(compiled.output);
  19290. var topDictTracker = compiled.trackers[0];
  19291. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19292. output.add(stringIndex);
  19293. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19294. output.add(globalSubrIndex);
  19295. // Now start on the other entries that have no specfic order.
  19296. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19297. if (cff.encoding.predefined) {
  19298. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19299. output);
  19300. } else {
  19301. var encoding = this.compileEncoding(cff.encoding);
  19302. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19303. output.add(encoding);
  19304. }
  19305. }
  19306. if (cff.charset && cff.topDict.hasName('charset')) {
  19307. if (cff.charset.predefined) {
  19308. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19309. output);
  19310. } else {
  19311. var charset = this.compileCharset(cff.charset);
  19312. topDictTracker.setEntryLocation('charset', [output.length], output);
  19313. output.add(charset);
  19314. }
  19315. }
  19316. var charStrings = this.compileCharStrings(cff.charStrings);
  19317. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19318. output.add(charStrings);
  19319. if (cff.isCIDFont) {
  19320. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19321. // and linux don't seem to care.
  19322. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19323. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19324. output.add(fdSelect);
  19325. // It is unclear if the sub font dictionary can have CID related
  19326. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19327. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19328. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19329. output.add(compiled.output);
  19330. var fontDictTrackers = compiled.trackers;
  19331. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19332. }
  19333. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19334. // If the font data ends with INDEX whose object data is zero-length,
  19335. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19336. output.add([0]);
  19337. return output.data;
  19338. },
  19339. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19340. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19341. return this.encodeInteger(value);
  19342. } else {
  19343. return this.encodeFloat(value);
  19344. }
  19345. },
  19346. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19347. var value = num.toString();
  19348. // rounding inaccurate doubles
  19349. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19350. if (m) {
  19351. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19352. value = (Math.round(num * epsilon) / epsilon).toString();
  19353. }
  19354. var nibbles = '';
  19355. var i, ii;
  19356. for (i = 0, ii = value.length; i < ii; ++i) {
  19357. var a = value[i];
  19358. if (a === 'e') {
  19359. nibbles += value[++i] === '-' ? 'c' : 'b';
  19360. } else if (a === '.') {
  19361. nibbles += 'a';
  19362. } else if (a === '-') {
  19363. nibbles += 'e';
  19364. } else {
  19365. nibbles += a;
  19366. }
  19367. }
  19368. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19369. var out = [30];
  19370. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19371. out.push(parseInt(nibbles.substr(i, 2), 16));
  19372. }
  19373. return out;
  19374. },
  19375. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19376. var code;
  19377. if (value >= -107 && value <= 107) {
  19378. code = [value + 139];
  19379. } else if (value >= 108 && value <= 1131) {
  19380. value = [value - 108];
  19381. code = [(value >> 8) + 247, value & 0xFF];
  19382. } else if (value >= -1131 && value <= -108) {
  19383. value = -value - 108;
  19384. code = [(value >> 8) + 251, value & 0xFF];
  19385. } else if (value >= -32768 && value <= 32767) {
  19386. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19387. } else {
  19388. code = [0x1d,
  19389. (value >> 24) & 0xFF,
  19390. (value >> 16) & 0xFF,
  19391. (value >> 8) & 0xFF,
  19392. value & 0xFF];
  19393. }
  19394. return code;
  19395. },
  19396. compileHeader: function CFFCompiler_compileHeader(header) {
  19397. return [
  19398. header.major,
  19399. header.minor,
  19400. header.hdrSize,
  19401. header.offSize
  19402. ];
  19403. },
  19404. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19405. var nameIndex = new CFFIndex();
  19406. for (var i = 0, ii = names.length; i < ii; ++i) {
  19407. nameIndex.add(stringToBytes(names[i]));
  19408. }
  19409. return this.compileIndex(nameIndex);
  19410. },
  19411. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19412. length,
  19413. removeCidKeys) {
  19414. var fontDictTrackers = [];
  19415. var fdArrayIndex = new CFFIndex();
  19416. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19417. var fontDict = dicts[i];
  19418. if (removeCidKeys) {
  19419. fontDict.removeByName('CIDFontVersion');
  19420. fontDict.removeByName('CIDFontRevision');
  19421. fontDict.removeByName('CIDFontType');
  19422. fontDict.removeByName('CIDCount');
  19423. fontDict.removeByName('UIDBase');
  19424. }
  19425. var fontDictTracker = new CFFOffsetTracker();
  19426. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19427. fontDictTrackers.push(fontDictTracker);
  19428. fdArrayIndex.add(fontDictData);
  19429. fontDictTracker.offset(length);
  19430. }
  19431. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19432. return {
  19433. trackers: fontDictTrackers,
  19434. output: fdArrayIndex
  19435. };
  19436. },
  19437. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19438. trackers,
  19439. output) {
  19440. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19441. var fontDict = dicts[i];
  19442. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19443. 'There must be an private dictionary.');
  19444. var privateDict = fontDict.privateDict;
  19445. var privateDictTracker = new CFFOffsetTracker();
  19446. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19447. var outputLength = output.length;
  19448. privateDictTracker.offset(outputLength);
  19449. if (!privateDictData.length) {
  19450. // The private dictionary was empty, set the output length to zero to
  19451. // ensure the offset length isn't out of bounds in the eyes of the
  19452. // sanitizer.
  19453. outputLength = 0;
  19454. }
  19455. trackers[i].setEntryLocation('Private',
  19456. [privateDictData.length, outputLength],
  19457. output);
  19458. output.add(privateDictData);
  19459. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19460. var subrs = this.compileIndex(privateDict.subrsIndex);
  19461. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19462. output);
  19463. output.add(subrs);
  19464. }
  19465. }
  19466. },
  19467. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19468. var out = [];
  19469. // The dictionary keys must be in a certain order.
  19470. var order = dict.order;
  19471. for (var i = 0; i < order.length; ++i) {
  19472. var key = order[i];
  19473. if (!(key in dict.values)) {
  19474. continue;
  19475. }
  19476. var values = dict.values[key];
  19477. var types = dict.types[key];
  19478. if (!isArray(types)) {
  19479. types = [types];
  19480. }
  19481. if (!isArray(values)) {
  19482. values = [values];
  19483. }
  19484. // Remove any empty dict values.
  19485. if (values.length === 0) {
  19486. continue;
  19487. }
  19488. for (var j = 0, jj = types.length; j < jj; ++j) {
  19489. var type = types[j];
  19490. var value = values[j];
  19491. switch (type) {
  19492. case 'num':
  19493. case 'sid':
  19494. out = out.concat(this.encodeNumber(value));
  19495. break;
  19496. case 'offset':
  19497. // For offsets we just insert a 32bit integer so we don't have to
  19498. // deal with figuring out the length of the offset when it gets
  19499. // replaced later on by the compiler.
  19500. var name = dict.keyToNameMap[key];
  19501. // Some offsets have the offset and the length, so just record the
  19502. // position of the first one.
  19503. if (!offsetTracker.isTracking(name)) {
  19504. offsetTracker.track(name, out.length);
  19505. }
  19506. out = out.concat([0x1d, 0, 0, 0, 0]);
  19507. break;
  19508. case 'array':
  19509. case 'delta':
  19510. out = out.concat(this.encodeNumber(value));
  19511. for (var k = 1, kk = values.length; k < kk; ++k) {
  19512. out = out.concat(this.encodeNumber(values[k]));
  19513. }
  19514. break;
  19515. default:
  19516. error('Unknown data type of ' + type);
  19517. break;
  19518. }
  19519. }
  19520. out = out.concat(dict.opcodes[key]);
  19521. }
  19522. return out;
  19523. },
  19524. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19525. var stringIndex = new CFFIndex();
  19526. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19527. stringIndex.add(stringToBytes(strings[i]));
  19528. }
  19529. return this.compileIndex(stringIndex);
  19530. },
  19531. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19532. var globalSubrIndex = this.cff.globalSubrIndex;
  19533. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19534. },
  19535. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19536. return this.compileIndex(charStrings);
  19537. },
  19538. compileCharset: function CFFCompiler_compileCharset(charset) {
  19539. return this.compileTypedArray(charset.raw);
  19540. },
  19541. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19542. return this.compileTypedArray(encoding.raw);
  19543. },
  19544. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19545. return this.compileTypedArray(fdSelect);
  19546. },
  19547. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19548. var out = [];
  19549. for (var i = 0, ii = data.length; i < ii; ++i) {
  19550. out[i] = data[i];
  19551. }
  19552. return out;
  19553. },
  19554. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19555. trackers = trackers || [];
  19556. var objects = index.objects;
  19557. // First 2 bytes contains the number of objects contained into this index
  19558. var count = objects.length;
  19559. // If there is no object, just create an index. This technically
  19560. // should just be [0, 0] but OTS has an issue with that.
  19561. if (count === 0) {
  19562. return [0, 0, 0];
  19563. }
  19564. var data = [(count >> 8) & 0xFF, count & 0xff];
  19565. var lastOffset = 1, i;
  19566. for (i = 0; i < count; ++i) {
  19567. lastOffset += objects[i].length;
  19568. }
  19569. var offsetSize;
  19570. if (lastOffset < 0x100) {
  19571. offsetSize = 1;
  19572. } else if (lastOffset < 0x10000) {
  19573. offsetSize = 2;
  19574. } else if (lastOffset < 0x1000000) {
  19575. offsetSize = 3;
  19576. } else {
  19577. offsetSize = 4;
  19578. }
  19579. // Next byte contains the offset size use to reference object in the file
  19580. data.push(offsetSize);
  19581. // Add another offset after this one because we need a new offset
  19582. var relativeOffset = 1;
  19583. for (i = 0; i < count + 1; i++) {
  19584. if (offsetSize === 1) {
  19585. data.push(relativeOffset & 0xFF);
  19586. } else if (offsetSize === 2) {
  19587. data.push((relativeOffset >> 8) & 0xFF,
  19588. relativeOffset & 0xFF);
  19589. } else if (offsetSize === 3) {
  19590. data.push((relativeOffset >> 16) & 0xFF,
  19591. (relativeOffset >> 8) & 0xFF,
  19592. relativeOffset & 0xFF);
  19593. } else {
  19594. data.push((relativeOffset >>> 24) & 0xFF,
  19595. (relativeOffset >> 16) & 0xFF,
  19596. (relativeOffset >> 8) & 0xFF,
  19597. relativeOffset & 0xFF);
  19598. }
  19599. if (objects[i]) {
  19600. relativeOffset += objects[i].length;
  19601. }
  19602. }
  19603. for (i = 0; i < count; i++) {
  19604. // Notify the tracker where the object will be offset in the data.
  19605. if (trackers[i]) {
  19606. trackers[i].offset(data.length);
  19607. }
  19608. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19609. data.push(objects[i][j]);
  19610. }
  19611. }
  19612. return data;
  19613. }
  19614. };
  19615. return CFFCompiler;
  19616. })();
  19617. // Workaround for seac on Windows.
  19618. (function checkSeacSupport() {
  19619. if (/Windows/.test(navigator.userAgent)) {
  19620. SEAC_ANALYSIS_ENABLED = true;
  19621. }
  19622. })();
  19623. // Workaround for Private Use Area characters in Chrome on Windows
  19624. // http://code.google.com/p/chromium/issues/detail?id=122465
  19625. // https://github.com/mozilla/pdf.js/issues/1689
  19626. (function checkChromeWindows() {
  19627. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19628. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19629. }
  19630. })();
  19631. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19632. function getLong(data, offset) {
  19633. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19634. (data[offset + 2] << 8) | data[offset + 3];
  19635. }
  19636. function getUshort(data, offset) {
  19637. return (data[offset] << 8) | data[offset + 1];
  19638. }
  19639. function parseCmap(data, start, end) {
  19640. var offset = (getUshort(data, start + 2) === 1 ?
  19641. getLong(data, start + 8) : getLong(data, start + 16));
  19642. var format = getUshort(data, start + offset);
  19643. var length, ranges, p, i;
  19644. if (format === 4) {
  19645. length = getUshort(data, start + offset + 2);
  19646. var segCount = getUshort(data, start + offset + 6) >> 1;
  19647. p = start + offset + 14;
  19648. ranges = [];
  19649. for (i = 0; i < segCount; i++, p += 2) {
  19650. ranges[i] = {end: getUshort(data, p)};
  19651. }
  19652. p += 2;
  19653. for (i = 0; i < segCount; i++, p += 2) {
  19654. ranges[i].start = getUshort(data, p);
  19655. }
  19656. for (i = 0; i < segCount; i++, p += 2) {
  19657. ranges[i].idDelta = getUshort(data, p);
  19658. }
  19659. for (i = 0; i < segCount; i++, p += 2) {
  19660. var idOffset = getUshort(data, p);
  19661. if (idOffset === 0) {
  19662. continue;
  19663. }
  19664. ranges[i].ids = [];
  19665. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19666. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19667. idOffset += 2;
  19668. }
  19669. }
  19670. return ranges;
  19671. } else if (format === 12) {
  19672. length = getLong(data, start + offset + 4);
  19673. var groups = getLong(data, start + offset + 12);
  19674. p = start + offset + 16;
  19675. ranges = [];
  19676. for (i = 0; i < groups; i++) {
  19677. ranges.push({
  19678. start: getLong(data, p),
  19679. end: getLong(data, p + 4),
  19680. idDelta: getLong(data, p + 8) - getLong(data, p)
  19681. });
  19682. p += 12;
  19683. }
  19684. return ranges;
  19685. }
  19686. error('not supported cmap: ' + format);
  19687. }
  19688. function parseCff(data, start, end) {
  19689. var properties = {};
  19690. var parser = new CFFParser(new Stream(data, start, end - start),
  19691. properties);
  19692. var cff = parser.parse();
  19693. return {
  19694. glyphs: cff.charStrings.objects,
  19695. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19696. cff.topDict.privateDict.subrsIndex.objects),
  19697. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19698. };
  19699. }
  19700. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19701. var itemSize, itemDecode;
  19702. if (isGlyphLocationsLong) {
  19703. itemSize = 4;
  19704. itemDecode = function fontItemDecodeLong(data, offset) {
  19705. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19706. (data[offset + 2] << 8) | data[offset + 3];
  19707. };
  19708. } else {
  19709. itemSize = 2;
  19710. itemDecode = function fontItemDecode(data, offset) {
  19711. return (data[offset] << 9) | (data[offset + 1] << 1);
  19712. };
  19713. }
  19714. var glyphs = [];
  19715. var startOffset = itemDecode(loca, 0);
  19716. for (var j = itemSize; j < loca.length; j += itemSize) {
  19717. var endOffset = itemDecode(loca, j);
  19718. glyphs.push(glyf.subarray(startOffset, endOffset));
  19719. startOffset = endOffset;
  19720. }
  19721. return glyphs;
  19722. }
  19723. function lookupCmap(ranges, unicode) {
  19724. var code = unicode.charCodeAt(0);
  19725. var l = 0, r = ranges.length - 1;
  19726. while (l < r) {
  19727. var c = (l + r + 1) >> 1;
  19728. if (code < ranges[c].start) {
  19729. r = c - 1;
  19730. } else {
  19731. l = c;
  19732. }
  19733. }
  19734. if (ranges[l].start <= code && code <= ranges[l].end) {
  19735. return (ranges[l].idDelta + (ranges[l].ids ?
  19736. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19737. }
  19738. return 0;
  19739. }
  19740. function compileGlyf(code, js, font) {
  19741. function moveTo(x, y) {
  19742. js.push('c.moveTo(' + x + ',' + y + ');');
  19743. }
  19744. function lineTo(x, y) {
  19745. js.push('c.lineTo(' + x + ',' + y + ');');
  19746. }
  19747. function quadraticCurveTo(xa, ya, x, y) {
  19748. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19749. x + ',' + y + ');');
  19750. }
  19751. var i = 0;
  19752. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19753. var flags;
  19754. var x = 0, y = 0;
  19755. i += 10;
  19756. if (numberOfContours < 0) {
  19757. // composite glyph
  19758. do {
  19759. flags = (code[i] << 8) | code[i + 1];
  19760. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19761. i += 4;
  19762. var arg1, arg2;
  19763. if ((flags & 0x01)) {
  19764. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19765. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19766. i += 4;
  19767. } else {
  19768. arg1 = code[i++]; arg2 = code[i++];
  19769. }
  19770. if ((flags & 0x02)) {
  19771. x = arg1;
  19772. y = arg2;
  19773. } else {
  19774. x = 0; y = 0; // TODO "they are points" ?
  19775. }
  19776. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19777. if ((flags & 0x08)) {
  19778. scaleX =
  19779. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19780. i += 2;
  19781. } else if ((flags & 0x40)) {
  19782. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19783. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19784. i += 4;
  19785. } else if ((flags & 0x80)) {
  19786. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19787. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19788. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19789. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19790. i += 8;
  19791. }
  19792. var subglyph = font.glyphs[glyphIndex];
  19793. if (subglyph) {
  19794. js.push('c.save();');
  19795. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19796. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19797. compileGlyf(subglyph, js, font);
  19798. js.push('c.restore();');
  19799. }
  19800. } while ((flags & 0x20));
  19801. } else {
  19802. // simple glyph
  19803. var endPtsOfContours = [];
  19804. var j, jj;
  19805. for (j = 0; j < numberOfContours; j++) {
  19806. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19807. i += 2;
  19808. }
  19809. var instructionLength = (code[i] << 8) | code[i + 1];
  19810. i += 2 + instructionLength; // skipping the instructions
  19811. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19812. var points = [];
  19813. while (points.length < numberOfPoints) {
  19814. flags = code[i++];
  19815. var repeat = 1;
  19816. if ((flags & 0x08)) {
  19817. repeat += code[i++];
  19818. }
  19819. while (repeat-- > 0) {
  19820. points.push({flags: flags});
  19821. }
  19822. }
  19823. for (j = 0; j < numberOfPoints; j++) {
  19824. switch (points[j].flags & 0x12) {
  19825. case 0x00:
  19826. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19827. i += 2;
  19828. break;
  19829. case 0x02:
  19830. x -= code[i++];
  19831. break;
  19832. case 0x12:
  19833. x += code[i++];
  19834. break;
  19835. }
  19836. points[j].x = x;
  19837. }
  19838. for (j = 0; j < numberOfPoints; j++) {
  19839. switch (points[j].flags & 0x24) {
  19840. case 0x00:
  19841. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19842. i += 2;
  19843. break;
  19844. case 0x04:
  19845. y -= code[i++];
  19846. break;
  19847. case 0x24:
  19848. y += code[i++];
  19849. break;
  19850. }
  19851. points[j].y = y;
  19852. }
  19853. var startPoint = 0;
  19854. for (i = 0; i < numberOfContours; i++) {
  19855. var endPoint = endPtsOfContours[i];
  19856. // contours might have implicit points, which is located in the middle
  19857. // between two neighboring off-curve points
  19858. var contour = points.slice(startPoint, endPoint + 1);
  19859. if ((contour[0].flags & 1)) {
  19860. contour.push(contour[0]); // using start point at the contour end
  19861. } else if ((contour[contour.length - 1].flags & 1)) {
  19862. // first is off-curve point, trying to use one from the end
  19863. contour.unshift(contour[contour.length - 1]);
  19864. } else {
  19865. // start and end are off-curve points, creating implicit one
  19866. var p = {
  19867. flags: 1,
  19868. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19869. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19870. };
  19871. contour.unshift(p);
  19872. contour.push(p);
  19873. }
  19874. moveTo(contour[0].x, contour[0].y);
  19875. for (j = 1, jj = contour.length; j < jj; j++) {
  19876. if ((contour[j].flags & 1)) {
  19877. lineTo(contour[j].x, contour[j].y);
  19878. } else if ((contour[j + 1].flags & 1)){
  19879. quadraticCurveTo(contour[j].x, contour[j].y,
  19880. contour[j + 1].x, contour[j + 1].y);
  19881. j++;
  19882. } else {
  19883. quadraticCurveTo(contour[j].x, contour[j].y,
  19884. (contour[j].x + contour[j + 1].x) / 2,
  19885. (contour[j].y + contour[j + 1].y) / 2);
  19886. }
  19887. }
  19888. startPoint = endPoint + 1;
  19889. }
  19890. }
  19891. }
  19892. function compileCharString(code, js, font) {
  19893. var stack = [];
  19894. var x = 0, y = 0;
  19895. var stems = 0;
  19896. function moveTo(x, y) {
  19897. js.push('c.moveTo(' + x + ',' + y + ');');
  19898. }
  19899. function lineTo(x, y) {
  19900. js.push('c.lineTo(' + x + ',' + y + ');');
  19901. }
  19902. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19903. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19904. x + ',' + y + ');');
  19905. }
  19906. function parse(code) {
  19907. var i = 0;
  19908. while (i < code.length) {
  19909. var stackClean = false;
  19910. var v = code[i++];
  19911. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19912. switch (v) {
  19913. case 1: // hstem
  19914. stems += stack.length >> 1;
  19915. stackClean = true;
  19916. break;
  19917. case 3: // vstem
  19918. stems += stack.length >> 1;
  19919. stackClean = true;
  19920. break;
  19921. case 4: // vmoveto
  19922. y += stack.pop();
  19923. moveTo(x, y);
  19924. stackClean = true;
  19925. break;
  19926. case 5: // rlineto
  19927. while (stack.length > 0) {
  19928. x += stack.shift();
  19929. y += stack.shift();
  19930. lineTo(x, y);
  19931. }
  19932. break;
  19933. case 6: // hlineto
  19934. while (stack.length > 0) {
  19935. x += stack.shift();
  19936. lineTo(x, y);
  19937. if (stack.length === 0) {
  19938. break;
  19939. }
  19940. y += stack.shift();
  19941. lineTo(x, y);
  19942. }
  19943. break;
  19944. case 7: // vlineto
  19945. while (stack.length > 0) {
  19946. y += stack.shift();
  19947. lineTo(x, y);
  19948. if (stack.length === 0) {
  19949. break;
  19950. }
  19951. x += stack.shift();
  19952. lineTo(x, y);
  19953. }
  19954. break;
  19955. case 8: // rrcurveto
  19956. while (stack.length > 0) {
  19957. xa = x + stack.shift(); ya = y + stack.shift();
  19958. xb = xa + stack.shift(); yb = ya + stack.shift();
  19959. x = xb + stack.shift(); y = yb + stack.shift();
  19960. bezierCurveTo(xa, ya, xb, yb, x, y);
  19961. }
  19962. break;
  19963. case 10: // callsubr
  19964. n = stack.pop() + font.subrsBias;
  19965. subrCode = font.subrs[n];
  19966. if (subrCode) {
  19967. parse(subrCode);
  19968. }
  19969. break;
  19970. case 11: // return
  19971. return;
  19972. case 12:
  19973. v = code[i++];
  19974. switch (v) {
  19975. case 34: // flex
  19976. xa = x + stack.shift();
  19977. xb = xa + stack.shift(); y1 = y + stack.shift();
  19978. x = xb + stack.shift();
  19979. bezierCurveTo(xa, y, xb, y1, x, y1);
  19980. xa = x + stack.shift();
  19981. xb = xa + stack.shift();
  19982. x = xb + stack.shift();
  19983. bezierCurveTo(xa, y1, xb, y, x, y);
  19984. break;
  19985. case 35: // flex
  19986. xa = x + stack.shift(); ya = y + stack.shift();
  19987. xb = xa + stack.shift(); yb = ya + stack.shift();
  19988. x = xb + stack.shift(); y = yb + stack.shift();
  19989. bezierCurveTo(xa, ya, xb, yb, x, y);
  19990. xa = x + stack.shift(); ya = y + stack.shift();
  19991. xb = xa + stack.shift(); yb = ya + stack.shift();
  19992. x = xb + stack.shift(); y = yb + stack.shift();
  19993. bezierCurveTo(xa, ya, xb, yb, x, y);
  19994. stack.pop(); // fd
  19995. break;
  19996. case 36: // hflex1
  19997. xa = x + stack.shift(); y1 = y + stack.shift();
  19998. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19999. x = xb + stack.shift();
  20000. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20001. xa = x + stack.shift();
  20002. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20003. x = xb + stack.shift();
  20004. bezierCurveTo(xa, y2, xb, y3, x, y);
  20005. break;
  20006. case 37: // flex1
  20007. var x0 = x, y0 = y;
  20008. xa = x + stack.shift(); ya = y + stack.shift();
  20009. xb = xa + stack.shift(); yb = ya + stack.shift();
  20010. x = xb + stack.shift(); y = yb + stack.shift();
  20011. bezierCurveTo(xa, ya, xb, yb, x, y);
  20012. xa = x + stack.shift(); ya = y + stack.shift();
  20013. xb = xa + stack.shift(); yb = ya + stack.shift();
  20014. x = xb; y = yb;
  20015. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20016. x += stack.shift();
  20017. } else {
  20018. y += stack.shift();
  20019. }
  20020. bezierCurveTo(xa, ya, xb, yb, x, y);
  20021. break;
  20022. default:
  20023. error('unknown operator: 12 ' + v);
  20024. }
  20025. break;
  20026. case 14: // endchar
  20027. if (stack.length >= 4) {
  20028. var achar = stack.pop();
  20029. var bchar = stack.pop();
  20030. y = stack.pop();
  20031. x = stack.pop();
  20032. js.push('c.save();');
  20033. js.push('c.translate('+ x + ',' + y + ');');
  20034. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20035. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20036. compileCharString(font.glyphs[gid], js, font);
  20037. js.push('c.restore();');
  20038. gid = lookupCmap(font.cmap, String.fromCharCode(
  20039. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20040. compileCharString(font.glyphs[gid], js, font);
  20041. }
  20042. return;
  20043. case 18: // hstemhm
  20044. stems += stack.length >> 1;
  20045. stackClean = true;
  20046. break;
  20047. case 19: // hintmask
  20048. stems += stack.length >> 1;
  20049. i += (stems + 7) >> 3;
  20050. stackClean = true;
  20051. break;
  20052. case 20: // cntrmask
  20053. stems += stack.length >> 1;
  20054. i += (stems + 7) >> 3;
  20055. stackClean = true;
  20056. break;
  20057. case 21: // rmoveto
  20058. y += stack.pop();
  20059. x += stack.pop();
  20060. moveTo(x, y);
  20061. stackClean = true;
  20062. break;
  20063. case 22: // hmoveto
  20064. x += stack.pop();
  20065. moveTo(x, y);
  20066. stackClean = true;
  20067. break;
  20068. case 23: // vstemhm
  20069. stems += stack.length >> 1;
  20070. stackClean = true;
  20071. break;
  20072. case 24: // rcurveline
  20073. while (stack.length > 2) {
  20074. xa = x + stack.shift(); ya = y + stack.shift();
  20075. xb = xa + stack.shift(); yb = ya + stack.shift();
  20076. x = xb + stack.shift(); y = yb + stack.shift();
  20077. bezierCurveTo(xa, ya, xb, yb, x, y);
  20078. }
  20079. x += stack.shift();
  20080. y += stack.shift();
  20081. lineTo(x, y);
  20082. break;
  20083. case 25: // rlinecurve
  20084. while (stack.length > 6) {
  20085. x += stack.shift();
  20086. y += stack.shift();
  20087. lineTo(x, y);
  20088. }
  20089. xa = x + stack.shift(); ya = y + stack.shift();
  20090. xb = xa + stack.shift(); yb = ya + stack.shift();
  20091. x = xb + stack.shift(); y = yb + stack.shift();
  20092. bezierCurveTo(xa, ya, xb, yb, x, y);
  20093. break;
  20094. case 26: // vvcurveto
  20095. if (stack.length % 2) {
  20096. x += stack.shift();
  20097. }
  20098. while (stack.length > 0) {
  20099. xa = x; ya = y + stack.shift();
  20100. xb = xa + stack.shift(); yb = ya + stack.shift();
  20101. x = xb; y = yb + stack.shift();
  20102. bezierCurveTo(xa, ya, xb, yb, x, y);
  20103. }
  20104. break;
  20105. case 27: // hhcurveto
  20106. if (stack.length % 2) {
  20107. y += stack.shift();
  20108. }
  20109. while (stack.length > 0) {
  20110. xa = x + stack.shift(); ya = y;
  20111. xb = xa + stack.shift(); yb = ya + stack.shift();
  20112. x = xb + stack.shift(); y = yb;
  20113. bezierCurveTo(xa, ya, xb, yb, x, y);
  20114. }
  20115. break;
  20116. case 28:
  20117. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20118. i += 2;
  20119. break;
  20120. case 29: // callgsubr
  20121. n = stack.pop() + font.gsubrsBias;
  20122. subrCode = font.gsubrs[n];
  20123. if (subrCode) {
  20124. parse(subrCode);
  20125. }
  20126. break;
  20127. case 30: // vhcurveto
  20128. while (stack.length > 0) {
  20129. xa = x; ya = y + stack.shift();
  20130. xb = xa + stack.shift(); yb = ya + stack.shift();
  20131. x = xb + stack.shift();
  20132. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20133. bezierCurveTo(xa, ya, xb, yb, x, y);
  20134. if (stack.length === 0) {
  20135. break;
  20136. }
  20137. xa = x + stack.shift(); ya = y;
  20138. xb = xa + stack.shift(); yb = ya + stack.shift();
  20139. y = yb + stack.shift();
  20140. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20141. bezierCurveTo(xa, ya, xb, yb, x, y);
  20142. }
  20143. break;
  20144. case 31: // hvcurveto
  20145. while (stack.length > 0) {
  20146. xa = x + stack.shift(); ya = y;
  20147. xb = xa + stack.shift(); yb = ya + stack.shift();
  20148. y = yb + stack.shift();
  20149. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20150. bezierCurveTo(xa, ya, xb, yb, x, y);
  20151. if (stack.length === 0) {
  20152. break;
  20153. }
  20154. xa = x; ya = y + stack.shift();
  20155. xb = xa + stack.shift(); yb = ya + stack.shift();
  20156. x = xb + stack.shift();
  20157. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20158. bezierCurveTo(xa, ya, xb, yb, x, y);
  20159. }
  20160. break;
  20161. default:
  20162. if (v < 32) {
  20163. error('unknown operator: ' + v);
  20164. }
  20165. if (v < 247) {
  20166. stack.push(v - 139);
  20167. } else if (v < 251) {
  20168. stack.push((v - 247) * 256 + code[i++] + 108);
  20169. } else if (v < 255) {
  20170. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20171. } else {
  20172. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20173. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20174. i += 4;
  20175. }
  20176. break;
  20177. }
  20178. if (stackClean) {
  20179. stack.length = 0;
  20180. }
  20181. }
  20182. }
  20183. parse(code);
  20184. }
  20185. var noop = '';
  20186. function CompiledFont(fontMatrix) {
  20187. this.compiledGlyphs = {};
  20188. this.fontMatrix = fontMatrix;
  20189. }
  20190. CompiledFont.prototype = {
  20191. getPathJs: function (unicode) {
  20192. var gid = lookupCmap(this.cmap, unicode);
  20193. var fn = this.compiledGlyphs[gid];
  20194. if (!fn) {
  20195. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20196. }
  20197. return fn;
  20198. },
  20199. compileGlyph: function (code) {
  20200. if (!code || code.length === 0 || code[0] === 14) {
  20201. return noop;
  20202. }
  20203. var js = [];
  20204. js.push('c.save();');
  20205. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20206. js.push('c.scale(size, -size);');
  20207. this.compileGlyphImpl(code, js);
  20208. js.push('c.restore();');
  20209. return js.join('\n');
  20210. },
  20211. compileGlyphImpl: function () {
  20212. error('Children classes should implement this.');
  20213. },
  20214. hasBuiltPath: function (unicode) {
  20215. var gid = lookupCmap(this.cmap, unicode);
  20216. return gid in this.compiledGlyphs;
  20217. }
  20218. };
  20219. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20220. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20221. CompiledFont.call(this, fontMatrix);
  20222. this.glyphs = glyphs;
  20223. this.cmap = cmap;
  20224. this.compiledGlyphs = [];
  20225. }
  20226. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20227. compileGlyphImpl: function (code, js) {
  20228. compileGlyf(code, js, this);
  20229. }
  20230. });
  20231. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20232. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20233. CompiledFont.call(this, fontMatrix);
  20234. this.glyphs = cffInfo.glyphs;
  20235. this.gsubrs = cffInfo.gsubrs || [];
  20236. this.subrs = cffInfo.subrs || [];
  20237. this.cmap = cmap;
  20238. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20239. this.compiledGlyphs = [];
  20240. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20241. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20242. this.subrsBias = (this.subrs.length < 1240 ?
  20243. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20244. }
  20245. Util.inherit(Type2Compiled, CompiledFont, {
  20246. compileGlyphImpl: function (code, js) {
  20247. compileCharString(code, js, this);
  20248. }
  20249. });
  20250. return {
  20251. create: function FontRendererFactory_create(font) {
  20252. var data = new Uint8Array(font.data);
  20253. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20254. var numTables = getUshort(data, 4);
  20255. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20256. var tag = bytesToString(data.subarray(p, p + 4));
  20257. var offset = getLong(data, p + 8);
  20258. var length = getLong(data, p + 12);
  20259. switch (tag) {
  20260. case 'cmap':
  20261. cmap = parseCmap(data, offset, offset + length);
  20262. break;
  20263. case 'glyf':
  20264. glyf = data.subarray(offset, offset + length);
  20265. break;
  20266. case 'loca':
  20267. loca = data.subarray(offset, offset + length);
  20268. break;
  20269. case 'head':
  20270. unitsPerEm = getUshort(data, offset + 18);
  20271. indexToLocFormat = getUshort(data, offset + 50);
  20272. break;
  20273. case 'CFF ':
  20274. cff = parseCff(data, offset, offset + length);
  20275. break;
  20276. }
  20277. }
  20278. if (glyf) {
  20279. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20280. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20281. return new TrueTypeCompiled(
  20282. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20283. } else {
  20284. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20285. }
  20286. }
  20287. };
  20288. })();
  20289. var GlyphsUnicode = {
  20290. A: 0x0041,
  20291. AE: 0x00C6,
  20292. AEacute: 0x01FC,
  20293. AEmacron: 0x01E2,
  20294. AEsmall: 0xF7E6,
  20295. Aacute: 0x00C1,
  20296. Aacutesmall: 0xF7E1,
  20297. Abreve: 0x0102,
  20298. Abreveacute: 0x1EAE,
  20299. Abrevecyrillic: 0x04D0,
  20300. Abrevedotbelow: 0x1EB6,
  20301. Abrevegrave: 0x1EB0,
  20302. Abrevehookabove: 0x1EB2,
  20303. Abrevetilde: 0x1EB4,
  20304. Acaron: 0x01CD,
  20305. Acircle: 0x24B6,
  20306. Acircumflex: 0x00C2,
  20307. Acircumflexacute: 0x1EA4,
  20308. Acircumflexdotbelow: 0x1EAC,
  20309. Acircumflexgrave: 0x1EA6,
  20310. Acircumflexhookabove: 0x1EA8,
  20311. Acircumflexsmall: 0xF7E2,
  20312. Acircumflextilde: 0x1EAA,
  20313. Acute: 0xF6C9,
  20314. Acutesmall: 0xF7B4,
  20315. Acyrillic: 0x0410,
  20316. Adblgrave: 0x0200,
  20317. Adieresis: 0x00C4,
  20318. Adieresiscyrillic: 0x04D2,
  20319. Adieresismacron: 0x01DE,
  20320. Adieresissmall: 0xF7E4,
  20321. Adotbelow: 0x1EA0,
  20322. Adotmacron: 0x01E0,
  20323. Agrave: 0x00C0,
  20324. Agravesmall: 0xF7E0,
  20325. Ahookabove: 0x1EA2,
  20326. Aiecyrillic: 0x04D4,
  20327. Ainvertedbreve: 0x0202,
  20328. Alpha: 0x0391,
  20329. Alphatonos: 0x0386,
  20330. Amacron: 0x0100,
  20331. Amonospace: 0xFF21,
  20332. Aogonek: 0x0104,
  20333. Aring: 0x00C5,
  20334. Aringacute: 0x01FA,
  20335. Aringbelow: 0x1E00,
  20336. Aringsmall: 0xF7E5,
  20337. Asmall: 0xF761,
  20338. Atilde: 0x00C3,
  20339. Atildesmall: 0xF7E3,
  20340. Aybarmenian: 0x0531,
  20341. B: 0x0042,
  20342. Bcircle: 0x24B7,
  20343. Bdotaccent: 0x1E02,
  20344. Bdotbelow: 0x1E04,
  20345. Becyrillic: 0x0411,
  20346. Benarmenian: 0x0532,
  20347. Beta: 0x0392,
  20348. Bhook: 0x0181,
  20349. Blinebelow: 0x1E06,
  20350. Bmonospace: 0xFF22,
  20351. Brevesmall: 0xF6F4,
  20352. Bsmall: 0xF762,
  20353. Btopbar: 0x0182,
  20354. C: 0x0043,
  20355. Caarmenian: 0x053E,
  20356. Cacute: 0x0106,
  20357. Caron: 0xF6CA,
  20358. Caronsmall: 0xF6F5,
  20359. Ccaron: 0x010C,
  20360. Ccedilla: 0x00C7,
  20361. Ccedillaacute: 0x1E08,
  20362. Ccedillasmall: 0xF7E7,
  20363. Ccircle: 0x24B8,
  20364. Ccircumflex: 0x0108,
  20365. Cdot: 0x010A,
  20366. Cdotaccent: 0x010A,
  20367. Cedillasmall: 0xF7B8,
  20368. Chaarmenian: 0x0549,
  20369. Cheabkhasiancyrillic: 0x04BC,
  20370. Checyrillic: 0x0427,
  20371. Chedescenderabkhasiancyrillic: 0x04BE,
  20372. Chedescendercyrillic: 0x04B6,
  20373. Chedieresiscyrillic: 0x04F4,
  20374. Cheharmenian: 0x0543,
  20375. Chekhakassiancyrillic: 0x04CB,
  20376. Cheverticalstrokecyrillic: 0x04B8,
  20377. Chi: 0x03A7,
  20378. Chook: 0x0187,
  20379. Circumflexsmall: 0xF6F6,
  20380. Cmonospace: 0xFF23,
  20381. Coarmenian: 0x0551,
  20382. Csmall: 0xF763,
  20383. D: 0x0044,
  20384. DZ: 0x01F1,
  20385. DZcaron: 0x01C4,
  20386. Daarmenian: 0x0534,
  20387. Dafrican: 0x0189,
  20388. Dcaron: 0x010E,
  20389. Dcedilla: 0x1E10,
  20390. Dcircle: 0x24B9,
  20391. Dcircumflexbelow: 0x1E12,
  20392. Dcroat: 0x0110,
  20393. Ddotaccent: 0x1E0A,
  20394. Ddotbelow: 0x1E0C,
  20395. Decyrillic: 0x0414,
  20396. Deicoptic: 0x03EE,
  20397. Delta: 0x2206,
  20398. Deltagreek: 0x0394,
  20399. Dhook: 0x018A,
  20400. Dieresis: 0xF6CB,
  20401. DieresisAcute: 0xF6CC,
  20402. DieresisGrave: 0xF6CD,
  20403. Dieresissmall: 0xF7A8,
  20404. Digammagreek: 0x03DC,
  20405. Djecyrillic: 0x0402,
  20406. Dlinebelow: 0x1E0E,
  20407. Dmonospace: 0xFF24,
  20408. Dotaccentsmall: 0xF6F7,
  20409. Dslash: 0x0110,
  20410. Dsmall: 0xF764,
  20411. Dtopbar: 0x018B,
  20412. Dz: 0x01F2,
  20413. Dzcaron: 0x01C5,
  20414. Dzeabkhasiancyrillic: 0x04E0,
  20415. Dzecyrillic: 0x0405,
  20416. Dzhecyrillic: 0x040F,
  20417. E: 0x0045,
  20418. Eacute: 0x00C9,
  20419. Eacutesmall: 0xF7E9,
  20420. Ebreve: 0x0114,
  20421. Ecaron: 0x011A,
  20422. Ecedillabreve: 0x1E1C,
  20423. Echarmenian: 0x0535,
  20424. Ecircle: 0x24BA,
  20425. Ecircumflex: 0x00CA,
  20426. Ecircumflexacute: 0x1EBE,
  20427. Ecircumflexbelow: 0x1E18,
  20428. Ecircumflexdotbelow: 0x1EC6,
  20429. Ecircumflexgrave: 0x1EC0,
  20430. Ecircumflexhookabove: 0x1EC2,
  20431. Ecircumflexsmall: 0xF7EA,
  20432. Ecircumflextilde: 0x1EC4,
  20433. Ecyrillic: 0x0404,
  20434. Edblgrave: 0x0204,
  20435. Edieresis: 0x00CB,
  20436. Edieresissmall: 0xF7EB,
  20437. Edot: 0x0116,
  20438. Edotaccent: 0x0116,
  20439. Edotbelow: 0x1EB8,
  20440. Efcyrillic: 0x0424,
  20441. Egrave: 0x00C8,
  20442. Egravesmall: 0xF7E8,
  20443. Eharmenian: 0x0537,
  20444. Ehookabove: 0x1EBA,
  20445. Eightroman: 0x2167,
  20446. Einvertedbreve: 0x0206,
  20447. Eiotifiedcyrillic: 0x0464,
  20448. Elcyrillic: 0x041B,
  20449. Elevenroman: 0x216A,
  20450. Emacron: 0x0112,
  20451. Emacronacute: 0x1E16,
  20452. Emacrongrave: 0x1E14,
  20453. Emcyrillic: 0x041C,
  20454. Emonospace: 0xFF25,
  20455. Encyrillic: 0x041D,
  20456. Endescendercyrillic: 0x04A2,
  20457. Eng: 0x014A,
  20458. Enghecyrillic: 0x04A4,
  20459. Enhookcyrillic: 0x04C7,
  20460. Eogonek: 0x0118,
  20461. Eopen: 0x0190,
  20462. Epsilon: 0x0395,
  20463. Epsilontonos: 0x0388,
  20464. Ercyrillic: 0x0420,
  20465. Ereversed: 0x018E,
  20466. Ereversedcyrillic: 0x042D,
  20467. Escyrillic: 0x0421,
  20468. Esdescendercyrillic: 0x04AA,
  20469. Esh: 0x01A9,
  20470. Esmall: 0xF765,
  20471. Eta: 0x0397,
  20472. Etarmenian: 0x0538,
  20473. Etatonos: 0x0389,
  20474. Eth: 0x00D0,
  20475. Ethsmall: 0xF7F0,
  20476. Etilde: 0x1EBC,
  20477. Etildebelow: 0x1E1A,
  20478. Euro: 0x20AC,
  20479. Ezh: 0x01B7,
  20480. Ezhcaron: 0x01EE,
  20481. Ezhreversed: 0x01B8,
  20482. F: 0x0046,
  20483. Fcircle: 0x24BB,
  20484. Fdotaccent: 0x1E1E,
  20485. Feharmenian: 0x0556,
  20486. Feicoptic: 0x03E4,
  20487. Fhook: 0x0191,
  20488. Fitacyrillic: 0x0472,
  20489. Fiveroman: 0x2164,
  20490. Fmonospace: 0xFF26,
  20491. Fourroman: 0x2163,
  20492. Fsmall: 0xF766,
  20493. G: 0x0047,
  20494. GBsquare: 0x3387,
  20495. Gacute: 0x01F4,
  20496. Gamma: 0x0393,
  20497. Gammaafrican: 0x0194,
  20498. Gangiacoptic: 0x03EA,
  20499. Gbreve: 0x011E,
  20500. Gcaron: 0x01E6,
  20501. Gcedilla: 0x0122,
  20502. Gcircle: 0x24BC,
  20503. Gcircumflex: 0x011C,
  20504. Gcommaaccent: 0x0122,
  20505. Gdot: 0x0120,
  20506. Gdotaccent: 0x0120,
  20507. Gecyrillic: 0x0413,
  20508. Ghadarmenian: 0x0542,
  20509. Ghemiddlehookcyrillic: 0x0494,
  20510. Ghestrokecyrillic: 0x0492,
  20511. Gheupturncyrillic: 0x0490,
  20512. Ghook: 0x0193,
  20513. Gimarmenian: 0x0533,
  20514. Gjecyrillic: 0x0403,
  20515. Gmacron: 0x1E20,
  20516. Gmonospace: 0xFF27,
  20517. Grave: 0xF6CE,
  20518. Gravesmall: 0xF760,
  20519. Gsmall: 0xF767,
  20520. Gsmallhook: 0x029B,
  20521. Gstroke: 0x01E4,
  20522. H: 0x0048,
  20523. H18533: 0x25CF,
  20524. H18543: 0x25AA,
  20525. H18551: 0x25AB,
  20526. H22073: 0x25A1,
  20527. HPsquare: 0x33CB,
  20528. Haabkhasiancyrillic: 0x04A8,
  20529. Hadescendercyrillic: 0x04B2,
  20530. Hardsigncyrillic: 0x042A,
  20531. Hbar: 0x0126,
  20532. Hbrevebelow: 0x1E2A,
  20533. Hcedilla: 0x1E28,
  20534. Hcircle: 0x24BD,
  20535. Hcircumflex: 0x0124,
  20536. Hdieresis: 0x1E26,
  20537. Hdotaccent: 0x1E22,
  20538. Hdotbelow: 0x1E24,
  20539. Hmonospace: 0xFF28,
  20540. Hoarmenian: 0x0540,
  20541. Horicoptic: 0x03E8,
  20542. Hsmall: 0xF768,
  20543. Hungarumlaut: 0xF6CF,
  20544. Hungarumlautsmall: 0xF6F8,
  20545. Hzsquare: 0x3390,
  20546. I: 0x0049,
  20547. IAcyrillic: 0x042F,
  20548. IJ: 0x0132,
  20549. IUcyrillic: 0x042E,
  20550. Iacute: 0x00CD,
  20551. Iacutesmall: 0xF7ED,
  20552. Ibreve: 0x012C,
  20553. Icaron: 0x01CF,
  20554. Icircle: 0x24BE,
  20555. Icircumflex: 0x00CE,
  20556. Icircumflexsmall: 0xF7EE,
  20557. Icyrillic: 0x0406,
  20558. Idblgrave: 0x0208,
  20559. Idieresis: 0x00CF,
  20560. Idieresisacute: 0x1E2E,
  20561. Idieresiscyrillic: 0x04E4,
  20562. Idieresissmall: 0xF7EF,
  20563. Idot: 0x0130,
  20564. Idotaccent: 0x0130,
  20565. Idotbelow: 0x1ECA,
  20566. Iebrevecyrillic: 0x04D6,
  20567. Iecyrillic: 0x0415,
  20568. Ifraktur: 0x2111,
  20569. Igrave: 0x00CC,
  20570. Igravesmall: 0xF7EC,
  20571. Ihookabove: 0x1EC8,
  20572. Iicyrillic: 0x0418,
  20573. Iinvertedbreve: 0x020A,
  20574. Iishortcyrillic: 0x0419,
  20575. Imacron: 0x012A,
  20576. Imacroncyrillic: 0x04E2,
  20577. Imonospace: 0xFF29,
  20578. Iniarmenian: 0x053B,
  20579. Iocyrillic: 0x0401,
  20580. Iogonek: 0x012E,
  20581. Iota: 0x0399,
  20582. Iotaafrican: 0x0196,
  20583. Iotadieresis: 0x03AA,
  20584. Iotatonos: 0x038A,
  20585. Ismall: 0xF769,
  20586. Istroke: 0x0197,
  20587. Itilde: 0x0128,
  20588. Itildebelow: 0x1E2C,
  20589. Izhitsacyrillic: 0x0474,
  20590. Izhitsadblgravecyrillic: 0x0476,
  20591. J: 0x004A,
  20592. Jaarmenian: 0x0541,
  20593. Jcircle: 0x24BF,
  20594. Jcircumflex: 0x0134,
  20595. Jecyrillic: 0x0408,
  20596. Jheharmenian: 0x054B,
  20597. Jmonospace: 0xFF2A,
  20598. Jsmall: 0xF76A,
  20599. K: 0x004B,
  20600. KBsquare: 0x3385,
  20601. KKsquare: 0x33CD,
  20602. Kabashkircyrillic: 0x04A0,
  20603. Kacute: 0x1E30,
  20604. Kacyrillic: 0x041A,
  20605. Kadescendercyrillic: 0x049A,
  20606. Kahookcyrillic: 0x04C3,
  20607. Kappa: 0x039A,
  20608. Kastrokecyrillic: 0x049E,
  20609. Kaverticalstrokecyrillic: 0x049C,
  20610. Kcaron: 0x01E8,
  20611. Kcedilla: 0x0136,
  20612. Kcircle: 0x24C0,
  20613. Kcommaaccent: 0x0136,
  20614. Kdotbelow: 0x1E32,
  20615. Keharmenian: 0x0554,
  20616. Kenarmenian: 0x053F,
  20617. Khacyrillic: 0x0425,
  20618. Kheicoptic: 0x03E6,
  20619. Khook: 0x0198,
  20620. Kjecyrillic: 0x040C,
  20621. Klinebelow: 0x1E34,
  20622. Kmonospace: 0xFF2B,
  20623. Koppacyrillic: 0x0480,
  20624. Koppagreek: 0x03DE,
  20625. Ksicyrillic: 0x046E,
  20626. Ksmall: 0xF76B,
  20627. L: 0x004C,
  20628. LJ: 0x01C7,
  20629. LL: 0xF6BF,
  20630. Lacute: 0x0139,
  20631. Lambda: 0x039B,
  20632. Lcaron: 0x013D,
  20633. Lcedilla: 0x013B,
  20634. Lcircle: 0x24C1,
  20635. Lcircumflexbelow: 0x1E3C,
  20636. Lcommaaccent: 0x013B,
  20637. Ldot: 0x013F,
  20638. Ldotaccent: 0x013F,
  20639. Ldotbelow: 0x1E36,
  20640. Ldotbelowmacron: 0x1E38,
  20641. Liwnarmenian: 0x053C,
  20642. Lj: 0x01C8,
  20643. Ljecyrillic: 0x0409,
  20644. Llinebelow: 0x1E3A,
  20645. Lmonospace: 0xFF2C,
  20646. Lslash: 0x0141,
  20647. Lslashsmall: 0xF6F9,
  20648. Lsmall: 0xF76C,
  20649. M: 0x004D,
  20650. MBsquare: 0x3386,
  20651. Macron: 0xF6D0,
  20652. Macronsmall: 0xF7AF,
  20653. Macute: 0x1E3E,
  20654. Mcircle: 0x24C2,
  20655. Mdotaccent: 0x1E40,
  20656. Mdotbelow: 0x1E42,
  20657. Menarmenian: 0x0544,
  20658. Mmonospace: 0xFF2D,
  20659. Msmall: 0xF76D,
  20660. Mturned: 0x019C,
  20661. Mu: 0x039C,
  20662. N: 0x004E,
  20663. NJ: 0x01CA,
  20664. Nacute: 0x0143,
  20665. Ncaron: 0x0147,
  20666. Ncedilla: 0x0145,
  20667. Ncircle: 0x24C3,
  20668. Ncircumflexbelow: 0x1E4A,
  20669. Ncommaaccent: 0x0145,
  20670. Ndotaccent: 0x1E44,
  20671. Ndotbelow: 0x1E46,
  20672. Nhookleft: 0x019D,
  20673. Nineroman: 0x2168,
  20674. Nj: 0x01CB,
  20675. Njecyrillic: 0x040A,
  20676. Nlinebelow: 0x1E48,
  20677. Nmonospace: 0xFF2E,
  20678. Nowarmenian: 0x0546,
  20679. Nsmall: 0xF76E,
  20680. Ntilde: 0x00D1,
  20681. Ntildesmall: 0xF7F1,
  20682. Nu: 0x039D,
  20683. O: 0x004F,
  20684. OE: 0x0152,
  20685. OEsmall: 0xF6FA,
  20686. Oacute: 0x00D3,
  20687. Oacutesmall: 0xF7F3,
  20688. Obarredcyrillic: 0x04E8,
  20689. Obarreddieresiscyrillic: 0x04EA,
  20690. Obreve: 0x014E,
  20691. Ocaron: 0x01D1,
  20692. Ocenteredtilde: 0x019F,
  20693. Ocircle: 0x24C4,
  20694. Ocircumflex: 0x00D4,
  20695. Ocircumflexacute: 0x1ED0,
  20696. Ocircumflexdotbelow: 0x1ED8,
  20697. Ocircumflexgrave: 0x1ED2,
  20698. Ocircumflexhookabove: 0x1ED4,
  20699. Ocircumflexsmall: 0xF7F4,
  20700. Ocircumflextilde: 0x1ED6,
  20701. Ocyrillic: 0x041E,
  20702. Odblacute: 0x0150,
  20703. Odblgrave: 0x020C,
  20704. Odieresis: 0x00D6,
  20705. Odieresiscyrillic: 0x04E6,
  20706. Odieresissmall: 0xF7F6,
  20707. Odotbelow: 0x1ECC,
  20708. Ogoneksmall: 0xF6FB,
  20709. Ograve: 0x00D2,
  20710. Ogravesmall: 0xF7F2,
  20711. Oharmenian: 0x0555,
  20712. Ohm: 0x2126,
  20713. Ohookabove: 0x1ECE,
  20714. Ohorn: 0x01A0,
  20715. Ohornacute: 0x1EDA,
  20716. Ohorndotbelow: 0x1EE2,
  20717. Ohorngrave: 0x1EDC,
  20718. Ohornhookabove: 0x1EDE,
  20719. Ohorntilde: 0x1EE0,
  20720. Ohungarumlaut: 0x0150,
  20721. Oi: 0x01A2,
  20722. Oinvertedbreve: 0x020E,
  20723. Omacron: 0x014C,
  20724. Omacronacute: 0x1E52,
  20725. Omacrongrave: 0x1E50,
  20726. Omega: 0x2126,
  20727. Omegacyrillic: 0x0460,
  20728. Omegagreek: 0x03A9,
  20729. Omegaroundcyrillic: 0x047A,
  20730. Omegatitlocyrillic: 0x047C,
  20731. Omegatonos: 0x038F,
  20732. Omicron: 0x039F,
  20733. Omicrontonos: 0x038C,
  20734. Omonospace: 0xFF2F,
  20735. Oneroman: 0x2160,
  20736. Oogonek: 0x01EA,
  20737. Oogonekmacron: 0x01EC,
  20738. Oopen: 0x0186,
  20739. Oslash: 0x00D8,
  20740. Oslashacute: 0x01FE,
  20741. Oslashsmall: 0xF7F8,
  20742. Osmall: 0xF76F,
  20743. Ostrokeacute: 0x01FE,
  20744. Otcyrillic: 0x047E,
  20745. Otilde: 0x00D5,
  20746. Otildeacute: 0x1E4C,
  20747. Otildedieresis: 0x1E4E,
  20748. Otildesmall: 0xF7F5,
  20749. P: 0x0050,
  20750. Pacute: 0x1E54,
  20751. Pcircle: 0x24C5,
  20752. Pdotaccent: 0x1E56,
  20753. Pecyrillic: 0x041F,
  20754. Peharmenian: 0x054A,
  20755. Pemiddlehookcyrillic: 0x04A6,
  20756. Phi: 0x03A6,
  20757. Phook: 0x01A4,
  20758. Pi: 0x03A0,
  20759. Piwrarmenian: 0x0553,
  20760. Pmonospace: 0xFF30,
  20761. Psi: 0x03A8,
  20762. Psicyrillic: 0x0470,
  20763. Psmall: 0xF770,
  20764. Q: 0x0051,
  20765. Qcircle: 0x24C6,
  20766. Qmonospace: 0xFF31,
  20767. Qsmall: 0xF771,
  20768. R: 0x0052,
  20769. Raarmenian: 0x054C,
  20770. Racute: 0x0154,
  20771. Rcaron: 0x0158,
  20772. Rcedilla: 0x0156,
  20773. Rcircle: 0x24C7,
  20774. Rcommaaccent: 0x0156,
  20775. Rdblgrave: 0x0210,
  20776. Rdotaccent: 0x1E58,
  20777. Rdotbelow: 0x1E5A,
  20778. Rdotbelowmacron: 0x1E5C,
  20779. Reharmenian: 0x0550,
  20780. Rfraktur: 0x211C,
  20781. Rho: 0x03A1,
  20782. Ringsmall: 0xF6FC,
  20783. Rinvertedbreve: 0x0212,
  20784. Rlinebelow: 0x1E5E,
  20785. Rmonospace: 0xFF32,
  20786. Rsmall: 0xF772,
  20787. Rsmallinverted: 0x0281,
  20788. Rsmallinvertedsuperior: 0x02B6,
  20789. S: 0x0053,
  20790. SF010000: 0x250C,
  20791. SF020000: 0x2514,
  20792. SF030000: 0x2510,
  20793. SF040000: 0x2518,
  20794. SF050000: 0x253C,
  20795. SF060000: 0x252C,
  20796. SF070000: 0x2534,
  20797. SF080000: 0x251C,
  20798. SF090000: 0x2524,
  20799. SF100000: 0x2500,
  20800. SF110000: 0x2502,
  20801. SF190000: 0x2561,
  20802. SF200000: 0x2562,
  20803. SF210000: 0x2556,
  20804. SF220000: 0x2555,
  20805. SF230000: 0x2563,
  20806. SF240000: 0x2551,
  20807. SF250000: 0x2557,
  20808. SF260000: 0x255D,
  20809. SF270000: 0x255C,
  20810. SF280000: 0x255B,
  20811. SF360000: 0x255E,
  20812. SF370000: 0x255F,
  20813. SF380000: 0x255A,
  20814. SF390000: 0x2554,
  20815. SF400000: 0x2569,
  20816. SF410000: 0x2566,
  20817. SF420000: 0x2560,
  20818. SF430000: 0x2550,
  20819. SF440000: 0x256C,
  20820. SF450000: 0x2567,
  20821. SF460000: 0x2568,
  20822. SF470000: 0x2564,
  20823. SF480000: 0x2565,
  20824. SF490000: 0x2559,
  20825. SF500000: 0x2558,
  20826. SF510000: 0x2552,
  20827. SF520000: 0x2553,
  20828. SF530000: 0x256B,
  20829. SF540000: 0x256A,
  20830. Sacute: 0x015A,
  20831. Sacutedotaccent: 0x1E64,
  20832. Sampigreek: 0x03E0,
  20833. Scaron: 0x0160,
  20834. Scarondotaccent: 0x1E66,
  20835. Scaronsmall: 0xF6FD,
  20836. Scedilla: 0x015E,
  20837. Schwa: 0x018F,
  20838. Schwacyrillic: 0x04D8,
  20839. Schwadieresiscyrillic: 0x04DA,
  20840. Scircle: 0x24C8,
  20841. Scircumflex: 0x015C,
  20842. Scommaaccent: 0x0218,
  20843. Sdotaccent: 0x1E60,
  20844. Sdotbelow: 0x1E62,
  20845. Sdotbelowdotaccent: 0x1E68,
  20846. Seharmenian: 0x054D,
  20847. Sevenroman: 0x2166,
  20848. Shaarmenian: 0x0547,
  20849. Shacyrillic: 0x0428,
  20850. Shchacyrillic: 0x0429,
  20851. Sheicoptic: 0x03E2,
  20852. Shhacyrillic: 0x04BA,
  20853. Shimacoptic: 0x03EC,
  20854. Sigma: 0x03A3,
  20855. Sixroman: 0x2165,
  20856. Smonospace: 0xFF33,
  20857. Softsigncyrillic: 0x042C,
  20858. Ssmall: 0xF773,
  20859. Stigmagreek: 0x03DA,
  20860. T: 0x0054,
  20861. Tau: 0x03A4,
  20862. Tbar: 0x0166,
  20863. Tcaron: 0x0164,
  20864. Tcedilla: 0x0162,
  20865. Tcircle: 0x24C9,
  20866. Tcircumflexbelow: 0x1E70,
  20867. Tcommaaccent: 0x0162,
  20868. Tdotaccent: 0x1E6A,
  20869. Tdotbelow: 0x1E6C,
  20870. Tecyrillic: 0x0422,
  20871. Tedescendercyrillic: 0x04AC,
  20872. Tenroman: 0x2169,
  20873. Tetsecyrillic: 0x04B4,
  20874. Theta: 0x0398,
  20875. Thook: 0x01AC,
  20876. Thorn: 0x00DE,
  20877. Thornsmall: 0xF7FE,
  20878. Threeroman: 0x2162,
  20879. Tildesmall: 0xF6FE,
  20880. Tiwnarmenian: 0x054F,
  20881. Tlinebelow: 0x1E6E,
  20882. Tmonospace: 0xFF34,
  20883. Toarmenian: 0x0539,
  20884. Tonefive: 0x01BC,
  20885. Tonesix: 0x0184,
  20886. Tonetwo: 0x01A7,
  20887. Tretroflexhook: 0x01AE,
  20888. Tsecyrillic: 0x0426,
  20889. Tshecyrillic: 0x040B,
  20890. Tsmall: 0xF774,
  20891. Twelveroman: 0x216B,
  20892. Tworoman: 0x2161,
  20893. U: 0x0055,
  20894. Uacute: 0x00DA,
  20895. Uacutesmall: 0xF7FA,
  20896. Ubreve: 0x016C,
  20897. Ucaron: 0x01D3,
  20898. Ucircle: 0x24CA,
  20899. Ucircumflex: 0x00DB,
  20900. Ucircumflexbelow: 0x1E76,
  20901. Ucircumflexsmall: 0xF7FB,
  20902. Ucyrillic: 0x0423,
  20903. Udblacute: 0x0170,
  20904. Udblgrave: 0x0214,
  20905. Udieresis: 0x00DC,
  20906. Udieresisacute: 0x01D7,
  20907. Udieresisbelow: 0x1E72,
  20908. Udieresiscaron: 0x01D9,
  20909. Udieresiscyrillic: 0x04F0,
  20910. Udieresisgrave: 0x01DB,
  20911. Udieresismacron: 0x01D5,
  20912. Udieresissmall: 0xF7FC,
  20913. Udotbelow: 0x1EE4,
  20914. Ugrave: 0x00D9,
  20915. Ugravesmall: 0xF7F9,
  20916. Uhookabove: 0x1EE6,
  20917. Uhorn: 0x01AF,
  20918. Uhornacute: 0x1EE8,
  20919. Uhorndotbelow: 0x1EF0,
  20920. Uhorngrave: 0x1EEA,
  20921. Uhornhookabove: 0x1EEC,
  20922. Uhorntilde: 0x1EEE,
  20923. Uhungarumlaut: 0x0170,
  20924. Uhungarumlautcyrillic: 0x04F2,
  20925. Uinvertedbreve: 0x0216,
  20926. Ukcyrillic: 0x0478,
  20927. Umacron: 0x016A,
  20928. Umacroncyrillic: 0x04EE,
  20929. Umacrondieresis: 0x1E7A,
  20930. Umonospace: 0xFF35,
  20931. Uogonek: 0x0172,
  20932. Upsilon: 0x03A5,
  20933. Upsilon1: 0x03D2,
  20934. Upsilonacutehooksymbolgreek: 0x03D3,
  20935. Upsilonafrican: 0x01B1,
  20936. Upsilondieresis: 0x03AB,
  20937. Upsilondieresishooksymbolgreek: 0x03D4,
  20938. Upsilonhooksymbol: 0x03D2,
  20939. Upsilontonos: 0x038E,
  20940. Uring: 0x016E,
  20941. Ushortcyrillic: 0x040E,
  20942. Usmall: 0xF775,
  20943. Ustraightcyrillic: 0x04AE,
  20944. Ustraightstrokecyrillic: 0x04B0,
  20945. Utilde: 0x0168,
  20946. Utildeacute: 0x1E78,
  20947. Utildebelow: 0x1E74,
  20948. V: 0x0056,
  20949. Vcircle: 0x24CB,
  20950. Vdotbelow: 0x1E7E,
  20951. Vecyrillic: 0x0412,
  20952. Vewarmenian: 0x054E,
  20953. Vhook: 0x01B2,
  20954. Vmonospace: 0xFF36,
  20955. Voarmenian: 0x0548,
  20956. Vsmall: 0xF776,
  20957. Vtilde: 0x1E7C,
  20958. W: 0x0057,
  20959. Wacute: 0x1E82,
  20960. Wcircle: 0x24CC,
  20961. Wcircumflex: 0x0174,
  20962. Wdieresis: 0x1E84,
  20963. Wdotaccent: 0x1E86,
  20964. Wdotbelow: 0x1E88,
  20965. Wgrave: 0x1E80,
  20966. Wmonospace: 0xFF37,
  20967. Wsmall: 0xF777,
  20968. X: 0x0058,
  20969. Xcircle: 0x24CD,
  20970. Xdieresis: 0x1E8C,
  20971. Xdotaccent: 0x1E8A,
  20972. Xeharmenian: 0x053D,
  20973. Xi: 0x039E,
  20974. Xmonospace: 0xFF38,
  20975. Xsmall: 0xF778,
  20976. Y: 0x0059,
  20977. Yacute: 0x00DD,
  20978. Yacutesmall: 0xF7FD,
  20979. Yatcyrillic: 0x0462,
  20980. Ycircle: 0x24CE,
  20981. Ycircumflex: 0x0176,
  20982. Ydieresis: 0x0178,
  20983. Ydieresissmall: 0xF7FF,
  20984. Ydotaccent: 0x1E8E,
  20985. Ydotbelow: 0x1EF4,
  20986. Yericyrillic: 0x042B,
  20987. Yerudieresiscyrillic: 0x04F8,
  20988. Ygrave: 0x1EF2,
  20989. Yhook: 0x01B3,
  20990. Yhookabove: 0x1EF6,
  20991. Yiarmenian: 0x0545,
  20992. Yicyrillic: 0x0407,
  20993. Yiwnarmenian: 0x0552,
  20994. Ymonospace: 0xFF39,
  20995. Ysmall: 0xF779,
  20996. Ytilde: 0x1EF8,
  20997. Yusbigcyrillic: 0x046A,
  20998. Yusbigiotifiedcyrillic: 0x046C,
  20999. Yuslittlecyrillic: 0x0466,
  21000. Yuslittleiotifiedcyrillic: 0x0468,
  21001. Z: 0x005A,
  21002. Zaarmenian: 0x0536,
  21003. Zacute: 0x0179,
  21004. Zcaron: 0x017D,
  21005. Zcaronsmall: 0xF6FF,
  21006. Zcircle: 0x24CF,
  21007. Zcircumflex: 0x1E90,
  21008. Zdot: 0x017B,
  21009. Zdotaccent: 0x017B,
  21010. Zdotbelow: 0x1E92,
  21011. Zecyrillic: 0x0417,
  21012. Zedescendercyrillic: 0x0498,
  21013. Zedieresiscyrillic: 0x04DE,
  21014. Zeta: 0x0396,
  21015. Zhearmenian: 0x053A,
  21016. Zhebrevecyrillic: 0x04C1,
  21017. Zhecyrillic: 0x0416,
  21018. Zhedescendercyrillic: 0x0496,
  21019. Zhedieresiscyrillic: 0x04DC,
  21020. Zlinebelow: 0x1E94,
  21021. Zmonospace: 0xFF3A,
  21022. Zsmall: 0xF77A,
  21023. Zstroke: 0x01B5,
  21024. a: 0x0061,
  21025. aabengali: 0x0986,
  21026. aacute: 0x00E1,
  21027. aadeva: 0x0906,
  21028. aagujarati: 0x0A86,
  21029. aagurmukhi: 0x0A06,
  21030. aamatragurmukhi: 0x0A3E,
  21031. aarusquare: 0x3303,
  21032. aavowelsignbengali: 0x09BE,
  21033. aavowelsigndeva: 0x093E,
  21034. aavowelsigngujarati: 0x0ABE,
  21035. abbreviationmarkarmenian: 0x055F,
  21036. abbreviationsigndeva: 0x0970,
  21037. abengali: 0x0985,
  21038. abopomofo: 0x311A,
  21039. abreve: 0x0103,
  21040. abreveacute: 0x1EAF,
  21041. abrevecyrillic: 0x04D1,
  21042. abrevedotbelow: 0x1EB7,
  21043. abrevegrave: 0x1EB1,
  21044. abrevehookabove: 0x1EB3,
  21045. abrevetilde: 0x1EB5,
  21046. acaron: 0x01CE,
  21047. acircle: 0x24D0,
  21048. acircumflex: 0x00E2,
  21049. acircumflexacute: 0x1EA5,
  21050. acircumflexdotbelow: 0x1EAD,
  21051. acircumflexgrave: 0x1EA7,
  21052. acircumflexhookabove: 0x1EA9,
  21053. acircumflextilde: 0x1EAB,
  21054. acute: 0x00B4,
  21055. acutebelowcmb: 0x0317,
  21056. acutecmb: 0x0301,
  21057. acutecomb: 0x0301,
  21058. acutedeva: 0x0954,
  21059. acutelowmod: 0x02CF,
  21060. acutetonecmb: 0x0341,
  21061. acyrillic: 0x0430,
  21062. adblgrave: 0x0201,
  21063. addakgurmukhi: 0x0A71,
  21064. adeva: 0x0905,
  21065. adieresis: 0x00E4,
  21066. adieresiscyrillic: 0x04D3,
  21067. adieresismacron: 0x01DF,
  21068. adotbelow: 0x1EA1,
  21069. adotmacron: 0x01E1,
  21070. ae: 0x00E6,
  21071. aeacute: 0x01FD,
  21072. aekorean: 0x3150,
  21073. aemacron: 0x01E3,
  21074. afii00208: 0x2015,
  21075. afii08941: 0x20A4,
  21076. afii10017: 0x0410,
  21077. afii10018: 0x0411,
  21078. afii10019: 0x0412,
  21079. afii10020: 0x0413,
  21080. afii10021: 0x0414,
  21081. afii10022: 0x0415,
  21082. afii10023: 0x0401,
  21083. afii10024: 0x0416,
  21084. afii10025: 0x0417,
  21085. afii10026: 0x0418,
  21086. afii10027: 0x0419,
  21087. afii10028: 0x041A,
  21088. afii10029: 0x041B,
  21089. afii10030: 0x041C,
  21090. afii10031: 0x041D,
  21091. afii10032: 0x041E,
  21092. afii10033: 0x041F,
  21093. afii10034: 0x0420,
  21094. afii10035: 0x0421,
  21095. afii10036: 0x0422,
  21096. afii10037: 0x0423,
  21097. afii10038: 0x0424,
  21098. afii10039: 0x0425,
  21099. afii10040: 0x0426,
  21100. afii10041: 0x0427,
  21101. afii10042: 0x0428,
  21102. afii10043: 0x0429,
  21103. afii10044: 0x042A,
  21104. afii10045: 0x042B,
  21105. afii10046: 0x042C,
  21106. afii10047: 0x042D,
  21107. afii10048: 0x042E,
  21108. afii10049: 0x042F,
  21109. afii10050: 0x0490,
  21110. afii10051: 0x0402,
  21111. afii10052: 0x0403,
  21112. afii10053: 0x0404,
  21113. afii10054: 0x0405,
  21114. afii10055: 0x0406,
  21115. afii10056: 0x0407,
  21116. afii10057: 0x0408,
  21117. afii10058: 0x0409,
  21118. afii10059: 0x040A,
  21119. afii10060: 0x040B,
  21120. afii10061: 0x040C,
  21121. afii10062: 0x040E,
  21122. afii10063: 0xF6C4,
  21123. afii10064: 0xF6C5,
  21124. afii10065: 0x0430,
  21125. afii10066: 0x0431,
  21126. afii10067: 0x0432,
  21127. afii10068: 0x0433,
  21128. afii10069: 0x0434,
  21129. afii10070: 0x0435,
  21130. afii10071: 0x0451,
  21131. afii10072: 0x0436,
  21132. afii10073: 0x0437,
  21133. afii10074: 0x0438,
  21134. afii10075: 0x0439,
  21135. afii10076: 0x043A,
  21136. afii10077: 0x043B,
  21137. afii10078: 0x043C,
  21138. afii10079: 0x043D,
  21139. afii10080: 0x043E,
  21140. afii10081: 0x043F,
  21141. afii10082: 0x0440,
  21142. afii10083: 0x0441,
  21143. afii10084: 0x0442,
  21144. afii10085: 0x0443,
  21145. afii10086: 0x0444,
  21146. afii10087: 0x0445,
  21147. afii10088: 0x0446,
  21148. afii10089: 0x0447,
  21149. afii10090: 0x0448,
  21150. afii10091: 0x0449,
  21151. afii10092: 0x044A,
  21152. afii10093: 0x044B,
  21153. afii10094: 0x044C,
  21154. afii10095: 0x044D,
  21155. afii10096: 0x044E,
  21156. afii10097: 0x044F,
  21157. afii10098: 0x0491,
  21158. afii10099: 0x0452,
  21159. afii10100: 0x0453,
  21160. afii10101: 0x0454,
  21161. afii10102: 0x0455,
  21162. afii10103: 0x0456,
  21163. afii10104: 0x0457,
  21164. afii10105: 0x0458,
  21165. afii10106: 0x0459,
  21166. afii10107: 0x045A,
  21167. afii10108: 0x045B,
  21168. afii10109: 0x045C,
  21169. afii10110: 0x045E,
  21170. afii10145: 0x040F,
  21171. afii10146: 0x0462,
  21172. afii10147: 0x0472,
  21173. afii10148: 0x0474,
  21174. afii10192: 0xF6C6,
  21175. afii10193: 0x045F,
  21176. afii10194: 0x0463,
  21177. afii10195: 0x0473,
  21178. afii10196: 0x0475,
  21179. afii10831: 0xF6C7,
  21180. afii10832: 0xF6C8,
  21181. afii10846: 0x04D9,
  21182. afii299: 0x200E,
  21183. afii300: 0x200F,
  21184. afii301: 0x200D,
  21185. afii57381: 0x066A,
  21186. afii57388: 0x060C,
  21187. afii57392: 0x0660,
  21188. afii57393: 0x0661,
  21189. afii57394: 0x0662,
  21190. afii57395: 0x0663,
  21191. afii57396: 0x0664,
  21192. afii57397: 0x0665,
  21193. afii57398: 0x0666,
  21194. afii57399: 0x0667,
  21195. afii57400: 0x0668,
  21196. afii57401: 0x0669,
  21197. afii57403: 0x061B,
  21198. afii57407: 0x061F,
  21199. afii57409: 0x0621,
  21200. afii57410: 0x0622,
  21201. afii57411: 0x0623,
  21202. afii57412: 0x0624,
  21203. afii57413: 0x0625,
  21204. afii57414: 0x0626,
  21205. afii57415: 0x0627,
  21206. afii57416: 0x0628,
  21207. afii57417: 0x0629,
  21208. afii57418: 0x062A,
  21209. afii57419: 0x062B,
  21210. afii57420: 0x062C,
  21211. afii57421: 0x062D,
  21212. afii57422: 0x062E,
  21213. afii57423: 0x062F,
  21214. afii57424: 0x0630,
  21215. afii57425: 0x0631,
  21216. afii57426: 0x0632,
  21217. afii57427: 0x0633,
  21218. afii57428: 0x0634,
  21219. afii57429: 0x0635,
  21220. afii57430: 0x0636,
  21221. afii57431: 0x0637,
  21222. afii57432: 0x0638,
  21223. afii57433: 0x0639,
  21224. afii57434: 0x063A,
  21225. afii57440: 0x0640,
  21226. afii57441: 0x0641,
  21227. afii57442: 0x0642,
  21228. afii57443: 0x0643,
  21229. afii57444: 0x0644,
  21230. afii57445: 0x0645,
  21231. afii57446: 0x0646,
  21232. afii57448: 0x0648,
  21233. afii57449: 0x0649,
  21234. afii57450: 0x064A,
  21235. afii57451: 0x064B,
  21236. afii57452: 0x064C,
  21237. afii57453: 0x064D,
  21238. afii57454: 0x064E,
  21239. afii57455: 0x064F,
  21240. afii57456: 0x0650,
  21241. afii57457: 0x0651,
  21242. afii57458: 0x0652,
  21243. afii57470: 0x0647,
  21244. afii57505: 0x06A4,
  21245. afii57506: 0x067E,
  21246. afii57507: 0x0686,
  21247. afii57508: 0x0698,
  21248. afii57509: 0x06AF,
  21249. afii57511: 0x0679,
  21250. afii57512: 0x0688,
  21251. afii57513: 0x0691,
  21252. afii57514: 0x06BA,
  21253. afii57519: 0x06D2,
  21254. afii57534: 0x06D5,
  21255. afii57636: 0x20AA,
  21256. afii57645: 0x05BE,
  21257. afii57658: 0x05C3,
  21258. afii57664: 0x05D0,
  21259. afii57665: 0x05D1,
  21260. afii57666: 0x05D2,
  21261. afii57667: 0x05D3,
  21262. afii57668: 0x05D4,
  21263. afii57669: 0x05D5,
  21264. afii57670: 0x05D6,
  21265. afii57671: 0x05D7,
  21266. afii57672: 0x05D8,
  21267. afii57673: 0x05D9,
  21268. afii57674: 0x05DA,
  21269. afii57675: 0x05DB,
  21270. afii57676: 0x05DC,
  21271. afii57677: 0x05DD,
  21272. afii57678: 0x05DE,
  21273. afii57679: 0x05DF,
  21274. afii57680: 0x05E0,
  21275. afii57681: 0x05E1,
  21276. afii57682: 0x05E2,
  21277. afii57683: 0x05E3,
  21278. afii57684: 0x05E4,
  21279. afii57685: 0x05E5,
  21280. afii57686: 0x05E6,
  21281. afii57687: 0x05E7,
  21282. afii57688: 0x05E8,
  21283. afii57689: 0x05E9,
  21284. afii57690: 0x05EA,
  21285. afii57694: 0xFB2A,
  21286. afii57695: 0xFB2B,
  21287. afii57700: 0xFB4B,
  21288. afii57705: 0xFB1F,
  21289. afii57716: 0x05F0,
  21290. afii57717: 0x05F1,
  21291. afii57718: 0x05F2,
  21292. afii57723: 0xFB35,
  21293. afii57793: 0x05B4,
  21294. afii57794: 0x05B5,
  21295. afii57795: 0x05B6,
  21296. afii57796: 0x05BB,
  21297. afii57797: 0x05B8,
  21298. afii57798: 0x05B7,
  21299. afii57799: 0x05B0,
  21300. afii57800: 0x05B2,
  21301. afii57801: 0x05B1,
  21302. afii57802: 0x05B3,
  21303. afii57803: 0x05C2,
  21304. afii57804: 0x05C1,
  21305. afii57806: 0x05B9,
  21306. afii57807: 0x05BC,
  21307. afii57839: 0x05BD,
  21308. afii57841: 0x05BF,
  21309. afii57842: 0x05C0,
  21310. afii57929: 0x02BC,
  21311. afii61248: 0x2105,
  21312. afii61289: 0x2113,
  21313. afii61352: 0x2116,
  21314. afii61573: 0x202C,
  21315. afii61574: 0x202D,
  21316. afii61575: 0x202E,
  21317. afii61664: 0x200C,
  21318. afii63167: 0x066D,
  21319. afii64937: 0x02BD,
  21320. agrave: 0x00E0,
  21321. agujarati: 0x0A85,
  21322. agurmukhi: 0x0A05,
  21323. ahiragana: 0x3042,
  21324. ahookabove: 0x1EA3,
  21325. aibengali: 0x0990,
  21326. aibopomofo: 0x311E,
  21327. aideva: 0x0910,
  21328. aiecyrillic: 0x04D5,
  21329. aigujarati: 0x0A90,
  21330. aigurmukhi: 0x0A10,
  21331. aimatragurmukhi: 0x0A48,
  21332. ainarabic: 0x0639,
  21333. ainfinalarabic: 0xFECA,
  21334. aininitialarabic: 0xFECB,
  21335. ainmedialarabic: 0xFECC,
  21336. ainvertedbreve: 0x0203,
  21337. aivowelsignbengali: 0x09C8,
  21338. aivowelsigndeva: 0x0948,
  21339. aivowelsigngujarati: 0x0AC8,
  21340. akatakana: 0x30A2,
  21341. akatakanahalfwidth: 0xFF71,
  21342. akorean: 0x314F,
  21343. alef: 0x05D0,
  21344. alefarabic: 0x0627,
  21345. alefdageshhebrew: 0xFB30,
  21346. aleffinalarabic: 0xFE8E,
  21347. alefhamzaabovearabic: 0x0623,
  21348. alefhamzaabovefinalarabic: 0xFE84,
  21349. alefhamzabelowarabic: 0x0625,
  21350. alefhamzabelowfinalarabic: 0xFE88,
  21351. alefhebrew: 0x05D0,
  21352. aleflamedhebrew: 0xFB4F,
  21353. alefmaddaabovearabic: 0x0622,
  21354. alefmaddaabovefinalarabic: 0xFE82,
  21355. alefmaksuraarabic: 0x0649,
  21356. alefmaksurafinalarabic: 0xFEF0,
  21357. alefmaksurainitialarabic: 0xFEF3,
  21358. alefmaksuramedialarabic: 0xFEF4,
  21359. alefpatahhebrew: 0xFB2E,
  21360. alefqamatshebrew: 0xFB2F,
  21361. aleph: 0x2135,
  21362. allequal: 0x224C,
  21363. alpha: 0x03B1,
  21364. alphatonos: 0x03AC,
  21365. amacron: 0x0101,
  21366. amonospace: 0xFF41,
  21367. ampersand: 0x0026,
  21368. ampersandmonospace: 0xFF06,
  21369. ampersandsmall: 0xF726,
  21370. amsquare: 0x33C2,
  21371. anbopomofo: 0x3122,
  21372. angbopomofo: 0x3124,
  21373. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21374. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21375. angkhankhuthai: 0x0E5A,
  21376. angle: 0x2220,
  21377. anglebracketleft: 0x3008,
  21378. anglebracketleftvertical: 0xFE3F,
  21379. anglebracketright: 0x3009,
  21380. anglebracketrightvertical: 0xFE40,
  21381. angleleft: 0x2329,
  21382. angleright: 0x232A,
  21383. angstrom: 0x212B,
  21384. anoteleia: 0x0387,
  21385. anudattadeva: 0x0952,
  21386. anusvarabengali: 0x0982,
  21387. anusvaradeva: 0x0902,
  21388. anusvaragujarati: 0x0A82,
  21389. aogonek: 0x0105,
  21390. apaatosquare: 0x3300,
  21391. aparen: 0x249C,
  21392. apostrophearmenian: 0x055A,
  21393. apostrophemod: 0x02BC,
  21394. apple: 0xF8FF,
  21395. approaches: 0x2250,
  21396. approxequal: 0x2248,
  21397. approxequalorimage: 0x2252,
  21398. approximatelyequal: 0x2245,
  21399. araeaekorean: 0x318E,
  21400. araeakorean: 0x318D,
  21401. arc: 0x2312,
  21402. arighthalfring: 0x1E9A,
  21403. aring: 0x00E5,
  21404. aringacute: 0x01FB,
  21405. aringbelow: 0x1E01,
  21406. arrowboth: 0x2194,
  21407. arrowdashdown: 0x21E3,
  21408. arrowdashleft: 0x21E0,
  21409. arrowdashright: 0x21E2,
  21410. arrowdashup: 0x21E1,
  21411. arrowdblboth: 0x21D4,
  21412. arrowdbldown: 0x21D3,
  21413. arrowdblleft: 0x21D0,
  21414. arrowdblright: 0x21D2,
  21415. arrowdblup: 0x21D1,
  21416. arrowdown: 0x2193,
  21417. arrowdownleft: 0x2199,
  21418. arrowdownright: 0x2198,
  21419. arrowdownwhite: 0x21E9,
  21420. arrowheaddownmod: 0x02C5,
  21421. arrowheadleftmod: 0x02C2,
  21422. arrowheadrightmod: 0x02C3,
  21423. arrowheadupmod: 0x02C4,
  21424. arrowhorizex: 0xF8E7,
  21425. arrowleft: 0x2190,
  21426. arrowleftdbl: 0x21D0,
  21427. arrowleftdblstroke: 0x21CD,
  21428. arrowleftoverright: 0x21C6,
  21429. arrowleftwhite: 0x21E6,
  21430. arrowright: 0x2192,
  21431. arrowrightdblstroke: 0x21CF,
  21432. arrowrightheavy: 0x279E,
  21433. arrowrightoverleft: 0x21C4,
  21434. arrowrightwhite: 0x21E8,
  21435. arrowtableft: 0x21E4,
  21436. arrowtabright: 0x21E5,
  21437. arrowup: 0x2191,
  21438. arrowupdn: 0x2195,
  21439. arrowupdnbse: 0x21A8,
  21440. arrowupdownbase: 0x21A8,
  21441. arrowupleft: 0x2196,
  21442. arrowupleftofdown: 0x21C5,
  21443. arrowupright: 0x2197,
  21444. arrowupwhite: 0x21E7,
  21445. arrowvertex: 0xF8E6,
  21446. asciicircum: 0x005E,
  21447. asciicircummonospace: 0xFF3E,
  21448. asciitilde: 0x007E,
  21449. asciitildemonospace: 0xFF5E,
  21450. ascript: 0x0251,
  21451. ascriptturned: 0x0252,
  21452. asmallhiragana: 0x3041,
  21453. asmallkatakana: 0x30A1,
  21454. asmallkatakanahalfwidth: 0xFF67,
  21455. asterisk: 0x002A,
  21456. asteriskaltonearabic: 0x066D,
  21457. asteriskarabic: 0x066D,
  21458. asteriskmath: 0x2217,
  21459. asteriskmonospace: 0xFF0A,
  21460. asterisksmall: 0xFE61,
  21461. asterism: 0x2042,
  21462. asuperior: 0xF6E9,
  21463. asymptoticallyequal: 0x2243,
  21464. at: 0x0040,
  21465. atilde: 0x00E3,
  21466. atmonospace: 0xFF20,
  21467. atsmall: 0xFE6B,
  21468. aturned: 0x0250,
  21469. aubengali: 0x0994,
  21470. aubopomofo: 0x3120,
  21471. audeva: 0x0914,
  21472. augujarati: 0x0A94,
  21473. augurmukhi: 0x0A14,
  21474. aulengthmarkbengali: 0x09D7,
  21475. aumatragurmukhi: 0x0A4C,
  21476. auvowelsignbengali: 0x09CC,
  21477. auvowelsigndeva: 0x094C,
  21478. auvowelsigngujarati: 0x0ACC,
  21479. avagrahadeva: 0x093D,
  21480. aybarmenian: 0x0561,
  21481. ayin: 0x05E2,
  21482. ayinaltonehebrew: 0xFB20,
  21483. ayinhebrew: 0x05E2,
  21484. b: 0x0062,
  21485. babengali: 0x09AC,
  21486. backslash: 0x005C,
  21487. backslashmonospace: 0xFF3C,
  21488. badeva: 0x092C,
  21489. bagujarati: 0x0AAC,
  21490. bagurmukhi: 0x0A2C,
  21491. bahiragana: 0x3070,
  21492. bahtthai: 0x0E3F,
  21493. bakatakana: 0x30D0,
  21494. bar: 0x007C,
  21495. barmonospace: 0xFF5C,
  21496. bbopomofo: 0x3105,
  21497. bcircle: 0x24D1,
  21498. bdotaccent: 0x1E03,
  21499. bdotbelow: 0x1E05,
  21500. beamedsixteenthnotes: 0x266C,
  21501. because: 0x2235,
  21502. becyrillic: 0x0431,
  21503. beharabic: 0x0628,
  21504. behfinalarabic: 0xFE90,
  21505. behinitialarabic: 0xFE91,
  21506. behiragana: 0x3079,
  21507. behmedialarabic: 0xFE92,
  21508. behmeeminitialarabic: 0xFC9F,
  21509. behmeemisolatedarabic: 0xFC08,
  21510. behnoonfinalarabic: 0xFC6D,
  21511. bekatakana: 0x30D9,
  21512. benarmenian: 0x0562,
  21513. bet: 0x05D1,
  21514. beta: 0x03B2,
  21515. betasymbolgreek: 0x03D0,
  21516. betdagesh: 0xFB31,
  21517. betdageshhebrew: 0xFB31,
  21518. bethebrew: 0x05D1,
  21519. betrafehebrew: 0xFB4C,
  21520. bhabengali: 0x09AD,
  21521. bhadeva: 0x092D,
  21522. bhagujarati: 0x0AAD,
  21523. bhagurmukhi: 0x0A2D,
  21524. bhook: 0x0253,
  21525. bihiragana: 0x3073,
  21526. bikatakana: 0x30D3,
  21527. bilabialclick: 0x0298,
  21528. bindigurmukhi: 0x0A02,
  21529. birusquare: 0x3331,
  21530. blackcircle: 0x25CF,
  21531. blackdiamond: 0x25C6,
  21532. blackdownpointingtriangle: 0x25BC,
  21533. blackleftpointingpointer: 0x25C4,
  21534. blackleftpointingtriangle: 0x25C0,
  21535. blacklenticularbracketleft: 0x3010,
  21536. blacklenticularbracketleftvertical: 0xFE3B,
  21537. blacklenticularbracketright: 0x3011,
  21538. blacklenticularbracketrightvertical: 0xFE3C,
  21539. blacklowerlefttriangle: 0x25E3,
  21540. blacklowerrighttriangle: 0x25E2,
  21541. blackrectangle: 0x25AC,
  21542. blackrightpointingpointer: 0x25BA,
  21543. blackrightpointingtriangle: 0x25B6,
  21544. blacksmallsquare: 0x25AA,
  21545. blacksmilingface: 0x263B,
  21546. blacksquare: 0x25A0,
  21547. blackstar: 0x2605,
  21548. blackupperlefttriangle: 0x25E4,
  21549. blackupperrighttriangle: 0x25E5,
  21550. blackuppointingsmalltriangle: 0x25B4,
  21551. blackuppointingtriangle: 0x25B2,
  21552. blank: 0x2423,
  21553. blinebelow: 0x1E07,
  21554. block: 0x2588,
  21555. bmonospace: 0xFF42,
  21556. bobaimaithai: 0x0E1A,
  21557. bohiragana: 0x307C,
  21558. bokatakana: 0x30DC,
  21559. bparen: 0x249D,
  21560. bqsquare: 0x33C3,
  21561. braceex: 0xF8F4,
  21562. braceleft: 0x007B,
  21563. braceleftbt: 0xF8F3,
  21564. braceleftmid: 0xF8F2,
  21565. braceleftmonospace: 0xFF5B,
  21566. braceleftsmall: 0xFE5B,
  21567. bracelefttp: 0xF8F1,
  21568. braceleftvertical: 0xFE37,
  21569. braceright: 0x007D,
  21570. bracerightbt: 0xF8FE,
  21571. bracerightmid: 0xF8FD,
  21572. bracerightmonospace: 0xFF5D,
  21573. bracerightsmall: 0xFE5C,
  21574. bracerighttp: 0xF8FC,
  21575. bracerightvertical: 0xFE38,
  21576. bracketleft: 0x005B,
  21577. bracketleftbt: 0xF8F0,
  21578. bracketleftex: 0xF8EF,
  21579. bracketleftmonospace: 0xFF3B,
  21580. bracketlefttp: 0xF8EE,
  21581. bracketright: 0x005D,
  21582. bracketrightbt: 0xF8FB,
  21583. bracketrightex: 0xF8FA,
  21584. bracketrightmonospace: 0xFF3D,
  21585. bracketrighttp: 0xF8F9,
  21586. breve: 0x02D8,
  21587. brevebelowcmb: 0x032E,
  21588. brevecmb: 0x0306,
  21589. breveinvertedbelowcmb: 0x032F,
  21590. breveinvertedcmb: 0x0311,
  21591. breveinverteddoublecmb: 0x0361,
  21592. bridgebelowcmb: 0x032A,
  21593. bridgeinvertedbelowcmb: 0x033A,
  21594. brokenbar: 0x00A6,
  21595. bstroke: 0x0180,
  21596. bsuperior: 0xF6EA,
  21597. btopbar: 0x0183,
  21598. buhiragana: 0x3076,
  21599. bukatakana: 0x30D6,
  21600. bullet: 0x2022,
  21601. bulletinverse: 0x25D8,
  21602. bulletoperator: 0x2219,
  21603. bullseye: 0x25CE,
  21604. c: 0x0063,
  21605. caarmenian: 0x056E,
  21606. cabengali: 0x099A,
  21607. cacute: 0x0107,
  21608. cadeva: 0x091A,
  21609. cagujarati: 0x0A9A,
  21610. cagurmukhi: 0x0A1A,
  21611. calsquare: 0x3388,
  21612. candrabindubengali: 0x0981,
  21613. candrabinducmb: 0x0310,
  21614. candrabindudeva: 0x0901,
  21615. candrabindugujarati: 0x0A81,
  21616. capslock: 0x21EA,
  21617. careof: 0x2105,
  21618. caron: 0x02C7,
  21619. caronbelowcmb: 0x032C,
  21620. caroncmb: 0x030C,
  21621. carriagereturn: 0x21B5,
  21622. cbopomofo: 0x3118,
  21623. ccaron: 0x010D,
  21624. ccedilla: 0x00E7,
  21625. ccedillaacute: 0x1E09,
  21626. ccircle: 0x24D2,
  21627. ccircumflex: 0x0109,
  21628. ccurl: 0x0255,
  21629. cdot: 0x010B,
  21630. cdotaccent: 0x010B,
  21631. cdsquare: 0x33C5,
  21632. cedilla: 0x00B8,
  21633. cedillacmb: 0x0327,
  21634. cent: 0x00A2,
  21635. centigrade: 0x2103,
  21636. centinferior: 0xF6DF,
  21637. centmonospace: 0xFFE0,
  21638. centoldstyle: 0xF7A2,
  21639. centsuperior: 0xF6E0,
  21640. chaarmenian: 0x0579,
  21641. chabengali: 0x099B,
  21642. chadeva: 0x091B,
  21643. chagujarati: 0x0A9B,
  21644. chagurmukhi: 0x0A1B,
  21645. chbopomofo: 0x3114,
  21646. cheabkhasiancyrillic: 0x04BD,
  21647. checkmark: 0x2713,
  21648. checyrillic: 0x0447,
  21649. chedescenderabkhasiancyrillic: 0x04BF,
  21650. chedescendercyrillic: 0x04B7,
  21651. chedieresiscyrillic: 0x04F5,
  21652. cheharmenian: 0x0573,
  21653. chekhakassiancyrillic: 0x04CC,
  21654. cheverticalstrokecyrillic: 0x04B9,
  21655. chi: 0x03C7,
  21656. chieuchacirclekorean: 0x3277,
  21657. chieuchaparenkorean: 0x3217,
  21658. chieuchcirclekorean: 0x3269,
  21659. chieuchkorean: 0x314A,
  21660. chieuchparenkorean: 0x3209,
  21661. chochangthai: 0x0E0A,
  21662. chochanthai: 0x0E08,
  21663. chochingthai: 0x0E09,
  21664. chochoethai: 0x0E0C,
  21665. chook: 0x0188,
  21666. cieucacirclekorean: 0x3276,
  21667. cieucaparenkorean: 0x3216,
  21668. cieuccirclekorean: 0x3268,
  21669. cieuckorean: 0x3148,
  21670. cieucparenkorean: 0x3208,
  21671. cieucuparenkorean: 0x321C,
  21672. circle: 0x25CB,
  21673. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21674. circlemultiply: 0x2297,
  21675. circleot: 0x2299,
  21676. circleplus: 0x2295,
  21677. circlepostalmark: 0x3036,
  21678. circlewithlefthalfblack: 0x25D0,
  21679. circlewithrighthalfblack: 0x25D1,
  21680. circumflex: 0x02C6,
  21681. circumflexbelowcmb: 0x032D,
  21682. circumflexcmb: 0x0302,
  21683. clear: 0x2327,
  21684. clickalveolar: 0x01C2,
  21685. clickdental: 0x01C0,
  21686. clicklateral: 0x01C1,
  21687. clickretroflex: 0x01C3,
  21688. club: 0x2663,
  21689. clubsuitblack: 0x2663,
  21690. clubsuitwhite: 0x2667,
  21691. cmcubedsquare: 0x33A4,
  21692. cmonospace: 0xFF43,
  21693. cmsquaredsquare: 0x33A0,
  21694. coarmenian: 0x0581,
  21695. colon: 0x003A,
  21696. colonmonetary: 0x20A1,
  21697. colonmonospace: 0xFF1A,
  21698. colonsign: 0x20A1,
  21699. colonsmall: 0xFE55,
  21700. colontriangularhalfmod: 0x02D1,
  21701. colontriangularmod: 0x02D0,
  21702. comma: 0x002C,
  21703. commaabovecmb: 0x0313,
  21704. commaaboverightcmb: 0x0315,
  21705. commaaccent: 0xF6C3,
  21706. commaarabic: 0x060C,
  21707. commaarmenian: 0x055D,
  21708. commainferior: 0xF6E1,
  21709. commamonospace: 0xFF0C,
  21710. commareversedabovecmb: 0x0314,
  21711. commareversedmod: 0x02BD,
  21712. commasmall: 0xFE50,
  21713. commasuperior: 0xF6E2,
  21714. commaturnedabovecmb: 0x0312,
  21715. commaturnedmod: 0x02BB,
  21716. compass: 0x263C,
  21717. congruent: 0x2245,
  21718. contourintegral: 0x222E,
  21719. control: 0x2303,
  21720. controlACK: 0x0006,
  21721. controlBEL: 0x0007,
  21722. controlBS: 0x0008,
  21723. controlCAN: 0x0018,
  21724. controlCR: 0x000D,
  21725. controlDC1: 0x0011,
  21726. controlDC2: 0x0012,
  21727. controlDC3: 0x0013,
  21728. controlDC4: 0x0014,
  21729. controlDEL: 0x007F,
  21730. controlDLE: 0x0010,
  21731. controlEM: 0x0019,
  21732. controlENQ: 0x0005,
  21733. controlEOT: 0x0004,
  21734. controlESC: 0x001B,
  21735. controlETB: 0x0017,
  21736. controlETX: 0x0003,
  21737. controlFF: 0x000C,
  21738. controlFS: 0x001C,
  21739. controlGS: 0x001D,
  21740. controlHT: 0x0009,
  21741. controlLF: 0x000A,
  21742. controlNAK: 0x0015,
  21743. controlRS: 0x001E,
  21744. controlSI: 0x000F,
  21745. controlSO: 0x000E,
  21746. controlSOT: 0x0002,
  21747. controlSTX: 0x0001,
  21748. controlSUB: 0x001A,
  21749. controlSYN: 0x0016,
  21750. controlUS: 0x001F,
  21751. controlVT: 0x000B,
  21752. copyright: 0x00A9,
  21753. copyrightsans: 0xF8E9,
  21754. copyrightserif: 0xF6D9,
  21755. cornerbracketleft: 0x300C,
  21756. cornerbracketlefthalfwidth: 0xFF62,
  21757. cornerbracketleftvertical: 0xFE41,
  21758. cornerbracketright: 0x300D,
  21759. cornerbracketrighthalfwidth: 0xFF63,
  21760. cornerbracketrightvertical: 0xFE42,
  21761. corporationsquare: 0x337F,
  21762. cosquare: 0x33C7,
  21763. coverkgsquare: 0x33C6,
  21764. cparen: 0x249E,
  21765. cruzeiro: 0x20A2,
  21766. cstretched: 0x0297,
  21767. curlyand: 0x22CF,
  21768. curlyor: 0x22CE,
  21769. currency: 0x00A4,
  21770. cyrBreve: 0xF6D1,
  21771. cyrFlex: 0xF6D2,
  21772. cyrbreve: 0xF6D4,
  21773. cyrflex: 0xF6D5,
  21774. d: 0x0064,
  21775. daarmenian: 0x0564,
  21776. dabengali: 0x09A6,
  21777. dadarabic: 0x0636,
  21778. dadeva: 0x0926,
  21779. dadfinalarabic: 0xFEBE,
  21780. dadinitialarabic: 0xFEBF,
  21781. dadmedialarabic: 0xFEC0,
  21782. dagesh: 0x05BC,
  21783. dageshhebrew: 0x05BC,
  21784. dagger: 0x2020,
  21785. daggerdbl: 0x2021,
  21786. dagujarati: 0x0AA6,
  21787. dagurmukhi: 0x0A26,
  21788. dahiragana: 0x3060,
  21789. dakatakana: 0x30C0,
  21790. dalarabic: 0x062F,
  21791. dalet: 0x05D3,
  21792. daletdagesh: 0xFB33,
  21793. daletdageshhebrew: 0xFB33,
  21794. dalethebrew: 0x05D3,
  21795. dalfinalarabic: 0xFEAA,
  21796. dammaarabic: 0x064F,
  21797. dammalowarabic: 0x064F,
  21798. dammatanaltonearabic: 0x064C,
  21799. dammatanarabic: 0x064C,
  21800. danda: 0x0964,
  21801. dargahebrew: 0x05A7,
  21802. dargalefthebrew: 0x05A7,
  21803. dasiapneumatacyrilliccmb: 0x0485,
  21804. dblGrave: 0xF6D3,
  21805. dblanglebracketleft: 0x300A,
  21806. dblanglebracketleftvertical: 0xFE3D,
  21807. dblanglebracketright: 0x300B,
  21808. dblanglebracketrightvertical: 0xFE3E,
  21809. dblarchinvertedbelowcmb: 0x032B,
  21810. dblarrowleft: 0x21D4,
  21811. dblarrowright: 0x21D2,
  21812. dbldanda: 0x0965,
  21813. dblgrave: 0xF6D6,
  21814. dblgravecmb: 0x030F,
  21815. dblintegral: 0x222C,
  21816. dbllowline: 0x2017,
  21817. dbllowlinecmb: 0x0333,
  21818. dbloverlinecmb: 0x033F,
  21819. dblprimemod: 0x02BA,
  21820. dblverticalbar: 0x2016,
  21821. dblverticallineabovecmb: 0x030E,
  21822. dbopomofo: 0x3109,
  21823. dbsquare: 0x33C8,
  21824. dcaron: 0x010F,
  21825. dcedilla: 0x1E11,
  21826. dcircle: 0x24D3,
  21827. dcircumflexbelow: 0x1E13,
  21828. dcroat: 0x0111,
  21829. ddabengali: 0x09A1,
  21830. ddadeva: 0x0921,
  21831. ddagujarati: 0x0AA1,
  21832. ddagurmukhi: 0x0A21,
  21833. ddalarabic: 0x0688,
  21834. ddalfinalarabic: 0xFB89,
  21835. dddhadeva: 0x095C,
  21836. ddhabengali: 0x09A2,
  21837. ddhadeva: 0x0922,
  21838. ddhagujarati: 0x0AA2,
  21839. ddhagurmukhi: 0x0A22,
  21840. ddotaccent: 0x1E0B,
  21841. ddotbelow: 0x1E0D,
  21842. decimalseparatorarabic: 0x066B,
  21843. decimalseparatorpersian: 0x066B,
  21844. decyrillic: 0x0434,
  21845. degree: 0x00B0,
  21846. dehihebrew: 0x05AD,
  21847. dehiragana: 0x3067,
  21848. deicoptic: 0x03EF,
  21849. dekatakana: 0x30C7,
  21850. deleteleft: 0x232B,
  21851. deleteright: 0x2326,
  21852. delta: 0x03B4,
  21853. deltaturned: 0x018D,
  21854. denominatorminusonenumeratorbengali: 0x09F8,
  21855. dezh: 0x02A4,
  21856. dhabengali: 0x09A7,
  21857. dhadeva: 0x0927,
  21858. dhagujarati: 0x0AA7,
  21859. dhagurmukhi: 0x0A27,
  21860. dhook: 0x0257,
  21861. dialytikatonos: 0x0385,
  21862. dialytikatonoscmb: 0x0344,
  21863. diamond: 0x2666,
  21864. diamondsuitwhite: 0x2662,
  21865. dieresis: 0x00A8,
  21866. dieresisacute: 0xF6D7,
  21867. dieresisbelowcmb: 0x0324,
  21868. dieresiscmb: 0x0308,
  21869. dieresisgrave: 0xF6D8,
  21870. dieresistonos: 0x0385,
  21871. dihiragana: 0x3062,
  21872. dikatakana: 0x30C2,
  21873. dittomark: 0x3003,
  21874. divide: 0x00F7,
  21875. divides: 0x2223,
  21876. divisionslash: 0x2215,
  21877. djecyrillic: 0x0452,
  21878. dkshade: 0x2593,
  21879. dlinebelow: 0x1E0F,
  21880. dlsquare: 0x3397,
  21881. dmacron: 0x0111,
  21882. dmonospace: 0xFF44,
  21883. dnblock: 0x2584,
  21884. dochadathai: 0x0E0E,
  21885. dodekthai: 0x0E14,
  21886. dohiragana: 0x3069,
  21887. dokatakana: 0x30C9,
  21888. dollar: 0x0024,
  21889. dollarinferior: 0xF6E3,
  21890. dollarmonospace: 0xFF04,
  21891. dollaroldstyle: 0xF724,
  21892. dollarsmall: 0xFE69,
  21893. dollarsuperior: 0xF6E4,
  21894. dong: 0x20AB,
  21895. dorusquare: 0x3326,
  21896. dotaccent: 0x02D9,
  21897. dotaccentcmb: 0x0307,
  21898. dotbelowcmb: 0x0323,
  21899. dotbelowcomb: 0x0323,
  21900. dotkatakana: 0x30FB,
  21901. dotlessi: 0x0131,
  21902. dotlessj: 0xF6BE,
  21903. dotlessjstrokehook: 0x0284,
  21904. dotmath: 0x22C5,
  21905. dottedcircle: 0x25CC,
  21906. doubleyodpatah: 0xFB1F,
  21907. doubleyodpatahhebrew: 0xFB1F,
  21908. downtackbelowcmb: 0x031E,
  21909. downtackmod: 0x02D5,
  21910. dparen: 0x249F,
  21911. dsuperior: 0xF6EB,
  21912. dtail: 0x0256,
  21913. dtopbar: 0x018C,
  21914. duhiragana: 0x3065,
  21915. dukatakana: 0x30C5,
  21916. dz: 0x01F3,
  21917. dzaltone: 0x02A3,
  21918. dzcaron: 0x01C6,
  21919. dzcurl: 0x02A5,
  21920. dzeabkhasiancyrillic: 0x04E1,
  21921. dzecyrillic: 0x0455,
  21922. dzhecyrillic: 0x045F,
  21923. e: 0x0065,
  21924. eacute: 0x00E9,
  21925. earth: 0x2641,
  21926. ebengali: 0x098F,
  21927. ebopomofo: 0x311C,
  21928. ebreve: 0x0115,
  21929. ecandradeva: 0x090D,
  21930. ecandragujarati: 0x0A8D,
  21931. ecandravowelsigndeva: 0x0945,
  21932. ecandravowelsigngujarati: 0x0AC5,
  21933. ecaron: 0x011B,
  21934. ecedillabreve: 0x1E1D,
  21935. echarmenian: 0x0565,
  21936. echyiwnarmenian: 0x0587,
  21937. ecircle: 0x24D4,
  21938. ecircumflex: 0x00EA,
  21939. ecircumflexacute: 0x1EBF,
  21940. ecircumflexbelow: 0x1E19,
  21941. ecircumflexdotbelow: 0x1EC7,
  21942. ecircumflexgrave: 0x1EC1,
  21943. ecircumflexhookabove: 0x1EC3,
  21944. ecircumflextilde: 0x1EC5,
  21945. ecyrillic: 0x0454,
  21946. edblgrave: 0x0205,
  21947. edeva: 0x090F,
  21948. edieresis: 0x00EB,
  21949. edot: 0x0117,
  21950. edotaccent: 0x0117,
  21951. edotbelow: 0x1EB9,
  21952. eegurmukhi: 0x0A0F,
  21953. eematragurmukhi: 0x0A47,
  21954. efcyrillic: 0x0444,
  21955. egrave: 0x00E8,
  21956. egujarati: 0x0A8F,
  21957. eharmenian: 0x0567,
  21958. ehbopomofo: 0x311D,
  21959. ehiragana: 0x3048,
  21960. ehookabove: 0x1EBB,
  21961. eibopomofo: 0x311F,
  21962. eight: 0x0038,
  21963. eightarabic: 0x0668,
  21964. eightbengali: 0x09EE,
  21965. eightcircle: 0x2467,
  21966. eightcircleinversesansserif: 0x2791,
  21967. eightdeva: 0x096E,
  21968. eighteencircle: 0x2471,
  21969. eighteenparen: 0x2485,
  21970. eighteenperiod: 0x2499,
  21971. eightgujarati: 0x0AEE,
  21972. eightgurmukhi: 0x0A6E,
  21973. eighthackarabic: 0x0668,
  21974. eighthangzhou: 0x3028,
  21975. eighthnotebeamed: 0x266B,
  21976. eightideographicparen: 0x3227,
  21977. eightinferior: 0x2088,
  21978. eightmonospace: 0xFF18,
  21979. eightoldstyle: 0xF738,
  21980. eightparen: 0x247B,
  21981. eightperiod: 0x248F,
  21982. eightpersian: 0x06F8,
  21983. eightroman: 0x2177,
  21984. eightsuperior: 0x2078,
  21985. eightthai: 0x0E58,
  21986. einvertedbreve: 0x0207,
  21987. eiotifiedcyrillic: 0x0465,
  21988. ekatakana: 0x30A8,
  21989. ekatakanahalfwidth: 0xFF74,
  21990. ekonkargurmukhi: 0x0A74,
  21991. ekorean: 0x3154,
  21992. elcyrillic: 0x043B,
  21993. element: 0x2208,
  21994. elevencircle: 0x246A,
  21995. elevenparen: 0x247E,
  21996. elevenperiod: 0x2492,
  21997. elevenroman: 0x217A,
  21998. ellipsis: 0x2026,
  21999. ellipsisvertical: 0x22EE,
  22000. emacron: 0x0113,
  22001. emacronacute: 0x1E17,
  22002. emacrongrave: 0x1E15,
  22003. emcyrillic: 0x043C,
  22004. emdash: 0x2014,
  22005. emdashvertical: 0xFE31,
  22006. emonospace: 0xFF45,
  22007. emphasismarkarmenian: 0x055B,
  22008. emptyset: 0x2205,
  22009. enbopomofo: 0x3123,
  22010. encyrillic: 0x043D,
  22011. endash: 0x2013,
  22012. endashvertical: 0xFE32,
  22013. endescendercyrillic: 0x04A3,
  22014. eng: 0x014B,
  22015. engbopomofo: 0x3125,
  22016. enghecyrillic: 0x04A5,
  22017. enhookcyrillic: 0x04C8,
  22018. enspace: 0x2002,
  22019. eogonek: 0x0119,
  22020. eokorean: 0x3153,
  22021. eopen: 0x025B,
  22022. eopenclosed: 0x029A,
  22023. eopenreversed: 0x025C,
  22024. eopenreversedclosed: 0x025E,
  22025. eopenreversedhook: 0x025D,
  22026. eparen: 0x24A0,
  22027. epsilon: 0x03B5,
  22028. epsilontonos: 0x03AD,
  22029. equal: 0x003D,
  22030. equalmonospace: 0xFF1D,
  22031. equalsmall: 0xFE66,
  22032. equalsuperior: 0x207C,
  22033. equivalence: 0x2261,
  22034. erbopomofo: 0x3126,
  22035. ercyrillic: 0x0440,
  22036. ereversed: 0x0258,
  22037. ereversedcyrillic: 0x044D,
  22038. escyrillic: 0x0441,
  22039. esdescendercyrillic: 0x04AB,
  22040. esh: 0x0283,
  22041. eshcurl: 0x0286,
  22042. eshortdeva: 0x090E,
  22043. eshortvowelsigndeva: 0x0946,
  22044. eshreversedloop: 0x01AA,
  22045. eshsquatreversed: 0x0285,
  22046. esmallhiragana: 0x3047,
  22047. esmallkatakana: 0x30A7,
  22048. esmallkatakanahalfwidth: 0xFF6A,
  22049. estimated: 0x212E,
  22050. esuperior: 0xF6EC,
  22051. eta: 0x03B7,
  22052. etarmenian: 0x0568,
  22053. etatonos: 0x03AE,
  22054. eth: 0x00F0,
  22055. etilde: 0x1EBD,
  22056. etildebelow: 0x1E1B,
  22057. etnahtafoukhhebrew: 0x0591,
  22058. etnahtafoukhlefthebrew: 0x0591,
  22059. etnahtahebrew: 0x0591,
  22060. etnahtalefthebrew: 0x0591,
  22061. eturned: 0x01DD,
  22062. eukorean: 0x3161,
  22063. euro: 0x20AC,
  22064. evowelsignbengali: 0x09C7,
  22065. evowelsigndeva: 0x0947,
  22066. evowelsigngujarati: 0x0AC7,
  22067. exclam: 0x0021,
  22068. exclamarmenian: 0x055C,
  22069. exclamdbl: 0x203C,
  22070. exclamdown: 0x00A1,
  22071. exclamdownsmall: 0xF7A1,
  22072. exclammonospace: 0xFF01,
  22073. exclamsmall: 0xF721,
  22074. existential: 0x2203,
  22075. ezh: 0x0292,
  22076. ezhcaron: 0x01EF,
  22077. ezhcurl: 0x0293,
  22078. ezhreversed: 0x01B9,
  22079. ezhtail: 0x01BA,
  22080. f: 0x0066,
  22081. fadeva: 0x095E,
  22082. fagurmukhi: 0x0A5E,
  22083. fahrenheit: 0x2109,
  22084. fathaarabic: 0x064E,
  22085. fathalowarabic: 0x064E,
  22086. fathatanarabic: 0x064B,
  22087. fbopomofo: 0x3108,
  22088. fcircle: 0x24D5,
  22089. fdotaccent: 0x1E1F,
  22090. feharabic: 0x0641,
  22091. feharmenian: 0x0586,
  22092. fehfinalarabic: 0xFED2,
  22093. fehinitialarabic: 0xFED3,
  22094. fehmedialarabic: 0xFED4,
  22095. feicoptic: 0x03E5,
  22096. female: 0x2640,
  22097. ff: 0xFB00,
  22098. ffi: 0xFB03,
  22099. ffl: 0xFB04,
  22100. fi: 0xFB01,
  22101. fifteencircle: 0x246E,
  22102. fifteenparen: 0x2482,
  22103. fifteenperiod: 0x2496,
  22104. figuredash: 0x2012,
  22105. filledbox: 0x25A0,
  22106. filledrect: 0x25AC,
  22107. finalkaf: 0x05DA,
  22108. finalkafdagesh: 0xFB3A,
  22109. finalkafdageshhebrew: 0xFB3A,
  22110. finalkafhebrew: 0x05DA,
  22111. finalmem: 0x05DD,
  22112. finalmemhebrew: 0x05DD,
  22113. finalnun: 0x05DF,
  22114. finalnunhebrew: 0x05DF,
  22115. finalpe: 0x05E3,
  22116. finalpehebrew: 0x05E3,
  22117. finaltsadi: 0x05E5,
  22118. finaltsadihebrew: 0x05E5,
  22119. firsttonechinese: 0x02C9,
  22120. fisheye: 0x25C9,
  22121. fitacyrillic: 0x0473,
  22122. five: 0x0035,
  22123. fivearabic: 0x0665,
  22124. fivebengali: 0x09EB,
  22125. fivecircle: 0x2464,
  22126. fivecircleinversesansserif: 0x278E,
  22127. fivedeva: 0x096B,
  22128. fiveeighths: 0x215D,
  22129. fivegujarati: 0x0AEB,
  22130. fivegurmukhi: 0x0A6B,
  22131. fivehackarabic: 0x0665,
  22132. fivehangzhou: 0x3025,
  22133. fiveideographicparen: 0x3224,
  22134. fiveinferior: 0x2085,
  22135. fivemonospace: 0xFF15,
  22136. fiveoldstyle: 0xF735,
  22137. fiveparen: 0x2478,
  22138. fiveperiod: 0x248C,
  22139. fivepersian: 0x06F5,
  22140. fiveroman: 0x2174,
  22141. fivesuperior: 0x2075,
  22142. fivethai: 0x0E55,
  22143. fl: 0xFB02,
  22144. florin: 0x0192,
  22145. fmonospace: 0xFF46,
  22146. fmsquare: 0x3399,
  22147. fofanthai: 0x0E1F,
  22148. fofathai: 0x0E1D,
  22149. fongmanthai: 0x0E4F,
  22150. forall: 0x2200,
  22151. four: 0x0034,
  22152. fourarabic: 0x0664,
  22153. fourbengali: 0x09EA,
  22154. fourcircle: 0x2463,
  22155. fourcircleinversesansserif: 0x278D,
  22156. fourdeva: 0x096A,
  22157. fourgujarati: 0x0AEA,
  22158. fourgurmukhi: 0x0A6A,
  22159. fourhackarabic: 0x0664,
  22160. fourhangzhou: 0x3024,
  22161. fourideographicparen: 0x3223,
  22162. fourinferior: 0x2084,
  22163. fourmonospace: 0xFF14,
  22164. fournumeratorbengali: 0x09F7,
  22165. fouroldstyle: 0xF734,
  22166. fourparen: 0x2477,
  22167. fourperiod: 0x248B,
  22168. fourpersian: 0x06F4,
  22169. fourroman: 0x2173,
  22170. foursuperior: 0x2074,
  22171. fourteencircle: 0x246D,
  22172. fourteenparen: 0x2481,
  22173. fourteenperiod: 0x2495,
  22174. fourthai: 0x0E54,
  22175. fourthtonechinese: 0x02CB,
  22176. fparen: 0x24A1,
  22177. fraction: 0x2044,
  22178. franc: 0x20A3,
  22179. g: 0x0067,
  22180. gabengali: 0x0997,
  22181. gacute: 0x01F5,
  22182. gadeva: 0x0917,
  22183. gafarabic: 0x06AF,
  22184. gaffinalarabic: 0xFB93,
  22185. gafinitialarabic: 0xFB94,
  22186. gafmedialarabic: 0xFB95,
  22187. gagujarati: 0x0A97,
  22188. gagurmukhi: 0x0A17,
  22189. gahiragana: 0x304C,
  22190. gakatakana: 0x30AC,
  22191. gamma: 0x03B3,
  22192. gammalatinsmall: 0x0263,
  22193. gammasuperior: 0x02E0,
  22194. gangiacoptic: 0x03EB,
  22195. gbopomofo: 0x310D,
  22196. gbreve: 0x011F,
  22197. gcaron: 0x01E7,
  22198. gcedilla: 0x0123,
  22199. gcircle: 0x24D6,
  22200. gcircumflex: 0x011D,
  22201. gcommaaccent: 0x0123,
  22202. gdot: 0x0121,
  22203. gdotaccent: 0x0121,
  22204. gecyrillic: 0x0433,
  22205. gehiragana: 0x3052,
  22206. gekatakana: 0x30B2,
  22207. geometricallyequal: 0x2251,
  22208. gereshaccenthebrew: 0x059C,
  22209. gereshhebrew: 0x05F3,
  22210. gereshmuqdamhebrew: 0x059D,
  22211. germandbls: 0x00DF,
  22212. gershayimaccenthebrew: 0x059E,
  22213. gershayimhebrew: 0x05F4,
  22214. getamark: 0x3013,
  22215. ghabengali: 0x0998,
  22216. ghadarmenian: 0x0572,
  22217. ghadeva: 0x0918,
  22218. ghagujarati: 0x0A98,
  22219. ghagurmukhi: 0x0A18,
  22220. ghainarabic: 0x063A,
  22221. ghainfinalarabic: 0xFECE,
  22222. ghaininitialarabic: 0xFECF,
  22223. ghainmedialarabic: 0xFED0,
  22224. ghemiddlehookcyrillic: 0x0495,
  22225. ghestrokecyrillic: 0x0493,
  22226. gheupturncyrillic: 0x0491,
  22227. ghhadeva: 0x095A,
  22228. ghhagurmukhi: 0x0A5A,
  22229. ghook: 0x0260,
  22230. ghzsquare: 0x3393,
  22231. gihiragana: 0x304E,
  22232. gikatakana: 0x30AE,
  22233. gimarmenian: 0x0563,
  22234. gimel: 0x05D2,
  22235. gimeldagesh: 0xFB32,
  22236. gimeldageshhebrew: 0xFB32,
  22237. gimelhebrew: 0x05D2,
  22238. gjecyrillic: 0x0453,
  22239. glottalinvertedstroke: 0x01BE,
  22240. glottalstop: 0x0294,
  22241. glottalstopinverted: 0x0296,
  22242. glottalstopmod: 0x02C0,
  22243. glottalstopreversed: 0x0295,
  22244. glottalstopreversedmod: 0x02C1,
  22245. glottalstopreversedsuperior: 0x02E4,
  22246. glottalstopstroke: 0x02A1,
  22247. glottalstopstrokereversed: 0x02A2,
  22248. gmacron: 0x1E21,
  22249. gmonospace: 0xFF47,
  22250. gohiragana: 0x3054,
  22251. gokatakana: 0x30B4,
  22252. gparen: 0x24A2,
  22253. gpasquare: 0x33AC,
  22254. gradient: 0x2207,
  22255. grave: 0x0060,
  22256. gravebelowcmb: 0x0316,
  22257. gravecmb: 0x0300,
  22258. gravecomb: 0x0300,
  22259. gravedeva: 0x0953,
  22260. gravelowmod: 0x02CE,
  22261. gravemonospace: 0xFF40,
  22262. gravetonecmb: 0x0340,
  22263. greater: 0x003E,
  22264. greaterequal: 0x2265,
  22265. greaterequalorless: 0x22DB,
  22266. greatermonospace: 0xFF1E,
  22267. greaterorequivalent: 0x2273,
  22268. greaterorless: 0x2277,
  22269. greateroverequal: 0x2267,
  22270. greatersmall: 0xFE65,
  22271. gscript: 0x0261,
  22272. gstroke: 0x01E5,
  22273. guhiragana: 0x3050,
  22274. guillemotleft: 0x00AB,
  22275. guillemotright: 0x00BB,
  22276. guilsinglleft: 0x2039,
  22277. guilsinglright: 0x203A,
  22278. gukatakana: 0x30B0,
  22279. guramusquare: 0x3318,
  22280. gysquare: 0x33C9,
  22281. h: 0x0068,
  22282. haabkhasiancyrillic: 0x04A9,
  22283. haaltonearabic: 0x06C1,
  22284. habengali: 0x09B9,
  22285. hadescendercyrillic: 0x04B3,
  22286. hadeva: 0x0939,
  22287. hagujarati: 0x0AB9,
  22288. hagurmukhi: 0x0A39,
  22289. haharabic: 0x062D,
  22290. hahfinalarabic: 0xFEA2,
  22291. hahinitialarabic: 0xFEA3,
  22292. hahiragana: 0x306F,
  22293. hahmedialarabic: 0xFEA4,
  22294. haitusquare: 0x332A,
  22295. hakatakana: 0x30CF,
  22296. hakatakanahalfwidth: 0xFF8A,
  22297. halantgurmukhi: 0x0A4D,
  22298. hamzaarabic: 0x0621,
  22299. hamzalowarabic: 0x0621,
  22300. hangulfiller: 0x3164,
  22301. hardsigncyrillic: 0x044A,
  22302. harpoonleftbarbup: 0x21BC,
  22303. harpoonrightbarbup: 0x21C0,
  22304. hasquare: 0x33CA,
  22305. hatafpatah: 0x05B2,
  22306. hatafpatah16: 0x05B2,
  22307. hatafpatah23: 0x05B2,
  22308. hatafpatah2f: 0x05B2,
  22309. hatafpatahhebrew: 0x05B2,
  22310. hatafpatahnarrowhebrew: 0x05B2,
  22311. hatafpatahquarterhebrew: 0x05B2,
  22312. hatafpatahwidehebrew: 0x05B2,
  22313. hatafqamats: 0x05B3,
  22314. hatafqamats1b: 0x05B3,
  22315. hatafqamats28: 0x05B3,
  22316. hatafqamats34: 0x05B3,
  22317. hatafqamatshebrew: 0x05B3,
  22318. hatafqamatsnarrowhebrew: 0x05B3,
  22319. hatafqamatsquarterhebrew: 0x05B3,
  22320. hatafqamatswidehebrew: 0x05B3,
  22321. hatafsegol: 0x05B1,
  22322. hatafsegol17: 0x05B1,
  22323. hatafsegol24: 0x05B1,
  22324. hatafsegol30: 0x05B1,
  22325. hatafsegolhebrew: 0x05B1,
  22326. hatafsegolnarrowhebrew: 0x05B1,
  22327. hatafsegolquarterhebrew: 0x05B1,
  22328. hatafsegolwidehebrew: 0x05B1,
  22329. hbar: 0x0127,
  22330. hbopomofo: 0x310F,
  22331. hbrevebelow: 0x1E2B,
  22332. hcedilla: 0x1E29,
  22333. hcircle: 0x24D7,
  22334. hcircumflex: 0x0125,
  22335. hdieresis: 0x1E27,
  22336. hdotaccent: 0x1E23,
  22337. hdotbelow: 0x1E25,
  22338. he: 0x05D4,
  22339. heart: 0x2665,
  22340. heartsuitblack: 0x2665,
  22341. heartsuitwhite: 0x2661,
  22342. hedagesh: 0xFB34,
  22343. hedageshhebrew: 0xFB34,
  22344. hehaltonearabic: 0x06C1,
  22345. heharabic: 0x0647,
  22346. hehebrew: 0x05D4,
  22347. hehfinalaltonearabic: 0xFBA7,
  22348. hehfinalalttwoarabic: 0xFEEA,
  22349. hehfinalarabic: 0xFEEA,
  22350. hehhamzaabovefinalarabic: 0xFBA5,
  22351. hehhamzaaboveisolatedarabic: 0xFBA4,
  22352. hehinitialaltonearabic: 0xFBA8,
  22353. hehinitialarabic: 0xFEEB,
  22354. hehiragana: 0x3078,
  22355. hehmedialaltonearabic: 0xFBA9,
  22356. hehmedialarabic: 0xFEEC,
  22357. heiseierasquare: 0x337B,
  22358. hekatakana: 0x30D8,
  22359. hekatakanahalfwidth: 0xFF8D,
  22360. hekutaarusquare: 0x3336,
  22361. henghook: 0x0267,
  22362. herutusquare: 0x3339,
  22363. het: 0x05D7,
  22364. hethebrew: 0x05D7,
  22365. hhook: 0x0266,
  22366. hhooksuperior: 0x02B1,
  22367. hieuhacirclekorean: 0x327B,
  22368. hieuhaparenkorean: 0x321B,
  22369. hieuhcirclekorean: 0x326D,
  22370. hieuhkorean: 0x314E,
  22371. hieuhparenkorean: 0x320D,
  22372. hihiragana: 0x3072,
  22373. hikatakana: 0x30D2,
  22374. hikatakanahalfwidth: 0xFF8B,
  22375. hiriq: 0x05B4,
  22376. hiriq14: 0x05B4,
  22377. hiriq21: 0x05B4,
  22378. hiriq2d: 0x05B4,
  22379. hiriqhebrew: 0x05B4,
  22380. hiriqnarrowhebrew: 0x05B4,
  22381. hiriqquarterhebrew: 0x05B4,
  22382. hiriqwidehebrew: 0x05B4,
  22383. hlinebelow: 0x1E96,
  22384. hmonospace: 0xFF48,
  22385. hoarmenian: 0x0570,
  22386. hohipthai: 0x0E2B,
  22387. hohiragana: 0x307B,
  22388. hokatakana: 0x30DB,
  22389. hokatakanahalfwidth: 0xFF8E,
  22390. holam: 0x05B9,
  22391. holam19: 0x05B9,
  22392. holam26: 0x05B9,
  22393. holam32: 0x05B9,
  22394. holamhebrew: 0x05B9,
  22395. holamnarrowhebrew: 0x05B9,
  22396. holamquarterhebrew: 0x05B9,
  22397. holamwidehebrew: 0x05B9,
  22398. honokhukthai: 0x0E2E,
  22399. hookabovecomb: 0x0309,
  22400. hookcmb: 0x0309,
  22401. hookpalatalizedbelowcmb: 0x0321,
  22402. hookretroflexbelowcmb: 0x0322,
  22403. hoonsquare: 0x3342,
  22404. horicoptic: 0x03E9,
  22405. horizontalbar: 0x2015,
  22406. horncmb: 0x031B,
  22407. hotsprings: 0x2668,
  22408. house: 0x2302,
  22409. hparen: 0x24A3,
  22410. hsuperior: 0x02B0,
  22411. hturned: 0x0265,
  22412. huhiragana: 0x3075,
  22413. huiitosquare: 0x3333,
  22414. hukatakana: 0x30D5,
  22415. hukatakanahalfwidth: 0xFF8C,
  22416. hungarumlaut: 0x02DD,
  22417. hungarumlautcmb: 0x030B,
  22418. hv: 0x0195,
  22419. hyphen: 0x002D,
  22420. hypheninferior: 0xF6E5,
  22421. hyphenmonospace: 0xFF0D,
  22422. hyphensmall: 0xFE63,
  22423. hyphensuperior: 0xF6E6,
  22424. hyphentwo: 0x2010,
  22425. i: 0x0069,
  22426. iacute: 0x00ED,
  22427. iacyrillic: 0x044F,
  22428. ibengali: 0x0987,
  22429. ibopomofo: 0x3127,
  22430. ibreve: 0x012D,
  22431. icaron: 0x01D0,
  22432. icircle: 0x24D8,
  22433. icircumflex: 0x00EE,
  22434. icyrillic: 0x0456,
  22435. idblgrave: 0x0209,
  22436. ideographearthcircle: 0x328F,
  22437. ideographfirecircle: 0x328B,
  22438. ideographicallianceparen: 0x323F,
  22439. ideographiccallparen: 0x323A,
  22440. ideographiccentrecircle: 0x32A5,
  22441. ideographicclose: 0x3006,
  22442. ideographiccomma: 0x3001,
  22443. ideographiccommaleft: 0xFF64,
  22444. ideographiccongratulationparen: 0x3237,
  22445. ideographiccorrectcircle: 0x32A3,
  22446. ideographicearthparen: 0x322F,
  22447. ideographicenterpriseparen: 0x323D,
  22448. ideographicexcellentcircle: 0x329D,
  22449. ideographicfestivalparen: 0x3240,
  22450. ideographicfinancialcircle: 0x3296,
  22451. ideographicfinancialparen: 0x3236,
  22452. ideographicfireparen: 0x322B,
  22453. ideographichaveparen: 0x3232,
  22454. ideographichighcircle: 0x32A4,
  22455. ideographiciterationmark: 0x3005,
  22456. ideographiclaborcircle: 0x3298,
  22457. ideographiclaborparen: 0x3238,
  22458. ideographicleftcircle: 0x32A7,
  22459. ideographiclowcircle: 0x32A6,
  22460. ideographicmedicinecircle: 0x32A9,
  22461. ideographicmetalparen: 0x322E,
  22462. ideographicmoonparen: 0x322A,
  22463. ideographicnameparen: 0x3234,
  22464. ideographicperiod: 0x3002,
  22465. ideographicprintcircle: 0x329E,
  22466. ideographicreachparen: 0x3243,
  22467. ideographicrepresentparen: 0x3239,
  22468. ideographicresourceparen: 0x323E,
  22469. ideographicrightcircle: 0x32A8,
  22470. ideographicsecretcircle: 0x3299,
  22471. ideographicselfparen: 0x3242,
  22472. ideographicsocietyparen: 0x3233,
  22473. ideographicspace: 0x3000,
  22474. ideographicspecialparen: 0x3235,
  22475. ideographicstockparen: 0x3231,
  22476. ideographicstudyparen: 0x323B,
  22477. ideographicsunparen: 0x3230,
  22478. ideographicsuperviseparen: 0x323C,
  22479. ideographicwaterparen: 0x322C,
  22480. ideographicwoodparen: 0x322D,
  22481. ideographiczero: 0x3007,
  22482. ideographmetalcircle: 0x328E,
  22483. ideographmooncircle: 0x328A,
  22484. ideographnamecircle: 0x3294,
  22485. ideographsuncircle: 0x3290,
  22486. ideographwatercircle: 0x328C,
  22487. ideographwoodcircle: 0x328D,
  22488. ideva: 0x0907,
  22489. idieresis: 0x00EF,
  22490. idieresisacute: 0x1E2F,
  22491. idieresiscyrillic: 0x04E5,
  22492. idotbelow: 0x1ECB,
  22493. iebrevecyrillic: 0x04D7,
  22494. iecyrillic: 0x0435,
  22495. ieungacirclekorean: 0x3275,
  22496. ieungaparenkorean: 0x3215,
  22497. ieungcirclekorean: 0x3267,
  22498. ieungkorean: 0x3147,
  22499. ieungparenkorean: 0x3207,
  22500. igrave: 0x00EC,
  22501. igujarati: 0x0A87,
  22502. igurmukhi: 0x0A07,
  22503. ihiragana: 0x3044,
  22504. ihookabove: 0x1EC9,
  22505. iibengali: 0x0988,
  22506. iicyrillic: 0x0438,
  22507. iideva: 0x0908,
  22508. iigujarati: 0x0A88,
  22509. iigurmukhi: 0x0A08,
  22510. iimatragurmukhi: 0x0A40,
  22511. iinvertedbreve: 0x020B,
  22512. iishortcyrillic: 0x0439,
  22513. iivowelsignbengali: 0x09C0,
  22514. iivowelsigndeva: 0x0940,
  22515. iivowelsigngujarati: 0x0AC0,
  22516. ij: 0x0133,
  22517. ikatakana: 0x30A4,
  22518. ikatakanahalfwidth: 0xFF72,
  22519. ikorean: 0x3163,
  22520. ilde: 0x02DC,
  22521. iluyhebrew: 0x05AC,
  22522. imacron: 0x012B,
  22523. imacroncyrillic: 0x04E3,
  22524. imageorapproximatelyequal: 0x2253,
  22525. imatragurmukhi: 0x0A3F,
  22526. imonospace: 0xFF49,
  22527. increment: 0x2206,
  22528. infinity: 0x221E,
  22529. iniarmenian: 0x056B,
  22530. integral: 0x222B,
  22531. integralbottom: 0x2321,
  22532. integralbt: 0x2321,
  22533. integralex: 0xF8F5,
  22534. integraltop: 0x2320,
  22535. integraltp: 0x2320,
  22536. intersection: 0x2229,
  22537. intisquare: 0x3305,
  22538. invbullet: 0x25D8,
  22539. invcircle: 0x25D9,
  22540. invsmileface: 0x263B,
  22541. iocyrillic: 0x0451,
  22542. iogonek: 0x012F,
  22543. iota: 0x03B9,
  22544. iotadieresis: 0x03CA,
  22545. iotadieresistonos: 0x0390,
  22546. iotalatin: 0x0269,
  22547. iotatonos: 0x03AF,
  22548. iparen: 0x24A4,
  22549. irigurmukhi: 0x0A72,
  22550. ismallhiragana: 0x3043,
  22551. ismallkatakana: 0x30A3,
  22552. ismallkatakanahalfwidth: 0xFF68,
  22553. issharbengali: 0x09FA,
  22554. istroke: 0x0268,
  22555. isuperior: 0xF6ED,
  22556. iterationhiragana: 0x309D,
  22557. iterationkatakana: 0x30FD,
  22558. itilde: 0x0129,
  22559. itildebelow: 0x1E2D,
  22560. iubopomofo: 0x3129,
  22561. iucyrillic: 0x044E,
  22562. ivowelsignbengali: 0x09BF,
  22563. ivowelsigndeva: 0x093F,
  22564. ivowelsigngujarati: 0x0ABF,
  22565. izhitsacyrillic: 0x0475,
  22566. izhitsadblgravecyrillic: 0x0477,
  22567. j: 0x006A,
  22568. jaarmenian: 0x0571,
  22569. jabengali: 0x099C,
  22570. jadeva: 0x091C,
  22571. jagujarati: 0x0A9C,
  22572. jagurmukhi: 0x0A1C,
  22573. jbopomofo: 0x3110,
  22574. jcaron: 0x01F0,
  22575. jcircle: 0x24D9,
  22576. jcircumflex: 0x0135,
  22577. jcrossedtail: 0x029D,
  22578. jdotlessstroke: 0x025F,
  22579. jecyrillic: 0x0458,
  22580. jeemarabic: 0x062C,
  22581. jeemfinalarabic: 0xFE9E,
  22582. jeeminitialarabic: 0xFE9F,
  22583. jeemmedialarabic: 0xFEA0,
  22584. jeharabic: 0x0698,
  22585. jehfinalarabic: 0xFB8B,
  22586. jhabengali: 0x099D,
  22587. jhadeva: 0x091D,
  22588. jhagujarati: 0x0A9D,
  22589. jhagurmukhi: 0x0A1D,
  22590. jheharmenian: 0x057B,
  22591. jis: 0x3004,
  22592. jmonospace: 0xFF4A,
  22593. jparen: 0x24A5,
  22594. jsuperior: 0x02B2,
  22595. k: 0x006B,
  22596. kabashkircyrillic: 0x04A1,
  22597. kabengali: 0x0995,
  22598. kacute: 0x1E31,
  22599. kacyrillic: 0x043A,
  22600. kadescendercyrillic: 0x049B,
  22601. kadeva: 0x0915,
  22602. kaf: 0x05DB,
  22603. kafarabic: 0x0643,
  22604. kafdagesh: 0xFB3B,
  22605. kafdageshhebrew: 0xFB3B,
  22606. kaffinalarabic: 0xFEDA,
  22607. kafhebrew: 0x05DB,
  22608. kafinitialarabic: 0xFEDB,
  22609. kafmedialarabic: 0xFEDC,
  22610. kafrafehebrew: 0xFB4D,
  22611. kagujarati: 0x0A95,
  22612. kagurmukhi: 0x0A15,
  22613. kahiragana: 0x304B,
  22614. kahookcyrillic: 0x04C4,
  22615. kakatakana: 0x30AB,
  22616. kakatakanahalfwidth: 0xFF76,
  22617. kappa: 0x03BA,
  22618. kappasymbolgreek: 0x03F0,
  22619. kapyeounmieumkorean: 0x3171,
  22620. kapyeounphieuphkorean: 0x3184,
  22621. kapyeounpieupkorean: 0x3178,
  22622. kapyeounssangpieupkorean: 0x3179,
  22623. karoriisquare: 0x330D,
  22624. kashidaautoarabic: 0x0640,
  22625. kashidaautonosidebearingarabic: 0x0640,
  22626. kasmallkatakana: 0x30F5,
  22627. kasquare: 0x3384,
  22628. kasraarabic: 0x0650,
  22629. kasratanarabic: 0x064D,
  22630. kastrokecyrillic: 0x049F,
  22631. katahiraprolongmarkhalfwidth: 0xFF70,
  22632. kaverticalstrokecyrillic: 0x049D,
  22633. kbopomofo: 0x310E,
  22634. kcalsquare: 0x3389,
  22635. kcaron: 0x01E9,
  22636. kcedilla: 0x0137,
  22637. kcircle: 0x24DA,
  22638. kcommaaccent: 0x0137,
  22639. kdotbelow: 0x1E33,
  22640. keharmenian: 0x0584,
  22641. kehiragana: 0x3051,
  22642. kekatakana: 0x30B1,
  22643. kekatakanahalfwidth: 0xFF79,
  22644. kenarmenian: 0x056F,
  22645. kesmallkatakana: 0x30F6,
  22646. kgreenlandic: 0x0138,
  22647. khabengali: 0x0996,
  22648. khacyrillic: 0x0445,
  22649. khadeva: 0x0916,
  22650. khagujarati: 0x0A96,
  22651. khagurmukhi: 0x0A16,
  22652. khaharabic: 0x062E,
  22653. khahfinalarabic: 0xFEA6,
  22654. khahinitialarabic: 0xFEA7,
  22655. khahmedialarabic: 0xFEA8,
  22656. kheicoptic: 0x03E7,
  22657. khhadeva: 0x0959,
  22658. khhagurmukhi: 0x0A59,
  22659. khieukhacirclekorean: 0x3278,
  22660. khieukhaparenkorean: 0x3218,
  22661. khieukhcirclekorean: 0x326A,
  22662. khieukhkorean: 0x314B,
  22663. khieukhparenkorean: 0x320A,
  22664. khokhaithai: 0x0E02,
  22665. khokhonthai: 0x0E05,
  22666. khokhuatthai: 0x0E03,
  22667. khokhwaithai: 0x0E04,
  22668. khomutthai: 0x0E5B,
  22669. khook: 0x0199,
  22670. khorakhangthai: 0x0E06,
  22671. khzsquare: 0x3391,
  22672. kihiragana: 0x304D,
  22673. kikatakana: 0x30AD,
  22674. kikatakanahalfwidth: 0xFF77,
  22675. kiroguramusquare: 0x3315,
  22676. kiromeetorusquare: 0x3316,
  22677. kirosquare: 0x3314,
  22678. kiyeokacirclekorean: 0x326E,
  22679. kiyeokaparenkorean: 0x320E,
  22680. kiyeokcirclekorean: 0x3260,
  22681. kiyeokkorean: 0x3131,
  22682. kiyeokparenkorean: 0x3200,
  22683. kiyeoksioskorean: 0x3133,
  22684. kjecyrillic: 0x045C,
  22685. klinebelow: 0x1E35,
  22686. klsquare: 0x3398,
  22687. kmcubedsquare: 0x33A6,
  22688. kmonospace: 0xFF4B,
  22689. kmsquaredsquare: 0x33A2,
  22690. kohiragana: 0x3053,
  22691. kohmsquare: 0x33C0,
  22692. kokaithai: 0x0E01,
  22693. kokatakana: 0x30B3,
  22694. kokatakanahalfwidth: 0xFF7A,
  22695. kooposquare: 0x331E,
  22696. koppacyrillic: 0x0481,
  22697. koreanstandardsymbol: 0x327F,
  22698. koroniscmb: 0x0343,
  22699. kparen: 0x24A6,
  22700. kpasquare: 0x33AA,
  22701. ksicyrillic: 0x046F,
  22702. ktsquare: 0x33CF,
  22703. kturned: 0x029E,
  22704. kuhiragana: 0x304F,
  22705. kukatakana: 0x30AF,
  22706. kukatakanahalfwidth: 0xFF78,
  22707. kvsquare: 0x33B8,
  22708. kwsquare: 0x33BE,
  22709. l: 0x006C,
  22710. labengali: 0x09B2,
  22711. lacute: 0x013A,
  22712. ladeva: 0x0932,
  22713. lagujarati: 0x0AB2,
  22714. lagurmukhi: 0x0A32,
  22715. lakkhangyaothai: 0x0E45,
  22716. lamaleffinalarabic: 0xFEFC,
  22717. lamalefhamzaabovefinalarabic: 0xFEF8,
  22718. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22719. lamalefhamzabelowfinalarabic: 0xFEFA,
  22720. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22721. lamalefisolatedarabic: 0xFEFB,
  22722. lamalefmaddaabovefinalarabic: 0xFEF6,
  22723. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22724. lamarabic: 0x0644,
  22725. lambda: 0x03BB,
  22726. lambdastroke: 0x019B,
  22727. lamed: 0x05DC,
  22728. lameddagesh: 0xFB3C,
  22729. lameddageshhebrew: 0xFB3C,
  22730. lamedhebrew: 0x05DC,
  22731. lamfinalarabic: 0xFEDE,
  22732. lamhahinitialarabic: 0xFCCA,
  22733. laminitialarabic: 0xFEDF,
  22734. lamjeeminitialarabic: 0xFCC9,
  22735. lamkhahinitialarabic: 0xFCCB,
  22736. lamlamhehisolatedarabic: 0xFDF2,
  22737. lammedialarabic: 0xFEE0,
  22738. lammeemhahinitialarabic: 0xFD88,
  22739. lammeeminitialarabic: 0xFCCC,
  22740. largecircle: 0x25EF,
  22741. lbar: 0x019A,
  22742. lbelt: 0x026C,
  22743. lbopomofo: 0x310C,
  22744. lcaron: 0x013E,
  22745. lcedilla: 0x013C,
  22746. lcircle: 0x24DB,
  22747. lcircumflexbelow: 0x1E3D,
  22748. lcommaaccent: 0x013C,
  22749. ldot: 0x0140,
  22750. ldotaccent: 0x0140,
  22751. ldotbelow: 0x1E37,
  22752. ldotbelowmacron: 0x1E39,
  22753. leftangleabovecmb: 0x031A,
  22754. lefttackbelowcmb: 0x0318,
  22755. less: 0x003C,
  22756. lessequal: 0x2264,
  22757. lessequalorgreater: 0x22DA,
  22758. lessmonospace: 0xFF1C,
  22759. lessorequivalent: 0x2272,
  22760. lessorgreater: 0x2276,
  22761. lessoverequal: 0x2266,
  22762. lesssmall: 0xFE64,
  22763. lezh: 0x026E,
  22764. lfblock: 0x258C,
  22765. lhookretroflex: 0x026D,
  22766. lira: 0x20A4,
  22767. liwnarmenian: 0x056C,
  22768. lj: 0x01C9,
  22769. ljecyrillic: 0x0459,
  22770. ll: 0xF6C0,
  22771. lladeva: 0x0933,
  22772. llagujarati: 0x0AB3,
  22773. llinebelow: 0x1E3B,
  22774. llladeva: 0x0934,
  22775. llvocalicbengali: 0x09E1,
  22776. llvocalicdeva: 0x0961,
  22777. llvocalicvowelsignbengali: 0x09E3,
  22778. llvocalicvowelsigndeva: 0x0963,
  22779. lmiddletilde: 0x026B,
  22780. lmonospace: 0xFF4C,
  22781. lmsquare: 0x33D0,
  22782. lochulathai: 0x0E2C,
  22783. logicaland: 0x2227,
  22784. logicalnot: 0x00AC,
  22785. logicalnotreversed: 0x2310,
  22786. logicalor: 0x2228,
  22787. lolingthai: 0x0E25,
  22788. longs: 0x017F,
  22789. lowlinecenterline: 0xFE4E,
  22790. lowlinecmb: 0x0332,
  22791. lowlinedashed: 0xFE4D,
  22792. lozenge: 0x25CA,
  22793. lparen: 0x24A7,
  22794. lslash: 0x0142,
  22795. lsquare: 0x2113,
  22796. lsuperior: 0xF6EE,
  22797. ltshade: 0x2591,
  22798. luthai: 0x0E26,
  22799. lvocalicbengali: 0x098C,
  22800. lvocalicdeva: 0x090C,
  22801. lvocalicvowelsignbengali: 0x09E2,
  22802. lvocalicvowelsigndeva: 0x0962,
  22803. lxsquare: 0x33D3,
  22804. m: 0x006D,
  22805. mabengali: 0x09AE,
  22806. macron: 0x00AF,
  22807. macronbelowcmb: 0x0331,
  22808. macroncmb: 0x0304,
  22809. macronlowmod: 0x02CD,
  22810. macronmonospace: 0xFFE3,
  22811. macute: 0x1E3F,
  22812. madeva: 0x092E,
  22813. magujarati: 0x0AAE,
  22814. magurmukhi: 0x0A2E,
  22815. mahapakhhebrew: 0x05A4,
  22816. mahapakhlefthebrew: 0x05A4,
  22817. mahiragana: 0x307E,
  22818. maichattawalowleftthai: 0xF895,
  22819. maichattawalowrightthai: 0xF894,
  22820. maichattawathai: 0x0E4B,
  22821. maichattawaupperleftthai: 0xF893,
  22822. maieklowleftthai: 0xF88C,
  22823. maieklowrightthai: 0xF88B,
  22824. maiekthai: 0x0E48,
  22825. maiekupperleftthai: 0xF88A,
  22826. maihanakatleftthai: 0xF884,
  22827. maihanakatthai: 0x0E31,
  22828. maitaikhuleftthai: 0xF889,
  22829. maitaikhuthai: 0x0E47,
  22830. maitholowleftthai: 0xF88F,
  22831. maitholowrightthai: 0xF88E,
  22832. maithothai: 0x0E49,
  22833. maithoupperleftthai: 0xF88D,
  22834. maitrilowleftthai: 0xF892,
  22835. maitrilowrightthai: 0xF891,
  22836. maitrithai: 0x0E4A,
  22837. maitriupperleftthai: 0xF890,
  22838. maiyamokthai: 0x0E46,
  22839. makatakana: 0x30DE,
  22840. makatakanahalfwidth: 0xFF8F,
  22841. male: 0x2642,
  22842. mansyonsquare: 0x3347,
  22843. maqafhebrew: 0x05BE,
  22844. mars: 0x2642,
  22845. masoracirclehebrew: 0x05AF,
  22846. masquare: 0x3383,
  22847. mbopomofo: 0x3107,
  22848. mbsquare: 0x33D4,
  22849. mcircle: 0x24DC,
  22850. mcubedsquare: 0x33A5,
  22851. mdotaccent: 0x1E41,
  22852. mdotbelow: 0x1E43,
  22853. meemarabic: 0x0645,
  22854. meemfinalarabic: 0xFEE2,
  22855. meeminitialarabic: 0xFEE3,
  22856. meemmedialarabic: 0xFEE4,
  22857. meemmeeminitialarabic: 0xFCD1,
  22858. meemmeemisolatedarabic: 0xFC48,
  22859. meetorusquare: 0x334D,
  22860. mehiragana: 0x3081,
  22861. meizierasquare: 0x337E,
  22862. mekatakana: 0x30E1,
  22863. mekatakanahalfwidth: 0xFF92,
  22864. mem: 0x05DE,
  22865. memdagesh: 0xFB3E,
  22866. memdageshhebrew: 0xFB3E,
  22867. memhebrew: 0x05DE,
  22868. menarmenian: 0x0574,
  22869. merkhahebrew: 0x05A5,
  22870. merkhakefulahebrew: 0x05A6,
  22871. merkhakefulalefthebrew: 0x05A6,
  22872. merkhalefthebrew: 0x05A5,
  22873. mhook: 0x0271,
  22874. mhzsquare: 0x3392,
  22875. middledotkatakanahalfwidth: 0xFF65,
  22876. middot: 0x00B7,
  22877. mieumacirclekorean: 0x3272,
  22878. mieumaparenkorean: 0x3212,
  22879. mieumcirclekorean: 0x3264,
  22880. mieumkorean: 0x3141,
  22881. mieumpansioskorean: 0x3170,
  22882. mieumparenkorean: 0x3204,
  22883. mieumpieupkorean: 0x316E,
  22884. mieumsioskorean: 0x316F,
  22885. mihiragana: 0x307F,
  22886. mikatakana: 0x30DF,
  22887. mikatakanahalfwidth: 0xFF90,
  22888. minus: 0x2212,
  22889. minusbelowcmb: 0x0320,
  22890. minuscircle: 0x2296,
  22891. minusmod: 0x02D7,
  22892. minusplus: 0x2213,
  22893. minute: 0x2032,
  22894. miribaarusquare: 0x334A,
  22895. mirisquare: 0x3349,
  22896. mlonglegturned: 0x0270,
  22897. mlsquare: 0x3396,
  22898. mmcubedsquare: 0x33A3,
  22899. mmonospace: 0xFF4D,
  22900. mmsquaredsquare: 0x339F,
  22901. mohiragana: 0x3082,
  22902. mohmsquare: 0x33C1,
  22903. mokatakana: 0x30E2,
  22904. mokatakanahalfwidth: 0xFF93,
  22905. molsquare: 0x33D6,
  22906. momathai: 0x0E21,
  22907. moverssquare: 0x33A7,
  22908. moverssquaredsquare: 0x33A8,
  22909. mparen: 0x24A8,
  22910. mpasquare: 0x33AB,
  22911. mssquare: 0x33B3,
  22912. msuperior: 0xF6EF,
  22913. mturned: 0x026F,
  22914. mu: 0x00B5,
  22915. mu1: 0x00B5,
  22916. muasquare: 0x3382,
  22917. muchgreater: 0x226B,
  22918. muchless: 0x226A,
  22919. mufsquare: 0x338C,
  22920. mugreek: 0x03BC,
  22921. mugsquare: 0x338D,
  22922. muhiragana: 0x3080,
  22923. mukatakana: 0x30E0,
  22924. mukatakanahalfwidth: 0xFF91,
  22925. mulsquare: 0x3395,
  22926. multiply: 0x00D7,
  22927. mumsquare: 0x339B,
  22928. munahhebrew: 0x05A3,
  22929. munahlefthebrew: 0x05A3,
  22930. musicalnote: 0x266A,
  22931. musicalnotedbl: 0x266B,
  22932. musicflatsign: 0x266D,
  22933. musicsharpsign: 0x266F,
  22934. mussquare: 0x33B2,
  22935. muvsquare: 0x33B6,
  22936. muwsquare: 0x33BC,
  22937. mvmegasquare: 0x33B9,
  22938. mvsquare: 0x33B7,
  22939. mwmegasquare: 0x33BF,
  22940. mwsquare: 0x33BD,
  22941. n: 0x006E,
  22942. nabengali: 0x09A8,
  22943. nabla: 0x2207,
  22944. nacute: 0x0144,
  22945. nadeva: 0x0928,
  22946. nagujarati: 0x0AA8,
  22947. nagurmukhi: 0x0A28,
  22948. nahiragana: 0x306A,
  22949. nakatakana: 0x30CA,
  22950. nakatakanahalfwidth: 0xFF85,
  22951. napostrophe: 0x0149,
  22952. nasquare: 0x3381,
  22953. nbopomofo: 0x310B,
  22954. nbspace: 0x00A0,
  22955. ncaron: 0x0148,
  22956. ncedilla: 0x0146,
  22957. ncircle: 0x24DD,
  22958. ncircumflexbelow: 0x1E4B,
  22959. ncommaaccent: 0x0146,
  22960. ndotaccent: 0x1E45,
  22961. ndotbelow: 0x1E47,
  22962. nehiragana: 0x306D,
  22963. nekatakana: 0x30CD,
  22964. nekatakanahalfwidth: 0xFF88,
  22965. newsheqelsign: 0x20AA,
  22966. nfsquare: 0x338B,
  22967. ngabengali: 0x0999,
  22968. ngadeva: 0x0919,
  22969. ngagujarati: 0x0A99,
  22970. ngagurmukhi: 0x0A19,
  22971. ngonguthai: 0x0E07,
  22972. nhiragana: 0x3093,
  22973. nhookleft: 0x0272,
  22974. nhookretroflex: 0x0273,
  22975. nieunacirclekorean: 0x326F,
  22976. nieunaparenkorean: 0x320F,
  22977. nieuncieuckorean: 0x3135,
  22978. nieuncirclekorean: 0x3261,
  22979. nieunhieuhkorean: 0x3136,
  22980. nieunkorean: 0x3134,
  22981. nieunpansioskorean: 0x3168,
  22982. nieunparenkorean: 0x3201,
  22983. nieunsioskorean: 0x3167,
  22984. nieuntikeutkorean: 0x3166,
  22985. nihiragana: 0x306B,
  22986. nikatakana: 0x30CB,
  22987. nikatakanahalfwidth: 0xFF86,
  22988. nikhahitleftthai: 0xF899,
  22989. nikhahitthai: 0x0E4D,
  22990. nine: 0x0039,
  22991. ninearabic: 0x0669,
  22992. ninebengali: 0x09EF,
  22993. ninecircle: 0x2468,
  22994. ninecircleinversesansserif: 0x2792,
  22995. ninedeva: 0x096F,
  22996. ninegujarati: 0x0AEF,
  22997. ninegurmukhi: 0x0A6F,
  22998. ninehackarabic: 0x0669,
  22999. ninehangzhou: 0x3029,
  23000. nineideographicparen: 0x3228,
  23001. nineinferior: 0x2089,
  23002. ninemonospace: 0xFF19,
  23003. nineoldstyle: 0xF739,
  23004. nineparen: 0x247C,
  23005. nineperiod: 0x2490,
  23006. ninepersian: 0x06F9,
  23007. nineroman: 0x2178,
  23008. ninesuperior: 0x2079,
  23009. nineteencircle: 0x2472,
  23010. nineteenparen: 0x2486,
  23011. nineteenperiod: 0x249A,
  23012. ninethai: 0x0E59,
  23013. nj: 0x01CC,
  23014. njecyrillic: 0x045A,
  23015. nkatakana: 0x30F3,
  23016. nkatakanahalfwidth: 0xFF9D,
  23017. nlegrightlong: 0x019E,
  23018. nlinebelow: 0x1E49,
  23019. nmonospace: 0xFF4E,
  23020. nmsquare: 0x339A,
  23021. nnabengali: 0x09A3,
  23022. nnadeva: 0x0923,
  23023. nnagujarati: 0x0AA3,
  23024. nnagurmukhi: 0x0A23,
  23025. nnnadeva: 0x0929,
  23026. nohiragana: 0x306E,
  23027. nokatakana: 0x30CE,
  23028. nokatakanahalfwidth: 0xFF89,
  23029. nonbreakingspace: 0x00A0,
  23030. nonenthai: 0x0E13,
  23031. nonuthai: 0x0E19,
  23032. noonarabic: 0x0646,
  23033. noonfinalarabic: 0xFEE6,
  23034. noonghunnaarabic: 0x06BA,
  23035. noonghunnafinalarabic: 0xFB9F,
  23036. nooninitialarabic: 0xFEE7,
  23037. noonjeeminitialarabic: 0xFCD2,
  23038. noonjeemisolatedarabic: 0xFC4B,
  23039. noonmedialarabic: 0xFEE8,
  23040. noonmeeminitialarabic: 0xFCD5,
  23041. noonmeemisolatedarabic: 0xFC4E,
  23042. noonnoonfinalarabic: 0xFC8D,
  23043. notcontains: 0x220C,
  23044. notelement: 0x2209,
  23045. notelementof: 0x2209,
  23046. notequal: 0x2260,
  23047. notgreater: 0x226F,
  23048. notgreaternorequal: 0x2271,
  23049. notgreaternorless: 0x2279,
  23050. notidentical: 0x2262,
  23051. notless: 0x226E,
  23052. notlessnorequal: 0x2270,
  23053. notparallel: 0x2226,
  23054. notprecedes: 0x2280,
  23055. notsubset: 0x2284,
  23056. notsucceeds: 0x2281,
  23057. notsuperset: 0x2285,
  23058. nowarmenian: 0x0576,
  23059. nparen: 0x24A9,
  23060. nssquare: 0x33B1,
  23061. nsuperior: 0x207F,
  23062. ntilde: 0x00F1,
  23063. nu: 0x03BD,
  23064. nuhiragana: 0x306C,
  23065. nukatakana: 0x30CC,
  23066. nukatakanahalfwidth: 0xFF87,
  23067. nuktabengali: 0x09BC,
  23068. nuktadeva: 0x093C,
  23069. nuktagujarati: 0x0ABC,
  23070. nuktagurmukhi: 0x0A3C,
  23071. numbersign: 0x0023,
  23072. numbersignmonospace: 0xFF03,
  23073. numbersignsmall: 0xFE5F,
  23074. numeralsigngreek: 0x0374,
  23075. numeralsignlowergreek: 0x0375,
  23076. numero: 0x2116,
  23077. nun: 0x05E0,
  23078. nundagesh: 0xFB40,
  23079. nundageshhebrew: 0xFB40,
  23080. nunhebrew: 0x05E0,
  23081. nvsquare: 0x33B5,
  23082. nwsquare: 0x33BB,
  23083. nyabengali: 0x099E,
  23084. nyadeva: 0x091E,
  23085. nyagujarati: 0x0A9E,
  23086. nyagurmukhi: 0x0A1E,
  23087. o: 0x006F,
  23088. oacute: 0x00F3,
  23089. oangthai: 0x0E2D,
  23090. obarred: 0x0275,
  23091. obarredcyrillic: 0x04E9,
  23092. obarreddieresiscyrillic: 0x04EB,
  23093. obengali: 0x0993,
  23094. obopomofo: 0x311B,
  23095. obreve: 0x014F,
  23096. ocandradeva: 0x0911,
  23097. ocandragujarati: 0x0A91,
  23098. ocandravowelsigndeva: 0x0949,
  23099. ocandravowelsigngujarati: 0x0AC9,
  23100. ocaron: 0x01D2,
  23101. ocircle: 0x24DE,
  23102. ocircumflex: 0x00F4,
  23103. ocircumflexacute: 0x1ED1,
  23104. ocircumflexdotbelow: 0x1ED9,
  23105. ocircumflexgrave: 0x1ED3,
  23106. ocircumflexhookabove: 0x1ED5,
  23107. ocircumflextilde: 0x1ED7,
  23108. ocyrillic: 0x043E,
  23109. odblacute: 0x0151,
  23110. odblgrave: 0x020D,
  23111. odeva: 0x0913,
  23112. odieresis: 0x00F6,
  23113. odieresiscyrillic: 0x04E7,
  23114. odotbelow: 0x1ECD,
  23115. oe: 0x0153,
  23116. oekorean: 0x315A,
  23117. ogonek: 0x02DB,
  23118. ogonekcmb: 0x0328,
  23119. ograve: 0x00F2,
  23120. ogujarati: 0x0A93,
  23121. oharmenian: 0x0585,
  23122. ohiragana: 0x304A,
  23123. ohookabove: 0x1ECF,
  23124. ohorn: 0x01A1,
  23125. ohornacute: 0x1EDB,
  23126. ohorndotbelow: 0x1EE3,
  23127. ohorngrave: 0x1EDD,
  23128. ohornhookabove: 0x1EDF,
  23129. ohorntilde: 0x1EE1,
  23130. ohungarumlaut: 0x0151,
  23131. oi: 0x01A3,
  23132. oinvertedbreve: 0x020F,
  23133. okatakana: 0x30AA,
  23134. okatakanahalfwidth: 0xFF75,
  23135. okorean: 0x3157,
  23136. olehebrew: 0x05AB,
  23137. omacron: 0x014D,
  23138. omacronacute: 0x1E53,
  23139. omacrongrave: 0x1E51,
  23140. omdeva: 0x0950,
  23141. omega: 0x03C9,
  23142. omega1: 0x03D6,
  23143. omegacyrillic: 0x0461,
  23144. omegalatinclosed: 0x0277,
  23145. omegaroundcyrillic: 0x047B,
  23146. omegatitlocyrillic: 0x047D,
  23147. omegatonos: 0x03CE,
  23148. omgujarati: 0x0AD0,
  23149. omicron: 0x03BF,
  23150. omicrontonos: 0x03CC,
  23151. omonospace: 0xFF4F,
  23152. one: 0x0031,
  23153. onearabic: 0x0661,
  23154. onebengali: 0x09E7,
  23155. onecircle: 0x2460,
  23156. onecircleinversesansserif: 0x278A,
  23157. onedeva: 0x0967,
  23158. onedotenleader: 0x2024,
  23159. oneeighth: 0x215B,
  23160. onefitted: 0xF6DC,
  23161. onegujarati: 0x0AE7,
  23162. onegurmukhi: 0x0A67,
  23163. onehackarabic: 0x0661,
  23164. onehalf: 0x00BD,
  23165. onehangzhou: 0x3021,
  23166. oneideographicparen: 0x3220,
  23167. oneinferior: 0x2081,
  23168. onemonospace: 0xFF11,
  23169. onenumeratorbengali: 0x09F4,
  23170. oneoldstyle: 0xF731,
  23171. oneparen: 0x2474,
  23172. oneperiod: 0x2488,
  23173. onepersian: 0x06F1,
  23174. onequarter: 0x00BC,
  23175. oneroman: 0x2170,
  23176. onesuperior: 0x00B9,
  23177. onethai: 0x0E51,
  23178. onethird: 0x2153,
  23179. oogonek: 0x01EB,
  23180. oogonekmacron: 0x01ED,
  23181. oogurmukhi: 0x0A13,
  23182. oomatragurmukhi: 0x0A4B,
  23183. oopen: 0x0254,
  23184. oparen: 0x24AA,
  23185. openbullet: 0x25E6,
  23186. option: 0x2325,
  23187. ordfeminine: 0x00AA,
  23188. ordmasculine: 0x00BA,
  23189. orthogonal: 0x221F,
  23190. oshortdeva: 0x0912,
  23191. oshortvowelsigndeva: 0x094A,
  23192. oslash: 0x00F8,
  23193. oslashacute: 0x01FF,
  23194. osmallhiragana: 0x3049,
  23195. osmallkatakana: 0x30A9,
  23196. osmallkatakanahalfwidth: 0xFF6B,
  23197. ostrokeacute: 0x01FF,
  23198. osuperior: 0xF6F0,
  23199. otcyrillic: 0x047F,
  23200. otilde: 0x00F5,
  23201. otildeacute: 0x1E4D,
  23202. otildedieresis: 0x1E4F,
  23203. oubopomofo: 0x3121,
  23204. overline: 0x203E,
  23205. overlinecenterline: 0xFE4A,
  23206. overlinecmb: 0x0305,
  23207. overlinedashed: 0xFE49,
  23208. overlinedblwavy: 0xFE4C,
  23209. overlinewavy: 0xFE4B,
  23210. overscore: 0x00AF,
  23211. ovowelsignbengali: 0x09CB,
  23212. ovowelsigndeva: 0x094B,
  23213. ovowelsigngujarati: 0x0ACB,
  23214. p: 0x0070,
  23215. paampssquare: 0x3380,
  23216. paasentosquare: 0x332B,
  23217. pabengali: 0x09AA,
  23218. pacute: 0x1E55,
  23219. padeva: 0x092A,
  23220. pagedown: 0x21DF,
  23221. pageup: 0x21DE,
  23222. pagujarati: 0x0AAA,
  23223. pagurmukhi: 0x0A2A,
  23224. pahiragana: 0x3071,
  23225. paiyannoithai: 0x0E2F,
  23226. pakatakana: 0x30D1,
  23227. palatalizationcyrilliccmb: 0x0484,
  23228. palochkacyrillic: 0x04C0,
  23229. pansioskorean: 0x317F,
  23230. paragraph: 0x00B6,
  23231. parallel: 0x2225,
  23232. parenleft: 0x0028,
  23233. parenleftaltonearabic: 0xFD3E,
  23234. parenleftbt: 0xF8ED,
  23235. parenleftex: 0xF8EC,
  23236. parenleftinferior: 0x208D,
  23237. parenleftmonospace: 0xFF08,
  23238. parenleftsmall: 0xFE59,
  23239. parenleftsuperior: 0x207D,
  23240. parenlefttp: 0xF8EB,
  23241. parenleftvertical: 0xFE35,
  23242. parenright: 0x0029,
  23243. parenrightaltonearabic: 0xFD3F,
  23244. parenrightbt: 0xF8F8,
  23245. parenrightex: 0xF8F7,
  23246. parenrightinferior: 0x208E,
  23247. parenrightmonospace: 0xFF09,
  23248. parenrightsmall: 0xFE5A,
  23249. parenrightsuperior: 0x207E,
  23250. parenrighttp: 0xF8F6,
  23251. parenrightvertical: 0xFE36,
  23252. partialdiff: 0x2202,
  23253. paseqhebrew: 0x05C0,
  23254. pashtahebrew: 0x0599,
  23255. pasquare: 0x33A9,
  23256. patah: 0x05B7,
  23257. patah11: 0x05B7,
  23258. patah1d: 0x05B7,
  23259. patah2a: 0x05B7,
  23260. patahhebrew: 0x05B7,
  23261. patahnarrowhebrew: 0x05B7,
  23262. patahquarterhebrew: 0x05B7,
  23263. patahwidehebrew: 0x05B7,
  23264. pazerhebrew: 0x05A1,
  23265. pbopomofo: 0x3106,
  23266. pcircle: 0x24DF,
  23267. pdotaccent: 0x1E57,
  23268. pe: 0x05E4,
  23269. pecyrillic: 0x043F,
  23270. pedagesh: 0xFB44,
  23271. pedageshhebrew: 0xFB44,
  23272. peezisquare: 0x333B,
  23273. pefinaldageshhebrew: 0xFB43,
  23274. peharabic: 0x067E,
  23275. peharmenian: 0x057A,
  23276. pehebrew: 0x05E4,
  23277. pehfinalarabic: 0xFB57,
  23278. pehinitialarabic: 0xFB58,
  23279. pehiragana: 0x307A,
  23280. pehmedialarabic: 0xFB59,
  23281. pekatakana: 0x30DA,
  23282. pemiddlehookcyrillic: 0x04A7,
  23283. perafehebrew: 0xFB4E,
  23284. percent: 0x0025,
  23285. percentarabic: 0x066A,
  23286. percentmonospace: 0xFF05,
  23287. percentsmall: 0xFE6A,
  23288. period: 0x002E,
  23289. periodarmenian: 0x0589,
  23290. periodcentered: 0x00B7,
  23291. periodhalfwidth: 0xFF61,
  23292. periodinferior: 0xF6E7,
  23293. periodmonospace: 0xFF0E,
  23294. periodsmall: 0xFE52,
  23295. periodsuperior: 0xF6E8,
  23296. perispomenigreekcmb: 0x0342,
  23297. perpendicular: 0x22A5,
  23298. perthousand: 0x2030,
  23299. peseta: 0x20A7,
  23300. pfsquare: 0x338A,
  23301. phabengali: 0x09AB,
  23302. phadeva: 0x092B,
  23303. phagujarati: 0x0AAB,
  23304. phagurmukhi: 0x0A2B,
  23305. phi: 0x03C6,
  23306. phi1: 0x03D5,
  23307. phieuphacirclekorean: 0x327A,
  23308. phieuphaparenkorean: 0x321A,
  23309. phieuphcirclekorean: 0x326C,
  23310. phieuphkorean: 0x314D,
  23311. phieuphparenkorean: 0x320C,
  23312. philatin: 0x0278,
  23313. phinthuthai: 0x0E3A,
  23314. phisymbolgreek: 0x03D5,
  23315. phook: 0x01A5,
  23316. phophanthai: 0x0E1E,
  23317. phophungthai: 0x0E1C,
  23318. phosamphaothai: 0x0E20,
  23319. pi: 0x03C0,
  23320. pieupacirclekorean: 0x3273,
  23321. pieupaparenkorean: 0x3213,
  23322. pieupcieuckorean: 0x3176,
  23323. pieupcirclekorean: 0x3265,
  23324. pieupkiyeokkorean: 0x3172,
  23325. pieupkorean: 0x3142,
  23326. pieupparenkorean: 0x3205,
  23327. pieupsioskiyeokkorean: 0x3174,
  23328. pieupsioskorean: 0x3144,
  23329. pieupsiostikeutkorean: 0x3175,
  23330. pieupthieuthkorean: 0x3177,
  23331. pieuptikeutkorean: 0x3173,
  23332. pihiragana: 0x3074,
  23333. pikatakana: 0x30D4,
  23334. pisymbolgreek: 0x03D6,
  23335. piwrarmenian: 0x0583,
  23336. plus: 0x002B,
  23337. plusbelowcmb: 0x031F,
  23338. pluscircle: 0x2295,
  23339. plusminus: 0x00B1,
  23340. plusmod: 0x02D6,
  23341. plusmonospace: 0xFF0B,
  23342. plussmall: 0xFE62,
  23343. plussuperior: 0x207A,
  23344. pmonospace: 0xFF50,
  23345. pmsquare: 0x33D8,
  23346. pohiragana: 0x307D,
  23347. pointingindexdownwhite: 0x261F,
  23348. pointingindexleftwhite: 0x261C,
  23349. pointingindexrightwhite: 0x261E,
  23350. pointingindexupwhite: 0x261D,
  23351. pokatakana: 0x30DD,
  23352. poplathai: 0x0E1B,
  23353. postalmark: 0x3012,
  23354. postalmarkface: 0x3020,
  23355. pparen: 0x24AB,
  23356. precedes: 0x227A,
  23357. prescription: 0x211E,
  23358. primemod: 0x02B9,
  23359. primereversed: 0x2035,
  23360. product: 0x220F,
  23361. projective: 0x2305,
  23362. prolongedkana: 0x30FC,
  23363. propellor: 0x2318,
  23364. propersubset: 0x2282,
  23365. propersuperset: 0x2283,
  23366. proportion: 0x2237,
  23367. proportional: 0x221D,
  23368. psi: 0x03C8,
  23369. psicyrillic: 0x0471,
  23370. psilipneumatacyrilliccmb: 0x0486,
  23371. pssquare: 0x33B0,
  23372. puhiragana: 0x3077,
  23373. pukatakana: 0x30D7,
  23374. pvsquare: 0x33B4,
  23375. pwsquare: 0x33BA,
  23376. q: 0x0071,
  23377. qadeva: 0x0958,
  23378. qadmahebrew: 0x05A8,
  23379. qafarabic: 0x0642,
  23380. qaffinalarabic: 0xFED6,
  23381. qafinitialarabic: 0xFED7,
  23382. qafmedialarabic: 0xFED8,
  23383. qamats: 0x05B8,
  23384. qamats10: 0x05B8,
  23385. qamats1a: 0x05B8,
  23386. qamats1c: 0x05B8,
  23387. qamats27: 0x05B8,
  23388. qamats29: 0x05B8,
  23389. qamats33: 0x05B8,
  23390. qamatsde: 0x05B8,
  23391. qamatshebrew: 0x05B8,
  23392. qamatsnarrowhebrew: 0x05B8,
  23393. qamatsqatanhebrew: 0x05B8,
  23394. qamatsqatannarrowhebrew: 0x05B8,
  23395. qamatsqatanquarterhebrew: 0x05B8,
  23396. qamatsqatanwidehebrew: 0x05B8,
  23397. qamatsquarterhebrew: 0x05B8,
  23398. qamatswidehebrew: 0x05B8,
  23399. qarneyparahebrew: 0x059F,
  23400. qbopomofo: 0x3111,
  23401. qcircle: 0x24E0,
  23402. qhook: 0x02A0,
  23403. qmonospace: 0xFF51,
  23404. qof: 0x05E7,
  23405. qofdagesh: 0xFB47,
  23406. qofdageshhebrew: 0xFB47,
  23407. qofhebrew: 0x05E7,
  23408. qparen: 0x24AC,
  23409. quarternote: 0x2669,
  23410. qubuts: 0x05BB,
  23411. qubuts18: 0x05BB,
  23412. qubuts25: 0x05BB,
  23413. qubuts31: 0x05BB,
  23414. qubutshebrew: 0x05BB,
  23415. qubutsnarrowhebrew: 0x05BB,
  23416. qubutsquarterhebrew: 0x05BB,
  23417. qubutswidehebrew: 0x05BB,
  23418. question: 0x003F,
  23419. questionarabic: 0x061F,
  23420. questionarmenian: 0x055E,
  23421. questiondown: 0x00BF,
  23422. questiondownsmall: 0xF7BF,
  23423. questiongreek: 0x037E,
  23424. questionmonospace: 0xFF1F,
  23425. questionsmall: 0xF73F,
  23426. quotedbl: 0x0022,
  23427. quotedblbase: 0x201E,
  23428. quotedblleft: 0x201C,
  23429. quotedblmonospace: 0xFF02,
  23430. quotedblprime: 0x301E,
  23431. quotedblprimereversed: 0x301D,
  23432. quotedblright: 0x201D,
  23433. quoteleft: 0x2018,
  23434. quoteleftreversed: 0x201B,
  23435. quotereversed: 0x201B,
  23436. quoteright: 0x2019,
  23437. quoterightn: 0x0149,
  23438. quotesinglbase: 0x201A,
  23439. quotesingle: 0x0027,
  23440. quotesinglemonospace: 0xFF07,
  23441. r: 0x0072,
  23442. raarmenian: 0x057C,
  23443. rabengali: 0x09B0,
  23444. racute: 0x0155,
  23445. radeva: 0x0930,
  23446. radical: 0x221A,
  23447. radicalex: 0xF8E5,
  23448. radoverssquare: 0x33AE,
  23449. radoverssquaredsquare: 0x33AF,
  23450. radsquare: 0x33AD,
  23451. rafe: 0x05BF,
  23452. rafehebrew: 0x05BF,
  23453. ragujarati: 0x0AB0,
  23454. ragurmukhi: 0x0A30,
  23455. rahiragana: 0x3089,
  23456. rakatakana: 0x30E9,
  23457. rakatakanahalfwidth: 0xFF97,
  23458. ralowerdiagonalbengali: 0x09F1,
  23459. ramiddlediagonalbengali: 0x09F0,
  23460. ramshorn: 0x0264,
  23461. ratio: 0x2236,
  23462. rbopomofo: 0x3116,
  23463. rcaron: 0x0159,
  23464. rcedilla: 0x0157,
  23465. rcircle: 0x24E1,
  23466. rcommaaccent: 0x0157,
  23467. rdblgrave: 0x0211,
  23468. rdotaccent: 0x1E59,
  23469. rdotbelow: 0x1E5B,
  23470. rdotbelowmacron: 0x1E5D,
  23471. referencemark: 0x203B,
  23472. reflexsubset: 0x2286,
  23473. reflexsuperset: 0x2287,
  23474. registered: 0x00AE,
  23475. registersans: 0xF8E8,
  23476. registerserif: 0xF6DA,
  23477. reharabic: 0x0631,
  23478. reharmenian: 0x0580,
  23479. rehfinalarabic: 0xFEAE,
  23480. rehiragana: 0x308C,
  23481. rekatakana: 0x30EC,
  23482. rekatakanahalfwidth: 0xFF9A,
  23483. resh: 0x05E8,
  23484. reshdageshhebrew: 0xFB48,
  23485. reshhebrew: 0x05E8,
  23486. reversedtilde: 0x223D,
  23487. reviahebrew: 0x0597,
  23488. reviamugrashhebrew: 0x0597,
  23489. revlogicalnot: 0x2310,
  23490. rfishhook: 0x027E,
  23491. rfishhookreversed: 0x027F,
  23492. rhabengali: 0x09DD,
  23493. rhadeva: 0x095D,
  23494. rho: 0x03C1,
  23495. rhook: 0x027D,
  23496. rhookturned: 0x027B,
  23497. rhookturnedsuperior: 0x02B5,
  23498. rhosymbolgreek: 0x03F1,
  23499. rhotichookmod: 0x02DE,
  23500. rieulacirclekorean: 0x3271,
  23501. rieulaparenkorean: 0x3211,
  23502. rieulcirclekorean: 0x3263,
  23503. rieulhieuhkorean: 0x3140,
  23504. rieulkiyeokkorean: 0x313A,
  23505. rieulkiyeoksioskorean: 0x3169,
  23506. rieulkorean: 0x3139,
  23507. rieulmieumkorean: 0x313B,
  23508. rieulpansioskorean: 0x316C,
  23509. rieulparenkorean: 0x3203,
  23510. rieulphieuphkorean: 0x313F,
  23511. rieulpieupkorean: 0x313C,
  23512. rieulpieupsioskorean: 0x316B,
  23513. rieulsioskorean: 0x313D,
  23514. rieulthieuthkorean: 0x313E,
  23515. rieultikeutkorean: 0x316A,
  23516. rieulyeorinhieuhkorean: 0x316D,
  23517. rightangle: 0x221F,
  23518. righttackbelowcmb: 0x0319,
  23519. righttriangle: 0x22BF,
  23520. rihiragana: 0x308A,
  23521. rikatakana: 0x30EA,
  23522. rikatakanahalfwidth: 0xFF98,
  23523. ring: 0x02DA,
  23524. ringbelowcmb: 0x0325,
  23525. ringcmb: 0x030A,
  23526. ringhalfleft: 0x02BF,
  23527. ringhalfleftarmenian: 0x0559,
  23528. ringhalfleftbelowcmb: 0x031C,
  23529. ringhalfleftcentered: 0x02D3,
  23530. ringhalfright: 0x02BE,
  23531. ringhalfrightbelowcmb: 0x0339,
  23532. ringhalfrightcentered: 0x02D2,
  23533. rinvertedbreve: 0x0213,
  23534. rittorusquare: 0x3351,
  23535. rlinebelow: 0x1E5F,
  23536. rlongleg: 0x027C,
  23537. rlonglegturned: 0x027A,
  23538. rmonospace: 0xFF52,
  23539. rohiragana: 0x308D,
  23540. rokatakana: 0x30ED,
  23541. rokatakanahalfwidth: 0xFF9B,
  23542. roruathai: 0x0E23,
  23543. rparen: 0x24AD,
  23544. rrabengali: 0x09DC,
  23545. rradeva: 0x0931,
  23546. rragurmukhi: 0x0A5C,
  23547. rreharabic: 0x0691,
  23548. rrehfinalarabic: 0xFB8D,
  23549. rrvocalicbengali: 0x09E0,
  23550. rrvocalicdeva: 0x0960,
  23551. rrvocalicgujarati: 0x0AE0,
  23552. rrvocalicvowelsignbengali: 0x09C4,
  23553. rrvocalicvowelsigndeva: 0x0944,
  23554. rrvocalicvowelsigngujarati: 0x0AC4,
  23555. rsuperior: 0xF6F1,
  23556. rtblock: 0x2590,
  23557. rturned: 0x0279,
  23558. rturnedsuperior: 0x02B4,
  23559. ruhiragana: 0x308B,
  23560. rukatakana: 0x30EB,
  23561. rukatakanahalfwidth: 0xFF99,
  23562. rupeemarkbengali: 0x09F2,
  23563. rupeesignbengali: 0x09F3,
  23564. rupiah: 0xF6DD,
  23565. ruthai: 0x0E24,
  23566. rvocalicbengali: 0x098B,
  23567. rvocalicdeva: 0x090B,
  23568. rvocalicgujarati: 0x0A8B,
  23569. rvocalicvowelsignbengali: 0x09C3,
  23570. rvocalicvowelsigndeva: 0x0943,
  23571. rvocalicvowelsigngujarati: 0x0AC3,
  23572. s: 0x0073,
  23573. sabengali: 0x09B8,
  23574. sacute: 0x015B,
  23575. sacutedotaccent: 0x1E65,
  23576. sadarabic: 0x0635,
  23577. sadeva: 0x0938,
  23578. sadfinalarabic: 0xFEBA,
  23579. sadinitialarabic: 0xFEBB,
  23580. sadmedialarabic: 0xFEBC,
  23581. sagujarati: 0x0AB8,
  23582. sagurmukhi: 0x0A38,
  23583. sahiragana: 0x3055,
  23584. sakatakana: 0x30B5,
  23585. sakatakanahalfwidth: 0xFF7B,
  23586. sallallahoualayhewasallamarabic: 0xFDFA,
  23587. samekh: 0x05E1,
  23588. samekhdagesh: 0xFB41,
  23589. samekhdageshhebrew: 0xFB41,
  23590. samekhhebrew: 0x05E1,
  23591. saraaathai: 0x0E32,
  23592. saraaethai: 0x0E41,
  23593. saraaimaimalaithai: 0x0E44,
  23594. saraaimaimuanthai: 0x0E43,
  23595. saraamthai: 0x0E33,
  23596. saraathai: 0x0E30,
  23597. saraethai: 0x0E40,
  23598. saraiileftthai: 0xF886,
  23599. saraiithai: 0x0E35,
  23600. saraileftthai: 0xF885,
  23601. saraithai: 0x0E34,
  23602. saraothai: 0x0E42,
  23603. saraueeleftthai: 0xF888,
  23604. saraueethai: 0x0E37,
  23605. saraueleftthai: 0xF887,
  23606. sarauethai: 0x0E36,
  23607. sarauthai: 0x0E38,
  23608. sarauuthai: 0x0E39,
  23609. sbopomofo: 0x3119,
  23610. scaron: 0x0161,
  23611. scarondotaccent: 0x1E67,
  23612. scedilla: 0x015F,
  23613. schwa: 0x0259,
  23614. schwacyrillic: 0x04D9,
  23615. schwadieresiscyrillic: 0x04DB,
  23616. schwahook: 0x025A,
  23617. scircle: 0x24E2,
  23618. scircumflex: 0x015D,
  23619. scommaaccent: 0x0219,
  23620. sdotaccent: 0x1E61,
  23621. sdotbelow: 0x1E63,
  23622. sdotbelowdotaccent: 0x1E69,
  23623. seagullbelowcmb: 0x033C,
  23624. second: 0x2033,
  23625. secondtonechinese: 0x02CA,
  23626. section: 0x00A7,
  23627. seenarabic: 0x0633,
  23628. seenfinalarabic: 0xFEB2,
  23629. seeninitialarabic: 0xFEB3,
  23630. seenmedialarabic: 0xFEB4,
  23631. segol: 0x05B6,
  23632. segol13: 0x05B6,
  23633. segol1f: 0x05B6,
  23634. segol2c: 0x05B6,
  23635. segolhebrew: 0x05B6,
  23636. segolnarrowhebrew: 0x05B6,
  23637. segolquarterhebrew: 0x05B6,
  23638. segoltahebrew: 0x0592,
  23639. segolwidehebrew: 0x05B6,
  23640. seharmenian: 0x057D,
  23641. sehiragana: 0x305B,
  23642. sekatakana: 0x30BB,
  23643. sekatakanahalfwidth: 0xFF7E,
  23644. semicolon: 0x003B,
  23645. semicolonarabic: 0x061B,
  23646. semicolonmonospace: 0xFF1B,
  23647. semicolonsmall: 0xFE54,
  23648. semivoicedmarkkana: 0x309C,
  23649. semivoicedmarkkanahalfwidth: 0xFF9F,
  23650. sentisquare: 0x3322,
  23651. sentosquare: 0x3323,
  23652. seven: 0x0037,
  23653. sevenarabic: 0x0667,
  23654. sevenbengali: 0x09ED,
  23655. sevencircle: 0x2466,
  23656. sevencircleinversesansserif: 0x2790,
  23657. sevendeva: 0x096D,
  23658. seveneighths: 0x215E,
  23659. sevengujarati: 0x0AED,
  23660. sevengurmukhi: 0x0A6D,
  23661. sevenhackarabic: 0x0667,
  23662. sevenhangzhou: 0x3027,
  23663. sevenideographicparen: 0x3226,
  23664. seveninferior: 0x2087,
  23665. sevenmonospace: 0xFF17,
  23666. sevenoldstyle: 0xF737,
  23667. sevenparen: 0x247A,
  23668. sevenperiod: 0x248E,
  23669. sevenpersian: 0x06F7,
  23670. sevenroman: 0x2176,
  23671. sevensuperior: 0x2077,
  23672. seventeencircle: 0x2470,
  23673. seventeenparen: 0x2484,
  23674. seventeenperiod: 0x2498,
  23675. seventhai: 0x0E57,
  23676. sfthyphen: 0x00AD,
  23677. shaarmenian: 0x0577,
  23678. shabengali: 0x09B6,
  23679. shacyrillic: 0x0448,
  23680. shaddaarabic: 0x0651,
  23681. shaddadammaarabic: 0xFC61,
  23682. shaddadammatanarabic: 0xFC5E,
  23683. shaddafathaarabic: 0xFC60,
  23684. shaddakasraarabic: 0xFC62,
  23685. shaddakasratanarabic: 0xFC5F,
  23686. shade: 0x2592,
  23687. shadedark: 0x2593,
  23688. shadelight: 0x2591,
  23689. shademedium: 0x2592,
  23690. shadeva: 0x0936,
  23691. shagujarati: 0x0AB6,
  23692. shagurmukhi: 0x0A36,
  23693. shalshelethebrew: 0x0593,
  23694. shbopomofo: 0x3115,
  23695. shchacyrillic: 0x0449,
  23696. sheenarabic: 0x0634,
  23697. sheenfinalarabic: 0xFEB6,
  23698. sheeninitialarabic: 0xFEB7,
  23699. sheenmedialarabic: 0xFEB8,
  23700. sheicoptic: 0x03E3,
  23701. sheqel: 0x20AA,
  23702. sheqelhebrew: 0x20AA,
  23703. sheva: 0x05B0,
  23704. sheva115: 0x05B0,
  23705. sheva15: 0x05B0,
  23706. sheva22: 0x05B0,
  23707. sheva2e: 0x05B0,
  23708. shevahebrew: 0x05B0,
  23709. shevanarrowhebrew: 0x05B0,
  23710. shevaquarterhebrew: 0x05B0,
  23711. shevawidehebrew: 0x05B0,
  23712. shhacyrillic: 0x04BB,
  23713. shimacoptic: 0x03ED,
  23714. shin: 0x05E9,
  23715. shindagesh: 0xFB49,
  23716. shindageshhebrew: 0xFB49,
  23717. shindageshshindot: 0xFB2C,
  23718. shindageshshindothebrew: 0xFB2C,
  23719. shindageshsindot: 0xFB2D,
  23720. shindageshsindothebrew: 0xFB2D,
  23721. shindothebrew: 0x05C1,
  23722. shinhebrew: 0x05E9,
  23723. shinshindot: 0xFB2A,
  23724. shinshindothebrew: 0xFB2A,
  23725. shinsindot: 0xFB2B,
  23726. shinsindothebrew: 0xFB2B,
  23727. shook: 0x0282,
  23728. sigma: 0x03C3,
  23729. sigma1: 0x03C2,
  23730. sigmafinal: 0x03C2,
  23731. sigmalunatesymbolgreek: 0x03F2,
  23732. sihiragana: 0x3057,
  23733. sikatakana: 0x30B7,
  23734. sikatakanahalfwidth: 0xFF7C,
  23735. siluqhebrew: 0x05BD,
  23736. siluqlefthebrew: 0x05BD,
  23737. similar: 0x223C,
  23738. sindothebrew: 0x05C2,
  23739. siosacirclekorean: 0x3274,
  23740. siosaparenkorean: 0x3214,
  23741. sioscieuckorean: 0x317E,
  23742. sioscirclekorean: 0x3266,
  23743. sioskiyeokkorean: 0x317A,
  23744. sioskorean: 0x3145,
  23745. siosnieunkorean: 0x317B,
  23746. siosparenkorean: 0x3206,
  23747. siospieupkorean: 0x317D,
  23748. siostikeutkorean: 0x317C,
  23749. six: 0x0036,
  23750. sixarabic: 0x0666,
  23751. sixbengali: 0x09EC,
  23752. sixcircle: 0x2465,
  23753. sixcircleinversesansserif: 0x278F,
  23754. sixdeva: 0x096C,
  23755. sixgujarati: 0x0AEC,
  23756. sixgurmukhi: 0x0A6C,
  23757. sixhackarabic: 0x0666,
  23758. sixhangzhou: 0x3026,
  23759. sixideographicparen: 0x3225,
  23760. sixinferior: 0x2086,
  23761. sixmonospace: 0xFF16,
  23762. sixoldstyle: 0xF736,
  23763. sixparen: 0x2479,
  23764. sixperiod: 0x248D,
  23765. sixpersian: 0x06F6,
  23766. sixroman: 0x2175,
  23767. sixsuperior: 0x2076,
  23768. sixteencircle: 0x246F,
  23769. sixteencurrencydenominatorbengali: 0x09F9,
  23770. sixteenparen: 0x2483,
  23771. sixteenperiod: 0x2497,
  23772. sixthai: 0x0E56,
  23773. slash: 0x002F,
  23774. slashmonospace: 0xFF0F,
  23775. slong: 0x017F,
  23776. slongdotaccent: 0x1E9B,
  23777. smileface: 0x263A,
  23778. smonospace: 0xFF53,
  23779. sofpasuqhebrew: 0x05C3,
  23780. softhyphen: 0x00AD,
  23781. softsigncyrillic: 0x044C,
  23782. sohiragana: 0x305D,
  23783. sokatakana: 0x30BD,
  23784. sokatakanahalfwidth: 0xFF7F,
  23785. soliduslongoverlaycmb: 0x0338,
  23786. solidusshortoverlaycmb: 0x0337,
  23787. sorusithai: 0x0E29,
  23788. sosalathai: 0x0E28,
  23789. sosothai: 0x0E0B,
  23790. sosuathai: 0x0E2A,
  23791. space: 0x0020,
  23792. spacehackarabic: 0x0020,
  23793. spade: 0x2660,
  23794. spadesuitblack: 0x2660,
  23795. spadesuitwhite: 0x2664,
  23796. sparen: 0x24AE,
  23797. squarebelowcmb: 0x033B,
  23798. squarecc: 0x33C4,
  23799. squarecm: 0x339D,
  23800. squarediagonalcrosshatchfill: 0x25A9,
  23801. squarehorizontalfill: 0x25A4,
  23802. squarekg: 0x338F,
  23803. squarekm: 0x339E,
  23804. squarekmcapital: 0x33CE,
  23805. squareln: 0x33D1,
  23806. squarelog: 0x33D2,
  23807. squaremg: 0x338E,
  23808. squaremil: 0x33D5,
  23809. squaremm: 0x339C,
  23810. squaremsquared: 0x33A1,
  23811. squareorthogonalcrosshatchfill: 0x25A6,
  23812. squareupperlefttolowerrightfill: 0x25A7,
  23813. squareupperrighttolowerleftfill: 0x25A8,
  23814. squareverticalfill: 0x25A5,
  23815. squarewhitewithsmallblack: 0x25A3,
  23816. srsquare: 0x33DB,
  23817. ssabengali: 0x09B7,
  23818. ssadeva: 0x0937,
  23819. ssagujarati: 0x0AB7,
  23820. ssangcieuckorean: 0x3149,
  23821. ssanghieuhkorean: 0x3185,
  23822. ssangieungkorean: 0x3180,
  23823. ssangkiyeokkorean: 0x3132,
  23824. ssangnieunkorean: 0x3165,
  23825. ssangpieupkorean: 0x3143,
  23826. ssangsioskorean: 0x3146,
  23827. ssangtikeutkorean: 0x3138,
  23828. ssuperior: 0xF6F2,
  23829. sterling: 0x00A3,
  23830. sterlingmonospace: 0xFFE1,
  23831. strokelongoverlaycmb: 0x0336,
  23832. strokeshortoverlaycmb: 0x0335,
  23833. subset: 0x2282,
  23834. subsetnotequal: 0x228A,
  23835. subsetorequal: 0x2286,
  23836. succeeds: 0x227B,
  23837. suchthat: 0x220B,
  23838. suhiragana: 0x3059,
  23839. sukatakana: 0x30B9,
  23840. sukatakanahalfwidth: 0xFF7D,
  23841. sukunarabic: 0x0652,
  23842. summation: 0x2211,
  23843. sun: 0x263C,
  23844. superset: 0x2283,
  23845. supersetnotequal: 0x228B,
  23846. supersetorequal: 0x2287,
  23847. svsquare: 0x33DC,
  23848. syouwaerasquare: 0x337C,
  23849. t: 0x0074,
  23850. tabengali: 0x09A4,
  23851. tackdown: 0x22A4,
  23852. tackleft: 0x22A3,
  23853. tadeva: 0x0924,
  23854. tagujarati: 0x0AA4,
  23855. tagurmukhi: 0x0A24,
  23856. taharabic: 0x0637,
  23857. tahfinalarabic: 0xFEC2,
  23858. tahinitialarabic: 0xFEC3,
  23859. tahiragana: 0x305F,
  23860. tahmedialarabic: 0xFEC4,
  23861. taisyouerasquare: 0x337D,
  23862. takatakana: 0x30BF,
  23863. takatakanahalfwidth: 0xFF80,
  23864. tatweelarabic: 0x0640,
  23865. tau: 0x03C4,
  23866. tav: 0x05EA,
  23867. tavdages: 0xFB4A,
  23868. tavdagesh: 0xFB4A,
  23869. tavdageshhebrew: 0xFB4A,
  23870. tavhebrew: 0x05EA,
  23871. tbar: 0x0167,
  23872. tbopomofo: 0x310A,
  23873. tcaron: 0x0165,
  23874. tccurl: 0x02A8,
  23875. tcedilla: 0x0163,
  23876. tcheharabic: 0x0686,
  23877. tchehfinalarabic: 0xFB7B,
  23878. tchehinitialarabic: 0xFB7C,
  23879. tchehmedialarabic: 0xFB7D,
  23880. tcircle: 0x24E3,
  23881. tcircumflexbelow: 0x1E71,
  23882. tcommaaccent: 0x0163,
  23883. tdieresis: 0x1E97,
  23884. tdotaccent: 0x1E6B,
  23885. tdotbelow: 0x1E6D,
  23886. tecyrillic: 0x0442,
  23887. tedescendercyrillic: 0x04AD,
  23888. teharabic: 0x062A,
  23889. tehfinalarabic: 0xFE96,
  23890. tehhahinitialarabic: 0xFCA2,
  23891. tehhahisolatedarabic: 0xFC0C,
  23892. tehinitialarabic: 0xFE97,
  23893. tehiragana: 0x3066,
  23894. tehjeeminitialarabic: 0xFCA1,
  23895. tehjeemisolatedarabic: 0xFC0B,
  23896. tehmarbutaarabic: 0x0629,
  23897. tehmarbutafinalarabic: 0xFE94,
  23898. tehmedialarabic: 0xFE98,
  23899. tehmeeminitialarabic: 0xFCA4,
  23900. tehmeemisolatedarabic: 0xFC0E,
  23901. tehnoonfinalarabic: 0xFC73,
  23902. tekatakana: 0x30C6,
  23903. tekatakanahalfwidth: 0xFF83,
  23904. telephone: 0x2121,
  23905. telephoneblack: 0x260E,
  23906. telishagedolahebrew: 0x05A0,
  23907. telishaqetanahebrew: 0x05A9,
  23908. tencircle: 0x2469,
  23909. tenideographicparen: 0x3229,
  23910. tenparen: 0x247D,
  23911. tenperiod: 0x2491,
  23912. tenroman: 0x2179,
  23913. tesh: 0x02A7,
  23914. tet: 0x05D8,
  23915. tetdagesh: 0xFB38,
  23916. tetdageshhebrew: 0xFB38,
  23917. tethebrew: 0x05D8,
  23918. tetsecyrillic: 0x04B5,
  23919. tevirhebrew: 0x059B,
  23920. tevirlefthebrew: 0x059B,
  23921. thabengali: 0x09A5,
  23922. thadeva: 0x0925,
  23923. thagujarati: 0x0AA5,
  23924. thagurmukhi: 0x0A25,
  23925. thalarabic: 0x0630,
  23926. thalfinalarabic: 0xFEAC,
  23927. thanthakhatlowleftthai: 0xF898,
  23928. thanthakhatlowrightthai: 0xF897,
  23929. thanthakhatthai: 0x0E4C,
  23930. thanthakhatupperleftthai: 0xF896,
  23931. theharabic: 0x062B,
  23932. thehfinalarabic: 0xFE9A,
  23933. thehinitialarabic: 0xFE9B,
  23934. thehmedialarabic: 0xFE9C,
  23935. thereexists: 0x2203,
  23936. therefore: 0x2234,
  23937. theta: 0x03B8,
  23938. theta1: 0x03D1,
  23939. thetasymbolgreek: 0x03D1,
  23940. thieuthacirclekorean: 0x3279,
  23941. thieuthaparenkorean: 0x3219,
  23942. thieuthcirclekorean: 0x326B,
  23943. thieuthkorean: 0x314C,
  23944. thieuthparenkorean: 0x320B,
  23945. thirteencircle: 0x246C,
  23946. thirteenparen: 0x2480,
  23947. thirteenperiod: 0x2494,
  23948. thonangmonthothai: 0x0E11,
  23949. thook: 0x01AD,
  23950. thophuthaothai: 0x0E12,
  23951. thorn: 0x00FE,
  23952. thothahanthai: 0x0E17,
  23953. thothanthai: 0x0E10,
  23954. thothongthai: 0x0E18,
  23955. thothungthai: 0x0E16,
  23956. thousandcyrillic: 0x0482,
  23957. thousandsseparatorarabic: 0x066C,
  23958. thousandsseparatorpersian: 0x066C,
  23959. three: 0x0033,
  23960. threearabic: 0x0663,
  23961. threebengali: 0x09E9,
  23962. threecircle: 0x2462,
  23963. threecircleinversesansserif: 0x278C,
  23964. threedeva: 0x0969,
  23965. threeeighths: 0x215C,
  23966. threegujarati: 0x0AE9,
  23967. threegurmukhi: 0x0A69,
  23968. threehackarabic: 0x0663,
  23969. threehangzhou: 0x3023,
  23970. threeideographicparen: 0x3222,
  23971. threeinferior: 0x2083,
  23972. threemonospace: 0xFF13,
  23973. threenumeratorbengali: 0x09F6,
  23974. threeoldstyle: 0xF733,
  23975. threeparen: 0x2476,
  23976. threeperiod: 0x248A,
  23977. threepersian: 0x06F3,
  23978. threequarters: 0x00BE,
  23979. threequartersemdash: 0xF6DE,
  23980. threeroman: 0x2172,
  23981. threesuperior: 0x00B3,
  23982. threethai: 0x0E53,
  23983. thzsquare: 0x3394,
  23984. tihiragana: 0x3061,
  23985. tikatakana: 0x30C1,
  23986. tikatakanahalfwidth: 0xFF81,
  23987. tikeutacirclekorean: 0x3270,
  23988. tikeutaparenkorean: 0x3210,
  23989. tikeutcirclekorean: 0x3262,
  23990. tikeutkorean: 0x3137,
  23991. tikeutparenkorean: 0x3202,
  23992. tilde: 0x02DC,
  23993. tildebelowcmb: 0x0330,
  23994. tildecmb: 0x0303,
  23995. tildecomb: 0x0303,
  23996. tildedoublecmb: 0x0360,
  23997. tildeoperator: 0x223C,
  23998. tildeoverlaycmb: 0x0334,
  23999. tildeverticalcmb: 0x033E,
  24000. timescircle: 0x2297,
  24001. tipehahebrew: 0x0596,
  24002. tipehalefthebrew: 0x0596,
  24003. tippigurmukhi: 0x0A70,
  24004. titlocyrilliccmb: 0x0483,
  24005. tiwnarmenian: 0x057F,
  24006. tlinebelow: 0x1E6F,
  24007. tmonospace: 0xFF54,
  24008. toarmenian: 0x0569,
  24009. tohiragana: 0x3068,
  24010. tokatakana: 0x30C8,
  24011. tokatakanahalfwidth: 0xFF84,
  24012. tonebarextrahighmod: 0x02E5,
  24013. tonebarextralowmod: 0x02E9,
  24014. tonebarhighmod: 0x02E6,
  24015. tonebarlowmod: 0x02E8,
  24016. tonebarmidmod: 0x02E7,
  24017. tonefive: 0x01BD,
  24018. tonesix: 0x0185,
  24019. tonetwo: 0x01A8,
  24020. tonos: 0x0384,
  24021. tonsquare: 0x3327,
  24022. topatakthai: 0x0E0F,
  24023. tortoiseshellbracketleft: 0x3014,
  24024. tortoiseshellbracketleftsmall: 0xFE5D,
  24025. tortoiseshellbracketleftvertical: 0xFE39,
  24026. tortoiseshellbracketright: 0x3015,
  24027. tortoiseshellbracketrightsmall: 0xFE5E,
  24028. tortoiseshellbracketrightvertical: 0xFE3A,
  24029. totaothai: 0x0E15,
  24030. tpalatalhook: 0x01AB,
  24031. tparen: 0x24AF,
  24032. trademark: 0x2122,
  24033. trademarksans: 0xF8EA,
  24034. trademarkserif: 0xF6DB,
  24035. tretroflexhook: 0x0288,
  24036. triagdn: 0x25BC,
  24037. triaglf: 0x25C4,
  24038. triagrt: 0x25BA,
  24039. triagup: 0x25B2,
  24040. ts: 0x02A6,
  24041. tsadi: 0x05E6,
  24042. tsadidagesh: 0xFB46,
  24043. tsadidageshhebrew: 0xFB46,
  24044. tsadihebrew: 0x05E6,
  24045. tsecyrillic: 0x0446,
  24046. tsere: 0x05B5,
  24047. tsere12: 0x05B5,
  24048. tsere1e: 0x05B5,
  24049. tsere2b: 0x05B5,
  24050. tserehebrew: 0x05B5,
  24051. tserenarrowhebrew: 0x05B5,
  24052. tserequarterhebrew: 0x05B5,
  24053. tserewidehebrew: 0x05B5,
  24054. tshecyrillic: 0x045B,
  24055. tsuperior: 0xF6F3,
  24056. ttabengali: 0x099F,
  24057. ttadeva: 0x091F,
  24058. ttagujarati: 0x0A9F,
  24059. ttagurmukhi: 0x0A1F,
  24060. tteharabic: 0x0679,
  24061. ttehfinalarabic: 0xFB67,
  24062. ttehinitialarabic: 0xFB68,
  24063. ttehmedialarabic: 0xFB69,
  24064. tthabengali: 0x09A0,
  24065. tthadeva: 0x0920,
  24066. tthagujarati: 0x0AA0,
  24067. tthagurmukhi: 0x0A20,
  24068. tturned: 0x0287,
  24069. tuhiragana: 0x3064,
  24070. tukatakana: 0x30C4,
  24071. tukatakanahalfwidth: 0xFF82,
  24072. tusmallhiragana: 0x3063,
  24073. tusmallkatakana: 0x30C3,
  24074. tusmallkatakanahalfwidth: 0xFF6F,
  24075. twelvecircle: 0x246B,
  24076. twelveparen: 0x247F,
  24077. twelveperiod: 0x2493,
  24078. twelveroman: 0x217B,
  24079. twentycircle: 0x2473,
  24080. twentyhangzhou: 0x5344,
  24081. twentyparen: 0x2487,
  24082. twentyperiod: 0x249B,
  24083. two: 0x0032,
  24084. twoarabic: 0x0662,
  24085. twobengali: 0x09E8,
  24086. twocircle: 0x2461,
  24087. twocircleinversesansserif: 0x278B,
  24088. twodeva: 0x0968,
  24089. twodotenleader: 0x2025,
  24090. twodotleader: 0x2025,
  24091. twodotleadervertical: 0xFE30,
  24092. twogujarati: 0x0AE8,
  24093. twogurmukhi: 0x0A68,
  24094. twohackarabic: 0x0662,
  24095. twohangzhou: 0x3022,
  24096. twoideographicparen: 0x3221,
  24097. twoinferior: 0x2082,
  24098. twomonospace: 0xFF12,
  24099. twonumeratorbengali: 0x09F5,
  24100. twooldstyle: 0xF732,
  24101. twoparen: 0x2475,
  24102. twoperiod: 0x2489,
  24103. twopersian: 0x06F2,
  24104. tworoman: 0x2171,
  24105. twostroke: 0x01BB,
  24106. twosuperior: 0x00B2,
  24107. twothai: 0x0E52,
  24108. twothirds: 0x2154,
  24109. u: 0x0075,
  24110. uacute: 0x00FA,
  24111. ubar: 0x0289,
  24112. ubengali: 0x0989,
  24113. ubopomofo: 0x3128,
  24114. ubreve: 0x016D,
  24115. ucaron: 0x01D4,
  24116. ucircle: 0x24E4,
  24117. ucircumflex: 0x00FB,
  24118. ucircumflexbelow: 0x1E77,
  24119. ucyrillic: 0x0443,
  24120. udattadeva: 0x0951,
  24121. udblacute: 0x0171,
  24122. udblgrave: 0x0215,
  24123. udeva: 0x0909,
  24124. udieresis: 0x00FC,
  24125. udieresisacute: 0x01D8,
  24126. udieresisbelow: 0x1E73,
  24127. udieresiscaron: 0x01DA,
  24128. udieresiscyrillic: 0x04F1,
  24129. udieresisgrave: 0x01DC,
  24130. udieresismacron: 0x01D6,
  24131. udotbelow: 0x1EE5,
  24132. ugrave: 0x00F9,
  24133. ugujarati: 0x0A89,
  24134. ugurmukhi: 0x0A09,
  24135. uhiragana: 0x3046,
  24136. uhookabove: 0x1EE7,
  24137. uhorn: 0x01B0,
  24138. uhornacute: 0x1EE9,
  24139. uhorndotbelow: 0x1EF1,
  24140. uhorngrave: 0x1EEB,
  24141. uhornhookabove: 0x1EED,
  24142. uhorntilde: 0x1EEF,
  24143. uhungarumlaut: 0x0171,
  24144. uhungarumlautcyrillic: 0x04F3,
  24145. uinvertedbreve: 0x0217,
  24146. ukatakana: 0x30A6,
  24147. ukatakanahalfwidth: 0xFF73,
  24148. ukcyrillic: 0x0479,
  24149. ukorean: 0x315C,
  24150. umacron: 0x016B,
  24151. umacroncyrillic: 0x04EF,
  24152. umacrondieresis: 0x1E7B,
  24153. umatragurmukhi: 0x0A41,
  24154. umonospace: 0xFF55,
  24155. underscore: 0x005F,
  24156. underscoredbl: 0x2017,
  24157. underscoremonospace: 0xFF3F,
  24158. underscorevertical: 0xFE33,
  24159. underscorewavy: 0xFE4F,
  24160. union: 0x222A,
  24161. universal: 0x2200,
  24162. uogonek: 0x0173,
  24163. uparen: 0x24B0,
  24164. upblock: 0x2580,
  24165. upperdothebrew: 0x05C4,
  24166. upsilon: 0x03C5,
  24167. upsilondieresis: 0x03CB,
  24168. upsilondieresistonos: 0x03B0,
  24169. upsilonlatin: 0x028A,
  24170. upsilontonos: 0x03CD,
  24171. uptackbelowcmb: 0x031D,
  24172. uptackmod: 0x02D4,
  24173. uragurmukhi: 0x0A73,
  24174. uring: 0x016F,
  24175. ushortcyrillic: 0x045E,
  24176. usmallhiragana: 0x3045,
  24177. usmallkatakana: 0x30A5,
  24178. usmallkatakanahalfwidth: 0xFF69,
  24179. ustraightcyrillic: 0x04AF,
  24180. ustraightstrokecyrillic: 0x04B1,
  24181. utilde: 0x0169,
  24182. utildeacute: 0x1E79,
  24183. utildebelow: 0x1E75,
  24184. uubengali: 0x098A,
  24185. uudeva: 0x090A,
  24186. uugujarati: 0x0A8A,
  24187. uugurmukhi: 0x0A0A,
  24188. uumatragurmukhi: 0x0A42,
  24189. uuvowelsignbengali: 0x09C2,
  24190. uuvowelsigndeva: 0x0942,
  24191. uuvowelsigngujarati: 0x0AC2,
  24192. uvowelsignbengali: 0x09C1,
  24193. uvowelsigndeva: 0x0941,
  24194. uvowelsigngujarati: 0x0AC1,
  24195. v: 0x0076,
  24196. vadeva: 0x0935,
  24197. vagujarati: 0x0AB5,
  24198. vagurmukhi: 0x0A35,
  24199. vakatakana: 0x30F7,
  24200. vav: 0x05D5,
  24201. vavdagesh: 0xFB35,
  24202. vavdagesh65: 0xFB35,
  24203. vavdageshhebrew: 0xFB35,
  24204. vavhebrew: 0x05D5,
  24205. vavholam: 0xFB4B,
  24206. vavholamhebrew: 0xFB4B,
  24207. vavvavhebrew: 0x05F0,
  24208. vavyodhebrew: 0x05F1,
  24209. vcircle: 0x24E5,
  24210. vdotbelow: 0x1E7F,
  24211. vecyrillic: 0x0432,
  24212. veharabic: 0x06A4,
  24213. vehfinalarabic: 0xFB6B,
  24214. vehinitialarabic: 0xFB6C,
  24215. vehmedialarabic: 0xFB6D,
  24216. vekatakana: 0x30F9,
  24217. venus: 0x2640,
  24218. verticalbar: 0x007C,
  24219. verticallineabovecmb: 0x030D,
  24220. verticallinebelowcmb: 0x0329,
  24221. verticallinelowmod: 0x02CC,
  24222. verticallinemod: 0x02C8,
  24223. vewarmenian: 0x057E,
  24224. vhook: 0x028B,
  24225. vikatakana: 0x30F8,
  24226. viramabengali: 0x09CD,
  24227. viramadeva: 0x094D,
  24228. viramagujarati: 0x0ACD,
  24229. visargabengali: 0x0983,
  24230. visargadeva: 0x0903,
  24231. visargagujarati: 0x0A83,
  24232. vmonospace: 0xFF56,
  24233. voarmenian: 0x0578,
  24234. voicediterationhiragana: 0x309E,
  24235. voicediterationkatakana: 0x30FE,
  24236. voicedmarkkana: 0x309B,
  24237. voicedmarkkanahalfwidth: 0xFF9E,
  24238. vokatakana: 0x30FA,
  24239. vparen: 0x24B1,
  24240. vtilde: 0x1E7D,
  24241. vturned: 0x028C,
  24242. vuhiragana: 0x3094,
  24243. vukatakana: 0x30F4,
  24244. w: 0x0077,
  24245. wacute: 0x1E83,
  24246. waekorean: 0x3159,
  24247. wahiragana: 0x308F,
  24248. wakatakana: 0x30EF,
  24249. wakatakanahalfwidth: 0xFF9C,
  24250. wakorean: 0x3158,
  24251. wasmallhiragana: 0x308E,
  24252. wasmallkatakana: 0x30EE,
  24253. wattosquare: 0x3357,
  24254. wavedash: 0x301C,
  24255. wavyunderscorevertical: 0xFE34,
  24256. wawarabic: 0x0648,
  24257. wawfinalarabic: 0xFEEE,
  24258. wawhamzaabovearabic: 0x0624,
  24259. wawhamzaabovefinalarabic: 0xFE86,
  24260. wbsquare: 0x33DD,
  24261. wcircle: 0x24E6,
  24262. wcircumflex: 0x0175,
  24263. wdieresis: 0x1E85,
  24264. wdotaccent: 0x1E87,
  24265. wdotbelow: 0x1E89,
  24266. wehiragana: 0x3091,
  24267. weierstrass: 0x2118,
  24268. wekatakana: 0x30F1,
  24269. wekorean: 0x315E,
  24270. weokorean: 0x315D,
  24271. wgrave: 0x1E81,
  24272. whitebullet: 0x25E6,
  24273. whitecircle: 0x25CB,
  24274. whitecircleinverse: 0x25D9,
  24275. whitecornerbracketleft: 0x300E,
  24276. whitecornerbracketleftvertical: 0xFE43,
  24277. whitecornerbracketright: 0x300F,
  24278. whitecornerbracketrightvertical: 0xFE44,
  24279. whitediamond: 0x25C7,
  24280. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24281. whitedownpointingsmalltriangle: 0x25BF,
  24282. whitedownpointingtriangle: 0x25BD,
  24283. whiteleftpointingsmalltriangle: 0x25C3,
  24284. whiteleftpointingtriangle: 0x25C1,
  24285. whitelenticularbracketleft: 0x3016,
  24286. whitelenticularbracketright: 0x3017,
  24287. whiterightpointingsmalltriangle: 0x25B9,
  24288. whiterightpointingtriangle: 0x25B7,
  24289. whitesmallsquare: 0x25AB,
  24290. whitesmilingface: 0x263A,
  24291. whitesquare: 0x25A1,
  24292. whitestar: 0x2606,
  24293. whitetelephone: 0x260F,
  24294. whitetortoiseshellbracketleft: 0x3018,
  24295. whitetortoiseshellbracketright: 0x3019,
  24296. whiteuppointingsmalltriangle: 0x25B5,
  24297. whiteuppointingtriangle: 0x25B3,
  24298. wihiragana: 0x3090,
  24299. wikatakana: 0x30F0,
  24300. wikorean: 0x315F,
  24301. wmonospace: 0xFF57,
  24302. wohiragana: 0x3092,
  24303. wokatakana: 0x30F2,
  24304. wokatakanahalfwidth: 0xFF66,
  24305. won: 0x20A9,
  24306. wonmonospace: 0xFFE6,
  24307. wowaenthai: 0x0E27,
  24308. wparen: 0x24B2,
  24309. wring: 0x1E98,
  24310. wsuperior: 0x02B7,
  24311. wturned: 0x028D,
  24312. wynn: 0x01BF,
  24313. x: 0x0078,
  24314. xabovecmb: 0x033D,
  24315. xbopomofo: 0x3112,
  24316. xcircle: 0x24E7,
  24317. xdieresis: 0x1E8D,
  24318. xdotaccent: 0x1E8B,
  24319. xeharmenian: 0x056D,
  24320. xi: 0x03BE,
  24321. xmonospace: 0xFF58,
  24322. xparen: 0x24B3,
  24323. xsuperior: 0x02E3,
  24324. y: 0x0079,
  24325. yaadosquare: 0x334E,
  24326. yabengali: 0x09AF,
  24327. yacute: 0x00FD,
  24328. yadeva: 0x092F,
  24329. yaekorean: 0x3152,
  24330. yagujarati: 0x0AAF,
  24331. yagurmukhi: 0x0A2F,
  24332. yahiragana: 0x3084,
  24333. yakatakana: 0x30E4,
  24334. yakatakanahalfwidth: 0xFF94,
  24335. yakorean: 0x3151,
  24336. yamakkanthai: 0x0E4E,
  24337. yasmallhiragana: 0x3083,
  24338. yasmallkatakana: 0x30E3,
  24339. yasmallkatakanahalfwidth: 0xFF6C,
  24340. yatcyrillic: 0x0463,
  24341. ycircle: 0x24E8,
  24342. ycircumflex: 0x0177,
  24343. ydieresis: 0x00FF,
  24344. ydotaccent: 0x1E8F,
  24345. ydotbelow: 0x1EF5,
  24346. yeharabic: 0x064A,
  24347. yehbarreearabic: 0x06D2,
  24348. yehbarreefinalarabic: 0xFBAF,
  24349. yehfinalarabic: 0xFEF2,
  24350. yehhamzaabovearabic: 0x0626,
  24351. yehhamzaabovefinalarabic: 0xFE8A,
  24352. yehhamzaaboveinitialarabic: 0xFE8B,
  24353. yehhamzaabovemedialarabic: 0xFE8C,
  24354. yehinitialarabic: 0xFEF3,
  24355. yehmedialarabic: 0xFEF4,
  24356. yehmeeminitialarabic: 0xFCDD,
  24357. yehmeemisolatedarabic: 0xFC58,
  24358. yehnoonfinalarabic: 0xFC94,
  24359. yehthreedotsbelowarabic: 0x06D1,
  24360. yekorean: 0x3156,
  24361. yen: 0x00A5,
  24362. yenmonospace: 0xFFE5,
  24363. yeokorean: 0x3155,
  24364. yeorinhieuhkorean: 0x3186,
  24365. yerahbenyomohebrew: 0x05AA,
  24366. yerahbenyomolefthebrew: 0x05AA,
  24367. yericyrillic: 0x044B,
  24368. yerudieresiscyrillic: 0x04F9,
  24369. yesieungkorean: 0x3181,
  24370. yesieungpansioskorean: 0x3183,
  24371. yesieungsioskorean: 0x3182,
  24372. yetivhebrew: 0x059A,
  24373. ygrave: 0x1EF3,
  24374. yhook: 0x01B4,
  24375. yhookabove: 0x1EF7,
  24376. yiarmenian: 0x0575,
  24377. yicyrillic: 0x0457,
  24378. yikorean: 0x3162,
  24379. yinyang: 0x262F,
  24380. yiwnarmenian: 0x0582,
  24381. ymonospace: 0xFF59,
  24382. yod: 0x05D9,
  24383. yoddagesh: 0xFB39,
  24384. yoddageshhebrew: 0xFB39,
  24385. yodhebrew: 0x05D9,
  24386. yodyodhebrew: 0x05F2,
  24387. yodyodpatahhebrew: 0xFB1F,
  24388. yohiragana: 0x3088,
  24389. yoikorean: 0x3189,
  24390. yokatakana: 0x30E8,
  24391. yokatakanahalfwidth: 0xFF96,
  24392. yokorean: 0x315B,
  24393. yosmallhiragana: 0x3087,
  24394. yosmallkatakana: 0x30E7,
  24395. yosmallkatakanahalfwidth: 0xFF6E,
  24396. yotgreek: 0x03F3,
  24397. yoyaekorean: 0x3188,
  24398. yoyakorean: 0x3187,
  24399. yoyakthai: 0x0E22,
  24400. yoyingthai: 0x0E0D,
  24401. yparen: 0x24B4,
  24402. ypogegrammeni: 0x037A,
  24403. ypogegrammenigreekcmb: 0x0345,
  24404. yr: 0x01A6,
  24405. yring: 0x1E99,
  24406. ysuperior: 0x02B8,
  24407. ytilde: 0x1EF9,
  24408. yturned: 0x028E,
  24409. yuhiragana: 0x3086,
  24410. yuikorean: 0x318C,
  24411. yukatakana: 0x30E6,
  24412. yukatakanahalfwidth: 0xFF95,
  24413. yukorean: 0x3160,
  24414. yusbigcyrillic: 0x046B,
  24415. yusbigiotifiedcyrillic: 0x046D,
  24416. yuslittlecyrillic: 0x0467,
  24417. yuslittleiotifiedcyrillic: 0x0469,
  24418. yusmallhiragana: 0x3085,
  24419. yusmallkatakana: 0x30E5,
  24420. yusmallkatakanahalfwidth: 0xFF6D,
  24421. yuyekorean: 0x318B,
  24422. yuyeokorean: 0x318A,
  24423. yyabengali: 0x09DF,
  24424. yyadeva: 0x095F,
  24425. z: 0x007A,
  24426. zaarmenian: 0x0566,
  24427. zacute: 0x017A,
  24428. zadeva: 0x095B,
  24429. zagurmukhi: 0x0A5B,
  24430. zaharabic: 0x0638,
  24431. zahfinalarabic: 0xFEC6,
  24432. zahinitialarabic: 0xFEC7,
  24433. zahiragana: 0x3056,
  24434. zahmedialarabic: 0xFEC8,
  24435. zainarabic: 0x0632,
  24436. zainfinalarabic: 0xFEB0,
  24437. zakatakana: 0x30B6,
  24438. zaqefgadolhebrew: 0x0595,
  24439. zaqefqatanhebrew: 0x0594,
  24440. zarqahebrew: 0x0598,
  24441. zayin: 0x05D6,
  24442. zayindagesh: 0xFB36,
  24443. zayindageshhebrew: 0xFB36,
  24444. zayinhebrew: 0x05D6,
  24445. zbopomofo: 0x3117,
  24446. zcaron: 0x017E,
  24447. zcircle: 0x24E9,
  24448. zcircumflex: 0x1E91,
  24449. zcurl: 0x0291,
  24450. zdot: 0x017C,
  24451. zdotaccent: 0x017C,
  24452. zdotbelow: 0x1E93,
  24453. zecyrillic: 0x0437,
  24454. zedescendercyrillic: 0x0499,
  24455. zedieresiscyrillic: 0x04DF,
  24456. zehiragana: 0x305C,
  24457. zekatakana: 0x30BC,
  24458. zero: 0x0030,
  24459. zeroarabic: 0x0660,
  24460. zerobengali: 0x09E6,
  24461. zerodeva: 0x0966,
  24462. zerogujarati: 0x0AE6,
  24463. zerogurmukhi: 0x0A66,
  24464. zerohackarabic: 0x0660,
  24465. zeroinferior: 0x2080,
  24466. zeromonospace: 0xFF10,
  24467. zerooldstyle: 0xF730,
  24468. zeropersian: 0x06F0,
  24469. zerosuperior: 0x2070,
  24470. zerothai: 0x0E50,
  24471. zerowidthjoiner: 0xFEFF,
  24472. zerowidthnonjoiner: 0x200C,
  24473. zerowidthspace: 0x200B,
  24474. zeta: 0x03B6,
  24475. zhbopomofo: 0x3113,
  24476. zhearmenian: 0x056A,
  24477. zhebrevecyrillic: 0x04C2,
  24478. zhecyrillic: 0x0436,
  24479. zhedescendercyrillic: 0x0497,
  24480. zhedieresiscyrillic: 0x04DD,
  24481. zihiragana: 0x3058,
  24482. zikatakana: 0x30B8,
  24483. zinorhebrew: 0x05AE,
  24484. zlinebelow: 0x1E95,
  24485. zmonospace: 0xFF5A,
  24486. zohiragana: 0x305E,
  24487. zokatakana: 0x30BE,
  24488. zparen: 0x24B5,
  24489. zretroflexhook: 0x0290,
  24490. zstroke: 0x01B6,
  24491. zuhiragana: 0x305A,
  24492. zukatakana: 0x30BA,
  24493. '.notdef': 0x0000
  24494. };
  24495. var DingbatsGlyphsUnicode = {
  24496. space: 0x0020,
  24497. a1: 0x2701,
  24498. a2: 0x2702,
  24499. a202: 0x2703,
  24500. a3: 0x2704,
  24501. a4: 0x260E,
  24502. a5: 0x2706,
  24503. a119: 0x2707,
  24504. a118: 0x2708,
  24505. a117: 0x2709,
  24506. a11: 0x261B,
  24507. a12: 0x261E,
  24508. a13: 0x270C,
  24509. a14: 0x270D,
  24510. a15: 0x270E,
  24511. a16: 0x270F,
  24512. a105: 0x2710,
  24513. a17: 0x2711,
  24514. a18: 0x2712,
  24515. a19: 0x2713,
  24516. a20: 0x2714,
  24517. a21: 0x2715,
  24518. a22: 0x2716,
  24519. a23: 0x2717,
  24520. a24: 0x2718,
  24521. a25: 0x2719,
  24522. a26: 0x271A,
  24523. a27: 0x271B,
  24524. a28: 0x271C,
  24525. a6: 0x271D,
  24526. a7: 0x271E,
  24527. a8: 0x271F,
  24528. a9: 0x2720,
  24529. a10: 0x2721,
  24530. a29: 0x2722,
  24531. a30: 0x2723,
  24532. a31: 0x2724,
  24533. a32: 0x2725,
  24534. a33: 0x2726,
  24535. a34: 0x2727,
  24536. a35: 0x2605,
  24537. a36: 0x2729,
  24538. a37: 0x272A,
  24539. a38: 0x272B,
  24540. a39: 0x272C,
  24541. a40: 0x272D,
  24542. a41: 0x272E,
  24543. a42: 0x272F,
  24544. a43: 0x2730,
  24545. a44: 0x2731,
  24546. a45: 0x2732,
  24547. a46: 0x2733,
  24548. a47: 0x2734,
  24549. a48: 0x2735,
  24550. a49: 0x2736,
  24551. a50: 0x2737,
  24552. a51: 0x2738,
  24553. a52: 0x2739,
  24554. a53: 0x273A,
  24555. a54: 0x273B,
  24556. a55: 0x273C,
  24557. a56: 0x273D,
  24558. a57: 0x273E,
  24559. a58: 0x273F,
  24560. a59: 0x2740,
  24561. a60: 0x2741,
  24562. a61: 0x2742,
  24563. a62: 0x2743,
  24564. a63: 0x2744,
  24565. a64: 0x2745,
  24566. a65: 0x2746,
  24567. a66: 0x2747,
  24568. a67: 0x2748,
  24569. a68: 0x2749,
  24570. a69: 0x274A,
  24571. a70: 0x274B,
  24572. a71: 0x25CF,
  24573. a72: 0x274D,
  24574. a73: 0x25A0,
  24575. a74: 0x274F,
  24576. a203: 0x2750,
  24577. a75: 0x2751,
  24578. a204: 0x2752,
  24579. a76: 0x25B2,
  24580. a77: 0x25BC,
  24581. a78: 0x25C6,
  24582. a79: 0x2756,
  24583. a81: 0x25D7,
  24584. a82: 0x2758,
  24585. a83: 0x2759,
  24586. a84: 0x275A,
  24587. a97: 0x275B,
  24588. a98: 0x275C,
  24589. a99: 0x275D,
  24590. a100: 0x275E,
  24591. a101: 0x2761,
  24592. a102: 0x2762,
  24593. a103: 0x2763,
  24594. a104: 0x2764,
  24595. a106: 0x2765,
  24596. a107: 0x2766,
  24597. a108: 0x2767,
  24598. a112: 0x2663,
  24599. a111: 0x2666,
  24600. a110: 0x2665,
  24601. a109: 0x2660,
  24602. a120: 0x2460,
  24603. a121: 0x2461,
  24604. a122: 0x2462,
  24605. a123: 0x2463,
  24606. a124: 0x2464,
  24607. a125: 0x2465,
  24608. a126: 0x2466,
  24609. a127: 0x2467,
  24610. a128: 0x2468,
  24611. a129: 0x2469,
  24612. a130: 0x2776,
  24613. a131: 0x2777,
  24614. a132: 0x2778,
  24615. a133: 0x2779,
  24616. a134: 0x277A,
  24617. a135: 0x277B,
  24618. a136: 0x277C,
  24619. a137: 0x277D,
  24620. a138: 0x277E,
  24621. a139: 0x277F,
  24622. a140: 0x2780,
  24623. a141: 0x2781,
  24624. a142: 0x2782,
  24625. a143: 0x2783,
  24626. a144: 0x2784,
  24627. a145: 0x2785,
  24628. a146: 0x2786,
  24629. a147: 0x2787,
  24630. a148: 0x2788,
  24631. a149: 0x2789,
  24632. a150: 0x278A,
  24633. a151: 0x278B,
  24634. a152: 0x278C,
  24635. a153: 0x278D,
  24636. a154: 0x278E,
  24637. a155: 0x278F,
  24638. a156: 0x2790,
  24639. a157: 0x2791,
  24640. a158: 0x2792,
  24641. a159: 0x2793,
  24642. a160: 0x2794,
  24643. a161: 0x2192,
  24644. a163: 0x2194,
  24645. a164: 0x2195,
  24646. a196: 0x2798,
  24647. a165: 0x2799,
  24648. a192: 0x279A,
  24649. a166: 0x279B,
  24650. a167: 0x279C,
  24651. a168: 0x279D,
  24652. a169: 0x279E,
  24653. a170: 0x279F,
  24654. a171: 0x27A0,
  24655. a172: 0x27A1,
  24656. a173: 0x27A2,
  24657. a162: 0x27A3,
  24658. a174: 0x27A4,
  24659. a175: 0x27A5,
  24660. a176: 0x27A6,
  24661. a177: 0x27A7,
  24662. a178: 0x27A8,
  24663. a179: 0x27A9,
  24664. a193: 0x27AA,
  24665. a180: 0x27AB,
  24666. a199: 0x27AC,
  24667. a181: 0x27AD,
  24668. a200: 0x27AE,
  24669. a182: 0x27AF,
  24670. a201: 0x27B1,
  24671. a183: 0x27B2,
  24672. a184: 0x27B3,
  24673. a197: 0x27B4,
  24674. a185: 0x27B5,
  24675. a194: 0x27B6,
  24676. a198: 0x27B7,
  24677. a186: 0x27B8,
  24678. a195: 0x27B9,
  24679. a187: 0x27BA,
  24680. a188: 0x27BB,
  24681. a189: 0x27BC,
  24682. a190: 0x27BD,
  24683. a191: 0x27BE,
  24684. a89: 0x2768, // 0xF8D7
  24685. a90: 0x2769, // 0xF8D8
  24686. a93: 0x276A, // 0xF8D9
  24687. a94: 0x276B, // 0xF8DA
  24688. a91: 0x276C, // 0xF8DB
  24689. a92: 0x276D, // 0xF8DC
  24690. a205: 0x276E, // 0xF8DD
  24691. a85: 0x276F, // 0xF8DE
  24692. a206: 0x2770, // 0xF8DF
  24693. a86: 0x2771, // 0xF8E0
  24694. a87: 0x2772, // 0xF8E1
  24695. a88: 0x2773, // 0xF8E2
  24696. a95: 0x2774, // 0xF8E3
  24697. a96: 0x2775, // 0xF8E4
  24698. '.notdef': 0x0000
  24699. };
  24700. var PDFImage = (function PDFImageClosure() {
  24701. /**
  24702. * Decode the image in the main thread if it supported. Resovles the promise
  24703. * when the image data is ready.
  24704. */
  24705. function handleImageData(handler, xref, res, image) {
  24706. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24707. // For natively supported jpegs send them to the main thread for decoding.
  24708. var dict = image.dict;
  24709. var colorSpace = dict.get('ColorSpace', 'CS');
  24710. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24711. var numComps = colorSpace.numComps;
  24712. var decodePromise = handler.sendWithPromise('JpegDecode',
  24713. [image.getIR(), numComps]);
  24714. return decodePromise.then(function (message) {
  24715. var data = message.data;
  24716. return new Stream(data, 0, data.length, image.dict);
  24717. });
  24718. } else {
  24719. return Promise.resolve(image);
  24720. }
  24721. }
  24722. /**
  24723. * Decode and clamp a value. The formula is different from the spec because we
  24724. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24725. */
  24726. function decodeAndClamp(value, addend, coefficient, max) {
  24727. value = addend + value * coefficient;
  24728. // Clamp the value to the range
  24729. return (value < 0 ? 0 : (value > max ? max : value));
  24730. }
  24731. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24732. this.image = image;
  24733. var dict = image.dict;
  24734. if (dict.has('Filter')) {
  24735. var filter = dict.get('Filter').name;
  24736. if (filter === 'JPXDecode') {
  24737. var jpxImage = new JpxImage();
  24738. jpxImage.parseImageProperties(image.stream);
  24739. image.stream.reset();
  24740. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24741. image.numComps = jpxImage.componentsCount;
  24742. } else if (filter === 'JBIG2Decode') {
  24743. image.bitsPerComponent = 1;
  24744. image.numComps = 1;
  24745. }
  24746. }
  24747. // TODO cache rendered images?
  24748. this.width = dict.get('Width', 'W');
  24749. this.height = dict.get('Height', 'H');
  24750. if (this.width < 1 || this.height < 1) {
  24751. error('Invalid image width: ' + this.width + ' or height: ' +
  24752. this.height);
  24753. }
  24754. this.interpolate = dict.get('Interpolate', 'I') || false;
  24755. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24756. this.matte = dict.get('Matte') || false;
  24757. var bitsPerComponent = image.bitsPerComponent;
  24758. if (!bitsPerComponent) {
  24759. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24760. if (!bitsPerComponent) {
  24761. if (this.imageMask) {
  24762. bitsPerComponent = 1;
  24763. } else {
  24764. error('Bits per component missing in image: ' + this.imageMask);
  24765. }
  24766. }
  24767. }
  24768. this.bpc = bitsPerComponent;
  24769. if (!this.imageMask) {
  24770. var colorSpace = dict.get('ColorSpace', 'CS');
  24771. if (!colorSpace) {
  24772. info('JPX images (which do not require color spaces)');
  24773. switch (image.numComps) {
  24774. case 1:
  24775. colorSpace = Name.get('DeviceGray');
  24776. break;
  24777. case 3:
  24778. colorSpace = Name.get('DeviceRGB');
  24779. break;
  24780. case 4:
  24781. colorSpace = Name.get('DeviceCMYK');
  24782. break;
  24783. default:
  24784. error('JPX images with ' + this.numComps +
  24785. ' color components not supported.');
  24786. }
  24787. }
  24788. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24789. this.numComps = this.colorSpace.numComps;
  24790. }
  24791. this.decode = dict.get('Decode', 'D');
  24792. this.needsDecode = false;
  24793. if (this.decode &&
  24794. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24795. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24796. this.needsDecode = true;
  24797. // Do some preprocessing to avoid more math.
  24798. var max = (1 << bitsPerComponent) - 1;
  24799. this.decodeCoefficients = [];
  24800. this.decodeAddends = [];
  24801. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24802. var dmin = this.decode[i];
  24803. var dmax = this.decode[i + 1];
  24804. this.decodeCoefficients[j] = dmax - dmin;
  24805. this.decodeAddends[j] = max * dmin;
  24806. }
  24807. }
  24808. if (smask) {
  24809. this.smask = new PDFImage(xref, res, smask, false);
  24810. } else if (mask) {
  24811. if (isStream(mask)) {
  24812. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24813. } else {
  24814. // Color key mask (just an array).
  24815. this.mask = mask;
  24816. }
  24817. }
  24818. }
  24819. /**
  24820. * Handles processing of image data and returns the Promise that is resolved
  24821. * with a PDFImage when the image is ready to be used.
  24822. */
  24823. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24824. res, image, inline) {
  24825. var imagePromise = handleImageData(handler, xref, res, image);
  24826. var smaskPromise;
  24827. var maskPromise;
  24828. var smask = image.dict.get('SMask');
  24829. var mask = image.dict.get('Mask');
  24830. if (smask) {
  24831. smaskPromise = handleImageData(handler, xref, res, smask);
  24832. maskPromise = Promise.resolve(null);
  24833. } else {
  24834. smaskPromise = Promise.resolve(null);
  24835. if (mask) {
  24836. if (isStream(mask)) {
  24837. maskPromise = handleImageData(handler, xref, res, mask);
  24838. } else if (isArray(mask)) {
  24839. maskPromise = Promise.resolve(mask);
  24840. } else {
  24841. warn('Unsupported mask format.');
  24842. maskPromise = Promise.resolve(null);
  24843. }
  24844. } else {
  24845. maskPromise = Promise.resolve(null);
  24846. }
  24847. }
  24848. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24849. function(results) {
  24850. var imageData = results[0];
  24851. var smaskData = results[1];
  24852. var maskData = results[2];
  24853. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24854. });
  24855. };
  24856. /**
  24857. * Resize an image using the nearest neighbor algorithm. Currently only
  24858. * supports one and three component images.
  24859. * @param {TypedArray} pixels The original image with one component.
  24860. * @param {Number} bpc Number of bits per component.
  24861. * @param {Number} components Number of color components, 1 or 3 is supported.
  24862. * @param {Number} w1 Original width.
  24863. * @param {Number} h1 Original height.
  24864. * @param {Number} w2 New width.
  24865. * @param {Number} h2 New height.
  24866. * @param {TypedArray} dest (Optional) The destination buffer.
  24867. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24868. * @return {TypedArray} Resized image data.
  24869. */
  24870. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24871. w1, h1, w2, h2, dest, alpha01) {
  24872. if (components !== 1 && components !== 3) {
  24873. error('Unsupported component count for resizing.');
  24874. }
  24875. var length = w2 * h2 * components;
  24876. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24877. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24878. var xRatio = w1 / w2;
  24879. var yRatio = h1 / h2;
  24880. var i, j, py, newIndex = 0, oldIndex;
  24881. var xScaled = new Uint16Array(w2);
  24882. var w1Scanline = w1 * components;
  24883. if (alpha01 !== 1) {
  24884. alpha01 = 0;
  24885. }
  24886. for (j = 0; j < w2; j++) {
  24887. xScaled[j] = Math.floor(j * xRatio) * components;
  24888. }
  24889. if (components === 1) {
  24890. for (i = 0; i < h2; i++) {
  24891. py = Math.floor(i * yRatio) * w1Scanline;
  24892. for (j = 0; j < w2; j++) {
  24893. oldIndex = py + xScaled[j];
  24894. temp[newIndex++] = pixels[oldIndex];
  24895. }
  24896. }
  24897. } else if (components === 3) {
  24898. for (i = 0; i < h2; i++) {
  24899. py = Math.floor(i * yRatio) * w1Scanline;
  24900. for (j = 0; j < w2; j++) {
  24901. oldIndex = py + xScaled[j];
  24902. temp[newIndex++] = pixels[oldIndex++];
  24903. temp[newIndex++] = pixels[oldIndex++];
  24904. temp[newIndex++] = pixels[oldIndex++];
  24905. newIndex += alpha01;
  24906. }
  24907. }
  24908. }
  24909. return temp;
  24910. };
  24911. PDFImage.createMask =
  24912. function PDFImage_createMask(imgArray, width, height,
  24913. imageIsFromDecodeStream, inverseDecode) {
  24914. // |imgArray| might not contain full data for every pixel of the mask, so
  24915. // we need to distinguish between |computedLength| and |actualLength|.
  24916. // In particular, if inverseDecode is true, then the array we return must
  24917. // have a length of |computedLength|.
  24918. var computedLength = ((width + 7) >> 3) * height;
  24919. var actualLength = imgArray.byteLength;
  24920. var haveFullData = computedLength === actualLength;
  24921. var data, i;
  24922. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24923. // imgArray came from a DecodeStream and its data is in an appropriate
  24924. // form, so we can just transfer it.
  24925. data = imgArray;
  24926. } else if (!inverseDecode) {
  24927. data = new Uint8Array(actualLength);
  24928. data.set(imgArray);
  24929. } else {
  24930. data = new Uint8Array(computedLength);
  24931. data.set(imgArray);
  24932. for (i = actualLength; i < computedLength; i++) {
  24933. data[i] = 0xff;
  24934. }
  24935. }
  24936. // If necessary, invert the original mask data (but not any extra we might
  24937. // have added above). It's safe to modify the array -- whether it's the
  24938. // original or a copy, we're about to transfer it anyway, so nothing else
  24939. // in this thread can be relying on its contents.
  24940. if (inverseDecode) {
  24941. for (i = 0; i < actualLength; i++) {
  24942. data[i] = ~data[i];
  24943. }
  24944. }
  24945. return {data: data, width: width, height: height};
  24946. };
  24947. PDFImage.prototype = {
  24948. get drawWidth() {
  24949. return Math.max(this.width,
  24950. this.smask && this.smask.width || 0,
  24951. this.mask && this.mask.width || 0);
  24952. },
  24953. get drawHeight() {
  24954. return Math.max(this.height,
  24955. this.smask && this.smask.height || 0,
  24956. this.mask && this.mask.height || 0);
  24957. },
  24958. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24959. var bpc = this.bpc;
  24960. var numComps = this.numComps;
  24961. var decodeAddends = this.decodeAddends;
  24962. var decodeCoefficients = this.decodeCoefficients;
  24963. var max = (1 << bpc) - 1;
  24964. var i, ii;
  24965. if (bpc === 1) {
  24966. // If the buffer needed decode that means it just needs to be inverted.
  24967. for (i = 0, ii = buffer.length; i < ii; i++) {
  24968. buffer[i] = +!(buffer[i]);
  24969. }
  24970. return;
  24971. }
  24972. var index = 0;
  24973. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24974. for (var j = 0; j < numComps; j++) {
  24975. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24976. decodeCoefficients[j], max);
  24977. index++;
  24978. }
  24979. }
  24980. },
  24981. getComponents: function PDFImage_getComponents(buffer) {
  24982. var bpc = this.bpc;
  24983. // This image doesn't require any extra work.
  24984. if (bpc === 8) {
  24985. return buffer;
  24986. }
  24987. var width = this.width;
  24988. var height = this.height;
  24989. var numComps = this.numComps;
  24990. var length = width * height * numComps;
  24991. var bufferPos = 0;
  24992. var output = (bpc <= 8 ? new Uint8Array(length) :
  24993. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24994. var rowComps = width * numComps;
  24995. var max = (1 << bpc) - 1;
  24996. var i = 0, ii, buf;
  24997. if (bpc === 1) {
  24998. // Optimization for reading 1 bpc images.
  24999. var mask, loop1End, loop2End;
  25000. for (var j = 0; j < height; j++) {
  25001. loop1End = i + (rowComps & ~7);
  25002. loop2End = i + rowComps;
  25003. // unroll loop for all full bytes
  25004. while (i < loop1End) {
  25005. buf = buffer[bufferPos++];
  25006. output[i] = (buf >> 7) & 1;
  25007. output[i + 1] = (buf >> 6) & 1;
  25008. output[i + 2] = (buf >> 5) & 1;
  25009. output[i + 3] = (buf >> 4) & 1;
  25010. output[i + 4] = (buf >> 3) & 1;
  25011. output[i + 5] = (buf >> 2) & 1;
  25012. output[i + 6] = (buf >> 1) & 1;
  25013. output[i + 7] = buf & 1;
  25014. i += 8;
  25015. }
  25016. // handle remaing bits
  25017. if (i < loop2End) {
  25018. buf = buffer[bufferPos++];
  25019. mask = 128;
  25020. while (i < loop2End) {
  25021. output[i++] = +!!(buf & mask);
  25022. mask >>= 1;
  25023. }
  25024. }
  25025. }
  25026. } else {
  25027. // The general case that handles all other bpc values.
  25028. var bits = 0;
  25029. buf = 0;
  25030. for (i = 0, ii = length; i < ii; ++i) {
  25031. if (i % rowComps === 0) {
  25032. buf = 0;
  25033. bits = 0;
  25034. }
  25035. while (bits < bpc) {
  25036. buf = (buf << 8) | buffer[bufferPos++];
  25037. bits += 8;
  25038. }
  25039. var remainingBits = bits - bpc;
  25040. var value = buf >> remainingBits;
  25041. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25042. buf = buf & ((1 << remainingBits) - 1);
  25043. bits = remainingBits;
  25044. }
  25045. }
  25046. return output;
  25047. },
  25048. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25049. actualHeight, image) {
  25050. var smask = this.smask;
  25051. var mask = this.mask;
  25052. var alphaBuf, sw, sh, i, ii, j;
  25053. if (smask) {
  25054. sw = smask.width;
  25055. sh = smask.height;
  25056. alphaBuf = new Uint8Array(sw * sh);
  25057. smask.fillGrayBuffer(alphaBuf);
  25058. if (sw !== width || sh !== height) {
  25059. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25060. height);
  25061. }
  25062. } else if (mask) {
  25063. if (mask instanceof PDFImage) {
  25064. sw = mask.width;
  25065. sh = mask.height;
  25066. alphaBuf = new Uint8Array(sw * sh);
  25067. mask.numComps = 1;
  25068. mask.fillGrayBuffer(alphaBuf);
  25069. // Need to invert values in rgbaBuf
  25070. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25071. alphaBuf[i] = 255 - alphaBuf[i];
  25072. }
  25073. if (sw !== width || sh !== height) {
  25074. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25075. height);
  25076. }
  25077. } else if (isArray(mask)) {
  25078. // Color key mask: if any of the compontents are outside the range
  25079. // then they should be painted.
  25080. alphaBuf = new Uint8Array(width * height);
  25081. var numComps = this.numComps;
  25082. for (i = 0, ii = width * height; i < ii; ++i) {
  25083. var opacity = 0;
  25084. var imageOffset = i * numComps;
  25085. for (j = 0; j < numComps; ++j) {
  25086. var color = image[imageOffset + j];
  25087. var maskOffset = j * 2;
  25088. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25089. opacity = 255;
  25090. break;
  25091. }
  25092. }
  25093. alphaBuf[i] = opacity;
  25094. }
  25095. } else {
  25096. error('Unknown mask format.');
  25097. }
  25098. }
  25099. if (alphaBuf) {
  25100. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25101. rgbaBuf[j] = alphaBuf[i];
  25102. }
  25103. } else {
  25104. // No mask.
  25105. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25106. rgbaBuf[j] = 255;
  25107. }
  25108. }
  25109. },
  25110. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25111. var matte = this.smask && this.smask.matte;
  25112. if (!matte) {
  25113. return;
  25114. }
  25115. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25116. var matteR = matteRgb[0];
  25117. var matteG = matteRgb[1];
  25118. var matteB = matteRgb[2];
  25119. var length = width * height * 4;
  25120. var r, g, b;
  25121. for (var i = 0; i < length; i += 4) {
  25122. var alpha = buffer[i + 3];
  25123. if (alpha === 0) {
  25124. // according formula we have to get Infinity in all components
  25125. // making it white (typical paper color) should be okay
  25126. buffer[i] = 255;
  25127. buffer[i + 1] = 255;
  25128. buffer[i + 2] = 255;
  25129. continue;
  25130. }
  25131. var k = 255 / alpha;
  25132. r = (buffer[i] - matteR) * k + matteR;
  25133. g = (buffer[i + 1] - matteG) * k + matteG;
  25134. b = (buffer[i + 2] - matteB) * k + matteB;
  25135. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25136. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25137. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25138. }
  25139. },
  25140. createImageData: function PDFImage_createImageData(forceRGBA) {
  25141. var drawWidth = this.drawWidth;
  25142. var drawHeight = this.drawHeight;
  25143. var imgData = { // other fields are filled in below
  25144. width: drawWidth,
  25145. height: drawHeight
  25146. };
  25147. var numComps = this.numComps;
  25148. var originalWidth = this.width;
  25149. var originalHeight = this.height;
  25150. var bpc = this.bpc;
  25151. // Rows start at byte boundary.
  25152. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25153. var imgArray;
  25154. if (!forceRGBA) {
  25155. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25156. // without any complications, we pass a same-sized copy to the main
  25157. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25158. // of memory for many scanned documents. It's also much faster.
  25159. //
  25160. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25161. // complications, we avoid expanding by 1.333x to RGBA form.
  25162. var kind;
  25163. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25164. kind = ImageKind.GRAYSCALE_1BPP;
  25165. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25166. !this.needsDecode) {
  25167. kind = ImageKind.RGB_24BPP;
  25168. }
  25169. if (kind && !this.smask && !this.mask &&
  25170. drawWidth === originalWidth && drawHeight === originalHeight) {
  25171. imgData.kind = kind;
  25172. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25173. // If imgArray came from a DecodeStream, we're safe to transfer it
  25174. // (and thus neuter it) because it will constitute the entire
  25175. // DecodeStream's data. But if it came from a Stream, we need to
  25176. // copy it because it'll only be a portion of the Stream's data, and
  25177. // the rest will be read later on.
  25178. if (this.image instanceof DecodeStream) {
  25179. imgData.data = imgArray;
  25180. } else {
  25181. var newArray = new Uint8Array(imgArray.length);
  25182. newArray.set(imgArray);
  25183. imgData.data = newArray;
  25184. }
  25185. if (this.needsDecode) {
  25186. // Invert the buffer (which must be grayscale if we reached here).
  25187. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25188. var buffer = imgData.data;
  25189. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25190. buffer[i] ^= 0xff;
  25191. }
  25192. }
  25193. return imgData;
  25194. }
  25195. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25196. imgData.kind = ImageKind.RGB_24BPP;
  25197. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25198. drawWidth, drawHeight, true);
  25199. return imgData;
  25200. }
  25201. }
  25202. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25203. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25204. var actualHeight = 0 | (imgArray.length / rowBytes *
  25205. drawHeight / originalHeight);
  25206. var comps = this.getComponents(imgArray);
  25207. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25208. // more compact RGB_24BPP form if allowable.
  25209. var alpha01, maybeUndoPreblend;
  25210. if (!forceRGBA && !this.smask && !this.mask) {
  25211. imgData.kind = ImageKind.RGB_24BPP;
  25212. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25213. alpha01 = 0;
  25214. maybeUndoPreblend = false;
  25215. } else {
  25216. imgData.kind = ImageKind.RGBA_32BPP;
  25217. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25218. alpha01 = 1;
  25219. maybeUndoPreblend = true;
  25220. // Color key masking (opacity) must be performed before decoding.
  25221. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25222. comps);
  25223. }
  25224. if (this.needsDecode) {
  25225. this.decodeBuffer(comps);
  25226. }
  25227. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25228. drawWidth, drawHeight, actualHeight, bpc, comps,
  25229. alpha01);
  25230. if (maybeUndoPreblend) {
  25231. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25232. }
  25233. return imgData;
  25234. },
  25235. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25236. var numComps = this.numComps;
  25237. if (numComps !== 1) {
  25238. error('Reading gray scale from a color image: ' + numComps);
  25239. }
  25240. var width = this.width;
  25241. var height = this.height;
  25242. var bpc = this.bpc;
  25243. // rows start at byte boundary
  25244. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25245. var imgArray = this.getImageBytes(height * rowBytes);
  25246. var comps = this.getComponents(imgArray);
  25247. var i, length;
  25248. if (bpc === 1) {
  25249. // inline decoding (= inversion) for 1 bpc images
  25250. length = width * height;
  25251. if (this.needsDecode) {
  25252. // invert and scale to {0, 255}
  25253. for (i = 0; i < length; ++i) {
  25254. buffer[i] = (comps[i] - 1) & 255;
  25255. }
  25256. } else {
  25257. // scale to {0, 255}
  25258. for (i = 0; i < length; ++i) {
  25259. buffer[i] = (-comps[i]) & 255;
  25260. }
  25261. }
  25262. return;
  25263. }
  25264. if (this.needsDecode) {
  25265. this.decodeBuffer(comps);
  25266. }
  25267. length = width * height;
  25268. // we aren't using a colorspace so we need to scale the value
  25269. var scale = 255 / ((1 << bpc) - 1);
  25270. for (i = 0; i < length; ++i) {
  25271. buffer[i] = (scale * comps[i]) | 0;
  25272. }
  25273. },
  25274. getImageBytes: function PDFImage_getImageBytes(length,
  25275. drawWidth, drawHeight,
  25276. forceRGB) {
  25277. this.image.reset();
  25278. this.image.drawWidth = drawWidth || this.width;
  25279. this.image.drawHeight = drawHeight || this.height;
  25280. this.image.forceRGB = !!forceRGB;
  25281. return this.image.getBytes(length);
  25282. }
  25283. };
  25284. return PDFImage;
  25285. })();
  25286. // The Metrics object contains glyph widths (in glyph space units).
  25287. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25288. // space unit corresponds to 1/1000th of text space unit.
  25289. var Metrics = {
  25290. 'Courier': 600,
  25291. 'Courier-Bold': 600,
  25292. 'Courier-BoldOblique': 600,
  25293. 'Courier-Oblique': 600,
  25294. 'Helvetica' : {
  25295. 'space': 278,
  25296. 'exclam': 278,
  25297. 'quotedbl': 355,
  25298. 'numbersign': 556,
  25299. 'dollar': 556,
  25300. 'percent': 889,
  25301. 'ampersand': 667,
  25302. 'quoteright': 222,
  25303. 'parenleft': 333,
  25304. 'parenright': 333,
  25305. 'asterisk': 389,
  25306. 'plus': 584,
  25307. 'comma': 278,
  25308. 'hyphen': 333,
  25309. 'period': 278,
  25310. 'slash': 278,
  25311. 'zero': 556,
  25312. 'one': 556,
  25313. 'two': 556,
  25314. 'three': 556,
  25315. 'four': 556,
  25316. 'five': 556,
  25317. 'six': 556,
  25318. 'seven': 556,
  25319. 'eight': 556,
  25320. 'nine': 556,
  25321. 'colon': 278,
  25322. 'semicolon': 278,
  25323. 'less': 584,
  25324. 'equal': 584,
  25325. 'greater': 584,
  25326. 'question': 556,
  25327. 'at': 1015,
  25328. 'A': 667,
  25329. 'B': 667,
  25330. 'C': 722,
  25331. 'D': 722,
  25332. 'E': 667,
  25333. 'F': 611,
  25334. 'G': 778,
  25335. 'H': 722,
  25336. 'I': 278,
  25337. 'J': 500,
  25338. 'K': 667,
  25339. 'L': 556,
  25340. 'M': 833,
  25341. 'N': 722,
  25342. 'O': 778,
  25343. 'P': 667,
  25344. 'Q': 778,
  25345. 'R': 722,
  25346. 'S': 667,
  25347. 'T': 611,
  25348. 'U': 722,
  25349. 'V': 667,
  25350. 'W': 944,
  25351. 'X': 667,
  25352. 'Y': 667,
  25353. 'Z': 611,
  25354. 'bracketleft': 278,
  25355. 'backslash': 278,
  25356. 'bracketright': 278,
  25357. 'asciicircum': 469,
  25358. 'underscore': 556,
  25359. 'quoteleft': 222,
  25360. 'a': 556,
  25361. 'b': 556,
  25362. 'c': 500,
  25363. 'd': 556,
  25364. 'e': 556,
  25365. 'f': 278,
  25366. 'g': 556,
  25367. 'h': 556,
  25368. 'i': 222,
  25369. 'j': 222,
  25370. 'k': 500,
  25371. 'l': 222,
  25372. 'm': 833,
  25373. 'n': 556,
  25374. 'o': 556,
  25375. 'p': 556,
  25376. 'q': 556,
  25377. 'r': 333,
  25378. 's': 500,
  25379. 't': 278,
  25380. 'u': 556,
  25381. 'v': 500,
  25382. 'w': 722,
  25383. 'x': 500,
  25384. 'y': 500,
  25385. 'z': 500,
  25386. 'braceleft': 334,
  25387. 'bar': 260,
  25388. 'braceright': 334,
  25389. 'asciitilde': 584,
  25390. 'exclamdown': 333,
  25391. 'cent': 556,
  25392. 'sterling': 556,
  25393. 'fraction': 167,
  25394. 'yen': 556,
  25395. 'florin': 556,
  25396. 'section': 556,
  25397. 'currency': 556,
  25398. 'quotesingle': 191,
  25399. 'quotedblleft': 333,
  25400. 'guillemotleft': 556,
  25401. 'guilsinglleft': 333,
  25402. 'guilsinglright': 333,
  25403. 'fi': 500,
  25404. 'fl': 500,
  25405. 'endash': 556,
  25406. 'dagger': 556,
  25407. 'daggerdbl': 556,
  25408. 'periodcentered': 278,
  25409. 'paragraph': 537,
  25410. 'bullet': 350,
  25411. 'quotesinglbase': 222,
  25412. 'quotedblbase': 333,
  25413. 'quotedblright': 333,
  25414. 'guillemotright': 556,
  25415. 'ellipsis': 1000,
  25416. 'perthousand': 1000,
  25417. 'questiondown': 611,
  25418. 'grave': 333,
  25419. 'acute': 333,
  25420. 'circumflex': 333,
  25421. 'tilde': 333,
  25422. 'macron': 333,
  25423. 'breve': 333,
  25424. 'dotaccent': 333,
  25425. 'dieresis': 333,
  25426. 'ring': 333,
  25427. 'cedilla': 333,
  25428. 'hungarumlaut': 333,
  25429. 'ogonek': 333,
  25430. 'caron': 333,
  25431. 'emdash': 1000,
  25432. 'AE': 1000,
  25433. 'ordfeminine': 370,
  25434. 'Lslash': 556,
  25435. 'Oslash': 778,
  25436. 'OE': 1000,
  25437. 'ordmasculine': 365,
  25438. 'ae': 889,
  25439. 'dotlessi': 278,
  25440. 'lslash': 222,
  25441. 'oslash': 611,
  25442. 'oe': 944,
  25443. 'germandbls': 611,
  25444. 'Idieresis': 278,
  25445. 'eacute': 556,
  25446. 'abreve': 556,
  25447. 'uhungarumlaut': 556,
  25448. 'ecaron': 556,
  25449. 'Ydieresis': 667,
  25450. 'divide': 584,
  25451. 'Yacute': 667,
  25452. 'Acircumflex': 667,
  25453. 'aacute': 556,
  25454. 'Ucircumflex': 722,
  25455. 'yacute': 500,
  25456. 'scommaaccent': 500,
  25457. 'ecircumflex': 556,
  25458. 'Uring': 722,
  25459. 'Udieresis': 722,
  25460. 'aogonek': 556,
  25461. 'Uacute': 722,
  25462. 'uogonek': 556,
  25463. 'Edieresis': 667,
  25464. 'Dcroat': 722,
  25465. 'commaaccent': 250,
  25466. 'copyright': 737,
  25467. 'Emacron': 667,
  25468. 'ccaron': 500,
  25469. 'aring': 556,
  25470. 'Ncommaaccent': 722,
  25471. 'lacute': 222,
  25472. 'agrave': 556,
  25473. 'Tcommaaccent': 611,
  25474. 'Cacute': 722,
  25475. 'atilde': 556,
  25476. 'Edotaccent': 667,
  25477. 'scaron': 500,
  25478. 'scedilla': 500,
  25479. 'iacute': 278,
  25480. 'lozenge': 471,
  25481. 'Rcaron': 722,
  25482. 'Gcommaaccent': 778,
  25483. 'ucircumflex': 556,
  25484. 'acircumflex': 556,
  25485. 'Amacron': 667,
  25486. 'rcaron': 333,
  25487. 'ccedilla': 500,
  25488. 'Zdotaccent': 611,
  25489. 'Thorn': 667,
  25490. 'Omacron': 778,
  25491. 'Racute': 722,
  25492. 'Sacute': 667,
  25493. 'dcaron': 643,
  25494. 'Umacron': 722,
  25495. 'uring': 556,
  25496. 'threesuperior': 333,
  25497. 'Ograve': 778,
  25498. 'Agrave': 667,
  25499. 'Abreve': 667,
  25500. 'multiply': 584,
  25501. 'uacute': 556,
  25502. 'Tcaron': 611,
  25503. 'partialdiff': 476,
  25504. 'ydieresis': 500,
  25505. 'Nacute': 722,
  25506. 'icircumflex': 278,
  25507. 'Ecircumflex': 667,
  25508. 'adieresis': 556,
  25509. 'edieresis': 556,
  25510. 'cacute': 500,
  25511. 'nacute': 556,
  25512. 'umacron': 556,
  25513. 'Ncaron': 722,
  25514. 'Iacute': 278,
  25515. 'plusminus': 584,
  25516. 'brokenbar': 260,
  25517. 'registered': 737,
  25518. 'Gbreve': 778,
  25519. 'Idotaccent': 278,
  25520. 'summation': 600,
  25521. 'Egrave': 667,
  25522. 'racute': 333,
  25523. 'omacron': 556,
  25524. 'Zacute': 611,
  25525. 'Zcaron': 611,
  25526. 'greaterequal': 549,
  25527. 'Eth': 722,
  25528. 'Ccedilla': 722,
  25529. 'lcommaaccent': 222,
  25530. 'tcaron': 317,
  25531. 'eogonek': 556,
  25532. 'Uogonek': 722,
  25533. 'Aacute': 667,
  25534. 'Adieresis': 667,
  25535. 'egrave': 556,
  25536. 'zacute': 500,
  25537. 'iogonek': 222,
  25538. 'Oacute': 778,
  25539. 'oacute': 556,
  25540. 'amacron': 556,
  25541. 'sacute': 500,
  25542. 'idieresis': 278,
  25543. 'Ocircumflex': 778,
  25544. 'Ugrave': 722,
  25545. 'Delta': 612,
  25546. 'thorn': 556,
  25547. 'twosuperior': 333,
  25548. 'Odieresis': 778,
  25549. 'mu': 556,
  25550. 'igrave': 278,
  25551. 'ohungarumlaut': 556,
  25552. 'Eogonek': 667,
  25553. 'dcroat': 556,
  25554. 'threequarters': 834,
  25555. 'Scedilla': 667,
  25556. 'lcaron': 299,
  25557. 'Kcommaaccent': 667,
  25558. 'Lacute': 556,
  25559. 'trademark': 1000,
  25560. 'edotaccent': 556,
  25561. 'Igrave': 278,
  25562. 'Imacron': 278,
  25563. 'Lcaron': 556,
  25564. 'onehalf': 834,
  25565. 'lessequal': 549,
  25566. 'ocircumflex': 556,
  25567. 'ntilde': 556,
  25568. 'Uhungarumlaut': 722,
  25569. 'Eacute': 667,
  25570. 'emacron': 556,
  25571. 'gbreve': 556,
  25572. 'onequarter': 834,
  25573. 'Scaron': 667,
  25574. 'Scommaaccent': 667,
  25575. 'Ohungarumlaut': 778,
  25576. 'degree': 400,
  25577. 'ograve': 556,
  25578. 'Ccaron': 722,
  25579. 'ugrave': 556,
  25580. 'radical': 453,
  25581. 'Dcaron': 722,
  25582. 'rcommaaccent': 333,
  25583. 'Ntilde': 722,
  25584. 'otilde': 556,
  25585. 'Rcommaaccent': 722,
  25586. 'Lcommaaccent': 556,
  25587. 'Atilde': 667,
  25588. 'Aogonek': 667,
  25589. 'Aring': 667,
  25590. 'Otilde': 778,
  25591. 'zdotaccent': 500,
  25592. 'Ecaron': 667,
  25593. 'Iogonek': 278,
  25594. 'kcommaaccent': 500,
  25595. 'minus': 584,
  25596. 'Icircumflex': 278,
  25597. 'ncaron': 556,
  25598. 'tcommaaccent': 278,
  25599. 'logicalnot': 584,
  25600. 'odieresis': 556,
  25601. 'udieresis': 556,
  25602. 'notequal': 549,
  25603. 'gcommaaccent': 556,
  25604. 'eth': 556,
  25605. 'zcaron': 500,
  25606. 'ncommaaccent': 556,
  25607. 'onesuperior': 333,
  25608. 'imacron': 278,
  25609. 'Euro': 556
  25610. },
  25611. 'Helvetica-Bold': {
  25612. 'space': 278,
  25613. 'exclam': 333,
  25614. 'quotedbl': 474,
  25615. 'numbersign': 556,
  25616. 'dollar': 556,
  25617. 'percent': 889,
  25618. 'ampersand': 722,
  25619. 'quoteright': 278,
  25620. 'parenleft': 333,
  25621. 'parenright': 333,
  25622. 'asterisk': 389,
  25623. 'plus': 584,
  25624. 'comma': 278,
  25625. 'hyphen': 333,
  25626. 'period': 278,
  25627. 'slash': 278,
  25628. 'zero': 556,
  25629. 'one': 556,
  25630. 'two': 556,
  25631. 'three': 556,
  25632. 'four': 556,
  25633. 'five': 556,
  25634. 'six': 556,
  25635. 'seven': 556,
  25636. 'eight': 556,
  25637. 'nine': 556,
  25638. 'colon': 333,
  25639. 'semicolon': 333,
  25640. 'less': 584,
  25641. 'equal': 584,
  25642. 'greater': 584,
  25643. 'question': 611,
  25644. 'at': 975,
  25645. 'A': 722,
  25646. 'B': 722,
  25647. 'C': 722,
  25648. 'D': 722,
  25649. 'E': 667,
  25650. 'F': 611,
  25651. 'G': 778,
  25652. 'H': 722,
  25653. 'I': 278,
  25654. 'J': 556,
  25655. 'K': 722,
  25656. 'L': 611,
  25657. 'M': 833,
  25658. 'N': 722,
  25659. 'O': 778,
  25660. 'P': 667,
  25661. 'Q': 778,
  25662. 'R': 722,
  25663. 'S': 667,
  25664. 'T': 611,
  25665. 'U': 722,
  25666. 'V': 667,
  25667. 'W': 944,
  25668. 'X': 667,
  25669. 'Y': 667,
  25670. 'Z': 611,
  25671. 'bracketleft': 333,
  25672. 'backslash': 278,
  25673. 'bracketright': 333,
  25674. 'asciicircum': 584,
  25675. 'underscore': 556,
  25676. 'quoteleft': 278,
  25677. 'a': 556,
  25678. 'b': 611,
  25679. 'c': 556,
  25680. 'd': 611,
  25681. 'e': 556,
  25682. 'f': 333,
  25683. 'g': 611,
  25684. 'h': 611,
  25685. 'i': 278,
  25686. 'j': 278,
  25687. 'k': 556,
  25688. 'l': 278,
  25689. 'm': 889,
  25690. 'n': 611,
  25691. 'o': 611,
  25692. 'p': 611,
  25693. 'q': 611,
  25694. 'r': 389,
  25695. 's': 556,
  25696. 't': 333,
  25697. 'u': 611,
  25698. 'v': 556,
  25699. 'w': 778,
  25700. 'x': 556,
  25701. 'y': 556,
  25702. 'z': 500,
  25703. 'braceleft': 389,
  25704. 'bar': 280,
  25705. 'braceright': 389,
  25706. 'asciitilde': 584,
  25707. 'exclamdown': 333,
  25708. 'cent': 556,
  25709. 'sterling': 556,
  25710. 'fraction': 167,
  25711. 'yen': 556,
  25712. 'florin': 556,
  25713. 'section': 556,
  25714. 'currency': 556,
  25715. 'quotesingle': 238,
  25716. 'quotedblleft': 500,
  25717. 'guillemotleft': 556,
  25718. 'guilsinglleft': 333,
  25719. 'guilsinglright': 333,
  25720. 'fi': 611,
  25721. 'fl': 611,
  25722. 'endash': 556,
  25723. 'dagger': 556,
  25724. 'daggerdbl': 556,
  25725. 'periodcentered': 278,
  25726. 'paragraph': 556,
  25727. 'bullet': 350,
  25728. 'quotesinglbase': 278,
  25729. 'quotedblbase': 500,
  25730. 'quotedblright': 500,
  25731. 'guillemotright': 556,
  25732. 'ellipsis': 1000,
  25733. 'perthousand': 1000,
  25734. 'questiondown': 611,
  25735. 'grave': 333,
  25736. 'acute': 333,
  25737. 'circumflex': 333,
  25738. 'tilde': 333,
  25739. 'macron': 333,
  25740. 'breve': 333,
  25741. 'dotaccent': 333,
  25742. 'dieresis': 333,
  25743. 'ring': 333,
  25744. 'cedilla': 333,
  25745. 'hungarumlaut': 333,
  25746. 'ogonek': 333,
  25747. 'caron': 333,
  25748. 'emdash': 1000,
  25749. 'AE': 1000,
  25750. 'ordfeminine': 370,
  25751. 'Lslash': 611,
  25752. 'Oslash': 778,
  25753. 'OE': 1000,
  25754. 'ordmasculine': 365,
  25755. 'ae': 889,
  25756. 'dotlessi': 278,
  25757. 'lslash': 278,
  25758. 'oslash': 611,
  25759. 'oe': 944,
  25760. 'germandbls': 611,
  25761. 'Idieresis': 278,
  25762. 'eacute': 556,
  25763. 'abreve': 556,
  25764. 'uhungarumlaut': 611,
  25765. 'ecaron': 556,
  25766. 'Ydieresis': 667,
  25767. 'divide': 584,
  25768. 'Yacute': 667,
  25769. 'Acircumflex': 722,
  25770. 'aacute': 556,
  25771. 'Ucircumflex': 722,
  25772. 'yacute': 556,
  25773. 'scommaaccent': 556,
  25774. 'ecircumflex': 556,
  25775. 'Uring': 722,
  25776. 'Udieresis': 722,
  25777. 'aogonek': 556,
  25778. 'Uacute': 722,
  25779. 'uogonek': 611,
  25780. 'Edieresis': 667,
  25781. 'Dcroat': 722,
  25782. 'commaaccent': 250,
  25783. 'copyright': 737,
  25784. 'Emacron': 667,
  25785. 'ccaron': 556,
  25786. 'aring': 556,
  25787. 'Ncommaaccent': 722,
  25788. 'lacute': 278,
  25789. 'agrave': 556,
  25790. 'Tcommaaccent': 611,
  25791. 'Cacute': 722,
  25792. 'atilde': 556,
  25793. 'Edotaccent': 667,
  25794. 'scaron': 556,
  25795. 'scedilla': 556,
  25796. 'iacute': 278,
  25797. 'lozenge': 494,
  25798. 'Rcaron': 722,
  25799. 'Gcommaaccent': 778,
  25800. 'ucircumflex': 611,
  25801. 'acircumflex': 556,
  25802. 'Amacron': 722,
  25803. 'rcaron': 389,
  25804. 'ccedilla': 556,
  25805. 'Zdotaccent': 611,
  25806. 'Thorn': 667,
  25807. 'Omacron': 778,
  25808. 'Racute': 722,
  25809. 'Sacute': 667,
  25810. 'dcaron': 743,
  25811. 'Umacron': 722,
  25812. 'uring': 611,
  25813. 'threesuperior': 333,
  25814. 'Ograve': 778,
  25815. 'Agrave': 722,
  25816. 'Abreve': 722,
  25817. 'multiply': 584,
  25818. 'uacute': 611,
  25819. 'Tcaron': 611,
  25820. 'partialdiff': 494,
  25821. 'ydieresis': 556,
  25822. 'Nacute': 722,
  25823. 'icircumflex': 278,
  25824. 'Ecircumflex': 667,
  25825. 'adieresis': 556,
  25826. 'edieresis': 556,
  25827. 'cacute': 556,
  25828. 'nacute': 611,
  25829. 'umacron': 611,
  25830. 'Ncaron': 722,
  25831. 'Iacute': 278,
  25832. 'plusminus': 584,
  25833. 'brokenbar': 280,
  25834. 'registered': 737,
  25835. 'Gbreve': 778,
  25836. 'Idotaccent': 278,
  25837. 'summation': 600,
  25838. 'Egrave': 667,
  25839. 'racute': 389,
  25840. 'omacron': 611,
  25841. 'Zacute': 611,
  25842. 'Zcaron': 611,
  25843. 'greaterequal': 549,
  25844. 'Eth': 722,
  25845. 'Ccedilla': 722,
  25846. 'lcommaaccent': 278,
  25847. 'tcaron': 389,
  25848. 'eogonek': 556,
  25849. 'Uogonek': 722,
  25850. 'Aacute': 722,
  25851. 'Adieresis': 722,
  25852. 'egrave': 556,
  25853. 'zacute': 500,
  25854. 'iogonek': 278,
  25855. 'Oacute': 778,
  25856. 'oacute': 611,
  25857. 'amacron': 556,
  25858. 'sacute': 556,
  25859. 'idieresis': 278,
  25860. 'Ocircumflex': 778,
  25861. 'Ugrave': 722,
  25862. 'Delta': 612,
  25863. 'thorn': 611,
  25864. 'twosuperior': 333,
  25865. 'Odieresis': 778,
  25866. 'mu': 611,
  25867. 'igrave': 278,
  25868. 'ohungarumlaut': 611,
  25869. 'Eogonek': 667,
  25870. 'dcroat': 611,
  25871. 'threequarters': 834,
  25872. 'Scedilla': 667,
  25873. 'lcaron': 400,
  25874. 'Kcommaaccent': 722,
  25875. 'Lacute': 611,
  25876. 'trademark': 1000,
  25877. 'edotaccent': 556,
  25878. 'Igrave': 278,
  25879. 'Imacron': 278,
  25880. 'Lcaron': 611,
  25881. 'onehalf': 834,
  25882. 'lessequal': 549,
  25883. 'ocircumflex': 611,
  25884. 'ntilde': 611,
  25885. 'Uhungarumlaut': 722,
  25886. 'Eacute': 667,
  25887. 'emacron': 556,
  25888. 'gbreve': 611,
  25889. 'onequarter': 834,
  25890. 'Scaron': 667,
  25891. 'Scommaaccent': 667,
  25892. 'Ohungarumlaut': 778,
  25893. 'degree': 400,
  25894. 'ograve': 611,
  25895. 'Ccaron': 722,
  25896. 'ugrave': 611,
  25897. 'radical': 549,
  25898. 'Dcaron': 722,
  25899. 'rcommaaccent': 389,
  25900. 'Ntilde': 722,
  25901. 'otilde': 611,
  25902. 'Rcommaaccent': 722,
  25903. 'Lcommaaccent': 611,
  25904. 'Atilde': 722,
  25905. 'Aogonek': 722,
  25906. 'Aring': 722,
  25907. 'Otilde': 778,
  25908. 'zdotaccent': 500,
  25909. 'Ecaron': 667,
  25910. 'Iogonek': 278,
  25911. 'kcommaaccent': 556,
  25912. 'minus': 584,
  25913. 'Icircumflex': 278,
  25914. 'ncaron': 611,
  25915. 'tcommaaccent': 333,
  25916. 'logicalnot': 584,
  25917. 'odieresis': 611,
  25918. 'udieresis': 611,
  25919. 'notequal': 549,
  25920. 'gcommaaccent': 611,
  25921. 'eth': 611,
  25922. 'zcaron': 500,
  25923. 'ncommaaccent': 611,
  25924. 'onesuperior': 333,
  25925. 'imacron': 278,
  25926. 'Euro': 556
  25927. },
  25928. 'Helvetica-BoldOblique': {
  25929. 'space': 278,
  25930. 'exclam': 333,
  25931. 'quotedbl': 474,
  25932. 'numbersign': 556,
  25933. 'dollar': 556,
  25934. 'percent': 889,
  25935. 'ampersand': 722,
  25936. 'quoteright': 278,
  25937. 'parenleft': 333,
  25938. 'parenright': 333,
  25939. 'asterisk': 389,
  25940. 'plus': 584,
  25941. 'comma': 278,
  25942. 'hyphen': 333,
  25943. 'period': 278,
  25944. 'slash': 278,
  25945. 'zero': 556,
  25946. 'one': 556,
  25947. 'two': 556,
  25948. 'three': 556,
  25949. 'four': 556,
  25950. 'five': 556,
  25951. 'six': 556,
  25952. 'seven': 556,
  25953. 'eight': 556,
  25954. 'nine': 556,
  25955. 'colon': 333,
  25956. 'semicolon': 333,
  25957. 'less': 584,
  25958. 'equal': 584,
  25959. 'greater': 584,
  25960. 'question': 611,
  25961. 'at': 975,
  25962. 'A': 722,
  25963. 'B': 722,
  25964. 'C': 722,
  25965. 'D': 722,
  25966. 'E': 667,
  25967. 'F': 611,
  25968. 'G': 778,
  25969. 'H': 722,
  25970. 'I': 278,
  25971. 'J': 556,
  25972. 'K': 722,
  25973. 'L': 611,
  25974. 'M': 833,
  25975. 'N': 722,
  25976. 'O': 778,
  25977. 'P': 667,
  25978. 'Q': 778,
  25979. 'R': 722,
  25980. 'S': 667,
  25981. 'T': 611,
  25982. 'U': 722,
  25983. 'V': 667,
  25984. 'W': 944,
  25985. 'X': 667,
  25986. 'Y': 667,
  25987. 'Z': 611,
  25988. 'bracketleft': 333,
  25989. 'backslash': 278,
  25990. 'bracketright': 333,
  25991. 'asciicircum': 584,
  25992. 'underscore': 556,
  25993. 'quoteleft': 278,
  25994. 'a': 556,
  25995. 'b': 611,
  25996. 'c': 556,
  25997. 'd': 611,
  25998. 'e': 556,
  25999. 'f': 333,
  26000. 'g': 611,
  26001. 'h': 611,
  26002. 'i': 278,
  26003. 'j': 278,
  26004. 'k': 556,
  26005. 'l': 278,
  26006. 'm': 889,
  26007. 'n': 611,
  26008. 'o': 611,
  26009. 'p': 611,
  26010. 'q': 611,
  26011. 'r': 389,
  26012. 's': 556,
  26013. 't': 333,
  26014. 'u': 611,
  26015. 'v': 556,
  26016. 'w': 778,
  26017. 'x': 556,
  26018. 'y': 556,
  26019. 'z': 500,
  26020. 'braceleft': 389,
  26021. 'bar': 280,
  26022. 'braceright': 389,
  26023. 'asciitilde': 584,
  26024. 'exclamdown': 333,
  26025. 'cent': 556,
  26026. 'sterling': 556,
  26027. 'fraction': 167,
  26028. 'yen': 556,
  26029. 'florin': 556,
  26030. 'section': 556,
  26031. 'currency': 556,
  26032. 'quotesingle': 238,
  26033. 'quotedblleft': 500,
  26034. 'guillemotleft': 556,
  26035. 'guilsinglleft': 333,
  26036. 'guilsinglright': 333,
  26037. 'fi': 611,
  26038. 'fl': 611,
  26039. 'endash': 556,
  26040. 'dagger': 556,
  26041. 'daggerdbl': 556,
  26042. 'periodcentered': 278,
  26043. 'paragraph': 556,
  26044. 'bullet': 350,
  26045. 'quotesinglbase': 278,
  26046. 'quotedblbase': 500,
  26047. 'quotedblright': 500,
  26048. 'guillemotright': 556,
  26049. 'ellipsis': 1000,
  26050. 'perthousand': 1000,
  26051. 'questiondown': 611,
  26052. 'grave': 333,
  26053. 'acute': 333,
  26054. 'circumflex': 333,
  26055. 'tilde': 333,
  26056. 'macron': 333,
  26057. 'breve': 333,
  26058. 'dotaccent': 333,
  26059. 'dieresis': 333,
  26060. 'ring': 333,
  26061. 'cedilla': 333,
  26062. 'hungarumlaut': 333,
  26063. 'ogonek': 333,
  26064. 'caron': 333,
  26065. 'emdash': 1000,
  26066. 'AE': 1000,
  26067. 'ordfeminine': 370,
  26068. 'Lslash': 611,
  26069. 'Oslash': 778,
  26070. 'OE': 1000,
  26071. 'ordmasculine': 365,
  26072. 'ae': 889,
  26073. 'dotlessi': 278,
  26074. 'lslash': 278,
  26075. 'oslash': 611,
  26076. 'oe': 944,
  26077. 'germandbls': 611,
  26078. 'Idieresis': 278,
  26079. 'eacute': 556,
  26080. 'abreve': 556,
  26081. 'uhungarumlaut': 611,
  26082. 'ecaron': 556,
  26083. 'Ydieresis': 667,
  26084. 'divide': 584,
  26085. 'Yacute': 667,
  26086. 'Acircumflex': 722,
  26087. 'aacute': 556,
  26088. 'Ucircumflex': 722,
  26089. 'yacute': 556,
  26090. 'scommaaccent': 556,
  26091. 'ecircumflex': 556,
  26092. 'Uring': 722,
  26093. 'Udieresis': 722,
  26094. 'aogonek': 556,
  26095. 'Uacute': 722,
  26096. 'uogonek': 611,
  26097. 'Edieresis': 667,
  26098. 'Dcroat': 722,
  26099. 'commaaccent': 250,
  26100. 'copyright': 737,
  26101. 'Emacron': 667,
  26102. 'ccaron': 556,
  26103. 'aring': 556,
  26104. 'Ncommaaccent': 722,
  26105. 'lacute': 278,
  26106. 'agrave': 556,
  26107. 'Tcommaaccent': 611,
  26108. 'Cacute': 722,
  26109. 'atilde': 556,
  26110. 'Edotaccent': 667,
  26111. 'scaron': 556,
  26112. 'scedilla': 556,
  26113. 'iacute': 278,
  26114. 'lozenge': 494,
  26115. 'Rcaron': 722,
  26116. 'Gcommaaccent': 778,
  26117. 'ucircumflex': 611,
  26118. 'acircumflex': 556,
  26119. 'Amacron': 722,
  26120. 'rcaron': 389,
  26121. 'ccedilla': 556,
  26122. 'Zdotaccent': 611,
  26123. 'Thorn': 667,
  26124. 'Omacron': 778,
  26125. 'Racute': 722,
  26126. 'Sacute': 667,
  26127. 'dcaron': 743,
  26128. 'Umacron': 722,
  26129. 'uring': 611,
  26130. 'threesuperior': 333,
  26131. 'Ograve': 778,
  26132. 'Agrave': 722,
  26133. 'Abreve': 722,
  26134. 'multiply': 584,
  26135. 'uacute': 611,
  26136. 'Tcaron': 611,
  26137. 'partialdiff': 494,
  26138. 'ydieresis': 556,
  26139. 'Nacute': 722,
  26140. 'icircumflex': 278,
  26141. 'Ecircumflex': 667,
  26142. 'adieresis': 556,
  26143. 'edieresis': 556,
  26144. 'cacute': 556,
  26145. 'nacute': 611,
  26146. 'umacron': 611,
  26147. 'Ncaron': 722,
  26148. 'Iacute': 278,
  26149. 'plusminus': 584,
  26150. 'brokenbar': 280,
  26151. 'registered': 737,
  26152. 'Gbreve': 778,
  26153. 'Idotaccent': 278,
  26154. 'summation': 600,
  26155. 'Egrave': 667,
  26156. 'racute': 389,
  26157. 'omacron': 611,
  26158. 'Zacute': 611,
  26159. 'Zcaron': 611,
  26160. 'greaterequal': 549,
  26161. 'Eth': 722,
  26162. 'Ccedilla': 722,
  26163. 'lcommaaccent': 278,
  26164. 'tcaron': 389,
  26165. 'eogonek': 556,
  26166. 'Uogonek': 722,
  26167. 'Aacute': 722,
  26168. 'Adieresis': 722,
  26169. 'egrave': 556,
  26170. 'zacute': 500,
  26171. 'iogonek': 278,
  26172. 'Oacute': 778,
  26173. 'oacute': 611,
  26174. 'amacron': 556,
  26175. 'sacute': 556,
  26176. 'idieresis': 278,
  26177. 'Ocircumflex': 778,
  26178. 'Ugrave': 722,
  26179. 'Delta': 612,
  26180. 'thorn': 611,
  26181. 'twosuperior': 333,
  26182. 'Odieresis': 778,
  26183. 'mu': 611,
  26184. 'igrave': 278,
  26185. 'ohungarumlaut': 611,
  26186. 'Eogonek': 667,
  26187. 'dcroat': 611,
  26188. 'threequarters': 834,
  26189. 'Scedilla': 667,
  26190. 'lcaron': 400,
  26191. 'Kcommaaccent': 722,
  26192. 'Lacute': 611,
  26193. 'trademark': 1000,
  26194. 'edotaccent': 556,
  26195. 'Igrave': 278,
  26196. 'Imacron': 278,
  26197. 'Lcaron': 611,
  26198. 'onehalf': 834,
  26199. 'lessequal': 549,
  26200. 'ocircumflex': 611,
  26201. 'ntilde': 611,
  26202. 'Uhungarumlaut': 722,
  26203. 'Eacute': 667,
  26204. 'emacron': 556,
  26205. 'gbreve': 611,
  26206. 'onequarter': 834,
  26207. 'Scaron': 667,
  26208. 'Scommaaccent': 667,
  26209. 'Ohungarumlaut': 778,
  26210. 'degree': 400,
  26211. 'ograve': 611,
  26212. 'Ccaron': 722,
  26213. 'ugrave': 611,
  26214. 'radical': 549,
  26215. 'Dcaron': 722,
  26216. 'rcommaaccent': 389,
  26217. 'Ntilde': 722,
  26218. 'otilde': 611,
  26219. 'Rcommaaccent': 722,
  26220. 'Lcommaaccent': 611,
  26221. 'Atilde': 722,
  26222. 'Aogonek': 722,
  26223. 'Aring': 722,
  26224. 'Otilde': 778,
  26225. 'zdotaccent': 500,
  26226. 'Ecaron': 667,
  26227. 'Iogonek': 278,
  26228. 'kcommaaccent': 556,
  26229. 'minus': 584,
  26230. 'Icircumflex': 278,
  26231. 'ncaron': 611,
  26232. 'tcommaaccent': 333,
  26233. 'logicalnot': 584,
  26234. 'odieresis': 611,
  26235. 'udieresis': 611,
  26236. 'notequal': 549,
  26237. 'gcommaaccent': 611,
  26238. 'eth': 611,
  26239. 'zcaron': 500,
  26240. 'ncommaaccent': 611,
  26241. 'onesuperior': 333,
  26242. 'imacron': 278,
  26243. 'Euro': 556
  26244. },
  26245. 'Helvetica-Oblique' : {
  26246. 'space': 278,
  26247. 'exclam': 278,
  26248. 'quotedbl': 355,
  26249. 'numbersign': 556,
  26250. 'dollar': 556,
  26251. 'percent': 889,
  26252. 'ampersand': 667,
  26253. 'quoteright': 222,
  26254. 'parenleft': 333,
  26255. 'parenright': 333,
  26256. 'asterisk': 389,
  26257. 'plus': 584,
  26258. 'comma': 278,
  26259. 'hyphen': 333,
  26260. 'period': 278,
  26261. 'slash': 278,
  26262. 'zero': 556,
  26263. 'one': 556,
  26264. 'two': 556,
  26265. 'three': 556,
  26266. 'four': 556,
  26267. 'five': 556,
  26268. 'six': 556,
  26269. 'seven': 556,
  26270. 'eight': 556,
  26271. 'nine': 556,
  26272. 'colon': 278,
  26273. 'semicolon': 278,
  26274. 'less': 584,
  26275. 'equal': 584,
  26276. 'greater': 584,
  26277. 'question': 556,
  26278. 'at': 1015,
  26279. 'A': 667,
  26280. 'B': 667,
  26281. 'C': 722,
  26282. 'D': 722,
  26283. 'E': 667,
  26284. 'F': 611,
  26285. 'G': 778,
  26286. 'H': 722,
  26287. 'I': 278,
  26288. 'J': 500,
  26289. 'K': 667,
  26290. 'L': 556,
  26291. 'M': 833,
  26292. 'N': 722,
  26293. 'O': 778,
  26294. 'P': 667,
  26295. 'Q': 778,
  26296. 'R': 722,
  26297. 'S': 667,
  26298. 'T': 611,
  26299. 'U': 722,
  26300. 'V': 667,
  26301. 'W': 944,
  26302. 'X': 667,
  26303. 'Y': 667,
  26304. 'Z': 611,
  26305. 'bracketleft': 278,
  26306. 'backslash': 278,
  26307. 'bracketright': 278,
  26308. 'asciicircum': 469,
  26309. 'underscore': 556,
  26310. 'quoteleft': 222,
  26311. 'a': 556,
  26312. 'b': 556,
  26313. 'c': 500,
  26314. 'd': 556,
  26315. 'e': 556,
  26316. 'f': 278,
  26317. 'g': 556,
  26318. 'h': 556,
  26319. 'i': 222,
  26320. 'j': 222,
  26321. 'k': 500,
  26322. 'l': 222,
  26323. 'm': 833,
  26324. 'n': 556,
  26325. 'o': 556,
  26326. 'p': 556,
  26327. 'q': 556,
  26328. 'r': 333,
  26329. 's': 500,
  26330. 't': 278,
  26331. 'u': 556,
  26332. 'v': 500,
  26333. 'w': 722,
  26334. 'x': 500,
  26335. 'y': 500,
  26336. 'z': 500,
  26337. 'braceleft': 334,
  26338. 'bar': 260,
  26339. 'braceright': 334,
  26340. 'asciitilde': 584,
  26341. 'exclamdown': 333,
  26342. 'cent': 556,
  26343. 'sterling': 556,
  26344. 'fraction': 167,
  26345. 'yen': 556,
  26346. 'florin': 556,
  26347. 'section': 556,
  26348. 'currency': 556,
  26349. 'quotesingle': 191,
  26350. 'quotedblleft': 333,
  26351. 'guillemotleft': 556,
  26352. 'guilsinglleft': 333,
  26353. 'guilsinglright': 333,
  26354. 'fi': 500,
  26355. 'fl': 500,
  26356. 'endash': 556,
  26357. 'dagger': 556,
  26358. 'daggerdbl': 556,
  26359. 'periodcentered': 278,
  26360. 'paragraph': 537,
  26361. 'bullet': 350,
  26362. 'quotesinglbase': 222,
  26363. 'quotedblbase': 333,
  26364. 'quotedblright': 333,
  26365. 'guillemotright': 556,
  26366. 'ellipsis': 1000,
  26367. 'perthousand': 1000,
  26368. 'questiondown': 611,
  26369. 'grave': 333,
  26370. 'acute': 333,
  26371. 'circumflex': 333,
  26372. 'tilde': 333,
  26373. 'macron': 333,
  26374. 'breve': 333,
  26375. 'dotaccent': 333,
  26376. 'dieresis': 333,
  26377. 'ring': 333,
  26378. 'cedilla': 333,
  26379. 'hungarumlaut': 333,
  26380. 'ogonek': 333,
  26381. 'caron': 333,
  26382. 'emdash': 1000,
  26383. 'AE': 1000,
  26384. 'ordfeminine': 370,
  26385. 'Lslash': 556,
  26386. 'Oslash': 778,
  26387. 'OE': 1000,
  26388. 'ordmasculine': 365,
  26389. 'ae': 889,
  26390. 'dotlessi': 278,
  26391. 'lslash': 222,
  26392. 'oslash': 611,
  26393. 'oe': 944,
  26394. 'germandbls': 611,
  26395. 'Idieresis': 278,
  26396. 'eacute': 556,
  26397. 'abreve': 556,
  26398. 'uhungarumlaut': 556,
  26399. 'ecaron': 556,
  26400. 'Ydieresis': 667,
  26401. 'divide': 584,
  26402. 'Yacute': 667,
  26403. 'Acircumflex': 667,
  26404. 'aacute': 556,
  26405. 'Ucircumflex': 722,
  26406. 'yacute': 500,
  26407. 'scommaaccent': 500,
  26408. 'ecircumflex': 556,
  26409. 'Uring': 722,
  26410. 'Udieresis': 722,
  26411. 'aogonek': 556,
  26412. 'Uacute': 722,
  26413. 'uogonek': 556,
  26414. 'Edieresis': 667,
  26415. 'Dcroat': 722,
  26416. 'commaaccent': 250,
  26417. 'copyright': 737,
  26418. 'Emacron': 667,
  26419. 'ccaron': 500,
  26420. 'aring': 556,
  26421. 'Ncommaaccent': 722,
  26422. 'lacute': 222,
  26423. 'agrave': 556,
  26424. 'Tcommaaccent': 611,
  26425. 'Cacute': 722,
  26426. 'atilde': 556,
  26427. 'Edotaccent': 667,
  26428. 'scaron': 500,
  26429. 'scedilla': 500,
  26430. 'iacute': 278,
  26431. 'lozenge': 471,
  26432. 'Rcaron': 722,
  26433. 'Gcommaaccent': 778,
  26434. 'ucircumflex': 556,
  26435. 'acircumflex': 556,
  26436. 'Amacron': 667,
  26437. 'rcaron': 333,
  26438. 'ccedilla': 500,
  26439. 'Zdotaccent': 611,
  26440. 'Thorn': 667,
  26441. 'Omacron': 778,
  26442. 'Racute': 722,
  26443. 'Sacute': 667,
  26444. 'dcaron': 643,
  26445. 'Umacron': 722,
  26446. 'uring': 556,
  26447. 'threesuperior': 333,
  26448. 'Ograve': 778,
  26449. 'Agrave': 667,
  26450. 'Abreve': 667,
  26451. 'multiply': 584,
  26452. 'uacute': 556,
  26453. 'Tcaron': 611,
  26454. 'partialdiff': 476,
  26455. 'ydieresis': 500,
  26456. 'Nacute': 722,
  26457. 'icircumflex': 278,
  26458. 'Ecircumflex': 667,
  26459. 'adieresis': 556,
  26460. 'edieresis': 556,
  26461. 'cacute': 500,
  26462. 'nacute': 556,
  26463. 'umacron': 556,
  26464. 'Ncaron': 722,
  26465. 'Iacute': 278,
  26466. 'plusminus': 584,
  26467. 'brokenbar': 260,
  26468. 'registered': 737,
  26469. 'Gbreve': 778,
  26470. 'Idotaccent': 278,
  26471. 'summation': 600,
  26472. 'Egrave': 667,
  26473. 'racute': 333,
  26474. 'omacron': 556,
  26475. 'Zacute': 611,
  26476. 'Zcaron': 611,
  26477. 'greaterequal': 549,
  26478. 'Eth': 722,
  26479. 'Ccedilla': 722,
  26480. 'lcommaaccent': 222,
  26481. 'tcaron': 317,
  26482. 'eogonek': 556,
  26483. 'Uogonek': 722,
  26484. 'Aacute': 667,
  26485. 'Adieresis': 667,
  26486. 'egrave': 556,
  26487. 'zacute': 500,
  26488. 'iogonek': 222,
  26489. 'Oacute': 778,
  26490. 'oacute': 556,
  26491. 'amacron': 556,
  26492. 'sacute': 500,
  26493. 'idieresis': 278,
  26494. 'Ocircumflex': 778,
  26495. 'Ugrave': 722,
  26496. 'Delta': 612,
  26497. 'thorn': 556,
  26498. 'twosuperior': 333,
  26499. 'Odieresis': 778,
  26500. 'mu': 556,
  26501. 'igrave': 278,
  26502. 'ohungarumlaut': 556,
  26503. 'Eogonek': 667,
  26504. 'dcroat': 556,
  26505. 'threequarters': 834,
  26506. 'Scedilla': 667,
  26507. 'lcaron': 299,
  26508. 'Kcommaaccent': 667,
  26509. 'Lacute': 556,
  26510. 'trademark': 1000,
  26511. 'edotaccent': 556,
  26512. 'Igrave': 278,
  26513. 'Imacron': 278,
  26514. 'Lcaron': 556,
  26515. 'onehalf': 834,
  26516. 'lessequal': 549,
  26517. 'ocircumflex': 556,
  26518. 'ntilde': 556,
  26519. 'Uhungarumlaut': 722,
  26520. 'Eacute': 667,
  26521. 'emacron': 556,
  26522. 'gbreve': 556,
  26523. 'onequarter': 834,
  26524. 'Scaron': 667,
  26525. 'Scommaaccent': 667,
  26526. 'Ohungarumlaut': 778,
  26527. 'degree': 400,
  26528. 'ograve': 556,
  26529. 'Ccaron': 722,
  26530. 'ugrave': 556,
  26531. 'radical': 453,
  26532. 'Dcaron': 722,
  26533. 'rcommaaccent': 333,
  26534. 'Ntilde': 722,
  26535. 'otilde': 556,
  26536. 'Rcommaaccent': 722,
  26537. 'Lcommaaccent': 556,
  26538. 'Atilde': 667,
  26539. 'Aogonek': 667,
  26540. 'Aring': 667,
  26541. 'Otilde': 778,
  26542. 'zdotaccent': 500,
  26543. 'Ecaron': 667,
  26544. 'Iogonek': 278,
  26545. 'kcommaaccent': 500,
  26546. 'minus': 584,
  26547. 'Icircumflex': 278,
  26548. 'ncaron': 556,
  26549. 'tcommaaccent': 278,
  26550. 'logicalnot': 584,
  26551. 'odieresis': 556,
  26552. 'udieresis': 556,
  26553. 'notequal': 549,
  26554. 'gcommaaccent': 556,
  26555. 'eth': 556,
  26556. 'zcaron': 500,
  26557. 'ncommaaccent': 556,
  26558. 'onesuperior': 333,
  26559. 'imacron': 278,
  26560. 'Euro': 556
  26561. },
  26562. 'Symbol': {
  26563. 'space': 250,
  26564. 'exclam': 333,
  26565. 'universal': 713,
  26566. 'numbersign': 500,
  26567. 'existential': 549,
  26568. 'percent': 833,
  26569. 'ampersand': 778,
  26570. 'suchthat': 439,
  26571. 'parenleft': 333,
  26572. 'parenright': 333,
  26573. 'asteriskmath': 500,
  26574. 'plus': 549,
  26575. 'comma': 250,
  26576. 'minus': 549,
  26577. 'period': 250,
  26578. 'slash': 278,
  26579. 'zero': 500,
  26580. 'one': 500,
  26581. 'two': 500,
  26582. 'three': 500,
  26583. 'four': 500,
  26584. 'five': 500,
  26585. 'six': 500,
  26586. 'seven': 500,
  26587. 'eight': 500,
  26588. 'nine': 500,
  26589. 'colon': 278,
  26590. 'semicolon': 278,
  26591. 'less': 549,
  26592. 'equal': 549,
  26593. 'greater': 549,
  26594. 'question': 444,
  26595. 'congruent': 549,
  26596. 'Alpha': 722,
  26597. 'Beta': 667,
  26598. 'Chi': 722,
  26599. 'Delta': 612,
  26600. 'Epsilon': 611,
  26601. 'Phi': 763,
  26602. 'Gamma': 603,
  26603. 'Eta': 722,
  26604. 'Iota': 333,
  26605. 'theta1': 631,
  26606. 'Kappa': 722,
  26607. 'Lambda': 686,
  26608. 'Mu': 889,
  26609. 'Nu': 722,
  26610. 'Omicron': 722,
  26611. 'Pi': 768,
  26612. 'Theta': 741,
  26613. 'Rho': 556,
  26614. 'Sigma': 592,
  26615. 'Tau': 611,
  26616. 'Upsilon': 690,
  26617. 'sigma1': 439,
  26618. 'Omega': 768,
  26619. 'Xi': 645,
  26620. 'Psi': 795,
  26621. 'Zeta': 611,
  26622. 'bracketleft': 333,
  26623. 'therefore': 863,
  26624. 'bracketright': 333,
  26625. 'perpendicular': 658,
  26626. 'underscore': 500,
  26627. 'radicalex': 500,
  26628. 'alpha': 631,
  26629. 'beta': 549,
  26630. 'chi': 549,
  26631. 'delta': 494,
  26632. 'epsilon': 439,
  26633. 'phi': 521,
  26634. 'gamma': 411,
  26635. 'eta': 603,
  26636. 'iota': 329,
  26637. 'phi1': 603,
  26638. 'kappa': 549,
  26639. 'lambda': 549,
  26640. 'mu': 576,
  26641. 'nu': 521,
  26642. 'omicron': 549,
  26643. 'pi': 549,
  26644. 'theta': 521,
  26645. 'rho': 549,
  26646. 'sigma': 603,
  26647. 'tau': 439,
  26648. 'upsilon': 576,
  26649. 'omega1': 713,
  26650. 'omega': 686,
  26651. 'xi': 493,
  26652. 'psi': 686,
  26653. 'zeta': 494,
  26654. 'braceleft': 480,
  26655. 'bar': 200,
  26656. 'braceright': 480,
  26657. 'similar': 549,
  26658. 'Euro': 750,
  26659. 'Upsilon1': 620,
  26660. 'minute': 247,
  26661. 'lessequal': 549,
  26662. 'fraction': 167,
  26663. 'infinity': 713,
  26664. 'florin': 500,
  26665. 'club': 753,
  26666. 'diamond': 753,
  26667. 'heart': 753,
  26668. 'spade': 753,
  26669. 'arrowboth': 1042,
  26670. 'arrowleft': 987,
  26671. 'arrowup': 603,
  26672. 'arrowright': 987,
  26673. 'arrowdown': 603,
  26674. 'degree': 400,
  26675. 'plusminus': 549,
  26676. 'second': 411,
  26677. 'greaterequal': 549,
  26678. 'multiply': 549,
  26679. 'proportional': 713,
  26680. 'partialdiff': 494,
  26681. 'bullet': 460,
  26682. 'divide': 549,
  26683. 'notequal': 549,
  26684. 'equivalence': 549,
  26685. 'approxequal': 549,
  26686. 'ellipsis': 1000,
  26687. 'arrowvertex': 603,
  26688. 'arrowhorizex': 1000,
  26689. 'carriagereturn': 658,
  26690. 'aleph': 823,
  26691. 'Ifraktur': 686,
  26692. 'Rfraktur': 795,
  26693. 'weierstrass': 987,
  26694. 'circlemultiply': 768,
  26695. 'circleplus': 768,
  26696. 'emptyset': 823,
  26697. 'intersection': 768,
  26698. 'union': 768,
  26699. 'propersuperset': 713,
  26700. 'reflexsuperset': 713,
  26701. 'notsubset': 713,
  26702. 'propersubset': 713,
  26703. 'reflexsubset': 713,
  26704. 'element': 713,
  26705. 'notelement': 713,
  26706. 'angle': 768,
  26707. 'gradient': 713,
  26708. 'registerserif': 790,
  26709. 'copyrightserif': 790,
  26710. 'trademarkserif': 890,
  26711. 'product': 823,
  26712. 'radical': 549,
  26713. 'dotmath': 250,
  26714. 'logicalnot': 713,
  26715. 'logicaland': 603,
  26716. 'logicalor': 603,
  26717. 'arrowdblboth': 1042,
  26718. 'arrowdblleft': 987,
  26719. 'arrowdblup': 603,
  26720. 'arrowdblright': 987,
  26721. 'arrowdbldown': 603,
  26722. 'lozenge': 494,
  26723. 'angleleft': 329,
  26724. 'registersans': 790,
  26725. 'copyrightsans': 790,
  26726. 'trademarksans': 786,
  26727. 'summation': 713,
  26728. 'parenlefttp': 384,
  26729. 'parenleftex': 384,
  26730. 'parenleftbt': 384,
  26731. 'bracketlefttp': 384,
  26732. 'bracketleftex': 384,
  26733. 'bracketleftbt': 384,
  26734. 'bracelefttp': 494,
  26735. 'braceleftmid': 494,
  26736. 'braceleftbt': 494,
  26737. 'braceex': 494,
  26738. 'angleright': 329,
  26739. 'integral': 274,
  26740. 'integraltp': 686,
  26741. 'integralex': 686,
  26742. 'integralbt': 686,
  26743. 'parenrighttp': 384,
  26744. 'parenrightex': 384,
  26745. 'parenrightbt': 384,
  26746. 'bracketrighttp': 384,
  26747. 'bracketrightex': 384,
  26748. 'bracketrightbt': 384,
  26749. 'bracerighttp': 494,
  26750. 'bracerightmid': 494,
  26751. 'bracerightbt': 494,
  26752. 'apple': 790
  26753. },
  26754. 'Times-Roman': {
  26755. 'space': 250,
  26756. 'exclam': 333,
  26757. 'quotedbl': 408,
  26758. 'numbersign': 500,
  26759. 'dollar': 500,
  26760. 'percent': 833,
  26761. 'ampersand': 778,
  26762. 'quoteright': 333,
  26763. 'parenleft': 333,
  26764. 'parenright': 333,
  26765. 'asterisk': 500,
  26766. 'plus': 564,
  26767. 'comma': 250,
  26768. 'hyphen': 333,
  26769. 'period': 250,
  26770. 'slash': 278,
  26771. 'zero': 500,
  26772. 'one': 500,
  26773. 'two': 500,
  26774. 'three': 500,
  26775. 'four': 500,
  26776. 'five': 500,
  26777. 'six': 500,
  26778. 'seven': 500,
  26779. 'eight': 500,
  26780. 'nine': 500,
  26781. 'colon': 278,
  26782. 'semicolon': 278,
  26783. 'less': 564,
  26784. 'equal': 564,
  26785. 'greater': 564,
  26786. 'question': 444,
  26787. 'at': 921,
  26788. 'A': 722,
  26789. 'B': 667,
  26790. 'C': 667,
  26791. 'D': 722,
  26792. 'E': 611,
  26793. 'F': 556,
  26794. 'G': 722,
  26795. 'H': 722,
  26796. 'I': 333,
  26797. 'J': 389,
  26798. 'K': 722,
  26799. 'L': 611,
  26800. 'M': 889,
  26801. 'N': 722,
  26802. 'O': 722,
  26803. 'P': 556,
  26804. 'Q': 722,
  26805. 'R': 667,
  26806. 'S': 556,
  26807. 'T': 611,
  26808. 'U': 722,
  26809. 'V': 722,
  26810. 'W': 944,
  26811. 'X': 722,
  26812. 'Y': 722,
  26813. 'Z': 611,
  26814. 'bracketleft': 333,
  26815. 'backslash': 278,
  26816. 'bracketright': 333,
  26817. 'asciicircum': 469,
  26818. 'underscore': 500,
  26819. 'quoteleft': 333,
  26820. 'a': 444,
  26821. 'b': 500,
  26822. 'c': 444,
  26823. 'd': 500,
  26824. 'e': 444,
  26825. 'f': 333,
  26826. 'g': 500,
  26827. 'h': 500,
  26828. 'i': 278,
  26829. 'j': 278,
  26830. 'k': 500,
  26831. 'l': 278,
  26832. 'm': 778,
  26833. 'n': 500,
  26834. 'o': 500,
  26835. 'p': 500,
  26836. 'q': 500,
  26837. 'r': 333,
  26838. 's': 389,
  26839. 't': 278,
  26840. 'u': 500,
  26841. 'v': 500,
  26842. 'w': 722,
  26843. 'x': 500,
  26844. 'y': 500,
  26845. 'z': 444,
  26846. 'braceleft': 480,
  26847. 'bar': 200,
  26848. 'braceright': 480,
  26849. 'asciitilde': 541,
  26850. 'exclamdown': 333,
  26851. 'cent': 500,
  26852. 'sterling': 500,
  26853. 'fraction': 167,
  26854. 'yen': 500,
  26855. 'florin': 500,
  26856. 'section': 500,
  26857. 'currency': 500,
  26858. 'quotesingle': 180,
  26859. 'quotedblleft': 444,
  26860. 'guillemotleft': 500,
  26861. 'guilsinglleft': 333,
  26862. 'guilsinglright': 333,
  26863. 'fi': 556,
  26864. 'fl': 556,
  26865. 'endash': 500,
  26866. 'dagger': 500,
  26867. 'daggerdbl': 500,
  26868. 'periodcentered': 250,
  26869. 'paragraph': 453,
  26870. 'bullet': 350,
  26871. 'quotesinglbase': 333,
  26872. 'quotedblbase': 444,
  26873. 'quotedblright': 444,
  26874. 'guillemotright': 500,
  26875. 'ellipsis': 1000,
  26876. 'perthousand': 1000,
  26877. 'questiondown': 444,
  26878. 'grave': 333,
  26879. 'acute': 333,
  26880. 'circumflex': 333,
  26881. 'tilde': 333,
  26882. 'macron': 333,
  26883. 'breve': 333,
  26884. 'dotaccent': 333,
  26885. 'dieresis': 333,
  26886. 'ring': 333,
  26887. 'cedilla': 333,
  26888. 'hungarumlaut': 333,
  26889. 'ogonek': 333,
  26890. 'caron': 333,
  26891. 'emdash': 1000,
  26892. 'AE': 889,
  26893. 'ordfeminine': 276,
  26894. 'Lslash': 611,
  26895. 'Oslash': 722,
  26896. 'OE': 889,
  26897. 'ordmasculine': 310,
  26898. 'ae': 667,
  26899. 'dotlessi': 278,
  26900. 'lslash': 278,
  26901. 'oslash': 500,
  26902. 'oe': 722,
  26903. 'germandbls': 500,
  26904. 'Idieresis': 333,
  26905. 'eacute': 444,
  26906. 'abreve': 444,
  26907. 'uhungarumlaut': 500,
  26908. 'ecaron': 444,
  26909. 'Ydieresis': 722,
  26910. 'divide': 564,
  26911. 'Yacute': 722,
  26912. 'Acircumflex': 722,
  26913. 'aacute': 444,
  26914. 'Ucircumflex': 722,
  26915. 'yacute': 500,
  26916. 'scommaaccent': 389,
  26917. 'ecircumflex': 444,
  26918. 'Uring': 722,
  26919. 'Udieresis': 722,
  26920. 'aogonek': 444,
  26921. 'Uacute': 722,
  26922. 'uogonek': 500,
  26923. 'Edieresis': 611,
  26924. 'Dcroat': 722,
  26925. 'commaaccent': 250,
  26926. 'copyright': 760,
  26927. 'Emacron': 611,
  26928. 'ccaron': 444,
  26929. 'aring': 444,
  26930. 'Ncommaaccent': 722,
  26931. 'lacute': 278,
  26932. 'agrave': 444,
  26933. 'Tcommaaccent': 611,
  26934. 'Cacute': 667,
  26935. 'atilde': 444,
  26936. 'Edotaccent': 611,
  26937. 'scaron': 389,
  26938. 'scedilla': 389,
  26939. 'iacute': 278,
  26940. 'lozenge': 471,
  26941. 'Rcaron': 667,
  26942. 'Gcommaaccent': 722,
  26943. 'ucircumflex': 500,
  26944. 'acircumflex': 444,
  26945. 'Amacron': 722,
  26946. 'rcaron': 333,
  26947. 'ccedilla': 444,
  26948. 'Zdotaccent': 611,
  26949. 'Thorn': 556,
  26950. 'Omacron': 722,
  26951. 'Racute': 667,
  26952. 'Sacute': 556,
  26953. 'dcaron': 588,
  26954. 'Umacron': 722,
  26955. 'uring': 500,
  26956. 'threesuperior': 300,
  26957. 'Ograve': 722,
  26958. 'Agrave': 722,
  26959. 'Abreve': 722,
  26960. 'multiply': 564,
  26961. 'uacute': 500,
  26962. 'Tcaron': 611,
  26963. 'partialdiff': 476,
  26964. 'ydieresis': 500,
  26965. 'Nacute': 722,
  26966. 'icircumflex': 278,
  26967. 'Ecircumflex': 611,
  26968. 'adieresis': 444,
  26969. 'edieresis': 444,
  26970. 'cacute': 444,
  26971. 'nacute': 500,
  26972. 'umacron': 500,
  26973. 'Ncaron': 722,
  26974. 'Iacute': 333,
  26975. 'plusminus': 564,
  26976. 'brokenbar': 200,
  26977. 'registered': 760,
  26978. 'Gbreve': 722,
  26979. 'Idotaccent': 333,
  26980. 'summation': 600,
  26981. 'Egrave': 611,
  26982. 'racute': 333,
  26983. 'omacron': 500,
  26984. 'Zacute': 611,
  26985. 'Zcaron': 611,
  26986. 'greaterequal': 549,
  26987. 'Eth': 722,
  26988. 'Ccedilla': 667,
  26989. 'lcommaaccent': 278,
  26990. 'tcaron': 326,
  26991. 'eogonek': 444,
  26992. 'Uogonek': 722,
  26993. 'Aacute': 722,
  26994. 'Adieresis': 722,
  26995. 'egrave': 444,
  26996. 'zacute': 444,
  26997. 'iogonek': 278,
  26998. 'Oacute': 722,
  26999. 'oacute': 500,
  27000. 'amacron': 444,
  27001. 'sacute': 389,
  27002. 'idieresis': 278,
  27003. 'Ocircumflex': 722,
  27004. 'Ugrave': 722,
  27005. 'Delta': 612,
  27006. 'thorn': 500,
  27007. 'twosuperior': 300,
  27008. 'Odieresis': 722,
  27009. 'mu': 500,
  27010. 'igrave': 278,
  27011. 'ohungarumlaut': 500,
  27012. 'Eogonek': 611,
  27013. 'dcroat': 500,
  27014. 'threequarters': 750,
  27015. 'Scedilla': 556,
  27016. 'lcaron': 344,
  27017. 'Kcommaaccent': 722,
  27018. 'Lacute': 611,
  27019. 'trademark': 980,
  27020. 'edotaccent': 444,
  27021. 'Igrave': 333,
  27022. 'Imacron': 333,
  27023. 'Lcaron': 611,
  27024. 'onehalf': 750,
  27025. 'lessequal': 549,
  27026. 'ocircumflex': 500,
  27027. 'ntilde': 500,
  27028. 'Uhungarumlaut': 722,
  27029. 'Eacute': 611,
  27030. 'emacron': 444,
  27031. 'gbreve': 500,
  27032. 'onequarter': 750,
  27033. 'Scaron': 556,
  27034. 'Scommaaccent': 556,
  27035. 'Ohungarumlaut': 722,
  27036. 'degree': 400,
  27037. 'ograve': 500,
  27038. 'Ccaron': 667,
  27039. 'ugrave': 500,
  27040. 'radical': 453,
  27041. 'Dcaron': 722,
  27042. 'rcommaaccent': 333,
  27043. 'Ntilde': 722,
  27044. 'otilde': 500,
  27045. 'Rcommaaccent': 667,
  27046. 'Lcommaaccent': 611,
  27047. 'Atilde': 722,
  27048. 'Aogonek': 722,
  27049. 'Aring': 722,
  27050. 'Otilde': 722,
  27051. 'zdotaccent': 444,
  27052. 'Ecaron': 611,
  27053. 'Iogonek': 333,
  27054. 'kcommaaccent': 500,
  27055. 'minus': 564,
  27056. 'Icircumflex': 333,
  27057. 'ncaron': 500,
  27058. 'tcommaaccent': 278,
  27059. 'logicalnot': 564,
  27060. 'odieresis': 500,
  27061. 'udieresis': 500,
  27062. 'notequal': 549,
  27063. 'gcommaaccent': 500,
  27064. 'eth': 500,
  27065. 'zcaron': 444,
  27066. 'ncommaaccent': 500,
  27067. 'onesuperior': 300,
  27068. 'imacron': 278,
  27069. 'Euro': 500
  27070. },
  27071. 'Times-Bold': {
  27072. 'space': 250,
  27073. 'exclam': 333,
  27074. 'quotedbl': 555,
  27075. 'numbersign': 500,
  27076. 'dollar': 500,
  27077. 'percent': 1000,
  27078. 'ampersand': 833,
  27079. 'quoteright': 333,
  27080. 'parenleft': 333,
  27081. 'parenright': 333,
  27082. 'asterisk': 500,
  27083. 'plus': 570,
  27084. 'comma': 250,
  27085. 'hyphen': 333,
  27086. 'period': 250,
  27087. 'slash': 278,
  27088. 'zero': 500,
  27089. 'one': 500,
  27090. 'two': 500,
  27091. 'three': 500,
  27092. 'four': 500,
  27093. 'five': 500,
  27094. 'six': 500,
  27095. 'seven': 500,
  27096. 'eight': 500,
  27097. 'nine': 500,
  27098. 'colon': 333,
  27099. 'semicolon': 333,
  27100. 'less': 570,
  27101. 'equal': 570,
  27102. 'greater': 570,
  27103. 'question': 500,
  27104. 'at': 930,
  27105. 'A': 722,
  27106. 'B': 667,
  27107. 'C': 722,
  27108. 'D': 722,
  27109. 'E': 667,
  27110. 'F': 611,
  27111. 'G': 778,
  27112. 'H': 778,
  27113. 'I': 389,
  27114. 'J': 500,
  27115. 'K': 778,
  27116. 'L': 667,
  27117. 'M': 944,
  27118. 'N': 722,
  27119. 'O': 778,
  27120. 'P': 611,
  27121. 'Q': 778,
  27122. 'R': 722,
  27123. 'S': 556,
  27124. 'T': 667,
  27125. 'U': 722,
  27126. 'V': 722,
  27127. 'W': 1000,
  27128. 'X': 722,
  27129. 'Y': 722,
  27130. 'Z': 667,
  27131. 'bracketleft': 333,
  27132. 'backslash': 278,
  27133. 'bracketright': 333,
  27134. 'asciicircum': 581,
  27135. 'underscore': 500,
  27136. 'quoteleft': 333,
  27137. 'a': 500,
  27138. 'b': 556,
  27139. 'c': 444,
  27140. 'd': 556,
  27141. 'e': 444,
  27142. 'f': 333,
  27143. 'g': 500,
  27144. 'h': 556,
  27145. 'i': 278,
  27146. 'j': 333,
  27147. 'k': 556,
  27148. 'l': 278,
  27149. 'm': 833,
  27150. 'n': 556,
  27151. 'o': 500,
  27152. 'p': 556,
  27153. 'q': 556,
  27154. 'r': 444,
  27155. 's': 389,
  27156. 't': 333,
  27157. 'u': 556,
  27158. 'v': 500,
  27159. 'w': 722,
  27160. 'x': 500,
  27161. 'y': 500,
  27162. 'z': 444,
  27163. 'braceleft': 394,
  27164. 'bar': 220,
  27165. 'braceright': 394,
  27166. 'asciitilde': 520,
  27167. 'exclamdown': 333,
  27168. 'cent': 500,
  27169. 'sterling': 500,
  27170. 'fraction': 167,
  27171. 'yen': 500,
  27172. 'florin': 500,
  27173. 'section': 500,
  27174. 'currency': 500,
  27175. 'quotesingle': 278,
  27176. 'quotedblleft': 500,
  27177. 'guillemotleft': 500,
  27178. 'guilsinglleft': 333,
  27179. 'guilsinglright': 333,
  27180. 'fi': 556,
  27181. 'fl': 556,
  27182. 'endash': 500,
  27183. 'dagger': 500,
  27184. 'daggerdbl': 500,
  27185. 'periodcentered': 250,
  27186. 'paragraph': 540,
  27187. 'bullet': 350,
  27188. 'quotesinglbase': 333,
  27189. 'quotedblbase': 500,
  27190. 'quotedblright': 500,
  27191. 'guillemotright': 500,
  27192. 'ellipsis': 1000,
  27193. 'perthousand': 1000,
  27194. 'questiondown': 500,
  27195. 'grave': 333,
  27196. 'acute': 333,
  27197. 'circumflex': 333,
  27198. 'tilde': 333,
  27199. 'macron': 333,
  27200. 'breve': 333,
  27201. 'dotaccent': 333,
  27202. 'dieresis': 333,
  27203. 'ring': 333,
  27204. 'cedilla': 333,
  27205. 'hungarumlaut': 333,
  27206. 'ogonek': 333,
  27207. 'caron': 333,
  27208. 'emdash': 1000,
  27209. 'AE': 1000,
  27210. 'ordfeminine': 300,
  27211. 'Lslash': 667,
  27212. 'Oslash': 778,
  27213. 'OE': 1000,
  27214. 'ordmasculine': 330,
  27215. 'ae': 722,
  27216. 'dotlessi': 278,
  27217. 'lslash': 278,
  27218. 'oslash': 500,
  27219. 'oe': 722,
  27220. 'germandbls': 556,
  27221. 'Idieresis': 389,
  27222. 'eacute': 444,
  27223. 'abreve': 500,
  27224. 'uhungarumlaut': 556,
  27225. 'ecaron': 444,
  27226. 'Ydieresis': 722,
  27227. 'divide': 570,
  27228. 'Yacute': 722,
  27229. 'Acircumflex': 722,
  27230. 'aacute': 500,
  27231. 'Ucircumflex': 722,
  27232. 'yacute': 500,
  27233. 'scommaaccent': 389,
  27234. 'ecircumflex': 444,
  27235. 'Uring': 722,
  27236. 'Udieresis': 722,
  27237. 'aogonek': 500,
  27238. 'Uacute': 722,
  27239. 'uogonek': 556,
  27240. 'Edieresis': 667,
  27241. 'Dcroat': 722,
  27242. 'commaaccent': 250,
  27243. 'copyright': 747,
  27244. 'Emacron': 667,
  27245. 'ccaron': 444,
  27246. 'aring': 500,
  27247. 'Ncommaaccent': 722,
  27248. 'lacute': 278,
  27249. 'agrave': 500,
  27250. 'Tcommaaccent': 667,
  27251. 'Cacute': 722,
  27252. 'atilde': 500,
  27253. 'Edotaccent': 667,
  27254. 'scaron': 389,
  27255. 'scedilla': 389,
  27256. 'iacute': 278,
  27257. 'lozenge': 494,
  27258. 'Rcaron': 722,
  27259. 'Gcommaaccent': 778,
  27260. 'ucircumflex': 556,
  27261. 'acircumflex': 500,
  27262. 'Amacron': 722,
  27263. 'rcaron': 444,
  27264. 'ccedilla': 444,
  27265. 'Zdotaccent': 667,
  27266. 'Thorn': 611,
  27267. 'Omacron': 778,
  27268. 'Racute': 722,
  27269. 'Sacute': 556,
  27270. 'dcaron': 672,
  27271. 'Umacron': 722,
  27272. 'uring': 556,
  27273. 'threesuperior': 300,
  27274. 'Ograve': 778,
  27275. 'Agrave': 722,
  27276. 'Abreve': 722,
  27277. 'multiply': 570,
  27278. 'uacute': 556,
  27279. 'Tcaron': 667,
  27280. 'partialdiff': 494,
  27281. 'ydieresis': 500,
  27282. 'Nacute': 722,
  27283. 'icircumflex': 278,
  27284. 'Ecircumflex': 667,
  27285. 'adieresis': 500,
  27286. 'edieresis': 444,
  27287. 'cacute': 444,
  27288. 'nacute': 556,
  27289. 'umacron': 556,
  27290. 'Ncaron': 722,
  27291. 'Iacute': 389,
  27292. 'plusminus': 570,
  27293. 'brokenbar': 220,
  27294. 'registered': 747,
  27295. 'Gbreve': 778,
  27296. 'Idotaccent': 389,
  27297. 'summation': 600,
  27298. 'Egrave': 667,
  27299. 'racute': 444,
  27300. 'omacron': 500,
  27301. 'Zacute': 667,
  27302. 'Zcaron': 667,
  27303. 'greaterequal': 549,
  27304. 'Eth': 722,
  27305. 'Ccedilla': 722,
  27306. 'lcommaaccent': 278,
  27307. 'tcaron': 416,
  27308. 'eogonek': 444,
  27309. 'Uogonek': 722,
  27310. 'Aacute': 722,
  27311. 'Adieresis': 722,
  27312. 'egrave': 444,
  27313. 'zacute': 444,
  27314. 'iogonek': 278,
  27315. 'Oacute': 778,
  27316. 'oacute': 500,
  27317. 'amacron': 500,
  27318. 'sacute': 389,
  27319. 'idieresis': 278,
  27320. 'Ocircumflex': 778,
  27321. 'Ugrave': 722,
  27322. 'Delta': 612,
  27323. 'thorn': 556,
  27324. 'twosuperior': 300,
  27325. 'Odieresis': 778,
  27326. 'mu': 556,
  27327. 'igrave': 278,
  27328. 'ohungarumlaut': 500,
  27329. 'Eogonek': 667,
  27330. 'dcroat': 556,
  27331. 'threequarters': 750,
  27332. 'Scedilla': 556,
  27333. 'lcaron': 394,
  27334. 'Kcommaaccent': 778,
  27335. 'Lacute': 667,
  27336. 'trademark': 1000,
  27337. 'edotaccent': 444,
  27338. 'Igrave': 389,
  27339. 'Imacron': 389,
  27340. 'Lcaron': 667,
  27341. 'onehalf': 750,
  27342. 'lessequal': 549,
  27343. 'ocircumflex': 500,
  27344. 'ntilde': 556,
  27345. 'Uhungarumlaut': 722,
  27346. 'Eacute': 667,
  27347. 'emacron': 444,
  27348. 'gbreve': 500,
  27349. 'onequarter': 750,
  27350. 'Scaron': 556,
  27351. 'Scommaaccent': 556,
  27352. 'Ohungarumlaut': 778,
  27353. 'degree': 400,
  27354. 'ograve': 500,
  27355. 'Ccaron': 722,
  27356. 'ugrave': 556,
  27357. 'radical': 549,
  27358. 'Dcaron': 722,
  27359. 'rcommaaccent': 444,
  27360. 'Ntilde': 722,
  27361. 'otilde': 500,
  27362. 'Rcommaaccent': 722,
  27363. 'Lcommaaccent': 667,
  27364. 'Atilde': 722,
  27365. 'Aogonek': 722,
  27366. 'Aring': 722,
  27367. 'Otilde': 778,
  27368. 'zdotaccent': 444,
  27369. 'Ecaron': 667,
  27370. 'Iogonek': 389,
  27371. 'kcommaaccent': 556,
  27372. 'minus': 570,
  27373. 'Icircumflex': 389,
  27374. 'ncaron': 556,
  27375. 'tcommaaccent': 333,
  27376. 'logicalnot': 570,
  27377. 'odieresis': 500,
  27378. 'udieresis': 556,
  27379. 'notequal': 549,
  27380. 'gcommaaccent': 500,
  27381. 'eth': 500,
  27382. 'zcaron': 444,
  27383. 'ncommaaccent': 556,
  27384. 'onesuperior': 300,
  27385. 'imacron': 278,
  27386. 'Euro': 500
  27387. },
  27388. 'Times-BoldItalic': {
  27389. 'space': 250,
  27390. 'exclam': 389,
  27391. 'quotedbl': 555,
  27392. 'numbersign': 500,
  27393. 'dollar': 500,
  27394. 'percent': 833,
  27395. 'ampersand': 778,
  27396. 'quoteright': 333,
  27397. 'parenleft': 333,
  27398. 'parenright': 333,
  27399. 'asterisk': 500,
  27400. 'plus': 570,
  27401. 'comma': 250,
  27402. 'hyphen': 333,
  27403. 'period': 250,
  27404. 'slash': 278,
  27405. 'zero': 500,
  27406. 'one': 500,
  27407. 'two': 500,
  27408. 'three': 500,
  27409. 'four': 500,
  27410. 'five': 500,
  27411. 'six': 500,
  27412. 'seven': 500,
  27413. 'eight': 500,
  27414. 'nine': 500,
  27415. 'colon': 333,
  27416. 'semicolon': 333,
  27417. 'less': 570,
  27418. 'equal': 570,
  27419. 'greater': 570,
  27420. 'question': 500,
  27421. 'at': 832,
  27422. 'A': 667,
  27423. 'B': 667,
  27424. 'C': 667,
  27425. 'D': 722,
  27426. 'E': 667,
  27427. 'F': 667,
  27428. 'G': 722,
  27429. 'H': 778,
  27430. 'I': 389,
  27431. 'J': 500,
  27432. 'K': 667,
  27433. 'L': 611,
  27434. 'M': 889,
  27435. 'N': 722,
  27436. 'O': 722,
  27437. 'P': 611,
  27438. 'Q': 722,
  27439. 'R': 667,
  27440. 'S': 556,
  27441. 'T': 611,
  27442. 'U': 722,
  27443. 'V': 667,
  27444. 'W': 889,
  27445. 'X': 667,
  27446. 'Y': 611,
  27447. 'Z': 611,
  27448. 'bracketleft': 333,
  27449. 'backslash': 278,
  27450. 'bracketright': 333,
  27451. 'asciicircum': 570,
  27452. 'underscore': 500,
  27453. 'quoteleft': 333,
  27454. 'a': 500,
  27455. 'b': 500,
  27456. 'c': 444,
  27457. 'd': 500,
  27458. 'e': 444,
  27459. 'f': 333,
  27460. 'g': 500,
  27461. 'h': 556,
  27462. 'i': 278,
  27463. 'j': 278,
  27464. 'k': 500,
  27465. 'l': 278,
  27466. 'm': 778,
  27467. 'n': 556,
  27468. 'o': 500,
  27469. 'p': 500,
  27470. 'q': 500,
  27471. 'r': 389,
  27472. 's': 389,
  27473. 't': 278,
  27474. 'u': 556,
  27475. 'v': 444,
  27476. 'w': 667,
  27477. 'x': 500,
  27478. 'y': 444,
  27479. 'z': 389,
  27480. 'braceleft': 348,
  27481. 'bar': 220,
  27482. 'braceright': 348,
  27483. 'asciitilde': 570,
  27484. 'exclamdown': 389,
  27485. 'cent': 500,
  27486. 'sterling': 500,
  27487. 'fraction': 167,
  27488. 'yen': 500,
  27489. 'florin': 500,
  27490. 'section': 500,
  27491. 'currency': 500,
  27492. 'quotesingle': 278,
  27493. 'quotedblleft': 500,
  27494. 'guillemotleft': 500,
  27495. 'guilsinglleft': 333,
  27496. 'guilsinglright': 333,
  27497. 'fi': 556,
  27498. 'fl': 556,
  27499. 'endash': 500,
  27500. 'dagger': 500,
  27501. 'daggerdbl': 500,
  27502. 'periodcentered': 250,
  27503. 'paragraph': 500,
  27504. 'bullet': 350,
  27505. 'quotesinglbase': 333,
  27506. 'quotedblbase': 500,
  27507. 'quotedblright': 500,
  27508. 'guillemotright': 500,
  27509. 'ellipsis': 1000,
  27510. 'perthousand': 1000,
  27511. 'questiondown': 500,
  27512. 'grave': 333,
  27513. 'acute': 333,
  27514. 'circumflex': 333,
  27515. 'tilde': 333,
  27516. 'macron': 333,
  27517. 'breve': 333,
  27518. 'dotaccent': 333,
  27519. 'dieresis': 333,
  27520. 'ring': 333,
  27521. 'cedilla': 333,
  27522. 'hungarumlaut': 333,
  27523. 'ogonek': 333,
  27524. 'caron': 333,
  27525. 'emdash': 1000,
  27526. 'AE': 944,
  27527. 'ordfeminine': 266,
  27528. 'Lslash': 611,
  27529. 'Oslash': 722,
  27530. 'OE': 944,
  27531. 'ordmasculine': 300,
  27532. 'ae': 722,
  27533. 'dotlessi': 278,
  27534. 'lslash': 278,
  27535. 'oslash': 500,
  27536. 'oe': 722,
  27537. 'germandbls': 500,
  27538. 'Idieresis': 389,
  27539. 'eacute': 444,
  27540. 'abreve': 500,
  27541. 'uhungarumlaut': 556,
  27542. 'ecaron': 444,
  27543. 'Ydieresis': 611,
  27544. 'divide': 570,
  27545. 'Yacute': 611,
  27546. 'Acircumflex': 667,
  27547. 'aacute': 500,
  27548. 'Ucircumflex': 722,
  27549. 'yacute': 444,
  27550. 'scommaaccent': 389,
  27551. 'ecircumflex': 444,
  27552. 'Uring': 722,
  27553. 'Udieresis': 722,
  27554. 'aogonek': 500,
  27555. 'Uacute': 722,
  27556. 'uogonek': 556,
  27557. 'Edieresis': 667,
  27558. 'Dcroat': 722,
  27559. 'commaaccent': 250,
  27560. 'copyright': 747,
  27561. 'Emacron': 667,
  27562. 'ccaron': 444,
  27563. 'aring': 500,
  27564. 'Ncommaaccent': 722,
  27565. 'lacute': 278,
  27566. 'agrave': 500,
  27567. 'Tcommaaccent': 611,
  27568. 'Cacute': 667,
  27569. 'atilde': 500,
  27570. 'Edotaccent': 667,
  27571. 'scaron': 389,
  27572. 'scedilla': 389,
  27573. 'iacute': 278,
  27574. 'lozenge': 494,
  27575. 'Rcaron': 667,
  27576. 'Gcommaaccent': 722,
  27577. 'ucircumflex': 556,
  27578. 'acircumflex': 500,
  27579. 'Amacron': 667,
  27580. 'rcaron': 389,
  27581. 'ccedilla': 444,
  27582. 'Zdotaccent': 611,
  27583. 'Thorn': 611,
  27584. 'Omacron': 722,
  27585. 'Racute': 667,
  27586. 'Sacute': 556,
  27587. 'dcaron': 608,
  27588. 'Umacron': 722,
  27589. 'uring': 556,
  27590. 'threesuperior': 300,
  27591. 'Ograve': 722,
  27592. 'Agrave': 667,
  27593. 'Abreve': 667,
  27594. 'multiply': 570,
  27595. 'uacute': 556,
  27596. 'Tcaron': 611,
  27597. 'partialdiff': 494,
  27598. 'ydieresis': 444,
  27599. 'Nacute': 722,
  27600. 'icircumflex': 278,
  27601. 'Ecircumflex': 667,
  27602. 'adieresis': 500,
  27603. 'edieresis': 444,
  27604. 'cacute': 444,
  27605. 'nacute': 556,
  27606. 'umacron': 556,
  27607. 'Ncaron': 722,
  27608. 'Iacute': 389,
  27609. 'plusminus': 570,
  27610. 'brokenbar': 220,
  27611. 'registered': 747,
  27612. 'Gbreve': 722,
  27613. 'Idotaccent': 389,
  27614. 'summation': 600,
  27615. 'Egrave': 667,
  27616. 'racute': 389,
  27617. 'omacron': 500,
  27618. 'Zacute': 611,
  27619. 'Zcaron': 611,
  27620. 'greaterequal': 549,
  27621. 'Eth': 722,
  27622. 'Ccedilla': 667,
  27623. 'lcommaaccent': 278,
  27624. 'tcaron': 366,
  27625. 'eogonek': 444,
  27626. 'Uogonek': 722,
  27627. 'Aacute': 667,
  27628. 'Adieresis': 667,
  27629. 'egrave': 444,
  27630. 'zacute': 389,
  27631. 'iogonek': 278,
  27632. 'Oacute': 722,
  27633. 'oacute': 500,
  27634. 'amacron': 500,
  27635. 'sacute': 389,
  27636. 'idieresis': 278,
  27637. 'Ocircumflex': 722,
  27638. 'Ugrave': 722,
  27639. 'Delta': 612,
  27640. 'thorn': 500,
  27641. 'twosuperior': 300,
  27642. 'Odieresis': 722,
  27643. 'mu': 576,
  27644. 'igrave': 278,
  27645. 'ohungarumlaut': 500,
  27646. 'Eogonek': 667,
  27647. 'dcroat': 500,
  27648. 'threequarters': 750,
  27649. 'Scedilla': 556,
  27650. 'lcaron': 382,
  27651. 'Kcommaaccent': 667,
  27652. 'Lacute': 611,
  27653. 'trademark': 1000,
  27654. 'edotaccent': 444,
  27655. 'Igrave': 389,
  27656. 'Imacron': 389,
  27657. 'Lcaron': 611,
  27658. 'onehalf': 750,
  27659. 'lessequal': 549,
  27660. 'ocircumflex': 500,
  27661. 'ntilde': 556,
  27662. 'Uhungarumlaut': 722,
  27663. 'Eacute': 667,
  27664. 'emacron': 444,
  27665. 'gbreve': 500,
  27666. 'onequarter': 750,
  27667. 'Scaron': 556,
  27668. 'Scommaaccent': 556,
  27669. 'Ohungarumlaut': 722,
  27670. 'degree': 400,
  27671. 'ograve': 500,
  27672. 'Ccaron': 667,
  27673. 'ugrave': 556,
  27674. 'radical': 549,
  27675. 'Dcaron': 722,
  27676. 'rcommaaccent': 389,
  27677. 'Ntilde': 722,
  27678. 'otilde': 500,
  27679. 'Rcommaaccent': 667,
  27680. 'Lcommaaccent': 611,
  27681. 'Atilde': 667,
  27682. 'Aogonek': 667,
  27683. 'Aring': 667,
  27684. 'Otilde': 722,
  27685. 'zdotaccent': 389,
  27686. 'Ecaron': 667,
  27687. 'Iogonek': 389,
  27688. 'kcommaaccent': 500,
  27689. 'minus': 606,
  27690. 'Icircumflex': 389,
  27691. 'ncaron': 556,
  27692. 'tcommaaccent': 278,
  27693. 'logicalnot': 606,
  27694. 'odieresis': 500,
  27695. 'udieresis': 556,
  27696. 'notequal': 549,
  27697. 'gcommaaccent': 500,
  27698. 'eth': 500,
  27699. 'zcaron': 389,
  27700. 'ncommaaccent': 556,
  27701. 'onesuperior': 300,
  27702. 'imacron': 278,
  27703. 'Euro': 500
  27704. },
  27705. 'Times-Italic': {
  27706. 'space': 250,
  27707. 'exclam': 333,
  27708. 'quotedbl': 420,
  27709. 'numbersign': 500,
  27710. 'dollar': 500,
  27711. 'percent': 833,
  27712. 'ampersand': 778,
  27713. 'quoteright': 333,
  27714. 'parenleft': 333,
  27715. 'parenright': 333,
  27716. 'asterisk': 500,
  27717. 'plus': 675,
  27718. 'comma': 250,
  27719. 'hyphen': 333,
  27720. 'period': 250,
  27721. 'slash': 278,
  27722. 'zero': 500,
  27723. 'one': 500,
  27724. 'two': 500,
  27725. 'three': 500,
  27726. 'four': 500,
  27727. 'five': 500,
  27728. 'six': 500,
  27729. 'seven': 500,
  27730. 'eight': 500,
  27731. 'nine': 500,
  27732. 'colon': 333,
  27733. 'semicolon': 333,
  27734. 'less': 675,
  27735. 'equal': 675,
  27736. 'greater': 675,
  27737. 'question': 500,
  27738. 'at': 920,
  27739. 'A': 611,
  27740. 'B': 611,
  27741. 'C': 667,
  27742. 'D': 722,
  27743. 'E': 611,
  27744. 'F': 611,
  27745. 'G': 722,
  27746. 'H': 722,
  27747. 'I': 333,
  27748. 'J': 444,
  27749. 'K': 667,
  27750. 'L': 556,
  27751. 'M': 833,
  27752. 'N': 667,
  27753. 'O': 722,
  27754. 'P': 611,
  27755. 'Q': 722,
  27756. 'R': 611,
  27757. 'S': 500,
  27758. 'T': 556,
  27759. 'U': 722,
  27760. 'V': 611,
  27761. 'W': 833,
  27762. 'X': 611,
  27763. 'Y': 556,
  27764. 'Z': 556,
  27765. 'bracketleft': 389,
  27766. 'backslash': 278,
  27767. 'bracketright': 389,
  27768. 'asciicircum': 422,
  27769. 'underscore': 500,
  27770. 'quoteleft': 333,
  27771. 'a': 500,
  27772. 'b': 500,
  27773. 'c': 444,
  27774. 'd': 500,
  27775. 'e': 444,
  27776. 'f': 278,
  27777. 'g': 500,
  27778. 'h': 500,
  27779. 'i': 278,
  27780. 'j': 278,
  27781. 'k': 444,
  27782. 'l': 278,
  27783. 'm': 722,
  27784. 'n': 500,
  27785. 'o': 500,
  27786. 'p': 500,
  27787. 'q': 500,
  27788. 'r': 389,
  27789. 's': 389,
  27790. 't': 278,
  27791. 'u': 500,
  27792. 'v': 444,
  27793. 'w': 667,
  27794. 'x': 444,
  27795. 'y': 444,
  27796. 'z': 389,
  27797. 'braceleft': 400,
  27798. 'bar': 275,
  27799. 'braceright': 400,
  27800. 'asciitilde': 541,
  27801. 'exclamdown': 389,
  27802. 'cent': 500,
  27803. 'sterling': 500,
  27804. 'fraction': 167,
  27805. 'yen': 500,
  27806. 'florin': 500,
  27807. 'section': 500,
  27808. 'currency': 500,
  27809. 'quotesingle': 214,
  27810. 'quotedblleft': 556,
  27811. 'guillemotleft': 500,
  27812. 'guilsinglleft': 333,
  27813. 'guilsinglright': 333,
  27814. 'fi': 500,
  27815. 'fl': 500,
  27816. 'endash': 500,
  27817. 'dagger': 500,
  27818. 'daggerdbl': 500,
  27819. 'periodcentered': 250,
  27820. 'paragraph': 523,
  27821. 'bullet': 350,
  27822. 'quotesinglbase': 333,
  27823. 'quotedblbase': 556,
  27824. 'quotedblright': 556,
  27825. 'guillemotright': 500,
  27826. 'ellipsis': 889,
  27827. 'perthousand': 1000,
  27828. 'questiondown': 500,
  27829. 'grave': 333,
  27830. 'acute': 333,
  27831. 'circumflex': 333,
  27832. 'tilde': 333,
  27833. 'macron': 333,
  27834. 'breve': 333,
  27835. 'dotaccent': 333,
  27836. 'dieresis': 333,
  27837. 'ring': 333,
  27838. 'cedilla': 333,
  27839. 'hungarumlaut': 333,
  27840. 'ogonek': 333,
  27841. 'caron': 333,
  27842. 'emdash': 889,
  27843. 'AE': 889,
  27844. 'ordfeminine': 276,
  27845. 'Lslash': 556,
  27846. 'Oslash': 722,
  27847. 'OE': 944,
  27848. 'ordmasculine': 310,
  27849. 'ae': 667,
  27850. 'dotlessi': 278,
  27851. 'lslash': 278,
  27852. 'oslash': 500,
  27853. 'oe': 667,
  27854. 'germandbls': 500,
  27855. 'Idieresis': 333,
  27856. 'eacute': 444,
  27857. 'abreve': 500,
  27858. 'uhungarumlaut': 500,
  27859. 'ecaron': 444,
  27860. 'Ydieresis': 556,
  27861. 'divide': 675,
  27862. 'Yacute': 556,
  27863. 'Acircumflex': 611,
  27864. 'aacute': 500,
  27865. 'Ucircumflex': 722,
  27866. 'yacute': 444,
  27867. 'scommaaccent': 389,
  27868. 'ecircumflex': 444,
  27869. 'Uring': 722,
  27870. 'Udieresis': 722,
  27871. 'aogonek': 500,
  27872. 'Uacute': 722,
  27873. 'uogonek': 500,
  27874. 'Edieresis': 611,
  27875. 'Dcroat': 722,
  27876. 'commaaccent': 250,
  27877. 'copyright': 760,
  27878. 'Emacron': 611,
  27879. 'ccaron': 444,
  27880. 'aring': 500,
  27881. 'Ncommaaccent': 667,
  27882. 'lacute': 278,
  27883. 'agrave': 500,
  27884. 'Tcommaaccent': 556,
  27885. 'Cacute': 667,
  27886. 'atilde': 500,
  27887. 'Edotaccent': 611,
  27888. 'scaron': 389,
  27889. 'scedilla': 389,
  27890. 'iacute': 278,
  27891. 'lozenge': 471,
  27892. 'Rcaron': 611,
  27893. 'Gcommaaccent': 722,
  27894. 'ucircumflex': 500,
  27895. 'acircumflex': 500,
  27896. 'Amacron': 611,
  27897. 'rcaron': 389,
  27898. 'ccedilla': 444,
  27899. 'Zdotaccent': 556,
  27900. 'Thorn': 611,
  27901. 'Omacron': 722,
  27902. 'Racute': 611,
  27903. 'Sacute': 500,
  27904. 'dcaron': 544,
  27905. 'Umacron': 722,
  27906. 'uring': 500,
  27907. 'threesuperior': 300,
  27908. 'Ograve': 722,
  27909. 'Agrave': 611,
  27910. 'Abreve': 611,
  27911. 'multiply': 675,
  27912. 'uacute': 500,
  27913. 'Tcaron': 556,
  27914. 'partialdiff': 476,
  27915. 'ydieresis': 444,
  27916. 'Nacute': 667,
  27917. 'icircumflex': 278,
  27918. 'Ecircumflex': 611,
  27919. 'adieresis': 500,
  27920. 'edieresis': 444,
  27921. 'cacute': 444,
  27922. 'nacute': 500,
  27923. 'umacron': 500,
  27924. 'Ncaron': 667,
  27925. 'Iacute': 333,
  27926. 'plusminus': 675,
  27927. 'brokenbar': 275,
  27928. 'registered': 760,
  27929. 'Gbreve': 722,
  27930. 'Idotaccent': 333,
  27931. 'summation': 600,
  27932. 'Egrave': 611,
  27933. 'racute': 389,
  27934. 'omacron': 500,
  27935. 'Zacute': 556,
  27936. 'Zcaron': 556,
  27937. 'greaterequal': 549,
  27938. 'Eth': 722,
  27939. 'Ccedilla': 667,
  27940. 'lcommaaccent': 278,
  27941. 'tcaron': 300,
  27942. 'eogonek': 444,
  27943. 'Uogonek': 722,
  27944. 'Aacute': 611,
  27945. 'Adieresis': 611,
  27946. 'egrave': 444,
  27947. 'zacute': 389,
  27948. 'iogonek': 278,
  27949. 'Oacute': 722,
  27950. 'oacute': 500,
  27951. 'amacron': 500,
  27952. 'sacute': 389,
  27953. 'idieresis': 278,
  27954. 'Ocircumflex': 722,
  27955. 'Ugrave': 722,
  27956. 'Delta': 612,
  27957. 'thorn': 500,
  27958. 'twosuperior': 300,
  27959. 'Odieresis': 722,
  27960. 'mu': 500,
  27961. 'igrave': 278,
  27962. 'ohungarumlaut': 500,
  27963. 'Eogonek': 611,
  27964. 'dcroat': 500,
  27965. 'threequarters': 750,
  27966. 'Scedilla': 500,
  27967. 'lcaron': 300,
  27968. 'Kcommaaccent': 667,
  27969. 'Lacute': 556,
  27970. 'trademark': 980,
  27971. 'edotaccent': 444,
  27972. 'Igrave': 333,
  27973. 'Imacron': 333,
  27974. 'Lcaron': 611,
  27975. 'onehalf': 750,
  27976. 'lessequal': 549,
  27977. 'ocircumflex': 500,
  27978. 'ntilde': 500,
  27979. 'Uhungarumlaut': 722,
  27980. 'Eacute': 611,
  27981. 'emacron': 444,
  27982. 'gbreve': 500,
  27983. 'onequarter': 750,
  27984. 'Scaron': 500,
  27985. 'Scommaaccent': 500,
  27986. 'Ohungarumlaut': 722,
  27987. 'degree': 400,
  27988. 'ograve': 500,
  27989. 'Ccaron': 667,
  27990. 'ugrave': 500,
  27991. 'radical': 453,
  27992. 'Dcaron': 722,
  27993. 'rcommaaccent': 389,
  27994. 'Ntilde': 667,
  27995. 'otilde': 500,
  27996. 'Rcommaaccent': 611,
  27997. 'Lcommaaccent': 556,
  27998. 'Atilde': 611,
  27999. 'Aogonek': 611,
  28000. 'Aring': 611,
  28001. 'Otilde': 722,
  28002. 'zdotaccent': 389,
  28003. 'Ecaron': 611,
  28004. 'Iogonek': 333,
  28005. 'kcommaaccent': 444,
  28006. 'minus': 675,
  28007. 'Icircumflex': 333,
  28008. 'ncaron': 500,
  28009. 'tcommaaccent': 278,
  28010. 'logicalnot': 675,
  28011. 'odieresis': 500,
  28012. 'udieresis': 500,
  28013. 'notequal': 549,
  28014. 'gcommaaccent': 500,
  28015. 'eth': 500,
  28016. 'zcaron': 389,
  28017. 'ncommaaccent': 500,
  28018. 'onesuperior': 300,
  28019. 'imacron': 278,
  28020. 'Euro': 500
  28021. },
  28022. 'ZapfDingbats': {
  28023. 'space': 278,
  28024. 'a1': 974,
  28025. 'a2': 961,
  28026. 'a202': 974,
  28027. 'a3': 980,
  28028. 'a4': 719,
  28029. 'a5': 789,
  28030. 'a119': 790,
  28031. 'a118': 791,
  28032. 'a117': 690,
  28033. 'a11': 960,
  28034. 'a12': 939,
  28035. 'a13': 549,
  28036. 'a14': 855,
  28037. 'a15': 911,
  28038. 'a16': 933,
  28039. 'a105': 911,
  28040. 'a17': 945,
  28041. 'a18': 974,
  28042. 'a19': 755,
  28043. 'a20': 846,
  28044. 'a21': 762,
  28045. 'a22': 761,
  28046. 'a23': 571,
  28047. 'a24': 677,
  28048. 'a25': 763,
  28049. 'a26': 760,
  28050. 'a27': 759,
  28051. 'a28': 754,
  28052. 'a6': 494,
  28053. 'a7': 552,
  28054. 'a8': 537,
  28055. 'a9': 577,
  28056. 'a10': 692,
  28057. 'a29': 786,
  28058. 'a30': 788,
  28059. 'a31': 788,
  28060. 'a32': 790,
  28061. 'a33': 793,
  28062. 'a34': 794,
  28063. 'a35': 816,
  28064. 'a36': 823,
  28065. 'a37': 789,
  28066. 'a38': 841,
  28067. 'a39': 823,
  28068. 'a40': 833,
  28069. 'a41': 816,
  28070. 'a42': 831,
  28071. 'a43': 923,
  28072. 'a44': 744,
  28073. 'a45': 723,
  28074. 'a46': 749,
  28075. 'a47': 790,
  28076. 'a48': 792,
  28077. 'a49': 695,
  28078. 'a50': 776,
  28079. 'a51': 768,
  28080. 'a52': 792,
  28081. 'a53': 759,
  28082. 'a54': 707,
  28083. 'a55': 708,
  28084. 'a56': 682,
  28085. 'a57': 701,
  28086. 'a58': 826,
  28087. 'a59': 815,
  28088. 'a60': 789,
  28089. 'a61': 789,
  28090. 'a62': 707,
  28091. 'a63': 687,
  28092. 'a64': 696,
  28093. 'a65': 689,
  28094. 'a66': 786,
  28095. 'a67': 787,
  28096. 'a68': 713,
  28097. 'a69': 791,
  28098. 'a70': 785,
  28099. 'a71': 791,
  28100. 'a72': 873,
  28101. 'a73': 761,
  28102. 'a74': 762,
  28103. 'a203': 762,
  28104. 'a75': 759,
  28105. 'a204': 759,
  28106. 'a76': 892,
  28107. 'a77': 892,
  28108. 'a78': 788,
  28109. 'a79': 784,
  28110. 'a81': 438,
  28111. 'a82': 138,
  28112. 'a83': 277,
  28113. 'a84': 415,
  28114. 'a97': 392,
  28115. 'a98': 392,
  28116. 'a99': 668,
  28117. 'a100': 668,
  28118. 'a89': 390,
  28119. 'a90': 390,
  28120. 'a93': 317,
  28121. 'a94': 317,
  28122. 'a91': 276,
  28123. 'a92': 276,
  28124. 'a205': 509,
  28125. 'a85': 509,
  28126. 'a206': 410,
  28127. 'a86': 410,
  28128. 'a87': 234,
  28129. 'a88': 234,
  28130. 'a95': 334,
  28131. 'a96': 334,
  28132. 'a101': 732,
  28133. 'a102': 544,
  28134. 'a103': 544,
  28135. 'a104': 910,
  28136. 'a106': 667,
  28137. 'a107': 760,
  28138. 'a108': 760,
  28139. 'a112': 776,
  28140. 'a111': 595,
  28141. 'a110': 694,
  28142. 'a109': 626,
  28143. 'a120': 788,
  28144. 'a121': 788,
  28145. 'a122': 788,
  28146. 'a123': 788,
  28147. 'a124': 788,
  28148. 'a125': 788,
  28149. 'a126': 788,
  28150. 'a127': 788,
  28151. 'a128': 788,
  28152. 'a129': 788,
  28153. 'a130': 788,
  28154. 'a131': 788,
  28155. 'a132': 788,
  28156. 'a133': 788,
  28157. 'a134': 788,
  28158. 'a135': 788,
  28159. 'a136': 788,
  28160. 'a137': 788,
  28161. 'a138': 788,
  28162. 'a139': 788,
  28163. 'a140': 788,
  28164. 'a141': 788,
  28165. 'a142': 788,
  28166. 'a143': 788,
  28167. 'a144': 788,
  28168. 'a145': 788,
  28169. 'a146': 788,
  28170. 'a147': 788,
  28171. 'a148': 788,
  28172. 'a149': 788,
  28173. 'a150': 788,
  28174. 'a151': 788,
  28175. 'a152': 788,
  28176. 'a153': 788,
  28177. 'a154': 788,
  28178. 'a155': 788,
  28179. 'a156': 788,
  28180. 'a157': 788,
  28181. 'a158': 788,
  28182. 'a159': 788,
  28183. 'a160': 894,
  28184. 'a161': 838,
  28185. 'a163': 1016,
  28186. 'a164': 458,
  28187. 'a196': 748,
  28188. 'a165': 924,
  28189. 'a192': 748,
  28190. 'a166': 918,
  28191. 'a167': 927,
  28192. 'a168': 928,
  28193. 'a169': 928,
  28194. 'a170': 834,
  28195. 'a171': 873,
  28196. 'a172': 828,
  28197. 'a173': 924,
  28198. 'a162': 924,
  28199. 'a174': 917,
  28200. 'a175': 930,
  28201. 'a176': 931,
  28202. 'a177': 463,
  28203. 'a178': 883,
  28204. 'a179': 836,
  28205. 'a193': 836,
  28206. 'a180': 867,
  28207. 'a199': 867,
  28208. 'a181': 696,
  28209. 'a200': 696,
  28210. 'a182': 874,
  28211. 'a201': 874,
  28212. 'a183': 760,
  28213. 'a184': 946,
  28214. 'a197': 771,
  28215. 'a185': 865,
  28216. 'a194': 771,
  28217. 'a198': 888,
  28218. 'a186': 967,
  28219. 'a195': 888,
  28220. 'a187': 831,
  28221. 'a188': 873,
  28222. 'a189': 927,
  28223. 'a190': 970,
  28224. 'a191': 918
  28225. }
  28226. };
  28227. var EOF = {};
  28228. function isEOF(v) {
  28229. return (v === EOF);
  28230. }
  28231. var MAX_LENGTH_TO_CACHE = 1000;
  28232. var Parser = (function ParserClosure() {
  28233. function Parser(lexer, allowStreams, xref) {
  28234. this.lexer = lexer;
  28235. this.allowStreams = allowStreams;
  28236. this.xref = xref;
  28237. this.imageCache = {};
  28238. this.refill();
  28239. }
  28240. Parser.prototype = {
  28241. refill: function Parser_refill() {
  28242. this.buf1 = this.lexer.getObj();
  28243. this.buf2 = this.lexer.getObj();
  28244. },
  28245. shift: function Parser_shift() {
  28246. if (isCmd(this.buf2, 'ID')) {
  28247. this.buf1 = this.buf2;
  28248. this.buf2 = null;
  28249. } else {
  28250. this.buf1 = this.buf2;
  28251. this.buf2 = this.lexer.getObj();
  28252. }
  28253. },
  28254. getObj: function Parser_getObj(cipherTransform) {
  28255. var buf1 = this.buf1;
  28256. this.shift();
  28257. if (buf1 instanceof Cmd) {
  28258. switch (buf1.cmd) {
  28259. case 'BI': // inline image
  28260. return this.makeInlineImage(cipherTransform);
  28261. case '[': // array
  28262. var array = [];
  28263. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28264. array.push(this.getObj(cipherTransform));
  28265. }
  28266. if (isEOF(this.buf1)) {
  28267. error('End of file inside array');
  28268. }
  28269. this.shift();
  28270. return array;
  28271. case '<<': // dictionary or stream
  28272. var dict = new Dict(this.xref);
  28273. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28274. if (!isName(this.buf1)) {
  28275. info('Malformed dictionary: key must be a name object');
  28276. this.shift();
  28277. continue;
  28278. }
  28279. var key = this.buf1.name;
  28280. this.shift();
  28281. if (isEOF(this.buf1)) {
  28282. break;
  28283. }
  28284. dict.set(key, this.getObj(cipherTransform));
  28285. }
  28286. if (isEOF(this.buf1)) {
  28287. error('End of file inside dictionary');
  28288. }
  28289. // Stream objects are not allowed inside content streams or
  28290. // object streams.
  28291. if (isCmd(this.buf2, 'stream')) {
  28292. return (this.allowStreams ?
  28293. this.makeStream(dict, cipherTransform) : dict);
  28294. }
  28295. this.shift();
  28296. return dict;
  28297. default: // simple object
  28298. return buf1;
  28299. }
  28300. }
  28301. if (isInt(buf1)) { // indirect reference or integer
  28302. var num = buf1;
  28303. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28304. var ref = new Ref(num, this.buf1);
  28305. this.shift();
  28306. this.shift();
  28307. return ref;
  28308. }
  28309. return num;
  28310. }
  28311. if (isString(buf1)) { // string
  28312. var str = buf1;
  28313. if (cipherTransform) {
  28314. str = cipherTransform.decryptString(str);
  28315. }
  28316. return str;
  28317. }
  28318. // simple object
  28319. return buf1;
  28320. },
  28321. /**
  28322. * Find the end of the stream by searching for the /EI\s/.
  28323. * @returns {number} The inline stream length.
  28324. */
  28325. findDefaultInlineStreamEnd:
  28326. function Parser_findDefaultInlineStreamEnd(stream) {
  28327. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28328. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28329. while ((ch = stream.getByte()) !== -1) {
  28330. if (state === 0) {
  28331. state = (ch === E) ? 1 : 0;
  28332. } else if (state === 1) {
  28333. state = (ch === I) ? 2 : 0;
  28334. } else {
  28335. assert(state === 2);
  28336. if (ch === SPACE || ch === LF || ch === CR) {
  28337. // Let's check the next five bytes are ASCII... just be sure.
  28338. n = 5;
  28339. followingBytes = stream.peekBytes(n);
  28340. for (i = 0; i < n; i++) {
  28341. ch = followingBytes[i];
  28342. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28343. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28344. // it's binary stuff. Resetting the state.
  28345. state = 0;
  28346. break;
  28347. }
  28348. }
  28349. if (state === 2) {
  28350. break; // Finished!
  28351. }
  28352. } else {
  28353. state = 0;
  28354. }
  28355. }
  28356. }
  28357. return ((stream.pos - 4) - startPos);
  28358. },
  28359. /**
  28360. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28361. * @returns {number} The inline stream length.
  28362. */
  28363. findASCII85DecodeInlineStreamEnd:
  28364. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28365. var TILDE = 0x7E, GT = 0x3E;
  28366. var startPos = stream.pos, ch, length;
  28367. while ((ch = stream.getByte()) !== -1) {
  28368. if (ch === TILDE && stream.peekByte() === GT) {
  28369. stream.skip();
  28370. break;
  28371. }
  28372. }
  28373. length = stream.pos - startPos;
  28374. if (ch === -1) {
  28375. warn('Inline ASCII85Decode image stream: ' +
  28376. 'EOD marker not found, searching for /EI/ instead.');
  28377. stream.skip(-length); // Reset the stream position.
  28378. return this.findDefaultInlineStreamEnd(stream);
  28379. }
  28380. this.inlineStreamSkipEI(stream);
  28381. return length;
  28382. },
  28383. /**
  28384. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28385. * @returns {number} The inline stream length.
  28386. */
  28387. findASCIIHexDecodeInlineStreamEnd:
  28388. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28389. var GT = 0x3E;
  28390. var startPos = stream.pos, ch, length;
  28391. while ((ch = stream.getByte()) !== -1) {
  28392. if (ch === GT) {
  28393. break;
  28394. }
  28395. }
  28396. length = stream.pos - startPos;
  28397. if (ch === -1) {
  28398. warn('Inline ASCIIHexDecode image stream: ' +
  28399. 'EOD marker not found, searching for /EI/ instead.');
  28400. stream.skip(-length); // Reset the stream position.
  28401. return this.findDefaultInlineStreamEnd(stream);
  28402. }
  28403. this.inlineStreamSkipEI(stream);
  28404. return length;
  28405. },
  28406. /**
  28407. * Skip over the /EI/ for streams where we search for an EOD marker.
  28408. */
  28409. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28410. var E = 0x45, I = 0x49;
  28411. var state = 0, ch;
  28412. while ((ch = stream.getByte()) !== -1) {
  28413. if (state === 0) {
  28414. state = (ch === E) ? 1 : 0;
  28415. } else if (state === 1) {
  28416. state = (ch === I) ? 2 : 0;
  28417. } else if (state === 2) {
  28418. break;
  28419. }
  28420. }
  28421. },
  28422. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28423. var lexer = this.lexer;
  28424. var stream = lexer.stream;
  28425. // Parse dictionary.
  28426. var dict = new Dict(null);
  28427. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28428. if (!isName(this.buf1)) {
  28429. error('Dictionary key must be a name object');
  28430. }
  28431. var key = this.buf1.name;
  28432. this.shift();
  28433. if (isEOF(this.buf1)) {
  28434. break;
  28435. }
  28436. dict.set(key, this.getObj(cipherTransform));
  28437. }
  28438. // Extract the name of the first (i.e. the current) image filter.
  28439. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28440. if (isName(filter)) {
  28441. filterName = filter.name;
  28442. } else if (isArray(filter) && isName(filter[0])) {
  28443. filterName = filter[0].name;
  28444. }
  28445. // Parse image stream.
  28446. var startPos = stream.pos, length, i, ii;
  28447. if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28448. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28449. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28450. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28451. } else {
  28452. length = this.findDefaultInlineStreamEnd(stream);
  28453. }
  28454. var imageStream = stream.makeSubStream(startPos, length, dict);
  28455. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28456. // adler32 checksum.
  28457. var adler32;
  28458. if (length < MAX_LENGTH_TO_CACHE) {
  28459. var imageBytes = imageStream.getBytes();
  28460. imageStream.reset();
  28461. var a = 1;
  28462. var b = 0;
  28463. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28464. // No modulo required in the loop if imageBytes.length < 5552.
  28465. a += imageBytes[i] & 0xff;
  28466. b += a;
  28467. }
  28468. adler32 = ((b % 65521) << 16) | (a % 65521);
  28469. if (this.imageCache.adler32 === adler32) {
  28470. this.buf2 = Cmd.get('EI');
  28471. this.shift();
  28472. this.imageCache[adler32].reset();
  28473. return this.imageCache[adler32];
  28474. }
  28475. }
  28476. if (cipherTransform) {
  28477. imageStream = cipherTransform.createStream(imageStream, length);
  28478. }
  28479. imageStream = this.filter(imageStream, dict, length);
  28480. imageStream.dict = dict;
  28481. if (adler32 !== undefined) {
  28482. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28483. this.imageCache[adler32] = imageStream;
  28484. }
  28485. this.buf2 = Cmd.get('EI');
  28486. this.shift();
  28487. return imageStream;
  28488. },
  28489. fetchIfRef: function Parser_fetchIfRef(obj) {
  28490. // not relying on the xref.fetchIfRef -- xref might not be set
  28491. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28492. },
  28493. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28494. var lexer = this.lexer;
  28495. var stream = lexer.stream;
  28496. // get stream start position
  28497. lexer.skipToNextLine();
  28498. var pos = stream.pos - 1;
  28499. // get length
  28500. var length = this.fetchIfRef(dict.get('Length'));
  28501. if (!isInt(length)) {
  28502. info('Bad ' + length + ' attribute in stream');
  28503. length = 0;
  28504. }
  28505. // skip over the stream data
  28506. stream.pos = pos + length;
  28507. lexer.nextChar();
  28508. this.shift(); // '>>'
  28509. this.shift(); // 'stream'
  28510. if (!isCmd(this.buf1, 'endstream')) {
  28511. // bad stream length, scanning for endstream
  28512. stream.pos = pos;
  28513. var SCAN_BLOCK_SIZE = 2048;
  28514. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28515. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28516. 0x61, 0x6D];
  28517. var skipped = 0, found = false, i, j;
  28518. while (stream.pos < stream.end) {
  28519. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28520. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28521. if (scanLength <= 0) {
  28522. break;
  28523. }
  28524. found = false;
  28525. for (i = 0, j = 0; i < scanLength; i++) {
  28526. var b = scanBytes[i];
  28527. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28528. i -= j;
  28529. j = 0;
  28530. } else {
  28531. j++;
  28532. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28533. i++;
  28534. found = true;
  28535. break;
  28536. }
  28537. }
  28538. }
  28539. if (found) {
  28540. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28541. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28542. break;
  28543. }
  28544. skipped += scanLength;
  28545. stream.pos += scanLength;
  28546. }
  28547. if (!found) {
  28548. error('Missing endstream');
  28549. }
  28550. length = skipped;
  28551. lexer.nextChar();
  28552. this.shift();
  28553. this.shift();
  28554. }
  28555. this.shift(); // 'endstream'
  28556. stream = stream.makeSubStream(pos, length, dict);
  28557. if (cipherTransform) {
  28558. stream = cipherTransform.createStream(stream, length);
  28559. }
  28560. stream = this.filter(stream, dict, length);
  28561. stream.dict = dict;
  28562. return stream;
  28563. },
  28564. filter: function Parser_filter(stream, dict, length) {
  28565. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28566. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28567. if (isName(filter)) {
  28568. return this.makeFilter(stream, filter.name, length, params);
  28569. }
  28570. var maybeLength = length;
  28571. if (isArray(filter)) {
  28572. var filterArray = filter;
  28573. var paramsArray = params;
  28574. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28575. filter = filterArray[i];
  28576. if (!isName(filter)) {
  28577. error('Bad filter name: ' + filter);
  28578. }
  28579. params = null;
  28580. if (isArray(paramsArray) && (i in paramsArray)) {
  28581. params = paramsArray[i];
  28582. }
  28583. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28584. // after the first stream the length variable is invalid
  28585. maybeLength = null;
  28586. }
  28587. }
  28588. return stream;
  28589. },
  28590. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28591. if (stream.dict.get('Length') === 0) {
  28592. return new NullStream(stream);
  28593. }
  28594. try {
  28595. if (params) {
  28596. params = this.fetchIfRef(params);
  28597. }
  28598. var xrefStreamStats = this.xref.stats.streamTypes;
  28599. if (name === 'FlateDecode' || name === 'Fl') {
  28600. xrefStreamStats[StreamType.FLATE] = true;
  28601. if (params) {
  28602. return new PredictorStream(new FlateStream(stream, maybeLength),
  28603. maybeLength, params);
  28604. }
  28605. return new FlateStream(stream, maybeLength);
  28606. }
  28607. if (name === 'LZWDecode' || name === 'LZW') {
  28608. xrefStreamStats[StreamType.LZW] = true;
  28609. var earlyChange = 1;
  28610. if (params) {
  28611. if (params.has('EarlyChange')) {
  28612. earlyChange = params.get('EarlyChange');
  28613. }
  28614. return new PredictorStream(
  28615. new LZWStream(stream, maybeLength, earlyChange),
  28616. maybeLength, params);
  28617. }
  28618. return new LZWStream(stream, maybeLength, earlyChange);
  28619. }
  28620. if (name === 'DCTDecode' || name === 'DCT') {
  28621. xrefStreamStats[StreamType.DCT] = true;
  28622. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28623. }
  28624. if (name === 'JPXDecode' || name === 'JPX') {
  28625. xrefStreamStats[StreamType.JPX] = true;
  28626. return new JpxStream(stream, maybeLength, stream.dict);
  28627. }
  28628. if (name === 'ASCII85Decode' || name === 'A85') {
  28629. xrefStreamStats[StreamType.A85] = true;
  28630. return new Ascii85Stream(stream, maybeLength);
  28631. }
  28632. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28633. xrefStreamStats[StreamType.AHX] = true;
  28634. return new AsciiHexStream(stream, maybeLength);
  28635. }
  28636. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28637. xrefStreamStats[StreamType.CCF] = true;
  28638. return new CCITTFaxStream(stream, maybeLength, params);
  28639. }
  28640. if (name === 'RunLengthDecode' || name === 'RL') {
  28641. xrefStreamStats[StreamType.RL] = true;
  28642. return new RunLengthStream(stream, maybeLength);
  28643. }
  28644. if (name === 'JBIG2Decode') {
  28645. xrefStreamStats[StreamType.JBIG] = true;
  28646. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28647. }
  28648. warn('filter "' + name + '" not supported yet');
  28649. return stream;
  28650. } catch (ex) {
  28651. if (ex instanceof MissingDataException) {
  28652. throw ex;
  28653. }
  28654. warn('Invalid stream: \"' + ex + '\"');
  28655. return new NullStream(stream);
  28656. }
  28657. }
  28658. };
  28659. return Parser;
  28660. })();
  28661. var Lexer = (function LexerClosure() {
  28662. function Lexer(stream, knownCommands) {
  28663. this.stream = stream;
  28664. this.nextChar();
  28665. // While lexing, we build up many strings one char at a time. Using += for
  28666. // this can result in lots of garbage strings. It's better to build an
  28667. // array of single-char strings and then join() them together at the end.
  28668. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28669. // purpose uses less memory than using a new array for each string.
  28670. this.strBuf = [];
  28671. // The PDFs might have "glued" commands with other commands, operands or
  28672. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28673. // commands and their prefixes. The prefixes are built the following way:
  28674. // if there a command that is a prefix of the other valid command or
  28675. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28676. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28677. // other commands or literals as a prefix. The knowCommands is optional.
  28678. this.knownCommands = knownCommands;
  28679. }
  28680. Lexer.isSpace = function Lexer_isSpace(ch) {
  28681. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28682. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28683. };
  28684. // A '1' in this array means the character is white space. A '1' or
  28685. // '2' means the character ends a name or command.
  28686. var specialChars = [
  28687. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28689. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28703. ];
  28704. function toHexDigit(ch) {
  28705. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28706. return ch & 0x0F;
  28707. }
  28708. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28709. // 'A'-'F', 'a'-'f'
  28710. return (ch & 0x0F) + 9;
  28711. }
  28712. return -1;
  28713. }
  28714. Lexer.prototype = {
  28715. nextChar: function Lexer_nextChar() {
  28716. return (this.currentChar = this.stream.getByte());
  28717. },
  28718. peekChar: function Lexer_peekChar() {
  28719. return this.stream.peekByte();
  28720. },
  28721. getNumber: function Lexer_getNumber() {
  28722. var ch = this.currentChar;
  28723. var eNotation = false;
  28724. var divideBy = 0; // different from 0 if it's a floating point value
  28725. var sign = 1;
  28726. if (ch === 0x2D) { // '-'
  28727. sign = -1;
  28728. ch = this.nextChar();
  28729. } else if (ch === 0x2B) { // '+'
  28730. ch = this.nextChar();
  28731. }
  28732. if (ch === 0x2E) { // '.'
  28733. divideBy = 10;
  28734. ch = this.nextChar();
  28735. }
  28736. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28737. error('Invalid number: ' + String.fromCharCode(ch));
  28738. return 0;
  28739. }
  28740. var baseValue = ch - 0x30; // '0'
  28741. var powerValue = 0;
  28742. var powerValueSign = 1;
  28743. while ((ch = this.nextChar()) >= 0) {
  28744. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28745. var currentDigit = ch - 0x30; // '0'
  28746. if (eNotation) { // We are after an 'e' or 'E'
  28747. powerValue = powerValue * 10 + currentDigit;
  28748. } else {
  28749. if (divideBy !== 0) { // We are after a point
  28750. divideBy *= 10;
  28751. }
  28752. baseValue = baseValue * 10 + currentDigit;
  28753. }
  28754. } else if (ch === 0x2E) { // '.'
  28755. if (divideBy === 0) {
  28756. divideBy = 1;
  28757. } else {
  28758. // A number can have only one '.'
  28759. break;
  28760. }
  28761. } else if (ch === 0x2D) { // '-'
  28762. // ignore minus signs in the middle of numbers to match
  28763. // Adobe's behavior
  28764. warn('Badly formated number');
  28765. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28766. // 'E' can be either a scientific notation or the beginning of a new
  28767. // operator
  28768. ch = this.peekChar();
  28769. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28770. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28771. this.nextChar(); // Consume the sign character
  28772. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28773. // The 'E' must be the beginning of a new operator
  28774. break;
  28775. }
  28776. eNotation = true;
  28777. } else {
  28778. // the last character doesn't belong to us
  28779. break;
  28780. }
  28781. }
  28782. if (divideBy !== 0) {
  28783. baseValue /= divideBy;
  28784. }
  28785. if (eNotation) {
  28786. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28787. }
  28788. return sign * baseValue;
  28789. },
  28790. getString: function Lexer_getString() {
  28791. var numParen = 1;
  28792. var done = false;
  28793. var strBuf = this.strBuf;
  28794. strBuf.length = 0;
  28795. var ch = this.nextChar();
  28796. while (true) {
  28797. var charBuffered = false;
  28798. switch (ch | 0) {
  28799. case -1:
  28800. warn('Unterminated string');
  28801. done = true;
  28802. break;
  28803. case 0x28: // '('
  28804. ++numParen;
  28805. strBuf.push('(');
  28806. break;
  28807. case 0x29: // ')'
  28808. if (--numParen === 0) {
  28809. this.nextChar(); // consume strings ')'
  28810. done = true;
  28811. } else {
  28812. strBuf.push(')');
  28813. }
  28814. break;
  28815. case 0x5C: // '\\'
  28816. ch = this.nextChar();
  28817. switch (ch) {
  28818. case -1:
  28819. warn('Unterminated string');
  28820. done = true;
  28821. break;
  28822. case 0x6E: // 'n'
  28823. strBuf.push('\n');
  28824. break;
  28825. case 0x72: // 'r'
  28826. strBuf.push('\r');
  28827. break;
  28828. case 0x74: // 't'
  28829. strBuf.push('\t');
  28830. break;
  28831. case 0x62: // 'b'
  28832. strBuf.push('\b');
  28833. break;
  28834. case 0x66: // 'f'
  28835. strBuf.push('\f');
  28836. break;
  28837. case 0x5C: // '\'
  28838. case 0x28: // '('
  28839. case 0x29: // ')'
  28840. strBuf.push(String.fromCharCode(ch));
  28841. break;
  28842. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28843. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28844. var x = ch & 0x0F;
  28845. ch = this.nextChar();
  28846. charBuffered = true;
  28847. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28848. x = (x << 3) + (ch & 0x0F);
  28849. ch = this.nextChar();
  28850. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28851. charBuffered = false;
  28852. x = (x << 3) + (ch & 0x0F);
  28853. }
  28854. }
  28855. strBuf.push(String.fromCharCode(x));
  28856. break;
  28857. case 0x0D: // CR
  28858. if (this.peekChar() === 0x0A) { // LF
  28859. this.nextChar();
  28860. }
  28861. break;
  28862. case 0x0A: // LF
  28863. break;
  28864. default:
  28865. strBuf.push(String.fromCharCode(ch));
  28866. break;
  28867. }
  28868. break;
  28869. default:
  28870. strBuf.push(String.fromCharCode(ch));
  28871. break;
  28872. }
  28873. if (done) {
  28874. break;
  28875. }
  28876. if (!charBuffered) {
  28877. ch = this.nextChar();
  28878. }
  28879. }
  28880. return strBuf.join('');
  28881. },
  28882. getName: function Lexer_getName() {
  28883. var ch;
  28884. var strBuf = this.strBuf;
  28885. strBuf.length = 0;
  28886. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28887. if (ch === 0x23) { // '#'
  28888. ch = this.nextChar();
  28889. var x = toHexDigit(ch);
  28890. if (x !== -1) {
  28891. var x2 = toHexDigit(this.nextChar());
  28892. if (x2 === -1) {
  28893. error('Illegal digit in hex char in name: ' + x2);
  28894. }
  28895. strBuf.push(String.fromCharCode((x << 4) | x2));
  28896. } else {
  28897. strBuf.push('#', String.fromCharCode(ch));
  28898. }
  28899. } else {
  28900. strBuf.push(String.fromCharCode(ch));
  28901. }
  28902. }
  28903. if (strBuf.length > 128) {
  28904. error('Warning: name token is longer than allowed by the spec: ' +
  28905. strBuf.length);
  28906. }
  28907. return Name.get(strBuf.join(''));
  28908. },
  28909. getHexString: function Lexer_getHexString() {
  28910. var strBuf = this.strBuf;
  28911. strBuf.length = 0;
  28912. var ch = this.currentChar;
  28913. var isFirstHex = true;
  28914. var firstDigit;
  28915. var secondDigit;
  28916. while (true) {
  28917. if (ch < 0) {
  28918. warn('Unterminated hex string');
  28919. break;
  28920. } else if (ch === 0x3E) { // '>'
  28921. this.nextChar();
  28922. break;
  28923. } else if (specialChars[ch] === 1) {
  28924. ch = this.nextChar();
  28925. continue;
  28926. } else {
  28927. if (isFirstHex) {
  28928. firstDigit = toHexDigit(ch);
  28929. if (firstDigit === -1) {
  28930. warn('Ignoring invalid character "' + ch + '" in hex string');
  28931. ch = this.nextChar();
  28932. continue;
  28933. }
  28934. } else {
  28935. secondDigit = toHexDigit(ch);
  28936. if (secondDigit === -1) {
  28937. warn('Ignoring invalid character "' + ch + '" in hex string');
  28938. ch = this.nextChar();
  28939. continue;
  28940. }
  28941. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28942. }
  28943. isFirstHex = !isFirstHex;
  28944. ch = this.nextChar();
  28945. }
  28946. }
  28947. return strBuf.join('');
  28948. },
  28949. getObj: function Lexer_getObj() {
  28950. // skip whitespace and comments
  28951. var comment = false;
  28952. var ch = this.currentChar;
  28953. while (true) {
  28954. if (ch < 0) {
  28955. return EOF;
  28956. }
  28957. if (comment) {
  28958. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28959. comment = false;
  28960. }
  28961. } else if (ch === 0x25) { // '%'
  28962. comment = true;
  28963. } else if (specialChars[ch] !== 1) {
  28964. break;
  28965. }
  28966. ch = this.nextChar();
  28967. }
  28968. // start reading token
  28969. switch (ch | 0) {
  28970. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28971. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28972. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28973. return this.getNumber();
  28974. case 0x28: // '('
  28975. return this.getString();
  28976. case 0x2F: // '/'
  28977. return this.getName();
  28978. // array punctuation
  28979. case 0x5B: // '['
  28980. this.nextChar();
  28981. return Cmd.get('[');
  28982. case 0x5D: // ']'
  28983. this.nextChar();
  28984. return Cmd.get(']');
  28985. // hex string or dict punctuation
  28986. case 0x3C: // '<'
  28987. ch = this.nextChar();
  28988. if (ch === 0x3C) {
  28989. // dict punctuation
  28990. this.nextChar();
  28991. return Cmd.get('<<');
  28992. }
  28993. return this.getHexString();
  28994. // dict punctuation
  28995. case 0x3E: // '>'
  28996. ch = this.nextChar();
  28997. if (ch === 0x3E) {
  28998. this.nextChar();
  28999. return Cmd.get('>>');
  29000. }
  29001. return Cmd.get('>');
  29002. case 0x7B: // '{'
  29003. this.nextChar();
  29004. return Cmd.get('{');
  29005. case 0x7D: // '}'
  29006. this.nextChar();
  29007. return Cmd.get('}');
  29008. case 0x29: // ')'
  29009. error('Illegal character: ' + ch);
  29010. break;
  29011. }
  29012. // command
  29013. var str = String.fromCharCode(ch);
  29014. var knownCommands = this.knownCommands;
  29015. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29016. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29017. // stop if known command is found and next character does not make
  29018. // the str a command
  29019. var possibleCommand = str + String.fromCharCode(ch);
  29020. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29021. break;
  29022. }
  29023. if (str.length === 128) {
  29024. error('Command token too long: ' + str.length);
  29025. }
  29026. str = possibleCommand;
  29027. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29028. }
  29029. if (str === 'true') {
  29030. return true;
  29031. }
  29032. if (str === 'false') {
  29033. return false;
  29034. }
  29035. if (str === 'null') {
  29036. return null;
  29037. }
  29038. return Cmd.get(str);
  29039. },
  29040. skipToNextLine: function Lexer_skipToNextLine() {
  29041. var ch = this.currentChar;
  29042. while (ch >= 0) {
  29043. if (ch === 0x0D) { // CR
  29044. ch = this.nextChar();
  29045. if (ch === 0x0A) { // LF
  29046. this.nextChar();
  29047. }
  29048. break;
  29049. } else if (ch === 0x0A) { // LF
  29050. this.nextChar();
  29051. break;
  29052. }
  29053. ch = this.nextChar();
  29054. }
  29055. }
  29056. };
  29057. return Lexer;
  29058. })();
  29059. var Linearization = {
  29060. create: function LinearizationCreate(stream) {
  29061. function getInt(name, allowZeroValue) {
  29062. var obj = linDict.get(name);
  29063. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29064. return obj;
  29065. }
  29066. throw new Error('The "' + name + '" parameter in the linearization ' +
  29067. 'dictionary is invalid.');
  29068. }
  29069. function getHints() {
  29070. var hints = linDict.get('H'), hintsLength, item;
  29071. if (isArray(hints) &&
  29072. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29073. for (var index = 0; index < hintsLength; index++) {
  29074. if (!(isInt(item = hints[index]) && item > 0)) {
  29075. throw new Error('Hint (' + index +
  29076. ') in the linearization dictionary is invalid.');
  29077. }
  29078. }
  29079. return hints;
  29080. }
  29081. throw new Error('Hint array in the linearization dictionary is invalid.');
  29082. }
  29083. var parser = new Parser(new Lexer(stream), false, null);
  29084. var obj1 = parser.getObj();
  29085. var obj2 = parser.getObj();
  29086. var obj3 = parser.getObj();
  29087. var linDict = parser.getObj();
  29088. var obj, length;
  29089. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29090. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29091. return null; // No valid linearization dictionary found.
  29092. } else if ((length = getInt('L')) !== stream.length) {
  29093. throw new Error('The "L" parameter in the linearization dictionary ' +
  29094. 'does not equal the stream length.');
  29095. }
  29096. return {
  29097. length: length,
  29098. hints: getHints(),
  29099. objectNumberFirst: getInt('O'),
  29100. endFirst: getInt('E'),
  29101. numPages: getInt('N'),
  29102. mainXRefEntriesOffset: getInt('T'),
  29103. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29104. };
  29105. }
  29106. };
  29107. var PostScriptParser = (function PostScriptParserClosure() {
  29108. function PostScriptParser(lexer) {
  29109. this.lexer = lexer;
  29110. this.operators = [];
  29111. this.token = null;
  29112. this.prev = null;
  29113. }
  29114. PostScriptParser.prototype = {
  29115. nextToken: function PostScriptParser_nextToken() {
  29116. this.prev = this.token;
  29117. this.token = this.lexer.getToken();
  29118. },
  29119. accept: function PostScriptParser_accept(type) {
  29120. if (this.token.type === type) {
  29121. this.nextToken();
  29122. return true;
  29123. }
  29124. return false;
  29125. },
  29126. expect: function PostScriptParser_expect(type) {
  29127. if (this.accept(type)) {
  29128. return true;
  29129. }
  29130. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29131. type + '.');
  29132. },
  29133. parse: function PostScriptParser_parse() {
  29134. this.nextToken();
  29135. this.expect(PostScriptTokenTypes.LBRACE);
  29136. this.parseBlock();
  29137. this.expect(PostScriptTokenTypes.RBRACE);
  29138. return this.operators;
  29139. },
  29140. parseBlock: function PostScriptParser_parseBlock() {
  29141. while (true) {
  29142. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29143. this.operators.push(this.prev.value);
  29144. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29145. this.operators.push(this.prev.value);
  29146. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29147. this.parseCondition();
  29148. } else {
  29149. return;
  29150. }
  29151. }
  29152. },
  29153. parseCondition: function PostScriptParser_parseCondition() {
  29154. // Add two place holders that will be updated later
  29155. var conditionLocation = this.operators.length;
  29156. this.operators.push(null, null);
  29157. this.parseBlock();
  29158. this.expect(PostScriptTokenTypes.RBRACE);
  29159. if (this.accept(PostScriptTokenTypes.IF)) {
  29160. // The true block is right after the 'if' so it just falls through on
  29161. // true else it jumps and skips the true block.
  29162. this.operators[conditionLocation] = this.operators.length;
  29163. this.operators[conditionLocation + 1] = 'jz';
  29164. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29165. var jumpLocation = this.operators.length;
  29166. this.operators.push(null, null);
  29167. var endOfTrue = this.operators.length;
  29168. this.parseBlock();
  29169. this.expect(PostScriptTokenTypes.RBRACE);
  29170. this.expect(PostScriptTokenTypes.IFELSE);
  29171. // The jump is added at the end of the true block to skip the false
  29172. // block.
  29173. this.operators[jumpLocation] = this.operators.length;
  29174. this.operators[jumpLocation + 1] = 'j';
  29175. this.operators[conditionLocation] = endOfTrue;
  29176. this.operators[conditionLocation + 1] = 'jz';
  29177. } else {
  29178. error('PS Function: error parsing conditional.');
  29179. }
  29180. }
  29181. };
  29182. return PostScriptParser;
  29183. })();
  29184. var PostScriptTokenTypes = {
  29185. LBRACE: 0,
  29186. RBRACE: 1,
  29187. NUMBER: 2,
  29188. OPERATOR: 3,
  29189. IF: 4,
  29190. IFELSE: 5
  29191. };
  29192. var PostScriptToken = (function PostScriptTokenClosure() {
  29193. function PostScriptToken(type, value) {
  29194. this.type = type;
  29195. this.value = value;
  29196. }
  29197. var opCache = {};
  29198. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29199. var opValue = opCache[op];
  29200. if (opValue) {
  29201. return opValue;
  29202. }
  29203. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29204. };
  29205. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29206. '{');
  29207. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29208. '}');
  29209. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29210. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29211. 'IFELSE');
  29212. return PostScriptToken;
  29213. })();
  29214. var PostScriptLexer = (function PostScriptLexerClosure() {
  29215. function PostScriptLexer(stream) {
  29216. this.stream = stream;
  29217. this.nextChar();
  29218. this.strBuf = [];
  29219. }
  29220. PostScriptLexer.prototype = {
  29221. nextChar: function PostScriptLexer_nextChar() {
  29222. return (this.currentChar = this.stream.getByte());
  29223. },
  29224. getToken: function PostScriptLexer_getToken() {
  29225. var comment = false;
  29226. var ch = this.currentChar;
  29227. // skip comments
  29228. while (true) {
  29229. if (ch < 0) {
  29230. return EOF;
  29231. }
  29232. if (comment) {
  29233. if (ch === 0x0A || ch === 0x0D) {
  29234. comment = false;
  29235. }
  29236. } else if (ch === 0x25) { // '%'
  29237. comment = true;
  29238. } else if (!Lexer.isSpace(ch)) {
  29239. break;
  29240. }
  29241. ch = this.nextChar();
  29242. }
  29243. switch (ch | 0) {
  29244. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29245. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29246. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29247. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29248. this.getNumber());
  29249. case 0x7B: // '{'
  29250. this.nextChar();
  29251. return PostScriptToken.LBRACE;
  29252. case 0x7D: // '}'
  29253. this.nextChar();
  29254. return PostScriptToken.RBRACE;
  29255. }
  29256. // operator
  29257. var strBuf = this.strBuf;
  29258. strBuf.length = 0;
  29259. strBuf[0] = String.fromCharCode(ch);
  29260. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29261. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29262. strBuf.push(String.fromCharCode(ch));
  29263. }
  29264. var str = strBuf.join('');
  29265. switch (str.toLowerCase()) {
  29266. case 'if':
  29267. return PostScriptToken.IF;
  29268. case 'ifelse':
  29269. return PostScriptToken.IFELSE;
  29270. default:
  29271. return PostScriptToken.getOperator(str);
  29272. }
  29273. },
  29274. getNumber: function PostScriptLexer_getNumber() {
  29275. var ch = this.currentChar;
  29276. var strBuf = this.strBuf;
  29277. strBuf.length = 0;
  29278. strBuf[0] = String.fromCharCode(ch);
  29279. while ((ch = this.nextChar()) >= 0) {
  29280. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29281. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29282. strBuf.push(String.fromCharCode(ch));
  29283. } else {
  29284. break;
  29285. }
  29286. }
  29287. var value = parseFloat(strBuf.join(''));
  29288. if (isNaN(value)) {
  29289. error('Invalid floating point number: ' + value);
  29290. }
  29291. return value;
  29292. }
  29293. };
  29294. return PostScriptLexer;
  29295. })();
  29296. var Stream = (function StreamClosure() {
  29297. function Stream(arrayBuffer, start, length, dict) {
  29298. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29299. arrayBuffer : new Uint8Array(arrayBuffer));
  29300. this.start = start || 0;
  29301. this.pos = this.start;
  29302. this.end = (start + length) || this.bytes.length;
  29303. this.dict = dict;
  29304. }
  29305. // required methods for a stream. if a particular stream does not
  29306. // implement these, an error should be thrown
  29307. Stream.prototype = {
  29308. get length() {
  29309. return this.end - this.start;
  29310. },
  29311. get isEmpty() {
  29312. return this.length === 0;
  29313. },
  29314. getByte: function Stream_getByte() {
  29315. if (this.pos >= this.end) {
  29316. return -1;
  29317. }
  29318. return this.bytes[this.pos++];
  29319. },
  29320. getUint16: function Stream_getUint16() {
  29321. var b0 = this.getByte();
  29322. var b1 = this.getByte();
  29323. return (b0 << 8) + b1;
  29324. },
  29325. getInt32: function Stream_getInt32() {
  29326. var b0 = this.getByte();
  29327. var b1 = this.getByte();
  29328. var b2 = this.getByte();
  29329. var b3 = this.getByte();
  29330. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29331. },
  29332. // returns subarray of original buffer
  29333. // should only be read
  29334. getBytes: function Stream_getBytes(length) {
  29335. var bytes = this.bytes;
  29336. var pos = this.pos;
  29337. var strEnd = this.end;
  29338. if (!length) {
  29339. return bytes.subarray(pos, strEnd);
  29340. }
  29341. var end = pos + length;
  29342. if (end > strEnd) {
  29343. end = strEnd;
  29344. }
  29345. this.pos = end;
  29346. return bytes.subarray(pos, end);
  29347. },
  29348. peekByte: function Stream_peekByte() {
  29349. var peekedByte = this.getByte();
  29350. this.pos--;
  29351. return peekedByte;
  29352. },
  29353. peekBytes: function Stream_peekBytes(length) {
  29354. var bytes = this.getBytes(length);
  29355. this.pos -= bytes.length;
  29356. return bytes;
  29357. },
  29358. skip: function Stream_skip(n) {
  29359. if (!n) {
  29360. n = 1;
  29361. }
  29362. this.pos += n;
  29363. },
  29364. reset: function Stream_reset() {
  29365. this.pos = this.start;
  29366. },
  29367. moveStart: function Stream_moveStart() {
  29368. this.start = this.pos;
  29369. },
  29370. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29371. return new Stream(this.bytes.buffer, start, length, dict);
  29372. },
  29373. isStream: true
  29374. };
  29375. return Stream;
  29376. })();
  29377. var StringStream = (function StringStreamClosure() {
  29378. function StringStream(str) {
  29379. var length = str.length;
  29380. var bytes = new Uint8Array(length);
  29381. for (var n = 0; n < length; ++n) {
  29382. bytes[n] = str.charCodeAt(n);
  29383. }
  29384. Stream.call(this, bytes);
  29385. }
  29386. StringStream.prototype = Stream.prototype;
  29387. return StringStream;
  29388. })();
  29389. // super class for the decoding streams
  29390. var DecodeStream = (function DecodeStreamClosure() {
  29391. // Lots of DecodeStreams are created whose buffers are never used. For these
  29392. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29393. // having special cases that would be required if we used |null| for an empty
  29394. // buffer.
  29395. var emptyBuffer = new Uint8Array(0);
  29396. function DecodeStream(maybeMinBufferLength) {
  29397. this.pos = 0;
  29398. this.bufferLength = 0;
  29399. this.eof = false;
  29400. this.buffer = emptyBuffer;
  29401. this.minBufferLength = 512;
  29402. if (maybeMinBufferLength) {
  29403. // Compute the first power of two that is as big as maybeMinBufferLength.
  29404. while (this.minBufferLength < maybeMinBufferLength) {
  29405. this.minBufferLength *= 2;
  29406. }
  29407. }
  29408. }
  29409. DecodeStream.prototype = {
  29410. get isEmpty() {
  29411. while (!this.eof && this.bufferLength === 0) {
  29412. this.readBlock();
  29413. }
  29414. return this.bufferLength === 0;
  29415. },
  29416. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29417. var buffer = this.buffer;
  29418. if (requested <= buffer.byteLength) {
  29419. return buffer;
  29420. }
  29421. var size = this.minBufferLength;
  29422. while (size < requested) {
  29423. size *= 2;
  29424. }
  29425. var buffer2 = new Uint8Array(size);
  29426. buffer2.set(buffer);
  29427. return (this.buffer = buffer2);
  29428. },
  29429. getByte: function DecodeStream_getByte() {
  29430. var pos = this.pos;
  29431. while (this.bufferLength <= pos) {
  29432. if (this.eof) {
  29433. return -1;
  29434. }
  29435. this.readBlock();
  29436. }
  29437. return this.buffer[this.pos++];
  29438. },
  29439. getUint16: function DecodeStream_getUint16() {
  29440. var b0 = this.getByte();
  29441. var b1 = this.getByte();
  29442. return (b0 << 8) + b1;
  29443. },
  29444. getInt32: function DecodeStream_getInt32() {
  29445. var b0 = this.getByte();
  29446. var b1 = this.getByte();
  29447. var b2 = this.getByte();
  29448. var b3 = this.getByte();
  29449. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29450. },
  29451. getBytes: function DecodeStream_getBytes(length) {
  29452. var end, pos = this.pos;
  29453. if (length) {
  29454. this.ensureBuffer(pos + length);
  29455. end = pos + length;
  29456. while (!this.eof && this.bufferLength < end) {
  29457. this.readBlock();
  29458. }
  29459. var bufEnd = this.bufferLength;
  29460. if (end > bufEnd) {
  29461. end = bufEnd;
  29462. }
  29463. } else {
  29464. while (!this.eof) {
  29465. this.readBlock();
  29466. }
  29467. end = this.bufferLength;
  29468. }
  29469. this.pos = end;
  29470. return this.buffer.subarray(pos, end);
  29471. },
  29472. peekByte: function DecodeStream_peekByte() {
  29473. var peekedByte = this.getByte();
  29474. this.pos--;
  29475. return peekedByte;
  29476. },
  29477. peekBytes: function DecodeStream_peekBytes(length) {
  29478. var bytes = this.getBytes(length);
  29479. this.pos -= bytes.length;
  29480. return bytes;
  29481. },
  29482. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29483. var end = start + length;
  29484. while (this.bufferLength <= end && !this.eof) {
  29485. this.readBlock();
  29486. }
  29487. return new Stream(this.buffer, start, length, dict);
  29488. },
  29489. skip: function DecodeStream_skip(n) {
  29490. if (!n) {
  29491. n = 1;
  29492. }
  29493. this.pos += n;
  29494. },
  29495. reset: function DecodeStream_reset() {
  29496. this.pos = 0;
  29497. },
  29498. getBaseStreams: function DecodeStream_getBaseStreams() {
  29499. if (this.str && this.str.getBaseStreams) {
  29500. return this.str.getBaseStreams();
  29501. }
  29502. return [];
  29503. }
  29504. };
  29505. return DecodeStream;
  29506. })();
  29507. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29508. function StreamsSequenceStream(streams) {
  29509. this.streams = streams;
  29510. DecodeStream.call(this, /* maybeLength = */ null);
  29511. }
  29512. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29513. StreamsSequenceStream.prototype.readBlock =
  29514. function streamSequenceStreamReadBlock() {
  29515. var streams = this.streams;
  29516. if (streams.length === 0) {
  29517. this.eof = true;
  29518. return;
  29519. }
  29520. var stream = streams.shift();
  29521. var chunk = stream.getBytes();
  29522. var bufferLength = this.bufferLength;
  29523. var newLength = bufferLength + chunk.length;
  29524. var buffer = this.ensureBuffer(newLength);
  29525. buffer.set(chunk, bufferLength);
  29526. this.bufferLength = newLength;
  29527. };
  29528. StreamsSequenceStream.prototype.getBaseStreams =
  29529. function StreamsSequenceStream_getBaseStreams() {
  29530. var baseStreams = [];
  29531. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29532. var stream = this.streams[i];
  29533. if (stream.getBaseStreams) {
  29534. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29535. }
  29536. }
  29537. return baseStreams;
  29538. };
  29539. return StreamsSequenceStream;
  29540. })();
  29541. var FlateStream = (function FlateStreamClosure() {
  29542. var codeLenCodeMap = new Uint32Array([
  29543. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29544. ]);
  29545. var lengthDecode = new Uint32Array([
  29546. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29547. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29548. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29549. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29550. ]);
  29551. var distDecode = new Uint32Array([
  29552. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29553. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29554. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29555. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29556. ]);
  29557. var fixedLitCodeTab = [new Uint32Array([
  29558. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29559. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29560. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29561. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29562. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29563. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29564. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29565. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29566. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29567. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29568. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29569. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29570. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29571. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29572. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29573. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29574. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29575. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29576. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29577. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29578. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29579. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29580. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29581. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29582. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29583. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29584. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29585. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29586. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29587. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29588. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29589. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29590. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29591. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29592. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29593. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29594. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29595. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29596. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29597. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29598. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29599. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29600. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29601. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29602. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29603. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29604. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29605. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29606. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29607. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29608. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29609. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29610. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29611. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29612. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29613. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29614. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29615. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29616. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29617. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29618. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29619. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29620. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29621. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29622. ]), 9];
  29623. var fixedDistCodeTab = [new Uint32Array([
  29624. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29625. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29626. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29627. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29628. ]), 5];
  29629. function FlateStream(str, maybeLength) {
  29630. this.str = str;
  29631. this.dict = str.dict;
  29632. var cmf = str.getByte();
  29633. var flg = str.getByte();
  29634. if (cmf === -1 || flg === -1) {
  29635. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29636. }
  29637. if ((cmf & 0x0f) !== 0x08) {
  29638. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29639. }
  29640. if ((((cmf << 8) + flg) % 31) !== 0) {
  29641. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29642. }
  29643. if (flg & 0x20) {
  29644. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29645. }
  29646. this.codeSize = 0;
  29647. this.codeBuf = 0;
  29648. DecodeStream.call(this, maybeLength);
  29649. }
  29650. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29651. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29652. var str = this.str;
  29653. var codeSize = this.codeSize;
  29654. var codeBuf = this.codeBuf;
  29655. var b;
  29656. while (codeSize < bits) {
  29657. if ((b = str.getByte()) === -1) {
  29658. error('Bad encoding in flate stream');
  29659. }
  29660. codeBuf |= b << codeSize;
  29661. codeSize += 8;
  29662. }
  29663. b = codeBuf & ((1 << bits) - 1);
  29664. this.codeBuf = codeBuf >> bits;
  29665. this.codeSize = codeSize -= bits;
  29666. return b;
  29667. };
  29668. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29669. var str = this.str;
  29670. var codes = table[0];
  29671. var maxLen = table[1];
  29672. var codeSize = this.codeSize;
  29673. var codeBuf = this.codeBuf;
  29674. var b;
  29675. while (codeSize < maxLen) {
  29676. if ((b = str.getByte()) === -1) {
  29677. // premature end of stream. code might however still be valid.
  29678. // codeSize < codeLen check below guards against incomplete codeVal.
  29679. break;
  29680. }
  29681. codeBuf |= (b << codeSize);
  29682. codeSize += 8;
  29683. }
  29684. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29685. var codeLen = code >> 16;
  29686. var codeVal = code & 0xffff;
  29687. if (codeLen < 1 || codeSize < codeLen) {
  29688. error('Bad encoding in flate stream');
  29689. }
  29690. this.codeBuf = (codeBuf >> codeLen);
  29691. this.codeSize = (codeSize - codeLen);
  29692. return codeVal;
  29693. };
  29694. FlateStream.prototype.generateHuffmanTable =
  29695. function flateStreamGenerateHuffmanTable(lengths) {
  29696. var n = lengths.length;
  29697. // find max code length
  29698. var maxLen = 0;
  29699. var i;
  29700. for (i = 0; i < n; ++i) {
  29701. if (lengths[i] > maxLen) {
  29702. maxLen = lengths[i];
  29703. }
  29704. }
  29705. // build the table
  29706. var size = 1 << maxLen;
  29707. var codes = new Uint32Array(size);
  29708. for (var len = 1, code = 0, skip = 2;
  29709. len <= maxLen;
  29710. ++len, code <<= 1, skip <<= 1) {
  29711. for (var val = 0; val < n; ++val) {
  29712. if (lengths[val] === len) {
  29713. // bit-reverse the code
  29714. var code2 = 0;
  29715. var t = code;
  29716. for (i = 0; i < len; ++i) {
  29717. code2 = (code2 << 1) | (t & 1);
  29718. t >>= 1;
  29719. }
  29720. // fill the table entries
  29721. for (i = code2; i < size; i += skip) {
  29722. codes[i] = (len << 16) | val;
  29723. }
  29724. ++code;
  29725. }
  29726. }
  29727. }
  29728. return [codes, maxLen];
  29729. };
  29730. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29731. var buffer, len;
  29732. var str = this.str;
  29733. // read block header
  29734. var hdr = this.getBits(3);
  29735. if (hdr & 1) {
  29736. this.eof = true;
  29737. }
  29738. hdr >>= 1;
  29739. if (hdr === 0) { // uncompressed block
  29740. var b;
  29741. if ((b = str.getByte()) === -1) {
  29742. error('Bad block header in flate stream');
  29743. }
  29744. var blockLen = b;
  29745. if ((b = str.getByte()) === -1) {
  29746. error('Bad block header in flate stream');
  29747. }
  29748. blockLen |= (b << 8);
  29749. if ((b = str.getByte()) === -1) {
  29750. error('Bad block header in flate stream');
  29751. }
  29752. var check = b;
  29753. if ((b = str.getByte()) === -1) {
  29754. error('Bad block header in flate stream');
  29755. }
  29756. check |= (b << 8);
  29757. if (check !== (~blockLen & 0xffff) &&
  29758. (blockLen !== 0 || check !== 0)) {
  29759. // Ignoring error for bad "empty" block (see issue 1277)
  29760. error('Bad uncompressed block length in flate stream');
  29761. }
  29762. this.codeBuf = 0;
  29763. this.codeSize = 0;
  29764. var bufferLength = this.bufferLength;
  29765. buffer = this.ensureBuffer(bufferLength + blockLen);
  29766. var end = bufferLength + blockLen;
  29767. this.bufferLength = end;
  29768. if (blockLen === 0) {
  29769. if (str.peekByte() === -1) {
  29770. this.eof = true;
  29771. }
  29772. } else {
  29773. for (var n = bufferLength; n < end; ++n) {
  29774. if ((b = str.getByte()) === -1) {
  29775. this.eof = true;
  29776. break;
  29777. }
  29778. buffer[n] = b;
  29779. }
  29780. }
  29781. return;
  29782. }
  29783. var litCodeTable;
  29784. var distCodeTable;
  29785. if (hdr === 1) { // compressed block, fixed codes
  29786. litCodeTable = fixedLitCodeTab;
  29787. distCodeTable = fixedDistCodeTab;
  29788. } else if (hdr === 2) { // compressed block, dynamic codes
  29789. var numLitCodes = this.getBits(5) + 257;
  29790. var numDistCodes = this.getBits(5) + 1;
  29791. var numCodeLenCodes = this.getBits(4) + 4;
  29792. // build the code lengths code table
  29793. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29794. var i;
  29795. for (i = 0; i < numCodeLenCodes; ++i) {
  29796. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29797. }
  29798. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29799. // build the literal and distance code tables
  29800. len = 0;
  29801. i = 0;
  29802. var codes = numLitCodes + numDistCodes;
  29803. var codeLengths = new Uint8Array(codes);
  29804. var bitsLength, bitsOffset, what;
  29805. while (i < codes) {
  29806. var code = this.getCode(codeLenCodeTab);
  29807. if (code === 16) {
  29808. bitsLength = 2; bitsOffset = 3; what = len;
  29809. } else if (code === 17) {
  29810. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29811. } else if (code === 18) {
  29812. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29813. } else {
  29814. codeLengths[i++] = len = code;
  29815. continue;
  29816. }
  29817. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29818. while (repeatLength-- > 0) {
  29819. codeLengths[i++] = what;
  29820. }
  29821. }
  29822. litCodeTable =
  29823. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29824. distCodeTable =
  29825. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29826. } else {
  29827. error('Unknown block type in flate stream');
  29828. }
  29829. buffer = this.buffer;
  29830. var limit = buffer ? buffer.length : 0;
  29831. var pos = this.bufferLength;
  29832. while (true) {
  29833. var code1 = this.getCode(litCodeTable);
  29834. if (code1 < 256) {
  29835. if (pos + 1 >= limit) {
  29836. buffer = this.ensureBuffer(pos + 1);
  29837. limit = buffer.length;
  29838. }
  29839. buffer[pos++] = code1;
  29840. continue;
  29841. }
  29842. if (code1 === 256) {
  29843. this.bufferLength = pos;
  29844. return;
  29845. }
  29846. code1 -= 257;
  29847. code1 = lengthDecode[code1];
  29848. var code2 = code1 >> 16;
  29849. if (code2 > 0) {
  29850. code2 = this.getBits(code2);
  29851. }
  29852. len = (code1 & 0xffff) + code2;
  29853. code1 = this.getCode(distCodeTable);
  29854. code1 = distDecode[code1];
  29855. code2 = code1 >> 16;
  29856. if (code2 > 0) {
  29857. code2 = this.getBits(code2);
  29858. }
  29859. var dist = (code1 & 0xffff) + code2;
  29860. if (pos + len >= limit) {
  29861. buffer = this.ensureBuffer(pos + len);
  29862. limit = buffer.length;
  29863. }
  29864. for (var k = 0; k < len; ++k, ++pos) {
  29865. buffer[pos] = buffer[pos - dist];
  29866. }
  29867. }
  29868. };
  29869. return FlateStream;
  29870. })();
  29871. var PredictorStream = (function PredictorStreamClosure() {
  29872. function PredictorStream(str, maybeLength, params) {
  29873. var predictor = this.predictor = params.get('Predictor') || 1;
  29874. if (predictor <= 1) {
  29875. return str; // no prediction
  29876. }
  29877. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29878. error('Unsupported predictor: ' + predictor);
  29879. }
  29880. if (predictor === 2) {
  29881. this.readBlock = this.readBlockTiff;
  29882. } else {
  29883. this.readBlock = this.readBlockPng;
  29884. }
  29885. this.str = str;
  29886. this.dict = str.dict;
  29887. var colors = this.colors = params.get('Colors') || 1;
  29888. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29889. var columns = this.columns = params.get('Columns') || 1;
  29890. this.pixBytes = (colors * bits + 7) >> 3;
  29891. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29892. DecodeStream.call(this, maybeLength);
  29893. return this;
  29894. }
  29895. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29896. PredictorStream.prototype.readBlockTiff =
  29897. function predictorStreamReadBlockTiff() {
  29898. var rowBytes = this.rowBytes;
  29899. var bufferLength = this.bufferLength;
  29900. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29901. var bits = this.bits;
  29902. var colors = this.colors;
  29903. var rawBytes = this.str.getBytes(rowBytes);
  29904. this.eof = !rawBytes.length;
  29905. if (this.eof) {
  29906. return;
  29907. }
  29908. var inbuf = 0, outbuf = 0;
  29909. var inbits = 0, outbits = 0;
  29910. var pos = bufferLength;
  29911. var i;
  29912. if (bits === 1) {
  29913. for (i = 0; i < rowBytes; ++i) {
  29914. var c = rawBytes[i];
  29915. inbuf = (inbuf << 8) | c;
  29916. // bitwise addition is exclusive or
  29917. // first shift inbuf and then add
  29918. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29919. // truncate inbuf (assumes colors < 16)
  29920. inbuf &= 0xFFFF;
  29921. }
  29922. } else if (bits === 8) {
  29923. for (i = 0; i < colors; ++i) {
  29924. buffer[pos++] = rawBytes[i];
  29925. }
  29926. for (; i < rowBytes; ++i) {
  29927. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29928. pos++;
  29929. }
  29930. } else {
  29931. var compArray = new Uint8Array(colors + 1);
  29932. var bitMask = (1 << bits) - 1;
  29933. var j = 0, k = bufferLength;
  29934. var columns = this.columns;
  29935. for (i = 0; i < columns; ++i) {
  29936. for (var kk = 0; kk < colors; ++kk) {
  29937. if (inbits < bits) {
  29938. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29939. inbits += 8;
  29940. }
  29941. compArray[kk] = (compArray[kk] +
  29942. (inbuf >> (inbits - bits))) & bitMask;
  29943. inbits -= bits;
  29944. outbuf = (outbuf << bits) | compArray[kk];
  29945. outbits += bits;
  29946. if (outbits >= 8) {
  29947. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29948. outbits -= 8;
  29949. }
  29950. }
  29951. }
  29952. if (outbits > 0) {
  29953. buffer[k++] = (outbuf << (8 - outbits)) +
  29954. (inbuf & ((1 << (8 - outbits)) - 1));
  29955. }
  29956. }
  29957. this.bufferLength += rowBytes;
  29958. };
  29959. PredictorStream.prototype.readBlockPng =
  29960. function predictorStreamReadBlockPng() {
  29961. var rowBytes = this.rowBytes;
  29962. var pixBytes = this.pixBytes;
  29963. var predictor = this.str.getByte();
  29964. var rawBytes = this.str.getBytes(rowBytes);
  29965. this.eof = !rawBytes.length;
  29966. if (this.eof) {
  29967. return;
  29968. }
  29969. var bufferLength = this.bufferLength;
  29970. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29971. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29972. if (prevRow.length === 0) {
  29973. prevRow = new Uint8Array(rowBytes);
  29974. }
  29975. var i, j = bufferLength, up, c;
  29976. switch (predictor) {
  29977. case 0:
  29978. for (i = 0; i < rowBytes; ++i) {
  29979. buffer[j++] = rawBytes[i];
  29980. }
  29981. break;
  29982. case 1:
  29983. for (i = 0; i < pixBytes; ++i) {
  29984. buffer[j++] = rawBytes[i];
  29985. }
  29986. for (; i < rowBytes; ++i) {
  29987. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29988. j++;
  29989. }
  29990. break;
  29991. case 2:
  29992. for (i = 0; i < rowBytes; ++i) {
  29993. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29994. }
  29995. break;
  29996. case 3:
  29997. for (i = 0; i < pixBytes; ++i) {
  29998. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  29999. }
  30000. for (; i < rowBytes; ++i) {
  30001. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30002. rawBytes[i]) & 0xFF;
  30003. j++;
  30004. }
  30005. break;
  30006. case 4:
  30007. // we need to save the up left pixels values. the simplest way
  30008. // is to create a new buffer
  30009. for (i = 0; i < pixBytes; ++i) {
  30010. up = prevRow[i];
  30011. c = rawBytes[i];
  30012. buffer[j++] = up + c;
  30013. }
  30014. for (; i < rowBytes; ++i) {
  30015. up = prevRow[i];
  30016. var upLeft = prevRow[i - pixBytes];
  30017. var left = buffer[j - pixBytes];
  30018. var p = left + up - upLeft;
  30019. var pa = p - left;
  30020. if (pa < 0) {
  30021. pa = -pa;
  30022. }
  30023. var pb = p - up;
  30024. if (pb < 0) {
  30025. pb = -pb;
  30026. }
  30027. var pc = p - upLeft;
  30028. if (pc < 0) {
  30029. pc = -pc;
  30030. }
  30031. c = rawBytes[i];
  30032. if (pa <= pb && pa <= pc) {
  30033. buffer[j++] = left + c;
  30034. } else if (pb <= pc) {
  30035. buffer[j++] = up + c;
  30036. } else {
  30037. buffer[j++] = upLeft + c;
  30038. }
  30039. }
  30040. break;
  30041. default:
  30042. error('Unsupported predictor: ' + predictor);
  30043. }
  30044. this.bufferLength += rowBytes;
  30045. };
  30046. return PredictorStream;
  30047. })();
  30048. /**
  30049. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30050. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30051. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30052. * a library to decode these images and the stream behaves like all the other
  30053. * DecodeStreams.
  30054. */
  30055. var JpegStream = (function JpegStreamClosure() {
  30056. function JpegStream(stream, maybeLength, dict, xref) {
  30057. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30058. // Note: this seems to mainly affect inline images.
  30059. var ch;
  30060. while ((ch = stream.getByte()) !== -1) {
  30061. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30062. stream.skip(-1); // Reset the stream position to the SOI.
  30063. break;
  30064. }
  30065. }
  30066. this.stream = stream;
  30067. this.maybeLength = maybeLength;
  30068. this.dict = dict;
  30069. DecodeStream.call(this, maybeLength);
  30070. }
  30071. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30072. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30073. get: function JpegStream_bytes() {
  30074. // If this.maybeLength is null, we'll get the entire stream.
  30075. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30076. },
  30077. configurable: true
  30078. });
  30079. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30080. if (this.bufferLength) {
  30081. return;
  30082. }
  30083. try {
  30084. var jpegImage = new JpegImage();
  30085. // checking if values needs to be transformed before conversion
  30086. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30087. var decodeArr = this.dict.get('Decode');
  30088. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30089. var decodeArrLength = decodeArr.length;
  30090. var transform = new Int32Array(decodeArrLength);
  30091. var transformNeeded = false;
  30092. var maxValue = (1 << bitsPerComponent) - 1;
  30093. for (var i = 0; i < decodeArrLength; i += 2) {
  30094. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30095. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30096. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30097. transformNeeded = true;
  30098. }
  30099. }
  30100. if (transformNeeded) {
  30101. jpegImage.decodeTransform = transform;
  30102. }
  30103. }
  30104. jpegImage.parse(this.bytes);
  30105. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30106. this.forceRGB);
  30107. this.buffer = data;
  30108. this.bufferLength = data.length;
  30109. this.eof = true;
  30110. } catch (e) {
  30111. error('JPEG error: ' + e);
  30112. }
  30113. };
  30114. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30115. this.ensureBuffer();
  30116. return this.buffer;
  30117. };
  30118. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30119. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30120. };
  30121. /**
  30122. * Checks if the image can be decoded and displayed by the browser without any
  30123. * further processing such as color space conversions.
  30124. */
  30125. JpegStream.prototype.isNativelySupported =
  30126. function JpegStream_isNativelySupported(xref, res) {
  30127. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30128. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30129. };
  30130. /**
  30131. * Checks if the image can be decoded by the browser.
  30132. */
  30133. JpegStream.prototype.isNativelyDecodable =
  30134. function JpegStream_isNativelyDecodable(xref, res) {
  30135. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30136. var numComps = cs.numComps;
  30137. return numComps === 1 || numComps === 3;
  30138. };
  30139. return JpegStream;
  30140. })();
  30141. /**
  30142. * For JPEG 2000's we use a library to decode these images and
  30143. * the stream behaves like all the other DecodeStreams.
  30144. */
  30145. var JpxStream = (function JpxStreamClosure() {
  30146. function JpxStream(stream, maybeLength, dict) {
  30147. this.stream = stream;
  30148. this.maybeLength = maybeLength;
  30149. this.dict = dict;
  30150. DecodeStream.call(this, maybeLength);
  30151. }
  30152. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30153. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30154. get: function JpxStream_bytes() {
  30155. // If this.maybeLength is null, we'll get the entire stream.
  30156. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30157. },
  30158. configurable: true
  30159. });
  30160. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30161. if (this.bufferLength) {
  30162. return;
  30163. }
  30164. var jpxImage = new JpxImage();
  30165. jpxImage.parse(this.bytes);
  30166. var width = jpxImage.width;
  30167. var height = jpxImage.height;
  30168. var componentsCount = jpxImage.componentsCount;
  30169. var tileCount = jpxImage.tiles.length;
  30170. if (tileCount === 1) {
  30171. this.buffer = jpxImage.tiles[0].items;
  30172. } else {
  30173. var data = new Uint8Array(width * height * componentsCount);
  30174. for (var k = 0; k < tileCount; k++) {
  30175. var tileComponents = jpxImage.tiles[k];
  30176. var tileWidth = tileComponents.width;
  30177. var tileHeight = tileComponents.height;
  30178. var tileLeft = tileComponents.left;
  30179. var tileTop = tileComponents.top;
  30180. var src = tileComponents.items;
  30181. var srcPosition = 0;
  30182. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30183. var imgRowSize = width * componentsCount;
  30184. var tileRowSize = tileWidth * componentsCount;
  30185. for (var j = 0; j < tileHeight; j++) {
  30186. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30187. data.set(rowBytes, dataPosition);
  30188. srcPosition += tileRowSize;
  30189. dataPosition += imgRowSize;
  30190. }
  30191. }
  30192. this.buffer = data;
  30193. }
  30194. this.bufferLength = this.buffer.length;
  30195. this.eof = true;
  30196. };
  30197. return JpxStream;
  30198. })();
  30199. /**
  30200. * For JBIG2's we use a library to decode these images and
  30201. * the stream behaves like all the other DecodeStreams.
  30202. */
  30203. var Jbig2Stream = (function Jbig2StreamClosure() {
  30204. function Jbig2Stream(stream, maybeLength, dict) {
  30205. this.stream = stream;
  30206. this.maybeLength = maybeLength;
  30207. this.dict = dict;
  30208. DecodeStream.call(this, maybeLength);
  30209. }
  30210. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30211. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30212. get: function Jbig2Stream_bytes() {
  30213. // If this.maybeLength is null, we'll get the entire stream.
  30214. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30215. },
  30216. configurable: true
  30217. });
  30218. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30219. if (this.bufferLength) {
  30220. return;
  30221. }
  30222. var jbig2Image = new Jbig2Image();
  30223. var chunks = [], xref = this.dict.xref;
  30224. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30225. // According to the PDF specification, DecodeParms can be either
  30226. // a dictionary, or an array whose elements are dictionaries.
  30227. if (isArray(decodeParams)) {
  30228. if (decodeParams.length > 1) {
  30229. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30230. 'not supported.');
  30231. }
  30232. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30233. }
  30234. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30235. var globalsStream = decodeParams.get('JBIG2Globals');
  30236. var globals = globalsStream.getBytes();
  30237. chunks.push({data: globals, start: 0, end: globals.length});
  30238. }
  30239. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30240. var data = jbig2Image.parseChunks(chunks);
  30241. var dataLength = data.length;
  30242. // JBIG2 had black as 1 and white as 0, inverting the colors
  30243. for (var i = 0; i < dataLength; i++) {
  30244. data[i] ^= 0xFF;
  30245. }
  30246. this.buffer = data;
  30247. this.bufferLength = dataLength;
  30248. this.eof = true;
  30249. };
  30250. return Jbig2Stream;
  30251. })();
  30252. var DecryptStream = (function DecryptStreamClosure() {
  30253. function DecryptStream(str, maybeLength, decrypt) {
  30254. this.str = str;
  30255. this.dict = str.dict;
  30256. this.decrypt = decrypt;
  30257. this.nextChunk = null;
  30258. this.initialized = false;
  30259. DecodeStream.call(this, maybeLength);
  30260. }
  30261. var chunkSize = 512;
  30262. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30263. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30264. var chunk;
  30265. if (this.initialized) {
  30266. chunk = this.nextChunk;
  30267. } else {
  30268. chunk = this.str.getBytes(chunkSize);
  30269. this.initialized = true;
  30270. }
  30271. if (!chunk || chunk.length === 0) {
  30272. this.eof = true;
  30273. return;
  30274. }
  30275. this.nextChunk = this.str.getBytes(chunkSize);
  30276. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30277. var decrypt = this.decrypt;
  30278. chunk = decrypt(chunk, !hasMoreData);
  30279. var bufferLength = this.bufferLength;
  30280. var i, n = chunk.length;
  30281. var buffer = this.ensureBuffer(bufferLength + n);
  30282. for (i = 0; i < n; i++) {
  30283. buffer[bufferLength++] = chunk[i];
  30284. }
  30285. this.bufferLength = bufferLength;
  30286. };
  30287. return DecryptStream;
  30288. })();
  30289. var Ascii85Stream = (function Ascii85StreamClosure() {
  30290. function Ascii85Stream(str, maybeLength) {
  30291. this.str = str;
  30292. this.dict = str.dict;
  30293. this.input = new Uint8Array(5);
  30294. // Most streams increase in size when decoded, but Ascii85 streams
  30295. // typically shrink by ~20%.
  30296. if (maybeLength) {
  30297. maybeLength = 0.8 * maybeLength;
  30298. }
  30299. DecodeStream.call(this, maybeLength);
  30300. }
  30301. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30302. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30303. var TILDA_CHAR = 0x7E; // '~'
  30304. var Z_LOWER_CHAR = 0x7A; // 'z'
  30305. var EOF = -1;
  30306. var str = this.str;
  30307. var c = str.getByte();
  30308. while (Lexer.isSpace(c)) {
  30309. c = str.getByte();
  30310. }
  30311. if (c === EOF || c === TILDA_CHAR) {
  30312. this.eof = true;
  30313. return;
  30314. }
  30315. var bufferLength = this.bufferLength, buffer;
  30316. var i;
  30317. // special code for z
  30318. if (c === Z_LOWER_CHAR) {
  30319. buffer = this.ensureBuffer(bufferLength + 4);
  30320. for (i = 0; i < 4; ++i) {
  30321. buffer[bufferLength + i] = 0;
  30322. }
  30323. this.bufferLength += 4;
  30324. } else {
  30325. var input = this.input;
  30326. input[0] = c;
  30327. for (i = 1; i < 5; ++i) {
  30328. c = str.getByte();
  30329. while (Lexer.isSpace(c)) {
  30330. c = str.getByte();
  30331. }
  30332. input[i] = c;
  30333. if (c === EOF || c === TILDA_CHAR) {
  30334. break;
  30335. }
  30336. }
  30337. buffer = this.ensureBuffer(bufferLength + i - 1);
  30338. this.bufferLength += i - 1;
  30339. // partial ending;
  30340. if (i < 5) {
  30341. for (; i < 5; ++i) {
  30342. input[i] = 0x21 + 84;
  30343. }
  30344. this.eof = true;
  30345. }
  30346. var t = 0;
  30347. for (i = 0; i < 5; ++i) {
  30348. t = t * 85 + (input[i] - 0x21);
  30349. }
  30350. for (i = 3; i >= 0; --i) {
  30351. buffer[bufferLength + i] = t & 0xFF;
  30352. t >>= 8;
  30353. }
  30354. }
  30355. };
  30356. return Ascii85Stream;
  30357. })();
  30358. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30359. function AsciiHexStream(str, maybeLength) {
  30360. this.str = str;
  30361. this.dict = str.dict;
  30362. this.firstDigit = -1;
  30363. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30364. // by 50%.
  30365. if (maybeLength) {
  30366. maybeLength = 0.5 * maybeLength;
  30367. }
  30368. DecodeStream.call(this, maybeLength);
  30369. }
  30370. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30371. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30372. var UPSTREAM_BLOCK_SIZE = 8000;
  30373. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30374. if (!bytes.length) {
  30375. this.eof = true;
  30376. return;
  30377. }
  30378. var maxDecodeLength = (bytes.length + 1) >> 1;
  30379. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30380. var bufferLength = this.bufferLength;
  30381. var firstDigit = this.firstDigit;
  30382. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30383. var ch = bytes[i], digit;
  30384. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30385. digit = ch & 0x0F;
  30386. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30387. // 'A'-'Z', 'a'-'z'
  30388. digit = (ch & 0x0F) + 9;
  30389. } else if (ch === 0x3E) { // '>'
  30390. this.eof = true;
  30391. break;
  30392. } else { // probably whitespace
  30393. continue; // ignoring
  30394. }
  30395. if (firstDigit < 0) {
  30396. firstDigit = digit;
  30397. } else {
  30398. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30399. firstDigit = -1;
  30400. }
  30401. }
  30402. if (firstDigit >= 0 && this.eof) {
  30403. // incomplete byte
  30404. buffer[bufferLength++] = (firstDigit << 4);
  30405. firstDigit = -1;
  30406. }
  30407. this.firstDigit = firstDigit;
  30408. this.bufferLength = bufferLength;
  30409. };
  30410. return AsciiHexStream;
  30411. })();
  30412. var RunLengthStream = (function RunLengthStreamClosure() {
  30413. function RunLengthStream(str, maybeLength) {
  30414. this.str = str;
  30415. this.dict = str.dict;
  30416. DecodeStream.call(this, maybeLength);
  30417. }
  30418. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30419. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30420. // The repeatHeader has following format. The first byte defines type of run
  30421. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30422. // (in addition to the second byte from the header), n = 129 through 255 -
  30423. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30424. var repeatHeader = this.str.getBytes(2);
  30425. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30426. this.eof = true;
  30427. return;
  30428. }
  30429. var buffer;
  30430. var bufferLength = this.bufferLength;
  30431. var n = repeatHeader[0];
  30432. if (n < 128) {
  30433. // copy n bytes
  30434. buffer = this.ensureBuffer(bufferLength + n + 1);
  30435. buffer[bufferLength++] = repeatHeader[1];
  30436. if (n > 0) {
  30437. var source = this.str.getBytes(n);
  30438. buffer.set(source, bufferLength);
  30439. bufferLength += n;
  30440. }
  30441. } else {
  30442. n = 257 - n;
  30443. var b = repeatHeader[1];
  30444. buffer = this.ensureBuffer(bufferLength + n + 1);
  30445. for (var i = 0; i < n; i++) {
  30446. buffer[bufferLength++] = b;
  30447. }
  30448. }
  30449. this.bufferLength = bufferLength;
  30450. };
  30451. return RunLengthStream;
  30452. })();
  30453. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30454. var ccittEOL = -2;
  30455. var twoDimPass = 0;
  30456. var twoDimHoriz = 1;
  30457. var twoDimVert0 = 2;
  30458. var twoDimVertR1 = 3;
  30459. var twoDimVertL1 = 4;
  30460. var twoDimVertR2 = 5;
  30461. var twoDimVertL2 = 6;
  30462. var twoDimVertR3 = 7;
  30463. var twoDimVertL3 = 8;
  30464. var twoDimTable = [
  30465. [-1, -1], [-1, -1], // 000000x
  30466. [7, twoDimVertL3], // 0000010
  30467. [7, twoDimVertR3], // 0000011
  30468. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30469. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30470. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30471. [4, twoDimPass], [4, twoDimPass],
  30472. [4, twoDimPass], [4, twoDimPass],
  30473. [4, twoDimPass], [4, twoDimPass],
  30474. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30475. [3, twoDimHoriz], [3, twoDimHoriz],
  30476. [3, twoDimHoriz], [3, twoDimHoriz],
  30477. [3, twoDimHoriz], [3, twoDimHoriz],
  30478. [3, twoDimHoriz], [3, twoDimHoriz],
  30479. [3, twoDimHoriz], [3, twoDimHoriz],
  30480. [3, twoDimHoriz], [3, twoDimHoriz],
  30481. [3, twoDimHoriz], [3, twoDimHoriz],
  30482. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30483. [3, twoDimVertL1], [3, twoDimVertL1],
  30484. [3, twoDimVertL1], [3, twoDimVertL1],
  30485. [3, twoDimVertL1], [3, twoDimVertL1],
  30486. [3, twoDimVertL1], [3, twoDimVertL1],
  30487. [3, twoDimVertL1], [3, twoDimVertL1],
  30488. [3, twoDimVertL1], [3, twoDimVertL1],
  30489. [3, twoDimVertL1], [3, twoDimVertL1],
  30490. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30491. [3, twoDimVertR1], [3, twoDimVertR1],
  30492. [3, twoDimVertR1], [3, twoDimVertR1],
  30493. [3, twoDimVertR1], [3, twoDimVertR1],
  30494. [3, twoDimVertR1], [3, twoDimVertR1],
  30495. [3, twoDimVertR1], [3, twoDimVertR1],
  30496. [3, twoDimVertR1], [3, twoDimVertR1],
  30497. [3, twoDimVertR1], [3, twoDimVertR1],
  30498. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30499. [1, twoDimVert0], [1, twoDimVert0],
  30500. [1, twoDimVert0], [1, twoDimVert0],
  30501. [1, twoDimVert0], [1, twoDimVert0],
  30502. [1, twoDimVert0], [1, twoDimVert0],
  30503. [1, twoDimVert0], [1, twoDimVert0],
  30504. [1, twoDimVert0], [1, twoDimVert0],
  30505. [1, twoDimVert0], [1, twoDimVert0],
  30506. [1, twoDimVert0], [1, twoDimVert0],
  30507. [1, twoDimVert0], [1, twoDimVert0],
  30508. [1, twoDimVert0], [1, twoDimVert0],
  30509. [1, twoDimVert0], [1, twoDimVert0],
  30510. [1, twoDimVert0], [1, twoDimVert0],
  30511. [1, twoDimVert0], [1, twoDimVert0],
  30512. [1, twoDimVert0], [1, twoDimVert0],
  30513. [1, twoDimVert0], [1, twoDimVert0],
  30514. [1, twoDimVert0], [1, twoDimVert0],
  30515. [1, twoDimVert0], [1, twoDimVert0],
  30516. [1, twoDimVert0], [1, twoDimVert0],
  30517. [1, twoDimVert0], [1, twoDimVert0],
  30518. [1, twoDimVert0], [1, twoDimVert0],
  30519. [1, twoDimVert0], [1, twoDimVert0],
  30520. [1, twoDimVert0], [1, twoDimVert0],
  30521. [1, twoDimVert0], [1, twoDimVert0],
  30522. [1, twoDimVert0], [1, twoDimVert0],
  30523. [1, twoDimVert0], [1, twoDimVert0],
  30524. [1, twoDimVert0], [1, twoDimVert0],
  30525. [1, twoDimVert0], [1, twoDimVert0],
  30526. [1, twoDimVert0], [1, twoDimVert0],
  30527. [1, twoDimVert0], [1, twoDimVert0],
  30528. [1, twoDimVert0], [1, twoDimVert0],
  30529. [1, twoDimVert0], [1, twoDimVert0]
  30530. ];
  30531. var whiteTable1 = [
  30532. [-1, -1], // 00000
  30533. [12, ccittEOL], // 00001
  30534. [-1, -1], [-1, -1], // 0001x
  30535. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30536. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30537. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30538. [11, 1792], [11, 1792], // 1000x
  30539. [12, 1984], // 10010
  30540. [12, 2048], // 10011
  30541. [12, 2112], // 10100
  30542. [12, 2176], // 10101
  30543. [12, 2240], // 10110
  30544. [12, 2304], // 10111
  30545. [11, 1856], [11, 1856], // 1100x
  30546. [11, 1920], [11, 1920], // 1101x
  30547. [12, 2368], // 11100
  30548. [12, 2432], // 11101
  30549. [12, 2496], // 11110
  30550. [12, 2560] // 11111
  30551. ];
  30552. var whiteTable2 = [
  30553. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30554. [8, 29], [8, 29], // 00000010x
  30555. [8, 30], [8, 30], // 00000011x
  30556. [8, 45], [8, 45], // 00000100x
  30557. [8, 46], [8, 46], // 00000101x
  30558. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30559. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30560. [8, 47], [8, 47], // 00001010x
  30561. [8, 48], [8, 48], // 00001011x
  30562. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30563. [6, 13], [6, 13], [6, 13], [6, 13],
  30564. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30565. [8, 33], [8, 33], // 00010010x
  30566. [8, 34], [8, 34], // 00010011x
  30567. [8, 35], [8, 35], // 00010100x
  30568. [8, 36], [8, 36], // 00010101x
  30569. [8, 37], [8, 37], // 00010110x
  30570. [8, 38], [8, 38], // 00010111x
  30571. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30572. [8, 31], [8, 31], // 00011010x
  30573. [8, 32], [8, 32], // 00011011x
  30574. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30575. [6, 1], [6, 1], [6, 1], [6, 1],
  30576. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30577. [6, 12], [6, 12], [6, 12], [6, 12],
  30578. [8, 53], [8, 53], // 00100100x
  30579. [8, 54], [8, 54], // 00100101x
  30580. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30581. [8, 39], [8, 39], // 00101000x
  30582. [8, 40], [8, 40], // 00101001x
  30583. [8, 41], [8, 41], // 00101010x
  30584. [8, 42], [8, 42], // 00101011x
  30585. [8, 43], [8, 43], // 00101100x
  30586. [8, 44], [8, 44], // 00101101x
  30587. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30588. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30589. [8, 61], [8, 61], // 00110010x
  30590. [8, 62], [8, 62], // 00110011x
  30591. [8, 63], [8, 63], // 00110100x
  30592. [8, 0], [8, 0], // 00110101x
  30593. [8, 320], [8, 320], // 00110110x
  30594. [8, 384], [8, 384], // 00110111x
  30595. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30596. [5, 10], [5, 10], [5, 10], [5, 10],
  30597. [5, 10], [5, 10], [5, 10], [5, 10],
  30598. [5, 10], [5, 10], [5, 10], [5, 10],
  30599. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30600. [5, 11], [5, 11], [5, 11], [5, 11],
  30601. [5, 11], [5, 11], [5, 11], [5, 11],
  30602. [5, 11], [5, 11], [5, 11], [5, 11],
  30603. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30604. [8, 59], [8, 59], // 01001010x
  30605. [8, 60], [8, 60], // 01001011x
  30606. [9, 1472], // 010011000
  30607. [9, 1536], // 010011001
  30608. [9, 1600], // 010011010
  30609. [9, 1728], // 010011011
  30610. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30611. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30612. [8, 49], [8, 49], // 01010010x
  30613. [8, 50], [8, 50], // 01010011x
  30614. [8, 51], [8, 51], // 01010100x
  30615. [8, 52], [8, 52], // 01010101x
  30616. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30617. [8, 55], [8, 55], // 01011000x
  30618. [8, 56], [8, 56], // 01011001x
  30619. [8, 57], [8, 57], // 01011010x
  30620. [8, 58], [8, 58], // 01011011x
  30621. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30622. [6, 192], [6, 192], [6, 192], [6, 192],
  30623. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30624. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30625. [8, 448], [8, 448], // 01100100x
  30626. [8, 512], [8, 512], // 01100101x
  30627. [9, 704], // 011001100
  30628. [9, 768], // 011001101
  30629. [8, 640], [8, 640], // 01100111x
  30630. [8, 576], [8, 576], // 01101000x
  30631. [9, 832], // 011010010
  30632. [9, 896], // 011010011
  30633. [9, 960], // 011010100
  30634. [9, 1024], // 011010101
  30635. [9, 1088], // 011010110
  30636. [9, 1152], // 011010111
  30637. [9, 1216], // 011011000
  30638. [9, 1280], // 011011001
  30639. [9, 1344], // 011011010
  30640. [9, 1408], // 011011011
  30641. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30642. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30643. [4, 2], [4, 2], [4, 2], [4, 2],
  30644. [4, 2], [4, 2], [4, 2], [4, 2],
  30645. [4, 2], [4, 2], [4, 2], [4, 2],
  30646. [4, 2], [4, 2], [4, 2], [4, 2],
  30647. [4, 2], [4, 2], [4, 2], [4, 2],
  30648. [4, 2], [4, 2], [4, 2], [4, 2],
  30649. [4, 2], [4, 2], [4, 2], [4, 2],
  30650. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30651. [4, 3], [4, 3], [4, 3], [4, 3],
  30652. [4, 3], [4, 3], [4, 3], [4, 3],
  30653. [4, 3], [4, 3], [4, 3], [4, 3],
  30654. [4, 3], [4, 3], [4, 3], [4, 3],
  30655. [4, 3], [4, 3], [4, 3], [4, 3],
  30656. [4, 3], [4, 3], [4, 3], [4, 3],
  30657. [4, 3], [4, 3], [4, 3], [4, 3],
  30658. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30659. [5, 128], [5, 128], [5, 128], [5, 128],
  30660. [5, 128], [5, 128], [5, 128], [5, 128],
  30661. [5, 128], [5, 128], [5, 128], [5, 128],
  30662. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30663. [5, 8], [5, 8], [5, 8], [5, 8],
  30664. [5, 8], [5, 8], [5, 8], [5, 8],
  30665. [5, 8], [5, 8], [5, 8], [5, 8],
  30666. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30667. [5, 9], [5, 9], [5, 9], [5, 9],
  30668. [5, 9], [5, 9], [5, 9], [5, 9],
  30669. [5, 9], [5, 9], [5, 9], [5, 9],
  30670. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30671. [6, 16], [6, 16], [6, 16], [6, 16],
  30672. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30673. [6, 17], [6, 17], [6, 17], [6, 17],
  30674. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30675. [4, 4], [4, 4], [4, 4], [4, 4],
  30676. [4, 4], [4, 4], [4, 4], [4, 4],
  30677. [4, 4], [4, 4], [4, 4], [4, 4],
  30678. [4, 4], [4, 4], [4, 4], [4, 4],
  30679. [4, 4], [4, 4], [4, 4], [4, 4],
  30680. [4, 4], [4, 4], [4, 4], [4, 4],
  30681. [4, 4], [4, 4], [4, 4], [4, 4],
  30682. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30683. [4, 5], [4, 5], [4, 5], [4, 5],
  30684. [4, 5], [4, 5], [4, 5], [4, 5],
  30685. [4, 5], [4, 5], [4, 5], [4, 5],
  30686. [4, 5], [4, 5], [4, 5], [4, 5],
  30687. [4, 5], [4, 5], [4, 5], [4, 5],
  30688. [4, 5], [4, 5], [4, 5], [4, 5],
  30689. [4, 5], [4, 5], [4, 5], [4, 5],
  30690. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30691. [6, 14], [6, 14], [6, 14], [6, 14],
  30692. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30693. [6, 15], [6, 15], [6, 15], [6, 15],
  30694. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30695. [5, 64], [5, 64], [5, 64], [5, 64],
  30696. [5, 64], [5, 64], [5, 64], [5, 64],
  30697. [5, 64], [5, 64], [5, 64], [5, 64],
  30698. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30699. [4, 6], [4, 6], [4, 6], [4, 6],
  30700. [4, 6], [4, 6], [4, 6], [4, 6],
  30701. [4, 6], [4, 6], [4, 6], [4, 6],
  30702. [4, 6], [4, 6], [4, 6], [4, 6],
  30703. [4, 6], [4, 6], [4, 6], [4, 6],
  30704. [4, 6], [4, 6], [4, 6], [4, 6],
  30705. [4, 6], [4, 6], [4, 6], [4, 6],
  30706. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30707. [4, 7], [4, 7], [4, 7], [4, 7],
  30708. [4, 7], [4, 7], [4, 7], [4, 7],
  30709. [4, 7], [4, 7], [4, 7], [4, 7],
  30710. [4, 7], [4, 7], [4, 7], [4, 7],
  30711. [4, 7], [4, 7], [4, 7], [4, 7],
  30712. [4, 7], [4, 7], [4, 7], [4, 7],
  30713. [4, 7], [4, 7], [4, 7], [4, 7]
  30714. ];
  30715. var blackTable1 = [
  30716. [-1, -1], [-1, -1], // 000000000000x
  30717. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30718. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30719. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30720. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30721. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30722. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30723. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30724. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30725. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30726. [12, 1984], [12, 1984], // 000000010010x
  30727. [12, 2048], [12, 2048], // 000000010011x
  30728. [12, 2112], [12, 2112], // 000000010100x
  30729. [12, 2176], [12, 2176], // 000000010101x
  30730. [12, 2240], [12, 2240], // 000000010110x
  30731. [12, 2304], [12, 2304], // 000000010111x
  30732. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30733. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30734. [12, 2368], [12, 2368], // 000000011100x
  30735. [12, 2432], [12, 2432], // 000000011101x
  30736. [12, 2496], [12, 2496], // 000000011110x
  30737. [12, 2560], [12, 2560], // 000000011111x
  30738. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30739. [10, 18], [10, 18], [10, 18], [10, 18],
  30740. [12, 52], [12, 52], // 000000100100x
  30741. [13, 640], // 0000001001010
  30742. [13, 704], // 0000001001011
  30743. [13, 768], // 0000001001100
  30744. [13, 832], // 0000001001101
  30745. [12, 55], [12, 55], // 000000100111x
  30746. [12, 56], [12, 56], // 000000101000x
  30747. [13, 1280], // 0000001010010
  30748. [13, 1344], // 0000001010011
  30749. [13, 1408], // 0000001010100
  30750. [13, 1472], // 0000001010101
  30751. [12, 59], [12, 59], // 000000101011x
  30752. [12, 60], [12, 60], // 000000101100x
  30753. [13, 1536], // 0000001011010
  30754. [13, 1600], // 0000001011011
  30755. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30756. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30757. [13, 1664], // 0000001100100
  30758. [13, 1728], // 0000001100101
  30759. [12, 320], [12, 320], // 000000110011x
  30760. [12, 384], [12, 384], // 000000110100x
  30761. [12, 448], [12, 448], // 000000110101x
  30762. [13, 512], // 0000001101100
  30763. [13, 576], // 0000001101101
  30764. [12, 53], [12, 53], // 000000110111x
  30765. [12, 54], [12, 54], // 000000111000x
  30766. [13, 896], // 0000001110010
  30767. [13, 960], // 0000001110011
  30768. [13, 1024], // 0000001110100
  30769. [13, 1088], // 0000001110101
  30770. [13, 1152], // 0000001110110
  30771. [13, 1216], // 0000001110111
  30772. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30773. [10, 64], [10, 64], [10, 64], [10, 64]
  30774. ];
  30775. var blackTable2 = [
  30776. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30777. [8, 13], [8, 13], [8, 13], [8, 13],
  30778. [8, 13], [8, 13], [8, 13], [8, 13],
  30779. [8, 13], [8, 13], [8, 13], [8, 13],
  30780. [11, 23], [11, 23], // 00000101000x
  30781. [12, 50], // 000001010010
  30782. [12, 51], // 000001010011
  30783. [12, 44], // 000001010100
  30784. [12, 45], // 000001010101
  30785. [12, 46], // 000001010110
  30786. [12, 47], // 000001010111
  30787. [12, 57], // 000001011000
  30788. [12, 58], // 000001011001
  30789. [12, 61], // 000001011010
  30790. [12, 256], // 000001011011
  30791. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30792. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30793. [12, 48], // 000001100100
  30794. [12, 49], // 000001100101
  30795. [12, 62], // 000001100110
  30796. [12, 63], // 000001100111
  30797. [12, 30], // 000001101000
  30798. [12, 31], // 000001101001
  30799. [12, 32], // 000001101010
  30800. [12, 33], // 000001101011
  30801. [12, 40], // 000001101100
  30802. [12, 41], // 000001101101
  30803. [11, 22], [11, 22], // 00000110111x
  30804. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30805. [8, 14], [8, 14], [8, 14], [8, 14],
  30806. [8, 14], [8, 14], [8, 14], [8, 14],
  30807. [8, 14], [8, 14], [8, 14], [8, 14],
  30808. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30809. [7, 10], [7, 10], [7, 10], [7, 10],
  30810. [7, 10], [7, 10], [7, 10], [7, 10],
  30811. [7, 10], [7, 10], [7, 10], [7, 10],
  30812. [7, 10], [7, 10], [7, 10], [7, 10],
  30813. [7, 10], [7, 10], [7, 10], [7, 10],
  30814. [7, 10], [7, 10], [7, 10], [7, 10],
  30815. [7, 10], [7, 10], [7, 10], [7, 10],
  30816. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30817. [7, 11], [7, 11], [7, 11], [7, 11],
  30818. [7, 11], [7, 11], [7, 11], [7, 11],
  30819. [7, 11], [7, 11], [7, 11], [7, 11],
  30820. [7, 11], [7, 11], [7, 11], [7, 11],
  30821. [7, 11], [7, 11], [7, 11], [7, 11],
  30822. [7, 11], [7, 11], [7, 11], [7, 11],
  30823. [7, 11], [7, 11], [7, 11], [7, 11],
  30824. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30825. [9, 15], [9, 15], [9, 15], [9, 15],
  30826. [12, 128], // 000011001000
  30827. [12, 192], // 000011001001
  30828. [12, 26], // 000011001010
  30829. [12, 27], // 000011001011
  30830. [12, 28], // 000011001100
  30831. [12, 29], // 000011001101
  30832. [11, 19], [11, 19], // 00001100111x
  30833. [11, 20], [11, 20], // 00001101000x
  30834. [12, 34], // 000011010010
  30835. [12, 35], // 000011010011
  30836. [12, 36], // 000011010100
  30837. [12, 37], // 000011010101
  30838. [12, 38], // 000011010110
  30839. [12, 39], // 000011010111
  30840. [11, 21], [11, 21], // 00001101100x
  30841. [12, 42], // 000011011010
  30842. [12, 43], // 000011011011
  30843. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30844. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30845. [7, 12], [7, 12], [7, 12], [7, 12],
  30846. [7, 12], [7, 12], [7, 12], [7, 12],
  30847. [7, 12], [7, 12], [7, 12], [7, 12],
  30848. [7, 12], [7, 12], [7, 12], [7, 12],
  30849. [7, 12], [7, 12], [7, 12], [7, 12],
  30850. [7, 12], [7, 12], [7, 12], [7, 12],
  30851. [7, 12], [7, 12], [7, 12], [7, 12]
  30852. ];
  30853. var blackTable3 = [
  30854. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30855. [6, 9], // 000100
  30856. [6, 8], // 000101
  30857. [5, 7], [5, 7], // 00011x
  30858. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30859. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30860. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30861. [3, 1], [3, 1], [3, 1], [3, 1],
  30862. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30863. [3, 4], [3, 4], [3, 4], [3, 4],
  30864. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30865. [2, 3], [2, 3], [2, 3], [2, 3],
  30866. [2, 3], [2, 3], [2, 3], [2, 3],
  30867. [2, 3], [2, 3], [2, 3], [2, 3],
  30868. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30869. [2, 2], [2, 2], [2, 2], [2, 2],
  30870. [2, 2], [2, 2], [2, 2], [2, 2],
  30871. [2, 2], [2, 2], [2, 2], [2, 2]
  30872. ];
  30873. function CCITTFaxStream(str, maybeLength, params) {
  30874. this.str = str;
  30875. this.dict = str.dict;
  30876. params = params || Dict.empty;
  30877. this.encoding = params.get('K') || 0;
  30878. this.eoline = params.get('EndOfLine') || false;
  30879. this.byteAlign = params.get('EncodedByteAlign') || false;
  30880. this.columns = params.get('Columns') || 1728;
  30881. this.rows = params.get('Rows') || 0;
  30882. var eoblock = params.get('EndOfBlock');
  30883. if (eoblock === null || eoblock === undefined) {
  30884. eoblock = true;
  30885. }
  30886. this.eoblock = eoblock;
  30887. this.black = params.get('BlackIs1') || false;
  30888. this.codingLine = new Uint32Array(this.columns + 1);
  30889. this.refLine = new Uint32Array(this.columns + 2);
  30890. this.codingLine[0] = this.columns;
  30891. this.codingPos = 0;
  30892. this.row = 0;
  30893. this.nextLine2D = this.encoding < 0;
  30894. this.inputBits = 0;
  30895. this.inputBuf = 0;
  30896. this.outputBits = 0;
  30897. var code1;
  30898. while ((code1 = this.lookBits(12)) === 0) {
  30899. this.eatBits(1);
  30900. }
  30901. if (code1 === 1) {
  30902. this.eatBits(12);
  30903. }
  30904. if (this.encoding > 0) {
  30905. this.nextLine2D = !this.lookBits(1);
  30906. this.eatBits(1);
  30907. }
  30908. DecodeStream.call(this, maybeLength);
  30909. }
  30910. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30911. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30912. while (!this.eof) {
  30913. var c = this.lookChar();
  30914. this.ensureBuffer(this.bufferLength + 1);
  30915. this.buffer[this.bufferLength++] = c;
  30916. }
  30917. };
  30918. CCITTFaxStream.prototype.addPixels =
  30919. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30920. var codingLine = this.codingLine;
  30921. var codingPos = this.codingPos;
  30922. if (a1 > codingLine[codingPos]) {
  30923. if (a1 > this.columns) {
  30924. info('row is wrong length');
  30925. this.err = true;
  30926. a1 = this.columns;
  30927. }
  30928. if ((codingPos & 1) ^ blackPixels) {
  30929. ++codingPos;
  30930. }
  30931. codingLine[codingPos] = a1;
  30932. }
  30933. this.codingPos = codingPos;
  30934. };
  30935. CCITTFaxStream.prototype.addPixelsNeg =
  30936. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30937. var codingLine = this.codingLine;
  30938. var codingPos = this.codingPos;
  30939. if (a1 > codingLine[codingPos]) {
  30940. if (a1 > this.columns) {
  30941. info('row is wrong length');
  30942. this.err = true;
  30943. a1 = this.columns;
  30944. }
  30945. if ((codingPos & 1) ^ blackPixels) {
  30946. ++codingPos;
  30947. }
  30948. codingLine[codingPos] = a1;
  30949. } else if (a1 < codingLine[codingPos]) {
  30950. if (a1 < 0) {
  30951. info('invalid code');
  30952. this.err = true;
  30953. a1 = 0;
  30954. }
  30955. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30956. --codingPos;
  30957. }
  30958. codingLine[codingPos] = a1;
  30959. }
  30960. this.codingPos = codingPos;
  30961. };
  30962. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30963. var refLine = this.refLine;
  30964. var codingLine = this.codingLine;
  30965. var columns = this.columns;
  30966. var refPos, blackPixels, bits, i;
  30967. if (this.outputBits === 0) {
  30968. if (this.eof) {
  30969. return null;
  30970. }
  30971. this.err = false;
  30972. var code1, code2, code3;
  30973. if (this.nextLine2D) {
  30974. for (i = 0; codingLine[i] < columns; ++i) {
  30975. refLine[i] = codingLine[i];
  30976. }
  30977. refLine[i++] = columns;
  30978. refLine[i] = columns;
  30979. codingLine[0] = 0;
  30980. this.codingPos = 0;
  30981. refPos = 0;
  30982. blackPixels = 0;
  30983. while (codingLine[this.codingPos] < columns) {
  30984. code1 = this.getTwoDimCode();
  30985. switch (code1) {
  30986. case twoDimPass:
  30987. this.addPixels(refLine[refPos + 1], blackPixels);
  30988. if (refLine[refPos + 1] < columns) {
  30989. refPos += 2;
  30990. }
  30991. break;
  30992. case twoDimHoriz:
  30993. code1 = code2 = 0;
  30994. if (blackPixels) {
  30995. do {
  30996. code1 += (code3 = this.getBlackCode());
  30997. } while (code3 >= 64);
  30998. do {
  30999. code2 += (code3 = this.getWhiteCode());
  31000. } while (code3 >= 64);
  31001. } else {
  31002. do {
  31003. code1 += (code3 = this.getWhiteCode());
  31004. } while (code3 >= 64);
  31005. do {
  31006. code2 += (code3 = this.getBlackCode());
  31007. } while (code3 >= 64);
  31008. }
  31009. this.addPixels(codingLine[this.codingPos] +
  31010. code1, blackPixels);
  31011. if (codingLine[this.codingPos] < columns) {
  31012. this.addPixels(codingLine[this.codingPos] + code2,
  31013. blackPixels ^ 1);
  31014. }
  31015. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31016. refLine[refPos] < columns) {
  31017. refPos += 2;
  31018. }
  31019. break;
  31020. case twoDimVertR3:
  31021. this.addPixels(refLine[refPos] + 3, blackPixels);
  31022. blackPixels ^= 1;
  31023. if (codingLine[this.codingPos] < columns) {
  31024. ++refPos;
  31025. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31026. refLine[refPos] < columns) {
  31027. refPos += 2;
  31028. }
  31029. }
  31030. break;
  31031. case twoDimVertR2:
  31032. this.addPixels(refLine[refPos] + 2, blackPixels);
  31033. blackPixels ^= 1;
  31034. if (codingLine[this.codingPos] < columns) {
  31035. ++refPos;
  31036. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31037. refLine[refPos] < columns) {
  31038. refPos += 2;
  31039. }
  31040. }
  31041. break;
  31042. case twoDimVertR1:
  31043. this.addPixels(refLine[refPos] + 1, blackPixels);
  31044. blackPixels ^= 1;
  31045. if (codingLine[this.codingPos] < columns) {
  31046. ++refPos;
  31047. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31048. refLine[refPos] < columns) {
  31049. refPos += 2;
  31050. }
  31051. }
  31052. break;
  31053. case twoDimVert0:
  31054. this.addPixels(refLine[refPos], blackPixels);
  31055. blackPixels ^= 1;
  31056. if (codingLine[this.codingPos] < columns) {
  31057. ++refPos;
  31058. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31059. refLine[refPos] < columns) {
  31060. refPos += 2;
  31061. }
  31062. }
  31063. break;
  31064. case twoDimVertL3:
  31065. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31066. blackPixels ^= 1;
  31067. if (codingLine[this.codingPos] < columns) {
  31068. if (refPos > 0) {
  31069. --refPos;
  31070. } else {
  31071. ++refPos;
  31072. }
  31073. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31074. refLine[refPos] < columns) {
  31075. refPos += 2;
  31076. }
  31077. }
  31078. break;
  31079. case twoDimVertL2:
  31080. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31081. blackPixels ^= 1;
  31082. if (codingLine[this.codingPos] < columns) {
  31083. if (refPos > 0) {
  31084. --refPos;
  31085. } else {
  31086. ++refPos;
  31087. }
  31088. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31089. refLine[refPos] < columns) {
  31090. refPos += 2;
  31091. }
  31092. }
  31093. break;
  31094. case twoDimVertL1:
  31095. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31096. blackPixels ^= 1;
  31097. if (codingLine[this.codingPos] < columns) {
  31098. if (refPos > 0) {
  31099. --refPos;
  31100. } else {
  31101. ++refPos;
  31102. }
  31103. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31104. refLine[refPos] < columns) {
  31105. refPos += 2;
  31106. }
  31107. }
  31108. break;
  31109. case EOF:
  31110. this.addPixels(columns, 0);
  31111. this.eof = true;
  31112. break;
  31113. default:
  31114. info('bad 2d code');
  31115. this.addPixels(columns, 0);
  31116. this.err = true;
  31117. }
  31118. }
  31119. } else {
  31120. codingLine[0] = 0;
  31121. this.codingPos = 0;
  31122. blackPixels = 0;
  31123. while (codingLine[this.codingPos] < columns) {
  31124. code1 = 0;
  31125. if (blackPixels) {
  31126. do {
  31127. code1 += (code3 = this.getBlackCode());
  31128. } while (code3 >= 64);
  31129. } else {
  31130. do {
  31131. code1 += (code3 = this.getWhiteCode());
  31132. } while (code3 >= 64);
  31133. }
  31134. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31135. blackPixels ^= 1;
  31136. }
  31137. }
  31138. var gotEOL = false;
  31139. if (!this.eoblock && this.row === this.rows - 1) {
  31140. this.eof = true;
  31141. } else if (this.eoline || !this.byteAlign) {
  31142. code1 = this.lookBits(12);
  31143. if (this.eoline) {
  31144. while (code1 !== EOF && code1 !== 1) {
  31145. this.eatBits(1);
  31146. code1 = this.lookBits(12);
  31147. }
  31148. } else {
  31149. while (code1 === 0) {
  31150. this.eatBits(1);
  31151. code1 = this.lookBits(12);
  31152. }
  31153. }
  31154. if (code1 === 1) {
  31155. this.eatBits(12);
  31156. gotEOL = true;
  31157. } else if (code1 === EOF) {
  31158. this.eof = true;
  31159. }
  31160. }
  31161. if (this.byteAlign && !gotEOL) {
  31162. this.inputBits &= ~7;
  31163. }
  31164. if (!this.eof && this.encoding > 0) {
  31165. this.nextLine2D = !this.lookBits(1);
  31166. this.eatBits(1);
  31167. }
  31168. if (this.eoblock && gotEOL && this.byteAlign) {
  31169. code1 = this.lookBits(12);
  31170. if (code1 === 1) {
  31171. this.eatBits(12);
  31172. if (this.encoding > 0) {
  31173. this.lookBits(1);
  31174. this.eatBits(1);
  31175. }
  31176. if (this.encoding >= 0) {
  31177. for (i = 0; i < 4; ++i) {
  31178. code1 = this.lookBits(12);
  31179. if (code1 !== 1) {
  31180. info('bad rtc code: ' + code1);
  31181. }
  31182. this.eatBits(12);
  31183. if (this.encoding > 0) {
  31184. this.lookBits(1);
  31185. this.eatBits(1);
  31186. }
  31187. }
  31188. }
  31189. this.eof = true;
  31190. }
  31191. } else if (this.err && this.eoline) {
  31192. while (true) {
  31193. code1 = this.lookBits(13);
  31194. if (code1 === EOF) {
  31195. this.eof = true;
  31196. return null;
  31197. }
  31198. if ((code1 >> 1) === 1) {
  31199. break;
  31200. }
  31201. this.eatBits(1);
  31202. }
  31203. this.eatBits(12);
  31204. if (this.encoding > 0) {
  31205. this.eatBits(1);
  31206. this.nextLine2D = !(code1 & 1);
  31207. }
  31208. }
  31209. if (codingLine[0] > 0) {
  31210. this.outputBits = codingLine[this.codingPos = 0];
  31211. } else {
  31212. this.outputBits = codingLine[this.codingPos = 1];
  31213. }
  31214. this.row++;
  31215. }
  31216. var c;
  31217. if (this.outputBits >= 8) {
  31218. c = (this.codingPos & 1) ? 0 : 0xFF;
  31219. this.outputBits -= 8;
  31220. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31221. this.codingPos++;
  31222. this.outputBits = (codingLine[this.codingPos] -
  31223. codingLine[this.codingPos - 1]);
  31224. }
  31225. } else {
  31226. bits = 8;
  31227. c = 0;
  31228. do {
  31229. if (this.outputBits > bits) {
  31230. c <<= bits;
  31231. if (!(this.codingPos & 1)) {
  31232. c |= 0xFF >> (8 - bits);
  31233. }
  31234. this.outputBits -= bits;
  31235. bits = 0;
  31236. } else {
  31237. c <<= this.outputBits;
  31238. if (!(this.codingPos & 1)) {
  31239. c |= 0xFF >> (8 - this.outputBits);
  31240. }
  31241. bits -= this.outputBits;
  31242. this.outputBits = 0;
  31243. if (codingLine[this.codingPos] < columns) {
  31244. this.codingPos++;
  31245. this.outputBits = (codingLine[this.codingPos] -
  31246. codingLine[this.codingPos - 1]);
  31247. } else if (bits > 0) {
  31248. c <<= bits;
  31249. bits = 0;
  31250. }
  31251. }
  31252. } while (bits);
  31253. }
  31254. if (this.black) {
  31255. c ^= 0xFF;
  31256. }
  31257. return c;
  31258. };
  31259. // This functions returns the code found from the table.
  31260. // The start and end parameters set the boundaries for searching the table.
  31261. // The limit parameter is optional. Function returns an array with three
  31262. // values. The first array element indicates whether a valid code is being
  31263. // returned. The second array element is the actual code. The third array
  31264. // element indicates whether EOF was reached.
  31265. CCITTFaxStream.prototype.findTableCode =
  31266. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31267. var limitValue = limit || 0;
  31268. for (var i = start; i <= end; ++i) {
  31269. var code = this.lookBits(i);
  31270. if (code === EOF) {
  31271. return [true, 1, false];
  31272. }
  31273. if (i < end) {
  31274. code <<= end - i;
  31275. }
  31276. if (!limitValue || code >= limitValue) {
  31277. var p = table[code - limitValue];
  31278. if (p[0] === i) {
  31279. this.eatBits(i);
  31280. return [true, p[1], true];
  31281. }
  31282. }
  31283. }
  31284. return [false, 0, false];
  31285. };
  31286. CCITTFaxStream.prototype.getTwoDimCode =
  31287. function ccittFaxStreamGetTwoDimCode() {
  31288. var code = 0;
  31289. var p;
  31290. if (this.eoblock) {
  31291. code = this.lookBits(7);
  31292. p = twoDimTable[code];
  31293. if (p && p[0] > 0) {
  31294. this.eatBits(p[0]);
  31295. return p[1];
  31296. }
  31297. } else {
  31298. var result = this.findTableCode(1, 7, twoDimTable);
  31299. if (result[0] && result[2]) {
  31300. return result[1];
  31301. }
  31302. }
  31303. info('Bad two dim code');
  31304. return EOF;
  31305. };
  31306. CCITTFaxStream.prototype.getWhiteCode =
  31307. function ccittFaxStreamGetWhiteCode() {
  31308. var code = 0;
  31309. var p;
  31310. if (this.eoblock) {
  31311. code = this.lookBits(12);
  31312. if (code === EOF) {
  31313. return 1;
  31314. }
  31315. if ((code >> 5) === 0) {
  31316. p = whiteTable1[code];
  31317. } else {
  31318. p = whiteTable2[code >> 3];
  31319. }
  31320. if (p[0] > 0) {
  31321. this.eatBits(p[0]);
  31322. return p[1];
  31323. }
  31324. } else {
  31325. var result = this.findTableCode(1, 9, whiteTable2);
  31326. if (result[0]) {
  31327. return result[1];
  31328. }
  31329. result = this.findTableCode(11, 12, whiteTable1);
  31330. if (result[0]) {
  31331. return result[1];
  31332. }
  31333. }
  31334. info('bad white code');
  31335. this.eatBits(1);
  31336. return 1;
  31337. };
  31338. CCITTFaxStream.prototype.getBlackCode =
  31339. function ccittFaxStreamGetBlackCode() {
  31340. var code, p;
  31341. if (this.eoblock) {
  31342. code = this.lookBits(13);
  31343. if (code === EOF) {
  31344. return 1;
  31345. }
  31346. if ((code >> 7) === 0) {
  31347. p = blackTable1[code];
  31348. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31349. p = blackTable2[(code >> 1) - 64];
  31350. } else {
  31351. p = blackTable3[code >> 7];
  31352. }
  31353. if (p[0] > 0) {
  31354. this.eatBits(p[0]);
  31355. return p[1];
  31356. }
  31357. } else {
  31358. var result = this.findTableCode(2, 6, blackTable3);
  31359. if (result[0]) {
  31360. return result[1];
  31361. }
  31362. result = this.findTableCode(7, 12, blackTable2, 64);
  31363. if (result[0]) {
  31364. return result[1];
  31365. }
  31366. result = this.findTableCode(10, 13, blackTable1);
  31367. if (result[0]) {
  31368. return result[1];
  31369. }
  31370. }
  31371. info('bad black code');
  31372. this.eatBits(1);
  31373. return 1;
  31374. };
  31375. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31376. var c;
  31377. while (this.inputBits < n) {
  31378. if ((c = this.str.getByte()) === -1) {
  31379. if (this.inputBits === 0) {
  31380. return EOF;
  31381. }
  31382. return ((this.inputBuf << (n - this.inputBits)) &
  31383. (0xFFFF >> (16 - n)));
  31384. }
  31385. this.inputBuf = (this.inputBuf << 8) + c;
  31386. this.inputBits += 8;
  31387. }
  31388. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31389. };
  31390. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31391. if ((this.inputBits -= n) < 0) {
  31392. this.inputBits = 0;
  31393. }
  31394. };
  31395. return CCITTFaxStream;
  31396. })();
  31397. var LZWStream = (function LZWStreamClosure() {
  31398. function LZWStream(str, maybeLength, earlyChange) {
  31399. this.str = str;
  31400. this.dict = str.dict;
  31401. this.cachedData = 0;
  31402. this.bitsCached = 0;
  31403. var maxLzwDictionarySize = 4096;
  31404. var lzwState = {
  31405. earlyChange: earlyChange,
  31406. codeLength: 9,
  31407. nextCode: 258,
  31408. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31409. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31410. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31411. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31412. currentSequenceLength: 0
  31413. };
  31414. for (var i = 0; i < 256; ++i) {
  31415. lzwState.dictionaryValues[i] = i;
  31416. lzwState.dictionaryLengths[i] = 1;
  31417. }
  31418. this.lzwState = lzwState;
  31419. DecodeStream.call(this, maybeLength);
  31420. }
  31421. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31422. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31423. var bitsCached = this.bitsCached;
  31424. var cachedData = this.cachedData;
  31425. while (bitsCached < n) {
  31426. var c = this.str.getByte();
  31427. if (c === -1) {
  31428. this.eof = true;
  31429. return null;
  31430. }
  31431. cachedData = (cachedData << 8) | c;
  31432. bitsCached += 8;
  31433. }
  31434. this.bitsCached = (bitsCached -= n);
  31435. this.cachedData = cachedData;
  31436. this.lastCode = null;
  31437. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31438. };
  31439. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31440. var blockSize = 512;
  31441. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31442. var i, j, q;
  31443. var lzwState = this.lzwState;
  31444. if (!lzwState) {
  31445. return; // eof was found
  31446. }
  31447. var earlyChange = lzwState.earlyChange;
  31448. var nextCode = lzwState.nextCode;
  31449. var dictionaryValues = lzwState.dictionaryValues;
  31450. var dictionaryLengths = lzwState.dictionaryLengths;
  31451. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31452. var codeLength = lzwState.codeLength;
  31453. var prevCode = lzwState.prevCode;
  31454. var currentSequence = lzwState.currentSequence;
  31455. var currentSequenceLength = lzwState.currentSequenceLength;
  31456. var decodedLength = 0;
  31457. var currentBufferLength = this.bufferLength;
  31458. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31459. for (i = 0; i < blockSize; i++) {
  31460. var code = this.readBits(codeLength);
  31461. var hasPrev = currentSequenceLength > 0;
  31462. if (code < 256) {
  31463. currentSequence[0] = code;
  31464. currentSequenceLength = 1;
  31465. } else if (code >= 258) {
  31466. if (code < nextCode) {
  31467. currentSequenceLength = dictionaryLengths[code];
  31468. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31469. currentSequence[j] = dictionaryValues[q];
  31470. q = dictionaryPrevCodes[q];
  31471. }
  31472. } else {
  31473. currentSequence[currentSequenceLength++] = currentSequence[0];
  31474. }
  31475. } else if (code === 256) {
  31476. codeLength = 9;
  31477. nextCode = 258;
  31478. currentSequenceLength = 0;
  31479. continue;
  31480. } else {
  31481. this.eof = true;
  31482. delete this.lzwState;
  31483. break;
  31484. }
  31485. if (hasPrev) {
  31486. dictionaryPrevCodes[nextCode] = prevCode;
  31487. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31488. dictionaryValues[nextCode] = currentSequence[0];
  31489. nextCode++;
  31490. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31491. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31492. 0.6931471805599453 + 1, 12) | 0;
  31493. }
  31494. prevCode = code;
  31495. decodedLength += currentSequenceLength;
  31496. if (estimatedDecodedSize < decodedLength) {
  31497. do {
  31498. estimatedDecodedSize += decodedSizeDelta;
  31499. } while (estimatedDecodedSize < decodedLength);
  31500. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31501. }
  31502. for (j = 0; j < currentSequenceLength; j++) {
  31503. buffer[currentBufferLength++] = currentSequence[j];
  31504. }
  31505. }
  31506. lzwState.nextCode = nextCode;
  31507. lzwState.codeLength = codeLength;
  31508. lzwState.prevCode = prevCode;
  31509. lzwState.currentSequenceLength = currentSequenceLength;
  31510. this.bufferLength = currentBufferLength;
  31511. };
  31512. return LZWStream;
  31513. })();
  31514. var NullStream = (function NullStreamClosure() {
  31515. function NullStream() {
  31516. Stream.call(this, new Uint8Array(0));
  31517. }
  31518. NullStream.prototype = Stream.prototype;
  31519. return NullStream;
  31520. })();
  31521. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31522. setup: function wphSetup(handler) {
  31523. var pdfManager;
  31524. function loadDocument(recoveryMode) {
  31525. var loadDocumentCapability = createPromiseCapability();
  31526. var parseSuccess = function parseSuccess() {
  31527. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31528. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31529. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31530. Promise.all([numPagesPromise, fingerprintPromise,
  31531. encryptedPromise]).then(function onDocReady(results) {
  31532. var doc = {
  31533. numPages: results[0],
  31534. fingerprint: results[1],
  31535. encrypted: !!results[2],
  31536. };
  31537. loadDocumentCapability.resolve(doc);
  31538. },
  31539. parseFailure);
  31540. };
  31541. var parseFailure = function parseFailure(e) {
  31542. loadDocumentCapability.reject(e);
  31543. };
  31544. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31545. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31546. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31547. parseSuccess, parseFailure);
  31548. }, parseFailure);
  31549. }, parseFailure);
  31550. return loadDocumentCapability.promise;
  31551. }
  31552. function getPdfManager(data) {
  31553. var pdfManagerCapability = createPromiseCapability();
  31554. var source = data.source;
  31555. var disableRange = data.disableRange;
  31556. if (source.data) {
  31557. try {
  31558. pdfManager = new LocalPdfManager(source.data, source.password);
  31559. pdfManagerCapability.resolve();
  31560. } catch (ex) {
  31561. pdfManagerCapability.reject(ex);
  31562. }
  31563. return pdfManagerCapability.promise;
  31564. } else if (source.chunkedViewerLoading) {
  31565. try {
  31566. pdfManager = new NetworkPdfManager(source, handler);
  31567. pdfManagerCapability.resolve();
  31568. } catch (ex) {
  31569. pdfManagerCapability.reject(ex);
  31570. }
  31571. return pdfManagerCapability.promise;
  31572. }
  31573. var networkManager = new NetworkManager(source.url, {
  31574. httpHeaders: source.httpHeaders,
  31575. withCredentials: source.withCredentials
  31576. });
  31577. var cachedChunks = [];
  31578. var fullRequestXhrId = networkManager.requestFull({
  31579. onHeadersReceived: function onHeadersReceived() {
  31580. if (disableRange) {
  31581. return;
  31582. }
  31583. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31584. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31585. return;
  31586. }
  31587. var contentEncoding =
  31588. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31589. if (contentEncoding !== 'identity') {
  31590. return;
  31591. }
  31592. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31593. length = parseInt(length, 10);
  31594. if (!isInt(length)) {
  31595. return;
  31596. }
  31597. source.length = length;
  31598. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31599. // The file size is smaller than the size of two chunks, so it does
  31600. // not make any sense to abort the request and retry with a range
  31601. // request.
  31602. return;
  31603. }
  31604. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31605. // We can continue fetching when progressive loading is enabled,
  31606. // and we don't need the autoFetch feature.
  31607. source.disableAutoFetch = true;
  31608. } else {
  31609. // NOTE: by cancelling the full request, and then issuing range
  31610. // requests, there will be an issue for sites where you can only
  31611. // request the pdf once. However, if this is the case, then the
  31612. // server should not be returning that it can support range
  31613. // requests.
  31614. networkManager.abortRequest(fullRequestXhrId);
  31615. }
  31616. try {
  31617. pdfManager = new NetworkPdfManager(source, handler);
  31618. pdfManagerCapability.resolve(pdfManager);
  31619. } catch (ex) {
  31620. pdfManagerCapability.reject(ex);
  31621. }
  31622. },
  31623. onProgressiveData: source.disableStream ? null :
  31624. function onProgressiveData(chunk) {
  31625. if (!pdfManager) {
  31626. cachedChunks.push(chunk);
  31627. return;
  31628. }
  31629. pdfManager.sendProgressiveData(chunk);
  31630. },
  31631. onDone: function onDone(args) {
  31632. if (pdfManager) {
  31633. return; // already processed
  31634. }
  31635. var pdfFile;
  31636. if (args === null) {
  31637. // TODO add some streaming manager, e.g. for unknown length files.
  31638. // The data was returned in the onProgressiveData, combining...
  31639. var pdfFileLength = 0, pos = 0;
  31640. cachedChunks.forEach(function (chunk) {
  31641. pdfFileLength += chunk.byteLength;
  31642. });
  31643. if (source.length && pdfFileLength !== source.length) {
  31644. warn('reported HTTP length is different from actual');
  31645. }
  31646. var pdfFileArray = new Uint8Array(pdfFileLength);
  31647. cachedChunks.forEach(function (chunk) {
  31648. pdfFileArray.set(new Uint8Array(chunk), pos);
  31649. pos += chunk.byteLength;
  31650. });
  31651. pdfFile = pdfFileArray.buffer;
  31652. } else {
  31653. pdfFile = args.chunk;
  31654. }
  31655. // the data is array, instantiating directly from it
  31656. try {
  31657. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31658. pdfManagerCapability.resolve();
  31659. } catch (ex) {
  31660. pdfManagerCapability.reject(ex);
  31661. }
  31662. },
  31663. onError: function onError(status) {
  31664. var exception;
  31665. if (status === 404) {
  31666. exception = new MissingPDFException('Missing PDF "' +
  31667. source.url + '".');
  31668. handler.send('MissingPDF', exception);
  31669. } else {
  31670. exception = new UnexpectedResponseException(
  31671. 'Unexpected server response (' + status +
  31672. ') while retrieving PDF "' + source.url + '".', status);
  31673. handler.send('UnexpectedResponse', exception);
  31674. }
  31675. },
  31676. onProgress: function onProgress(evt) {
  31677. handler.send('DocProgress', {
  31678. loaded: evt.loaded,
  31679. total: evt.lengthComputable ? evt.total : source.length
  31680. });
  31681. }
  31682. });
  31683. return pdfManagerCapability.promise;
  31684. }
  31685. handler.on('test', function wphSetupTest(data) {
  31686. // check if Uint8Array can be sent to worker
  31687. if (!(data instanceof Uint8Array)) {
  31688. handler.send('test', false);
  31689. return;
  31690. }
  31691. // making sure postMessage transfers are working
  31692. var supportTransfers = data[0] === 255;
  31693. handler.postMessageTransfers = supportTransfers;
  31694. // check if the response property is supported by xhr
  31695. var xhr = new XMLHttpRequest();
  31696. var responseExists = 'response' in xhr;
  31697. // check if the property is actually implemented
  31698. try {
  31699. var dummy = xhr.responseType;
  31700. } catch (e) {
  31701. responseExists = false;
  31702. }
  31703. if (!responseExists) {
  31704. handler.send('test', false);
  31705. return;
  31706. }
  31707. handler.send('test', {
  31708. supportTypedArray: true,
  31709. supportTransfers: supportTransfers
  31710. });
  31711. });
  31712. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31713. var onSuccess = function(doc) {
  31714. handler.send('GetDoc', { pdfInfo: doc });
  31715. };
  31716. var onFailure = function(e) {
  31717. if (e instanceof PasswordException) {
  31718. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31719. handler.send('NeedPassword', e);
  31720. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31721. handler.send('IncorrectPassword', e);
  31722. }
  31723. } else if (e instanceof InvalidPDFException) {
  31724. handler.send('InvalidPDF', e);
  31725. } else if (e instanceof MissingPDFException) {
  31726. handler.send('MissingPDF', e);
  31727. } else if (e instanceof UnexpectedResponseException) {
  31728. handler.send('UnexpectedResponse', e);
  31729. } else {
  31730. handler.send('UnknownError',
  31731. new UnknownErrorException(e.message, e.toString()));
  31732. }
  31733. };
  31734. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31735. -1 : data.maxImageSize;
  31736. PDFJS.disableFontFace = data.disableFontFace;
  31737. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31738. PDFJS.verbosity = data.verbosity;
  31739. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31740. null : data.cMapUrl;
  31741. PDFJS.cMapPacked = data.cMapPacked === true;
  31742. getPdfManager(data).then(function () {
  31743. handler.send('PDFManagerReady', null);
  31744. pdfManager.onLoadedStream().then(function(stream) {
  31745. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31746. });
  31747. }).then(function pdfManagerReady() {
  31748. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31749. // Try again with recoveryMode == true
  31750. if (!(ex instanceof XRefParseException)) {
  31751. if (ex instanceof PasswordException) {
  31752. // after password exception prepare to receive a new password
  31753. // to repeat loading
  31754. pdfManager.passwordChanged().then(pdfManagerReady);
  31755. }
  31756. onFailure(ex);
  31757. return;
  31758. }
  31759. pdfManager.requestLoadedStream();
  31760. pdfManager.onLoadedStream().then(function() {
  31761. loadDocument(true).then(onSuccess, onFailure);
  31762. });
  31763. }, onFailure);
  31764. }, onFailure);
  31765. });
  31766. handler.on('GetPage', function wphSetupGetPage(data) {
  31767. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31768. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31769. var refPromise = pdfManager.ensure(page, 'ref');
  31770. var viewPromise = pdfManager.ensure(page, 'view');
  31771. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31772. function(results) {
  31773. return {
  31774. rotate: results[0],
  31775. ref: results[1],
  31776. view: results[2]
  31777. };
  31778. });
  31779. });
  31780. });
  31781. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31782. var ref = new Ref(data.ref.num, data.ref.gen);
  31783. var catalog = pdfManager.pdfDocument.catalog;
  31784. return catalog.getPageIndex(ref);
  31785. });
  31786. handler.on('GetDestinations',
  31787. function wphSetupGetDestinations(data) {
  31788. return pdfManager.ensureCatalog('destinations');
  31789. }
  31790. );
  31791. handler.on('GetDestination',
  31792. function wphSetupGetDestination(data) {
  31793. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  31794. }
  31795. );
  31796. handler.on('GetAttachments',
  31797. function wphSetupGetAttachments(data) {
  31798. return pdfManager.ensureCatalog('attachments');
  31799. }
  31800. );
  31801. handler.on('GetJavaScript',
  31802. function wphSetupGetJavaScript(data) {
  31803. return pdfManager.ensureCatalog('javaScript');
  31804. }
  31805. );
  31806. handler.on('GetOutline',
  31807. function wphSetupGetOutline(data) {
  31808. return pdfManager.ensureCatalog('documentOutline');
  31809. }
  31810. );
  31811. handler.on('GetMetadata',
  31812. function wphSetupGetMetadata(data) {
  31813. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31814. pdfManager.ensureCatalog('metadata')]);
  31815. }
  31816. );
  31817. handler.on('GetData', function wphSetupGetData(data) {
  31818. pdfManager.requestLoadedStream();
  31819. return pdfManager.onLoadedStream().then(function(stream) {
  31820. return stream.bytes;
  31821. });
  31822. });
  31823. handler.on('GetStats',
  31824. function wphSetupGetStats(data) {
  31825. return pdfManager.pdfDocument.xref.stats;
  31826. }
  31827. );
  31828. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31829. pdfManager.updatePassword(data);
  31830. });
  31831. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31832. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31833. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31834. });
  31835. });
  31836. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31837. pdfManager.getPage(data.pageIndex).then(function(page) {
  31838. var pageNum = data.pageIndex + 1;
  31839. var start = Date.now();
  31840. // Pre compile the pdf page and fetch the fonts/images.
  31841. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31842. info('page=' + pageNum + ' - getOperatorList: time=' +
  31843. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31844. }, function(e) {
  31845. var minimumStackMessage =
  31846. 'worker.js: while trying to getPage() and getOperatorList()';
  31847. var wrappedException;
  31848. // Turn the error into an obj that can be serialized
  31849. if (typeof e === 'string') {
  31850. wrappedException = {
  31851. message: e,
  31852. stack: minimumStackMessage
  31853. };
  31854. } else if (typeof e === 'object') {
  31855. wrappedException = {
  31856. message: e.message || e.toString(),
  31857. stack: e.stack || minimumStackMessage
  31858. };
  31859. } else {
  31860. wrappedException = {
  31861. message: 'Unknown exception type: ' + (typeof e),
  31862. stack: minimumStackMessage
  31863. };
  31864. }
  31865. handler.send('PageError', {
  31866. pageNum: pageNum,
  31867. error: wrappedException,
  31868. intent: data.intent
  31869. });
  31870. });
  31871. });
  31872. }, this);
  31873. handler.on('GetTextContent', function wphExtractText(data) {
  31874. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31875. var pageNum = data.pageIndex + 1;
  31876. var start = Date.now();
  31877. return page.extractTextContent().then(function(textContent) {
  31878. info('text indexing: page=' + pageNum + ' - time=' +
  31879. (Date.now() - start) + 'ms');
  31880. return textContent;
  31881. });
  31882. });
  31883. });
  31884. handler.on('Cleanup', function wphCleanup(data) {
  31885. return pdfManager.cleanup();
  31886. });
  31887. handler.on('Terminate', function wphTerminate(data) {
  31888. pdfManager.terminate();
  31889. });
  31890. }
  31891. };
  31892. var consoleTimer = {};
  31893. var workerConsole = {
  31894. log: function log() {
  31895. var args = Array.prototype.slice.call(arguments);
  31896. globalScope.postMessage({
  31897. action: 'console_log',
  31898. data: args
  31899. });
  31900. },
  31901. error: function error() {
  31902. var args = Array.prototype.slice.call(arguments);
  31903. globalScope.postMessage({
  31904. action: 'console_error',
  31905. data: args
  31906. });
  31907. throw 'pdf.js execution error';
  31908. },
  31909. time: function time(name) {
  31910. consoleTimer[name] = Date.now();
  31911. },
  31912. timeEnd: function timeEnd(name) {
  31913. var time = consoleTimer[name];
  31914. if (!time) {
  31915. error('Unknown timer name ' + name);
  31916. }
  31917. this.log('Timer:', name, Date.now() - time);
  31918. }
  31919. };
  31920. // Worker thread?
  31921. if (typeof window === 'undefined') {
  31922. if (!('console' in globalScope)) {
  31923. globalScope.console = workerConsole;
  31924. }
  31925. // Listen for unsupported features so we can pass them on to the main thread.
  31926. PDFJS.UnsupportedManager.listen(function (msg) {
  31927. globalScope.postMessage({
  31928. action: '_unsupported_feature',
  31929. data: msg
  31930. });
  31931. });
  31932. var handler = new MessageHandler('worker_processor', this);
  31933. WorkerMessageHandler.setup(handler);
  31934. }
  31935. /* This class implements the QM Coder decoding as defined in
  31936. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31937. * Annex C.3 Arithmetic decoding procedure
  31938. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31939. *
  31940. * The arithmetic decoder is used in conjunction with context models to decode
  31941. * JPEG2000 and JBIG2 streams.
  31942. */
  31943. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31944. // Table C-2
  31945. var QeTable = [
  31946. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31947. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31948. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31949. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31950. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31951. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31952. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31953. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31954. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31955. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31956. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31957. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31958. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31959. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31960. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31961. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31962. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31963. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31964. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31965. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31966. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31967. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31968. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31969. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31970. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31971. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31972. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31973. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31974. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31975. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31976. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31977. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31978. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31979. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31980. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  31981. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  31982. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  31983. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  31984. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  31985. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  31986. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  31987. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  31988. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  31989. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  31990. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  31991. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  31992. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  31993. ];
  31994. // C.3.5 Initialisation of the decoder (INITDEC)
  31995. function ArithmeticDecoder(data, start, end) {
  31996. this.data = data;
  31997. this.bp = start;
  31998. this.dataEnd = end;
  31999. this.chigh = data[start];
  32000. this.clow = 0;
  32001. this.byteIn();
  32002. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32003. this.clow = (this.clow << 7) & 0xFFFF;
  32004. this.ct -= 7;
  32005. this.a = 0x8000;
  32006. }
  32007. ArithmeticDecoder.prototype = {
  32008. // C.3.4 Compressed data input (BYTEIN)
  32009. byteIn: function ArithmeticDecoder_byteIn() {
  32010. var data = this.data;
  32011. var bp = this.bp;
  32012. if (data[bp] === 0xFF) {
  32013. var b1 = data[bp + 1];
  32014. if (b1 > 0x8F) {
  32015. this.clow += 0xFF00;
  32016. this.ct = 8;
  32017. } else {
  32018. bp++;
  32019. this.clow += (data[bp] << 9);
  32020. this.ct = 7;
  32021. this.bp = bp;
  32022. }
  32023. } else {
  32024. bp++;
  32025. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32026. this.ct = 8;
  32027. this.bp = bp;
  32028. }
  32029. if (this.clow > 0xFFFF) {
  32030. this.chigh += (this.clow >> 16);
  32031. this.clow &= 0xFFFF;
  32032. }
  32033. },
  32034. // C.3.2 Decoding a decision (DECODE)
  32035. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32036. // contexts are packed into 1 byte:
  32037. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32038. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32039. var qeTableIcx = QeTable[cx_index];
  32040. var qeIcx = qeTableIcx.qe;
  32041. var d;
  32042. var a = this.a - qeIcx;
  32043. if (this.chigh < qeIcx) {
  32044. // exchangeLps
  32045. if (a < qeIcx) {
  32046. a = qeIcx;
  32047. d = cx_mps;
  32048. cx_index = qeTableIcx.nmps;
  32049. } else {
  32050. a = qeIcx;
  32051. d = 1 ^ cx_mps;
  32052. if (qeTableIcx.switchFlag === 1) {
  32053. cx_mps = d;
  32054. }
  32055. cx_index = qeTableIcx.nlps;
  32056. }
  32057. } else {
  32058. this.chigh -= qeIcx;
  32059. if ((a & 0x8000) !== 0) {
  32060. this.a = a;
  32061. return cx_mps;
  32062. }
  32063. // exchangeMps
  32064. if (a < qeIcx) {
  32065. d = 1 ^ cx_mps;
  32066. if (qeTableIcx.switchFlag === 1) {
  32067. cx_mps = d;
  32068. }
  32069. cx_index = qeTableIcx.nlps;
  32070. } else {
  32071. d = cx_mps;
  32072. cx_index = qeTableIcx.nmps;
  32073. }
  32074. }
  32075. // C.3.3 renormD;
  32076. do {
  32077. if (this.ct === 0) {
  32078. this.byteIn();
  32079. }
  32080. a <<= 1;
  32081. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32082. this.clow = (this.clow << 1) & 0xFFFF;
  32083. this.ct--;
  32084. } while ((a & 0x8000) === 0);
  32085. this.a = a;
  32086. contexts[pos] = cx_index << 1 | cx_mps;
  32087. return d;
  32088. }
  32089. };
  32090. return ArithmeticDecoder;
  32091. })();
  32092. var JpegImage = (function jpegImage() {
  32093. var dctZigZag = new Uint8Array([
  32094. 0,
  32095. 1, 8,
  32096. 16, 9, 2,
  32097. 3, 10, 17, 24,
  32098. 32, 25, 18, 11, 4,
  32099. 5, 12, 19, 26, 33, 40,
  32100. 48, 41, 34, 27, 20, 13, 6,
  32101. 7, 14, 21, 28, 35, 42, 49, 56,
  32102. 57, 50, 43, 36, 29, 22, 15,
  32103. 23, 30, 37, 44, 51, 58,
  32104. 59, 52, 45, 38, 31,
  32105. 39, 46, 53, 60,
  32106. 61, 54, 47,
  32107. 55, 62,
  32108. 63
  32109. ]);
  32110. var dctCos1 = 4017; // cos(pi/16)
  32111. var dctSin1 = 799; // sin(pi/16)
  32112. var dctCos3 = 3406; // cos(3*pi/16)
  32113. var dctSin3 = 2276; // sin(3*pi/16)
  32114. var dctCos6 = 1567; // cos(6*pi/16)
  32115. var dctSin6 = 3784; // sin(6*pi/16)
  32116. var dctSqrt2 = 5793; // sqrt(2)
  32117. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32118. function constructor() {
  32119. }
  32120. function buildHuffmanTable(codeLengths, values) {
  32121. var k = 0, code = [], i, j, length = 16;
  32122. while (length > 0 && !codeLengths[length - 1]) {
  32123. length--;
  32124. }
  32125. code.push({children: [], index: 0});
  32126. var p = code[0], q;
  32127. for (i = 0; i < length; i++) {
  32128. for (j = 0; j < codeLengths[i]; j++) {
  32129. p = code.pop();
  32130. p.children[p.index] = values[k];
  32131. while (p.index > 0) {
  32132. p = code.pop();
  32133. }
  32134. p.index++;
  32135. code.push(p);
  32136. while (code.length <= i) {
  32137. code.push(q = {children: [], index: 0});
  32138. p.children[p.index] = q.children;
  32139. p = q;
  32140. }
  32141. k++;
  32142. }
  32143. if (i + 1 < length) {
  32144. // p here points to last code
  32145. code.push(q = {children: [], index: 0});
  32146. p.children[p.index] = q.children;
  32147. p = q;
  32148. }
  32149. }
  32150. return code[0].children;
  32151. }
  32152. function getBlockBufferOffset(component, row, col) {
  32153. return 64 * ((component.blocksPerLine + 1) * row + col);
  32154. }
  32155. function decodeScan(data, offset, frame, components, resetInterval,
  32156. spectralStart, spectralEnd, successivePrev, successive) {
  32157. var precision = frame.precision;
  32158. var samplesPerLine = frame.samplesPerLine;
  32159. var scanLines = frame.scanLines;
  32160. var mcusPerLine = frame.mcusPerLine;
  32161. var progressive = frame.progressive;
  32162. var maxH = frame.maxH, maxV = frame.maxV;
  32163. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32164. function readBit() {
  32165. if (bitsCount > 0) {
  32166. bitsCount--;
  32167. return (bitsData >> bitsCount) & 1;
  32168. }
  32169. bitsData = data[offset++];
  32170. if (bitsData === 0xFF) {
  32171. var nextByte = data[offset++];
  32172. if (nextByte) {
  32173. throw 'unexpected marker: ' +
  32174. ((bitsData << 8) | nextByte).toString(16);
  32175. }
  32176. // unstuff 0
  32177. }
  32178. bitsCount = 7;
  32179. return bitsData >>> 7;
  32180. }
  32181. function decodeHuffman(tree) {
  32182. var node = tree;
  32183. while (true) {
  32184. node = node[readBit()];
  32185. if (typeof node === 'number') {
  32186. return node;
  32187. }
  32188. if (typeof node !== 'object') {
  32189. throw 'invalid huffman sequence';
  32190. }
  32191. }
  32192. }
  32193. function receive(length) {
  32194. var n = 0;
  32195. while (length > 0) {
  32196. n = (n << 1) | readBit();
  32197. length--;
  32198. }
  32199. return n;
  32200. }
  32201. function receiveAndExtend(length) {
  32202. if (length === 1) {
  32203. return readBit() === 1 ? 1 : -1;
  32204. }
  32205. var n = receive(length);
  32206. if (n >= 1 << (length - 1)) {
  32207. return n;
  32208. }
  32209. return n + (-1 << length) + 1;
  32210. }
  32211. function decodeBaseline(component, offset) {
  32212. var t = decodeHuffman(component.huffmanTableDC);
  32213. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32214. component.blockData[offset] = (component.pred += diff);
  32215. var k = 1;
  32216. while (k < 64) {
  32217. var rs = decodeHuffman(component.huffmanTableAC);
  32218. var s = rs & 15, r = rs >> 4;
  32219. if (s === 0) {
  32220. if (r < 15) {
  32221. break;
  32222. }
  32223. k += 16;
  32224. continue;
  32225. }
  32226. k += r;
  32227. var z = dctZigZag[k];
  32228. component.blockData[offset + z] = receiveAndExtend(s);
  32229. k++;
  32230. }
  32231. }
  32232. function decodeDCFirst(component, offset) {
  32233. var t = decodeHuffman(component.huffmanTableDC);
  32234. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32235. component.blockData[offset] = (component.pred += diff);
  32236. }
  32237. function decodeDCSuccessive(component, offset) {
  32238. component.blockData[offset] |= readBit() << successive;
  32239. }
  32240. var eobrun = 0;
  32241. function decodeACFirst(component, offset) {
  32242. if (eobrun > 0) {
  32243. eobrun--;
  32244. return;
  32245. }
  32246. var k = spectralStart, e = spectralEnd;
  32247. while (k <= e) {
  32248. var rs = decodeHuffman(component.huffmanTableAC);
  32249. var s = rs & 15, r = rs >> 4;
  32250. if (s === 0) {
  32251. if (r < 15) {
  32252. eobrun = receive(r) + (1 << r) - 1;
  32253. break;
  32254. }
  32255. k += 16;
  32256. continue;
  32257. }
  32258. k += r;
  32259. var z = dctZigZag[k];
  32260. component.blockData[offset + z] =
  32261. receiveAndExtend(s) * (1 << successive);
  32262. k++;
  32263. }
  32264. }
  32265. var successiveACState = 0, successiveACNextValue;
  32266. function decodeACSuccessive(component, offset) {
  32267. var k = spectralStart;
  32268. var e = spectralEnd;
  32269. var r = 0;
  32270. var s;
  32271. var rs;
  32272. while (k <= e) {
  32273. var z = dctZigZag[k];
  32274. switch (successiveACState) {
  32275. case 0: // initial state
  32276. rs = decodeHuffman(component.huffmanTableAC);
  32277. s = rs & 15;
  32278. r = rs >> 4;
  32279. if (s === 0) {
  32280. if (r < 15) {
  32281. eobrun = receive(r) + (1 << r);
  32282. successiveACState = 4;
  32283. } else {
  32284. r = 16;
  32285. successiveACState = 1;
  32286. }
  32287. } else {
  32288. if (s !== 1) {
  32289. throw 'invalid ACn encoding';
  32290. }
  32291. successiveACNextValue = receiveAndExtend(s);
  32292. successiveACState = r ? 2 : 3;
  32293. }
  32294. continue;
  32295. case 1: // skipping r zero items
  32296. case 2:
  32297. if (component.blockData[offset + z]) {
  32298. component.blockData[offset + z] += (readBit() << successive);
  32299. } else {
  32300. r--;
  32301. if (r === 0) {
  32302. successiveACState = successiveACState === 2 ? 3 : 0;
  32303. }
  32304. }
  32305. break;
  32306. case 3: // set value for a zero item
  32307. if (component.blockData[offset + z]) {
  32308. component.blockData[offset + z] += (readBit() << successive);
  32309. } else {
  32310. component.blockData[offset + z] =
  32311. successiveACNextValue << successive;
  32312. successiveACState = 0;
  32313. }
  32314. break;
  32315. case 4: // eob
  32316. if (component.blockData[offset + z]) {
  32317. component.blockData[offset + z] += (readBit() << successive);
  32318. }
  32319. break;
  32320. }
  32321. k++;
  32322. }
  32323. if (successiveACState === 4) {
  32324. eobrun--;
  32325. if (eobrun === 0) {
  32326. successiveACState = 0;
  32327. }
  32328. }
  32329. }
  32330. function decodeMcu(component, decode, mcu, row, col) {
  32331. var mcuRow = (mcu / mcusPerLine) | 0;
  32332. var mcuCol = mcu % mcusPerLine;
  32333. var blockRow = mcuRow * component.v + row;
  32334. var blockCol = mcuCol * component.h + col;
  32335. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32336. decode(component, offset);
  32337. }
  32338. function decodeBlock(component, decode, mcu) {
  32339. var blockRow = (mcu / component.blocksPerLine) | 0;
  32340. var blockCol = mcu % component.blocksPerLine;
  32341. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32342. decode(component, offset);
  32343. }
  32344. var componentsLength = components.length;
  32345. var component, i, j, k, n;
  32346. var decodeFn;
  32347. if (progressive) {
  32348. if (spectralStart === 0) {
  32349. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32350. } else {
  32351. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32352. }
  32353. } else {
  32354. decodeFn = decodeBaseline;
  32355. }
  32356. var mcu = 0, marker;
  32357. var mcuExpected;
  32358. if (componentsLength === 1) {
  32359. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32360. } else {
  32361. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32362. }
  32363. if (!resetInterval) {
  32364. resetInterval = mcuExpected;
  32365. }
  32366. var h, v;
  32367. while (mcu < mcuExpected) {
  32368. // reset interval stuff
  32369. for (i = 0; i < componentsLength; i++) {
  32370. components[i].pred = 0;
  32371. }
  32372. eobrun = 0;
  32373. if (componentsLength === 1) {
  32374. component = components[0];
  32375. for (n = 0; n < resetInterval; n++) {
  32376. decodeBlock(component, decodeFn, mcu);
  32377. mcu++;
  32378. }
  32379. } else {
  32380. for (n = 0; n < resetInterval; n++) {
  32381. for (i = 0; i < componentsLength; i++) {
  32382. component = components[i];
  32383. h = component.h;
  32384. v = component.v;
  32385. for (j = 0; j < v; j++) {
  32386. for (k = 0; k < h; k++) {
  32387. decodeMcu(component, decodeFn, mcu, j, k);
  32388. }
  32389. }
  32390. }
  32391. mcu++;
  32392. }
  32393. }
  32394. // find marker
  32395. bitsCount = 0;
  32396. marker = (data[offset] << 8) | data[offset + 1];
  32397. if (marker <= 0xFF00) {
  32398. throw 'marker was not found';
  32399. }
  32400. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32401. offset += 2;
  32402. } else {
  32403. break;
  32404. }
  32405. }
  32406. return offset - startOffset;
  32407. }
  32408. // A port of poppler's IDCT method which in turn is taken from:
  32409. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32410. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32411. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32412. // 988-991.
  32413. function quantizeAndInverse(component, blockBufferOffset, p) {
  32414. var qt = component.quantizationTable, blockData = component.blockData;
  32415. var v0, v1, v2, v3, v4, v5, v6, v7;
  32416. var p0, p1, p2, p3, p4, p5, p6, p7;
  32417. var t;
  32418. // inverse DCT on rows
  32419. for (var row = 0; row < 64; row += 8) {
  32420. // gather block data
  32421. p0 = blockData[blockBufferOffset + row];
  32422. p1 = blockData[blockBufferOffset + row + 1];
  32423. p2 = blockData[blockBufferOffset + row + 2];
  32424. p3 = blockData[blockBufferOffset + row + 3];
  32425. p4 = blockData[blockBufferOffset + row + 4];
  32426. p5 = blockData[blockBufferOffset + row + 5];
  32427. p6 = blockData[blockBufferOffset + row + 6];
  32428. p7 = blockData[blockBufferOffset + row + 7];
  32429. // dequant p0
  32430. p0 *= qt[row];
  32431. // check for all-zero AC coefficients
  32432. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32433. t = (dctSqrt2 * p0 + 512) >> 10;
  32434. p[row] = t;
  32435. p[row + 1] = t;
  32436. p[row + 2] = t;
  32437. p[row + 3] = t;
  32438. p[row + 4] = t;
  32439. p[row + 5] = t;
  32440. p[row + 6] = t;
  32441. p[row + 7] = t;
  32442. continue;
  32443. }
  32444. // dequant p1 ... p7
  32445. p1 *= qt[row + 1];
  32446. p2 *= qt[row + 2];
  32447. p3 *= qt[row + 3];
  32448. p4 *= qt[row + 4];
  32449. p5 *= qt[row + 5];
  32450. p6 *= qt[row + 6];
  32451. p7 *= qt[row + 7];
  32452. // stage 4
  32453. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32454. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32455. v2 = p2;
  32456. v3 = p6;
  32457. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32458. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32459. v5 = p3 << 4;
  32460. v6 = p5 << 4;
  32461. // stage 3
  32462. v0 = (v0 + v1 + 1) >> 1;
  32463. v1 = v0 - v1;
  32464. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32465. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32466. v3 = t;
  32467. v4 = (v4 + v6 + 1) >> 1;
  32468. v6 = v4 - v6;
  32469. v7 = (v7 + v5 + 1) >> 1;
  32470. v5 = v7 - v5;
  32471. // stage 2
  32472. v0 = (v0 + v3 + 1) >> 1;
  32473. v3 = v0 - v3;
  32474. v1 = (v1 + v2 + 1) >> 1;
  32475. v2 = v1 - v2;
  32476. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32477. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32478. v7 = t;
  32479. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32480. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32481. v6 = t;
  32482. // stage 1
  32483. p[row] = v0 + v7;
  32484. p[row + 7] = v0 - v7;
  32485. p[row + 1] = v1 + v6;
  32486. p[row + 6] = v1 - v6;
  32487. p[row + 2] = v2 + v5;
  32488. p[row + 5] = v2 - v5;
  32489. p[row + 3] = v3 + v4;
  32490. p[row + 4] = v3 - v4;
  32491. }
  32492. // inverse DCT on columns
  32493. for (var col = 0; col < 8; ++col) {
  32494. p0 = p[col];
  32495. p1 = p[col + 8];
  32496. p2 = p[col + 16];
  32497. p3 = p[col + 24];
  32498. p4 = p[col + 32];
  32499. p5 = p[col + 40];
  32500. p6 = p[col + 48];
  32501. p7 = p[col + 56];
  32502. // check for all-zero AC coefficients
  32503. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32504. t = (dctSqrt2 * p0 + 8192) >> 14;
  32505. // convert to 8 bit
  32506. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32507. blockData[blockBufferOffset + col] = t;
  32508. blockData[blockBufferOffset + col + 8] = t;
  32509. blockData[blockBufferOffset + col + 16] = t;
  32510. blockData[blockBufferOffset + col + 24] = t;
  32511. blockData[blockBufferOffset + col + 32] = t;
  32512. blockData[blockBufferOffset + col + 40] = t;
  32513. blockData[blockBufferOffset + col + 48] = t;
  32514. blockData[blockBufferOffset + col + 56] = t;
  32515. continue;
  32516. }
  32517. // stage 4
  32518. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32519. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32520. v2 = p2;
  32521. v3 = p6;
  32522. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32523. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32524. v5 = p3;
  32525. v6 = p5;
  32526. // stage 3
  32527. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32528. // converting to UInt8 range later.
  32529. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32530. v1 = v0 - v1;
  32531. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32532. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32533. v3 = t;
  32534. v4 = (v4 + v6 + 1) >> 1;
  32535. v6 = v4 - v6;
  32536. v7 = (v7 + v5 + 1) >> 1;
  32537. v5 = v7 - v5;
  32538. // stage 2
  32539. v0 = (v0 + v3 + 1) >> 1;
  32540. v3 = v0 - v3;
  32541. v1 = (v1 + v2 + 1) >> 1;
  32542. v2 = v1 - v2;
  32543. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32544. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32545. v7 = t;
  32546. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32547. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32548. v6 = t;
  32549. // stage 1
  32550. p0 = v0 + v7;
  32551. p7 = v0 - v7;
  32552. p1 = v1 + v6;
  32553. p6 = v1 - v6;
  32554. p2 = v2 + v5;
  32555. p5 = v2 - v5;
  32556. p3 = v3 + v4;
  32557. p4 = v3 - v4;
  32558. // convert to 8-bit integers
  32559. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32560. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32561. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32562. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32563. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32564. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32565. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32566. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32567. // store block data
  32568. blockData[blockBufferOffset + col] = p0;
  32569. blockData[blockBufferOffset + col + 8] = p1;
  32570. blockData[blockBufferOffset + col + 16] = p2;
  32571. blockData[blockBufferOffset + col + 24] = p3;
  32572. blockData[blockBufferOffset + col + 32] = p4;
  32573. blockData[blockBufferOffset + col + 40] = p5;
  32574. blockData[blockBufferOffset + col + 48] = p6;
  32575. blockData[blockBufferOffset + col + 56] = p7;
  32576. }
  32577. }
  32578. function buildComponentData(frame, component) {
  32579. var blocksPerLine = component.blocksPerLine;
  32580. var blocksPerColumn = component.blocksPerColumn;
  32581. var computationBuffer = new Int16Array(64);
  32582. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32583. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32584. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32585. quantizeAndInverse(component, offset, computationBuffer);
  32586. }
  32587. }
  32588. return component.blockData;
  32589. }
  32590. function clamp0to255(a) {
  32591. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32592. }
  32593. constructor.prototype = {
  32594. parse: function parse(data) {
  32595. function readUint16() {
  32596. var value = (data[offset] << 8) | data[offset + 1];
  32597. offset += 2;
  32598. return value;
  32599. }
  32600. function readDataBlock() {
  32601. var length = readUint16();
  32602. var array = data.subarray(offset, offset + length - 2);
  32603. offset += array.length;
  32604. return array;
  32605. }
  32606. function prepareComponents(frame) {
  32607. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32608. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32609. for (var i = 0; i < frame.components.length; i++) {
  32610. component = frame.components[i];
  32611. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32612. component.h / frame.maxH);
  32613. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32614. component.v / frame.maxV);
  32615. var blocksPerLineForMcu = mcusPerLine * component.h;
  32616. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32617. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32618. (blocksPerLineForMcu + 1);
  32619. component.blockData = new Int16Array(blocksBufferSize);
  32620. component.blocksPerLine = blocksPerLine;
  32621. component.blocksPerColumn = blocksPerColumn;
  32622. }
  32623. frame.mcusPerLine = mcusPerLine;
  32624. frame.mcusPerColumn = mcusPerColumn;
  32625. }
  32626. var offset = 0, length = data.length;
  32627. var jfif = null;
  32628. var adobe = null;
  32629. var pixels = null;
  32630. var frame, resetInterval;
  32631. var quantizationTables = [];
  32632. var huffmanTablesAC = [], huffmanTablesDC = [];
  32633. var fileMarker = readUint16();
  32634. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32635. throw 'SOI not found';
  32636. }
  32637. fileMarker = readUint16();
  32638. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32639. var i, j, l;
  32640. switch(fileMarker) {
  32641. case 0xFFE0: // APP0 (Application Specific)
  32642. case 0xFFE1: // APP1
  32643. case 0xFFE2: // APP2
  32644. case 0xFFE3: // APP3
  32645. case 0xFFE4: // APP4
  32646. case 0xFFE5: // APP5
  32647. case 0xFFE6: // APP6
  32648. case 0xFFE7: // APP7
  32649. case 0xFFE8: // APP8
  32650. case 0xFFE9: // APP9
  32651. case 0xFFEA: // APP10
  32652. case 0xFFEB: // APP11
  32653. case 0xFFEC: // APP12
  32654. case 0xFFED: // APP13
  32655. case 0xFFEE: // APP14
  32656. case 0xFFEF: // APP15
  32657. case 0xFFFE: // COM (Comment)
  32658. var appData = readDataBlock();
  32659. if (fileMarker === 0xFFE0) {
  32660. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32661. appData[2] === 0x49 && appData[3] === 0x46 &&
  32662. appData[4] === 0) { // 'JFIF\x00'
  32663. jfif = {
  32664. version: { major: appData[5], minor: appData[6] },
  32665. densityUnits: appData[7],
  32666. xDensity: (appData[8] << 8) | appData[9],
  32667. yDensity: (appData[10] << 8) | appData[11],
  32668. thumbWidth: appData[12],
  32669. thumbHeight: appData[13],
  32670. thumbData: appData.subarray(14, 14 +
  32671. 3 * appData[12] * appData[13])
  32672. };
  32673. }
  32674. }
  32675. // TODO APP1 - Exif
  32676. if (fileMarker === 0xFFEE) {
  32677. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32678. appData[2] === 0x6F && appData[3] === 0x62 &&
  32679. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32680. adobe = {
  32681. version: appData[6],
  32682. flags0: (appData[7] << 8) | appData[8],
  32683. flags1: (appData[9] << 8) | appData[10],
  32684. transformCode: appData[11]
  32685. };
  32686. }
  32687. }
  32688. break;
  32689. case 0xFFDB: // DQT (Define Quantization Tables)
  32690. var quantizationTablesLength = readUint16();
  32691. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32692. var z;
  32693. while (offset < quantizationTablesEnd) {
  32694. var quantizationTableSpec = data[offset++];
  32695. var tableData = new Uint16Array(64);
  32696. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32697. for (j = 0; j < 64; j++) {
  32698. z = dctZigZag[j];
  32699. tableData[z] = data[offset++];
  32700. }
  32701. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32702. for (j = 0; j < 64; j++) {
  32703. z = dctZigZag[j];
  32704. tableData[z] = readUint16();
  32705. }
  32706. } else {
  32707. throw 'DQT: invalid table spec';
  32708. }
  32709. quantizationTables[quantizationTableSpec & 15] = tableData;
  32710. }
  32711. break;
  32712. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32713. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32714. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32715. if (frame) {
  32716. throw 'Only single frame JPEGs supported';
  32717. }
  32718. readUint16(); // skip data length
  32719. frame = {};
  32720. frame.extended = (fileMarker === 0xFFC1);
  32721. frame.progressive = (fileMarker === 0xFFC2);
  32722. frame.precision = data[offset++];
  32723. frame.scanLines = readUint16();
  32724. frame.samplesPerLine = readUint16();
  32725. frame.components = [];
  32726. frame.componentIds = {};
  32727. var componentsCount = data[offset++], componentId;
  32728. var maxH = 0, maxV = 0;
  32729. for (i = 0; i < componentsCount; i++) {
  32730. componentId = data[offset];
  32731. var h = data[offset + 1] >> 4;
  32732. var v = data[offset + 1] & 15;
  32733. if (maxH < h) {
  32734. maxH = h;
  32735. }
  32736. if (maxV < v) {
  32737. maxV = v;
  32738. }
  32739. var qId = data[offset + 2];
  32740. l = frame.components.push({
  32741. h: h,
  32742. v: v,
  32743. quantizationTable: quantizationTables[qId]
  32744. });
  32745. frame.componentIds[componentId] = l - 1;
  32746. offset += 3;
  32747. }
  32748. frame.maxH = maxH;
  32749. frame.maxV = maxV;
  32750. prepareComponents(frame);
  32751. break;
  32752. case 0xFFC4: // DHT (Define Huffman Tables)
  32753. var huffmanLength = readUint16();
  32754. for (i = 2; i < huffmanLength;) {
  32755. var huffmanTableSpec = data[offset++];
  32756. var codeLengths = new Uint8Array(16);
  32757. var codeLengthSum = 0;
  32758. for (j = 0; j < 16; j++, offset++) {
  32759. codeLengthSum += (codeLengths[j] = data[offset]);
  32760. }
  32761. var huffmanValues = new Uint8Array(codeLengthSum);
  32762. for (j = 0; j < codeLengthSum; j++, offset++) {
  32763. huffmanValues[j] = data[offset];
  32764. }
  32765. i += 17 + codeLengthSum;
  32766. ((huffmanTableSpec >> 4) === 0 ?
  32767. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32768. buildHuffmanTable(codeLengths, huffmanValues);
  32769. }
  32770. break;
  32771. case 0xFFDD: // DRI (Define Restart Interval)
  32772. readUint16(); // skip data length
  32773. resetInterval = readUint16();
  32774. break;
  32775. case 0xFFDA: // SOS (Start of Scan)
  32776. var scanLength = readUint16();
  32777. var selectorsCount = data[offset++];
  32778. var components = [], component;
  32779. for (i = 0; i < selectorsCount; i++) {
  32780. var componentIndex = frame.componentIds[data[offset++]];
  32781. component = frame.components[componentIndex];
  32782. var tableSpec = data[offset++];
  32783. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32784. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32785. components.push(component);
  32786. }
  32787. var spectralStart = data[offset++];
  32788. var spectralEnd = data[offset++];
  32789. var successiveApproximation = data[offset++];
  32790. var processed = decodeScan(data, offset,
  32791. frame, components, resetInterval,
  32792. spectralStart, spectralEnd,
  32793. successiveApproximation >> 4, successiveApproximation & 15);
  32794. offset += processed;
  32795. break;
  32796. default:
  32797. if (data[offset - 3] === 0xFF &&
  32798. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32799. // could be incorrect encoding -- last 0xFF byte of the previous
  32800. // block was eaten by the encoder
  32801. offset -= 3;
  32802. break;
  32803. }
  32804. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32805. }
  32806. fileMarker = readUint16();
  32807. }
  32808. this.width = frame.samplesPerLine;
  32809. this.height = frame.scanLines;
  32810. this.jfif = jfif;
  32811. this.adobe = adobe;
  32812. this.components = [];
  32813. for (i = 0; i < frame.components.length; i++) {
  32814. component = frame.components[i];
  32815. this.components.push({
  32816. output: buildComponentData(frame, component),
  32817. scaleX: component.h / frame.maxH,
  32818. scaleY: component.v / frame.maxV,
  32819. blocksPerLine: component.blocksPerLine,
  32820. blocksPerColumn: component.blocksPerColumn
  32821. });
  32822. }
  32823. this.numComponents = this.components.length;
  32824. },
  32825. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32826. var scaleX = this.width / width, scaleY = this.height / height;
  32827. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32828. var x, y, i, j, k;
  32829. var index;
  32830. var offset = 0;
  32831. var output;
  32832. var numComponents = this.components.length;
  32833. var dataLength = width * height * numComponents;
  32834. var data = new Uint8Array(dataLength);
  32835. var xScaleBlockOffset = new Uint32Array(width);
  32836. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32837. for (i = 0; i < numComponents; i++) {
  32838. component = this.components[i];
  32839. componentScaleX = component.scaleX * scaleX;
  32840. componentScaleY = component.scaleY * scaleY;
  32841. offset = i;
  32842. output = component.output;
  32843. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32844. // precalculate the xScaleBlockOffset
  32845. for (x = 0; x < width; x++) {
  32846. j = 0 | (x * componentScaleX);
  32847. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32848. }
  32849. // linearize the blocks of the component
  32850. for (y = 0; y < height; y++) {
  32851. j = 0 | (y * componentScaleY);
  32852. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32853. for (x = 0; x < width; x++) {
  32854. data[offset] = output[index + xScaleBlockOffset[x]];
  32855. offset += numComponents;
  32856. }
  32857. }
  32858. }
  32859. // decodeTransform contains pairs of multiplier (-256..256) and additive
  32860. var transform = this.decodeTransform;
  32861. if (transform) {
  32862. for (i = 0; i < dataLength;) {
  32863. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32864. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32865. }
  32866. }
  32867. }
  32868. return data;
  32869. },
  32870. _isColorConversionNeeded: function isColorConversionNeeded() {
  32871. if (this.adobe && this.adobe.transformCode) {
  32872. // The adobe transform marker overrides any previous setting
  32873. return true;
  32874. } else if (this.numComponents === 3) {
  32875. return true;
  32876. } else {
  32877. return false;
  32878. }
  32879. },
  32880. _convertYccToRgb: function convertYccToRgb(data) {
  32881. var Y, Cb, Cr;
  32882. for (var i = 0, length = data.length; i < length; i += 3) {
  32883. Y = data[i ];
  32884. Cb = data[i + 1];
  32885. Cr = data[i + 2];
  32886. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  32887. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  32888. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  32889. }
  32890. return data;
  32891. },
  32892. _convertYcckToRgb: function convertYcckToRgb(data) {
  32893. var Y, Cb, Cr, k;
  32894. var offset = 0;
  32895. for (var i = 0, length = data.length; i < length; i += 4) {
  32896. Y = data[i];
  32897. Cb = data[i + 1];
  32898. Cr = data[i + 2];
  32899. k = data[i + 3];
  32900. var r = -122.67195406894 +
  32901. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  32902. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  32903. 0.154362151871126) +
  32904. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  32905. 0.00477271405408747 * k + 1.53380253221734) +
  32906. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  32907. 0.48357088451265) +
  32908. k * (-0.000336197177618394 * k + 0.484791561490776);
  32909. var g = 107.268039397724 +
  32910. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  32911. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  32912. 0.176491792462875) +
  32913. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  32914. 0.000770482631801132 * k - 0.151051492775562) +
  32915. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  32916. 0.25802910206845) +
  32917. k * (-0.000318913117588328 * k - 0.213742400323665);
  32918. var b = -20.810012546947 +
  32919. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  32920. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  32921. 0.814272968359295) +
  32922. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  32923. 0.000560833691242812 * k - 0.195152027534049) +
  32924. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  32925. 0.116935020465145) +
  32926. k * (-0.000343531996510555 * k + 0.24165260232407);
  32927. data[offset++] = clamp0to255(r);
  32928. data[offset++] = clamp0to255(g);
  32929. data[offset++] = clamp0to255(b);
  32930. }
  32931. return data;
  32932. },
  32933. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32934. var Y, Cb, Cr;
  32935. for (var i = 0, length = data.length; i < length; i += 4) {
  32936. Y = data[i];
  32937. Cb = data[i + 1];
  32938. Cr = data[i + 2];
  32939. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32940. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32941. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32942. // K in data[i + 3] is unchanged
  32943. }
  32944. return data;
  32945. },
  32946. _convertCmykToRgb: function convertCmykToRgb(data) {
  32947. var c, m, y, k;
  32948. var offset = 0;
  32949. var min = -255 * 255 * 255;
  32950. var scale = 1 / 255 / 255;
  32951. for (var i = 0, length = data.length; i < length; i += 4) {
  32952. c = data[i];
  32953. m = data[i + 1];
  32954. y = data[i + 2];
  32955. k = data[i + 3];
  32956. var r =
  32957. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32958. 18.82290502165302 * y + 212.25662451639585 * k -
  32959. 72734.4411664936) +
  32960. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32961. 17.873870861415444 * k - 1401.7366389350734) +
  32962. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32963. 4465.541406466231) -
  32964. k * (21.86122147463605 * k + 48317.86113160301);
  32965. var g =
  32966. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32967. 6.871425592049007 * y + 31.159100130055922 * k -
  32968. 20220.756542821975) +
  32969. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32970. 131.35250912493976 * k - 48691.05921601825) +
  32971. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32972. 6341.191035517494) -
  32973. k * (20.737325471181034 * k + 47890.15695978492);
  32974. var b =
  32975. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32976. 30.89978309703729 * y - 0.23883238689178934 * k -
  32977. 3616.812083916688) +
  32978. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32979. 50.606957656360734 * k - 28620.90484698408) +
  32980. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  32981. 49363.43385999684) -
  32982. k * (22.33816807309886 * k + 45932.16563550634);
  32983. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  32984. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  32985. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  32986. }
  32987. return data;
  32988. },
  32989. getData: function getData(width, height, forceRGBoutput) {
  32990. if (this.numComponents > 4) {
  32991. throw 'Unsupported color mode';
  32992. }
  32993. // type of data: Uint8Array(width * height * numComponents)
  32994. var data = this._getLinearizedBlockData(width, height);
  32995. if (this.numComponents === 3) {
  32996. return this._convertYccToRgb(data);
  32997. } else if (this.numComponents === 4) {
  32998. if (this._isColorConversionNeeded()) {
  32999. if (forceRGBoutput) {
  33000. return this._convertYcckToRgb(data);
  33001. } else {
  33002. return this._convertYcckToCmyk(data);
  33003. }
  33004. } else if (forceRGBoutput) {
  33005. return this._convertCmykToRgb(data);
  33006. }
  33007. }
  33008. return data;
  33009. }
  33010. };
  33011. return constructor;
  33012. })();
  33013. var JpxImage = (function JpxImageClosure() {
  33014. // Table E.1
  33015. var SubbandsGainLog2 = {
  33016. 'LL': 0,
  33017. 'LH': 1,
  33018. 'HL': 1,
  33019. 'HH': 2
  33020. };
  33021. function JpxImage() {
  33022. this.failOnCorruptedImage = false;
  33023. }
  33024. JpxImage.prototype = {
  33025. parse: function JpxImage_parse(data) {
  33026. var head = readUint16(data, 0);
  33027. // No box header, immediate start of codestream (SOC)
  33028. if (head === 0xFF4F) {
  33029. this.parseCodestream(data, 0, data.length);
  33030. return;
  33031. }
  33032. var position = 0, length = data.length;
  33033. while (position < length) {
  33034. var headerSize = 8;
  33035. var lbox = readUint32(data, position);
  33036. var tbox = readUint32(data, position + 4);
  33037. position += headerSize;
  33038. if (lbox === 1) {
  33039. // XLBox: read UInt64 according to spec.
  33040. // JavaScript's int precision of 53 bit should be sufficient here.
  33041. lbox = readUint32(data, position) * 4294967296 +
  33042. readUint32(data, position + 4);
  33043. position += 8;
  33044. headerSize += 8;
  33045. }
  33046. if (lbox === 0) {
  33047. lbox = length - position + headerSize;
  33048. }
  33049. if (lbox < headerSize) {
  33050. throw new Error('JPX Error: Invalid box field size');
  33051. }
  33052. var dataLength = lbox - headerSize;
  33053. var jumpDataLength = true;
  33054. switch (tbox) {
  33055. case 0x6A703268: // 'jp2h'
  33056. jumpDataLength = false; // parsing child boxes
  33057. break;
  33058. case 0x636F6C72: // 'colr'
  33059. // Colorspaces are not used, the CS from the PDF is used.
  33060. var method = data[position];
  33061. var precedence = data[position + 1];
  33062. var approximation = data[position + 2];
  33063. if (method === 1) {
  33064. // enumerated colorspace
  33065. var colorspace = readUint32(data, position + 3);
  33066. switch (colorspace) {
  33067. case 16: // this indicates a sRGB colorspace
  33068. case 17: // this indicates a grayscale colorspace
  33069. case 18: // this indicates a YUV colorspace
  33070. break;
  33071. default:
  33072. warn('Unknown colorspace ' + colorspace);
  33073. break;
  33074. }
  33075. } else if (method === 2) {
  33076. info('ICC profile not supported');
  33077. }
  33078. break;
  33079. case 0x6A703263: // 'jp2c'
  33080. this.parseCodestream(data, position, position + dataLength);
  33081. break;
  33082. case 0x6A502020: // 'jP\024\024'
  33083. if (0x0d0a870a !== readUint32(data, position)) {
  33084. warn('Invalid JP2 signature');
  33085. }
  33086. break;
  33087. // The following header types are valid but currently not used:
  33088. case 0x6A501A1A: // 'jP\032\032'
  33089. case 0x66747970: // 'ftyp'
  33090. case 0x72726571: // 'rreq'
  33091. case 0x72657320: // 'res '
  33092. case 0x69686472: // 'ihdr'
  33093. break;
  33094. default:
  33095. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33096. (tbox >> 16) & 0xFF,
  33097. (tbox >> 8) & 0xFF,
  33098. tbox & 0xFF);
  33099. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33100. break;
  33101. }
  33102. if (jumpDataLength) {
  33103. position += dataLength;
  33104. }
  33105. }
  33106. },
  33107. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33108. var newByte = stream.getByte();
  33109. while (newByte >= 0) {
  33110. var oldByte = newByte;
  33111. newByte = stream.getByte();
  33112. var code = (oldByte << 8) | newByte;
  33113. // Image and tile size (SIZ)
  33114. if (code === 0xFF51) {
  33115. stream.skip(4);
  33116. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33117. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33118. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33119. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33120. stream.skip(16);
  33121. var Csiz = stream.getUint16(); // Byte 36
  33122. this.width = Xsiz - XOsiz;
  33123. this.height = Ysiz - YOsiz;
  33124. this.componentsCount = Csiz;
  33125. // Results are always returned as Uint8Arrays
  33126. this.bitsPerComponent = 8;
  33127. return;
  33128. }
  33129. }
  33130. throw new Error('JPX Error: No size marker found in JPX stream');
  33131. },
  33132. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33133. var context = {};
  33134. try {
  33135. var doNotRecover = false;
  33136. var position = start;
  33137. while (position + 1 < end) {
  33138. var code = readUint16(data, position);
  33139. position += 2;
  33140. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33141. switch (code) {
  33142. case 0xFF4F: // Start of codestream (SOC)
  33143. context.mainHeader = true;
  33144. break;
  33145. case 0xFFD9: // End of codestream (EOC)
  33146. break;
  33147. case 0xFF51: // Image and tile size (SIZ)
  33148. length = readUint16(data, position);
  33149. var siz = {};
  33150. siz.Xsiz = readUint32(data, position + 4);
  33151. siz.Ysiz = readUint32(data, position + 8);
  33152. siz.XOsiz = readUint32(data, position + 12);
  33153. siz.YOsiz = readUint32(data, position + 16);
  33154. siz.XTsiz = readUint32(data, position + 20);
  33155. siz.YTsiz = readUint32(data, position + 24);
  33156. siz.XTOsiz = readUint32(data, position + 28);
  33157. siz.YTOsiz = readUint32(data, position + 32);
  33158. var componentsCount = readUint16(data, position + 36);
  33159. siz.Csiz = componentsCount;
  33160. var components = [];
  33161. j = position + 38;
  33162. for (var i = 0; i < componentsCount; i++) {
  33163. var component = {
  33164. precision: (data[j] & 0x7F) + 1,
  33165. isSigned: !!(data[j] & 0x80),
  33166. XRsiz: data[j + 1],
  33167. YRsiz: data[j + 1]
  33168. };
  33169. calculateComponentDimensions(component, siz);
  33170. components.push(component);
  33171. }
  33172. context.SIZ = siz;
  33173. context.components = components;
  33174. calculateTileGrids(context, components);
  33175. context.QCC = [];
  33176. context.COC = [];
  33177. break;
  33178. case 0xFF55: // Tile-part lengths, main header (TLM)
  33179. var Ltlm = readUint16(data, position); // Marker segment length
  33180. // Skip tile length markers
  33181. position += Ltlm;
  33182. break;
  33183. case 0xFF5C: // Quantization default (QCD)
  33184. length = readUint16(data, position);
  33185. var qcd = {};
  33186. j = position + 2;
  33187. sqcd = data[j++];
  33188. switch (sqcd & 0x1F) {
  33189. case 0:
  33190. spqcdSize = 8;
  33191. scalarExpounded = true;
  33192. break;
  33193. case 1:
  33194. spqcdSize = 16;
  33195. scalarExpounded = false;
  33196. break;
  33197. case 2:
  33198. spqcdSize = 16;
  33199. scalarExpounded = true;
  33200. break;
  33201. default:
  33202. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33203. }
  33204. qcd.noQuantization = (spqcdSize === 8);
  33205. qcd.scalarExpounded = scalarExpounded;
  33206. qcd.guardBits = sqcd >> 5;
  33207. spqcds = [];
  33208. while (j < length + position) {
  33209. var spqcd = {};
  33210. if (spqcdSize === 8) {
  33211. spqcd.epsilon = data[j++] >> 3;
  33212. spqcd.mu = 0;
  33213. } else {
  33214. spqcd.epsilon = data[j] >> 3;
  33215. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33216. j += 2;
  33217. }
  33218. spqcds.push(spqcd);
  33219. }
  33220. qcd.SPqcds = spqcds;
  33221. if (context.mainHeader) {
  33222. context.QCD = qcd;
  33223. } else {
  33224. context.currentTile.QCD = qcd;
  33225. context.currentTile.QCC = [];
  33226. }
  33227. break;
  33228. case 0xFF5D: // Quantization component (QCC)
  33229. length = readUint16(data, position);
  33230. var qcc = {};
  33231. j = position + 2;
  33232. var cqcc;
  33233. if (context.SIZ.Csiz < 257) {
  33234. cqcc = data[j++];
  33235. } else {
  33236. cqcc = readUint16(data, j);
  33237. j += 2;
  33238. }
  33239. sqcd = data[j++];
  33240. switch (sqcd & 0x1F) {
  33241. case 0:
  33242. spqcdSize = 8;
  33243. scalarExpounded = true;
  33244. break;
  33245. case 1:
  33246. spqcdSize = 16;
  33247. scalarExpounded = false;
  33248. break;
  33249. case 2:
  33250. spqcdSize = 16;
  33251. scalarExpounded = true;
  33252. break;
  33253. default:
  33254. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33255. }
  33256. qcc.noQuantization = (spqcdSize === 8);
  33257. qcc.scalarExpounded = scalarExpounded;
  33258. qcc.guardBits = sqcd >> 5;
  33259. spqcds = [];
  33260. while (j < (length + position)) {
  33261. spqcd = {};
  33262. if (spqcdSize === 8) {
  33263. spqcd.epsilon = data[j++] >> 3;
  33264. spqcd.mu = 0;
  33265. } else {
  33266. spqcd.epsilon = data[j] >> 3;
  33267. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33268. j += 2;
  33269. }
  33270. spqcds.push(spqcd);
  33271. }
  33272. qcc.SPqcds = spqcds;
  33273. if (context.mainHeader) {
  33274. context.QCC[cqcc] = qcc;
  33275. } else {
  33276. context.currentTile.QCC[cqcc] = qcc;
  33277. }
  33278. break;
  33279. case 0xFF52: // Coding style default (COD)
  33280. length = readUint16(data, position);
  33281. var cod = {};
  33282. j = position + 2;
  33283. var scod = data[j++];
  33284. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33285. cod.sopMarkerUsed = !!(scod & 2);
  33286. cod.ephMarkerUsed = !!(scod & 4);
  33287. cod.progressionOrder = data[j++];
  33288. cod.layersCount = readUint16(data, j);
  33289. j += 2;
  33290. cod.multipleComponentTransform = data[j++];
  33291. cod.decompositionLevelsCount = data[j++];
  33292. cod.xcb = (data[j++] & 0xF) + 2;
  33293. cod.ycb = (data[j++] & 0xF) + 2;
  33294. var blockStyle = data[j++];
  33295. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33296. cod.resetContextProbabilities = !!(blockStyle & 2);
  33297. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33298. cod.verticalyStripe = !!(blockStyle & 8);
  33299. cod.predictableTermination = !!(blockStyle & 16);
  33300. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33301. cod.reversibleTransformation = data[j++];
  33302. if (cod.entropyCoderWithCustomPrecincts) {
  33303. var precinctsSizes = [];
  33304. while (j < length + position) {
  33305. var precinctsSize = data[j++];
  33306. precinctsSizes.push({
  33307. PPx: precinctsSize & 0xF,
  33308. PPy: precinctsSize >> 4
  33309. });
  33310. }
  33311. cod.precinctsSizes = precinctsSizes;
  33312. }
  33313. var unsupported = [];
  33314. if (cod.selectiveArithmeticCodingBypass) {
  33315. unsupported.push('selectiveArithmeticCodingBypass');
  33316. }
  33317. if (cod.resetContextProbabilities) {
  33318. unsupported.push('resetContextProbabilities');
  33319. }
  33320. if (cod.terminationOnEachCodingPass) {
  33321. unsupported.push('terminationOnEachCodingPass');
  33322. }
  33323. if (cod.verticalyStripe) {
  33324. unsupported.push('verticalyStripe');
  33325. }
  33326. if (cod.predictableTermination) {
  33327. unsupported.push('predictableTermination');
  33328. }
  33329. if (unsupported.length > 0) {
  33330. doNotRecover = true;
  33331. throw new Error('JPX Error: Unsupported COD options (' +
  33332. unsupported.join(', ') + ')');
  33333. }
  33334. if (context.mainHeader) {
  33335. context.COD = cod;
  33336. } else {
  33337. context.currentTile.COD = cod;
  33338. context.currentTile.COC = [];
  33339. }
  33340. break;
  33341. case 0xFF90: // Start of tile-part (SOT)
  33342. length = readUint16(data, position);
  33343. tile = {};
  33344. tile.index = readUint16(data, position + 2);
  33345. tile.length = readUint32(data, position + 4);
  33346. tile.dataEnd = tile.length + position - 2;
  33347. tile.partIndex = data[position + 8];
  33348. tile.partsCount = data[position + 9];
  33349. context.mainHeader = false;
  33350. if (tile.partIndex === 0) {
  33351. // reset component specific settings
  33352. tile.COD = context.COD;
  33353. tile.COC = context.COC.slice(0); // clone of the global COC
  33354. tile.QCD = context.QCD;
  33355. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33356. }
  33357. context.currentTile = tile;
  33358. break;
  33359. case 0xFF93: // Start of data (SOD)
  33360. tile = context.currentTile;
  33361. if (tile.partIndex === 0) {
  33362. initializeTile(context, tile.index);
  33363. buildPackets(context);
  33364. }
  33365. // moving to the end of the data
  33366. length = tile.dataEnd - position;
  33367. parseTilePackets(context, data, position, length);
  33368. break;
  33369. case 0xFF64: // Comment (COM)
  33370. length = readUint16(data, position);
  33371. // skipping content
  33372. break;
  33373. case 0xFF53: // Coding style component (COC)
  33374. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33375. 'not implemented');
  33376. default:
  33377. throw new Error('JPX Error: Unknown codestream code: ' +
  33378. code.toString(16));
  33379. }
  33380. position += length;
  33381. }
  33382. } catch (e) {
  33383. if (doNotRecover || this.failOnCorruptedImage) {
  33384. throw e;
  33385. } else {
  33386. warn('Trying to recover from ' + e.message);
  33387. }
  33388. }
  33389. this.tiles = transformComponents(context);
  33390. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33391. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33392. this.componentsCount = context.SIZ.Csiz;
  33393. }
  33394. };
  33395. function calculateComponentDimensions(component, siz) {
  33396. // Section B.2 Component mapping
  33397. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33398. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33399. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33400. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33401. component.width = component.x1 - component.x0;
  33402. component.height = component.y1 - component.y0;
  33403. }
  33404. function calculateTileGrids(context, components) {
  33405. var siz = context.SIZ;
  33406. // Section B.3 Division into tile and tile-components
  33407. var tile, tiles = [];
  33408. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33409. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33410. for (var q = 0; q < numYtiles; q++) {
  33411. for (var p = 0; p < numXtiles; p++) {
  33412. tile = {};
  33413. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33414. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33415. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33416. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33417. tile.width = tile.tx1 - tile.tx0;
  33418. tile.height = tile.ty1 - tile.ty0;
  33419. tile.components = [];
  33420. tiles.push(tile);
  33421. }
  33422. }
  33423. context.tiles = tiles;
  33424. var componentsCount = siz.Csiz;
  33425. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33426. var component = components[i];
  33427. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33428. var tileComponent = {};
  33429. tile = tiles[j];
  33430. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33431. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33432. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33433. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33434. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33435. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33436. tile.components[i] = tileComponent;
  33437. }
  33438. }
  33439. }
  33440. function getBlocksDimensions(context, component, r) {
  33441. var codOrCoc = component.codingStyleParameters;
  33442. var result = {};
  33443. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33444. result.PPx = 15;
  33445. result.PPy = 15;
  33446. } else {
  33447. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33448. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33449. }
  33450. // calculate codeblock size as described in section B.7
  33451. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33452. Math.min(codOrCoc.xcb, result.PPx));
  33453. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33454. Math.min(codOrCoc.ycb, result.PPy));
  33455. return result;
  33456. }
  33457. function buildPrecincts(context, resolution, dimensions) {
  33458. // Section B.6 Division resolution to precincts
  33459. var precinctWidth = 1 << dimensions.PPx;
  33460. var precinctHeight = 1 << dimensions.PPy;
  33461. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33462. // to precincts. Precinct partition divides a resolution according to width
  33463. // and height parameters. The subband that belongs to the resolution level
  33464. // has a different size than the level, unless it is the zero resolution.
  33465. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33466. // The precinct partitioning for a particular subband is derived from a
  33467. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33468. // resolution level)... The LL band associated with each resolution level is
  33469. // divided into precincts... Each of the resulting precinct regions is then
  33470. // mapped into its child subbands (if any) at the next lower resolution
  33471. // level. This is accomplished by using the coordinate transformation
  33472. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33473. // coordinates of a point in the LL band and child subband, respectively.
  33474. var isZeroRes = resolution.resLevel === 0;
  33475. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33476. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33477. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33478. Math.ceil(resolution.trx1 / precinctWidth) -
  33479. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33480. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33481. Math.ceil(resolution.try1 / precinctHeight) -
  33482. Math.floor(resolution.try0 / precinctHeight) : 0);
  33483. var numprecincts = numprecinctswide * numprecinctshigh;
  33484. resolution.precinctParameters = {
  33485. precinctWidth: precinctWidth,
  33486. precinctHeight: precinctHeight,
  33487. numprecinctswide: numprecinctswide,
  33488. numprecinctshigh: numprecinctshigh,
  33489. numprecincts: numprecincts,
  33490. precinctWidthInSubband: precinctWidthInSubband,
  33491. precinctHeightInSubband: precinctHeightInSubband
  33492. };
  33493. }
  33494. function buildCodeblocks(context, subband, dimensions) {
  33495. // Section B.7 Division sub-band into code-blocks
  33496. var xcb_ = dimensions.xcb_;
  33497. var ycb_ = dimensions.ycb_;
  33498. var codeblockWidth = 1 << xcb_;
  33499. var codeblockHeight = 1 << ycb_;
  33500. var cbx0 = subband.tbx0 >> xcb_;
  33501. var cby0 = subband.tby0 >> ycb_;
  33502. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33503. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33504. var precinctParameters = subband.resolution.precinctParameters;
  33505. var codeblocks = [];
  33506. var precincts = [];
  33507. var i, j, codeblock, precinctNumber;
  33508. for (j = cby0; j < cby1; j++) {
  33509. for (i = cbx0; i < cbx1; i++) {
  33510. codeblock = {
  33511. cbx: i,
  33512. cby: j,
  33513. tbx0: codeblockWidth * i,
  33514. tby0: codeblockHeight * j,
  33515. tbx1: codeblockWidth * (i + 1),
  33516. tby1: codeblockHeight * (j + 1)
  33517. };
  33518. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33519. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33520. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33521. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33522. // Calculate precinct number for this codeblock, codeblock position
  33523. // should be relative to its subband, use actual dimension and position
  33524. // See comment about codeblock group width and height
  33525. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33526. precinctParameters.precinctWidthInSubband);
  33527. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33528. precinctParameters.precinctHeightInSubband);
  33529. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33530. codeblock.precinctNumber = precinctNumber;
  33531. codeblock.subbandType = subband.type;
  33532. codeblock.Lblock = 3;
  33533. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33534. codeblock.tby1_ <= codeblock.tby0_) {
  33535. continue;
  33536. }
  33537. codeblocks.push(codeblock);
  33538. // building precinct for the sub-band
  33539. var precinct = precincts[precinctNumber];
  33540. if (precinct !== undefined) {
  33541. if (i < precinct.cbxMin) {
  33542. precinct.cbxMin = i;
  33543. } else if (i > precinct.cbxMax) {
  33544. precinct.cbxMax = i;
  33545. }
  33546. if (j < precinct.cbyMin) {
  33547. precinct.cbxMin = j;
  33548. } else if (j > precinct.cbyMax) {
  33549. precinct.cbyMax = j;
  33550. }
  33551. } else {
  33552. precincts[precinctNumber] = precinct = {
  33553. cbxMin: i,
  33554. cbyMin: j,
  33555. cbxMax: i,
  33556. cbyMax: j
  33557. };
  33558. }
  33559. codeblock.precinct = precinct;
  33560. }
  33561. }
  33562. subband.codeblockParameters = {
  33563. codeblockWidth: xcb_,
  33564. codeblockHeight: ycb_,
  33565. numcodeblockwide: cbx1 - cbx0 + 1,
  33566. numcodeblockhigh: cby1 - cby0 + 1
  33567. };
  33568. subband.codeblocks = codeblocks;
  33569. subband.precincts = precincts;
  33570. }
  33571. function createPacket(resolution, precinctNumber, layerNumber) {
  33572. var precinctCodeblocks = [];
  33573. // Section B.10.8 Order of info in packet
  33574. var subbands = resolution.subbands;
  33575. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33576. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33577. var subband = subbands[i];
  33578. var codeblocks = subband.codeblocks;
  33579. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33580. var codeblock = codeblocks[j];
  33581. if (codeblock.precinctNumber !== precinctNumber) {
  33582. continue;
  33583. }
  33584. precinctCodeblocks.push(codeblock);
  33585. }
  33586. }
  33587. return {
  33588. layerNumber: layerNumber,
  33589. codeblocks: precinctCodeblocks
  33590. };
  33591. }
  33592. function LayerResolutionComponentPositionIterator(context) {
  33593. var siz = context.SIZ;
  33594. var tileIndex = context.currentTile.index;
  33595. var tile = context.tiles[tileIndex];
  33596. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33597. var componentsCount = siz.Csiz;
  33598. var maxDecompositionLevelsCount = 0;
  33599. for (var q = 0; q < componentsCount; q++) {
  33600. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33601. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33602. }
  33603. var l = 0, r = 0, i = 0, k = 0;
  33604. this.nextPacket = function JpxImage_nextPacket() {
  33605. // Section B.12.1.1 Layer-resolution-component-position
  33606. for (; l < layersCount; l++) {
  33607. for (; r <= maxDecompositionLevelsCount; r++) {
  33608. for (; i < componentsCount; i++) {
  33609. var component = tile.components[i];
  33610. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33611. continue;
  33612. }
  33613. var resolution = component.resolutions[r];
  33614. var numprecincts = resolution.precinctParameters.numprecincts;
  33615. for (; k < numprecincts;) {
  33616. var packet = createPacket(resolution, k, l);
  33617. k++;
  33618. return packet;
  33619. }
  33620. k = 0;
  33621. }
  33622. i = 0;
  33623. }
  33624. r = 0;
  33625. }
  33626. throw new Error('JPX Error: Out of packets');
  33627. };
  33628. }
  33629. function ResolutionLayerComponentPositionIterator(context) {
  33630. var siz = context.SIZ;
  33631. var tileIndex = context.currentTile.index;
  33632. var tile = context.tiles[tileIndex];
  33633. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33634. var componentsCount = siz.Csiz;
  33635. var maxDecompositionLevelsCount = 0;
  33636. for (var q = 0; q < componentsCount; q++) {
  33637. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33638. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33639. }
  33640. var r = 0, l = 0, i = 0, k = 0;
  33641. this.nextPacket = function JpxImage_nextPacket() {
  33642. // Section B.12.1.2 Resolution-layer-component-position
  33643. for (; r <= maxDecompositionLevelsCount; r++) {
  33644. for (; l < layersCount; l++) {
  33645. for (; i < componentsCount; i++) {
  33646. var component = tile.components[i];
  33647. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33648. continue;
  33649. }
  33650. var resolution = component.resolutions[r];
  33651. var numprecincts = resolution.precinctParameters.numprecincts;
  33652. for (; k < numprecincts;) {
  33653. var packet = createPacket(resolution, k, l);
  33654. k++;
  33655. return packet;
  33656. }
  33657. k = 0;
  33658. }
  33659. i = 0;
  33660. }
  33661. l = 0;
  33662. }
  33663. throw new Error('JPX Error: Out of packets');
  33664. };
  33665. }
  33666. function ResolutionPositionComponentLayerIterator(context) {
  33667. var siz = context.SIZ;
  33668. var tileIndex = context.currentTile.index;
  33669. var tile = context.tiles[tileIndex];
  33670. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33671. var componentsCount = siz.Csiz;
  33672. var l, r, c, p;
  33673. var maxDecompositionLevelsCount = 0;
  33674. for (c = 0; c < componentsCount; c++) {
  33675. var component = tile.components[c];
  33676. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33677. component.codingStyleParameters.decompositionLevelsCount);
  33678. }
  33679. var maxNumPrecinctsInLevel = new Int32Array(
  33680. maxDecompositionLevelsCount + 1);
  33681. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33682. var maxNumPrecincts = 0;
  33683. for (c = 0; c < componentsCount; ++c) {
  33684. var resolutions = tile.components[c].resolutions;
  33685. if (r < resolutions.length) {
  33686. maxNumPrecincts = Math.max(maxNumPrecincts,
  33687. resolutions[r].precinctParameters.numprecincts);
  33688. }
  33689. }
  33690. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  33691. }
  33692. l = 0;
  33693. r = 0;
  33694. c = 0;
  33695. p = 0;
  33696. this.nextPacket = function JpxImage_nextPacket() {
  33697. // Section B.12.1.3 Resolution-position-component-layer
  33698. for (; r <= maxDecompositionLevelsCount; r++) {
  33699. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  33700. for (; c < componentsCount; c++) {
  33701. var component = tile.components[c];
  33702. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33703. continue;
  33704. }
  33705. var resolution = component.resolutions[r];
  33706. var numprecincts = resolution.precinctParameters.numprecincts;
  33707. if (p >= numprecincts) {
  33708. continue;
  33709. }
  33710. for (; l < layersCount;) {
  33711. var packet = createPacket(resolution, p, l);
  33712. l++;
  33713. return packet;
  33714. }
  33715. l = 0;
  33716. }
  33717. c = 0;
  33718. }
  33719. p = 0;
  33720. }
  33721. throw new Error('JPX Error: Out of packets');
  33722. };
  33723. }
  33724. function PositionComponentResolutionLayerIterator(context) {
  33725. var siz = context.SIZ;
  33726. var tileIndex = context.currentTile.index;
  33727. var tile = context.tiles[tileIndex];
  33728. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33729. var componentsCount = siz.Csiz;
  33730. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33731. var precinctsIterationSizes = precinctsSizes;
  33732. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33733. this.nextPacket = function JpxImage_nextPacket() {
  33734. // Section B.12.1.4 Position-component-resolution-layer
  33735. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33736. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33737. for (; c < componentsCount; c++) {
  33738. var component = tile.components[c];
  33739. var decompositionLevelsCount =
  33740. component.codingStyleParameters.decompositionLevelsCount;
  33741. for (; r <= decompositionLevelsCount; r++) {
  33742. var resolution = component.resolutions[r];
  33743. var sizeInImageScale =
  33744. precinctsSizes.components[c].resolutions[r];
  33745. var k = getPrecinctIndexIfExist(
  33746. px,
  33747. py,
  33748. sizeInImageScale,
  33749. precinctsIterationSizes,
  33750. resolution);
  33751. if (k === null) {
  33752. continue;
  33753. }
  33754. for (; l < layersCount;) {
  33755. var packet = createPacket(resolution, k, l);
  33756. l++;
  33757. return packet;
  33758. }
  33759. l = 0;
  33760. }
  33761. r = 0;
  33762. }
  33763. c = 0;
  33764. }
  33765. px = 0;
  33766. }
  33767. throw new Error('JPX Error: Out of packets');
  33768. };
  33769. }
  33770. function ComponentPositionResolutionLayerIterator(context) {
  33771. var siz = context.SIZ;
  33772. var tileIndex = context.currentTile.index;
  33773. var tile = context.tiles[tileIndex];
  33774. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33775. var componentsCount = siz.Csiz;
  33776. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33777. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33778. this.nextPacket = function JpxImage_nextPacket() {
  33779. // Section B.12.1.5 Component-position-resolution-layer
  33780. for (; c < componentsCount; ++c) {
  33781. var component = tile.components[c];
  33782. var precinctsIterationSizes = precinctsSizes.components[c];
  33783. var decompositionLevelsCount =
  33784. component.codingStyleParameters.decompositionLevelsCount;
  33785. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33786. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33787. for (; r <= decompositionLevelsCount; r++) {
  33788. var resolution = component.resolutions[r];
  33789. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  33790. var k = getPrecinctIndexIfExist(
  33791. px,
  33792. py,
  33793. sizeInImageScale,
  33794. precinctsIterationSizes,
  33795. resolution);
  33796. if (k === null) {
  33797. continue;
  33798. }
  33799. for (; l < layersCount;) {
  33800. var packet = createPacket(resolution, k, l);
  33801. l++;
  33802. return packet;
  33803. }
  33804. l = 0;
  33805. }
  33806. r = 0;
  33807. }
  33808. px = 0;
  33809. }
  33810. py = 0;
  33811. }
  33812. throw new Error('JPX Error: Out of packets');
  33813. };
  33814. }
  33815. function getPrecinctIndexIfExist(
  33816. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  33817. var posX = pxIndex * precinctIterationSizes.minWidth;
  33818. var posY = pyIndex * precinctIterationSizes.minHeight;
  33819. if (posX % sizeInImageScale.width !== 0 ||
  33820. posY % sizeInImageScale.height !== 0) {
  33821. return null;
  33822. }
  33823. var startPrecinctRowIndex =
  33824. (posY / sizeInImageScale.width) *
  33825. resolution.precinctParameters.numprecinctswide;
  33826. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  33827. }
  33828. function getPrecinctSizesInImageScale(tile) {
  33829. var componentsCount = tile.components.length;
  33830. var minWidth = Number.MAX_VALUE;
  33831. var minHeight = Number.MAX_VALUE;
  33832. var maxNumWide = 0;
  33833. var maxNumHigh = 0;
  33834. var sizePerComponent = new Array(componentsCount);
  33835. for (var c = 0; c < componentsCount; c++) {
  33836. var component = tile.components[c];
  33837. var decompositionLevelsCount =
  33838. component.codingStyleParameters.decompositionLevelsCount;
  33839. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  33840. var minWidthCurrentComponent = Number.MAX_VALUE;
  33841. var minHeightCurrentComponent = Number.MAX_VALUE;
  33842. var maxNumWideCurrentComponent = 0;
  33843. var maxNumHighCurrentComponent = 0;
  33844. var scale = 1;
  33845. for (var r = decompositionLevelsCount; r >= 0; --r) {
  33846. var resolution = component.resolutions[r];
  33847. var widthCurrentResolution =
  33848. scale * resolution.precinctParameters.precinctWidth;
  33849. var heightCurrentResolution =
  33850. scale * resolution.precinctParameters.precinctHeight;
  33851. minWidthCurrentComponent = Math.min(
  33852. minWidthCurrentComponent,
  33853. widthCurrentResolution);
  33854. minHeightCurrentComponent = Math.min(
  33855. minHeightCurrentComponent,
  33856. heightCurrentResolution);
  33857. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  33858. resolution.precinctParameters.numprecinctswide);
  33859. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  33860. resolution.precinctParameters.numprecinctshigh);
  33861. sizePerResolution[r] = {
  33862. width: widthCurrentResolution,
  33863. height: heightCurrentResolution
  33864. };
  33865. scale <<= 1;
  33866. }
  33867. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  33868. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  33869. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  33870. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  33871. sizePerComponent[c] = {
  33872. resolutions: sizePerResolution,
  33873. minWidth: minWidthCurrentComponent,
  33874. minHeight: minHeightCurrentComponent,
  33875. maxNumWide: maxNumWideCurrentComponent,
  33876. maxNumHigh: maxNumHighCurrentComponent
  33877. };
  33878. }
  33879. return {
  33880. components: sizePerComponent,
  33881. minWidth: minWidth,
  33882. minHeight: minHeight,
  33883. maxNumWide: maxNumWide,
  33884. maxNumHigh: maxNumHigh
  33885. };
  33886. }
  33887. function buildPackets(context) {
  33888. var siz = context.SIZ;
  33889. var tileIndex = context.currentTile.index;
  33890. var tile = context.tiles[tileIndex];
  33891. var componentsCount = siz.Csiz;
  33892. // Creating resolutions and sub-bands for each component
  33893. for (var c = 0; c < componentsCount; c++) {
  33894. var component = tile.components[c];
  33895. var decompositionLevelsCount =
  33896. component.codingStyleParameters.decompositionLevelsCount;
  33897. // Section B.5 Resolution levels and sub-bands
  33898. var resolutions = [];
  33899. var subbands = [];
  33900. for (var r = 0; r <= decompositionLevelsCount; r++) {
  33901. var blocksDimensions = getBlocksDimensions(context, component, r);
  33902. var resolution = {};
  33903. var scale = 1 << (decompositionLevelsCount - r);
  33904. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  33905. resolution.try0 = Math.ceil(component.tcy0 / scale);
  33906. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  33907. resolution.try1 = Math.ceil(component.tcy1 / scale);
  33908. resolution.resLevel = r;
  33909. buildPrecincts(context, resolution, blocksDimensions);
  33910. resolutions.push(resolution);
  33911. var subband;
  33912. if (r === 0) {
  33913. // one sub-band (LL) with last decomposition
  33914. subband = {};
  33915. subband.type = 'LL';
  33916. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  33917. subband.tby0 = Math.ceil(component.tcy0 / scale);
  33918. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  33919. subband.tby1 = Math.ceil(component.tcy1 / scale);
  33920. subband.resolution = resolution;
  33921. buildCodeblocks(context, subband, blocksDimensions);
  33922. subbands.push(subband);
  33923. resolution.subbands = [subband];
  33924. } else {
  33925. var bscale = 1 << (decompositionLevelsCount - r + 1);
  33926. var resolutionSubbands = [];
  33927. // three sub-bands (HL, LH and HH) with rest of decompositions
  33928. subband = {};
  33929. subband.type = 'HL';
  33930. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33931. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  33932. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33933. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  33934. subband.resolution = resolution;
  33935. buildCodeblocks(context, subband, blocksDimensions);
  33936. subbands.push(subband);
  33937. resolutionSubbands.push(subband);
  33938. subband = {};
  33939. subband.type = 'LH';
  33940. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  33941. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33942. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  33943. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33944. subband.resolution = resolution;
  33945. buildCodeblocks(context, subband, blocksDimensions);
  33946. subbands.push(subband);
  33947. resolutionSubbands.push(subband);
  33948. subband = {};
  33949. subband.type = 'HH';
  33950. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33951. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33952. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33953. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33954. subband.resolution = resolution;
  33955. buildCodeblocks(context, subband, blocksDimensions);
  33956. subbands.push(subband);
  33957. resolutionSubbands.push(subband);
  33958. resolution.subbands = resolutionSubbands;
  33959. }
  33960. }
  33961. component.resolutions = resolutions;
  33962. component.subbands = subbands;
  33963. }
  33964. // Generate the packets sequence
  33965. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  33966. switch (progressionOrder) {
  33967. case 0:
  33968. tile.packetsIterator =
  33969. new LayerResolutionComponentPositionIterator(context);
  33970. break;
  33971. case 1:
  33972. tile.packetsIterator =
  33973. new ResolutionLayerComponentPositionIterator(context);
  33974. break;
  33975. case 2:
  33976. tile.packetsIterator =
  33977. new ResolutionPositionComponentLayerIterator(context);
  33978. break;
  33979. case 3:
  33980. tile.packetsIterator =
  33981. new PositionComponentResolutionLayerIterator(context);
  33982. break;
  33983. case 4:
  33984. tile.packetsIterator =
  33985. new ComponentPositionResolutionLayerIterator(context);
  33986. break;
  33987. default:
  33988. throw new Error('JPX Error: Unsupported progression order ' +
  33989. progressionOrder);
  33990. }
  33991. }
  33992. function parseTilePackets(context, data, offset, dataLength) {
  33993. var position = 0;
  33994. var buffer, bufferSize = 0, skipNextBit = false;
  33995. function readBits(count) {
  33996. while (bufferSize < count) {
  33997. var b = data[offset + position];
  33998. position++;
  33999. if (skipNextBit) {
  34000. buffer = (buffer << 7) | b;
  34001. bufferSize += 7;
  34002. skipNextBit = false;
  34003. } else {
  34004. buffer = (buffer << 8) | b;
  34005. bufferSize += 8;
  34006. }
  34007. if (b === 0xFF) {
  34008. skipNextBit = true;
  34009. }
  34010. }
  34011. bufferSize -= count;
  34012. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34013. }
  34014. function skipMarkerIfEqual(value) {
  34015. if (data[offset + position - 1] === 0xFF &&
  34016. data[offset + position] === value) {
  34017. skipBytes(1);
  34018. return true;
  34019. } else if (data[offset + position] === 0xFF &&
  34020. data[offset + position + 1] === value) {
  34021. skipBytes(2);
  34022. return true;
  34023. }
  34024. return false;
  34025. }
  34026. function skipBytes(count) {
  34027. position += count;
  34028. }
  34029. function alignToByte() {
  34030. bufferSize = 0;
  34031. if (skipNextBit) {
  34032. position++;
  34033. skipNextBit = false;
  34034. }
  34035. }
  34036. function readCodingpasses() {
  34037. if (readBits(1) === 0) {
  34038. return 1;
  34039. }
  34040. if (readBits(1) === 0) {
  34041. return 2;
  34042. }
  34043. var value = readBits(2);
  34044. if (value < 3) {
  34045. return value + 3;
  34046. }
  34047. value = readBits(5);
  34048. if (value < 31) {
  34049. return value + 6;
  34050. }
  34051. value = readBits(7);
  34052. return value + 37;
  34053. }
  34054. var tileIndex = context.currentTile.index;
  34055. var tile = context.tiles[tileIndex];
  34056. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34057. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34058. var packetsIterator = tile.packetsIterator;
  34059. while (position < dataLength) {
  34060. alignToByte();
  34061. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34062. // Skip also marker segment length and packet sequence ID
  34063. skipBytes(4);
  34064. }
  34065. var packet = packetsIterator.nextPacket();
  34066. if (!readBits(1)) {
  34067. continue;
  34068. }
  34069. var layerNumber = packet.layerNumber;
  34070. var queue = [], codeblock;
  34071. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34072. codeblock = packet.codeblocks[i];
  34073. var precinct = codeblock.precinct;
  34074. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34075. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34076. var codeblockIncluded = false;
  34077. var firstTimeInclusion = false;
  34078. var valueReady;
  34079. if (codeblock['included'] !== undefined) {
  34080. codeblockIncluded = !!readBits(1);
  34081. } else {
  34082. // reading inclusion tree
  34083. precinct = codeblock.precinct;
  34084. var inclusionTree, zeroBitPlanesTree;
  34085. if (precinct['inclusionTree'] !== undefined) {
  34086. inclusionTree = precinct.inclusionTree;
  34087. } else {
  34088. // building inclusion and zero bit-planes trees
  34089. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34090. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34091. inclusionTree = new InclusionTree(width, height, layerNumber);
  34092. zeroBitPlanesTree = new TagTree(width, height);
  34093. precinct.inclusionTree = inclusionTree;
  34094. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34095. }
  34096. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34097. while (true) {
  34098. if (readBits(1)) {
  34099. valueReady = !inclusionTree.nextLevel();
  34100. if (valueReady) {
  34101. codeblock.included = true;
  34102. codeblockIncluded = firstTimeInclusion = true;
  34103. break;
  34104. }
  34105. } else {
  34106. inclusionTree.incrementValue(layerNumber);
  34107. break;
  34108. }
  34109. }
  34110. }
  34111. }
  34112. if (!codeblockIncluded) {
  34113. continue;
  34114. }
  34115. if (firstTimeInclusion) {
  34116. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34117. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34118. while (true) {
  34119. if (readBits(1)) {
  34120. valueReady = !zeroBitPlanesTree.nextLevel();
  34121. if (valueReady) {
  34122. break;
  34123. }
  34124. } else {
  34125. zeroBitPlanesTree.incrementValue();
  34126. }
  34127. }
  34128. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34129. }
  34130. var codingpasses = readCodingpasses();
  34131. while (readBits(1)) {
  34132. codeblock.Lblock++;
  34133. }
  34134. var codingpassesLog2 = log2(codingpasses);
  34135. // rounding down log2
  34136. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34137. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34138. var codedDataLength = readBits(bits);
  34139. queue.push({
  34140. codeblock: codeblock,
  34141. codingpasses: codingpasses,
  34142. dataLength: codedDataLength
  34143. });
  34144. }
  34145. alignToByte();
  34146. if (ephMarkerUsed) {
  34147. skipMarkerIfEqual(0x92);
  34148. }
  34149. while (queue.length > 0) {
  34150. var packetItem = queue.shift();
  34151. codeblock = packetItem.codeblock;
  34152. if (codeblock['data'] === undefined) {
  34153. codeblock.data = [];
  34154. }
  34155. codeblock.data.push({
  34156. data: data,
  34157. start: offset + position,
  34158. end: offset + position + packetItem.dataLength,
  34159. codingpasses: packetItem.codingpasses
  34160. });
  34161. position += packetItem.dataLength;
  34162. }
  34163. }
  34164. return position;
  34165. }
  34166. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34167. delta, mb, reversible, segmentationSymbolUsed) {
  34168. var x0 = subband.tbx0;
  34169. var y0 = subband.tby0;
  34170. var width = subband.tbx1 - subband.tbx0;
  34171. var codeblocks = subband.codeblocks;
  34172. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34173. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34174. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34175. var codeblock = codeblocks[i];
  34176. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34177. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34178. if (blockWidth === 0 || blockHeight === 0) {
  34179. continue;
  34180. }
  34181. if (codeblock['data'] === undefined) {
  34182. continue;
  34183. }
  34184. var bitModel, currentCodingpassType;
  34185. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34186. codeblock.zeroBitPlanes, mb);
  34187. currentCodingpassType = 2; // first bit plane starts from cleanup
  34188. // collect data
  34189. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34190. var j, jj, dataItem;
  34191. for (j = 0, jj = data.length; j < jj; j++) {
  34192. dataItem = data[j];
  34193. totalLength += dataItem.end - dataItem.start;
  34194. codingpasses += dataItem.codingpasses;
  34195. }
  34196. var encodedData = new Uint8Array(totalLength);
  34197. var position = 0;
  34198. for (j = 0, jj = data.length; j < jj; j++) {
  34199. dataItem = data[j];
  34200. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34201. encodedData.set(chunk, position);
  34202. position += chunk.length;
  34203. }
  34204. // decoding the item
  34205. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34206. bitModel.setDecoder(decoder);
  34207. for (j = 0; j < codingpasses; j++) {
  34208. switch (currentCodingpassType) {
  34209. case 0:
  34210. bitModel.runSignificancePropogationPass();
  34211. break;
  34212. case 1:
  34213. bitModel.runMagnitudeRefinementPass();
  34214. break;
  34215. case 2:
  34216. bitModel.runCleanupPass();
  34217. if (segmentationSymbolUsed) {
  34218. bitModel.checkSegmentationSymbol();
  34219. }
  34220. break;
  34221. }
  34222. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34223. }
  34224. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34225. var sign = bitModel.coefficentsSign;
  34226. var magnitude = bitModel.coefficentsMagnitude;
  34227. var bitsDecoded = bitModel.bitsDecoded;
  34228. var magnitudeCorrection = reversible ? 0 : 0.5;
  34229. var k, n, nb;
  34230. position = 0;
  34231. // Do the interleaving of Section F.3.3 here, so we do not need
  34232. // to copy later. LL level is not interleaved, just copied.
  34233. var interleave = (subband.type !== 'LL');
  34234. for (j = 0; j < blockHeight; j++) {
  34235. var row = (offset / width) | 0; // row in the non-interleaved subband
  34236. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34237. for (k = 0; k < blockWidth; k++) {
  34238. n = magnitude[position];
  34239. if (n !== 0) {
  34240. n = (n + magnitudeCorrection) * delta;
  34241. if (sign[position] !== 0) {
  34242. n = -n;
  34243. }
  34244. nb = bitsDecoded[position];
  34245. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34246. if (reversible && (nb >= mb)) {
  34247. coefficients[pos] = n;
  34248. } else {
  34249. coefficients[pos] = n * (1 << (mb - nb));
  34250. }
  34251. }
  34252. offset++;
  34253. position++;
  34254. }
  34255. offset += width - blockWidth;
  34256. }
  34257. }
  34258. }
  34259. function transformTile(context, tile, c) {
  34260. var component = tile.components[c];
  34261. var codingStyleParameters = component.codingStyleParameters;
  34262. var quantizationParameters = component.quantizationParameters;
  34263. var decompositionLevelsCount =
  34264. codingStyleParameters.decompositionLevelsCount;
  34265. var spqcds = quantizationParameters.SPqcds;
  34266. var scalarExpounded = quantizationParameters.scalarExpounded;
  34267. var guardBits = quantizationParameters.guardBits;
  34268. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34269. var precision = context.components[c].precision;
  34270. var reversible = codingStyleParameters.reversibleTransformation;
  34271. var transform = (reversible ? new ReversibleTransform() :
  34272. new IrreversibleTransform());
  34273. var subbandCoefficients = [];
  34274. var b = 0;
  34275. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34276. var resolution = component.resolutions[i];
  34277. var width = resolution.trx1 - resolution.trx0;
  34278. var height = resolution.try1 - resolution.try0;
  34279. // Allocate space for the whole sublevel.
  34280. var coefficients = new Float32Array(width * height);
  34281. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34282. var mu, epsilon;
  34283. if (!scalarExpounded) {
  34284. // formula E-5
  34285. mu = spqcds[0].mu;
  34286. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34287. } else {
  34288. mu = spqcds[b].mu;
  34289. epsilon = spqcds[b].epsilon;
  34290. b++;
  34291. }
  34292. var subband = resolution.subbands[j];
  34293. var gainLog2 = SubbandsGainLog2[subband.type];
  34294. // calulate quantization coefficient (Section E.1.1.1)
  34295. var delta = (reversible ? 1 :
  34296. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34297. var mb = (guardBits + epsilon - 1);
  34298. // In the first resolution level, copyCoefficients will fill the
  34299. // whole array with coefficients. In the succeding passes,
  34300. // copyCoefficients will consecutively fill in the values that belong
  34301. // to the interleaved positions of the HL, LH, and HH coefficients.
  34302. // The LL coefficients will then be interleaved in Transform.iterate().
  34303. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34304. reversible, segmentationSymbolUsed);
  34305. }
  34306. subbandCoefficients.push({
  34307. width: width,
  34308. height: height,
  34309. items: coefficients
  34310. });
  34311. }
  34312. var result = transform.calculate(subbandCoefficients,
  34313. component.tcx0, component.tcy0);
  34314. return {
  34315. left: component.tcx0,
  34316. top: component.tcy0,
  34317. width: result.width,
  34318. height: result.height,
  34319. items: result.items
  34320. };
  34321. }
  34322. function transformComponents(context) {
  34323. var siz = context.SIZ;
  34324. var components = context.components;
  34325. var componentsCount = siz.Csiz;
  34326. var resultImages = [];
  34327. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34328. var tile = context.tiles[i];
  34329. var transformedTiles = [];
  34330. var c;
  34331. for (c = 0; c < componentsCount; c++) {
  34332. transformedTiles[c] = transformTile(context, tile, c);
  34333. }
  34334. var tile0 = transformedTiles[0];
  34335. var out = new Uint8Array(tile0.items.length * componentsCount);
  34336. var result = {
  34337. left: tile0.left,
  34338. top: tile0.top,
  34339. width: tile0.width,
  34340. height: tile0.height,
  34341. items: out
  34342. };
  34343. // Section G.2.2 Inverse multi component transform
  34344. var shift, offset, max, min, maxK;
  34345. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34346. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34347. var fourComponents = componentsCount === 4;
  34348. var y0items = transformedTiles[0].items;
  34349. var y1items = transformedTiles[1].items;
  34350. var y2items = transformedTiles[2].items;
  34351. var y3items = fourComponents ? transformedTiles[3].items : null;
  34352. // HACK: The multiple component transform formulas below assume that
  34353. // all components have the same precision. With this in mind, we
  34354. // compute shift and offset only once.
  34355. shift = components[0].precision - 8;
  34356. offset = (128 << shift) + 0.5;
  34357. max = 255 * (1 << shift);
  34358. maxK = max * 0.5;
  34359. min = -maxK;
  34360. var component0 = tile.components[0];
  34361. var alpha01 = componentsCount - 3;
  34362. jj = y0items.length;
  34363. if (!component0.codingStyleParameters.reversibleTransformation) {
  34364. // inverse irreversible multiple component transform
  34365. for (j = 0; j < jj; j++, pos += alpha01) {
  34366. y0 = y0items[j] + offset;
  34367. y1 = y1items[j];
  34368. y2 = y2items[j];
  34369. r = y0 + 1.402 * y2;
  34370. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34371. b = y0 + 1.772 * y1;
  34372. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34373. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34374. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34375. }
  34376. } else {
  34377. // inverse reversible multiple component transform
  34378. for (j = 0; j < jj; j++, pos += alpha01) {
  34379. y0 = y0items[j] + offset;
  34380. y1 = y1items[j];
  34381. y2 = y2items[j];
  34382. g = y0 - ((y2 + y1) >> 2);
  34383. r = g + y2;
  34384. b = g + y1;
  34385. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34386. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34387. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34388. }
  34389. }
  34390. if (fourComponents) {
  34391. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34392. k = y3items[j];
  34393. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34394. }
  34395. }
  34396. } else { // no multi-component transform
  34397. for (c = 0; c < componentsCount; c++) {
  34398. var items = transformedTiles[c].items;
  34399. shift = components[c].precision - 8;
  34400. offset = (128 << shift) + 0.5;
  34401. max = (127.5 * (1 << shift));
  34402. min = -max;
  34403. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34404. val = items[j];
  34405. out[pos] = val <= min ? 0 :
  34406. val >= max ? 255 : (val + offset) >> shift;
  34407. pos += componentsCount;
  34408. }
  34409. }
  34410. }
  34411. resultImages.push(result);
  34412. }
  34413. return resultImages;
  34414. }
  34415. function initializeTile(context, tileIndex) {
  34416. var siz = context.SIZ;
  34417. var componentsCount = siz.Csiz;
  34418. var tile = context.tiles[tileIndex];
  34419. for (var c = 0; c < componentsCount; c++) {
  34420. var component = tile.components[c];
  34421. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34422. context.currentTile.QCC[c] : context.currentTile.QCD);
  34423. component.quantizationParameters = qcdOrQcc;
  34424. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34425. context.currentTile.COC[c] : context.currentTile.COD);
  34426. component.codingStyleParameters = codOrCoc;
  34427. }
  34428. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34429. }
  34430. // Section B.10.2 Tag trees
  34431. var TagTree = (function TagTreeClosure() {
  34432. function TagTree(width, height) {
  34433. var levelsLength = log2(Math.max(width, height)) + 1;
  34434. this.levels = [];
  34435. for (var i = 0; i < levelsLength; i++) {
  34436. var level = {
  34437. width: width,
  34438. height: height,
  34439. items: []
  34440. };
  34441. this.levels.push(level);
  34442. width = Math.ceil(width / 2);
  34443. height = Math.ceil(height / 2);
  34444. }
  34445. }
  34446. TagTree.prototype = {
  34447. reset: function TagTree_reset(i, j) {
  34448. var currentLevel = 0, value = 0, level;
  34449. while (currentLevel < this.levels.length) {
  34450. level = this.levels[currentLevel];
  34451. var index = i + j * level.width;
  34452. if (level.items[index] !== undefined) {
  34453. value = level.items[index];
  34454. break;
  34455. }
  34456. level.index = index;
  34457. i >>= 1;
  34458. j >>= 1;
  34459. currentLevel++;
  34460. }
  34461. currentLevel--;
  34462. level = this.levels[currentLevel];
  34463. level.items[level.index] = value;
  34464. this.currentLevel = currentLevel;
  34465. delete this.value;
  34466. },
  34467. incrementValue: function TagTree_incrementValue() {
  34468. var level = this.levels[this.currentLevel];
  34469. level.items[level.index]++;
  34470. },
  34471. nextLevel: function TagTree_nextLevel() {
  34472. var currentLevel = this.currentLevel;
  34473. var level = this.levels[currentLevel];
  34474. var value = level.items[level.index];
  34475. currentLevel--;
  34476. if (currentLevel < 0) {
  34477. this.value = value;
  34478. return false;
  34479. }
  34480. this.currentLevel = currentLevel;
  34481. level = this.levels[currentLevel];
  34482. level.items[level.index] = value;
  34483. return true;
  34484. }
  34485. };
  34486. return TagTree;
  34487. })();
  34488. var InclusionTree = (function InclusionTreeClosure() {
  34489. function InclusionTree(width, height, defaultValue) {
  34490. var levelsLength = log2(Math.max(width, height)) + 1;
  34491. this.levels = [];
  34492. for (var i = 0; i < levelsLength; i++) {
  34493. var items = new Uint8Array(width * height);
  34494. for (var j = 0, jj = items.length; j < jj; j++) {
  34495. items[j] = defaultValue;
  34496. }
  34497. var level = {
  34498. width: width,
  34499. height: height,
  34500. items: items
  34501. };
  34502. this.levels.push(level);
  34503. width = Math.ceil(width / 2);
  34504. height = Math.ceil(height / 2);
  34505. }
  34506. }
  34507. InclusionTree.prototype = {
  34508. reset: function InclusionTree_reset(i, j, stopValue) {
  34509. var currentLevel = 0;
  34510. while (currentLevel < this.levels.length) {
  34511. var level = this.levels[currentLevel];
  34512. var index = i + j * level.width;
  34513. level.index = index;
  34514. var value = level.items[index];
  34515. if (value === 0xFF) {
  34516. break;
  34517. }
  34518. if (value > stopValue) {
  34519. this.currentLevel = currentLevel;
  34520. // already know about this one, propagating the value to top levels
  34521. this.propagateValues();
  34522. return false;
  34523. }
  34524. i >>= 1;
  34525. j >>= 1;
  34526. currentLevel++;
  34527. }
  34528. this.currentLevel = currentLevel - 1;
  34529. return true;
  34530. },
  34531. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34532. var level = this.levels[this.currentLevel];
  34533. level.items[level.index] = stopValue + 1;
  34534. this.propagateValues();
  34535. },
  34536. propagateValues: function InclusionTree_propagateValues() {
  34537. var levelIndex = this.currentLevel;
  34538. var level = this.levels[levelIndex];
  34539. var currentValue = level.items[level.index];
  34540. while (--levelIndex >= 0) {
  34541. level = this.levels[levelIndex];
  34542. level.items[level.index] = currentValue;
  34543. }
  34544. },
  34545. nextLevel: function InclusionTree_nextLevel() {
  34546. var currentLevel = this.currentLevel;
  34547. var level = this.levels[currentLevel];
  34548. var value = level.items[level.index];
  34549. level.items[level.index] = 0xFF;
  34550. currentLevel--;
  34551. if (currentLevel < 0) {
  34552. return false;
  34553. }
  34554. this.currentLevel = currentLevel;
  34555. level = this.levels[currentLevel];
  34556. level.items[level.index] = value;
  34557. return true;
  34558. }
  34559. };
  34560. return InclusionTree;
  34561. })();
  34562. // Section D. Coefficient bit modeling
  34563. var BitModel = (function BitModelClosure() {
  34564. var UNIFORM_CONTEXT = 17;
  34565. var RUNLENGTH_CONTEXT = 18;
  34566. // Table D-1
  34567. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34568. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34569. var LLAndLHContextsLabel = new Uint8Array([
  34570. 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,
  34571. 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,
  34572. 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
  34573. ]);
  34574. var HLContextLabel = new Uint8Array([
  34575. 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,
  34576. 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,
  34577. 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
  34578. ]);
  34579. var HHContextLabel = new Uint8Array([
  34580. 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,
  34581. 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,
  34582. 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
  34583. ]);
  34584. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34585. this.width = width;
  34586. this.height = height;
  34587. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34588. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34589. var coefficientCount = width * height;
  34590. // coefficients outside the encoding region treated as insignificant
  34591. // add border state cells for significanceState
  34592. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34593. this.coefficentsSign = new Uint8Array(coefficientCount);
  34594. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34595. mb > 6 ? new Uint16Array(coefficientCount) :
  34596. new Uint8Array(coefficientCount);
  34597. this.processingFlags = new Uint8Array(coefficientCount);
  34598. var bitsDecoded = new Uint8Array(coefficientCount);
  34599. if (zeroBitPlanes !== 0) {
  34600. for (var i = 0; i < coefficientCount; i++) {
  34601. bitsDecoded[i] = zeroBitPlanes;
  34602. }
  34603. }
  34604. this.bitsDecoded = bitsDecoded;
  34605. this.reset();
  34606. }
  34607. BitModel.prototype = {
  34608. setDecoder: function BitModel_setDecoder(decoder) {
  34609. this.decoder = decoder;
  34610. },
  34611. reset: function BitModel_reset() {
  34612. // We have 17 contexts that are accessed via context labels,
  34613. // plus the uniform and runlength context.
  34614. this.contexts = new Int8Array(19);
  34615. // Contexts are packed into 1 byte:
  34616. // highest 7 bits carry the index, lowest bit carries mps
  34617. this.contexts[0] = (4 << 1) | 0;
  34618. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34619. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34620. },
  34621. setNeighborsSignificance:
  34622. function BitModel_setNeighborsSignificance(row, column, index) {
  34623. var neighborsSignificance = this.neighborsSignificance;
  34624. var width = this.width, height = this.height;
  34625. var left = (column > 0);
  34626. var right = (column + 1 < width);
  34627. var i;
  34628. if (row > 0) {
  34629. i = index - width;
  34630. if (left) {
  34631. neighborsSignificance[i - 1] += 0x10;
  34632. }
  34633. if (right) {
  34634. neighborsSignificance[i + 1] += 0x10;
  34635. }
  34636. neighborsSignificance[i] += 0x04;
  34637. }
  34638. if (row + 1 < height) {
  34639. i = index + width;
  34640. if (left) {
  34641. neighborsSignificance[i - 1] += 0x10;
  34642. }
  34643. if (right) {
  34644. neighborsSignificance[i + 1] += 0x10;
  34645. }
  34646. neighborsSignificance[i] += 0x04;
  34647. }
  34648. if (left) {
  34649. neighborsSignificance[index - 1] += 0x01;
  34650. }
  34651. if (right) {
  34652. neighborsSignificance[index + 1] += 0x01;
  34653. }
  34654. neighborsSignificance[index] |= 0x80;
  34655. },
  34656. runSignificancePropogationPass:
  34657. function BitModel_runSignificancePropogationPass() {
  34658. var decoder = this.decoder;
  34659. var width = this.width, height = this.height;
  34660. var coefficentsMagnitude = this.coefficentsMagnitude;
  34661. var coefficentsSign = this.coefficentsSign;
  34662. var neighborsSignificance = this.neighborsSignificance;
  34663. var processingFlags = this.processingFlags;
  34664. var contexts = this.contexts;
  34665. var labels = this.contextLabelTable;
  34666. var bitsDecoded = this.bitsDecoded;
  34667. var processedInverseMask = ~1;
  34668. var processedMask = 1;
  34669. var firstMagnitudeBitMask = 2;
  34670. for (var i0 = 0; i0 < height; i0 += 4) {
  34671. for (var j = 0; j < width; j++) {
  34672. var index = i0 * width + j;
  34673. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34674. var i = i0 + i1;
  34675. if (i >= height) {
  34676. break;
  34677. }
  34678. // clear processed flag first
  34679. processingFlags[index] &= processedInverseMask;
  34680. if (coefficentsMagnitude[index] ||
  34681. !neighborsSignificance[index]) {
  34682. continue;
  34683. }
  34684. var contextLabel = labels[neighborsSignificance[index]];
  34685. var decision = decoder.readBit(contexts, contextLabel);
  34686. if (decision) {
  34687. var sign = this.decodeSignBit(i, j, index);
  34688. coefficentsSign[index] = sign;
  34689. coefficentsMagnitude[index] = 1;
  34690. this.setNeighborsSignificance(i, j, index);
  34691. processingFlags[index] |= firstMagnitudeBitMask;
  34692. }
  34693. bitsDecoded[index]++;
  34694. processingFlags[index] |= processedMask;
  34695. }
  34696. }
  34697. }
  34698. },
  34699. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34700. var width = this.width, height = this.height;
  34701. var coefficentsMagnitude = this.coefficentsMagnitude;
  34702. var coefficentsSign = this.coefficentsSign;
  34703. var contribution, sign0, sign1, significance1;
  34704. var contextLabel, decoded;
  34705. // calculate horizontal contribution
  34706. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34707. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34708. sign1 = coefficentsSign[index + 1];
  34709. if (significance1) {
  34710. sign0 = coefficentsSign[index - 1];
  34711. contribution = 1 - sign1 - sign0;
  34712. } else {
  34713. contribution = 1 - sign1 - sign1;
  34714. }
  34715. } else if (significance1) {
  34716. sign0 = coefficentsSign[index - 1];
  34717. contribution = 1 - sign0 - sign0;
  34718. } else {
  34719. contribution = 0;
  34720. }
  34721. var horizontalContribution = 3 * contribution;
  34722. // calculate vertical contribution and combine with the horizontal
  34723. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34724. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34725. sign1 = coefficentsSign[index + width];
  34726. if (significance1) {
  34727. sign0 = coefficentsSign[index - width];
  34728. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34729. } else {
  34730. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34731. }
  34732. } else if (significance1) {
  34733. sign0 = coefficentsSign[index - width];
  34734. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34735. } else {
  34736. contribution = horizontalContribution;
  34737. }
  34738. if (contribution >= 0) {
  34739. contextLabel = 9 + contribution;
  34740. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34741. } else {
  34742. contextLabel = 9 - contribution;
  34743. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34744. }
  34745. return decoded;
  34746. },
  34747. runMagnitudeRefinementPass:
  34748. function BitModel_runMagnitudeRefinementPass() {
  34749. var decoder = this.decoder;
  34750. var width = this.width, height = this.height;
  34751. var coefficentsMagnitude = this.coefficentsMagnitude;
  34752. var neighborsSignificance = this.neighborsSignificance;
  34753. var contexts = this.contexts;
  34754. var bitsDecoded = this.bitsDecoded;
  34755. var processingFlags = this.processingFlags;
  34756. var processedMask = 1;
  34757. var firstMagnitudeBitMask = 2;
  34758. var length = width * height;
  34759. var width4 = width * 4;
  34760. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34761. indexNext = Math.min(length, index0 + width4);
  34762. for (var j = 0; j < width; j++) {
  34763. for (var index = index0 + j; index < indexNext; index += width) {
  34764. // significant but not those that have just become
  34765. if (!coefficentsMagnitude[index] ||
  34766. (processingFlags[index] & processedMask) !== 0) {
  34767. continue;
  34768. }
  34769. var contextLabel = 16;
  34770. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34771. processingFlags[index] ^= firstMagnitudeBitMask;
  34772. // first refinement
  34773. var significance = neighborsSignificance[index] & 127;
  34774. contextLabel = significance === 0 ? 15 : 14;
  34775. }
  34776. var bit = decoder.readBit(contexts, contextLabel);
  34777. coefficentsMagnitude[index] =
  34778. (coefficentsMagnitude[index] << 1) | bit;
  34779. bitsDecoded[index]++;
  34780. processingFlags[index] |= processedMask;
  34781. }
  34782. }
  34783. }
  34784. },
  34785. runCleanupPass: function BitModel_runCleanupPass() {
  34786. var decoder = this.decoder;
  34787. var width = this.width, height = this.height;
  34788. var neighborsSignificance = this.neighborsSignificance;
  34789. var coefficentsMagnitude = this.coefficentsMagnitude;
  34790. var coefficentsSign = this.coefficentsSign;
  34791. var contexts = this.contexts;
  34792. var labels = this.contextLabelTable;
  34793. var bitsDecoded = this.bitsDecoded;
  34794. var processingFlags = this.processingFlags;
  34795. var processedMask = 1;
  34796. var firstMagnitudeBitMask = 2;
  34797. var oneRowDown = width;
  34798. var twoRowsDown = width * 2;
  34799. var threeRowsDown = width * 3;
  34800. var iNext;
  34801. for (var i0 = 0; i0 < height; i0 = iNext) {
  34802. iNext = Math.min(i0 + 4, height);
  34803. var indexBase = i0 * width;
  34804. var checkAllEmpty = i0 + 3 < height;
  34805. for (var j = 0; j < width; j++) {
  34806. var index0 = indexBase + j;
  34807. // using the property: labels[neighborsSignificance[index]] === 0
  34808. // when neighborsSignificance[index] === 0
  34809. var allEmpty = (checkAllEmpty &&
  34810. processingFlags[index0] === 0 &&
  34811. processingFlags[index0 + oneRowDown] === 0 &&
  34812. processingFlags[index0 + twoRowsDown] === 0 &&
  34813. processingFlags[index0 + threeRowsDown] === 0 &&
  34814. neighborsSignificance[index0] === 0 &&
  34815. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34816. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34817. neighborsSignificance[index0 + threeRowsDown] === 0);
  34818. var i1 = 0, index = index0;
  34819. var i = i0, sign;
  34820. if (allEmpty) {
  34821. var hasSignificantCoefficent =
  34822. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34823. if (!hasSignificantCoefficent) {
  34824. bitsDecoded[index0]++;
  34825. bitsDecoded[index0 + oneRowDown]++;
  34826. bitsDecoded[index0 + twoRowsDown]++;
  34827. bitsDecoded[index0 + threeRowsDown]++;
  34828. continue; // next column
  34829. }
  34830. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34831. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34832. if (i1 !== 0) {
  34833. i = i0 + i1;
  34834. index += i1 * width;
  34835. }
  34836. sign = this.decodeSignBit(i, j, index);
  34837. coefficentsSign[index] = sign;
  34838. coefficentsMagnitude[index] = 1;
  34839. this.setNeighborsSignificance(i, j, index);
  34840. processingFlags[index] |= firstMagnitudeBitMask;
  34841. index = index0;
  34842. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34843. bitsDecoded[index]++;
  34844. }
  34845. i1++;
  34846. }
  34847. for (i = i0 + i1; i < iNext; i++, index += width) {
  34848. if (coefficentsMagnitude[index] ||
  34849. (processingFlags[index] & processedMask) !== 0) {
  34850. continue;
  34851. }
  34852. var contextLabel = labels[neighborsSignificance[index]];
  34853. var decision = decoder.readBit(contexts, contextLabel);
  34854. if (decision === 1) {
  34855. sign = this.decodeSignBit(i, j, index);
  34856. coefficentsSign[index] = sign;
  34857. coefficentsMagnitude[index] = 1;
  34858. this.setNeighborsSignificance(i, j, index);
  34859. processingFlags[index] |= firstMagnitudeBitMask;
  34860. }
  34861. bitsDecoded[index]++;
  34862. }
  34863. }
  34864. }
  34865. },
  34866. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  34867. var decoder = this.decoder;
  34868. var contexts = this.contexts;
  34869. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  34870. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  34871. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34872. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34873. if (symbol !== 0xA) {
  34874. throw new Error('JPX Error: Invalid segmentation symbol');
  34875. }
  34876. }
  34877. };
  34878. return BitModel;
  34879. })();
  34880. // Section F, Discrete wavelet transformation
  34881. var Transform = (function TransformClosure() {
  34882. function Transform() {}
  34883. Transform.prototype.calculate =
  34884. function transformCalculate(subbands, u0, v0) {
  34885. var ll = subbands[0];
  34886. for (var i = 1, ii = subbands.length; i < ii; i++) {
  34887. ll = this.iterate(ll, subbands[i], u0, v0);
  34888. }
  34889. return ll;
  34890. };
  34891. Transform.prototype.extend = function extend(buffer, offset, size) {
  34892. // Section F.3.7 extending... using max extension of 4
  34893. var i1 = offset - 1, j1 = offset + 1;
  34894. var i2 = offset + size - 2, j2 = offset + size;
  34895. buffer[i1--] = buffer[j1++];
  34896. buffer[j2++] = buffer[i2--];
  34897. buffer[i1--] = buffer[j1++];
  34898. buffer[j2++] = buffer[i2--];
  34899. buffer[i1--] = buffer[j1++];
  34900. buffer[j2++] = buffer[i2--];
  34901. buffer[i1] = buffer[j1];
  34902. buffer[j2] = buffer[i2];
  34903. };
  34904. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  34905. u0, v0) {
  34906. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  34907. var width = hl_lh_hh.width;
  34908. var height = hl_lh_hh.height;
  34909. var items = hl_lh_hh.items;
  34910. var i, j, k, l, u, v;
  34911. // Interleave LL according to Section F.3.3
  34912. for (k = 0, i = 0; i < llHeight; i++) {
  34913. l = i * 2 * width;
  34914. for (j = 0; j < llWidth; j++, k++, l += 2) {
  34915. items[l] = llItems[k];
  34916. }
  34917. }
  34918. // The LL band is not needed anymore.
  34919. llItems = ll.items = null;
  34920. var bufferPadding = 4;
  34921. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  34922. // Section F.3.4 HOR_SR
  34923. if (width === 1) {
  34924. // if width = 1, when u0 even keep items as is, when odd divide by 2
  34925. if ((u0 & 1) !== 0) {
  34926. for (v = 0, k = 0; v < height; v++, k += width) {
  34927. items[k] *= 0.5;
  34928. }
  34929. }
  34930. } else {
  34931. for (v = 0, k = 0; v < height; v++, k += width) {
  34932. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  34933. this.extend(rowBuffer, bufferPadding, width);
  34934. this.filter(rowBuffer, bufferPadding, width);
  34935. items.set(
  34936. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  34937. k);
  34938. }
  34939. }
  34940. // Accesses to the items array can take long, because it may not fit into
  34941. // CPU cache and has to be fetched from main memory. Since subsequent
  34942. // accesses to the items array are not local when reading columns, we
  34943. // have a cache miss every time. To reduce cache misses, get up to
  34944. // 'numBuffers' items at a time and store them into the individual
  34945. // buffers. The colBuffers should be small enough to fit into CPU cache.
  34946. var numBuffers = 16;
  34947. var colBuffers = [];
  34948. for (i = 0; i < numBuffers; i++) {
  34949. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  34950. }
  34951. var b, currentBuffer = 0;
  34952. ll = bufferPadding + height;
  34953. // Section F.3.5 VER_SR
  34954. if (height === 1) {
  34955. // if height = 1, when v0 even keep items as is, when odd divide by 2
  34956. if ((v0 & 1) !== 0) {
  34957. for (u = 0; u < width; u++) {
  34958. items[u] *= 0.5;
  34959. }
  34960. }
  34961. } else {
  34962. for (u = 0; u < width; u++) {
  34963. // if we ran out of buffers, copy several image columns at once
  34964. if (currentBuffer === 0) {
  34965. numBuffers = Math.min(width - u, numBuffers);
  34966. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  34967. for (b = 0; b < numBuffers; b++) {
  34968. colBuffers[b][l] = items[k + b];
  34969. }
  34970. }
  34971. currentBuffer = numBuffers;
  34972. }
  34973. currentBuffer--;
  34974. var buffer = colBuffers[currentBuffer];
  34975. this.extend(buffer, bufferPadding, height);
  34976. this.filter(buffer, bufferPadding, height);
  34977. // If this is last buffer in this group of buffers, flush all buffers.
  34978. if (currentBuffer === 0) {
  34979. k = u - numBuffers + 1;
  34980. for (l = bufferPadding; l < ll; k += width, l++) {
  34981. for (b = 0; b < numBuffers; b++) {
  34982. items[k + b] = colBuffers[b][l];
  34983. }
  34984. }
  34985. }
  34986. }
  34987. }
  34988. return {
  34989. width: width,
  34990. height: height,
  34991. items: items
  34992. };
  34993. };
  34994. return Transform;
  34995. })();
  34996. // Section 3.8.2 Irreversible 9-7 filter
  34997. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  34998. function IrreversibleTransform() {
  34999. Transform.call(this);
  35000. }
  35001. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35002. IrreversibleTransform.prototype.filter =
  35003. function irreversibleTransformFilter(x, offset, length) {
  35004. var len = length >> 1;
  35005. offset = offset | 0;
  35006. var j, n, current, next;
  35007. var alpha = -1.586134342059924;
  35008. var beta = -0.052980118572961;
  35009. var gamma = 0.882911075530934;
  35010. var delta = 0.443506852043971;
  35011. var K = 1.230174104914001;
  35012. var K_ = 1 / K;
  35013. // step 1 is combined with step 3
  35014. // step 2
  35015. j = offset - 3;
  35016. for (n = len + 4; n--; j += 2) {
  35017. x[j] *= K_;
  35018. }
  35019. // step 1 & 3
  35020. j = offset - 2;
  35021. current = delta * x[j -1];
  35022. for (n = len + 3; n--; j += 2) {
  35023. next = delta * x[j + 1];
  35024. x[j] = K * x[j] - current - next;
  35025. if (n--) {
  35026. j += 2;
  35027. current = delta * x[j + 1];
  35028. x[j] = K * x[j] - current - next;
  35029. } else {
  35030. break;
  35031. }
  35032. }
  35033. // step 4
  35034. j = offset - 1;
  35035. current = gamma * x[j - 1];
  35036. for (n = len + 2; n--; j += 2) {
  35037. next = gamma * x[j + 1];
  35038. x[j] -= current + next;
  35039. if (n--) {
  35040. j += 2;
  35041. current = gamma * x[j + 1];
  35042. x[j] -= current + next;
  35043. } else {
  35044. break;
  35045. }
  35046. }
  35047. // step 5
  35048. j = offset;
  35049. current = beta * x[j - 1];
  35050. for (n = len + 1; n--; j += 2) {
  35051. next = beta * x[j + 1];
  35052. x[j] -= current + next;
  35053. if (n--) {
  35054. j += 2;
  35055. current = beta * x[j + 1];
  35056. x[j] -= current + next;
  35057. } else {
  35058. break;
  35059. }
  35060. }
  35061. // step 6
  35062. if (len !== 0) {
  35063. j = offset + 1;
  35064. current = alpha * x[j - 1];
  35065. for (n = len; n--; j += 2) {
  35066. next = alpha * x[j + 1];
  35067. x[j] -= current + next;
  35068. if (n--) {
  35069. j += 2;
  35070. current = alpha * x[j + 1];
  35071. x[j] -= current + next;
  35072. } else {
  35073. break;
  35074. }
  35075. }
  35076. }
  35077. };
  35078. return IrreversibleTransform;
  35079. })();
  35080. // Section 3.8.1 Reversible 5-3 filter
  35081. var ReversibleTransform = (function ReversibleTransformClosure() {
  35082. function ReversibleTransform() {
  35083. Transform.call(this);
  35084. }
  35085. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35086. ReversibleTransform.prototype.filter =
  35087. function reversibleTransformFilter(x, offset, length) {
  35088. var len = length >> 1;
  35089. offset = offset | 0;
  35090. var j, n;
  35091. for (j = offset, n = len + 1; n--; j += 2) {
  35092. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35093. }
  35094. for (j = offset + 1, n = len; n--; j += 2) {
  35095. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35096. }
  35097. };
  35098. return ReversibleTransform;
  35099. })();
  35100. return JpxImage;
  35101. })();
  35102. var Jbig2Image = (function Jbig2ImageClosure() {
  35103. // Utility data structures
  35104. function ContextCache() {}
  35105. ContextCache.prototype = {
  35106. getContexts: function(id) {
  35107. if (id in this) {
  35108. return this[id];
  35109. }
  35110. return (this[id] = new Int8Array(1 << 16));
  35111. }
  35112. };
  35113. function DecodingContext(data, start, end) {
  35114. this.data = data;
  35115. this.start = start;
  35116. this.end = end;
  35117. }
  35118. DecodingContext.prototype = {
  35119. get decoder() {
  35120. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35121. return shadow(this, 'decoder', decoder);
  35122. },
  35123. get contextCache() {
  35124. var cache = new ContextCache();
  35125. return shadow(this, 'contextCache', cache);
  35126. }
  35127. };
  35128. // Annex A. Arithmetic Integer Decoding Procedure
  35129. // A.2 Procedure for decoding values
  35130. function decodeInteger(contextCache, procedure, decoder) {
  35131. var contexts = contextCache.getContexts(procedure);
  35132. var prev = 1;
  35133. function readBits(length) {
  35134. var v = 0;
  35135. for (var i = 0; i < length; i++) {
  35136. var bit = decoder.readBit(contexts, prev);
  35137. prev = (prev < 256 ? (prev << 1) | bit :
  35138. (((prev << 1) | bit) & 511) | 256);
  35139. v = (v << 1) | bit;
  35140. }
  35141. return v >>> 0;
  35142. }
  35143. var sign = readBits(1);
  35144. var value = readBits(1) ?
  35145. (readBits(1) ?
  35146. (readBits(1) ?
  35147. (readBits(1) ?
  35148. (readBits(1) ?
  35149. (readBits(32) + 4436) :
  35150. readBits(12) + 340) :
  35151. readBits(8) + 84) :
  35152. readBits(6) + 20) :
  35153. readBits(4) + 4) :
  35154. readBits(2);
  35155. return (sign === 0 ? value : (value > 0 ? -value : null));
  35156. }
  35157. // A.3 The IAID decoding procedure
  35158. function decodeIAID(contextCache, decoder, codeLength) {
  35159. var contexts = contextCache.getContexts('IAID');
  35160. var prev = 1;
  35161. for (var i = 0; i < codeLength; i++) {
  35162. var bit = decoder.readBit(contexts, prev);
  35163. prev = (prev << 1) | bit;
  35164. }
  35165. if (codeLength < 31) {
  35166. return prev & ((1 << codeLength) - 1);
  35167. }
  35168. return prev & 0x7FFFFFFF;
  35169. }
  35170. // 7.3 Segment types
  35171. var SegmentTypes = [
  35172. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35173. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35174. null, null, null, null, null, 'patternDictionary', null, null, null,
  35175. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35176. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35177. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35178. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35179. 'IntermediateGenericRefinementRegion', null,
  35180. 'ImmediateGenericRefinementRegion',
  35181. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35182. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35183. 'Tables', null, null, null, null, null, null, null, null,
  35184. 'Extension'
  35185. ];
  35186. var CodingTemplates = [
  35187. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35188. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35189. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35190. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35191. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35192. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35193. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35194. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35195. {x: -1, y: 0}],
  35196. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35197. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35198. ];
  35199. var RefinementTemplates = [
  35200. {
  35201. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35202. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35203. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35204. },
  35205. {
  35206. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35207. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35208. {x: 0, y: 1}, {x: 1, y: 1}]
  35209. }
  35210. ];
  35211. // See 6.2.5.7 Decoding the bitmap.
  35212. var ReusedContexts = [
  35213. 0x9B25, // 10011 0110010 0101
  35214. 0x0795, // 0011 110010 101
  35215. 0x00E5, // 001 11001 01
  35216. 0x0195 // 011001 0101
  35217. ];
  35218. var RefinementReusedContexts = [
  35219. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35220. 0x0008 // '0000' + '001000'
  35221. ];
  35222. function decodeBitmapTemplate0(width, height, decodingContext) {
  35223. var decoder = decodingContext.decoder;
  35224. var contexts = decodingContext.contextCache.getContexts('GB');
  35225. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35226. // ...ooooo....
  35227. // ..ooooooo... Context template for current pixel (X)
  35228. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35229. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35230. for (i = 0; i < height; i++) {
  35231. row = bitmap[i] = new Uint8Array(width);
  35232. row1 = (i < 1) ? row : bitmap[i - 1];
  35233. row2 = (i < 2) ? row : bitmap[i - 2];
  35234. // At the beginning of each row:
  35235. // Fill contextLabel with pixels that are above/right of (X)
  35236. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35237. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35238. (row1[3] << 4);
  35239. for (j = 0; j < width; j++) {
  35240. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35241. // At each pixel: Clear contextLabel pixels that are shifted
  35242. // out of the context, then add new ones.
  35243. // If j + n is out of range at the right image border, then
  35244. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  35245. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35246. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  35247. }
  35248. }
  35249. return bitmap;
  35250. }
  35251. // 6.2 Generic Region Decoding Procedure
  35252. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35253. decodingContext) {
  35254. if (mmr) {
  35255. error('JBIG2 error: MMR encoding is not supported');
  35256. }
  35257. // Use optimized version for the most common case
  35258. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35259. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35260. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35261. return decodeBitmapTemplate0(width, height, decodingContext);
  35262. }
  35263. var useskip = !!skip;
  35264. var template = CodingTemplates[templateIndex].concat(at);
  35265. // Sorting is non-standard, and it is not required. But sorting increases
  35266. // the number of template bits that can be reused from the previous
  35267. // contextLabel in the main loop.
  35268. template.sort(function (a, b) {
  35269. return (a.y - b.y) || (a.x - b.x);
  35270. });
  35271. var templateLength = template.length;
  35272. var templateX = new Int8Array(templateLength);
  35273. var templateY = new Int8Array(templateLength);
  35274. var changingTemplateEntries = [];
  35275. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35276. var c, k;
  35277. for (k = 0; k < templateLength; k++) {
  35278. templateX[k] = template[k].x;
  35279. templateY[k] = template[k].y;
  35280. minX = Math.min(minX, template[k].x);
  35281. maxX = Math.max(maxX, template[k].x);
  35282. minY = Math.min(minY, template[k].y);
  35283. // Check if the template pixel appears in two consecutive context labels,
  35284. // so it can be reused. Otherwise, we add it to the list of changing
  35285. // template entries.
  35286. if (k < templateLength - 1 &&
  35287. template[k].y === template[k + 1].y &&
  35288. template[k].x === template[k + 1].x - 1) {
  35289. reuseMask |= 1 << (templateLength - 1 - k);
  35290. } else {
  35291. changingTemplateEntries.push(k);
  35292. }
  35293. }
  35294. var changingEntriesLength = changingTemplateEntries.length;
  35295. var changingTemplateX = new Int8Array(changingEntriesLength);
  35296. var changingTemplateY = new Int8Array(changingEntriesLength);
  35297. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35298. for (c = 0; c < changingEntriesLength; c++) {
  35299. k = changingTemplateEntries[c];
  35300. changingTemplateX[c] = template[k].x;
  35301. changingTemplateY[c] = template[k].y;
  35302. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35303. }
  35304. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35305. var sbb_left = -minX;
  35306. var sbb_top = -minY;
  35307. var sbb_right = width - maxX;
  35308. var pseudoPixelContext = ReusedContexts[templateIndex];
  35309. var row = new Uint8Array(width);
  35310. var bitmap = [];
  35311. var decoder = decodingContext.decoder;
  35312. var contexts = decodingContext.contextCache.getContexts('GB');
  35313. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35314. for (var i = 0; i < height; i++) {
  35315. if (prediction) {
  35316. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35317. ltp ^= sltp;
  35318. if (ltp) {
  35319. bitmap.push(row); // duplicate previous row
  35320. continue;
  35321. }
  35322. }
  35323. row = new Uint8Array(row);
  35324. bitmap.push(row);
  35325. for (j = 0; j < width; j++) {
  35326. if (useskip && skip[i][j]) {
  35327. row[j] = 0;
  35328. continue;
  35329. }
  35330. // Are we in the middle of a scanline, so we can reuse contextLabel
  35331. // bits?
  35332. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35333. // If yes, we can just shift the bits that are reusable and only
  35334. // fetch the remaining ones.
  35335. contextLabel = (contextLabel << 1) & reuseMask;
  35336. for (k = 0; k < changingEntriesLength; k++) {
  35337. i0 = i + changingTemplateY[k];
  35338. j0 = j + changingTemplateX[k];
  35339. bit = bitmap[i0][j0];
  35340. if (bit) {
  35341. bit = changingTemplateBit[k];
  35342. contextLabel |= bit;
  35343. }
  35344. }
  35345. } else {
  35346. // compute the contextLabel from scratch
  35347. contextLabel = 0;
  35348. shift = templateLength - 1;
  35349. for (k = 0; k < templateLength; k++, shift--) {
  35350. j0 = j + templateX[k];
  35351. if (j0 >= 0 && j0 < width) {
  35352. i0 = i + templateY[k];
  35353. if (i0 >= 0) {
  35354. bit = bitmap[i0][j0];
  35355. if (bit) {
  35356. contextLabel |= bit << shift;
  35357. }
  35358. }
  35359. }
  35360. }
  35361. }
  35362. var pixel = decoder.readBit(contexts, contextLabel);
  35363. row[j] = pixel;
  35364. }
  35365. }
  35366. return bitmap;
  35367. }
  35368. // 6.3.2 Generic Refinement Region Decoding Procedure
  35369. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35370. offsetX, offsetY, prediction, at,
  35371. decodingContext) {
  35372. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35373. if (templateIndex === 0) {
  35374. codingTemplate = codingTemplate.concat([at[0]]);
  35375. }
  35376. var codingTemplateLength = codingTemplate.length;
  35377. var codingTemplateX = new Int32Array(codingTemplateLength);
  35378. var codingTemplateY = new Int32Array(codingTemplateLength);
  35379. var k;
  35380. for (k = 0; k < codingTemplateLength; k++) {
  35381. codingTemplateX[k] = codingTemplate[k].x;
  35382. codingTemplateY[k] = codingTemplate[k].y;
  35383. }
  35384. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35385. if (templateIndex === 0) {
  35386. referenceTemplate = referenceTemplate.concat([at[1]]);
  35387. }
  35388. var referenceTemplateLength = referenceTemplate.length;
  35389. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35390. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35391. for (k = 0; k < referenceTemplateLength; k++) {
  35392. referenceTemplateX[k] = referenceTemplate[k].x;
  35393. referenceTemplateY[k] = referenceTemplate[k].y;
  35394. }
  35395. var referenceWidth = referenceBitmap[0].length;
  35396. var referenceHeight = referenceBitmap.length;
  35397. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35398. var bitmap = [];
  35399. var decoder = decodingContext.decoder;
  35400. var contexts = decodingContext.contextCache.getContexts('GR');
  35401. var ltp = 0;
  35402. for (var i = 0; i < height; i++) {
  35403. if (prediction) {
  35404. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35405. ltp ^= sltp;
  35406. if (ltp) {
  35407. error('JBIG2 error: prediction is not supported');
  35408. }
  35409. }
  35410. var row = new Uint8Array(width);
  35411. bitmap.push(row);
  35412. for (var j = 0; j < width; j++) {
  35413. var i0, j0;
  35414. var contextLabel = 0;
  35415. for (k = 0; k < codingTemplateLength; k++) {
  35416. i0 = i + codingTemplateY[k];
  35417. j0 = j + codingTemplateX[k];
  35418. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35419. contextLabel <<= 1; // out of bound pixel
  35420. } else {
  35421. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35422. }
  35423. }
  35424. for (k = 0; k < referenceTemplateLength; k++) {
  35425. i0 = i + referenceTemplateY[k] + offsetY;
  35426. j0 = j + referenceTemplateX[k] + offsetX;
  35427. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35428. j0 >= referenceWidth) {
  35429. contextLabel <<= 1; // out of bound pixel
  35430. } else {
  35431. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35432. }
  35433. }
  35434. var pixel = decoder.readBit(contexts, contextLabel);
  35435. row[j] = pixel;
  35436. }
  35437. }
  35438. return bitmap;
  35439. }
  35440. // 6.5.5 Decoding the symbol dictionary
  35441. function decodeSymbolDictionary(huffman, refinement, symbols,
  35442. numberOfNewSymbols, numberOfExportedSymbols,
  35443. huffmanTables, templateIndex, at,
  35444. refinementTemplateIndex, refinementAt,
  35445. decodingContext) {
  35446. if (huffman) {
  35447. error('JBIG2 error: huffman is not supported');
  35448. }
  35449. var newSymbols = [];
  35450. var currentHeight = 0;
  35451. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35452. var decoder = decodingContext.decoder;
  35453. var contextCache = decodingContext.contextCache;
  35454. while (newSymbols.length < numberOfNewSymbols) {
  35455. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35456. currentHeight += deltaHeight;
  35457. var currentWidth = 0;
  35458. var totalWidth = 0;
  35459. while (true) {
  35460. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35461. if (deltaWidth === null) {
  35462. break; // OOB
  35463. }
  35464. currentWidth += deltaWidth;
  35465. totalWidth += currentWidth;
  35466. var bitmap;
  35467. if (refinement) {
  35468. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35469. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35470. if (numberOfInstances > 1) {
  35471. bitmap = decodeTextRegion(huffman, refinement,
  35472. currentWidth, currentHeight, 0,
  35473. numberOfInstances, 1, //strip size
  35474. symbols.concat(newSymbols),
  35475. symbolCodeLength,
  35476. 0, //transposed
  35477. 0, //ds offset
  35478. 1, //top left 7.4.3.1.1
  35479. 0, //OR operator
  35480. huffmanTables,
  35481. refinementTemplateIndex, refinementAt,
  35482. decodingContext);
  35483. } else {
  35484. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35485. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35486. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35487. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35488. newSymbols[symbolId - symbols.length]);
  35489. bitmap = decodeRefinement(currentWidth, currentHeight,
  35490. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35491. decodingContext);
  35492. }
  35493. } else {
  35494. // 6.5.8.1 Direct-coded symbol bitmap
  35495. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35496. templateIndex, false, null, at, decodingContext);
  35497. }
  35498. newSymbols.push(bitmap);
  35499. }
  35500. }
  35501. // 6.5.10 Exported symbols
  35502. var exportedSymbols = [];
  35503. var flags = [], currentFlag = false;
  35504. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35505. while (flags.length < totalSymbolsLength) {
  35506. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35507. while (runLength--) {
  35508. flags.push(currentFlag);
  35509. }
  35510. currentFlag = !currentFlag;
  35511. }
  35512. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35513. if (flags[i]) {
  35514. exportedSymbols.push(symbols[i]);
  35515. }
  35516. }
  35517. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35518. if (flags[i]) {
  35519. exportedSymbols.push(newSymbols[j]);
  35520. }
  35521. }
  35522. return exportedSymbols;
  35523. }
  35524. function decodeTextRegion(huffman, refinement, width, height,
  35525. defaultPixelValue, numberOfSymbolInstances,
  35526. stripSize, inputSymbols, symbolCodeLength,
  35527. transposed, dsOffset, referenceCorner,
  35528. combinationOperator, huffmanTables,
  35529. refinementTemplateIndex, refinementAt,
  35530. decodingContext) {
  35531. if (huffman) {
  35532. error('JBIG2 error: huffman is not supported');
  35533. }
  35534. // Prepare bitmap
  35535. var bitmap = [];
  35536. var i, row;
  35537. for (i = 0; i < height; i++) {
  35538. row = new Uint8Array(width);
  35539. if (defaultPixelValue) {
  35540. for (var j = 0; j < width; j++) {
  35541. row[j] = defaultPixelValue;
  35542. }
  35543. }
  35544. bitmap.push(row);
  35545. }
  35546. var decoder = decodingContext.decoder;
  35547. var contextCache = decodingContext.contextCache;
  35548. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35549. var firstS = 0;
  35550. i = 0;
  35551. while (i < numberOfSymbolInstances) {
  35552. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35553. stripT += deltaT;
  35554. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35555. firstS += deltaFirstS;
  35556. var currentS = firstS;
  35557. do {
  35558. var currentT = (stripSize === 1 ? 0 :
  35559. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35560. var t = stripSize * stripT + currentT;
  35561. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35562. var applyRefinement = (refinement &&
  35563. decodeInteger(contextCache, 'IARI', decoder));
  35564. var symbolBitmap = inputSymbols[symbolId];
  35565. var symbolWidth = symbolBitmap[0].length;
  35566. var symbolHeight = symbolBitmap.length;
  35567. if (applyRefinement) {
  35568. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35569. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35570. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35571. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35572. symbolWidth += rdw;
  35573. symbolHeight += rdh;
  35574. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35575. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35576. (rdh >> 1) + rdy, false, refinementAt,
  35577. decodingContext);
  35578. }
  35579. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35580. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35581. var s2, t2, symbolRow;
  35582. if (transposed) {
  35583. // Place Symbol Bitmap from T1,S1
  35584. for (s2 = 0; s2 < symbolHeight; s2++) {
  35585. row = bitmap[offsetS + s2];
  35586. if (!row) {
  35587. continue;
  35588. }
  35589. symbolRow = symbolBitmap[s2];
  35590. // To ignore Parts of Symbol bitmap which goes
  35591. // outside bitmap region
  35592. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35593. switch (combinationOperator) {
  35594. case 0: // OR
  35595. for (t2 = 0; t2 < maxWidth; t2++) {
  35596. row[offsetT + t2] |= symbolRow[t2];
  35597. }
  35598. break;
  35599. case 2: // XOR
  35600. for (t2 = 0; t2 < maxWidth; t2++) {
  35601. row[offsetT + t2] ^= symbolRow[t2];
  35602. }
  35603. break;
  35604. default:
  35605. error('JBIG2 error: operator ' + combinationOperator +
  35606. ' is not supported');
  35607. }
  35608. }
  35609. currentS += symbolHeight - 1;
  35610. } else {
  35611. for (t2 = 0; t2 < symbolHeight; t2++) {
  35612. row = bitmap[offsetT + t2];
  35613. if (!row) {
  35614. continue;
  35615. }
  35616. symbolRow = symbolBitmap[t2];
  35617. switch (combinationOperator) {
  35618. case 0: // OR
  35619. for (s2 = 0; s2 < symbolWidth; s2++) {
  35620. row[offsetS + s2] |= symbolRow[s2];
  35621. }
  35622. break;
  35623. case 2: // XOR
  35624. for (s2 = 0; s2 < symbolWidth; s2++) {
  35625. row[offsetS + s2] ^= symbolRow[s2];
  35626. }
  35627. break;
  35628. default:
  35629. error('JBIG2 error: operator ' + combinationOperator +
  35630. ' is not supported');
  35631. }
  35632. }
  35633. currentS += symbolWidth - 1;
  35634. }
  35635. i++;
  35636. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35637. if (deltaS === null) {
  35638. break; // OOB
  35639. }
  35640. currentS += deltaS + dsOffset;
  35641. } while (true);
  35642. }
  35643. return bitmap;
  35644. }
  35645. function readSegmentHeader(data, start) {
  35646. var segmentHeader = {};
  35647. segmentHeader.number = readUint32(data, start);
  35648. var flags = data[start + 4];
  35649. var segmentType = flags & 0x3F;
  35650. if (!SegmentTypes[segmentType]) {
  35651. error('JBIG2 error: invalid segment type: ' + segmentType);
  35652. }
  35653. segmentHeader.type = segmentType;
  35654. segmentHeader.typeName = SegmentTypes[segmentType];
  35655. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35656. var pageAssociationFieldSize = !!(flags & 0x40);
  35657. var referredFlags = data[start + 5];
  35658. var referredToCount = (referredFlags >> 5) & 7;
  35659. var retainBits = [referredFlags & 31];
  35660. var position = start + 6;
  35661. if (referredFlags === 7) {
  35662. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35663. position += 3;
  35664. var bytes = (referredToCount + 7) >> 3;
  35665. retainBits[0] = data[position++];
  35666. while (--bytes > 0) {
  35667. retainBits.push(data[position++]);
  35668. }
  35669. } else if (referredFlags === 5 || referredFlags === 6) {
  35670. error('JBIG2 error: invalid referred-to flags');
  35671. }
  35672. segmentHeader.retainBits = retainBits;
  35673. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35674. (segmentHeader.number <= 65536 ? 2 : 4));
  35675. var referredTo = [];
  35676. var i, ii;
  35677. for (i = 0; i < referredToCount; i++) {
  35678. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35679. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35680. readUint32(data, position)));
  35681. referredTo.push(number);
  35682. position += referredToSegmentNumberSize;
  35683. }
  35684. segmentHeader.referredTo = referredTo;
  35685. if (!pageAssociationFieldSize) {
  35686. segmentHeader.pageAssociation = data[position++];
  35687. } else {
  35688. segmentHeader.pageAssociation = readUint32(data, position);
  35689. position += 4;
  35690. }
  35691. segmentHeader.length = readUint32(data, position);
  35692. position += 4;
  35693. if (segmentHeader.length === 0xFFFFFFFF) {
  35694. // 7.2.7 Segment data length, unknown segment length
  35695. if (segmentType === 38) { // ImmediateGenericRegion
  35696. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35697. var genericRegionSegmentFlags = data[position +
  35698. RegionSegmentInformationFieldLength];
  35699. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35700. // searching for the segment end
  35701. var searchPatternLength = 6;
  35702. var searchPattern = new Uint8Array(searchPatternLength);
  35703. if (!genericRegionMmr) {
  35704. searchPattern[0] = 0xFF;
  35705. searchPattern[1] = 0xAC;
  35706. }
  35707. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35708. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35709. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35710. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35711. for (i = position, ii = data.length; i < ii; i++) {
  35712. var j = 0;
  35713. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35714. j++;
  35715. }
  35716. if (j === searchPatternLength) {
  35717. segmentHeader.length = i + searchPatternLength;
  35718. break;
  35719. }
  35720. }
  35721. if (segmentHeader.length === 0xFFFFFFFF) {
  35722. error('JBIG2 error: segment end was not found');
  35723. }
  35724. } else {
  35725. error('JBIG2 error: invalid unknown segment length');
  35726. }
  35727. }
  35728. segmentHeader.headerEnd = position;
  35729. return segmentHeader;
  35730. }
  35731. function readSegments(header, data, start, end) {
  35732. var segments = [];
  35733. var position = start;
  35734. while (position < end) {
  35735. var segmentHeader = readSegmentHeader(data, position);
  35736. position = segmentHeader.headerEnd;
  35737. var segment = {
  35738. header: segmentHeader,
  35739. data: data
  35740. };
  35741. if (!header.randomAccess) {
  35742. segment.start = position;
  35743. position += segmentHeader.length;
  35744. segment.end = position;
  35745. }
  35746. segments.push(segment);
  35747. if (segmentHeader.type === 51) {
  35748. break; // end of file is found
  35749. }
  35750. }
  35751. if (header.randomAccess) {
  35752. for (var i = 0, ii = segments.length; i < ii; i++) {
  35753. segments[i].start = position;
  35754. position += segments[i].header.length;
  35755. segments[i].end = position;
  35756. }
  35757. }
  35758. return segments;
  35759. }
  35760. // 7.4.1 Region segment information field
  35761. function readRegionSegmentInformation(data, start) {
  35762. return {
  35763. width: readUint32(data, start),
  35764. height: readUint32(data, start + 4),
  35765. x: readUint32(data, start + 8),
  35766. y: readUint32(data, start + 12),
  35767. combinationOperator: data[start + 16] & 7
  35768. };
  35769. }
  35770. var RegionSegmentInformationFieldLength = 17;
  35771. function processSegment(segment, visitor) {
  35772. var header = segment.header;
  35773. var data = segment.data, position = segment.start, end = segment.end;
  35774. var args, at, i, atLength;
  35775. switch (header.type) {
  35776. case 0: // SymbolDictionary
  35777. // 7.4.2 Symbol dictionary segment syntax
  35778. var dictionary = {};
  35779. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35780. dictionary.huffman = !!(dictionaryFlags & 1);
  35781. dictionary.refinement = !!(dictionaryFlags & 2);
  35782. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35783. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35784. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35785. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35786. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35787. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35788. dictionary.template = (dictionaryFlags >> 10) & 3;
  35789. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35790. position += 2;
  35791. if (!dictionary.huffman) {
  35792. atLength = dictionary.template === 0 ? 4 : 1;
  35793. at = [];
  35794. for (i = 0; i < atLength; i++) {
  35795. at.push({
  35796. x: readInt8(data, position),
  35797. y: readInt8(data, position + 1)
  35798. });
  35799. position += 2;
  35800. }
  35801. dictionary.at = at;
  35802. }
  35803. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35804. at = [];
  35805. for (i = 0; i < 2; i++) {
  35806. at.push({
  35807. x: readInt8(data, position),
  35808. y: readInt8(data, position + 1)
  35809. });
  35810. position += 2;
  35811. }
  35812. dictionary.refinementAt = at;
  35813. }
  35814. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35815. position += 4;
  35816. dictionary.numberOfNewSymbols = readUint32(data, position);
  35817. position += 4;
  35818. args = [dictionary, header.number, header.referredTo,
  35819. data, position, end];
  35820. break;
  35821. case 6: // ImmediateTextRegion
  35822. case 7: // ImmediateLosslessTextRegion
  35823. var textRegion = {};
  35824. textRegion.info = readRegionSegmentInformation(data, position);
  35825. position += RegionSegmentInformationFieldLength;
  35826. var textRegionSegmentFlags = readUint16(data, position);
  35827. position += 2;
  35828. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35829. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35830. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35831. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35832. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35833. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35834. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35835. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35836. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35837. if (textRegion.huffman) {
  35838. var textRegionHuffmanFlags = readUint16(data, position);
  35839. position += 2;
  35840. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35841. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35842. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35843. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35844. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35845. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35846. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35847. textRegion.huffmanRefinementSizeSelector =
  35848. !!(textRegionHuffmanFlags & 14);
  35849. }
  35850. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35851. at = [];
  35852. for (i = 0; i < 2; i++) {
  35853. at.push({
  35854. x: readInt8(data, position),
  35855. y: readInt8(data, position + 1)
  35856. });
  35857. position += 2;
  35858. }
  35859. textRegion.refinementAt = at;
  35860. }
  35861. textRegion.numberOfSymbolInstances = readUint32(data, position);
  35862. position += 4;
  35863. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  35864. if (textRegion.huffman) {
  35865. error('JBIG2 error: huffman is not supported');
  35866. }
  35867. args = [textRegion, header.referredTo, data, position, end];
  35868. break;
  35869. case 38: // ImmediateGenericRegion
  35870. case 39: // ImmediateLosslessGenericRegion
  35871. var genericRegion = {};
  35872. genericRegion.info = readRegionSegmentInformation(data, position);
  35873. position += RegionSegmentInformationFieldLength;
  35874. var genericRegionSegmentFlags = data[position++];
  35875. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  35876. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  35877. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  35878. if (!genericRegion.mmr) {
  35879. atLength = genericRegion.template === 0 ? 4 : 1;
  35880. at = [];
  35881. for (i = 0; i < atLength; i++) {
  35882. at.push({
  35883. x: readInt8(data, position),
  35884. y: readInt8(data, position + 1)
  35885. });
  35886. position += 2;
  35887. }
  35888. genericRegion.at = at;
  35889. }
  35890. args = [genericRegion, data, position, end];
  35891. break;
  35892. case 48: // PageInformation
  35893. var pageInfo = {
  35894. width: readUint32(data, position),
  35895. height: readUint32(data, position + 4),
  35896. resolutionX: readUint32(data, position + 8),
  35897. resolutionY: readUint32(data, position + 12)
  35898. };
  35899. if (pageInfo.height === 0xFFFFFFFF) {
  35900. delete pageInfo.height;
  35901. }
  35902. var pageSegmentFlags = data[position + 16];
  35903. var pageStripingInformatiom = readUint16(data, position + 17);
  35904. pageInfo.lossless = !!(pageSegmentFlags & 1);
  35905. pageInfo.refinement = !!(pageSegmentFlags & 2);
  35906. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  35907. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  35908. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  35909. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  35910. args = [pageInfo];
  35911. break;
  35912. case 49: // EndOfPage
  35913. break;
  35914. case 50: // EndOfStripe
  35915. break;
  35916. case 51: // EndOfFile
  35917. break;
  35918. case 62: // 7.4.15 defines 2 extension types which
  35919. // are comments and can be ignored.
  35920. break;
  35921. default:
  35922. error('JBIG2 error: segment type ' + header.typeName + '(' +
  35923. header.type + ') is not implemented');
  35924. }
  35925. var callbackName = 'on' + header.typeName;
  35926. if (callbackName in visitor) {
  35927. visitor[callbackName].apply(visitor, args);
  35928. }
  35929. }
  35930. function processSegments(segments, visitor) {
  35931. for (var i = 0, ii = segments.length; i < ii; i++) {
  35932. processSegment(segments[i], visitor);
  35933. }
  35934. }
  35935. function parseJbig2(data, start, end) {
  35936. var position = start;
  35937. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  35938. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  35939. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  35940. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  35941. error('JBIG2 error: invalid header');
  35942. }
  35943. var header = {};
  35944. position += 8;
  35945. var flags = data[position++];
  35946. header.randomAccess = !(flags & 1);
  35947. if (!(flags & 2)) {
  35948. header.numberOfPages = readUint32(data, position);
  35949. position += 4;
  35950. }
  35951. var segments = readSegments(header, data, position, end);
  35952. error('Not implemented');
  35953. // processSegments(segments, new SimpleSegmentVisitor());
  35954. }
  35955. function parseJbig2Chunks(chunks) {
  35956. var visitor = new SimpleSegmentVisitor();
  35957. for (var i = 0, ii = chunks.length; i < ii; i++) {
  35958. var chunk = chunks[i];
  35959. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  35960. processSegments(segments, visitor);
  35961. }
  35962. return visitor.buffer;
  35963. }
  35964. function SimpleSegmentVisitor() {}
  35965. SimpleSegmentVisitor.prototype = {
  35966. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  35967. this.currentPageInfo = info;
  35968. var rowSize = (info.width + 7) >> 3;
  35969. var buffer = new Uint8Array(rowSize * info.height);
  35970. // The contents of ArrayBuffers are initialized to 0.
  35971. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  35972. if (info.defaultPixelValue) {
  35973. for (var i = 0, ii = buffer.length; i < ii; i++) {
  35974. buffer[i] = 0xFF;
  35975. }
  35976. }
  35977. this.buffer = buffer;
  35978. },
  35979. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  35980. var pageInfo = this.currentPageInfo;
  35981. var width = regionInfo.width, height = regionInfo.height;
  35982. var rowSize = (pageInfo.width + 7) >> 3;
  35983. var combinationOperator = pageInfo.combinationOperatorOverride ?
  35984. regionInfo.combinationOperator : pageInfo.combinationOperator;
  35985. var buffer = this.buffer;
  35986. var mask0 = 128 >> (regionInfo.x & 7);
  35987. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  35988. var i, j, mask, offset;
  35989. switch (combinationOperator) {
  35990. case 0: // OR
  35991. for (i = 0; i < height; i++) {
  35992. mask = mask0;
  35993. offset = offset0;
  35994. for (j = 0; j < width; j++) {
  35995. if (bitmap[i][j]) {
  35996. buffer[offset] |= mask;
  35997. }
  35998. mask >>= 1;
  35999. if (!mask) {
  36000. mask = 128;
  36001. offset++;
  36002. }
  36003. }
  36004. offset0 += rowSize;
  36005. }
  36006. break;
  36007. case 2: // XOR
  36008. for (i = 0; i < height; i++) {
  36009. mask = mask0;
  36010. offset = offset0;
  36011. for (j = 0; j < width; j++) {
  36012. if (bitmap[i][j]) {
  36013. buffer[offset] ^= mask;
  36014. }
  36015. mask >>= 1;
  36016. if (!mask) {
  36017. mask = 128;
  36018. offset++;
  36019. }
  36020. }
  36021. offset0 += rowSize;
  36022. }
  36023. break;
  36024. default:
  36025. error('JBIG2 error: operator ' + combinationOperator +
  36026. ' is not supported');
  36027. }
  36028. },
  36029. onImmediateGenericRegion:
  36030. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36031. start, end) {
  36032. var regionInfo = region.info;
  36033. var decodingContext = new DecodingContext(data, start, end);
  36034. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36035. region.template, region.prediction, null,
  36036. region.at, decodingContext);
  36037. this.drawBitmap(regionInfo, bitmap);
  36038. },
  36039. onImmediateLosslessGenericRegion:
  36040. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36041. this.onImmediateGenericRegion.apply(this, arguments);
  36042. },
  36043. onSymbolDictionary:
  36044. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36045. currentSegment,
  36046. referredSegments,
  36047. data, start, end) {
  36048. var huffmanTables;
  36049. if (dictionary.huffman) {
  36050. error('JBIG2 error: huffman is not supported');
  36051. }
  36052. // Combines exported symbols from all referred segments
  36053. var symbols = this.symbols;
  36054. if (!symbols) {
  36055. this.symbols = symbols = {};
  36056. }
  36057. var inputSymbols = [];
  36058. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36059. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36060. }
  36061. var decodingContext = new DecodingContext(data, start, end);
  36062. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36063. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36064. dictionary.numberOfExportedSymbols, huffmanTables,
  36065. dictionary.template, dictionary.at,
  36066. dictionary.refinementTemplate, dictionary.refinementAt,
  36067. decodingContext);
  36068. },
  36069. onImmediateTextRegion:
  36070. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36071. referredSegments,
  36072. data, start, end) {
  36073. var regionInfo = region.info;
  36074. var huffmanTables;
  36075. // Combines exported symbols from all referred segments
  36076. var symbols = this.symbols;
  36077. var inputSymbols = [];
  36078. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36079. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36080. }
  36081. var symbolCodeLength = log2(inputSymbols.length);
  36082. var decodingContext = new DecodingContext(data, start, end);
  36083. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36084. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36085. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36086. symbolCodeLength, region.transposed, region.dsOffset,
  36087. region.referenceCorner, region.combinationOperator, huffmanTables,
  36088. region.refinementTemplate, region.refinementAt, decodingContext);
  36089. this.drawBitmap(regionInfo, bitmap);
  36090. },
  36091. onImmediateLosslessTextRegion:
  36092. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36093. this.onImmediateTextRegion.apply(this, arguments);
  36094. }
  36095. };
  36096. function Jbig2Image() {}
  36097. Jbig2Image.prototype = {
  36098. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36099. return parseJbig2Chunks(chunks);
  36100. }
  36101. };
  36102. return Jbig2Image;
  36103. })();
  36104. var bidi = PDFJS.bidi = (function bidiClosure() {
  36105. // Character types for symbols from 0000 to 00FF.
  36106. var baseTypes = [
  36107. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36108. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36109. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36110. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36111. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36112. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36113. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36114. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36115. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36116. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36117. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36118. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36119. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36120. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36121. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36122. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36123. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36124. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36125. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36126. ];
  36127. // Character types for symbols from 0600 to 06FF
  36128. var arabicTypes = [
  36129. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36130. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36131. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36132. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36133. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36134. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36135. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36136. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36137. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36138. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36139. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36140. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36141. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36142. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36143. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36144. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36145. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36146. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36147. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36148. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36149. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36150. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36151. ];
  36152. function isOdd(i) {
  36153. return (i & 1) !== 0;
  36154. }
  36155. function isEven(i) {
  36156. return (i & 1) === 0;
  36157. }
  36158. function findUnequal(arr, start, value) {
  36159. for (var j = start, jj = arr.length; j < jj; ++j) {
  36160. if (arr[j] !== value) {
  36161. return j;
  36162. }
  36163. }
  36164. return j;
  36165. }
  36166. function setValues(arr, start, end, value) {
  36167. for (var j = start; j < end; ++j) {
  36168. arr[j] = value;
  36169. }
  36170. }
  36171. function reverseValues(arr, start, end) {
  36172. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36173. var temp = arr[i];
  36174. arr[i] = arr[j];
  36175. arr[j] = temp;
  36176. }
  36177. }
  36178. function createBidiText(str, isLTR, vertical) {
  36179. return {
  36180. str: str,
  36181. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36182. };
  36183. }
  36184. // These are used in bidi(), which is called frequently. We re-use them on
  36185. // each call to avoid unnecessary allocations.
  36186. var chars = [];
  36187. var types = [];
  36188. function bidi(str, startLevel, vertical) {
  36189. var isLTR = true;
  36190. var strLength = str.length;
  36191. if (strLength === 0 || vertical) {
  36192. return createBidiText(str, isLTR, vertical);
  36193. }
  36194. // Get types and fill arrays
  36195. chars.length = strLength;
  36196. types.length = strLength;
  36197. var numBidi = 0;
  36198. var i, ii;
  36199. for (i = 0; i < strLength; ++i) {
  36200. chars[i] = str.charAt(i);
  36201. var charCode = str.charCodeAt(i);
  36202. var charType = 'L';
  36203. if (charCode <= 0x00ff) {
  36204. charType = baseTypes[charCode];
  36205. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36206. charType = 'R';
  36207. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36208. charType = arabicTypes[charCode & 0xff];
  36209. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36210. charType = 'AL';
  36211. }
  36212. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36213. numBidi++;
  36214. }
  36215. types[i] = charType;
  36216. }
  36217. // Detect the bidi method
  36218. // - If there are no rtl characters then no bidi needed
  36219. // - If less than 30% chars are rtl then string is primarily ltr
  36220. // - If more than 30% chars are rtl then string is primarily rtl
  36221. if (numBidi === 0) {
  36222. isLTR = true;
  36223. return createBidiText(str, isLTR);
  36224. }
  36225. if (startLevel === -1) {
  36226. if ((strLength / numBidi) < 0.3) {
  36227. isLTR = true;
  36228. startLevel = 0;
  36229. } else {
  36230. isLTR = false;
  36231. startLevel = 1;
  36232. }
  36233. }
  36234. var levels = [];
  36235. for (i = 0; i < strLength; ++i) {
  36236. levels[i] = startLevel;
  36237. }
  36238. /*
  36239. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36240. */
  36241. var e = (isOdd(startLevel) ? 'R' : 'L');
  36242. var sor = e;
  36243. var eor = sor;
  36244. /*
  36245. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36246. type of the NSM to the type of the previous character. If the NSM is at the
  36247. start of the level run, it will get the type of sor.
  36248. */
  36249. var lastType = sor;
  36250. for (i = 0; i < strLength; ++i) {
  36251. if (types[i] === 'NSM') {
  36252. types[i] = lastType;
  36253. } else {
  36254. lastType = types[i];
  36255. }
  36256. }
  36257. /*
  36258. W2. Search backwards from each instance of a European number until the
  36259. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36260. the type of the European number to Arabic number.
  36261. */
  36262. lastType = sor;
  36263. var t;
  36264. for (i = 0; i < strLength; ++i) {
  36265. t = types[i];
  36266. if (t === 'EN') {
  36267. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36268. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36269. lastType = t;
  36270. }
  36271. }
  36272. /*
  36273. W3. Change all ALs to R.
  36274. */
  36275. for (i = 0; i < strLength; ++i) {
  36276. t = types[i];
  36277. if (t === 'AL') {
  36278. types[i] = 'R';
  36279. }
  36280. }
  36281. /*
  36282. W4. A single European separator between two European numbers changes to a
  36283. European number. A single common separator between two numbers of the same
  36284. type changes to that type:
  36285. */
  36286. for (i = 1; i < strLength - 1; ++i) {
  36287. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36288. types[i] = 'EN';
  36289. }
  36290. if (types[i] === 'CS' &&
  36291. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36292. types[i + 1] === types[i - 1]) {
  36293. types[i] = types[i - 1];
  36294. }
  36295. }
  36296. /*
  36297. W5. A sequence of European terminators adjacent to European numbers changes
  36298. to all European numbers:
  36299. */
  36300. for (i = 0; i < strLength; ++i) {
  36301. if (types[i] === 'EN') {
  36302. // do before
  36303. var j;
  36304. for (j = i - 1; j >= 0; --j) {
  36305. if (types[j] !== 'ET') {
  36306. break;
  36307. }
  36308. types[j] = 'EN';
  36309. }
  36310. // do after
  36311. for (j = i + 1; j < strLength; --j) {
  36312. if (types[j] !== 'ET') {
  36313. break;
  36314. }
  36315. types[j] = 'EN';
  36316. }
  36317. }
  36318. }
  36319. /*
  36320. W6. Otherwise, separators and terminators change to Other Neutral:
  36321. */
  36322. for (i = 0; i < strLength; ++i) {
  36323. t = types[i];
  36324. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36325. types[i] = 'ON';
  36326. }
  36327. }
  36328. /*
  36329. W7. Search backwards from each instance of a European number until the
  36330. first strong type (R, L, or sor) is found. If an L is found, then change
  36331. the type of the European number to L.
  36332. */
  36333. lastType = sor;
  36334. for (i = 0; i < strLength; ++i) {
  36335. t = types[i];
  36336. if (t === 'EN') {
  36337. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36338. } else if (t === 'R' || t === 'L') {
  36339. lastType = t;
  36340. }
  36341. }
  36342. /*
  36343. N1. A sequence of neutrals takes the direction of the surrounding strong
  36344. text if the text on both sides has the same direction. European and Arabic
  36345. numbers are treated as though they were R. Start-of-level-run (sor) and
  36346. end-of-level-run (eor) are used at level run boundaries.
  36347. */
  36348. for (i = 0; i < strLength; ++i) {
  36349. if (types[i] === 'ON') {
  36350. var end = findUnequal(types, i + 1, 'ON');
  36351. var before = sor;
  36352. if (i > 0) {
  36353. before = types[i - 1];
  36354. }
  36355. var after = eor;
  36356. if (end + 1 < strLength) {
  36357. after = types[end + 1];
  36358. }
  36359. if (before !== 'L') {
  36360. before = 'R';
  36361. }
  36362. if (after !== 'L') {
  36363. after = 'R';
  36364. }
  36365. if (before === after) {
  36366. setValues(types, i, end, before);
  36367. }
  36368. i = end - 1; // reset to end (-1 so next iteration is ok)
  36369. }
  36370. }
  36371. /*
  36372. N2. Any remaining neutrals take the embedding direction.
  36373. */
  36374. for (i = 0; i < strLength; ++i) {
  36375. if (types[i] === 'ON') {
  36376. types[i] = e;
  36377. }
  36378. }
  36379. /*
  36380. I1. For all characters with an even (left-to-right) embedding direction,
  36381. those of type R go up one level and those of type AN or EN go up two
  36382. levels.
  36383. I2. For all characters with an odd (right-to-left) embedding direction,
  36384. those of type L, EN or AN go up one level.
  36385. */
  36386. for (i = 0; i < strLength; ++i) {
  36387. t = types[i];
  36388. if (isEven(levels[i])) {
  36389. if (t === 'R') {
  36390. levels[i] += 1;
  36391. } else if (t === 'AN' || t === 'EN') {
  36392. levels[i] += 2;
  36393. }
  36394. } else { // isOdd
  36395. if (t === 'L' || t === 'AN' || t === 'EN') {
  36396. levels[i] += 1;
  36397. }
  36398. }
  36399. }
  36400. /*
  36401. L1. On each line, reset the embedding level of the following characters to
  36402. the paragraph embedding level:
  36403. segment separators,
  36404. paragraph separators,
  36405. any sequence of whitespace characters preceding a segment separator or
  36406. paragraph separator, and any sequence of white space characters at the end
  36407. of the line.
  36408. */
  36409. // don't bother as text is only single line
  36410. /*
  36411. L2. From the highest level found in the text to the lowest odd level on
  36412. each line, reverse any contiguous sequence of characters that are at that
  36413. level or higher.
  36414. */
  36415. // find highest level & lowest odd level
  36416. var highestLevel = -1;
  36417. var lowestOddLevel = 99;
  36418. var level;
  36419. for (i = 0, ii = levels.length; i < ii; ++i) {
  36420. level = levels[i];
  36421. if (highestLevel < level) {
  36422. highestLevel = level;
  36423. }
  36424. if (lowestOddLevel > level && isOdd(level)) {
  36425. lowestOddLevel = level;
  36426. }
  36427. }
  36428. // now reverse between those limits
  36429. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36430. // find segments to reverse
  36431. var start = -1;
  36432. for (i = 0, ii = levels.length; i < ii; ++i) {
  36433. if (levels[i] < level) {
  36434. if (start >= 0) {
  36435. reverseValues(chars, start, i);
  36436. start = -1;
  36437. }
  36438. } else if (start < 0) {
  36439. start = i;
  36440. }
  36441. }
  36442. if (start >= 0) {
  36443. reverseValues(chars, start, levels.length);
  36444. }
  36445. }
  36446. /*
  36447. L3. Combining marks applied to a right-to-left base character will at this
  36448. point precede their base character. If the rendering engine expects them to
  36449. follow the base characters in the final display process, then the ordering
  36450. of the marks and the base character must be reversed.
  36451. */
  36452. // don't bother for now
  36453. /*
  36454. L4. A character that possesses the mirrored property as specified by
  36455. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36456. directionality of that character is R.
  36457. */
  36458. // don't mirror as characters are already mirrored in the pdf
  36459. // Finally, return string
  36460. var result = '';
  36461. for (i = 0, ii = chars.length; i < ii; ++i) {
  36462. var ch = chars[i];
  36463. if (ch !== '<' && ch !== '>') {
  36464. result += ch;
  36465. }
  36466. }
  36467. return createBidiText(result, isLTR);
  36468. }
  36469. return bidi;
  36470. })();
  36471. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36472. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36473. /* Copyright 2014 Opera Software ASA
  36474. *
  36475. * Licensed under the Apache License, Version 2.0 (the "License");
  36476. * you may not use this file except in compliance with the License.
  36477. * You may obtain a copy of the License at
  36478. *
  36479. * http://www.apache.org/licenses/LICENSE-2.0
  36480. *
  36481. * Unless required by applicable law or agreed to in writing, software
  36482. * distributed under the License is distributed on an "AS IS" BASIS,
  36483. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36484. * See the License for the specific language governing permissions and
  36485. * limitations under the License.
  36486. *
  36487. *
  36488. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36489. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36490. */
  36491. /* globals Uint32ArrayView */
  36492. 'use strict';
  36493. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36494. // Workaround for missing math precison in JS.
  36495. var MASK_HIGH = 0xffff0000;
  36496. var MASK_LOW = 0xffff;
  36497. function MurmurHash3_64 (seed) {
  36498. var SEED = 0xc3d2e1f0;
  36499. this.h1 = seed ? seed & 0xffffffff : SEED;
  36500. this.h2 = seed ? seed & 0xffffffff : SEED;
  36501. }
  36502. var alwaysUseUint32ArrayView = false;
  36503. // old webkits have issues with non-aligned arrays
  36504. try {
  36505. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36506. } catch (e) {
  36507. alwaysUseUint32ArrayView = true;
  36508. }
  36509. MurmurHash3_64.prototype = {
  36510. update: function MurmurHash3_64_update(input) {
  36511. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36512. var i;
  36513. if (typeof input === 'string') {
  36514. var data = new Uint8Array(input.length * 2);
  36515. var length = 0;
  36516. for (i = 0; i < input.length; i++) {
  36517. var code = input.charCodeAt(i);
  36518. if (code <= 0xff) {
  36519. data[length++] = code;
  36520. }
  36521. else {
  36522. data[length++] = code >>> 8;
  36523. data[length++] = code & 0xff;
  36524. }
  36525. }
  36526. } else if (input instanceof Uint8Array) {
  36527. data = input;
  36528. length = data.length;
  36529. } else if (typeof input === 'object' && ('length' in input)) {
  36530. // processing regular arrays as well, e.g. for IE9
  36531. data = input;
  36532. length = data.length;
  36533. useUint32ArrayView = true;
  36534. } else {
  36535. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36536. 'Input must be a string or array.');
  36537. }
  36538. var blockCounts = length >> 2;
  36539. var tailLength = length - blockCounts * 4;
  36540. // we don't care about endianness here
  36541. var dataUint32 = useUint32ArrayView ?
  36542. new Uint32ArrayView(data, blockCounts) :
  36543. new Uint32Array(data.buffer, 0, blockCounts);
  36544. var k1 = 0;
  36545. var k2 = 0;
  36546. var h1 = this.h1;
  36547. var h2 = this.h2;
  36548. var C1 = 0xcc9e2d51;
  36549. var C2 = 0x1b873593;
  36550. var C1_LOW = C1 & MASK_LOW;
  36551. var C2_LOW = C2 & MASK_LOW;
  36552. for (i = 0; i < blockCounts; i++) {
  36553. if (i & 1) {
  36554. k1 = dataUint32[i];
  36555. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36556. k1 = k1 << 15 | k1 >>> 17;
  36557. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36558. h1 ^= k1;
  36559. h1 = h1 << 13 | h1 >>> 19;
  36560. h1 = h1 * 5 + 0xe6546b64;
  36561. } else {
  36562. k2 = dataUint32[i];
  36563. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36564. k2 = k2 << 15 | k2 >>> 17;
  36565. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36566. h2 ^= k2;
  36567. h2 = h2 << 13 | h2 >>> 19;
  36568. h2 = h2 * 5 + 0xe6546b64;
  36569. }
  36570. }
  36571. k1 = 0;
  36572. switch (tailLength) {
  36573. case 3:
  36574. k1 ^= data[blockCounts * 4 + 2] << 16;
  36575. /* falls through */
  36576. case 2:
  36577. k1 ^= data[blockCounts * 4 + 1] << 8;
  36578. /* falls through */
  36579. case 1:
  36580. k1 ^= data[blockCounts * 4];
  36581. /* falls through */
  36582. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36583. k1 = k1 << 15 | k1 >>> 17;
  36584. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36585. if (blockCounts & 1) {
  36586. h1 ^= k1;
  36587. } else {
  36588. h2 ^= k1;
  36589. }
  36590. }
  36591. this.h1 = h1;
  36592. this.h2 = h2;
  36593. return this;
  36594. },
  36595. hexdigest: function MurmurHash3_64_hexdigest () {
  36596. var h1 = this.h1;
  36597. var h2 = this.h2;
  36598. h1 ^= h2 >>> 1;
  36599. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36600. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36601. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36602. h1 ^= h2 >>> 1;
  36603. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36604. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36605. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36606. h1 ^= h2 >>> 1;
  36607. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36608. var hex = (arr[i] >>> 0).toString(16);
  36609. while (hex.length < 8) {
  36610. hex = '0' + hex;
  36611. }
  36612. str += hex;
  36613. }
  36614. return str;
  36615. }
  36616. };
  36617. return MurmurHash3_64;
  36618. })();
  36619. }).call((typeof window === 'undefined') ? this : window);
  36620. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36621. // workerSrc is not set -- using last script url to define default location
  36622. PDFJS.workerSrc = (function () {
  36623. 'use strict';
  36624. var scriptTagContainer = document.body ||
  36625. document.getElementsByTagName('head')[0];
  36626. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36627. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36628. })();
  36629. }