pdf.worker.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.2.135';
  22. PDFJS.build = '467c6f9';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. var globalScope = (typeof window === 'undefined') ? this : window;
  27. var isWorker = (typeof window === 'undefined');
  28. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  29. var TextRenderingMode = {
  30. FILL: 0,
  31. STROKE: 1,
  32. FILL_STROKE: 2,
  33. INVISIBLE: 3,
  34. FILL_ADD_TO_PATH: 4,
  35. STROKE_ADD_TO_PATH: 5,
  36. FILL_STROKE_ADD_TO_PATH: 6,
  37. ADD_TO_PATH: 7,
  38. FILL_STROKE_MASK: 3,
  39. ADD_TO_PATH_FLAG: 4
  40. };
  41. var ImageKind = {
  42. GRAYSCALE_1BPP: 1,
  43. RGB_24BPP: 2,
  44. RGBA_32BPP: 3
  45. };
  46. var AnnotationType = {
  47. WIDGET: 1,
  48. TEXT: 2,
  49. LINK: 3
  50. };
  51. var AnnotationBorderStyleType = {
  52. SOLID: 1,
  53. DASHED: 2,
  54. BEVELED: 3,
  55. INSET: 4,
  56. UNDERLINE: 5
  57. };
  58. var StreamType = {
  59. UNKNOWN: 0,
  60. FLATE: 1,
  61. LZW: 2,
  62. DCT: 3,
  63. JPX: 4,
  64. JBIG: 5,
  65. A85: 6,
  66. AHX: 7,
  67. CCF: 8,
  68. RL: 9
  69. };
  70. var FontType = {
  71. UNKNOWN: 0,
  72. TYPE1: 1,
  73. TYPE1C: 2,
  74. CIDFONTTYPE0: 3,
  75. CIDFONTTYPE0C: 4,
  76. TRUETYPE: 5,
  77. CIDFONTTYPE2: 6,
  78. TYPE3: 7,
  79. OPENTYPE: 8,
  80. TYPE0: 9,
  81. MMTYPE1: 10
  82. };
  83. // The global PDFJS object exposes the API
  84. // In production, it will be declared outside a global wrapper
  85. // In development, it will be declared here
  86. if (!globalScope.PDFJS) {
  87. globalScope.PDFJS = {};
  88. }
  89. globalScope.PDFJS.pdfBug = false;
  90. PDFJS.VERBOSITY_LEVELS = {
  91. errors: 0,
  92. warnings: 1,
  93. infos: 5
  94. };
  95. // All the possible operations for an operator list.
  96. var OPS = PDFJS.OPS = {
  97. // Intentionally start from 1 so it is easy to spot bad operators that will be
  98. // 0's.
  99. dependency: 1,
  100. setLineWidth: 2,
  101. setLineCap: 3,
  102. setLineJoin: 4,
  103. setMiterLimit: 5,
  104. setDash: 6,
  105. setRenderingIntent: 7,
  106. setFlatness: 8,
  107. setGState: 9,
  108. save: 10,
  109. restore: 11,
  110. transform: 12,
  111. moveTo: 13,
  112. lineTo: 14,
  113. curveTo: 15,
  114. curveTo2: 16,
  115. curveTo3: 17,
  116. closePath: 18,
  117. rectangle: 19,
  118. stroke: 20,
  119. closeStroke: 21,
  120. fill: 22,
  121. eoFill: 23,
  122. fillStroke: 24,
  123. eoFillStroke: 25,
  124. closeFillStroke: 26,
  125. closeEOFillStroke: 27,
  126. endPath: 28,
  127. clip: 29,
  128. eoClip: 30,
  129. beginText: 31,
  130. endText: 32,
  131. setCharSpacing: 33,
  132. setWordSpacing: 34,
  133. setHScale: 35,
  134. setLeading: 36,
  135. setFont: 37,
  136. setTextRenderingMode: 38,
  137. setTextRise: 39,
  138. moveText: 40,
  139. setLeadingMoveText: 41,
  140. setTextMatrix: 42,
  141. nextLine: 43,
  142. showText: 44,
  143. showSpacedText: 45,
  144. nextLineShowText: 46,
  145. nextLineSetSpacingShowText: 47,
  146. setCharWidth: 48,
  147. setCharWidthAndBounds: 49,
  148. setStrokeColorSpace: 50,
  149. setFillColorSpace: 51,
  150. setStrokeColor: 52,
  151. setStrokeColorN: 53,
  152. setFillColor: 54,
  153. setFillColorN: 55,
  154. setStrokeGray: 56,
  155. setFillGray: 57,
  156. setStrokeRGBColor: 58,
  157. setFillRGBColor: 59,
  158. setStrokeCMYKColor: 60,
  159. setFillCMYKColor: 61,
  160. shadingFill: 62,
  161. beginInlineImage: 63,
  162. beginImageData: 64,
  163. endInlineImage: 65,
  164. paintXObject: 66,
  165. markPoint: 67,
  166. markPointProps: 68,
  167. beginMarkedContent: 69,
  168. beginMarkedContentProps: 70,
  169. endMarkedContent: 71,
  170. beginCompat: 72,
  171. endCompat: 73,
  172. paintFormXObjectBegin: 74,
  173. paintFormXObjectEnd: 75,
  174. beginGroup: 76,
  175. endGroup: 77,
  176. beginAnnotations: 78,
  177. endAnnotations: 79,
  178. beginAnnotation: 80,
  179. endAnnotation: 81,
  180. paintJpegXObject: 82,
  181. paintImageMaskXObject: 83,
  182. paintImageMaskXObjectGroup: 84,
  183. paintImageXObject: 85,
  184. paintInlineImageXObject: 86,
  185. paintInlineImageXObjectGroup: 87,
  186. paintImageXObjectRepeat: 88,
  187. paintImageMaskXObjectRepeat: 89,
  188. paintSolidColorImageMask: 90,
  189. constructPath: 91
  190. };
  191. // A notice for devs. These are good for things that are helpful to devs, such
  192. // as warning that Workers were disabled, which is important to devs but not
  193. // end users.
  194. function info(msg) {
  195. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  196. console.log('Info: ' + msg);
  197. }
  198. }
  199. // Non-fatal warnings.
  200. function warn(msg) {
  201. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  202. console.log('Warning: ' + msg);
  203. }
  204. }
  205. // Deprecated API function -- treated as warnings.
  206. function deprecated(details) {
  207. warn('Deprecated API usage: ' + details);
  208. }
  209. // Fatal errors that should trigger the fallback UI and halt execution by
  210. // throwing an exception.
  211. function error(msg) {
  212. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  213. console.log('Error: ' + msg);
  214. console.log(backtrace());
  215. }
  216. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  217. throw new Error(msg);
  218. }
  219. function backtrace() {
  220. try {
  221. throw new Error();
  222. } catch (e) {
  223. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  224. }
  225. }
  226. function assert(cond, msg) {
  227. if (!cond) {
  228. error(msg);
  229. }
  230. }
  231. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  232. unknown: 'unknown',
  233. forms: 'forms',
  234. javaScript: 'javaScript',
  235. smask: 'smask',
  236. shadingPattern: 'shadingPattern',
  237. font: 'font'
  238. };
  239. var UnsupportedManager = PDFJS.UnsupportedManager =
  240. (function UnsupportedManagerClosure() {
  241. var listeners = [];
  242. return {
  243. listen: function (cb) {
  244. listeners.push(cb);
  245. },
  246. notify: function (featureId) {
  247. warn('Unsupported feature "' + featureId + '"');
  248. for (var i = 0, ii = listeners.length; i < ii; i++) {
  249. listeners[i](featureId);
  250. }
  251. }
  252. };
  253. })();
  254. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  255. // absolute URL, it will be returned as is.
  256. function combineUrl(baseUrl, url) {
  257. if (!url) {
  258. return baseUrl;
  259. }
  260. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  261. return url;
  262. }
  263. var i;
  264. if (url.charAt(0) === '/') {
  265. // absolute path
  266. i = baseUrl.indexOf('://');
  267. if (url.charAt(1) === '/') {
  268. ++i;
  269. } else {
  270. i = baseUrl.indexOf('/', i + 3);
  271. }
  272. return baseUrl.substring(0, i) + url;
  273. } else {
  274. // relative path
  275. var pathLength = baseUrl.length;
  276. i = baseUrl.lastIndexOf('#');
  277. pathLength = i >= 0 ? i : pathLength;
  278. i = baseUrl.lastIndexOf('?', pathLength);
  279. pathLength = i >= 0 ? i : pathLength;
  280. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  281. return baseUrl.substring(0, prefixLength + 1) + url;
  282. }
  283. }
  284. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  285. function isValidUrl(url, allowRelative) {
  286. if (!url) {
  287. return false;
  288. }
  289. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  290. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  291. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  292. if (!protocol) {
  293. return allowRelative;
  294. }
  295. protocol = protocol[0].toLowerCase();
  296. switch (protocol) {
  297. case 'http':
  298. case 'https':
  299. case 'ftp':
  300. case 'mailto':
  301. case 'tel':
  302. return true;
  303. default:
  304. return false;
  305. }
  306. }
  307. PDFJS.isValidUrl = isValidUrl;
  308. function shadow(obj, prop, value) {
  309. Object.defineProperty(obj, prop, { value: value,
  310. enumerable: true,
  311. configurable: true,
  312. writable: false });
  313. return value;
  314. }
  315. PDFJS.shadow = shadow;
  316. var LinkTarget = PDFJS.LinkTarget = {
  317. NONE: 0, // Default value.
  318. SELF: 1,
  319. BLANK: 2,
  320. PARENT: 3,
  321. TOP: 4,
  322. };
  323. var LinkTargetStringMap = [
  324. '',
  325. '_self',
  326. '_blank',
  327. '_parent',
  328. '_top'
  329. ];
  330. function isExternalLinkTargetSet() {
  331. if (PDFJS.openExternalLinksInNewWindow) {
  332. warn('PDFJS.openExternalLinksInNewWindow is deprecated, ' +
  333. 'use PDFJS.externalLinkTarget instead.');
  334. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  335. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  336. }
  337. // Reset the deprecated parameter, to suppress further warnings.
  338. PDFJS.openExternalLinksInNewWindow = false;
  339. }
  340. switch (PDFJS.externalLinkTarget) {
  341. case LinkTarget.NONE:
  342. return false;
  343. case LinkTarget.SELF:
  344. case LinkTarget.BLANK:
  345. case LinkTarget.PARENT:
  346. case LinkTarget.TOP:
  347. return true;
  348. }
  349. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  350. // Reset the external link target, to suppress further warnings.
  351. PDFJS.externalLinkTarget = LinkTarget.NONE;
  352. return false;
  353. }
  354. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  355. var PasswordResponses = PDFJS.PasswordResponses = {
  356. NEED_PASSWORD: 1,
  357. INCORRECT_PASSWORD: 2
  358. };
  359. var PasswordException = (function PasswordExceptionClosure() {
  360. function PasswordException(msg, code) {
  361. this.name = 'PasswordException';
  362. this.message = msg;
  363. this.code = code;
  364. }
  365. PasswordException.prototype = new Error();
  366. PasswordException.constructor = PasswordException;
  367. return PasswordException;
  368. })();
  369. PDFJS.PasswordException = PasswordException;
  370. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  371. function UnknownErrorException(msg, details) {
  372. this.name = 'UnknownErrorException';
  373. this.message = msg;
  374. this.details = details;
  375. }
  376. UnknownErrorException.prototype = new Error();
  377. UnknownErrorException.constructor = UnknownErrorException;
  378. return UnknownErrorException;
  379. })();
  380. PDFJS.UnknownErrorException = UnknownErrorException;
  381. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  382. function InvalidPDFException(msg) {
  383. this.name = 'InvalidPDFException';
  384. this.message = msg;
  385. }
  386. InvalidPDFException.prototype = new Error();
  387. InvalidPDFException.constructor = InvalidPDFException;
  388. return InvalidPDFException;
  389. })();
  390. PDFJS.InvalidPDFException = InvalidPDFException;
  391. var MissingPDFException = (function MissingPDFExceptionClosure() {
  392. function MissingPDFException(msg) {
  393. this.name = 'MissingPDFException';
  394. this.message = msg;
  395. }
  396. MissingPDFException.prototype = new Error();
  397. MissingPDFException.constructor = MissingPDFException;
  398. return MissingPDFException;
  399. })();
  400. PDFJS.MissingPDFException = MissingPDFException;
  401. var UnexpectedResponseException =
  402. (function UnexpectedResponseExceptionClosure() {
  403. function UnexpectedResponseException(msg, status) {
  404. this.name = 'UnexpectedResponseException';
  405. this.message = msg;
  406. this.status = status;
  407. }
  408. UnexpectedResponseException.prototype = new Error();
  409. UnexpectedResponseException.constructor = UnexpectedResponseException;
  410. return UnexpectedResponseException;
  411. })();
  412. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  413. var NotImplementedException = (function NotImplementedExceptionClosure() {
  414. function NotImplementedException(msg) {
  415. this.message = msg;
  416. }
  417. NotImplementedException.prototype = new Error();
  418. NotImplementedException.prototype.name = 'NotImplementedException';
  419. NotImplementedException.constructor = NotImplementedException;
  420. return NotImplementedException;
  421. })();
  422. var MissingDataException = (function MissingDataExceptionClosure() {
  423. function MissingDataException(begin, end) {
  424. this.begin = begin;
  425. this.end = end;
  426. this.message = 'Missing data [' + begin + ', ' + end + ')';
  427. }
  428. MissingDataException.prototype = new Error();
  429. MissingDataException.prototype.name = 'MissingDataException';
  430. MissingDataException.constructor = MissingDataException;
  431. return MissingDataException;
  432. })();
  433. var XRefParseException = (function XRefParseExceptionClosure() {
  434. function XRefParseException(msg) {
  435. this.message = msg;
  436. }
  437. XRefParseException.prototype = new Error();
  438. XRefParseException.prototype.name = 'XRefParseException';
  439. XRefParseException.constructor = XRefParseException;
  440. return XRefParseException;
  441. })();
  442. function bytesToString(bytes) {
  443. assert(bytes !== null && typeof bytes === 'object' &&
  444. bytes.length !== undefined, 'Invalid argument for bytesToString');
  445. var length = bytes.length;
  446. var MAX_ARGUMENT_COUNT = 8192;
  447. if (length < MAX_ARGUMENT_COUNT) {
  448. return String.fromCharCode.apply(null, bytes);
  449. }
  450. var strBuf = [];
  451. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  452. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  453. var chunk = bytes.subarray(i, chunkEnd);
  454. strBuf.push(String.fromCharCode.apply(null, chunk));
  455. }
  456. return strBuf.join('');
  457. }
  458. function stringToBytes(str) {
  459. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  460. var length = str.length;
  461. var bytes = new Uint8Array(length);
  462. for (var i = 0; i < length; ++i) {
  463. bytes[i] = str.charCodeAt(i) & 0xFF;
  464. }
  465. return bytes;
  466. }
  467. function string32(value) {
  468. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  469. (value >> 8) & 0xff, value & 0xff);
  470. }
  471. function log2(x) {
  472. var n = 1, i = 0;
  473. while (x > n) {
  474. n <<= 1;
  475. i++;
  476. }
  477. return i;
  478. }
  479. function readInt8(data, start) {
  480. return (data[start] << 24) >> 24;
  481. }
  482. function readUint16(data, offset) {
  483. return (data[offset] << 8) | data[offset + 1];
  484. }
  485. function readUint32(data, offset) {
  486. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  487. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  488. }
  489. // Lazy test the endianness of the platform
  490. // NOTE: This will be 'true' for simulated TypedArrays
  491. function isLittleEndian() {
  492. var buffer8 = new Uint8Array(2);
  493. buffer8[0] = 1;
  494. var buffer16 = new Uint16Array(buffer8.buffer);
  495. return (buffer16[0] === 1);
  496. }
  497. Object.defineProperty(PDFJS, 'isLittleEndian', {
  498. configurable: true,
  499. get: function PDFJS_isLittleEndian() {
  500. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  501. }
  502. });
  503. // Lazy test if the userAgent support CanvasTypedArrays
  504. function hasCanvasTypedArrays() {
  505. var canvas = document.createElement('canvas');
  506. canvas.width = canvas.height = 1;
  507. var ctx = canvas.getContext('2d');
  508. var imageData = ctx.createImageData(1, 1);
  509. return (typeof imageData.data.buffer !== 'undefined');
  510. }
  511. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  512. configurable: true,
  513. get: function PDFJS_hasCanvasTypedArrays() {
  514. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  515. }
  516. });
  517. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  518. function Uint32ArrayView(buffer, length) {
  519. this.buffer = buffer;
  520. this.byteLength = buffer.length;
  521. this.length = length === undefined ? (this.byteLength >> 2) : length;
  522. ensureUint32ArrayViewProps(this.length);
  523. }
  524. Uint32ArrayView.prototype = Object.create(null);
  525. var uint32ArrayViewSetters = 0;
  526. function createUint32ArrayProp(index) {
  527. return {
  528. get: function () {
  529. var buffer = this.buffer, offset = index << 2;
  530. return (buffer[offset] | (buffer[offset + 1] << 8) |
  531. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  532. },
  533. set: function (value) {
  534. var buffer = this.buffer, offset = index << 2;
  535. buffer[offset] = value & 255;
  536. buffer[offset + 1] = (value >> 8) & 255;
  537. buffer[offset + 2] = (value >> 16) & 255;
  538. buffer[offset + 3] = (value >>> 24) & 255;
  539. }
  540. };
  541. }
  542. function ensureUint32ArrayViewProps(length) {
  543. while (uint32ArrayViewSetters < length) {
  544. Object.defineProperty(Uint32ArrayView.prototype,
  545. uint32ArrayViewSetters,
  546. createUint32ArrayProp(uint32ArrayViewSetters));
  547. uint32ArrayViewSetters++;
  548. }
  549. }
  550. return Uint32ArrayView;
  551. })();
  552. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  553. var Util = PDFJS.Util = (function UtilClosure() {
  554. function Util() {}
  555. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  556. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  557. // creating many intermediate strings.
  558. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  559. rgbBuf[1] = r;
  560. rgbBuf[3] = g;
  561. rgbBuf[5] = b;
  562. return rgbBuf.join('');
  563. };
  564. // Concatenates two transformation matrices together and returns the result.
  565. Util.transform = function Util_transform(m1, m2) {
  566. return [
  567. m1[0] * m2[0] + m1[2] * m2[1],
  568. m1[1] * m2[0] + m1[3] * m2[1],
  569. m1[0] * m2[2] + m1[2] * m2[3],
  570. m1[1] * m2[2] + m1[3] * m2[3],
  571. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  572. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  573. ];
  574. };
  575. // For 2d affine transforms
  576. Util.applyTransform = function Util_applyTransform(p, m) {
  577. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  578. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  579. return [xt, yt];
  580. };
  581. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  582. var d = m[0] * m[3] - m[1] * m[2];
  583. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  584. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  585. return [xt, yt];
  586. };
  587. // Applies the transform to the rectangle and finds the minimum axially
  588. // aligned bounding box.
  589. Util.getAxialAlignedBoundingBox =
  590. function Util_getAxialAlignedBoundingBox(r, m) {
  591. var p1 = Util.applyTransform(r, m);
  592. var p2 = Util.applyTransform(r.slice(2, 4), m);
  593. var p3 = Util.applyTransform([r[0], r[3]], m);
  594. var p4 = Util.applyTransform([r[2], r[1]], m);
  595. return [
  596. Math.min(p1[0], p2[0], p3[0], p4[0]),
  597. Math.min(p1[1], p2[1], p3[1], p4[1]),
  598. Math.max(p1[0], p2[0], p3[0], p4[0]),
  599. Math.max(p1[1], p2[1], p3[1], p4[1])
  600. ];
  601. };
  602. Util.inverseTransform = function Util_inverseTransform(m) {
  603. var d = m[0] * m[3] - m[1] * m[2];
  604. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  605. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  606. };
  607. // Apply a generic 3d matrix M on a 3-vector v:
  608. // | a b c | | X |
  609. // | d e f | x | Y |
  610. // | g h i | | Z |
  611. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  612. // with v as [X,Y,Z]
  613. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  614. return [
  615. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  616. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  617. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  618. ];
  619. };
  620. // This calculation uses Singular Value Decomposition.
  621. // The SVD can be represented with formula A = USV. We are interested in the
  622. // matrix S here because it represents the scale values.
  623. Util.singularValueDecompose2dScale =
  624. function Util_singularValueDecompose2dScale(m) {
  625. var transpose = [m[0], m[2], m[1], m[3]];
  626. // Multiply matrix m with its transpose.
  627. var a = m[0] * transpose[0] + m[1] * transpose[2];
  628. var b = m[0] * transpose[1] + m[1] * transpose[3];
  629. var c = m[2] * transpose[0] + m[3] * transpose[2];
  630. var d = m[2] * transpose[1] + m[3] * transpose[3];
  631. // Solve the second degree polynomial to get roots.
  632. var first = (a + d) / 2;
  633. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  634. var sx = first + second || 1;
  635. var sy = first - second || 1;
  636. // Scale values are the square roots of the eigenvalues.
  637. return [Math.sqrt(sx), Math.sqrt(sy)];
  638. };
  639. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  640. // For coordinate systems whose origin lies in the bottom-left, this
  641. // means normalization to (BL,TR) ordering. For systems with origin in the
  642. // top-left, this means (TL,BR) ordering.
  643. Util.normalizeRect = function Util_normalizeRect(rect) {
  644. var r = rect.slice(0); // clone rect
  645. if (rect[0] > rect[2]) {
  646. r[0] = rect[2];
  647. r[2] = rect[0];
  648. }
  649. if (rect[1] > rect[3]) {
  650. r[1] = rect[3];
  651. r[3] = rect[1];
  652. }
  653. return r;
  654. };
  655. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  656. // intersection of rect1 and rect2. If no intersection, returns 'false'
  657. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  658. Util.intersect = function Util_intersect(rect1, rect2) {
  659. function compare(a, b) {
  660. return a - b;
  661. }
  662. // Order points along the axes
  663. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  664. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  665. result = [];
  666. rect1 = Util.normalizeRect(rect1);
  667. rect2 = Util.normalizeRect(rect2);
  668. // X: first and second points belong to different rectangles?
  669. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  670. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  671. // Intersection must be between second and third points
  672. result[0] = orderedX[1];
  673. result[2] = orderedX[2];
  674. } else {
  675. return false;
  676. }
  677. // Y: first and second points belong to different rectangles?
  678. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  679. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  680. // Intersection must be between second and third points
  681. result[1] = orderedY[1];
  682. result[3] = orderedY[2];
  683. } else {
  684. return false;
  685. }
  686. return result;
  687. };
  688. Util.sign = function Util_sign(num) {
  689. return num < 0 ? -1 : 1;
  690. };
  691. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  692. Array.prototype.push.apply(arr1, arr2);
  693. };
  694. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  695. Array.prototype.unshift.apply(arr1, arr2);
  696. };
  697. Util.extendObj = function extendObj(obj1, obj2) {
  698. for (var key in obj2) {
  699. obj1[key] = obj2[key];
  700. }
  701. };
  702. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  703. name) {
  704. while (dict && !dict.has(name)) {
  705. dict = dict.get('Parent');
  706. }
  707. if (!dict) {
  708. return null;
  709. }
  710. return dict.get(name);
  711. };
  712. Util.inherit = function Util_inherit(sub, base, prototype) {
  713. sub.prototype = Object.create(base.prototype);
  714. sub.prototype.constructor = sub;
  715. for (var prop in prototype) {
  716. sub.prototype[prop] = prototype[prop];
  717. }
  718. };
  719. Util.loadScript = function Util_loadScript(src, callback) {
  720. var script = document.createElement('script');
  721. var loaded = false;
  722. script.setAttribute('src', src);
  723. if (callback) {
  724. script.onload = function() {
  725. if (!loaded) {
  726. callback();
  727. }
  728. loaded = true;
  729. };
  730. }
  731. document.getElementsByTagName('head')[0].appendChild(script);
  732. };
  733. return Util;
  734. })();
  735. /**
  736. * PDF page viewport created based on scale, rotation and offset.
  737. * @class
  738. * @alias PDFJS.PageViewport
  739. */
  740. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  741. /**
  742. * @constructor
  743. * @private
  744. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  745. * @param scale {number} scale of the viewport.
  746. * @param rotation {number} rotations of the viewport in degrees.
  747. * @param offsetX {number} offset X
  748. * @param offsetY {number} offset Y
  749. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  750. */
  751. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  752. this.viewBox = viewBox;
  753. this.scale = scale;
  754. this.rotation = rotation;
  755. this.offsetX = offsetX;
  756. this.offsetY = offsetY;
  757. // creating transform to convert pdf coordinate system to the normal
  758. // canvas like coordinates taking in account scale and rotation
  759. var centerX = (viewBox[2] + viewBox[0]) / 2;
  760. var centerY = (viewBox[3] + viewBox[1]) / 2;
  761. var rotateA, rotateB, rotateC, rotateD;
  762. rotation = rotation % 360;
  763. rotation = rotation < 0 ? rotation + 360 : rotation;
  764. switch (rotation) {
  765. case 180:
  766. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  767. break;
  768. case 90:
  769. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  770. break;
  771. case 270:
  772. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  773. break;
  774. //case 0:
  775. default:
  776. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  777. break;
  778. }
  779. if (dontFlip) {
  780. rotateC = -rotateC; rotateD = -rotateD;
  781. }
  782. var offsetCanvasX, offsetCanvasY;
  783. var width, height;
  784. if (rotateA === 0) {
  785. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  786. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  787. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  788. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  789. } else {
  790. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  791. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  792. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  793. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  794. }
  795. // creating transform for the following operations:
  796. // translate(-centerX, -centerY), rotate and flip vertically,
  797. // scale, and translate(offsetCanvasX, offsetCanvasY)
  798. this.transform = [
  799. rotateA * scale,
  800. rotateB * scale,
  801. rotateC * scale,
  802. rotateD * scale,
  803. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  804. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  805. ];
  806. this.width = width;
  807. this.height = height;
  808. this.fontScale = scale;
  809. }
  810. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  811. /**
  812. * Clones viewport with additional properties.
  813. * @param args {Object} (optional) If specified, may contain the 'scale' or
  814. * 'rotation' properties to override the corresponding properties in
  815. * the cloned viewport.
  816. * @returns {PDFJS.PageViewport} Cloned viewport.
  817. */
  818. clone: function PageViewPort_clone(args) {
  819. args = args || {};
  820. var scale = 'scale' in args ? args.scale : this.scale;
  821. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  822. return new PageViewport(this.viewBox.slice(), scale, rotation,
  823. this.offsetX, this.offsetY, args.dontFlip);
  824. },
  825. /**
  826. * Converts PDF point to the viewport coordinates. For examples, useful for
  827. * converting PDF location into canvas pixel coordinates.
  828. * @param x {number} X coordinate.
  829. * @param y {number} Y coordinate.
  830. * @returns {Object} Object that contains 'x' and 'y' properties of the
  831. * point in the viewport coordinate space.
  832. * @see {@link convertToPdfPoint}
  833. * @see {@link convertToViewportRectangle}
  834. */
  835. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  836. return Util.applyTransform([x, y], this.transform);
  837. },
  838. /**
  839. * Converts PDF rectangle to the viewport coordinates.
  840. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  841. * @returns {Array} Contains corresponding coordinates of the rectangle
  842. * in the viewport coordinate space.
  843. * @see {@link convertToViewportPoint}
  844. */
  845. convertToViewportRectangle:
  846. function PageViewport_convertToViewportRectangle(rect) {
  847. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  848. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  849. return [tl[0], tl[1], br[0], br[1]];
  850. },
  851. /**
  852. * Converts viewport coordinates to the PDF location. For examples, useful
  853. * for converting canvas pixel location into PDF one.
  854. * @param x {number} X coordinate.
  855. * @param y {number} Y coordinate.
  856. * @returns {Object} Object that contains 'x' and 'y' properties of the
  857. * point in the PDF coordinate space.
  858. * @see {@link convertToViewportPoint}
  859. */
  860. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  861. return Util.applyInverseTransform([x, y], this.transform);
  862. }
  863. };
  864. return PageViewport;
  865. })();
  866. var PDFStringTranslateTable = [
  867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  868. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  869. 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,
  870. 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,
  871. 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,
  872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  873. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  874. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  875. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  876. ];
  877. function stringToPDFString(str) {
  878. var i, n = str.length, strBuf = [];
  879. if (str[0] === '\xFE' && str[1] === '\xFF') {
  880. // UTF16BE BOM
  881. for (i = 2; i < n; i += 2) {
  882. strBuf.push(String.fromCharCode(
  883. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  884. }
  885. } else {
  886. for (i = 0; i < n; ++i) {
  887. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  888. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  889. }
  890. }
  891. return strBuf.join('');
  892. }
  893. function stringToUTF8String(str) {
  894. return decodeURIComponent(escape(str));
  895. }
  896. function utf8StringToString(str) {
  897. return unescape(encodeURIComponent(str));
  898. }
  899. function isEmptyObj(obj) {
  900. for (var key in obj) {
  901. return false;
  902. }
  903. return true;
  904. }
  905. function isBool(v) {
  906. return typeof v === 'boolean';
  907. }
  908. function isInt(v) {
  909. return typeof v === 'number' && ((v | 0) === v);
  910. }
  911. function isNum(v) {
  912. return typeof v === 'number';
  913. }
  914. function isString(v) {
  915. return typeof v === 'string';
  916. }
  917. function isName(v) {
  918. return v instanceof Name;
  919. }
  920. function isCmd(v, cmd) {
  921. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  922. }
  923. function isDict(v, type) {
  924. if (!(v instanceof Dict)) {
  925. return false;
  926. }
  927. if (!type) {
  928. return true;
  929. }
  930. var dictType = v.get('Type');
  931. return isName(dictType) && dictType.name === type;
  932. }
  933. function isArray(v) {
  934. return v instanceof Array;
  935. }
  936. function isStream(v) {
  937. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  938. }
  939. function isArrayBuffer(v) {
  940. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  941. }
  942. function isRef(v) {
  943. return v instanceof Ref;
  944. }
  945. /**
  946. * Promise Capability object.
  947. *
  948. * @typedef {Object} PromiseCapability
  949. * @property {Promise} promise - A promise object.
  950. * @property {function} resolve - Fullfills the promise.
  951. * @property {function} reject - Rejects the promise.
  952. */
  953. /**
  954. * Creates a promise capability object.
  955. * @alias PDFJS.createPromiseCapability
  956. *
  957. * @return {PromiseCapability} A capability object contains:
  958. * - a Promise, resolve and reject methods.
  959. */
  960. function createPromiseCapability() {
  961. var capability = {};
  962. capability.promise = new Promise(function (resolve, reject) {
  963. capability.resolve = resolve;
  964. capability.reject = reject;
  965. });
  966. return capability;
  967. }
  968. PDFJS.createPromiseCapability = createPromiseCapability;
  969. /**
  970. * Polyfill for Promises:
  971. * The following promise implementation tries to generally implement the
  972. * Promise/A+ spec. Some notable differences from other promise libaries are:
  973. * - There currently isn't a seperate deferred and promise object.
  974. * - Unhandled rejections eventually show an error if they aren't handled.
  975. *
  976. * Based off of the work in:
  977. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  978. */
  979. (function PromiseClosure() {
  980. if (globalScope.Promise) {
  981. // Promises existing in the DOM/Worker, checking presence of all/resolve
  982. if (typeof globalScope.Promise.all !== 'function') {
  983. globalScope.Promise.all = function (iterable) {
  984. var count = 0, results = [], resolve, reject;
  985. var promise = new globalScope.Promise(function (resolve_, reject_) {
  986. resolve = resolve_;
  987. reject = reject_;
  988. });
  989. iterable.forEach(function (p, i) {
  990. count++;
  991. p.then(function (result) {
  992. results[i] = result;
  993. count--;
  994. if (count === 0) {
  995. resolve(results);
  996. }
  997. }, reject);
  998. });
  999. if (count === 0) {
  1000. resolve(results);
  1001. }
  1002. return promise;
  1003. };
  1004. }
  1005. if (typeof globalScope.Promise.resolve !== 'function') {
  1006. globalScope.Promise.resolve = function (value) {
  1007. return new globalScope.Promise(function (resolve) { resolve(value); });
  1008. };
  1009. }
  1010. if (typeof globalScope.Promise.reject !== 'function') {
  1011. globalScope.Promise.reject = function (reason) {
  1012. return new globalScope.Promise(function (resolve, reject) {
  1013. reject(reason);
  1014. });
  1015. };
  1016. }
  1017. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1018. globalScope.Promise.prototype.catch = function (onReject) {
  1019. return globalScope.Promise.prototype.then(undefined, onReject);
  1020. };
  1021. }
  1022. return;
  1023. }
  1024. var STATUS_PENDING = 0;
  1025. var STATUS_RESOLVED = 1;
  1026. var STATUS_REJECTED = 2;
  1027. // In an attempt to avoid silent exceptions, unhandled rejections are
  1028. // tracked and if they aren't handled in a certain amount of time an
  1029. // error is logged.
  1030. var REJECTION_TIMEOUT = 500;
  1031. var HandlerManager = {
  1032. handlers: [],
  1033. running: false,
  1034. unhandledRejections: [],
  1035. pendingRejectionCheck: false,
  1036. scheduleHandlers: function scheduleHandlers(promise) {
  1037. if (promise._status === STATUS_PENDING) {
  1038. return;
  1039. }
  1040. this.handlers = this.handlers.concat(promise._handlers);
  1041. promise._handlers = [];
  1042. if (this.running) {
  1043. return;
  1044. }
  1045. this.running = true;
  1046. setTimeout(this.runHandlers.bind(this), 0);
  1047. },
  1048. runHandlers: function runHandlers() {
  1049. var RUN_TIMEOUT = 1; // ms
  1050. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1051. while (this.handlers.length > 0) {
  1052. var handler = this.handlers.shift();
  1053. var nextStatus = handler.thisPromise._status;
  1054. var nextValue = handler.thisPromise._value;
  1055. try {
  1056. if (nextStatus === STATUS_RESOLVED) {
  1057. if (typeof handler.onResolve === 'function') {
  1058. nextValue = handler.onResolve(nextValue);
  1059. }
  1060. } else if (typeof handler.onReject === 'function') {
  1061. nextValue = handler.onReject(nextValue);
  1062. nextStatus = STATUS_RESOLVED;
  1063. if (handler.thisPromise._unhandledRejection) {
  1064. this.removeUnhandeledRejection(handler.thisPromise);
  1065. }
  1066. }
  1067. } catch (ex) {
  1068. nextStatus = STATUS_REJECTED;
  1069. nextValue = ex;
  1070. }
  1071. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1072. if (Date.now() >= timeoutAt) {
  1073. break;
  1074. }
  1075. }
  1076. if (this.handlers.length > 0) {
  1077. setTimeout(this.runHandlers.bind(this), 0);
  1078. return;
  1079. }
  1080. this.running = false;
  1081. },
  1082. addUnhandledRejection: function addUnhandledRejection(promise) {
  1083. this.unhandledRejections.push({
  1084. promise: promise,
  1085. time: Date.now()
  1086. });
  1087. this.scheduleRejectionCheck();
  1088. },
  1089. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1090. promise._unhandledRejection = false;
  1091. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1092. if (this.unhandledRejections[i].promise === promise) {
  1093. this.unhandledRejections.splice(i);
  1094. i--;
  1095. }
  1096. }
  1097. },
  1098. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1099. if (this.pendingRejectionCheck) {
  1100. return;
  1101. }
  1102. this.pendingRejectionCheck = true;
  1103. setTimeout(function rejectionCheck() {
  1104. this.pendingRejectionCheck = false;
  1105. var now = Date.now();
  1106. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1107. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1108. var unhandled = this.unhandledRejections[i].promise._value;
  1109. var msg = 'Unhandled rejection: ' + unhandled;
  1110. if (unhandled.stack) {
  1111. msg += '\n' + unhandled.stack;
  1112. }
  1113. warn(msg);
  1114. this.unhandledRejections.splice(i);
  1115. i--;
  1116. }
  1117. }
  1118. if (this.unhandledRejections.length) {
  1119. this.scheduleRejectionCheck();
  1120. }
  1121. }.bind(this), REJECTION_TIMEOUT);
  1122. }
  1123. };
  1124. function Promise(resolver) {
  1125. this._status = STATUS_PENDING;
  1126. this._handlers = [];
  1127. try {
  1128. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1129. } catch (e) {
  1130. this._reject(e);
  1131. }
  1132. }
  1133. /**
  1134. * Builds a promise that is resolved when all the passed in promises are
  1135. * resolved.
  1136. * @param {array} array of data and/or promises to wait for.
  1137. * @return {Promise} New dependant promise.
  1138. */
  1139. Promise.all = function Promise_all(promises) {
  1140. var resolveAll, rejectAll;
  1141. var deferred = new Promise(function (resolve, reject) {
  1142. resolveAll = resolve;
  1143. rejectAll = reject;
  1144. });
  1145. var unresolved = promises.length;
  1146. var results = [];
  1147. if (unresolved === 0) {
  1148. resolveAll(results);
  1149. return deferred;
  1150. }
  1151. function reject(reason) {
  1152. if (deferred._status === STATUS_REJECTED) {
  1153. return;
  1154. }
  1155. results = [];
  1156. rejectAll(reason);
  1157. }
  1158. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1159. var promise = promises[i];
  1160. var resolve = (function(i) {
  1161. return function(value) {
  1162. if (deferred._status === STATUS_REJECTED) {
  1163. return;
  1164. }
  1165. results[i] = value;
  1166. unresolved--;
  1167. if (unresolved === 0) {
  1168. resolveAll(results);
  1169. }
  1170. };
  1171. })(i);
  1172. if (Promise.isPromise(promise)) {
  1173. promise.then(resolve, reject);
  1174. } else {
  1175. resolve(promise);
  1176. }
  1177. }
  1178. return deferred;
  1179. };
  1180. /**
  1181. * Checks if the value is likely a promise (has a 'then' function).
  1182. * @return {boolean} true if value is thenable
  1183. */
  1184. Promise.isPromise = function Promise_isPromise(value) {
  1185. return value && typeof value.then === 'function';
  1186. };
  1187. /**
  1188. * Creates resolved promise
  1189. * @param value resolve value
  1190. * @returns {Promise}
  1191. */
  1192. Promise.resolve = function Promise_resolve(value) {
  1193. return new Promise(function (resolve) { resolve(value); });
  1194. };
  1195. /**
  1196. * Creates rejected promise
  1197. * @param reason rejection value
  1198. * @returns {Promise}
  1199. */
  1200. Promise.reject = function Promise_reject(reason) {
  1201. return new Promise(function (resolve, reject) { reject(reason); });
  1202. };
  1203. Promise.prototype = {
  1204. _status: null,
  1205. _value: null,
  1206. _handlers: null,
  1207. _unhandledRejection: null,
  1208. _updateStatus: function Promise__updateStatus(status, value) {
  1209. if (this._status === STATUS_RESOLVED ||
  1210. this._status === STATUS_REJECTED) {
  1211. return;
  1212. }
  1213. if (status === STATUS_RESOLVED &&
  1214. Promise.isPromise(value)) {
  1215. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1216. this._updateStatus.bind(this, STATUS_REJECTED));
  1217. return;
  1218. }
  1219. this._status = status;
  1220. this._value = value;
  1221. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1222. this._unhandledRejection = true;
  1223. HandlerManager.addUnhandledRejection(this);
  1224. }
  1225. HandlerManager.scheduleHandlers(this);
  1226. },
  1227. _resolve: function Promise_resolve(value) {
  1228. this._updateStatus(STATUS_RESOLVED, value);
  1229. },
  1230. _reject: function Promise_reject(reason) {
  1231. this._updateStatus(STATUS_REJECTED, reason);
  1232. },
  1233. then: function Promise_then(onResolve, onReject) {
  1234. var nextPromise = new Promise(function (resolve, reject) {
  1235. this.resolve = resolve;
  1236. this.reject = reject;
  1237. });
  1238. this._handlers.push({
  1239. thisPromise: this,
  1240. onResolve: onResolve,
  1241. onReject: onReject,
  1242. nextPromise: nextPromise
  1243. });
  1244. HandlerManager.scheduleHandlers(this);
  1245. return nextPromise;
  1246. },
  1247. catch: function Promise_catch(onReject) {
  1248. return this.then(undefined, onReject);
  1249. }
  1250. };
  1251. globalScope.Promise = Promise;
  1252. })();
  1253. var StatTimer = (function StatTimerClosure() {
  1254. function rpad(str, pad, length) {
  1255. while (str.length < length) {
  1256. str += pad;
  1257. }
  1258. return str;
  1259. }
  1260. function StatTimer() {
  1261. this.started = {};
  1262. this.times = [];
  1263. this.enabled = true;
  1264. }
  1265. StatTimer.prototype = {
  1266. time: function StatTimer_time(name) {
  1267. if (!this.enabled) {
  1268. return;
  1269. }
  1270. if (name in this.started) {
  1271. warn('Timer is already running for ' + name);
  1272. }
  1273. this.started[name] = Date.now();
  1274. },
  1275. timeEnd: function StatTimer_timeEnd(name) {
  1276. if (!this.enabled) {
  1277. return;
  1278. }
  1279. if (!(name in this.started)) {
  1280. warn('Timer has not been started for ' + name);
  1281. }
  1282. this.times.push({
  1283. 'name': name,
  1284. 'start': this.started[name],
  1285. 'end': Date.now()
  1286. });
  1287. // Remove timer from started so it can be called again.
  1288. delete this.started[name];
  1289. },
  1290. toString: function StatTimer_toString() {
  1291. var i, ii;
  1292. var times = this.times;
  1293. var out = '';
  1294. // Find the longest name for padding purposes.
  1295. var longest = 0;
  1296. for (i = 0, ii = times.length; i < ii; ++i) {
  1297. var name = times[i]['name'];
  1298. if (name.length > longest) {
  1299. longest = name.length;
  1300. }
  1301. }
  1302. for (i = 0, ii = times.length; i < ii; ++i) {
  1303. var span = times[i];
  1304. var duration = span.end - span.start;
  1305. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1306. }
  1307. return out;
  1308. }
  1309. };
  1310. return StatTimer;
  1311. })();
  1312. PDFJS.createBlob = function createBlob(data, contentType) {
  1313. if (typeof Blob !== 'undefined') {
  1314. return new Blob([data], { type: contentType });
  1315. }
  1316. // Blob builder is deprecated in FF14 and removed in FF18.
  1317. var bb = new MozBlobBuilder();
  1318. bb.append(data);
  1319. return bb.getBlob(contentType);
  1320. };
  1321. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1322. // Blob/createObjectURL is not available, falling back to data schema.
  1323. var digits =
  1324. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1325. return function createObjectURL(data, contentType) {
  1326. if (!PDFJS.disableCreateObjectURL &&
  1327. typeof URL !== 'undefined' && URL.createObjectURL) {
  1328. var blob = PDFJS.createBlob(data, contentType);
  1329. return URL.createObjectURL(blob);
  1330. }
  1331. var buffer = 'data:' + contentType + ';base64,';
  1332. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1333. var b1 = data[i] & 0xFF;
  1334. var b2 = data[i + 1] & 0xFF;
  1335. var b3 = data[i + 2] & 0xFF;
  1336. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1337. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1338. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1339. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1340. }
  1341. return buffer;
  1342. };
  1343. })();
  1344. function MessageHandler(name, comObj) {
  1345. this.name = name;
  1346. this.comObj = comObj;
  1347. this.callbackIndex = 1;
  1348. this.postMessageTransfers = true;
  1349. var callbacksCapabilities = this.callbacksCapabilities = {};
  1350. var ah = this.actionHandler = {};
  1351. ah['console_log'] = [function ahConsoleLog(data) {
  1352. console.log.apply(console, data);
  1353. }];
  1354. ah['console_error'] = [function ahConsoleError(data) {
  1355. console.error.apply(console, data);
  1356. }];
  1357. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1358. UnsupportedManager.notify(data);
  1359. }];
  1360. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1361. var data = event.data;
  1362. if (data.isReply) {
  1363. var callbackId = data.callbackId;
  1364. if (data.callbackId in callbacksCapabilities) {
  1365. var callback = callbacksCapabilities[callbackId];
  1366. delete callbacksCapabilities[callbackId];
  1367. if ('error' in data) {
  1368. callback.reject(data.error);
  1369. } else {
  1370. callback.resolve(data.data);
  1371. }
  1372. } else {
  1373. error('Cannot resolve callback ' + callbackId);
  1374. }
  1375. } else if (data.action in ah) {
  1376. var action = ah[data.action];
  1377. if (data.callbackId) {
  1378. Promise.resolve().then(function () {
  1379. return action[0].call(action[1], data.data);
  1380. }).then(function (result) {
  1381. comObj.postMessage({
  1382. isReply: true,
  1383. callbackId: data.callbackId,
  1384. data: result
  1385. });
  1386. }, function (reason) {
  1387. if (reason instanceof Error) {
  1388. // Serialize error to avoid "DataCloneError"
  1389. reason = reason + '';
  1390. }
  1391. comObj.postMessage({
  1392. isReply: true,
  1393. callbackId: data.callbackId,
  1394. error: reason
  1395. });
  1396. });
  1397. } else {
  1398. action[0].call(action[1], data.data);
  1399. }
  1400. } else {
  1401. error('Unknown action from worker: ' + data.action);
  1402. }
  1403. };
  1404. }
  1405. MessageHandler.prototype = {
  1406. on: function messageHandlerOn(actionName, handler, scope) {
  1407. var ah = this.actionHandler;
  1408. if (ah[actionName]) {
  1409. error('There is already an actionName called "' + actionName + '"');
  1410. }
  1411. ah[actionName] = [handler, scope];
  1412. },
  1413. /**
  1414. * Sends a message to the comObj to invoke the action with the supplied data.
  1415. * @param {String} actionName Action to call.
  1416. * @param {JSON} data JSON data to send.
  1417. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1418. */
  1419. send: function messageHandlerSend(actionName, data, transfers) {
  1420. var message = {
  1421. action: actionName,
  1422. data: data
  1423. };
  1424. this.postMessage(message, transfers);
  1425. },
  1426. /**
  1427. * Sends a message to the comObj to invoke the action with the supplied data.
  1428. * Expects that other side will callback with the response.
  1429. * @param {String} actionName Action to call.
  1430. * @param {JSON} data JSON data to send.
  1431. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1432. * @returns {Promise} Promise to be resolved with response data.
  1433. */
  1434. sendWithPromise:
  1435. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1436. var callbackId = this.callbackIndex++;
  1437. var message = {
  1438. action: actionName,
  1439. data: data,
  1440. callbackId: callbackId
  1441. };
  1442. var capability = createPromiseCapability();
  1443. this.callbacksCapabilities[callbackId] = capability;
  1444. try {
  1445. this.postMessage(message, transfers);
  1446. } catch (e) {
  1447. capability.reject(e);
  1448. }
  1449. return capability.promise;
  1450. },
  1451. /**
  1452. * Sends raw message to the comObj.
  1453. * @private
  1454. * @param message {Object} Raw message.
  1455. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1456. */
  1457. postMessage: function (message, transfers) {
  1458. if (transfers && this.postMessageTransfers) {
  1459. this.comObj.postMessage(message, transfers);
  1460. } else {
  1461. this.comObj.postMessage(message);
  1462. }
  1463. }
  1464. };
  1465. function loadJpegStream(id, imageUrl, objs) {
  1466. var img = new Image();
  1467. img.onload = (function loadJpegStream_onloadClosure() {
  1468. objs.resolve(id, img);
  1469. });
  1470. img.onerror = (function loadJpegStream_onerrorClosure() {
  1471. objs.resolve(id, null);
  1472. warn('Error during JPEG image loading');
  1473. });
  1474. img.src = imageUrl;
  1475. }
  1476. var NetworkManager = (function NetworkManagerClosure() {
  1477. var OK_RESPONSE = 200;
  1478. var PARTIAL_CONTENT_RESPONSE = 206;
  1479. function NetworkManager(url, args) {
  1480. this.url = url;
  1481. args = args || {};
  1482. this.isHttp = /^https?:/i.test(url);
  1483. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1484. this.withCredentials = args.withCredentials || false;
  1485. this.getXhr = args.getXhr ||
  1486. function NetworkManager_getXhr() {
  1487. return new XMLHttpRequest();
  1488. };
  1489. this.currXhrId = 0;
  1490. this.pendingRequests = {};
  1491. this.loadedRequests = {};
  1492. }
  1493. function getArrayBuffer(xhr) {
  1494. var data = xhr.response;
  1495. if (typeof data !== 'string') {
  1496. return data;
  1497. }
  1498. var length = data.length;
  1499. var array = new Uint8Array(length);
  1500. for (var i = 0; i < length; i++) {
  1501. array[i] = data.charCodeAt(i) & 0xFF;
  1502. }
  1503. return array.buffer;
  1504. }
  1505. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1506. try {
  1507. var x = new XMLHttpRequest();
  1508. // Firefox 37- required .open() to be called before setting responseType.
  1509. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1510. // Even though the URL is not visited, .open() could fail if the URL is
  1511. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1512. // When this error occurs, this feature detection method will mistakenly
  1513. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1514. x.open('GET', 'https://example.com');
  1515. x.responseType = 'moz-chunked-arraybuffer';
  1516. return x.responseType === 'moz-chunked-arraybuffer';
  1517. } catch (e) {
  1518. return false;
  1519. }
  1520. })();
  1521. NetworkManager.prototype = {
  1522. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1523. var args = {
  1524. begin: begin,
  1525. end: end
  1526. };
  1527. for (var prop in listeners) {
  1528. args[prop] = listeners[prop];
  1529. }
  1530. return this.request(args);
  1531. },
  1532. requestFull: function NetworkManager_requestFull(listeners) {
  1533. return this.request(listeners);
  1534. },
  1535. request: function NetworkManager_request(args) {
  1536. var xhr = this.getXhr();
  1537. var xhrId = this.currXhrId++;
  1538. var pendingRequest = this.pendingRequests[xhrId] = {
  1539. xhr: xhr
  1540. };
  1541. xhr.open('GET', this.url);
  1542. xhr.withCredentials = this.withCredentials;
  1543. for (var property in this.httpHeaders) {
  1544. var value = this.httpHeaders[property];
  1545. if (typeof value === 'undefined') {
  1546. continue;
  1547. }
  1548. xhr.setRequestHeader(property, value);
  1549. }
  1550. if (this.isHttp && 'begin' in args && 'end' in args) {
  1551. var rangeStr = args.begin + '-' + (args.end - 1);
  1552. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1553. pendingRequest.expectedStatus = 206;
  1554. } else {
  1555. pendingRequest.expectedStatus = 200;
  1556. }
  1557. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1558. if (useMozChunkedLoading) {
  1559. xhr.responseType = 'moz-chunked-arraybuffer';
  1560. pendingRequest.onProgressiveData = args.onProgressiveData;
  1561. pendingRequest.mozChunked = true;
  1562. } else {
  1563. xhr.responseType = 'arraybuffer';
  1564. }
  1565. if (args.onError) {
  1566. xhr.onerror = function(evt) {
  1567. args.onError(xhr.status);
  1568. };
  1569. }
  1570. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1571. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1572. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1573. pendingRequest.onDone = args.onDone;
  1574. pendingRequest.onError = args.onError;
  1575. pendingRequest.onProgress = args.onProgress;
  1576. xhr.send(null);
  1577. return xhrId;
  1578. },
  1579. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1580. var pendingRequest = this.pendingRequests[xhrId];
  1581. if (!pendingRequest) {
  1582. // Maybe abortRequest was called...
  1583. return;
  1584. }
  1585. if (pendingRequest.mozChunked) {
  1586. var chunk = getArrayBuffer(pendingRequest.xhr);
  1587. pendingRequest.onProgressiveData(chunk);
  1588. }
  1589. var onProgress = pendingRequest.onProgress;
  1590. if (onProgress) {
  1591. onProgress(evt);
  1592. }
  1593. },
  1594. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1595. var pendingRequest = this.pendingRequests[xhrId];
  1596. if (!pendingRequest) {
  1597. // Maybe abortRequest was called...
  1598. return;
  1599. }
  1600. var xhr = pendingRequest.xhr;
  1601. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1602. pendingRequest.onHeadersReceived();
  1603. delete pendingRequest.onHeadersReceived;
  1604. }
  1605. if (xhr.readyState !== 4) {
  1606. return;
  1607. }
  1608. if (!(xhrId in this.pendingRequests)) {
  1609. // The XHR request might have been aborted in onHeadersReceived()
  1610. // callback, in which case we should abort request
  1611. return;
  1612. }
  1613. delete this.pendingRequests[xhrId];
  1614. // success status == 0 can be on ftp, file and other protocols
  1615. if (xhr.status === 0 && this.isHttp) {
  1616. if (pendingRequest.onError) {
  1617. pendingRequest.onError(xhr.status);
  1618. }
  1619. return;
  1620. }
  1621. var xhrStatus = xhr.status || OK_RESPONSE;
  1622. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1623. // "A server MAY ignore the Range header". This means it's possible to
  1624. // get a 200 rather than a 206 response from a range request.
  1625. var ok_response_on_range_request =
  1626. xhrStatus === OK_RESPONSE &&
  1627. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1628. if (!ok_response_on_range_request &&
  1629. xhrStatus !== pendingRequest.expectedStatus) {
  1630. if (pendingRequest.onError) {
  1631. pendingRequest.onError(xhr.status);
  1632. }
  1633. return;
  1634. }
  1635. this.loadedRequests[xhrId] = true;
  1636. var chunk = getArrayBuffer(xhr);
  1637. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1638. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1639. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1640. var begin = parseInt(matches[1], 10);
  1641. pendingRequest.onDone({
  1642. begin: begin,
  1643. chunk: chunk
  1644. });
  1645. } else if (pendingRequest.onProgressiveData) {
  1646. pendingRequest.onDone(null);
  1647. } else if (chunk) {
  1648. pendingRequest.onDone({
  1649. begin: 0,
  1650. chunk: chunk
  1651. });
  1652. } else if (pendingRequest.onError) {
  1653. pendingRequest.onError(xhr.status);
  1654. }
  1655. },
  1656. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1657. for (var xhrId in this.pendingRequests) {
  1658. return true;
  1659. }
  1660. return false;
  1661. },
  1662. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1663. return this.pendingRequests[xhrId].xhr;
  1664. },
  1665. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1666. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1667. },
  1668. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1669. return xhrId in this.pendingRequests;
  1670. },
  1671. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1672. return xhrId in this.loadedRequests;
  1673. },
  1674. abortAllRequests: function NetworkManager_abortAllRequests() {
  1675. for (var xhrId in this.pendingRequests) {
  1676. this.abortRequest(xhrId | 0);
  1677. }
  1678. },
  1679. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1680. var xhr = this.pendingRequests[xhrId].xhr;
  1681. delete this.pendingRequests[xhrId];
  1682. xhr.abort();
  1683. }
  1684. };
  1685. return NetworkManager;
  1686. })();
  1687. var ChunkedStream = (function ChunkedStreamClosure() {
  1688. function ChunkedStream(length, chunkSize, manager) {
  1689. this.bytes = new Uint8Array(length);
  1690. this.start = 0;
  1691. this.pos = 0;
  1692. this.end = length;
  1693. this.chunkSize = chunkSize;
  1694. this.loadedChunks = [];
  1695. this.numChunksLoaded = 0;
  1696. this.numChunks = Math.ceil(length / chunkSize);
  1697. this.manager = manager;
  1698. this.progressiveDataLength = 0;
  1699. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1700. }
  1701. // required methods for a stream. if a particular stream does not
  1702. // implement these, an error should be thrown
  1703. ChunkedStream.prototype = {
  1704. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1705. var chunks = [];
  1706. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1707. if (!this.loadedChunks[chunk]) {
  1708. chunks.push(chunk);
  1709. }
  1710. }
  1711. return chunks;
  1712. },
  1713. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1714. return [this];
  1715. },
  1716. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1717. return this.numChunksLoaded === this.numChunks;
  1718. },
  1719. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1720. var end = begin + chunk.byteLength;
  1721. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1722. // Using this.length is inaccurate here since this.start can be moved
  1723. // See ChunkedStream.moveStart()
  1724. var length = this.bytes.length;
  1725. assert(end % this.chunkSize === 0 || end === length,
  1726. 'Bad end offset: ' + end);
  1727. this.bytes.set(new Uint8Array(chunk), begin);
  1728. var chunkSize = this.chunkSize;
  1729. var beginChunk = Math.floor(begin / chunkSize);
  1730. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1731. var curChunk;
  1732. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1733. if (!this.loadedChunks[curChunk]) {
  1734. this.loadedChunks[curChunk] = true;
  1735. ++this.numChunksLoaded;
  1736. }
  1737. }
  1738. },
  1739. onReceiveProgressiveData:
  1740. function ChunkedStream_onReceiveProgressiveData(data) {
  1741. var position = this.progressiveDataLength;
  1742. var beginChunk = Math.floor(position / this.chunkSize);
  1743. this.bytes.set(new Uint8Array(data), position);
  1744. position += data.byteLength;
  1745. this.progressiveDataLength = position;
  1746. var endChunk = position >= this.end ? this.numChunks :
  1747. Math.floor(position / this.chunkSize);
  1748. var curChunk;
  1749. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1750. if (!this.loadedChunks[curChunk]) {
  1751. this.loadedChunks[curChunk] = true;
  1752. ++this.numChunksLoaded;
  1753. }
  1754. }
  1755. },
  1756. ensureByte: function ChunkedStream_ensureByte(pos) {
  1757. var chunk = Math.floor(pos / this.chunkSize);
  1758. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1759. return;
  1760. }
  1761. if (!this.loadedChunks[chunk]) {
  1762. throw new MissingDataException(pos, pos + 1);
  1763. }
  1764. this.lastSuccessfulEnsureByteChunk = chunk;
  1765. },
  1766. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1767. if (begin >= end) {
  1768. return;
  1769. }
  1770. if (end <= this.progressiveDataLength) {
  1771. return;
  1772. }
  1773. var chunkSize = this.chunkSize;
  1774. var beginChunk = Math.floor(begin / chunkSize);
  1775. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1776. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1777. if (!this.loadedChunks[chunk]) {
  1778. throw new MissingDataException(begin, end);
  1779. }
  1780. }
  1781. },
  1782. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1783. var chunk, numChunks = this.numChunks;
  1784. for (var i = 0; i < numChunks; ++i) {
  1785. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  1786. if (!this.loadedChunks[chunk]) {
  1787. return chunk;
  1788. }
  1789. }
  1790. return null;
  1791. },
  1792. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1793. return !!this.loadedChunks[chunk];
  1794. },
  1795. get length() {
  1796. return this.end - this.start;
  1797. },
  1798. get isEmpty() {
  1799. return this.length === 0;
  1800. },
  1801. getByte: function ChunkedStream_getByte() {
  1802. var pos = this.pos;
  1803. if (pos >= this.end) {
  1804. return -1;
  1805. }
  1806. this.ensureByte(pos);
  1807. return this.bytes[this.pos++];
  1808. },
  1809. getUint16: function ChunkedStream_getUint16() {
  1810. var b0 = this.getByte();
  1811. var b1 = this.getByte();
  1812. if (b0 === -1 || b1 === -1) {
  1813. return -1;
  1814. }
  1815. return (b0 << 8) + b1;
  1816. },
  1817. getInt32: function ChunkedStream_getInt32() {
  1818. var b0 = this.getByte();
  1819. var b1 = this.getByte();
  1820. var b2 = this.getByte();
  1821. var b3 = this.getByte();
  1822. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1823. },
  1824. // returns subarray of original buffer
  1825. // should only be read
  1826. getBytes: function ChunkedStream_getBytes(length) {
  1827. var bytes = this.bytes;
  1828. var pos = this.pos;
  1829. var strEnd = this.end;
  1830. if (!length) {
  1831. this.ensureRange(pos, strEnd);
  1832. return bytes.subarray(pos, strEnd);
  1833. }
  1834. var end = pos + length;
  1835. if (end > strEnd) {
  1836. end = strEnd;
  1837. }
  1838. this.ensureRange(pos, end);
  1839. this.pos = end;
  1840. return bytes.subarray(pos, end);
  1841. },
  1842. peekByte: function ChunkedStream_peekByte() {
  1843. var peekedByte = this.getByte();
  1844. this.pos--;
  1845. return peekedByte;
  1846. },
  1847. peekBytes: function ChunkedStream_peekBytes(length) {
  1848. var bytes = this.getBytes(length);
  1849. this.pos -= bytes.length;
  1850. return bytes;
  1851. },
  1852. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1853. this.ensureRange(begin, end);
  1854. return this.bytes.subarray(begin, end);
  1855. },
  1856. skip: function ChunkedStream_skip(n) {
  1857. if (!n) {
  1858. n = 1;
  1859. }
  1860. this.pos += n;
  1861. },
  1862. reset: function ChunkedStream_reset() {
  1863. this.pos = this.start;
  1864. },
  1865. moveStart: function ChunkedStream_moveStart() {
  1866. this.start = this.pos;
  1867. },
  1868. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1869. this.ensureRange(start, start + length);
  1870. function ChunkedStreamSubstream() {}
  1871. ChunkedStreamSubstream.prototype = Object.create(this);
  1872. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1873. var chunkSize = this.chunkSize;
  1874. var beginChunk = Math.floor(this.start / chunkSize);
  1875. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1876. var missingChunks = [];
  1877. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1878. if (!this.loadedChunks[chunk]) {
  1879. missingChunks.push(chunk);
  1880. }
  1881. }
  1882. return missingChunks;
  1883. };
  1884. var subStream = new ChunkedStreamSubstream();
  1885. subStream.pos = subStream.start = start;
  1886. subStream.end = start + length || this.end;
  1887. subStream.dict = dict;
  1888. return subStream;
  1889. },
  1890. isStream: true
  1891. };
  1892. return ChunkedStream;
  1893. })();
  1894. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1895. function ChunkedStreamManager(length, chunkSize, url, args) {
  1896. this.stream = new ChunkedStream(length, chunkSize, this);
  1897. this.length = length;
  1898. this.chunkSize = chunkSize;
  1899. this.url = url;
  1900. this.disableAutoFetch = args.disableAutoFetch;
  1901. var msgHandler = this.msgHandler = args.msgHandler;
  1902. if (args.chunkedViewerLoading) {
  1903. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1904. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1905. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1906. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1907. };
  1908. } else {
  1909. var getXhr = function getXhr() {
  1910. return new XMLHttpRequest();
  1911. };
  1912. this.networkManager = new NetworkManager(this.url, {
  1913. getXhr: getXhr,
  1914. httpHeaders: args.httpHeaders,
  1915. withCredentials: args.withCredentials
  1916. });
  1917. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1918. this.networkManager.requestRange(begin, end, {
  1919. onDone: this.onReceiveData.bind(this),
  1920. onProgress: this.onProgress.bind(this)
  1921. });
  1922. };
  1923. }
  1924. this.currRequestId = 0;
  1925. this.chunksNeededByRequest = {};
  1926. this.requestsByChunk = {};
  1927. this.promisesByRequest = {};
  1928. this.progressiveDataLength = 0;
  1929. this._loadedStreamCapability = createPromiseCapability();
  1930. if (args.initialData) {
  1931. this.onReceiveData({chunk: args.initialData});
  1932. }
  1933. }
  1934. ChunkedStreamManager.prototype = {
  1935. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1936. return this._loadedStreamCapability.promise;
  1937. },
  1938. // Get all the chunks that are not yet loaded and groups them into
  1939. // contiguous ranges to load in as few requests as possible
  1940. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1941. var missingChunks = this.stream.getMissingChunks();
  1942. this._requestChunks(missingChunks);
  1943. return this._loadedStreamCapability.promise;
  1944. },
  1945. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  1946. var requestId = this.currRequestId++;
  1947. var chunksNeeded;
  1948. var i, ii;
  1949. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1950. for (i = 0, ii = chunks.length; i < ii; i++) {
  1951. if (!this.stream.hasChunk(chunks[i])) {
  1952. chunksNeeded[chunks[i]] = true;
  1953. }
  1954. }
  1955. if (isEmptyObj(chunksNeeded)) {
  1956. return Promise.resolve();
  1957. }
  1958. var capability = createPromiseCapability();
  1959. this.promisesByRequest[requestId] = capability;
  1960. var chunksToRequest = [];
  1961. for (var chunk in chunksNeeded) {
  1962. chunk = chunk | 0;
  1963. if (!(chunk in this.requestsByChunk)) {
  1964. this.requestsByChunk[chunk] = [];
  1965. chunksToRequest.push(chunk);
  1966. }
  1967. this.requestsByChunk[chunk].push(requestId);
  1968. }
  1969. if (!chunksToRequest.length) {
  1970. return capability.promise;
  1971. }
  1972. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1973. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1974. var groupedChunk = groupedChunksToRequest[i];
  1975. var begin = groupedChunk.beginChunk * this.chunkSize;
  1976. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1977. this.sendRequest(begin, end);
  1978. }
  1979. return capability.promise;
  1980. },
  1981. getStream: function ChunkedStreamManager_getStream() {
  1982. return this.stream;
  1983. },
  1984. // Loads any chunks in the requested range that are not yet loaded
  1985. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  1986. end = Math.min(end, this.length);
  1987. var beginChunk = this.getBeginChunk(begin);
  1988. var endChunk = this.getEndChunk(end);
  1989. var chunks = [];
  1990. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1991. chunks.push(chunk);
  1992. }
  1993. return this._requestChunks(chunks);
  1994. },
  1995. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  1996. ranges = ranges || [];
  1997. var chunksToRequest = [];
  1998. for (var i = 0; i < ranges.length; i++) {
  1999. var beginChunk = this.getBeginChunk(ranges[i].begin);
  2000. var endChunk = this.getEndChunk(ranges[i].end);
  2001. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2002. if (chunksToRequest.indexOf(chunk) < 0) {
  2003. chunksToRequest.push(chunk);
  2004. }
  2005. }
  2006. }
  2007. chunksToRequest.sort(function(a, b) { return a - b; });
  2008. return this._requestChunks(chunksToRequest);
  2009. },
  2010. // Groups a sorted array of chunks into as few contiguous larger
  2011. // chunks as possible
  2012. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  2013. var groupedChunks = [];
  2014. var beginChunk = -1;
  2015. var prevChunk = -1;
  2016. for (var i = 0; i < chunks.length; ++i) {
  2017. var chunk = chunks[i];
  2018. if (beginChunk < 0) {
  2019. beginChunk = chunk;
  2020. }
  2021. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  2022. groupedChunks.push({ beginChunk: beginChunk,
  2023. endChunk: prevChunk + 1 });
  2024. beginChunk = chunk;
  2025. }
  2026. if (i + 1 === chunks.length) {
  2027. groupedChunks.push({ beginChunk: beginChunk,
  2028. endChunk: chunk + 1 });
  2029. }
  2030. prevChunk = chunk;
  2031. }
  2032. return groupedChunks;
  2033. },
  2034. onProgress: function ChunkedStreamManager_onProgress(args) {
  2035. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2036. args.loaded);
  2037. this.msgHandler.send('DocProgress', {
  2038. loaded: bytesLoaded,
  2039. total: this.length
  2040. });
  2041. },
  2042. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2043. var chunk = args.chunk;
  2044. var isProgressive = args.begin === undefined;
  2045. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2046. var end = begin + chunk.byteLength;
  2047. var beginChunk = Math.floor(begin / this.chunkSize);
  2048. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2049. Math.ceil(end / this.chunkSize);
  2050. if (isProgressive) {
  2051. this.stream.onReceiveProgressiveData(chunk);
  2052. this.progressiveDataLength = end;
  2053. } else {
  2054. this.stream.onReceiveData(begin, chunk);
  2055. }
  2056. if (this.stream.allChunksLoaded()) {
  2057. this._loadedStreamCapability.resolve(this.stream);
  2058. }
  2059. var loadedRequests = [];
  2060. var i, requestId;
  2061. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2062. // The server might return more chunks than requested
  2063. var requestIds = this.requestsByChunk[chunk] || [];
  2064. delete this.requestsByChunk[chunk];
  2065. for (i = 0; i < requestIds.length; ++i) {
  2066. requestId = requestIds[i];
  2067. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2068. if (chunk in chunksNeeded) {
  2069. delete chunksNeeded[chunk];
  2070. }
  2071. if (!isEmptyObj(chunksNeeded)) {
  2072. continue;
  2073. }
  2074. loadedRequests.push(requestId);
  2075. }
  2076. }
  2077. // If there are no pending requests, automatically fetch the next
  2078. // unfetched chunk of the PDF
  2079. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2080. var nextEmptyChunk;
  2081. if (this.stream.numChunksLoaded === 1) {
  2082. // This is a special optimization so that after fetching the first
  2083. // chunk, rather than fetching the second chunk, we fetch the last
  2084. // chunk.
  2085. var lastChunk = this.stream.numChunks - 1;
  2086. if (!this.stream.hasChunk(lastChunk)) {
  2087. nextEmptyChunk = lastChunk;
  2088. }
  2089. } else {
  2090. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2091. }
  2092. if (isInt(nextEmptyChunk)) {
  2093. this._requestChunks([nextEmptyChunk]);
  2094. }
  2095. }
  2096. for (i = 0; i < loadedRequests.length; ++i) {
  2097. requestId = loadedRequests[i];
  2098. var capability = this.promisesByRequest[requestId];
  2099. delete this.promisesByRequest[requestId];
  2100. capability.resolve();
  2101. }
  2102. this.msgHandler.send('DocProgress', {
  2103. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2104. total: this.length
  2105. });
  2106. },
  2107. onError: function ChunkedStreamManager_onError(err) {
  2108. this._loadedStreamCapability.reject(err);
  2109. },
  2110. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2111. var chunk = Math.floor(begin / this.chunkSize);
  2112. return chunk;
  2113. },
  2114. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2115. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2116. return chunk;
  2117. },
  2118. abort: function ChunkedStreamManager_abort() {
  2119. if (this.networkManager) {
  2120. this.networkManager.abortAllRequests();
  2121. }
  2122. for(var requestId in this.promisesByRequest) {
  2123. var capability = this.promisesByRequest[requestId];
  2124. capability.reject(new Error('Request was aborted'));
  2125. }
  2126. }
  2127. };
  2128. return ChunkedStreamManager;
  2129. })();
  2130. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2131. var BasePdfManager = (function BasePdfManagerClosure() {
  2132. function BasePdfManager() {
  2133. throw new Error('Cannot initialize BaseManagerManager');
  2134. }
  2135. BasePdfManager.prototype = {
  2136. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2137. throw new NotImplementedException();
  2138. },
  2139. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2140. return this.ensure(this.pdfDocument, prop, args);
  2141. },
  2142. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2143. return this.ensure(this.pdfDocument.xref, prop, args);
  2144. },
  2145. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2146. return this.ensure(this.pdfDocument.catalog, prop, args);
  2147. },
  2148. getPage: function BasePdfManager_pagePage(pageIndex) {
  2149. return this.pdfDocument.getPage(pageIndex);
  2150. },
  2151. cleanup: function BasePdfManager_cleanup() {
  2152. return this.pdfDocument.cleanup();
  2153. },
  2154. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2155. return new NotImplementedException();
  2156. },
  2157. requestRange: function BasePdfManager_ensure(begin, end) {
  2158. return new NotImplementedException();
  2159. },
  2160. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2161. return new NotImplementedException();
  2162. },
  2163. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2164. return new NotImplementedException();
  2165. },
  2166. updatePassword: function BasePdfManager_updatePassword(password) {
  2167. this.pdfDocument.xref.password = this.password = password;
  2168. if (this._passwordChangedCapability) {
  2169. this._passwordChangedCapability.resolve();
  2170. }
  2171. },
  2172. passwordChanged: function BasePdfManager_passwordChanged() {
  2173. this._passwordChangedCapability = createPromiseCapability();
  2174. return this._passwordChangedCapability.promise;
  2175. },
  2176. terminate: function BasePdfManager_terminate() {
  2177. return new NotImplementedException();
  2178. }
  2179. };
  2180. return BasePdfManager;
  2181. })();
  2182. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2183. function LocalPdfManager(data, password) {
  2184. var stream = new Stream(data);
  2185. this.pdfDocument = new PDFDocument(this, stream, password);
  2186. this._loadedStreamCapability = createPromiseCapability();
  2187. this._loadedStreamCapability.resolve(stream);
  2188. }
  2189. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2190. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2191. LocalPdfManager.prototype.ensure =
  2192. function LocalPdfManager_ensure(obj, prop, args) {
  2193. return new Promise(function (resolve, reject) {
  2194. try {
  2195. var value = obj[prop];
  2196. var result;
  2197. if (typeof value === 'function') {
  2198. result = value.apply(obj, args);
  2199. } else {
  2200. result = value;
  2201. }
  2202. resolve(result);
  2203. } catch (e) {
  2204. reject(e);
  2205. }
  2206. });
  2207. };
  2208. LocalPdfManager.prototype.requestRange =
  2209. function LocalPdfManager_requestRange(begin, end) {
  2210. return Promise.resolve();
  2211. };
  2212. LocalPdfManager.prototype.requestLoadedStream =
  2213. function LocalPdfManager_requestLoadedStream() {
  2214. };
  2215. LocalPdfManager.prototype.onLoadedStream =
  2216. function LocalPdfManager_getLoadedStream() {
  2217. return this._loadedStreamCapability.promise;
  2218. };
  2219. LocalPdfManager.prototype.terminate =
  2220. function LocalPdfManager_terminate() {
  2221. return;
  2222. };
  2223. return LocalPdfManager;
  2224. })();
  2225. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2226. function NetworkPdfManager(args, msgHandler) {
  2227. this.msgHandler = msgHandler;
  2228. var params = {
  2229. msgHandler: msgHandler,
  2230. httpHeaders: args.httpHeaders,
  2231. withCredentials: args.withCredentials,
  2232. chunkedViewerLoading: args.chunkedViewerLoading,
  2233. disableAutoFetch: args.disableAutoFetch,
  2234. initialData: args.initialData
  2235. };
  2236. this.streamManager = new ChunkedStreamManager(args.length,
  2237. args.rangeChunkSize,
  2238. args.url, params);
  2239. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2240. args.password);
  2241. }
  2242. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2243. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2244. NetworkPdfManager.prototype.ensure =
  2245. function NetworkPdfManager_ensure(obj, prop, args) {
  2246. var pdfManager = this;
  2247. return new Promise(function (resolve, reject) {
  2248. function ensureHelper() {
  2249. try {
  2250. var result;
  2251. var value = obj[prop];
  2252. if (typeof value === 'function') {
  2253. result = value.apply(obj, args);
  2254. } else {
  2255. result = value;
  2256. }
  2257. resolve(result);
  2258. } catch(e) {
  2259. if (!(e instanceof MissingDataException)) {
  2260. reject(e);
  2261. return;
  2262. }
  2263. pdfManager.streamManager.requestRange(e.begin, e.end).
  2264. then(ensureHelper, reject);
  2265. }
  2266. }
  2267. ensureHelper();
  2268. });
  2269. };
  2270. NetworkPdfManager.prototype.requestRange =
  2271. function NetworkPdfManager_requestRange(begin, end) {
  2272. return this.streamManager.requestRange(begin, end);
  2273. };
  2274. NetworkPdfManager.prototype.requestLoadedStream =
  2275. function NetworkPdfManager_requestLoadedStream() {
  2276. this.streamManager.requestAllChunks();
  2277. };
  2278. NetworkPdfManager.prototype.sendProgressiveData =
  2279. function NetworkPdfManager_sendProgressiveData(chunk) {
  2280. this.streamManager.onReceiveData({ chunk: chunk });
  2281. };
  2282. NetworkPdfManager.prototype.onLoadedStream =
  2283. function NetworkPdfManager_getLoadedStream() {
  2284. return this.streamManager.onLoadedStream();
  2285. };
  2286. NetworkPdfManager.prototype.terminate =
  2287. function NetworkPdfManager_terminate() {
  2288. this.streamManager.abort();
  2289. };
  2290. return NetworkPdfManager;
  2291. })();
  2292. var Page = (function PageClosure() {
  2293. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2294. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2295. this.pdfManager = pdfManager;
  2296. this.pageIndex = pageIndex;
  2297. this.pageDict = pageDict;
  2298. this.xref = xref;
  2299. this.ref = ref;
  2300. this.fontCache = fontCache;
  2301. this.idCounters = {
  2302. obj: 0
  2303. };
  2304. this.resourcesPromise = null;
  2305. }
  2306. Page.prototype = {
  2307. getPageProp: function Page_getPageProp(key) {
  2308. return this.pageDict.get(key);
  2309. },
  2310. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2311. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2312. var MAX_LOOP_COUNT = 100;
  2313. // Always walk up the entire parent chain, to be able to find
  2314. // e.g. \Resources placed on multiple levels of the tree.
  2315. while (dict) {
  2316. var value = dict.get(key);
  2317. if (value) {
  2318. if (!valueArray) {
  2319. valueArray = [];
  2320. }
  2321. valueArray.push(value);
  2322. }
  2323. if (++loopCount > MAX_LOOP_COUNT) {
  2324. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2325. break;
  2326. }
  2327. dict = dict.get('Parent');
  2328. }
  2329. if (!valueArray) {
  2330. return Dict.empty;
  2331. }
  2332. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2333. loopCount > MAX_LOOP_COUNT) {
  2334. return valueArray[0];
  2335. }
  2336. return Dict.merge(this.xref, valueArray);
  2337. },
  2338. get content() {
  2339. return this.getPageProp('Contents');
  2340. },
  2341. get resources() {
  2342. // For robustness: The spec states that a \Resources entry has to be
  2343. // present, but can be empty. Some document omit it still, in this case
  2344. // we return an empty dictionary.
  2345. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2346. },
  2347. get mediaBox() {
  2348. var obj = this.getInheritedPageProp('MediaBox');
  2349. // Reset invalid media box to letter size.
  2350. if (!isArray(obj) || obj.length !== 4) {
  2351. obj = LETTER_SIZE_MEDIABOX;
  2352. }
  2353. return shadow(this, 'mediaBox', obj);
  2354. },
  2355. get view() {
  2356. var mediaBox = this.mediaBox;
  2357. var cropBox = this.getInheritedPageProp('CropBox');
  2358. if (!isArray(cropBox) || cropBox.length !== 4) {
  2359. return shadow(this, 'view', mediaBox);
  2360. }
  2361. // From the spec, 6th ed., p.963:
  2362. // "The crop, bleed, trim, and art boxes should not ordinarily
  2363. // extend beyond the boundaries of the media box. If they do, they are
  2364. // effectively reduced to their intersection with the media box."
  2365. cropBox = Util.intersect(cropBox, mediaBox);
  2366. if (!cropBox) {
  2367. return shadow(this, 'view', mediaBox);
  2368. }
  2369. return shadow(this, 'view', cropBox);
  2370. },
  2371. get rotate() {
  2372. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2373. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2374. if (rotate % 90 !== 0) {
  2375. rotate = 0;
  2376. } else if (rotate >= 360) {
  2377. rotate = rotate % 360;
  2378. } else if (rotate < 0) {
  2379. // The spec doesn't cover negatives, assume its counterclockwise
  2380. // rotation. The following is the other implementation of modulo.
  2381. rotate = ((rotate % 360) + 360) % 360;
  2382. }
  2383. return shadow(this, 'rotate', rotate);
  2384. },
  2385. getContentStream: function Page_getContentStream() {
  2386. var content = this.content;
  2387. var stream;
  2388. if (isArray(content)) {
  2389. // fetching items
  2390. var xref = this.xref;
  2391. var i, n = content.length;
  2392. var streams = [];
  2393. for (i = 0; i < n; ++i) {
  2394. streams.push(xref.fetchIfRef(content[i]));
  2395. }
  2396. stream = new StreamsSequenceStream(streams);
  2397. } else if (isStream(content)) {
  2398. stream = content;
  2399. } else {
  2400. // replacing non-existent page content with empty one
  2401. stream = new NullStream();
  2402. }
  2403. return stream;
  2404. },
  2405. loadResources: function Page_loadResources(keys) {
  2406. if (!this.resourcesPromise) {
  2407. // TODO: add async getInheritedPageProp and remove this.
  2408. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2409. }
  2410. return this.resourcesPromise.then(function resourceSuccess() {
  2411. var objectLoader = new ObjectLoader(this.resources.map,
  2412. keys,
  2413. this.xref);
  2414. return objectLoader.load();
  2415. }.bind(this));
  2416. },
  2417. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  2418. var self = this;
  2419. var pdfManager = this.pdfManager;
  2420. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2421. []);
  2422. var resourcesPromise = this.loadResources([
  2423. 'ExtGState',
  2424. 'ColorSpace',
  2425. 'Pattern',
  2426. 'Shading',
  2427. 'XObject',
  2428. 'Font'
  2429. // ProcSet
  2430. // Properties
  2431. ]);
  2432. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2433. handler, this.pageIndex,
  2434. 'p' + this.pageIndex + '_',
  2435. this.idCounters,
  2436. this.fontCache);
  2437. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2438. var pageListPromise = dataPromises.then(function(data) {
  2439. var contentStream = data[0];
  2440. var opList = new OperatorList(intent, handler, self.pageIndex);
  2441. handler.send('StartRenderPage', {
  2442. transparency: partialEvaluator.hasBlendModes(self.resources),
  2443. pageIndex: self.pageIndex,
  2444. intent: intent
  2445. });
  2446. return partialEvaluator.getOperatorList(contentStream, task,
  2447. self.resources, opList).then(function () {
  2448. return opList;
  2449. });
  2450. });
  2451. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2452. return Promise.all([pageListPromise, annotationsPromise]).then(
  2453. function(datas) {
  2454. var pageOpList = datas[0];
  2455. var annotations = datas[1];
  2456. if (annotations.length === 0) {
  2457. pageOpList.flush(true);
  2458. return pageOpList;
  2459. }
  2460. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2461. annotations, pageOpList, pdfManager, partialEvaluator, task, intent);
  2462. return annotationsReadyPromise.then(function () {
  2463. pageOpList.flush(true);
  2464. return pageOpList;
  2465. });
  2466. });
  2467. },
  2468. extractTextContent: function Page_extractTextContent(task) {
  2469. var handler = {
  2470. on: function nullHandlerOn() {},
  2471. send: function nullHandlerSend() {}
  2472. };
  2473. var self = this;
  2474. var pdfManager = this.pdfManager;
  2475. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2476. []);
  2477. var resourcesPromise = this.loadResources([
  2478. 'ExtGState',
  2479. 'XObject',
  2480. 'Font'
  2481. ]);
  2482. var dataPromises = Promise.all([contentStreamPromise,
  2483. resourcesPromise]);
  2484. return dataPromises.then(function(data) {
  2485. var contentStream = data[0];
  2486. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2487. handler, self.pageIndex,
  2488. 'p' + self.pageIndex + '_',
  2489. self.idCounters,
  2490. self.fontCache);
  2491. return partialEvaluator.getTextContent(contentStream,
  2492. task,
  2493. self.resources);
  2494. });
  2495. },
  2496. getAnnotationsData: function Page_getAnnotationsData() {
  2497. var annotations = this.annotations;
  2498. var annotationsData = [];
  2499. for (var i = 0, n = annotations.length; i < n; ++i) {
  2500. annotationsData.push(annotations[i].data);
  2501. }
  2502. return annotationsData;
  2503. },
  2504. get annotations() {
  2505. var annotations = [];
  2506. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  2507. var annotationFactory = new AnnotationFactory();
  2508. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2509. var annotationRef = annotationRefs[i];
  2510. var annotation = annotationFactory.create(this.xref, annotationRef);
  2511. if (annotation &&
  2512. (annotation.isViewable() || annotation.isPrintable())) {
  2513. annotations.push(annotation);
  2514. }
  2515. }
  2516. return shadow(this, 'annotations', annotations);
  2517. }
  2518. };
  2519. return Page;
  2520. })();
  2521. /**
  2522. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2523. * `PDFDoc`, this one doesn't have any job management code.
  2524. * Right now there exists one PDFDocument on the main thread + one object
  2525. * for each worker. If there is no worker support enabled, there are two
  2526. * `PDFDocument` objects on the main thread created.
  2527. */
  2528. var PDFDocument = (function PDFDocumentClosure() {
  2529. var FINGERPRINT_FIRST_BYTES = 1024;
  2530. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2531. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2532. function PDFDocument(pdfManager, arg, password) {
  2533. if (isStream(arg)) {
  2534. init.call(this, pdfManager, arg, password);
  2535. } else if (isArrayBuffer(arg)) {
  2536. init.call(this, pdfManager, new Stream(arg), password);
  2537. } else {
  2538. error('PDFDocument: Unknown argument type');
  2539. }
  2540. }
  2541. function init(pdfManager, stream, password) {
  2542. assert(stream.length > 0, 'stream must have data');
  2543. this.pdfManager = pdfManager;
  2544. this.stream = stream;
  2545. var xref = new XRef(this.stream, password, pdfManager);
  2546. this.xref = xref;
  2547. }
  2548. function find(stream, needle, limit, backwards) {
  2549. var pos = stream.pos;
  2550. var end = stream.end;
  2551. var strBuf = [];
  2552. if (pos + limit > end) {
  2553. limit = end - pos;
  2554. }
  2555. for (var n = 0; n < limit; ++n) {
  2556. strBuf.push(String.fromCharCode(stream.getByte()));
  2557. }
  2558. var str = strBuf.join('');
  2559. stream.pos = pos;
  2560. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2561. if (index === -1) {
  2562. return false; /* not found */
  2563. }
  2564. stream.pos += index;
  2565. return true; /* found */
  2566. }
  2567. var DocumentInfoValidators = {
  2568. get entries() {
  2569. // Lazily build this since all the validation functions below are not
  2570. // defined until after this file loads.
  2571. return shadow(this, 'entries', {
  2572. Title: isString,
  2573. Author: isString,
  2574. Subject: isString,
  2575. Keywords: isString,
  2576. Creator: isString,
  2577. Producer: isString,
  2578. CreationDate: isString,
  2579. ModDate: isString,
  2580. Trapped: isName
  2581. });
  2582. }
  2583. };
  2584. PDFDocument.prototype = {
  2585. parse: function PDFDocument_parse(recoveryMode) {
  2586. this.setup(recoveryMode);
  2587. var version = this.catalog.catDict.get('Version');
  2588. if (isName(version)) {
  2589. this.pdfFormatVersion = version.name;
  2590. }
  2591. try {
  2592. // checking if AcroForm is present
  2593. this.acroForm = this.catalog.catDict.get('AcroForm');
  2594. if (this.acroForm) {
  2595. this.xfa = this.acroForm.get('XFA');
  2596. var fields = this.acroForm.get('Fields');
  2597. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2598. !this.xfa) {
  2599. // no fields and no XFA -- not a form (?)
  2600. this.acroForm = null;
  2601. }
  2602. }
  2603. } catch (ex) {
  2604. info('Something wrong with AcroForm entry');
  2605. this.acroForm = null;
  2606. }
  2607. },
  2608. get linearization() {
  2609. var linearization = null;
  2610. if (this.stream.length) {
  2611. try {
  2612. linearization = Linearization.create(this.stream);
  2613. } catch (err) {
  2614. if (err instanceof MissingDataException) {
  2615. throw err;
  2616. }
  2617. info(err);
  2618. }
  2619. }
  2620. // shadow the prototype getter with a data property
  2621. return shadow(this, 'linearization', linearization);
  2622. },
  2623. get startXRef() {
  2624. var stream = this.stream;
  2625. var startXRef = 0;
  2626. var linearization = this.linearization;
  2627. if (linearization) {
  2628. // Find end of first obj.
  2629. stream.reset();
  2630. if (find(stream, 'endobj', 1024)) {
  2631. startXRef = stream.pos + 6;
  2632. }
  2633. } else {
  2634. // Find startxref by jumping backward from the end of the file.
  2635. var step = 1024;
  2636. var found = false, pos = stream.end;
  2637. while (!found && pos > 0) {
  2638. pos -= step - 'startxref'.length;
  2639. if (pos < 0) {
  2640. pos = 0;
  2641. }
  2642. stream.pos = pos;
  2643. found = find(stream, 'startxref', step, true);
  2644. }
  2645. if (found) {
  2646. stream.skip(9);
  2647. var ch;
  2648. do {
  2649. ch = stream.getByte();
  2650. } while (Lexer.isSpace(ch));
  2651. var str = '';
  2652. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2653. str += String.fromCharCode(ch);
  2654. ch = stream.getByte();
  2655. }
  2656. startXRef = parseInt(str, 10);
  2657. if (isNaN(startXRef)) {
  2658. startXRef = 0;
  2659. }
  2660. }
  2661. }
  2662. // shadow the prototype getter with a data property
  2663. return shadow(this, 'startXRef', startXRef);
  2664. },
  2665. get mainXRefEntriesOffset() {
  2666. var mainXRefEntriesOffset = 0;
  2667. var linearization = this.linearization;
  2668. if (linearization) {
  2669. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2670. }
  2671. // shadow the prototype getter with a data property
  2672. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2673. },
  2674. // Find the header, remove leading garbage and setup the stream
  2675. // starting from the header.
  2676. checkHeader: function PDFDocument_checkHeader() {
  2677. var stream = this.stream;
  2678. stream.reset();
  2679. if (find(stream, '%PDF-', 1024)) {
  2680. // Found the header, trim off any garbage before it.
  2681. stream.moveStart();
  2682. // Reading file format version
  2683. var MAX_VERSION_LENGTH = 12;
  2684. var version = '', ch;
  2685. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2686. if (version.length >= MAX_VERSION_LENGTH) {
  2687. break;
  2688. }
  2689. version += String.fromCharCode(ch);
  2690. }
  2691. if (!this.pdfFormatVersion) {
  2692. // removing "%PDF-"-prefix
  2693. this.pdfFormatVersion = version.substring(5);
  2694. }
  2695. return;
  2696. }
  2697. // May not be a PDF file, continue anyway.
  2698. },
  2699. parseStartXRef: function PDFDocument_parseStartXRef() {
  2700. var startXRef = this.startXRef;
  2701. this.xref.setStartXRef(startXRef);
  2702. },
  2703. setup: function PDFDocument_setup(recoveryMode) {
  2704. this.xref.parse(recoveryMode);
  2705. this.catalog = new Catalog(this.pdfManager, this.xref);
  2706. },
  2707. get numPages() {
  2708. var linearization = this.linearization;
  2709. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2710. // shadow the prototype getter
  2711. return shadow(this, 'numPages', num);
  2712. },
  2713. get documentInfo() {
  2714. var docInfo = {
  2715. PDFFormatVersion: this.pdfFormatVersion,
  2716. IsAcroFormPresent: !!this.acroForm,
  2717. IsXFAPresent: !!this.xfa
  2718. };
  2719. var infoDict;
  2720. try {
  2721. infoDict = this.xref.trailer.get('Info');
  2722. } catch (err) {
  2723. info('The document information dictionary is invalid.');
  2724. }
  2725. if (infoDict) {
  2726. var validEntries = DocumentInfoValidators.entries;
  2727. // Only fill the document info with valid entries from the spec.
  2728. for (var key in validEntries) {
  2729. if (infoDict.has(key)) {
  2730. var value = infoDict.get(key);
  2731. // Make sure the value conforms to the spec.
  2732. if (validEntries[key](value)) {
  2733. docInfo[key] = (typeof value !== 'string' ?
  2734. value : stringToPDFString(value));
  2735. } else {
  2736. info('Bad value in document info for "' + key + '"');
  2737. }
  2738. }
  2739. }
  2740. }
  2741. return shadow(this, 'documentInfo', docInfo);
  2742. },
  2743. get fingerprint() {
  2744. var xref = this.xref, hash, fileID = '';
  2745. var idArray = xref.trailer.get('ID');
  2746. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  2747. idArray[0] !== EMPTY_FINGERPRINT) {
  2748. hash = stringToBytes(idArray[0]);
  2749. } else {
  2750. if (this.stream.ensureRange) {
  2751. this.stream.ensureRange(0,
  2752. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2753. }
  2754. hash = calculateMD5(this.stream.bytes.subarray(0,
  2755. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2756. }
  2757. for (var i = 0, n = hash.length; i < n; i++) {
  2758. var hex = hash[i].toString(16);
  2759. fileID += hex.length === 1 ? '0' + hex : hex;
  2760. }
  2761. return shadow(this, 'fingerprint', fileID);
  2762. },
  2763. getPage: function PDFDocument_getPage(pageIndex) {
  2764. return this.catalog.getPage(pageIndex);
  2765. },
  2766. cleanup: function PDFDocument_cleanup() {
  2767. return this.catalog.cleanup();
  2768. }
  2769. };
  2770. return PDFDocument;
  2771. })();
  2772. var Name = (function NameClosure() {
  2773. function Name(name) {
  2774. this.name = name;
  2775. }
  2776. Name.prototype = {};
  2777. var nameCache = {};
  2778. Name.get = function Name_get(name) {
  2779. var nameValue = nameCache[name];
  2780. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2781. };
  2782. return Name;
  2783. })();
  2784. var Cmd = (function CmdClosure() {
  2785. function Cmd(cmd) {
  2786. this.cmd = cmd;
  2787. }
  2788. Cmd.prototype = {};
  2789. var cmdCache = {};
  2790. Cmd.get = function Cmd_get(cmd) {
  2791. var cmdValue = cmdCache[cmd];
  2792. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2793. };
  2794. return Cmd;
  2795. })();
  2796. var Dict = (function DictClosure() {
  2797. var nonSerializable = function nonSerializableClosure() {
  2798. return nonSerializable; // creating closure on some variable
  2799. };
  2800. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2801. 'Background': true,
  2802. 'ExtGState': true,
  2803. 'Halftone': true,
  2804. 'Layout': true,
  2805. 'Mask': true,
  2806. 'Pagination': true,
  2807. 'Printing': true
  2808. };
  2809. function isRecursionAllowedFor(dict) {
  2810. if (!isName(dict.Type)) {
  2811. return true;
  2812. }
  2813. var dictType = dict.Type.name;
  2814. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2815. }
  2816. // xref is optional
  2817. function Dict(xref) {
  2818. // Map should only be used internally, use functions below to access.
  2819. this.map = Object.create(null);
  2820. this.xref = xref;
  2821. this.objId = null;
  2822. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2823. }
  2824. Dict.prototype = {
  2825. assignXref: function Dict_assignXref(newXref) {
  2826. this.xref = newXref;
  2827. },
  2828. // automatically dereferences Ref objects
  2829. get: function Dict_get(key1, key2, key3) {
  2830. var value;
  2831. var xref = this.xref;
  2832. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2833. typeof key2 === 'undefined') {
  2834. return xref ? xref.fetchIfRef(value) : value;
  2835. }
  2836. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2837. typeof key3 === 'undefined') {
  2838. return xref ? xref.fetchIfRef(value) : value;
  2839. }
  2840. value = this.map[key3] || null;
  2841. return xref ? xref.fetchIfRef(value) : value;
  2842. },
  2843. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2844. getAsync: function Dict_getAsync(key1, key2, key3) {
  2845. var value;
  2846. var xref = this.xref;
  2847. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2848. typeof key2 === 'undefined') {
  2849. if (xref) {
  2850. return xref.fetchIfRefAsync(value);
  2851. }
  2852. return Promise.resolve(value);
  2853. }
  2854. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2855. typeof key3 === 'undefined') {
  2856. if (xref) {
  2857. return xref.fetchIfRefAsync(value);
  2858. }
  2859. return Promise.resolve(value);
  2860. }
  2861. value = this.map[key3] || null;
  2862. if (xref) {
  2863. return xref.fetchIfRefAsync(value);
  2864. }
  2865. return Promise.resolve(value);
  2866. },
  2867. // Same as get(), but dereferences all elements if the result is an Array.
  2868. getArray: function Dict_getArray(key1, key2, key3) {
  2869. var value = this.get(key1, key2, key3);
  2870. var xref = this.xref;
  2871. if (!isArray(value) || !xref) {
  2872. return value;
  2873. }
  2874. value = value.slice(); // Ensure that we don't modify the Dict data.
  2875. for (var i = 0, ii = value.length; i < ii; i++) {
  2876. if (!isRef(value[i])) {
  2877. continue;
  2878. }
  2879. value[i] = xref.fetch(value[i]);
  2880. }
  2881. return value;
  2882. },
  2883. // no dereferencing
  2884. getRaw: function Dict_getRaw(key) {
  2885. return this.map[key];
  2886. },
  2887. // creates new map and dereferences all Refs
  2888. getAll: function Dict_getAll() {
  2889. var all = Object.create(null);
  2890. var queue = null;
  2891. var key, obj;
  2892. for (key in this.map) {
  2893. obj = this.get(key);
  2894. if (obj instanceof Dict) {
  2895. if (isRecursionAllowedFor(obj)) {
  2896. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2897. } else {
  2898. all[key] = this.getRaw(key);
  2899. }
  2900. } else {
  2901. all[key] = obj;
  2902. }
  2903. }
  2904. if (!queue) {
  2905. return all;
  2906. }
  2907. // trying to take cyclic references into the account
  2908. var processed = Object.create(null);
  2909. while (queue.length > 0) {
  2910. var item = queue.shift();
  2911. var itemObj = item.obj;
  2912. var objId = itemObj.objId;
  2913. if (objId && objId in processed) {
  2914. item.target[item.key] = processed[objId];
  2915. continue;
  2916. }
  2917. var dereferenced = Object.create(null);
  2918. for (key in itemObj.map) {
  2919. obj = itemObj.get(key);
  2920. if (obj instanceof Dict) {
  2921. if (isRecursionAllowedFor(obj)) {
  2922. queue.push({target: dereferenced, key: key, obj: obj});
  2923. } else {
  2924. dereferenced[key] = itemObj.getRaw(key);
  2925. }
  2926. } else {
  2927. dereferenced[key] = obj;
  2928. }
  2929. }
  2930. if (objId) {
  2931. processed[objId] = dereferenced;
  2932. }
  2933. item.target[item.key] = dereferenced;
  2934. }
  2935. return all;
  2936. },
  2937. getKeys: function Dict_getKeys() {
  2938. return Object.keys(this.map);
  2939. },
  2940. set: function Dict_set(key, value) {
  2941. this.map[key] = value;
  2942. },
  2943. has: function Dict_has(key) {
  2944. return key in this.map;
  2945. },
  2946. forEach: function Dict_forEach(callback) {
  2947. for (var key in this.map) {
  2948. callback(key, this.get(key));
  2949. }
  2950. }
  2951. };
  2952. Dict.empty = new Dict(null);
  2953. Dict.merge = function Dict_merge(xref, dictArray) {
  2954. var mergedDict = new Dict(xref);
  2955. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  2956. var dict = dictArray[i];
  2957. if (!isDict(dict)) {
  2958. continue;
  2959. }
  2960. for (var keyName in dict.map) {
  2961. if (mergedDict.map[keyName]) {
  2962. continue;
  2963. }
  2964. mergedDict.map[keyName] = dict.map[keyName];
  2965. }
  2966. }
  2967. return mergedDict;
  2968. };
  2969. return Dict;
  2970. })();
  2971. var Ref = (function RefClosure() {
  2972. function Ref(num, gen) {
  2973. this.num = num;
  2974. this.gen = gen;
  2975. }
  2976. Ref.prototype = {
  2977. toString: function Ref_toString() {
  2978. // This function is hot, so we make the string as compact as possible.
  2979. // |this.gen| is almost always zero, so we treat that case specially.
  2980. var str = this.num + 'R';
  2981. if (this.gen !== 0) {
  2982. str += this.gen;
  2983. }
  2984. return str;
  2985. }
  2986. };
  2987. return Ref;
  2988. })();
  2989. // The reference is identified by number and generation.
  2990. // This structure stores only one instance of the reference.
  2991. var RefSet = (function RefSetClosure() {
  2992. function RefSet() {
  2993. this.dict = {};
  2994. }
  2995. RefSet.prototype = {
  2996. has: function RefSet_has(ref) {
  2997. return ref.toString() in this.dict;
  2998. },
  2999. put: function RefSet_put(ref) {
  3000. this.dict[ref.toString()] = true;
  3001. },
  3002. remove: function RefSet_remove(ref) {
  3003. delete this.dict[ref.toString()];
  3004. }
  3005. };
  3006. return RefSet;
  3007. })();
  3008. var RefSetCache = (function RefSetCacheClosure() {
  3009. function RefSetCache() {
  3010. this.dict = Object.create(null);
  3011. }
  3012. RefSetCache.prototype = {
  3013. get: function RefSetCache_get(ref) {
  3014. return this.dict[ref.toString()];
  3015. },
  3016. has: function RefSetCache_has(ref) {
  3017. return ref.toString() in this.dict;
  3018. },
  3019. put: function RefSetCache_put(ref, obj) {
  3020. this.dict[ref.toString()] = obj;
  3021. },
  3022. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  3023. this.dict[ref.toString()] = this.get(aliasRef);
  3024. },
  3025. forEach: function RefSetCache_forEach(fn, thisArg) {
  3026. for (var i in this.dict) {
  3027. fn.call(thisArg, this.dict[i]);
  3028. }
  3029. },
  3030. clear: function RefSetCache_clear() {
  3031. this.dict = Object.create(null);
  3032. }
  3033. };
  3034. return RefSetCache;
  3035. })();
  3036. var Catalog = (function CatalogClosure() {
  3037. function Catalog(pdfManager, xref) {
  3038. this.pdfManager = pdfManager;
  3039. this.xref = xref;
  3040. this.catDict = xref.getCatalogObj();
  3041. this.fontCache = new RefSetCache();
  3042. assert(isDict(this.catDict),
  3043. 'catalog object is not a dictionary');
  3044. this.pagePromises = [];
  3045. }
  3046. Catalog.prototype = {
  3047. get metadata() {
  3048. var streamRef = this.catDict.getRaw('Metadata');
  3049. if (!isRef(streamRef)) {
  3050. return shadow(this, 'metadata', null);
  3051. }
  3052. var encryptMetadata = (!this.xref.encrypt ? false :
  3053. this.xref.encrypt.encryptMetadata);
  3054. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3055. var metadata;
  3056. if (stream && isDict(stream.dict)) {
  3057. var type = stream.dict.get('Type');
  3058. var subtype = stream.dict.get('Subtype');
  3059. if (isName(type) && isName(subtype) &&
  3060. type.name === 'Metadata' && subtype.name === 'XML') {
  3061. // XXX: This should examine the charset the XML document defines,
  3062. // however since there are currently no real means to decode
  3063. // arbitrary charsets, let's just hope that the author of the PDF
  3064. // was reasonable enough to stick with the XML default charset,
  3065. // which is UTF-8.
  3066. try {
  3067. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3068. } catch (e) {
  3069. info('Skipping invalid metadata.');
  3070. }
  3071. }
  3072. }
  3073. return shadow(this, 'metadata', metadata);
  3074. },
  3075. get toplevelPagesDict() {
  3076. var pagesObj = this.catDict.get('Pages');
  3077. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3078. // shadow the prototype getter
  3079. return shadow(this, 'toplevelPagesDict', pagesObj);
  3080. },
  3081. get documentOutline() {
  3082. var obj = null;
  3083. try {
  3084. obj = this.readDocumentOutline();
  3085. } catch (ex) {
  3086. if (ex instanceof MissingDataException) {
  3087. throw ex;
  3088. }
  3089. warn('Unable to read document outline');
  3090. }
  3091. return shadow(this, 'documentOutline', obj);
  3092. },
  3093. readDocumentOutline: function Catalog_readDocumentOutline() {
  3094. var xref = this.xref;
  3095. var obj = this.catDict.get('Outlines');
  3096. var root = { items: [] };
  3097. if (isDict(obj)) {
  3098. obj = obj.getRaw('First');
  3099. var processed = new RefSet();
  3100. if (isRef(obj)) {
  3101. var queue = [{obj: obj, parent: root}];
  3102. // to avoid recursion keeping track of the items
  3103. // in the processed dictionary
  3104. processed.put(obj);
  3105. while (queue.length > 0) {
  3106. var i = queue.shift();
  3107. var outlineDict = xref.fetchIfRef(i.obj);
  3108. if (outlineDict === null) {
  3109. continue;
  3110. }
  3111. if (!outlineDict.has('Title')) {
  3112. error('Invalid outline item');
  3113. }
  3114. var dest = outlineDict.get('A');
  3115. if (dest) {
  3116. dest = dest.get('D');
  3117. } else if (outlineDict.has('Dest')) {
  3118. dest = outlineDict.getRaw('Dest');
  3119. if (isName(dest)) {
  3120. dest = dest.name;
  3121. }
  3122. }
  3123. var title = outlineDict.get('Title');
  3124. var outlineItem = {
  3125. dest: dest,
  3126. title: stringToPDFString(title),
  3127. color: outlineDict.get('C') || [0, 0, 0],
  3128. count: outlineDict.get('Count'),
  3129. bold: !!(outlineDict.get('F') & 2),
  3130. italic: !!(outlineDict.get('F') & 1),
  3131. items: []
  3132. };
  3133. i.parent.items.push(outlineItem);
  3134. obj = outlineDict.getRaw('First');
  3135. if (isRef(obj) && !processed.has(obj)) {
  3136. queue.push({obj: obj, parent: outlineItem});
  3137. processed.put(obj);
  3138. }
  3139. obj = outlineDict.getRaw('Next');
  3140. if (isRef(obj) && !processed.has(obj)) {
  3141. queue.push({obj: obj, parent: i.parent});
  3142. processed.put(obj);
  3143. }
  3144. }
  3145. }
  3146. }
  3147. return (root.items.length > 0 ? root.items : null);
  3148. },
  3149. get numPages() {
  3150. var obj = this.toplevelPagesDict.get('Count');
  3151. assert(
  3152. isInt(obj),
  3153. 'page count in top level pages object is not an integer'
  3154. );
  3155. // shadow the prototype getter
  3156. return shadow(this, 'num', obj);
  3157. },
  3158. get destinations() {
  3159. function fetchDestination(dest) {
  3160. return isDict(dest) ? dest.get('D') : dest;
  3161. }
  3162. var xref = this.xref;
  3163. var dests = {}, nameTreeRef, nameDictionaryRef;
  3164. var obj = this.catDict.get('Names');
  3165. if (obj && obj.has('Dests')) {
  3166. nameTreeRef = obj.getRaw('Dests');
  3167. } else if (this.catDict.has('Dests')) {
  3168. nameDictionaryRef = this.catDict.get('Dests');
  3169. }
  3170. if (nameDictionaryRef) {
  3171. // reading simple destination dictionary
  3172. obj = nameDictionaryRef;
  3173. obj.forEach(function catalogForEach(key, value) {
  3174. if (!value) {
  3175. return;
  3176. }
  3177. dests[key] = fetchDestination(value);
  3178. });
  3179. }
  3180. if (nameTreeRef) {
  3181. var nameTree = new NameTree(nameTreeRef, xref);
  3182. var names = nameTree.getAll();
  3183. for (var name in names) {
  3184. if (!names.hasOwnProperty(name)) {
  3185. continue;
  3186. }
  3187. dests[name] = fetchDestination(names[name]);
  3188. }
  3189. }
  3190. return shadow(this, 'destinations', dests);
  3191. },
  3192. getDestination: function Catalog_getDestination(destinationId) {
  3193. function fetchDestination(dest) {
  3194. return isDict(dest) ? dest.get('D') : dest;
  3195. }
  3196. var xref = this.xref;
  3197. var dest = null, nameTreeRef, nameDictionaryRef;
  3198. var obj = this.catDict.get('Names');
  3199. if (obj && obj.has('Dests')) {
  3200. nameTreeRef = obj.getRaw('Dests');
  3201. } else if (this.catDict.has('Dests')) {
  3202. nameDictionaryRef = this.catDict.get('Dests');
  3203. }
  3204. if (nameDictionaryRef) { // Simple destination dictionary.
  3205. var value = nameDictionaryRef.get(destinationId);
  3206. if (value) {
  3207. dest = fetchDestination(value);
  3208. }
  3209. }
  3210. if (nameTreeRef) {
  3211. var nameTree = new NameTree(nameTreeRef, xref);
  3212. dest = fetchDestination(nameTree.get(destinationId));
  3213. }
  3214. return dest;
  3215. },
  3216. get attachments() {
  3217. var xref = this.xref;
  3218. var attachments = null, nameTreeRef;
  3219. var obj = this.catDict.get('Names');
  3220. if (obj) {
  3221. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3222. }
  3223. if (nameTreeRef) {
  3224. var nameTree = new NameTree(nameTreeRef, xref);
  3225. var names = nameTree.getAll();
  3226. for (var name in names) {
  3227. if (!names.hasOwnProperty(name)) {
  3228. continue;
  3229. }
  3230. var fs = new FileSpec(names[name], xref);
  3231. if (!attachments) {
  3232. attachments = {};
  3233. }
  3234. attachments[stringToPDFString(name)] = fs.serializable;
  3235. }
  3236. }
  3237. return shadow(this, 'attachments', attachments);
  3238. },
  3239. get javaScript() {
  3240. var xref = this.xref;
  3241. var obj = this.catDict.get('Names');
  3242. var javaScript = [];
  3243. function appendIfJavaScriptDict(jsDict) {
  3244. var type = jsDict.get('S');
  3245. if (!isName(type) || type.name !== 'JavaScript') {
  3246. return;
  3247. }
  3248. var js = jsDict.get('JS');
  3249. if (isStream(js)) {
  3250. js = bytesToString(js.getBytes());
  3251. } else if (!isString(js)) {
  3252. return;
  3253. }
  3254. javaScript.push(stringToPDFString(js));
  3255. }
  3256. if (obj && obj.has('JavaScript')) {
  3257. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3258. var names = nameTree.getAll();
  3259. for (var name in names) {
  3260. if (!names.hasOwnProperty(name)) {
  3261. continue;
  3262. }
  3263. // We don't really use the JavaScript right now. This code is
  3264. // defensive so we don't cause errors on document load.
  3265. var jsDict = names[name];
  3266. if (isDict(jsDict)) {
  3267. appendIfJavaScriptDict(jsDict);
  3268. }
  3269. }
  3270. }
  3271. // Append OpenAction actions to javaScript array
  3272. var openactionDict = this.catDict.get('OpenAction');
  3273. if (isDict(openactionDict, 'Action')) {
  3274. var actionType = openactionDict.get('S');
  3275. if (isName(actionType) && actionType.name === 'Named') {
  3276. // The named Print action is not a part of the PDF 1.7 specification,
  3277. // but is supported by many PDF readers/writers (including Adobe's).
  3278. var action = openactionDict.get('N');
  3279. if (isName(action) && action.name === 'Print') {
  3280. javaScript.push('print({});');
  3281. }
  3282. } else {
  3283. appendIfJavaScriptDict(openactionDict);
  3284. }
  3285. }
  3286. return shadow(this, 'javaScript', javaScript);
  3287. },
  3288. cleanup: function Catalog_cleanup() {
  3289. var promises = [];
  3290. this.fontCache.forEach(function (promise) {
  3291. promises.push(promise);
  3292. });
  3293. return Promise.all(promises).then(function (translatedFonts) {
  3294. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3295. var font = translatedFonts[i].dict;
  3296. delete font.translated;
  3297. }
  3298. this.fontCache.clear();
  3299. }.bind(this));
  3300. },
  3301. getPage: function Catalog_getPage(pageIndex) {
  3302. if (!(pageIndex in this.pagePromises)) {
  3303. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3304. function (a) {
  3305. var dict = a[0];
  3306. var ref = a[1];
  3307. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3308. this.fontCache);
  3309. }.bind(this)
  3310. );
  3311. }
  3312. return this.pagePromises[pageIndex];
  3313. },
  3314. getPageDict: function Catalog_getPageDict(pageIndex) {
  3315. var capability = createPromiseCapability();
  3316. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3317. var currentPageIndex = 0;
  3318. var xref = this.xref;
  3319. var checkAllKids = false;
  3320. function next() {
  3321. while (nodesToVisit.length) {
  3322. var currentNode = nodesToVisit.pop();
  3323. if (isRef(currentNode)) {
  3324. xref.fetchAsync(currentNode).then(function (obj) {
  3325. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3326. if (pageIndex === currentPageIndex) {
  3327. capability.resolve([obj, currentNode]);
  3328. } else {
  3329. currentPageIndex++;
  3330. next();
  3331. }
  3332. return;
  3333. }
  3334. nodesToVisit.push(obj);
  3335. next();
  3336. }, capability.reject);
  3337. return;
  3338. }
  3339. // Must be a child page dictionary.
  3340. assert(
  3341. isDict(currentNode),
  3342. 'page dictionary kid reference points to wrong type of object'
  3343. );
  3344. var count = currentNode.get('Count');
  3345. // If the current node doesn't have any children, avoid getting stuck
  3346. // in an empty node further down in the tree (see issue5644.pdf).
  3347. if (count === 0) {
  3348. checkAllKids = true;
  3349. }
  3350. // Skip nodes where the page can't be.
  3351. if (currentPageIndex + count <= pageIndex) {
  3352. currentPageIndex += count;
  3353. continue;
  3354. }
  3355. var kids = currentNode.get('Kids');
  3356. assert(isArray(kids), 'page dictionary kids object is not an array');
  3357. if (!checkAllKids && count === kids.length) {
  3358. // Nodes that don't have the page have been skipped and this is the
  3359. // bottom of the tree which means the page requested must be a
  3360. // descendant of this pages node. Ideally we would just resolve the
  3361. // promise with the page ref here, but there is the case where more
  3362. // pages nodes could link to single a page (see issue 3666 pdf). To
  3363. // handle this push it back on the queue so if it is a pages node it
  3364. // will be descended into.
  3365. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3366. currentPageIndex = pageIndex;
  3367. continue;
  3368. } else {
  3369. for (var last = kids.length - 1; last >= 0; last--) {
  3370. nodesToVisit.push(kids[last]);
  3371. }
  3372. }
  3373. }
  3374. capability.reject('Page index ' + pageIndex + ' not found.');
  3375. }
  3376. next();
  3377. return capability.promise;
  3378. },
  3379. getPageIndex: function Catalog_getPageIndex(ref) {
  3380. // The page tree nodes have the count of all the leaves below them. To get
  3381. // how many pages are before we just have to walk up the tree and keep
  3382. // adding the count of siblings to the left of the node.
  3383. var xref = this.xref;
  3384. function pagesBeforeRef(kidRef) {
  3385. var total = 0;
  3386. var parentRef;
  3387. return xref.fetchAsync(kidRef).then(function (node) {
  3388. if (!node) {
  3389. return null;
  3390. }
  3391. parentRef = node.getRaw('Parent');
  3392. return node.getAsync('Parent');
  3393. }).then(function (parent) {
  3394. if (!parent) {
  3395. return null;
  3396. }
  3397. return parent.getAsync('Kids');
  3398. }).then(function (kids) {
  3399. if (!kids) {
  3400. return null;
  3401. }
  3402. var kidPromises = [];
  3403. var found = false;
  3404. for (var i = 0; i < kids.length; i++) {
  3405. var kid = kids[i];
  3406. assert(isRef(kid), 'kids must be a ref');
  3407. if (kid.num === kidRef.num) {
  3408. found = true;
  3409. break;
  3410. }
  3411. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3412. if (kid.has('Count')) {
  3413. var count = kid.get('Count');
  3414. total += count;
  3415. } else { // page leaf node
  3416. total++;
  3417. }
  3418. }));
  3419. }
  3420. if (!found) {
  3421. error('kid ref not found in parents kids');
  3422. }
  3423. return Promise.all(kidPromises).then(function () {
  3424. return [total, parentRef];
  3425. });
  3426. });
  3427. }
  3428. var total = 0;
  3429. function next(ref) {
  3430. return pagesBeforeRef(ref).then(function (args) {
  3431. if (!args) {
  3432. return total;
  3433. }
  3434. var count = args[0];
  3435. var parentRef = args[1];
  3436. total += count;
  3437. return next(parentRef);
  3438. });
  3439. }
  3440. return next(ref);
  3441. }
  3442. };
  3443. return Catalog;
  3444. })();
  3445. var XRef = (function XRefClosure() {
  3446. function XRef(stream, password) {
  3447. this.stream = stream;
  3448. this.entries = [];
  3449. this.xrefstms = {};
  3450. // prepare the XRef cache
  3451. this.cache = [];
  3452. this.password = password;
  3453. this.stats = {
  3454. streamTypes: [],
  3455. fontTypes: []
  3456. };
  3457. }
  3458. XRef.prototype = {
  3459. setStartXRef: function XRef_setStartXRef(startXRef) {
  3460. // Store the starting positions of xref tables as we process them
  3461. // so we can recover from missing data errors
  3462. this.startXRefQueue = [startXRef];
  3463. },
  3464. parse: function XRef_parse(recoveryMode) {
  3465. var trailerDict;
  3466. if (!recoveryMode) {
  3467. trailerDict = this.readXRef();
  3468. } else {
  3469. warn('Indexing all PDF objects');
  3470. trailerDict = this.indexObjects();
  3471. }
  3472. trailerDict.assignXref(this);
  3473. this.trailer = trailerDict;
  3474. var encrypt = trailerDict.get('Encrypt');
  3475. if (encrypt) {
  3476. var ids = trailerDict.get('ID');
  3477. var fileId = (ids && ids.length) ? ids[0] : '';
  3478. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3479. this.password);
  3480. }
  3481. // get the root dictionary (catalog) object
  3482. if (!(this.root = trailerDict.get('Root'))) {
  3483. error('Invalid root reference');
  3484. }
  3485. },
  3486. processXRefTable: function XRef_processXRefTable(parser) {
  3487. if (!('tableState' in this)) {
  3488. // Stores state of the table as we process it so we can resume
  3489. // from middle of table in case of missing data error
  3490. this.tableState = {
  3491. entryNum: 0,
  3492. streamPos: parser.lexer.stream.pos,
  3493. parserBuf1: parser.buf1,
  3494. parserBuf2: parser.buf2
  3495. };
  3496. }
  3497. var obj = this.readXRefTable(parser);
  3498. // Sanity check
  3499. if (!isCmd(obj, 'trailer')) {
  3500. error('Invalid XRef table: could not find trailer dictionary');
  3501. }
  3502. // Read trailer dictionary, e.g.
  3503. // trailer
  3504. // << /Size 22
  3505. // /Root 20R
  3506. // /Info 10R
  3507. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3508. // >>
  3509. // The parser goes through the entire stream << ... >> and provides
  3510. // a getter interface for the key-value table
  3511. var dict = parser.getObj();
  3512. // The pdflib PDF generator can generate a nested trailer dictionary
  3513. if (!isDict(dict) && dict.dict) {
  3514. dict = dict.dict;
  3515. }
  3516. if (!isDict(dict)) {
  3517. error('Invalid XRef table: could not parse trailer dictionary');
  3518. }
  3519. delete this.tableState;
  3520. return dict;
  3521. },
  3522. readXRefTable: function XRef_readXRefTable(parser) {
  3523. // Example of cross-reference table:
  3524. // xref
  3525. // 0 1 <-- subsection header (first obj #, obj count)
  3526. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3527. // 23 2 <-- subsection header ... and so on ...
  3528. // 0000025518 00002 n
  3529. // 0000025635 00000 n
  3530. // trailer
  3531. // ...
  3532. var stream = parser.lexer.stream;
  3533. var tableState = this.tableState;
  3534. stream.pos = tableState.streamPos;
  3535. parser.buf1 = tableState.parserBuf1;
  3536. parser.buf2 = tableState.parserBuf2;
  3537. // Outer loop is over subsection headers
  3538. var obj;
  3539. while (true) {
  3540. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3541. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3542. break;
  3543. }
  3544. tableState.firstEntryNum = obj;
  3545. tableState.entryCount = parser.getObj();
  3546. }
  3547. var first = tableState.firstEntryNum;
  3548. var count = tableState.entryCount;
  3549. if (!isInt(first) || !isInt(count)) {
  3550. error('Invalid XRef table: wrong types in subsection header');
  3551. }
  3552. // Inner loop is over objects themselves
  3553. for (var i = tableState.entryNum; i < count; i++) {
  3554. tableState.streamPos = stream.pos;
  3555. tableState.entryNum = i;
  3556. tableState.parserBuf1 = parser.buf1;
  3557. tableState.parserBuf2 = parser.buf2;
  3558. var entry = {};
  3559. entry.offset = parser.getObj();
  3560. entry.gen = parser.getObj();
  3561. var type = parser.getObj();
  3562. if (isCmd(type, 'f')) {
  3563. entry.free = true;
  3564. } else if (isCmd(type, 'n')) {
  3565. entry.uncompressed = true;
  3566. }
  3567. // Validate entry obj
  3568. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3569. !(entry.free || entry.uncompressed)) {
  3570. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3571. }
  3572. if (!this.entries[i + first]) {
  3573. this.entries[i + first] = entry;
  3574. }
  3575. }
  3576. tableState.entryNum = 0;
  3577. tableState.streamPos = stream.pos;
  3578. tableState.parserBuf1 = parser.buf1;
  3579. tableState.parserBuf2 = parser.buf2;
  3580. delete tableState.firstEntryNum;
  3581. delete tableState.entryCount;
  3582. }
  3583. // Per issue 3248: hp scanners generate bad XRef
  3584. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3585. // shifting the entries
  3586. this.entries.shift();
  3587. }
  3588. // Sanity check: as per spec, first object must be free
  3589. if (this.entries[0] && !this.entries[0].free) {
  3590. error('Invalid XRef table: unexpected first object');
  3591. }
  3592. return obj;
  3593. },
  3594. processXRefStream: function XRef_processXRefStream(stream) {
  3595. if (!('streamState' in this)) {
  3596. // Stores state of the stream as we process it so we can resume
  3597. // from middle of stream in case of missing data error
  3598. var streamParameters = stream.dict;
  3599. var byteWidths = streamParameters.get('W');
  3600. var range = streamParameters.get('Index');
  3601. if (!range) {
  3602. range = [0, streamParameters.get('Size')];
  3603. }
  3604. this.streamState = {
  3605. entryRanges: range,
  3606. byteWidths: byteWidths,
  3607. entryNum: 0,
  3608. streamPos: stream.pos
  3609. };
  3610. }
  3611. this.readXRefStream(stream);
  3612. delete this.streamState;
  3613. return stream.dict;
  3614. },
  3615. readXRefStream: function XRef_readXRefStream(stream) {
  3616. var i, j;
  3617. var streamState = this.streamState;
  3618. stream.pos = streamState.streamPos;
  3619. var byteWidths = streamState.byteWidths;
  3620. var typeFieldWidth = byteWidths[0];
  3621. var offsetFieldWidth = byteWidths[1];
  3622. var generationFieldWidth = byteWidths[2];
  3623. var entryRanges = streamState.entryRanges;
  3624. while (entryRanges.length > 0) {
  3625. var first = entryRanges[0];
  3626. var n = entryRanges[1];
  3627. if (!isInt(first) || !isInt(n)) {
  3628. error('Invalid XRef range fields: ' + first + ', ' + n);
  3629. }
  3630. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3631. !isInt(generationFieldWidth)) {
  3632. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3633. }
  3634. for (i = streamState.entryNum; i < n; ++i) {
  3635. streamState.entryNum = i;
  3636. streamState.streamPos = stream.pos;
  3637. var type = 0, offset = 0, generation = 0;
  3638. for (j = 0; j < typeFieldWidth; ++j) {
  3639. type = (type << 8) | stream.getByte();
  3640. }
  3641. // if type field is absent, its default value is 1
  3642. if (typeFieldWidth === 0) {
  3643. type = 1;
  3644. }
  3645. for (j = 0; j < offsetFieldWidth; ++j) {
  3646. offset = (offset << 8) | stream.getByte();
  3647. }
  3648. for (j = 0; j < generationFieldWidth; ++j) {
  3649. generation = (generation << 8) | stream.getByte();
  3650. }
  3651. var entry = {};
  3652. entry.offset = offset;
  3653. entry.gen = generation;
  3654. switch (type) {
  3655. case 0:
  3656. entry.free = true;
  3657. break;
  3658. case 1:
  3659. entry.uncompressed = true;
  3660. break;
  3661. case 2:
  3662. break;
  3663. default:
  3664. error('Invalid XRef entry type: ' + type);
  3665. }
  3666. if (!this.entries[first + i]) {
  3667. this.entries[first + i] = entry;
  3668. }
  3669. }
  3670. streamState.entryNum = 0;
  3671. streamState.streamPos = stream.pos;
  3672. entryRanges.splice(0, 2);
  3673. }
  3674. },
  3675. indexObjects: function XRef_indexObjects() {
  3676. // Simple scan through the PDF content to find objects,
  3677. // trailers and XRef streams.
  3678. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  3679. var PERCENT = 0x25, LT = 0x3C;
  3680. function readToken(data, offset) {
  3681. var token = '', ch = data[offset];
  3682. while (ch !== LF && ch !== CR && ch !== LT) {
  3683. if (++offset >= data.length) {
  3684. break;
  3685. }
  3686. token += String.fromCharCode(ch);
  3687. ch = data[offset];
  3688. }
  3689. return token;
  3690. }
  3691. function skipUntil(data, offset, what) {
  3692. var length = what.length, dataLength = data.length;
  3693. var skipped = 0;
  3694. // finding byte sequence
  3695. while (offset < dataLength) {
  3696. var i = 0;
  3697. while (i < length && data[offset + i] === what[i]) {
  3698. ++i;
  3699. }
  3700. if (i >= length) {
  3701. break; // sequence found
  3702. }
  3703. offset++;
  3704. skipped++;
  3705. }
  3706. return skipped;
  3707. }
  3708. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  3709. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3710. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3711. 101, 102]);
  3712. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3713. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3714. // Clear out any existing entries, since they may be bogus.
  3715. this.entries.length = 0;
  3716. var stream = this.stream;
  3717. stream.pos = 0;
  3718. var buffer = stream.getBytes();
  3719. var position = stream.start, length = buffer.length;
  3720. var trailers = [], xrefStms = [];
  3721. while (position < length) {
  3722. var ch = buffer[position];
  3723. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  3724. ++position;
  3725. continue;
  3726. }
  3727. if (ch === PERCENT) { // %-comment
  3728. do {
  3729. ++position;
  3730. if (position >= length) {
  3731. break;
  3732. }
  3733. ch = buffer[position];
  3734. } while (ch !== LF && ch !== CR);
  3735. continue;
  3736. }
  3737. var token = readToken(buffer, position);
  3738. var m;
  3739. if (token.indexOf('xref') === 0 &&
  3740. (token.length === 4 || /\s/.test(token[4]))) {
  3741. position += skipUntil(buffer, position, trailerBytes);
  3742. trailers.push(position);
  3743. position += skipUntil(buffer, position, startxrefBytes);
  3744. } else if ((m = objRegExp.exec(token))) {
  3745. if (typeof this.entries[m[1]] === 'undefined') {
  3746. this.entries[m[1]] = {
  3747. offset: position - stream.start,
  3748. gen: m[2] | 0,
  3749. uncompressed: true
  3750. };
  3751. }
  3752. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3753. var content = buffer.subarray(position, position + contentLength);
  3754. // checking XRef stream suspect
  3755. // (it shall have '/XRef' and next char is not a letter)
  3756. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3757. if (xrefTagOffset < contentLength &&
  3758. content[xrefTagOffset + 5] < 64) {
  3759. xrefStms.push(position - stream.start);
  3760. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  3761. }
  3762. position += contentLength;
  3763. } else if (token.indexOf('trailer') === 0 &&
  3764. (token.length === 7 || /\s/.test(token[7]))) {
  3765. trailers.push(position);
  3766. position += skipUntil(buffer, position, startxrefBytes);
  3767. } else {
  3768. position += token.length + 1;
  3769. }
  3770. }
  3771. // reading XRef streams
  3772. var i, ii;
  3773. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3774. this.startXRefQueue.push(xrefStms[i]);
  3775. this.readXRef(/* recoveryMode */ true);
  3776. }
  3777. // finding main trailer
  3778. var dict;
  3779. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3780. stream.pos = trailers[i];
  3781. var parser = new Parser(new Lexer(stream), true, this);
  3782. var obj = parser.getObj();
  3783. if (!isCmd(obj, 'trailer')) {
  3784. continue;
  3785. }
  3786. // read the trailer dictionary
  3787. if (!isDict(dict = parser.getObj())) {
  3788. continue;
  3789. }
  3790. // taking the first one with 'ID'
  3791. if (dict.has('ID')) {
  3792. return dict;
  3793. }
  3794. }
  3795. // no tailer with 'ID', taking last one (if exists)
  3796. if (dict) {
  3797. return dict;
  3798. }
  3799. // nothing helps
  3800. // calling error() would reject worker with an UnknownErrorException.
  3801. throw new InvalidPDFException('Invalid PDF structure');
  3802. },
  3803. readXRef: function XRef_readXRef(recoveryMode) {
  3804. var stream = this.stream;
  3805. try {
  3806. while (this.startXRefQueue.length) {
  3807. var startXRef = this.startXRefQueue[0];
  3808. stream.pos = startXRef + stream.start;
  3809. var parser = new Parser(new Lexer(stream), true, this);
  3810. var obj = parser.getObj();
  3811. var dict;
  3812. // Get dictionary
  3813. if (isCmd(obj, 'xref')) {
  3814. // Parse end-of-file XRef
  3815. dict = this.processXRefTable(parser);
  3816. if (!this.topDict) {
  3817. this.topDict = dict;
  3818. }
  3819. // Recursively get other XRefs 'XRefStm', if any
  3820. obj = dict.get('XRefStm');
  3821. if (isInt(obj)) {
  3822. var pos = obj;
  3823. // ignore previously loaded xref streams
  3824. // (possible infinite recursion)
  3825. if (!(pos in this.xrefstms)) {
  3826. this.xrefstms[pos] = 1;
  3827. this.startXRefQueue.push(pos);
  3828. }
  3829. }
  3830. } else if (isInt(obj)) {
  3831. // Parse in-stream XRef
  3832. if (!isInt(parser.getObj()) ||
  3833. !isCmd(parser.getObj(), 'obj') ||
  3834. !isStream(obj = parser.getObj())) {
  3835. error('Invalid XRef stream');
  3836. }
  3837. dict = this.processXRefStream(obj);
  3838. if (!this.topDict) {
  3839. this.topDict = dict;
  3840. }
  3841. if (!dict) {
  3842. error('Failed to read XRef stream');
  3843. }
  3844. } else {
  3845. error('Invalid XRef stream header');
  3846. }
  3847. // Recursively get previous dictionary, if any
  3848. obj = dict.get('Prev');
  3849. if (isInt(obj)) {
  3850. this.startXRefQueue.push(obj);
  3851. } else if (isRef(obj)) {
  3852. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3853. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3854. this.startXRefQueue.push(obj.num);
  3855. }
  3856. this.startXRefQueue.shift();
  3857. }
  3858. return this.topDict;
  3859. } catch (e) {
  3860. if (e instanceof MissingDataException) {
  3861. throw e;
  3862. }
  3863. info('(while reading XRef): ' + e);
  3864. }
  3865. if (recoveryMode) {
  3866. return;
  3867. }
  3868. throw new XRefParseException();
  3869. },
  3870. getEntry: function XRef_getEntry(i) {
  3871. var xrefEntry = this.entries[i];
  3872. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3873. return xrefEntry;
  3874. }
  3875. return null;
  3876. },
  3877. fetchIfRef: function XRef_fetchIfRef(obj) {
  3878. if (!isRef(obj)) {
  3879. return obj;
  3880. }
  3881. return this.fetch(obj);
  3882. },
  3883. fetch: function XRef_fetch(ref, suppressEncryption) {
  3884. assert(isRef(ref), 'ref object is not a reference');
  3885. var num = ref.num;
  3886. if (num in this.cache) {
  3887. var cacheEntry = this.cache[num];
  3888. return cacheEntry;
  3889. }
  3890. var xrefEntry = this.getEntry(num);
  3891. // the referenced entry can be free
  3892. if (xrefEntry === null) {
  3893. return (this.cache[num] = null);
  3894. }
  3895. if (xrefEntry.uncompressed) {
  3896. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3897. } else {
  3898. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3899. }
  3900. if (isDict(xrefEntry)){
  3901. xrefEntry.objId = ref.toString();
  3902. } else if (isStream(xrefEntry)) {
  3903. xrefEntry.dict.objId = ref.toString();
  3904. }
  3905. return xrefEntry;
  3906. },
  3907. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3908. suppressEncryption) {
  3909. var gen = ref.gen;
  3910. var num = ref.num;
  3911. if (xrefEntry.gen !== gen) {
  3912. error('inconsistent generation in XRef');
  3913. }
  3914. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3915. this.stream.start);
  3916. var parser = new Parser(new Lexer(stream), true, this);
  3917. var obj1 = parser.getObj();
  3918. var obj2 = parser.getObj();
  3919. var obj3 = parser.getObj();
  3920. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3921. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3922. !isCmd(obj3)) {
  3923. error('bad XRef entry');
  3924. }
  3925. if (!isCmd(obj3, 'obj')) {
  3926. // some bad PDFs use "obj1234" and really mean 1234
  3927. if (obj3.cmd.indexOf('obj') === 0) {
  3928. num = parseInt(obj3.cmd.substring(3), 10);
  3929. if (!isNaN(num)) {
  3930. return num;
  3931. }
  3932. }
  3933. error('bad XRef entry');
  3934. }
  3935. if (this.encrypt && !suppressEncryption) {
  3936. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3937. } else {
  3938. xrefEntry = parser.getObj();
  3939. }
  3940. if (!isStream(xrefEntry)) {
  3941. this.cache[num] = xrefEntry;
  3942. }
  3943. return xrefEntry;
  3944. },
  3945. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3946. suppressEncryption) {
  3947. var tableOffset = xrefEntry.offset;
  3948. var stream = this.fetch(new Ref(tableOffset, 0));
  3949. if (!isStream(stream)) {
  3950. error('bad ObjStm stream');
  3951. }
  3952. var first = stream.dict.get('First');
  3953. var n = stream.dict.get('N');
  3954. if (!isInt(first) || !isInt(n)) {
  3955. error('invalid first and n parameters for ObjStm stream');
  3956. }
  3957. var parser = new Parser(new Lexer(stream), false, this);
  3958. parser.allowStreams = true;
  3959. var i, entries = [], num, nums = [];
  3960. // read the object numbers to populate cache
  3961. for (i = 0; i < n; ++i) {
  3962. num = parser.getObj();
  3963. if (!isInt(num)) {
  3964. error('invalid object number in the ObjStm stream: ' + num);
  3965. }
  3966. nums.push(num);
  3967. var offset = parser.getObj();
  3968. if (!isInt(offset)) {
  3969. error('invalid object offset in the ObjStm stream: ' + offset);
  3970. }
  3971. }
  3972. // read stream objects for cache
  3973. for (i = 0; i < n; ++i) {
  3974. entries.push(parser.getObj());
  3975. num = nums[i];
  3976. var entry = this.entries[num];
  3977. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3978. this.cache[num] = entries[i];
  3979. }
  3980. }
  3981. xrefEntry = entries[xrefEntry.gen];
  3982. if (xrefEntry === undefined) {
  3983. error('bad XRef entry for compressed object');
  3984. }
  3985. return xrefEntry;
  3986. },
  3987. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3988. if (!isRef(obj)) {
  3989. return Promise.resolve(obj);
  3990. }
  3991. return this.fetchAsync(obj);
  3992. },
  3993. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3994. var streamManager = this.stream.manager;
  3995. var xref = this;
  3996. return new Promise(function tryFetch(resolve, reject) {
  3997. try {
  3998. resolve(xref.fetch(ref, suppressEncryption));
  3999. } catch (e) {
  4000. if (e instanceof MissingDataException) {
  4001. streamManager.requestRange(e.begin, e.end).then(function () {
  4002. tryFetch(resolve, reject);
  4003. }, reject);
  4004. return;
  4005. }
  4006. reject(e);
  4007. }
  4008. });
  4009. },
  4010. getCatalogObj: function XRef_getCatalogObj() {
  4011. return this.root;
  4012. }
  4013. };
  4014. return XRef;
  4015. })();
  4016. /**
  4017. * A NameTree is like a Dict but has some advantageous properties, see the
  4018. * spec (7.9.6) for more details.
  4019. * TODO: implement all the Dict functions and make this more efficent.
  4020. */
  4021. var NameTree = (function NameTreeClosure() {
  4022. function NameTree(root, xref) {
  4023. this.root = root;
  4024. this.xref = xref;
  4025. }
  4026. NameTree.prototype = {
  4027. getAll: function NameTree_getAll() {
  4028. var dict = {};
  4029. if (!this.root) {
  4030. return dict;
  4031. }
  4032. var xref = this.xref;
  4033. // reading name tree
  4034. var processed = new RefSet();
  4035. processed.put(this.root);
  4036. var queue = [this.root];
  4037. while (queue.length > 0) {
  4038. var i, n;
  4039. var obj = xref.fetchIfRef(queue.shift());
  4040. if (!isDict(obj)) {
  4041. continue;
  4042. }
  4043. if (obj.has('Kids')) {
  4044. var kids = obj.get('Kids');
  4045. for (i = 0, n = kids.length; i < n; i++) {
  4046. var kid = kids[i];
  4047. if (processed.has(kid)) {
  4048. error('invalid destinations');
  4049. }
  4050. queue.push(kid);
  4051. processed.put(kid);
  4052. }
  4053. continue;
  4054. }
  4055. var names = obj.get('Names');
  4056. if (names) {
  4057. for (i = 0, n = names.length; i < n; i += 2) {
  4058. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  4059. }
  4060. }
  4061. }
  4062. return dict;
  4063. },
  4064. get: function NameTree_get(destinationId) {
  4065. if (!this.root) {
  4066. return null;
  4067. }
  4068. var xref = this.xref;
  4069. var kidsOrNames = xref.fetchIfRef(this.root);
  4070. var loopCount = 0;
  4071. var MAX_NAMES_LEVELS = 10;
  4072. var l, r, m;
  4073. // Perform a binary search to quickly find the entry that
  4074. // contains the named destination we are looking for.
  4075. while (kidsOrNames.has('Kids')) {
  4076. loopCount++;
  4077. if (loopCount > MAX_NAMES_LEVELS) {
  4078. warn('Search depth limit for named destionations has been reached.');
  4079. return null;
  4080. }
  4081. var kids = kidsOrNames.get('Kids');
  4082. if (!isArray(kids)) {
  4083. return null;
  4084. }
  4085. l = 0;
  4086. r = kids.length - 1;
  4087. while (l <= r) {
  4088. m = (l + r) >> 1;
  4089. var kid = xref.fetchIfRef(kids[m]);
  4090. var limits = kid.get('Limits');
  4091. if (destinationId < xref.fetchIfRef(limits[0])) {
  4092. r = m - 1;
  4093. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  4094. l = m + 1;
  4095. } else {
  4096. kidsOrNames = xref.fetchIfRef(kids[m]);
  4097. break;
  4098. }
  4099. }
  4100. if (l > r) {
  4101. return null;
  4102. }
  4103. }
  4104. // If we get here, then we have found the right entry. Now
  4105. // go through the named destinations in the Named dictionary
  4106. // until we find the exact destination we're looking for.
  4107. var names = kidsOrNames.get('Names');
  4108. if (isArray(names)) {
  4109. // Perform a binary search to reduce the lookup time.
  4110. l = 0;
  4111. r = names.length - 2;
  4112. while (l <= r) {
  4113. // Check only even indices (0, 2, 4, ...) because the
  4114. // odd indices contain the actual D array.
  4115. m = (l + r) & ~1;
  4116. if (destinationId < xref.fetchIfRef(names[m])) {
  4117. r = m - 2;
  4118. } else if (destinationId > xref.fetchIfRef(names[m])) {
  4119. l = m + 2;
  4120. } else {
  4121. return xref.fetchIfRef(names[m + 1]);
  4122. }
  4123. }
  4124. }
  4125. return null;
  4126. }
  4127. };
  4128. return NameTree;
  4129. })();
  4130. /**
  4131. * "A PDF file can refer to the contents of another file by using a File
  4132. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4133. * NOTE: Only embedded files are supported (as part of the attachments support)
  4134. * TODO: support the 'URL' file system (with caching if !/V), portable
  4135. * collections attributes and related files (/RF)
  4136. */
  4137. var FileSpec = (function FileSpecClosure() {
  4138. function FileSpec(root, xref) {
  4139. if (!root || !isDict(root)) {
  4140. return;
  4141. }
  4142. this.xref = xref;
  4143. this.root = root;
  4144. if (root.has('FS')) {
  4145. this.fs = root.get('FS');
  4146. }
  4147. this.description = root.has('Desc') ?
  4148. stringToPDFString(root.get('Desc')) :
  4149. '';
  4150. if (root.has('RF')) {
  4151. warn('Related file specifications are not supported');
  4152. }
  4153. this.contentAvailable = true;
  4154. if (!root.has('EF')) {
  4155. this.contentAvailable = false;
  4156. warn('Non-embedded file specifications are not supported');
  4157. }
  4158. }
  4159. function pickPlatformItem(dict) {
  4160. // Look for the filename in this order:
  4161. // UF, F, Unix, Mac, DOS
  4162. if (dict.has('UF')) {
  4163. return dict.get('UF');
  4164. } else if (dict.has('F')) {
  4165. return dict.get('F');
  4166. } else if (dict.has('Unix')) {
  4167. return dict.get('Unix');
  4168. } else if (dict.has('Mac')) {
  4169. return dict.get('Mac');
  4170. } else if (dict.has('DOS')) {
  4171. return dict.get('DOS');
  4172. } else {
  4173. return null;
  4174. }
  4175. }
  4176. FileSpec.prototype = {
  4177. get filename() {
  4178. if (!this._filename && this.root) {
  4179. var filename = pickPlatformItem(this.root) || 'unnamed';
  4180. this._filename = stringToPDFString(filename).
  4181. replace(/\\\\/g, '\\').
  4182. replace(/\\\//g, '/').
  4183. replace(/\\/g, '/');
  4184. }
  4185. return this._filename;
  4186. },
  4187. get content() {
  4188. if (!this.contentAvailable) {
  4189. return null;
  4190. }
  4191. if (!this.contentRef && this.root) {
  4192. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4193. }
  4194. var content = null;
  4195. if (this.contentRef) {
  4196. var xref = this.xref;
  4197. var fileObj = xref.fetchIfRef(this.contentRef);
  4198. if (fileObj && isStream(fileObj)) {
  4199. content = fileObj.getBytes();
  4200. } else {
  4201. warn('Embedded file specification points to non-existing/invalid ' +
  4202. 'content');
  4203. }
  4204. } else {
  4205. warn('Embedded file specification does not have a content');
  4206. }
  4207. return content;
  4208. },
  4209. get serializable() {
  4210. return {
  4211. filename: this.filename,
  4212. content: this.content
  4213. };
  4214. }
  4215. };
  4216. return FileSpec;
  4217. })();
  4218. /**
  4219. * A helper for loading missing data in object graphs. It traverses the graph
  4220. * depth first and queues up any objects that have missing data. Once it has
  4221. * has traversed as many objects that are available it attempts to bundle the
  4222. * missing data requests and then resume from the nodes that weren't ready.
  4223. *
  4224. * NOTE: It provides protection from circular references by keeping track of
  4225. * of loaded references. However, you must be careful not to load any graphs
  4226. * that have references to the catalog or other pages since that will cause the
  4227. * entire PDF document object graph to be traversed.
  4228. */
  4229. var ObjectLoader = (function() {
  4230. function mayHaveChildren(value) {
  4231. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4232. }
  4233. function addChildren(node, nodesToVisit) {
  4234. var value;
  4235. if (isDict(node) || isStream(node)) {
  4236. var map;
  4237. if (isDict(node)) {
  4238. map = node.map;
  4239. } else {
  4240. map = node.dict.map;
  4241. }
  4242. for (var key in map) {
  4243. value = map[key];
  4244. if (mayHaveChildren(value)) {
  4245. nodesToVisit.push(value);
  4246. }
  4247. }
  4248. } else if (isArray(node)) {
  4249. for (var i = 0, ii = node.length; i < ii; i++) {
  4250. value = node[i];
  4251. if (mayHaveChildren(value)) {
  4252. nodesToVisit.push(value);
  4253. }
  4254. }
  4255. }
  4256. }
  4257. function ObjectLoader(obj, keys, xref) {
  4258. this.obj = obj;
  4259. this.keys = keys;
  4260. this.xref = xref;
  4261. this.refSet = null;
  4262. this.capability = null;
  4263. }
  4264. ObjectLoader.prototype = {
  4265. load: function ObjectLoader_load() {
  4266. var keys = this.keys;
  4267. this.capability = createPromiseCapability();
  4268. // Don't walk the graph if all the data is already loaded.
  4269. if (!(this.xref.stream instanceof ChunkedStream) ||
  4270. this.xref.stream.getMissingChunks().length === 0) {
  4271. this.capability.resolve();
  4272. return this.capability.promise;
  4273. }
  4274. this.refSet = new RefSet();
  4275. // Setup the initial nodes to visit.
  4276. var nodesToVisit = [];
  4277. for (var i = 0; i < keys.length; i++) {
  4278. nodesToVisit.push(this.obj[keys[i]]);
  4279. }
  4280. this._walk(nodesToVisit);
  4281. return this.capability.promise;
  4282. },
  4283. _walk: function ObjectLoader_walk(nodesToVisit) {
  4284. var nodesToRevisit = [];
  4285. var pendingRequests = [];
  4286. // DFS walk of the object graph.
  4287. while (nodesToVisit.length) {
  4288. var currentNode = nodesToVisit.pop();
  4289. // Only references or chunked streams can cause missing data exceptions.
  4290. if (isRef(currentNode)) {
  4291. // Skip nodes that have already been visited.
  4292. if (this.refSet.has(currentNode)) {
  4293. continue;
  4294. }
  4295. try {
  4296. var ref = currentNode;
  4297. this.refSet.put(ref);
  4298. currentNode = this.xref.fetch(currentNode);
  4299. } catch (e) {
  4300. if (!(e instanceof MissingDataException)) {
  4301. throw e;
  4302. }
  4303. nodesToRevisit.push(currentNode);
  4304. pendingRequests.push({ begin: e.begin, end: e.end });
  4305. }
  4306. }
  4307. if (currentNode && currentNode.getBaseStreams) {
  4308. var baseStreams = currentNode.getBaseStreams();
  4309. var foundMissingData = false;
  4310. for (var i = 0; i < baseStreams.length; i++) {
  4311. var stream = baseStreams[i];
  4312. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4313. foundMissingData = true;
  4314. pendingRequests.push({
  4315. begin: stream.start,
  4316. end: stream.end
  4317. });
  4318. }
  4319. }
  4320. if (foundMissingData) {
  4321. nodesToRevisit.push(currentNode);
  4322. }
  4323. }
  4324. addChildren(currentNode, nodesToVisit);
  4325. }
  4326. if (pendingRequests.length) {
  4327. this.xref.stream.manager.requestRanges(pendingRequests).then(
  4328. function pendingRequestCallback() {
  4329. nodesToVisit = nodesToRevisit;
  4330. for (var i = 0; i < nodesToRevisit.length; i++) {
  4331. var node = nodesToRevisit[i];
  4332. // Remove any reference nodes from the currrent refset so they
  4333. // aren't skipped when we revist them.
  4334. if (isRef(node)) {
  4335. this.refSet.remove(node);
  4336. }
  4337. }
  4338. this._walk(nodesToVisit);
  4339. }.bind(this), this.capability.reject);
  4340. return;
  4341. }
  4342. // Everything is loaded.
  4343. this.refSet = null;
  4344. this.capability.resolve();
  4345. }
  4346. };
  4347. return ObjectLoader;
  4348. })();
  4349. var ISOAdobeCharset = [
  4350. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4351. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4352. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4353. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4354. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4355. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4356. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4357. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4358. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4359. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4360. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4361. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4362. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4363. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4364. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4365. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4366. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4367. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4368. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4369. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4370. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4371. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4372. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4373. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4374. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4375. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4376. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4377. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4378. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4379. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4380. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4381. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4382. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4383. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4384. ];
  4385. var ExpertCharset = [
  4386. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4387. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4388. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4389. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4390. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4391. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4392. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4393. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4394. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4395. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4396. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4397. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4398. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4399. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4400. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4401. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4402. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4403. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4404. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4405. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4406. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4407. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4408. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4409. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4410. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4411. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4412. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4413. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4414. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4415. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4416. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4417. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4418. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4419. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4420. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4421. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4422. 'Ydieresissmall'
  4423. ];
  4424. var ExpertSubsetCharset = [
  4425. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4426. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4427. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4428. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4429. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4430. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4431. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4432. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4433. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4434. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4435. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4436. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4437. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4438. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4439. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4440. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4441. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4442. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4443. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4444. 'periodinferior', 'commainferior'
  4445. ];
  4446. var DEFAULT_ICON_SIZE = 22; // px
  4447. /**
  4448. * @class
  4449. * @alias AnnotationFactory
  4450. */
  4451. function AnnotationFactory() {}
  4452. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  4453. /**
  4454. * @param {XRef} xref
  4455. * @param {Object} ref
  4456. * @returns {Annotation}
  4457. */
  4458. create: function AnnotationFactory_create(xref, ref) {
  4459. var dict = xref.fetchIfRef(ref);
  4460. if (!isDict(dict)) {
  4461. return;
  4462. }
  4463. // Determine the annotation's subtype.
  4464. var subtype = dict.get('Subtype');
  4465. subtype = isName(subtype) ? subtype.name : '';
  4466. // Return the right annotation object based on the subtype and field type.
  4467. var parameters = {
  4468. dict: dict,
  4469. ref: ref
  4470. };
  4471. switch (subtype) {
  4472. case 'Link':
  4473. return new LinkAnnotation(parameters);
  4474. case 'Text':
  4475. return new TextAnnotation(parameters);
  4476. case 'Widget':
  4477. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4478. if (isName(fieldType) && fieldType.name === 'Tx') {
  4479. return new TextWidgetAnnotation(parameters);
  4480. }
  4481. return new WidgetAnnotation(parameters);
  4482. default:
  4483. warn('Unimplemented annotation type "' + subtype + '", ' +
  4484. 'falling back to base annotation');
  4485. return new Annotation(parameters);
  4486. }
  4487. }
  4488. };
  4489. var Annotation = (function AnnotationClosure() {
  4490. // 12.5.5: Algorithm: Appearance streams
  4491. function getTransformMatrix(rect, bbox, matrix) {
  4492. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4493. var minX = bounds[0];
  4494. var minY = bounds[1];
  4495. var maxX = bounds[2];
  4496. var maxY = bounds[3];
  4497. if (minX === maxX || minY === maxY) {
  4498. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4499. // just apply the transform for rect
  4500. return [1, 0, 0, 1, rect[0], rect[1]];
  4501. }
  4502. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4503. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4504. return [
  4505. xRatio,
  4506. 0,
  4507. 0,
  4508. yRatio,
  4509. rect[0] - minX * xRatio,
  4510. rect[1] - minY * yRatio
  4511. ];
  4512. }
  4513. function getDefaultAppearance(dict) {
  4514. var appearanceState = dict.get('AP');
  4515. if (!isDict(appearanceState)) {
  4516. return;
  4517. }
  4518. var appearance;
  4519. var appearances = appearanceState.get('N');
  4520. if (isDict(appearances)) {
  4521. var as = dict.get('AS');
  4522. if (as && appearances.has(as.name)) {
  4523. appearance = appearances.get(as.name);
  4524. }
  4525. } else {
  4526. appearance = appearances;
  4527. }
  4528. return appearance;
  4529. }
  4530. function Annotation(params) {
  4531. var dict = params.dict;
  4532. var data = this.data = {};
  4533. data.subtype = dict.get('Subtype').name;
  4534. data.annotationFlags = dict.get('F');
  4535. this.setRectangle(dict.get('Rect'));
  4536. data.rect = this.rectangle;
  4537. this.setColor(dict.get('C'));
  4538. data.color = this.color;
  4539. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  4540. this.setBorderStyle(dict);
  4541. this.appearance = getDefaultAppearance(dict);
  4542. data.hasAppearance = !!this.appearance;
  4543. data.id = params.ref.num;
  4544. }
  4545. Annotation.prototype = {
  4546. /**
  4547. * Set the rectangle.
  4548. *
  4549. * @public
  4550. * @memberof Annotation
  4551. * @param {Array} rectangle - The rectangle array with exactly four entries
  4552. */
  4553. setRectangle: function Annotation_setRectangle(rectangle) {
  4554. if (isArray(rectangle) && rectangle.length === 4) {
  4555. this.rectangle = Util.normalizeRect(rectangle);
  4556. } else {
  4557. this.rectangle = [0, 0, 0, 0];
  4558. }
  4559. },
  4560. /**
  4561. * Set the color and take care of color space conversion.
  4562. *
  4563. * @public
  4564. * @memberof Annotation
  4565. * @param {Array} color - The color array containing either 0
  4566. * (transparent), 1 (grayscale), 3 (RGB) or
  4567. * 4 (CMYK) elements
  4568. */
  4569. setColor: function Annotation_setColor(color) {
  4570. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  4571. if (!isArray(color)) {
  4572. this.color = rgbColor;
  4573. return;
  4574. }
  4575. switch (color.length) {
  4576. case 0: // Transparent, which we indicate with a null value
  4577. this.color = null;
  4578. break;
  4579. case 1: // Convert grayscale to RGB
  4580. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  4581. this.color = rgbColor;
  4582. break;
  4583. case 3: // Convert RGB percentages to RGB
  4584. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  4585. this.color = rgbColor;
  4586. break;
  4587. case 4: // Convert CMYK to RGB
  4588. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  4589. this.color = rgbColor;
  4590. break;
  4591. default:
  4592. this.color = rgbColor;
  4593. break;
  4594. }
  4595. },
  4596. /**
  4597. * Set the border style (as AnnotationBorderStyle object).
  4598. *
  4599. * @public
  4600. * @memberof Annotation
  4601. * @param {Dict} borderStyle - The border style dictionary
  4602. */
  4603. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  4604. if (!isDict(borderStyle)) {
  4605. return;
  4606. }
  4607. if (borderStyle.has('BS')) {
  4608. var dict = borderStyle.get('BS');
  4609. var dictType;
  4610. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  4611. dictType.name === 'Border')) {
  4612. this.borderStyle.setWidth(dict.get('W'));
  4613. this.borderStyle.setStyle(dict.get('S'));
  4614. this.borderStyle.setDashArray(dict.get('D'));
  4615. }
  4616. } else if (borderStyle.has('Border')) {
  4617. var array = borderStyle.get('Border');
  4618. if (isArray(array) && array.length >= 3) {
  4619. this.borderStyle.setHorizontalCornerRadius(array[0]);
  4620. this.borderStyle.setVerticalCornerRadius(array[1]);
  4621. this.borderStyle.setWidth(array[2]);
  4622. if (array.length === 4) { // Dash array available
  4623. this.borderStyle.setDashArray(array[3]);
  4624. }
  4625. }
  4626. } else {
  4627. // There are no border entries in the dictionary. According to the
  4628. // specification, we should draw a solid border of width 1 in that
  4629. // case, but Adobe Reader did not implement that part of the
  4630. // specification and instead draws no border at all, so we do the same.
  4631. // See also https://github.com/mozilla/pdf.js/issues/6179.
  4632. this.borderStyle.setWidth(0);
  4633. }
  4634. },
  4635. isInvisible: function Annotation_isInvisible() {
  4636. var data = this.data;
  4637. return !!(data &&
  4638. data.annotationFlags && // Default: not invisible
  4639. data.annotationFlags & 0x1); // Invisible
  4640. },
  4641. isViewable: function Annotation_isViewable() {
  4642. var data = this.data;
  4643. return !!(!this.isInvisible() &&
  4644. data &&
  4645. (!data.annotationFlags ||
  4646. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4647. data.rect); // rectangle is necessary
  4648. },
  4649. isPrintable: function Annotation_isPrintable() {
  4650. var data = this.data;
  4651. return !!(!this.isInvisible() &&
  4652. data &&
  4653. data.annotationFlags && // Default: not printable
  4654. data.annotationFlags & 0x4 && // Print
  4655. !(data.annotationFlags & 0x2) && // Hidden
  4656. data.rect); // rectangle is necessary
  4657. },
  4658. loadResources: function Annotation_loadResources(keys) {
  4659. return new Promise(function (resolve, reject) {
  4660. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4661. if (!resources) {
  4662. resolve();
  4663. return;
  4664. }
  4665. var objectLoader = new ObjectLoader(resources.map,
  4666. keys,
  4667. resources.xref);
  4668. objectLoader.load().then(function() {
  4669. resolve(resources);
  4670. }, reject);
  4671. }, reject);
  4672. }.bind(this));
  4673. },
  4674. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  4675. if (!this.appearance) {
  4676. return Promise.resolve(new OperatorList());
  4677. }
  4678. var data = this.data;
  4679. var appearanceDict = this.appearance.dict;
  4680. var resourcesPromise = this.loadResources([
  4681. 'ExtGState',
  4682. 'ColorSpace',
  4683. 'Pattern',
  4684. 'Shading',
  4685. 'XObject',
  4686. 'Font'
  4687. // ProcSet
  4688. // Properties
  4689. ]);
  4690. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4691. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4692. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4693. var self = this;
  4694. return resourcesPromise.then(function(resources) {
  4695. var opList = new OperatorList();
  4696. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4697. return evaluator.getOperatorList(self.appearance, task,
  4698. resources, opList).
  4699. then(function () {
  4700. opList.addOp(OPS.endAnnotation, []);
  4701. self.appearance.reset();
  4702. return opList;
  4703. });
  4704. });
  4705. }
  4706. };
  4707. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4708. annotations, opList, pdfManager, partialEvaluator, task, intent) {
  4709. function reject(e) {
  4710. annotationsReadyCapability.reject(e);
  4711. }
  4712. var annotationsReadyCapability = createPromiseCapability();
  4713. var annotationPromises = [];
  4714. for (var i = 0, n = annotations.length; i < n; ++i) {
  4715. if (intent === 'display' && annotations[i].isViewable() ||
  4716. intent === 'print' && annotations[i].isPrintable()) {
  4717. annotationPromises.push(
  4718. annotations[i].getOperatorList(partialEvaluator, task));
  4719. }
  4720. }
  4721. Promise.all(annotationPromises).then(function(datas) {
  4722. opList.addOp(OPS.beginAnnotations, []);
  4723. for (var i = 0, n = datas.length; i < n; ++i) {
  4724. var annotOpList = datas[i];
  4725. opList.addOpList(annotOpList);
  4726. }
  4727. opList.addOp(OPS.endAnnotations, []);
  4728. annotationsReadyCapability.resolve();
  4729. }, reject);
  4730. return annotationsReadyCapability.promise;
  4731. };
  4732. return Annotation;
  4733. })();
  4734. /**
  4735. * Contains all data regarding an annotation's border style.
  4736. *
  4737. * @class
  4738. */
  4739. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  4740. /**
  4741. * @constructor
  4742. * @private
  4743. */
  4744. function AnnotationBorderStyle() {
  4745. this.width = 1;
  4746. this.style = AnnotationBorderStyleType.SOLID;
  4747. this.dashArray = [3];
  4748. this.horizontalCornerRadius = 0;
  4749. this.verticalCornerRadius = 0;
  4750. }
  4751. AnnotationBorderStyle.prototype = {
  4752. /**
  4753. * Set the width.
  4754. *
  4755. * @public
  4756. * @memberof AnnotationBorderStyle
  4757. * @param {integer} width - The width
  4758. */
  4759. setWidth: function AnnotationBorderStyle_setWidth(width) {
  4760. if (width === (width | 0)) {
  4761. this.width = width;
  4762. }
  4763. },
  4764. /**
  4765. * Set the style.
  4766. *
  4767. * @public
  4768. * @memberof AnnotationBorderStyle
  4769. * @param {Object} style - The style object
  4770. * @see {@link shared/util.js}
  4771. */
  4772. setStyle: function AnnotationBorderStyle_setStyle(style) {
  4773. if (!style) {
  4774. return;
  4775. }
  4776. switch (style.name) {
  4777. case 'S':
  4778. this.style = AnnotationBorderStyleType.SOLID;
  4779. break;
  4780. case 'D':
  4781. this.style = AnnotationBorderStyleType.DASHED;
  4782. break;
  4783. case 'B':
  4784. this.style = AnnotationBorderStyleType.BEVELED;
  4785. break;
  4786. case 'I':
  4787. this.style = AnnotationBorderStyleType.INSET;
  4788. break;
  4789. case 'U':
  4790. this.style = AnnotationBorderStyleType.UNDERLINE;
  4791. break;
  4792. default:
  4793. break;
  4794. }
  4795. },
  4796. /**
  4797. * Set the dash array.
  4798. *
  4799. * @public
  4800. * @memberof AnnotationBorderStyle
  4801. * @param {Array} dashArray - The dash array with at least one element
  4802. */
  4803. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  4804. // We validate the dash array, but we do not use it because CSS does not
  4805. // allow us to change spacing of dashes. For more information, visit
  4806. // http://www.w3.org/TR/css3-background/#the-border-style.
  4807. if (isArray(dashArray) && dashArray.length > 0) {
  4808. // According to the PDF specification: the elements in a dashArray
  4809. // shall be numbers that are nonnegative and not all equal to zero.
  4810. var isValid = true;
  4811. var allZeros = true;
  4812. for (var i = 0, len = dashArray.length; i < len; i++) {
  4813. var element = dashArray[i];
  4814. var validNumber = (+element >= 0);
  4815. if (!validNumber) {
  4816. isValid = false;
  4817. break;
  4818. } else if (element > 0) {
  4819. allZeros = false;
  4820. }
  4821. }
  4822. if (isValid && !allZeros) {
  4823. this.dashArray = dashArray;
  4824. } else {
  4825. this.width = 0; // Adobe behavior when the array is invalid.
  4826. }
  4827. } else if (dashArray) {
  4828. this.width = 0; // Adobe behavior when the array is invalid.
  4829. }
  4830. },
  4831. /**
  4832. * Set the horizontal corner radius (from a Border dictionary).
  4833. *
  4834. * @public
  4835. * @memberof AnnotationBorderStyle
  4836. * @param {integer} radius - The horizontal corner radius
  4837. */
  4838. setHorizontalCornerRadius:
  4839. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  4840. if (radius === (radius | 0)) {
  4841. this.horizontalCornerRadius = radius;
  4842. }
  4843. },
  4844. /**
  4845. * Set the vertical corner radius (from a Border dictionary).
  4846. *
  4847. * @public
  4848. * @memberof AnnotationBorderStyle
  4849. * @param {integer} radius - The vertical corner radius
  4850. */
  4851. setVerticalCornerRadius:
  4852. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  4853. if (radius === (radius | 0)) {
  4854. this.verticalCornerRadius = radius;
  4855. }
  4856. }
  4857. };
  4858. return AnnotationBorderStyle;
  4859. })();
  4860. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4861. function WidgetAnnotation(params) {
  4862. Annotation.call(this, params);
  4863. var dict = params.dict;
  4864. var data = this.data;
  4865. data.fieldValue = stringToPDFString(
  4866. Util.getInheritableProperty(dict, 'V') || '');
  4867. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4868. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4869. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4870. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4871. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4872. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4873. // Building the full field name by collecting the field and
  4874. // its ancestors 'T' data and joining them using '.'.
  4875. var fieldName = [];
  4876. var namedItem = dict;
  4877. var ref = params.ref;
  4878. while (namedItem) {
  4879. var parent = namedItem.get('Parent');
  4880. var parentRef = namedItem.getRaw('Parent');
  4881. var name = namedItem.get('T');
  4882. if (name) {
  4883. fieldName.unshift(stringToPDFString(name));
  4884. } else if (parent && ref) {
  4885. // The field name is absent, that means more than one field
  4886. // with the same name may exist. Replacing the empty name
  4887. // with the '`' plus index in the parent's 'Kids' array.
  4888. // This is not in the PDF spec but necessary to id the
  4889. // the input controls.
  4890. var kids = parent.get('Kids');
  4891. var j, jj;
  4892. for (j = 0, jj = kids.length; j < jj; j++) {
  4893. var kidRef = kids[j];
  4894. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4895. break;
  4896. }
  4897. }
  4898. fieldName.unshift('`' + j);
  4899. }
  4900. namedItem = parent;
  4901. ref = parentRef;
  4902. }
  4903. data.fullName = fieldName.join('.');
  4904. }
  4905. var parent = Annotation.prototype;
  4906. Util.inherit(WidgetAnnotation, Annotation, {
  4907. isViewable: function WidgetAnnotation_isViewable() {
  4908. if (this.data.fieldType === 'Sig') {
  4909. warn('unimplemented annotation type: Widget signature');
  4910. return false;
  4911. }
  4912. return parent.isViewable.call(this);
  4913. }
  4914. });
  4915. return WidgetAnnotation;
  4916. })();
  4917. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4918. function TextWidgetAnnotation(params) {
  4919. WidgetAnnotation.call(this, params);
  4920. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4921. this.data.annotationType = AnnotationType.WIDGET;
  4922. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4923. }
  4924. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4925. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  4926. task) {
  4927. if (this.appearance) {
  4928. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  4929. }
  4930. var opList = new OperatorList();
  4931. var data = this.data;
  4932. // Even if there is an appearance stream, ignore it. This is the
  4933. // behaviour used by Adobe Reader.
  4934. if (!data.defaultAppearance) {
  4935. return Promise.resolve(opList);
  4936. }
  4937. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4938. return evaluator.getOperatorList(stream, task,
  4939. this.fieldResources, opList).
  4940. then(function () {
  4941. return opList;
  4942. });
  4943. }
  4944. });
  4945. return TextWidgetAnnotation;
  4946. })();
  4947. var TextAnnotation = (function TextAnnotationClosure() {
  4948. function TextAnnotation(params) {
  4949. Annotation.call(this, params);
  4950. var dict = params.dict;
  4951. var data = this.data;
  4952. var content = dict.get('Contents');
  4953. var title = dict.get('T');
  4954. data.annotationType = AnnotationType.TEXT;
  4955. data.content = stringToPDFString(content || '');
  4956. data.title = stringToPDFString(title || '');
  4957. data.hasHtml = true;
  4958. if (data.hasAppearance) {
  4959. data.name = 'NoIcon';
  4960. } else {
  4961. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4962. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4963. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4964. }
  4965. if (dict.has('C')) {
  4966. data.hasBgColor = true;
  4967. }
  4968. }
  4969. Util.inherit(TextAnnotation, Annotation, { });
  4970. return TextAnnotation;
  4971. })();
  4972. var LinkAnnotation = (function LinkAnnotationClosure() {
  4973. function LinkAnnotation(params) {
  4974. Annotation.call(this, params);
  4975. var dict = params.dict;
  4976. var data = this.data;
  4977. data.annotationType = AnnotationType.LINK;
  4978. data.hasHtml = true;
  4979. var action = dict.get('A');
  4980. if (action && isDict(action)) {
  4981. var linkType = action.get('S').name;
  4982. if (linkType === 'URI') {
  4983. var url = action.get('URI');
  4984. if (isName(url)) {
  4985. // Some bad PDFs do not put parentheses around relative URLs.
  4986. url = '/' + url.name;
  4987. } else if (url) {
  4988. url = addDefaultProtocolToUrl(url);
  4989. }
  4990. // TODO: pdf spec mentions urls can be relative to a Base
  4991. // entry in the dictionary.
  4992. if (!isValidUrl(url, false)) {
  4993. url = '';
  4994. }
  4995. // According to ISO 32000-1:2008, section 12.6.4.7,
  4996. // URI should to be encoded in 7-bit ASCII.
  4997. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4998. try {
  4999. data.url = stringToUTF8String(url);
  5000. } catch (e) {
  5001. // Fall back to a simple copy.
  5002. data.url = url;
  5003. }
  5004. } else if (linkType === 'GoTo') {
  5005. data.dest = action.get('D');
  5006. } else if (linkType === 'GoToR') {
  5007. var urlDict = action.get('F');
  5008. if (isDict(urlDict)) {
  5009. // We assume that the 'url' is a Filspec dictionary
  5010. // and fetch the url without checking any further
  5011. url = urlDict.get('F') || '';
  5012. }
  5013. // TODO: pdf reference says that GoToR
  5014. // can also have 'NewWindow' attribute
  5015. if (!isValidUrl(url, false)) {
  5016. url = '';
  5017. }
  5018. data.url = url;
  5019. data.dest = action.get('D');
  5020. } else if (linkType === 'Named') {
  5021. data.action = action.get('N').name;
  5022. } else {
  5023. warn('unrecognized link type: ' + linkType);
  5024. }
  5025. } else if (dict.has('Dest')) {
  5026. // simple destination link
  5027. var dest = dict.get('Dest');
  5028. data.dest = isName(dest) ? dest.name : dest;
  5029. }
  5030. }
  5031. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  5032. function addDefaultProtocolToUrl(url) {
  5033. if (url && url.indexOf('www.') === 0) {
  5034. return ('http://' + url);
  5035. }
  5036. return url;
  5037. }
  5038. Util.inherit(LinkAnnotation, Annotation, { });
  5039. return LinkAnnotation;
  5040. })();
  5041. var PDFFunction = (function PDFFunctionClosure() {
  5042. var CONSTRUCT_SAMPLED = 0;
  5043. var CONSTRUCT_INTERPOLATED = 2;
  5044. var CONSTRUCT_STICHED = 3;
  5045. var CONSTRUCT_POSTSCRIPT = 4;
  5046. return {
  5047. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  5048. str) {
  5049. var i, ii;
  5050. var length = 1;
  5051. for (i = 0, ii = size.length; i < ii; i++) {
  5052. length *= size[i];
  5053. }
  5054. length *= outputSize;
  5055. var array = new Array(length);
  5056. var codeSize = 0;
  5057. var codeBuf = 0;
  5058. // 32 is a valid bps so shifting won't work
  5059. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  5060. var strBytes = str.getBytes((length * bps + 7) / 8);
  5061. var strIdx = 0;
  5062. for (i = 0; i < length; i++) {
  5063. while (codeSize < bps) {
  5064. codeBuf <<= 8;
  5065. codeBuf |= strBytes[strIdx++];
  5066. codeSize += 8;
  5067. }
  5068. codeSize -= bps;
  5069. array[i] = (codeBuf >> codeSize) * sampleMul;
  5070. codeBuf &= (1 << codeSize) - 1;
  5071. }
  5072. return array;
  5073. },
  5074. getIR: function PDFFunction_getIR(xref, fn) {
  5075. var dict = fn.dict;
  5076. if (!dict) {
  5077. dict = fn;
  5078. }
  5079. var types = [this.constructSampled,
  5080. null,
  5081. this.constructInterpolated,
  5082. this.constructStiched,
  5083. this.constructPostScript];
  5084. var typeNum = dict.get('FunctionType');
  5085. var typeFn = types[typeNum];
  5086. if (!typeFn) {
  5087. error('Unknown type of function');
  5088. }
  5089. return typeFn.call(this, fn, dict, xref);
  5090. },
  5091. fromIR: function PDFFunction_fromIR(IR) {
  5092. var type = IR[0];
  5093. switch (type) {
  5094. case CONSTRUCT_SAMPLED:
  5095. return this.constructSampledFromIR(IR);
  5096. case CONSTRUCT_INTERPOLATED:
  5097. return this.constructInterpolatedFromIR(IR);
  5098. case CONSTRUCT_STICHED:
  5099. return this.constructStichedFromIR(IR);
  5100. //case CONSTRUCT_POSTSCRIPT:
  5101. default:
  5102. return this.constructPostScriptFromIR(IR);
  5103. }
  5104. },
  5105. parse: function PDFFunction_parse(xref, fn) {
  5106. var IR = this.getIR(xref, fn);
  5107. return this.fromIR(IR);
  5108. },
  5109. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  5110. if (!isArray(fnObj)) {
  5111. // not an array -- parsing as regular function
  5112. return this.parse(xref, fnObj);
  5113. }
  5114. var fnArray = [];
  5115. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  5116. var obj = xref.fetchIfRef(fnObj[j]);
  5117. fnArray.push(PDFFunction.parse(xref, obj));
  5118. }
  5119. return function (src, srcOffset, dest, destOffset) {
  5120. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  5121. fnArray[i](src, srcOffset, dest, destOffset + i);
  5122. }
  5123. };
  5124. },
  5125. constructSampled: function PDFFunction_constructSampled(str, dict) {
  5126. function toMultiArray(arr) {
  5127. var inputLength = arr.length;
  5128. var out = [];
  5129. var index = 0;
  5130. for (var i = 0; i < inputLength; i += 2) {
  5131. out[index] = [arr[i], arr[i + 1]];
  5132. ++index;
  5133. }
  5134. return out;
  5135. }
  5136. var domain = dict.get('Domain');
  5137. var range = dict.get('Range');
  5138. if (!domain || !range) {
  5139. error('No domain or range');
  5140. }
  5141. var inputSize = domain.length / 2;
  5142. var outputSize = range.length / 2;
  5143. domain = toMultiArray(domain);
  5144. range = toMultiArray(range);
  5145. var size = dict.get('Size');
  5146. var bps = dict.get('BitsPerSample');
  5147. var order = dict.get('Order') || 1;
  5148. if (order !== 1) {
  5149. // No description how cubic spline interpolation works in PDF32000:2008
  5150. // As in poppler, ignoring order, linear interpolation may work as good
  5151. info('No support for cubic spline interpolation: ' + order);
  5152. }
  5153. var encode = dict.get('Encode');
  5154. if (!encode) {
  5155. encode = [];
  5156. for (var i = 0; i < inputSize; ++i) {
  5157. encode.push(0);
  5158. encode.push(size[i] - 1);
  5159. }
  5160. }
  5161. encode = toMultiArray(encode);
  5162. var decode = dict.get('Decode');
  5163. if (!decode) {
  5164. decode = range;
  5165. } else {
  5166. decode = toMultiArray(decode);
  5167. }
  5168. var samples = this.getSampleArray(size, outputSize, bps, str);
  5169. return [
  5170. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  5171. outputSize, Math.pow(2, bps) - 1, range
  5172. ];
  5173. },
  5174. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  5175. // See chapter 3, page 109 of the PDF reference
  5176. function interpolate(x, xmin, xmax, ymin, ymax) {
  5177. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  5178. }
  5179. return function constructSampledFromIRResult(src, srcOffset,
  5180. dest, destOffset) {
  5181. // See chapter 3, page 110 of the PDF reference.
  5182. var m = IR[1];
  5183. var domain = IR[2];
  5184. var encode = IR[3];
  5185. var decode = IR[4];
  5186. var samples = IR[5];
  5187. var size = IR[6];
  5188. var n = IR[7];
  5189. //var mask = IR[8];
  5190. var range = IR[9];
  5191. // Building the cube vertices: its part and sample index
  5192. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5193. var cubeVertices = 1 << m;
  5194. var cubeN = new Float64Array(cubeVertices);
  5195. var cubeVertex = new Uint32Array(cubeVertices);
  5196. var i, j;
  5197. for (j = 0; j < cubeVertices; j++) {
  5198. cubeN[j] = 1;
  5199. }
  5200. var k = n, pos = 1;
  5201. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5202. for (i = 0; i < m; ++i) {
  5203. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5204. var domain_2i = domain[i][0];
  5205. var domain_2i_1 = domain[i][1];
  5206. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5207. domain_2i_1);
  5208. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5209. // Encode_2i, Encode_2i+1)
  5210. var e = interpolate(xi, domain_2i, domain_2i_1,
  5211. encode[i][0], encode[i][1]);
  5212. // e_i' = min(max(e_i, 0), Size_i - 1)
  5213. var size_i = size[i];
  5214. e = Math.min(Math.max(e, 0), size_i - 1);
  5215. // Adjusting the cube: N and vertex sample index
  5216. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5217. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5218. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5219. var offset0 = e0 * k;
  5220. var offset1 = offset0 + k; // e1 * k
  5221. for (j = 0; j < cubeVertices; j++) {
  5222. if (j & pos) {
  5223. cubeN[j] *= n1;
  5224. cubeVertex[j] += offset1;
  5225. } else {
  5226. cubeN[j] *= n0;
  5227. cubeVertex[j] += offset0;
  5228. }
  5229. }
  5230. k *= size_i;
  5231. pos <<= 1;
  5232. }
  5233. for (j = 0; j < n; ++j) {
  5234. // Sum all cube vertices' samples portions
  5235. var rj = 0;
  5236. for (i = 0; i < cubeVertices; i++) {
  5237. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5238. }
  5239. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5240. // Decode_2j, Decode_2j+1)
  5241. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5242. // y_j = min(max(r_j, range_2j), range_2j+1)
  5243. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5244. range[j][1]);
  5245. }
  5246. };
  5247. },
  5248. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5249. dict) {
  5250. var c0 = dict.get('C0') || [0];
  5251. var c1 = dict.get('C1') || [1];
  5252. var n = dict.get('N');
  5253. if (!isArray(c0) || !isArray(c1)) {
  5254. error('Illegal dictionary for interpolated function');
  5255. }
  5256. var length = c0.length;
  5257. var diff = [];
  5258. for (var i = 0; i < length; ++i) {
  5259. diff.push(c1[i] - c0[i]);
  5260. }
  5261. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5262. },
  5263. constructInterpolatedFromIR:
  5264. function PDFFunction_constructInterpolatedFromIR(IR) {
  5265. var c0 = IR[1];
  5266. var diff = IR[2];
  5267. var n = IR[3];
  5268. var length = diff.length;
  5269. return function constructInterpolatedFromIRResult(src, srcOffset,
  5270. dest, destOffset) {
  5271. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5272. for (var j = 0; j < length; ++j) {
  5273. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5274. }
  5275. };
  5276. },
  5277. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5278. var domain = dict.get('Domain');
  5279. if (!domain) {
  5280. error('No domain');
  5281. }
  5282. var inputSize = domain.length / 2;
  5283. if (inputSize !== 1) {
  5284. error('Bad domain for stiched function');
  5285. }
  5286. var fnRefs = dict.get('Functions');
  5287. var fns = [];
  5288. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5289. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5290. }
  5291. var bounds = dict.get('Bounds');
  5292. var encode = dict.get('Encode');
  5293. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5294. },
  5295. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5296. var domain = IR[1];
  5297. var bounds = IR[2];
  5298. var encode = IR[3];
  5299. var fnsIR = IR[4];
  5300. var fns = [];
  5301. var tmpBuf = new Float32Array(1);
  5302. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5303. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5304. }
  5305. return function constructStichedFromIRResult(src, srcOffset,
  5306. dest, destOffset) {
  5307. var clip = function constructStichedFromIRClip(v, min, max) {
  5308. if (v > max) {
  5309. v = max;
  5310. } else if (v < min) {
  5311. v = min;
  5312. }
  5313. return v;
  5314. };
  5315. // clip to domain
  5316. var v = clip(src[srcOffset], domain[0], domain[1]);
  5317. // calulate which bound the value is in
  5318. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5319. if (v < bounds[i]) {
  5320. break;
  5321. }
  5322. }
  5323. // encode value into domain of function
  5324. var dmin = domain[0];
  5325. if (i > 0) {
  5326. dmin = bounds[i - 1];
  5327. }
  5328. var dmax = domain[1];
  5329. if (i < bounds.length) {
  5330. dmax = bounds[i];
  5331. }
  5332. var rmin = encode[2 * i];
  5333. var rmax = encode[2 * i + 1];
  5334. // Prevent the value from becoming NaN as a result
  5335. // of division by zero (fixes issue6113.pdf).
  5336. tmpBuf[0] = dmin === dmax ? rmin :
  5337. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5338. // call the appropriate function
  5339. fns[i](tmpBuf, 0, dest, destOffset);
  5340. };
  5341. },
  5342. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5343. xref) {
  5344. var domain = dict.get('Domain');
  5345. var range = dict.get('Range');
  5346. if (!domain) {
  5347. error('No domain.');
  5348. }
  5349. if (!range) {
  5350. error('No range.');
  5351. }
  5352. var lexer = new PostScriptLexer(fn);
  5353. var parser = new PostScriptParser(lexer);
  5354. var code = parser.parse();
  5355. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5356. },
  5357. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5358. IR) {
  5359. var domain = IR[1];
  5360. var range = IR[2];
  5361. var code = IR[3];
  5362. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5363. if (compiled) {
  5364. // Compiled function consists of simple expressions such as addition,
  5365. // subtraction, Math.max, and also contains 'var' and 'return'
  5366. // statements. See the generation in the PostScriptCompiler below.
  5367. /*jshint -W054 */
  5368. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5369. }
  5370. info('Unable to compile PS function');
  5371. var numOutputs = range.length >> 1;
  5372. var numInputs = domain.length >> 1;
  5373. var evaluator = new PostScriptEvaluator(code);
  5374. // Cache the values for a big speed up, the cache size is limited though
  5375. // since the number of possible values can be huge from a PS function.
  5376. var cache = {};
  5377. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5378. // seen in our tests.
  5379. var MAX_CACHE_SIZE = 2048 * 4;
  5380. var cache_available = MAX_CACHE_SIZE;
  5381. var tmpBuf = new Float32Array(numInputs);
  5382. return function constructPostScriptFromIRResult(src, srcOffset,
  5383. dest, destOffset) {
  5384. var i, value;
  5385. var key = '';
  5386. var input = tmpBuf;
  5387. for (i = 0; i < numInputs; i++) {
  5388. value = src[srcOffset + i];
  5389. input[i] = value;
  5390. key += value + '_';
  5391. }
  5392. var cachedValue = cache[key];
  5393. if (cachedValue !== undefined) {
  5394. dest.set(cachedValue, destOffset);
  5395. return;
  5396. }
  5397. var output = new Float32Array(numOutputs);
  5398. var stack = evaluator.execute(input);
  5399. var stackIndex = stack.length - numOutputs;
  5400. for (i = 0; i < numOutputs; i++) {
  5401. value = stack[stackIndex + i];
  5402. var bound = range[i * 2];
  5403. if (value < bound) {
  5404. value = bound;
  5405. } else {
  5406. bound = range[i * 2 +1];
  5407. if (value > bound) {
  5408. value = bound;
  5409. }
  5410. }
  5411. output[i] = value;
  5412. }
  5413. if (cache_available > 0) {
  5414. cache_available--;
  5415. cache[key] = output;
  5416. }
  5417. dest.set(output, destOffset);
  5418. };
  5419. }
  5420. };
  5421. })();
  5422. function isPDFFunction(v) {
  5423. var fnDict;
  5424. if (typeof v !== 'object') {
  5425. return false;
  5426. } else if (isDict(v)) {
  5427. fnDict = v;
  5428. } else if (isStream(v)) {
  5429. fnDict = v.dict;
  5430. } else {
  5431. return false;
  5432. }
  5433. return fnDict.has('FunctionType');
  5434. }
  5435. var PostScriptStack = (function PostScriptStackClosure() {
  5436. var MAX_STACK_SIZE = 100;
  5437. function PostScriptStack(initialStack) {
  5438. this.stack = !initialStack ? [] :
  5439. Array.prototype.slice.call(initialStack, 0);
  5440. }
  5441. PostScriptStack.prototype = {
  5442. push: function PostScriptStack_push(value) {
  5443. if (this.stack.length >= MAX_STACK_SIZE) {
  5444. error('PostScript function stack overflow.');
  5445. }
  5446. this.stack.push(value);
  5447. },
  5448. pop: function PostScriptStack_pop() {
  5449. if (this.stack.length <= 0) {
  5450. error('PostScript function stack underflow.');
  5451. }
  5452. return this.stack.pop();
  5453. },
  5454. copy: function PostScriptStack_copy(n) {
  5455. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5456. error('PostScript function stack overflow.');
  5457. }
  5458. var stack = this.stack;
  5459. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5460. stack.push(stack[i]);
  5461. }
  5462. },
  5463. index: function PostScriptStack_index(n) {
  5464. this.push(this.stack[this.stack.length - n - 1]);
  5465. },
  5466. // rotate the last n stack elements p times
  5467. roll: function PostScriptStack_roll(n, p) {
  5468. var stack = this.stack;
  5469. var l = stack.length - n;
  5470. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5471. for (i = l, j = r; i < j; i++, j--) {
  5472. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5473. }
  5474. for (i = l, j = c - 1; i < j; i++, j--) {
  5475. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5476. }
  5477. for (i = c, j = r; i < j; i++, j--) {
  5478. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5479. }
  5480. }
  5481. };
  5482. return PostScriptStack;
  5483. })();
  5484. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5485. function PostScriptEvaluator(operators) {
  5486. this.operators = operators;
  5487. }
  5488. PostScriptEvaluator.prototype = {
  5489. execute: function PostScriptEvaluator_execute(initialStack) {
  5490. var stack = new PostScriptStack(initialStack);
  5491. var counter = 0;
  5492. var operators = this.operators;
  5493. var length = operators.length;
  5494. var operator, a, b;
  5495. while (counter < length) {
  5496. operator = operators[counter++];
  5497. if (typeof operator === 'number') {
  5498. // Operator is really an operand and should be pushed to the stack.
  5499. stack.push(operator);
  5500. continue;
  5501. }
  5502. switch (operator) {
  5503. // non standard ps operators
  5504. case 'jz': // jump if false
  5505. b = stack.pop();
  5506. a = stack.pop();
  5507. if (!a) {
  5508. counter = b;
  5509. }
  5510. break;
  5511. case 'j': // jump
  5512. a = stack.pop();
  5513. counter = a;
  5514. break;
  5515. // all ps operators in alphabetical order (excluding if/ifelse)
  5516. case 'abs':
  5517. a = stack.pop();
  5518. stack.push(Math.abs(a));
  5519. break;
  5520. case 'add':
  5521. b = stack.pop();
  5522. a = stack.pop();
  5523. stack.push(a + b);
  5524. break;
  5525. case 'and':
  5526. b = stack.pop();
  5527. a = stack.pop();
  5528. if (isBool(a) && isBool(b)) {
  5529. stack.push(a && b);
  5530. } else {
  5531. stack.push(a & b);
  5532. }
  5533. break;
  5534. case 'atan':
  5535. a = stack.pop();
  5536. stack.push(Math.atan(a));
  5537. break;
  5538. case 'bitshift':
  5539. b = stack.pop();
  5540. a = stack.pop();
  5541. if (a > 0) {
  5542. stack.push(a << b);
  5543. } else {
  5544. stack.push(a >> b);
  5545. }
  5546. break;
  5547. case 'ceiling':
  5548. a = stack.pop();
  5549. stack.push(Math.ceil(a));
  5550. break;
  5551. case 'copy':
  5552. a = stack.pop();
  5553. stack.copy(a);
  5554. break;
  5555. case 'cos':
  5556. a = stack.pop();
  5557. stack.push(Math.cos(a));
  5558. break;
  5559. case 'cvi':
  5560. a = stack.pop() | 0;
  5561. stack.push(a);
  5562. break;
  5563. case 'cvr':
  5564. // noop
  5565. break;
  5566. case 'div':
  5567. b = stack.pop();
  5568. a = stack.pop();
  5569. stack.push(a / b);
  5570. break;
  5571. case 'dup':
  5572. stack.copy(1);
  5573. break;
  5574. case 'eq':
  5575. b = stack.pop();
  5576. a = stack.pop();
  5577. stack.push(a === b);
  5578. break;
  5579. case 'exch':
  5580. stack.roll(2, 1);
  5581. break;
  5582. case 'exp':
  5583. b = stack.pop();
  5584. a = stack.pop();
  5585. stack.push(Math.pow(a, b));
  5586. break;
  5587. case 'false':
  5588. stack.push(false);
  5589. break;
  5590. case 'floor':
  5591. a = stack.pop();
  5592. stack.push(Math.floor(a));
  5593. break;
  5594. case 'ge':
  5595. b = stack.pop();
  5596. a = stack.pop();
  5597. stack.push(a >= b);
  5598. break;
  5599. case 'gt':
  5600. b = stack.pop();
  5601. a = stack.pop();
  5602. stack.push(a > b);
  5603. break;
  5604. case 'idiv':
  5605. b = stack.pop();
  5606. a = stack.pop();
  5607. stack.push((a / b) | 0);
  5608. break;
  5609. case 'index':
  5610. a = stack.pop();
  5611. stack.index(a);
  5612. break;
  5613. case 'le':
  5614. b = stack.pop();
  5615. a = stack.pop();
  5616. stack.push(a <= b);
  5617. break;
  5618. case 'ln':
  5619. a = stack.pop();
  5620. stack.push(Math.log(a));
  5621. break;
  5622. case 'log':
  5623. a = stack.pop();
  5624. stack.push(Math.log(a) / Math.LN10);
  5625. break;
  5626. case 'lt':
  5627. b = stack.pop();
  5628. a = stack.pop();
  5629. stack.push(a < b);
  5630. break;
  5631. case 'mod':
  5632. b = stack.pop();
  5633. a = stack.pop();
  5634. stack.push(a % b);
  5635. break;
  5636. case 'mul':
  5637. b = stack.pop();
  5638. a = stack.pop();
  5639. stack.push(a * b);
  5640. break;
  5641. case 'ne':
  5642. b = stack.pop();
  5643. a = stack.pop();
  5644. stack.push(a !== b);
  5645. break;
  5646. case 'neg':
  5647. a = stack.pop();
  5648. stack.push(-a);
  5649. break;
  5650. case 'not':
  5651. a = stack.pop();
  5652. if (isBool(a)) {
  5653. stack.push(!a);
  5654. } else {
  5655. stack.push(~a);
  5656. }
  5657. break;
  5658. case 'or':
  5659. b = stack.pop();
  5660. a = stack.pop();
  5661. if (isBool(a) && isBool(b)) {
  5662. stack.push(a || b);
  5663. } else {
  5664. stack.push(a | b);
  5665. }
  5666. break;
  5667. case 'pop':
  5668. stack.pop();
  5669. break;
  5670. case 'roll':
  5671. b = stack.pop();
  5672. a = stack.pop();
  5673. stack.roll(a, b);
  5674. break;
  5675. case 'round':
  5676. a = stack.pop();
  5677. stack.push(Math.round(a));
  5678. break;
  5679. case 'sin':
  5680. a = stack.pop();
  5681. stack.push(Math.sin(a));
  5682. break;
  5683. case 'sqrt':
  5684. a = stack.pop();
  5685. stack.push(Math.sqrt(a));
  5686. break;
  5687. case 'sub':
  5688. b = stack.pop();
  5689. a = stack.pop();
  5690. stack.push(a - b);
  5691. break;
  5692. case 'true':
  5693. stack.push(true);
  5694. break;
  5695. case 'truncate':
  5696. a = stack.pop();
  5697. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5698. stack.push(a);
  5699. break;
  5700. case 'xor':
  5701. b = stack.pop();
  5702. a = stack.pop();
  5703. if (isBool(a) && isBool(b)) {
  5704. stack.push(a !== b);
  5705. } else {
  5706. stack.push(a ^ b);
  5707. }
  5708. break;
  5709. default:
  5710. error('Unknown operator ' + operator);
  5711. break;
  5712. }
  5713. }
  5714. return stack.stack;
  5715. }
  5716. };
  5717. return PostScriptEvaluator;
  5718. })();
  5719. // Most of the PDFs functions consist of simple operations such as:
  5720. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5721. //
  5722. // We can compile most of such programs, and at the same moment, we can
  5723. // optimize some expressions using basic math properties. Keeping track of
  5724. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5725. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5726. function AstNode(type) {
  5727. this.type = type;
  5728. }
  5729. AstNode.prototype.visit = function (visitor) {
  5730. throw new Error('abstract method');
  5731. };
  5732. function AstArgument(index, min, max) {
  5733. AstNode.call(this, 'args');
  5734. this.index = index;
  5735. this.min = min;
  5736. this.max = max;
  5737. }
  5738. AstArgument.prototype = Object.create(AstNode.prototype);
  5739. AstArgument.prototype.visit = function (visitor) {
  5740. visitor.visitArgument(this);
  5741. };
  5742. function AstLiteral(number) {
  5743. AstNode.call(this, 'literal');
  5744. this.number = number;
  5745. this.min = number;
  5746. this.max = number;
  5747. }
  5748. AstLiteral.prototype = Object.create(AstNode.prototype);
  5749. AstLiteral.prototype.visit = function (visitor) {
  5750. visitor.visitLiteral(this);
  5751. };
  5752. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5753. AstNode.call(this, 'binary');
  5754. this.op = op;
  5755. this.arg1 = arg1;
  5756. this.arg2 = arg2;
  5757. this.min = min;
  5758. this.max = max;
  5759. }
  5760. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5761. AstBinaryOperation.prototype.visit = function (visitor) {
  5762. visitor.visitBinaryOperation(this);
  5763. };
  5764. function AstMin(arg, max) {
  5765. AstNode.call(this, 'max');
  5766. this.arg = arg;
  5767. this.min = arg.min;
  5768. this.max = max;
  5769. }
  5770. AstMin.prototype = Object.create(AstNode.prototype);
  5771. AstMin.prototype.visit = function (visitor) {
  5772. visitor.visitMin(this);
  5773. };
  5774. function AstVariable(index, min, max) {
  5775. AstNode.call(this, 'var');
  5776. this.index = index;
  5777. this.min = min;
  5778. this.max = max;
  5779. }
  5780. AstVariable.prototype = Object.create(AstNode.prototype);
  5781. AstVariable.prototype.visit = function (visitor) {
  5782. visitor.visitVariable(this);
  5783. };
  5784. function AstVariableDefinition(variable, arg) {
  5785. AstNode.call(this, 'definition');
  5786. this.variable = variable;
  5787. this.arg = arg;
  5788. }
  5789. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5790. AstVariableDefinition.prototype.visit = function (visitor) {
  5791. visitor.visitVariableDefinition(this);
  5792. };
  5793. function ExpressionBuilderVisitor() {
  5794. this.parts = [];
  5795. }
  5796. ExpressionBuilderVisitor.prototype = {
  5797. visitArgument: function (arg) {
  5798. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5799. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5800. },
  5801. visitVariable: function (variable) {
  5802. this.parts.push('v', variable.index);
  5803. },
  5804. visitLiteral: function (literal) {
  5805. this.parts.push(literal.number);
  5806. },
  5807. visitBinaryOperation: function (operation) {
  5808. this.parts.push('(');
  5809. operation.arg1.visit(this);
  5810. this.parts.push(' ', operation.op, ' ');
  5811. operation.arg2.visit(this);
  5812. this.parts.push(')');
  5813. },
  5814. visitVariableDefinition: function (definition) {
  5815. this.parts.push('var ');
  5816. definition.variable.visit(this);
  5817. this.parts.push(' = ');
  5818. definition.arg.visit(this);
  5819. this.parts.push(';');
  5820. },
  5821. visitMin: function (max) {
  5822. this.parts.push('Math.min(');
  5823. max.arg.visit(this);
  5824. this.parts.push(', ', max.max, ')');
  5825. },
  5826. toString: function () {
  5827. return this.parts.join('');
  5828. }
  5829. };
  5830. function buildAddOperation(num1, num2) {
  5831. if (num2.type === 'literal' && num2.number === 0) {
  5832. // optimization: second operand is 0
  5833. return num1;
  5834. }
  5835. if (num1.type === 'literal' && num1.number === 0) {
  5836. // optimization: first operand is 0
  5837. return num2;
  5838. }
  5839. if (num2.type === 'literal' && num1.type === 'literal') {
  5840. // optimization: operands operand are literals
  5841. return new AstLiteral(num1.number + num2.number);
  5842. }
  5843. return new AstBinaryOperation('+', num1, num2,
  5844. num1.min + num2.min, num1.max + num2.max);
  5845. }
  5846. function buildMulOperation(num1, num2) {
  5847. if (num2.type === 'literal') {
  5848. // optimization: second operands is a literal...
  5849. if (num2.number === 0) {
  5850. return new AstLiteral(0); // and it's 0
  5851. } else if (num2.number === 1) {
  5852. return num1; // and it's 1
  5853. } else if (num1.type === 'literal') {
  5854. // ... and first operands is a literal too
  5855. return new AstLiteral(num1.number * num2.number);
  5856. }
  5857. }
  5858. if (num1.type === 'literal') {
  5859. // optimization: first operands is a literal...
  5860. if (num1.number === 0) {
  5861. return new AstLiteral(0); // and it's 0
  5862. } else if (num1.number === 1) {
  5863. return num2; // and it's 1
  5864. }
  5865. }
  5866. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5867. num1.max * num2.min, num1.max * num2.max);
  5868. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5869. num1.max * num2.min, num1.max * num2.max);
  5870. return new AstBinaryOperation('*', num1, num2, min, max);
  5871. }
  5872. function buildSubOperation(num1, num2) {
  5873. if (num2.type === 'literal') {
  5874. // optimization: second operands is a literal...
  5875. if (num2.number === 0) {
  5876. return num1; // ... and it's 0
  5877. } else if (num1.type === 'literal') {
  5878. // ... and first operands is a literal too
  5879. return new AstLiteral(num1.number - num2.number);
  5880. }
  5881. }
  5882. if (num2.type === 'binary' && num2.op === '-' &&
  5883. num1.type === 'literal' && num1.number === 1 &&
  5884. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5885. // optimization for case: 1 - (1 - x)
  5886. return num2.arg2;
  5887. }
  5888. return new AstBinaryOperation('-', num1, num2,
  5889. num1.min - num2.max, num1.max - num2.min);
  5890. }
  5891. function buildMinOperation(num1, max) {
  5892. if (num1.min >= max) {
  5893. // optimization: num1 min value is not less than required max
  5894. return new AstLiteral(max); // just returning max
  5895. } else if (num1.max <= max) {
  5896. // optimization: num1 max value is not greater than required max
  5897. return num1; // just returning an argument
  5898. }
  5899. return new AstMin(num1, max);
  5900. }
  5901. function PostScriptCompiler() {}
  5902. PostScriptCompiler.prototype = {
  5903. compile: function PostScriptCompiler_compile(code, domain, range) {
  5904. var stack = [];
  5905. var i, ii;
  5906. var instructions = [];
  5907. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5908. var lastRegister = 0;
  5909. var n, j, min, max;
  5910. var num1, num2, ast1, ast2, tmpVar, item;
  5911. for (i = 0; i < inputSize; i++) {
  5912. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5913. }
  5914. for (i = 0, ii = code.length; i < ii; i++) {
  5915. item = code[i];
  5916. if (typeof item === 'number') {
  5917. stack.push(new AstLiteral(item));
  5918. continue;
  5919. }
  5920. switch (item) {
  5921. case 'add':
  5922. if (stack.length < 2) {
  5923. return null;
  5924. }
  5925. num2 = stack.pop();
  5926. num1 = stack.pop();
  5927. stack.push(buildAddOperation(num1, num2));
  5928. break;
  5929. case 'cvr':
  5930. if (stack.length < 1) {
  5931. return null;
  5932. }
  5933. break;
  5934. case 'mul':
  5935. if (stack.length < 2) {
  5936. return null;
  5937. }
  5938. num2 = stack.pop();
  5939. num1 = stack.pop();
  5940. stack.push(buildMulOperation(num1, num2));
  5941. break;
  5942. case 'sub':
  5943. if (stack.length < 2) {
  5944. return null;
  5945. }
  5946. num2 = stack.pop();
  5947. num1 = stack.pop();
  5948. stack.push(buildSubOperation(num1, num2));
  5949. break;
  5950. case 'exch':
  5951. if (stack.length < 2) {
  5952. return null;
  5953. }
  5954. ast1 = stack.pop(); ast2 = stack.pop();
  5955. stack.push(ast1, ast2);
  5956. break;
  5957. case 'pop':
  5958. if (stack.length < 1) {
  5959. return null;
  5960. }
  5961. stack.pop();
  5962. break;
  5963. case 'index':
  5964. if (stack.length < 1) {
  5965. return null;
  5966. }
  5967. num1 = stack.pop();
  5968. if (num1.type !== 'literal') {
  5969. return null;
  5970. }
  5971. n = num1.number;
  5972. if (n < 0 || (n|0) !== n || stack.length < n) {
  5973. return null;
  5974. }
  5975. ast1 = stack[stack.length - n - 1];
  5976. if (ast1.type === 'literal' || ast1.type === 'var') {
  5977. stack.push(ast1);
  5978. break;
  5979. }
  5980. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5981. stack[stack.length - n - 1] = tmpVar;
  5982. stack.push(tmpVar);
  5983. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5984. break;
  5985. case 'dup':
  5986. if (stack.length < 1) {
  5987. return null;
  5988. }
  5989. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5990. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5991. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5992. // special case of the commands sequence for the min operation
  5993. num1 = stack.pop();
  5994. stack.push(buildMinOperation(num1, code[i + 1]));
  5995. i += 6;
  5996. break;
  5997. }
  5998. ast1 = stack[stack.length - 1];
  5999. if (ast1.type === 'literal' || ast1.type === 'var') {
  6000. // we don't have to save into intermediate variable a literal or
  6001. // variable.
  6002. stack.push(ast1);
  6003. break;
  6004. }
  6005. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  6006. stack[stack.length - 1] = tmpVar;
  6007. stack.push(tmpVar);
  6008. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  6009. break;
  6010. case 'roll':
  6011. if (stack.length < 2) {
  6012. return null;
  6013. }
  6014. num2 = stack.pop();
  6015. num1 = stack.pop();
  6016. if (num2.type !== 'literal' || num1.type !== 'literal') {
  6017. // both roll operands must be numbers
  6018. return null;
  6019. }
  6020. j = num2.number;
  6021. n = num1.number;
  6022. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  6023. // ... and integers
  6024. return null;
  6025. }
  6026. j = ((j % n) + n) % n;
  6027. if (j === 0) {
  6028. break; // just skipping -- there are nothing to rotate
  6029. }
  6030. Array.prototype.push.apply(stack,
  6031. stack.splice(stack.length - n, n - j));
  6032. break;
  6033. default:
  6034. return null; // unsupported operator
  6035. }
  6036. }
  6037. if (stack.length !== outputSize) {
  6038. return null;
  6039. }
  6040. var result = [];
  6041. instructions.forEach(function (instruction) {
  6042. var statementBuilder = new ExpressionBuilderVisitor();
  6043. instruction.visit(statementBuilder);
  6044. result.push(statementBuilder.toString());
  6045. });
  6046. stack.forEach(function (expr, i) {
  6047. var statementBuilder = new ExpressionBuilderVisitor();
  6048. expr.visit(statementBuilder);
  6049. var min = range[i * 2], max = range[i * 2 + 1];
  6050. var out = [statementBuilder.toString()];
  6051. if (min > expr.min) {
  6052. out.unshift('Math.max(', min, ', ');
  6053. out.push(')');
  6054. }
  6055. if (max < expr.max) {
  6056. out.unshift('Math.min(', max, ', ');
  6057. out.push(')');
  6058. }
  6059. out.unshift('dest[destOffset + ', i, '] = ');
  6060. out.push(';');
  6061. result.push(out.join(''));
  6062. });
  6063. return result.join('\n');
  6064. }
  6065. };
  6066. return PostScriptCompiler;
  6067. })();
  6068. var ColorSpace = (function ColorSpaceClosure() {
  6069. // Constructor should define this.numComps, this.defaultColor, this.name
  6070. function ColorSpace() {
  6071. error('should not call ColorSpace constructor');
  6072. }
  6073. ColorSpace.prototype = {
  6074. /**
  6075. * Converts the color value to the RGB color. The color components are
  6076. * located in the src array starting from the srcOffset. Returns the array
  6077. * of the rgb components, each value ranging from [0,255].
  6078. */
  6079. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  6080. var rgb = new Uint8Array(3);
  6081. this.getRgbItem(src, srcOffset, rgb, 0);
  6082. return rgb;
  6083. },
  6084. /**
  6085. * Converts the color value to the RGB color, similar to the getRgb method.
  6086. * The result placed into the dest array starting from the destOffset.
  6087. */
  6088. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  6089. dest, destOffset) {
  6090. error('Should not call ColorSpace.getRgbItem');
  6091. },
  6092. /**
  6093. * Converts the specified number of the color values to the RGB colors.
  6094. * The colors are located in the src array starting from the srcOffset.
  6095. * The result is placed into the dest array starting from the destOffset.
  6096. * The src array items shall be in [0,2^bits) range, the dest array items
  6097. * will be in [0,255] range. alpha01 indicates how many alpha components
  6098. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  6099. * array).
  6100. */
  6101. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  6102. dest, destOffset, bits,
  6103. alpha01) {
  6104. error('Should not call ColorSpace.getRgbBuffer');
  6105. },
  6106. /**
  6107. * Determines the number of bytes required to store the result of the
  6108. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  6109. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  6110. */
  6111. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  6112. alpha01) {
  6113. error('Should not call ColorSpace.getOutputLength');
  6114. },
  6115. /**
  6116. * Returns true if source data will be equal the result/output data.
  6117. */
  6118. isPassthrough: function ColorSpace_isPassthrough(bits) {
  6119. return false;
  6120. },
  6121. /**
  6122. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  6123. * how many alpha components there are in the dest array; it will be either
  6124. * 0 (RGB array) or 1 (RGBA array).
  6125. */
  6126. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  6127. originalHeight, width, height,
  6128. actualHeight, bpc, comps, alpha01) {
  6129. var count = originalWidth * originalHeight;
  6130. var rgbBuf = null;
  6131. var numComponentColors = 1 << bpc;
  6132. var needsResizing = originalHeight !== height || originalWidth !== width;
  6133. var i, ii;
  6134. if (this.isPassthrough(bpc)) {
  6135. rgbBuf = comps;
  6136. } else if (this.numComps === 1 && count > numComponentColors &&
  6137. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  6138. // Optimization: create a color map when there is just one component and
  6139. // we are converting more colors than the size of the color map. We
  6140. // don't build the map if the colorspace is gray or rgb since those
  6141. // methods are faster than building a map. This mainly offers big speed
  6142. // ups for indexed and alternate colorspaces.
  6143. //
  6144. // TODO it may be worth while to cache the color map. While running
  6145. // testing I never hit a cache so I will leave that out for now (perhaps
  6146. // we are reparsing colorspaces too much?).
  6147. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  6148. new Uint16Array(numComponentColors);
  6149. var key;
  6150. for (i = 0; i < numComponentColors; i++) {
  6151. allColors[i] = i;
  6152. }
  6153. var colorMap = new Uint8Array(numComponentColors * 3);
  6154. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  6155. /* alpha01 = */ 0);
  6156. var destPos, rgbPos;
  6157. if (!needsResizing) {
  6158. // Fill in the RGB values directly into |dest|.
  6159. destPos = 0;
  6160. for (i = 0; i < count; ++i) {
  6161. key = comps[i] * 3;
  6162. dest[destPos++] = colorMap[key];
  6163. dest[destPos++] = colorMap[key + 1];
  6164. dest[destPos++] = colorMap[key + 2];
  6165. destPos += alpha01;
  6166. }
  6167. } else {
  6168. rgbBuf = new Uint8Array(count * 3);
  6169. rgbPos = 0;
  6170. for (i = 0; i < count; ++i) {
  6171. key = comps[i] * 3;
  6172. rgbBuf[rgbPos++] = colorMap[key];
  6173. rgbBuf[rgbPos++] = colorMap[key + 1];
  6174. rgbBuf[rgbPos++] = colorMap[key + 2];
  6175. }
  6176. }
  6177. } else {
  6178. if (!needsResizing) {
  6179. // Fill in the RGB values directly into |dest|.
  6180. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  6181. alpha01);
  6182. } else {
  6183. rgbBuf = new Uint8Array(count * 3);
  6184. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  6185. /* alpha01 = */ 0);
  6186. }
  6187. }
  6188. if (rgbBuf) {
  6189. if (needsResizing) {
  6190. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  6191. height, dest, alpha01);
  6192. } else {
  6193. rgbPos = 0;
  6194. destPos = 0;
  6195. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6196. dest[destPos++] = rgbBuf[rgbPos++];
  6197. dest[destPos++] = rgbBuf[rgbPos++];
  6198. dest[destPos++] = rgbBuf[rgbPos++];
  6199. destPos += alpha01;
  6200. }
  6201. }
  6202. }
  6203. },
  6204. /**
  6205. * True if the colorspace has components in the default range of [0, 1].
  6206. * This should be true for all colorspaces except for lab color spaces
  6207. * which are [0,100], [-128, 127], [-128, 127].
  6208. */
  6209. usesZeroToOneRange: true
  6210. };
  6211. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6212. var IR = ColorSpace.parseToIR(cs, xref, res);
  6213. if (IR instanceof AlternateCS) {
  6214. return IR;
  6215. }
  6216. return ColorSpace.fromIR(IR);
  6217. };
  6218. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6219. var name = isArray(IR) ? IR[0] : IR;
  6220. var whitePoint, blackPoint, gamma;
  6221. switch (name) {
  6222. case 'DeviceGrayCS':
  6223. return this.singletons.gray;
  6224. case 'DeviceRgbCS':
  6225. return this.singletons.rgb;
  6226. case 'DeviceCmykCS':
  6227. return this.singletons.cmyk;
  6228. case 'CalGrayCS':
  6229. whitePoint = IR[1].WhitePoint;
  6230. blackPoint = IR[1].BlackPoint;
  6231. gamma = IR[1].Gamma;
  6232. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6233. case 'CalRGBCS':
  6234. whitePoint = IR[1].WhitePoint;
  6235. blackPoint = IR[1].BlackPoint;
  6236. gamma = IR[1].Gamma;
  6237. var matrix = IR[1].Matrix;
  6238. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6239. case 'PatternCS':
  6240. var basePatternCS = IR[1];
  6241. if (basePatternCS) {
  6242. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6243. }
  6244. return new PatternCS(basePatternCS);
  6245. case 'IndexedCS':
  6246. var baseIndexedCS = IR[1];
  6247. var hiVal = IR[2];
  6248. var lookup = IR[3];
  6249. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6250. case 'AlternateCS':
  6251. var numComps = IR[1];
  6252. var alt = IR[2];
  6253. var tintFnIR = IR[3];
  6254. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6255. PDFFunction.fromIR(tintFnIR));
  6256. case 'LabCS':
  6257. whitePoint = IR[1].WhitePoint;
  6258. blackPoint = IR[1].BlackPoint;
  6259. var range = IR[1].Range;
  6260. return new LabCS(whitePoint, blackPoint, range);
  6261. default:
  6262. error('Unknown name ' + name);
  6263. }
  6264. return null;
  6265. };
  6266. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6267. if (isName(cs)) {
  6268. var colorSpaces = res.get('ColorSpace');
  6269. if (isDict(colorSpaces)) {
  6270. var refcs = colorSpaces.get(cs.name);
  6271. if (refcs) {
  6272. cs = refcs;
  6273. }
  6274. }
  6275. }
  6276. cs = xref.fetchIfRef(cs);
  6277. var mode;
  6278. if (isName(cs)) {
  6279. mode = cs.name;
  6280. this.mode = mode;
  6281. switch (mode) {
  6282. case 'DeviceGray':
  6283. case 'G':
  6284. return 'DeviceGrayCS';
  6285. case 'DeviceRGB':
  6286. case 'RGB':
  6287. return 'DeviceRgbCS';
  6288. case 'DeviceCMYK':
  6289. case 'CMYK':
  6290. return 'DeviceCmykCS';
  6291. case 'Pattern':
  6292. return ['PatternCS', null];
  6293. default:
  6294. error('unrecognized colorspace ' + mode);
  6295. }
  6296. } else if (isArray(cs)) {
  6297. mode = xref.fetchIfRef(cs[0]).name;
  6298. this.mode = mode;
  6299. var numComps, params, alt;
  6300. switch (mode) {
  6301. case 'DeviceGray':
  6302. case 'G':
  6303. return 'DeviceGrayCS';
  6304. case 'DeviceRGB':
  6305. case 'RGB':
  6306. return 'DeviceRgbCS';
  6307. case 'DeviceCMYK':
  6308. case 'CMYK':
  6309. return 'DeviceCmykCS';
  6310. case 'CalGray':
  6311. params = xref.fetchIfRef(cs[1]).getAll();
  6312. return ['CalGrayCS', params];
  6313. case 'CalRGB':
  6314. params = xref.fetchIfRef(cs[1]).getAll();
  6315. return ['CalRGBCS', params];
  6316. case 'ICCBased':
  6317. var stream = xref.fetchIfRef(cs[1]);
  6318. var dict = stream.dict;
  6319. numComps = dict.get('N');
  6320. alt = dict.get('Alternate');
  6321. if (alt) {
  6322. var altIR = ColorSpace.parseToIR(alt, xref, res);
  6323. // Parse the /Alternate CS to ensure that the number of components
  6324. // are correct, and also (indirectly) that it is not a PatternCS.
  6325. var altCS = ColorSpace.fromIR(altIR);
  6326. if (altCS.numComps === numComps) {
  6327. return altIR;
  6328. }
  6329. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  6330. }
  6331. if (numComps === 1) {
  6332. return 'DeviceGrayCS';
  6333. } else if (numComps === 3) {
  6334. return 'DeviceRgbCS';
  6335. } else if (numComps === 4) {
  6336. return 'DeviceCmykCS';
  6337. }
  6338. break;
  6339. case 'Pattern':
  6340. var basePatternCS = cs[1] || null;
  6341. if (basePatternCS) {
  6342. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6343. }
  6344. return ['PatternCS', basePatternCS];
  6345. case 'Indexed':
  6346. case 'I':
  6347. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6348. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  6349. var lookup = xref.fetchIfRef(cs[3]);
  6350. if (isStream(lookup)) {
  6351. lookup = lookup.getBytes();
  6352. }
  6353. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6354. case 'Separation':
  6355. case 'DeviceN':
  6356. var name = xref.fetchIfRef(cs[1]);
  6357. numComps = 1;
  6358. if (isName(name)) {
  6359. numComps = 1;
  6360. } else if (isArray(name)) {
  6361. numComps = name.length;
  6362. }
  6363. alt = ColorSpace.parseToIR(cs[2], xref, res);
  6364. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6365. return ['AlternateCS', numComps, alt, tintFnIR];
  6366. case 'Lab':
  6367. params = xref.fetchIfRef(cs[1]).getAll();
  6368. return ['LabCS', params];
  6369. default:
  6370. error('unimplemented color space object "' + mode + '"');
  6371. }
  6372. } else {
  6373. error('unrecognized color space object: "' + cs + '"');
  6374. }
  6375. return null;
  6376. };
  6377. /**
  6378. * Checks if a decode map matches the default decode map for a color space.
  6379. * This handles the general decode maps where there are two values per
  6380. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6381. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6382. * slightly different.
  6383. * @param {Array} decode Decode map (usually from an image).
  6384. * @param {Number} n Number of components the color space has.
  6385. */
  6386. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6387. if (!isArray(decode)) {
  6388. return true;
  6389. }
  6390. if (n * 2 !== decode.length) {
  6391. warn('The decode map is not the correct length');
  6392. return true;
  6393. }
  6394. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6395. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6396. return false;
  6397. }
  6398. }
  6399. return true;
  6400. };
  6401. ColorSpace.singletons = {
  6402. get gray() {
  6403. return shadow(this, 'gray', new DeviceGrayCS());
  6404. },
  6405. get rgb() {
  6406. return shadow(this, 'rgb', new DeviceRgbCS());
  6407. },
  6408. get cmyk() {
  6409. return shadow(this, 'cmyk', new DeviceCmykCS());
  6410. }
  6411. };
  6412. return ColorSpace;
  6413. })();
  6414. /**
  6415. * Alternate color space handles both Separation and DeviceN color spaces. A
  6416. * Separation color space is actually just a DeviceN with one color component.
  6417. * Both color spaces use a tinting function to convert colors to a base color
  6418. * space.
  6419. */
  6420. var AlternateCS = (function AlternateCSClosure() {
  6421. function AlternateCS(numComps, base, tintFn) {
  6422. this.name = 'Alternate';
  6423. this.numComps = numComps;
  6424. this.defaultColor = new Float32Array(numComps);
  6425. for (var i = 0; i < numComps; ++i) {
  6426. this.defaultColor[i] = 1;
  6427. }
  6428. this.base = base;
  6429. this.tintFn = tintFn;
  6430. this.tmpBuf = new Float32Array(base.numComps);
  6431. }
  6432. AlternateCS.prototype = {
  6433. getRgb: ColorSpace.prototype.getRgb,
  6434. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6435. dest, destOffset) {
  6436. var tmpBuf = this.tmpBuf;
  6437. this.tintFn(src, srcOffset, tmpBuf, 0);
  6438. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6439. },
  6440. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6441. dest, destOffset, bits,
  6442. alpha01) {
  6443. var tintFn = this.tintFn;
  6444. var base = this.base;
  6445. var scale = 1 / ((1 << bits) - 1);
  6446. var baseNumComps = base.numComps;
  6447. var usesZeroToOneRange = base.usesZeroToOneRange;
  6448. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6449. alpha01 === 0;
  6450. var pos = isPassthrough ? destOffset : 0;
  6451. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6452. var numComps = this.numComps;
  6453. var scaled = new Float32Array(numComps);
  6454. var tinted = new Float32Array(baseNumComps);
  6455. var i, j;
  6456. if (usesZeroToOneRange) {
  6457. for (i = 0; i < count; i++) {
  6458. for (j = 0; j < numComps; j++) {
  6459. scaled[j] = src[srcOffset++] * scale;
  6460. }
  6461. tintFn(scaled, 0, tinted, 0);
  6462. for (j = 0; j < baseNumComps; j++) {
  6463. baseBuf[pos++] = tinted[j] * 255;
  6464. }
  6465. }
  6466. } else {
  6467. for (i = 0; i < count; i++) {
  6468. for (j = 0; j < numComps; j++) {
  6469. scaled[j] = src[srcOffset++] * scale;
  6470. }
  6471. tintFn(scaled, 0, tinted, 0);
  6472. base.getRgbItem(tinted, 0, baseBuf, pos);
  6473. pos += baseNumComps;
  6474. }
  6475. }
  6476. if (!isPassthrough) {
  6477. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6478. }
  6479. },
  6480. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6481. alpha01) {
  6482. return this.base.getOutputLength(inputLength *
  6483. this.base.numComps / this.numComps,
  6484. alpha01);
  6485. },
  6486. isPassthrough: ColorSpace.prototype.isPassthrough,
  6487. fillRgb: ColorSpace.prototype.fillRgb,
  6488. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6489. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6490. },
  6491. usesZeroToOneRange: true
  6492. };
  6493. return AlternateCS;
  6494. })();
  6495. var PatternCS = (function PatternCSClosure() {
  6496. function PatternCS(baseCS) {
  6497. this.name = 'Pattern';
  6498. this.base = baseCS;
  6499. }
  6500. PatternCS.prototype = {};
  6501. return PatternCS;
  6502. })();
  6503. var IndexedCS = (function IndexedCSClosure() {
  6504. function IndexedCS(base, highVal, lookup) {
  6505. this.name = 'Indexed';
  6506. this.numComps = 1;
  6507. this.defaultColor = new Uint8Array([0]);
  6508. this.base = base;
  6509. this.highVal = highVal;
  6510. var baseNumComps = base.numComps;
  6511. var length = baseNumComps * highVal;
  6512. var lookupArray;
  6513. if (isStream(lookup)) {
  6514. lookupArray = new Uint8Array(length);
  6515. var bytes = lookup.getBytes(length);
  6516. lookupArray.set(bytes);
  6517. } else if (isString(lookup)) {
  6518. lookupArray = new Uint8Array(length);
  6519. for (var i = 0; i < length; ++i) {
  6520. lookupArray[i] = lookup.charCodeAt(i);
  6521. }
  6522. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6523. lookupArray = lookup;
  6524. } else {
  6525. error('Unrecognized lookup table: ' + lookup);
  6526. }
  6527. this.lookup = lookupArray;
  6528. }
  6529. IndexedCS.prototype = {
  6530. getRgb: ColorSpace.prototype.getRgb,
  6531. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6532. dest, destOffset) {
  6533. var numComps = this.base.numComps;
  6534. var start = src[srcOffset] * numComps;
  6535. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6536. },
  6537. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6538. dest, destOffset, bits,
  6539. alpha01) {
  6540. var base = this.base;
  6541. var numComps = base.numComps;
  6542. var outputDelta = base.getOutputLength(numComps, alpha01);
  6543. var lookup = this.lookup;
  6544. for (var i = 0; i < count; ++i) {
  6545. var lookupPos = src[srcOffset++] * numComps;
  6546. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6547. destOffset += outputDelta;
  6548. }
  6549. },
  6550. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6551. return this.base.getOutputLength(inputLength * this.base.numComps,
  6552. alpha01);
  6553. },
  6554. isPassthrough: ColorSpace.prototype.isPassthrough,
  6555. fillRgb: ColorSpace.prototype.fillRgb,
  6556. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6557. // indexed color maps shouldn't be changed
  6558. return true;
  6559. },
  6560. usesZeroToOneRange: true
  6561. };
  6562. return IndexedCS;
  6563. })();
  6564. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6565. function DeviceGrayCS() {
  6566. this.name = 'DeviceGray';
  6567. this.numComps = 1;
  6568. this.defaultColor = new Float32Array([0]);
  6569. }
  6570. DeviceGrayCS.prototype = {
  6571. getRgb: ColorSpace.prototype.getRgb,
  6572. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6573. dest, destOffset) {
  6574. var c = (src[srcOffset] * 255) | 0;
  6575. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6576. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6577. },
  6578. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6579. dest, destOffset, bits,
  6580. alpha01) {
  6581. var scale = 255 / ((1 << bits) - 1);
  6582. var j = srcOffset, q = destOffset;
  6583. for (var i = 0; i < count; ++i) {
  6584. var c = (scale * src[j++]) | 0;
  6585. dest[q++] = c;
  6586. dest[q++] = c;
  6587. dest[q++] = c;
  6588. q += alpha01;
  6589. }
  6590. },
  6591. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6592. alpha01) {
  6593. return inputLength * (3 + alpha01);
  6594. },
  6595. isPassthrough: ColorSpace.prototype.isPassthrough,
  6596. fillRgb: ColorSpace.prototype.fillRgb,
  6597. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6598. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6599. },
  6600. usesZeroToOneRange: true
  6601. };
  6602. return DeviceGrayCS;
  6603. })();
  6604. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6605. function DeviceRgbCS() {
  6606. this.name = 'DeviceRGB';
  6607. this.numComps = 3;
  6608. this.defaultColor = new Float32Array([0, 0, 0]);
  6609. }
  6610. DeviceRgbCS.prototype = {
  6611. getRgb: ColorSpace.prototype.getRgb,
  6612. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6613. dest, destOffset) {
  6614. var r = (src[srcOffset] * 255) | 0;
  6615. var g = (src[srcOffset + 1] * 255) | 0;
  6616. var b = (src[srcOffset + 2] * 255) | 0;
  6617. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6618. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6619. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6620. },
  6621. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6622. dest, destOffset, bits,
  6623. alpha01) {
  6624. if (bits === 8 && alpha01 === 0) {
  6625. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6626. return;
  6627. }
  6628. var scale = 255 / ((1 << bits) - 1);
  6629. var j = srcOffset, q = destOffset;
  6630. for (var i = 0; i < count; ++i) {
  6631. dest[q++] = (scale * src[j++]) | 0;
  6632. dest[q++] = (scale * src[j++]) | 0;
  6633. dest[q++] = (scale * src[j++]) | 0;
  6634. q += alpha01;
  6635. }
  6636. },
  6637. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6638. alpha01) {
  6639. return (inputLength * (3 + alpha01) / 3) | 0;
  6640. },
  6641. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6642. return bits === 8;
  6643. },
  6644. fillRgb: ColorSpace.prototype.fillRgb,
  6645. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6646. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6647. },
  6648. usesZeroToOneRange: true
  6649. };
  6650. return DeviceRgbCS;
  6651. })();
  6652. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6653. // The coefficients below was found using numerical analysis: the method of
  6654. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6655. // where color_value is the tabular value from the table of sampled RGB colors
  6656. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6657. // CMYK color conversion using the estimation below:
  6658. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6659. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6660. var c = src[srcOffset + 0] * srcScale;
  6661. var m = src[srcOffset + 1] * srcScale;
  6662. var y = src[srcOffset + 2] * srcScale;
  6663. var k = src[srcOffset + 3] * srcScale;
  6664. var r =
  6665. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6666. 18.82290502165302 * y + 212.25662451639585 * k +
  6667. -285.2331026137004) +
  6668. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6669. -17.873870861415444 * k - 5.497006427196366) +
  6670. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6671. 17.5119270841813) +
  6672. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6673. var g =
  6674. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6675. 6.871425592049007 * y + 31.159100130055922 * k +
  6676. -79.2970844816548) +
  6677. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6678. 131.35250912493976 * k - 190.9453302588951) +
  6679. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6680. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6681. var b =
  6682. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6683. 30.89978309703729 * y - 0.23883238689178934 * k +
  6684. -14.183576799673286) +
  6685. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6686. 50.606957656360734 * k - 112.23884253719248) +
  6687. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6688. -193.58209356861505) +
  6689. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6690. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6691. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6692. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6693. }
  6694. function DeviceCmykCS() {
  6695. this.name = 'DeviceCMYK';
  6696. this.numComps = 4;
  6697. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6698. }
  6699. DeviceCmykCS.prototype = {
  6700. getRgb: ColorSpace.prototype.getRgb,
  6701. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6702. dest, destOffset) {
  6703. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6704. },
  6705. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6706. dest, destOffset, bits,
  6707. alpha01) {
  6708. var scale = 1 / ((1 << bits) - 1);
  6709. for (var i = 0; i < count; i++) {
  6710. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6711. srcOffset += 4;
  6712. destOffset += 3 + alpha01;
  6713. }
  6714. },
  6715. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6716. alpha01) {
  6717. return (inputLength / 4 * (3 + alpha01)) | 0;
  6718. },
  6719. isPassthrough: ColorSpace.prototype.isPassthrough,
  6720. fillRgb: ColorSpace.prototype.fillRgb,
  6721. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6722. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6723. },
  6724. usesZeroToOneRange: true
  6725. };
  6726. return DeviceCmykCS;
  6727. })();
  6728. //
  6729. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6730. //
  6731. var CalGrayCS = (function CalGrayCSClosure() {
  6732. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6733. this.name = 'CalGray';
  6734. this.numComps = 1;
  6735. this.defaultColor = new Float32Array([0]);
  6736. if (!whitePoint) {
  6737. error('WhitePoint missing - required for color space CalGray');
  6738. }
  6739. blackPoint = blackPoint || [0, 0, 0];
  6740. gamma = gamma || 1;
  6741. // Translate arguments to spec variables.
  6742. this.XW = whitePoint[0];
  6743. this.YW = whitePoint[1];
  6744. this.ZW = whitePoint[2];
  6745. this.XB = blackPoint[0];
  6746. this.YB = blackPoint[1];
  6747. this.ZB = blackPoint[2];
  6748. this.G = gamma;
  6749. // Validate variables as per spec.
  6750. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6751. error('Invalid WhitePoint components for ' + this.name +
  6752. ', no fallback available');
  6753. }
  6754. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6755. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6756. this.XB = this.YB = this.ZB = 0;
  6757. }
  6758. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6759. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6760. ', ZB: ' + this.ZB + ', only default values are supported.');
  6761. }
  6762. if (this.G < 1) {
  6763. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6764. ', falling back to default');
  6765. this.G = 1;
  6766. }
  6767. }
  6768. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6769. // A represents a gray component of a calibrated gray space.
  6770. // A <---> AG in the spec
  6771. var A = src[srcOffset] * scale;
  6772. var AG = Math.pow(A, cs.G);
  6773. // Computes L as per spec. ( = cs.YW * AG )
  6774. // Except if other than default BlackPoint values are used.
  6775. var L = cs.YW * AG;
  6776. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6777. // Convert values to rgb range [0, 255].
  6778. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6779. dest[destOffset] = val;
  6780. dest[destOffset + 1] = val;
  6781. dest[destOffset + 2] = val;
  6782. }
  6783. CalGrayCS.prototype = {
  6784. getRgb: ColorSpace.prototype.getRgb,
  6785. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6786. dest, destOffset) {
  6787. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6788. },
  6789. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6790. dest, destOffset, bits,
  6791. alpha01) {
  6792. var scale = 1 / ((1 << bits) - 1);
  6793. for (var i = 0; i < count; ++i) {
  6794. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6795. srcOffset += 1;
  6796. destOffset += 3 + alpha01;
  6797. }
  6798. },
  6799. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6800. return inputLength * (3 + alpha01);
  6801. },
  6802. isPassthrough: ColorSpace.prototype.isPassthrough,
  6803. fillRgb: ColorSpace.prototype.fillRgb,
  6804. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6805. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6806. },
  6807. usesZeroToOneRange: true
  6808. };
  6809. return CalGrayCS;
  6810. })();
  6811. //
  6812. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6813. //
  6814. var CalRGBCS = (function CalRGBCSClosure() {
  6815. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6816. // matrices.
  6817. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6818. 0.8951, 0.2664, -0.1614,
  6819. -0.7502, 1.7135, 0.0367,
  6820. 0.0389, -0.0685, 1.0296]);
  6821. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6822. 0.9869929, -0.1470543, 0.1599627,
  6823. 0.4323053, 0.5183603, 0.0492912,
  6824. -0.0085287, 0.0400428, 0.9684867]);
  6825. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6826. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6827. 3.2404542, -1.5371385, -0.4985314,
  6828. -0.9692660, 1.8760108, 0.0415560,
  6829. 0.0556434, -0.2040259, 1.0572252]);
  6830. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6831. var tempNormalizeMatrix = new Float32Array(3);
  6832. var tempConvertMatrix1 = new Float32Array(3);
  6833. var tempConvertMatrix2 = new Float32Array(3);
  6834. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6835. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6836. this.name = 'CalRGB';
  6837. this.numComps = 3;
  6838. this.defaultColor = new Float32Array(3);
  6839. if (!whitePoint) {
  6840. error('WhitePoint missing - required for color space CalRGB');
  6841. }
  6842. blackPoint = blackPoint || new Float32Array(3);
  6843. gamma = gamma || new Float32Array([1, 1, 1]);
  6844. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6845. // Translate arguments to spec variables.
  6846. var XW = whitePoint[0];
  6847. var YW = whitePoint[1];
  6848. var ZW = whitePoint[2];
  6849. this.whitePoint = whitePoint;
  6850. var XB = blackPoint[0];
  6851. var YB = blackPoint[1];
  6852. var ZB = blackPoint[2];
  6853. this.blackPoint = blackPoint;
  6854. this.GR = gamma[0];
  6855. this.GG = gamma[1];
  6856. this.GB = gamma[2];
  6857. this.MXA = matrix[0];
  6858. this.MYA = matrix[1];
  6859. this.MZA = matrix[2];
  6860. this.MXB = matrix[3];
  6861. this.MYB = matrix[4];
  6862. this.MZB = matrix[5];
  6863. this.MXC = matrix[6];
  6864. this.MYC = matrix[7];
  6865. this.MZC = matrix[8];
  6866. // Validate variables as per spec.
  6867. if (XW < 0 || ZW < 0 || YW !== 1) {
  6868. error('Invalid WhitePoint components for ' + this.name +
  6869. ', no fallback available');
  6870. }
  6871. if (XB < 0 || YB < 0 || ZB < 0) {
  6872. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6873. ', ' + ZB + '], falling back to default');
  6874. this.blackPoint = new Float32Array(3);
  6875. }
  6876. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6877. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6878. '] for ' + this.name + ', falling back to default');
  6879. this.GR = this.GG = this.GB = 1;
  6880. }
  6881. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6882. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6883. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6884. info('Invalid Matrix for ' + this.name + ' [' +
  6885. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6886. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6887. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6888. '], falling back to default');
  6889. this.MXA = this.MYB = this.MZC = 1;
  6890. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6891. }
  6892. }
  6893. function matrixProduct(a, b, result) {
  6894. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6895. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6896. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6897. }
  6898. function convertToFlat(sourceWhitePoint, LMS, result) {
  6899. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6900. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6901. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6902. }
  6903. function convertToD65(sourceWhitePoint, LMS, result) {
  6904. var D65X = 0.95047;
  6905. var D65Y = 1;
  6906. var D65Z = 1.08883;
  6907. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6908. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6909. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6910. }
  6911. function sRGBTransferFunction(color) {
  6912. // See http://en.wikipedia.org/wiki/SRGB.
  6913. if (color <= 0.0031308){
  6914. return adjustToRange(0, 1, 12.92 * color);
  6915. }
  6916. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6917. }
  6918. function adjustToRange(min, max, value) {
  6919. return Math.max(min, Math.min(max, value));
  6920. }
  6921. function decodeL(L) {
  6922. if (L < 0) {
  6923. return -decodeL(-L);
  6924. }
  6925. if (L > 8.0) {
  6926. return Math.pow(((L + 16) / 116), 3);
  6927. }
  6928. return L * DECODE_L_CONSTANT;
  6929. }
  6930. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6931. // In case the blackPoint is already the default blackPoint then there is
  6932. // no need to do compensation.
  6933. if (sourceBlackPoint[0] === 0 &&
  6934. sourceBlackPoint[1] === 0 &&
  6935. sourceBlackPoint[2] === 0) {
  6936. result[0] = XYZ_Flat[0];
  6937. result[1] = XYZ_Flat[1];
  6938. result[2] = XYZ_Flat[2];
  6939. return;
  6940. }
  6941. // For the blackPoint calculation details, please see
  6942. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6943. // AdobeBPC.pdf.
  6944. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6945. var zeroDecodeL = decodeL(0);
  6946. var X_DST = zeroDecodeL;
  6947. var X_SRC = decodeL(sourceBlackPoint[0]);
  6948. var Y_DST = zeroDecodeL;
  6949. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6950. var Z_DST = zeroDecodeL;
  6951. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6952. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6953. var X_Offset = 1 - X_Scale;
  6954. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6955. var Y_Offset = 1 - Y_Scale;
  6956. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6957. var Z_Offset = 1 - Z_Scale;
  6958. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6959. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6960. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6961. }
  6962. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6963. // In case the whitePoint is already flat then there is no need to do
  6964. // normalization.
  6965. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6966. result[0] = XYZ_In[0];
  6967. result[1] = XYZ_In[1];
  6968. result[2] = XYZ_In[2];
  6969. return;
  6970. }
  6971. var LMS = result;
  6972. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6973. var LMS_Flat = tempNormalizeMatrix;
  6974. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6975. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6976. }
  6977. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6978. var LMS = result;
  6979. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6980. var LMS_D65 = tempNormalizeMatrix;
  6981. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6982. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6983. }
  6984. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6985. // A, B and C represent a red, green and blue components of a calibrated
  6986. // rgb space.
  6987. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6988. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6989. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6990. // A <---> AGR in the spec
  6991. // B <---> BGG in the spec
  6992. // C <---> CGB in the spec
  6993. var AGR = Math.pow(A, cs.GR);
  6994. var BGG = Math.pow(B, cs.GG);
  6995. var CGB = Math.pow(C, cs.GB);
  6996. // Computes intermediate variables L, M, N as per spec.
  6997. // To decode X, Y, Z values map L, M, N directly to them.
  6998. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6999. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  7000. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  7001. // The following calculations are based on this document:
  7002. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  7003. // AdobeBPC.pdf.
  7004. var XYZ = tempConvertMatrix1;
  7005. XYZ[0] = X;
  7006. XYZ[1] = Y;
  7007. XYZ[2] = Z;
  7008. var XYZ_Flat = tempConvertMatrix2;
  7009. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  7010. var XYZ_Black = tempConvertMatrix1;
  7011. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  7012. var XYZ_D65 = tempConvertMatrix2;
  7013. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  7014. var SRGB = tempConvertMatrix1;
  7015. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  7016. var sR = sRGBTransferFunction(SRGB[0]);
  7017. var sG = sRGBTransferFunction(SRGB[1]);
  7018. var sB = sRGBTransferFunction(SRGB[2]);
  7019. // Convert the values to rgb range [0, 255].
  7020. dest[destOffset] = Math.round(sR * 255);
  7021. dest[destOffset + 1] = Math.round(sG * 255);
  7022. dest[destOffset + 2] = Math.round(sB * 255);
  7023. }
  7024. CalRGBCS.prototype = {
  7025. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  7026. var rgb = new Uint8Array(3);
  7027. this.getRgbItem(src, srcOffset, rgb, 0);
  7028. return rgb;
  7029. },
  7030. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  7031. dest, destOffset) {
  7032. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  7033. },
  7034. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  7035. dest, destOffset, bits,
  7036. alpha01) {
  7037. var scale = 1 / ((1 << bits) - 1);
  7038. for (var i = 0; i < count; ++i) {
  7039. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  7040. srcOffset += 3;
  7041. destOffset += 3 + alpha01;
  7042. }
  7043. },
  7044. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  7045. return (inputLength * (3 + alpha01) / 3) | 0;
  7046. },
  7047. isPassthrough: ColorSpace.prototype.isPassthrough,
  7048. fillRgb: ColorSpace.prototype.fillRgb,
  7049. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  7050. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7051. },
  7052. usesZeroToOneRange: true
  7053. };
  7054. return CalRGBCS;
  7055. })();
  7056. //
  7057. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  7058. //
  7059. var LabCS = (function LabCSClosure() {
  7060. function LabCS(whitePoint, blackPoint, range) {
  7061. this.name = 'Lab';
  7062. this.numComps = 3;
  7063. this.defaultColor = new Float32Array([0, 0, 0]);
  7064. if (!whitePoint) {
  7065. error('WhitePoint missing - required for color space Lab');
  7066. }
  7067. blackPoint = blackPoint || [0, 0, 0];
  7068. range = range || [-100, 100, -100, 100];
  7069. // Translate args to spec variables
  7070. this.XW = whitePoint[0];
  7071. this.YW = whitePoint[1];
  7072. this.ZW = whitePoint[2];
  7073. this.amin = range[0];
  7074. this.amax = range[1];
  7075. this.bmin = range[2];
  7076. this.bmax = range[3];
  7077. // These are here just for completeness - the spec doesn't offer any
  7078. // formulas that use BlackPoint in Lab
  7079. this.XB = blackPoint[0];
  7080. this.YB = blackPoint[1];
  7081. this.ZB = blackPoint[2];
  7082. // Validate vars as per spec
  7083. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7084. error('Invalid WhitePoint components, no fallback available');
  7085. }
  7086. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7087. info('Invalid BlackPoint, falling back to default');
  7088. this.XB = this.YB = this.ZB = 0;
  7089. }
  7090. if (this.amin > this.amax || this.bmin > this.bmax) {
  7091. info('Invalid Range, falling back to defaults');
  7092. this.amin = -100;
  7093. this.amax = 100;
  7094. this.bmin = -100;
  7095. this.bmax = 100;
  7096. }
  7097. }
  7098. // Function g(x) from spec
  7099. function fn_g(x) {
  7100. if (x >= 6 / 29) {
  7101. return x * x * x;
  7102. } else {
  7103. return (108 / 841) * (x - 4 / 29);
  7104. }
  7105. }
  7106. function decode(value, high1, low2, high2) {
  7107. return low2 + (value) * (high2 - low2) / (high1);
  7108. }
  7109. // If decoding is needed maxVal should be 2^bits per component - 1.
  7110. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  7111. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  7112. // not the usual [0, 1]. If a command like setFillColor is used the src
  7113. // values will already be within the correct range. However, if we are
  7114. // converting an image we have to map the values to the correct range given
  7115. // above.
  7116. // Ls,as,bs <---> L*,a*,b* in the spec
  7117. var Ls = src[srcOffset];
  7118. var as = src[srcOffset + 1];
  7119. var bs = src[srcOffset + 2];
  7120. if (maxVal !== false) {
  7121. Ls = decode(Ls, maxVal, 0, 100);
  7122. as = decode(as, maxVal, cs.amin, cs.amax);
  7123. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  7124. }
  7125. // Adjust limits of 'as' and 'bs'
  7126. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  7127. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  7128. // Computes intermediate variables X,Y,Z as per spec
  7129. var M = (Ls + 16) / 116;
  7130. var L = M + (as / 500);
  7131. var N = M - (bs / 200);
  7132. var X = cs.XW * fn_g(L);
  7133. var Y = cs.YW * fn_g(M);
  7134. var Z = cs.ZW * fn_g(N);
  7135. var r, g, b;
  7136. // Using different conversions for D50 and D65 white points,
  7137. // per http://www.color.org/srgb.pdf
  7138. if (cs.ZW < 1) {
  7139. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  7140. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  7141. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  7142. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  7143. } else {
  7144. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  7145. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  7146. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  7147. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  7148. }
  7149. // clamp color values to [0,1] range then convert to [0,255] range.
  7150. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  7151. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  7152. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  7153. }
  7154. LabCS.prototype = {
  7155. getRgb: ColorSpace.prototype.getRgb,
  7156. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  7157. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  7158. },
  7159. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  7160. dest, destOffset, bits,
  7161. alpha01) {
  7162. var maxVal = (1 << bits) - 1;
  7163. for (var i = 0; i < count; i++) {
  7164. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  7165. srcOffset += 3;
  7166. destOffset += 3 + alpha01;
  7167. }
  7168. },
  7169. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  7170. return (inputLength * (3 + alpha01) / 3) | 0;
  7171. },
  7172. isPassthrough: ColorSpace.prototype.isPassthrough,
  7173. fillRgb: ColorSpace.prototype.fillRgb,
  7174. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  7175. // XXX: Decoding is handled with the lab conversion because of the strange
  7176. // ranges that are used.
  7177. return true;
  7178. },
  7179. usesZeroToOneRange: false
  7180. };
  7181. return LabCS;
  7182. })();
  7183. var ARCFourCipher = (function ARCFourCipherClosure() {
  7184. function ARCFourCipher(key) {
  7185. this.a = 0;
  7186. this.b = 0;
  7187. var s = new Uint8Array(256);
  7188. var i, j = 0, tmp, keyLength = key.length;
  7189. for (i = 0; i < 256; ++i) {
  7190. s[i] = i;
  7191. }
  7192. for (i = 0; i < 256; ++i) {
  7193. tmp = s[i];
  7194. j = (j + tmp + key[i % keyLength]) & 0xFF;
  7195. s[i] = s[j];
  7196. s[j] = tmp;
  7197. }
  7198. this.s = s;
  7199. }
  7200. ARCFourCipher.prototype = {
  7201. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  7202. var i, n = data.length, tmp, tmp2;
  7203. var a = this.a, b = this.b, s = this.s;
  7204. var output = new Uint8Array(n);
  7205. for (i = 0; i < n; ++i) {
  7206. a = (a + 1) & 0xFF;
  7207. tmp = s[a];
  7208. b = (b + tmp) & 0xFF;
  7209. tmp2 = s[b];
  7210. s[a] = tmp2;
  7211. s[b] = tmp;
  7212. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7213. }
  7214. this.a = a;
  7215. this.b = b;
  7216. return output;
  7217. }
  7218. };
  7219. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7220. return ARCFourCipher;
  7221. })();
  7222. var calculateMD5 = (function calculateMD5Closure() {
  7223. var r = new Uint8Array([
  7224. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7225. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7226. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7227. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7228. var k = new Int32Array([
  7229. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7230. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7231. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7232. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7233. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7234. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7235. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7236. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7237. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7238. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7239. -145523070, -1120210379, 718787259, -343485551]);
  7240. function hash(data, offset, length) {
  7241. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7242. // pre-processing
  7243. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7244. var padded = new Uint8Array(paddedLength);
  7245. var i, j, n;
  7246. for (i = 0; i < length; ++i) {
  7247. padded[i] = data[offset++];
  7248. }
  7249. padded[i++] = 0x80;
  7250. n = paddedLength - 8;
  7251. while (i < n) {
  7252. padded[i++] = 0;
  7253. }
  7254. padded[i++] = (length << 3) & 0xFF;
  7255. padded[i++] = (length >> 5) & 0xFF;
  7256. padded[i++] = (length >> 13) & 0xFF;
  7257. padded[i++] = (length >> 21) & 0xFF;
  7258. padded[i++] = (length >>> 29) & 0xFF;
  7259. padded[i++] = 0;
  7260. padded[i++] = 0;
  7261. padded[i++] = 0;
  7262. var w = new Int32Array(16);
  7263. for (i = 0; i < paddedLength;) {
  7264. for (j = 0; j < 16; ++j, i += 4) {
  7265. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7266. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7267. }
  7268. var a = h0, b = h1, c = h2, d = h3, f, g;
  7269. for (j = 0; j < 64; ++j) {
  7270. if (j < 16) {
  7271. f = (b & c) | ((~b) & d);
  7272. g = j;
  7273. } else if (j < 32) {
  7274. f = (d & b) | ((~d) & c);
  7275. g = (5 * j + 1) & 15;
  7276. } else if (j < 48) {
  7277. f = b ^ c ^ d;
  7278. g = (3 * j + 5) & 15;
  7279. } else {
  7280. f = c ^ (b | (~d));
  7281. g = (7 * j) & 15;
  7282. }
  7283. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7284. d = c;
  7285. c = b;
  7286. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7287. a = tmp;
  7288. }
  7289. h0 = (h0 + a) | 0;
  7290. h1 = (h1 + b) | 0;
  7291. h2 = (h2 + c) | 0;
  7292. h3 = (h3 + d) | 0;
  7293. }
  7294. return new Uint8Array([
  7295. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7296. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7297. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7298. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7299. ]);
  7300. }
  7301. return hash;
  7302. })();
  7303. var Word64 = (function Word64Closure() {
  7304. function Word64(highInteger, lowInteger) {
  7305. this.high = highInteger | 0;
  7306. this.low = lowInteger | 0;
  7307. }
  7308. Word64.prototype = {
  7309. and: function Word64_and(word) {
  7310. this.high &= word.high;
  7311. this.low &= word.low;
  7312. },
  7313. xor: function Word64_xor(word) {
  7314. this.high ^= word.high;
  7315. this.low ^= word.low;
  7316. },
  7317. or: function Word64_or(word) {
  7318. this.high |= word.high;
  7319. this.low |= word.low;
  7320. },
  7321. shiftRight: function Word64_shiftRight(places) {
  7322. if (places >= 32) {
  7323. this.low = (this.high >>> (places - 32)) | 0;
  7324. this.high = 0;
  7325. } else {
  7326. this.low = (this.low >>> places) | (this.high << (32 - places));
  7327. this.high = (this.high >>> places) | 0;
  7328. }
  7329. },
  7330. shiftLeft: function Word64_shiftLeft(places) {
  7331. if (places >= 32) {
  7332. this.high = this.low << (places - 32);
  7333. this.low = 0;
  7334. } else {
  7335. this.high = (this.high << places) | (this.low >>> (32 - places));
  7336. this.low = this.low << places;
  7337. }
  7338. },
  7339. rotateRight: function Word64_rotateRight(places) {
  7340. var low, high;
  7341. if (places & 32) {
  7342. high = this.low;
  7343. low = this.high;
  7344. } else {
  7345. low = this.low;
  7346. high = this.high;
  7347. }
  7348. places &= 31;
  7349. this.low = (low >>> places) | (high << (32 - places));
  7350. this.high = (high >>> places) | (low << (32 - places));
  7351. },
  7352. not: function Word64_not() {
  7353. this.high = ~this.high;
  7354. this.low = ~this.low;
  7355. },
  7356. add: function Word64_add(word) {
  7357. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7358. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7359. if (lowAdd > 0xFFFFFFFF) {
  7360. highAdd += 1;
  7361. }
  7362. this.low = lowAdd | 0;
  7363. this.high = highAdd | 0;
  7364. },
  7365. copyTo: function Word64_copyTo(bytes, offset) {
  7366. bytes[offset] = (this.high >>> 24) & 0xFF;
  7367. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7368. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7369. bytes[offset + 3] = this.high & 0xFF;
  7370. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7371. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7372. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7373. bytes[offset + 7] = this.low & 0xFF;
  7374. },
  7375. assign: function Word64_assign(word) {
  7376. this.high = word.high;
  7377. this.low = word.low;
  7378. }
  7379. };
  7380. return Word64;
  7381. })();
  7382. var calculateSHA256 = (function calculateSHA256Closure() {
  7383. function rotr(x, n) {
  7384. return (x >>> n) | (x << 32 - n);
  7385. }
  7386. function ch(x, y, z) {
  7387. return (x & y) ^ (~x & z);
  7388. }
  7389. function maj(x, y, z) {
  7390. return (x & y) ^ (x & z) ^ (y & z);
  7391. }
  7392. function sigma(x) {
  7393. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7394. }
  7395. function sigmaPrime(x) {
  7396. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7397. }
  7398. function littleSigma(x) {
  7399. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7400. }
  7401. function littleSigmaPrime(x) {
  7402. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7403. }
  7404. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7405. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7406. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7407. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7408. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7409. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7410. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7411. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7412. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7413. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7414. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7415. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7416. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7417. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7418. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7419. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7420. function hash(data, offset, length) {
  7421. // initial hash values
  7422. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7423. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7424. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7425. // pre-processing
  7426. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7427. var padded = new Uint8Array(paddedLength);
  7428. var i, j, n;
  7429. for (i = 0; i < length; ++i) {
  7430. padded[i] = data[offset++];
  7431. }
  7432. padded[i++] = 0x80;
  7433. n = paddedLength - 8;
  7434. while (i < n) {
  7435. padded[i++] = 0;
  7436. }
  7437. padded[i++] = 0;
  7438. padded[i++] = 0;
  7439. padded[i++] = 0;
  7440. padded[i++] = (length >>> 29) & 0xFF;
  7441. padded[i++] = (length >> 21) & 0xFF;
  7442. padded[i++] = (length >> 13) & 0xFF;
  7443. padded[i++] = (length >> 5) & 0xFF;
  7444. padded[i++] = (length << 3) & 0xFF;
  7445. var w = new Uint32Array(64);
  7446. // for each 512 bit block
  7447. for (i = 0; i < paddedLength;) {
  7448. for (j = 0; j < 16; ++j) {
  7449. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7450. (padded[i + 2] << 8) | (padded[i + 3]));
  7451. i += 4;
  7452. }
  7453. for (j = 16; j < 64; ++j) {
  7454. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7455. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7456. }
  7457. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7458. f = h5, g = h6, h = h7, t1, t2;
  7459. for (j = 0; j < 64; ++j) {
  7460. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7461. t2 = sigma(a) + maj(a, b, c);
  7462. h = g;
  7463. g = f;
  7464. f = e;
  7465. e = (d + t1) | 0;
  7466. d = c;
  7467. c = b;
  7468. b = a;
  7469. a = (t1 + t2) | 0;
  7470. }
  7471. h0 = (h0 + a) | 0;
  7472. h1 = (h1 + b) | 0;
  7473. h2 = (h2 + c) | 0;
  7474. h3 = (h3 + d) | 0;
  7475. h4 = (h4 + e) | 0;
  7476. h5 = (h5 + f) | 0;
  7477. h6 = (h6 + g) | 0;
  7478. h7 = (h7 + h) | 0;
  7479. }
  7480. return new Uint8Array([
  7481. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7482. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7483. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7484. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7485. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7486. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7487. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7488. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7489. ]);
  7490. }
  7491. return hash;
  7492. })();
  7493. var calculateSHA512 = (function calculateSHA512Closure() {
  7494. function ch(result, x, y, z, tmp) {
  7495. result.assign(x);
  7496. result.and(y);
  7497. tmp.assign(x);
  7498. tmp.not();
  7499. tmp.and(z);
  7500. result.xor(tmp);
  7501. }
  7502. function maj(result, x, y, z, tmp) {
  7503. result.assign(x);
  7504. result.and(y);
  7505. tmp.assign(x);
  7506. tmp.and(z);
  7507. result.xor(tmp);
  7508. tmp.assign(y);
  7509. tmp.and(z);
  7510. result.xor(tmp);
  7511. }
  7512. function sigma(result, x, tmp) {
  7513. result.assign(x);
  7514. result.rotateRight(28);
  7515. tmp.assign(x);
  7516. tmp.rotateRight(34);
  7517. result.xor(tmp);
  7518. tmp.assign(x);
  7519. tmp.rotateRight(39);
  7520. result.xor(tmp);
  7521. }
  7522. function sigmaPrime(result, x, tmp) {
  7523. result.assign(x);
  7524. result.rotateRight(14);
  7525. tmp.assign(x);
  7526. tmp.rotateRight(18);
  7527. result.xor(tmp);
  7528. tmp.assign(x);
  7529. tmp.rotateRight(41);
  7530. result.xor(tmp);
  7531. }
  7532. function littleSigma(result, x, tmp) {
  7533. result.assign(x);
  7534. result.rotateRight(1);
  7535. tmp.assign(x);
  7536. tmp.rotateRight(8);
  7537. result.xor(tmp);
  7538. tmp.assign(x);
  7539. tmp.shiftRight(7);
  7540. result.xor(tmp);
  7541. }
  7542. function littleSigmaPrime(result, x, tmp) {
  7543. result.assign(x);
  7544. result.rotateRight(19);
  7545. tmp.assign(x);
  7546. tmp.rotateRight(61);
  7547. result.xor(tmp);
  7548. tmp.assign(x);
  7549. tmp.shiftRight(6);
  7550. result.xor(tmp);
  7551. }
  7552. var k = [
  7553. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7554. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7555. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7556. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7557. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7558. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7559. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7560. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7561. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7562. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7563. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7564. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7565. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7566. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7567. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7568. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7569. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7570. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7571. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7572. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7573. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7574. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7575. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7576. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7577. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7578. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7579. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7580. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7581. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7582. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7583. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7584. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7585. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7586. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7587. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7588. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7589. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7590. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7591. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7592. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7593. function hash(data, offset, length, mode384) {
  7594. mode384 = !!mode384;
  7595. // initial hash values
  7596. var h0, h1, h2, h3, h4, h5, h6, h7;
  7597. if (!mode384) {
  7598. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7599. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7600. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7601. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7602. h4 = new Word64(0x510e527f, 0xade682d1);
  7603. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7604. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7605. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7606. }
  7607. else {
  7608. // SHA384 is exactly the same
  7609. // except with different starting values and a trimmed result
  7610. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7611. h1 = new Word64(0x629a292a, 0x367cd507);
  7612. h2 = new Word64(0x9159015a, 0x3070dd17);
  7613. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7614. h4 = new Word64(0x67332667, 0xffc00b31);
  7615. h5 = new Word64(0x8eb44a87, 0x68581511);
  7616. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7617. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7618. }
  7619. // pre-processing
  7620. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7621. var padded = new Uint8Array(paddedLength);
  7622. var i, j, n;
  7623. for (i = 0; i < length; ++i) {
  7624. padded[i] = data[offset++];
  7625. }
  7626. padded[i++] = 0x80;
  7627. n = paddedLength - 16;
  7628. while (i < n) {
  7629. padded[i++] = 0;
  7630. }
  7631. padded[i++] = 0;
  7632. padded[i++] = 0;
  7633. padded[i++] = 0;
  7634. padded[i++] = 0;
  7635. padded[i++] = 0;
  7636. padded[i++] = 0;
  7637. padded[i++] = 0;
  7638. padded[i++] = 0;
  7639. padded[i++] = 0;
  7640. padded[i++] = 0;
  7641. padded[i++] = 0;
  7642. padded[i++] = (length >>> 29) & 0xFF;
  7643. padded[i++] = (length >> 21) & 0xFF;
  7644. padded[i++] = (length >> 13) & 0xFF;
  7645. padded[i++] = (length >> 5) & 0xFF;
  7646. padded[i++] = (length << 3) & 0xFF;
  7647. var w = new Array(80);
  7648. for (i = 0; i < 80; i++) {
  7649. w[i] = new Word64(0, 0);
  7650. }
  7651. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7652. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7653. var g = new Word64(0, 0), h = new Word64(0, 0);
  7654. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7655. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7656. // for each 1024 bit block
  7657. for (i = 0; i < paddedLength;) {
  7658. for (j = 0; j < 16; ++j) {
  7659. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7660. (padded[i + 2] << 8) | (padded[i + 3]);
  7661. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7662. (padded[i + 6]) << 8 | (padded[i + 7]);
  7663. i += 8;
  7664. }
  7665. for (j = 16; j < 80; ++j) {
  7666. tmp3 = w[j];
  7667. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7668. tmp3.add(w[j - 7]);
  7669. littleSigma(tmp1, w[j - 15], tmp2);
  7670. tmp3.add(tmp1);
  7671. tmp3.add(w[j - 16]);
  7672. }
  7673. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7674. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7675. for (j = 0; j < 80; ++j) {
  7676. t1.assign(h);
  7677. sigmaPrime(tmp1, e, tmp2);
  7678. t1.add(tmp1);
  7679. ch(tmp1, e, f, g, tmp2);
  7680. t1.add(tmp1);
  7681. t1.add(k[j]);
  7682. t1.add(w[j]);
  7683. sigma(t2, a, tmp2);
  7684. maj(tmp1, a, b, c, tmp2);
  7685. t2.add(tmp1);
  7686. tmp3 = h;
  7687. h = g;
  7688. g = f;
  7689. f = e;
  7690. d.add(t1);
  7691. e = d;
  7692. d = c;
  7693. c = b;
  7694. b = a;
  7695. tmp3.assign(t1);
  7696. tmp3.add(t2);
  7697. a = tmp3;
  7698. }
  7699. h0.add(a);
  7700. h1.add(b);
  7701. h2.add(c);
  7702. h3.add(d);
  7703. h4.add(e);
  7704. h5.add(f);
  7705. h6.add(g);
  7706. h7.add(h);
  7707. }
  7708. var result;
  7709. if (!mode384) {
  7710. result = new Uint8Array(64);
  7711. h0.copyTo(result,0);
  7712. h1.copyTo(result,8);
  7713. h2.copyTo(result,16);
  7714. h3.copyTo(result,24);
  7715. h4.copyTo(result,32);
  7716. h5.copyTo(result,40);
  7717. h6.copyTo(result,48);
  7718. h7.copyTo(result,56);
  7719. }
  7720. else {
  7721. result = new Uint8Array(48);
  7722. h0.copyTo(result,0);
  7723. h1.copyTo(result,8);
  7724. h2.copyTo(result,16);
  7725. h3.copyTo(result,24);
  7726. h4.copyTo(result,32);
  7727. h5.copyTo(result,40);
  7728. }
  7729. return result;
  7730. }
  7731. return hash;
  7732. })();
  7733. var calculateSHA384 = (function calculateSHA384Closure() {
  7734. function hash(data, offset, length) {
  7735. return calculateSHA512(data, offset, length, true);
  7736. }
  7737. return hash;
  7738. })();
  7739. var NullCipher = (function NullCipherClosure() {
  7740. function NullCipher() {
  7741. }
  7742. NullCipher.prototype = {
  7743. decryptBlock: function NullCipher_decryptBlock(data) {
  7744. return data;
  7745. }
  7746. };
  7747. return NullCipher;
  7748. })();
  7749. var AES128Cipher = (function AES128CipherClosure() {
  7750. var rcon = new Uint8Array([
  7751. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7752. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7753. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7754. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7755. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7756. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7757. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7758. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7759. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7760. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7761. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7762. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7763. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7764. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7765. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7766. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7767. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7768. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7769. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7770. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7771. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7772. 0x74, 0xe8, 0xcb, 0x8d]);
  7773. var s = new Uint8Array([
  7774. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7775. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7776. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7777. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7778. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7779. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7780. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7781. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7782. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7783. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7784. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7785. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7786. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7787. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7788. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7789. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7790. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7791. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7792. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7793. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7794. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7795. 0xb0, 0x54, 0xbb, 0x16]);
  7796. var inv_s = new Uint8Array([
  7797. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7798. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7799. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7800. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7801. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7802. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7803. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7804. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7805. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7806. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7807. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7808. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7809. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7810. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7811. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7812. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7813. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7814. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7815. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7816. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7817. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7818. 0x55, 0x21, 0x0c, 0x7d]);
  7819. var mixCol = new Uint8Array(256);
  7820. for (var i = 0; i < 256; i++) {
  7821. if (i < 128) {
  7822. mixCol[i] = i << 1;
  7823. } else {
  7824. mixCol[i] = (i << 1) ^ 0x1b;
  7825. }
  7826. }
  7827. var mix = new Uint32Array([
  7828. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7829. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7830. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7831. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7832. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7833. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7834. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7835. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7836. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7837. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7838. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7839. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7840. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7841. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7842. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7843. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7844. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7845. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7846. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7847. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7848. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7849. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7850. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7851. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7852. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7853. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7854. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7855. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7856. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7857. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7858. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7859. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7860. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7861. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7862. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7863. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7864. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7865. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7866. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7867. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7868. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7869. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7870. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7871. function expandKey128(cipherKey) {
  7872. var b = 176, result = new Uint8Array(b);
  7873. result.set(cipherKey);
  7874. for (var j = 16, i = 1; j < b; ++i) {
  7875. // RotWord
  7876. var t1 = result[j - 3], t2 = result[j - 2],
  7877. t3 = result[j - 1], t4 = result[j - 4];
  7878. // SubWord
  7879. t1 = s[t1];
  7880. t2 = s[t2];
  7881. t3 = s[t3];
  7882. t4 = s[t4];
  7883. // Rcon
  7884. t1 = t1 ^ rcon[i];
  7885. for (var n = 0; n < 4; ++n) {
  7886. result[j] = (t1 ^= result[j - 16]);
  7887. j++;
  7888. result[j] = (t2 ^= result[j - 16]);
  7889. j++;
  7890. result[j] = (t3 ^= result[j - 16]);
  7891. j++;
  7892. result[j] = (t4 ^= result[j - 16]);
  7893. j++;
  7894. }
  7895. }
  7896. return result;
  7897. }
  7898. function decrypt128(input, key) {
  7899. var state = new Uint8Array(16);
  7900. state.set(input);
  7901. var i, j, k;
  7902. var t, u, v;
  7903. // AddRoundKey
  7904. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7905. state[j] ^= key[k];
  7906. }
  7907. for (i = 9; i >= 1; --i) {
  7908. // InvShiftRows
  7909. t = state[13];
  7910. state[13] = state[9];
  7911. state[9] = state[5];
  7912. state[5] = state[1];
  7913. state[1] = t;
  7914. t = state[14];
  7915. u = state[10];
  7916. state[14] = state[6];
  7917. state[10] = state[2];
  7918. state[6] = t;
  7919. state[2] = u;
  7920. t = state[15];
  7921. u = state[11];
  7922. v = state[7];
  7923. state[15] = state[3];
  7924. state[11] = t;
  7925. state[7] = u;
  7926. state[3] = v;
  7927. // InvSubBytes
  7928. for (j = 0; j < 16; ++j) {
  7929. state[j] = inv_s[state[j]];
  7930. }
  7931. // AddRoundKey
  7932. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7933. state[j] ^= key[k];
  7934. }
  7935. // InvMixColumns
  7936. for (j = 0; j < 16; j += 4) {
  7937. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7938. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7939. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7940. (s3 >>> 24) ^ (s3 << 8));
  7941. state[j] = (t >>> 24) & 0xFF;
  7942. state[j + 1] = (t >> 16) & 0xFF;
  7943. state[j + 2] = (t >> 8) & 0xFF;
  7944. state[j + 3] = t & 0xFF;
  7945. }
  7946. }
  7947. // InvShiftRows
  7948. t = state[13];
  7949. state[13] = state[9];
  7950. state[9] = state[5];
  7951. state[5] = state[1];
  7952. state[1] = t;
  7953. t = state[14];
  7954. u = state[10];
  7955. state[14] = state[6];
  7956. state[10] = state[2];
  7957. state[6] = t;
  7958. state[2] = u;
  7959. t = state[15];
  7960. u = state[11];
  7961. v = state[7];
  7962. state[15] = state[3];
  7963. state[11] = t;
  7964. state[7] = u;
  7965. state[3] = v;
  7966. for (j = 0; j < 16; ++j) {
  7967. // InvSubBytes
  7968. state[j] = inv_s[state[j]];
  7969. // AddRoundKey
  7970. state[j] ^= key[j];
  7971. }
  7972. return state;
  7973. }
  7974. function encrypt128(input, key) {
  7975. var t, u, v, k;
  7976. var state = new Uint8Array(16);
  7977. state.set(input);
  7978. for (j = 0; j < 16; ++j) {
  7979. // AddRoundKey
  7980. state[j] ^= key[j];
  7981. }
  7982. for (i = 1; i < 10; i++) {
  7983. //SubBytes
  7984. for (j = 0; j < 16; ++j) {
  7985. state[j] = s[state[j]];
  7986. }
  7987. //ShiftRows
  7988. v = state[1];
  7989. state[1] = state[5];
  7990. state[5] = state[9];
  7991. state[9] = state[13];
  7992. state[13] = v;
  7993. v = state[2];
  7994. u = state[6];
  7995. state[2] = state[10];
  7996. state[6] = state[14];
  7997. state[10] = v;
  7998. state[14] = u;
  7999. v = state[3];
  8000. u = state[7];
  8001. t = state[11];
  8002. state[3] = state[15];
  8003. state[7] = v;
  8004. state[11] = u;
  8005. state[15] = t;
  8006. //MixColumns
  8007. for (var j = 0; j < 16; j += 4) {
  8008. var s0 = state[j + 0], s1 = state[j + 1];
  8009. var s2 = state[j + 2], s3 = state[j + 3];
  8010. t = s0 ^ s1 ^ s2 ^ s3;
  8011. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8012. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8013. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8014. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8015. }
  8016. //AddRoundKey
  8017. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8018. state[j] ^= key[k];
  8019. }
  8020. }
  8021. //SubBytes
  8022. for (j = 0; j < 16; ++j) {
  8023. state[j] = s[state[j]];
  8024. }
  8025. //ShiftRows
  8026. v = state[1];
  8027. state[1] = state[5];
  8028. state[5] = state[9];
  8029. state[9] = state[13];
  8030. state[13] = v;
  8031. v = state[2];
  8032. u = state[6];
  8033. state[2] = state[10];
  8034. state[6] = state[14];
  8035. state[10] = v;
  8036. state[14] = u;
  8037. v = state[3];
  8038. u = state[7];
  8039. t = state[11];
  8040. state[3] = state[15];
  8041. state[7] = v;
  8042. state[11] = u;
  8043. state[15] = t;
  8044. //AddRoundKey
  8045. for (j = 0, k = 160; j < 16; ++j, ++k) {
  8046. state[j] ^= key[k];
  8047. }
  8048. return state;
  8049. }
  8050. function AES128Cipher(key) {
  8051. this.key = expandKey128(key);
  8052. this.buffer = new Uint8Array(16);
  8053. this.bufferPosition = 0;
  8054. }
  8055. function decryptBlock2(data, finalize) {
  8056. var i, j, ii, sourceLength = data.length,
  8057. buffer = this.buffer, bufferLength = this.bufferPosition,
  8058. result = [], iv = this.iv;
  8059. for (i = 0; i < sourceLength; ++i) {
  8060. buffer[bufferLength] = data[i];
  8061. ++bufferLength;
  8062. if (bufferLength < 16) {
  8063. continue;
  8064. }
  8065. // buffer is full, decrypting
  8066. var plain = decrypt128(buffer, this.key);
  8067. // xor-ing the IV vector to get plain text
  8068. for (j = 0; j < 16; ++j) {
  8069. plain[j] ^= iv[j];
  8070. }
  8071. iv = buffer;
  8072. result.push(plain);
  8073. buffer = new Uint8Array(16);
  8074. bufferLength = 0;
  8075. }
  8076. // saving incomplete buffer
  8077. this.buffer = buffer;
  8078. this.bufferLength = bufferLength;
  8079. this.iv = iv;
  8080. if (result.length === 0) {
  8081. return new Uint8Array([]);
  8082. }
  8083. // combining plain text blocks into one
  8084. var outputLength = 16 * result.length;
  8085. if (finalize) {
  8086. // undo a padding that is described in RFC 2898
  8087. var lastBlock = result[result.length - 1];
  8088. var psLen = lastBlock[15];
  8089. if (psLen <= 16) {
  8090. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8091. if (lastBlock[i] !== psLen) {
  8092. // Invalid padding, assume that the block has no padding.
  8093. psLen = 0;
  8094. break;
  8095. }
  8096. }
  8097. outputLength -= psLen;
  8098. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8099. }
  8100. }
  8101. var output = new Uint8Array(outputLength);
  8102. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8103. output.set(result[i], j);
  8104. }
  8105. return output;
  8106. }
  8107. AES128Cipher.prototype = {
  8108. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  8109. var i, sourceLength = data.length;
  8110. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8111. // waiting for IV values -- they are at the start of the stream
  8112. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  8113. buffer[bufferLength] = data[i];
  8114. }
  8115. if (bufferLength < 16) {
  8116. // need more data
  8117. this.bufferLength = bufferLength;
  8118. return new Uint8Array([]);
  8119. }
  8120. this.iv = buffer;
  8121. this.buffer = new Uint8Array(16);
  8122. this.bufferLength = 0;
  8123. // starting decryption
  8124. this.decryptBlock = decryptBlock2;
  8125. return this.decryptBlock(data.subarray(16), finalize);
  8126. },
  8127. encrypt: function AES128Cipher_encrypt(data, iv) {
  8128. var i, j, ii, sourceLength = data.length,
  8129. buffer = this.buffer, bufferLength = this.bufferPosition,
  8130. result = [];
  8131. if (!iv) {
  8132. iv = new Uint8Array(16);
  8133. }
  8134. for (i = 0; i < sourceLength; ++i) {
  8135. buffer[bufferLength] = data[i];
  8136. ++bufferLength;
  8137. if (bufferLength < 16) {
  8138. continue;
  8139. }
  8140. for (j = 0; j < 16; ++j) {
  8141. buffer[j] ^= iv[j];
  8142. }
  8143. // buffer is full, encrypting
  8144. var cipher = encrypt128(buffer, this.key);
  8145. iv = cipher;
  8146. result.push(cipher);
  8147. buffer = new Uint8Array(16);
  8148. bufferLength = 0;
  8149. }
  8150. // saving incomplete buffer
  8151. this.buffer = buffer;
  8152. this.bufferLength = bufferLength;
  8153. this.iv = iv;
  8154. if (result.length === 0) {
  8155. return new Uint8Array([]);
  8156. }
  8157. // combining plain text blocks into one
  8158. var outputLength = 16 * result.length;
  8159. var output = new Uint8Array(outputLength);
  8160. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8161. output.set(result[i], j);
  8162. }
  8163. return output;
  8164. }
  8165. };
  8166. return AES128Cipher;
  8167. })();
  8168. var AES256Cipher = (function AES256CipherClosure() {
  8169. var rcon = new Uint8Array([
  8170. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8171. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8172. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8173. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8174. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8175. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8176. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8177. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8178. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8179. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8180. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8181. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8182. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8183. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8184. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8185. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8186. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8187. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8188. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8189. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8190. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8191. 0x74, 0xe8, 0xcb, 0x8d]);
  8192. var s = new Uint8Array([
  8193. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8194. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8195. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8196. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8197. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8198. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8199. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8200. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8201. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8202. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8203. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8204. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8205. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8206. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8207. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8208. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8209. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8210. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8211. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8212. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8213. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8214. 0xb0, 0x54, 0xbb, 0x16]);
  8215. var inv_s = new Uint8Array([
  8216. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8217. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8218. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8219. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8220. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8221. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8222. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8223. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8224. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8225. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8226. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8227. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8228. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8229. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8230. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8231. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8232. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8233. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8234. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8235. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8236. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8237. 0x55, 0x21, 0x0c, 0x7d]);
  8238. var mixCol = new Uint8Array(256);
  8239. for (var i = 0; i < 256; i++) {
  8240. if (i < 128) {
  8241. mixCol[i] = i << 1;
  8242. } else {
  8243. mixCol[i] = (i << 1) ^ 0x1b;
  8244. }
  8245. }
  8246. var mix = new Uint32Array([
  8247. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8248. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8249. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8250. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8251. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8252. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8253. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8254. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8255. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8256. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8257. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8258. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8259. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8260. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8261. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8262. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8263. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8264. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8265. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8266. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8267. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8268. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8269. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8270. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8271. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8272. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8273. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8274. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8275. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8276. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8277. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8278. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8279. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8280. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8281. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8282. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8283. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8284. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8285. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8286. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8287. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8288. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8289. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8290. function expandKey256(cipherKey) {
  8291. var b = 240, result = new Uint8Array(b);
  8292. var r = 1;
  8293. result.set(cipherKey);
  8294. for (var j = 32, i = 1; j < b; ++i) {
  8295. if (j % 32 === 16) {
  8296. t1 = s[t1];
  8297. t2 = s[t2];
  8298. t3 = s[t3];
  8299. t4 = s[t4];
  8300. } else if (j % 32 === 0) {
  8301. // RotWord
  8302. var t1 = result[j - 3], t2 = result[j - 2],
  8303. t3 = result[j - 1], t4 = result[j - 4];
  8304. // SubWord
  8305. t1 = s[t1];
  8306. t2 = s[t2];
  8307. t3 = s[t3];
  8308. t4 = s[t4];
  8309. // Rcon
  8310. t1 = t1 ^ r;
  8311. if ((r <<= 1) >= 256) {
  8312. r = (r ^ 0x1b) & 0xFF;
  8313. }
  8314. }
  8315. for (var n = 0; n < 4; ++n) {
  8316. result[j] = (t1 ^= result[j - 32]);
  8317. j++;
  8318. result[j] = (t2 ^= result[j - 32]);
  8319. j++;
  8320. result[j] = (t3 ^= result[j - 32]);
  8321. j++;
  8322. result[j] = (t4 ^= result[j - 32]);
  8323. j++;
  8324. }
  8325. }
  8326. return result;
  8327. }
  8328. function decrypt256(input, key) {
  8329. var state = new Uint8Array(16);
  8330. state.set(input);
  8331. var i, j, k;
  8332. var t, u, v;
  8333. // AddRoundKey
  8334. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8335. state[j] ^= key[k];
  8336. }
  8337. for (i = 13; i >= 1; --i) {
  8338. // InvShiftRows
  8339. t = state[13];
  8340. state[13] = state[9];
  8341. state[9] = state[5];
  8342. state[5] = state[1];
  8343. state[1] = t;
  8344. t = state[14];
  8345. u = state[10];
  8346. state[14] = state[6];
  8347. state[10] = state[2];
  8348. state[6] = t;
  8349. state[2] = u;
  8350. t = state[15];
  8351. u = state[11];
  8352. v = state[7];
  8353. state[15] = state[3];
  8354. state[11] = t;
  8355. state[7] = u;
  8356. state[3] = v;
  8357. // InvSubBytes
  8358. for (j = 0; j < 16; ++j) {
  8359. state[j] = inv_s[state[j]];
  8360. }
  8361. // AddRoundKey
  8362. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8363. state[j] ^= key[k];
  8364. }
  8365. // InvMixColumns
  8366. for (j = 0; j < 16; j += 4) {
  8367. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8368. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8369. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8370. (s3 >>> 24) ^ (s3 << 8));
  8371. state[j] = (t >>> 24) & 0xFF;
  8372. state[j + 1] = (t >> 16) & 0xFF;
  8373. state[j + 2] = (t >> 8) & 0xFF;
  8374. state[j + 3] = t & 0xFF;
  8375. }
  8376. }
  8377. // InvShiftRows
  8378. t = state[13];
  8379. state[13] = state[9];
  8380. state[9] = state[5];
  8381. state[5] = state[1];
  8382. state[1] = t;
  8383. t = state[14];
  8384. u = state[10];
  8385. state[14] = state[6];
  8386. state[10] = state[2];
  8387. state[6] = t;
  8388. state[2] = u;
  8389. t = state[15];
  8390. u = state[11];
  8391. v = state[7];
  8392. state[15] = state[3];
  8393. state[11] = t;
  8394. state[7] = u;
  8395. state[3] = v;
  8396. for (j = 0; j < 16; ++j) {
  8397. // InvSubBytes
  8398. state[j] = inv_s[state[j]];
  8399. // AddRoundKey
  8400. state[j] ^= key[j];
  8401. }
  8402. return state;
  8403. }
  8404. function encrypt256(input, key) {
  8405. var t, u, v, k;
  8406. var state = new Uint8Array(16);
  8407. state.set(input);
  8408. for (j = 0; j < 16; ++j) {
  8409. // AddRoundKey
  8410. state[j] ^= key[j];
  8411. }
  8412. for (i = 1; i < 14; i++) {
  8413. //SubBytes
  8414. for (j = 0; j < 16; ++j) {
  8415. state[j] = s[state[j]];
  8416. }
  8417. //ShiftRows
  8418. v = state[1];
  8419. state[1] = state[5];
  8420. state[5] = state[9];
  8421. state[9] = state[13];
  8422. state[13] = v;
  8423. v = state[2];
  8424. u = state[6];
  8425. state[2] = state[10];
  8426. state[6] = state[14];
  8427. state[10] = v;
  8428. state[14] = u;
  8429. v = state[3];
  8430. u = state[7];
  8431. t = state[11];
  8432. state[3] = state[15];
  8433. state[7] = v;
  8434. state[11] = u;
  8435. state[15] = t;
  8436. //MixColumns
  8437. for (var j = 0; j < 16; j += 4) {
  8438. var s0 = state[j + 0], s1 = state[j + 1];
  8439. var s2 = state[j + 2], s3 = state[j + 3];
  8440. t = s0 ^ s1 ^ s2 ^ s3;
  8441. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8442. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8443. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8444. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8445. }
  8446. //AddRoundKey
  8447. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8448. state[j] ^= key[k];
  8449. }
  8450. }
  8451. //SubBytes
  8452. for (j = 0; j < 16; ++j) {
  8453. state[j] = s[state[j]];
  8454. }
  8455. //ShiftRows
  8456. v = state[1];
  8457. state[1] = state[5];
  8458. state[5] = state[9];
  8459. state[9] = state[13];
  8460. state[13] = v;
  8461. v = state[2];
  8462. u = state[6];
  8463. state[2] = state[10];
  8464. state[6] = state[14];
  8465. state[10] = v;
  8466. state[14] = u;
  8467. v = state[3];
  8468. u = state[7];
  8469. t = state[11];
  8470. state[3] = state[15];
  8471. state[7] = v;
  8472. state[11] = u;
  8473. state[15] = t;
  8474. //AddRoundKey
  8475. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8476. state[j] ^= key[k];
  8477. }
  8478. return state;
  8479. }
  8480. function AES256Cipher(key) {
  8481. this.key = expandKey256(key);
  8482. this.buffer = new Uint8Array(16);
  8483. this.bufferPosition = 0;
  8484. }
  8485. function decryptBlock2(data, finalize) {
  8486. var i, j, ii, sourceLength = data.length,
  8487. buffer = this.buffer, bufferLength = this.bufferPosition,
  8488. result = [], iv = this.iv;
  8489. for (i = 0; i < sourceLength; ++i) {
  8490. buffer[bufferLength] = data[i];
  8491. ++bufferLength;
  8492. if (bufferLength < 16) {
  8493. continue;
  8494. }
  8495. // buffer is full, decrypting
  8496. var plain = decrypt256(buffer, this.key);
  8497. // xor-ing the IV vector to get plain text
  8498. for (j = 0; j < 16; ++j) {
  8499. plain[j] ^= iv[j];
  8500. }
  8501. iv = buffer;
  8502. result.push(plain);
  8503. buffer = new Uint8Array(16);
  8504. bufferLength = 0;
  8505. }
  8506. // saving incomplete buffer
  8507. this.buffer = buffer;
  8508. this.bufferLength = bufferLength;
  8509. this.iv = iv;
  8510. if (result.length === 0) {
  8511. return new Uint8Array([]);
  8512. }
  8513. // combining plain text blocks into one
  8514. var outputLength = 16 * result.length;
  8515. if (finalize) {
  8516. // undo a padding that is described in RFC 2898
  8517. var lastBlock = result[result.length - 1];
  8518. var psLen = lastBlock[15];
  8519. if (psLen <= 16) {
  8520. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8521. if (lastBlock[i] !== psLen) {
  8522. // Invalid padding, assume that the block has no padding.
  8523. psLen = 0;
  8524. break;
  8525. }
  8526. }
  8527. outputLength -= psLen;
  8528. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8529. }
  8530. }
  8531. var output = new Uint8Array(outputLength);
  8532. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8533. output.set(result[i], j);
  8534. }
  8535. return output;
  8536. }
  8537. AES256Cipher.prototype = {
  8538. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8539. var i, sourceLength = data.length;
  8540. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8541. // if not supplied an IV wait for IV values
  8542. // they are at the start of the stream
  8543. if (iv) {
  8544. this.iv = iv;
  8545. } else {
  8546. for (i = 0; bufferLength < 16 &&
  8547. i < sourceLength; ++i, ++bufferLength) {
  8548. buffer[bufferLength] = data[i];
  8549. }
  8550. if (bufferLength < 16) {
  8551. //need more data
  8552. this.bufferLength = bufferLength;
  8553. return new Uint8Array([]);
  8554. }
  8555. this.iv = buffer;
  8556. data = data.subarray(16);
  8557. }
  8558. this.buffer = new Uint8Array(16);
  8559. this.bufferLength = 0;
  8560. // starting decryption
  8561. this.decryptBlock = decryptBlock2;
  8562. return this.decryptBlock(data, finalize);
  8563. },
  8564. encrypt: function AES256Cipher_encrypt(data, iv) {
  8565. var i, j, ii, sourceLength = data.length,
  8566. buffer = this.buffer, bufferLength = this.bufferPosition,
  8567. result = [];
  8568. if (!iv) {
  8569. iv = new Uint8Array(16);
  8570. }
  8571. for (i = 0; i < sourceLength; ++i) {
  8572. buffer[bufferLength] = data[i];
  8573. ++bufferLength;
  8574. if (bufferLength < 16) {
  8575. continue;
  8576. }
  8577. for (j = 0; j < 16; ++j) {
  8578. buffer[j] ^= iv[j];
  8579. }
  8580. // buffer is full, encrypting
  8581. var cipher = encrypt256(buffer, this.key);
  8582. this.iv = cipher;
  8583. result.push(cipher);
  8584. buffer = new Uint8Array(16);
  8585. bufferLength = 0;
  8586. }
  8587. // saving incomplete buffer
  8588. this.buffer = buffer;
  8589. this.bufferLength = bufferLength;
  8590. this.iv = iv;
  8591. if (result.length === 0) {
  8592. return new Uint8Array([]);
  8593. }
  8594. // combining plain text blocks into one
  8595. var outputLength = 16 * result.length;
  8596. var output = new Uint8Array(outputLength);
  8597. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8598. output.set(result[i], j);
  8599. }
  8600. return output;
  8601. }
  8602. };
  8603. return AES256Cipher;
  8604. })();
  8605. var PDF17 = (function PDF17Closure() {
  8606. function compareByteArrays(array1, array2) {
  8607. if (array1.length !== array2.length) {
  8608. return false;
  8609. }
  8610. for (var i = 0; i < array1.length; i++) {
  8611. if (array1[i] !== array2[i]) {
  8612. return false;
  8613. }
  8614. }
  8615. return true;
  8616. }
  8617. function PDF17() {
  8618. }
  8619. PDF17.prototype = {
  8620. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8621. ownerValidationSalt,
  8622. userBytes,
  8623. ownerPassword) {
  8624. var hashData = new Uint8Array(password.length + 56);
  8625. hashData.set(password, 0);
  8626. hashData.set(ownerValidationSalt, password.length);
  8627. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8628. var result = calculateSHA256(hashData, 0, hashData.length);
  8629. return compareByteArrays(result, ownerPassword);
  8630. },
  8631. checkUserPassword: function PDF17_checkUserPassword(password,
  8632. userValidationSalt,
  8633. userPassword) {
  8634. var hashData = new Uint8Array(password.length + 8);
  8635. hashData.set(password, 0);
  8636. hashData.set(userValidationSalt, password.length);
  8637. var result = calculateSHA256(hashData, 0, hashData.length);
  8638. return compareByteArrays(result, userPassword);
  8639. },
  8640. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8641. ownerEncryption) {
  8642. var hashData = new Uint8Array(password.length + 56);
  8643. hashData.set(password, 0);
  8644. hashData.set(ownerKeySalt, password.length);
  8645. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8646. var key = calculateSHA256(hashData, 0, hashData.length);
  8647. var cipher = new AES256Cipher(key);
  8648. return cipher.decryptBlock(ownerEncryption,
  8649. false,
  8650. new Uint8Array(16));
  8651. },
  8652. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8653. userEncryption) {
  8654. var hashData = new Uint8Array(password.length + 8);
  8655. hashData.set(password, 0);
  8656. hashData.set(userKeySalt, password.length);
  8657. //key is the decryption key for the UE string
  8658. var key = calculateSHA256(hashData, 0, hashData.length);
  8659. var cipher = new AES256Cipher(key);
  8660. return cipher.decryptBlock(userEncryption,
  8661. false,
  8662. new Uint8Array(16));
  8663. }
  8664. };
  8665. return PDF17;
  8666. })();
  8667. var PDF20 = (function PDF20Closure() {
  8668. function concatArrays(array1, array2) {
  8669. var t = new Uint8Array(array1.length + array2.length);
  8670. t.set(array1, 0);
  8671. t.set(array2, array1.length);
  8672. return t;
  8673. }
  8674. function calculatePDF20Hash(password, input, userBytes) {
  8675. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8676. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8677. var e = [0];
  8678. var i = 0;
  8679. while (i < 64 || e[e.length - 1] > i - 32) {
  8680. var arrayLength = password.length + k.length + userBytes.length;
  8681. var k1 = new Uint8Array(arrayLength * 64);
  8682. var array = concatArrays(password, k);
  8683. array = concatArrays(array, userBytes);
  8684. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8685. k1.set(array, pos);
  8686. }
  8687. //AES128 CBC NO PADDING with
  8688. //first 16 bytes of k as the key and the second 16 as the iv.
  8689. var cipher = new AES128Cipher(k.subarray(0, 16));
  8690. e = cipher.encrypt(k1, k.subarray(16, 32));
  8691. //Now we have to take the first 16 bytes of an unsigned
  8692. //big endian integer... and compute the remainder
  8693. //modulo 3.... That is a fairly large number and
  8694. //JavaScript isn't going to handle that well...
  8695. //So we're using a trick that allows us to perform
  8696. //modulo math byte by byte
  8697. var remainder = 0;
  8698. for (var z = 0; z < 16; z++) {
  8699. remainder *= (256 % 3);
  8700. remainder %= 3;
  8701. remainder += ((e[z] >>> 0) % 3);
  8702. remainder %= 3;
  8703. }
  8704. if (remainder === 0) {
  8705. k = calculateSHA256(e, 0, e.length);
  8706. }
  8707. else if (remainder === 1) {
  8708. k = calculateSHA384(e, 0, e.length);
  8709. }
  8710. else if (remainder === 2) {
  8711. k = calculateSHA512(e, 0, e.length);
  8712. }
  8713. i++;
  8714. }
  8715. return k.subarray(0, 32);
  8716. }
  8717. function PDF20() {
  8718. }
  8719. function compareByteArrays(array1, array2) {
  8720. if (array1.length !== array2.length) {
  8721. return false;
  8722. }
  8723. for (var i = 0; i < array1.length; i++) {
  8724. if (array1[i] !== array2[i]) {
  8725. return false;
  8726. }
  8727. }
  8728. return true;
  8729. }
  8730. PDF20.prototype = {
  8731. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8732. return calculatePDF20Hash(password, concatBytes, userBytes);
  8733. },
  8734. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8735. ownerValidationSalt,
  8736. userBytes,
  8737. ownerPassword) {
  8738. var hashData = new Uint8Array(password.length + 56);
  8739. hashData.set(password, 0);
  8740. hashData.set(ownerValidationSalt, password.length);
  8741. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8742. var result = calculatePDF20Hash(password, hashData, userBytes);
  8743. return compareByteArrays(result, ownerPassword);
  8744. },
  8745. checkUserPassword: function PDF20_checkUserPassword(password,
  8746. userValidationSalt,
  8747. userPassword) {
  8748. var hashData = new Uint8Array(password.length + 8);
  8749. hashData.set(password, 0);
  8750. hashData.set(userValidationSalt, password.length);
  8751. var result = calculatePDF20Hash(password, hashData, []);
  8752. return compareByteArrays(result, userPassword);
  8753. },
  8754. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8755. ownerEncryption) {
  8756. var hashData = new Uint8Array(password.length + 56);
  8757. hashData.set(password, 0);
  8758. hashData.set(ownerKeySalt, password.length);
  8759. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8760. var key = calculatePDF20Hash(password, hashData, userBytes);
  8761. var cipher = new AES256Cipher(key);
  8762. return cipher.decryptBlock(ownerEncryption,
  8763. false,
  8764. new Uint8Array(16));
  8765. },
  8766. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8767. userEncryption) {
  8768. var hashData = new Uint8Array(password.length + 8);
  8769. hashData.set(password, 0);
  8770. hashData.set(userKeySalt, password.length);
  8771. //key is the decryption key for the UE string
  8772. var key = calculatePDF20Hash(password, hashData, []);
  8773. var cipher = new AES256Cipher(key);
  8774. return cipher.decryptBlock(userEncryption,
  8775. false,
  8776. new Uint8Array(16));
  8777. }
  8778. };
  8779. return PDF20;
  8780. })();
  8781. var CipherTransform = (function CipherTransformClosure() {
  8782. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8783. this.stringCipherConstructor = stringCipherConstructor;
  8784. this.streamCipherConstructor = streamCipherConstructor;
  8785. }
  8786. CipherTransform.prototype = {
  8787. createStream: function CipherTransform_createStream(stream, length) {
  8788. var cipher = new this.streamCipherConstructor();
  8789. return new DecryptStream(stream, length,
  8790. function cipherTransformDecryptStream(data, finalize) {
  8791. return cipher.decryptBlock(data, finalize);
  8792. }
  8793. );
  8794. },
  8795. decryptString: function CipherTransform_decryptString(s) {
  8796. var cipher = new this.stringCipherConstructor();
  8797. var data = stringToBytes(s);
  8798. data = cipher.decryptBlock(data, true);
  8799. return bytesToString(data);
  8800. }
  8801. };
  8802. return CipherTransform;
  8803. })();
  8804. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8805. var defaultPasswordBytes = new Uint8Array([
  8806. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8807. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8808. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8809. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8810. function createEncryptionKey20(revision, password, ownerPassword,
  8811. ownerValidationSalt, ownerKeySalt, uBytes,
  8812. userPassword, userValidationSalt, userKeySalt,
  8813. ownerEncryption, userEncryption, perms) {
  8814. if (password) {
  8815. var passwordLength = Math.min(127, password.length);
  8816. password = password.subarray(0, passwordLength);
  8817. } else {
  8818. password = [];
  8819. }
  8820. var pdfAlgorithm;
  8821. if (revision === 6) {
  8822. pdfAlgorithm = new PDF20();
  8823. } else {
  8824. pdfAlgorithm = new PDF17();
  8825. }
  8826. if (pdfAlgorithm) {
  8827. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8828. userPassword)) {
  8829. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8830. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  8831. ownerValidationSalt,
  8832. uBytes,
  8833. ownerPassword)) {
  8834. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8835. ownerEncryption);
  8836. }
  8837. }
  8838. return null;
  8839. }
  8840. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8841. flags, revision, keyLength, encryptMetadata) {
  8842. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8843. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8844. if (password) {
  8845. n = Math.min(32, password.length);
  8846. for (; i < n; ++i) {
  8847. hashData[i] = password[i];
  8848. }
  8849. }
  8850. j = 0;
  8851. while (i < 32) {
  8852. hashData[i++] = defaultPasswordBytes[j++];
  8853. }
  8854. // as now the padded password in the hashData[0..i]
  8855. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8856. hashData[i++] = ownerPassword[j];
  8857. }
  8858. hashData[i++] = flags & 0xFF;
  8859. hashData[i++] = (flags >> 8) & 0xFF;
  8860. hashData[i++] = (flags >> 16) & 0xFF;
  8861. hashData[i++] = (flags >>> 24) & 0xFF;
  8862. for (j = 0, n = fileId.length; j < n; ++j) {
  8863. hashData[i++] = fileId[j];
  8864. }
  8865. if (revision >= 4 && !encryptMetadata) {
  8866. hashData[i++] = 0xFF;
  8867. hashData[i++] = 0xFF;
  8868. hashData[i++] = 0xFF;
  8869. hashData[i++] = 0xFF;
  8870. }
  8871. var hash = calculateMD5(hashData, 0, i);
  8872. var keyLengthInBytes = keyLength >> 3;
  8873. if (revision >= 3) {
  8874. for (j = 0; j < 50; ++j) {
  8875. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8876. }
  8877. }
  8878. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8879. var cipher, checkData;
  8880. if (revision >= 3) {
  8881. for (i = 0; i < 32; ++i) {
  8882. hashData[i] = defaultPasswordBytes[i];
  8883. }
  8884. for (j = 0, n = fileId.length; j < n; ++j) {
  8885. hashData[i++] = fileId[j];
  8886. }
  8887. cipher = new ARCFourCipher(encryptionKey);
  8888. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8889. n = encryptionKey.length;
  8890. var derivedKey = new Uint8Array(n), k;
  8891. for (j = 1; j <= 19; ++j) {
  8892. for (k = 0; k < n; ++k) {
  8893. derivedKey[k] = encryptionKey[k] ^ j;
  8894. }
  8895. cipher = new ARCFourCipher(derivedKey);
  8896. checkData = cipher.encryptBlock(checkData);
  8897. }
  8898. for (j = 0, n = checkData.length; j < n; ++j) {
  8899. if (userPassword[j] !== checkData[j]) {
  8900. return null;
  8901. }
  8902. }
  8903. } else {
  8904. cipher = new ARCFourCipher(encryptionKey);
  8905. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8906. for (j = 0, n = checkData.length; j < n; ++j) {
  8907. if (userPassword[j] !== checkData[j]) {
  8908. return null;
  8909. }
  8910. }
  8911. }
  8912. return encryptionKey;
  8913. }
  8914. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8915. var hashData = new Uint8Array(32), i = 0, j, n;
  8916. n = Math.min(32, password.length);
  8917. for (; i < n; ++i) {
  8918. hashData[i] = password[i];
  8919. }
  8920. j = 0;
  8921. while (i < 32) {
  8922. hashData[i++] = defaultPasswordBytes[j++];
  8923. }
  8924. var hash = calculateMD5(hashData, 0, i);
  8925. var keyLengthInBytes = keyLength >> 3;
  8926. if (revision >= 3) {
  8927. for (j = 0; j < 50; ++j) {
  8928. hash = calculateMD5(hash, 0, hash.length);
  8929. }
  8930. }
  8931. var cipher, userPassword;
  8932. if (revision >= 3) {
  8933. userPassword = ownerPassword;
  8934. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8935. for (j = 19; j >= 0; j--) {
  8936. for (k = 0; k < keyLengthInBytes; ++k) {
  8937. derivedKey[k] = hash[k] ^ j;
  8938. }
  8939. cipher = new ARCFourCipher(derivedKey);
  8940. userPassword = cipher.encryptBlock(userPassword);
  8941. }
  8942. } else {
  8943. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8944. userPassword = cipher.encryptBlock(ownerPassword);
  8945. }
  8946. return userPassword;
  8947. }
  8948. var identityName = Name.get('Identity');
  8949. function CipherTransformFactory(dict, fileId, password) {
  8950. var filter = dict.get('Filter');
  8951. if (!isName(filter) || filter.name !== 'Standard') {
  8952. error('unknown encryption method');
  8953. }
  8954. this.dict = dict;
  8955. var algorithm = dict.get('V');
  8956. if (!isInt(algorithm) ||
  8957. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8958. algorithm !== 5)) {
  8959. error('unsupported encryption algorithm');
  8960. }
  8961. this.algorithm = algorithm;
  8962. var keyLength = dict.get('Length') || 40;
  8963. if (!isInt(keyLength) ||
  8964. keyLength < 40 || (keyLength % 8) !== 0) {
  8965. error('invalid key length');
  8966. }
  8967. // prepare keys
  8968. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8969. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8970. var flags = dict.get('P');
  8971. var revision = dict.get('R');
  8972. // meaningful when V is 4 or 5
  8973. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8974. dict.get('EncryptMetadata') !== false);
  8975. this.encryptMetadata = encryptMetadata;
  8976. var fileIdBytes = stringToBytes(fileId);
  8977. var passwordBytes;
  8978. if (password) {
  8979. if (revision === 6) {
  8980. try {
  8981. password = utf8StringToString(password);
  8982. } catch (ex) {
  8983. warn('CipherTransformFactory: ' +
  8984. 'Unable to convert UTF8 encoded password.');
  8985. }
  8986. }
  8987. passwordBytes = stringToBytes(password);
  8988. }
  8989. var encryptionKey;
  8990. if (algorithm !== 5) {
  8991. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8992. ownerPassword, userPassword, flags,
  8993. revision, keyLength, encryptMetadata);
  8994. }
  8995. else {
  8996. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8997. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8998. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8999. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  9000. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  9001. var ownerEncryption = stringToBytes(dict.get('OE'));
  9002. var userEncryption = stringToBytes(dict.get('UE'));
  9003. var perms = stringToBytes(dict.get('Perms'));
  9004. encryptionKey =
  9005. createEncryptionKey20(revision, passwordBytes,
  9006. ownerPassword, ownerValidationSalt,
  9007. ownerKeySalt, uBytes,
  9008. userPassword, userValidationSalt,
  9009. userKeySalt, ownerEncryption,
  9010. userEncryption, perms);
  9011. }
  9012. if (!encryptionKey && !password) {
  9013. throw new PasswordException('No password given',
  9014. PasswordResponses.NEED_PASSWORD);
  9015. } else if (!encryptionKey && password) {
  9016. // Attempting use the password as an owner password
  9017. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  9018. revision, keyLength);
  9019. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  9020. ownerPassword, userPassword, flags,
  9021. revision, keyLength, encryptMetadata);
  9022. }
  9023. if (!encryptionKey) {
  9024. throw new PasswordException('Incorrect Password',
  9025. PasswordResponses.INCORRECT_PASSWORD);
  9026. }
  9027. this.encryptionKey = encryptionKey;
  9028. if (algorithm >= 4) {
  9029. this.cf = dict.get('CF');
  9030. this.stmf = dict.get('StmF') || identityName;
  9031. this.strf = dict.get('StrF') || identityName;
  9032. this.eff = dict.get('EFF') || this.stmf;
  9033. }
  9034. }
  9035. function buildObjectKey(num, gen, encryptionKey, isAes) {
  9036. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  9037. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  9038. key[i] = encryptionKey[i];
  9039. }
  9040. key[i++] = num & 0xFF;
  9041. key[i++] = (num >> 8) & 0xFF;
  9042. key[i++] = (num >> 16) & 0xFF;
  9043. key[i++] = gen & 0xFF;
  9044. key[i++] = (gen >> 8) & 0xFF;
  9045. if (isAes) {
  9046. key[i++] = 0x73;
  9047. key[i++] = 0x41;
  9048. key[i++] = 0x6C;
  9049. key[i++] = 0x54;
  9050. }
  9051. var hash = calculateMD5(key, 0, i);
  9052. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  9053. }
  9054. function buildCipherConstructor(cf, name, num, gen, key) {
  9055. var cryptFilter = cf.get(name.name);
  9056. var cfm;
  9057. if (cryptFilter !== null && cryptFilter !== undefined) {
  9058. cfm = cryptFilter.get('CFM');
  9059. }
  9060. if (!cfm || cfm.name === 'None') {
  9061. return function cipherTransformFactoryBuildCipherConstructorNone() {
  9062. return new NullCipher();
  9063. };
  9064. }
  9065. if ('V2' === cfm.name) {
  9066. return function cipherTransformFactoryBuildCipherConstructorV2() {
  9067. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  9068. };
  9069. }
  9070. if ('AESV2' === cfm.name) {
  9071. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  9072. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  9073. };
  9074. }
  9075. if ('AESV3' === cfm.name) {
  9076. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  9077. return new AES256Cipher(key);
  9078. };
  9079. }
  9080. error('Unknown crypto method');
  9081. }
  9082. CipherTransformFactory.prototype = {
  9083. createCipherTransform:
  9084. function CipherTransformFactory_createCipherTransform(num, gen) {
  9085. if (this.algorithm === 4 || this.algorithm === 5) {
  9086. return new CipherTransform(
  9087. buildCipherConstructor(this.cf, this.stmf,
  9088. num, gen, this.encryptionKey),
  9089. buildCipherConstructor(this.cf, this.strf,
  9090. num, gen, this.encryptionKey));
  9091. }
  9092. // algorithms 1 and 2
  9093. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  9094. var cipherConstructor = function buildCipherCipherConstructor() {
  9095. return new ARCFourCipher(key);
  9096. };
  9097. return new CipherTransform(cipherConstructor, cipherConstructor);
  9098. }
  9099. };
  9100. return CipherTransformFactory;
  9101. })();
  9102. var ShadingType = {
  9103. FUNCTION_BASED: 1,
  9104. AXIAL: 2,
  9105. RADIAL: 3,
  9106. FREE_FORM_MESH: 4,
  9107. LATTICE_FORM_MESH: 5,
  9108. COONS_PATCH_MESH: 6,
  9109. TENSOR_PATCH_MESH: 7
  9110. };
  9111. var Pattern = (function PatternClosure() {
  9112. // Constructor should define this.getPattern
  9113. function Pattern() {
  9114. error('should not call Pattern constructor');
  9115. }
  9116. Pattern.prototype = {
  9117. // Input: current Canvas context
  9118. // Output: the appropriate fillStyle or strokeStyle
  9119. getPattern: function Pattern_getPattern(ctx) {
  9120. error('Should not call Pattern.getStyle: ' + ctx);
  9121. }
  9122. };
  9123. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  9124. res) {
  9125. var dict = isStream(shading) ? shading.dict : shading;
  9126. var type = dict.get('ShadingType');
  9127. try {
  9128. switch (type) {
  9129. case ShadingType.AXIAL:
  9130. case ShadingType.RADIAL:
  9131. // Both radial and axial shadings are handled by RadialAxial shading.
  9132. return new Shadings.RadialAxial(dict, matrix, xref, res);
  9133. case ShadingType.FREE_FORM_MESH:
  9134. case ShadingType.LATTICE_FORM_MESH:
  9135. case ShadingType.COONS_PATCH_MESH:
  9136. case ShadingType.TENSOR_PATCH_MESH:
  9137. return new Shadings.Mesh(shading, matrix, xref, res);
  9138. default:
  9139. throw new Error('Unsupported ShadingType: ' + type);
  9140. }
  9141. } catch (ex) {
  9142. if (ex instanceof MissingDataException) {
  9143. throw ex;
  9144. }
  9145. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  9146. warn(ex);
  9147. return new Shadings.Dummy();
  9148. }
  9149. };
  9150. return Pattern;
  9151. })();
  9152. var Shadings = {};
  9153. // A small number to offset the first/last color stops so we can insert ones to
  9154. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  9155. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  9156. // internally so we have to go bigger.
  9157. Shadings.SMALL_NUMBER = 1e-2;
  9158. // Radial and axial shading have very similar implementations
  9159. // If needed, the implementations can be broken into two classes
  9160. Shadings.RadialAxial = (function RadialAxialClosure() {
  9161. function RadialAxial(dict, matrix, xref, res) {
  9162. this.matrix = matrix;
  9163. this.coordsArr = dict.get('Coords');
  9164. this.shadingType = dict.get('ShadingType');
  9165. this.type = 'Pattern';
  9166. var cs = dict.get('ColorSpace', 'CS');
  9167. cs = ColorSpace.parse(cs, xref, res);
  9168. this.cs = cs;
  9169. var t0 = 0.0, t1 = 1.0;
  9170. if (dict.has('Domain')) {
  9171. var domainArr = dict.get('Domain');
  9172. t0 = domainArr[0];
  9173. t1 = domainArr[1];
  9174. }
  9175. var extendStart = false, extendEnd = false;
  9176. if (dict.has('Extend')) {
  9177. var extendArr = dict.get('Extend');
  9178. extendStart = extendArr[0];
  9179. extendEnd = extendArr[1];
  9180. }
  9181. if (this.shadingType === ShadingType.RADIAL &&
  9182. (!extendStart || !extendEnd)) {
  9183. // Radial gradient only currently works if either circle is fully within
  9184. // the other circle.
  9185. var x1 = this.coordsArr[0];
  9186. var y1 = this.coordsArr[1];
  9187. var r1 = this.coordsArr[2];
  9188. var x2 = this.coordsArr[3];
  9189. var y2 = this.coordsArr[4];
  9190. var r2 = this.coordsArr[5];
  9191. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  9192. if (r1 <= r2 + distance &&
  9193. r2 <= r1 + distance) {
  9194. warn('Unsupported radial gradient.');
  9195. }
  9196. }
  9197. this.extendStart = extendStart;
  9198. this.extendEnd = extendEnd;
  9199. var fnObj = dict.get('Function');
  9200. var fn = PDFFunction.parseArray(xref, fnObj);
  9201. // 10 samples seems good enough for now, but probably won't work
  9202. // if there are sharp color changes. Ideally, we would implement
  9203. // the spec faithfully and add lossless optimizations.
  9204. var diff = t1 - t0;
  9205. var step = diff / 10;
  9206. var colorStops = this.colorStops = [];
  9207. // Protect against bad domains so we don't end up in an infinte loop below.
  9208. if (t0 >= t1 || step <= 0) {
  9209. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9210. // now.
  9211. info('Bad shading domain.');
  9212. return;
  9213. }
  9214. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9215. var rgbColor;
  9216. for (var i = t0; i <= t1; i += step) {
  9217. ratio[0] = i;
  9218. fn(ratio, 0, color, 0);
  9219. rgbColor = cs.getRgb(color, 0);
  9220. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9221. colorStops.push([(i - t0) / diff, cssColor]);
  9222. }
  9223. var background = 'transparent';
  9224. if (dict.has('Background')) {
  9225. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9226. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9227. }
  9228. if (!extendStart) {
  9229. // Insert a color stop at the front and offset the first real color stop
  9230. // so it doesn't conflict with the one we insert.
  9231. colorStops.unshift([0, background]);
  9232. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9233. }
  9234. if (!extendEnd) {
  9235. // Same idea as above in extendStart but for the end.
  9236. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9237. colorStops.push([1, background]);
  9238. }
  9239. this.colorStops = colorStops;
  9240. }
  9241. RadialAxial.prototype = {
  9242. getIR: function RadialAxial_getIR() {
  9243. var coordsArr = this.coordsArr;
  9244. var shadingType = this.shadingType;
  9245. var type, p0, p1, r0, r1;
  9246. if (shadingType === ShadingType.AXIAL) {
  9247. p0 = [coordsArr[0], coordsArr[1]];
  9248. p1 = [coordsArr[2], coordsArr[3]];
  9249. r0 = null;
  9250. r1 = null;
  9251. type = 'axial';
  9252. } else if (shadingType === ShadingType.RADIAL) {
  9253. p0 = [coordsArr[0], coordsArr[1]];
  9254. p1 = [coordsArr[3], coordsArr[4]];
  9255. r0 = coordsArr[2];
  9256. r1 = coordsArr[5];
  9257. type = 'radial';
  9258. } else {
  9259. error('getPattern type unknown: ' + shadingType);
  9260. }
  9261. var matrix = this.matrix;
  9262. if (matrix) {
  9263. p0 = Util.applyTransform(p0, matrix);
  9264. p1 = Util.applyTransform(p1, matrix);
  9265. if (shadingType === ShadingType.RADIAL) {
  9266. var scale = Util.singularValueDecompose2dScale(matrix);
  9267. r0 *= scale[0];
  9268. r1 *= scale[1];
  9269. }
  9270. }
  9271. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9272. }
  9273. };
  9274. return RadialAxial;
  9275. })();
  9276. // All mesh shading. For now, they will be presented as set of the triangles
  9277. // to be drawn on the canvas and rgb color for each vertex.
  9278. Shadings.Mesh = (function MeshClosure() {
  9279. function MeshStreamReader(stream, context) {
  9280. this.stream = stream;
  9281. this.context = context;
  9282. this.buffer = 0;
  9283. this.bufferLength = 0;
  9284. var numComps = context.numComps;
  9285. this.tmpCompsBuf = new Float32Array(numComps);
  9286. var csNumComps = context.colorSpace.numComps;
  9287. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9288. this.tmpCompsBuf;
  9289. }
  9290. MeshStreamReader.prototype = {
  9291. get hasData() {
  9292. if (this.stream.end) {
  9293. return this.stream.pos < this.stream.end;
  9294. }
  9295. if (this.bufferLength > 0) {
  9296. return true;
  9297. }
  9298. var nextByte = this.stream.getByte();
  9299. if (nextByte < 0) {
  9300. return false;
  9301. }
  9302. this.buffer = nextByte;
  9303. this.bufferLength = 8;
  9304. return true;
  9305. },
  9306. readBits: function MeshStreamReader_readBits(n) {
  9307. var buffer = this.buffer;
  9308. var bufferLength = this.bufferLength;
  9309. if (n === 32) {
  9310. if (bufferLength === 0) {
  9311. return ((this.stream.getByte() << 24) |
  9312. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9313. this.stream.getByte()) >>> 0;
  9314. }
  9315. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9316. (this.stream.getByte() << 8) | this.stream.getByte();
  9317. var nextByte = this.stream.getByte();
  9318. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9319. return ((buffer << (8 - bufferLength)) |
  9320. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9321. }
  9322. if (n === 8 && bufferLength === 0) {
  9323. return this.stream.getByte();
  9324. }
  9325. while (bufferLength < n) {
  9326. buffer = (buffer << 8) | this.stream.getByte();
  9327. bufferLength += 8;
  9328. }
  9329. bufferLength -= n;
  9330. this.bufferLength = bufferLength;
  9331. this.buffer = buffer & ((1 << bufferLength) - 1);
  9332. return buffer >> bufferLength;
  9333. },
  9334. align: function MeshStreamReader_align() {
  9335. this.buffer = 0;
  9336. this.bufferLength = 0;
  9337. },
  9338. readFlag: function MeshStreamReader_readFlag() {
  9339. return this.readBits(this.context.bitsPerFlag);
  9340. },
  9341. readCoordinate: function MeshStreamReader_readCoordinate() {
  9342. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9343. var xi = this.readBits(bitsPerCoordinate);
  9344. var yi = this.readBits(bitsPerCoordinate);
  9345. var decode = this.context.decode;
  9346. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9347. 2.3283064365386963e-10; // 2 ^ -32
  9348. return [
  9349. xi * scale * (decode[1] - decode[0]) + decode[0],
  9350. yi * scale * (decode[3] - decode[2]) + decode[2]
  9351. ];
  9352. },
  9353. readComponents: function MeshStreamReader_readComponents() {
  9354. var numComps = this.context.numComps;
  9355. var bitsPerComponent = this.context.bitsPerComponent;
  9356. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9357. 2.3283064365386963e-10; // 2 ^ -32
  9358. var decode = this.context.decode;
  9359. var components = this.tmpCompsBuf;
  9360. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9361. var ci = this.readBits(bitsPerComponent);
  9362. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9363. }
  9364. var color = this.tmpCsCompsBuf;
  9365. if (this.context.colorFn) {
  9366. this.context.colorFn(components, 0, color, 0);
  9367. }
  9368. return this.context.colorSpace.getRgb(color, 0);
  9369. }
  9370. };
  9371. function decodeType4Shading(mesh, reader) {
  9372. var coords = mesh.coords;
  9373. var colors = mesh.colors;
  9374. var operators = [];
  9375. var ps = []; // not maintaining cs since that will match ps
  9376. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9377. while (reader.hasData) {
  9378. var f = reader.readFlag();
  9379. var coord = reader.readCoordinate();
  9380. var color = reader.readComponents();
  9381. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9382. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9383. switch (f) {
  9384. case 0:
  9385. verticesLeft = 3;
  9386. break;
  9387. case 1:
  9388. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9389. verticesLeft = 1;
  9390. break;
  9391. case 2:
  9392. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9393. verticesLeft = 1;
  9394. break;
  9395. }
  9396. operators.push(f);
  9397. }
  9398. ps.push(coords.length);
  9399. coords.push(coord);
  9400. colors.push(color);
  9401. verticesLeft--;
  9402. reader.align();
  9403. }
  9404. mesh.figures.push({
  9405. type: 'triangles',
  9406. coords: new Int32Array(ps),
  9407. colors: new Int32Array(ps),
  9408. });
  9409. }
  9410. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9411. var coords = mesh.coords;
  9412. var colors = mesh.colors;
  9413. var ps = []; // not maintaining cs since that will match ps
  9414. while (reader.hasData) {
  9415. var coord = reader.readCoordinate();
  9416. var color = reader.readComponents();
  9417. ps.push(coords.length);
  9418. coords.push(coord);
  9419. colors.push(color);
  9420. }
  9421. mesh.figures.push({
  9422. type: 'lattice',
  9423. coords: new Int32Array(ps),
  9424. colors: new Int32Array(ps),
  9425. verticesPerRow: verticesPerRow
  9426. });
  9427. }
  9428. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9429. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9430. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9431. var getB = (function getBClosure() {
  9432. function buildB(count) {
  9433. var lut = [];
  9434. for (var i = 0; i <= count; i++) {
  9435. var t = i / count, t_ = 1 - t;
  9436. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9437. 3 * t * t * t_, t * t * t]));
  9438. }
  9439. return lut;
  9440. }
  9441. var cache = [];
  9442. return function getB(count) {
  9443. if (!cache[count]) {
  9444. cache[count] = buildB(count);
  9445. }
  9446. return cache[count];
  9447. };
  9448. })();
  9449. function buildFigureFromPatch(mesh, index) {
  9450. var figure = mesh.figures[index];
  9451. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9452. var coords = mesh.coords, colors = mesh.colors;
  9453. var pi = figure.coords;
  9454. var ci = figure.colors;
  9455. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9456. coords[pi[12]][0], coords[pi[15]][0]);
  9457. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9458. coords[pi[12]][1], coords[pi[15]][1]);
  9459. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9460. coords[pi[12]][0], coords[pi[15]][0]);
  9461. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9462. coords[pi[12]][1], coords[pi[15]][1]);
  9463. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9464. (mesh.bounds[2] - mesh.bounds[0]));
  9465. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9466. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9467. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9468. (mesh.bounds[3] - mesh.bounds[1]));
  9469. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9470. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9471. var verticesPerRow = splitXBy + 1;
  9472. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9473. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9474. var k = 0;
  9475. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9476. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9477. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9478. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9479. for (var row = 0; row <= splitYBy; row++) {
  9480. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9481. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9482. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9483. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9484. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9485. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9486. for (var col = 0; col <= splitXBy; col++, k++) {
  9487. if ((row === 0 || row === splitYBy) &&
  9488. (col === 0 || col === splitXBy)) {
  9489. continue;
  9490. }
  9491. var x = 0, y = 0;
  9492. var q = 0;
  9493. for (var i = 0; i <= 3; i++) {
  9494. for (var j = 0; j <= 3; j++, q++) {
  9495. var m = bRow[row][i] * bCol[col][j];
  9496. x += coords[pi[q]][0] * m;
  9497. y += coords[pi[q]][1] * m;
  9498. }
  9499. }
  9500. figureCoords[k] = coords.length;
  9501. coords.push([x, y]);
  9502. figureColors[k] = colors.length;
  9503. var newColor = new Uint8Array(3);
  9504. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9505. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9506. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9507. colors.push(newColor);
  9508. }
  9509. }
  9510. figureCoords[0] = pi[0];
  9511. figureColors[0] = ci[0];
  9512. figureCoords[splitXBy] = pi[3];
  9513. figureColors[splitXBy] = ci[1];
  9514. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9515. figureColors[verticesPerRow * splitYBy] = ci[2];
  9516. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9517. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9518. mesh.figures[index] = {
  9519. type: 'lattice',
  9520. coords: figureCoords,
  9521. colors: figureColors,
  9522. verticesPerRow: verticesPerRow
  9523. };
  9524. }
  9525. function decodeType6Shading(mesh, reader) {
  9526. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9527. var coords = mesh.coords;
  9528. var colors = mesh.colors;
  9529. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9530. var cs = new Int32Array(4); // c00, c30, c03, c33
  9531. while (reader.hasData) {
  9532. var f = reader.readFlag();
  9533. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9534. var i, ii;
  9535. var pi = coords.length;
  9536. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9537. coords.push(reader.readCoordinate());
  9538. }
  9539. var ci = colors.length;
  9540. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9541. colors.push(reader.readComponents());
  9542. }
  9543. var tmp1, tmp2, tmp3, tmp4;
  9544. switch (f) {
  9545. case 0:
  9546. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9547. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9548. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9549. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9550. cs[2] = ci + 1; cs[3] = ci + 2;
  9551. cs[0] = ci; cs[1] = ci + 3;
  9552. break;
  9553. case 1:
  9554. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9555. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9556. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9557. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  9558. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9559. tmp1 = cs[2]; tmp2 = cs[3];
  9560. cs[2] = tmp2; cs[3] = ci;
  9561. cs[0] = tmp1; cs[1] = ci + 1;
  9562. break;
  9563. case 2:
  9564. tmp1 = ps[15];
  9565. tmp2 = ps[11];
  9566. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9567. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9568. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  9569. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9570. tmp1 = cs[3];
  9571. cs[2] = cs[1]; cs[3] = ci;
  9572. cs[0] = tmp1; cs[1] = ci + 1;
  9573. break;
  9574. case 3:
  9575. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9576. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9577. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  9578. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9579. cs[2] = cs[0]; cs[3] = ci;
  9580. cs[0] = cs[1]; cs[1] = ci + 1;
  9581. break;
  9582. }
  9583. // set p11, p12, p21, p22
  9584. ps[5] = coords.length;
  9585. coords.push([
  9586. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9587. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9588. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9589. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9590. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9591. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9592. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9593. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9594. ]);
  9595. ps[6] = coords.length;
  9596. coords.push([
  9597. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9598. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9599. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9600. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9601. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9602. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9603. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9604. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9605. ]);
  9606. ps[9] = coords.length;
  9607. coords.push([
  9608. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9609. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9610. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9611. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9612. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9613. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9614. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9615. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9616. ]);
  9617. ps[10] = coords.length;
  9618. coords.push([
  9619. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9620. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9621. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9622. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9623. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9624. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9625. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9626. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9627. ]);
  9628. mesh.figures.push({
  9629. type: 'patch',
  9630. coords: new Int32Array(ps), // making copies of ps and cs
  9631. colors: new Int32Array(cs)
  9632. });
  9633. }
  9634. }
  9635. function decodeType7Shading(mesh, reader) {
  9636. var coords = mesh.coords;
  9637. var colors = mesh.colors;
  9638. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9639. var cs = new Int32Array(4); // c00, c30, c03, c33
  9640. while (reader.hasData) {
  9641. var f = reader.readFlag();
  9642. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9643. var i, ii;
  9644. var pi = coords.length;
  9645. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9646. coords.push(reader.readCoordinate());
  9647. }
  9648. var ci = colors.length;
  9649. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9650. colors.push(reader.readComponents());
  9651. }
  9652. var tmp1, tmp2, tmp3, tmp4;
  9653. switch (f) {
  9654. case 0:
  9655. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9656. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9657. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9658. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9659. cs[2] = ci + 1; cs[3] = ci + 2;
  9660. cs[0] = ci; cs[1] = ci + 3;
  9661. break;
  9662. case 1:
  9663. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9664. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9665. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9666. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9667. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9668. tmp1 = cs[2]; tmp2 = cs[3];
  9669. cs[2] = tmp2; cs[3] = ci;
  9670. cs[0] = tmp1; cs[1] = ci + 1;
  9671. break;
  9672. case 2:
  9673. tmp1 = ps[15];
  9674. tmp2 = ps[11];
  9675. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9676. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9677. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9678. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9679. tmp1 = cs[3];
  9680. cs[2] = cs[1]; cs[3] = ci;
  9681. cs[0] = tmp1; cs[1] = ci + 1;
  9682. break;
  9683. case 3:
  9684. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9685. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9686. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9687. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9688. cs[2] = cs[0]; cs[3] = ci;
  9689. cs[0] = cs[1]; cs[1] = ci + 1;
  9690. break;
  9691. }
  9692. mesh.figures.push({
  9693. type: 'patch',
  9694. coords: new Int32Array(ps), // making copies of ps and cs
  9695. colors: new Int32Array(cs)
  9696. });
  9697. }
  9698. }
  9699. function updateBounds(mesh) {
  9700. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9701. maxX = minX, maxY = minY;
  9702. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9703. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9704. minX = minX > x ? x : minX;
  9705. minY = minY > y ? y : minY;
  9706. maxX = maxX < x ? x : maxX;
  9707. maxY = maxY < y ? y : maxY;
  9708. }
  9709. mesh.bounds = [minX, minY, maxX, maxY];
  9710. }
  9711. function packData(mesh) {
  9712. var i, ii, j, jj;
  9713. var coords = mesh.coords;
  9714. var coordsPacked = new Float32Array(coords.length * 2);
  9715. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9716. var xy = coords[i];
  9717. coordsPacked[j++] = xy[0];
  9718. coordsPacked[j++] = xy[1];
  9719. }
  9720. mesh.coords = coordsPacked;
  9721. var colors = mesh.colors;
  9722. var colorsPacked = new Uint8Array(colors.length * 3);
  9723. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9724. var c = colors[i];
  9725. colorsPacked[j++] = c[0];
  9726. colorsPacked[j++] = c[1];
  9727. colorsPacked[j++] = c[2];
  9728. }
  9729. mesh.colors = colorsPacked;
  9730. var figures = mesh.figures;
  9731. for (i = 0, ii = figures.length; i < ii; i++) {
  9732. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9733. for (j = 0, jj = ps.length; j < jj; j++) {
  9734. ps[j] *= 2;
  9735. cs[j] *= 3;
  9736. }
  9737. }
  9738. }
  9739. function Mesh(stream, matrix, xref, res) {
  9740. assert(isStream(stream), 'Mesh data is not a stream');
  9741. var dict = stream.dict;
  9742. this.matrix = matrix;
  9743. this.shadingType = dict.get('ShadingType');
  9744. this.type = 'Pattern';
  9745. this.bbox = dict.get('BBox');
  9746. var cs = dict.get('ColorSpace', 'CS');
  9747. cs = ColorSpace.parse(cs, xref, res);
  9748. this.cs = cs;
  9749. this.background = dict.has('Background') ?
  9750. cs.getRgb(dict.get('Background'), 0) : null;
  9751. var fnObj = dict.get('Function');
  9752. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9753. this.coords = [];
  9754. this.colors = [];
  9755. this.figures = [];
  9756. var decodeContext = {
  9757. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9758. bitsPerComponent: dict.get('BitsPerComponent'),
  9759. bitsPerFlag: dict.get('BitsPerFlag'),
  9760. decode: dict.get('Decode'),
  9761. colorFn: fn,
  9762. colorSpace: cs,
  9763. numComps: fn ? 1 : cs.numComps
  9764. };
  9765. var reader = new MeshStreamReader(stream, decodeContext);
  9766. var patchMesh = false;
  9767. switch (this.shadingType) {
  9768. case ShadingType.FREE_FORM_MESH:
  9769. decodeType4Shading(this, reader);
  9770. break;
  9771. case ShadingType.LATTICE_FORM_MESH:
  9772. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9773. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9774. decodeType5Shading(this, reader, verticesPerRow);
  9775. break;
  9776. case ShadingType.COONS_PATCH_MESH:
  9777. decodeType6Shading(this, reader);
  9778. patchMesh = true;
  9779. break;
  9780. case ShadingType.TENSOR_PATCH_MESH:
  9781. decodeType7Shading(this, reader);
  9782. patchMesh = true;
  9783. break;
  9784. default:
  9785. error('Unsupported mesh type.');
  9786. break;
  9787. }
  9788. if (patchMesh) {
  9789. // dirty bounds calculation for determining, how dense shall be triangles
  9790. updateBounds(this);
  9791. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9792. buildFigureFromPatch(this, i);
  9793. }
  9794. }
  9795. // calculate bounds
  9796. updateBounds(this);
  9797. packData(this);
  9798. }
  9799. Mesh.prototype = {
  9800. getIR: function Mesh_getIR() {
  9801. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9802. this.bounds, this.matrix, this.bbox, this.background];
  9803. }
  9804. };
  9805. return Mesh;
  9806. })();
  9807. Shadings.Dummy = (function DummyClosure() {
  9808. function Dummy() {
  9809. this.type = 'Pattern';
  9810. }
  9811. Dummy.prototype = {
  9812. getIR: function Dummy_getIR() {
  9813. return ['Dummy'];
  9814. }
  9815. };
  9816. return Dummy;
  9817. })();
  9818. function getTilingPatternIR(operatorList, dict, args) {
  9819. var matrix = dict.get('Matrix');
  9820. var bbox = dict.get('BBox');
  9821. var xstep = dict.get('XStep');
  9822. var ystep = dict.get('YStep');
  9823. var paintType = dict.get('PaintType');
  9824. var tilingType = dict.get('TilingType');
  9825. return [
  9826. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9827. paintType, tilingType
  9828. ];
  9829. }
  9830. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9831. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9832. uniquePrefix, idCounters, fontCache) {
  9833. this.pdfManager = pdfManager;
  9834. this.xref = xref;
  9835. this.handler = handler;
  9836. this.pageIndex = pageIndex;
  9837. this.uniquePrefix = uniquePrefix;
  9838. this.idCounters = idCounters;
  9839. this.fontCache = fontCache;
  9840. }
  9841. // Trying to minimize Date.now() usage and check every 100 time
  9842. var TIME_SLOT_DURATION_MS = 20;
  9843. var CHECK_TIME_EVERY = 100;
  9844. function TimeSlotManager() {
  9845. this.reset();
  9846. }
  9847. TimeSlotManager.prototype = {
  9848. check: function TimeSlotManager_check() {
  9849. if (++this.checked < CHECK_TIME_EVERY) {
  9850. return false;
  9851. }
  9852. this.checked = 0;
  9853. return this.endTime <= Date.now();
  9854. },
  9855. reset: function TimeSlotManager_reset() {
  9856. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9857. this.checked = 0;
  9858. }
  9859. };
  9860. var deferred = Promise.resolve();
  9861. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9862. PartialEvaluator.prototype = {
  9863. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9864. if (!isDict(resources)) {
  9865. return false;
  9866. }
  9867. var processed = Object.create(null);
  9868. if (resources.objId) {
  9869. processed[resources.objId] = true;
  9870. }
  9871. var nodes = [resources];
  9872. while (nodes.length) {
  9873. var key;
  9874. var node = nodes.shift();
  9875. // First check the current resources for blend modes.
  9876. var graphicStates = node.get('ExtGState');
  9877. if (isDict(graphicStates)) {
  9878. graphicStates = graphicStates.getAll();
  9879. for (key in graphicStates) {
  9880. var graphicState = graphicStates[key];
  9881. var bm = graphicState['BM'];
  9882. if (isName(bm) && bm.name !== 'Normal') {
  9883. return true;
  9884. }
  9885. }
  9886. }
  9887. // Descend into the XObjects to look for more resources and blend modes.
  9888. var xObjects = node.get('XObject');
  9889. if (!isDict(xObjects)) {
  9890. continue;
  9891. }
  9892. xObjects = xObjects.getAll();
  9893. for (key in xObjects) {
  9894. var xObject = xObjects[key];
  9895. if (!isStream(xObject)) {
  9896. continue;
  9897. }
  9898. if (xObject.dict.objId) {
  9899. if (processed[xObject.dict.objId]) {
  9900. // stream has objId and is processed already
  9901. continue;
  9902. }
  9903. processed[xObject.dict.objId] = true;
  9904. }
  9905. var xResources = xObject.dict.get('Resources');
  9906. // Checking objId to detect an infinite loop.
  9907. if (isDict(xResources) &&
  9908. (!xResources.objId || !processed[xResources.objId])) {
  9909. nodes.push(xResources);
  9910. if (xResources.objId) {
  9911. processed[xResources.objId] = true;
  9912. }
  9913. }
  9914. }
  9915. }
  9916. return false;
  9917. },
  9918. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9919. xobj, smask,
  9920. operatorList,
  9921. task,
  9922. initialState) {
  9923. var matrix = xobj.dict.getArray('Matrix');
  9924. var bbox = xobj.dict.getArray('BBox');
  9925. var group = xobj.dict.get('Group');
  9926. if (group) {
  9927. var groupOptions = {
  9928. matrix: matrix,
  9929. bbox: bbox,
  9930. smask: smask,
  9931. isolated: false,
  9932. knockout: false
  9933. };
  9934. var groupSubtype = group.get('S');
  9935. var colorSpace;
  9936. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9937. groupOptions.isolated = (group.get('I') || false);
  9938. groupOptions.knockout = (group.get('K') || false);
  9939. colorSpace = (group.has('CS') ?
  9940. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9941. }
  9942. if (smask && smask.backdrop) {
  9943. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9944. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9945. }
  9946. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9947. }
  9948. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9949. return this.getOperatorList(xobj, task,
  9950. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9951. then(function () {
  9952. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9953. if (group) {
  9954. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9955. }
  9956. });
  9957. },
  9958. buildPaintImageXObject:
  9959. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9960. inline, operatorList,
  9961. cacheKey, imageCache) {
  9962. var self = this;
  9963. var dict = image.dict;
  9964. var w = dict.get('Width', 'W');
  9965. var h = dict.get('Height', 'H');
  9966. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9967. warn('Image dimensions are missing, or not numbers.');
  9968. return;
  9969. }
  9970. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9971. warn('Image exceeded maximum allowed size and was removed.');
  9972. return;
  9973. }
  9974. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9975. var imgData, args;
  9976. if (imageMask) {
  9977. // This depends on a tmpCanvas being filled with the
  9978. // current fillStyle, such that processing the pixel
  9979. // data can't be done here. Instead of creating a
  9980. // complete PDFImage, only read the information needed
  9981. // for later.
  9982. var width = dict.get('Width', 'W');
  9983. var height = dict.get('Height', 'H');
  9984. var bitStrideLength = (width + 7) >> 3;
  9985. var imgArray = image.getBytes(bitStrideLength * height);
  9986. var decode = dict.get('Decode', 'D');
  9987. var inverseDecode = (!!decode && decode[0] > 0);
  9988. imgData = PDFImage.createMask(imgArray, width, height,
  9989. image instanceof DecodeStream,
  9990. inverseDecode);
  9991. imgData.cached = true;
  9992. args = [imgData];
  9993. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9994. if (cacheKey) {
  9995. imageCache[cacheKey] = {
  9996. fn: OPS.paintImageMaskXObject,
  9997. args: args
  9998. };
  9999. }
  10000. return;
  10001. }
  10002. var softMask = (dict.get('SMask', 'SM') || false);
  10003. var mask = (dict.get('Mask') || false);
  10004. var SMALL_IMAGE_DIMENSIONS = 200;
  10005. // Inlining small images into the queue as RGB data
  10006. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  10007. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  10008. var imageObj = new PDFImage(this.xref, resources, image,
  10009. inline, null, null);
  10010. // We force the use of RGBA_32BPP images here, because we can't handle
  10011. // any other kind.
  10012. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  10013. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  10014. return;
  10015. }
  10016. // If there is no imageMask, create the PDFImage and a lot
  10017. // of image processing can be done here.
  10018. var uniquePrefix = (this.uniquePrefix || '');
  10019. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  10020. operatorList.addDependency(objId);
  10021. args = [objId, w, h];
  10022. if (!softMask && !mask && image instanceof JpegStream &&
  10023. image.isNativelySupported(this.xref, resources)) {
  10024. // These JPEGs don't need any more processing so we can just send it.
  10025. operatorList.addOp(OPS.paintJpegXObject, args);
  10026. this.handler.send('obj',
  10027. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  10028. return;
  10029. }
  10030. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  10031. then(function(imageObj) {
  10032. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  10033. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  10034. [imgData.data.buffer]);
  10035. }).then(undefined, function (reason) {
  10036. warn('Unable to decode image: ' + reason);
  10037. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  10038. });
  10039. operatorList.addOp(OPS.paintImageXObject, args);
  10040. if (cacheKey) {
  10041. imageCache[cacheKey] = {
  10042. fn: OPS.paintImageXObject,
  10043. args: args
  10044. };
  10045. }
  10046. },
  10047. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  10048. operatorList, task,
  10049. stateManager) {
  10050. var smaskContent = smask.get('G');
  10051. var smaskOptions = {
  10052. subtype: smask.get('S').name,
  10053. backdrop: smask.get('BC')
  10054. };
  10055. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  10056. operatorList, task, stateManager.state.clone());
  10057. },
  10058. handleTilingType:
  10059. function PartialEvaluator_handleTilingType(fn, args, resources,
  10060. pattern, patternDict,
  10061. operatorList, task) {
  10062. // Create an IR of the pattern code.
  10063. var tilingOpList = new OperatorList();
  10064. // Merge the available resources, to prevent issues when the patternDict
  10065. // is missing some /Resources entries (fixes issue6541.pdf).
  10066. var resourcesArray = [patternDict.get('Resources'), resources];
  10067. var patternResources = Dict.merge(this.xref, resourcesArray);
  10068. return this.getOperatorList(pattern, task, patternResources,
  10069. tilingOpList).then(function () {
  10070. // Add the dependencies to the parent operator list so they are
  10071. // resolved before sub operator list is executed synchronously.
  10072. operatorList.addDependencies(tilingOpList.dependencies);
  10073. operatorList.addOp(fn, getTilingPatternIR({
  10074. fnArray: tilingOpList.fnArray,
  10075. argsArray: tilingOpList.argsArray
  10076. }, patternDict, args));
  10077. });
  10078. },
  10079. handleSetFont:
  10080. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  10081. operatorList, task, state) {
  10082. // TODO(mack): Not needed?
  10083. var fontName;
  10084. if (fontArgs) {
  10085. fontArgs = fontArgs.slice();
  10086. fontName = fontArgs[0].name;
  10087. }
  10088. var self = this;
  10089. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  10090. function (translated) {
  10091. if (!translated.font.isType3Font) {
  10092. return translated;
  10093. }
  10094. return translated.loadType3Data(self, resources, operatorList, task).
  10095. then(function () {
  10096. return translated;
  10097. });
  10098. }).then(function (translated) {
  10099. state.font = translated.font;
  10100. translated.send(self.handler);
  10101. return translated.loadedName;
  10102. });
  10103. },
  10104. handleText: function PartialEvaluator_handleText(chars, state) {
  10105. var font = state.font;
  10106. var glyphs = font.charsToGlyphs(chars);
  10107. var isAddToPathSet = !!(state.textRenderingMode &
  10108. TextRenderingMode.ADD_TO_PATH_FLAG);
  10109. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  10110. var buildPath = function (fontChar) {
  10111. if (!font.renderer.hasBuiltPath(fontChar)) {
  10112. var path = font.renderer.getPathJs(fontChar);
  10113. this.handler.send('commonobj', [
  10114. font.loadedName + '_path_' + fontChar,
  10115. 'FontPath',
  10116. path
  10117. ]);
  10118. }
  10119. }.bind(this);
  10120. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  10121. var glyph = glyphs[i];
  10122. buildPath(glyph.fontChar);
  10123. // If the glyph has an accent we need to build a path for its
  10124. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  10125. var accent = glyph.accent;
  10126. if (accent && accent.fontChar) {
  10127. buildPath(accent.fontChar);
  10128. }
  10129. }
  10130. }
  10131. return glyphs;
  10132. },
  10133. setGState: function PartialEvaluator_setGState(resources, gState,
  10134. operatorList, task,
  10135. xref, stateManager) {
  10136. // This array holds the converted/processed state data.
  10137. var gStateObj = [];
  10138. var gStateMap = gState.map;
  10139. var self = this;
  10140. var promise = Promise.resolve();
  10141. for (var key in gStateMap) {
  10142. var value = gStateMap[key];
  10143. switch (key) {
  10144. case 'Type':
  10145. break;
  10146. case 'LW':
  10147. case 'LC':
  10148. case 'LJ':
  10149. case 'ML':
  10150. case 'D':
  10151. case 'RI':
  10152. case 'FL':
  10153. case 'CA':
  10154. case 'ca':
  10155. gStateObj.push([key, value]);
  10156. break;
  10157. case 'Font':
  10158. promise = promise.then(function () {
  10159. return self.handleSetFont(resources, null, value[0], operatorList,
  10160. task, stateManager.state).
  10161. then(function (loadedName) {
  10162. operatorList.addDependency(loadedName);
  10163. gStateObj.push([key, [loadedName, value[1]]]);
  10164. });
  10165. });
  10166. break;
  10167. case 'BM':
  10168. gStateObj.push([key, value]);
  10169. break;
  10170. case 'SMask':
  10171. if (isName(value) && value.name === 'None') {
  10172. gStateObj.push([key, false]);
  10173. break;
  10174. }
  10175. var dict = xref.fetchIfRef(value);
  10176. if (isDict(dict)) {
  10177. promise = promise.then(function () {
  10178. return self.handleSMask(dict, resources, operatorList,
  10179. task, stateManager);
  10180. });
  10181. gStateObj.push([key, true]);
  10182. } else {
  10183. warn('Unsupported SMask type');
  10184. }
  10185. break;
  10186. // Only generate info log messages for the following since
  10187. // they are unlikely to have a big impact on the rendering.
  10188. case 'OP':
  10189. case 'op':
  10190. case 'OPM':
  10191. case 'BG':
  10192. case 'BG2':
  10193. case 'UCR':
  10194. case 'UCR2':
  10195. case 'TR':
  10196. case 'TR2':
  10197. case 'HT':
  10198. case 'SM':
  10199. case 'SA':
  10200. case 'AIS':
  10201. case 'TK':
  10202. // TODO implement these operators.
  10203. info('graphic state operator ' + key);
  10204. break;
  10205. default:
  10206. info('Unknown graphic state operator ' + key);
  10207. break;
  10208. }
  10209. }
  10210. return promise.then(function () {
  10211. if (gStateObj.length >= 0) {
  10212. operatorList.addOp(OPS.setGState, [gStateObj]);
  10213. }
  10214. });
  10215. },
  10216. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10217. resources) {
  10218. function errorFont() {
  10219. return Promise.resolve(new TranslatedFont('g_font_error',
  10220. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10221. }
  10222. var fontRef;
  10223. if (font) { // Loading by ref.
  10224. assert(isRef(font));
  10225. fontRef = font;
  10226. } else { // Loading by name.
  10227. var fontRes = resources.get('Font');
  10228. if (fontRes) {
  10229. fontRef = fontRes.getRaw(fontName);
  10230. } else {
  10231. warn('fontRes not available');
  10232. return errorFont();
  10233. }
  10234. }
  10235. if (!fontRef) {
  10236. warn('fontRef not available');
  10237. return errorFont();
  10238. }
  10239. if (this.fontCache.has(fontRef)) {
  10240. return this.fontCache.get(fontRef);
  10241. }
  10242. font = xref.fetchIfRef(fontRef);
  10243. if (!isDict(font)) {
  10244. return errorFont();
  10245. }
  10246. // We are holding font.translated references just for fontRef that are not
  10247. // dictionaries (Dict). See explanation below.
  10248. if (font.translated) {
  10249. return font.translated;
  10250. }
  10251. var fontCapability = createPromiseCapability();
  10252. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10253. var descriptor = preEvaluatedFont.descriptor;
  10254. var fontID = fontRef.num + '_' + fontRef.gen;
  10255. if (isDict(descriptor)) {
  10256. if (!descriptor.fontAliases) {
  10257. descriptor.fontAliases = Object.create(null);
  10258. }
  10259. var fontAliases = descriptor.fontAliases;
  10260. var hash = preEvaluatedFont.hash;
  10261. if (fontAliases[hash]) {
  10262. var aliasFontRef = fontAliases[hash].aliasRef;
  10263. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10264. this.fontCache.putAlias(fontRef, aliasFontRef);
  10265. return this.fontCache.get(fontRef);
  10266. }
  10267. }
  10268. if (!fontAliases[hash]) {
  10269. fontAliases[hash] = {
  10270. fontID: Font.getFontID()
  10271. };
  10272. }
  10273. fontAliases[hash].aliasRef = fontRef;
  10274. fontID = fontAliases[hash].fontID;
  10275. }
  10276. // Workaround for bad PDF generators that don't reference fonts
  10277. // properly, i.e. by not using an object identifier.
  10278. // Check if the fontRef is a Dict (as opposed to a standard object),
  10279. // in which case we don't cache the font and instead reference it by
  10280. // fontName in font.loadedName below.
  10281. var fontRefIsDict = isDict(fontRef);
  10282. if (!fontRefIsDict) {
  10283. this.fontCache.put(fontRef, fontCapability.promise);
  10284. }
  10285. // Keep track of each font we translated so the caller can
  10286. // load them asynchronously before calling display on a page.
  10287. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10288. fontName.replace(/\W/g, '') : fontID);
  10289. font.translated = fontCapability.promise;
  10290. // TODO move promises into translate font
  10291. var translatedPromise;
  10292. try {
  10293. translatedPromise = Promise.resolve(
  10294. this.translateFont(preEvaluatedFont, xref));
  10295. } catch (e) {
  10296. translatedPromise = Promise.reject(e);
  10297. }
  10298. translatedPromise.then(function (translatedFont) {
  10299. if (translatedFont.fontType !== undefined) {
  10300. var xrefFontStats = xref.stats.fontTypes;
  10301. xrefFontStats[translatedFont.fontType] = true;
  10302. }
  10303. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10304. translatedFont, font));
  10305. }, function (reason) {
  10306. // TODO fontCapability.reject?
  10307. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10308. try {
  10309. // error, but it's still nice to have font type reported
  10310. var descriptor = preEvaluatedFont.descriptor;
  10311. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10312. var subtype = fontFile3 && fontFile3.get('Subtype');
  10313. var fontType = getFontType(preEvaluatedFont.type,
  10314. subtype && subtype.name);
  10315. var xrefFontStats = xref.stats.fontTypes;
  10316. xrefFontStats[fontType] = true;
  10317. } catch (ex) { }
  10318. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10319. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10320. font));
  10321. });
  10322. return fontCapability.promise;
  10323. },
  10324. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10325. var lastIndex = operatorList.length - 1;
  10326. if (!args) {
  10327. args = [];
  10328. }
  10329. if (lastIndex < 0 ||
  10330. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10331. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10332. } else {
  10333. var opArgs = operatorList.argsArray[lastIndex];
  10334. opArgs[0].push(fn);
  10335. Array.prototype.push.apply(opArgs[1], args);
  10336. }
  10337. },
  10338. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10339. cs, patterns, resources, task, xref) {
  10340. // compile tiling patterns
  10341. var patternName = args[args.length - 1];
  10342. // SCN/scn applies patterns along with normal colors
  10343. var pattern;
  10344. if (isName(patternName) &&
  10345. (pattern = patterns.get(patternName.name))) {
  10346. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10347. var typeNum = dict.get('PatternType');
  10348. if (typeNum === TILING_PATTERN) {
  10349. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10350. return this.handleTilingType(fn, color, resources, pattern,
  10351. dict, operatorList, task);
  10352. } else if (typeNum === SHADING_PATTERN) {
  10353. var shading = dict.get('Shading');
  10354. var matrix = dict.get('Matrix');
  10355. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10356. operatorList.addOp(fn, pattern.getIR());
  10357. return Promise.resolve();
  10358. } else {
  10359. return Promise.reject('Unknown PatternType: ' + typeNum);
  10360. }
  10361. }
  10362. // TODO shall we fail here?
  10363. operatorList.addOp(fn, args);
  10364. return Promise.resolve();
  10365. },
  10366. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10367. task,
  10368. resources,
  10369. operatorList,
  10370. initialState) {
  10371. var self = this;
  10372. var xref = this.xref;
  10373. var imageCache = {};
  10374. assert(operatorList);
  10375. resources = (resources || Dict.empty);
  10376. var xobjs = (resources.get('XObject') || Dict.empty);
  10377. var patterns = (resources.get('Pattern') || Dict.empty);
  10378. var stateManager = new StateManager(initialState || new EvalState());
  10379. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10380. var timeSlotManager = new TimeSlotManager();
  10381. return new Promise(function next(resolve, reject) {
  10382. task.ensureNotTerminated();
  10383. timeSlotManager.reset();
  10384. var stop, operation = {}, i, ii, cs;
  10385. while (!(stop = timeSlotManager.check())) {
  10386. // The arguments parsed by read() are used beyond this loop, so we
  10387. // cannot reuse the same array on each iteration. Therefore we pass
  10388. // in |null| as the initial value (see the comment on
  10389. // EvaluatorPreprocessor_read() for why).
  10390. operation.args = null;
  10391. if (!(preprocessor.read(operation))) {
  10392. break;
  10393. }
  10394. var args = operation.args;
  10395. var fn = operation.fn;
  10396. switch (fn | 0) {
  10397. case OPS.paintXObject:
  10398. if (args[0].code) {
  10399. break;
  10400. }
  10401. // eagerly compile XForm objects
  10402. var name = args[0].name;
  10403. if (!name) {
  10404. warn('XObject must be referred to by name.');
  10405. continue;
  10406. }
  10407. if (imageCache[name] !== undefined) {
  10408. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10409. args = null;
  10410. continue;
  10411. }
  10412. var xobj = xobjs.get(name);
  10413. if (xobj) {
  10414. assert(isStream(xobj), 'XObject should be a stream');
  10415. var type = xobj.dict.get('Subtype');
  10416. assert(isName(type),
  10417. 'XObject should have a Name subtype');
  10418. if (type.name === 'Form') {
  10419. stateManager.save();
  10420. return self.buildFormXObject(resources, xobj, null,
  10421. operatorList, task,
  10422. stateManager.state.clone()).
  10423. then(function () {
  10424. stateManager.restore();
  10425. next(resolve, reject);
  10426. }, reject);
  10427. } else if (type.name === 'Image') {
  10428. self.buildPaintImageXObject(resources, xobj, false,
  10429. operatorList, name, imageCache);
  10430. args = null;
  10431. continue;
  10432. } else if (type.name === 'PS') {
  10433. // PostScript XObjects are unused when viewing documents.
  10434. // See section 4.7.1 of Adobe's PDF reference.
  10435. info('Ignored XObject subtype PS');
  10436. continue;
  10437. } else {
  10438. error('Unhandled XObject subtype ' + type.name);
  10439. }
  10440. }
  10441. break;
  10442. case OPS.setFont:
  10443. var fontSize = args[1];
  10444. // eagerly collect all fonts
  10445. return self.handleSetFont(resources, args, null, operatorList,
  10446. task, stateManager.state).
  10447. then(function (loadedName) {
  10448. operatorList.addDependency(loadedName);
  10449. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10450. next(resolve, reject);
  10451. }, reject);
  10452. case OPS.endInlineImage:
  10453. var cacheKey = args[0].cacheKey;
  10454. if (cacheKey) {
  10455. var cacheEntry = imageCache[cacheKey];
  10456. if (cacheEntry !== undefined) {
  10457. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10458. args = null;
  10459. continue;
  10460. }
  10461. }
  10462. self.buildPaintImageXObject(resources, args[0], true,
  10463. operatorList, cacheKey, imageCache);
  10464. args = null;
  10465. continue;
  10466. case OPS.showText:
  10467. args[0] = self.handleText(args[0], stateManager.state);
  10468. break;
  10469. case OPS.showSpacedText:
  10470. var arr = args[0];
  10471. var combinedGlyphs = [];
  10472. var arrLength = arr.length;
  10473. var state = stateManager.state;
  10474. for (i = 0; i < arrLength; ++i) {
  10475. var arrItem = arr[i];
  10476. if (isString(arrItem)) {
  10477. Array.prototype.push.apply(combinedGlyphs,
  10478. self.handleText(arrItem, state));
  10479. } else if (isNum(arrItem)) {
  10480. combinedGlyphs.push(arrItem);
  10481. }
  10482. }
  10483. args[0] = combinedGlyphs;
  10484. fn = OPS.showText;
  10485. break;
  10486. case OPS.nextLineShowText:
  10487. operatorList.addOp(OPS.nextLine);
  10488. args[0] = self.handleText(args[0], stateManager.state);
  10489. fn = OPS.showText;
  10490. break;
  10491. case OPS.nextLineSetSpacingShowText:
  10492. operatorList.addOp(OPS.nextLine);
  10493. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10494. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10495. args[0] = self.handleText(args[0], stateManager.state);
  10496. fn = OPS.showText;
  10497. break;
  10498. case OPS.setTextRenderingMode:
  10499. stateManager.state.textRenderingMode = args[0];
  10500. break;
  10501. case OPS.setFillColorSpace:
  10502. stateManager.state.fillColorSpace =
  10503. ColorSpace.parse(args[0], xref, resources);
  10504. continue;
  10505. case OPS.setStrokeColorSpace:
  10506. stateManager.state.strokeColorSpace =
  10507. ColorSpace.parse(args[0], xref, resources);
  10508. continue;
  10509. case OPS.setFillColor:
  10510. cs = stateManager.state.fillColorSpace;
  10511. args = cs.getRgb(args, 0);
  10512. fn = OPS.setFillRGBColor;
  10513. break;
  10514. case OPS.setStrokeColor:
  10515. cs = stateManager.state.strokeColorSpace;
  10516. args = cs.getRgb(args, 0);
  10517. fn = OPS.setStrokeRGBColor;
  10518. break;
  10519. case OPS.setFillGray:
  10520. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10521. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10522. fn = OPS.setFillRGBColor;
  10523. break;
  10524. case OPS.setStrokeGray:
  10525. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10526. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10527. fn = OPS.setStrokeRGBColor;
  10528. break;
  10529. case OPS.setFillCMYKColor:
  10530. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10531. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10532. fn = OPS.setFillRGBColor;
  10533. break;
  10534. case OPS.setStrokeCMYKColor:
  10535. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10536. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10537. fn = OPS.setStrokeRGBColor;
  10538. break;
  10539. case OPS.setFillRGBColor:
  10540. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10541. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10542. break;
  10543. case OPS.setStrokeRGBColor:
  10544. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10545. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10546. break;
  10547. case OPS.setFillColorN:
  10548. cs = stateManager.state.fillColorSpace;
  10549. if (cs.name === 'Pattern') {
  10550. return self.handleColorN(operatorList, OPS.setFillColorN,
  10551. args, cs, patterns, resources, task, xref).then(function() {
  10552. next(resolve, reject);
  10553. }, reject);
  10554. }
  10555. args = cs.getRgb(args, 0);
  10556. fn = OPS.setFillRGBColor;
  10557. break;
  10558. case OPS.setStrokeColorN:
  10559. cs = stateManager.state.strokeColorSpace;
  10560. if (cs.name === 'Pattern') {
  10561. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10562. args, cs, patterns, resources, task, xref).then(function() {
  10563. next(resolve, reject);
  10564. }, reject);
  10565. }
  10566. args = cs.getRgb(args, 0);
  10567. fn = OPS.setStrokeRGBColor;
  10568. break;
  10569. case OPS.shadingFill:
  10570. var shadingRes = resources.get('Shading');
  10571. if (!shadingRes) {
  10572. error('No shading resource found');
  10573. }
  10574. var shading = shadingRes.get(args[0].name);
  10575. if (!shading) {
  10576. error('No shading object found');
  10577. }
  10578. var shadingFill = Pattern.parseShading(shading, null, xref,
  10579. resources);
  10580. var patternIR = shadingFill.getIR();
  10581. args = [patternIR];
  10582. fn = OPS.shadingFill;
  10583. break;
  10584. case OPS.setGState:
  10585. var dictName = args[0];
  10586. var extGState = resources.get('ExtGState');
  10587. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10588. break;
  10589. }
  10590. var gState = extGState.get(dictName.name);
  10591. return self.setGState(resources, gState, operatorList, task,
  10592. xref, stateManager).then(function() {
  10593. next(resolve, reject);
  10594. }, reject);
  10595. case OPS.moveTo:
  10596. case OPS.lineTo:
  10597. case OPS.curveTo:
  10598. case OPS.curveTo2:
  10599. case OPS.curveTo3:
  10600. case OPS.closePath:
  10601. self.buildPath(operatorList, fn, args);
  10602. continue;
  10603. case OPS.rectangle:
  10604. self.buildPath(operatorList, fn, args);
  10605. continue;
  10606. case OPS.markPoint:
  10607. case OPS.markPointProps:
  10608. case OPS.beginMarkedContent:
  10609. case OPS.beginMarkedContentProps:
  10610. case OPS.endMarkedContent:
  10611. case OPS.beginCompat:
  10612. case OPS.endCompat:
  10613. // Ignore operators where the corresponding handlers are known to
  10614. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  10615. // serialization errors and is also a bit more efficient.
  10616. // We could also try to serialize all objects in a general way,
  10617. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  10618. // but doing so is meaningless without knowing the semantics.
  10619. continue;
  10620. default:
  10621. // Note: Let's hope that the ignored operator does not have any
  10622. // non-serializable arguments, otherwise postMessage will throw
  10623. // "An object could not be cloned.".
  10624. }
  10625. operatorList.addOp(fn, args);
  10626. }
  10627. if (stop) {
  10628. deferred.then(function () {
  10629. next(resolve, reject);
  10630. }, reject);
  10631. return;
  10632. }
  10633. // Some PDFs don't close all restores inside object/form.
  10634. // Closing those for them.
  10635. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10636. operatorList.addOp(OPS.restore, []);
  10637. }
  10638. resolve();
  10639. });
  10640. },
  10641. getTextContent: function PartialEvaluator_getTextContent(stream, task,
  10642. resources,
  10643. stateManager) {
  10644. stateManager = (stateManager || new StateManager(new TextState()));
  10645. var textContent = {
  10646. items: [],
  10647. styles: Object.create(null)
  10648. };
  10649. var textContentItem = {
  10650. initialized: false,
  10651. str: [],
  10652. width: 0,
  10653. height: 0,
  10654. vertical: false,
  10655. lastAdvanceWidth: 0,
  10656. lastAdvanceHeight: 0,
  10657. textAdvanceScale: 0,
  10658. spaceWidth: 0,
  10659. fakeSpaceMin: Infinity,
  10660. fakeMultiSpaceMin: Infinity,
  10661. fakeMultiSpaceMax: -0,
  10662. textRunBreakAllowed: false,
  10663. transform: null,
  10664. fontName: null
  10665. };
  10666. var SPACE_FACTOR = 0.3;
  10667. var MULTI_SPACE_FACTOR = 1.5;
  10668. var MULTI_SPACE_FACTOR_MAX = 4;
  10669. var self = this;
  10670. var xref = this.xref;
  10671. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10672. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10673. var xobjs = null;
  10674. var xobjsCache = {};
  10675. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10676. var textState;
  10677. function ensureTextContentItem() {
  10678. if (textContentItem.initialized) {
  10679. return textContentItem;
  10680. }
  10681. var font = textState.font;
  10682. if (!(font.loadedName in textContent.styles)) {
  10683. textContent.styles[font.loadedName] = {
  10684. fontFamily: font.fallbackName,
  10685. ascent: font.ascent,
  10686. descent: font.descent,
  10687. vertical: font.vertical
  10688. };
  10689. }
  10690. textContentItem.fontName = font.loadedName;
  10691. // 9.4.4 Text Space Details
  10692. var tsm = [textState.fontSize * textState.textHScale, 0,
  10693. 0, textState.fontSize,
  10694. 0, textState.textRise];
  10695. if (font.isType3Font &&
  10696. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10697. textState.fontSize === 1) {
  10698. var glyphHeight = font.bbox[3] - font.bbox[1];
  10699. if (glyphHeight > 0) {
  10700. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10701. tsm[3] *= glyphHeight;
  10702. }
  10703. }
  10704. var trm = Util.transform(textState.ctm,
  10705. Util.transform(textState.textMatrix, tsm));
  10706. textContentItem.transform = trm;
  10707. if (!font.vertical) {
  10708. textContentItem.width = 0;
  10709. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10710. textContentItem.vertical = false;
  10711. } else {
  10712. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10713. textContentItem.height = 0;
  10714. textContentItem.vertical = true;
  10715. }
  10716. var a = textState.textLineMatrix[0];
  10717. var b = textState.textLineMatrix[1];
  10718. var scaleLineX = Math.sqrt(a * a + b * b);
  10719. a = textState.ctm[0];
  10720. b = textState.ctm[1];
  10721. var scaleCtmX = Math.sqrt(a * a + b * b);
  10722. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  10723. textContentItem.lastAdvanceWidth = 0;
  10724. textContentItem.lastAdvanceHeight = 0;
  10725. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  10726. if (spaceWidth) {
  10727. textContentItem.spaceWidth = spaceWidth;
  10728. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  10729. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  10730. textContentItem.fakeMultiSpaceMax =
  10731. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  10732. // It's okay for monospace fonts to fake as much space as needed.
  10733. textContentItem.textRunBreakAllowed = !font.isMonospace;
  10734. } else {
  10735. textContentItem.spaceWidth = 0;
  10736. textContentItem.fakeSpaceMin = Infinity;
  10737. textContentItem.fakeMultiSpaceMin = Infinity;
  10738. textContentItem.fakeMultiSpaceMax = 0;
  10739. textContentItem.textRunBreakAllowed = false;
  10740. }
  10741. textContentItem.initialized = true;
  10742. return textContentItem;
  10743. }
  10744. function runBidiTransform(textChunk) {
  10745. var str = textChunk.str.join('');
  10746. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  10747. return {
  10748. str: bidiResult.str,
  10749. dir: bidiResult.dir,
  10750. width: textChunk.width,
  10751. height: textChunk.height,
  10752. transform: textChunk.transform,
  10753. fontName: textChunk.fontName
  10754. };
  10755. }
  10756. function handleSetFont(fontName, fontRef) {
  10757. return self.loadFont(fontName, fontRef, xref, resources).
  10758. then(function (translated) {
  10759. textState.font = translated.font;
  10760. textState.fontMatrix = translated.font.fontMatrix ||
  10761. FONT_IDENTITY_MATRIX;
  10762. });
  10763. }
  10764. function buildTextContentItem(chars) {
  10765. var font = textState.font;
  10766. var textChunk = ensureTextContentItem();
  10767. var width = 0;
  10768. var height = 0;
  10769. var glyphs = font.charsToGlyphs(chars);
  10770. var defaultVMetrics = font.defaultVMetrics;
  10771. for (var i = 0; i < glyphs.length; i++) {
  10772. var glyph = glyphs[i];
  10773. var vMetricX = null;
  10774. var vMetricY = null;
  10775. var glyphWidth = null;
  10776. if (font.vertical) {
  10777. if (glyph.vmetric) {
  10778. glyphWidth = glyph.vmetric[0];
  10779. vMetricX = glyph.vmetric[1];
  10780. vMetricY = glyph.vmetric[2];
  10781. } else {
  10782. glyphWidth = glyph.width;
  10783. vMetricX = glyph.width * 0.5;
  10784. vMetricY = defaultVMetrics[2];
  10785. }
  10786. } else {
  10787. glyphWidth = glyph.width;
  10788. }
  10789. var glyphUnicode = glyph.unicode;
  10790. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10791. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10792. }
  10793. glyphUnicode = reverseIfRtl(glyphUnicode);
  10794. // The following will calculate the x and y of the individual glyphs.
  10795. // if (font.vertical) {
  10796. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10797. // textState.fontMatrix[0];
  10798. // tsm[5] -= vMetricY * textState.fontSize *
  10799. // textState.fontMatrix[0];
  10800. // }
  10801. // var trm = Util.transform(textState.textMatrix, tsm);
  10802. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10803. // var x = pt[0];
  10804. // var y = pt[1];
  10805. var charSpacing = textState.charSpacing;
  10806. if (glyph.isSpace) {
  10807. var wordSpacing = textState.wordSpacing;
  10808. charSpacing += wordSpacing;
  10809. if (wordSpacing > 0) {
  10810. addFakeSpaces(wordSpacing, textChunk.str);
  10811. }
  10812. }
  10813. var tx = 0;
  10814. var ty = 0;
  10815. if (!font.vertical) {
  10816. var w0 = glyphWidth * textState.fontMatrix[0];
  10817. tx = (w0 * textState.fontSize + charSpacing) *
  10818. textState.textHScale;
  10819. width += tx;
  10820. } else {
  10821. var w1 = glyphWidth * textState.fontMatrix[0];
  10822. ty = w1 * textState.fontSize + charSpacing;
  10823. height += ty;
  10824. }
  10825. textState.translateTextMatrix(tx, ty);
  10826. textChunk.str.push(glyphUnicode);
  10827. }
  10828. if (!font.vertical) {
  10829. textChunk.lastAdvanceWidth = width;
  10830. textChunk.width += width * textChunk.textAdvanceScale;
  10831. } else {
  10832. textChunk.lastAdvanceHeight = height;
  10833. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  10834. }
  10835. return textChunk;
  10836. }
  10837. function addFakeSpaces(width, strBuf) {
  10838. if (width < textContentItem.fakeSpaceMin) {
  10839. return;
  10840. }
  10841. if (width < textContentItem.fakeMultiSpaceMin) {
  10842. strBuf.push(' ');
  10843. return;
  10844. }
  10845. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  10846. while (fakeSpaces-- > 0) {
  10847. strBuf.push(' ');
  10848. }
  10849. }
  10850. function flushTextContentItem() {
  10851. if (!textContentItem.initialized) {
  10852. return;
  10853. }
  10854. textContent.items.push(runBidiTransform(textContentItem));
  10855. textContentItem.initialized = false;
  10856. textContentItem.str.length = 0;
  10857. }
  10858. var timeSlotManager = new TimeSlotManager();
  10859. return new Promise(function next(resolve, reject) {
  10860. task.ensureNotTerminated();
  10861. timeSlotManager.reset();
  10862. var stop, operation = {}, args = [];
  10863. while (!(stop = timeSlotManager.check())) {
  10864. // The arguments parsed by read() are not used beyond this loop, so
  10865. // we can reuse the same array on every iteration, thus avoiding
  10866. // unnecessary allocations.
  10867. args.length = 0;
  10868. operation.args = args;
  10869. if (!(preprocessor.read(operation))) {
  10870. break;
  10871. }
  10872. textState = stateManager.state;
  10873. var fn = operation.fn;
  10874. args = operation.args;
  10875. var advance;
  10876. switch (fn | 0) {
  10877. case OPS.setFont:
  10878. flushTextContentItem();
  10879. textState.fontSize = args[1];
  10880. return handleSetFont(args[0].name).then(function() {
  10881. next(resolve, reject);
  10882. }, reject);
  10883. case OPS.setTextRise:
  10884. flushTextContentItem();
  10885. textState.textRise = args[0];
  10886. break;
  10887. case OPS.setHScale:
  10888. flushTextContentItem();
  10889. textState.textHScale = args[0] / 100;
  10890. break;
  10891. case OPS.setLeading:
  10892. flushTextContentItem();
  10893. textState.leading = args[0];
  10894. break;
  10895. case OPS.moveText:
  10896. // Optimization to treat same line movement as advance
  10897. var isSameTextLine = !textState.font ? false :
  10898. ((textState.font.vertical ? args[0] : args[1]) === 0);
  10899. advance = args[0] - args[1];
  10900. if (isSameTextLine && textContentItem.initialized &&
  10901. advance > 0 &&
  10902. advance <= textContentItem.fakeMultiSpaceMax) {
  10903. textState.translateTextLineMatrix(args[0], args[1]);
  10904. textContentItem.width +=
  10905. (args[0] - textContentItem.lastAdvanceWidth);
  10906. textContentItem.height +=
  10907. (args[1] - textContentItem.lastAdvanceHeight);
  10908. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  10909. (args[1] - textContentItem.lastAdvanceHeight);
  10910. addFakeSpaces(diff, textContentItem.str);
  10911. break;
  10912. }
  10913. flushTextContentItem();
  10914. textState.translateTextLineMatrix(args[0], args[1]);
  10915. textState.textMatrix = textState.textLineMatrix.slice();
  10916. break;
  10917. case OPS.setLeadingMoveText:
  10918. flushTextContentItem();
  10919. textState.leading = -args[1];
  10920. textState.translateTextLineMatrix(args[0], args[1]);
  10921. textState.textMatrix = textState.textLineMatrix.slice();
  10922. break;
  10923. case OPS.nextLine:
  10924. flushTextContentItem();
  10925. textState.carriageReturn();
  10926. break;
  10927. case OPS.setTextMatrix:
  10928. flushTextContentItem();
  10929. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10930. args[4], args[5]);
  10931. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10932. args[4], args[5]);
  10933. break;
  10934. case OPS.setCharSpacing:
  10935. textState.charSpacing = args[0];
  10936. break;
  10937. case OPS.setWordSpacing:
  10938. textState.wordSpacing = args[0];
  10939. break;
  10940. case OPS.beginText:
  10941. flushTextContentItem();
  10942. textState.textMatrix = IDENTITY_MATRIX.slice();
  10943. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10944. break;
  10945. case OPS.showSpacedText:
  10946. var items = args[0];
  10947. var offset;
  10948. for (var j = 0, jj = items.length; j < jj; j++) {
  10949. if (typeof items[j] === 'string') {
  10950. buildTextContentItem(items[j]);
  10951. } else {
  10952. ensureTextContentItem();
  10953. // PDF Specification 5.3.2 states:
  10954. // The number is expressed in thousandths of a unit of text
  10955. // space.
  10956. // This amount is subtracted from the current horizontal or
  10957. // vertical coordinate, depending on the writing mode.
  10958. // In the default coordinate system, a positive adjustment
  10959. // has the effect of moving the next glyph painted either to
  10960. // the left or down by the given amount.
  10961. advance = items[j] * textState.fontSize / 1000;
  10962. var breakTextRun = false;
  10963. if (textState.font.vertical) {
  10964. offset = advance *
  10965. (textState.textHScale * textState.textMatrix[2] +
  10966. textState.textMatrix[3]);
  10967. textState.translateTextMatrix(0, advance);
  10968. breakTextRun = textContentItem.textRunBreakAllowed &&
  10969. advance > textContentItem.fakeMultiSpaceMax;
  10970. if (!breakTextRun) {
  10971. // Value needs to be added to height to paint down.
  10972. textContentItem.height += offset;
  10973. }
  10974. } else {
  10975. advance = -advance;
  10976. offset = advance * (
  10977. textState.textHScale * textState.textMatrix[0] +
  10978. textState.textMatrix[1]);
  10979. textState.translateTextMatrix(advance, 0);
  10980. breakTextRun = textContentItem.textRunBreakAllowed &&
  10981. advance > textContentItem.fakeMultiSpaceMax;
  10982. if (!breakTextRun) {
  10983. // Value needs to be subtracted from width to paint left.
  10984. textContentItem.width += offset;
  10985. }
  10986. }
  10987. if (breakTextRun) {
  10988. flushTextContentItem();
  10989. } else if (advance > 0) {
  10990. addFakeSpaces(advance, textContentItem.str);
  10991. }
  10992. }
  10993. }
  10994. break;
  10995. case OPS.showText:
  10996. buildTextContentItem(args[0]);
  10997. break;
  10998. case OPS.nextLineShowText:
  10999. flushTextContentItem();
  11000. textState.carriageReturn();
  11001. buildTextContentItem(args[0]);
  11002. break;
  11003. case OPS.nextLineSetSpacingShowText:
  11004. flushTextContentItem();
  11005. textState.wordSpacing = args[0];
  11006. textState.charSpacing = args[1];
  11007. textState.carriageReturn();
  11008. buildTextContentItem(args[2]);
  11009. break;
  11010. case OPS.paintXObject:
  11011. flushTextContentItem();
  11012. if (args[0].code) {
  11013. break;
  11014. }
  11015. if (!xobjs) {
  11016. xobjs = (resources.get('XObject') || Dict.empty);
  11017. }
  11018. var name = args[0].name;
  11019. if (xobjsCache.key === name) {
  11020. if (xobjsCache.texts) {
  11021. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  11022. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  11023. }
  11024. break;
  11025. }
  11026. var xobj = xobjs.get(name);
  11027. if (!xobj) {
  11028. break;
  11029. }
  11030. assert(isStream(xobj), 'XObject should be a stream');
  11031. var type = xobj.dict.get('Subtype');
  11032. assert(isName(type),
  11033. 'XObject should have a Name subtype');
  11034. if ('Form' !== type.name) {
  11035. xobjsCache.key = name;
  11036. xobjsCache.texts = null;
  11037. break;
  11038. }
  11039. stateManager.save();
  11040. var matrix = xobj.dict.get('Matrix');
  11041. if (isArray(matrix) && matrix.length === 6) {
  11042. stateManager.transform(matrix);
  11043. }
  11044. return self.getTextContent(xobj, task,
  11045. xobj.dict.get('Resources') || resources, stateManager).
  11046. then(function (formTextContent) {
  11047. Util.appendToArray(textContent.items, formTextContent.items);
  11048. Util.extendObj(textContent.styles, formTextContent.styles);
  11049. stateManager.restore();
  11050. xobjsCache.key = name;
  11051. xobjsCache.texts = formTextContent;
  11052. next(resolve, reject);
  11053. }, reject);
  11054. case OPS.setGState:
  11055. flushTextContentItem();
  11056. var dictName = args[0];
  11057. var extGState = resources.get('ExtGState');
  11058. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  11059. break;
  11060. }
  11061. var gsStateMap = extGState.get(dictName.name);
  11062. var gsStateFont = null;
  11063. for (var key in gsStateMap) {
  11064. if (key === 'Font') {
  11065. assert(!gsStateFont);
  11066. gsStateFont = gsStateMap[key];
  11067. }
  11068. }
  11069. if (gsStateFont) {
  11070. textState.fontSize = gsStateFont[1];
  11071. return handleSetFont(gsStateFont[0]).then(function() {
  11072. next(resolve, reject);
  11073. }, reject);
  11074. }
  11075. break;
  11076. } // switch
  11077. } // while
  11078. if (stop) {
  11079. deferred.then(function () {
  11080. next(resolve, reject);
  11081. }, reject);
  11082. return;
  11083. }
  11084. flushTextContentItem();
  11085. resolve(textContent);
  11086. });
  11087. },
  11088. extractDataStructures: function
  11089. partialEvaluatorExtractDataStructures(dict, baseDict,
  11090. xref, properties) {
  11091. // 9.10.2
  11092. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  11093. if (toUnicode) {
  11094. properties.toUnicode = this.readToUnicode(toUnicode);
  11095. }
  11096. if (properties.composite) {
  11097. // CIDSystemInfo helps to match CID to glyphs
  11098. var cidSystemInfo = dict.get('CIDSystemInfo');
  11099. if (isDict(cidSystemInfo)) {
  11100. properties.cidSystemInfo = {
  11101. registry: cidSystemInfo.get('Registry'),
  11102. ordering: cidSystemInfo.get('Ordering'),
  11103. supplement: cidSystemInfo.get('Supplement')
  11104. };
  11105. }
  11106. var cidToGidMap = dict.get('CIDToGIDMap');
  11107. if (isStream(cidToGidMap)) {
  11108. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  11109. }
  11110. }
  11111. // Based on 9.6.6 of the spec the encoding can come from multiple places
  11112. // and depends on the font type. The base encoding and differences are
  11113. // read here, but the encoding that is actually used is chosen during
  11114. // glyph mapping in the font.
  11115. // TODO: Loading the built in encoding in the font would allow the
  11116. // differences to be merged in here not require us to hold on to it.
  11117. var differences = [];
  11118. var baseEncodingName = null;
  11119. var encoding;
  11120. if (dict.has('Encoding')) {
  11121. encoding = dict.get('Encoding');
  11122. if (isDict(encoding)) {
  11123. baseEncodingName = encoding.get('BaseEncoding');
  11124. baseEncodingName = (isName(baseEncodingName) ?
  11125. baseEncodingName.name : null);
  11126. // Load the differences between the base and original
  11127. if (encoding.has('Differences')) {
  11128. var diffEncoding = encoding.get('Differences');
  11129. var index = 0;
  11130. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  11131. var data = diffEncoding[j];
  11132. if (isNum(data)) {
  11133. index = data;
  11134. } else if (isName(data)) {
  11135. differences[index++] = data.name;
  11136. } else if (isRef(data)) {
  11137. diffEncoding[j--] = xref.fetch(data);
  11138. continue;
  11139. } else {
  11140. error('Invalid entry in \'Differences\' array: ' + data);
  11141. }
  11142. }
  11143. }
  11144. } else if (isName(encoding)) {
  11145. baseEncodingName = encoding.name;
  11146. } else {
  11147. error('Encoding is not a Name nor a Dict');
  11148. }
  11149. // According to table 114 if the encoding is a named encoding it must be
  11150. // one of these predefined encodings.
  11151. if ((baseEncodingName !== 'MacRomanEncoding' &&
  11152. baseEncodingName !== 'MacExpertEncoding' &&
  11153. baseEncodingName !== 'WinAnsiEncoding')) {
  11154. baseEncodingName = null;
  11155. }
  11156. }
  11157. if (baseEncodingName) {
  11158. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  11159. } else {
  11160. encoding = (properties.type === 'TrueType' ?
  11161. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  11162. // The Symbolic attribute can be misused for regular fonts
  11163. // Heuristic: we have to check if the font is a standard one also
  11164. if (!!(properties.flags & FontFlags.Symbolic)) {
  11165. encoding = Encodings.MacRomanEncoding;
  11166. if (!properties.file) {
  11167. if (/Symbol/i.test(properties.name)) {
  11168. encoding = Encodings.SymbolSetEncoding;
  11169. } else if (/Dingbats/i.test(properties.name)) {
  11170. encoding = Encodings.ZapfDingbatsEncoding;
  11171. }
  11172. }
  11173. }
  11174. properties.defaultEncoding = encoding;
  11175. }
  11176. properties.differences = differences;
  11177. properties.baseEncodingName = baseEncodingName;
  11178. properties.dict = dict;
  11179. },
  11180. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  11181. var cmap, cmapObj = toUnicode;
  11182. if (isName(cmapObj)) {
  11183. cmap = CMapFactory.create(cmapObj,
  11184. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11185. if (cmap instanceof IdentityCMap) {
  11186. return new IdentityToUnicodeMap(0, 0xFFFF);
  11187. }
  11188. return new ToUnicodeMap(cmap.getMap());
  11189. } else if (isStream(cmapObj)) {
  11190. cmap = CMapFactory.create(cmapObj,
  11191. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11192. if (cmap instanceof IdentityCMap) {
  11193. return new IdentityToUnicodeMap(0, 0xFFFF);
  11194. }
  11195. var map = new Array(cmap.length);
  11196. // Convert UTF-16BE
  11197. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  11198. // to iterate over all keys.
  11199. cmap.forEach(function(charCode, token) {
  11200. var str = [];
  11201. for (var k = 0; k < token.length; k += 2) {
  11202. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11203. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  11204. str.push(w1);
  11205. continue;
  11206. }
  11207. k += 2;
  11208. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11209. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  11210. }
  11211. map[charCode] = String.fromCharCode.apply(String, str);
  11212. });
  11213. return new ToUnicodeMap(map);
  11214. }
  11215. return null;
  11216. },
  11217. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  11218. // Extract the encoding from the CIDToGIDMap
  11219. var glyphsData = cidToGidStream.getBytes();
  11220. // Set encoding 0 to later verify the font has an encoding
  11221. var result = [];
  11222. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  11223. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  11224. if (glyphID === 0) {
  11225. continue;
  11226. }
  11227. var code = j >> 1;
  11228. result[code] = glyphID;
  11229. }
  11230. return result;
  11231. },
  11232. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  11233. descriptor,
  11234. properties) {
  11235. var glyphsWidths = [];
  11236. var defaultWidth = 0;
  11237. var glyphsVMetrics = [];
  11238. var defaultVMetrics;
  11239. var i, ii, j, jj, start, code, widths;
  11240. if (properties.composite) {
  11241. defaultWidth = dict.get('DW') || 1000;
  11242. widths = dict.get('W');
  11243. if (widths) {
  11244. for (i = 0, ii = widths.length; i < ii; i++) {
  11245. start = widths[i++];
  11246. code = xref.fetchIfRef(widths[i]);
  11247. if (isArray(code)) {
  11248. for (j = 0, jj = code.length; j < jj; j++) {
  11249. glyphsWidths[start++] = code[j];
  11250. }
  11251. } else {
  11252. var width = widths[++i];
  11253. for (j = start; j <= code; j++) {
  11254. glyphsWidths[j] = width;
  11255. }
  11256. }
  11257. }
  11258. }
  11259. if (properties.vertical) {
  11260. var vmetrics = (dict.get('DW2') || [880, -1000]);
  11261. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  11262. vmetrics = dict.get('W2');
  11263. if (vmetrics) {
  11264. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  11265. start = vmetrics[i++];
  11266. code = xref.fetchIfRef(vmetrics[i]);
  11267. if (isArray(code)) {
  11268. for (j = 0, jj = code.length; j < jj; j++) {
  11269. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  11270. }
  11271. } else {
  11272. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  11273. for (j = start; j <= code; j++) {
  11274. glyphsVMetrics[j] = vmetric;
  11275. }
  11276. }
  11277. }
  11278. }
  11279. }
  11280. } else {
  11281. var firstChar = properties.firstChar;
  11282. widths = dict.get('Widths');
  11283. if (widths) {
  11284. j = firstChar;
  11285. for (i = 0, ii = widths.length; i < ii; i++) {
  11286. glyphsWidths[j++] = widths[i];
  11287. }
  11288. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  11289. } else {
  11290. // Trying get the BaseFont metrics (see comment above).
  11291. var baseFontName = dict.get('BaseFont');
  11292. if (isName(baseFontName)) {
  11293. var metrics = this.getBaseFontMetrics(baseFontName.name);
  11294. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  11295. properties);
  11296. defaultWidth = metrics.defaultWidth;
  11297. }
  11298. }
  11299. }
  11300. // Heuristic: detection of monospace font by checking all non-zero widths
  11301. var isMonospace = true;
  11302. var firstWidth = defaultWidth;
  11303. for (var glyph in glyphsWidths) {
  11304. var glyphWidth = glyphsWidths[glyph];
  11305. if (!glyphWidth) {
  11306. continue;
  11307. }
  11308. if (!firstWidth) {
  11309. firstWidth = glyphWidth;
  11310. continue;
  11311. }
  11312. if (firstWidth !== glyphWidth) {
  11313. isMonospace = false;
  11314. break;
  11315. }
  11316. }
  11317. if (isMonospace) {
  11318. properties.flags |= FontFlags.FixedPitch;
  11319. }
  11320. properties.defaultWidth = defaultWidth;
  11321. properties.widths = glyphsWidths;
  11322. properties.defaultVMetrics = defaultVMetrics;
  11323. properties.vmetrics = glyphsVMetrics;
  11324. },
  11325. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  11326. // Simulating descriptor flags attribute
  11327. var fontNameWoStyle = baseFontName.split('-')[0];
  11328. return (fontNameWoStyle in serifFonts) ||
  11329. (fontNameWoStyle.search(/serif/gi) !== -1);
  11330. },
  11331. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  11332. var defaultWidth = 0;
  11333. var widths = [];
  11334. var monospace = false;
  11335. var lookupName = (stdFontMap[name] || name);
  11336. if (!(lookupName in Metrics)) {
  11337. // Use default fonts for looking up font metrics if the passed
  11338. // font is not a base font
  11339. if (this.isSerifFont(name)) {
  11340. lookupName = 'Times-Roman';
  11341. } else {
  11342. lookupName = 'Helvetica';
  11343. }
  11344. }
  11345. var glyphWidths = Metrics[lookupName];
  11346. if (isNum(glyphWidths)) {
  11347. defaultWidth = glyphWidths;
  11348. monospace = true;
  11349. } else {
  11350. widths = glyphWidths;
  11351. }
  11352. return {
  11353. defaultWidth: defaultWidth,
  11354. monospace: monospace,
  11355. widths: widths
  11356. };
  11357. },
  11358. buildCharCodeToWidth:
  11359. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11360. properties) {
  11361. var widths = Object.create(null);
  11362. var differences = properties.differences;
  11363. var encoding = properties.defaultEncoding;
  11364. for (var charCode = 0; charCode < 256; charCode++) {
  11365. if (charCode in differences &&
  11366. widthsByGlyphName[differences[charCode]]) {
  11367. widths[charCode] = widthsByGlyphName[differences[charCode]];
  11368. continue;
  11369. }
  11370. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  11371. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  11372. continue;
  11373. }
  11374. }
  11375. return widths;
  11376. },
  11377. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  11378. var baseDict = dict;
  11379. var type = dict.get('Subtype');
  11380. assert(isName(type), 'invalid font Subtype');
  11381. var composite = false;
  11382. var uint8array;
  11383. if (type.name === 'Type0') {
  11384. // If font is a composite
  11385. // - get the descendant font
  11386. // - set the type according to the descendant font
  11387. // - get the FontDescriptor from the descendant font
  11388. var df = dict.get('DescendantFonts');
  11389. if (!df) {
  11390. error('Descendant fonts are not specified');
  11391. }
  11392. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  11393. type = dict.get('Subtype');
  11394. assert(isName(type), 'invalid font Subtype');
  11395. composite = true;
  11396. }
  11397. var descriptor = dict.get('FontDescriptor');
  11398. if (descriptor) {
  11399. var hash = new MurmurHash3_64();
  11400. var encoding = baseDict.getRaw('Encoding');
  11401. if (isName(encoding)) {
  11402. hash.update(encoding.name);
  11403. } else if (isRef(encoding)) {
  11404. hash.update(encoding.num + '_' + encoding.gen);
  11405. } else if (isDict(encoding)) {
  11406. var keys = encoding.getKeys();
  11407. for (var i = 0, ii = keys.length; i < ii; i++) {
  11408. var entry = encoding.getRaw(keys[i]);
  11409. if (isName(entry)) {
  11410. hash.update(entry.name);
  11411. } else if (isRef(entry)) {
  11412. hash.update(entry.num + '_' + entry.gen);
  11413. } else if (isArray(entry)) { // 'Differences' entry.
  11414. // Ideally we should check the contents of the array, but to avoid
  11415. // parsing it here and then again in |extractDataStructures|,
  11416. // we only use the array length for now (fixes bug1157493.pdf).
  11417. hash.update(entry.length.toString());
  11418. }
  11419. }
  11420. }
  11421. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11422. if (isStream(toUnicode)) {
  11423. var stream = toUnicode.str || toUnicode;
  11424. uint8array = stream.buffer ?
  11425. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11426. new Uint8Array(stream.bytes.buffer,
  11427. stream.start, stream.end - stream.start);
  11428. hash.update(uint8array);
  11429. } else if (isName(toUnicode)) {
  11430. hash.update(toUnicode.name);
  11431. }
  11432. var widths = dict.get('Widths') || baseDict.get('Widths');
  11433. if (widths) {
  11434. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11435. hash.update(uint8array);
  11436. }
  11437. }
  11438. return {
  11439. descriptor: descriptor,
  11440. dict: dict,
  11441. baseDict: baseDict,
  11442. composite: composite,
  11443. type: type.name,
  11444. hash: hash ? hash.hexdigest() : ''
  11445. };
  11446. },
  11447. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11448. xref) {
  11449. var baseDict = preEvaluatedFont.baseDict;
  11450. var dict = preEvaluatedFont.dict;
  11451. var composite = preEvaluatedFont.composite;
  11452. var descriptor = preEvaluatedFont.descriptor;
  11453. var type = preEvaluatedFont.type;
  11454. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11455. var properties;
  11456. if (!descriptor) {
  11457. if (type === 'Type3') {
  11458. // FontDescriptor is only required for Type3 fonts when the document
  11459. // is a tagged pdf. Create a barbebones one to get by.
  11460. descriptor = new Dict(null);
  11461. descriptor.set('FontName', Name.get(type));
  11462. descriptor.set('FontBBox', dict.get('FontBBox'));
  11463. } else {
  11464. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11465. // FontDescriptor was not required.
  11466. // This case is here for compatibility.
  11467. var baseFontName = dict.get('BaseFont');
  11468. if (!isName(baseFontName)) {
  11469. error('Base font is not specified');
  11470. }
  11471. // Using base font name as a font name.
  11472. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11473. var metrics = this.getBaseFontMetrics(baseFontName);
  11474. // Simulating descriptor flags attribute
  11475. var fontNameWoStyle = baseFontName.split('-')[0];
  11476. var flags =
  11477. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11478. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11479. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11480. FontFlags.Nonsymbolic);
  11481. properties = {
  11482. type: type,
  11483. name: baseFontName,
  11484. widths: metrics.widths,
  11485. defaultWidth: metrics.defaultWidth,
  11486. flags: flags,
  11487. firstChar: 0,
  11488. lastChar: maxCharIndex
  11489. };
  11490. this.extractDataStructures(dict, dict, xref, properties);
  11491. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11492. properties);
  11493. return new Font(baseFontName, null, properties);
  11494. }
  11495. }
  11496. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11497. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11498. // to ignore this rule when a variant of a standart font is used.
  11499. // TODO Fill the width array depending on which of the base font this is
  11500. // a variant.
  11501. var firstChar = (dict.get('FirstChar') || 0);
  11502. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11503. var fontName = descriptor.get('FontName');
  11504. var baseFont = dict.get('BaseFont');
  11505. // Some bad PDFs have a string as the font name.
  11506. if (isString(fontName)) {
  11507. fontName = Name.get(fontName);
  11508. }
  11509. if (isString(baseFont)) {
  11510. baseFont = Name.get(baseFont);
  11511. }
  11512. if (type !== 'Type3') {
  11513. var fontNameStr = fontName && fontName.name;
  11514. var baseFontStr = baseFont && baseFont.name;
  11515. if (fontNameStr !== baseFontStr) {
  11516. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11517. '" but should be the same as the Font\'s BaseFont "' +
  11518. baseFontStr + '"');
  11519. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11520. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11521. if (fontNameStr && baseFontStr &&
  11522. baseFontStr.indexOf(fontNameStr) === 0) {
  11523. fontName = baseFont;
  11524. }
  11525. }
  11526. }
  11527. fontName = (fontName || baseFont);
  11528. assert(isName(fontName), 'invalid font name');
  11529. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11530. if (fontFile) {
  11531. if (fontFile.dict) {
  11532. var subtype = fontFile.dict.get('Subtype');
  11533. if (subtype) {
  11534. subtype = subtype.name;
  11535. }
  11536. var length1 = fontFile.dict.get('Length1');
  11537. var length2 = fontFile.dict.get('Length2');
  11538. }
  11539. }
  11540. properties = {
  11541. type: type,
  11542. name: fontName.name,
  11543. subtype: subtype,
  11544. file: fontFile,
  11545. length1: length1,
  11546. length2: length2,
  11547. loadedName: baseDict.loadedName,
  11548. composite: composite,
  11549. wideChars: composite,
  11550. fixedPitch: false,
  11551. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11552. firstChar: firstChar || 0,
  11553. lastChar: (lastChar || maxCharIndex),
  11554. bbox: descriptor.get('FontBBox'),
  11555. ascent: descriptor.get('Ascent'),
  11556. descent: descriptor.get('Descent'),
  11557. xHeight: descriptor.get('XHeight'),
  11558. capHeight: descriptor.get('CapHeight'),
  11559. flags: descriptor.get('Flags'),
  11560. italicAngle: descriptor.get('ItalicAngle'),
  11561. coded: false
  11562. };
  11563. if (composite) {
  11564. var cidEncoding = baseDict.get('Encoding');
  11565. if (isName(cidEncoding)) {
  11566. properties.cidEncoding = cidEncoding.name;
  11567. }
  11568. properties.cMap = CMapFactory.create(cidEncoding,
  11569. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11570. properties.vertical = properties.cMap.vertical;
  11571. }
  11572. this.extractDataStructures(dict, baseDict, xref, properties);
  11573. this.extractWidths(dict, xref, descriptor, properties);
  11574. if (type === 'Type3') {
  11575. properties.isType3Font = true;
  11576. }
  11577. return new Font(fontName.name, fontFile, properties);
  11578. }
  11579. };
  11580. return PartialEvaluator;
  11581. })();
  11582. var TranslatedFont = (function TranslatedFontClosure() {
  11583. function TranslatedFont(loadedName, font, dict) {
  11584. this.loadedName = loadedName;
  11585. this.font = font;
  11586. this.dict = dict;
  11587. this.type3Loaded = null;
  11588. this.sent = false;
  11589. }
  11590. TranslatedFont.prototype = {
  11591. send: function (handler) {
  11592. if (this.sent) {
  11593. return;
  11594. }
  11595. var fontData = this.font.exportData();
  11596. handler.send('commonobj', [
  11597. this.loadedName,
  11598. 'Font',
  11599. fontData
  11600. ]);
  11601. this.sent = true;
  11602. },
  11603. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  11604. assert(this.font.isType3Font);
  11605. if (this.type3Loaded) {
  11606. return this.type3Loaded;
  11607. }
  11608. var translatedFont = this.font;
  11609. var loadCharProcsPromise = Promise.resolve();
  11610. var charProcs = this.dict.get('CharProcs').getAll();
  11611. var fontResources = this.dict.get('Resources') || resources;
  11612. var charProcKeys = Object.keys(charProcs);
  11613. var charProcOperatorList = {};
  11614. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11615. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11616. var glyphStream = charProcs[key];
  11617. var operatorList = new OperatorList();
  11618. return evaluator.getOperatorList(glyphStream, task, fontResources,
  11619. operatorList).then(function () {
  11620. charProcOperatorList[key] = operatorList.getIR();
  11621. // Add the dependencies to the parent operator list so they are
  11622. // resolved before sub operator list is executed synchronously.
  11623. parentOperatorList.addDependencies(operatorList.dependencies);
  11624. }, function (reason) {
  11625. warn('Type3 font resource \"' + key + '\" is not available');
  11626. var operatorList = new OperatorList();
  11627. charProcOperatorList[key] = operatorList.getIR();
  11628. });
  11629. }.bind(this, charProcKeys[i]));
  11630. }
  11631. this.type3Loaded = loadCharProcsPromise.then(function () {
  11632. translatedFont.charProcOperatorList = charProcOperatorList;
  11633. });
  11634. return this.type3Loaded;
  11635. }
  11636. };
  11637. return TranslatedFont;
  11638. })();
  11639. var OperatorList = (function OperatorListClosure() {
  11640. var CHUNK_SIZE = 1000;
  11641. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11642. function getTransfers(queue) {
  11643. var transfers = [];
  11644. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11645. for (var i = 0, ii = queue.length; i < ii; i++) {
  11646. switch (fnArray[i]) {
  11647. case OPS.paintInlineImageXObject:
  11648. case OPS.paintInlineImageXObjectGroup:
  11649. case OPS.paintImageMaskXObject:
  11650. var arg = argsArray[i][0]; // first param in imgData
  11651. if (!arg.cached) {
  11652. transfers.push(arg.data.buffer);
  11653. }
  11654. break;
  11655. }
  11656. }
  11657. return transfers;
  11658. }
  11659. function OperatorList(intent, messageHandler, pageIndex) {
  11660. this.messageHandler = messageHandler;
  11661. this.fnArray = [];
  11662. this.argsArray = [];
  11663. this.dependencies = {};
  11664. this._totalLength = 0;
  11665. this.pageIndex = pageIndex;
  11666. this.intent = intent;
  11667. }
  11668. OperatorList.prototype = {
  11669. get length() {
  11670. return this.argsArray.length;
  11671. },
  11672. /**
  11673. * @returns {number} The total length of the entire operator list,
  11674. * since `this.length === 0` after flushing.
  11675. */
  11676. get totalLength() {
  11677. return (this._totalLength + this.length);
  11678. },
  11679. addOp: function(fn, args) {
  11680. this.fnArray.push(fn);
  11681. this.argsArray.push(args);
  11682. if (this.messageHandler) {
  11683. if (this.fnArray.length >= CHUNK_SIZE) {
  11684. this.flush();
  11685. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11686. (fn === OPS.restore || fn === OPS.endText)) {
  11687. // heuristic to flush on boundary of restore or endText
  11688. this.flush();
  11689. }
  11690. }
  11691. },
  11692. addDependency: function(dependency) {
  11693. if (dependency in this.dependencies) {
  11694. return;
  11695. }
  11696. this.dependencies[dependency] = true;
  11697. this.addOp(OPS.dependency, [dependency]);
  11698. },
  11699. addDependencies: function(dependencies) {
  11700. for (var key in dependencies) {
  11701. this.addDependency(key);
  11702. }
  11703. },
  11704. addOpList: function(opList) {
  11705. Util.extendObj(this.dependencies, opList.dependencies);
  11706. for (var i = 0, ii = opList.length; i < ii; i++) {
  11707. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11708. }
  11709. },
  11710. getIR: function() {
  11711. return {
  11712. fnArray: this.fnArray,
  11713. argsArray: this.argsArray,
  11714. length: this.length
  11715. };
  11716. },
  11717. flush: function(lastChunk) {
  11718. if (this.intent !== 'oplist') {
  11719. new QueueOptimizer().optimize(this);
  11720. }
  11721. var transfers = getTransfers(this);
  11722. var length = this.length;
  11723. this._totalLength += length;
  11724. this.messageHandler.send('RenderPageChunk', {
  11725. operatorList: {
  11726. fnArray: this.fnArray,
  11727. argsArray: this.argsArray,
  11728. lastChunk: lastChunk,
  11729. length: length
  11730. },
  11731. pageIndex: this.pageIndex,
  11732. intent: this.intent
  11733. }, transfers);
  11734. this.dependencies = {};
  11735. this.fnArray.length = 0;
  11736. this.argsArray.length = 0;
  11737. }
  11738. };
  11739. return OperatorList;
  11740. })();
  11741. var StateManager = (function StateManagerClosure() {
  11742. function StateManager(initialState) {
  11743. this.state = initialState;
  11744. this.stateStack = [];
  11745. }
  11746. StateManager.prototype = {
  11747. save: function () {
  11748. var old = this.state;
  11749. this.stateStack.push(this.state);
  11750. this.state = old.clone();
  11751. },
  11752. restore: function () {
  11753. var prev = this.stateStack.pop();
  11754. if (prev) {
  11755. this.state = prev;
  11756. }
  11757. },
  11758. transform: function (args) {
  11759. this.state.ctm = Util.transform(this.state.ctm, args);
  11760. }
  11761. };
  11762. return StateManager;
  11763. })();
  11764. var TextState = (function TextStateClosure() {
  11765. function TextState() {
  11766. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11767. this.fontSize = 0;
  11768. this.font = null;
  11769. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11770. this.textMatrix = IDENTITY_MATRIX.slice();
  11771. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11772. this.charSpacing = 0;
  11773. this.wordSpacing = 0;
  11774. this.leading = 0;
  11775. this.textHScale = 1;
  11776. this.textRise = 0;
  11777. }
  11778. TextState.prototype = {
  11779. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11780. var m = this.textMatrix;
  11781. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11782. },
  11783. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11784. var m = this.textLineMatrix;
  11785. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11786. },
  11787. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11788. var m = this.textMatrix;
  11789. m[4] = m[0] * x + m[2] * y + m[4];
  11790. m[5] = m[1] * x + m[3] * y + m[5];
  11791. },
  11792. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11793. var m = this.textLineMatrix;
  11794. m[4] = m[0] * x + m[2] * y + m[4];
  11795. m[5] = m[1] * x + m[3] * y + m[5];
  11796. },
  11797. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11798. // 9.4.4 Text Space Details
  11799. var tsm = [this.fontSize * this.textHScale, 0,
  11800. 0, this.fontSize,
  11801. 0, this.textRise];
  11802. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11803. },
  11804. carriageReturn: function TextState_carriageReturn() {
  11805. this.translateTextLineMatrix(0, -this.leading);
  11806. this.textMatrix = this.textLineMatrix.slice();
  11807. },
  11808. clone: function TextState_clone() {
  11809. var clone = Object.create(this);
  11810. clone.textMatrix = this.textMatrix.slice();
  11811. clone.textLineMatrix = this.textLineMatrix.slice();
  11812. clone.fontMatrix = this.fontMatrix.slice();
  11813. return clone;
  11814. }
  11815. };
  11816. return TextState;
  11817. })();
  11818. var EvalState = (function EvalStateClosure() {
  11819. function EvalState() {
  11820. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11821. this.font = null;
  11822. this.textRenderingMode = TextRenderingMode.FILL;
  11823. this.fillColorSpace = ColorSpace.singletons.gray;
  11824. this.strokeColorSpace = ColorSpace.singletons.gray;
  11825. }
  11826. EvalState.prototype = {
  11827. clone: function CanvasExtraState_clone() {
  11828. return Object.create(this);
  11829. },
  11830. };
  11831. return EvalState;
  11832. })();
  11833. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11834. // Specifies properties for each command
  11835. //
  11836. // If variableArgs === true: [0, `numArgs`] expected
  11837. // If variableArgs === false: exactly `numArgs` expected
  11838. var OP_MAP = {
  11839. // Graphic state
  11840. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11841. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11842. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11843. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11844. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11845. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11846. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11847. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11848. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11849. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11850. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11851. // Path
  11852. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11853. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11854. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11855. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11856. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11857. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11858. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11859. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11860. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11861. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11862. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11863. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11864. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11865. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11866. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11867. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11868. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11869. // Clipping
  11870. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11871. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11872. // Text
  11873. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11874. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11875. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11876. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11877. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11878. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11879. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11880. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11881. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11882. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11883. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11884. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11885. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11886. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11887. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11888. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11889. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11890. variableArgs: false },
  11891. // Type3 fonts
  11892. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11893. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11894. // Color
  11895. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11896. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11897. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11898. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11899. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11900. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11901. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11902. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11903. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11904. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11905. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11906. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11907. // Shading
  11908. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11909. // Images
  11910. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11911. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11912. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11913. // XObjects
  11914. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11915. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11916. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11917. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11918. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11919. variableArgs: false },
  11920. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11921. // Compatibility
  11922. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11923. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11924. // (reserved partial commands for the lexer)
  11925. BM: null,
  11926. BD: null,
  11927. 'true': null,
  11928. fa: null,
  11929. fal: null,
  11930. fals: null,
  11931. 'false': null,
  11932. nu: null,
  11933. nul: null,
  11934. 'null': null
  11935. };
  11936. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11937. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11938. // dictionary
  11939. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11940. this.stateManager = stateManager;
  11941. this.nonProcessedArgs = [];
  11942. }
  11943. EvaluatorPreprocessor.prototype = {
  11944. get savedStatesDepth() {
  11945. return this.stateManager.stateStack.length;
  11946. },
  11947. // |operation| is an object with two fields:
  11948. //
  11949. // - |fn| is an out param.
  11950. //
  11951. // - |args| is an inout param. On entry, it should have one of two values.
  11952. //
  11953. // - An empty array. This indicates that the caller is providing the
  11954. // array in which the args will be stored in. The caller should use
  11955. // this value if it can reuse a single array for each call to read().
  11956. //
  11957. // - |null|. This indicates that the caller needs this function to create
  11958. // the array in which any args are stored in. If there are zero args,
  11959. // this function will leave |operation.args| as |null| (thus avoiding
  11960. // allocations that would occur if we used an empty array to represent
  11961. // zero arguments). Otherwise, it will replace |null| with a new array
  11962. // containing the arguments. The caller should use this value if it
  11963. // cannot reuse an array for each call to read().
  11964. //
  11965. // These two modes are present because this function is very hot and so
  11966. // avoiding allocations where possible is worthwhile.
  11967. //
  11968. read: function EvaluatorPreprocessor_read(operation) {
  11969. var args = operation.args;
  11970. while (true) {
  11971. var obj = this.parser.getObj();
  11972. if (isCmd(obj)) {
  11973. var cmd = obj.cmd;
  11974. // Check that the command is valid
  11975. var opSpec = OP_MAP[cmd];
  11976. if (!opSpec) {
  11977. warn('Unknown command "' + cmd + '"');
  11978. continue;
  11979. }
  11980. var fn = opSpec.id;
  11981. var numArgs = opSpec.numArgs;
  11982. var argsLength = args !== null ? args.length : 0;
  11983. if (!opSpec.variableArgs) {
  11984. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11985. if (argsLength !== numArgs) {
  11986. var nonProcessedArgs = this.nonProcessedArgs;
  11987. while (argsLength > numArgs) {
  11988. nonProcessedArgs.push(args.shift());
  11989. argsLength--;
  11990. }
  11991. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11992. if (!args) {
  11993. args = [];
  11994. }
  11995. args.unshift(nonProcessedArgs.pop());
  11996. argsLength++;
  11997. }
  11998. }
  11999. if (argsLength < numArgs) {
  12000. // If we receive too few args, it's not possible to possible
  12001. // to execute the command, so skip the command
  12002. info('Command ' + fn + ': because expected ' +
  12003. numArgs + ' args, but received ' + argsLength +
  12004. ' args; skipping');
  12005. args = null;
  12006. continue;
  12007. }
  12008. } else if (argsLength > numArgs) {
  12009. info('Command ' + fn + ': expected [0,' + numArgs +
  12010. '] args, but received ' + argsLength + ' args');
  12011. }
  12012. // TODO figure out how to type-check vararg functions
  12013. this.preprocessCommand(fn, args);
  12014. operation.fn = fn;
  12015. operation.args = args;
  12016. return true;
  12017. } else {
  12018. if (isEOF(obj)) {
  12019. return false; // no more commands
  12020. }
  12021. // argument
  12022. if (obj !== null) {
  12023. if (!args) {
  12024. args = [];
  12025. }
  12026. args.push((obj instanceof Dict ? obj.getAll() : obj));
  12027. assert(args.length <= 33, 'Too many arguments');
  12028. }
  12029. }
  12030. }
  12031. },
  12032. preprocessCommand:
  12033. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  12034. switch (fn | 0) {
  12035. case OPS.save:
  12036. this.stateManager.save();
  12037. break;
  12038. case OPS.restore:
  12039. this.stateManager.restore();
  12040. break;
  12041. case OPS.transform:
  12042. this.stateManager.transform(args);
  12043. break;
  12044. }
  12045. }
  12046. };
  12047. return EvaluatorPreprocessor;
  12048. })();
  12049. var QueueOptimizer = (function QueueOptimizerClosure() {
  12050. function addState(parentState, pattern, fn) {
  12051. var state = parentState;
  12052. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  12053. var item = pattern[i];
  12054. state = (state[item] || (state[item] = []));
  12055. }
  12056. state[pattern[pattern.length - 1]] = fn;
  12057. }
  12058. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12059. argsArray) {
  12060. // Handles special case of mainly LaTeX documents which use image masks to
  12061. // draw lines with the current fill style.
  12062. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  12063. // have been found at iFirstSave.
  12064. var iFirstPIMXO = iFirstSave + 2;
  12065. for (var i = 0; i < count; i++) {
  12066. var arg = argsArray[iFirstPIMXO + 4 * i];
  12067. var imageMask = arg.length === 1 && arg[0];
  12068. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  12069. (!imageMask.data.length ||
  12070. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  12071. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  12072. continue;
  12073. }
  12074. break;
  12075. }
  12076. return count - i;
  12077. }
  12078. var InitialState = [];
  12079. // This replaces (save, transform, paintInlineImageXObject, restore)+
  12080. // sequences with one |paintInlineImageXObjectGroup| operation.
  12081. addState(InitialState,
  12082. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  12083. function foundInlineImageGroup(context) {
  12084. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  12085. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  12086. var MAX_WIDTH = 1000;
  12087. var IMAGE_PADDING = 1;
  12088. var fnArray = context.fnArray, argsArray = context.argsArray;
  12089. var curr = context.iCurr;
  12090. var iFirstSave = curr - 3;
  12091. var iFirstTransform = curr - 2;
  12092. var iFirstPIIXO = curr - 1;
  12093. // Look for the quartets.
  12094. var i = iFirstSave + 4;
  12095. var ii = fnArray.length;
  12096. while (i + 3 < ii) {
  12097. if (fnArray[i] !== OPS.save ||
  12098. fnArray[i + 1] !== OPS.transform ||
  12099. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  12100. fnArray[i + 3] !== OPS.restore) {
  12101. break; // ops don't match
  12102. }
  12103. i += 4;
  12104. }
  12105. // At this point, i is the index of the first op past the last valid
  12106. // quartet.
  12107. var count = Math.min((i - iFirstSave) / 4,
  12108. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  12109. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  12110. return i;
  12111. }
  12112. // assuming that heights of those image is too small (~1 pixel)
  12113. // packing as much as possible by lines
  12114. var maxX = 0;
  12115. var map = [], maxLineHeight = 0;
  12116. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  12117. var q;
  12118. for (q = 0; q < count; q++) {
  12119. var transform = argsArray[iFirstTransform + (q << 2)];
  12120. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  12121. if (currentX + img.width > MAX_WIDTH) {
  12122. // starting new line
  12123. maxX = Math.max(maxX, currentX);
  12124. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  12125. currentX = 0;
  12126. maxLineHeight = 0;
  12127. }
  12128. map.push({
  12129. transform: transform,
  12130. x: currentX, y: currentY,
  12131. w: img.width, h: img.height
  12132. });
  12133. currentX += img.width + 2 * IMAGE_PADDING;
  12134. maxLineHeight = Math.max(maxLineHeight, img.height);
  12135. }
  12136. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  12137. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  12138. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  12139. var imgRowSize = imgWidth << 2;
  12140. for (q = 0; q < count; q++) {
  12141. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  12142. // Copy image by lines and extends pixels into padding.
  12143. var rowSize = map[q].w << 2;
  12144. var dataOffset = 0;
  12145. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  12146. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  12147. for (var k = 0, kk = map[q].h; k < kk; k++) {
  12148. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  12149. dataOffset += rowSize;
  12150. offset += imgRowSize;
  12151. }
  12152. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  12153. while (offset >= 0) {
  12154. data[offset - 4] = data[offset];
  12155. data[offset - 3] = data[offset + 1];
  12156. data[offset - 2] = data[offset + 2];
  12157. data[offset - 1] = data[offset + 3];
  12158. data[offset + rowSize] = data[offset + rowSize - 4];
  12159. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  12160. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  12161. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  12162. offset -= imgRowSize;
  12163. }
  12164. }
  12165. // Replace queue items.
  12166. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  12167. argsArray.splice(iFirstSave, count * 4,
  12168. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  12169. data: imgData }, map]);
  12170. return iFirstSave + 1;
  12171. });
  12172. // This replaces (save, transform, paintImageMaskXObject, restore)+
  12173. // sequences with one |paintImageMaskXObjectGroup| or one
  12174. // |paintImageMaskXObjectRepeat| operation.
  12175. addState(InitialState,
  12176. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  12177. function foundImageMaskGroup(context) {
  12178. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  12179. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  12180. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  12181. var fnArray = context.fnArray, argsArray = context.argsArray;
  12182. var curr = context.iCurr;
  12183. var iFirstSave = curr - 3;
  12184. var iFirstTransform = curr - 2;
  12185. var iFirstPIMXO = curr - 1;
  12186. // Look for the quartets.
  12187. var i = iFirstSave + 4;
  12188. var ii = fnArray.length;
  12189. while (i + 3 < ii) {
  12190. if (fnArray[i] !== OPS.save ||
  12191. fnArray[i + 1] !== OPS.transform ||
  12192. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  12193. fnArray[i + 3] !== OPS.restore) {
  12194. break; // ops don't match
  12195. }
  12196. i += 4;
  12197. }
  12198. // At this point, i is the index of the first op past the last valid
  12199. // quartet.
  12200. var count = (i - iFirstSave) / 4;
  12201. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12202. argsArray);
  12203. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  12204. return i;
  12205. }
  12206. var q;
  12207. var isSameImage = false;
  12208. var iTransform, transformArgs;
  12209. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  12210. if (argsArray[iFirstTransform][1] === 0 &&
  12211. argsArray[iFirstTransform][2] === 0) {
  12212. isSameImage = true;
  12213. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12214. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12215. iTransform = iFirstTransform + 4;
  12216. var iPIMXO = iFirstPIMXO + 4;
  12217. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  12218. transformArgs = argsArray[iTransform];
  12219. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  12220. transformArgs[0] !== firstTransformArg0 ||
  12221. transformArgs[1] !== 0 ||
  12222. transformArgs[2] !== 0 ||
  12223. transformArgs[3] !== firstTransformArg3) {
  12224. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  12225. isSameImage = false;
  12226. } else {
  12227. count = q;
  12228. }
  12229. break; // different image or transform
  12230. }
  12231. }
  12232. }
  12233. if (isSameImage) {
  12234. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  12235. var positions = new Float32Array(count * 2);
  12236. iTransform = iFirstTransform;
  12237. for (q = 0; q < count; q++, iTransform += 4) {
  12238. transformArgs = argsArray[iTransform];
  12239. positions[(q << 1)] = transformArgs[4];
  12240. positions[(q << 1) + 1] = transformArgs[5];
  12241. }
  12242. // Replace queue items.
  12243. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  12244. argsArray.splice(iFirstSave, count * 4,
  12245. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  12246. } else {
  12247. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  12248. var images = [];
  12249. for (q = 0; q < count; q++) {
  12250. transformArgs = argsArray[iFirstTransform + (q << 2)];
  12251. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  12252. images.push({ data: maskParams.data, width: maskParams.width,
  12253. height: maskParams.height,
  12254. transform: transformArgs });
  12255. }
  12256. // Replace queue items.
  12257. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  12258. argsArray.splice(iFirstSave, count * 4, [images]);
  12259. }
  12260. return iFirstSave + 1;
  12261. });
  12262. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  12263. // with one paintImageXObjectRepeat operation, if the |transform| and
  12264. // |paintImageXObjectRepeat| ops are appropriate.
  12265. addState(InitialState,
  12266. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  12267. function (context) {
  12268. var MIN_IMAGES_IN_BLOCK = 3;
  12269. var MAX_IMAGES_IN_BLOCK = 1000;
  12270. var fnArray = context.fnArray, argsArray = context.argsArray;
  12271. var curr = context.iCurr;
  12272. var iFirstSave = curr - 3;
  12273. var iFirstTransform = curr - 2;
  12274. var iFirstPIXO = curr - 1;
  12275. var iFirstRestore = curr;
  12276. if (argsArray[iFirstTransform][1] !== 0 ||
  12277. argsArray[iFirstTransform][2] !== 0) {
  12278. return iFirstRestore + 1; // transform has the wrong form
  12279. }
  12280. // Look for the quartets.
  12281. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  12282. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12283. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12284. var i = iFirstSave + 4;
  12285. var ii = fnArray.length;
  12286. while (i + 3 < ii) {
  12287. if (fnArray[i] !== OPS.save ||
  12288. fnArray[i + 1] !== OPS.transform ||
  12289. fnArray[i + 2] !== OPS.paintImageXObject ||
  12290. fnArray[i + 3] !== OPS.restore) {
  12291. break; // ops don't match
  12292. }
  12293. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  12294. argsArray[i + 1][1] !== 0 ||
  12295. argsArray[i + 1][2] !== 0 ||
  12296. argsArray[i + 1][3] !== firstTransformArg3) {
  12297. break; // transforms don't match
  12298. }
  12299. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  12300. break; // images don't match
  12301. }
  12302. i += 4;
  12303. }
  12304. // At this point, i is the index of the first op past the last valid
  12305. // quartet.
  12306. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  12307. if (count < MIN_IMAGES_IN_BLOCK) {
  12308. return i;
  12309. }
  12310. // Extract the (x,y) positions from all of the matching transforms.
  12311. var positions = new Float32Array(count * 2);
  12312. var iTransform = iFirstTransform;
  12313. for (var q = 0; q < count; q++, iTransform += 4) {
  12314. var transformArgs = argsArray[iTransform];
  12315. positions[(q << 1)] = transformArgs[4];
  12316. positions[(q << 1) + 1] = transformArgs[5];
  12317. }
  12318. // Replace queue items.
  12319. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  12320. positions];
  12321. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  12322. argsArray.splice(iFirstSave, count * 4, args);
  12323. return iFirstSave + 1;
  12324. });
  12325. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  12326. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  12327. // sequences, if the font for each one is the same.
  12328. addState(InitialState,
  12329. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  12330. function (context) {
  12331. var MIN_CHARS_IN_BLOCK = 3;
  12332. var MAX_CHARS_IN_BLOCK = 1000;
  12333. var fnArray = context.fnArray, argsArray = context.argsArray;
  12334. var curr = context.iCurr;
  12335. var iFirstBeginText = curr - 4;
  12336. var iFirstSetFont = curr - 3;
  12337. var iFirstSetTextMatrix = curr - 2;
  12338. var iFirstShowText = curr - 1;
  12339. var iFirstEndText = curr;
  12340. // Look for the quintets.
  12341. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  12342. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  12343. var i = iFirstBeginText + 5;
  12344. var ii = fnArray.length;
  12345. while (i + 4 < ii) {
  12346. if (fnArray[i] !== OPS.beginText ||
  12347. fnArray[i + 1] !== OPS.setFont ||
  12348. fnArray[i + 2] !== OPS.setTextMatrix ||
  12349. fnArray[i + 3] !== OPS.showText ||
  12350. fnArray[i + 4] !== OPS.endText) {
  12351. break; // ops don't match
  12352. }
  12353. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  12354. argsArray[i + 1][1] !== firstSetFontArg1) {
  12355. break; // fonts don't match
  12356. }
  12357. i += 5;
  12358. }
  12359. // At this point, i is the index of the first op past the last valid
  12360. // quintet.
  12361. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12362. if (count < MIN_CHARS_IN_BLOCK) {
  12363. return i;
  12364. }
  12365. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  12366. // showText, endText), include that as well. (E.g. <something> might be
  12367. // |dependency|.)
  12368. var iFirst = iFirstBeginText;
  12369. if (iFirstBeginText >= 4 &&
  12370. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  12371. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  12372. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  12373. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  12374. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  12375. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  12376. count++;
  12377. iFirst -= 5;
  12378. }
  12379. // Remove (endText, beginText, setFont) trios.
  12380. var iEndText = iFirst + 4;
  12381. for (var q = 1; q < count; q++) {
  12382. fnArray.splice(iEndText, 3);
  12383. argsArray.splice(iEndText, 3);
  12384. iEndText += 2;
  12385. }
  12386. return iEndText + 1;
  12387. });
  12388. function QueueOptimizer() {}
  12389. QueueOptimizer.prototype = {
  12390. optimize: function QueueOptimizer_optimize(queue) {
  12391. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12392. var context = {
  12393. iCurr: 0,
  12394. fnArray: fnArray,
  12395. argsArray: argsArray
  12396. };
  12397. var state;
  12398. var i = 0, ii = fnArray.length;
  12399. while (i < ii) {
  12400. state = (state || InitialState)[fnArray[i]];
  12401. if (typeof state === 'function') { // we found some handler
  12402. context.iCurr = i;
  12403. // state() returns the index of the first non-matching op (if we
  12404. // didn't match) or the first op past the modified ops (if we did
  12405. // match and replace).
  12406. i = state(context);
  12407. state = undefined; // reset the state machine
  12408. ii = context.fnArray.length;
  12409. } else {
  12410. i++;
  12411. }
  12412. }
  12413. }
  12414. };
  12415. return QueueOptimizer;
  12416. })();
  12417. var BUILT_IN_CMAPS = [
  12418. // << Start unicode maps.
  12419. 'Adobe-GB1-UCS2',
  12420. 'Adobe-CNS1-UCS2',
  12421. 'Adobe-Japan1-UCS2',
  12422. 'Adobe-Korea1-UCS2',
  12423. // >> End unicode maps.
  12424. '78-EUC-H',
  12425. '78-EUC-V',
  12426. '78-H',
  12427. '78-RKSJ-H',
  12428. '78-RKSJ-V',
  12429. '78-V',
  12430. '78ms-RKSJ-H',
  12431. '78ms-RKSJ-V',
  12432. '83pv-RKSJ-H',
  12433. '90ms-RKSJ-H',
  12434. '90ms-RKSJ-V',
  12435. '90msp-RKSJ-H',
  12436. '90msp-RKSJ-V',
  12437. '90pv-RKSJ-H',
  12438. '90pv-RKSJ-V',
  12439. 'Add-H',
  12440. 'Add-RKSJ-H',
  12441. 'Add-RKSJ-V',
  12442. 'Add-V',
  12443. 'Adobe-CNS1-0',
  12444. 'Adobe-CNS1-1',
  12445. 'Adobe-CNS1-2',
  12446. 'Adobe-CNS1-3',
  12447. 'Adobe-CNS1-4',
  12448. 'Adobe-CNS1-5',
  12449. 'Adobe-CNS1-6',
  12450. 'Adobe-GB1-0',
  12451. 'Adobe-GB1-1',
  12452. 'Adobe-GB1-2',
  12453. 'Adobe-GB1-3',
  12454. 'Adobe-GB1-4',
  12455. 'Adobe-GB1-5',
  12456. 'Adobe-Japan1-0',
  12457. 'Adobe-Japan1-1',
  12458. 'Adobe-Japan1-2',
  12459. 'Adobe-Japan1-3',
  12460. 'Adobe-Japan1-4',
  12461. 'Adobe-Japan1-5',
  12462. 'Adobe-Japan1-6',
  12463. 'Adobe-Korea1-0',
  12464. 'Adobe-Korea1-1',
  12465. 'Adobe-Korea1-2',
  12466. 'B5-H',
  12467. 'B5-V',
  12468. 'B5pc-H',
  12469. 'B5pc-V',
  12470. 'CNS-EUC-H',
  12471. 'CNS-EUC-V',
  12472. 'CNS1-H',
  12473. 'CNS1-V',
  12474. 'CNS2-H',
  12475. 'CNS2-V',
  12476. 'ETHK-B5-H',
  12477. 'ETHK-B5-V',
  12478. 'ETen-B5-H',
  12479. 'ETen-B5-V',
  12480. 'ETenms-B5-H',
  12481. 'ETenms-B5-V',
  12482. 'EUC-H',
  12483. 'EUC-V',
  12484. 'Ext-H',
  12485. 'Ext-RKSJ-H',
  12486. 'Ext-RKSJ-V',
  12487. 'Ext-V',
  12488. 'GB-EUC-H',
  12489. 'GB-EUC-V',
  12490. 'GB-H',
  12491. 'GB-V',
  12492. 'GBK-EUC-H',
  12493. 'GBK-EUC-V',
  12494. 'GBK2K-H',
  12495. 'GBK2K-V',
  12496. 'GBKp-EUC-H',
  12497. 'GBKp-EUC-V',
  12498. 'GBT-EUC-H',
  12499. 'GBT-EUC-V',
  12500. 'GBT-H',
  12501. 'GBT-V',
  12502. 'GBTpc-EUC-H',
  12503. 'GBTpc-EUC-V',
  12504. 'GBpc-EUC-H',
  12505. 'GBpc-EUC-V',
  12506. 'H',
  12507. 'HKdla-B5-H',
  12508. 'HKdla-B5-V',
  12509. 'HKdlb-B5-H',
  12510. 'HKdlb-B5-V',
  12511. 'HKgccs-B5-H',
  12512. 'HKgccs-B5-V',
  12513. 'HKm314-B5-H',
  12514. 'HKm314-B5-V',
  12515. 'HKm471-B5-H',
  12516. 'HKm471-B5-V',
  12517. 'HKscs-B5-H',
  12518. 'HKscs-B5-V',
  12519. 'Hankaku',
  12520. 'Hiragana',
  12521. 'KSC-EUC-H',
  12522. 'KSC-EUC-V',
  12523. 'KSC-H',
  12524. 'KSC-Johab-H',
  12525. 'KSC-Johab-V',
  12526. 'KSC-V',
  12527. 'KSCms-UHC-H',
  12528. 'KSCms-UHC-HW-H',
  12529. 'KSCms-UHC-HW-V',
  12530. 'KSCms-UHC-V',
  12531. 'KSCpc-EUC-H',
  12532. 'KSCpc-EUC-V',
  12533. 'Katakana',
  12534. 'NWP-H',
  12535. 'NWP-V',
  12536. 'RKSJ-H',
  12537. 'RKSJ-V',
  12538. 'Roman',
  12539. 'UniCNS-UCS2-H',
  12540. 'UniCNS-UCS2-V',
  12541. 'UniCNS-UTF16-H',
  12542. 'UniCNS-UTF16-V',
  12543. 'UniCNS-UTF32-H',
  12544. 'UniCNS-UTF32-V',
  12545. 'UniCNS-UTF8-H',
  12546. 'UniCNS-UTF8-V',
  12547. 'UniGB-UCS2-H',
  12548. 'UniGB-UCS2-V',
  12549. 'UniGB-UTF16-H',
  12550. 'UniGB-UTF16-V',
  12551. 'UniGB-UTF32-H',
  12552. 'UniGB-UTF32-V',
  12553. 'UniGB-UTF8-H',
  12554. 'UniGB-UTF8-V',
  12555. 'UniJIS-UCS2-H',
  12556. 'UniJIS-UCS2-HW-H',
  12557. 'UniJIS-UCS2-HW-V',
  12558. 'UniJIS-UCS2-V',
  12559. 'UniJIS-UTF16-H',
  12560. 'UniJIS-UTF16-V',
  12561. 'UniJIS-UTF32-H',
  12562. 'UniJIS-UTF32-V',
  12563. 'UniJIS-UTF8-H',
  12564. 'UniJIS-UTF8-V',
  12565. 'UniJIS2004-UTF16-H',
  12566. 'UniJIS2004-UTF16-V',
  12567. 'UniJIS2004-UTF32-H',
  12568. 'UniJIS2004-UTF32-V',
  12569. 'UniJIS2004-UTF8-H',
  12570. 'UniJIS2004-UTF8-V',
  12571. 'UniJISPro-UCS2-HW-V',
  12572. 'UniJISPro-UCS2-V',
  12573. 'UniJISPro-UTF8-V',
  12574. 'UniJISX0213-UTF32-H',
  12575. 'UniJISX0213-UTF32-V',
  12576. 'UniJISX02132004-UTF32-H',
  12577. 'UniJISX02132004-UTF32-V',
  12578. 'UniKS-UCS2-H',
  12579. 'UniKS-UCS2-V',
  12580. 'UniKS-UTF16-H',
  12581. 'UniKS-UTF16-V',
  12582. 'UniKS-UTF32-H',
  12583. 'UniKS-UTF32-V',
  12584. 'UniKS-UTF8-H',
  12585. 'UniKS-UTF8-V',
  12586. 'V',
  12587. 'WP-Symbol'];
  12588. // CMap, not to be confused with TrueType's cmap.
  12589. var CMap = (function CMapClosure() {
  12590. function CMap(builtInCMap) {
  12591. // Codespace ranges are stored as follows:
  12592. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12593. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12594. this.codespaceRanges = [[], [], [], []];
  12595. this.numCodespaceRanges = 0;
  12596. // Map entries have one of two forms.
  12597. // - cid chars are 16-bit unsigned integers, stored as integers.
  12598. // - bf chars are variable-length byte sequences, stored as strings, with
  12599. // one byte per character.
  12600. this._map = [];
  12601. this.name = '';
  12602. this.vertical = false;
  12603. this.useCMap = null;
  12604. this.builtInCMap = builtInCMap;
  12605. }
  12606. CMap.prototype = {
  12607. addCodespaceRange: function(n, low, high) {
  12608. this.codespaceRanges[n - 1].push(low, high);
  12609. this.numCodespaceRanges++;
  12610. },
  12611. mapCidRange: function(low, high, dstLow) {
  12612. while (low <= high) {
  12613. this._map[low++] = dstLow++;
  12614. }
  12615. },
  12616. mapBfRange: function(low, high, dstLow) {
  12617. var lastByte = dstLow.length - 1;
  12618. while (low <= high) {
  12619. this._map[low++] = dstLow;
  12620. // Only the last byte has to be incremented.
  12621. dstLow = dstLow.substr(0, lastByte) +
  12622. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12623. }
  12624. },
  12625. mapBfRangeToArray: function(low, high, array) {
  12626. var i = 0, ii = array.length;
  12627. while (low <= high && i < ii) {
  12628. this._map[low] = array[i++];
  12629. ++low;
  12630. }
  12631. },
  12632. // This is used for both bf and cid chars.
  12633. mapOne: function(src, dst) {
  12634. this._map[src] = dst;
  12635. },
  12636. lookup: function(code) {
  12637. return this._map[code];
  12638. },
  12639. contains: function(code) {
  12640. return this._map[code] !== undefined;
  12641. },
  12642. forEach: function(callback) {
  12643. // Most maps have fewer than 65536 entries, and for those we use normal
  12644. // array iteration. But really sparse tables are possible -- e.g. with
  12645. // indices in the *billions*. For such tables we use for..in, which isn't
  12646. // ideal because it stringifies the indices for all present elements, but
  12647. // it does avoid iterating over every undefined entry.
  12648. var map = this._map;
  12649. var length = map.length;
  12650. var i;
  12651. if (length <= 0x10000) {
  12652. for (i = 0; i < length; i++) {
  12653. if (map[i] !== undefined) {
  12654. callback(i, map[i]);
  12655. }
  12656. }
  12657. } else {
  12658. for (i in this._map) {
  12659. callback(i, map[i]);
  12660. }
  12661. }
  12662. },
  12663. charCodeOf: function(value) {
  12664. return this._map.indexOf(value);
  12665. },
  12666. getMap: function() {
  12667. return this._map;
  12668. },
  12669. readCharCode: function(str, offset, out) {
  12670. var c = 0;
  12671. var codespaceRanges = this.codespaceRanges;
  12672. var codespaceRangesLen = this.codespaceRanges.length;
  12673. // 9.7.6.2 CMap Mapping
  12674. // The code length is at most 4.
  12675. for (var n = 0; n < codespaceRangesLen; n++) {
  12676. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12677. // Check each codespace range to see if it falls within.
  12678. var codespaceRange = codespaceRanges[n];
  12679. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12680. var low = codespaceRange[k++];
  12681. var high = codespaceRange[k++];
  12682. if (c >= low && c <= high) {
  12683. out.charcode = c;
  12684. out.length = n + 1;
  12685. return;
  12686. }
  12687. }
  12688. }
  12689. out.charcode = 0;
  12690. out.length = 1;
  12691. },
  12692. get length() {
  12693. return this._map.length;
  12694. },
  12695. get isIdentityCMap() {
  12696. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12697. return false;
  12698. }
  12699. if (this._map.length !== 0x10000) {
  12700. return false;
  12701. }
  12702. for (var i = 0; i < 0x10000; i++) {
  12703. if (this._map[i] !== i) {
  12704. return false;
  12705. }
  12706. }
  12707. return true;
  12708. }
  12709. };
  12710. return CMap;
  12711. })();
  12712. // A special case of CMap, where the _map array implicitly has a length of
  12713. // 65536 and each element is equal to its index.
  12714. var IdentityCMap = (function IdentityCMapClosure() {
  12715. function IdentityCMap(vertical, n) {
  12716. CMap.call(this);
  12717. this.vertical = vertical;
  12718. this.addCodespaceRange(n, 0, 0xffff);
  12719. }
  12720. Util.inherit(IdentityCMap, CMap, {});
  12721. IdentityCMap.prototype = {
  12722. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12723. mapCidRange: function(low, high, dstLow) {
  12724. error('should not call mapCidRange');
  12725. },
  12726. mapBfRange: function(low, high, dstLow) {
  12727. error('should not call mapBfRange');
  12728. },
  12729. mapBfRangeToArray: function(low, high, array) {
  12730. error('should not call mapBfRangeToArray');
  12731. },
  12732. mapOne: function(src, dst) {
  12733. error('should not call mapCidOne');
  12734. },
  12735. lookup: function(code) {
  12736. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12737. },
  12738. contains: function(code) {
  12739. return isInt(code) && code <= 0xffff;
  12740. },
  12741. forEach: function(callback) {
  12742. for (var i = 0; i <= 0xffff; i++) {
  12743. callback(i, i);
  12744. }
  12745. },
  12746. charCodeOf: function(value) {
  12747. return (isInt(value) && value <= 0xffff) ? value : -1;
  12748. },
  12749. getMap: function() {
  12750. // Sometimes identity maps must be instantiated, but it's rare.
  12751. var map = new Array(0x10000);
  12752. for (var i = 0; i <= 0xffff; i++) {
  12753. map[i] = i;
  12754. }
  12755. return map;
  12756. },
  12757. readCharCode: CMap.prototype.readCharCode,
  12758. get length() {
  12759. return 0x10000;
  12760. },
  12761. get isIdentityCMap() {
  12762. error('should not access .isIdentityCMap');
  12763. }
  12764. };
  12765. return IdentityCMap;
  12766. })();
  12767. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12768. function fetchBinaryData(url) {
  12769. var nonBinaryRequest = PDFJS.disableWorker;
  12770. var request = new XMLHttpRequest();
  12771. request.open('GET', url, false);
  12772. if (!nonBinaryRequest) {
  12773. try {
  12774. request.responseType = 'arraybuffer';
  12775. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12776. } catch (e) {
  12777. nonBinaryRequest = true;
  12778. }
  12779. }
  12780. if (nonBinaryRequest && request.overrideMimeType) {
  12781. request.overrideMimeType('text/plain; charset=x-user-defined');
  12782. }
  12783. request.send(null);
  12784. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12785. error('Unable to get binary cMap at: ' + url);
  12786. }
  12787. if (nonBinaryRequest) {
  12788. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12789. return ch.charCodeAt(0) & 255;
  12790. });
  12791. return new Uint8Array(data);
  12792. }
  12793. return new Uint8Array(request.response);
  12794. }
  12795. function hexToInt(a, size) {
  12796. var n = 0;
  12797. for (var i = 0; i <= size; i++) {
  12798. n = (n << 8) | a[i];
  12799. }
  12800. return n >>> 0;
  12801. }
  12802. function hexToStr(a, size) {
  12803. // This code is hot. Special-case some common values to avoid creating an
  12804. // object with subarray().
  12805. if (size === 1) {
  12806. return String.fromCharCode(a[0], a[1]);
  12807. }
  12808. if (size === 3) {
  12809. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12810. }
  12811. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12812. }
  12813. function addHex(a, b, size) {
  12814. var c = 0;
  12815. for (var i = size; i >= 0; i--) {
  12816. c += a[i] + b[i];
  12817. a[i] = c & 255;
  12818. c >>= 8;
  12819. }
  12820. }
  12821. function incHex(a, size) {
  12822. var c = 1;
  12823. for (var i = size; i >= 0 && c > 0; i--) {
  12824. c += a[i];
  12825. a[i] = c & 255;
  12826. c >>= 8;
  12827. }
  12828. }
  12829. var MAX_NUM_SIZE = 16;
  12830. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12831. function BinaryCMapStream(data) {
  12832. this.buffer = data;
  12833. this.pos = 0;
  12834. this.end = data.length;
  12835. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12836. }
  12837. BinaryCMapStream.prototype = {
  12838. readByte: function () {
  12839. if (this.pos >= this.end) {
  12840. return -1;
  12841. }
  12842. return this.buffer[this.pos++];
  12843. },
  12844. readNumber: function () {
  12845. var n = 0;
  12846. var last;
  12847. do {
  12848. var b = this.readByte();
  12849. if (b < 0) {
  12850. error('unexpected EOF in bcmap');
  12851. }
  12852. last = !(b & 0x80);
  12853. n = (n << 7) | (b & 0x7F);
  12854. } while (!last);
  12855. return n;
  12856. },
  12857. readSigned: function () {
  12858. var n = this.readNumber();
  12859. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12860. },
  12861. readHex: function (num, size) {
  12862. num.set(this.buffer.subarray(this.pos,
  12863. this.pos + size + 1));
  12864. this.pos += size + 1;
  12865. },
  12866. readHexNumber: function (num, size) {
  12867. var last;
  12868. var stack = this.tmpBuf, sp = 0;
  12869. do {
  12870. var b = this.readByte();
  12871. if (b < 0) {
  12872. error('unexpected EOF in bcmap');
  12873. }
  12874. last = !(b & 0x80);
  12875. stack[sp++] = b & 0x7F;
  12876. } while (!last);
  12877. var i = size, buffer = 0, bufferSize = 0;
  12878. while (i >= 0) {
  12879. while (bufferSize < 8 && stack.length > 0) {
  12880. buffer = (stack[--sp] << bufferSize) | buffer;
  12881. bufferSize += 7;
  12882. }
  12883. num[i] = buffer & 255;
  12884. i--;
  12885. buffer >>= 8;
  12886. bufferSize -= 8;
  12887. }
  12888. },
  12889. readHexSigned: function (num, size) {
  12890. this.readHexNumber(num, size);
  12891. var sign = num[size] & 1 ? 255 : 0;
  12892. var c = 0;
  12893. for (var i = 0; i <= size; i++) {
  12894. c = ((c & 1) << 8) | num[i];
  12895. num[i] = (c >> 1) ^ sign;
  12896. }
  12897. },
  12898. readString: function () {
  12899. var len = this.readNumber();
  12900. var s = '';
  12901. for (var i = 0; i < len; i++) {
  12902. s += String.fromCharCode(this.readNumber());
  12903. }
  12904. return s;
  12905. }
  12906. };
  12907. function processBinaryCMap(url, cMap, extend) {
  12908. var data = fetchBinaryData(url);
  12909. var stream = new BinaryCMapStream(data);
  12910. var header = stream.readByte();
  12911. cMap.vertical = !!(header & 1);
  12912. var useCMap = null;
  12913. var start = new Uint8Array(MAX_NUM_SIZE);
  12914. var end = new Uint8Array(MAX_NUM_SIZE);
  12915. var char = new Uint8Array(MAX_NUM_SIZE);
  12916. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12917. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12918. var code;
  12919. var b;
  12920. while ((b = stream.readByte()) >= 0) {
  12921. var type = b >> 5;
  12922. if (type === 7) { // metadata, e.g. comment or usecmap
  12923. switch (b & 0x1F) {
  12924. case 0:
  12925. stream.readString(); // skipping comment
  12926. break;
  12927. case 1:
  12928. useCMap = stream.readString();
  12929. break;
  12930. }
  12931. continue;
  12932. }
  12933. var sequence = !!(b & 0x10);
  12934. var dataSize = b & 15;
  12935. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12936. var ucs2DataSize = 1;
  12937. var subitemsCount = stream.readNumber();
  12938. var i;
  12939. switch (type) {
  12940. case 0: // codespacerange
  12941. stream.readHex(start, dataSize);
  12942. stream.readHexNumber(end, dataSize);
  12943. addHex(end, start, dataSize);
  12944. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12945. hexToInt(end, dataSize));
  12946. for (i = 1; i < subitemsCount; i++) {
  12947. incHex(end, dataSize);
  12948. stream.readHexNumber(start, dataSize);
  12949. addHex(start, end, dataSize);
  12950. stream.readHexNumber(end, dataSize);
  12951. addHex(end, start, dataSize);
  12952. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12953. hexToInt(end, dataSize));
  12954. }
  12955. break;
  12956. case 1: // notdefrange
  12957. stream.readHex(start, dataSize);
  12958. stream.readHexNumber(end, dataSize);
  12959. addHex(end, start, dataSize);
  12960. code = stream.readNumber();
  12961. // undefined range, skipping
  12962. for (i = 1; i < subitemsCount; i++) {
  12963. incHex(end, dataSize);
  12964. stream.readHexNumber(start, dataSize);
  12965. addHex(start, end, dataSize);
  12966. stream.readHexNumber(end, dataSize);
  12967. addHex(end, start, dataSize);
  12968. code = stream.readNumber();
  12969. // nop
  12970. }
  12971. break;
  12972. case 2: // cidchar
  12973. stream.readHex(char, dataSize);
  12974. code = stream.readNumber();
  12975. cMap.mapOne(hexToInt(char, dataSize), code);
  12976. for (i = 1; i < subitemsCount; i++) {
  12977. incHex(char, dataSize);
  12978. if (!sequence) {
  12979. stream.readHexNumber(tmp, dataSize);
  12980. addHex(char, tmp, dataSize);
  12981. }
  12982. code = stream.readSigned() + (code + 1);
  12983. cMap.mapOne(hexToInt(char, dataSize), code);
  12984. }
  12985. break;
  12986. case 3: // cidrange
  12987. stream.readHex(start, dataSize);
  12988. stream.readHexNumber(end, dataSize);
  12989. addHex(end, start, dataSize);
  12990. code = stream.readNumber();
  12991. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12992. code);
  12993. for (i = 1; i < subitemsCount; i++) {
  12994. incHex(end, dataSize);
  12995. if (!sequence) {
  12996. stream.readHexNumber(start, dataSize);
  12997. addHex(start, end, dataSize);
  12998. } else {
  12999. start.set(end);
  13000. }
  13001. stream.readHexNumber(end, dataSize);
  13002. addHex(end, start, dataSize);
  13003. code = stream.readNumber();
  13004. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  13005. code);
  13006. }
  13007. break;
  13008. case 4: // bfchar
  13009. stream.readHex(char, ucs2DataSize);
  13010. stream.readHex(charCode, dataSize);
  13011. cMap.mapOne(hexToInt(char, ucs2DataSize),
  13012. hexToStr(charCode, dataSize));
  13013. for (i = 1; i < subitemsCount; i++) {
  13014. incHex(char, ucs2DataSize);
  13015. if (!sequence) {
  13016. stream.readHexNumber(tmp, ucs2DataSize);
  13017. addHex(char, tmp, ucs2DataSize);
  13018. }
  13019. incHex(charCode, dataSize);
  13020. stream.readHexSigned(tmp, dataSize);
  13021. addHex(charCode, tmp, dataSize);
  13022. cMap.mapOne(hexToInt(char, ucs2DataSize),
  13023. hexToStr(charCode, dataSize));
  13024. }
  13025. break;
  13026. case 5: // bfrange
  13027. stream.readHex(start, ucs2DataSize);
  13028. stream.readHexNumber(end, ucs2DataSize);
  13029. addHex(end, start, ucs2DataSize);
  13030. stream.readHex(charCode, dataSize);
  13031. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  13032. hexToInt(end, ucs2DataSize),
  13033. hexToStr(charCode, dataSize));
  13034. for (i = 1; i < subitemsCount; i++) {
  13035. incHex(end, ucs2DataSize);
  13036. if (!sequence) {
  13037. stream.readHexNumber(start, ucs2DataSize);
  13038. addHex(start, end, ucs2DataSize);
  13039. } else {
  13040. start.set(end);
  13041. }
  13042. stream.readHexNumber(end, ucs2DataSize);
  13043. addHex(end, start, ucs2DataSize);
  13044. stream.readHex(charCode, dataSize);
  13045. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  13046. hexToInt(end, ucs2DataSize),
  13047. hexToStr(charCode, dataSize));
  13048. }
  13049. break;
  13050. default:
  13051. error('Unknown type: ' + type);
  13052. break;
  13053. }
  13054. }
  13055. if (useCMap) {
  13056. extend(useCMap);
  13057. }
  13058. return cMap;
  13059. }
  13060. function BinaryCMapReader() {}
  13061. BinaryCMapReader.prototype = {
  13062. read: processBinaryCMap
  13063. };
  13064. return BinaryCMapReader;
  13065. })();
  13066. var CMapFactory = (function CMapFactoryClosure() {
  13067. function strToInt(str) {
  13068. var a = 0;
  13069. for (var i = 0; i < str.length; i++) {
  13070. a = (a << 8) | str.charCodeAt(i);
  13071. }
  13072. return a >>> 0;
  13073. }
  13074. function expectString(obj) {
  13075. if (!isString(obj)) {
  13076. error('Malformed CMap: expected string.');
  13077. }
  13078. }
  13079. function expectInt(obj) {
  13080. if (!isInt(obj)) {
  13081. error('Malformed CMap: expected int.');
  13082. }
  13083. }
  13084. function parseBfChar(cMap, lexer) {
  13085. while (true) {
  13086. var obj = lexer.getObj();
  13087. if (isEOF(obj)) {
  13088. break;
  13089. }
  13090. if (isCmd(obj, 'endbfchar')) {
  13091. return;
  13092. }
  13093. expectString(obj);
  13094. var src = strToInt(obj);
  13095. obj = lexer.getObj();
  13096. // TODO are /dstName used?
  13097. expectString(obj);
  13098. var dst = obj;
  13099. cMap.mapOne(src, dst);
  13100. }
  13101. }
  13102. function parseBfRange(cMap, lexer) {
  13103. while (true) {
  13104. var obj = lexer.getObj();
  13105. if (isEOF(obj)) {
  13106. break;
  13107. }
  13108. if (isCmd(obj, 'endbfrange')) {
  13109. return;
  13110. }
  13111. expectString(obj);
  13112. var low = strToInt(obj);
  13113. obj = lexer.getObj();
  13114. expectString(obj);
  13115. var high = strToInt(obj);
  13116. obj = lexer.getObj();
  13117. if (isInt(obj) || isString(obj)) {
  13118. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  13119. cMap.mapBfRange(low, high, dstLow);
  13120. } else if (isCmd(obj, '[')) {
  13121. obj = lexer.getObj();
  13122. var array = [];
  13123. while (!isCmd(obj, ']') && !isEOF(obj)) {
  13124. array.push(obj);
  13125. obj = lexer.getObj();
  13126. }
  13127. cMap.mapBfRangeToArray(low, high, array);
  13128. } else {
  13129. break;
  13130. }
  13131. }
  13132. error('Invalid bf range.');
  13133. }
  13134. function parseCidChar(cMap, lexer) {
  13135. while (true) {
  13136. var obj = lexer.getObj();
  13137. if (isEOF(obj)) {
  13138. break;
  13139. }
  13140. if (isCmd(obj, 'endcidchar')) {
  13141. return;
  13142. }
  13143. expectString(obj);
  13144. var src = strToInt(obj);
  13145. obj = lexer.getObj();
  13146. expectInt(obj);
  13147. var dst = obj;
  13148. cMap.mapOne(src, dst);
  13149. }
  13150. }
  13151. function parseCidRange(cMap, lexer) {
  13152. while (true) {
  13153. var obj = lexer.getObj();
  13154. if (isEOF(obj)) {
  13155. break;
  13156. }
  13157. if (isCmd(obj, 'endcidrange')) {
  13158. return;
  13159. }
  13160. expectString(obj);
  13161. var low = strToInt(obj);
  13162. obj = lexer.getObj();
  13163. expectString(obj);
  13164. var high = strToInt(obj);
  13165. obj = lexer.getObj();
  13166. expectInt(obj);
  13167. var dstLow = obj;
  13168. cMap.mapCidRange(low, high, dstLow);
  13169. }
  13170. }
  13171. function parseCodespaceRange(cMap, lexer) {
  13172. while (true) {
  13173. var obj = lexer.getObj();
  13174. if (isEOF(obj)) {
  13175. break;
  13176. }
  13177. if (isCmd(obj, 'endcodespacerange')) {
  13178. return;
  13179. }
  13180. if (!isString(obj)) {
  13181. break;
  13182. }
  13183. var low = strToInt(obj);
  13184. obj = lexer.getObj();
  13185. if (!isString(obj)) {
  13186. break;
  13187. }
  13188. var high = strToInt(obj);
  13189. cMap.addCodespaceRange(obj.length, low, high);
  13190. }
  13191. error('Invalid codespace range.');
  13192. }
  13193. function parseWMode(cMap, lexer) {
  13194. var obj = lexer.getObj();
  13195. if (isInt(obj)) {
  13196. cMap.vertical = !!obj;
  13197. }
  13198. }
  13199. function parseCMapName(cMap, lexer) {
  13200. var obj = lexer.getObj();
  13201. if (isName(obj) && isString(obj.name)) {
  13202. cMap.name = obj.name;
  13203. }
  13204. }
  13205. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  13206. var previous;
  13207. var embededUseCMap;
  13208. objLoop: while (true) {
  13209. var obj = lexer.getObj();
  13210. if (isEOF(obj)) {
  13211. break;
  13212. } else if (isName(obj)) {
  13213. if (obj.name === 'WMode') {
  13214. parseWMode(cMap, lexer);
  13215. } else if (obj.name === 'CMapName') {
  13216. parseCMapName(cMap, lexer);
  13217. }
  13218. previous = obj;
  13219. } else if (isCmd(obj)) {
  13220. switch (obj.cmd) {
  13221. case 'endcmap':
  13222. break objLoop;
  13223. case 'usecmap':
  13224. if (isName(previous)) {
  13225. embededUseCMap = previous.name;
  13226. }
  13227. break;
  13228. case 'begincodespacerange':
  13229. parseCodespaceRange(cMap, lexer);
  13230. break;
  13231. case 'beginbfchar':
  13232. parseBfChar(cMap, lexer);
  13233. break;
  13234. case 'begincidchar':
  13235. parseCidChar(cMap, lexer);
  13236. break;
  13237. case 'beginbfrange':
  13238. parseBfRange(cMap, lexer);
  13239. break;
  13240. case 'begincidrange':
  13241. parseCidRange(cMap, lexer);
  13242. break;
  13243. }
  13244. }
  13245. }
  13246. if (!useCMap && embededUseCMap) {
  13247. // Load the usecmap definition from the file only if there wasn't one
  13248. // specified.
  13249. useCMap = embededUseCMap;
  13250. }
  13251. if (useCMap) {
  13252. extendCMap(cMap, builtInCMapParams, useCMap);
  13253. }
  13254. }
  13255. function extendCMap(cMap, builtInCMapParams, useCMap) {
  13256. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  13257. // If there aren't any code space ranges defined clone all the parent ones
  13258. // into this cMap.
  13259. if (cMap.numCodespaceRanges === 0) {
  13260. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  13261. for (var i = 0; i < useCodespaceRanges.length; i++) {
  13262. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  13263. }
  13264. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  13265. }
  13266. // Merge the map into the current one, making sure not to override
  13267. // any previously defined entries.
  13268. cMap.useCMap.forEach(function(key, value) {
  13269. if (!cMap.contains(key)) {
  13270. cMap.mapOne(key, cMap.useCMap.lookup(key));
  13271. }
  13272. });
  13273. }
  13274. function parseBinaryCMap(name, builtInCMapParams) {
  13275. var url = builtInCMapParams.url + name + '.bcmap';
  13276. var cMap = new CMap(true);
  13277. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  13278. extendCMap(cMap, builtInCMapParams, useCMap);
  13279. });
  13280. return cMap;
  13281. }
  13282. function createBuiltInCMap(name, builtInCMapParams) {
  13283. if (name === 'Identity-H') {
  13284. return new IdentityCMap(false, 2);
  13285. } else if (name === 'Identity-V') {
  13286. return new IdentityCMap(true, 2);
  13287. }
  13288. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  13289. error('Unknown cMap name: ' + name);
  13290. }
  13291. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  13292. if (builtInCMapParams.packed) {
  13293. return parseBinaryCMap(name, builtInCMapParams);
  13294. }
  13295. var request = new XMLHttpRequest();
  13296. var url = builtInCMapParams.url + name;
  13297. request.open('GET', url, false);
  13298. request.send(null);
  13299. if (!request.responseText) {
  13300. error('Unable to get cMap at: ' + url);
  13301. }
  13302. var cMap = new CMap(true);
  13303. var lexer = new Lexer(new StringStream(request.responseText));
  13304. parseCMap(cMap, lexer, builtInCMapParams, null);
  13305. return cMap;
  13306. }
  13307. return {
  13308. create: function (encoding, builtInCMapParams, useCMap) {
  13309. if (isName(encoding)) {
  13310. return createBuiltInCMap(encoding.name, builtInCMapParams);
  13311. } else if (isStream(encoding)) {
  13312. var cMap = new CMap();
  13313. var lexer = new Lexer(encoding);
  13314. try {
  13315. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  13316. } catch (e) {
  13317. warn('Invalid CMap data. ' + e);
  13318. }
  13319. if (cMap.isIdentityCMap) {
  13320. return createBuiltInCMap(cMap.name, builtInCMapParams);
  13321. }
  13322. return cMap;
  13323. }
  13324. error('Encoding required.');
  13325. }
  13326. };
  13327. })();
  13328. // Unicode Private Use Area
  13329. var PRIVATE_USE_OFFSET_START = 0xE000;
  13330. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  13331. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  13332. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  13333. // except for Type 3 fonts
  13334. var PDF_GLYPH_SPACE_UNITS = 1000;
  13335. // Hinting is currently disabled due to unknown problems on windows
  13336. // in tracemonkey and various other pdfs with type1 fonts.
  13337. var HINTING_ENABLED = false;
  13338. // Accented charactars are not displayed properly on windows, using this flag
  13339. // to control analysis of seac charstrings.
  13340. var SEAC_ANALYSIS_ENABLED = false;
  13341. var FontFlags = {
  13342. FixedPitch: 1,
  13343. Serif: 2,
  13344. Symbolic: 4,
  13345. Script: 8,
  13346. Nonsymbolic: 32,
  13347. Italic: 64,
  13348. AllCap: 65536,
  13349. SmallCap: 131072,
  13350. ForceBold: 262144
  13351. };
  13352. var Encodings = {
  13353. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13354. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13355. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  13356. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  13357. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  13358. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  13359. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  13360. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  13361. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  13362. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  13363. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  13364. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  13365. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  13366. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  13367. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  13368. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  13369. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  13370. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  13371. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  13372. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13373. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  13374. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  13375. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  13376. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  13377. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  13378. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  13379. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  13380. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  13381. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  13382. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  13383. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  13384. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  13385. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  13386. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  13387. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  13388. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  13389. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  13390. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  13391. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  13392. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  13393. 'Ydieresissmall'],
  13394. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13395. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13396. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  13397. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  13398. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  13399. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  13400. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  13401. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  13402. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  13403. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  13404. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  13405. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  13406. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  13407. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  13408. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  13409. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  13410. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  13411. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  13412. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  13413. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  13414. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  13415. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  13416. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  13417. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13418. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13419. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13420. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13421. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13422. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13423. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13424. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13425. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13426. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13427. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13428. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13429. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13430. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13431. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13432. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13433. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13434. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13435. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13436. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13437. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13438. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13439. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13440. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13441. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13442. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13443. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13444. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13445. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13446. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13447. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13448. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13449. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13450. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13451. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13452. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13453. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13454. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13455. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13456. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13457. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13458. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13459. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13460. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13461. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13462. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13463. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13464. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13465. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13466. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13467. 'ogonek', 'caron'],
  13468. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13469. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13470. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13471. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13472. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13473. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13474. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13475. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13476. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13477. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13478. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13479. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13480. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13481. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13482. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13483. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13484. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13485. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13486. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13487. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13488. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13489. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13490. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13491. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13492. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13493. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13494. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13495. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13496. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13497. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13498. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13499. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13500. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13501. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13502. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13503. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13504. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13505. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13506. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13507. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13508. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13509. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13510. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13511. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13512. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13513. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13514. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13515. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13516. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13517. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13518. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13519. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13520. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13521. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13522. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13523. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13524. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13525. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13526. 'ydieresis'],
  13527. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13528. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13529. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13530. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13531. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13532. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13533. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13534. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13535. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13536. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13537. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13538. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13539. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13540. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13541. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13542. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13543. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13544. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13545. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13546. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13547. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13548. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13549. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13550. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13551. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13552. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13553. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13554. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13555. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13556. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13557. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13558. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13559. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13560. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13561. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13562. 'bracerightbt'],
  13563. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13564. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13565. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13566. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13567. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13568. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13569. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13570. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13571. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13572. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13573. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13574. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13575. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13576. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13577. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13578. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13579. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13580. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13581. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13582. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13583. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13584. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13585. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13586. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13587. };
  13588. /**
  13589. * Hold a map of decoded fonts and of the standard fourteen Type1
  13590. * fonts and their acronyms.
  13591. */
  13592. var stdFontMap = {
  13593. 'ArialNarrow': 'Helvetica',
  13594. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13595. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13596. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13597. 'ArialBlack': 'Helvetica',
  13598. 'ArialBlack-Bold': 'Helvetica-Bold',
  13599. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13600. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13601. 'Arial': 'Helvetica',
  13602. 'Arial-Bold': 'Helvetica-Bold',
  13603. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13604. 'Arial-Italic': 'Helvetica-Oblique',
  13605. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13606. 'Arial-BoldMT': 'Helvetica-Bold',
  13607. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13608. 'ArialMT': 'Helvetica',
  13609. 'Courier-Bold': 'Courier-Bold',
  13610. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13611. 'Courier-Italic': 'Courier-Oblique',
  13612. 'CourierNew': 'Courier',
  13613. 'CourierNew-Bold': 'Courier-Bold',
  13614. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13615. 'CourierNew-Italic': 'Courier-Oblique',
  13616. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13617. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13618. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13619. 'CourierNewPSMT': 'Courier',
  13620. 'Helvetica': 'Helvetica',
  13621. 'Helvetica-Bold': 'Helvetica-Bold',
  13622. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13623. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13624. 'Helvetica-Italic': 'Helvetica-Oblique',
  13625. 'Helvetica-Oblique':'Helvetica-Oblique',
  13626. 'Symbol-Bold': 'Symbol',
  13627. 'Symbol-BoldItalic': 'Symbol',
  13628. 'Symbol-Italic': 'Symbol',
  13629. 'TimesNewRoman': 'Times-Roman',
  13630. 'TimesNewRoman-Bold': 'Times-Bold',
  13631. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13632. 'TimesNewRoman-Italic': 'Times-Italic',
  13633. 'TimesNewRomanPS': 'Times-Roman',
  13634. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13635. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13636. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13637. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13638. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13639. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13640. 'TimesNewRomanPSMT': 'Times-Roman',
  13641. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13642. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13643. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13644. };
  13645. /**
  13646. * Holds the map of the non-standard fonts that might be included as a standard
  13647. * fonts without glyph data.
  13648. */
  13649. var nonStdFontMap = {
  13650. 'CenturyGothic': 'Helvetica',
  13651. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13652. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13653. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13654. 'ComicSansMS': 'Comic Sans MS',
  13655. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13656. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13657. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13658. 'LucidaConsole': 'Courier',
  13659. 'LucidaConsole-Bold': 'Courier-Bold',
  13660. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13661. 'LucidaConsole-Italic': 'Courier-Oblique',
  13662. 'MS-Gothic': 'MS Gothic',
  13663. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13664. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13665. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13666. 'MS-Mincho': 'MS Mincho',
  13667. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13668. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13669. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13670. 'MS-PGothic': 'MS PGothic',
  13671. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13672. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13673. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13674. 'MS-PMincho': 'MS PMincho',
  13675. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13676. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13677. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13678. 'Wingdings': 'ZapfDingbats'
  13679. };
  13680. var serifFonts = {
  13681. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13682. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13683. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13684. 'Arno': true, 'Aster': true, 'Aurora': true,
  13685. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13686. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13687. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13688. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13689. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13690. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13691. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13692. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13693. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13694. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13695. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13696. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13697. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13698. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13699. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13700. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13701. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13702. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13703. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13704. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13705. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13706. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13707. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13708. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13709. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13710. 'Miller': true, 'Minion': true, 'Modern': true,
  13711. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13712. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13713. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13714. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13715. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13716. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13717. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13718. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13719. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13720. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13721. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13722. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13723. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13724. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13725. };
  13726. var symbolsFonts = {
  13727. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13728. };
  13729. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13730. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13731. // glyphs, but common for some set of the standard fonts.
  13732. var GlyphMapForStandardFonts = {
  13733. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13734. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13735. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13736. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13737. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13738. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13739. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13740. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13741. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13742. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13743. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13744. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13745. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13746. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13747. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13748. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13749. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13750. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13751. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13752. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13753. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13754. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13755. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13756. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13757. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13758. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13759. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13760. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13761. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13762. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13763. '298': 380, '305': 963,
  13764. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13765. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13766. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13767. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13768. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13769. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13770. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13771. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13772. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13773. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13774. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13775. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13776. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13777. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13778. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13779. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13780. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13781. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13782. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13783. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13784. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13785. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13786. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13787. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13788. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13789. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13790. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13791. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13792. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13793. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13794. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13795. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13796. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13797. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13798. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13799. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13800. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13801. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13802. };
  13803. // The glyph map for ArialBlack differs slightly from the glyph map used for
  13804. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  13805. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  13806. var SupplementalGlyphMapForArialBlack = {
  13807. '227': 322, '264': 261, '291': 346,
  13808. };
  13809. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13810. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13811. // to the similar equivalents in the normal characters range.
  13812. var SpecialPUASymbols = {
  13813. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13814. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13815. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13816. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13817. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13818. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13819. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13820. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13821. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13822. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13823. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13824. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13825. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13826. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13827. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13828. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13829. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13830. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13831. '63723': 0x239B, // parenlefttp (0xF8EB)
  13832. '63724': 0x239C, // parenleftex (0xF8EC)
  13833. '63725': 0x239D, // parenleftbt (0xF8ED)
  13834. '63734': 0x239E, // parenrighttp (0xF8F6)
  13835. '63735': 0x239F, // parenrightex (0xF8F7)
  13836. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13837. };
  13838. function mapSpecialUnicodeValues(code) {
  13839. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13840. return 0;
  13841. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13842. return (SpecialPUASymbols[code] || code);
  13843. }
  13844. return code;
  13845. }
  13846. var UnicodeRanges = [
  13847. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13848. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13849. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13850. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13851. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13852. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13853. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13854. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13855. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13856. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13857. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13858. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13859. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13860. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13861. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13862. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13863. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13864. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13865. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13866. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13867. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13868. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13869. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13870. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13871. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13872. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13873. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13874. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13875. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13876. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13877. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13878. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13879. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13880. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13881. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13882. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13883. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13884. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13885. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13886. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13887. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13888. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13889. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13890. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13891. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13892. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13893. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13894. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13895. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13896. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13897. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13898. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13899. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13900. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13901. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13902. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13903. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13904. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13905. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13906. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13907. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13908. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13909. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13910. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13911. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13912. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13913. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13914. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13915. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13916. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13917. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13918. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13919. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13920. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13921. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13922. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13923. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13924. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13925. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13926. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13927. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13928. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13929. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13930. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13931. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13932. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13933. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13934. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13935. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13936. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13937. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13938. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13939. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13940. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13941. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13942. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13943. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13944. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13945. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13946. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13947. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13948. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13949. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13950. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13951. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13952. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13953. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13954. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13955. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13956. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13957. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13958. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13959. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13960. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13961. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13962. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13963. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13964. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13965. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13966. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13967. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13968. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13969. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13970. ];
  13971. var MacStandardGlyphOrdering = [
  13972. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13973. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13974. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13975. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13976. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13977. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13978. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13979. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13980. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13981. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13982. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13983. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13984. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13985. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13986. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13987. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13988. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13989. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13990. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13991. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13992. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13993. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13994. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13995. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13996. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13997. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13998. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13999. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  14000. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  14001. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  14002. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  14003. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  14004. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  14005. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  14006. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  14007. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  14008. function getUnicodeRangeFor(value) {
  14009. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  14010. var range = UnicodeRanges[i];
  14011. if (value >= range.begin && value < range.end) {
  14012. return i;
  14013. }
  14014. }
  14015. return -1;
  14016. }
  14017. function isRTLRangeFor(value) {
  14018. var range = UnicodeRanges[13];
  14019. if (value >= range.begin && value < range.end) {
  14020. return true;
  14021. }
  14022. range = UnicodeRanges[11];
  14023. if (value >= range.begin && value < range.end) {
  14024. return true;
  14025. }
  14026. return false;
  14027. }
  14028. // The normalization table is obtained by filtering the Unicode characters
  14029. // database with <compat> entries.
  14030. var NormalizedUnicodes = {
  14031. '\u00A8': '\u0020\u0308',
  14032. '\u00AF': '\u0020\u0304',
  14033. '\u00B4': '\u0020\u0301',
  14034. '\u00B5': '\u03BC',
  14035. '\u00B8': '\u0020\u0327',
  14036. '\u0132': '\u0049\u004A',
  14037. '\u0133': '\u0069\u006A',
  14038. '\u013F': '\u004C\u00B7',
  14039. '\u0140': '\u006C\u00B7',
  14040. '\u0149': '\u02BC\u006E',
  14041. '\u017F': '\u0073',
  14042. '\u01C4': '\u0044\u017D',
  14043. '\u01C5': '\u0044\u017E',
  14044. '\u01C6': '\u0064\u017E',
  14045. '\u01C7': '\u004C\u004A',
  14046. '\u01C8': '\u004C\u006A',
  14047. '\u01C9': '\u006C\u006A',
  14048. '\u01CA': '\u004E\u004A',
  14049. '\u01CB': '\u004E\u006A',
  14050. '\u01CC': '\u006E\u006A',
  14051. '\u01F1': '\u0044\u005A',
  14052. '\u01F2': '\u0044\u007A',
  14053. '\u01F3': '\u0064\u007A',
  14054. '\u02D8': '\u0020\u0306',
  14055. '\u02D9': '\u0020\u0307',
  14056. '\u02DA': '\u0020\u030A',
  14057. '\u02DB': '\u0020\u0328',
  14058. '\u02DC': '\u0020\u0303',
  14059. '\u02DD': '\u0020\u030B',
  14060. '\u037A': '\u0020\u0345',
  14061. '\u0384': '\u0020\u0301',
  14062. '\u03D0': '\u03B2',
  14063. '\u03D1': '\u03B8',
  14064. '\u03D2': '\u03A5',
  14065. '\u03D5': '\u03C6',
  14066. '\u03D6': '\u03C0',
  14067. '\u03F0': '\u03BA',
  14068. '\u03F1': '\u03C1',
  14069. '\u03F2': '\u03C2',
  14070. '\u03F4': '\u0398',
  14071. '\u03F5': '\u03B5',
  14072. '\u03F9': '\u03A3',
  14073. '\u0587': '\u0565\u0582',
  14074. '\u0675': '\u0627\u0674',
  14075. '\u0676': '\u0648\u0674',
  14076. '\u0677': '\u06C7\u0674',
  14077. '\u0678': '\u064A\u0674',
  14078. '\u0E33': '\u0E4D\u0E32',
  14079. '\u0EB3': '\u0ECD\u0EB2',
  14080. '\u0EDC': '\u0EAB\u0E99',
  14081. '\u0EDD': '\u0EAB\u0EA1',
  14082. '\u0F77': '\u0FB2\u0F81',
  14083. '\u0F79': '\u0FB3\u0F81',
  14084. '\u1E9A': '\u0061\u02BE',
  14085. '\u1FBD': '\u0020\u0313',
  14086. '\u1FBF': '\u0020\u0313',
  14087. '\u1FC0': '\u0020\u0342',
  14088. '\u1FFE': '\u0020\u0314',
  14089. '\u2002': '\u0020',
  14090. '\u2003': '\u0020',
  14091. '\u2004': '\u0020',
  14092. '\u2005': '\u0020',
  14093. '\u2006': '\u0020',
  14094. '\u2008': '\u0020',
  14095. '\u2009': '\u0020',
  14096. '\u200A': '\u0020',
  14097. '\u2017': '\u0020\u0333',
  14098. '\u2024': '\u002E',
  14099. '\u2025': '\u002E\u002E',
  14100. '\u2026': '\u002E\u002E\u002E',
  14101. '\u2033': '\u2032\u2032',
  14102. '\u2034': '\u2032\u2032\u2032',
  14103. '\u2036': '\u2035\u2035',
  14104. '\u2037': '\u2035\u2035\u2035',
  14105. '\u203C': '\u0021\u0021',
  14106. '\u203E': '\u0020\u0305',
  14107. '\u2047': '\u003F\u003F',
  14108. '\u2048': '\u003F\u0021',
  14109. '\u2049': '\u0021\u003F',
  14110. '\u2057': '\u2032\u2032\u2032\u2032',
  14111. '\u205F': '\u0020',
  14112. '\u20A8': '\u0052\u0073',
  14113. '\u2100': '\u0061\u002F\u0063',
  14114. '\u2101': '\u0061\u002F\u0073',
  14115. '\u2103': '\u00B0\u0043',
  14116. '\u2105': '\u0063\u002F\u006F',
  14117. '\u2106': '\u0063\u002F\u0075',
  14118. '\u2107': '\u0190',
  14119. '\u2109': '\u00B0\u0046',
  14120. '\u2116': '\u004E\u006F',
  14121. '\u2121': '\u0054\u0045\u004C',
  14122. '\u2135': '\u05D0',
  14123. '\u2136': '\u05D1',
  14124. '\u2137': '\u05D2',
  14125. '\u2138': '\u05D3',
  14126. '\u213B': '\u0046\u0041\u0058',
  14127. '\u2160': '\u0049',
  14128. '\u2161': '\u0049\u0049',
  14129. '\u2162': '\u0049\u0049\u0049',
  14130. '\u2163': '\u0049\u0056',
  14131. '\u2164': '\u0056',
  14132. '\u2165': '\u0056\u0049',
  14133. '\u2166': '\u0056\u0049\u0049',
  14134. '\u2167': '\u0056\u0049\u0049\u0049',
  14135. '\u2168': '\u0049\u0058',
  14136. '\u2169': '\u0058',
  14137. '\u216A': '\u0058\u0049',
  14138. '\u216B': '\u0058\u0049\u0049',
  14139. '\u216C': '\u004C',
  14140. '\u216D': '\u0043',
  14141. '\u216E': '\u0044',
  14142. '\u216F': '\u004D',
  14143. '\u2170': '\u0069',
  14144. '\u2171': '\u0069\u0069',
  14145. '\u2172': '\u0069\u0069\u0069',
  14146. '\u2173': '\u0069\u0076',
  14147. '\u2174': '\u0076',
  14148. '\u2175': '\u0076\u0069',
  14149. '\u2176': '\u0076\u0069\u0069',
  14150. '\u2177': '\u0076\u0069\u0069\u0069',
  14151. '\u2178': '\u0069\u0078',
  14152. '\u2179': '\u0078',
  14153. '\u217A': '\u0078\u0069',
  14154. '\u217B': '\u0078\u0069\u0069',
  14155. '\u217C': '\u006C',
  14156. '\u217D': '\u0063',
  14157. '\u217E': '\u0064',
  14158. '\u217F': '\u006D',
  14159. '\u222C': '\u222B\u222B',
  14160. '\u222D': '\u222B\u222B\u222B',
  14161. '\u222F': '\u222E\u222E',
  14162. '\u2230': '\u222E\u222E\u222E',
  14163. '\u2474': '\u0028\u0031\u0029',
  14164. '\u2475': '\u0028\u0032\u0029',
  14165. '\u2476': '\u0028\u0033\u0029',
  14166. '\u2477': '\u0028\u0034\u0029',
  14167. '\u2478': '\u0028\u0035\u0029',
  14168. '\u2479': '\u0028\u0036\u0029',
  14169. '\u247A': '\u0028\u0037\u0029',
  14170. '\u247B': '\u0028\u0038\u0029',
  14171. '\u247C': '\u0028\u0039\u0029',
  14172. '\u247D': '\u0028\u0031\u0030\u0029',
  14173. '\u247E': '\u0028\u0031\u0031\u0029',
  14174. '\u247F': '\u0028\u0031\u0032\u0029',
  14175. '\u2480': '\u0028\u0031\u0033\u0029',
  14176. '\u2481': '\u0028\u0031\u0034\u0029',
  14177. '\u2482': '\u0028\u0031\u0035\u0029',
  14178. '\u2483': '\u0028\u0031\u0036\u0029',
  14179. '\u2484': '\u0028\u0031\u0037\u0029',
  14180. '\u2485': '\u0028\u0031\u0038\u0029',
  14181. '\u2486': '\u0028\u0031\u0039\u0029',
  14182. '\u2487': '\u0028\u0032\u0030\u0029',
  14183. '\u2488': '\u0031\u002E',
  14184. '\u2489': '\u0032\u002E',
  14185. '\u248A': '\u0033\u002E',
  14186. '\u248B': '\u0034\u002E',
  14187. '\u248C': '\u0035\u002E',
  14188. '\u248D': '\u0036\u002E',
  14189. '\u248E': '\u0037\u002E',
  14190. '\u248F': '\u0038\u002E',
  14191. '\u2490': '\u0039\u002E',
  14192. '\u2491': '\u0031\u0030\u002E',
  14193. '\u2492': '\u0031\u0031\u002E',
  14194. '\u2493': '\u0031\u0032\u002E',
  14195. '\u2494': '\u0031\u0033\u002E',
  14196. '\u2495': '\u0031\u0034\u002E',
  14197. '\u2496': '\u0031\u0035\u002E',
  14198. '\u2497': '\u0031\u0036\u002E',
  14199. '\u2498': '\u0031\u0037\u002E',
  14200. '\u2499': '\u0031\u0038\u002E',
  14201. '\u249A': '\u0031\u0039\u002E',
  14202. '\u249B': '\u0032\u0030\u002E',
  14203. '\u249C': '\u0028\u0061\u0029',
  14204. '\u249D': '\u0028\u0062\u0029',
  14205. '\u249E': '\u0028\u0063\u0029',
  14206. '\u249F': '\u0028\u0064\u0029',
  14207. '\u24A0': '\u0028\u0065\u0029',
  14208. '\u24A1': '\u0028\u0066\u0029',
  14209. '\u24A2': '\u0028\u0067\u0029',
  14210. '\u24A3': '\u0028\u0068\u0029',
  14211. '\u24A4': '\u0028\u0069\u0029',
  14212. '\u24A5': '\u0028\u006A\u0029',
  14213. '\u24A6': '\u0028\u006B\u0029',
  14214. '\u24A7': '\u0028\u006C\u0029',
  14215. '\u24A8': '\u0028\u006D\u0029',
  14216. '\u24A9': '\u0028\u006E\u0029',
  14217. '\u24AA': '\u0028\u006F\u0029',
  14218. '\u24AB': '\u0028\u0070\u0029',
  14219. '\u24AC': '\u0028\u0071\u0029',
  14220. '\u24AD': '\u0028\u0072\u0029',
  14221. '\u24AE': '\u0028\u0073\u0029',
  14222. '\u24AF': '\u0028\u0074\u0029',
  14223. '\u24B0': '\u0028\u0075\u0029',
  14224. '\u24B1': '\u0028\u0076\u0029',
  14225. '\u24B2': '\u0028\u0077\u0029',
  14226. '\u24B3': '\u0028\u0078\u0029',
  14227. '\u24B4': '\u0028\u0079\u0029',
  14228. '\u24B5': '\u0028\u007A\u0029',
  14229. '\u2A0C': '\u222B\u222B\u222B\u222B',
  14230. '\u2A74': '\u003A\u003A\u003D',
  14231. '\u2A75': '\u003D\u003D',
  14232. '\u2A76': '\u003D\u003D\u003D',
  14233. '\u2E9F': '\u6BCD',
  14234. '\u2EF3': '\u9F9F',
  14235. '\u2F00': '\u4E00',
  14236. '\u2F01': '\u4E28',
  14237. '\u2F02': '\u4E36',
  14238. '\u2F03': '\u4E3F',
  14239. '\u2F04': '\u4E59',
  14240. '\u2F05': '\u4E85',
  14241. '\u2F06': '\u4E8C',
  14242. '\u2F07': '\u4EA0',
  14243. '\u2F08': '\u4EBA',
  14244. '\u2F09': '\u513F',
  14245. '\u2F0A': '\u5165',
  14246. '\u2F0B': '\u516B',
  14247. '\u2F0C': '\u5182',
  14248. '\u2F0D': '\u5196',
  14249. '\u2F0E': '\u51AB',
  14250. '\u2F0F': '\u51E0',
  14251. '\u2F10': '\u51F5',
  14252. '\u2F11': '\u5200',
  14253. '\u2F12': '\u529B',
  14254. '\u2F13': '\u52F9',
  14255. '\u2F14': '\u5315',
  14256. '\u2F15': '\u531A',
  14257. '\u2F16': '\u5338',
  14258. '\u2F17': '\u5341',
  14259. '\u2F18': '\u535C',
  14260. '\u2F19': '\u5369',
  14261. '\u2F1A': '\u5382',
  14262. '\u2F1B': '\u53B6',
  14263. '\u2F1C': '\u53C8',
  14264. '\u2F1D': '\u53E3',
  14265. '\u2F1E': '\u56D7',
  14266. '\u2F1F': '\u571F',
  14267. '\u2F20': '\u58EB',
  14268. '\u2F21': '\u5902',
  14269. '\u2F22': '\u590A',
  14270. '\u2F23': '\u5915',
  14271. '\u2F24': '\u5927',
  14272. '\u2F25': '\u5973',
  14273. '\u2F26': '\u5B50',
  14274. '\u2F27': '\u5B80',
  14275. '\u2F28': '\u5BF8',
  14276. '\u2F29': '\u5C0F',
  14277. '\u2F2A': '\u5C22',
  14278. '\u2F2B': '\u5C38',
  14279. '\u2F2C': '\u5C6E',
  14280. '\u2F2D': '\u5C71',
  14281. '\u2F2E': '\u5DDB',
  14282. '\u2F2F': '\u5DE5',
  14283. '\u2F30': '\u5DF1',
  14284. '\u2F31': '\u5DFE',
  14285. '\u2F32': '\u5E72',
  14286. '\u2F33': '\u5E7A',
  14287. '\u2F34': '\u5E7F',
  14288. '\u2F35': '\u5EF4',
  14289. '\u2F36': '\u5EFE',
  14290. '\u2F37': '\u5F0B',
  14291. '\u2F38': '\u5F13',
  14292. '\u2F39': '\u5F50',
  14293. '\u2F3A': '\u5F61',
  14294. '\u2F3B': '\u5F73',
  14295. '\u2F3C': '\u5FC3',
  14296. '\u2F3D': '\u6208',
  14297. '\u2F3E': '\u6236',
  14298. '\u2F3F': '\u624B',
  14299. '\u2F40': '\u652F',
  14300. '\u2F41': '\u6534',
  14301. '\u2F42': '\u6587',
  14302. '\u2F43': '\u6597',
  14303. '\u2F44': '\u65A4',
  14304. '\u2F45': '\u65B9',
  14305. '\u2F46': '\u65E0',
  14306. '\u2F47': '\u65E5',
  14307. '\u2F48': '\u66F0',
  14308. '\u2F49': '\u6708',
  14309. '\u2F4A': '\u6728',
  14310. '\u2F4B': '\u6B20',
  14311. '\u2F4C': '\u6B62',
  14312. '\u2F4D': '\u6B79',
  14313. '\u2F4E': '\u6BB3',
  14314. '\u2F4F': '\u6BCB',
  14315. '\u2F50': '\u6BD4',
  14316. '\u2F51': '\u6BDB',
  14317. '\u2F52': '\u6C0F',
  14318. '\u2F53': '\u6C14',
  14319. '\u2F54': '\u6C34',
  14320. '\u2F55': '\u706B',
  14321. '\u2F56': '\u722A',
  14322. '\u2F57': '\u7236',
  14323. '\u2F58': '\u723B',
  14324. '\u2F59': '\u723F',
  14325. '\u2F5A': '\u7247',
  14326. '\u2F5B': '\u7259',
  14327. '\u2F5C': '\u725B',
  14328. '\u2F5D': '\u72AC',
  14329. '\u2F5E': '\u7384',
  14330. '\u2F5F': '\u7389',
  14331. '\u2F60': '\u74DC',
  14332. '\u2F61': '\u74E6',
  14333. '\u2F62': '\u7518',
  14334. '\u2F63': '\u751F',
  14335. '\u2F64': '\u7528',
  14336. '\u2F65': '\u7530',
  14337. '\u2F66': '\u758B',
  14338. '\u2F67': '\u7592',
  14339. '\u2F68': '\u7676',
  14340. '\u2F69': '\u767D',
  14341. '\u2F6A': '\u76AE',
  14342. '\u2F6B': '\u76BF',
  14343. '\u2F6C': '\u76EE',
  14344. '\u2F6D': '\u77DB',
  14345. '\u2F6E': '\u77E2',
  14346. '\u2F6F': '\u77F3',
  14347. '\u2F70': '\u793A',
  14348. '\u2F71': '\u79B8',
  14349. '\u2F72': '\u79BE',
  14350. '\u2F73': '\u7A74',
  14351. '\u2F74': '\u7ACB',
  14352. '\u2F75': '\u7AF9',
  14353. '\u2F76': '\u7C73',
  14354. '\u2F77': '\u7CF8',
  14355. '\u2F78': '\u7F36',
  14356. '\u2F79': '\u7F51',
  14357. '\u2F7A': '\u7F8A',
  14358. '\u2F7B': '\u7FBD',
  14359. '\u2F7C': '\u8001',
  14360. '\u2F7D': '\u800C',
  14361. '\u2F7E': '\u8012',
  14362. '\u2F7F': '\u8033',
  14363. '\u2F80': '\u807F',
  14364. '\u2F81': '\u8089',
  14365. '\u2F82': '\u81E3',
  14366. '\u2F83': '\u81EA',
  14367. '\u2F84': '\u81F3',
  14368. '\u2F85': '\u81FC',
  14369. '\u2F86': '\u820C',
  14370. '\u2F87': '\u821B',
  14371. '\u2F88': '\u821F',
  14372. '\u2F89': '\u826E',
  14373. '\u2F8A': '\u8272',
  14374. '\u2F8B': '\u8278',
  14375. '\u2F8C': '\u864D',
  14376. '\u2F8D': '\u866B',
  14377. '\u2F8E': '\u8840',
  14378. '\u2F8F': '\u884C',
  14379. '\u2F90': '\u8863',
  14380. '\u2F91': '\u897E',
  14381. '\u2F92': '\u898B',
  14382. '\u2F93': '\u89D2',
  14383. '\u2F94': '\u8A00',
  14384. '\u2F95': '\u8C37',
  14385. '\u2F96': '\u8C46',
  14386. '\u2F97': '\u8C55',
  14387. '\u2F98': '\u8C78',
  14388. '\u2F99': '\u8C9D',
  14389. '\u2F9A': '\u8D64',
  14390. '\u2F9B': '\u8D70',
  14391. '\u2F9C': '\u8DB3',
  14392. '\u2F9D': '\u8EAB',
  14393. '\u2F9E': '\u8ECA',
  14394. '\u2F9F': '\u8F9B',
  14395. '\u2FA0': '\u8FB0',
  14396. '\u2FA1': '\u8FB5',
  14397. '\u2FA2': '\u9091',
  14398. '\u2FA3': '\u9149',
  14399. '\u2FA4': '\u91C6',
  14400. '\u2FA5': '\u91CC',
  14401. '\u2FA6': '\u91D1',
  14402. '\u2FA7': '\u9577',
  14403. '\u2FA8': '\u9580',
  14404. '\u2FA9': '\u961C',
  14405. '\u2FAA': '\u96B6',
  14406. '\u2FAB': '\u96B9',
  14407. '\u2FAC': '\u96E8',
  14408. '\u2FAD': '\u9751',
  14409. '\u2FAE': '\u975E',
  14410. '\u2FAF': '\u9762',
  14411. '\u2FB0': '\u9769',
  14412. '\u2FB1': '\u97CB',
  14413. '\u2FB2': '\u97ED',
  14414. '\u2FB3': '\u97F3',
  14415. '\u2FB4': '\u9801',
  14416. '\u2FB5': '\u98A8',
  14417. '\u2FB6': '\u98DB',
  14418. '\u2FB7': '\u98DF',
  14419. '\u2FB8': '\u9996',
  14420. '\u2FB9': '\u9999',
  14421. '\u2FBA': '\u99AC',
  14422. '\u2FBB': '\u9AA8',
  14423. '\u2FBC': '\u9AD8',
  14424. '\u2FBD': '\u9ADF',
  14425. '\u2FBE': '\u9B25',
  14426. '\u2FBF': '\u9B2F',
  14427. '\u2FC0': '\u9B32',
  14428. '\u2FC1': '\u9B3C',
  14429. '\u2FC2': '\u9B5A',
  14430. '\u2FC3': '\u9CE5',
  14431. '\u2FC4': '\u9E75',
  14432. '\u2FC5': '\u9E7F',
  14433. '\u2FC6': '\u9EA5',
  14434. '\u2FC7': '\u9EBB',
  14435. '\u2FC8': '\u9EC3',
  14436. '\u2FC9': '\u9ECD',
  14437. '\u2FCA': '\u9ED1',
  14438. '\u2FCB': '\u9EF9',
  14439. '\u2FCC': '\u9EFD',
  14440. '\u2FCD': '\u9F0E',
  14441. '\u2FCE': '\u9F13',
  14442. '\u2FCF': '\u9F20',
  14443. '\u2FD0': '\u9F3B',
  14444. '\u2FD1': '\u9F4A',
  14445. '\u2FD2': '\u9F52',
  14446. '\u2FD3': '\u9F8D',
  14447. '\u2FD4': '\u9F9C',
  14448. '\u2FD5': '\u9FA0',
  14449. '\u3036': '\u3012',
  14450. '\u3038': '\u5341',
  14451. '\u3039': '\u5344',
  14452. '\u303A': '\u5345',
  14453. '\u309B': '\u0020\u3099',
  14454. '\u309C': '\u0020\u309A',
  14455. '\u3131': '\u1100',
  14456. '\u3132': '\u1101',
  14457. '\u3133': '\u11AA',
  14458. '\u3134': '\u1102',
  14459. '\u3135': '\u11AC',
  14460. '\u3136': '\u11AD',
  14461. '\u3137': '\u1103',
  14462. '\u3138': '\u1104',
  14463. '\u3139': '\u1105',
  14464. '\u313A': '\u11B0',
  14465. '\u313B': '\u11B1',
  14466. '\u313C': '\u11B2',
  14467. '\u313D': '\u11B3',
  14468. '\u313E': '\u11B4',
  14469. '\u313F': '\u11B5',
  14470. '\u3140': '\u111A',
  14471. '\u3141': '\u1106',
  14472. '\u3142': '\u1107',
  14473. '\u3143': '\u1108',
  14474. '\u3144': '\u1121',
  14475. '\u3145': '\u1109',
  14476. '\u3146': '\u110A',
  14477. '\u3147': '\u110B',
  14478. '\u3148': '\u110C',
  14479. '\u3149': '\u110D',
  14480. '\u314A': '\u110E',
  14481. '\u314B': '\u110F',
  14482. '\u314C': '\u1110',
  14483. '\u314D': '\u1111',
  14484. '\u314E': '\u1112',
  14485. '\u314F': '\u1161',
  14486. '\u3150': '\u1162',
  14487. '\u3151': '\u1163',
  14488. '\u3152': '\u1164',
  14489. '\u3153': '\u1165',
  14490. '\u3154': '\u1166',
  14491. '\u3155': '\u1167',
  14492. '\u3156': '\u1168',
  14493. '\u3157': '\u1169',
  14494. '\u3158': '\u116A',
  14495. '\u3159': '\u116B',
  14496. '\u315A': '\u116C',
  14497. '\u315B': '\u116D',
  14498. '\u315C': '\u116E',
  14499. '\u315D': '\u116F',
  14500. '\u315E': '\u1170',
  14501. '\u315F': '\u1171',
  14502. '\u3160': '\u1172',
  14503. '\u3161': '\u1173',
  14504. '\u3162': '\u1174',
  14505. '\u3163': '\u1175',
  14506. '\u3164': '\u1160',
  14507. '\u3165': '\u1114',
  14508. '\u3166': '\u1115',
  14509. '\u3167': '\u11C7',
  14510. '\u3168': '\u11C8',
  14511. '\u3169': '\u11CC',
  14512. '\u316A': '\u11CE',
  14513. '\u316B': '\u11D3',
  14514. '\u316C': '\u11D7',
  14515. '\u316D': '\u11D9',
  14516. '\u316E': '\u111C',
  14517. '\u316F': '\u11DD',
  14518. '\u3170': '\u11DF',
  14519. '\u3171': '\u111D',
  14520. '\u3172': '\u111E',
  14521. '\u3173': '\u1120',
  14522. '\u3174': '\u1122',
  14523. '\u3175': '\u1123',
  14524. '\u3176': '\u1127',
  14525. '\u3177': '\u1129',
  14526. '\u3178': '\u112B',
  14527. '\u3179': '\u112C',
  14528. '\u317A': '\u112D',
  14529. '\u317B': '\u112E',
  14530. '\u317C': '\u112F',
  14531. '\u317D': '\u1132',
  14532. '\u317E': '\u1136',
  14533. '\u317F': '\u1140',
  14534. '\u3180': '\u1147',
  14535. '\u3181': '\u114C',
  14536. '\u3182': '\u11F1',
  14537. '\u3183': '\u11F2',
  14538. '\u3184': '\u1157',
  14539. '\u3185': '\u1158',
  14540. '\u3186': '\u1159',
  14541. '\u3187': '\u1184',
  14542. '\u3188': '\u1185',
  14543. '\u3189': '\u1188',
  14544. '\u318A': '\u1191',
  14545. '\u318B': '\u1192',
  14546. '\u318C': '\u1194',
  14547. '\u318D': '\u119E',
  14548. '\u318E': '\u11A1',
  14549. '\u3200': '\u0028\u1100\u0029',
  14550. '\u3201': '\u0028\u1102\u0029',
  14551. '\u3202': '\u0028\u1103\u0029',
  14552. '\u3203': '\u0028\u1105\u0029',
  14553. '\u3204': '\u0028\u1106\u0029',
  14554. '\u3205': '\u0028\u1107\u0029',
  14555. '\u3206': '\u0028\u1109\u0029',
  14556. '\u3207': '\u0028\u110B\u0029',
  14557. '\u3208': '\u0028\u110C\u0029',
  14558. '\u3209': '\u0028\u110E\u0029',
  14559. '\u320A': '\u0028\u110F\u0029',
  14560. '\u320B': '\u0028\u1110\u0029',
  14561. '\u320C': '\u0028\u1111\u0029',
  14562. '\u320D': '\u0028\u1112\u0029',
  14563. '\u320E': '\u0028\u1100\u1161\u0029',
  14564. '\u320F': '\u0028\u1102\u1161\u0029',
  14565. '\u3210': '\u0028\u1103\u1161\u0029',
  14566. '\u3211': '\u0028\u1105\u1161\u0029',
  14567. '\u3212': '\u0028\u1106\u1161\u0029',
  14568. '\u3213': '\u0028\u1107\u1161\u0029',
  14569. '\u3214': '\u0028\u1109\u1161\u0029',
  14570. '\u3215': '\u0028\u110B\u1161\u0029',
  14571. '\u3216': '\u0028\u110C\u1161\u0029',
  14572. '\u3217': '\u0028\u110E\u1161\u0029',
  14573. '\u3218': '\u0028\u110F\u1161\u0029',
  14574. '\u3219': '\u0028\u1110\u1161\u0029',
  14575. '\u321A': '\u0028\u1111\u1161\u0029',
  14576. '\u321B': '\u0028\u1112\u1161\u0029',
  14577. '\u321C': '\u0028\u110C\u116E\u0029',
  14578. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14579. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14580. '\u3220': '\u0028\u4E00\u0029',
  14581. '\u3221': '\u0028\u4E8C\u0029',
  14582. '\u3222': '\u0028\u4E09\u0029',
  14583. '\u3223': '\u0028\u56DB\u0029',
  14584. '\u3224': '\u0028\u4E94\u0029',
  14585. '\u3225': '\u0028\u516D\u0029',
  14586. '\u3226': '\u0028\u4E03\u0029',
  14587. '\u3227': '\u0028\u516B\u0029',
  14588. '\u3228': '\u0028\u4E5D\u0029',
  14589. '\u3229': '\u0028\u5341\u0029',
  14590. '\u322A': '\u0028\u6708\u0029',
  14591. '\u322B': '\u0028\u706B\u0029',
  14592. '\u322C': '\u0028\u6C34\u0029',
  14593. '\u322D': '\u0028\u6728\u0029',
  14594. '\u322E': '\u0028\u91D1\u0029',
  14595. '\u322F': '\u0028\u571F\u0029',
  14596. '\u3230': '\u0028\u65E5\u0029',
  14597. '\u3231': '\u0028\u682A\u0029',
  14598. '\u3232': '\u0028\u6709\u0029',
  14599. '\u3233': '\u0028\u793E\u0029',
  14600. '\u3234': '\u0028\u540D\u0029',
  14601. '\u3235': '\u0028\u7279\u0029',
  14602. '\u3236': '\u0028\u8CA1\u0029',
  14603. '\u3237': '\u0028\u795D\u0029',
  14604. '\u3238': '\u0028\u52B4\u0029',
  14605. '\u3239': '\u0028\u4EE3\u0029',
  14606. '\u323A': '\u0028\u547C\u0029',
  14607. '\u323B': '\u0028\u5B66\u0029',
  14608. '\u323C': '\u0028\u76E3\u0029',
  14609. '\u323D': '\u0028\u4F01\u0029',
  14610. '\u323E': '\u0028\u8CC7\u0029',
  14611. '\u323F': '\u0028\u5354\u0029',
  14612. '\u3240': '\u0028\u796D\u0029',
  14613. '\u3241': '\u0028\u4F11\u0029',
  14614. '\u3242': '\u0028\u81EA\u0029',
  14615. '\u3243': '\u0028\u81F3\u0029',
  14616. '\u32C0': '\u0031\u6708',
  14617. '\u32C1': '\u0032\u6708',
  14618. '\u32C2': '\u0033\u6708',
  14619. '\u32C3': '\u0034\u6708',
  14620. '\u32C4': '\u0035\u6708',
  14621. '\u32C5': '\u0036\u6708',
  14622. '\u32C6': '\u0037\u6708',
  14623. '\u32C7': '\u0038\u6708',
  14624. '\u32C8': '\u0039\u6708',
  14625. '\u32C9': '\u0031\u0030\u6708',
  14626. '\u32CA': '\u0031\u0031\u6708',
  14627. '\u32CB': '\u0031\u0032\u6708',
  14628. '\u3358': '\u0030\u70B9',
  14629. '\u3359': '\u0031\u70B9',
  14630. '\u335A': '\u0032\u70B9',
  14631. '\u335B': '\u0033\u70B9',
  14632. '\u335C': '\u0034\u70B9',
  14633. '\u335D': '\u0035\u70B9',
  14634. '\u335E': '\u0036\u70B9',
  14635. '\u335F': '\u0037\u70B9',
  14636. '\u3360': '\u0038\u70B9',
  14637. '\u3361': '\u0039\u70B9',
  14638. '\u3362': '\u0031\u0030\u70B9',
  14639. '\u3363': '\u0031\u0031\u70B9',
  14640. '\u3364': '\u0031\u0032\u70B9',
  14641. '\u3365': '\u0031\u0033\u70B9',
  14642. '\u3366': '\u0031\u0034\u70B9',
  14643. '\u3367': '\u0031\u0035\u70B9',
  14644. '\u3368': '\u0031\u0036\u70B9',
  14645. '\u3369': '\u0031\u0037\u70B9',
  14646. '\u336A': '\u0031\u0038\u70B9',
  14647. '\u336B': '\u0031\u0039\u70B9',
  14648. '\u336C': '\u0032\u0030\u70B9',
  14649. '\u336D': '\u0032\u0031\u70B9',
  14650. '\u336E': '\u0032\u0032\u70B9',
  14651. '\u336F': '\u0032\u0033\u70B9',
  14652. '\u3370': '\u0032\u0034\u70B9',
  14653. '\u33E0': '\u0031\u65E5',
  14654. '\u33E1': '\u0032\u65E5',
  14655. '\u33E2': '\u0033\u65E5',
  14656. '\u33E3': '\u0034\u65E5',
  14657. '\u33E4': '\u0035\u65E5',
  14658. '\u33E5': '\u0036\u65E5',
  14659. '\u33E6': '\u0037\u65E5',
  14660. '\u33E7': '\u0038\u65E5',
  14661. '\u33E8': '\u0039\u65E5',
  14662. '\u33E9': '\u0031\u0030\u65E5',
  14663. '\u33EA': '\u0031\u0031\u65E5',
  14664. '\u33EB': '\u0031\u0032\u65E5',
  14665. '\u33EC': '\u0031\u0033\u65E5',
  14666. '\u33ED': '\u0031\u0034\u65E5',
  14667. '\u33EE': '\u0031\u0035\u65E5',
  14668. '\u33EF': '\u0031\u0036\u65E5',
  14669. '\u33F0': '\u0031\u0037\u65E5',
  14670. '\u33F1': '\u0031\u0038\u65E5',
  14671. '\u33F2': '\u0031\u0039\u65E5',
  14672. '\u33F3': '\u0032\u0030\u65E5',
  14673. '\u33F4': '\u0032\u0031\u65E5',
  14674. '\u33F5': '\u0032\u0032\u65E5',
  14675. '\u33F6': '\u0032\u0033\u65E5',
  14676. '\u33F7': '\u0032\u0034\u65E5',
  14677. '\u33F8': '\u0032\u0035\u65E5',
  14678. '\u33F9': '\u0032\u0036\u65E5',
  14679. '\u33FA': '\u0032\u0037\u65E5',
  14680. '\u33FB': '\u0032\u0038\u65E5',
  14681. '\u33FC': '\u0032\u0039\u65E5',
  14682. '\u33FD': '\u0033\u0030\u65E5',
  14683. '\u33FE': '\u0033\u0031\u65E5',
  14684. '\uFB00': '\u0066\u0066',
  14685. '\uFB01': '\u0066\u0069',
  14686. '\uFB02': '\u0066\u006C',
  14687. '\uFB03': '\u0066\u0066\u0069',
  14688. '\uFB04': '\u0066\u0066\u006C',
  14689. '\uFB05': '\u017F\u0074',
  14690. '\uFB06': '\u0073\u0074',
  14691. '\uFB13': '\u0574\u0576',
  14692. '\uFB14': '\u0574\u0565',
  14693. '\uFB15': '\u0574\u056B',
  14694. '\uFB16': '\u057E\u0576',
  14695. '\uFB17': '\u0574\u056D',
  14696. '\uFB4F': '\u05D0\u05DC',
  14697. '\uFB50': '\u0671',
  14698. '\uFB51': '\u0671',
  14699. '\uFB52': '\u067B',
  14700. '\uFB53': '\u067B',
  14701. '\uFB54': '\u067B',
  14702. '\uFB55': '\u067B',
  14703. '\uFB56': '\u067E',
  14704. '\uFB57': '\u067E',
  14705. '\uFB58': '\u067E',
  14706. '\uFB59': '\u067E',
  14707. '\uFB5A': '\u0680',
  14708. '\uFB5B': '\u0680',
  14709. '\uFB5C': '\u0680',
  14710. '\uFB5D': '\u0680',
  14711. '\uFB5E': '\u067A',
  14712. '\uFB5F': '\u067A',
  14713. '\uFB60': '\u067A',
  14714. '\uFB61': '\u067A',
  14715. '\uFB62': '\u067F',
  14716. '\uFB63': '\u067F',
  14717. '\uFB64': '\u067F',
  14718. '\uFB65': '\u067F',
  14719. '\uFB66': '\u0679',
  14720. '\uFB67': '\u0679',
  14721. '\uFB68': '\u0679',
  14722. '\uFB69': '\u0679',
  14723. '\uFB6A': '\u06A4',
  14724. '\uFB6B': '\u06A4',
  14725. '\uFB6C': '\u06A4',
  14726. '\uFB6D': '\u06A4',
  14727. '\uFB6E': '\u06A6',
  14728. '\uFB6F': '\u06A6',
  14729. '\uFB70': '\u06A6',
  14730. '\uFB71': '\u06A6',
  14731. '\uFB72': '\u0684',
  14732. '\uFB73': '\u0684',
  14733. '\uFB74': '\u0684',
  14734. '\uFB75': '\u0684',
  14735. '\uFB76': '\u0683',
  14736. '\uFB77': '\u0683',
  14737. '\uFB78': '\u0683',
  14738. '\uFB79': '\u0683',
  14739. '\uFB7A': '\u0686',
  14740. '\uFB7B': '\u0686',
  14741. '\uFB7C': '\u0686',
  14742. '\uFB7D': '\u0686',
  14743. '\uFB7E': '\u0687',
  14744. '\uFB7F': '\u0687',
  14745. '\uFB80': '\u0687',
  14746. '\uFB81': '\u0687',
  14747. '\uFB82': '\u068D',
  14748. '\uFB83': '\u068D',
  14749. '\uFB84': '\u068C',
  14750. '\uFB85': '\u068C',
  14751. '\uFB86': '\u068E',
  14752. '\uFB87': '\u068E',
  14753. '\uFB88': '\u0688',
  14754. '\uFB89': '\u0688',
  14755. '\uFB8A': '\u0698',
  14756. '\uFB8B': '\u0698',
  14757. '\uFB8C': '\u0691',
  14758. '\uFB8D': '\u0691',
  14759. '\uFB8E': '\u06A9',
  14760. '\uFB8F': '\u06A9',
  14761. '\uFB90': '\u06A9',
  14762. '\uFB91': '\u06A9',
  14763. '\uFB92': '\u06AF',
  14764. '\uFB93': '\u06AF',
  14765. '\uFB94': '\u06AF',
  14766. '\uFB95': '\u06AF',
  14767. '\uFB96': '\u06B3',
  14768. '\uFB97': '\u06B3',
  14769. '\uFB98': '\u06B3',
  14770. '\uFB99': '\u06B3',
  14771. '\uFB9A': '\u06B1',
  14772. '\uFB9B': '\u06B1',
  14773. '\uFB9C': '\u06B1',
  14774. '\uFB9D': '\u06B1',
  14775. '\uFB9E': '\u06BA',
  14776. '\uFB9F': '\u06BA',
  14777. '\uFBA0': '\u06BB',
  14778. '\uFBA1': '\u06BB',
  14779. '\uFBA2': '\u06BB',
  14780. '\uFBA3': '\u06BB',
  14781. '\uFBA4': '\u06C0',
  14782. '\uFBA5': '\u06C0',
  14783. '\uFBA6': '\u06C1',
  14784. '\uFBA7': '\u06C1',
  14785. '\uFBA8': '\u06C1',
  14786. '\uFBA9': '\u06C1',
  14787. '\uFBAA': '\u06BE',
  14788. '\uFBAB': '\u06BE',
  14789. '\uFBAC': '\u06BE',
  14790. '\uFBAD': '\u06BE',
  14791. '\uFBAE': '\u06D2',
  14792. '\uFBAF': '\u06D2',
  14793. '\uFBB0': '\u06D3',
  14794. '\uFBB1': '\u06D3',
  14795. '\uFBD3': '\u06AD',
  14796. '\uFBD4': '\u06AD',
  14797. '\uFBD5': '\u06AD',
  14798. '\uFBD6': '\u06AD',
  14799. '\uFBD7': '\u06C7',
  14800. '\uFBD8': '\u06C7',
  14801. '\uFBD9': '\u06C6',
  14802. '\uFBDA': '\u06C6',
  14803. '\uFBDB': '\u06C8',
  14804. '\uFBDC': '\u06C8',
  14805. '\uFBDD': '\u0677',
  14806. '\uFBDE': '\u06CB',
  14807. '\uFBDF': '\u06CB',
  14808. '\uFBE0': '\u06C5',
  14809. '\uFBE1': '\u06C5',
  14810. '\uFBE2': '\u06C9',
  14811. '\uFBE3': '\u06C9',
  14812. '\uFBE4': '\u06D0',
  14813. '\uFBE5': '\u06D0',
  14814. '\uFBE6': '\u06D0',
  14815. '\uFBE7': '\u06D0',
  14816. '\uFBE8': '\u0649',
  14817. '\uFBE9': '\u0649',
  14818. '\uFBEA': '\u0626\u0627',
  14819. '\uFBEB': '\u0626\u0627',
  14820. '\uFBEC': '\u0626\u06D5',
  14821. '\uFBED': '\u0626\u06D5',
  14822. '\uFBEE': '\u0626\u0648',
  14823. '\uFBEF': '\u0626\u0648',
  14824. '\uFBF0': '\u0626\u06C7',
  14825. '\uFBF1': '\u0626\u06C7',
  14826. '\uFBF2': '\u0626\u06C6',
  14827. '\uFBF3': '\u0626\u06C6',
  14828. '\uFBF4': '\u0626\u06C8',
  14829. '\uFBF5': '\u0626\u06C8',
  14830. '\uFBF6': '\u0626\u06D0',
  14831. '\uFBF7': '\u0626\u06D0',
  14832. '\uFBF8': '\u0626\u06D0',
  14833. '\uFBF9': '\u0626\u0649',
  14834. '\uFBFA': '\u0626\u0649',
  14835. '\uFBFB': '\u0626\u0649',
  14836. '\uFBFC': '\u06CC',
  14837. '\uFBFD': '\u06CC',
  14838. '\uFBFE': '\u06CC',
  14839. '\uFBFF': '\u06CC',
  14840. '\uFC00': '\u0626\u062C',
  14841. '\uFC01': '\u0626\u062D',
  14842. '\uFC02': '\u0626\u0645',
  14843. '\uFC03': '\u0626\u0649',
  14844. '\uFC04': '\u0626\u064A',
  14845. '\uFC05': '\u0628\u062C',
  14846. '\uFC06': '\u0628\u062D',
  14847. '\uFC07': '\u0628\u062E',
  14848. '\uFC08': '\u0628\u0645',
  14849. '\uFC09': '\u0628\u0649',
  14850. '\uFC0A': '\u0628\u064A',
  14851. '\uFC0B': '\u062A\u062C',
  14852. '\uFC0C': '\u062A\u062D',
  14853. '\uFC0D': '\u062A\u062E',
  14854. '\uFC0E': '\u062A\u0645',
  14855. '\uFC0F': '\u062A\u0649',
  14856. '\uFC10': '\u062A\u064A',
  14857. '\uFC11': '\u062B\u062C',
  14858. '\uFC12': '\u062B\u0645',
  14859. '\uFC13': '\u062B\u0649',
  14860. '\uFC14': '\u062B\u064A',
  14861. '\uFC15': '\u062C\u062D',
  14862. '\uFC16': '\u062C\u0645',
  14863. '\uFC17': '\u062D\u062C',
  14864. '\uFC18': '\u062D\u0645',
  14865. '\uFC19': '\u062E\u062C',
  14866. '\uFC1A': '\u062E\u062D',
  14867. '\uFC1B': '\u062E\u0645',
  14868. '\uFC1C': '\u0633\u062C',
  14869. '\uFC1D': '\u0633\u062D',
  14870. '\uFC1E': '\u0633\u062E',
  14871. '\uFC1F': '\u0633\u0645',
  14872. '\uFC20': '\u0635\u062D',
  14873. '\uFC21': '\u0635\u0645',
  14874. '\uFC22': '\u0636\u062C',
  14875. '\uFC23': '\u0636\u062D',
  14876. '\uFC24': '\u0636\u062E',
  14877. '\uFC25': '\u0636\u0645',
  14878. '\uFC26': '\u0637\u062D',
  14879. '\uFC27': '\u0637\u0645',
  14880. '\uFC28': '\u0638\u0645',
  14881. '\uFC29': '\u0639\u062C',
  14882. '\uFC2A': '\u0639\u0645',
  14883. '\uFC2B': '\u063A\u062C',
  14884. '\uFC2C': '\u063A\u0645',
  14885. '\uFC2D': '\u0641\u062C',
  14886. '\uFC2E': '\u0641\u062D',
  14887. '\uFC2F': '\u0641\u062E',
  14888. '\uFC30': '\u0641\u0645',
  14889. '\uFC31': '\u0641\u0649',
  14890. '\uFC32': '\u0641\u064A',
  14891. '\uFC33': '\u0642\u062D',
  14892. '\uFC34': '\u0642\u0645',
  14893. '\uFC35': '\u0642\u0649',
  14894. '\uFC36': '\u0642\u064A',
  14895. '\uFC37': '\u0643\u0627',
  14896. '\uFC38': '\u0643\u062C',
  14897. '\uFC39': '\u0643\u062D',
  14898. '\uFC3A': '\u0643\u062E',
  14899. '\uFC3B': '\u0643\u0644',
  14900. '\uFC3C': '\u0643\u0645',
  14901. '\uFC3D': '\u0643\u0649',
  14902. '\uFC3E': '\u0643\u064A',
  14903. '\uFC3F': '\u0644\u062C',
  14904. '\uFC40': '\u0644\u062D',
  14905. '\uFC41': '\u0644\u062E',
  14906. '\uFC42': '\u0644\u0645',
  14907. '\uFC43': '\u0644\u0649',
  14908. '\uFC44': '\u0644\u064A',
  14909. '\uFC45': '\u0645\u062C',
  14910. '\uFC46': '\u0645\u062D',
  14911. '\uFC47': '\u0645\u062E',
  14912. '\uFC48': '\u0645\u0645',
  14913. '\uFC49': '\u0645\u0649',
  14914. '\uFC4A': '\u0645\u064A',
  14915. '\uFC4B': '\u0646\u062C',
  14916. '\uFC4C': '\u0646\u062D',
  14917. '\uFC4D': '\u0646\u062E',
  14918. '\uFC4E': '\u0646\u0645',
  14919. '\uFC4F': '\u0646\u0649',
  14920. '\uFC50': '\u0646\u064A',
  14921. '\uFC51': '\u0647\u062C',
  14922. '\uFC52': '\u0647\u0645',
  14923. '\uFC53': '\u0647\u0649',
  14924. '\uFC54': '\u0647\u064A',
  14925. '\uFC55': '\u064A\u062C',
  14926. '\uFC56': '\u064A\u062D',
  14927. '\uFC57': '\u064A\u062E',
  14928. '\uFC58': '\u064A\u0645',
  14929. '\uFC59': '\u064A\u0649',
  14930. '\uFC5A': '\u064A\u064A',
  14931. '\uFC5B': '\u0630\u0670',
  14932. '\uFC5C': '\u0631\u0670',
  14933. '\uFC5D': '\u0649\u0670',
  14934. '\uFC5E': '\u0020\u064C\u0651',
  14935. '\uFC5F': '\u0020\u064D\u0651',
  14936. '\uFC60': '\u0020\u064E\u0651',
  14937. '\uFC61': '\u0020\u064F\u0651',
  14938. '\uFC62': '\u0020\u0650\u0651',
  14939. '\uFC63': '\u0020\u0651\u0670',
  14940. '\uFC64': '\u0626\u0631',
  14941. '\uFC65': '\u0626\u0632',
  14942. '\uFC66': '\u0626\u0645',
  14943. '\uFC67': '\u0626\u0646',
  14944. '\uFC68': '\u0626\u0649',
  14945. '\uFC69': '\u0626\u064A',
  14946. '\uFC6A': '\u0628\u0631',
  14947. '\uFC6B': '\u0628\u0632',
  14948. '\uFC6C': '\u0628\u0645',
  14949. '\uFC6D': '\u0628\u0646',
  14950. '\uFC6E': '\u0628\u0649',
  14951. '\uFC6F': '\u0628\u064A',
  14952. '\uFC70': '\u062A\u0631',
  14953. '\uFC71': '\u062A\u0632',
  14954. '\uFC72': '\u062A\u0645',
  14955. '\uFC73': '\u062A\u0646',
  14956. '\uFC74': '\u062A\u0649',
  14957. '\uFC75': '\u062A\u064A',
  14958. '\uFC76': '\u062B\u0631',
  14959. '\uFC77': '\u062B\u0632',
  14960. '\uFC78': '\u062B\u0645',
  14961. '\uFC79': '\u062B\u0646',
  14962. '\uFC7A': '\u062B\u0649',
  14963. '\uFC7B': '\u062B\u064A',
  14964. '\uFC7C': '\u0641\u0649',
  14965. '\uFC7D': '\u0641\u064A',
  14966. '\uFC7E': '\u0642\u0649',
  14967. '\uFC7F': '\u0642\u064A',
  14968. '\uFC80': '\u0643\u0627',
  14969. '\uFC81': '\u0643\u0644',
  14970. '\uFC82': '\u0643\u0645',
  14971. '\uFC83': '\u0643\u0649',
  14972. '\uFC84': '\u0643\u064A',
  14973. '\uFC85': '\u0644\u0645',
  14974. '\uFC86': '\u0644\u0649',
  14975. '\uFC87': '\u0644\u064A',
  14976. '\uFC88': '\u0645\u0627',
  14977. '\uFC89': '\u0645\u0645',
  14978. '\uFC8A': '\u0646\u0631',
  14979. '\uFC8B': '\u0646\u0632',
  14980. '\uFC8C': '\u0646\u0645',
  14981. '\uFC8D': '\u0646\u0646',
  14982. '\uFC8E': '\u0646\u0649',
  14983. '\uFC8F': '\u0646\u064A',
  14984. '\uFC90': '\u0649\u0670',
  14985. '\uFC91': '\u064A\u0631',
  14986. '\uFC92': '\u064A\u0632',
  14987. '\uFC93': '\u064A\u0645',
  14988. '\uFC94': '\u064A\u0646',
  14989. '\uFC95': '\u064A\u0649',
  14990. '\uFC96': '\u064A\u064A',
  14991. '\uFC97': '\u0626\u062C',
  14992. '\uFC98': '\u0626\u062D',
  14993. '\uFC99': '\u0626\u062E',
  14994. '\uFC9A': '\u0626\u0645',
  14995. '\uFC9B': '\u0626\u0647',
  14996. '\uFC9C': '\u0628\u062C',
  14997. '\uFC9D': '\u0628\u062D',
  14998. '\uFC9E': '\u0628\u062E',
  14999. '\uFC9F': '\u0628\u0645',
  15000. '\uFCA0': '\u0628\u0647',
  15001. '\uFCA1': '\u062A\u062C',
  15002. '\uFCA2': '\u062A\u062D',
  15003. '\uFCA3': '\u062A\u062E',
  15004. '\uFCA4': '\u062A\u0645',
  15005. '\uFCA5': '\u062A\u0647',
  15006. '\uFCA6': '\u062B\u0645',
  15007. '\uFCA7': '\u062C\u062D',
  15008. '\uFCA8': '\u062C\u0645',
  15009. '\uFCA9': '\u062D\u062C',
  15010. '\uFCAA': '\u062D\u0645',
  15011. '\uFCAB': '\u062E\u062C',
  15012. '\uFCAC': '\u062E\u0645',
  15013. '\uFCAD': '\u0633\u062C',
  15014. '\uFCAE': '\u0633\u062D',
  15015. '\uFCAF': '\u0633\u062E',
  15016. '\uFCB0': '\u0633\u0645',
  15017. '\uFCB1': '\u0635\u062D',
  15018. '\uFCB2': '\u0635\u062E',
  15019. '\uFCB3': '\u0635\u0645',
  15020. '\uFCB4': '\u0636\u062C',
  15021. '\uFCB5': '\u0636\u062D',
  15022. '\uFCB6': '\u0636\u062E',
  15023. '\uFCB7': '\u0636\u0645',
  15024. '\uFCB8': '\u0637\u062D',
  15025. '\uFCB9': '\u0638\u0645',
  15026. '\uFCBA': '\u0639\u062C',
  15027. '\uFCBB': '\u0639\u0645',
  15028. '\uFCBC': '\u063A\u062C',
  15029. '\uFCBD': '\u063A\u0645',
  15030. '\uFCBE': '\u0641\u062C',
  15031. '\uFCBF': '\u0641\u062D',
  15032. '\uFCC0': '\u0641\u062E',
  15033. '\uFCC1': '\u0641\u0645',
  15034. '\uFCC2': '\u0642\u062D',
  15035. '\uFCC3': '\u0642\u0645',
  15036. '\uFCC4': '\u0643\u062C',
  15037. '\uFCC5': '\u0643\u062D',
  15038. '\uFCC6': '\u0643\u062E',
  15039. '\uFCC7': '\u0643\u0644',
  15040. '\uFCC8': '\u0643\u0645',
  15041. '\uFCC9': '\u0644\u062C',
  15042. '\uFCCA': '\u0644\u062D',
  15043. '\uFCCB': '\u0644\u062E',
  15044. '\uFCCC': '\u0644\u0645',
  15045. '\uFCCD': '\u0644\u0647',
  15046. '\uFCCE': '\u0645\u062C',
  15047. '\uFCCF': '\u0645\u062D',
  15048. '\uFCD0': '\u0645\u062E',
  15049. '\uFCD1': '\u0645\u0645',
  15050. '\uFCD2': '\u0646\u062C',
  15051. '\uFCD3': '\u0646\u062D',
  15052. '\uFCD4': '\u0646\u062E',
  15053. '\uFCD5': '\u0646\u0645',
  15054. '\uFCD6': '\u0646\u0647',
  15055. '\uFCD7': '\u0647\u062C',
  15056. '\uFCD8': '\u0647\u0645',
  15057. '\uFCD9': '\u0647\u0670',
  15058. '\uFCDA': '\u064A\u062C',
  15059. '\uFCDB': '\u064A\u062D',
  15060. '\uFCDC': '\u064A\u062E',
  15061. '\uFCDD': '\u064A\u0645',
  15062. '\uFCDE': '\u064A\u0647',
  15063. '\uFCDF': '\u0626\u0645',
  15064. '\uFCE0': '\u0626\u0647',
  15065. '\uFCE1': '\u0628\u0645',
  15066. '\uFCE2': '\u0628\u0647',
  15067. '\uFCE3': '\u062A\u0645',
  15068. '\uFCE4': '\u062A\u0647',
  15069. '\uFCE5': '\u062B\u0645',
  15070. '\uFCE6': '\u062B\u0647',
  15071. '\uFCE7': '\u0633\u0645',
  15072. '\uFCE8': '\u0633\u0647',
  15073. '\uFCE9': '\u0634\u0645',
  15074. '\uFCEA': '\u0634\u0647',
  15075. '\uFCEB': '\u0643\u0644',
  15076. '\uFCEC': '\u0643\u0645',
  15077. '\uFCED': '\u0644\u0645',
  15078. '\uFCEE': '\u0646\u0645',
  15079. '\uFCEF': '\u0646\u0647',
  15080. '\uFCF0': '\u064A\u0645',
  15081. '\uFCF1': '\u064A\u0647',
  15082. '\uFCF2': '\u0640\u064E\u0651',
  15083. '\uFCF3': '\u0640\u064F\u0651',
  15084. '\uFCF4': '\u0640\u0650\u0651',
  15085. '\uFCF5': '\u0637\u0649',
  15086. '\uFCF6': '\u0637\u064A',
  15087. '\uFCF7': '\u0639\u0649',
  15088. '\uFCF8': '\u0639\u064A',
  15089. '\uFCF9': '\u063A\u0649',
  15090. '\uFCFA': '\u063A\u064A',
  15091. '\uFCFB': '\u0633\u0649',
  15092. '\uFCFC': '\u0633\u064A',
  15093. '\uFCFD': '\u0634\u0649',
  15094. '\uFCFE': '\u0634\u064A',
  15095. '\uFCFF': '\u062D\u0649',
  15096. '\uFD00': '\u062D\u064A',
  15097. '\uFD01': '\u062C\u0649',
  15098. '\uFD02': '\u062C\u064A',
  15099. '\uFD03': '\u062E\u0649',
  15100. '\uFD04': '\u062E\u064A',
  15101. '\uFD05': '\u0635\u0649',
  15102. '\uFD06': '\u0635\u064A',
  15103. '\uFD07': '\u0636\u0649',
  15104. '\uFD08': '\u0636\u064A',
  15105. '\uFD09': '\u0634\u062C',
  15106. '\uFD0A': '\u0634\u062D',
  15107. '\uFD0B': '\u0634\u062E',
  15108. '\uFD0C': '\u0634\u0645',
  15109. '\uFD0D': '\u0634\u0631',
  15110. '\uFD0E': '\u0633\u0631',
  15111. '\uFD0F': '\u0635\u0631',
  15112. '\uFD10': '\u0636\u0631',
  15113. '\uFD11': '\u0637\u0649',
  15114. '\uFD12': '\u0637\u064A',
  15115. '\uFD13': '\u0639\u0649',
  15116. '\uFD14': '\u0639\u064A',
  15117. '\uFD15': '\u063A\u0649',
  15118. '\uFD16': '\u063A\u064A',
  15119. '\uFD17': '\u0633\u0649',
  15120. '\uFD18': '\u0633\u064A',
  15121. '\uFD19': '\u0634\u0649',
  15122. '\uFD1A': '\u0634\u064A',
  15123. '\uFD1B': '\u062D\u0649',
  15124. '\uFD1C': '\u062D\u064A',
  15125. '\uFD1D': '\u062C\u0649',
  15126. '\uFD1E': '\u062C\u064A',
  15127. '\uFD1F': '\u062E\u0649',
  15128. '\uFD20': '\u062E\u064A',
  15129. '\uFD21': '\u0635\u0649',
  15130. '\uFD22': '\u0635\u064A',
  15131. '\uFD23': '\u0636\u0649',
  15132. '\uFD24': '\u0636\u064A',
  15133. '\uFD25': '\u0634\u062C',
  15134. '\uFD26': '\u0634\u062D',
  15135. '\uFD27': '\u0634\u062E',
  15136. '\uFD28': '\u0634\u0645',
  15137. '\uFD29': '\u0634\u0631',
  15138. '\uFD2A': '\u0633\u0631',
  15139. '\uFD2B': '\u0635\u0631',
  15140. '\uFD2C': '\u0636\u0631',
  15141. '\uFD2D': '\u0634\u062C',
  15142. '\uFD2E': '\u0634\u062D',
  15143. '\uFD2F': '\u0634\u062E',
  15144. '\uFD30': '\u0634\u0645',
  15145. '\uFD31': '\u0633\u0647',
  15146. '\uFD32': '\u0634\u0647',
  15147. '\uFD33': '\u0637\u0645',
  15148. '\uFD34': '\u0633\u062C',
  15149. '\uFD35': '\u0633\u062D',
  15150. '\uFD36': '\u0633\u062E',
  15151. '\uFD37': '\u0634\u062C',
  15152. '\uFD38': '\u0634\u062D',
  15153. '\uFD39': '\u0634\u062E',
  15154. '\uFD3A': '\u0637\u0645',
  15155. '\uFD3B': '\u0638\u0645',
  15156. '\uFD3C': '\u0627\u064B',
  15157. '\uFD3D': '\u0627\u064B',
  15158. '\uFD50': '\u062A\u062C\u0645',
  15159. '\uFD51': '\u062A\u062D\u062C',
  15160. '\uFD52': '\u062A\u062D\u062C',
  15161. '\uFD53': '\u062A\u062D\u0645',
  15162. '\uFD54': '\u062A\u062E\u0645',
  15163. '\uFD55': '\u062A\u0645\u062C',
  15164. '\uFD56': '\u062A\u0645\u062D',
  15165. '\uFD57': '\u062A\u0645\u062E',
  15166. '\uFD58': '\u062C\u0645\u062D',
  15167. '\uFD59': '\u062C\u0645\u062D',
  15168. '\uFD5A': '\u062D\u0645\u064A',
  15169. '\uFD5B': '\u062D\u0645\u0649',
  15170. '\uFD5C': '\u0633\u062D\u062C',
  15171. '\uFD5D': '\u0633\u062C\u062D',
  15172. '\uFD5E': '\u0633\u062C\u0649',
  15173. '\uFD5F': '\u0633\u0645\u062D',
  15174. '\uFD60': '\u0633\u0645\u062D',
  15175. '\uFD61': '\u0633\u0645\u062C',
  15176. '\uFD62': '\u0633\u0645\u0645',
  15177. '\uFD63': '\u0633\u0645\u0645',
  15178. '\uFD64': '\u0635\u062D\u062D',
  15179. '\uFD65': '\u0635\u062D\u062D',
  15180. '\uFD66': '\u0635\u0645\u0645',
  15181. '\uFD67': '\u0634\u062D\u0645',
  15182. '\uFD68': '\u0634\u062D\u0645',
  15183. '\uFD69': '\u0634\u062C\u064A',
  15184. '\uFD6A': '\u0634\u0645\u062E',
  15185. '\uFD6B': '\u0634\u0645\u062E',
  15186. '\uFD6C': '\u0634\u0645\u0645',
  15187. '\uFD6D': '\u0634\u0645\u0645',
  15188. '\uFD6E': '\u0636\u062D\u0649',
  15189. '\uFD6F': '\u0636\u062E\u0645',
  15190. '\uFD70': '\u0636\u062E\u0645',
  15191. '\uFD71': '\u0637\u0645\u062D',
  15192. '\uFD72': '\u0637\u0645\u062D',
  15193. '\uFD73': '\u0637\u0645\u0645',
  15194. '\uFD74': '\u0637\u0645\u064A',
  15195. '\uFD75': '\u0639\u062C\u0645',
  15196. '\uFD76': '\u0639\u0645\u0645',
  15197. '\uFD77': '\u0639\u0645\u0645',
  15198. '\uFD78': '\u0639\u0645\u0649',
  15199. '\uFD79': '\u063A\u0645\u0645',
  15200. '\uFD7A': '\u063A\u0645\u064A',
  15201. '\uFD7B': '\u063A\u0645\u0649',
  15202. '\uFD7C': '\u0641\u062E\u0645',
  15203. '\uFD7D': '\u0641\u062E\u0645',
  15204. '\uFD7E': '\u0642\u0645\u062D',
  15205. '\uFD7F': '\u0642\u0645\u0645',
  15206. '\uFD80': '\u0644\u062D\u0645',
  15207. '\uFD81': '\u0644\u062D\u064A',
  15208. '\uFD82': '\u0644\u062D\u0649',
  15209. '\uFD83': '\u0644\u062C\u062C',
  15210. '\uFD84': '\u0644\u062C\u062C',
  15211. '\uFD85': '\u0644\u062E\u0645',
  15212. '\uFD86': '\u0644\u062E\u0645',
  15213. '\uFD87': '\u0644\u0645\u062D',
  15214. '\uFD88': '\u0644\u0645\u062D',
  15215. '\uFD89': '\u0645\u062D\u062C',
  15216. '\uFD8A': '\u0645\u062D\u0645',
  15217. '\uFD8B': '\u0645\u062D\u064A',
  15218. '\uFD8C': '\u0645\u062C\u062D',
  15219. '\uFD8D': '\u0645\u062C\u0645',
  15220. '\uFD8E': '\u0645\u062E\u062C',
  15221. '\uFD8F': '\u0645\u062E\u0645',
  15222. '\uFD92': '\u0645\u062C\u062E',
  15223. '\uFD93': '\u0647\u0645\u062C',
  15224. '\uFD94': '\u0647\u0645\u0645',
  15225. '\uFD95': '\u0646\u062D\u0645',
  15226. '\uFD96': '\u0646\u062D\u0649',
  15227. '\uFD97': '\u0646\u062C\u0645',
  15228. '\uFD98': '\u0646\u062C\u0645',
  15229. '\uFD99': '\u0646\u062C\u0649',
  15230. '\uFD9A': '\u0646\u0645\u064A',
  15231. '\uFD9B': '\u0646\u0645\u0649',
  15232. '\uFD9C': '\u064A\u0645\u0645',
  15233. '\uFD9D': '\u064A\u0645\u0645',
  15234. '\uFD9E': '\u0628\u062E\u064A',
  15235. '\uFD9F': '\u062A\u062C\u064A',
  15236. '\uFDA0': '\u062A\u062C\u0649',
  15237. '\uFDA1': '\u062A\u062E\u064A',
  15238. '\uFDA2': '\u062A\u062E\u0649',
  15239. '\uFDA3': '\u062A\u0645\u064A',
  15240. '\uFDA4': '\u062A\u0645\u0649',
  15241. '\uFDA5': '\u062C\u0645\u064A',
  15242. '\uFDA6': '\u062C\u062D\u0649',
  15243. '\uFDA7': '\u062C\u0645\u0649',
  15244. '\uFDA8': '\u0633\u062E\u0649',
  15245. '\uFDA9': '\u0635\u062D\u064A',
  15246. '\uFDAA': '\u0634\u062D\u064A',
  15247. '\uFDAB': '\u0636\u062D\u064A',
  15248. '\uFDAC': '\u0644\u062C\u064A',
  15249. '\uFDAD': '\u0644\u0645\u064A',
  15250. '\uFDAE': '\u064A\u062D\u064A',
  15251. '\uFDAF': '\u064A\u062C\u064A',
  15252. '\uFDB0': '\u064A\u0645\u064A',
  15253. '\uFDB1': '\u0645\u0645\u064A',
  15254. '\uFDB2': '\u0642\u0645\u064A',
  15255. '\uFDB3': '\u0646\u062D\u064A',
  15256. '\uFDB4': '\u0642\u0645\u062D',
  15257. '\uFDB5': '\u0644\u062D\u0645',
  15258. '\uFDB6': '\u0639\u0645\u064A',
  15259. '\uFDB7': '\u0643\u0645\u064A',
  15260. '\uFDB8': '\u0646\u062C\u062D',
  15261. '\uFDB9': '\u0645\u062E\u064A',
  15262. '\uFDBA': '\u0644\u062C\u0645',
  15263. '\uFDBB': '\u0643\u0645\u0645',
  15264. '\uFDBC': '\u0644\u062C\u0645',
  15265. '\uFDBD': '\u0646\u062C\u062D',
  15266. '\uFDBE': '\u062C\u062D\u064A',
  15267. '\uFDBF': '\u062D\u062C\u064A',
  15268. '\uFDC0': '\u0645\u062C\u064A',
  15269. '\uFDC1': '\u0641\u0645\u064A',
  15270. '\uFDC2': '\u0628\u062D\u064A',
  15271. '\uFDC3': '\u0643\u0645\u0645',
  15272. '\uFDC4': '\u0639\u062C\u0645',
  15273. '\uFDC5': '\u0635\u0645\u0645',
  15274. '\uFDC6': '\u0633\u062E\u064A',
  15275. '\uFDC7': '\u0646\u062C\u064A',
  15276. '\uFE49': '\u203E',
  15277. '\uFE4A': '\u203E',
  15278. '\uFE4B': '\u203E',
  15279. '\uFE4C': '\u203E',
  15280. '\uFE4D': '\u005F',
  15281. '\uFE4E': '\u005F',
  15282. '\uFE4F': '\u005F',
  15283. '\uFE80': '\u0621',
  15284. '\uFE81': '\u0622',
  15285. '\uFE82': '\u0622',
  15286. '\uFE83': '\u0623',
  15287. '\uFE84': '\u0623',
  15288. '\uFE85': '\u0624',
  15289. '\uFE86': '\u0624',
  15290. '\uFE87': '\u0625',
  15291. '\uFE88': '\u0625',
  15292. '\uFE89': '\u0626',
  15293. '\uFE8A': '\u0626',
  15294. '\uFE8B': '\u0626',
  15295. '\uFE8C': '\u0626',
  15296. '\uFE8D': '\u0627',
  15297. '\uFE8E': '\u0627',
  15298. '\uFE8F': '\u0628',
  15299. '\uFE90': '\u0628',
  15300. '\uFE91': '\u0628',
  15301. '\uFE92': '\u0628',
  15302. '\uFE93': '\u0629',
  15303. '\uFE94': '\u0629',
  15304. '\uFE95': '\u062A',
  15305. '\uFE96': '\u062A',
  15306. '\uFE97': '\u062A',
  15307. '\uFE98': '\u062A',
  15308. '\uFE99': '\u062B',
  15309. '\uFE9A': '\u062B',
  15310. '\uFE9B': '\u062B',
  15311. '\uFE9C': '\u062B',
  15312. '\uFE9D': '\u062C',
  15313. '\uFE9E': '\u062C',
  15314. '\uFE9F': '\u062C',
  15315. '\uFEA0': '\u062C',
  15316. '\uFEA1': '\u062D',
  15317. '\uFEA2': '\u062D',
  15318. '\uFEA3': '\u062D',
  15319. '\uFEA4': '\u062D',
  15320. '\uFEA5': '\u062E',
  15321. '\uFEA6': '\u062E',
  15322. '\uFEA7': '\u062E',
  15323. '\uFEA8': '\u062E',
  15324. '\uFEA9': '\u062F',
  15325. '\uFEAA': '\u062F',
  15326. '\uFEAB': '\u0630',
  15327. '\uFEAC': '\u0630',
  15328. '\uFEAD': '\u0631',
  15329. '\uFEAE': '\u0631',
  15330. '\uFEAF': '\u0632',
  15331. '\uFEB0': '\u0632',
  15332. '\uFEB1': '\u0633',
  15333. '\uFEB2': '\u0633',
  15334. '\uFEB3': '\u0633',
  15335. '\uFEB4': '\u0633',
  15336. '\uFEB5': '\u0634',
  15337. '\uFEB6': '\u0634',
  15338. '\uFEB7': '\u0634',
  15339. '\uFEB8': '\u0634',
  15340. '\uFEB9': '\u0635',
  15341. '\uFEBA': '\u0635',
  15342. '\uFEBB': '\u0635',
  15343. '\uFEBC': '\u0635',
  15344. '\uFEBD': '\u0636',
  15345. '\uFEBE': '\u0636',
  15346. '\uFEBF': '\u0636',
  15347. '\uFEC0': '\u0636',
  15348. '\uFEC1': '\u0637',
  15349. '\uFEC2': '\u0637',
  15350. '\uFEC3': '\u0637',
  15351. '\uFEC4': '\u0637',
  15352. '\uFEC5': '\u0638',
  15353. '\uFEC6': '\u0638',
  15354. '\uFEC7': '\u0638',
  15355. '\uFEC8': '\u0638',
  15356. '\uFEC9': '\u0639',
  15357. '\uFECA': '\u0639',
  15358. '\uFECB': '\u0639',
  15359. '\uFECC': '\u0639',
  15360. '\uFECD': '\u063A',
  15361. '\uFECE': '\u063A',
  15362. '\uFECF': '\u063A',
  15363. '\uFED0': '\u063A',
  15364. '\uFED1': '\u0641',
  15365. '\uFED2': '\u0641',
  15366. '\uFED3': '\u0641',
  15367. '\uFED4': '\u0641',
  15368. '\uFED5': '\u0642',
  15369. '\uFED6': '\u0642',
  15370. '\uFED7': '\u0642',
  15371. '\uFED8': '\u0642',
  15372. '\uFED9': '\u0643',
  15373. '\uFEDA': '\u0643',
  15374. '\uFEDB': '\u0643',
  15375. '\uFEDC': '\u0643',
  15376. '\uFEDD': '\u0644',
  15377. '\uFEDE': '\u0644',
  15378. '\uFEDF': '\u0644',
  15379. '\uFEE0': '\u0644',
  15380. '\uFEE1': '\u0645',
  15381. '\uFEE2': '\u0645',
  15382. '\uFEE3': '\u0645',
  15383. '\uFEE4': '\u0645',
  15384. '\uFEE5': '\u0646',
  15385. '\uFEE6': '\u0646',
  15386. '\uFEE7': '\u0646',
  15387. '\uFEE8': '\u0646',
  15388. '\uFEE9': '\u0647',
  15389. '\uFEEA': '\u0647',
  15390. '\uFEEB': '\u0647',
  15391. '\uFEEC': '\u0647',
  15392. '\uFEED': '\u0648',
  15393. '\uFEEE': '\u0648',
  15394. '\uFEEF': '\u0649',
  15395. '\uFEF0': '\u0649',
  15396. '\uFEF1': '\u064A',
  15397. '\uFEF2': '\u064A',
  15398. '\uFEF3': '\u064A',
  15399. '\uFEF4': '\u064A',
  15400. '\uFEF5': '\u0644\u0622',
  15401. '\uFEF6': '\u0644\u0622',
  15402. '\uFEF7': '\u0644\u0623',
  15403. '\uFEF8': '\u0644\u0623',
  15404. '\uFEF9': '\u0644\u0625',
  15405. '\uFEFA': '\u0644\u0625',
  15406. '\uFEFB': '\u0644\u0627',
  15407. '\uFEFC': '\u0644\u0627'
  15408. };
  15409. function reverseIfRtl(chars) {
  15410. var charsLength = chars.length;
  15411. //reverse an arabic ligature
  15412. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  15413. return chars;
  15414. }
  15415. var s = '';
  15416. for (var ii = charsLength - 1; ii >= 0; ii--) {
  15417. s += chars[ii];
  15418. }
  15419. return s;
  15420. }
  15421. function adjustWidths(properties) {
  15422. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  15423. return;
  15424. }
  15425. // adjusting width to fontMatrix scale
  15426. var scale = 0.001 / properties.fontMatrix[0];
  15427. var glyphsWidths = properties.widths;
  15428. for (var glyph in glyphsWidths) {
  15429. glyphsWidths[glyph] *= scale;
  15430. }
  15431. properties.defaultWidth *= scale;
  15432. }
  15433. function getFontType(type, subtype) {
  15434. switch (type) {
  15435. case 'Type1':
  15436. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15437. case 'CIDFontType0':
  15438. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15439. FontType.CIDFONTTYPE0;
  15440. case 'OpenType':
  15441. return FontType.OPENTYPE;
  15442. case 'TrueType':
  15443. return FontType.TRUETYPE;
  15444. case 'CIDFontType2':
  15445. return FontType.CIDFONTTYPE2;
  15446. case 'MMType1':
  15447. return FontType.MMTYPE1;
  15448. case 'Type0':
  15449. return FontType.TYPE0;
  15450. default:
  15451. return FontType.UNKNOWN;
  15452. }
  15453. }
  15454. var Glyph = (function GlyphClosure() {
  15455. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  15456. isSpace) {
  15457. this.fontChar = fontChar;
  15458. this.unicode = unicode;
  15459. this.accent = accent;
  15460. this.width = width;
  15461. this.vmetric = vmetric;
  15462. this.operatorListId = operatorListId;
  15463. this.isSpace = isSpace;
  15464. }
  15465. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  15466. vmetric, operatorListId, isSpace) {
  15467. return this.fontChar === fontChar &&
  15468. this.unicode === unicode &&
  15469. this.accent === accent &&
  15470. this.width === width &&
  15471. this.vmetric === vmetric &&
  15472. this.operatorListId === operatorListId &&
  15473. this.isSpace === isSpace;
  15474. };
  15475. return Glyph;
  15476. })();
  15477. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15478. function ToUnicodeMap(cmap) {
  15479. // The elements of this._map can be integers or strings, depending on how
  15480. // |cmap| was created.
  15481. this._map = cmap;
  15482. }
  15483. ToUnicodeMap.prototype = {
  15484. get length() {
  15485. return this._map.length;
  15486. },
  15487. forEach: function(callback) {
  15488. for (var charCode in this._map) {
  15489. callback(charCode, this._map[charCode].charCodeAt(0));
  15490. }
  15491. },
  15492. has: function(i) {
  15493. return this._map[i] !== undefined;
  15494. },
  15495. get: function(i) {
  15496. return this._map[i];
  15497. },
  15498. charCodeOf: function(v) {
  15499. return this._map.indexOf(v);
  15500. }
  15501. };
  15502. return ToUnicodeMap;
  15503. })();
  15504. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15505. function IdentityToUnicodeMap(firstChar, lastChar) {
  15506. this.firstChar = firstChar;
  15507. this.lastChar = lastChar;
  15508. }
  15509. IdentityToUnicodeMap.prototype = {
  15510. get length() {
  15511. return (this.lastChar + 1) - this.firstChar;
  15512. },
  15513. forEach: function (callback) {
  15514. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15515. callback(i, i);
  15516. }
  15517. },
  15518. has: function (i) {
  15519. return this.firstChar <= i && i <= this.lastChar;
  15520. },
  15521. get: function (i) {
  15522. if (this.firstChar <= i && i <= this.lastChar) {
  15523. return String.fromCharCode(i);
  15524. }
  15525. return undefined;
  15526. },
  15527. charCodeOf: function (v) {
  15528. error('should not call .charCodeOf');
  15529. }
  15530. };
  15531. return IdentityToUnicodeMap;
  15532. })();
  15533. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15534. function writeInt16(dest, offset, num) {
  15535. dest[offset] = (num >> 8) & 0xFF;
  15536. dest[offset + 1] = num & 0xFF;
  15537. }
  15538. function writeInt32(dest, offset, num) {
  15539. dest[offset] = (num >> 24) & 0xFF;
  15540. dest[offset + 1] = (num >> 16) & 0xFF;
  15541. dest[offset + 2] = (num >> 8) & 0xFF;
  15542. dest[offset + 3] = num & 0xFF;
  15543. }
  15544. function writeData(dest, offset, data) {
  15545. var i, ii;
  15546. if (data instanceof Uint8Array) {
  15547. dest.set(data, offset);
  15548. } else if (typeof data === 'string') {
  15549. for (i = 0, ii = data.length; i < ii; i++) {
  15550. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15551. }
  15552. } else {
  15553. // treating everything else as array
  15554. for (i = 0, ii = data.length; i < ii; i++) {
  15555. dest[offset++] = data[i] & 0xFF;
  15556. }
  15557. }
  15558. }
  15559. function OpenTypeFileBuilder(sfnt) {
  15560. this.sfnt = sfnt;
  15561. this.tables = Object.create(null);
  15562. }
  15563. OpenTypeFileBuilder.getSearchParams =
  15564. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15565. var maxPower2 = 1, log2 = 0;
  15566. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15567. maxPower2 <<= 1;
  15568. log2++;
  15569. }
  15570. var searchRange = maxPower2 * entrySize;
  15571. return {
  15572. range: searchRange,
  15573. entry: log2,
  15574. rangeShift: entrySize * entriesCount - searchRange
  15575. };
  15576. };
  15577. var OTF_HEADER_SIZE = 12;
  15578. var OTF_TABLE_ENTRY_SIZE = 16;
  15579. OpenTypeFileBuilder.prototype = {
  15580. toArray: function OpenTypeFileBuilder_toArray() {
  15581. var sfnt = this.sfnt;
  15582. // Tables needs to be written by ascendant alphabetic order
  15583. var tables = this.tables;
  15584. var tablesNames = Object.keys(tables);
  15585. tablesNames.sort();
  15586. var numTables = tablesNames.length;
  15587. var i, j, jj, table, tableName;
  15588. // layout the tables data
  15589. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15590. var tableOffsets = [offset];
  15591. for (i = 0; i < numTables; i++) {
  15592. table = tables[tablesNames[i]];
  15593. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15594. offset += paddedLength;
  15595. tableOffsets.push(offset);
  15596. }
  15597. var file = new Uint8Array(offset);
  15598. // write the table data first (mostly for checksum)
  15599. for (i = 0; i < numTables; i++) {
  15600. table = tables[tablesNames[i]];
  15601. writeData(file, tableOffsets[i], table);
  15602. }
  15603. // sfnt version (4 bytes)
  15604. if (sfnt === 'true') {
  15605. // Windows hates the Mac TrueType sfnt version number
  15606. sfnt = string32(0x00010000);
  15607. }
  15608. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15609. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15610. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15611. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15612. // numTables (2 bytes)
  15613. writeInt16(file, 4, numTables);
  15614. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15615. // searchRange (2 bytes)
  15616. writeInt16(file, 6, searchParams.range);
  15617. // entrySelector (2 bytes)
  15618. writeInt16(file, 8, searchParams.entry);
  15619. // rangeShift (2 bytes)
  15620. writeInt16(file, 10, searchParams.rangeShift);
  15621. offset = OTF_HEADER_SIZE;
  15622. // writing table entries
  15623. for (i = 0; i < numTables; i++) {
  15624. tableName = tablesNames[i];
  15625. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15626. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15627. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15628. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15629. // checksum
  15630. var checksum = 0;
  15631. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15632. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15633. (file[j + 2] << 8) + file[j + 3];
  15634. checksum = (checksum + quad) | 0;
  15635. }
  15636. writeInt32(file, offset + 4, checksum);
  15637. // offset
  15638. writeInt32(file, offset + 8, tableOffsets[i]);
  15639. // length
  15640. writeInt32(file, offset + 12, tables[tableName].length);
  15641. offset += OTF_TABLE_ENTRY_SIZE;
  15642. }
  15643. return file;
  15644. },
  15645. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15646. if (tag in this.tables) {
  15647. throw new Error('Table ' + tag + ' already exists');
  15648. }
  15649. this.tables[tag] = data;
  15650. }
  15651. };
  15652. return OpenTypeFileBuilder;
  15653. })();
  15654. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  15655. // issues when they are painted on the canvas, e.g. complex-script shaping or
  15656. // control/whitespace characters. The ranges are listed in pairs: the first item
  15657. // is a code of the first problematic code, the second one is the next
  15658. // non-problematic code. The ranges must be in sorted order.
  15659. var ProblematicCharRanges = new Int32Array([
  15660. // Control characters.
  15661. 0x0000, 0x0020,
  15662. 0x007F, 0x00A1,
  15663. 0x00AD, 0x00AE,
  15664. // Chars that is used in complex-script shaping.
  15665. 0x0600, 0x0780,
  15666. 0x08A0, 0x10A0,
  15667. 0x1780, 0x1800,
  15668. // General punctuation chars.
  15669. 0x2000, 0x2010,
  15670. 0x2011, 0x2012,
  15671. 0x2028, 0x2030,
  15672. 0x205F, 0x2070,
  15673. 0x25CC, 0x25CD,
  15674. // Chars that is used in complex-script shaping.
  15675. 0xAA60, 0xAA80,
  15676. // Specials Unicode block.
  15677. 0xFFF0, 0x10000
  15678. ]);
  15679. /**
  15680. * 'Font' is the class the outside world should use, it encapsulate all the font
  15681. * decoding logics whatever type it is (assuming the font type is supported).
  15682. *
  15683. * For example to read a Type1 font and to attach it to the document:
  15684. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15685. * type1Font.bind();
  15686. */
  15687. var Font = (function FontClosure() {
  15688. function Font(name, file, properties) {
  15689. var charCode, glyphName, fontChar;
  15690. this.name = name;
  15691. this.loadedName = properties.loadedName;
  15692. this.isType3Font = properties.isType3Font;
  15693. this.sizes = [];
  15694. this.glyphCache = {};
  15695. var names = name.split('+');
  15696. names = names.length > 1 ? names[1] : names[0];
  15697. names = names.split(/[-,_]/g)[0];
  15698. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15699. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15700. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15701. var type = properties.type;
  15702. var subtype = properties.subtype;
  15703. this.type = type;
  15704. this.fallbackName = (this.isMonospace ? 'monospace' :
  15705. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15706. this.differences = properties.differences;
  15707. this.widths = properties.widths;
  15708. this.defaultWidth = properties.defaultWidth;
  15709. this.composite = properties.composite;
  15710. this.wideChars = properties.wideChars;
  15711. this.cMap = properties.cMap;
  15712. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15713. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15714. this.fontMatrix = properties.fontMatrix;
  15715. this.bbox = properties.bbox;
  15716. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15717. this.toFontChar = [];
  15718. if (properties.type === 'Type3') {
  15719. for (charCode = 0; charCode < 256; charCode++) {
  15720. this.toFontChar[charCode] = (this.differences[charCode] ||
  15721. properties.defaultEncoding[charCode]);
  15722. }
  15723. this.fontType = FontType.TYPE3;
  15724. return;
  15725. }
  15726. this.cidEncoding = properties.cidEncoding;
  15727. this.vertical = properties.vertical;
  15728. if (this.vertical) {
  15729. this.vmetrics = properties.vmetrics;
  15730. this.defaultVMetrics = properties.defaultVMetrics;
  15731. }
  15732. if (!file || file.isEmpty) {
  15733. if (file) {
  15734. // Some bad PDF generators will include empty font files,
  15735. // attempting to recover by assuming that no file exists.
  15736. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15737. }
  15738. this.missingFile = true;
  15739. // The file data is not specified. Trying to fix the font name
  15740. // to be used with the canvas.font.
  15741. var fontName = name.replace(/[,_]/g, '-');
  15742. var isStandardFont = !!stdFontMap[fontName] ||
  15743. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15744. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15745. this.bold = (fontName.search(/bold/gi) !== -1);
  15746. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15747. (fontName.search(/italic/gi) !== -1));
  15748. // Use 'name' instead of 'fontName' here because the original
  15749. // name ArialBlack for example will be replaced by Helvetica.
  15750. this.black = (name.search(/Black/g) !== -1);
  15751. // if at least one width is present, remeasure all chars when exists
  15752. this.remeasure = Object.keys(this.widths).length > 0;
  15753. if (isStandardFont && type === 'CIDFontType2' &&
  15754. properties.cidEncoding.indexOf('Identity-') === 0) {
  15755. // Standard fonts might be embedded as CID font without glyph mapping.
  15756. // Building one based on GlyphMapForStandardFonts.
  15757. var map = [];
  15758. for (charCode in GlyphMapForStandardFonts) {
  15759. map[+charCode] = GlyphMapForStandardFonts[charCode];
  15760. }
  15761. if (/ArialBlack/i.test(name)) {
  15762. for (charCode in SupplementalGlyphMapForArialBlack) {
  15763. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  15764. }
  15765. }
  15766. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15767. if (!isIdentityUnicode) {
  15768. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15769. map[+charCode] = unicodeCharCode;
  15770. });
  15771. }
  15772. this.toFontChar = map;
  15773. this.toUnicode = new ToUnicodeMap(map);
  15774. } else if (/Symbol/i.test(fontName)) {
  15775. var symbols = Encodings.SymbolSetEncoding;
  15776. for (charCode in symbols) {
  15777. fontChar = GlyphsUnicode[symbols[charCode]];
  15778. if (!fontChar) {
  15779. continue;
  15780. }
  15781. this.toFontChar[charCode] = fontChar;
  15782. }
  15783. for (charCode in properties.differences) {
  15784. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15785. if (!fontChar) {
  15786. continue;
  15787. }
  15788. this.toFontChar[charCode] = fontChar;
  15789. }
  15790. } else if (/Dingbats/i.test(fontName)) {
  15791. if (/Wingdings/i.test(name)) {
  15792. warn('Wingdings font without embedded font file, ' +
  15793. 'falling back to the ZapfDingbats encoding.');
  15794. }
  15795. var dingbats = Encodings.ZapfDingbatsEncoding;
  15796. for (charCode in dingbats) {
  15797. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15798. if (!fontChar) {
  15799. continue;
  15800. }
  15801. this.toFontChar[charCode] = fontChar;
  15802. }
  15803. for (charCode in properties.differences) {
  15804. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15805. if (!fontChar) {
  15806. continue;
  15807. }
  15808. this.toFontChar[charCode] = fontChar;
  15809. }
  15810. } else if (isStandardFont) {
  15811. this.toFontChar = [];
  15812. for (charCode in properties.defaultEncoding) {
  15813. glyphName = (properties.differences[charCode] ||
  15814. properties.defaultEncoding[charCode]);
  15815. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15816. }
  15817. } else {
  15818. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15819. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15820. if (notCidFont) {
  15821. glyphName = (properties.differences[charCode] ||
  15822. properties.defaultEncoding[charCode]);
  15823. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15824. }
  15825. this.toFontChar[charCode] = unicodeCharCode;
  15826. }.bind(this));
  15827. }
  15828. this.loadedName = fontName.split('-')[0];
  15829. this.loading = false;
  15830. this.fontType = getFontType(type, subtype);
  15831. return;
  15832. }
  15833. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15834. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15835. // Some TrueType fonts by mistake claim Type1C
  15836. if (isTrueTypeFile(file)) {
  15837. subtype = 'TrueType';
  15838. } else {
  15839. type = 'Type1';
  15840. }
  15841. }
  15842. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15843. type = 'CIDFontType0';
  15844. }
  15845. if (subtype === 'OpenType') {
  15846. type = 'OpenType';
  15847. }
  15848. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15849. if (type === 'CIDFontType0') {
  15850. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15851. }
  15852. var data;
  15853. switch (type) {
  15854. case 'MMType1':
  15855. info('MMType1 font (' + name + '), falling back to Type1.');
  15856. /* falls through */
  15857. case 'Type1':
  15858. case 'CIDFontType0':
  15859. this.mimetype = 'font/opentype';
  15860. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15861. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15862. adjustWidths(properties);
  15863. // Wrap the CFF data inside an OTF font file
  15864. data = this.convert(name, cff, properties);
  15865. break;
  15866. case 'OpenType':
  15867. case 'TrueType':
  15868. case 'CIDFontType2':
  15869. this.mimetype = 'font/opentype';
  15870. // Repair the TrueType file. It is can be damaged in the point of
  15871. // view of the sanitizer
  15872. data = this.checkAndRepair(name, file, properties);
  15873. if (this.isOpenType) {
  15874. type = 'OpenType';
  15875. }
  15876. break;
  15877. default:
  15878. error('Font ' + type + ' is not supported');
  15879. break;
  15880. }
  15881. this.data = data;
  15882. this.fontType = getFontType(type, subtype);
  15883. // Transfer some properties again that could change during font conversion
  15884. this.fontMatrix = properties.fontMatrix;
  15885. this.widths = properties.widths;
  15886. this.defaultWidth = properties.defaultWidth;
  15887. this.encoding = properties.baseEncoding;
  15888. this.seacMap = properties.seacMap;
  15889. this.loading = true;
  15890. }
  15891. Font.getFontID = (function () {
  15892. var ID = 1;
  15893. return function Font_getFontID() {
  15894. return String(ID++);
  15895. };
  15896. })();
  15897. function int16(b0, b1) {
  15898. return (b0 << 8) + b1;
  15899. }
  15900. function int32(b0, b1, b2, b3) {
  15901. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15902. }
  15903. function string16(value) {
  15904. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15905. }
  15906. function safeString16(value) {
  15907. // clamp value to the 16-bit int range
  15908. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15909. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15910. }
  15911. function isTrueTypeFile(file) {
  15912. var header = file.peekBytes(4);
  15913. return readUint32(header, 0) === 0x00010000;
  15914. }
  15915. function isType1File(file) {
  15916. var header = file.peekBytes(2);
  15917. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15918. if (header[0] === 0x25 && header[1] === 0x21) {
  15919. return true;
  15920. }
  15921. // ... obviously some fonts violate that part of the specification,
  15922. // please refer to the comment in |Type1Font| below.
  15923. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15924. return true;
  15925. }
  15926. return false;
  15927. }
  15928. /**
  15929. * Helper function for |adjustMapping|.
  15930. * @return {boolean}
  15931. */
  15932. function isProblematicUnicodeLocation(code) {
  15933. // Using binary search to find a range start.
  15934. var i = 0, j = ProblematicCharRanges.length - 1;
  15935. while (i < j) {
  15936. var c = (i + j + 1) >> 1;
  15937. if (code < ProblematicCharRanges[c]) {
  15938. j = c - 1;
  15939. } else {
  15940. i = c;
  15941. }
  15942. }
  15943. // Even index means code in problematic range.
  15944. return !(i & 1);
  15945. }
  15946. /**
  15947. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15948. * with their unicode value. It also moves char codes that are in known
  15949. * problematic locations.
  15950. * @return {Object} Two properties:
  15951. * 'toFontChar' - maps original char codes(the value that will be read
  15952. * from commands such as show text) to the char codes that will be used in the
  15953. * font that we build
  15954. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15955. */
  15956. function adjustMapping(charCodeToGlyphId, properties) {
  15957. var toUnicode = properties.toUnicode;
  15958. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15959. var isIdentityUnicode =
  15960. properties.toUnicode instanceof IdentityToUnicodeMap;
  15961. var newMap = Object.create(null);
  15962. var toFontChar = [];
  15963. var usedFontCharCodes = [];
  15964. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15965. for (var originalCharCode in charCodeToGlyphId) {
  15966. originalCharCode |= 0;
  15967. var glyphId = charCodeToGlyphId[originalCharCode];
  15968. var fontCharCode = originalCharCode;
  15969. // First try to map the value to a unicode position if a non identity map
  15970. // was created.
  15971. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15972. var unicode = toUnicode.get(fontCharCode);
  15973. // TODO: Try to map ligatures to the correct spot.
  15974. if (unicode.length === 1) {
  15975. fontCharCode = unicode.charCodeAt(0);
  15976. }
  15977. }
  15978. // Try to move control characters, special characters and already mapped
  15979. // characters to the private use area since they will not be drawn by
  15980. // canvas if left in their current position. Also, move characters if the
  15981. // font was symbolic and there is only an identity unicode map since the
  15982. // characters probably aren't in the correct position (fixes an issue
  15983. // with firefox and thuluthfont).
  15984. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15985. isProblematicUnicodeLocation(fontCharCode) ||
  15986. (isSymbolic && isIdentityUnicode)) &&
  15987. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15988. // Loop to try and find a free spot in the private use area.
  15989. do {
  15990. fontCharCode = nextAvailableFontCharCode++;
  15991. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15992. fontCharCode = 0xF020;
  15993. nextAvailableFontCharCode = fontCharCode + 1;
  15994. }
  15995. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15996. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15997. }
  15998. newMap[fontCharCode] = glyphId;
  15999. toFontChar[originalCharCode] = fontCharCode;
  16000. usedFontCharCodes[fontCharCode] = true;
  16001. }
  16002. return {
  16003. toFontChar: toFontChar,
  16004. charCodeToGlyphId: newMap,
  16005. nextAvailableFontCharCode: nextAvailableFontCharCode
  16006. };
  16007. }
  16008. function getRanges(glyphs) {
  16009. // Array.sort() sorts by characters, not numerically, so convert to an
  16010. // array of characters.
  16011. var codes = [];
  16012. for (var charCode in glyphs) {
  16013. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  16014. }
  16015. codes.sort(function fontGetRangesSort(a, b) {
  16016. return a.fontCharCode - b.fontCharCode;
  16017. });
  16018. // Split the sorted codes into ranges.
  16019. var ranges = [];
  16020. var length = codes.length;
  16021. for (var n = 0; n < length; ) {
  16022. var start = codes[n].fontCharCode;
  16023. var codeIndices = [codes[n].glyphId];
  16024. ++n;
  16025. var end = start;
  16026. while (n < length && end + 1 === codes[n].fontCharCode) {
  16027. codeIndices.push(codes[n].glyphId);
  16028. ++end;
  16029. ++n;
  16030. if (end === 0xFFFF) {
  16031. break;
  16032. }
  16033. }
  16034. ranges.push([start, end, codeIndices]);
  16035. }
  16036. return ranges;
  16037. }
  16038. function createCmapTable(glyphs) {
  16039. var ranges = getRanges(glyphs);
  16040. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  16041. var cmap = '\x00\x00' + // version
  16042. string16(numTables) + // numTables
  16043. '\x00\x03' + // platformID
  16044. '\x00\x01' + // encodingID
  16045. string32(4 + numTables * 8); // start of the table record
  16046. var i, ii, j, jj;
  16047. for (i = ranges.length - 1; i >= 0; --i) {
  16048. if (ranges[i][0] <= 0xFFFF) { break; }
  16049. }
  16050. var bmpLength = i + 1;
  16051. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  16052. ranges[i][1] = 0xFFFE;
  16053. }
  16054. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  16055. var segCount = bmpLength + trailingRangesCount;
  16056. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  16057. // Fill up the 4 parallel arrays describing the segments.
  16058. var startCount = '';
  16059. var endCount = '';
  16060. var idDeltas = '';
  16061. var idRangeOffsets = '';
  16062. var glyphsIds = '';
  16063. var bias = 0;
  16064. var range, start, end, codes;
  16065. for (i = 0, ii = bmpLength; i < ii; i++) {
  16066. range = ranges[i];
  16067. start = range[0];
  16068. end = range[1];
  16069. startCount += string16(start);
  16070. endCount += string16(end);
  16071. codes = range[2];
  16072. var contiguous = true;
  16073. for (j = 1, jj = codes.length; j < jj; ++j) {
  16074. if (codes[j] !== codes[j - 1] + 1) {
  16075. contiguous = false;
  16076. break;
  16077. }
  16078. }
  16079. if (!contiguous) {
  16080. var offset = (segCount - i) * 2 + bias * 2;
  16081. bias += (end - start + 1);
  16082. idDeltas += string16(0);
  16083. idRangeOffsets += string16(offset);
  16084. for (j = 0, jj = codes.length; j < jj; ++j) {
  16085. glyphsIds += string16(codes[j]);
  16086. }
  16087. } else {
  16088. var startCode = codes[0];
  16089. idDeltas += string16((startCode - start) & 0xFFFF);
  16090. idRangeOffsets += string16(0);
  16091. }
  16092. }
  16093. if (trailingRangesCount > 0) {
  16094. endCount += '\xFF\xFF';
  16095. startCount += '\xFF\xFF';
  16096. idDeltas += '\x00\x01';
  16097. idRangeOffsets += '\x00\x00';
  16098. }
  16099. var format314 = '\x00\x00' + // language
  16100. string16(2 * segCount) +
  16101. string16(searchParams.range) +
  16102. string16(searchParams.entry) +
  16103. string16(searchParams.rangeShift) +
  16104. endCount + '\x00\x00' + startCount +
  16105. idDeltas + idRangeOffsets + glyphsIds;
  16106. var format31012 = '';
  16107. var header31012 = '';
  16108. if (numTables > 1) {
  16109. cmap += '\x00\x03' + // platformID
  16110. '\x00\x0A' + // encodingID
  16111. string32(4 + numTables * 8 +
  16112. 4 + format314.length); // start of the table record
  16113. format31012 = '';
  16114. for (i = 0, ii = ranges.length; i < ii; i++) {
  16115. range = ranges[i];
  16116. start = range[0];
  16117. codes = range[2];
  16118. var code = codes[0];
  16119. for (j = 1, jj = codes.length; j < jj; ++j) {
  16120. if (codes[j] !== codes[j - 1] + 1) {
  16121. end = range[0] + j - 1;
  16122. format31012 += string32(start) + // startCharCode
  16123. string32(end) + // endCharCode
  16124. string32(code); // startGlyphID
  16125. start = end + 1;
  16126. code = codes[j];
  16127. }
  16128. }
  16129. format31012 += string32(start) + // startCharCode
  16130. string32(range[1]) + // endCharCode
  16131. string32(code); // startGlyphID
  16132. }
  16133. header31012 = '\x00\x0C' + // format
  16134. '\x00\x00' + // reserved
  16135. string32(format31012.length + 16) + // length
  16136. '\x00\x00\x00\x00' + // language
  16137. string32(format31012.length / 12); // nGroups
  16138. }
  16139. return cmap + '\x00\x04' + // format
  16140. string16(format314.length + 4) + // length
  16141. format314 + header31012 + format31012;
  16142. }
  16143. function validateOS2Table(os2) {
  16144. var stream = new Stream(os2.data);
  16145. var version = stream.getUint16();
  16146. // TODO verify all OS/2 tables fields, but currently we validate only those
  16147. // that give us issues
  16148. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  16149. var selection = stream.getUint16();
  16150. if (version < 4 && (selection & 0x0300)) {
  16151. return false;
  16152. }
  16153. var firstChar = stream.getUint16();
  16154. var lastChar = stream.getUint16();
  16155. if (firstChar > lastChar) {
  16156. return false;
  16157. }
  16158. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  16159. var usWinAscent = stream.getUint16();
  16160. if (usWinAscent === 0) { // makes font unreadable by windows
  16161. return false;
  16162. }
  16163. // OS/2 appears to be valid, resetting some fields
  16164. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  16165. return true;
  16166. }
  16167. function createOS2Table(properties, charstrings, override) {
  16168. override = override || {
  16169. unitsPerEm: 0,
  16170. yMax: 0,
  16171. yMin: 0,
  16172. ascent: 0,
  16173. descent: 0
  16174. };
  16175. var ulUnicodeRange1 = 0;
  16176. var ulUnicodeRange2 = 0;
  16177. var ulUnicodeRange3 = 0;
  16178. var ulUnicodeRange4 = 0;
  16179. var firstCharIndex = null;
  16180. var lastCharIndex = 0;
  16181. if (charstrings) {
  16182. for (var code in charstrings) {
  16183. code |= 0;
  16184. if (firstCharIndex > code || !firstCharIndex) {
  16185. firstCharIndex = code;
  16186. }
  16187. if (lastCharIndex < code) {
  16188. lastCharIndex = code;
  16189. }
  16190. var position = getUnicodeRangeFor(code);
  16191. if (position < 32) {
  16192. ulUnicodeRange1 |= 1 << position;
  16193. } else if (position < 64) {
  16194. ulUnicodeRange2 |= 1 << position - 32;
  16195. } else if (position < 96) {
  16196. ulUnicodeRange3 |= 1 << position - 64;
  16197. } else if (position < 123) {
  16198. ulUnicodeRange4 |= 1 << position - 96;
  16199. } else {
  16200. error('Unicode ranges Bits > 123 are reserved for internal usage');
  16201. }
  16202. }
  16203. } else {
  16204. // TODO
  16205. firstCharIndex = 0;
  16206. lastCharIndex = 255;
  16207. }
  16208. var bbox = properties.bbox || [0, 0, 0, 0];
  16209. var unitsPerEm = (override.unitsPerEm ||
  16210. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  16211. // if the font units differ to the PDF glyph space units
  16212. // then scale up the values
  16213. var scale = (properties.ascentScaled ? 1.0 :
  16214. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  16215. var typoAscent = (override.ascent ||
  16216. Math.round(scale * (properties.ascent || bbox[3])));
  16217. var typoDescent = (override.descent ||
  16218. Math.round(scale * (properties.descent || bbox[1])));
  16219. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  16220. typoDescent = -typoDescent; // fixing incorrect descent
  16221. }
  16222. var winAscent = override.yMax || typoAscent;
  16223. var winDescent = -override.yMin || -typoDescent;
  16224. return '\x00\x03' + // version
  16225. '\x02\x24' + // xAvgCharWidth
  16226. '\x01\xF4' + // usWeightClass
  16227. '\x00\x05' + // usWidthClass
  16228. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  16229. '\x02\x8A' + // ySubscriptXSize
  16230. '\x02\xBB' + // ySubscriptYSize
  16231. '\x00\x00' + // ySubscriptXOffset
  16232. '\x00\x8C' + // ySubscriptYOffset
  16233. '\x02\x8A' + // ySuperScriptXSize
  16234. '\x02\xBB' + // ySuperScriptYSize
  16235. '\x00\x00' + // ySuperScriptXOffset
  16236. '\x01\xDF' + // ySuperScriptYOffset
  16237. '\x00\x31' + // yStrikeOutSize
  16238. '\x01\x02' + // yStrikeOutPosition
  16239. '\x00\x00' + // sFamilyClass
  16240. '\x00\x00\x06' +
  16241. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  16242. '\x00\x00\x00\x00\x00\x00' + // Panose
  16243. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  16244. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  16245. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  16246. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  16247. '\x2A\x32\x31\x2A' + // achVendID
  16248. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  16249. string16(firstCharIndex ||
  16250. properties.firstChar) + // usFirstCharIndex
  16251. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  16252. string16(typoAscent) + // sTypoAscender
  16253. string16(typoDescent) + // sTypoDescender
  16254. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  16255. string16(winAscent) + // usWinAscent
  16256. string16(winDescent) + // usWinDescent
  16257. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  16258. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  16259. string16(properties.xHeight) + // sxHeight
  16260. string16(properties.capHeight) + // sCapHeight
  16261. string16(0) + // usDefaultChar
  16262. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  16263. '\x00\x03'; // usMaxContext
  16264. }
  16265. function createPostTable(properties) {
  16266. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  16267. return ('\x00\x03\x00\x00' + // Version number
  16268. string32(angle) + // italicAngle
  16269. '\x00\x00' + // underlinePosition
  16270. '\x00\x00' + // underlineThickness
  16271. string32(properties.fixedPitch) + // isFixedPitch
  16272. '\x00\x00\x00\x00' + // minMemType42
  16273. '\x00\x00\x00\x00' + // maxMemType42
  16274. '\x00\x00\x00\x00' + // minMemType1
  16275. '\x00\x00\x00\x00'); // maxMemType1
  16276. }
  16277. function createNameTable(name, proto) {
  16278. if (!proto) {
  16279. proto = [[], []]; // no strings and unicode strings
  16280. }
  16281. var strings = [
  16282. proto[0][0] || 'Original licence', // 0.Copyright
  16283. proto[0][1] || name, // 1.Font family
  16284. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  16285. proto[0][3] || 'uniqueID', // 3.Unique ID
  16286. proto[0][4] || name, // 4.Full font name
  16287. proto[0][5] || 'Version 0.11', // 5.Version
  16288. proto[0][6] || '', // 6.Postscript name
  16289. proto[0][7] || 'Unknown', // 7.Trademark
  16290. proto[0][8] || 'Unknown', // 8.Manufacturer
  16291. proto[0][9] || 'Unknown' // 9.Designer
  16292. ];
  16293. // Mac want 1-byte per character strings while Windows want
  16294. // 2-bytes per character, so duplicate the names table
  16295. var stringsUnicode = [];
  16296. var i, ii, j, jj, str;
  16297. for (i = 0, ii = strings.length; i < ii; i++) {
  16298. str = proto[1][i] || strings[i];
  16299. var strBufUnicode = [];
  16300. for (j = 0, jj = str.length; j < jj; j++) {
  16301. strBufUnicode.push(string16(str.charCodeAt(j)));
  16302. }
  16303. stringsUnicode.push(strBufUnicode.join(''));
  16304. }
  16305. var names = [strings, stringsUnicode];
  16306. var platforms = ['\x00\x01', '\x00\x03'];
  16307. var encodings = ['\x00\x00', '\x00\x01'];
  16308. var languages = ['\x00\x00', '\x04\x09'];
  16309. var namesRecordCount = strings.length * platforms.length;
  16310. var nameTable =
  16311. '\x00\x00' + // format
  16312. string16(namesRecordCount) + // Number of names Record
  16313. string16(namesRecordCount * 12 + 6); // Storage
  16314. // Build the name records field
  16315. var strOffset = 0;
  16316. for (i = 0, ii = platforms.length; i < ii; i++) {
  16317. var strs = names[i];
  16318. for (j = 0, jj = strs.length; j < jj; j++) {
  16319. str = strs[j];
  16320. var nameRecord =
  16321. platforms[i] + // platform ID
  16322. encodings[i] + // encoding ID
  16323. languages[i] + // language ID
  16324. string16(j) + // name ID
  16325. string16(str.length) +
  16326. string16(strOffset);
  16327. nameTable += nameRecord;
  16328. strOffset += str.length;
  16329. }
  16330. }
  16331. nameTable += strings.join('') + stringsUnicode.join('');
  16332. return nameTable;
  16333. }
  16334. Font.prototype = {
  16335. name: null,
  16336. font: null,
  16337. mimetype: null,
  16338. encoding: null,
  16339. get renderer() {
  16340. var renderer = FontRendererFactory.create(this);
  16341. return shadow(this, 'renderer', renderer);
  16342. },
  16343. exportData: function Font_exportData() {
  16344. var data = {};
  16345. for (var i in this) {
  16346. if (this.hasOwnProperty(i)) {
  16347. data[i] = this[i];
  16348. }
  16349. }
  16350. return data;
  16351. },
  16352. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  16353. function readTableEntry(file) {
  16354. var tag = bytesToString(file.getBytes(4));
  16355. var checksum = file.getInt32();
  16356. var offset = file.getInt32() >>> 0;
  16357. var length = file.getInt32() >>> 0;
  16358. // Read the table associated data
  16359. var previousPosition = file.pos;
  16360. file.pos = file.start ? file.start : 0;
  16361. file.skip(offset);
  16362. var data = file.getBytes(length);
  16363. file.pos = previousPosition;
  16364. if (tag === 'head') {
  16365. // clearing checksum adjustment
  16366. data[8] = data[9] = data[10] = data[11] = 0;
  16367. data[17] |= 0x20; //Set font optimized for cleartype flag
  16368. }
  16369. return {
  16370. tag: tag,
  16371. checksum: checksum,
  16372. length: length,
  16373. offset: offset,
  16374. data: data
  16375. };
  16376. }
  16377. function readOpenTypeHeader(ttf) {
  16378. return {
  16379. version: bytesToString(ttf.getBytes(4)),
  16380. numTables: ttf.getUint16(),
  16381. searchRange: ttf.getUint16(),
  16382. entrySelector: ttf.getUint16(),
  16383. rangeShift: ttf.getUint16()
  16384. };
  16385. }
  16386. /**
  16387. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  16388. * PDF spec
  16389. */
  16390. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  16391. if (!cmap) {
  16392. warn('No cmap table available.');
  16393. return {
  16394. platformId: -1,
  16395. encodingId: -1,
  16396. mappings: [],
  16397. hasShortCmap: false
  16398. };
  16399. }
  16400. var segment;
  16401. var start = (font.start ? font.start : 0) + cmap.offset;
  16402. font.pos = start;
  16403. var version = font.getUint16();
  16404. var numTables = font.getUint16();
  16405. var potentialTable;
  16406. var canBreak = false;
  16407. // There's an order of preference in terms of which cmap subtable to
  16408. // use:
  16409. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  16410. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  16411. // The following takes advantage of the fact that the tables are sorted
  16412. // to work.
  16413. for (var i = 0; i < numTables; i++) {
  16414. var platformId = font.getUint16();
  16415. var encodingId = font.getUint16();
  16416. var offset = font.getInt32() >>> 0;
  16417. var useTable = false;
  16418. if (platformId === 0 && encodingId === 0) {
  16419. useTable = true;
  16420. // Continue the loop since there still may be a higher priority
  16421. // table.
  16422. } else if (platformId === 1 && encodingId === 0) {
  16423. useTable = true;
  16424. // Continue the loop since there still may be a higher priority
  16425. // table.
  16426. } else if (platformId === 3 && encodingId === 1 &&
  16427. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  16428. useTable = true;
  16429. if (!isSymbolicFont) {
  16430. canBreak = true;
  16431. }
  16432. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  16433. useTable = true;
  16434. canBreak = true;
  16435. }
  16436. if (useTable) {
  16437. potentialTable = {
  16438. platformId: platformId,
  16439. encodingId: encodingId,
  16440. offset: offset
  16441. };
  16442. }
  16443. if (canBreak) {
  16444. break;
  16445. }
  16446. }
  16447. if (potentialTable) {
  16448. font.pos = start + potentialTable.offset;
  16449. }
  16450. if (!potentialTable || font.peekByte() === -1) {
  16451. warn('Could not find a preferred cmap table.');
  16452. return {
  16453. platformId: -1,
  16454. encodingId: -1,
  16455. mappings: [],
  16456. hasShortCmap: false
  16457. };
  16458. }
  16459. var format = font.getUint16();
  16460. var length = font.getUint16();
  16461. var language = font.getUint16();
  16462. var hasShortCmap = false;
  16463. var mappings = [];
  16464. var j, glyphId;
  16465. // TODO(mack): refactor this cmap subtable reading logic out
  16466. if (format === 0) {
  16467. for (j = 0; j < 256; j++) {
  16468. var index = font.getByte();
  16469. if (!index) {
  16470. continue;
  16471. }
  16472. mappings.push({
  16473. charCode: j,
  16474. glyphId: index
  16475. });
  16476. }
  16477. hasShortCmap = true;
  16478. } else if (format === 4) {
  16479. // re-creating the table in format 4 since the encoding
  16480. // might be changed
  16481. var segCount = (font.getUint16() >> 1);
  16482. font.getBytes(6); // skipping range fields
  16483. var segIndex, segments = [];
  16484. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16485. segments.push({ end: font.getUint16() });
  16486. }
  16487. font.getUint16();
  16488. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16489. segments[segIndex].start = font.getUint16();
  16490. }
  16491. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16492. segments[segIndex].delta = font.getUint16();
  16493. }
  16494. var offsetsCount = 0;
  16495. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16496. segment = segments[segIndex];
  16497. var rangeOffset = font.getUint16();
  16498. if (!rangeOffset) {
  16499. segment.offsetIndex = -1;
  16500. continue;
  16501. }
  16502. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16503. segment.offsetIndex = offsetIndex;
  16504. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16505. segment.end - segment.start + 1);
  16506. }
  16507. var offsets = [];
  16508. for (j = 0; j < offsetsCount; j++) {
  16509. offsets.push(font.getUint16());
  16510. }
  16511. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16512. segment = segments[segIndex];
  16513. start = segment.start;
  16514. var end = segment.end;
  16515. var delta = segment.delta;
  16516. offsetIndex = segment.offsetIndex;
  16517. for (j = start; j <= end; j++) {
  16518. if (j === 0xFFFF) {
  16519. continue;
  16520. }
  16521. glyphId = (offsetIndex < 0 ?
  16522. j : offsets[offsetIndex + j - start]);
  16523. glyphId = (glyphId + delta) & 0xFFFF;
  16524. if (glyphId === 0) {
  16525. continue;
  16526. }
  16527. mappings.push({
  16528. charCode: j,
  16529. glyphId: glyphId
  16530. });
  16531. }
  16532. }
  16533. } else if (format === 6) {
  16534. // Format 6 is a 2-bytes dense mapping, which means the font data
  16535. // lives glue together even if they are pretty far in the unicode
  16536. // table. (This looks weird, so I can have missed something), this
  16537. // works on Linux but seems to fails on Mac so let's rewrite the
  16538. // cmap table to a 3-1-4 style
  16539. var firstCode = font.getUint16();
  16540. var entryCount = font.getUint16();
  16541. for (j = 0; j < entryCount; j++) {
  16542. glyphId = font.getUint16();
  16543. var charCode = firstCode + j;
  16544. mappings.push({
  16545. charCode: charCode,
  16546. glyphId: glyphId
  16547. });
  16548. }
  16549. } else {
  16550. warn('cmap table has unsupported format: ' + format);
  16551. return {
  16552. platformId: -1,
  16553. encodingId: -1,
  16554. mappings: [],
  16555. hasShortCmap: false
  16556. };
  16557. }
  16558. // removing duplicate entries
  16559. mappings.sort(function (a, b) {
  16560. return a.charCode - b.charCode;
  16561. });
  16562. for (i = 1; i < mappings.length; i++) {
  16563. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16564. mappings.splice(i, 1);
  16565. i--;
  16566. }
  16567. }
  16568. return {
  16569. platformId: potentialTable.platformId,
  16570. encodingId: potentialTable.encodingId,
  16571. mappings: mappings,
  16572. hasShortCmap: hasShortCmap
  16573. };
  16574. }
  16575. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16576. if (!header) {
  16577. if (metrics) {
  16578. metrics.data = null;
  16579. }
  16580. return;
  16581. }
  16582. font.pos = (font.start ? font.start : 0) + header.offset;
  16583. font.pos += header.length - 2;
  16584. var numOfMetrics = font.getUint16();
  16585. if (numOfMetrics > numGlyphs) {
  16586. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16587. 'greater than the numGlyphs (' + numGlyphs + ')');
  16588. // Reduce numOfMetrics if it is greater than numGlyphs
  16589. numOfMetrics = numGlyphs;
  16590. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16591. header.data[35] = numOfMetrics & 0x00ff;
  16592. }
  16593. var numOfSidebearings = numGlyphs - numOfMetrics;
  16594. var numMissing = numOfSidebearings -
  16595. ((metrics.length - numOfMetrics * 4) >> 1);
  16596. if (numMissing > 0) {
  16597. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16598. // Since we need to add two properties for each glyph, this explains
  16599. // the use of |numMissing * 2| when initializing the typed array.
  16600. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16601. entries.set(metrics.data);
  16602. metrics.data = entries;
  16603. }
  16604. }
  16605. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16606. hintsValid) {
  16607. if (sourceEnd - sourceStart <= 12) {
  16608. // glyph with data less than 12 is invalid one
  16609. return 0;
  16610. }
  16611. var glyf = source.subarray(sourceStart, sourceEnd);
  16612. var contoursCount = (glyf[0] << 8) | glyf[1];
  16613. if (contoursCount & 0x8000) {
  16614. // complex glyph, writing as is
  16615. dest.set(glyf, destStart);
  16616. return glyf.length;
  16617. }
  16618. var i, j = 10, flagsCount = 0;
  16619. for (i = 0; i < contoursCount; i++) {
  16620. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16621. flagsCount = endPoint + 1;
  16622. j += 2;
  16623. }
  16624. // skipping instructions
  16625. var instructionsStart = j;
  16626. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16627. j += 2 + instructionsLength;
  16628. var instructionsEnd = j;
  16629. // validating flags
  16630. var coordinatesLength = 0;
  16631. for (i = 0; i < flagsCount; i++) {
  16632. var flag = glyf[j++];
  16633. if (flag & 0xC0) {
  16634. // reserved flags must be zero, cleaning up
  16635. glyf[j - 1] = flag & 0x3F;
  16636. }
  16637. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16638. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16639. coordinatesLength += xyLength;
  16640. if (flag & 8) {
  16641. var repeat = glyf[j++];
  16642. i += repeat;
  16643. coordinatesLength += repeat * xyLength;
  16644. }
  16645. }
  16646. // glyph without coordinates will be rejected
  16647. if (coordinatesLength === 0) {
  16648. return 0;
  16649. }
  16650. var glyphDataLength = j + coordinatesLength;
  16651. if (glyphDataLength > glyf.length) {
  16652. // not enough data for coordinates
  16653. return 0;
  16654. }
  16655. if (!hintsValid && instructionsLength > 0) {
  16656. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16657. dest.set([0, 0], destStart + instructionsStart);
  16658. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16659. destStart + instructionsStart + 2);
  16660. glyphDataLength -= instructionsLength;
  16661. if (glyf.length - glyphDataLength > 3) {
  16662. glyphDataLength = (glyphDataLength + 3) & ~3;
  16663. }
  16664. return glyphDataLength;
  16665. }
  16666. if (glyf.length - glyphDataLength > 3) {
  16667. // truncating and aligning to 4 bytes the long glyph data
  16668. glyphDataLength = (glyphDataLength + 3) & ~3;
  16669. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16670. return glyphDataLength;
  16671. }
  16672. // glyph data is fine
  16673. dest.set(glyf, destStart);
  16674. return glyf.length;
  16675. }
  16676. function sanitizeHead(head, numGlyphs, locaLength) {
  16677. var data = head.data;
  16678. // Validate version:
  16679. // Should always be 0x00010000
  16680. var version = int32(data[0], data[1], data[2], data[3]);
  16681. if (version >> 16 !== 1) {
  16682. info('Attempting to fix invalid version in head table: ' + version);
  16683. data[0] = 0;
  16684. data[1] = 1;
  16685. data[2] = 0;
  16686. data[3] = 0;
  16687. }
  16688. var indexToLocFormat = int16(data[50], data[51]);
  16689. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16690. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16691. indexToLocFormat);
  16692. // The value of indexToLocFormat should be 0 if the loca table
  16693. // consists of short offsets, and should be 1 if the loca table
  16694. // consists of long offsets.
  16695. //
  16696. // The number of entries in the loca table should be numGlyphs + 1.
  16697. //
  16698. // Using this information, we can work backwards to deduce if the
  16699. // size of each offset in the loca table, and thus figure out the
  16700. // appropriate value for indexToLocFormat.
  16701. var numGlyphsPlusOne = numGlyphs + 1;
  16702. if (locaLength === numGlyphsPlusOne << 1) {
  16703. // 0x0000 indicates the loca table consists of short offsets
  16704. data[50] = 0;
  16705. data[51] = 0;
  16706. } else if (locaLength === numGlyphsPlusOne << 2) {
  16707. // 0x0001 indicates the loca table consists of long offsets
  16708. data[50] = 0;
  16709. data[51] = 1;
  16710. } else {
  16711. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16712. }
  16713. }
  16714. }
  16715. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16716. isGlyphLocationsLong, hintsValid,
  16717. dupFirstEntry) {
  16718. var itemSize, itemDecode, itemEncode;
  16719. if (isGlyphLocationsLong) {
  16720. itemSize = 4;
  16721. itemDecode = function fontItemDecodeLong(data, offset) {
  16722. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16723. (data[offset + 2] << 8) | data[offset + 3];
  16724. };
  16725. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16726. data[offset] = (value >>> 24) & 0xFF;
  16727. data[offset + 1] = (value >> 16) & 0xFF;
  16728. data[offset + 2] = (value >> 8) & 0xFF;
  16729. data[offset + 3] = value & 0xFF;
  16730. };
  16731. } else {
  16732. itemSize = 2;
  16733. itemDecode = function fontItemDecode(data, offset) {
  16734. return (data[offset] << 9) | (data[offset + 1] << 1);
  16735. };
  16736. itemEncode = function fontItemEncode(data, offset, value) {
  16737. data[offset] = (value >> 9) & 0xFF;
  16738. data[offset + 1] = (value >> 1) & 0xFF;
  16739. };
  16740. }
  16741. var locaData = loca.data;
  16742. var locaDataSize = itemSize * (1 + numGlyphs);
  16743. // is loca.data too short or long?
  16744. if (locaData.length !== locaDataSize) {
  16745. locaData = new Uint8Array(locaDataSize);
  16746. locaData.set(loca.data.subarray(0, locaDataSize));
  16747. loca.data = locaData;
  16748. }
  16749. // removing the invalid glyphs
  16750. var oldGlyfData = glyf.data;
  16751. var oldGlyfDataLength = oldGlyfData.length;
  16752. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16753. var startOffset = itemDecode(locaData, 0);
  16754. var writeOffset = 0;
  16755. var missingGlyphData = {};
  16756. itemEncode(locaData, 0, writeOffset);
  16757. var i, j;
  16758. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16759. var endOffset = itemDecode(locaData, j);
  16760. if (endOffset > oldGlyfDataLength &&
  16761. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16762. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16763. // the glyf table size, which makes last glyph out of range.
  16764. endOffset = oldGlyfDataLength;
  16765. }
  16766. if (endOffset > oldGlyfDataLength) {
  16767. // glyph end offset points outside glyf data, rejecting the glyph
  16768. itemEncode(locaData, j, writeOffset);
  16769. startOffset = endOffset;
  16770. continue;
  16771. }
  16772. if (startOffset === endOffset) {
  16773. missingGlyphData[i] = true;
  16774. }
  16775. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16776. newGlyfData, writeOffset, hintsValid);
  16777. writeOffset += newLength;
  16778. itemEncode(locaData, j, writeOffset);
  16779. startOffset = endOffset;
  16780. }
  16781. if (writeOffset === 0) {
  16782. // glyf table cannot be empty -- redoing the glyf and loca tables
  16783. // to have single glyph with one point
  16784. var simpleGlyph = new Uint8Array(
  16785. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16786. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16787. itemEncode(locaData, j, simpleGlyph.length);
  16788. }
  16789. glyf.data = simpleGlyph;
  16790. return missingGlyphData;
  16791. }
  16792. if (dupFirstEntry) {
  16793. var firstEntryLength = itemDecode(locaData, itemSize);
  16794. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16795. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16796. } else {
  16797. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16798. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16799. }
  16800. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16801. itemEncode(loca.data, locaData.length - itemSize,
  16802. writeOffset + firstEntryLength);
  16803. } else {
  16804. glyf.data = newGlyfData.subarray(0, writeOffset);
  16805. }
  16806. return missingGlyphData;
  16807. }
  16808. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16809. var start = (font.start ? font.start : 0) + post.offset;
  16810. font.pos = start;
  16811. var length = post.length, end = start + length;
  16812. var version = font.getInt32();
  16813. // skip rest to the tables
  16814. font.getBytes(28);
  16815. var glyphNames;
  16816. var valid = true;
  16817. var i;
  16818. switch (version) {
  16819. case 0x00010000:
  16820. glyphNames = MacStandardGlyphOrdering;
  16821. break;
  16822. case 0x00020000:
  16823. var numGlyphs = font.getUint16();
  16824. if (numGlyphs !== maxpNumGlyphs) {
  16825. valid = false;
  16826. break;
  16827. }
  16828. var glyphNameIndexes = [];
  16829. for (i = 0; i < numGlyphs; ++i) {
  16830. var index = font.getUint16();
  16831. if (index >= 32768) {
  16832. valid = false;
  16833. break;
  16834. }
  16835. glyphNameIndexes.push(index);
  16836. }
  16837. if (!valid) {
  16838. break;
  16839. }
  16840. var customNames = [];
  16841. var strBuf = [];
  16842. while (font.pos < end) {
  16843. var stringLength = font.getByte();
  16844. strBuf.length = stringLength;
  16845. for (i = 0; i < stringLength; ++i) {
  16846. strBuf[i] = String.fromCharCode(font.getByte());
  16847. }
  16848. customNames.push(strBuf.join(''));
  16849. }
  16850. glyphNames = [];
  16851. for (i = 0; i < numGlyphs; ++i) {
  16852. var j = glyphNameIndexes[i];
  16853. if (j < 258) {
  16854. glyphNames.push(MacStandardGlyphOrdering[j]);
  16855. continue;
  16856. }
  16857. glyphNames.push(customNames[j - 258]);
  16858. }
  16859. break;
  16860. case 0x00030000:
  16861. break;
  16862. default:
  16863. warn('Unknown/unsupported post table version ' + version);
  16864. valid = false;
  16865. if (properties.defaultEncoding) {
  16866. glyphNames = properties.defaultEncoding;
  16867. }
  16868. break;
  16869. }
  16870. properties.glyphNames = glyphNames;
  16871. return valid;
  16872. }
  16873. function readNameTable(nameTable) {
  16874. var start = (font.start ? font.start : 0) + nameTable.offset;
  16875. font.pos = start;
  16876. var names = [[], []];
  16877. var length = nameTable.length, end = start + length;
  16878. var format = font.getUint16();
  16879. var FORMAT_0_HEADER_LENGTH = 6;
  16880. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16881. // unsupported name table format or table "too" small
  16882. return names;
  16883. }
  16884. var numRecords = font.getUint16();
  16885. var stringsStart = font.getUint16();
  16886. var records = [];
  16887. var NAME_RECORD_LENGTH = 12;
  16888. var i, ii;
  16889. for (i = 0; i < numRecords &&
  16890. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16891. var r = {
  16892. platform: font.getUint16(),
  16893. encoding: font.getUint16(),
  16894. language: font.getUint16(),
  16895. name: font.getUint16(),
  16896. length: font.getUint16(),
  16897. offset: font.getUint16()
  16898. };
  16899. // using only Macintosh and Windows platform/encoding names
  16900. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16901. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16902. records.push(r);
  16903. }
  16904. }
  16905. for (i = 0, ii = records.length; i < ii; i++) {
  16906. var record = records[i];
  16907. var pos = start + stringsStart + record.offset;
  16908. if (pos + record.length > end) {
  16909. continue; // outside of name table, ignoring
  16910. }
  16911. font.pos = pos;
  16912. var nameIndex = record.name;
  16913. if (record.encoding) {
  16914. // unicode
  16915. var str = '';
  16916. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16917. str += String.fromCharCode(font.getUint16());
  16918. }
  16919. names[1][nameIndex] = str;
  16920. } else {
  16921. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16922. }
  16923. }
  16924. return names;
  16925. }
  16926. var TTOpsStackDeltas = [
  16927. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16928. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16929. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16930. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16931. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16932. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16933. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16934. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16935. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16936. // 0xC0-DF == -1 and 0xE0-FF == -2
  16937. function sanitizeTTProgram(table, ttContext) {
  16938. var data = table.data;
  16939. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16940. var stack = [];
  16941. var callstack = [];
  16942. var functionsCalled = [];
  16943. var tooComplexToFollowFunctions =
  16944. ttContext.tooComplexToFollowFunctions;
  16945. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16946. for (var ii = data.length; i < ii;) {
  16947. var op = data[i++];
  16948. // The TrueType instruction set docs can be found at
  16949. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16950. if (op === 0x40) { // NPUSHB - pushes n bytes
  16951. n = data[i++];
  16952. if (inFDEF || inELSE) {
  16953. i += n;
  16954. } else {
  16955. for (j = 0; j < n; j++) {
  16956. stack.push(data[i++]);
  16957. }
  16958. }
  16959. } else if (op === 0x41) { // NPUSHW - pushes n words
  16960. n = data[i++];
  16961. if (inFDEF || inELSE) {
  16962. i += n * 2;
  16963. } else {
  16964. for (j = 0; j < n; j++) {
  16965. b = data[i++];
  16966. stack.push((b << 8) | data[i++]);
  16967. }
  16968. }
  16969. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16970. n = op - 0xB0 + 1;
  16971. if (inFDEF || inELSE) {
  16972. i += n;
  16973. } else {
  16974. for (j = 0; j < n; j++) {
  16975. stack.push(data[i++]);
  16976. }
  16977. }
  16978. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16979. n = op - 0xB8 + 1;
  16980. if (inFDEF || inELSE) {
  16981. i += n * 2;
  16982. } else {
  16983. for (j = 0; j < n; j++) {
  16984. b = data[i++];
  16985. stack.push((b << 8) | data[i++]);
  16986. }
  16987. }
  16988. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16989. if (!inFDEF && !inELSE) {
  16990. // collecting inforamtion about which functions are used
  16991. funcId = stack[stack.length - 1];
  16992. ttContext.functionsUsed[funcId] = true;
  16993. if (funcId in ttContext.functionsStackDeltas) {
  16994. stack.length += ttContext.functionsStackDeltas[funcId];
  16995. } else if (funcId in ttContext.functionsDefined &&
  16996. functionsCalled.indexOf(funcId) < 0) {
  16997. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16998. functionsCalled.push(funcId);
  16999. pc = ttContext.functionsDefined[funcId];
  17000. if (!pc) {
  17001. warn('TT: CALL non-existent function');
  17002. ttContext.hintsValid = false;
  17003. return;
  17004. }
  17005. data = pc.data;
  17006. i = pc.i;
  17007. }
  17008. }
  17009. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  17010. if (inFDEF || inELSE) {
  17011. warn('TT: nested FDEFs not allowed');
  17012. tooComplexToFollowFunctions = true;
  17013. }
  17014. inFDEF = true;
  17015. // collecting inforamtion about which functions are defined
  17016. lastDeff = i;
  17017. funcId = stack.pop();
  17018. ttContext.functionsDefined[funcId] = {data: data, i: i};
  17019. } else if (op === 0x2D) { // ENDF - end of function
  17020. if (inFDEF) {
  17021. inFDEF = false;
  17022. lastEndf = i;
  17023. } else {
  17024. pc = callstack.pop();
  17025. if (!pc) {
  17026. warn('TT: ENDF bad stack');
  17027. ttContext.hintsValid = false;
  17028. return;
  17029. }
  17030. funcId = functionsCalled.pop();
  17031. data = pc.data;
  17032. i = pc.i;
  17033. ttContext.functionsStackDeltas[funcId] =
  17034. stack.length - pc.stackTop;
  17035. }
  17036. } else if (op === 0x89) { // IDEF - instruction definition
  17037. if (inFDEF || inELSE) {
  17038. warn('TT: nested IDEFs not allowed');
  17039. tooComplexToFollowFunctions = true;
  17040. }
  17041. inFDEF = true;
  17042. // recording it as a function to track ENDF
  17043. lastDeff = i;
  17044. } else if (op === 0x58) { // IF
  17045. ++ifLevel;
  17046. } else if (op === 0x1B) { // ELSE
  17047. inELSE = ifLevel;
  17048. } else if (op === 0x59) { // EIF
  17049. if (inELSE === ifLevel) {
  17050. inELSE = 0;
  17051. }
  17052. --ifLevel;
  17053. } else if (op === 0x1C) { // JMPR
  17054. if (!inFDEF && !inELSE) {
  17055. var offset = stack[stack.length - 1];
  17056. // only jumping forward to prevent infinite loop
  17057. if (offset > 0) {
  17058. i += offset - 1;
  17059. }
  17060. }
  17061. }
  17062. // Adjusting stack not extactly, but just enough to get function id
  17063. if (!inFDEF && !inELSE) {
  17064. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  17065. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  17066. if (op >= 0x71 && op <= 0x75) {
  17067. n = stack.pop();
  17068. if (n === n) {
  17069. stackDelta = -n * 2;
  17070. }
  17071. }
  17072. while (stackDelta < 0 && stack.length > 0) {
  17073. stack.pop();
  17074. stackDelta++;
  17075. }
  17076. while (stackDelta > 0) {
  17077. stack.push(NaN); // pushing any number into stack
  17078. stackDelta--;
  17079. }
  17080. }
  17081. }
  17082. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  17083. var content = [data];
  17084. if (i > data.length) {
  17085. content.push(new Uint8Array(i - data.length));
  17086. }
  17087. if (lastDeff > lastEndf) {
  17088. warn('TT: complementing a missing function tail');
  17089. // new function definition started, but not finished
  17090. // complete function by [CLEAR, ENDF]
  17091. content.push(new Uint8Array([0x22, 0x2D]));
  17092. }
  17093. foldTTTable(table, content);
  17094. }
  17095. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  17096. if (ttContext.tooComplexToFollowFunctions) {
  17097. return;
  17098. }
  17099. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  17100. warn('TT: more functions defined than expected');
  17101. ttContext.hintsValid = false;
  17102. return;
  17103. }
  17104. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  17105. if (j > maxFunctionDefs) {
  17106. warn('TT: invalid function id: ' + j);
  17107. ttContext.hintsValid = false;
  17108. return;
  17109. }
  17110. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  17111. warn('TT: undefined function: ' + j);
  17112. ttContext.hintsValid = false;
  17113. return;
  17114. }
  17115. }
  17116. }
  17117. function foldTTTable(table, content) {
  17118. if (content.length > 1) {
  17119. // concatenating the content items
  17120. var newLength = 0;
  17121. var j, jj;
  17122. for (j = 0, jj = content.length; j < jj; j++) {
  17123. newLength += content[j].length;
  17124. }
  17125. newLength = (newLength + 3) & ~3;
  17126. var result = new Uint8Array(newLength);
  17127. var pos = 0;
  17128. for (j = 0, jj = content.length; j < jj; j++) {
  17129. result.set(content[j], pos);
  17130. pos += content[j].length;
  17131. }
  17132. table.data = result;
  17133. table.length = newLength;
  17134. }
  17135. }
  17136. function sanitizeTTPrograms(fpgm, prep, cvt) {
  17137. var ttContext = {
  17138. functionsDefined: [],
  17139. functionsUsed: [],
  17140. functionsStackDeltas: [],
  17141. tooComplexToFollowFunctions: false,
  17142. hintsValid: true
  17143. };
  17144. if (fpgm) {
  17145. sanitizeTTProgram(fpgm, ttContext);
  17146. }
  17147. if (prep) {
  17148. sanitizeTTProgram(prep, ttContext);
  17149. }
  17150. if (fpgm) {
  17151. checkInvalidFunctions(ttContext, maxFunctionDefs);
  17152. }
  17153. if (cvt && (cvt.length & 1)) {
  17154. var cvtData = new Uint8Array(cvt.length + 1);
  17155. cvtData.set(cvt.data);
  17156. cvt.data = cvtData;
  17157. }
  17158. return ttContext.hintsValid;
  17159. }
  17160. // The following steps modify the original font data, making copy
  17161. font = new Stream(new Uint8Array(font.getBytes()));
  17162. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  17163. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  17164. var header = readOpenTypeHeader(font);
  17165. var numTables = header.numTables;
  17166. var cff, cffFile;
  17167. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  17168. hmtx: null, maxp: null, name: null, post: null };
  17169. var table;
  17170. for (var i = 0; i < numTables; i++) {
  17171. table = readTableEntry(font);
  17172. if (VALID_TABLES.indexOf(table.tag) < 0) {
  17173. continue; // skipping table if it's not a required or optional table
  17174. }
  17175. if (table.length === 0) {
  17176. continue; // skipping empty tables
  17177. }
  17178. tables[table.tag] = table;
  17179. }
  17180. var isTrueType = !tables['CFF '];
  17181. if (!isTrueType) {
  17182. // OpenType font
  17183. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  17184. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  17185. // no major tables: throwing everything at CFFFont
  17186. cffFile = new Stream(tables['CFF '].data);
  17187. cff = new CFFFont(cffFile, properties);
  17188. return this.convert(name, cff, properties);
  17189. }
  17190. delete tables.glyf;
  17191. delete tables.loca;
  17192. delete tables.fpgm;
  17193. delete tables.prep;
  17194. delete tables['cvt '];
  17195. this.isOpenType = true;
  17196. } else {
  17197. if (!tables.glyf || !tables.loca) {
  17198. error('Required "glyf" or "loca" tables are not found');
  17199. }
  17200. this.isOpenType = false;
  17201. }
  17202. if (!tables.maxp) {
  17203. error('Required "maxp" table is not found');
  17204. }
  17205. font.pos = (font.start || 0) + tables.maxp.offset;
  17206. var version = font.getInt32();
  17207. var numGlyphs = font.getUint16();
  17208. var maxFunctionDefs = 0;
  17209. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  17210. // maxZones can be invalid
  17211. font.pos += 8;
  17212. var maxZones = font.getUint16();
  17213. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  17214. tables.maxp.data[14] = 0;
  17215. tables.maxp.data[15] = 2;
  17216. }
  17217. font.pos += 4;
  17218. maxFunctionDefs = font.getUint16();
  17219. }
  17220. var dupFirstEntry = false;
  17221. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  17222. properties.toUnicode.get(0) > '\u0000') {
  17223. // oracle's defect (see 3427), duplicating first entry
  17224. dupFirstEntry = true;
  17225. numGlyphs++;
  17226. tables.maxp.data[4] = numGlyphs >> 8;
  17227. tables.maxp.data[5] = numGlyphs & 255;
  17228. }
  17229. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  17230. tables['cvt '], maxFunctionDefs);
  17231. if (!hintsValid) {
  17232. delete tables.fpgm;
  17233. delete tables.prep;
  17234. delete tables['cvt '];
  17235. }
  17236. // Ensure the hmtx table contains the advance width and
  17237. // sidebearings information for numGlyphs in the maxp table
  17238. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  17239. if (!tables.head) {
  17240. error('Required "head" table is not found');
  17241. }
  17242. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  17243. var missingGlyphs = {};
  17244. if (isTrueType) {
  17245. var isGlyphLocationsLong = int16(tables.head.data[50],
  17246. tables.head.data[51]);
  17247. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  17248. numGlyphs, isGlyphLocationsLong,
  17249. hintsValid, dupFirstEntry);
  17250. }
  17251. if (!tables.hhea) {
  17252. error('Required "hhea" table is not found');
  17253. }
  17254. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  17255. // Sometimes it's 0. That needs to be fixed
  17256. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  17257. tables.hhea.data[10] = 0xFF;
  17258. tables.hhea.data[11] = 0xFF;
  17259. }
  17260. // Extract some more font properties from the OpenType head and
  17261. // hhea tables; yMin and descent value are always negative.
  17262. var metricsOverride = {
  17263. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  17264. yMax: int16(tables.head.data[42], tables.head.data[43]),
  17265. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  17266. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  17267. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17268. };
  17269. // PDF FontDescriptor metrics lie -- using data from actual font.
  17270. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  17271. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  17272. // The 'post' table has glyphs names.
  17273. if (tables.post) {
  17274. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  17275. if (!valid) {
  17276. tables.post = null;
  17277. }
  17278. }
  17279. var charCodeToGlyphId = [], charCode;
  17280. var toUnicode = properties.toUnicode, widths = properties.widths;
  17281. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  17282. toUnicode.length === 0x10000);
  17283. // Helper function to try to skip mapping of empty glyphs.
  17284. // Note: In some cases, just relying on the glyph data doesn't work,
  17285. // hence we also use a few heuristics to fix various PDF files.
  17286. function hasGlyph(glyphId, charCode, widthCode) {
  17287. if (!missingGlyphs[glyphId]) {
  17288. return true;
  17289. }
  17290. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  17291. return true;
  17292. }
  17293. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  17294. return true;
  17295. }
  17296. return false;
  17297. }
  17298. if (properties.type === 'CIDFontType2') {
  17299. var cidToGidMap = properties.cidToGidMap || [];
  17300. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  17301. properties.cMap.forEach(function(charCode, cid) {
  17302. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17303. var glyphId = -1;
  17304. if (isCidToGidMapEmpty) {
  17305. glyphId = charCode;
  17306. } else if (cidToGidMap[cid] !== undefined) {
  17307. glyphId = cidToGidMap[cid];
  17308. }
  17309. if (glyphId >= 0 && glyphId < numGlyphs &&
  17310. hasGlyph(glyphId, charCode, cid)) {
  17311. charCodeToGlyphId[charCode] = glyphId;
  17312. }
  17313. });
  17314. if (dupFirstEntry) {
  17315. charCodeToGlyphId[0] = numGlyphs - 1;
  17316. }
  17317. } else {
  17318. // Most of the following logic in this code branch is based on the
  17319. // 9.6.6.4 of the PDF spec.
  17320. var hasEncoding =
  17321. properties.differences.length > 0 || !!properties.baseEncodingName;
  17322. var cmapTable =
  17323. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  17324. var cmapPlatformId = cmapTable.platformId;
  17325. var cmapEncodingId = cmapTable.encodingId;
  17326. var cmapMappings = cmapTable.mappings;
  17327. var cmapMappingsLength = cmapMappings.length;
  17328. // The spec seems to imply that if the font is symbolic the encoding
  17329. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  17330. // where the the font is symbolic and it has an encoding.
  17331. if (hasEncoding &&
  17332. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  17333. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  17334. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  17335. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  17336. // When no preferred cmap table was found and |baseEncodingName| is
  17337. // one of the predefined encodings, we seem to obtain a better
  17338. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  17339. // TODO: Note that this is a hack which should be removed as soon as
  17340. // we have proper support for more exotic cmap tables.
  17341. var baseEncoding = [];
  17342. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  17343. properties.baseEncodingName === 'WinAnsiEncoding') {
  17344. baseEncoding = Encodings[properties.baseEncodingName];
  17345. }
  17346. for (charCode = 0; charCode < 256; charCode++) {
  17347. var glyphName;
  17348. if (this.differences && charCode in this.differences) {
  17349. glyphName = this.differences[charCode];
  17350. } else if (charCode in baseEncoding &&
  17351. baseEncoding[charCode] !== '') {
  17352. glyphName = baseEncoding[charCode];
  17353. } else {
  17354. glyphName = Encodings.StandardEncoding[charCode];
  17355. }
  17356. if (!glyphName) {
  17357. continue;
  17358. }
  17359. var unicodeOrCharCode, isUnicode = false;
  17360. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  17361. unicodeOrCharCode = GlyphsUnicode[glyphName];
  17362. isUnicode = true;
  17363. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  17364. // TODO: the encoding needs to be updated with mac os table.
  17365. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  17366. }
  17367. var found = false;
  17368. for (i = 0; i < cmapMappingsLength; ++i) {
  17369. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  17370. continue;
  17371. }
  17372. var code = isUnicode ? charCode : unicodeOrCharCode;
  17373. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  17374. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17375. found = true;
  17376. break;
  17377. }
  17378. }
  17379. if (!found && properties.glyphNames) {
  17380. // Try to map using the post table.
  17381. var glyphId = properties.glyphNames.indexOf(glyphName);
  17382. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  17383. charCodeToGlyphId[charCode] = glyphId;
  17384. } else {
  17385. charCodeToGlyphId[charCode] = 0; // notdef
  17386. }
  17387. }
  17388. }
  17389. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  17390. // Default Unicode semantics, use the charcodes as is.
  17391. for (i = 0; i < cmapMappingsLength; ++i) {
  17392. charCodeToGlyphId[cmapMappings[i].charCode] =
  17393. cmapMappings[i].glyphId;
  17394. }
  17395. } else {
  17396. // For (3, 0) cmap tables:
  17397. // The charcode key being stored in charCodeToGlyphId is the lower
  17398. // byte of the two-byte charcodes of the cmap table since according to
  17399. // the spec: 'each byte from the string shall be prepended with the
  17400. // high byte of the range [of charcodes in the cmap table], to form
  17401. // a two-byte character, which shall be used to select the
  17402. // associated glyph description from the subtable'.
  17403. //
  17404. // For (1, 0) cmap tables:
  17405. // 'single bytes from the string shall be used to look up the
  17406. // associated glyph descriptions from the subtable'. This means
  17407. // charcodes in the cmap will be single bytes, so no-op since
  17408. // glyph.charCode & 0xFF === glyph.charCode
  17409. for (i = 0; i < cmapMappingsLength; ++i) {
  17410. charCode = cmapMappings[i].charCode & 0xFF;
  17411. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17412. }
  17413. }
  17414. }
  17415. if (charCodeToGlyphId.length === 0) {
  17416. // defines at least one glyph
  17417. charCodeToGlyphId[0] = 0;
  17418. }
  17419. // Converting glyphs and ids into font's cmap table
  17420. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  17421. this.toFontChar = newMapping.toFontChar;
  17422. tables.cmap = {
  17423. tag: 'cmap',
  17424. data: createCmapTable(newMapping.charCodeToGlyphId)
  17425. };
  17426. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  17427. tables['OS/2'] = {
  17428. tag: 'OS/2',
  17429. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  17430. metricsOverride)
  17431. };
  17432. }
  17433. // Rewrite the 'post' table if needed
  17434. if (!tables.post) {
  17435. tables.post = {
  17436. tag: 'post',
  17437. data: createPostTable(properties)
  17438. };
  17439. }
  17440. if (!isTrueType) {
  17441. try {
  17442. // Trying to repair CFF file
  17443. cffFile = new Stream(tables['CFF '].data);
  17444. var parser = new CFFParser(cffFile, properties);
  17445. cff = parser.parse();
  17446. var compiler = new CFFCompiler(cff);
  17447. tables['CFF '].data = compiler.compile();
  17448. } catch (e) {
  17449. warn('Failed to compile font ' + properties.loadedName);
  17450. }
  17451. }
  17452. // Re-creating 'name' table
  17453. if (!tables.name) {
  17454. tables.name = {
  17455. tag: 'name',
  17456. data: createNameTable(this.name)
  17457. };
  17458. } else {
  17459. // ... using existing 'name' table as prototype
  17460. var namePrototype = readNameTable(tables.name);
  17461. tables.name.data = createNameTable(name, namePrototype);
  17462. }
  17463. var builder = new OpenTypeFileBuilder(header.version);
  17464. for (var tableTag in tables) {
  17465. builder.addTable(tableTag, tables[tableTag].data);
  17466. }
  17467. return builder.toArray();
  17468. },
  17469. convert: function Font_convert(fontName, font, properties) {
  17470. // TODO: Check the charstring widths to determine this.
  17471. properties.fixedPitch = false;
  17472. var mapping = font.getGlyphMapping(properties);
  17473. var newMapping = adjustMapping(mapping, properties);
  17474. this.toFontChar = newMapping.toFontChar;
  17475. var numGlyphs = font.numGlyphs;
  17476. function getCharCodes(charCodeToGlyphId, glyphId) {
  17477. var charCodes = null;
  17478. for (var charCode in charCodeToGlyphId) {
  17479. if (glyphId === charCodeToGlyphId[charCode]) {
  17480. if (!charCodes) {
  17481. charCodes = [];
  17482. }
  17483. charCodes.push(charCode | 0);
  17484. }
  17485. }
  17486. return charCodes;
  17487. }
  17488. function createCharCode(charCodeToGlyphId, glyphId) {
  17489. for (var charCode in charCodeToGlyphId) {
  17490. if (glyphId === charCodeToGlyphId[charCode]) {
  17491. return charCode | 0;
  17492. }
  17493. }
  17494. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17495. glyphId;
  17496. return newMapping.nextAvailableFontCharCode++;
  17497. }
  17498. var seacs = font.seacs;
  17499. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17500. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17501. var charset = font.getCharset();
  17502. var seacMap = Object.create(null);
  17503. for (var glyphId in seacs) {
  17504. glyphId |= 0;
  17505. var seac = seacs[glyphId];
  17506. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17507. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17508. var baseGlyphId = charset.indexOf(baseGlyphName);
  17509. var accentGlyphId = charset.indexOf(accentGlyphName);
  17510. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17511. continue;
  17512. }
  17513. var accentOffset = {
  17514. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17515. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17516. };
  17517. var charCodes = getCharCodes(mapping, glyphId);
  17518. if (!charCodes) {
  17519. // There's no point in mapping it if the char code was never mapped
  17520. // to begin with.
  17521. continue;
  17522. }
  17523. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17524. var charCode = charCodes[i];
  17525. // Find a fontCharCode that maps to the base and accent glyphs.
  17526. // If one doesn't exists, create it.
  17527. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17528. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17529. baseGlyphId);
  17530. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17531. accentGlyphId);
  17532. seacMap[charCode] = {
  17533. baseFontCharCode: baseFontCharCode,
  17534. accentFontCharCode: accentFontCharCode,
  17535. accentOffset: accentOffset
  17536. };
  17537. }
  17538. }
  17539. properties.seacMap = seacMap;
  17540. }
  17541. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17542. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17543. // PostScript Font Program
  17544. builder.addTable('CFF ', font.data);
  17545. // OS/2 and Windows Specific metrics
  17546. builder.addTable('OS/2', createOS2Table(properties,
  17547. newMapping.charCodeToGlyphId));
  17548. // Character to glyphs mapping
  17549. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17550. // Font header
  17551. builder.addTable('head',
  17552. '\x00\x01\x00\x00' + // Version number
  17553. '\x00\x00\x10\x00' + // fontRevision
  17554. '\x00\x00\x00\x00' + // checksumAdjustement
  17555. '\x5F\x0F\x3C\xF5' + // magicNumber
  17556. '\x00\x00' + // Flags
  17557. safeString16(unitsPerEm) + // unitsPerEM
  17558. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17559. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17560. '\x00\x00' + // xMin
  17561. safeString16(properties.descent) + // yMin
  17562. '\x0F\xFF' + // xMax
  17563. safeString16(properties.ascent) + // yMax
  17564. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17565. '\x00\x11' + // lowestRecPPEM
  17566. '\x00\x00' + // fontDirectionHint
  17567. '\x00\x00' + // indexToLocFormat
  17568. '\x00\x00'); // glyphDataFormat
  17569. // Horizontal header
  17570. builder.addTable('hhea',
  17571. '\x00\x01\x00\x00' + // Version number
  17572. safeString16(properties.ascent) + // Typographic Ascent
  17573. safeString16(properties.descent) + // Typographic Descent
  17574. '\x00\x00' + // Line Gap
  17575. '\xFF\xFF' + // advanceWidthMax
  17576. '\x00\x00' + // minLeftSidebearing
  17577. '\x00\x00' + // minRightSidebearing
  17578. '\x00\x00' + // xMaxExtent
  17579. safeString16(properties.capHeight) + // caretSlopeRise
  17580. safeString16(Math.tan(properties.italicAngle) *
  17581. properties.xHeight) + // caretSlopeRun
  17582. '\x00\x00' + // caretOffset
  17583. '\x00\x00' + // -reserved-
  17584. '\x00\x00' + // -reserved-
  17585. '\x00\x00' + // -reserved-
  17586. '\x00\x00' + // -reserved-
  17587. '\x00\x00' + // metricDataFormat
  17588. string16(numGlyphs)); // Number of HMetrics
  17589. // Horizontal metrics
  17590. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17591. var charstrings = font.charstrings;
  17592. var cffWidths = font.cff ? font.cff.widths : null;
  17593. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17594. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17595. var width = 0;
  17596. if (charstrings) {
  17597. var charstring = charstrings[i - 1];
  17598. width = 'width' in charstring ? charstring.width : 0;
  17599. } else if (cffWidths) {
  17600. width = Math.ceil(cffWidths[i] || 0);
  17601. }
  17602. hmtx += string16(width) + string16(0);
  17603. }
  17604. return hmtx;
  17605. })());
  17606. // Maximum profile
  17607. builder.addTable('maxp',
  17608. '\x00\x00\x50\x00' + // Version number
  17609. string16(numGlyphs)); // Num of glyphs
  17610. // Naming tables
  17611. builder.addTable('name', createNameTable(fontName));
  17612. // PostScript informations
  17613. builder.addTable('post', createPostTable(properties));
  17614. return builder.toArray();
  17615. },
  17616. /**
  17617. * Builds a char code to unicode map based on section 9.10 of the spec.
  17618. * @param {Object} properties Font properties object.
  17619. * @return {Object} A ToUnicodeMap object.
  17620. */
  17621. buildToUnicode: function Font_buildToUnicode(properties) {
  17622. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17623. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17624. return properties.toUnicode;
  17625. }
  17626. // According to the spec if the font is a simple font we should only map
  17627. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17628. // the differences array only contains adobe standard or symbol set names,
  17629. // in pratice it seems better to always try to create a toUnicode
  17630. // map based of the default encoding.
  17631. var toUnicode, charcode;
  17632. if (!properties.composite /* is simple font */) {
  17633. toUnicode = [];
  17634. var encoding = properties.defaultEncoding.slice();
  17635. var baseEncodingName = properties.baseEncodingName;
  17636. // Merge in the differences array.
  17637. var differences = properties.differences;
  17638. for (charcode in differences) {
  17639. encoding[charcode] = differences[charcode];
  17640. }
  17641. for (charcode in encoding) {
  17642. // a) Map the character code to a character name.
  17643. var glyphName = encoding[charcode];
  17644. // b) Look up the character name in the Adobe Glyph List (see the
  17645. // Bibliography) to obtain the corresponding Unicode value.
  17646. if (glyphName === '') {
  17647. continue;
  17648. } else if (GlyphsUnicode[glyphName] === undefined) {
  17649. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17650. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17651. var code = 0;
  17652. switch (glyphName[0]) {
  17653. case 'G': // Gxx glyph
  17654. if (glyphName.length === 3) {
  17655. code = parseInt(glyphName.substr(1), 16);
  17656. }
  17657. break;
  17658. case 'g': // g00xx glyph
  17659. if (glyphName.length === 5) {
  17660. code = parseInt(glyphName.substr(1), 16);
  17661. }
  17662. break;
  17663. case 'C': // Cddd glyph
  17664. case 'c': // cddd glyph
  17665. if (glyphName.length >= 3) {
  17666. code = +glyphName.substr(1);
  17667. }
  17668. break;
  17669. }
  17670. if (code) {
  17671. // If |baseEncodingName| is one the predefined encodings,
  17672. // and |code| equals |charcode|, using the glyph defined in the
  17673. // baseEncoding seems to yield a better |toUnicode| mapping
  17674. // (fixes issue 5070).
  17675. if (baseEncodingName && code === +charcode) {
  17676. var baseEncoding = Encodings[baseEncodingName];
  17677. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17678. toUnicode[charcode] =
  17679. String.fromCharCode(GlyphsUnicode[glyphName]);
  17680. continue;
  17681. }
  17682. }
  17683. toUnicode[charcode] = String.fromCharCode(code);
  17684. }
  17685. continue;
  17686. }
  17687. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17688. }
  17689. return new ToUnicodeMap(toUnicode);
  17690. }
  17691. // If the font is a composite font that uses one of the predefined CMaps
  17692. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17693. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17694. // Adobe-Korea1 character collection:
  17695. if (properties.composite && (
  17696. (properties.cMap.builtInCMap &&
  17697. !(properties.cMap instanceof IdentityCMap)) ||
  17698. (properties.cidSystemInfo.registry === 'Adobe' &&
  17699. (properties.cidSystemInfo.ordering === 'GB1' ||
  17700. properties.cidSystemInfo.ordering === 'CNS1' ||
  17701. properties.cidSystemInfo.ordering === 'Japan1' ||
  17702. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17703. // Then:
  17704. // a) Map the character code to a character identifier (CID) according
  17705. // to the font’s CMap.
  17706. // b) Obtain the registry and ordering of the character collection used
  17707. // by the font’s CMap (for example, Adobe and Japan1) from its
  17708. // CIDSystemInfo dictionary.
  17709. var registry = properties.cidSystemInfo.registry;
  17710. var ordering = properties.cidSystemInfo.ordering;
  17711. // c) Construct a second CMap name by concatenating the registry and
  17712. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17713. // (for example, Adobe–Japan1–UCS2).
  17714. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17715. // d) Obtain the CMap with the name constructed in step (c) (available
  17716. // from the ASN Web site; see the Bibliography).
  17717. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17718. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17719. var cMap = properties.cMap;
  17720. toUnicode = [];
  17721. cMap.forEach(function(charcode, cid) {
  17722. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17723. // e) Map the CID obtained in step (a) according to the CMap obtained
  17724. // in step (d), producing a Unicode value.
  17725. var ucs2 = ucs2CMap.lookup(cid);
  17726. if (ucs2) {
  17727. toUnicode[charcode] =
  17728. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17729. ucs2.charCodeAt(1));
  17730. }
  17731. });
  17732. return new ToUnicodeMap(toUnicode);
  17733. }
  17734. // The viewer's choice, just use an identity map.
  17735. return new IdentityToUnicodeMap(properties.firstChar,
  17736. properties.lastChar);
  17737. },
  17738. get spaceWidth() {
  17739. if ('_shadowWidth' in this) {
  17740. return this._shadowWidth;
  17741. }
  17742. // trying to estimate space character width
  17743. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17744. var width;
  17745. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17746. var glyphName = possibleSpaceReplacements[i];
  17747. // if possible, getting width by glyph name
  17748. if (glyphName in this.widths) {
  17749. width = this.widths[glyphName];
  17750. break;
  17751. }
  17752. var glyphUnicode = GlyphsUnicode[glyphName];
  17753. // finding the charcode via unicodeToCID map
  17754. var charcode = 0;
  17755. if (this.composite) {
  17756. if (this.cMap.contains(glyphUnicode)) {
  17757. charcode = this.cMap.lookup(glyphUnicode);
  17758. }
  17759. }
  17760. // ... via toUnicode map
  17761. if (!charcode && 'toUnicode' in this) {
  17762. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17763. }
  17764. // setting it to unicode if negative or undefined
  17765. if (charcode <= 0) {
  17766. charcode = glyphUnicode;
  17767. }
  17768. // trying to get width via charcode
  17769. width = this.widths[charcode];
  17770. if (width) {
  17771. break; // the non-zero width found
  17772. }
  17773. }
  17774. width = width || this.defaultWidth;
  17775. // Do not shadow the property here. See discussion:
  17776. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17777. this._shadowWidth = width;
  17778. return width;
  17779. },
  17780. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  17781. var fontCharCode, width, operatorListId;
  17782. var widthCode = charcode;
  17783. if (this.cMap && this.cMap.contains(charcode)) {
  17784. widthCode = this.cMap.lookup(charcode);
  17785. }
  17786. width = this.widths[widthCode];
  17787. width = isNum(width) ? width : this.defaultWidth;
  17788. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17789. var unicode = this.toUnicode.get(charcode) || charcode;
  17790. if (typeof unicode === 'number') {
  17791. unicode = String.fromCharCode(unicode);
  17792. }
  17793. // First try the toFontChar map, if it's not there then try falling
  17794. // back to the char code.
  17795. fontCharCode = this.toFontChar[charcode] || charcode;
  17796. if (this.missingFile) {
  17797. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17798. }
  17799. if (this.isType3Font) {
  17800. // Font char code in this case is actually a glyph name.
  17801. operatorListId = fontCharCode;
  17802. }
  17803. var accent = null;
  17804. if (this.seacMap && this.seacMap[charcode]) {
  17805. var seac = this.seacMap[charcode];
  17806. fontCharCode = seac.baseFontCharCode;
  17807. accent = {
  17808. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17809. offset: seac.accentOffset
  17810. };
  17811. }
  17812. var fontChar = String.fromCharCode(fontCharCode);
  17813. var glyph = this.glyphCache[charcode];
  17814. if (!glyph ||
  17815. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17816. operatorListId, isSpace)) {
  17817. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17818. operatorListId, isSpace);
  17819. this.glyphCache[charcode] = glyph;
  17820. }
  17821. return glyph;
  17822. },
  17823. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17824. var charsCache = this.charsCache;
  17825. var glyphs, glyph, charcode;
  17826. // if we translated this string before, just grab it from the cache
  17827. if (charsCache) {
  17828. glyphs = charsCache[chars];
  17829. if (glyphs) {
  17830. return glyphs;
  17831. }
  17832. }
  17833. // lazily create the translation cache
  17834. if (!charsCache) {
  17835. charsCache = this.charsCache = Object.create(null);
  17836. }
  17837. glyphs = [];
  17838. var charsCacheKey = chars;
  17839. var i = 0, ii;
  17840. if (this.cMap) {
  17841. // composite fonts have multi-byte strings convert the string from
  17842. // single-byte to multi-byte
  17843. var c = {};
  17844. while (i < chars.length) {
  17845. this.cMap.readCharCode(chars, i, c);
  17846. charcode = c.charcode;
  17847. var length = c.length;
  17848. i += length;
  17849. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  17850. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  17851. glyph = this.charToGlyph(charcode, isSpace);
  17852. glyphs.push(glyph);
  17853. }
  17854. } else {
  17855. for (i = 0, ii = chars.length; i < ii; ++i) {
  17856. charcode = chars.charCodeAt(i);
  17857. glyph = this.charToGlyph(charcode, charcode === 0x20);
  17858. glyphs.push(glyph);
  17859. }
  17860. }
  17861. // Enter the translated string into the cache
  17862. return (charsCache[charsCacheKey] = glyphs);
  17863. }
  17864. };
  17865. return Font;
  17866. })();
  17867. var ErrorFont = (function ErrorFontClosure() {
  17868. function ErrorFont(error) {
  17869. this.error = error;
  17870. this.loadedName = 'g_font_error';
  17871. this.loading = false;
  17872. }
  17873. ErrorFont.prototype = {
  17874. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17875. return [];
  17876. },
  17877. exportData: function ErrorFont_exportData() {
  17878. return {error: this.error};
  17879. }
  17880. };
  17881. return ErrorFont;
  17882. })();
  17883. /**
  17884. * Shared logic for building a char code to glyph id mapping for Type1 and
  17885. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17886. * @param {Object} properties Font properties object.
  17887. * @param {Object} builtInEncoding The encoding contained within the actual font
  17888. * data.
  17889. * @param {Array} Array of glyph names where the index is the glyph ID.
  17890. * @returns {Object} A char code to glyph ID map.
  17891. */
  17892. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17893. var charCodeToGlyphId = Object.create(null);
  17894. var glyphId, charCode, baseEncoding;
  17895. if (properties.baseEncodingName) {
  17896. // If a valid base encoding name was used, the mapping is initialized with
  17897. // that.
  17898. baseEncoding = Encodings[properties.baseEncodingName];
  17899. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17900. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17901. if (glyphId >= 0) {
  17902. charCodeToGlyphId[charCode] = glyphId;
  17903. } else {
  17904. charCodeToGlyphId[charCode] = 0; // notdef
  17905. }
  17906. }
  17907. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17908. // For a symbolic font the encoding should be the fonts built-in
  17909. // encoding.
  17910. for (charCode in builtInEncoding) {
  17911. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17912. }
  17913. } else {
  17914. // For non-symbolic fonts that don't have a base encoding the standard
  17915. // encoding should be used.
  17916. baseEncoding = Encodings.StandardEncoding;
  17917. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17918. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17919. if (glyphId >= 0) {
  17920. charCodeToGlyphId[charCode] = glyphId;
  17921. } else {
  17922. charCodeToGlyphId[charCode] = 0; // notdef
  17923. }
  17924. }
  17925. }
  17926. // Lastly, merge in the differences.
  17927. var differences = properties.differences;
  17928. if (differences) {
  17929. for (charCode in differences) {
  17930. var glyphName = differences[charCode];
  17931. glyphId = glyphNames.indexOf(glyphName);
  17932. if (glyphId >= 0) {
  17933. charCodeToGlyphId[charCode] = glyphId;
  17934. } else {
  17935. charCodeToGlyphId[charCode] = 0; // notdef
  17936. }
  17937. }
  17938. }
  17939. return charCodeToGlyphId;
  17940. }
  17941. /*
  17942. * CharStrings are encoded following the the CharString Encoding sequence
  17943. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17944. * The value in a byte indicates a command, a number, or subsequent bytes
  17945. * that are to be interpreted in a special way.
  17946. *
  17947. * CharString Number Encoding:
  17948. * A CharString byte containing the values from 32 through 255 inclusive
  17949. * indicate an integer. These values are decoded in four ranges.
  17950. *
  17951. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17952. * indicate the integer v - 139. Thus, the integer values from -107 through
  17953. * 107 inclusive may be encoded in single byte.
  17954. *
  17955. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17956. * indicates an integer involving the next byte, w, according to the formula:
  17957. * [(v - 247) x 256] + w + 108
  17958. *
  17959. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17960. * indicates an integer involving the next byte, w, according to the formula:
  17961. * -[(v - 251) * 256] - w - 108
  17962. *
  17963. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17964. * are a two complement signed integer. The first of these bytes contains the
  17965. * highest order bits, the second byte contains the next higher order bits
  17966. * and the fourth byte contain the lowest order bits.
  17967. *
  17968. *
  17969. * CharString Command Encoding:
  17970. * CharStrings commands are encoded in 1 or 2 bytes.
  17971. *
  17972. * Single byte commands are encoded in 1 byte that contains a value between
  17973. * 0 and 31 inclusive.
  17974. * If a command byte contains the value 12, then the value in the next byte
  17975. * indicates a command. This "escape" mechanism allows many extra commands
  17976. * to be encoded and this encoding technique helps to minimize the length of
  17977. * the charStrings.
  17978. */
  17979. var Type1CharString = (function Type1CharStringClosure() {
  17980. var COMMAND_MAP = {
  17981. 'hstem': [1],
  17982. 'vstem': [3],
  17983. 'vmoveto': [4],
  17984. 'rlineto': [5],
  17985. 'hlineto': [6],
  17986. 'vlineto': [7],
  17987. 'rrcurveto': [8],
  17988. 'callsubr': [10],
  17989. 'flex': [12, 35],
  17990. 'drop' : [12, 18],
  17991. 'endchar': [14],
  17992. 'rmoveto': [21],
  17993. 'hmoveto': [22],
  17994. 'vhcurveto': [30],
  17995. 'hvcurveto': [31]
  17996. };
  17997. function Type1CharString() {
  17998. this.width = 0;
  17999. this.lsb = 0;
  18000. this.flexing = false;
  18001. this.output = [];
  18002. this.stack = [];
  18003. }
  18004. Type1CharString.prototype = {
  18005. convert: function Type1CharString_convert(encoded, subrs) {
  18006. var count = encoded.length;
  18007. var error = false;
  18008. var wx, sbx, subrNumber;
  18009. for (var i = 0; i < count; i++) {
  18010. var value = encoded[i];
  18011. if (value < 32) {
  18012. if (value === 12) {
  18013. value = (value << 8) + encoded[++i];
  18014. }
  18015. switch (value) {
  18016. case 1: // hstem
  18017. if (!HINTING_ENABLED) {
  18018. this.stack = [];
  18019. break;
  18020. }
  18021. error = this.executeCommand(2, COMMAND_MAP.hstem);
  18022. break;
  18023. case 3: // vstem
  18024. if (!HINTING_ENABLED) {
  18025. this.stack = [];
  18026. break;
  18027. }
  18028. error = this.executeCommand(2, COMMAND_MAP.vstem);
  18029. break;
  18030. case 4: // vmoveto
  18031. if (this.flexing) {
  18032. if (this.stack.length < 1) {
  18033. error = true;
  18034. break;
  18035. }
  18036. // Add the dx for flex and but also swap the values so they are
  18037. // the right order.
  18038. var dy = this.stack.pop();
  18039. this.stack.push(0, dy);
  18040. break;
  18041. }
  18042. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  18043. break;
  18044. case 5: // rlineto
  18045. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  18046. break;
  18047. case 6: // hlineto
  18048. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  18049. break;
  18050. case 7: // vlineto
  18051. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  18052. break;
  18053. case 8: // rrcurveto
  18054. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  18055. break;
  18056. case 9: // closepath
  18057. // closepath is a Type1 command that does not take argument and is
  18058. // useless in Type2 and it can simply be ignored.
  18059. this.stack = [];
  18060. break;
  18061. case 10: // callsubr
  18062. if (this.stack.length < 1) {
  18063. error = true;
  18064. break;
  18065. }
  18066. subrNumber = this.stack.pop();
  18067. error = this.convert(subrs[subrNumber], subrs);
  18068. break;
  18069. case 11: // return
  18070. return error;
  18071. case 13: // hsbw
  18072. if (this.stack.length < 2) {
  18073. error = true;
  18074. break;
  18075. }
  18076. // To convert to type2 we have to move the width value to the
  18077. // first part of the charstring and then use hmoveto with lsb.
  18078. wx = this.stack.pop();
  18079. sbx = this.stack.pop();
  18080. this.lsb = sbx;
  18081. this.width = wx;
  18082. this.stack.push(wx, sbx);
  18083. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  18084. break;
  18085. case 14: // endchar
  18086. this.output.push(COMMAND_MAP.endchar[0]);
  18087. break;
  18088. case 21: // rmoveto
  18089. if (this.flexing) {
  18090. break;
  18091. }
  18092. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  18093. break;
  18094. case 22: // hmoveto
  18095. if (this.flexing) {
  18096. // Add the dy for flex.
  18097. this.stack.push(0);
  18098. break;
  18099. }
  18100. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  18101. break;
  18102. case 30: // vhcurveto
  18103. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  18104. break;
  18105. case 31: // hvcurveto
  18106. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  18107. break;
  18108. case (12 << 8) + 0: // dotsection
  18109. // dotsection is a Type1 command to specify some hinting feature
  18110. // for dots that do not take a parameter and it can safely be
  18111. // ignored for Type2.
  18112. this.stack = [];
  18113. break;
  18114. case (12 << 8) + 1: // vstem3
  18115. if (!HINTING_ENABLED) {
  18116. this.stack = [];
  18117. break;
  18118. }
  18119. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  18120. // multiple parameters, so instead of returning [vh]stem3 take a
  18121. // shortcut and return [vhstem] instead.
  18122. error = this.executeCommand(2, COMMAND_MAP.vstem);
  18123. break;
  18124. case (12 << 8) + 2: // hstem3
  18125. if (!HINTING_ENABLED) {
  18126. this.stack = [];
  18127. break;
  18128. }
  18129. // See vstem3.
  18130. error = this.executeCommand(2, COMMAND_MAP.hstem);
  18131. break;
  18132. case (12 << 8) + 6: // seac
  18133. // seac is like type 2's special endchar but it doesn't use the
  18134. // first argument asb, so remove it.
  18135. if (SEAC_ANALYSIS_ENABLED) {
  18136. this.seac = this.stack.splice(-4, 4);
  18137. error = this.executeCommand(0, COMMAND_MAP.endchar);
  18138. } else {
  18139. error = this.executeCommand(4, COMMAND_MAP.endchar);
  18140. }
  18141. break;
  18142. case (12 << 8) + 7: // sbw
  18143. if (this.stack.length < 4) {
  18144. error = true;
  18145. break;
  18146. }
  18147. // To convert to type2 we have to move the width value to the
  18148. // first part of the charstring and then use rmoveto with
  18149. // (dx, dy). The height argument will not be used for vmtx and
  18150. // vhea tables reconstruction -- ignoring it.
  18151. var wy = this.stack.pop();
  18152. wx = this.stack.pop();
  18153. var sby = this.stack.pop();
  18154. sbx = this.stack.pop();
  18155. this.lsb = sbx;
  18156. this.width = wx;
  18157. this.stack.push(wx, sbx, sby);
  18158. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  18159. break;
  18160. case (12 << 8) + 12: // div
  18161. if (this.stack.length < 2) {
  18162. error = true;
  18163. break;
  18164. }
  18165. var num2 = this.stack.pop();
  18166. var num1 = this.stack.pop();
  18167. this.stack.push(num1 / num2);
  18168. break;
  18169. case (12 << 8) + 16: // callothersubr
  18170. if (this.stack.length < 2) {
  18171. error = true;
  18172. break;
  18173. }
  18174. subrNumber = this.stack.pop();
  18175. var numArgs = this.stack.pop();
  18176. if (subrNumber === 0 && numArgs === 3) {
  18177. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  18178. this.stack.push(
  18179. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  18180. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  18181. flexArgs[4], // bcp2x
  18182. flexArgs[5], // bcp2y
  18183. flexArgs[6], // p2x
  18184. flexArgs[7], // p2y
  18185. flexArgs[8], // bcp3x
  18186. flexArgs[9], // bcp3y
  18187. flexArgs[10], // bcp4x
  18188. flexArgs[11], // bcp4y
  18189. flexArgs[12], // p3x
  18190. flexArgs[13], // p3y
  18191. flexArgs[14] // flexDepth
  18192. // 15 = finalx unused by flex
  18193. // 16 = finaly unused by flex
  18194. );
  18195. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  18196. this.flexing = false;
  18197. this.stack.push(flexArgs[15], flexArgs[16]);
  18198. } else if (subrNumber === 1 && numArgs === 0) {
  18199. this.flexing = true;
  18200. }
  18201. break;
  18202. case (12 << 8) + 17: // pop
  18203. // Ignore this since it is only used with othersubr.
  18204. break;
  18205. case (12 << 8) + 33: // setcurrentpoint
  18206. // Ignore for now.
  18207. this.stack = [];
  18208. break;
  18209. default:
  18210. warn('Unknown type 1 charstring command of "' + value + '"');
  18211. break;
  18212. }
  18213. if (error) {
  18214. break;
  18215. }
  18216. continue;
  18217. } else if (value <= 246) {
  18218. value = value - 139;
  18219. } else if (value <= 250) {
  18220. value = ((value - 247) * 256) + encoded[++i] + 108;
  18221. } else if (value <= 254) {
  18222. value = -((value - 251) * 256) - encoded[++i] - 108;
  18223. } else {
  18224. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  18225. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  18226. }
  18227. this.stack.push(value);
  18228. }
  18229. return error;
  18230. },
  18231. executeCommand: function(howManyArgs, command, keepStack) {
  18232. var stackLength = this.stack.length;
  18233. if (howManyArgs > stackLength) {
  18234. return true;
  18235. }
  18236. var start = stackLength - howManyArgs;
  18237. for (var i = start; i < stackLength; i++) {
  18238. var value = this.stack[i];
  18239. if (value === (value | 0)) { // int
  18240. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  18241. } else { // fixed point
  18242. value = (65536 * value) | 0;
  18243. this.output.push(255,
  18244. (value >> 24) & 0xFF,
  18245. (value >> 16) & 0xFF,
  18246. (value >> 8) & 0xFF,
  18247. value & 0xFF);
  18248. }
  18249. }
  18250. this.output.push.apply(this.output, command);
  18251. if (keepStack) {
  18252. this.stack.splice(start, howManyArgs);
  18253. } else {
  18254. this.stack.length = 0;
  18255. }
  18256. return false;
  18257. }
  18258. };
  18259. return Type1CharString;
  18260. })();
  18261. /*
  18262. * Type1Parser encapsulate the needed code for parsing a Type1 font
  18263. * program. Some of its logic depends on the Type2 charstrings
  18264. * structure.
  18265. * Note: this doesn't really parse the font since that would require evaluation
  18266. * of PostScript, but it is possible in most cases to extract what we need
  18267. * without a full parse.
  18268. */
  18269. var Type1Parser = (function Type1ParserClosure() {
  18270. /*
  18271. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  18272. * of Plaintext Bytes. The function took a key as a parameter which can be
  18273. * for decrypting the eexec block of for decoding charStrings.
  18274. */
  18275. var EEXEC_ENCRYPT_KEY = 55665;
  18276. var CHAR_STRS_ENCRYPT_KEY = 4330;
  18277. function isHexDigit(code) {
  18278. return code >= 48 && code <= 57 || // '0'-'9'
  18279. code >= 65 && code <= 70 || // 'A'-'F'
  18280. code >= 97 && code <= 102; // 'a'-'f'
  18281. }
  18282. function decrypt(data, key, discardNumber) {
  18283. var r = key | 0, c1 = 52845, c2 = 22719;
  18284. var count = data.length;
  18285. var decrypted = new Uint8Array(count);
  18286. for (var i = 0; i < count; i++) {
  18287. var value = data[i];
  18288. decrypted[i] = value ^ (r >> 8);
  18289. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18290. }
  18291. return Array.prototype.slice.call(decrypted, discardNumber);
  18292. }
  18293. function decryptAscii(data, key, discardNumber) {
  18294. var r = key | 0, c1 = 52845, c2 = 22719;
  18295. var count = data.length, maybeLength = count >>> 1;
  18296. var decrypted = new Uint8Array(maybeLength);
  18297. var i, j;
  18298. for (i = 0, j = 0; i < count; i++) {
  18299. var digit1 = data[i];
  18300. if (!isHexDigit(digit1)) {
  18301. continue;
  18302. }
  18303. i++;
  18304. var digit2;
  18305. while (i < count && !isHexDigit(digit2 = data[i])) {
  18306. i++;
  18307. }
  18308. if (i < count) {
  18309. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  18310. decrypted[j++] = value ^ (r >> 8);
  18311. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18312. }
  18313. }
  18314. return Array.prototype.slice.call(decrypted, discardNumber, j);
  18315. }
  18316. function isSpecial(c) {
  18317. return c === 0x2F || // '/'
  18318. c === 0x5B || c === 0x5D || // '[', ']'
  18319. c === 0x7B || c === 0x7D || // '{', '}'
  18320. c === 0x28 || c === 0x29; // '(', ')'
  18321. }
  18322. function Type1Parser(stream, encrypted) {
  18323. if (encrypted) {
  18324. var data = stream.getBytes();
  18325. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  18326. isHexDigit(data[2]) && isHexDigit(data[3]));
  18327. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  18328. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  18329. }
  18330. this.stream = stream;
  18331. this.nextChar();
  18332. }
  18333. Type1Parser.prototype = {
  18334. readNumberArray: function Type1Parser_readNumberArray() {
  18335. this.getToken(); // read '[' or '{' (arrays can start with either)
  18336. var array = [];
  18337. while (true) {
  18338. var token = this.getToken();
  18339. if (token === null || token === ']' || token === '}') {
  18340. break;
  18341. }
  18342. array.push(parseFloat(token || 0));
  18343. }
  18344. return array;
  18345. },
  18346. readNumber: function Type1Parser_readNumber() {
  18347. var token = this.getToken();
  18348. return parseFloat(token || 0);
  18349. },
  18350. readInt: function Type1Parser_readInt() {
  18351. // Use '| 0' to prevent setting a double into length such as the double
  18352. // does not flow into the loop variable.
  18353. var token = this.getToken();
  18354. return parseInt(token || 0, 10) | 0;
  18355. },
  18356. readBoolean: function Type1Parser_readBoolean() {
  18357. var token = this.getToken();
  18358. // Use 1 and 0 since that's what type2 charstrings use.
  18359. return token === 'true' ? 1 : 0;
  18360. },
  18361. nextChar : function Type1_nextChar() {
  18362. return (this.currentChar = this.stream.getByte());
  18363. },
  18364. getToken: function Type1Parser_getToken() {
  18365. // Eat whitespace and comments.
  18366. var comment = false;
  18367. var ch = this.currentChar;
  18368. while (true) {
  18369. if (ch === -1) {
  18370. return null;
  18371. }
  18372. if (comment) {
  18373. if (ch === 0x0A || ch === 0x0D) {
  18374. comment = false;
  18375. }
  18376. } else if (ch === 0x25) { // '%'
  18377. comment = true;
  18378. } else if (!Lexer.isSpace(ch)) {
  18379. break;
  18380. }
  18381. ch = this.nextChar();
  18382. }
  18383. if (isSpecial(ch)) {
  18384. this.nextChar();
  18385. return String.fromCharCode(ch);
  18386. }
  18387. var token = '';
  18388. do {
  18389. token += String.fromCharCode(ch);
  18390. ch = this.nextChar();
  18391. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  18392. return token;
  18393. },
  18394. /*
  18395. * Returns an object containing a Subrs array and a CharStrings
  18396. * array extracted from and eexec encrypted block of data
  18397. */
  18398. extractFontProgram: function Type1Parser_extractFontProgram() {
  18399. var stream = this.stream;
  18400. var subrs = [], charstrings = [];
  18401. var program = {
  18402. subrs: [],
  18403. charstrings: [],
  18404. properties: {
  18405. 'privateData': {
  18406. 'lenIV': 4
  18407. }
  18408. }
  18409. };
  18410. var token, length, data, lenIV, encoded;
  18411. while ((token = this.getToken()) !== null) {
  18412. if (token !== '/') {
  18413. continue;
  18414. }
  18415. token = this.getToken();
  18416. switch (token) {
  18417. case 'CharStrings':
  18418. // The number immediately following CharStrings must be greater or
  18419. // equal to the number of CharStrings.
  18420. this.getToken();
  18421. this.getToken(); // read in 'dict'
  18422. this.getToken(); // read in 'dup'
  18423. this.getToken(); // read in 'begin'
  18424. while(true) {
  18425. token = this.getToken();
  18426. if (token === null || token === 'end') {
  18427. break;
  18428. }
  18429. if (token !== '/') {
  18430. continue;
  18431. }
  18432. var glyph = this.getToken();
  18433. length = this.readInt();
  18434. this.getToken(); // read in 'RD' or '-|'
  18435. data = stream.makeSubStream(stream.pos, length);
  18436. lenIV = program.properties.privateData['lenIV'];
  18437. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18438. // Skip past the required space and binary data.
  18439. stream.skip(length);
  18440. this.nextChar();
  18441. token = this.getToken(); // read in 'ND' or '|-'
  18442. if (token === 'noaccess') {
  18443. this.getToken(); // read in 'def'
  18444. }
  18445. charstrings.push({
  18446. glyph: glyph,
  18447. encoded: encoded
  18448. });
  18449. }
  18450. break;
  18451. case 'Subrs':
  18452. var num = this.readInt();
  18453. this.getToken(); // read in 'array'
  18454. while ((token = this.getToken()) === 'dup') {
  18455. var index = this.readInt();
  18456. length = this.readInt();
  18457. this.getToken(); // read in 'RD' or '-|'
  18458. data = stream.makeSubStream(stream.pos, length);
  18459. lenIV = program.properties.privateData['lenIV'];
  18460. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18461. // Skip past the required space and binary data.
  18462. stream.skip(length);
  18463. this.nextChar();
  18464. token = this.getToken(); // read in 'NP' or '|'
  18465. if (token === 'noaccess') {
  18466. this.getToken(); // read in 'put'
  18467. }
  18468. subrs[index] = encoded;
  18469. }
  18470. break;
  18471. case 'BlueValues':
  18472. case 'OtherBlues':
  18473. case 'FamilyBlues':
  18474. case 'FamilyOtherBlues':
  18475. var blueArray = this.readNumberArray();
  18476. // *Blue* values may contain invalid data: disables reading of
  18477. // those values when hinting is disabled.
  18478. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18479. HINTING_ENABLED) {
  18480. program.properties.privateData[token] = blueArray;
  18481. }
  18482. break;
  18483. case 'StemSnapH':
  18484. case 'StemSnapV':
  18485. program.properties.privateData[token] = this.readNumberArray();
  18486. break;
  18487. case 'StdHW':
  18488. case 'StdVW':
  18489. program.properties.privateData[token] =
  18490. this.readNumberArray()[0];
  18491. break;
  18492. case 'BlueShift':
  18493. case 'lenIV':
  18494. case 'BlueFuzz':
  18495. case 'BlueScale':
  18496. case 'LanguageGroup':
  18497. case 'ExpansionFactor':
  18498. program.properties.privateData[token] = this.readNumber();
  18499. break;
  18500. case 'ForceBold':
  18501. program.properties.privateData[token] = this.readBoolean();
  18502. break;
  18503. }
  18504. }
  18505. for (var i = 0; i < charstrings.length; i++) {
  18506. glyph = charstrings[i].glyph;
  18507. encoded = charstrings[i].encoded;
  18508. var charString = new Type1CharString();
  18509. var error = charString.convert(encoded, subrs);
  18510. var output = charString.output;
  18511. if (error) {
  18512. // It seems when FreeType encounters an error while evaluating a glyph
  18513. // that it completely ignores the glyph so we'll mimic that behaviour
  18514. // here and put an endchar to make the validator happy.
  18515. output = [14];
  18516. }
  18517. program.charstrings.push({
  18518. glyphName: glyph,
  18519. charstring: output,
  18520. width: charString.width,
  18521. lsb: charString.lsb,
  18522. seac: charString.seac
  18523. });
  18524. }
  18525. return program;
  18526. },
  18527. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18528. var token;
  18529. while ((token = this.getToken()) !== null) {
  18530. if (token !== '/') {
  18531. continue;
  18532. }
  18533. token = this.getToken();
  18534. switch (token) {
  18535. case 'FontMatrix':
  18536. var matrix = this.readNumberArray();
  18537. properties.fontMatrix = matrix;
  18538. break;
  18539. case 'Encoding':
  18540. var encodingArg = this.getToken();
  18541. var encoding;
  18542. if (!/^\d+$/.test(encodingArg)) {
  18543. // encoding name is specified
  18544. encoding = Encodings[encodingArg];
  18545. } else {
  18546. encoding = [];
  18547. var size = parseInt(encodingArg, 10) | 0;
  18548. this.getToken(); // read in 'array'
  18549. for (var j = 0; j < size; j++) {
  18550. token = this.getToken();
  18551. // skipping till first dup or def (e.g. ignoring for statement)
  18552. while (token !== 'dup' && token !== 'def') {
  18553. token = this.getToken();
  18554. if (token === null) {
  18555. return; // invalid header
  18556. }
  18557. }
  18558. if (token === 'def') {
  18559. break; // read all array data
  18560. }
  18561. var index = this.readInt();
  18562. this.getToken(); // read in '/'
  18563. var glyph = this.getToken();
  18564. encoding[index] = glyph;
  18565. this.getToken(); // read the in 'put'
  18566. }
  18567. }
  18568. properties.builtInEncoding = encoding;
  18569. break;
  18570. case 'FontBBox':
  18571. var fontBBox = this.readNumberArray();
  18572. // adjusting ascent/descent
  18573. properties.ascent = fontBBox[3];
  18574. properties.descent = fontBBox[1];
  18575. properties.ascentScaled = true;
  18576. break;
  18577. }
  18578. }
  18579. }
  18580. };
  18581. return Type1Parser;
  18582. })();
  18583. /**
  18584. * The CFF class takes a Type1 file and wrap it into a
  18585. * 'Compact Font Format' which itself embed Type2 charstrings.
  18586. */
  18587. var CFFStandardStrings = [
  18588. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18589. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18590. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18591. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18592. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18593. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18594. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18595. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18596. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18597. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18598. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18599. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18600. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18601. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18602. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18603. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18604. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18605. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18606. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18607. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18608. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18609. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18610. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18611. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18612. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18613. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18614. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18615. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18616. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18617. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18618. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18619. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18620. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18621. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18622. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18623. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18624. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18625. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18626. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18627. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18628. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18629. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18630. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18631. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18632. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18633. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18634. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18635. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18636. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18637. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18638. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18639. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18640. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18641. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18642. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18643. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18644. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18645. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18646. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18647. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18648. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18649. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18650. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18651. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18652. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18653. ];
  18654. // Type1Font is also a CIDFontType0.
  18655. var Type1Font = function Type1Font(name, file, properties) {
  18656. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18657. // Also, length1 and length2 might be off by 6 bytes as well.
  18658. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18659. var PFB_HEADER_SIZE = 6;
  18660. var headerBlockLength = properties.length1;
  18661. var eexecBlockLength = properties.length2;
  18662. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18663. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18664. if (pfbHeaderPresent) {
  18665. file.skip(PFB_HEADER_SIZE);
  18666. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18667. (pfbHeader[3] << 8) | pfbHeader[2];
  18668. }
  18669. // Get the data block containing glyphs and subrs informations
  18670. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18671. var headerBlockParser = new Type1Parser(headerBlock);
  18672. headerBlockParser.extractFontHeader(properties);
  18673. if (pfbHeaderPresent) {
  18674. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18675. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18676. (pfbHeader[3] << 8) | pfbHeader[2];
  18677. }
  18678. // Decrypt the data blocks and retrieve it's content
  18679. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18680. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18681. var data = eexecBlockParser.extractFontProgram();
  18682. for (var info in data.properties) {
  18683. properties[info] = data.properties[info];
  18684. }
  18685. var charstrings = data.charstrings;
  18686. var type2Charstrings = this.getType2Charstrings(charstrings);
  18687. var subrs = this.getType2Subrs(data.subrs);
  18688. this.charstrings = charstrings;
  18689. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18690. subrs, properties);
  18691. this.seacs = this.getSeacs(data.charstrings);
  18692. };
  18693. Type1Font.prototype = {
  18694. get numGlyphs() {
  18695. return this.charstrings.length + 1;
  18696. },
  18697. getCharset: function Type1Font_getCharset() {
  18698. var charset = ['.notdef'];
  18699. var charstrings = this.charstrings;
  18700. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18701. charset.push(charstrings[glyphId].glyphName);
  18702. }
  18703. return charset;
  18704. },
  18705. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18706. var charstrings = this.charstrings;
  18707. var glyphNames = ['.notdef'], glyphId;
  18708. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18709. glyphNames.push(charstrings[glyphId].glyphName);
  18710. }
  18711. var encoding = properties.builtInEncoding;
  18712. if (encoding) {
  18713. var builtInEncoding = {};
  18714. for (var charCode in encoding) {
  18715. glyphId = glyphNames.indexOf(encoding[charCode]);
  18716. if (glyphId >= 0) {
  18717. builtInEncoding[charCode] = glyphId;
  18718. }
  18719. }
  18720. }
  18721. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18722. },
  18723. getSeacs: function Type1Font_getSeacs(charstrings) {
  18724. var i, ii;
  18725. var seacMap = [];
  18726. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18727. var charstring = charstrings[i];
  18728. if (charstring.seac) {
  18729. // Offset by 1 for .notdef
  18730. seacMap[i + 1] = charstring.seac;
  18731. }
  18732. }
  18733. return seacMap;
  18734. },
  18735. getType2Charstrings: function Type1Font_getType2Charstrings(
  18736. type1Charstrings) {
  18737. var type2Charstrings = [];
  18738. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18739. type2Charstrings.push(type1Charstrings[i].charstring);
  18740. }
  18741. return type2Charstrings;
  18742. },
  18743. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18744. var bias = 0;
  18745. var count = type1Subrs.length;
  18746. if (count < 1133) {
  18747. bias = 107;
  18748. } else if (count < 33769) {
  18749. bias = 1131;
  18750. } else {
  18751. bias = 32768;
  18752. }
  18753. // Add a bunch of empty subrs to deal with the Type2 bias
  18754. var type2Subrs = [];
  18755. var i;
  18756. for (i = 0; i < bias; i++) {
  18757. type2Subrs.push([0x0B]);
  18758. }
  18759. for (i = 0; i < count; i++) {
  18760. type2Subrs.push(type1Subrs[i]);
  18761. }
  18762. return type2Subrs;
  18763. },
  18764. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18765. var cff = new CFF();
  18766. cff.header = new CFFHeader(1, 0, 4, 4);
  18767. cff.names = [name];
  18768. var topDict = new CFFTopDict();
  18769. // CFF strings IDs 0...390 are predefined names, so refering
  18770. // to entries in our own String INDEX starts at SID 391.
  18771. topDict.setByName('version', 391);
  18772. topDict.setByName('Notice', 392);
  18773. topDict.setByName('FullName', 393);
  18774. topDict.setByName('FamilyName', 394);
  18775. topDict.setByName('Weight', 395);
  18776. topDict.setByName('Encoding', null); // placeholder
  18777. topDict.setByName('FontMatrix', properties.fontMatrix);
  18778. topDict.setByName('FontBBox', properties.bbox);
  18779. topDict.setByName('charset', null); // placeholder
  18780. topDict.setByName('CharStrings', null); // placeholder
  18781. topDict.setByName('Private', null); // placeholder
  18782. cff.topDict = topDict;
  18783. var strings = new CFFStrings();
  18784. strings.add('Version 0.11'); // Version
  18785. strings.add('See original notice'); // Notice
  18786. strings.add(name); // FullName
  18787. strings.add(name); // FamilyName
  18788. strings.add('Medium'); // Weight
  18789. cff.strings = strings;
  18790. cff.globalSubrIndex = new CFFIndex();
  18791. var count = glyphs.length;
  18792. var charsetArray = [0];
  18793. var i, ii;
  18794. for (i = 0; i < count; i++) {
  18795. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18796. // TODO: Insert the string and correctly map it. Previously it was
  18797. // thought mapping names that aren't in the standard strings to .notdef
  18798. // was fine, however in issue818 when mapping them all to .notdef the
  18799. // adieresis glyph no longer worked.
  18800. if (index === -1) {
  18801. index = 0;
  18802. }
  18803. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18804. }
  18805. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18806. var charStringsIndex = new CFFIndex();
  18807. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18808. for (i = 0; i < count; i++) {
  18809. charStringsIndex.add(glyphs[i]);
  18810. }
  18811. cff.charStrings = charStringsIndex;
  18812. var privateDict = new CFFPrivateDict();
  18813. privateDict.setByName('Subrs', null); // placeholder
  18814. var fields = [
  18815. 'BlueValues',
  18816. 'OtherBlues',
  18817. 'FamilyBlues',
  18818. 'FamilyOtherBlues',
  18819. 'StemSnapH',
  18820. 'StemSnapV',
  18821. 'BlueShift',
  18822. 'BlueFuzz',
  18823. 'BlueScale',
  18824. 'LanguageGroup',
  18825. 'ExpansionFactor',
  18826. 'ForceBold',
  18827. 'StdHW',
  18828. 'StdVW'
  18829. ];
  18830. for (i = 0, ii = fields.length; i < ii; i++) {
  18831. var field = fields[i];
  18832. if (!properties.privateData.hasOwnProperty(field)) {
  18833. continue;
  18834. }
  18835. var value = properties.privateData[field];
  18836. if (isArray(value)) {
  18837. // All of the private dictionary array data in CFF must be stored as
  18838. // "delta-encoded" numbers.
  18839. for (var j = value.length - 1; j > 0; j--) {
  18840. value[j] -= value[j - 1]; // ... difference from previous value
  18841. }
  18842. }
  18843. privateDict.setByName(field, value);
  18844. }
  18845. cff.topDict.privateDict = privateDict;
  18846. var subrIndex = new CFFIndex();
  18847. for (i = 0, ii = subrs.length; i < ii; i++) {
  18848. subrIndex.add(subrs[i]);
  18849. }
  18850. privateDict.subrsIndex = subrIndex;
  18851. var compiler = new CFFCompiler(cff);
  18852. return compiler.compile();
  18853. }
  18854. };
  18855. var CFFFont = (function CFFFontClosure() {
  18856. function CFFFont(file, properties) {
  18857. this.properties = properties;
  18858. var parser = new CFFParser(file, properties);
  18859. this.cff = parser.parse();
  18860. var compiler = new CFFCompiler(this.cff);
  18861. this.seacs = this.cff.seacs;
  18862. try {
  18863. this.data = compiler.compile();
  18864. } catch (e) {
  18865. warn('Failed to compile font ' + properties.loadedName);
  18866. // There may have just been an issue with the compiler, set the data
  18867. // anyway and hope the font loaded.
  18868. this.data = file;
  18869. }
  18870. }
  18871. CFFFont.prototype = {
  18872. get numGlyphs() {
  18873. return this.cff.charStrings.count;
  18874. },
  18875. getCharset: function CFFFont_getCharset() {
  18876. return this.cff.charset.charset;
  18877. },
  18878. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18879. var cff = this.cff;
  18880. var properties = this.properties;
  18881. var charsets = cff.charset.charset;
  18882. var charCodeToGlyphId;
  18883. var glyphId;
  18884. if (properties.composite) {
  18885. charCodeToGlyphId = Object.create(null);
  18886. if (cff.isCIDFont) {
  18887. // If the font is actually a CID font then we should use the charset
  18888. // to map CIDs to GIDs.
  18889. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18890. var cid = charsets[glyphId];
  18891. var charCode = properties.cMap.charCodeOf(cid);
  18892. charCodeToGlyphId[charCode] = glyphId;
  18893. }
  18894. } else {
  18895. // If it is NOT actually a CID font then CIDs should be mapped
  18896. // directly to GIDs.
  18897. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18898. charCodeToGlyphId[glyphId] = glyphId;
  18899. }
  18900. }
  18901. return charCodeToGlyphId;
  18902. }
  18903. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18904. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18905. return charCodeToGlyphId;
  18906. }
  18907. };
  18908. return CFFFont;
  18909. })();
  18910. var CFFParser = (function CFFParserClosure() {
  18911. var CharstringValidationData = [
  18912. null,
  18913. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18914. null,
  18915. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18916. { id: 'vmoveto', min: 1, stackClearing: true },
  18917. { id: 'rlineto', min: 2, resetStack: true },
  18918. { id: 'hlineto', min: 1, resetStack: true },
  18919. { id: 'vlineto', min: 1, resetStack: true },
  18920. { id: 'rrcurveto', min: 6, resetStack: true },
  18921. null,
  18922. { id: 'callsubr', min: 1, undefStack: true },
  18923. { id: 'return', min: 0, undefStack: true },
  18924. null, // 12
  18925. null,
  18926. { id: 'endchar', min: 0, stackClearing: true },
  18927. null,
  18928. null,
  18929. null,
  18930. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18931. { id: 'hintmask', min: 0, stackClearing: true },
  18932. { id: 'cntrmask', min: 0, stackClearing: true },
  18933. { id: 'rmoveto', min: 2, stackClearing: true },
  18934. { id: 'hmoveto', min: 1, stackClearing: true },
  18935. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18936. { id: 'rcurveline', min: 8, resetStack: true },
  18937. { id: 'rlinecurve', min: 8, resetStack: true },
  18938. { id: 'vvcurveto', min: 4, resetStack: true },
  18939. { id: 'hhcurveto', min: 4, resetStack: true },
  18940. null, // shortint
  18941. { id: 'callgsubr', min: 1, undefStack: true },
  18942. { id: 'vhcurveto', min: 4, resetStack: true },
  18943. { id: 'hvcurveto', min: 4, resetStack: true }
  18944. ];
  18945. var CharstringValidationData12 = [
  18946. null,
  18947. null,
  18948. null,
  18949. { id: 'and', min: 2, stackDelta: -1 },
  18950. { id: 'or', min: 2, stackDelta: -1 },
  18951. { id: 'not', min: 1, stackDelta: 0 },
  18952. null,
  18953. null,
  18954. null,
  18955. { id: 'abs', min: 1, stackDelta: 0 },
  18956. { id: 'add', min: 2, stackDelta: -1,
  18957. stackFn: function stack_div(stack, index) {
  18958. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18959. }
  18960. },
  18961. { id: 'sub', min: 2, stackDelta: -1,
  18962. stackFn: function stack_div(stack, index) {
  18963. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18964. }
  18965. },
  18966. { id: 'div', min: 2, stackDelta: -1,
  18967. stackFn: function stack_div(stack, index) {
  18968. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18969. }
  18970. },
  18971. null,
  18972. { id: 'neg', min: 1, stackDelta: 0,
  18973. stackFn: function stack_div(stack, index) {
  18974. stack[index - 1] = -stack[index - 1];
  18975. }
  18976. },
  18977. { id: 'eq', min: 2, stackDelta: -1 },
  18978. null,
  18979. null,
  18980. { id: 'drop', min: 1, stackDelta: -1 },
  18981. null,
  18982. { id: 'put', min: 2, stackDelta: -2 },
  18983. { id: 'get', min: 1, stackDelta: 0 },
  18984. { id: 'ifelse', min: 4, stackDelta: -3 },
  18985. { id: 'random', min: 0, stackDelta: 1 },
  18986. { id: 'mul', min: 2, stackDelta: -1,
  18987. stackFn: function stack_div(stack, index) {
  18988. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18989. }
  18990. },
  18991. null,
  18992. { id: 'sqrt', min: 1, stackDelta: 0 },
  18993. { id: 'dup', min: 1, stackDelta: 1 },
  18994. { id: 'exch', min: 2, stackDelta: 0 },
  18995. { id: 'index', min: 2, stackDelta: 0 },
  18996. { id: 'roll', min: 3, stackDelta: -2 },
  18997. null,
  18998. null,
  18999. null,
  19000. { id: 'hflex', min: 7, resetStack: true },
  19001. { id: 'flex', min: 13, resetStack: true },
  19002. { id: 'hflex1', min: 9, resetStack: true },
  19003. { id: 'flex1', min: 11, resetStack: true }
  19004. ];
  19005. function CFFParser(file, properties) {
  19006. this.bytes = file.getBytes();
  19007. this.properties = properties;
  19008. }
  19009. CFFParser.prototype = {
  19010. parse: function CFFParser_parse() {
  19011. var properties = this.properties;
  19012. var cff = new CFF();
  19013. this.cff = cff;
  19014. // The first five sections must be in order, all the others are reached
  19015. // via offsets contained in one of the below.
  19016. var header = this.parseHeader();
  19017. var nameIndex = this.parseIndex(header.endPos);
  19018. var topDictIndex = this.parseIndex(nameIndex.endPos);
  19019. var stringIndex = this.parseIndex(topDictIndex.endPos);
  19020. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  19021. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  19022. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  19023. cff.header = header.obj;
  19024. cff.names = this.parseNameIndex(nameIndex.obj);
  19025. cff.strings = this.parseStringIndex(stringIndex.obj);
  19026. cff.topDict = topDict;
  19027. cff.globalSubrIndex = globalSubrIndex.obj;
  19028. this.parsePrivateDict(cff.topDict);
  19029. cff.isCIDFont = topDict.hasName('ROS');
  19030. var charStringOffset = topDict.getByName('CharStrings');
  19031. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  19032. cff.charStrings = charStringsAndSeacs.charStrings;
  19033. cff.seacs = charStringsAndSeacs.seacs;
  19034. cff.widths = charStringsAndSeacs.widths;
  19035. var fontMatrix = topDict.getByName('FontMatrix');
  19036. if (fontMatrix) {
  19037. properties.fontMatrix = fontMatrix;
  19038. }
  19039. var fontBBox = topDict.getByName('FontBBox');
  19040. if (fontBBox) {
  19041. // adjusting ascent/descent
  19042. properties.ascent = fontBBox[3];
  19043. properties.descent = fontBBox[1];
  19044. properties.ascentScaled = true;
  19045. }
  19046. var charset, encoding;
  19047. if (cff.isCIDFont) {
  19048. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  19049. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  19050. var dictRaw = fdArrayIndex.get(i);
  19051. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  19052. cff.strings);
  19053. this.parsePrivateDict(fontDict);
  19054. cff.fdArray.push(fontDict);
  19055. }
  19056. // cid fonts don't have an encoding
  19057. encoding = null;
  19058. charset = this.parseCharsets(topDict.getByName('charset'),
  19059. cff.charStrings.count, cff.strings, true);
  19060. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  19061. cff.charStrings.count);
  19062. } else {
  19063. charset = this.parseCharsets(topDict.getByName('charset'),
  19064. cff.charStrings.count, cff.strings, false);
  19065. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  19066. properties,
  19067. cff.strings, charset.charset);
  19068. }
  19069. cff.charset = charset;
  19070. cff.encoding = encoding;
  19071. return cff;
  19072. },
  19073. parseHeader: function CFFParser_parseHeader() {
  19074. var bytes = this.bytes;
  19075. var bytesLength = bytes.length;
  19076. var offset = 0;
  19077. // Prevent an infinite loop, by checking that the offset is within the
  19078. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  19079. while (offset < bytesLength && bytes[offset] !== 1) {
  19080. ++offset;
  19081. }
  19082. if (offset >= bytesLength) {
  19083. error('Invalid CFF header');
  19084. } else if (offset !== 0) {
  19085. info('cff data is shifted');
  19086. bytes = bytes.subarray(offset);
  19087. this.bytes = bytes;
  19088. }
  19089. var major = bytes[0];
  19090. var minor = bytes[1];
  19091. var hdrSize = bytes[2];
  19092. var offSize = bytes[3];
  19093. var header = new CFFHeader(major, minor, hdrSize, offSize);
  19094. return { obj: header, endPos: hdrSize };
  19095. },
  19096. parseDict: function CFFParser_parseDict(dict) {
  19097. var pos = 0;
  19098. function parseOperand() {
  19099. var value = dict[pos++];
  19100. if (value === 30) {
  19101. return parseFloatOperand(pos);
  19102. } else if (value === 28) {
  19103. value = dict[pos++];
  19104. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  19105. return value;
  19106. } else if (value === 29) {
  19107. value = dict[pos++];
  19108. value = (value << 8) | dict[pos++];
  19109. value = (value << 8) | dict[pos++];
  19110. value = (value << 8) | dict[pos++];
  19111. return value;
  19112. } else if (value >= 32 && value <= 246) {
  19113. return value - 139;
  19114. } else if (value >= 247 && value <= 250) {
  19115. return ((value - 247) * 256) + dict[pos++] + 108;
  19116. } else if (value >= 251 && value <= 254) {
  19117. return -((value - 251) * 256) - dict[pos++] - 108;
  19118. } else {
  19119. error('255 is not a valid DICT command');
  19120. }
  19121. return -1;
  19122. }
  19123. function parseFloatOperand() {
  19124. var str = '';
  19125. var eof = 15;
  19126. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  19127. '9', '.', 'E', 'E-', null, '-'];
  19128. var length = dict.length;
  19129. while (pos < length) {
  19130. var b = dict[pos++];
  19131. var b1 = b >> 4;
  19132. var b2 = b & 15;
  19133. if (b1 === eof) {
  19134. break;
  19135. }
  19136. str += lookup[b1];
  19137. if (b2 === eof) {
  19138. break;
  19139. }
  19140. str += lookup[b2];
  19141. }
  19142. return parseFloat(str);
  19143. }
  19144. var operands = [];
  19145. var entries = [];
  19146. pos = 0;
  19147. var end = dict.length;
  19148. while (pos < end) {
  19149. var b = dict[pos];
  19150. if (b <= 21) {
  19151. if (b === 12) {
  19152. b = (b << 8) | dict[++pos];
  19153. }
  19154. entries.push([b, operands]);
  19155. operands = [];
  19156. ++pos;
  19157. } else {
  19158. operands.push(parseOperand());
  19159. }
  19160. }
  19161. return entries;
  19162. },
  19163. parseIndex: function CFFParser_parseIndex(pos) {
  19164. var cffIndex = new CFFIndex();
  19165. var bytes = this.bytes;
  19166. var count = (bytes[pos++] << 8) | bytes[pos++];
  19167. var offsets = [];
  19168. var end = pos;
  19169. var i, ii;
  19170. if (count !== 0) {
  19171. var offsetSize = bytes[pos++];
  19172. // add 1 for offset to determine size of last object
  19173. var startPos = pos + ((count + 1) * offsetSize) - 1;
  19174. for (i = 0, ii = count + 1; i < ii; ++i) {
  19175. var offset = 0;
  19176. for (var j = 0; j < offsetSize; ++j) {
  19177. offset <<= 8;
  19178. offset += bytes[pos++];
  19179. }
  19180. offsets.push(startPos + offset);
  19181. }
  19182. end = offsets[count];
  19183. }
  19184. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  19185. var offsetStart = offsets[i];
  19186. var offsetEnd = offsets[i + 1];
  19187. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  19188. }
  19189. return {obj: cffIndex, endPos: end};
  19190. },
  19191. parseNameIndex: function CFFParser_parseNameIndex(index) {
  19192. var names = [];
  19193. for (var i = 0, ii = index.count; i < ii; ++i) {
  19194. var name = index.get(i);
  19195. // OTS doesn't allow names to be over 127 characters.
  19196. var length = Math.min(name.length, 127);
  19197. var data = [];
  19198. // OTS also only permits certain characters in the name.
  19199. for (var j = 0; j < length; ++j) {
  19200. var c = name[j];
  19201. if (j === 0 && c === 0) {
  19202. data[j] = c;
  19203. continue;
  19204. }
  19205. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  19206. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  19207. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  19208. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  19209. data[j] = 95;
  19210. continue;
  19211. }
  19212. data[j] = c;
  19213. }
  19214. names.push(bytesToString(data));
  19215. }
  19216. return names;
  19217. },
  19218. parseStringIndex: function CFFParser_parseStringIndex(index) {
  19219. var strings = new CFFStrings();
  19220. for (var i = 0, ii = index.count; i < ii; ++i) {
  19221. var data = index.get(i);
  19222. strings.add(bytesToString(data));
  19223. }
  19224. return strings;
  19225. },
  19226. createDict: function CFFParser_createDict(Type, dict, strings) {
  19227. var cffDict = new Type(strings);
  19228. for (var i = 0, ii = dict.length; i < ii; ++i) {
  19229. var pair = dict[i];
  19230. var key = pair[0];
  19231. var value = pair[1];
  19232. cffDict.setByKey(key, value);
  19233. }
  19234. return cffDict;
  19235. },
  19236. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  19237. var charStrings = this.parseIndex(charStringOffset).obj;
  19238. var seacs = [];
  19239. var widths = [];
  19240. var count = charStrings.count;
  19241. for (var i = 0; i < count; i++) {
  19242. var charstring = charStrings.get(i);
  19243. var stackSize = 0;
  19244. var stack = [];
  19245. var undefStack = true;
  19246. var hints = 0;
  19247. var valid = true;
  19248. var data = charstring;
  19249. var length = data.length;
  19250. var firstStackClearing = true;
  19251. for (var j = 0; j < length;) {
  19252. var value = data[j++];
  19253. var validationCommand = null;
  19254. if (value === 12) {
  19255. var q = data[j++];
  19256. if (q === 0) {
  19257. // The CFF specification state that the 'dotsection' command
  19258. // (12, 0) is deprecated and treated as a no-op, but all Type2
  19259. // charstrings processors should support them. Unfortunately
  19260. // the font sanitizer don't. As a workaround the sequence (12, 0)
  19261. // is replaced by a useless (0, hmoveto).
  19262. data[j - 2] = 139;
  19263. data[j - 1] = 22;
  19264. stackSize = 0;
  19265. } else {
  19266. validationCommand = CharstringValidationData12[q];
  19267. }
  19268. } else if (value === 28) { // number (16 bit)
  19269. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  19270. j += 2;
  19271. stackSize++;
  19272. } else if (value === 14) {
  19273. if (stackSize >= 4) {
  19274. stackSize -= 4;
  19275. if (SEAC_ANALYSIS_ENABLED) {
  19276. seacs[i] = stack.slice(stackSize, stackSize + 4);
  19277. valid = false;
  19278. }
  19279. }
  19280. validationCommand = CharstringValidationData[value];
  19281. } else if (value >= 32 && value <= 246) { // number
  19282. stack[stackSize] = value - 139;
  19283. stackSize++;
  19284. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  19285. stack[stackSize] = (value < 251 ?
  19286. ((value - 247) << 8) + data[j] + 108 :
  19287. -((value - 251) << 8) - data[j] - 108);
  19288. j++;
  19289. stackSize++;
  19290. } else if (value === 255) { // number (32 bit)
  19291. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  19292. (data[j + 2] << 8) | data[j + 3]) / 65536;
  19293. j += 4;
  19294. stackSize++;
  19295. } else if (value === 19 || value === 20) {
  19296. hints += stackSize >> 1;
  19297. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  19298. stackSize %= 2;
  19299. validationCommand = CharstringValidationData[value];
  19300. } else {
  19301. validationCommand = CharstringValidationData[value];
  19302. }
  19303. if (validationCommand) {
  19304. if (validationCommand.stem) {
  19305. hints += stackSize >> 1;
  19306. }
  19307. if ('min' in validationCommand) {
  19308. if (!undefStack && stackSize < validationCommand.min) {
  19309. warn('Not enough parameters for ' + validationCommand.id +
  19310. '; actual: ' + stackSize +
  19311. ', expected: ' + validationCommand.min);
  19312. valid = false;
  19313. break;
  19314. }
  19315. }
  19316. if (firstStackClearing && validationCommand.stackClearing) {
  19317. firstStackClearing = false;
  19318. // the optional character width can be found before the first
  19319. // stack-clearing command arguments
  19320. stackSize -= validationCommand.min;
  19321. if (stackSize >= 2 && validationCommand.stem) {
  19322. // there are even amount of arguments for stem commands
  19323. stackSize %= 2;
  19324. } else if (stackSize > 1) {
  19325. warn('Found too many parameters for stack-clearing command');
  19326. }
  19327. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  19328. widths[i] = stack[stackSize - 1];
  19329. }
  19330. }
  19331. if ('stackDelta' in validationCommand) {
  19332. if ('stackFn' in validationCommand) {
  19333. validationCommand.stackFn(stack, stackSize);
  19334. }
  19335. stackSize += validationCommand.stackDelta;
  19336. } else if (validationCommand.stackClearing) {
  19337. stackSize = 0;
  19338. } else if (validationCommand.resetStack) {
  19339. stackSize = 0;
  19340. undefStack = false;
  19341. } else if (validationCommand.undefStack) {
  19342. stackSize = 0;
  19343. undefStack = true;
  19344. firstStackClearing = false;
  19345. }
  19346. }
  19347. }
  19348. if (!valid) {
  19349. // resetting invalid charstring to single 'endchar'
  19350. charStrings.set(i, new Uint8Array([14]));
  19351. }
  19352. }
  19353. return { charStrings: charStrings, seacs: seacs, widths: widths };
  19354. },
  19355. emptyPrivateDictionary:
  19356. function CFFParser_emptyPrivateDictionary(parentDict) {
  19357. var privateDict = this.createDict(CFFPrivateDict, [],
  19358. parentDict.strings);
  19359. parentDict.setByKey(18, [0, 0]);
  19360. parentDict.privateDict = privateDict;
  19361. },
  19362. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  19363. // no private dict, do nothing
  19364. if (!parentDict.hasName('Private')) {
  19365. this.emptyPrivateDictionary(parentDict);
  19366. return;
  19367. }
  19368. var privateOffset = parentDict.getByName('Private');
  19369. // make sure the params are formatted correctly
  19370. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  19371. parentDict.removeByName('Private');
  19372. return;
  19373. }
  19374. var size = privateOffset[0];
  19375. var offset = privateOffset[1];
  19376. // remove empty dicts or ones that refer to invalid location
  19377. if (size === 0 || offset >= this.bytes.length) {
  19378. this.emptyPrivateDictionary(parentDict);
  19379. return;
  19380. }
  19381. var privateDictEnd = offset + size;
  19382. var dictData = this.bytes.subarray(offset, privateDictEnd);
  19383. var dict = this.parseDict(dictData);
  19384. var privateDict = this.createDict(CFFPrivateDict, dict,
  19385. parentDict.strings);
  19386. parentDict.privateDict = privateDict;
  19387. // Parse the Subrs index also since it's relative to the private dict.
  19388. if (!privateDict.getByName('Subrs')) {
  19389. return;
  19390. }
  19391. var subrsOffset = privateDict.getByName('Subrs');
  19392. var relativeOffset = offset + subrsOffset;
  19393. // Validate the offset.
  19394. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  19395. this.emptyPrivateDictionary(parentDict);
  19396. return;
  19397. }
  19398. var subrsIndex = this.parseIndex(relativeOffset);
  19399. privateDict.subrsIndex = subrsIndex.obj;
  19400. },
  19401. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  19402. if (pos === 0) {
  19403. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  19404. ISOAdobeCharset);
  19405. } else if (pos === 1) {
  19406. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  19407. ExpertCharset);
  19408. } else if (pos === 2) {
  19409. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  19410. ExpertSubsetCharset);
  19411. }
  19412. var bytes = this.bytes;
  19413. var start = pos;
  19414. var format = bytes[pos++];
  19415. var charset = ['.notdef'];
  19416. var id, count, i;
  19417. // subtract 1 for the .notdef glyph
  19418. length -= 1;
  19419. switch (format) {
  19420. case 0:
  19421. for (i = 0; i < length; i++) {
  19422. id = (bytes[pos++] << 8) | bytes[pos++];
  19423. charset.push(cid ? id : strings.get(id));
  19424. }
  19425. break;
  19426. case 1:
  19427. while (charset.length <= length) {
  19428. id = (bytes[pos++] << 8) | bytes[pos++];
  19429. count = bytes[pos++];
  19430. for (i = 0; i <= count; i++) {
  19431. charset.push(cid ? id++ : strings.get(id++));
  19432. }
  19433. }
  19434. break;
  19435. case 2:
  19436. while (charset.length <= length) {
  19437. id = (bytes[pos++] << 8) | bytes[pos++];
  19438. count = (bytes[pos++] << 8) | bytes[pos++];
  19439. for (i = 0; i <= count; i++) {
  19440. charset.push(cid ? id++ : strings.get(id++));
  19441. }
  19442. }
  19443. break;
  19444. default:
  19445. error('Unknown charset format');
  19446. }
  19447. // Raw won't be needed if we actually compile the charset.
  19448. var end = pos;
  19449. var raw = bytes.subarray(start, end);
  19450. return new CFFCharset(false, format, charset, raw);
  19451. },
  19452. parseEncoding: function CFFParser_parseEncoding(pos,
  19453. properties,
  19454. strings,
  19455. charset) {
  19456. var encoding = {};
  19457. var bytes = this.bytes;
  19458. var predefined = false;
  19459. var hasSupplement = false;
  19460. var format, i, ii;
  19461. var raw = null;
  19462. function readSupplement() {
  19463. var supplementsCount = bytes[pos++];
  19464. for (i = 0; i < supplementsCount; i++) {
  19465. var code = bytes[pos++];
  19466. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  19467. encoding[code] = charset.indexOf(strings.get(sid));
  19468. }
  19469. }
  19470. if (pos === 0 || pos === 1) {
  19471. predefined = true;
  19472. format = pos;
  19473. var baseEncoding = pos ? Encodings.ExpertEncoding :
  19474. Encodings.StandardEncoding;
  19475. for (i = 0, ii = charset.length; i < ii; i++) {
  19476. var index = baseEncoding.indexOf(charset[i]);
  19477. if (index !== -1) {
  19478. encoding[index] = i;
  19479. }
  19480. }
  19481. } else {
  19482. var dataStart = pos;
  19483. format = bytes[pos++];
  19484. switch (format & 0x7f) {
  19485. case 0:
  19486. var glyphsCount = bytes[pos++];
  19487. for (i = 1; i <= glyphsCount; i++) {
  19488. encoding[bytes[pos++]] = i;
  19489. }
  19490. break;
  19491. case 1:
  19492. var rangesCount = bytes[pos++];
  19493. var gid = 1;
  19494. for (i = 0; i < rangesCount; i++) {
  19495. var start = bytes[pos++];
  19496. var left = bytes[pos++];
  19497. for (var j = start; j <= start + left; j++) {
  19498. encoding[j] = gid++;
  19499. }
  19500. }
  19501. break;
  19502. default:
  19503. error('Unknow encoding format: ' + format + ' in CFF');
  19504. break;
  19505. }
  19506. var dataEnd = pos;
  19507. if (format & 0x80) {
  19508. // The font sanitizer does not support CFF encoding with a
  19509. // supplement, since the encoding is not really used to map
  19510. // between gid to glyph, let's overwrite what is declared in
  19511. // the top dictionary to let the sanitizer think the font use
  19512. // StandardEncoding, that's a lie but that's ok.
  19513. bytes[dataStart] &= 0x7f;
  19514. readSupplement();
  19515. hasSupplement = true;
  19516. }
  19517. raw = bytes.subarray(dataStart, dataEnd);
  19518. }
  19519. format = format & 0x7f;
  19520. return new CFFEncoding(predefined, format, encoding, raw);
  19521. },
  19522. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19523. var start = pos;
  19524. var bytes = this.bytes;
  19525. var format = bytes[pos++];
  19526. var fdSelect = [];
  19527. var i;
  19528. switch (format) {
  19529. case 0:
  19530. for (i = 0; i < length; ++i) {
  19531. var id = bytes[pos++];
  19532. fdSelect.push(id);
  19533. }
  19534. break;
  19535. case 3:
  19536. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19537. for (i = 0; i < rangesCount; ++i) {
  19538. var first = (bytes[pos++] << 8) | bytes[pos++];
  19539. var fdIndex = bytes[pos++];
  19540. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19541. for (var j = first; j < next; ++j) {
  19542. fdSelect.push(fdIndex);
  19543. }
  19544. }
  19545. // Advance past the sentinel(next).
  19546. pos += 2;
  19547. break;
  19548. default:
  19549. error('Unknown fdselect format ' + format);
  19550. break;
  19551. }
  19552. var end = pos;
  19553. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19554. }
  19555. };
  19556. return CFFParser;
  19557. })();
  19558. // Compact Font Format
  19559. var CFF = (function CFFClosure() {
  19560. function CFF() {
  19561. this.header = null;
  19562. this.names = [];
  19563. this.topDict = null;
  19564. this.strings = new CFFStrings();
  19565. this.globalSubrIndex = null;
  19566. // The following could really be per font, but since we only have one font
  19567. // store them here.
  19568. this.encoding = null;
  19569. this.charset = null;
  19570. this.charStrings = null;
  19571. this.fdArray = [];
  19572. this.fdSelect = null;
  19573. this.isCIDFont = false;
  19574. }
  19575. return CFF;
  19576. })();
  19577. var CFFHeader = (function CFFHeaderClosure() {
  19578. function CFFHeader(major, minor, hdrSize, offSize) {
  19579. this.major = major;
  19580. this.minor = minor;
  19581. this.hdrSize = hdrSize;
  19582. this.offSize = offSize;
  19583. }
  19584. return CFFHeader;
  19585. })();
  19586. var CFFStrings = (function CFFStringsClosure() {
  19587. function CFFStrings() {
  19588. this.strings = [];
  19589. }
  19590. CFFStrings.prototype = {
  19591. get: function CFFStrings_get(index) {
  19592. if (index >= 0 && index <= 390) {
  19593. return CFFStandardStrings[index];
  19594. }
  19595. if (index - 391 <= this.strings.length) {
  19596. return this.strings[index - 391];
  19597. }
  19598. return CFFStandardStrings[0];
  19599. },
  19600. add: function CFFStrings_add(value) {
  19601. this.strings.push(value);
  19602. },
  19603. get count() {
  19604. return this.strings.length;
  19605. }
  19606. };
  19607. return CFFStrings;
  19608. })();
  19609. var CFFIndex = (function CFFIndexClosure() {
  19610. function CFFIndex() {
  19611. this.objects = [];
  19612. this.length = 0;
  19613. }
  19614. CFFIndex.prototype = {
  19615. add: function CFFIndex_add(data) {
  19616. this.length += data.length;
  19617. this.objects.push(data);
  19618. },
  19619. set: function CFFIndex_set(index, data) {
  19620. this.length += data.length - this.objects[index].length;
  19621. this.objects[index] = data;
  19622. },
  19623. get: function CFFIndex_get(index) {
  19624. return this.objects[index];
  19625. },
  19626. get count() {
  19627. return this.objects.length;
  19628. }
  19629. };
  19630. return CFFIndex;
  19631. })();
  19632. var CFFDict = (function CFFDictClosure() {
  19633. function CFFDict(tables, strings) {
  19634. this.keyToNameMap = tables.keyToNameMap;
  19635. this.nameToKeyMap = tables.nameToKeyMap;
  19636. this.defaults = tables.defaults;
  19637. this.types = tables.types;
  19638. this.opcodes = tables.opcodes;
  19639. this.order = tables.order;
  19640. this.strings = strings;
  19641. this.values = {};
  19642. }
  19643. CFFDict.prototype = {
  19644. // value should always be an array
  19645. setByKey: function CFFDict_setByKey(key, value) {
  19646. if (!(key in this.keyToNameMap)) {
  19647. return false;
  19648. }
  19649. // ignore empty values
  19650. if (value.length === 0) {
  19651. return true;
  19652. }
  19653. var type = this.types[key];
  19654. // remove the array wrapping these types of values
  19655. if (type === 'num' || type === 'sid' || type === 'offset') {
  19656. value = value[0];
  19657. }
  19658. this.values[key] = value;
  19659. return true;
  19660. },
  19661. setByName: function CFFDict_setByName(name, value) {
  19662. if (!(name in this.nameToKeyMap)) {
  19663. error('Invalid dictionary name "' + name + '"');
  19664. }
  19665. this.values[this.nameToKeyMap[name]] = value;
  19666. },
  19667. hasName: function CFFDict_hasName(name) {
  19668. return this.nameToKeyMap[name] in this.values;
  19669. },
  19670. getByName: function CFFDict_getByName(name) {
  19671. if (!(name in this.nameToKeyMap)) {
  19672. error('Invalid dictionary name "' + name + '"');
  19673. }
  19674. var key = this.nameToKeyMap[name];
  19675. if (!(key in this.values)) {
  19676. return this.defaults[key];
  19677. }
  19678. return this.values[key];
  19679. },
  19680. removeByName: function CFFDict_removeByName(name) {
  19681. delete this.values[this.nameToKeyMap[name]];
  19682. }
  19683. };
  19684. CFFDict.createTables = function CFFDict_createTables(layout) {
  19685. var tables = {
  19686. keyToNameMap: {},
  19687. nameToKeyMap: {},
  19688. defaults: {},
  19689. types: {},
  19690. opcodes: {},
  19691. order: []
  19692. };
  19693. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19694. var entry = layout[i];
  19695. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19696. tables.keyToNameMap[key] = entry[1];
  19697. tables.nameToKeyMap[entry[1]] = key;
  19698. tables.types[key] = entry[2];
  19699. tables.defaults[key] = entry[3];
  19700. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19701. tables.order.push(key);
  19702. }
  19703. return tables;
  19704. };
  19705. return CFFDict;
  19706. })();
  19707. var CFFTopDict = (function CFFTopDictClosure() {
  19708. var layout = [
  19709. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19710. [[12, 20], 'SyntheticBase', 'num', null],
  19711. [0, 'version', 'sid', null],
  19712. [1, 'Notice', 'sid', null],
  19713. [[12, 0], 'Copyright', 'sid', null],
  19714. [2, 'FullName', 'sid', null],
  19715. [3, 'FamilyName', 'sid', null],
  19716. [4, 'Weight', 'sid', null],
  19717. [[12, 1], 'isFixedPitch', 'num', 0],
  19718. [[12, 2], 'ItalicAngle', 'num', 0],
  19719. [[12, 3], 'UnderlinePosition', 'num', -100],
  19720. [[12, 4], 'UnderlineThickness', 'num', 50],
  19721. [[12, 5], 'PaintType', 'num', 0],
  19722. [[12, 6], 'CharstringType', 'num', 2],
  19723. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19724. [0.001, 0, 0, 0.001, 0, 0]],
  19725. [13, 'UniqueID', 'num', null],
  19726. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19727. [[12, 8], 'StrokeWidth', 'num', 0],
  19728. [14, 'XUID', 'array', null],
  19729. [15, 'charset', 'offset', 0],
  19730. [16, 'Encoding', 'offset', 0],
  19731. [17, 'CharStrings', 'offset', 0],
  19732. [18, 'Private', ['offset', 'offset'], null],
  19733. [[12, 21], 'PostScript', 'sid', null],
  19734. [[12, 22], 'BaseFontName', 'sid', null],
  19735. [[12, 23], 'BaseFontBlend', 'delta', null],
  19736. [[12, 31], 'CIDFontVersion', 'num', 0],
  19737. [[12, 32], 'CIDFontRevision', 'num', 0],
  19738. [[12, 33], 'CIDFontType', 'num', 0],
  19739. [[12, 34], 'CIDCount', 'num', 8720],
  19740. [[12, 35], 'UIDBase', 'num', null],
  19741. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19742. // before FDArray.
  19743. [[12, 37], 'FDSelect', 'offset', null],
  19744. [[12, 36], 'FDArray', 'offset', null],
  19745. [[12, 38], 'FontName', 'sid', null]
  19746. ];
  19747. var tables = null;
  19748. function CFFTopDict(strings) {
  19749. if (tables === null) {
  19750. tables = CFFDict.createTables(layout);
  19751. }
  19752. CFFDict.call(this, tables, strings);
  19753. this.privateDict = null;
  19754. }
  19755. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19756. return CFFTopDict;
  19757. })();
  19758. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19759. var layout = [
  19760. [6, 'BlueValues', 'delta', null],
  19761. [7, 'OtherBlues', 'delta', null],
  19762. [8, 'FamilyBlues', 'delta', null],
  19763. [9, 'FamilyOtherBlues', 'delta', null],
  19764. [[12, 9], 'BlueScale', 'num', 0.039625],
  19765. [[12, 10], 'BlueShift', 'num', 7],
  19766. [[12, 11], 'BlueFuzz', 'num', 1],
  19767. [10, 'StdHW', 'num', null],
  19768. [11, 'StdVW', 'num', null],
  19769. [[12, 12], 'StemSnapH', 'delta', null],
  19770. [[12, 13], 'StemSnapV', 'delta', null],
  19771. [[12, 14], 'ForceBold', 'num', 0],
  19772. [[12, 17], 'LanguageGroup', 'num', 0],
  19773. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19774. [[12, 19], 'initialRandomSeed', 'num', 0],
  19775. [20, 'defaultWidthX', 'num', 0],
  19776. [21, 'nominalWidthX', 'num', 0],
  19777. [19, 'Subrs', 'offset', null]
  19778. ];
  19779. var tables = null;
  19780. function CFFPrivateDict(strings) {
  19781. if (tables === null) {
  19782. tables = CFFDict.createTables(layout);
  19783. }
  19784. CFFDict.call(this, tables, strings);
  19785. this.subrsIndex = null;
  19786. }
  19787. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19788. return CFFPrivateDict;
  19789. })();
  19790. var CFFCharsetPredefinedTypes = {
  19791. ISO_ADOBE: 0,
  19792. EXPERT: 1,
  19793. EXPERT_SUBSET: 2
  19794. };
  19795. var CFFCharset = (function CFFCharsetClosure() {
  19796. function CFFCharset(predefined, format, charset, raw) {
  19797. this.predefined = predefined;
  19798. this.format = format;
  19799. this.charset = charset;
  19800. this.raw = raw;
  19801. }
  19802. return CFFCharset;
  19803. })();
  19804. var CFFEncoding = (function CFFEncodingClosure() {
  19805. function CFFEncoding(predefined, format, encoding, raw) {
  19806. this.predefined = predefined;
  19807. this.format = format;
  19808. this.encoding = encoding;
  19809. this.raw = raw;
  19810. }
  19811. return CFFEncoding;
  19812. })();
  19813. var CFFFDSelect = (function CFFFDSelectClosure() {
  19814. function CFFFDSelect(fdSelect, raw) {
  19815. this.fdSelect = fdSelect;
  19816. this.raw = raw;
  19817. }
  19818. return CFFFDSelect;
  19819. })();
  19820. // Helper class to keep track of where an offset is within the data and helps
  19821. // filling in that offset once it's known.
  19822. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19823. function CFFOffsetTracker() {
  19824. this.offsets = {};
  19825. }
  19826. CFFOffsetTracker.prototype = {
  19827. isTracking: function CFFOffsetTracker_isTracking(key) {
  19828. return key in this.offsets;
  19829. },
  19830. track: function CFFOffsetTracker_track(key, location) {
  19831. if (key in this.offsets) {
  19832. error('Already tracking location of ' + key);
  19833. }
  19834. this.offsets[key] = location;
  19835. },
  19836. offset: function CFFOffsetTracker_offset(value) {
  19837. for (var key in this.offsets) {
  19838. this.offsets[key] += value;
  19839. }
  19840. },
  19841. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19842. values,
  19843. output) {
  19844. if (!(key in this.offsets)) {
  19845. error('Not tracking location of ' + key);
  19846. }
  19847. var data = output.data;
  19848. var dataOffset = this.offsets[key];
  19849. var size = 5;
  19850. for (var i = 0, ii = values.length; i < ii; ++i) {
  19851. var offset0 = i * size + dataOffset;
  19852. var offset1 = offset0 + 1;
  19853. var offset2 = offset0 + 2;
  19854. var offset3 = offset0 + 3;
  19855. var offset4 = offset0 + 4;
  19856. // It's easy to screw up offsets so perform this sanity check.
  19857. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19858. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19859. error('writing to an offset that is not empty');
  19860. }
  19861. var value = values[i];
  19862. data[offset0] = 0x1d;
  19863. data[offset1] = (value >> 24) & 0xFF;
  19864. data[offset2] = (value >> 16) & 0xFF;
  19865. data[offset3] = (value >> 8) & 0xFF;
  19866. data[offset4] = value & 0xFF;
  19867. }
  19868. }
  19869. };
  19870. return CFFOffsetTracker;
  19871. })();
  19872. // Takes a CFF and converts it to the binary representation.
  19873. var CFFCompiler = (function CFFCompilerClosure() {
  19874. function CFFCompiler(cff) {
  19875. this.cff = cff;
  19876. }
  19877. CFFCompiler.prototype = {
  19878. compile: function CFFCompiler_compile() {
  19879. var cff = this.cff;
  19880. var output = {
  19881. data: [],
  19882. length: 0,
  19883. add: function CFFCompiler_add(data) {
  19884. this.data = this.data.concat(data);
  19885. this.length = this.data.length;
  19886. }
  19887. };
  19888. // Compile the five entries that must be in order.
  19889. var header = this.compileHeader(cff.header);
  19890. output.add(header);
  19891. var nameIndex = this.compileNameIndex(cff.names);
  19892. output.add(nameIndex);
  19893. if (cff.isCIDFont) {
  19894. // The spec is unclear on how font matrices should relate to each other
  19895. // when there is one in the main top dict and the sub top dicts.
  19896. // Windows handles this differently than linux and osx so we have to
  19897. // normalize to work on all.
  19898. // Rules based off of some mailing list discussions:
  19899. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19900. // - If no main font matrix and there is a subfont matrix, use the
  19901. // subfont matrix.
  19902. // - If both have matrices, concat together.
  19903. // - If neither have matrices, use default.
  19904. // To make this work on all platforms we move the top matrix into each
  19905. // sub top dict and concat if necessary.
  19906. if (cff.topDict.hasName('FontMatrix')) {
  19907. var base = cff.topDict.getByName('FontMatrix');
  19908. cff.topDict.removeByName('FontMatrix');
  19909. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19910. var subDict = cff.fdArray[i];
  19911. var matrix = base.slice(0);
  19912. if (subDict.hasName('FontMatrix')) {
  19913. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19914. }
  19915. subDict.setByName('FontMatrix', matrix);
  19916. }
  19917. }
  19918. }
  19919. var compiled = this.compileTopDicts([cff.topDict],
  19920. output.length,
  19921. cff.isCIDFont);
  19922. output.add(compiled.output);
  19923. var topDictTracker = compiled.trackers[0];
  19924. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19925. output.add(stringIndex);
  19926. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19927. output.add(globalSubrIndex);
  19928. // Now start on the other entries that have no specfic order.
  19929. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19930. if (cff.encoding.predefined) {
  19931. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19932. output);
  19933. } else {
  19934. var encoding = this.compileEncoding(cff.encoding);
  19935. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19936. output.add(encoding);
  19937. }
  19938. }
  19939. if (cff.charset && cff.topDict.hasName('charset')) {
  19940. if (cff.charset.predefined) {
  19941. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19942. output);
  19943. } else {
  19944. var charset = this.compileCharset(cff.charset);
  19945. topDictTracker.setEntryLocation('charset', [output.length], output);
  19946. output.add(charset);
  19947. }
  19948. }
  19949. var charStrings = this.compileCharStrings(cff.charStrings);
  19950. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19951. output.add(charStrings);
  19952. if (cff.isCIDFont) {
  19953. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19954. // and linux don't seem to care.
  19955. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19956. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19957. output.add(fdSelect);
  19958. // It is unclear if the sub font dictionary can have CID related
  19959. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19960. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19961. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19962. output.add(compiled.output);
  19963. var fontDictTrackers = compiled.trackers;
  19964. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19965. }
  19966. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19967. // If the font data ends with INDEX whose object data is zero-length,
  19968. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19969. output.add([0]);
  19970. return output.data;
  19971. },
  19972. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19973. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19974. return this.encodeInteger(value);
  19975. } else {
  19976. return this.encodeFloat(value);
  19977. }
  19978. },
  19979. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19980. var value = num.toString();
  19981. // rounding inaccurate doubles
  19982. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19983. if (m) {
  19984. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19985. value = (Math.round(num * epsilon) / epsilon).toString();
  19986. }
  19987. var nibbles = '';
  19988. var i, ii;
  19989. for (i = 0, ii = value.length; i < ii; ++i) {
  19990. var a = value[i];
  19991. if (a === 'e') {
  19992. nibbles += value[++i] === '-' ? 'c' : 'b';
  19993. } else if (a === '.') {
  19994. nibbles += 'a';
  19995. } else if (a === '-') {
  19996. nibbles += 'e';
  19997. } else {
  19998. nibbles += a;
  19999. }
  20000. }
  20001. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  20002. var out = [30];
  20003. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  20004. out.push(parseInt(nibbles.substr(i, 2), 16));
  20005. }
  20006. return out;
  20007. },
  20008. encodeInteger: function CFFCompiler_encodeInteger(value) {
  20009. var code;
  20010. if (value >= -107 && value <= 107) {
  20011. code = [value + 139];
  20012. } else if (value >= 108 && value <= 1131) {
  20013. value = [value - 108];
  20014. code = [(value >> 8) + 247, value & 0xFF];
  20015. } else if (value >= -1131 && value <= -108) {
  20016. value = -value - 108;
  20017. code = [(value >> 8) + 251, value & 0xFF];
  20018. } else if (value >= -32768 && value <= 32767) {
  20019. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  20020. } else {
  20021. code = [0x1d,
  20022. (value >> 24) & 0xFF,
  20023. (value >> 16) & 0xFF,
  20024. (value >> 8) & 0xFF,
  20025. value & 0xFF];
  20026. }
  20027. return code;
  20028. },
  20029. compileHeader: function CFFCompiler_compileHeader(header) {
  20030. return [
  20031. header.major,
  20032. header.minor,
  20033. header.hdrSize,
  20034. header.offSize
  20035. ];
  20036. },
  20037. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  20038. var nameIndex = new CFFIndex();
  20039. for (var i = 0, ii = names.length; i < ii; ++i) {
  20040. nameIndex.add(stringToBytes(names[i]));
  20041. }
  20042. return this.compileIndex(nameIndex);
  20043. },
  20044. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  20045. length,
  20046. removeCidKeys) {
  20047. var fontDictTrackers = [];
  20048. var fdArrayIndex = new CFFIndex();
  20049. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  20050. var fontDict = dicts[i];
  20051. if (removeCidKeys) {
  20052. fontDict.removeByName('CIDFontVersion');
  20053. fontDict.removeByName('CIDFontRevision');
  20054. fontDict.removeByName('CIDFontType');
  20055. fontDict.removeByName('CIDCount');
  20056. fontDict.removeByName('UIDBase');
  20057. }
  20058. var fontDictTracker = new CFFOffsetTracker();
  20059. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  20060. fontDictTrackers.push(fontDictTracker);
  20061. fdArrayIndex.add(fontDictData);
  20062. fontDictTracker.offset(length);
  20063. }
  20064. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  20065. return {
  20066. trackers: fontDictTrackers,
  20067. output: fdArrayIndex
  20068. };
  20069. },
  20070. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  20071. trackers,
  20072. output) {
  20073. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  20074. var fontDict = dicts[i];
  20075. assert(fontDict.privateDict && fontDict.hasName('Private'),
  20076. 'There must be an private dictionary.');
  20077. var privateDict = fontDict.privateDict;
  20078. var privateDictTracker = new CFFOffsetTracker();
  20079. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  20080. var outputLength = output.length;
  20081. privateDictTracker.offset(outputLength);
  20082. if (!privateDictData.length) {
  20083. // The private dictionary was empty, set the output length to zero to
  20084. // ensure the offset length isn't out of bounds in the eyes of the
  20085. // sanitizer.
  20086. outputLength = 0;
  20087. }
  20088. trackers[i].setEntryLocation('Private',
  20089. [privateDictData.length, outputLength],
  20090. output);
  20091. output.add(privateDictData);
  20092. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  20093. var subrs = this.compileIndex(privateDict.subrsIndex);
  20094. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  20095. output);
  20096. output.add(subrs);
  20097. }
  20098. }
  20099. },
  20100. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  20101. var out = [];
  20102. // The dictionary keys must be in a certain order.
  20103. var order = dict.order;
  20104. for (var i = 0; i < order.length; ++i) {
  20105. var key = order[i];
  20106. if (!(key in dict.values)) {
  20107. continue;
  20108. }
  20109. var values = dict.values[key];
  20110. var types = dict.types[key];
  20111. if (!isArray(types)) {
  20112. types = [types];
  20113. }
  20114. if (!isArray(values)) {
  20115. values = [values];
  20116. }
  20117. // Remove any empty dict values.
  20118. if (values.length === 0) {
  20119. continue;
  20120. }
  20121. for (var j = 0, jj = types.length; j < jj; ++j) {
  20122. var type = types[j];
  20123. var value = values[j];
  20124. switch (type) {
  20125. case 'num':
  20126. case 'sid':
  20127. out = out.concat(this.encodeNumber(value));
  20128. break;
  20129. case 'offset':
  20130. // For offsets we just insert a 32bit integer so we don't have to
  20131. // deal with figuring out the length of the offset when it gets
  20132. // replaced later on by the compiler.
  20133. var name = dict.keyToNameMap[key];
  20134. // Some offsets have the offset and the length, so just record the
  20135. // position of the first one.
  20136. if (!offsetTracker.isTracking(name)) {
  20137. offsetTracker.track(name, out.length);
  20138. }
  20139. out = out.concat([0x1d, 0, 0, 0, 0]);
  20140. break;
  20141. case 'array':
  20142. case 'delta':
  20143. out = out.concat(this.encodeNumber(value));
  20144. for (var k = 1, kk = values.length; k < kk; ++k) {
  20145. out = out.concat(this.encodeNumber(values[k]));
  20146. }
  20147. break;
  20148. default:
  20149. error('Unknown data type of ' + type);
  20150. break;
  20151. }
  20152. }
  20153. out = out.concat(dict.opcodes[key]);
  20154. }
  20155. return out;
  20156. },
  20157. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  20158. var stringIndex = new CFFIndex();
  20159. for (var i = 0, ii = strings.length; i < ii; ++i) {
  20160. stringIndex.add(stringToBytes(strings[i]));
  20161. }
  20162. return this.compileIndex(stringIndex);
  20163. },
  20164. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  20165. var globalSubrIndex = this.cff.globalSubrIndex;
  20166. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  20167. },
  20168. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  20169. return this.compileIndex(charStrings);
  20170. },
  20171. compileCharset: function CFFCompiler_compileCharset(charset) {
  20172. return this.compileTypedArray(charset.raw);
  20173. },
  20174. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  20175. return this.compileTypedArray(encoding.raw);
  20176. },
  20177. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  20178. return this.compileTypedArray(fdSelect);
  20179. },
  20180. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  20181. var out = [];
  20182. for (var i = 0, ii = data.length; i < ii; ++i) {
  20183. out[i] = data[i];
  20184. }
  20185. return out;
  20186. },
  20187. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  20188. trackers = trackers || [];
  20189. var objects = index.objects;
  20190. // First 2 bytes contains the number of objects contained into this index
  20191. var count = objects.length;
  20192. // If there is no object, just create an index. This technically
  20193. // should just be [0, 0] but OTS has an issue with that.
  20194. if (count === 0) {
  20195. return [0, 0, 0];
  20196. }
  20197. var data = [(count >> 8) & 0xFF, count & 0xff];
  20198. var lastOffset = 1, i;
  20199. for (i = 0; i < count; ++i) {
  20200. lastOffset += objects[i].length;
  20201. }
  20202. var offsetSize;
  20203. if (lastOffset < 0x100) {
  20204. offsetSize = 1;
  20205. } else if (lastOffset < 0x10000) {
  20206. offsetSize = 2;
  20207. } else if (lastOffset < 0x1000000) {
  20208. offsetSize = 3;
  20209. } else {
  20210. offsetSize = 4;
  20211. }
  20212. // Next byte contains the offset size use to reference object in the file
  20213. data.push(offsetSize);
  20214. // Add another offset after this one because we need a new offset
  20215. var relativeOffset = 1;
  20216. for (i = 0; i < count + 1; i++) {
  20217. if (offsetSize === 1) {
  20218. data.push(relativeOffset & 0xFF);
  20219. } else if (offsetSize === 2) {
  20220. data.push((relativeOffset >> 8) & 0xFF,
  20221. relativeOffset & 0xFF);
  20222. } else if (offsetSize === 3) {
  20223. data.push((relativeOffset >> 16) & 0xFF,
  20224. (relativeOffset >> 8) & 0xFF,
  20225. relativeOffset & 0xFF);
  20226. } else {
  20227. data.push((relativeOffset >>> 24) & 0xFF,
  20228. (relativeOffset >> 16) & 0xFF,
  20229. (relativeOffset >> 8) & 0xFF,
  20230. relativeOffset & 0xFF);
  20231. }
  20232. if (objects[i]) {
  20233. relativeOffset += objects[i].length;
  20234. }
  20235. }
  20236. for (i = 0; i < count; i++) {
  20237. // Notify the tracker where the object will be offset in the data.
  20238. if (trackers[i]) {
  20239. trackers[i].offset(data.length);
  20240. }
  20241. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  20242. data.push(objects[i][j]);
  20243. }
  20244. }
  20245. return data;
  20246. }
  20247. };
  20248. return CFFCompiler;
  20249. })();
  20250. // Workaround for seac on Windows.
  20251. (function checkSeacSupport() {
  20252. if (/Windows/.test(navigator.userAgent)) {
  20253. SEAC_ANALYSIS_ENABLED = true;
  20254. }
  20255. })();
  20256. // Workaround for Private Use Area characters in Chrome on Windows
  20257. // http://code.google.com/p/chromium/issues/detail?id=122465
  20258. // https://github.com/mozilla/pdf.js/issues/1689
  20259. (function checkChromeWindows() {
  20260. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  20261. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  20262. }
  20263. })();
  20264. var FontRendererFactory = (function FontRendererFactoryClosure() {
  20265. function getLong(data, offset) {
  20266. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20267. (data[offset + 2] << 8) | data[offset + 3];
  20268. }
  20269. function getUshort(data, offset) {
  20270. return (data[offset] << 8) | data[offset + 1];
  20271. }
  20272. function parseCmap(data, start, end) {
  20273. var offset = (getUshort(data, start + 2) === 1 ?
  20274. getLong(data, start + 8) : getLong(data, start + 16));
  20275. var format = getUshort(data, start + offset);
  20276. var length, ranges, p, i;
  20277. if (format === 4) {
  20278. length = getUshort(data, start + offset + 2);
  20279. var segCount = getUshort(data, start + offset + 6) >> 1;
  20280. p = start + offset + 14;
  20281. ranges = [];
  20282. for (i = 0; i < segCount; i++, p += 2) {
  20283. ranges[i] = {end: getUshort(data, p)};
  20284. }
  20285. p += 2;
  20286. for (i = 0; i < segCount; i++, p += 2) {
  20287. ranges[i].start = getUshort(data, p);
  20288. }
  20289. for (i = 0; i < segCount; i++, p += 2) {
  20290. ranges[i].idDelta = getUshort(data, p);
  20291. }
  20292. for (i = 0; i < segCount; i++, p += 2) {
  20293. var idOffset = getUshort(data, p);
  20294. if (idOffset === 0) {
  20295. continue;
  20296. }
  20297. ranges[i].ids = [];
  20298. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  20299. ranges[i].ids[j] = getUshort(data, p + idOffset);
  20300. idOffset += 2;
  20301. }
  20302. }
  20303. return ranges;
  20304. } else if (format === 12) {
  20305. length = getLong(data, start + offset + 4);
  20306. var groups = getLong(data, start + offset + 12);
  20307. p = start + offset + 16;
  20308. ranges = [];
  20309. for (i = 0; i < groups; i++) {
  20310. ranges.push({
  20311. start: getLong(data, p),
  20312. end: getLong(data, p + 4),
  20313. idDelta: getLong(data, p + 8) - getLong(data, p)
  20314. });
  20315. p += 12;
  20316. }
  20317. return ranges;
  20318. }
  20319. error('not supported cmap: ' + format);
  20320. }
  20321. function parseCff(data, start, end) {
  20322. var properties = {};
  20323. var parser = new CFFParser(new Stream(data, start, end - start),
  20324. properties);
  20325. var cff = parser.parse();
  20326. return {
  20327. glyphs: cff.charStrings.objects,
  20328. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  20329. cff.topDict.privateDict.subrsIndex.objects),
  20330. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  20331. };
  20332. }
  20333. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  20334. var itemSize, itemDecode;
  20335. if (isGlyphLocationsLong) {
  20336. itemSize = 4;
  20337. itemDecode = function fontItemDecodeLong(data, offset) {
  20338. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20339. (data[offset + 2] << 8) | data[offset + 3];
  20340. };
  20341. } else {
  20342. itemSize = 2;
  20343. itemDecode = function fontItemDecode(data, offset) {
  20344. return (data[offset] << 9) | (data[offset + 1] << 1);
  20345. };
  20346. }
  20347. var glyphs = [];
  20348. var startOffset = itemDecode(loca, 0);
  20349. for (var j = itemSize; j < loca.length; j += itemSize) {
  20350. var endOffset = itemDecode(loca, j);
  20351. glyphs.push(glyf.subarray(startOffset, endOffset));
  20352. startOffset = endOffset;
  20353. }
  20354. return glyphs;
  20355. }
  20356. function lookupCmap(ranges, unicode) {
  20357. var code = unicode.charCodeAt(0);
  20358. var l = 0, r = ranges.length - 1;
  20359. while (l < r) {
  20360. var c = (l + r + 1) >> 1;
  20361. if (code < ranges[c].start) {
  20362. r = c - 1;
  20363. } else {
  20364. l = c;
  20365. }
  20366. }
  20367. if (ranges[l].start <= code && code <= ranges[l].end) {
  20368. return (ranges[l].idDelta + (ranges[l].ids ?
  20369. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  20370. }
  20371. return 0;
  20372. }
  20373. function compileGlyf(code, cmds, font) {
  20374. function moveTo(x, y) {
  20375. cmds.push({cmd: 'moveTo', args: [x, y]});
  20376. }
  20377. function lineTo(x, y) {
  20378. cmds.push({cmd: 'lineTo', args: [x, y]});
  20379. }
  20380. function quadraticCurveTo(xa, ya, x, y) {
  20381. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  20382. }
  20383. var i = 0;
  20384. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20385. var flags;
  20386. var x = 0, y = 0;
  20387. i += 10;
  20388. if (numberOfContours < 0) {
  20389. // composite glyph
  20390. do {
  20391. flags = (code[i] << 8) | code[i + 1];
  20392. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  20393. i += 4;
  20394. var arg1, arg2;
  20395. if ((flags & 0x01)) {
  20396. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20397. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  20398. i += 4;
  20399. } else {
  20400. arg1 = code[i++]; arg2 = code[i++];
  20401. }
  20402. if ((flags & 0x02)) {
  20403. x = arg1;
  20404. y = arg2;
  20405. } else {
  20406. x = 0; y = 0; // TODO "they are points" ?
  20407. }
  20408. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  20409. if ((flags & 0x08)) {
  20410. scaleX =
  20411. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20412. i += 2;
  20413. } else if ((flags & 0x40)) {
  20414. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20415. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20416. i += 4;
  20417. } else if ((flags & 0x80)) {
  20418. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20419. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20420. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  20421. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  20422. i += 8;
  20423. }
  20424. var subglyph = font.glyphs[glyphIndex];
  20425. if (subglyph) {
  20426. cmds.push({cmd: 'save'});
  20427. cmds.push({cmd: 'transform',
  20428. args: [scaleX, scale01, scale10, scaleY, x, y]});
  20429. compileGlyf(subglyph, cmds, font);
  20430. cmds.push({cmd: 'restore'});
  20431. }
  20432. } while ((flags & 0x20));
  20433. } else {
  20434. // simple glyph
  20435. var endPtsOfContours = [];
  20436. var j, jj;
  20437. for (j = 0; j < numberOfContours; j++) {
  20438. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  20439. i += 2;
  20440. }
  20441. var instructionLength = (code[i] << 8) | code[i + 1];
  20442. i += 2 + instructionLength; // skipping the instructions
  20443. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  20444. var points = [];
  20445. while (points.length < numberOfPoints) {
  20446. flags = code[i++];
  20447. var repeat = 1;
  20448. if ((flags & 0x08)) {
  20449. repeat += code[i++];
  20450. }
  20451. while (repeat-- > 0) {
  20452. points.push({flags: flags});
  20453. }
  20454. }
  20455. for (j = 0; j < numberOfPoints; j++) {
  20456. switch (points[j].flags & 0x12) {
  20457. case 0x00:
  20458. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20459. i += 2;
  20460. break;
  20461. case 0x02:
  20462. x -= code[i++];
  20463. break;
  20464. case 0x12:
  20465. x += code[i++];
  20466. break;
  20467. }
  20468. points[j].x = x;
  20469. }
  20470. for (j = 0; j < numberOfPoints; j++) {
  20471. switch (points[j].flags & 0x24) {
  20472. case 0x00:
  20473. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20474. i += 2;
  20475. break;
  20476. case 0x04:
  20477. y -= code[i++];
  20478. break;
  20479. case 0x24:
  20480. y += code[i++];
  20481. break;
  20482. }
  20483. points[j].y = y;
  20484. }
  20485. var startPoint = 0;
  20486. for (i = 0; i < numberOfContours; i++) {
  20487. var endPoint = endPtsOfContours[i];
  20488. // contours might have implicit points, which is located in the middle
  20489. // between two neighboring off-curve points
  20490. var contour = points.slice(startPoint, endPoint + 1);
  20491. if ((contour[0].flags & 1)) {
  20492. contour.push(contour[0]); // using start point at the contour end
  20493. } else if ((contour[contour.length - 1].flags & 1)) {
  20494. // first is off-curve point, trying to use one from the end
  20495. contour.unshift(contour[contour.length - 1]);
  20496. } else {
  20497. // start and end are off-curve points, creating implicit one
  20498. var p = {
  20499. flags: 1,
  20500. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20501. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20502. };
  20503. contour.unshift(p);
  20504. contour.push(p);
  20505. }
  20506. moveTo(contour[0].x, contour[0].y);
  20507. for (j = 1, jj = contour.length; j < jj; j++) {
  20508. if ((contour[j].flags & 1)) {
  20509. lineTo(contour[j].x, contour[j].y);
  20510. } else if ((contour[j + 1].flags & 1)){
  20511. quadraticCurveTo(contour[j].x, contour[j].y,
  20512. contour[j + 1].x, contour[j + 1].y);
  20513. j++;
  20514. } else {
  20515. quadraticCurveTo(contour[j].x, contour[j].y,
  20516. (contour[j].x + contour[j + 1].x) / 2,
  20517. (contour[j].y + contour[j + 1].y) / 2);
  20518. }
  20519. }
  20520. startPoint = endPoint + 1;
  20521. }
  20522. }
  20523. }
  20524. function compileCharString(code, cmds, font) {
  20525. var stack = [];
  20526. var x = 0, y = 0;
  20527. var stems = 0;
  20528. function moveTo(x, y) {
  20529. cmds.push({cmd: 'moveTo', args: [x, y]});
  20530. }
  20531. function lineTo(x, y) {
  20532. cmds.push({cmd: 'lineTo', args: [x, y]});
  20533. }
  20534. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20535. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  20536. }
  20537. function parse(code) {
  20538. var i = 0;
  20539. while (i < code.length) {
  20540. var stackClean = false;
  20541. var v = code[i++];
  20542. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20543. switch (v) {
  20544. case 1: // hstem
  20545. stems += stack.length >> 1;
  20546. stackClean = true;
  20547. break;
  20548. case 3: // vstem
  20549. stems += stack.length >> 1;
  20550. stackClean = true;
  20551. break;
  20552. case 4: // vmoveto
  20553. y += stack.pop();
  20554. moveTo(x, y);
  20555. stackClean = true;
  20556. break;
  20557. case 5: // rlineto
  20558. while (stack.length > 0) {
  20559. x += stack.shift();
  20560. y += stack.shift();
  20561. lineTo(x, y);
  20562. }
  20563. break;
  20564. case 6: // hlineto
  20565. while (stack.length > 0) {
  20566. x += stack.shift();
  20567. lineTo(x, y);
  20568. if (stack.length === 0) {
  20569. break;
  20570. }
  20571. y += stack.shift();
  20572. lineTo(x, y);
  20573. }
  20574. break;
  20575. case 7: // vlineto
  20576. while (stack.length > 0) {
  20577. y += stack.shift();
  20578. lineTo(x, y);
  20579. if (stack.length === 0) {
  20580. break;
  20581. }
  20582. x += stack.shift();
  20583. lineTo(x, y);
  20584. }
  20585. break;
  20586. case 8: // rrcurveto
  20587. while (stack.length > 0) {
  20588. xa = x + stack.shift(); ya = y + stack.shift();
  20589. xb = xa + stack.shift(); yb = ya + stack.shift();
  20590. x = xb + stack.shift(); y = yb + stack.shift();
  20591. bezierCurveTo(xa, ya, xb, yb, x, y);
  20592. }
  20593. break;
  20594. case 10: // callsubr
  20595. n = stack.pop() + font.subrsBias;
  20596. subrCode = font.subrs[n];
  20597. if (subrCode) {
  20598. parse(subrCode);
  20599. }
  20600. break;
  20601. case 11: // return
  20602. return;
  20603. case 12:
  20604. v = code[i++];
  20605. switch (v) {
  20606. case 34: // flex
  20607. xa = x + stack.shift();
  20608. xb = xa + stack.shift(); y1 = y + stack.shift();
  20609. x = xb + stack.shift();
  20610. bezierCurveTo(xa, y, xb, y1, x, y1);
  20611. xa = x + stack.shift();
  20612. xb = xa + stack.shift();
  20613. x = xb + stack.shift();
  20614. bezierCurveTo(xa, y1, xb, y, x, y);
  20615. break;
  20616. case 35: // flex
  20617. xa = x + stack.shift(); ya = y + stack.shift();
  20618. xb = xa + stack.shift(); yb = ya + stack.shift();
  20619. x = xb + stack.shift(); y = yb + stack.shift();
  20620. bezierCurveTo(xa, ya, xb, yb, x, y);
  20621. xa = x + stack.shift(); ya = y + stack.shift();
  20622. xb = xa + stack.shift(); yb = ya + stack.shift();
  20623. x = xb + stack.shift(); y = yb + stack.shift();
  20624. bezierCurveTo(xa, ya, xb, yb, x, y);
  20625. stack.pop(); // fd
  20626. break;
  20627. case 36: // hflex1
  20628. xa = x + stack.shift(); y1 = y + stack.shift();
  20629. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20630. x = xb + stack.shift();
  20631. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20632. xa = x + stack.shift();
  20633. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20634. x = xb + stack.shift();
  20635. bezierCurveTo(xa, y2, xb, y3, x, y);
  20636. break;
  20637. case 37: // flex1
  20638. var x0 = x, y0 = y;
  20639. xa = x + stack.shift(); ya = y + stack.shift();
  20640. xb = xa + stack.shift(); yb = ya + stack.shift();
  20641. x = xb + stack.shift(); y = yb + stack.shift();
  20642. bezierCurveTo(xa, ya, xb, yb, x, y);
  20643. xa = x + stack.shift(); ya = y + stack.shift();
  20644. xb = xa + stack.shift(); yb = ya + stack.shift();
  20645. x = xb; y = yb;
  20646. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20647. x += stack.shift();
  20648. } else {
  20649. y += stack.shift();
  20650. }
  20651. bezierCurveTo(xa, ya, xb, yb, x, y);
  20652. break;
  20653. default:
  20654. error('unknown operator: 12 ' + v);
  20655. }
  20656. break;
  20657. case 14: // endchar
  20658. if (stack.length >= 4) {
  20659. var achar = stack.pop();
  20660. var bchar = stack.pop();
  20661. y = stack.pop();
  20662. x = stack.pop();
  20663. cmds.push({cmd: 'save'});
  20664. cmds.push({cmd: 'translate', args: [x, y]});
  20665. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20666. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20667. compileCharString(font.glyphs[gid], cmds, font);
  20668. cmds.push({cmd: 'restore'});
  20669. gid = lookupCmap(font.cmap, String.fromCharCode(
  20670. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20671. compileCharString(font.glyphs[gid], cmds, font);
  20672. }
  20673. return;
  20674. case 18: // hstemhm
  20675. stems += stack.length >> 1;
  20676. stackClean = true;
  20677. break;
  20678. case 19: // hintmask
  20679. stems += stack.length >> 1;
  20680. i += (stems + 7) >> 3;
  20681. stackClean = true;
  20682. break;
  20683. case 20: // cntrmask
  20684. stems += stack.length >> 1;
  20685. i += (stems + 7) >> 3;
  20686. stackClean = true;
  20687. break;
  20688. case 21: // rmoveto
  20689. y += stack.pop();
  20690. x += stack.pop();
  20691. moveTo(x, y);
  20692. stackClean = true;
  20693. break;
  20694. case 22: // hmoveto
  20695. x += stack.pop();
  20696. moveTo(x, y);
  20697. stackClean = true;
  20698. break;
  20699. case 23: // vstemhm
  20700. stems += stack.length >> 1;
  20701. stackClean = true;
  20702. break;
  20703. case 24: // rcurveline
  20704. while (stack.length > 2) {
  20705. xa = x + stack.shift(); ya = y + stack.shift();
  20706. xb = xa + stack.shift(); yb = ya + stack.shift();
  20707. x = xb + stack.shift(); y = yb + stack.shift();
  20708. bezierCurveTo(xa, ya, xb, yb, x, y);
  20709. }
  20710. x += stack.shift();
  20711. y += stack.shift();
  20712. lineTo(x, y);
  20713. break;
  20714. case 25: // rlinecurve
  20715. while (stack.length > 6) {
  20716. x += stack.shift();
  20717. y += stack.shift();
  20718. lineTo(x, y);
  20719. }
  20720. xa = x + stack.shift(); ya = y + stack.shift();
  20721. xb = xa + stack.shift(); yb = ya + stack.shift();
  20722. x = xb + stack.shift(); y = yb + stack.shift();
  20723. bezierCurveTo(xa, ya, xb, yb, x, y);
  20724. break;
  20725. case 26: // vvcurveto
  20726. if (stack.length % 2) {
  20727. x += stack.shift();
  20728. }
  20729. while (stack.length > 0) {
  20730. xa = x; ya = y + stack.shift();
  20731. xb = xa + stack.shift(); yb = ya + stack.shift();
  20732. x = xb; y = yb + stack.shift();
  20733. bezierCurveTo(xa, ya, xb, yb, x, y);
  20734. }
  20735. break;
  20736. case 27: // hhcurveto
  20737. if (stack.length % 2) {
  20738. y += stack.shift();
  20739. }
  20740. while (stack.length > 0) {
  20741. xa = x + stack.shift(); ya = y;
  20742. xb = xa + stack.shift(); yb = ya + stack.shift();
  20743. x = xb + stack.shift(); y = yb;
  20744. bezierCurveTo(xa, ya, xb, yb, x, y);
  20745. }
  20746. break;
  20747. case 28:
  20748. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20749. i += 2;
  20750. break;
  20751. case 29: // callgsubr
  20752. n = stack.pop() + font.gsubrsBias;
  20753. subrCode = font.gsubrs[n];
  20754. if (subrCode) {
  20755. parse(subrCode);
  20756. }
  20757. break;
  20758. case 30: // vhcurveto
  20759. while (stack.length > 0) {
  20760. xa = x; ya = y + stack.shift();
  20761. xb = xa + stack.shift(); yb = ya + stack.shift();
  20762. x = xb + stack.shift();
  20763. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20764. bezierCurveTo(xa, ya, xb, yb, x, y);
  20765. if (stack.length === 0) {
  20766. break;
  20767. }
  20768. xa = x + stack.shift(); ya = y;
  20769. xb = xa + stack.shift(); yb = ya + stack.shift();
  20770. y = yb + stack.shift();
  20771. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20772. bezierCurveTo(xa, ya, xb, yb, x, y);
  20773. }
  20774. break;
  20775. case 31: // hvcurveto
  20776. while (stack.length > 0) {
  20777. xa = x + stack.shift(); ya = y;
  20778. xb = xa + stack.shift(); yb = ya + stack.shift();
  20779. y = yb + stack.shift();
  20780. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20781. bezierCurveTo(xa, ya, xb, yb, x, y);
  20782. if (stack.length === 0) {
  20783. break;
  20784. }
  20785. xa = x; ya = y + stack.shift();
  20786. xb = xa + stack.shift(); yb = ya + stack.shift();
  20787. x = xb + stack.shift();
  20788. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20789. bezierCurveTo(xa, ya, xb, yb, x, y);
  20790. }
  20791. break;
  20792. default:
  20793. if (v < 32) {
  20794. error('unknown operator: ' + v);
  20795. }
  20796. if (v < 247) {
  20797. stack.push(v - 139);
  20798. } else if (v < 251) {
  20799. stack.push((v - 247) * 256 + code[i++] + 108);
  20800. } else if (v < 255) {
  20801. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20802. } else {
  20803. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20804. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20805. i += 4;
  20806. }
  20807. break;
  20808. }
  20809. if (stackClean) {
  20810. stack.length = 0;
  20811. }
  20812. }
  20813. }
  20814. parse(code);
  20815. }
  20816. var noop = '';
  20817. function CompiledFont(fontMatrix) {
  20818. this.compiledGlyphs = {};
  20819. this.fontMatrix = fontMatrix;
  20820. }
  20821. CompiledFont.prototype = {
  20822. getPathJs: function (unicode) {
  20823. var gid = lookupCmap(this.cmap, unicode);
  20824. var fn = this.compiledGlyphs[gid];
  20825. if (!fn) {
  20826. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20827. }
  20828. return fn;
  20829. },
  20830. compileGlyph: function (code) {
  20831. if (!code || code.length === 0 || code[0] === 14) {
  20832. return noop;
  20833. }
  20834. var cmds = [];
  20835. cmds.push({cmd: 'save'});
  20836. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  20837. cmds.push({cmd: 'scale', args: ['size', '-size']});
  20838. this.compileGlyphImpl(code, cmds);
  20839. cmds.push({cmd: 'restore'});
  20840. return cmds;
  20841. },
  20842. compileGlyphImpl: function () {
  20843. error('Children classes should implement this.');
  20844. },
  20845. hasBuiltPath: function (unicode) {
  20846. var gid = lookupCmap(this.cmap, unicode);
  20847. return gid in this.compiledGlyphs;
  20848. }
  20849. };
  20850. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20851. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20852. CompiledFont.call(this, fontMatrix);
  20853. this.glyphs = glyphs;
  20854. this.cmap = cmap;
  20855. this.compiledGlyphs = [];
  20856. }
  20857. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20858. compileGlyphImpl: function (code, cmds) {
  20859. compileGlyf(code, cmds, this);
  20860. }
  20861. });
  20862. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20863. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20864. CompiledFont.call(this, fontMatrix);
  20865. this.glyphs = cffInfo.glyphs;
  20866. this.gsubrs = cffInfo.gsubrs || [];
  20867. this.subrs = cffInfo.subrs || [];
  20868. this.cmap = cmap;
  20869. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20870. this.compiledGlyphs = [];
  20871. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20872. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20873. this.subrsBias = (this.subrs.length < 1240 ?
  20874. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20875. }
  20876. Util.inherit(Type2Compiled, CompiledFont, {
  20877. compileGlyphImpl: function (code, cmds) {
  20878. compileCharString(code, cmds, this);
  20879. }
  20880. });
  20881. return {
  20882. create: function FontRendererFactory_create(font) {
  20883. var data = new Uint8Array(font.data);
  20884. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20885. var numTables = getUshort(data, 4);
  20886. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20887. var tag = bytesToString(data.subarray(p, p + 4));
  20888. var offset = getLong(data, p + 8);
  20889. var length = getLong(data, p + 12);
  20890. switch (tag) {
  20891. case 'cmap':
  20892. cmap = parseCmap(data, offset, offset + length);
  20893. break;
  20894. case 'glyf':
  20895. glyf = data.subarray(offset, offset + length);
  20896. break;
  20897. case 'loca':
  20898. loca = data.subarray(offset, offset + length);
  20899. break;
  20900. case 'head':
  20901. unitsPerEm = getUshort(data, offset + 18);
  20902. indexToLocFormat = getUshort(data, offset + 50);
  20903. break;
  20904. case 'CFF ':
  20905. cff = parseCff(data, offset, offset + length);
  20906. break;
  20907. }
  20908. }
  20909. if (glyf) {
  20910. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20911. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20912. return new TrueTypeCompiled(
  20913. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20914. } else {
  20915. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20916. }
  20917. }
  20918. };
  20919. })();
  20920. var GlyphsUnicode = {
  20921. A: 0x0041,
  20922. AE: 0x00C6,
  20923. AEacute: 0x01FC,
  20924. AEmacron: 0x01E2,
  20925. AEsmall: 0xF7E6,
  20926. Aacute: 0x00C1,
  20927. Aacutesmall: 0xF7E1,
  20928. Abreve: 0x0102,
  20929. Abreveacute: 0x1EAE,
  20930. Abrevecyrillic: 0x04D0,
  20931. Abrevedotbelow: 0x1EB6,
  20932. Abrevegrave: 0x1EB0,
  20933. Abrevehookabove: 0x1EB2,
  20934. Abrevetilde: 0x1EB4,
  20935. Acaron: 0x01CD,
  20936. Acircle: 0x24B6,
  20937. Acircumflex: 0x00C2,
  20938. Acircumflexacute: 0x1EA4,
  20939. Acircumflexdotbelow: 0x1EAC,
  20940. Acircumflexgrave: 0x1EA6,
  20941. Acircumflexhookabove: 0x1EA8,
  20942. Acircumflexsmall: 0xF7E2,
  20943. Acircumflextilde: 0x1EAA,
  20944. Acute: 0xF6C9,
  20945. Acutesmall: 0xF7B4,
  20946. Acyrillic: 0x0410,
  20947. Adblgrave: 0x0200,
  20948. Adieresis: 0x00C4,
  20949. Adieresiscyrillic: 0x04D2,
  20950. Adieresismacron: 0x01DE,
  20951. Adieresissmall: 0xF7E4,
  20952. Adotbelow: 0x1EA0,
  20953. Adotmacron: 0x01E0,
  20954. Agrave: 0x00C0,
  20955. Agravesmall: 0xF7E0,
  20956. Ahookabove: 0x1EA2,
  20957. Aiecyrillic: 0x04D4,
  20958. Ainvertedbreve: 0x0202,
  20959. Alpha: 0x0391,
  20960. Alphatonos: 0x0386,
  20961. Amacron: 0x0100,
  20962. Amonospace: 0xFF21,
  20963. Aogonek: 0x0104,
  20964. Aring: 0x00C5,
  20965. Aringacute: 0x01FA,
  20966. Aringbelow: 0x1E00,
  20967. Aringsmall: 0xF7E5,
  20968. Asmall: 0xF761,
  20969. Atilde: 0x00C3,
  20970. Atildesmall: 0xF7E3,
  20971. Aybarmenian: 0x0531,
  20972. B: 0x0042,
  20973. Bcircle: 0x24B7,
  20974. Bdotaccent: 0x1E02,
  20975. Bdotbelow: 0x1E04,
  20976. Becyrillic: 0x0411,
  20977. Benarmenian: 0x0532,
  20978. Beta: 0x0392,
  20979. Bhook: 0x0181,
  20980. Blinebelow: 0x1E06,
  20981. Bmonospace: 0xFF22,
  20982. Brevesmall: 0xF6F4,
  20983. Bsmall: 0xF762,
  20984. Btopbar: 0x0182,
  20985. C: 0x0043,
  20986. Caarmenian: 0x053E,
  20987. Cacute: 0x0106,
  20988. Caron: 0xF6CA,
  20989. Caronsmall: 0xF6F5,
  20990. Ccaron: 0x010C,
  20991. Ccedilla: 0x00C7,
  20992. Ccedillaacute: 0x1E08,
  20993. Ccedillasmall: 0xF7E7,
  20994. Ccircle: 0x24B8,
  20995. Ccircumflex: 0x0108,
  20996. Cdot: 0x010A,
  20997. Cdotaccent: 0x010A,
  20998. Cedillasmall: 0xF7B8,
  20999. Chaarmenian: 0x0549,
  21000. Cheabkhasiancyrillic: 0x04BC,
  21001. Checyrillic: 0x0427,
  21002. Chedescenderabkhasiancyrillic: 0x04BE,
  21003. Chedescendercyrillic: 0x04B6,
  21004. Chedieresiscyrillic: 0x04F4,
  21005. Cheharmenian: 0x0543,
  21006. Chekhakassiancyrillic: 0x04CB,
  21007. Cheverticalstrokecyrillic: 0x04B8,
  21008. Chi: 0x03A7,
  21009. Chook: 0x0187,
  21010. Circumflexsmall: 0xF6F6,
  21011. Cmonospace: 0xFF23,
  21012. Coarmenian: 0x0551,
  21013. Csmall: 0xF763,
  21014. D: 0x0044,
  21015. DZ: 0x01F1,
  21016. DZcaron: 0x01C4,
  21017. Daarmenian: 0x0534,
  21018. Dafrican: 0x0189,
  21019. Dcaron: 0x010E,
  21020. Dcedilla: 0x1E10,
  21021. Dcircle: 0x24B9,
  21022. Dcircumflexbelow: 0x1E12,
  21023. Dcroat: 0x0110,
  21024. Ddotaccent: 0x1E0A,
  21025. Ddotbelow: 0x1E0C,
  21026. Decyrillic: 0x0414,
  21027. Deicoptic: 0x03EE,
  21028. Delta: 0x2206,
  21029. Deltagreek: 0x0394,
  21030. Dhook: 0x018A,
  21031. Dieresis: 0xF6CB,
  21032. DieresisAcute: 0xF6CC,
  21033. DieresisGrave: 0xF6CD,
  21034. Dieresissmall: 0xF7A8,
  21035. Digammagreek: 0x03DC,
  21036. Djecyrillic: 0x0402,
  21037. Dlinebelow: 0x1E0E,
  21038. Dmonospace: 0xFF24,
  21039. Dotaccentsmall: 0xF6F7,
  21040. Dslash: 0x0110,
  21041. Dsmall: 0xF764,
  21042. Dtopbar: 0x018B,
  21043. Dz: 0x01F2,
  21044. Dzcaron: 0x01C5,
  21045. Dzeabkhasiancyrillic: 0x04E0,
  21046. Dzecyrillic: 0x0405,
  21047. Dzhecyrillic: 0x040F,
  21048. E: 0x0045,
  21049. Eacute: 0x00C9,
  21050. Eacutesmall: 0xF7E9,
  21051. Ebreve: 0x0114,
  21052. Ecaron: 0x011A,
  21053. Ecedillabreve: 0x1E1C,
  21054. Echarmenian: 0x0535,
  21055. Ecircle: 0x24BA,
  21056. Ecircumflex: 0x00CA,
  21057. Ecircumflexacute: 0x1EBE,
  21058. Ecircumflexbelow: 0x1E18,
  21059. Ecircumflexdotbelow: 0x1EC6,
  21060. Ecircumflexgrave: 0x1EC0,
  21061. Ecircumflexhookabove: 0x1EC2,
  21062. Ecircumflexsmall: 0xF7EA,
  21063. Ecircumflextilde: 0x1EC4,
  21064. Ecyrillic: 0x0404,
  21065. Edblgrave: 0x0204,
  21066. Edieresis: 0x00CB,
  21067. Edieresissmall: 0xF7EB,
  21068. Edot: 0x0116,
  21069. Edotaccent: 0x0116,
  21070. Edotbelow: 0x1EB8,
  21071. Efcyrillic: 0x0424,
  21072. Egrave: 0x00C8,
  21073. Egravesmall: 0xF7E8,
  21074. Eharmenian: 0x0537,
  21075. Ehookabove: 0x1EBA,
  21076. Eightroman: 0x2167,
  21077. Einvertedbreve: 0x0206,
  21078. Eiotifiedcyrillic: 0x0464,
  21079. Elcyrillic: 0x041B,
  21080. Elevenroman: 0x216A,
  21081. Emacron: 0x0112,
  21082. Emacronacute: 0x1E16,
  21083. Emacrongrave: 0x1E14,
  21084. Emcyrillic: 0x041C,
  21085. Emonospace: 0xFF25,
  21086. Encyrillic: 0x041D,
  21087. Endescendercyrillic: 0x04A2,
  21088. Eng: 0x014A,
  21089. Enghecyrillic: 0x04A4,
  21090. Enhookcyrillic: 0x04C7,
  21091. Eogonek: 0x0118,
  21092. Eopen: 0x0190,
  21093. Epsilon: 0x0395,
  21094. Epsilontonos: 0x0388,
  21095. Ercyrillic: 0x0420,
  21096. Ereversed: 0x018E,
  21097. Ereversedcyrillic: 0x042D,
  21098. Escyrillic: 0x0421,
  21099. Esdescendercyrillic: 0x04AA,
  21100. Esh: 0x01A9,
  21101. Esmall: 0xF765,
  21102. Eta: 0x0397,
  21103. Etarmenian: 0x0538,
  21104. Etatonos: 0x0389,
  21105. Eth: 0x00D0,
  21106. Ethsmall: 0xF7F0,
  21107. Etilde: 0x1EBC,
  21108. Etildebelow: 0x1E1A,
  21109. Euro: 0x20AC,
  21110. Ezh: 0x01B7,
  21111. Ezhcaron: 0x01EE,
  21112. Ezhreversed: 0x01B8,
  21113. F: 0x0046,
  21114. Fcircle: 0x24BB,
  21115. Fdotaccent: 0x1E1E,
  21116. Feharmenian: 0x0556,
  21117. Feicoptic: 0x03E4,
  21118. Fhook: 0x0191,
  21119. Fitacyrillic: 0x0472,
  21120. Fiveroman: 0x2164,
  21121. Fmonospace: 0xFF26,
  21122. Fourroman: 0x2163,
  21123. Fsmall: 0xF766,
  21124. G: 0x0047,
  21125. GBsquare: 0x3387,
  21126. Gacute: 0x01F4,
  21127. Gamma: 0x0393,
  21128. Gammaafrican: 0x0194,
  21129. Gangiacoptic: 0x03EA,
  21130. Gbreve: 0x011E,
  21131. Gcaron: 0x01E6,
  21132. Gcedilla: 0x0122,
  21133. Gcircle: 0x24BC,
  21134. Gcircumflex: 0x011C,
  21135. Gcommaaccent: 0x0122,
  21136. Gdot: 0x0120,
  21137. Gdotaccent: 0x0120,
  21138. Gecyrillic: 0x0413,
  21139. Ghadarmenian: 0x0542,
  21140. Ghemiddlehookcyrillic: 0x0494,
  21141. Ghestrokecyrillic: 0x0492,
  21142. Gheupturncyrillic: 0x0490,
  21143. Ghook: 0x0193,
  21144. Gimarmenian: 0x0533,
  21145. Gjecyrillic: 0x0403,
  21146. Gmacron: 0x1E20,
  21147. Gmonospace: 0xFF27,
  21148. Grave: 0xF6CE,
  21149. Gravesmall: 0xF760,
  21150. Gsmall: 0xF767,
  21151. Gsmallhook: 0x029B,
  21152. Gstroke: 0x01E4,
  21153. H: 0x0048,
  21154. H18533: 0x25CF,
  21155. H18543: 0x25AA,
  21156. H18551: 0x25AB,
  21157. H22073: 0x25A1,
  21158. HPsquare: 0x33CB,
  21159. Haabkhasiancyrillic: 0x04A8,
  21160. Hadescendercyrillic: 0x04B2,
  21161. Hardsigncyrillic: 0x042A,
  21162. Hbar: 0x0126,
  21163. Hbrevebelow: 0x1E2A,
  21164. Hcedilla: 0x1E28,
  21165. Hcircle: 0x24BD,
  21166. Hcircumflex: 0x0124,
  21167. Hdieresis: 0x1E26,
  21168. Hdotaccent: 0x1E22,
  21169. Hdotbelow: 0x1E24,
  21170. Hmonospace: 0xFF28,
  21171. Hoarmenian: 0x0540,
  21172. Horicoptic: 0x03E8,
  21173. Hsmall: 0xF768,
  21174. Hungarumlaut: 0xF6CF,
  21175. Hungarumlautsmall: 0xF6F8,
  21176. Hzsquare: 0x3390,
  21177. I: 0x0049,
  21178. IAcyrillic: 0x042F,
  21179. IJ: 0x0132,
  21180. IUcyrillic: 0x042E,
  21181. Iacute: 0x00CD,
  21182. Iacutesmall: 0xF7ED,
  21183. Ibreve: 0x012C,
  21184. Icaron: 0x01CF,
  21185. Icircle: 0x24BE,
  21186. Icircumflex: 0x00CE,
  21187. Icircumflexsmall: 0xF7EE,
  21188. Icyrillic: 0x0406,
  21189. Idblgrave: 0x0208,
  21190. Idieresis: 0x00CF,
  21191. Idieresisacute: 0x1E2E,
  21192. Idieresiscyrillic: 0x04E4,
  21193. Idieresissmall: 0xF7EF,
  21194. Idot: 0x0130,
  21195. Idotaccent: 0x0130,
  21196. Idotbelow: 0x1ECA,
  21197. Iebrevecyrillic: 0x04D6,
  21198. Iecyrillic: 0x0415,
  21199. Ifraktur: 0x2111,
  21200. Igrave: 0x00CC,
  21201. Igravesmall: 0xF7EC,
  21202. Ihookabove: 0x1EC8,
  21203. Iicyrillic: 0x0418,
  21204. Iinvertedbreve: 0x020A,
  21205. Iishortcyrillic: 0x0419,
  21206. Imacron: 0x012A,
  21207. Imacroncyrillic: 0x04E2,
  21208. Imonospace: 0xFF29,
  21209. Iniarmenian: 0x053B,
  21210. Iocyrillic: 0x0401,
  21211. Iogonek: 0x012E,
  21212. Iota: 0x0399,
  21213. Iotaafrican: 0x0196,
  21214. Iotadieresis: 0x03AA,
  21215. Iotatonos: 0x038A,
  21216. Ismall: 0xF769,
  21217. Istroke: 0x0197,
  21218. Itilde: 0x0128,
  21219. Itildebelow: 0x1E2C,
  21220. Izhitsacyrillic: 0x0474,
  21221. Izhitsadblgravecyrillic: 0x0476,
  21222. J: 0x004A,
  21223. Jaarmenian: 0x0541,
  21224. Jcircle: 0x24BF,
  21225. Jcircumflex: 0x0134,
  21226. Jecyrillic: 0x0408,
  21227. Jheharmenian: 0x054B,
  21228. Jmonospace: 0xFF2A,
  21229. Jsmall: 0xF76A,
  21230. K: 0x004B,
  21231. KBsquare: 0x3385,
  21232. KKsquare: 0x33CD,
  21233. Kabashkircyrillic: 0x04A0,
  21234. Kacute: 0x1E30,
  21235. Kacyrillic: 0x041A,
  21236. Kadescendercyrillic: 0x049A,
  21237. Kahookcyrillic: 0x04C3,
  21238. Kappa: 0x039A,
  21239. Kastrokecyrillic: 0x049E,
  21240. Kaverticalstrokecyrillic: 0x049C,
  21241. Kcaron: 0x01E8,
  21242. Kcedilla: 0x0136,
  21243. Kcircle: 0x24C0,
  21244. Kcommaaccent: 0x0136,
  21245. Kdotbelow: 0x1E32,
  21246. Keharmenian: 0x0554,
  21247. Kenarmenian: 0x053F,
  21248. Khacyrillic: 0x0425,
  21249. Kheicoptic: 0x03E6,
  21250. Khook: 0x0198,
  21251. Kjecyrillic: 0x040C,
  21252. Klinebelow: 0x1E34,
  21253. Kmonospace: 0xFF2B,
  21254. Koppacyrillic: 0x0480,
  21255. Koppagreek: 0x03DE,
  21256. Ksicyrillic: 0x046E,
  21257. Ksmall: 0xF76B,
  21258. L: 0x004C,
  21259. LJ: 0x01C7,
  21260. LL: 0xF6BF,
  21261. Lacute: 0x0139,
  21262. Lambda: 0x039B,
  21263. Lcaron: 0x013D,
  21264. Lcedilla: 0x013B,
  21265. Lcircle: 0x24C1,
  21266. Lcircumflexbelow: 0x1E3C,
  21267. Lcommaaccent: 0x013B,
  21268. Ldot: 0x013F,
  21269. Ldotaccent: 0x013F,
  21270. Ldotbelow: 0x1E36,
  21271. Ldotbelowmacron: 0x1E38,
  21272. Liwnarmenian: 0x053C,
  21273. Lj: 0x01C8,
  21274. Ljecyrillic: 0x0409,
  21275. Llinebelow: 0x1E3A,
  21276. Lmonospace: 0xFF2C,
  21277. Lslash: 0x0141,
  21278. Lslashsmall: 0xF6F9,
  21279. Lsmall: 0xF76C,
  21280. M: 0x004D,
  21281. MBsquare: 0x3386,
  21282. Macron: 0xF6D0,
  21283. Macronsmall: 0xF7AF,
  21284. Macute: 0x1E3E,
  21285. Mcircle: 0x24C2,
  21286. Mdotaccent: 0x1E40,
  21287. Mdotbelow: 0x1E42,
  21288. Menarmenian: 0x0544,
  21289. Mmonospace: 0xFF2D,
  21290. Msmall: 0xF76D,
  21291. Mturned: 0x019C,
  21292. Mu: 0x039C,
  21293. N: 0x004E,
  21294. NJ: 0x01CA,
  21295. Nacute: 0x0143,
  21296. Ncaron: 0x0147,
  21297. Ncedilla: 0x0145,
  21298. Ncircle: 0x24C3,
  21299. Ncircumflexbelow: 0x1E4A,
  21300. Ncommaaccent: 0x0145,
  21301. Ndotaccent: 0x1E44,
  21302. Ndotbelow: 0x1E46,
  21303. Nhookleft: 0x019D,
  21304. Nineroman: 0x2168,
  21305. Nj: 0x01CB,
  21306. Njecyrillic: 0x040A,
  21307. Nlinebelow: 0x1E48,
  21308. Nmonospace: 0xFF2E,
  21309. Nowarmenian: 0x0546,
  21310. Nsmall: 0xF76E,
  21311. Ntilde: 0x00D1,
  21312. Ntildesmall: 0xF7F1,
  21313. Nu: 0x039D,
  21314. O: 0x004F,
  21315. OE: 0x0152,
  21316. OEsmall: 0xF6FA,
  21317. Oacute: 0x00D3,
  21318. Oacutesmall: 0xF7F3,
  21319. Obarredcyrillic: 0x04E8,
  21320. Obarreddieresiscyrillic: 0x04EA,
  21321. Obreve: 0x014E,
  21322. Ocaron: 0x01D1,
  21323. Ocenteredtilde: 0x019F,
  21324. Ocircle: 0x24C4,
  21325. Ocircumflex: 0x00D4,
  21326. Ocircumflexacute: 0x1ED0,
  21327. Ocircumflexdotbelow: 0x1ED8,
  21328. Ocircumflexgrave: 0x1ED2,
  21329. Ocircumflexhookabove: 0x1ED4,
  21330. Ocircumflexsmall: 0xF7F4,
  21331. Ocircumflextilde: 0x1ED6,
  21332. Ocyrillic: 0x041E,
  21333. Odblacute: 0x0150,
  21334. Odblgrave: 0x020C,
  21335. Odieresis: 0x00D6,
  21336. Odieresiscyrillic: 0x04E6,
  21337. Odieresissmall: 0xF7F6,
  21338. Odotbelow: 0x1ECC,
  21339. Ogoneksmall: 0xF6FB,
  21340. Ograve: 0x00D2,
  21341. Ogravesmall: 0xF7F2,
  21342. Oharmenian: 0x0555,
  21343. Ohm: 0x2126,
  21344. Ohookabove: 0x1ECE,
  21345. Ohorn: 0x01A0,
  21346. Ohornacute: 0x1EDA,
  21347. Ohorndotbelow: 0x1EE2,
  21348. Ohorngrave: 0x1EDC,
  21349. Ohornhookabove: 0x1EDE,
  21350. Ohorntilde: 0x1EE0,
  21351. Ohungarumlaut: 0x0150,
  21352. Oi: 0x01A2,
  21353. Oinvertedbreve: 0x020E,
  21354. Omacron: 0x014C,
  21355. Omacronacute: 0x1E52,
  21356. Omacrongrave: 0x1E50,
  21357. Omega: 0x2126,
  21358. Omegacyrillic: 0x0460,
  21359. Omegagreek: 0x03A9,
  21360. Omegaroundcyrillic: 0x047A,
  21361. Omegatitlocyrillic: 0x047C,
  21362. Omegatonos: 0x038F,
  21363. Omicron: 0x039F,
  21364. Omicrontonos: 0x038C,
  21365. Omonospace: 0xFF2F,
  21366. Oneroman: 0x2160,
  21367. Oogonek: 0x01EA,
  21368. Oogonekmacron: 0x01EC,
  21369. Oopen: 0x0186,
  21370. Oslash: 0x00D8,
  21371. Oslashacute: 0x01FE,
  21372. Oslashsmall: 0xF7F8,
  21373. Osmall: 0xF76F,
  21374. Ostrokeacute: 0x01FE,
  21375. Otcyrillic: 0x047E,
  21376. Otilde: 0x00D5,
  21377. Otildeacute: 0x1E4C,
  21378. Otildedieresis: 0x1E4E,
  21379. Otildesmall: 0xF7F5,
  21380. P: 0x0050,
  21381. Pacute: 0x1E54,
  21382. Pcircle: 0x24C5,
  21383. Pdotaccent: 0x1E56,
  21384. Pecyrillic: 0x041F,
  21385. Peharmenian: 0x054A,
  21386. Pemiddlehookcyrillic: 0x04A6,
  21387. Phi: 0x03A6,
  21388. Phook: 0x01A4,
  21389. Pi: 0x03A0,
  21390. Piwrarmenian: 0x0553,
  21391. Pmonospace: 0xFF30,
  21392. Psi: 0x03A8,
  21393. Psicyrillic: 0x0470,
  21394. Psmall: 0xF770,
  21395. Q: 0x0051,
  21396. Qcircle: 0x24C6,
  21397. Qmonospace: 0xFF31,
  21398. Qsmall: 0xF771,
  21399. R: 0x0052,
  21400. Raarmenian: 0x054C,
  21401. Racute: 0x0154,
  21402. Rcaron: 0x0158,
  21403. Rcedilla: 0x0156,
  21404. Rcircle: 0x24C7,
  21405. Rcommaaccent: 0x0156,
  21406. Rdblgrave: 0x0210,
  21407. Rdotaccent: 0x1E58,
  21408. Rdotbelow: 0x1E5A,
  21409. Rdotbelowmacron: 0x1E5C,
  21410. Reharmenian: 0x0550,
  21411. Rfraktur: 0x211C,
  21412. Rho: 0x03A1,
  21413. Ringsmall: 0xF6FC,
  21414. Rinvertedbreve: 0x0212,
  21415. Rlinebelow: 0x1E5E,
  21416. Rmonospace: 0xFF32,
  21417. Rsmall: 0xF772,
  21418. Rsmallinverted: 0x0281,
  21419. Rsmallinvertedsuperior: 0x02B6,
  21420. S: 0x0053,
  21421. SF010000: 0x250C,
  21422. SF020000: 0x2514,
  21423. SF030000: 0x2510,
  21424. SF040000: 0x2518,
  21425. SF050000: 0x253C,
  21426. SF060000: 0x252C,
  21427. SF070000: 0x2534,
  21428. SF080000: 0x251C,
  21429. SF090000: 0x2524,
  21430. SF100000: 0x2500,
  21431. SF110000: 0x2502,
  21432. SF190000: 0x2561,
  21433. SF200000: 0x2562,
  21434. SF210000: 0x2556,
  21435. SF220000: 0x2555,
  21436. SF230000: 0x2563,
  21437. SF240000: 0x2551,
  21438. SF250000: 0x2557,
  21439. SF260000: 0x255D,
  21440. SF270000: 0x255C,
  21441. SF280000: 0x255B,
  21442. SF360000: 0x255E,
  21443. SF370000: 0x255F,
  21444. SF380000: 0x255A,
  21445. SF390000: 0x2554,
  21446. SF400000: 0x2569,
  21447. SF410000: 0x2566,
  21448. SF420000: 0x2560,
  21449. SF430000: 0x2550,
  21450. SF440000: 0x256C,
  21451. SF450000: 0x2567,
  21452. SF460000: 0x2568,
  21453. SF470000: 0x2564,
  21454. SF480000: 0x2565,
  21455. SF490000: 0x2559,
  21456. SF500000: 0x2558,
  21457. SF510000: 0x2552,
  21458. SF520000: 0x2553,
  21459. SF530000: 0x256B,
  21460. SF540000: 0x256A,
  21461. Sacute: 0x015A,
  21462. Sacutedotaccent: 0x1E64,
  21463. Sampigreek: 0x03E0,
  21464. Scaron: 0x0160,
  21465. Scarondotaccent: 0x1E66,
  21466. Scaronsmall: 0xF6FD,
  21467. Scedilla: 0x015E,
  21468. Schwa: 0x018F,
  21469. Schwacyrillic: 0x04D8,
  21470. Schwadieresiscyrillic: 0x04DA,
  21471. Scircle: 0x24C8,
  21472. Scircumflex: 0x015C,
  21473. Scommaaccent: 0x0218,
  21474. Sdotaccent: 0x1E60,
  21475. Sdotbelow: 0x1E62,
  21476. Sdotbelowdotaccent: 0x1E68,
  21477. Seharmenian: 0x054D,
  21478. Sevenroman: 0x2166,
  21479. Shaarmenian: 0x0547,
  21480. Shacyrillic: 0x0428,
  21481. Shchacyrillic: 0x0429,
  21482. Sheicoptic: 0x03E2,
  21483. Shhacyrillic: 0x04BA,
  21484. Shimacoptic: 0x03EC,
  21485. Sigma: 0x03A3,
  21486. Sixroman: 0x2165,
  21487. Smonospace: 0xFF33,
  21488. Softsigncyrillic: 0x042C,
  21489. Ssmall: 0xF773,
  21490. Stigmagreek: 0x03DA,
  21491. T: 0x0054,
  21492. Tau: 0x03A4,
  21493. Tbar: 0x0166,
  21494. Tcaron: 0x0164,
  21495. Tcedilla: 0x0162,
  21496. Tcircle: 0x24C9,
  21497. Tcircumflexbelow: 0x1E70,
  21498. Tcommaaccent: 0x0162,
  21499. Tdotaccent: 0x1E6A,
  21500. Tdotbelow: 0x1E6C,
  21501. Tecyrillic: 0x0422,
  21502. Tedescendercyrillic: 0x04AC,
  21503. Tenroman: 0x2169,
  21504. Tetsecyrillic: 0x04B4,
  21505. Theta: 0x0398,
  21506. Thook: 0x01AC,
  21507. Thorn: 0x00DE,
  21508. Thornsmall: 0xF7FE,
  21509. Threeroman: 0x2162,
  21510. Tildesmall: 0xF6FE,
  21511. Tiwnarmenian: 0x054F,
  21512. Tlinebelow: 0x1E6E,
  21513. Tmonospace: 0xFF34,
  21514. Toarmenian: 0x0539,
  21515. Tonefive: 0x01BC,
  21516. Tonesix: 0x0184,
  21517. Tonetwo: 0x01A7,
  21518. Tretroflexhook: 0x01AE,
  21519. Tsecyrillic: 0x0426,
  21520. Tshecyrillic: 0x040B,
  21521. Tsmall: 0xF774,
  21522. Twelveroman: 0x216B,
  21523. Tworoman: 0x2161,
  21524. U: 0x0055,
  21525. Uacute: 0x00DA,
  21526. Uacutesmall: 0xF7FA,
  21527. Ubreve: 0x016C,
  21528. Ucaron: 0x01D3,
  21529. Ucircle: 0x24CA,
  21530. Ucircumflex: 0x00DB,
  21531. Ucircumflexbelow: 0x1E76,
  21532. Ucircumflexsmall: 0xF7FB,
  21533. Ucyrillic: 0x0423,
  21534. Udblacute: 0x0170,
  21535. Udblgrave: 0x0214,
  21536. Udieresis: 0x00DC,
  21537. Udieresisacute: 0x01D7,
  21538. Udieresisbelow: 0x1E72,
  21539. Udieresiscaron: 0x01D9,
  21540. Udieresiscyrillic: 0x04F0,
  21541. Udieresisgrave: 0x01DB,
  21542. Udieresismacron: 0x01D5,
  21543. Udieresissmall: 0xF7FC,
  21544. Udotbelow: 0x1EE4,
  21545. Ugrave: 0x00D9,
  21546. Ugravesmall: 0xF7F9,
  21547. Uhookabove: 0x1EE6,
  21548. Uhorn: 0x01AF,
  21549. Uhornacute: 0x1EE8,
  21550. Uhorndotbelow: 0x1EF0,
  21551. Uhorngrave: 0x1EEA,
  21552. Uhornhookabove: 0x1EEC,
  21553. Uhorntilde: 0x1EEE,
  21554. Uhungarumlaut: 0x0170,
  21555. Uhungarumlautcyrillic: 0x04F2,
  21556. Uinvertedbreve: 0x0216,
  21557. Ukcyrillic: 0x0478,
  21558. Umacron: 0x016A,
  21559. Umacroncyrillic: 0x04EE,
  21560. Umacrondieresis: 0x1E7A,
  21561. Umonospace: 0xFF35,
  21562. Uogonek: 0x0172,
  21563. Upsilon: 0x03A5,
  21564. Upsilon1: 0x03D2,
  21565. Upsilonacutehooksymbolgreek: 0x03D3,
  21566. Upsilonafrican: 0x01B1,
  21567. Upsilondieresis: 0x03AB,
  21568. Upsilondieresishooksymbolgreek: 0x03D4,
  21569. Upsilonhooksymbol: 0x03D2,
  21570. Upsilontonos: 0x038E,
  21571. Uring: 0x016E,
  21572. Ushortcyrillic: 0x040E,
  21573. Usmall: 0xF775,
  21574. Ustraightcyrillic: 0x04AE,
  21575. Ustraightstrokecyrillic: 0x04B0,
  21576. Utilde: 0x0168,
  21577. Utildeacute: 0x1E78,
  21578. Utildebelow: 0x1E74,
  21579. V: 0x0056,
  21580. Vcircle: 0x24CB,
  21581. Vdotbelow: 0x1E7E,
  21582. Vecyrillic: 0x0412,
  21583. Vewarmenian: 0x054E,
  21584. Vhook: 0x01B2,
  21585. Vmonospace: 0xFF36,
  21586. Voarmenian: 0x0548,
  21587. Vsmall: 0xF776,
  21588. Vtilde: 0x1E7C,
  21589. W: 0x0057,
  21590. Wacute: 0x1E82,
  21591. Wcircle: 0x24CC,
  21592. Wcircumflex: 0x0174,
  21593. Wdieresis: 0x1E84,
  21594. Wdotaccent: 0x1E86,
  21595. Wdotbelow: 0x1E88,
  21596. Wgrave: 0x1E80,
  21597. Wmonospace: 0xFF37,
  21598. Wsmall: 0xF777,
  21599. X: 0x0058,
  21600. Xcircle: 0x24CD,
  21601. Xdieresis: 0x1E8C,
  21602. Xdotaccent: 0x1E8A,
  21603. Xeharmenian: 0x053D,
  21604. Xi: 0x039E,
  21605. Xmonospace: 0xFF38,
  21606. Xsmall: 0xF778,
  21607. Y: 0x0059,
  21608. Yacute: 0x00DD,
  21609. Yacutesmall: 0xF7FD,
  21610. Yatcyrillic: 0x0462,
  21611. Ycircle: 0x24CE,
  21612. Ycircumflex: 0x0176,
  21613. Ydieresis: 0x0178,
  21614. Ydieresissmall: 0xF7FF,
  21615. Ydotaccent: 0x1E8E,
  21616. Ydotbelow: 0x1EF4,
  21617. Yericyrillic: 0x042B,
  21618. Yerudieresiscyrillic: 0x04F8,
  21619. Ygrave: 0x1EF2,
  21620. Yhook: 0x01B3,
  21621. Yhookabove: 0x1EF6,
  21622. Yiarmenian: 0x0545,
  21623. Yicyrillic: 0x0407,
  21624. Yiwnarmenian: 0x0552,
  21625. Ymonospace: 0xFF39,
  21626. Ysmall: 0xF779,
  21627. Ytilde: 0x1EF8,
  21628. Yusbigcyrillic: 0x046A,
  21629. Yusbigiotifiedcyrillic: 0x046C,
  21630. Yuslittlecyrillic: 0x0466,
  21631. Yuslittleiotifiedcyrillic: 0x0468,
  21632. Z: 0x005A,
  21633. Zaarmenian: 0x0536,
  21634. Zacute: 0x0179,
  21635. Zcaron: 0x017D,
  21636. Zcaronsmall: 0xF6FF,
  21637. Zcircle: 0x24CF,
  21638. Zcircumflex: 0x1E90,
  21639. Zdot: 0x017B,
  21640. Zdotaccent: 0x017B,
  21641. Zdotbelow: 0x1E92,
  21642. Zecyrillic: 0x0417,
  21643. Zedescendercyrillic: 0x0498,
  21644. Zedieresiscyrillic: 0x04DE,
  21645. Zeta: 0x0396,
  21646. Zhearmenian: 0x053A,
  21647. Zhebrevecyrillic: 0x04C1,
  21648. Zhecyrillic: 0x0416,
  21649. Zhedescendercyrillic: 0x0496,
  21650. Zhedieresiscyrillic: 0x04DC,
  21651. Zlinebelow: 0x1E94,
  21652. Zmonospace: 0xFF3A,
  21653. Zsmall: 0xF77A,
  21654. Zstroke: 0x01B5,
  21655. a: 0x0061,
  21656. aabengali: 0x0986,
  21657. aacute: 0x00E1,
  21658. aadeva: 0x0906,
  21659. aagujarati: 0x0A86,
  21660. aagurmukhi: 0x0A06,
  21661. aamatragurmukhi: 0x0A3E,
  21662. aarusquare: 0x3303,
  21663. aavowelsignbengali: 0x09BE,
  21664. aavowelsigndeva: 0x093E,
  21665. aavowelsigngujarati: 0x0ABE,
  21666. abbreviationmarkarmenian: 0x055F,
  21667. abbreviationsigndeva: 0x0970,
  21668. abengali: 0x0985,
  21669. abopomofo: 0x311A,
  21670. abreve: 0x0103,
  21671. abreveacute: 0x1EAF,
  21672. abrevecyrillic: 0x04D1,
  21673. abrevedotbelow: 0x1EB7,
  21674. abrevegrave: 0x1EB1,
  21675. abrevehookabove: 0x1EB3,
  21676. abrevetilde: 0x1EB5,
  21677. acaron: 0x01CE,
  21678. acircle: 0x24D0,
  21679. acircumflex: 0x00E2,
  21680. acircumflexacute: 0x1EA5,
  21681. acircumflexdotbelow: 0x1EAD,
  21682. acircumflexgrave: 0x1EA7,
  21683. acircumflexhookabove: 0x1EA9,
  21684. acircumflextilde: 0x1EAB,
  21685. acute: 0x00B4,
  21686. acutebelowcmb: 0x0317,
  21687. acutecmb: 0x0301,
  21688. acutecomb: 0x0301,
  21689. acutedeva: 0x0954,
  21690. acutelowmod: 0x02CF,
  21691. acutetonecmb: 0x0341,
  21692. acyrillic: 0x0430,
  21693. adblgrave: 0x0201,
  21694. addakgurmukhi: 0x0A71,
  21695. adeva: 0x0905,
  21696. adieresis: 0x00E4,
  21697. adieresiscyrillic: 0x04D3,
  21698. adieresismacron: 0x01DF,
  21699. adotbelow: 0x1EA1,
  21700. adotmacron: 0x01E1,
  21701. ae: 0x00E6,
  21702. aeacute: 0x01FD,
  21703. aekorean: 0x3150,
  21704. aemacron: 0x01E3,
  21705. afii00208: 0x2015,
  21706. afii08941: 0x20A4,
  21707. afii10017: 0x0410,
  21708. afii10018: 0x0411,
  21709. afii10019: 0x0412,
  21710. afii10020: 0x0413,
  21711. afii10021: 0x0414,
  21712. afii10022: 0x0415,
  21713. afii10023: 0x0401,
  21714. afii10024: 0x0416,
  21715. afii10025: 0x0417,
  21716. afii10026: 0x0418,
  21717. afii10027: 0x0419,
  21718. afii10028: 0x041A,
  21719. afii10029: 0x041B,
  21720. afii10030: 0x041C,
  21721. afii10031: 0x041D,
  21722. afii10032: 0x041E,
  21723. afii10033: 0x041F,
  21724. afii10034: 0x0420,
  21725. afii10035: 0x0421,
  21726. afii10036: 0x0422,
  21727. afii10037: 0x0423,
  21728. afii10038: 0x0424,
  21729. afii10039: 0x0425,
  21730. afii10040: 0x0426,
  21731. afii10041: 0x0427,
  21732. afii10042: 0x0428,
  21733. afii10043: 0x0429,
  21734. afii10044: 0x042A,
  21735. afii10045: 0x042B,
  21736. afii10046: 0x042C,
  21737. afii10047: 0x042D,
  21738. afii10048: 0x042E,
  21739. afii10049: 0x042F,
  21740. afii10050: 0x0490,
  21741. afii10051: 0x0402,
  21742. afii10052: 0x0403,
  21743. afii10053: 0x0404,
  21744. afii10054: 0x0405,
  21745. afii10055: 0x0406,
  21746. afii10056: 0x0407,
  21747. afii10057: 0x0408,
  21748. afii10058: 0x0409,
  21749. afii10059: 0x040A,
  21750. afii10060: 0x040B,
  21751. afii10061: 0x040C,
  21752. afii10062: 0x040E,
  21753. afii10063: 0xF6C4,
  21754. afii10064: 0xF6C5,
  21755. afii10065: 0x0430,
  21756. afii10066: 0x0431,
  21757. afii10067: 0x0432,
  21758. afii10068: 0x0433,
  21759. afii10069: 0x0434,
  21760. afii10070: 0x0435,
  21761. afii10071: 0x0451,
  21762. afii10072: 0x0436,
  21763. afii10073: 0x0437,
  21764. afii10074: 0x0438,
  21765. afii10075: 0x0439,
  21766. afii10076: 0x043A,
  21767. afii10077: 0x043B,
  21768. afii10078: 0x043C,
  21769. afii10079: 0x043D,
  21770. afii10080: 0x043E,
  21771. afii10081: 0x043F,
  21772. afii10082: 0x0440,
  21773. afii10083: 0x0441,
  21774. afii10084: 0x0442,
  21775. afii10085: 0x0443,
  21776. afii10086: 0x0444,
  21777. afii10087: 0x0445,
  21778. afii10088: 0x0446,
  21779. afii10089: 0x0447,
  21780. afii10090: 0x0448,
  21781. afii10091: 0x0449,
  21782. afii10092: 0x044A,
  21783. afii10093: 0x044B,
  21784. afii10094: 0x044C,
  21785. afii10095: 0x044D,
  21786. afii10096: 0x044E,
  21787. afii10097: 0x044F,
  21788. afii10098: 0x0491,
  21789. afii10099: 0x0452,
  21790. afii10100: 0x0453,
  21791. afii10101: 0x0454,
  21792. afii10102: 0x0455,
  21793. afii10103: 0x0456,
  21794. afii10104: 0x0457,
  21795. afii10105: 0x0458,
  21796. afii10106: 0x0459,
  21797. afii10107: 0x045A,
  21798. afii10108: 0x045B,
  21799. afii10109: 0x045C,
  21800. afii10110: 0x045E,
  21801. afii10145: 0x040F,
  21802. afii10146: 0x0462,
  21803. afii10147: 0x0472,
  21804. afii10148: 0x0474,
  21805. afii10192: 0xF6C6,
  21806. afii10193: 0x045F,
  21807. afii10194: 0x0463,
  21808. afii10195: 0x0473,
  21809. afii10196: 0x0475,
  21810. afii10831: 0xF6C7,
  21811. afii10832: 0xF6C8,
  21812. afii10846: 0x04D9,
  21813. afii299: 0x200E,
  21814. afii300: 0x200F,
  21815. afii301: 0x200D,
  21816. afii57381: 0x066A,
  21817. afii57388: 0x060C,
  21818. afii57392: 0x0660,
  21819. afii57393: 0x0661,
  21820. afii57394: 0x0662,
  21821. afii57395: 0x0663,
  21822. afii57396: 0x0664,
  21823. afii57397: 0x0665,
  21824. afii57398: 0x0666,
  21825. afii57399: 0x0667,
  21826. afii57400: 0x0668,
  21827. afii57401: 0x0669,
  21828. afii57403: 0x061B,
  21829. afii57407: 0x061F,
  21830. afii57409: 0x0621,
  21831. afii57410: 0x0622,
  21832. afii57411: 0x0623,
  21833. afii57412: 0x0624,
  21834. afii57413: 0x0625,
  21835. afii57414: 0x0626,
  21836. afii57415: 0x0627,
  21837. afii57416: 0x0628,
  21838. afii57417: 0x0629,
  21839. afii57418: 0x062A,
  21840. afii57419: 0x062B,
  21841. afii57420: 0x062C,
  21842. afii57421: 0x062D,
  21843. afii57422: 0x062E,
  21844. afii57423: 0x062F,
  21845. afii57424: 0x0630,
  21846. afii57425: 0x0631,
  21847. afii57426: 0x0632,
  21848. afii57427: 0x0633,
  21849. afii57428: 0x0634,
  21850. afii57429: 0x0635,
  21851. afii57430: 0x0636,
  21852. afii57431: 0x0637,
  21853. afii57432: 0x0638,
  21854. afii57433: 0x0639,
  21855. afii57434: 0x063A,
  21856. afii57440: 0x0640,
  21857. afii57441: 0x0641,
  21858. afii57442: 0x0642,
  21859. afii57443: 0x0643,
  21860. afii57444: 0x0644,
  21861. afii57445: 0x0645,
  21862. afii57446: 0x0646,
  21863. afii57448: 0x0648,
  21864. afii57449: 0x0649,
  21865. afii57450: 0x064A,
  21866. afii57451: 0x064B,
  21867. afii57452: 0x064C,
  21868. afii57453: 0x064D,
  21869. afii57454: 0x064E,
  21870. afii57455: 0x064F,
  21871. afii57456: 0x0650,
  21872. afii57457: 0x0651,
  21873. afii57458: 0x0652,
  21874. afii57470: 0x0647,
  21875. afii57505: 0x06A4,
  21876. afii57506: 0x067E,
  21877. afii57507: 0x0686,
  21878. afii57508: 0x0698,
  21879. afii57509: 0x06AF,
  21880. afii57511: 0x0679,
  21881. afii57512: 0x0688,
  21882. afii57513: 0x0691,
  21883. afii57514: 0x06BA,
  21884. afii57519: 0x06D2,
  21885. afii57534: 0x06D5,
  21886. afii57636: 0x20AA,
  21887. afii57645: 0x05BE,
  21888. afii57658: 0x05C3,
  21889. afii57664: 0x05D0,
  21890. afii57665: 0x05D1,
  21891. afii57666: 0x05D2,
  21892. afii57667: 0x05D3,
  21893. afii57668: 0x05D4,
  21894. afii57669: 0x05D5,
  21895. afii57670: 0x05D6,
  21896. afii57671: 0x05D7,
  21897. afii57672: 0x05D8,
  21898. afii57673: 0x05D9,
  21899. afii57674: 0x05DA,
  21900. afii57675: 0x05DB,
  21901. afii57676: 0x05DC,
  21902. afii57677: 0x05DD,
  21903. afii57678: 0x05DE,
  21904. afii57679: 0x05DF,
  21905. afii57680: 0x05E0,
  21906. afii57681: 0x05E1,
  21907. afii57682: 0x05E2,
  21908. afii57683: 0x05E3,
  21909. afii57684: 0x05E4,
  21910. afii57685: 0x05E5,
  21911. afii57686: 0x05E6,
  21912. afii57687: 0x05E7,
  21913. afii57688: 0x05E8,
  21914. afii57689: 0x05E9,
  21915. afii57690: 0x05EA,
  21916. afii57694: 0xFB2A,
  21917. afii57695: 0xFB2B,
  21918. afii57700: 0xFB4B,
  21919. afii57705: 0xFB1F,
  21920. afii57716: 0x05F0,
  21921. afii57717: 0x05F1,
  21922. afii57718: 0x05F2,
  21923. afii57723: 0xFB35,
  21924. afii57793: 0x05B4,
  21925. afii57794: 0x05B5,
  21926. afii57795: 0x05B6,
  21927. afii57796: 0x05BB,
  21928. afii57797: 0x05B8,
  21929. afii57798: 0x05B7,
  21930. afii57799: 0x05B0,
  21931. afii57800: 0x05B2,
  21932. afii57801: 0x05B1,
  21933. afii57802: 0x05B3,
  21934. afii57803: 0x05C2,
  21935. afii57804: 0x05C1,
  21936. afii57806: 0x05B9,
  21937. afii57807: 0x05BC,
  21938. afii57839: 0x05BD,
  21939. afii57841: 0x05BF,
  21940. afii57842: 0x05C0,
  21941. afii57929: 0x02BC,
  21942. afii61248: 0x2105,
  21943. afii61289: 0x2113,
  21944. afii61352: 0x2116,
  21945. afii61573: 0x202C,
  21946. afii61574: 0x202D,
  21947. afii61575: 0x202E,
  21948. afii61664: 0x200C,
  21949. afii63167: 0x066D,
  21950. afii64937: 0x02BD,
  21951. agrave: 0x00E0,
  21952. agujarati: 0x0A85,
  21953. agurmukhi: 0x0A05,
  21954. ahiragana: 0x3042,
  21955. ahookabove: 0x1EA3,
  21956. aibengali: 0x0990,
  21957. aibopomofo: 0x311E,
  21958. aideva: 0x0910,
  21959. aiecyrillic: 0x04D5,
  21960. aigujarati: 0x0A90,
  21961. aigurmukhi: 0x0A10,
  21962. aimatragurmukhi: 0x0A48,
  21963. ainarabic: 0x0639,
  21964. ainfinalarabic: 0xFECA,
  21965. aininitialarabic: 0xFECB,
  21966. ainmedialarabic: 0xFECC,
  21967. ainvertedbreve: 0x0203,
  21968. aivowelsignbengali: 0x09C8,
  21969. aivowelsigndeva: 0x0948,
  21970. aivowelsigngujarati: 0x0AC8,
  21971. akatakana: 0x30A2,
  21972. akatakanahalfwidth: 0xFF71,
  21973. akorean: 0x314F,
  21974. alef: 0x05D0,
  21975. alefarabic: 0x0627,
  21976. alefdageshhebrew: 0xFB30,
  21977. aleffinalarabic: 0xFE8E,
  21978. alefhamzaabovearabic: 0x0623,
  21979. alefhamzaabovefinalarabic: 0xFE84,
  21980. alefhamzabelowarabic: 0x0625,
  21981. alefhamzabelowfinalarabic: 0xFE88,
  21982. alefhebrew: 0x05D0,
  21983. aleflamedhebrew: 0xFB4F,
  21984. alefmaddaabovearabic: 0x0622,
  21985. alefmaddaabovefinalarabic: 0xFE82,
  21986. alefmaksuraarabic: 0x0649,
  21987. alefmaksurafinalarabic: 0xFEF0,
  21988. alefmaksurainitialarabic: 0xFEF3,
  21989. alefmaksuramedialarabic: 0xFEF4,
  21990. alefpatahhebrew: 0xFB2E,
  21991. alefqamatshebrew: 0xFB2F,
  21992. aleph: 0x2135,
  21993. allequal: 0x224C,
  21994. alpha: 0x03B1,
  21995. alphatonos: 0x03AC,
  21996. amacron: 0x0101,
  21997. amonospace: 0xFF41,
  21998. ampersand: 0x0026,
  21999. ampersandmonospace: 0xFF06,
  22000. ampersandsmall: 0xF726,
  22001. amsquare: 0x33C2,
  22002. anbopomofo: 0x3122,
  22003. angbopomofo: 0x3124,
  22004. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  22005. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  22006. angkhankhuthai: 0x0E5A,
  22007. angle: 0x2220,
  22008. anglebracketleft: 0x3008,
  22009. anglebracketleftvertical: 0xFE3F,
  22010. anglebracketright: 0x3009,
  22011. anglebracketrightvertical: 0xFE40,
  22012. angleleft: 0x2329,
  22013. angleright: 0x232A,
  22014. angstrom: 0x212B,
  22015. anoteleia: 0x0387,
  22016. anudattadeva: 0x0952,
  22017. anusvarabengali: 0x0982,
  22018. anusvaradeva: 0x0902,
  22019. anusvaragujarati: 0x0A82,
  22020. aogonek: 0x0105,
  22021. apaatosquare: 0x3300,
  22022. aparen: 0x249C,
  22023. apostrophearmenian: 0x055A,
  22024. apostrophemod: 0x02BC,
  22025. apple: 0xF8FF,
  22026. approaches: 0x2250,
  22027. approxequal: 0x2248,
  22028. approxequalorimage: 0x2252,
  22029. approximatelyequal: 0x2245,
  22030. araeaekorean: 0x318E,
  22031. araeakorean: 0x318D,
  22032. arc: 0x2312,
  22033. arighthalfring: 0x1E9A,
  22034. aring: 0x00E5,
  22035. aringacute: 0x01FB,
  22036. aringbelow: 0x1E01,
  22037. arrowboth: 0x2194,
  22038. arrowdashdown: 0x21E3,
  22039. arrowdashleft: 0x21E0,
  22040. arrowdashright: 0x21E2,
  22041. arrowdashup: 0x21E1,
  22042. arrowdblboth: 0x21D4,
  22043. arrowdbldown: 0x21D3,
  22044. arrowdblleft: 0x21D0,
  22045. arrowdblright: 0x21D2,
  22046. arrowdblup: 0x21D1,
  22047. arrowdown: 0x2193,
  22048. arrowdownleft: 0x2199,
  22049. arrowdownright: 0x2198,
  22050. arrowdownwhite: 0x21E9,
  22051. arrowheaddownmod: 0x02C5,
  22052. arrowheadleftmod: 0x02C2,
  22053. arrowheadrightmod: 0x02C3,
  22054. arrowheadupmod: 0x02C4,
  22055. arrowhorizex: 0xF8E7,
  22056. arrowleft: 0x2190,
  22057. arrowleftdbl: 0x21D0,
  22058. arrowleftdblstroke: 0x21CD,
  22059. arrowleftoverright: 0x21C6,
  22060. arrowleftwhite: 0x21E6,
  22061. arrowright: 0x2192,
  22062. arrowrightdblstroke: 0x21CF,
  22063. arrowrightheavy: 0x279E,
  22064. arrowrightoverleft: 0x21C4,
  22065. arrowrightwhite: 0x21E8,
  22066. arrowtableft: 0x21E4,
  22067. arrowtabright: 0x21E5,
  22068. arrowup: 0x2191,
  22069. arrowupdn: 0x2195,
  22070. arrowupdnbse: 0x21A8,
  22071. arrowupdownbase: 0x21A8,
  22072. arrowupleft: 0x2196,
  22073. arrowupleftofdown: 0x21C5,
  22074. arrowupright: 0x2197,
  22075. arrowupwhite: 0x21E7,
  22076. arrowvertex: 0xF8E6,
  22077. asciicircum: 0x005E,
  22078. asciicircummonospace: 0xFF3E,
  22079. asciitilde: 0x007E,
  22080. asciitildemonospace: 0xFF5E,
  22081. ascript: 0x0251,
  22082. ascriptturned: 0x0252,
  22083. asmallhiragana: 0x3041,
  22084. asmallkatakana: 0x30A1,
  22085. asmallkatakanahalfwidth: 0xFF67,
  22086. asterisk: 0x002A,
  22087. asteriskaltonearabic: 0x066D,
  22088. asteriskarabic: 0x066D,
  22089. asteriskmath: 0x2217,
  22090. asteriskmonospace: 0xFF0A,
  22091. asterisksmall: 0xFE61,
  22092. asterism: 0x2042,
  22093. asuperior: 0xF6E9,
  22094. asymptoticallyequal: 0x2243,
  22095. at: 0x0040,
  22096. atilde: 0x00E3,
  22097. atmonospace: 0xFF20,
  22098. atsmall: 0xFE6B,
  22099. aturned: 0x0250,
  22100. aubengali: 0x0994,
  22101. aubopomofo: 0x3120,
  22102. audeva: 0x0914,
  22103. augujarati: 0x0A94,
  22104. augurmukhi: 0x0A14,
  22105. aulengthmarkbengali: 0x09D7,
  22106. aumatragurmukhi: 0x0A4C,
  22107. auvowelsignbengali: 0x09CC,
  22108. auvowelsigndeva: 0x094C,
  22109. auvowelsigngujarati: 0x0ACC,
  22110. avagrahadeva: 0x093D,
  22111. aybarmenian: 0x0561,
  22112. ayin: 0x05E2,
  22113. ayinaltonehebrew: 0xFB20,
  22114. ayinhebrew: 0x05E2,
  22115. b: 0x0062,
  22116. babengali: 0x09AC,
  22117. backslash: 0x005C,
  22118. backslashmonospace: 0xFF3C,
  22119. badeva: 0x092C,
  22120. bagujarati: 0x0AAC,
  22121. bagurmukhi: 0x0A2C,
  22122. bahiragana: 0x3070,
  22123. bahtthai: 0x0E3F,
  22124. bakatakana: 0x30D0,
  22125. bar: 0x007C,
  22126. barmonospace: 0xFF5C,
  22127. bbopomofo: 0x3105,
  22128. bcircle: 0x24D1,
  22129. bdotaccent: 0x1E03,
  22130. bdotbelow: 0x1E05,
  22131. beamedsixteenthnotes: 0x266C,
  22132. because: 0x2235,
  22133. becyrillic: 0x0431,
  22134. beharabic: 0x0628,
  22135. behfinalarabic: 0xFE90,
  22136. behinitialarabic: 0xFE91,
  22137. behiragana: 0x3079,
  22138. behmedialarabic: 0xFE92,
  22139. behmeeminitialarabic: 0xFC9F,
  22140. behmeemisolatedarabic: 0xFC08,
  22141. behnoonfinalarabic: 0xFC6D,
  22142. bekatakana: 0x30D9,
  22143. benarmenian: 0x0562,
  22144. bet: 0x05D1,
  22145. beta: 0x03B2,
  22146. betasymbolgreek: 0x03D0,
  22147. betdagesh: 0xFB31,
  22148. betdageshhebrew: 0xFB31,
  22149. bethebrew: 0x05D1,
  22150. betrafehebrew: 0xFB4C,
  22151. bhabengali: 0x09AD,
  22152. bhadeva: 0x092D,
  22153. bhagujarati: 0x0AAD,
  22154. bhagurmukhi: 0x0A2D,
  22155. bhook: 0x0253,
  22156. bihiragana: 0x3073,
  22157. bikatakana: 0x30D3,
  22158. bilabialclick: 0x0298,
  22159. bindigurmukhi: 0x0A02,
  22160. birusquare: 0x3331,
  22161. blackcircle: 0x25CF,
  22162. blackdiamond: 0x25C6,
  22163. blackdownpointingtriangle: 0x25BC,
  22164. blackleftpointingpointer: 0x25C4,
  22165. blackleftpointingtriangle: 0x25C0,
  22166. blacklenticularbracketleft: 0x3010,
  22167. blacklenticularbracketleftvertical: 0xFE3B,
  22168. blacklenticularbracketright: 0x3011,
  22169. blacklenticularbracketrightvertical: 0xFE3C,
  22170. blacklowerlefttriangle: 0x25E3,
  22171. blacklowerrighttriangle: 0x25E2,
  22172. blackrectangle: 0x25AC,
  22173. blackrightpointingpointer: 0x25BA,
  22174. blackrightpointingtriangle: 0x25B6,
  22175. blacksmallsquare: 0x25AA,
  22176. blacksmilingface: 0x263B,
  22177. blacksquare: 0x25A0,
  22178. blackstar: 0x2605,
  22179. blackupperlefttriangle: 0x25E4,
  22180. blackupperrighttriangle: 0x25E5,
  22181. blackuppointingsmalltriangle: 0x25B4,
  22182. blackuppointingtriangle: 0x25B2,
  22183. blank: 0x2423,
  22184. blinebelow: 0x1E07,
  22185. block: 0x2588,
  22186. bmonospace: 0xFF42,
  22187. bobaimaithai: 0x0E1A,
  22188. bohiragana: 0x307C,
  22189. bokatakana: 0x30DC,
  22190. bparen: 0x249D,
  22191. bqsquare: 0x33C3,
  22192. braceex: 0xF8F4,
  22193. braceleft: 0x007B,
  22194. braceleftbt: 0xF8F3,
  22195. braceleftmid: 0xF8F2,
  22196. braceleftmonospace: 0xFF5B,
  22197. braceleftsmall: 0xFE5B,
  22198. bracelefttp: 0xF8F1,
  22199. braceleftvertical: 0xFE37,
  22200. braceright: 0x007D,
  22201. bracerightbt: 0xF8FE,
  22202. bracerightmid: 0xF8FD,
  22203. bracerightmonospace: 0xFF5D,
  22204. bracerightsmall: 0xFE5C,
  22205. bracerighttp: 0xF8FC,
  22206. bracerightvertical: 0xFE38,
  22207. bracketleft: 0x005B,
  22208. bracketleftbt: 0xF8F0,
  22209. bracketleftex: 0xF8EF,
  22210. bracketleftmonospace: 0xFF3B,
  22211. bracketlefttp: 0xF8EE,
  22212. bracketright: 0x005D,
  22213. bracketrightbt: 0xF8FB,
  22214. bracketrightex: 0xF8FA,
  22215. bracketrightmonospace: 0xFF3D,
  22216. bracketrighttp: 0xF8F9,
  22217. breve: 0x02D8,
  22218. brevebelowcmb: 0x032E,
  22219. brevecmb: 0x0306,
  22220. breveinvertedbelowcmb: 0x032F,
  22221. breveinvertedcmb: 0x0311,
  22222. breveinverteddoublecmb: 0x0361,
  22223. bridgebelowcmb: 0x032A,
  22224. bridgeinvertedbelowcmb: 0x033A,
  22225. brokenbar: 0x00A6,
  22226. bstroke: 0x0180,
  22227. bsuperior: 0xF6EA,
  22228. btopbar: 0x0183,
  22229. buhiragana: 0x3076,
  22230. bukatakana: 0x30D6,
  22231. bullet: 0x2022,
  22232. bulletinverse: 0x25D8,
  22233. bulletoperator: 0x2219,
  22234. bullseye: 0x25CE,
  22235. c: 0x0063,
  22236. caarmenian: 0x056E,
  22237. cabengali: 0x099A,
  22238. cacute: 0x0107,
  22239. cadeva: 0x091A,
  22240. cagujarati: 0x0A9A,
  22241. cagurmukhi: 0x0A1A,
  22242. calsquare: 0x3388,
  22243. candrabindubengali: 0x0981,
  22244. candrabinducmb: 0x0310,
  22245. candrabindudeva: 0x0901,
  22246. candrabindugujarati: 0x0A81,
  22247. capslock: 0x21EA,
  22248. careof: 0x2105,
  22249. caron: 0x02C7,
  22250. caronbelowcmb: 0x032C,
  22251. caroncmb: 0x030C,
  22252. carriagereturn: 0x21B5,
  22253. cbopomofo: 0x3118,
  22254. ccaron: 0x010D,
  22255. ccedilla: 0x00E7,
  22256. ccedillaacute: 0x1E09,
  22257. ccircle: 0x24D2,
  22258. ccircumflex: 0x0109,
  22259. ccurl: 0x0255,
  22260. cdot: 0x010B,
  22261. cdotaccent: 0x010B,
  22262. cdsquare: 0x33C5,
  22263. cedilla: 0x00B8,
  22264. cedillacmb: 0x0327,
  22265. cent: 0x00A2,
  22266. centigrade: 0x2103,
  22267. centinferior: 0xF6DF,
  22268. centmonospace: 0xFFE0,
  22269. centoldstyle: 0xF7A2,
  22270. centsuperior: 0xF6E0,
  22271. chaarmenian: 0x0579,
  22272. chabengali: 0x099B,
  22273. chadeva: 0x091B,
  22274. chagujarati: 0x0A9B,
  22275. chagurmukhi: 0x0A1B,
  22276. chbopomofo: 0x3114,
  22277. cheabkhasiancyrillic: 0x04BD,
  22278. checkmark: 0x2713,
  22279. checyrillic: 0x0447,
  22280. chedescenderabkhasiancyrillic: 0x04BF,
  22281. chedescendercyrillic: 0x04B7,
  22282. chedieresiscyrillic: 0x04F5,
  22283. cheharmenian: 0x0573,
  22284. chekhakassiancyrillic: 0x04CC,
  22285. cheverticalstrokecyrillic: 0x04B9,
  22286. chi: 0x03C7,
  22287. chieuchacirclekorean: 0x3277,
  22288. chieuchaparenkorean: 0x3217,
  22289. chieuchcirclekorean: 0x3269,
  22290. chieuchkorean: 0x314A,
  22291. chieuchparenkorean: 0x3209,
  22292. chochangthai: 0x0E0A,
  22293. chochanthai: 0x0E08,
  22294. chochingthai: 0x0E09,
  22295. chochoethai: 0x0E0C,
  22296. chook: 0x0188,
  22297. cieucacirclekorean: 0x3276,
  22298. cieucaparenkorean: 0x3216,
  22299. cieuccirclekorean: 0x3268,
  22300. cieuckorean: 0x3148,
  22301. cieucparenkorean: 0x3208,
  22302. cieucuparenkorean: 0x321C,
  22303. circle: 0x25CB,
  22304. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  22305. circlemultiply: 0x2297,
  22306. circleot: 0x2299,
  22307. circleplus: 0x2295,
  22308. circlepostalmark: 0x3036,
  22309. circlewithlefthalfblack: 0x25D0,
  22310. circlewithrighthalfblack: 0x25D1,
  22311. circumflex: 0x02C6,
  22312. circumflexbelowcmb: 0x032D,
  22313. circumflexcmb: 0x0302,
  22314. clear: 0x2327,
  22315. clickalveolar: 0x01C2,
  22316. clickdental: 0x01C0,
  22317. clicklateral: 0x01C1,
  22318. clickretroflex: 0x01C3,
  22319. club: 0x2663,
  22320. clubsuitblack: 0x2663,
  22321. clubsuitwhite: 0x2667,
  22322. cmcubedsquare: 0x33A4,
  22323. cmonospace: 0xFF43,
  22324. cmsquaredsquare: 0x33A0,
  22325. coarmenian: 0x0581,
  22326. colon: 0x003A,
  22327. colonmonetary: 0x20A1,
  22328. colonmonospace: 0xFF1A,
  22329. colonsign: 0x20A1,
  22330. colonsmall: 0xFE55,
  22331. colontriangularhalfmod: 0x02D1,
  22332. colontriangularmod: 0x02D0,
  22333. comma: 0x002C,
  22334. commaabovecmb: 0x0313,
  22335. commaaboverightcmb: 0x0315,
  22336. commaaccent: 0xF6C3,
  22337. commaarabic: 0x060C,
  22338. commaarmenian: 0x055D,
  22339. commainferior: 0xF6E1,
  22340. commamonospace: 0xFF0C,
  22341. commareversedabovecmb: 0x0314,
  22342. commareversedmod: 0x02BD,
  22343. commasmall: 0xFE50,
  22344. commasuperior: 0xF6E2,
  22345. commaturnedabovecmb: 0x0312,
  22346. commaturnedmod: 0x02BB,
  22347. compass: 0x263C,
  22348. congruent: 0x2245,
  22349. contourintegral: 0x222E,
  22350. control: 0x2303,
  22351. controlACK: 0x0006,
  22352. controlBEL: 0x0007,
  22353. controlBS: 0x0008,
  22354. controlCAN: 0x0018,
  22355. controlCR: 0x000D,
  22356. controlDC1: 0x0011,
  22357. controlDC2: 0x0012,
  22358. controlDC3: 0x0013,
  22359. controlDC4: 0x0014,
  22360. controlDEL: 0x007F,
  22361. controlDLE: 0x0010,
  22362. controlEM: 0x0019,
  22363. controlENQ: 0x0005,
  22364. controlEOT: 0x0004,
  22365. controlESC: 0x001B,
  22366. controlETB: 0x0017,
  22367. controlETX: 0x0003,
  22368. controlFF: 0x000C,
  22369. controlFS: 0x001C,
  22370. controlGS: 0x001D,
  22371. controlHT: 0x0009,
  22372. controlLF: 0x000A,
  22373. controlNAK: 0x0015,
  22374. controlRS: 0x001E,
  22375. controlSI: 0x000F,
  22376. controlSO: 0x000E,
  22377. controlSOT: 0x0002,
  22378. controlSTX: 0x0001,
  22379. controlSUB: 0x001A,
  22380. controlSYN: 0x0016,
  22381. controlUS: 0x001F,
  22382. controlVT: 0x000B,
  22383. copyright: 0x00A9,
  22384. copyrightsans: 0xF8E9,
  22385. copyrightserif: 0xF6D9,
  22386. cornerbracketleft: 0x300C,
  22387. cornerbracketlefthalfwidth: 0xFF62,
  22388. cornerbracketleftvertical: 0xFE41,
  22389. cornerbracketright: 0x300D,
  22390. cornerbracketrighthalfwidth: 0xFF63,
  22391. cornerbracketrightvertical: 0xFE42,
  22392. corporationsquare: 0x337F,
  22393. cosquare: 0x33C7,
  22394. coverkgsquare: 0x33C6,
  22395. cparen: 0x249E,
  22396. cruzeiro: 0x20A2,
  22397. cstretched: 0x0297,
  22398. curlyand: 0x22CF,
  22399. curlyor: 0x22CE,
  22400. currency: 0x00A4,
  22401. cyrBreve: 0xF6D1,
  22402. cyrFlex: 0xF6D2,
  22403. cyrbreve: 0xF6D4,
  22404. cyrflex: 0xF6D5,
  22405. d: 0x0064,
  22406. daarmenian: 0x0564,
  22407. dabengali: 0x09A6,
  22408. dadarabic: 0x0636,
  22409. dadeva: 0x0926,
  22410. dadfinalarabic: 0xFEBE,
  22411. dadinitialarabic: 0xFEBF,
  22412. dadmedialarabic: 0xFEC0,
  22413. dagesh: 0x05BC,
  22414. dageshhebrew: 0x05BC,
  22415. dagger: 0x2020,
  22416. daggerdbl: 0x2021,
  22417. dagujarati: 0x0AA6,
  22418. dagurmukhi: 0x0A26,
  22419. dahiragana: 0x3060,
  22420. dakatakana: 0x30C0,
  22421. dalarabic: 0x062F,
  22422. dalet: 0x05D3,
  22423. daletdagesh: 0xFB33,
  22424. daletdageshhebrew: 0xFB33,
  22425. dalethebrew: 0x05D3,
  22426. dalfinalarabic: 0xFEAA,
  22427. dammaarabic: 0x064F,
  22428. dammalowarabic: 0x064F,
  22429. dammatanaltonearabic: 0x064C,
  22430. dammatanarabic: 0x064C,
  22431. danda: 0x0964,
  22432. dargahebrew: 0x05A7,
  22433. dargalefthebrew: 0x05A7,
  22434. dasiapneumatacyrilliccmb: 0x0485,
  22435. dblGrave: 0xF6D3,
  22436. dblanglebracketleft: 0x300A,
  22437. dblanglebracketleftvertical: 0xFE3D,
  22438. dblanglebracketright: 0x300B,
  22439. dblanglebracketrightvertical: 0xFE3E,
  22440. dblarchinvertedbelowcmb: 0x032B,
  22441. dblarrowleft: 0x21D4,
  22442. dblarrowright: 0x21D2,
  22443. dbldanda: 0x0965,
  22444. dblgrave: 0xF6D6,
  22445. dblgravecmb: 0x030F,
  22446. dblintegral: 0x222C,
  22447. dbllowline: 0x2017,
  22448. dbllowlinecmb: 0x0333,
  22449. dbloverlinecmb: 0x033F,
  22450. dblprimemod: 0x02BA,
  22451. dblverticalbar: 0x2016,
  22452. dblverticallineabovecmb: 0x030E,
  22453. dbopomofo: 0x3109,
  22454. dbsquare: 0x33C8,
  22455. dcaron: 0x010F,
  22456. dcedilla: 0x1E11,
  22457. dcircle: 0x24D3,
  22458. dcircumflexbelow: 0x1E13,
  22459. dcroat: 0x0111,
  22460. ddabengali: 0x09A1,
  22461. ddadeva: 0x0921,
  22462. ddagujarati: 0x0AA1,
  22463. ddagurmukhi: 0x0A21,
  22464. ddalarabic: 0x0688,
  22465. ddalfinalarabic: 0xFB89,
  22466. dddhadeva: 0x095C,
  22467. ddhabengali: 0x09A2,
  22468. ddhadeva: 0x0922,
  22469. ddhagujarati: 0x0AA2,
  22470. ddhagurmukhi: 0x0A22,
  22471. ddotaccent: 0x1E0B,
  22472. ddotbelow: 0x1E0D,
  22473. decimalseparatorarabic: 0x066B,
  22474. decimalseparatorpersian: 0x066B,
  22475. decyrillic: 0x0434,
  22476. degree: 0x00B0,
  22477. dehihebrew: 0x05AD,
  22478. dehiragana: 0x3067,
  22479. deicoptic: 0x03EF,
  22480. dekatakana: 0x30C7,
  22481. deleteleft: 0x232B,
  22482. deleteright: 0x2326,
  22483. delta: 0x03B4,
  22484. deltaturned: 0x018D,
  22485. denominatorminusonenumeratorbengali: 0x09F8,
  22486. dezh: 0x02A4,
  22487. dhabengali: 0x09A7,
  22488. dhadeva: 0x0927,
  22489. dhagujarati: 0x0AA7,
  22490. dhagurmukhi: 0x0A27,
  22491. dhook: 0x0257,
  22492. dialytikatonos: 0x0385,
  22493. dialytikatonoscmb: 0x0344,
  22494. diamond: 0x2666,
  22495. diamondsuitwhite: 0x2662,
  22496. dieresis: 0x00A8,
  22497. dieresisacute: 0xF6D7,
  22498. dieresisbelowcmb: 0x0324,
  22499. dieresiscmb: 0x0308,
  22500. dieresisgrave: 0xF6D8,
  22501. dieresistonos: 0x0385,
  22502. dihiragana: 0x3062,
  22503. dikatakana: 0x30C2,
  22504. dittomark: 0x3003,
  22505. divide: 0x00F7,
  22506. divides: 0x2223,
  22507. divisionslash: 0x2215,
  22508. djecyrillic: 0x0452,
  22509. dkshade: 0x2593,
  22510. dlinebelow: 0x1E0F,
  22511. dlsquare: 0x3397,
  22512. dmacron: 0x0111,
  22513. dmonospace: 0xFF44,
  22514. dnblock: 0x2584,
  22515. dochadathai: 0x0E0E,
  22516. dodekthai: 0x0E14,
  22517. dohiragana: 0x3069,
  22518. dokatakana: 0x30C9,
  22519. dollar: 0x0024,
  22520. dollarinferior: 0xF6E3,
  22521. dollarmonospace: 0xFF04,
  22522. dollaroldstyle: 0xF724,
  22523. dollarsmall: 0xFE69,
  22524. dollarsuperior: 0xF6E4,
  22525. dong: 0x20AB,
  22526. dorusquare: 0x3326,
  22527. dotaccent: 0x02D9,
  22528. dotaccentcmb: 0x0307,
  22529. dotbelowcmb: 0x0323,
  22530. dotbelowcomb: 0x0323,
  22531. dotkatakana: 0x30FB,
  22532. dotlessi: 0x0131,
  22533. dotlessj: 0xF6BE,
  22534. dotlessjstrokehook: 0x0284,
  22535. dotmath: 0x22C5,
  22536. dottedcircle: 0x25CC,
  22537. doubleyodpatah: 0xFB1F,
  22538. doubleyodpatahhebrew: 0xFB1F,
  22539. downtackbelowcmb: 0x031E,
  22540. downtackmod: 0x02D5,
  22541. dparen: 0x249F,
  22542. dsuperior: 0xF6EB,
  22543. dtail: 0x0256,
  22544. dtopbar: 0x018C,
  22545. duhiragana: 0x3065,
  22546. dukatakana: 0x30C5,
  22547. dz: 0x01F3,
  22548. dzaltone: 0x02A3,
  22549. dzcaron: 0x01C6,
  22550. dzcurl: 0x02A5,
  22551. dzeabkhasiancyrillic: 0x04E1,
  22552. dzecyrillic: 0x0455,
  22553. dzhecyrillic: 0x045F,
  22554. e: 0x0065,
  22555. eacute: 0x00E9,
  22556. earth: 0x2641,
  22557. ebengali: 0x098F,
  22558. ebopomofo: 0x311C,
  22559. ebreve: 0x0115,
  22560. ecandradeva: 0x090D,
  22561. ecandragujarati: 0x0A8D,
  22562. ecandravowelsigndeva: 0x0945,
  22563. ecandravowelsigngujarati: 0x0AC5,
  22564. ecaron: 0x011B,
  22565. ecedillabreve: 0x1E1D,
  22566. echarmenian: 0x0565,
  22567. echyiwnarmenian: 0x0587,
  22568. ecircle: 0x24D4,
  22569. ecircumflex: 0x00EA,
  22570. ecircumflexacute: 0x1EBF,
  22571. ecircumflexbelow: 0x1E19,
  22572. ecircumflexdotbelow: 0x1EC7,
  22573. ecircumflexgrave: 0x1EC1,
  22574. ecircumflexhookabove: 0x1EC3,
  22575. ecircumflextilde: 0x1EC5,
  22576. ecyrillic: 0x0454,
  22577. edblgrave: 0x0205,
  22578. edeva: 0x090F,
  22579. edieresis: 0x00EB,
  22580. edot: 0x0117,
  22581. edotaccent: 0x0117,
  22582. edotbelow: 0x1EB9,
  22583. eegurmukhi: 0x0A0F,
  22584. eematragurmukhi: 0x0A47,
  22585. efcyrillic: 0x0444,
  22586. egrave: 0x00E8,
  22587. egujarati: 0x0A8F,
  22588. eharmenian: 0x0567,
  22589. ehbopomofo: 0x311D,
  22590. ehiragana: 0x3048,
  22591. ehookabove: 0x1EBB,
  22592. eibopomofo: 0x311F,
  22593. eight: 0x0038,
  22594. eightarabic: 0x0668,
  22595. eightbengali: 0x09EE,
  22596. eightcircle: 0x2467,
  22597. eightcircleinversesansserif: 0x2791,
  22598. eightdeva: 0x096E,
  22599. eighteencircle: 0x2471,
  22600. eighteenparen: 0x2485,
  22601. eighteenperiod: 0x2499,
  22602. eightgujarati: 0x0AEE,
  22603. eightgurmukhi: 0x0A6E,
  22604. eighthackarabic: 0x0668,
  22605. eighthangzhou: 0x3028,
  22606. eighthnotebeamed: 0x266B,
  22607. eightideographicparen: 0x3227,
  22608. eightinferior: 0x2088,
  22609. eightmonospace: 0xFF18,
  22610. eightoldstyle: 0xF738,
  22611. eightparen: 0x247B,
  22612. eightperiod: 0x248F,
  22613. eightpersian: 0x06F8,
  22614. eightroman: 0x2177,
  22615. eightsuperior: 0x2078,
  22616. eightthai: 0x0E58,
  22617. einvertedbreve: 0x0207,
  22618. eiotifiedcyrillic: 0x0465,
  22619. ekatakana: 0x30A8,
  22620. ekatakanahalfwidth: 0xFF74,
  22621. ekonkargurmukhi: 0x0A74,
  22622. ekorean: 0x3154,
  22623. elcyrillic: 0x043B,
  22624. element: 0x2208,
  22625. elevencircle: 0x246A,
  22626. elevenparen: 0x247E,
  22627. elevenperiod: 0x2492,
  22628. elevenroman: 0x217A,
  22629. ellipsis: 0x2026,
  22630. ellipsisvertical: 0x22EE,
  22631. emacron: 0x0113,
  22632. emacronacute: 0x1E17,
  22633. emacrongrave: 0x1E15,
  22634. emcyrillic: 0x043C,
  22635. emdash: 0x2014,
  22636. emdashvertical: 0xFE31,
  22637. emonospace: 0xFF45,
  22638. emphasismarkarmenian: 0x055B,
  22639. emptyset: 0x2205,
  22640. enbopomofo: 0x3123,
  22641. encyrillic: 0x043D,
  22642. endash: 0x2013,
  22643. endashvertical: 0xFE32,
  22644. endescendercyrillic: 0x04A3,
  22645. eng: 0x014B,
  22646. engbopomofo: 0x3125,
  22647. enghecyrillic: 0x04A5,
  22648. enhookcyrillic: 0x04C8,
  22649. enspace: 0x2002,
  22650. eogonek: 0x0119,
  22651. eokorean: 0x3153,
  22652. eopen: 0x025B,
  22653. eopenclosed: 0x029A,
  22654. eopenreversed: 0x025C,
  22655. eopenreversedclosed: 0x025E,
  22656. eopenreversedhook: 0x025D,
  22657. eparen: 0x24A0,
  22658. epsilon: 0x03B5,
  22659. epsilontonos: 0x03AD,
  22660. equal: 0x003D,
  22661. equalmonospace: 0xFF1D,
  22662. equalsmall: 0xFE66,
  22663. equalsuperior: 0x207C,
  22664. equivalence: 0x2261,
  22665. erbopomofo: 0x3126,
  22666. ercyrillic: 0x0440,
  22667. ereversed: 0x0258,
  22668. ereversedcyrillic: 0x044D,
  22669. escyrillic: 0x0441,
  22670. esdescendercyrillic: 0x04AB,
  22671. esh: 0x0283,
  22672. eshcurl: 0x0286,
  22673. eshortdeva: 0x090E,
  22674. eshortvowelsigndeva: 0x0946,
  22675. eshreversedloop: 0x01AA,
  22676. eshsquatreversed: 0x0285,
  22677. esmallhiragana: 0x3047,
  22678. esmallkatakana: 0x30A7,
  22679. esmallkatakanahalfwidth: 0xFF6A,
  22680. estimated: 0x212E,
  22681. esuperior: 0xF6EC,
  22682. eta: 0x03B7,
  22683. etarmenian: 0x0568,
  22684. etatonos: 0x03AE,
  22685. eth: 0x00F0,
  22686. etilde: 0x1EBD,
  22687. etildebelow: 0x1E1B,
  22688. etnahtafoukhhebrew: 0x0591,
  22689. etnahtafoukhlefthebrew: 0x0591,
  22690. etnahtahebrew: 0x0591,
  22691. etnahtalefthebrew: 0x0591,
  22692. eturned: 0x01DD,
  22693. eukorean: 0x3161,
  22694. euro: 0x20AC,
  22695. evowelsignbengali: 0x09C7,
  22696. evowelsigndeva: 0x0947,
  22697. evowelsigngujarati: 0x0AC7,
  22698. exclam: 0x0021,
  22699. exclamarmenian: 0x055C,
  22700. exclamdbl: 0x203C,
  22701. exclamdown: 0x00A1,
  22702. exclamdownsmall: 0xF7A1,
  22703. exclammonospace: 0xFF01,
  22704. exclamsmall: 0xF721,
  22705. existential: 0x2203,
  22706. ezh: 0x0292,
  22707. ezhcaron: 0x01EF,
  22708. ezhcurl: 0x0293,
  22709. ezhreversed: 0x01B9,
  22710. ezhtail: 0x01BA,
  22711. f: 0x0066,
  22712. fadeva: 0x095E,
  22713. fagurmukhi: 0x0A5E,
  22714. fahrenheit: 0x2109,
  22715. fathaarabic: 0x064E,
  22716. fathalowarabic: 0x064E,
  22717. fathatanarabic: 0x064B,
  22718. fbopomofo: 0x3108,
  22719. fcircle: 0x24D5,
  22720. fdotaccent: 0x1E1F,
  22721. feharabic: 0x0641,
  22722. feharmenian: 0x0586,
  22723. fehfinalarabic: 0xFED2,
  22724. fehinitialarabic: 0xFED3,
  22725. fehmedialarabic: 0xFED4,
  22726. feicoptic: 0x03E5,
  22727. female: 0x2640,
  22728. ff: 0xFB00,
  22729. ffi: 0xFB03,
  22730. ffl: 0xFB04,
  22731. fi: 0xFB01,
  22732. fifteencircle: 0x246E,
  22733. fifteenparen: 0x2482,
  22734. fifteenperiod: 0x2496,
  22735. figuredash: 0x2012,
  22736. filledbox: 0x25A0,
  22737. filledrect: 0x25AC,
  22738. finalkaf: 0x05DA,
  22739. finalkafdagesh: 0xFB3A,
  22740. finalkafdageshhebrew: 0xFB3A,
  22741. finalkafhebrew: 0x05DA,
  22742. finalmem: 0x05DD,
  22743. finalmemhebrew: 0x05DD,
  22744. finalnun: 0x05DF,
  22745. finalnunhebrew: 0x05DF,
  22746. finalpe: 0x05E3,
  22747. finalpehebrew: 0x05E3,
  22748. finaltsadi: 0x05E5,
  22749. finaltsadihebrew: 0x05E5,
  22750. firsttonechinese: 0x02C9,
  22751. fisheye: 0x25C9,
  22752. fitacyrillic: 0x0473,
  22753. five: 0x0035,
  22754. fivearabic: 0x0665,
  22755. fivebengali: 0x09EB,
  22756. fivecircle: 0x2464,
  22757. fivecircleinversesansserif: 0x278E,
  22758. fivedeva: 0x096B,
  22759. fiveeighths: 0x215D,
  22760. fivegujarati: 0x0AEB,
  22761. fivegurmukhi: 0x0A6B,
  22762. fivehackarabic: 0x0665,
  22763. fivehangzhou: 0x3025,
  22764. fiveideographicparen: 0x3224,
  22765. fiveinferior: 0x2085,
  22766. fivemonospace: 0xFF15,
  22767. fiveoldstyle: 0xF735,
  22768. fiveparen: 0x2478,
  22769. fiveperiod: 0x248C,
  22770. fivepersian: 0x06F5,
  22771. fiveroman: 0x2174,
  22772. fivesuperior: 0x2075,
  22773. fivethai: 0x0E55,
  22774. fl: 0xFB02,
  22775. florin: 0x0192,
  22776. fmonospace: 0xFF46,
  22777. fmsquare: 0x3399,
  22778. fofanthai: 0x0E1F,
  22779. fofathai: 0x0E1D,
  22780. fongmanthai: 0x0E4F,
  22781. forall: 0x2200,
  22782. four: 0x0034,
  22783. fourarabic: 0x0664,
  22784. fourbengali: 0x09EA,
  22785. fourcircle: 0x2463,
  22786. fourcircleinversesansserif: 0x278D,
  22787. fourdeva: 0x096A,
  22788. fourgujarati: 0x0AEA,
  22789. fourgurmukhi: 0x0A6A,
  22790. fourhackarabic: 0x0664,
  22791. fourhangzhou: 0x3024,
  22792. fourideographicparen: 0x3223,
  22793. fourinferior: 0x2084,
  22794. fourmonospace: 0xFF14,
  22795. fournumeratorbengali: 0x09F7,
  22796. fouroldstyle: 0xF734,
  22797. fourparen: 0x2477,
  22798. fourperiod: 0x248B,
  22799. fourpersian: 0x06F4,
  22800. fourroman: 0x2173,
  22801. foursuperior: 0x2074,
  22802. fourteencircle: 0x246D,
  22803. fourteenparen: 0x2481,
  22804. fourteenperiod: 0x2495,
  22805. fourthai: 0x0E54,
  22806. fourthtonechinese: 0x02CB,
  22807. fparen: 0x24A1,
  22808. fraction: 0x2044,
  22809. franc: 0x20A3,
  22810. g: 0x0067,
  22811. gabengali: 0x0997,
  22812. gacute: 0x01F5,
  22813. gadeva: 0x0917,
  22814. gafarabic: 0x06AF,
  22815. gaffinalarabic: 0xFB93,
  22816. gafinitialarabic: 0xFB94,
  22817. gafmedialarabic: 0xFB95,
  22818. gagujarati: 0x0A97,
  22819. gagurmukhi: 0x0A17,
  22820. gahiragana: 0x304C,
  22821. gakatakana: 0x30AC,
  22822. gamma: 0x03B3,
  22823. gammalatinsmall: 0x0263,
  22824. gammasuperior: 0x02E0,
  22825. gangiacoptic: 0x03EB,
  22826. gbopomofo: 0x310D,
  22827. gbreve: 0x011F,
  22828. gcaron: 0x01E7,
  22829. gcedilla: 0x0123,
  22830. gcircle: 0x24D6,
  22831. gcircumflex: 0x011D,
  22832. gcommaaccent: 0x0123,
  22833. gdot: 0x0121,
  22834. gdotaccent: 0x0121,
  22835. gecyrillic: 0x0433,
  22836. gehiragana: 0x3052,
  22837. gekatakana: 0x30B2,
  22838. geometricallyequal: 0x2251,
  22839. gereshaccenthebrew: 0x059C,
  22840. gereshhebrew: 0x05F3,
  22841. gereshmuqdamhebrew: 0x059D,
  22842. germandbls: 0x00DF,
  22843. gershayimaccenthebrew: 0x059E,
  22844. gershayimhebrew: 0x05F4,
  22845. getamark: 0x3013,
  22846. ghabengali: 0x0998,
  22847. ghadarmenian: 0x0572,
  22848. ghadeva: 0x0918,
  22849. ghagujarati: 0x0A98,
  22850. ghagurmukhi: 0x0A18,
  22851. ghainarabic: 0x063A,
  22852. ghainfinalarabic: 0xFECE,
  22853. ghaininitialarabic: 0xFECF,
  22854. ghainmedialarabic: 0xFED0,
  22855. ghemiddlehookcyrillic: 0x0495,
  22856. ghestrokecyrillic: 0x0493,
  22857. gheupturncyrillic: 0x0491,
  22858. ghhadeva: 0x095A,
  22859. ghhagurmukhi: 0x0A5A,
  22860. ghook: 0x0260,
  22861. ghzsquare: 0x3393,
  22862. gihiragana: 0x304E,
  22863. gikatakana: 0x30AE,
  22864. gimarmenian: 0x0563,
  22865. gimel: 0x05D2,
  22866. gimeldagesh: 0xFB32,
  22867. gimeldageshhebrew: 0xFB32,
  22868. gimelhebrew: 0x05D2,
  22869. gjecyrillic: 0x0453,
  22870. glottalinvertedstroke: 0x01BE,
  22871. glottalstop: 0x0294,
  22872. glottalstopinverted: 0x0296,
  22873. glottalstopmod: 0x02C0,
  22874. glottalstopreversed: 0x0295,
  22875. glottalstopreversedmod: 0x02C1,
  22876. glottalstopreversedsuperior: 0x02E4,
  22877. glottalstopstroke: 0x02A1,
  22878. glottalstopstrokereversed: 0x02A2,
  22879. gmacron: 0x1E21,
  22880. gmonospace: 0xFF47,
  22881. gohiragana: 0x3054,
  22882. gokatakana: 0x30B4,
  22883. gparen: 0x24A2,
  22884. gpasquare: 0x33AC,
  22885. gradient: 0x2207,
  22886. grave: 0x0060,
  22887. gravebelowcmb: 0x0316,
  22888. gravecmb: 0x0300,
  22889. gravecomb: 0x0300,
  22890. gravedeva: 0x0953,
  22891. gravelowmod: 0x02CE,
  22892. gravemonospace: 0xFF40,
  22893. gravetonecmb: 0x0340,
  22894. greater: 0x003E,
  22895. greaterequal: 0x2265,
  22896. greaterequalorless: 0x22DB,
  22897. greatermonospace: 0xFF1E,
  22898. greaterorequivalent: 0x2273,
  22899. greaterorless: 0x2277,
  22900. greateroverequal: 0x2267,
  22901. greatersmall: 0xFE65,
  22902. gscript: 0x0261,
  22903. gstroke: 0x01E5,
  22904. guhiragana: 0x3050,
  22905. guillemotleft: 0x00AB,
  22906. guillemotright: 0x00BB,
  22907. guilsinglleft: 0x2039,
  22908. guilsinglright: 0x203A,
  22909. gukatakana: 0x30B0,
  22910. guramusquare: 0x3318,
  22911. gysquare: 0x33C9,
  22912. h: 0x0068,
  22913. haabkhasiancyrillic: 0x04A9,
  22914. haaltonearabic: 0x06C1,
  22915. habengali: 0x09B9,
  22916. hadescendercyrillic: 0x04B3,
  22917. hadeva: 0x0939,
  22918. hagujarati: 0x0AB9,
  22919. hagurmukhi: 0x0A39,
  22920. haharabic: 0x062D,
  22921. hahfinalarabic: 0xFEA2,
  22922. hahinitialarabic: 0xFEA3,
  22923. hahiragana: 0x306F,
  22924. hahmedialarabic: 0xFEA4,
  22925. haitusquare: 0x332A,
  22926. hakatakana: 0x30CF,
  22927. hakatakanahalfwidth: 0xFF8A,
  22928. halantgurmukhi: 0x0A4D,
  22929. hamzaarabic: 0x0621,
  22930. hamzalowarabic: 0x0621,
  22931. hangulfiller: 0x3164,
  22932. hardsigncyrillic: 0x044A,
  22933. harpoonleftbarbup: 0x21BC,
  22934. harpoonrightbarbup: 0x21C0,
  22935. hasquare: 0x33CA,
  22936. hatafpatah: 0x05B2,
  22937. hatafpatah16: 0x05B2,
  22938. hatafpatah23: 0x05B2,
  22939. hatafpatah2f: 0x05B2,
  22940. hatafpatahhebrew: 0x05B2,
  22941. hatafpatahnarrowhebrew: 0x05B2,
  22942. hatafpatahquarterhebrew: 0x05B2,
  22943. hatafpatahwidehebrew: 0x05B2,
  22944. hatafqamats: 0x05B3,
  22945. hatafqamats1b: 0x05B3,
  22946. hatafqamats28: 0x05B3,
  22947. hatafqamats34: 0x05B3,
  22948. hatafqamatshebrew: 0x05B3,
  22949. hatafqamatsnarrowhebrew: 0x05B3,
  22950. hatafqamatsquarterhebrew: 0x05B3,
  22951. hatafqamatswidehebrew: 0x05B3,
  22952. hatafsegol: 0x05B1,
  22953. hatafsegol17: 0x05B1,
  22954. hatafsegol24: 0x05B1,
  22955. hatafsegol30: 0x05B1,
  22956. hatafsegolhebrew: 0x05B1,
  22957. hatafsegolnarrowhebrew: 0x05B1,
  22958. hatafsegolquarterhebrew: 0x05B1,
  22959. hatafsegolwidehebrew: 0x05B1,
  22960. hbar: 0x0127,
  22961. hbopomofo: 0x310F,
  22962. hbrevebelow: 0x1E2B,
  22963. hcedilla: 0x1E29,
  22964. hcircle: 0x24D7,
  22965. hcircumflex: 0x0125,
  22966. hdieresis: 0x1E27,
  22967. hdotaccent: 0x1E23,
  22968. hdotbelow: 0x1E25,
  22969. he: 0x05D4,
  22970. heart: 0x2665,
  22971. heartsuitblack: 0x2665,
  22972. heartsuitwhite: 0x2661,
  22973. hedagesh: 0xFB34,
  22974. hedageshhebrew: 0xFB34,
  22975. hehaltonearabic: 0x06C1,
  22976. heharabic: 0x0647,
  22977. hehebrew: 0x05D4,
  22978. hehfinalaltonearabic: 0xFBA7,
  22979. hehfinalalttwoarabic: 0xFEEA,
  22980. hehfinalarabic: 0xFEEA,
  22981. hehhamzaabovefinalarabic: 0xFBA5,
  22982. hehhamzaaboveisolatedarabic: 0xFBA4,
  22983. hehinitialaltonearabic: 0xFBA8,
  22984. hehinitialarabic: 0xFEEB,
  22985. hehiragana: 0x3078,
  22986. hehmedialaltonearabic: 0xFBA9,
  22987. hehmedialarabic: 0xFEEC,
  22988. heiseierasquare: 0x337B,
  22989. hekatakana: 0x30D8,
  22990. hekatakanahalfwidth: 0xFF8D,
  22991. hekutaarusquare: 0x3336,
  22992. henghook: 0x0267,
  22993. herutusquare: 0x3339,
  22994. het: 0x05D7,
  22995. hethebrew: 0x05D7,
  22996. hhook: 0x0266,
  22997. hhooksuperior: 0x02B1,
  22998. hieuhacirclekorean: 0x327B,
  22999. hieuhaparenkorean: 0x321B,
  23000. hieuhcirclekorean: 0x326D,
  23001. hieuhkorean: 0x314E,
  23002. hieuhparenkorean: 0x320D,
  23003. hihiragana: 0x3072,
  23004. hikatakana: 0x30D2,
  23005. hikatakanahalfwidth: 0xFF8B,
  23006. hiriq: 0x05B4,
  23007. hiriq14: 0x05B4,
  23008. hiriq21: 0x05B4,
  23009. hiriq2d: 0x05B4,
  23010. hiriqhebrew: 0x05B4,
  23011. hiriqnarrowhebrew: 0x05B4,
  23012. hiriqquarterhebrew: 0x05B4,
  23013. hiriqwidehebrew: 0x05B4,
  23014. hlinebelow: 0x1E96,
  23015. hmonospace: 0xFF48,
  23016. hoarmenian: 0x0570,
  23017. hohipthai: 0x0E2B,
  23018. hohiragana: 0x307B,
  23019. hokatakana: 0x30DB,
  23020. hokatakanahalfwidth: 0xFF8E,
  23021. holam: 0x05B9,
  23022. holam19: 0x05B9,
  23023. holam26: 0x05B9,
  23024. holam32: 0x05B9,
  23025. holamhebrew: 0x05B9,
  23026. holamnarrowhebrew: 0x05B9,
  23027. holamquarterhebrew: 0x05B9,
  23028. holamwidehebrew: 0x05B9,
  23029. honokhukthai: 0x0E2E,
  23030. hookabovecomb: 0x0309,
  23031. hookcmb: 0x0309,
  23032. hookpalatalizedbelowcmb: 0x0321,
  23033. hookretroflexbelowcmb: 0x0322,
  23034. hoonsquare: 0x3342,
  23035. horicoptic: 0x03E9,
  23036. horizontalbar: 0x2015,
  23037. horncmb: 0x031B,
  23038. hotsprings: 0x2668,
  23039. house: 0x2302,
  23040. hparen: 0x24A3,
  23041. hsuperior: 0x02B0,
  23042. hturned: 0x0265,
  23043. huhiragana: 0x3075,
  23044. huiitosquare: 0x3333,
  23045. hukatakana: 0x30D5,
  23046. hukatakanahalfwidth: 0xFF8C,
  23047. hungarumlaut: 0x02DD,
  23048. hungarumlautcmb: 0x030B,
  23049. hv: 0x0195,
  23050. hyphen: 0x002D,
  23051. hypheninferior: 0xF6E5,
  23052. hyphenmonospace: 0xFF0D,
  23053. hyphensmall: 0xFE63,
  23054. hyphensuperior: 0xF6E6,
  23055. hyphentwo: 0x2010,
  23056. i: 0x0069,
  23057. iacute: 0x00ED,
  23058. iacyrillic: 0x044F,
  23059. ibengali: 0x0987,
  23060. ibopomofo: 0x3127,
  23061. ibreve: 0x012D,
  23062. icaron: 0x01D0,
  23063. icircle: 0x24D8,
  23064. icircumflex: 0x00EE,
  23065. icyrillic: 0x0456,
  23066. idblgrave: 0x0209,
  23067. ideographearthcircle: 0x328F,
  23068. ideographfirecircle: 0x328B,
  23069. ideographicallianceparen: 0x323F,
  23070. ideographiccallparen: 0x323A,
  23071. ideographiccentrecircle: 0x32A5,
  23072. ideographicclose: 0x3006,
  23073. ideographiccomma: 0x3001,
  23074. ideographiccommaleft: 0xFF64,
  23075. ideographiccongratulationparen: 0x3237,
  23076. ideographiccorrectcircle: 0x32A3,
  23077. ideographicearthparen: 0x322F,
  23078. ideographicenterpriseparen: 0x323D,
  23079. ideographicexcellentcircle: 0x329D,
  23080. ideographicfestivalparen: 0x3240,
  23081. ideographicfinancialcircle: 0x3296,
  23082. ideographicfinancialparen: 0x3236,
  23083. ideographicfireparen: 0x322B,
  23084. ideographichaveparen: 0x3232,
  23085. ideographichighcircle: 0x32A4,
  23086. ideographiciterationmark: 0x3005,
  23087. ideographiclaborcircle: 0x3298,
  23088. ideographiclaborparen: 0x3238,
  23089. ideographicleftcircle: 0x32A7,
  23090. ideographiclowcircle: 0x32A6,
  23091. ideographicmedicinecircle: 0x32A9,
  23092. ideographicmetalparen: 0x322E,
  23093. ideographicmoonparen: 0x322A,
  23094. ideographicnameparen: 0x3234,
  23095. ideographicperiod: 0x3002,
  23096. ideographicprintcircle: 0x329E,
  23097. ideographicreachparen: 0x3243,
  23098. ideographicrepresentparen: 0x3239,
  23099. ideographicresourceparen: 0x323E,
  23100. ideographicrightcircle: 0x32A8,
  23101. ideographicsecretcircle: 0x3299,
  23102. ideographicselfparen: 0x3242,
  23103. ideographicsocietyparen: 0x3233,
  23104. ideographicspace: 0x3000,
  23105. ideographicspecialparen: 0x3235,
  23106. ideographicstockparen: 0x3231,
  23107. ideographicstudyparen: 0x323B,
  23108. ideographicsunparen: 0x3230,
  23109. ideographicsuperviseparen: 0x323C,
  23110. ideographicwaterparen: 0x322C,
  23111. ideographicwoodparen: 0x322D,
  23112. ideographiczero: 0x3007,
  23113. ideographmetalcircle: 0x328E,
  23114. ideographmooncircle: 0x328A,
  23115. ideographnamecircle: 0x3294,
  23116. ideographsuncircle: 0x3290,
  23117. ideographwatercircle: 0x328C,
  23118. ideographwoodcircle: 0x328D,
  23119. ideva: 0x0907,
  23120. idieresis: 0x00EF,
  23121. idieresisacute: 0x1E2F,
  23122. idieresiscyrillic: 0x04E5,
  23123. idotbelow: 0x1ECB,
  23124. iebrevecyrillic: 0x04D7,
  23125. iecyrillic: 0x0435,
  23126. ieungacirclekorean: 0x3275,
  23127. ieungaparenkorean: 0x3215,
  23128. ieungcirclekorean: 0x3267,
  23129. ieungkorean: 0x3147,
  23130. ieungparenkorean: 0x3207,
  23131. igrave: 0x00EC,
  23132. igujarati: 0x0A87,
  23133. igurmukhi: 0x0A07,
  23134. ihiragana: 0x3044,
  23135. ihookabove: 0x1EC9,
  23136. iibengali: 0x0988,
  23137. iicyrillic: 0x0438,
  23138. iideva: 0x0908,
  23139. iigujarati: 0x0A88,
  23140. iigurmukhi: 0x0A08,
  23141. iimatragurmukhi: 0x0A40,
  23142. iinvertedbreve: 0x020B,
  23143. iishortcyrillic: 0x0439,
  23144. iivowelsignbengali: 0x09C0,
  23145. iivowelsigndeva: 0x0940,
  23146. iivowelsigngujarati: 0x0AC0,
  23147. ij: 0x0133,
  23148. ikatakana: 0x30A4,
  23149. ikatakanahalfwidth: 0xFF72,
  23150. ikorean: 0x3163,
  23151. ilde: 0x02DC,
  23152. iluyhebrew: 0x05AC,
  23153. imacron: 0x012B,
  23154. imacroncyrillic: 0x04E3,
  23155. imageorapproximatelyequal: 0x2253,
  23156. imatragurmukhi: 0x0A3F,
  23157. imonospace: 0xFF49,
  23158. increment: 0x2206,
  23159. infinity: 0x221E,
  23160. iniarmenian: 0x056B,
  23161. integral: 0x222B,
  23162. integralbottom: 0x2321,
  23163. integralbt: 0x2321,
  23164. integralex: 0xF8F5,
  23165. integraltop: 0x2320,
  23166. integraltp: 0x2320,
  23167. intersection: 0x2229,
  23168. intisquare: 0x3305,
  23169. invbullet: 0x25D8,
  23170. invcircle: 0x25D9,
  23171. invsmileface: 0x263B,
  23172. iocyrillic: 0x0451,
  23173. iogonek: 0x012F,
  23174. iota: 0x03B9,
  23175. iotadieresis: 0x03CA,
  23176. iotadieresistonos: 0x0390,
  23177. iotalatin: 0x0269,
  23178. iotatonos: 0x03AF,
  23179. iparen: 0x24A4,
  23180. irigurmukhi: 0x0A72,
  23181. ismallhiragana: 0x3043,
  23182. ismallkatakana: 0x30A3,
  23183. ismallkatakanahalfwidth: 0xFF68,
  23184. issharbengali: 0x09FA,
  23185. istroke: 0x0268,
  23186. isuperior: 0xF6ED,
  23187. iterationhiragana: 0x309D,
  23188. iterationkatakana: 0x30FD,
  23189. itilde: 0x0129,
  23190. itildebelow: 0x1E2D,
  23191. iubopomofo: 0x3129,
  23192. iucyrillic: 0x044E,
  23193. ivowelsignbengali: 0x09BF,
  23194. ivowelsigndeva: 0x093F,
  23195. ivowelsigngujarati: 0x0ABF,
  23196. izhitsacyrillic: 0x0475,
  23197. izhitsadblgravecyrillic: 0x0477,
  23198. j: 0x006A,
  23199. jaarmenian: 0x0571,
  23200. jabengali: 0x099C,
  23201. jadeva: 0x091C,
  23202. jagujarati: 0x0A9C,
  23203. jagurmukhi: 0x0A1C,
  23204. jbopomofo: 0x3110,
  23205. jcaron: 0x01F0,
  23206. jcircle: 0x24D9,
  23207. jcircumflex: 0x0135,
  23208. jcrossedtail: 0x029D,
  23209. jdotlessstroke: 0x025F,
  23210. jecyrillic: 0x0458,
  23211. jeemarabic: 0x062C,
  23212. jeemfinalarabic: 0xFE9E,
  23213. jeeminitialarabic: 0xFE9F,
  23214. jeemmedialarabic: 0xFEA0,
  23215. jeharabic: 0x0698,
  23216. jehfinalarabic: 0xFB8B,
  23217. jhabengali: 0x099D,
  23218. jhadeva: 0x091D,
  23219. jhagujarati: 0x0A9D,
  23220. jhagurmukhi: 0x0A1D,
  23221. jheharmenian: 0x057B,
  23222. jis: 0x3004,
  23223. jmonospace: 0xFF4A,
  23224. jparen: 0x24A5,
  23225. jsuperior: 0x02B2,
  23226. k: 0x006B,
  23227. kabashkircyrillic: 0x04A1,
  23228. kabengali: 0x0995,
  23229. kacute: 0x1E31,
  23230. kacyrillic: 0x043A,
  23231. kadescendercyrillic: 0x049B,
  23232. kadeva: 0x0915,
  23233. kaf: 0x05DB,
  23234. kafarabic: 0x0643,
  23235. kafdagesh: 0xFB3B,
  23236. kafdageshhebrew: 0xFB3B,
  23237. kaffinalarabic: 0xFEDA,
  23238. kafhebrew: 0x05DB,
  23239. kafinitialarabic: 0xFEDB,
  23240. kafmedialarabic: 0xFEDC,
  23241. kafrafehebrew: 0xFB4D,
  23242. kagujarati: 0x0A95,
  23243. kagurmukhi: 0x0A15,
  23244. kahiragana: 0x304B,
  23245. kahookcyrillic: 0x04C4,
  23246. kakatakana: 0x30AB,
  23247. kakatakanahalfwidth: 0xFF76,
  23248. kappa: 0x03BA,
  23249. kappasymbolgreek: 0x03F0,
  23250. kapyeounmieumkorean: 0x3171,
  23251. kapyeounphieuphkorean: 0x3184,
  23252. kapyeounpieupkorean: 0x3178,
  23253. kapyeounssangpieupkorean: 0x3179,
  23254. karoriisquare: 0x330D,
  23255. kashidaautoarabic: 0x0640,
  23256. kashidaautonosidebearingarabic: 0x0640,
  23257. kasmallkatakana: 0x30F5,
  23258. kasquare: 0x3384,
  23259. kasraarabic: 0x0650,
  23260. kasratanarabic: 0x064D,
  23261. kastrokecyrillic: 0x049F,
  23262. katahiraprolongmarkhalfwidth: 0xFF70,
  23263. kaverticalstrokecyrillic: 0x049D,
  23264. kbopomofo: 0x310E,
  23265. kcalsquare: 0x3389,
  23266. kcaron: 0x01E9,
  23267. kcedilla: 0x0137,
  23268. kcircle: 0x24DA,
  23269. kcommaaccent: 0x0137,
  23270. kdotbelow: 0x1E33,
  23271. keharmenian: 0x0584,
  23272. kehiragana: 0x3051,
  23273. kekatakana: 0x30B1,
  23274. kekatakanahalfwidth: 0xFF79,
  23275. kenarmenian: 0x056F,
  23276. kesmallkatakana: 0x30F6,
  23277. kgreenlandic: 0x0138,
  23278. khabengali: 0x0996,
  23279. khacyrillic: 0x0445,
  23280. khadeva: 0x0916,
  23281. khagujarati: 0x0A96,
  23282. khagurmukhi: 0x0A16,
  23283. khaharabic: 0x062E,
  23284. khahfinalarabic: 0xFEA6,
  23285. khahinitialarabic: 0xFEA7,
  23286. khahmedialarabic: 0xFEA8,
  23287. kheicoptic: 0x03E7,
  23288. khhadeva: 0x0959,
  23289. khhagurmukhi: 0x0A59,
  23290. khieukhacirclekorean: 0x3278,
  23291. khieukhaparenkorean: 0x3218,
  23292. khieukhcirclekorean: 0x326A,
  23293. khieukhkorean: 0x314B,
  23294. khieukhparenkorean: 0x320A,
  23295. khokhaithai: 0x0E02,
  23296. khokhonthai: 0x0E05,
  23297. khokhuatthai: 0x0E03,
  23298. khokhwaithai: 0x0E04,
  23299. khomutthai: 0x0E5B,
  23300. khook: 0x0199,
  23301. khorakhangthai: 0x0E06,
  23302. khzsquare: 0x3391,
  23303. kihiragana: 0x304D,
  23304. kikatakana: 0x30AD,
  23305. kikatakanahalfwidth: 0xFF77,
  23306. kiroguramusquare: 0x3315,
  23307. kiromeetorusquare: 0x3316,
  23308. kirosquare: 0x3314,
  23309. kiyeokacirclekorean: 0x326E,
  23310. kiyeokaparenkorean: 0x320E,
  23311. kiyeokcirclekorean: 0x3260,
  23312. kiyeokkorean: 0x3131,
  23313. kiyeokparenkorean: 0x3200,
  23314. kiyeoksioskorean: 0x3133,
  23315. kjecyrillic: 0x045C,
  23316. klinebelow: 0x1E35,
  23317. klsquare: 0x3398,
  23318. kmcubedsquare: 0x33A6,
  23319. kmonospace: 0xFF4B,
  23320. kmsquaredsquare: 0x33A2,
  23321. kohiragana: 0x3053,
  23322. kohmsquare: 0x33C0,
  23323. kokaithai: 0x0E01,
  23324. kokatakana: 0x30B3,
  23325. kokatakanahalfwidth: 0xFF7A,
  23326. kooposquare: 0x331E,
  23327. koppacyrillic: 0x0481,
  23328. koreanstandardsymbol: 0x327F,
  23329. koroniscmb: 0x0343,
  23330. kparen: 0x24A6,
  23331. kpasquare: 0x33AA,
  23332. ksicyrillic: 0x046F,
  23333. ktsquare: 0x33CF,
  23334. kturned: 0x029E,
  23335. kuhiragana: 0x304F,
  23336. kukatakana: 0x30AF,
  23337. kukatakanahalfwidth: 0xFF78,
  23338. kvsquare: 0x33B8,
  23339. kwsquare: 0x33BE,
  23340. l: 0x006C,
  23341. labengali: 0x09B2,
  23342. lacute: 0x013A,
  23343. ladeva: 0x0932,
  23344. lagujarati: 0x0AB2,
  23345. lagurmukhi: 0x0A32,
  23346. lakkhangyaothai: 0x0E45,
  23347. lamaleffinalarabic: 0xFEFC,
  23348. lamalefhamzaabovefinalarabic: 0xFEF8,
  23349. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  23350. lamalefhamzabelowfinalarabic: 0xFEFA,
  23351. lamalefhamzabelowisolatedarabic: 0xFEF9,
  23352. lamalefisolatedarabic: 0xFEFB,
  23353. lamalefmaddaabovefinalarabic: 0xFEF6,
  23354. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  23355. lamarabic: 0x0644,
  23356. lambda: 0x03BB,
  23357. lambdastroke: 0x019B,
  23358. lamed: 0x05DC,
  23359. lameddagesh: 0xFB3C,
  23360. lameddageshhebrew: 0xFB3C,
  23361. lamedhebrew: 0x05DC,
  23362. lamfinalarabic: 0xFEDE,
  23363. lamhahinitialarabic: 0xFCCA,
  23364. laminitialarabic: 0xFEDF,
  23365. lamjeeminitialarabic: 0xFCC9,
  23366. lamkhahinitialarabic: 0xFCCB,
  23367. lamlamhehisolatedarabic: 0xFDF2,
  23368. lammedialarabic: 0xFEE0,
  23369. lammeemhahinitialarabic: 0xFD88,
  23370. lammeeminitialarabic: 0xFCCC,
  23371. largecircle: 0x25EF,
  23372. lbar: 0x019A,
  23373. lbelt: 0x026C,
  23374. lbopomofo: 0x310C,
  23375. lcaron: 0x013E,
  23376. lcedilla: 0x013C,
  23377. lcircle: 0x24DB,
  23378. lcircumflexbelow: 0x1E3D,
  23379. lcommaaccent: 0x013C,
  23380. ldot: 0x0140,
  23381. ldotaccent: 0x0140,
  23382. ldotbelow: 0x1E37,
  23383. ldotbelowmacron: 0x1E39,
  23384. leftangleabovecmb: 0x031A,
  23385. lefttackbelowcmb: 0x0318,
  23386. less: 0x003C,
  23387. lessequal: 0x2264,
  23388. lessequalorgreater: 0x22DA,
  23389. lessmonospace: 0xFF1C,
  23390. lessorequivalent: 0x2272,
  23391. lessorgreater: 0x2276,
  23392. lessoverequal: 0x2266,
  23393. lesssmall: 0xFE64,
  23394. lezh: 0x026E,
  23395. lfblock: 0x258C,
  23396. lhookretroflex: 0x026D,
  23397. lira: 0x20A4,
  23398. liwnarmenian: 0x056C,
  23399. lj: 0x01C9,
  23400. ljecyrillic: 0x0459,
  23401. ll: 0xF6C0,
  23402. lladeva: 0x0933,
  23403. llagujarati: 0x0AB3,
  23404. llinebelow: 0x1E3B,
  23405. llladeva: 0x0934,
  23406. llvocalicbengali: 0x09E1,
  23407. llvocalicdeva: 0x0961,
  23408. llvocalicvowelsignbengali: 0x09E3,
  23409. llvocalicvowelsigndeva: 0x0963,
  23410. lmiddletilde: 0x026B,
  23411. lmonospace: 0xFF4C,
  23412. lmsquare: 0x33D0,
  23413. lochulathai: 0x0E2C,
  23414. logicaland: 0x2227,
  23415. logicalnot: 0x00AC,
  23416. logicalnotreversed: 0x2310,
  23417. logicalor: 0x2228,
  23418. lolingthai: 0x0E25,
  23419. longs: 0x017F,
  23420. lowlinecenterline: 0xFE4E,
  23421. lowlinecmb: 0x0332,
  23422. lowlinedashed: 0xFE4D,
  23423. lozenge: 0x25CA,
  23424. lparen: 0x24A7,
  23425. lslash: 0x0142,
  23426. lsquare: 0x2113,
  23427. lsuperior: 0xF6EE,
  23428. ltshade: 0x2591,
  23429. luthai: 0x0E26,
  23430. lvocalicbengali: 0x098C,
  23431. lvocalicdeva: 0x090C,
  23432. lvocalicvowelsignbengali: 0x09E2,
  23433. lvocalicvowelsigndeva: 0x0962,
  23434. lxsquare: 0x33D3,
  23435. m: 0x006D,
  23436. mabengali: 0x09AE,
  23437. macron: 0x00AF,
  23438. macronbelowcmb: 0x0331,
  23439. macroncmb: 0x0304,
  23440. macronlowmod: 0x02CD,
  23441. macronmonospace: 0xFFE3,
  23442. macute: 0x1E3F,
  23443. madeva: 0x092E,
  23444. magujarati: 0x0AAE,
  23445. magurmukhi: 0x0A2E,
  23446. mahapakhhebrew: 0x05A4,
  23447. mahapakhlefthebrew: 0x05A4,
  23448. mahiragana: 0x307E,
  23449. maichattawalowleftthai: 0xF895,
  23450. maichattawalowrightthai: 0xF894,
  23451. maichattawathai: 0x0E4B,
  23452. maichattawaupperleftthai: 0xF893,
  23453. maieklowleftthai: 0xF88C,
  23454. maieklowrightthai: 0xF88B,
  23455. maiekthai: 0x0E48,
  23456. maiekupperleftthai: 0xF88A,
  23457. maihanakatleftthai: 0xF884,
  23458. maihanakatthai: 0x0E31,
  23459. maitaikhuleftthai: 0xF889,
  23460. maitaikhuthai: 0x0E47,
  23461. maitholowleftthai: 0xF88F,
  23462. maitholowrightthai: 0xF88E,
  23463. maithothai: 0x0E49,
  23464. maithoupperleftthai: 0xF88D,
  23465. maitrilowleftthai: 0xF892,
  23466. maitrilowrightthai: 0xF891,
  23467. maitrithai: 0x0E4A,
  23468. maitriupperleftthai: 0xF890,
  23469. maiyamokthai: 0x0E46,
  23470. makatakana: 0x30DE,
  23471. makatakanahalfwidth: 0xFF8F,
  23472. male: 0x2642,
  23473. mansyonsquare: 0x3347,
  23474. maqafhebrew: 0x05BE,
  23475. mars: 0x2642,
  23476. masoracirclehebrew: 0x05AF,
  23477. masquare: 0x3383,
  23478. mbopomofo: 0x3107,
  23479. mbsquare: 0x33D4,
  23480. mcircle: 0x24DC,
  23481. mcubedsquare: 0x33A5,
  23482. mdotaccent: 0x1E41,
  23483. mdotbelow: 0x1E43,
  23484. meemarabic: 0x0645,
  23485. meemfinalarabic: 0xFEE2,
  23486. meeminitialarabic: 0xFEE3,
  23487. meemmedialarabic: 0xFEE4,
  23488. meemmeeminitialarabic: 0xFCD1,
  23489. meemmeemisolatedarabic: 0xFC48,
  23490. meetorusquare: 0x334D,
  23491. mehiragana: 0x3081,
  23492. meizierasquare: 0x337E,
  23493. mekatakana: 0x30E1,
  23494. mekatakanahalfwidth: 0xFF92,
  23495. mem: 0x05DE,
  23496. memdagesh: 0xFB3E,
  23497. memdageshhebrew: 0xFB3E,
  23498. memhebrew: 0x05DE,
  23499. menarmenian: 0x0574,
  23500. merkhahebrew: 0x05A5,
  23501. merkhakefulahebrew: 0x05A6,
  23502. merkhakefulalefthebrew: 0x05A6,
  23503. merkhalefthebrew: 0x05A5,
  23504. mhook: 0x0271,
  23505. mhzsquare: 0x3392,
  23506. middledotkatakanahalfwidth: 0xFF65,
  23507. middot: 0x00B7,
  23508. mieumacirclekorean: 0x3272,
  23509. mieumaparenkorean: 0x3212,
  23510. mieumcirclekorean: 0x3264,
  23511. mieumkorean: 0x3141,
  23512. mieumpansioskorean: 0x3170,
  23513. mieumparenkorean: 0x3204,
  23514. mieumpieupkorean: 0x316E,
  23515. mieumsioskorean: 0x316F,
  23516. mihiragana: 0x307F,
  23517. mikatakana: 0x30DF,
  23518. mikatakanahalfwidth: 0xFF90,
  23519. minus: 0x2212,
  23520. minusbelowcmb: 0x0320,
  23521. minuscircle: 0x2296,
  23522. minusmod: 0x02D7,
  23523. minusplus: 0x2213,
  23524. minute: 0x2032,
  23525. miribaarusquare: 0x334A,
  23526. mirisquare: 0x3349,
  23527. mlonglegturned: 0x0270,
  23528. mlsquare: 0x3396,
  23529. mmcubedsquare: 0x33A3,
  23530. mmonospace: 0xFF4D,
  23531. mmsquaredsquare: 0x339F,
  23532. mohiragana: 0x3082,
  23533. mohmsquare: 0x33C1,
  23534. mokatakana: 0x30E2,
  23535. mokatakanahalfwidth: 0xFF93,
  23536. molsquare: 0x33D6,
  23537. momathai: 0x0E21,
  23538. moverssquare: 0x33A7,
  23539. moverssquaredsquare: 0x33A8,
  23540. mparen: 0x24A8,
  23541. mpasquare: 0x33AB,
  23542. mssquare: 0x33B3,
  23543. msuperior: 0xF6EF,
  23544. mturned: 0x026F,
  23545. mu: 0x00B5,
  23546. mu1: 0x00B5,
  23547. muasquare: 0x3382,
  23548. muchgreater: 0x226B,
  23549. muchless: 0x226A,
  23550. mufsquare: 0x338C,
  23551. mugreek: 0x03BC,
  23552. mugsquare: 0x338D,
  23553. muhiragana: 0x3080,
  23554. mukatakana: 0x30E0,
  23555. mukatakanahalfwidth: 0xFF91,
  23556. mulsquare: 0x3395,
  23557. multiply: 0x00D7,
  23558. mumsquare: 0x339B,
  23559. munahhebrew: 0x05A3,
  23560. munahlefthebrew: 0x05A3,
  23561. musicalnote: 0x266A,
  23562. musicalnotedbl: 0x266B,
  23563. musicflatsign: 0x266D,
  23564. musicsharpsign: 0x266F,
  23565. mussquare: 0x33B2,
  23566. muvsquare: 0x33B6,
  23567. muwsquare: 0x33BC,
  23568. mvmegasquare: 0x33B9,
  23569. mvsquare: 0x33B7,
  23570. mwmegasquare: 0x33BF,
  23571. mwsquare: 0x33BD,
  23572. n: 0x006E,
  23573. nabengali: 0x09A8,
  23574. nabla: 0x2207,
  23575. nacute: 0x0144,
  23576. nadeva: 0x0928,
  23577. nagujarati: 0x0AA8,
  23578. nagurmukhi: 0x0A28,
  23579. nahiragana: 0x306A,
  23580. nakatakana: 0x30CA,
  23581. nakatakanahalfwidth: 0xFF85,
  23582. napostrophe: 0x0149,
  23583. nasquare: 0x3381,
  23584. nbopomofo: 0x310B,
  23585. nbspace: 0x00A0,
  23586. ncaron: 0x0148,
  23587. ncedilla: 0x0146,
  23588. ncircle: 0x24DD,
  23589. ncircumflexbelow: 0x1E4B,
  23590. ncommaaccent: 0x0146,
  23591. ndotaccent: 0x1E45,
  23592. ndotbelow: 0x1E47,
  23593. nehiragana: 0x306D,
  23594. nekatakana: 0x30CD,
  23595. nekatakanahalfwidth: 0xFF88,
  23596. newsheqelsign: 0x20AA,
  23597. nfsquare: 0x338B,
  23598. ngabengali: 0x0999,
  23599. ngadeva: 0x0919,
  23600. ngagujarati: 0x0A99,
  23601. ngagurmukhi: 0x0A19,
  23602. ngonguthai: 0x0E07,
  23603. nhiragana: 0x3093,
  23604. nhookleft: 0x0272,
  23605. nhookretroflex: 0x0273,
  23606. nieunacirclekorean: 0x326F,
  23607. nieunaparenkorean: 0x320F,
  23608. nieuncieuckorean: 0x3135,
  23609. nieuncirclekorean: 0x3261,
  23610. nieunhieuhkorean: 0x3136,
  23611. nieunkorean: 0x3134,
  23612. nieunpansioskorean: 0x3168,
  23613. nieunparenkorean: 0x3201,
  23614. nieunsioskorean: 0x3167,
  23615. nieuntikeutkorean: 0x3166,
  23616. nihiragana: 0x306B,
  23617. nikatakana: 0x30CB,
  23618. nikatakanahalfwidth: 0xFF86,
  23619. nikhahitleftthai: 0xF899,
  23620. nikhahitthai: 0x0E4D,
  23621. nine: 0x0039,
  23622. ninearabic: 0x0669,
  23623. ninebengali: 0x09EF,
  23624. ninecircle: 0x2468,
  23625. ninecircleinversesansserif: 0x2792,
  23626. ninedeva: 0x096F,
  23627. ninegujarati: 0x0AEF,
  23628. ninegurmukhi: 0x0A6F,
  23629. ninehackarabic: 0x0669,
  23630. ninehangzhou: 0x3029,
  23631. nineideographicparen: 0x3228,
  23632. nineinferior: 0x2089,
  23633. ninemonospace: 0xFF19,
  23634. nineoldstyle: 0xF739,
  23635. nineparen: 0x247C,
  23636. nineperiod: 0x2490,
  23637. ninepersian: 0x06F9,
  23638. nineroman: 0x2178,
  23639. ninesuperior: 0x2079,
  23640. nineteencircle: 0x2472,
  23641. nineteenparen: 0x2486,
  23642. nineteenperiod: 0x249A,
  23643. ninethai: 0x0E59,
  23644. nj: 0x01CC,
  23645. njecyrillic: 0x045A,
  23646. nkatakana: 0x30F3,
  23647. nkatakanahalfwidth: 0xFF9D,
  23648. nlegrightlong: 0x019E,
  23649. nlinebelow: 0x1E49,
  23650. nmonospace: 0xFF4E,
  23651. nmsquare: 0x339A,
  23652. nnabengali: 0x09A3,
  23653. nnadeva: 0x0923,
  23654. nnagujarati: 0x0AA3,
  23655. nnagurmukhi: 0x0A23,
  23656. nnnadeva: 0x0929,
  23657. nohiragana: 0x306E,
  23658. nokatakana: 0x30CE,
  23659. nokatakanahalfwidth: 0xFF89,
  23660. nonbreakingspace: 0x00A0,
  23661. nonenthai: 0x0E13,
  23662. nonuthai: 0x0E19,
  23663. noonarabic: 0x0646,
  23664. noonfinalarabic: 0xFEE6,
  23665. noonghunnaarabic: 0x06BA,
  23666. noonghunnafinalarabic: 0xFB9F,
  23667. nooninitialarabic: 0xFEE7,
  23668. noonjeeminitialarabic: 0xFCD2,
  23669. noonjeemisolatedarabic: 0xFC4B,
  23670. noonmedialarabic: 0xFEE8,
  23671. noonmeeminitialarabic: 0xFCD5,
  23672. noonmeemisolatedarabic: 0xFC4E,
  23673. noonnoonfinalarabic: 0xFC8D,
  23674. notcontains: 0x220C,
  23675. notelement: 0x2209,
  23676. notelementof: 0x2209,
  23677. notequal: 0x2260,
  23678. notgreater: 0x226F,
  23679. notgreaternorequal: 0x2271,
  23680. notgreaternorless: 0x2279,
  23681. notidentical: 0x2262,
  23682. notless: 0x226E,
  23683. notlessnorequal: 0x2270,
  23684. notparallel: 0x2226,
  23685. notprecedes: 0x2280,
  23686. notsubset: 0x2284,
  23687. notsucceeds: 0x2281,
  23688. notsuperset: 0x2285,
  23689. nowarmenian: 0x0576,
  23690. nparen: 0x24A9,
  23691. nssquare: 0x33B1,
  23692. nsuperior: 0x207F,
  23693. ntilde: 0x00F1,
  23694. nu: 0x03BD,
  23695. nuhiragana: 0x306C,
  23696. nukatakana: 0x30CC,
  23697. nukatakanahalfwidth: 0xFF87,
  23698. nuktabengali: 0x09BC,
  23699. nuktadeva: 0x093C,
  23700. nuktagujarati: 0x0ABC,
  23701. nuktagurmukhi: 0x0A3C,
  23702. numbersign: 0x0023,
  23703. numbersignmonospace: 0xFF03,
  23704. numbersignsmall: 0xFE5F,
  23705. numeralsigngreek: 0x0374,
  23706. numeralsignlowergreek: 0x0375,
  23707. numero: 0x2116,
  23708. nun: 0x05E0,
  23709. nundagesh: 0xFB40,
  23710. nundageshhebrew: 0xFB40,
  23711. nunhebrew: 0x05E0,
  23712. nvsquare: 0x33B5,
  23713. nwsquare: 0x33BB,
  23714. nyabengali: 0x099E,
  23715. nyadeva: 0x091E,
  23716. nyagujarati: 0x0A9E,
  23717. nyagurmukhi: 0x0A1E,
  23718. o: 0x006F,
  23719. oacute: 0x00F3,
  23720. oangthai: 0x0E2D,
  23721. obarred: 0x0275,
  23722. obarredcyrillic: 0x04E9,
  23723. obarreddieresiscyrillic: 0x04EB,
  23724. obengali: 0x0993,
  23725. obopomofo: 0x311B,
  23726. obreve: 0x014F,
  23727. ocandradeva: 0x0911,
  23728. ocandragujarati: 0x0A91,
  23729. ocandravowelsigndeva: 0x0949,
  23730. ocandravowelsigngujarati: 0x0AC9,
  23731. ocaron: 0x01D2,
  23732. ocircle: 0x24DE,
  23733. ocircumflex: 0x00F4,
  23734. ocircumflexacute: 0x1ED1,
  23735. ocircumflexdotbelow: 0x1ED9,
  23736. ocircumflexgrave: 0x1ED3,
  23737. ocircumflexhookabove: 0x1ED5,
  23738. ocircumflextilde: 0x1ED7,
  23739. ocyrillic: 0x043E,
  23740. odblacute: 0x0151,
  23741. odblgrave: 0x020D,
  23742. odeva: 0x0913,
  23743. odieresis: 0x00F6,
  23744. odieresiscyrillic: 0x04E7,
  23745. odotbelow: 0x1ECD,
  23746. oe: 0x0153,
  23747. oekorean: 0x315A,
  23748. ogonek: 0x02DB,
  23749. ogonekcmb: 0x0328,
  23750. ograve: 0x00F2,
  23751. ogujarati: 0x0A93,
  23752. oharmenian: 0x0585,
  23753. ohiragana: 0x304A,
  23754. ohookabove: 0x1ECF,
  23755. ohorn: 0x01A1,
  23756. ohornacute: 0x1EDB,
  23757. ohorndotbelow: 0x1EE3,
  23758. ohorngrave: 0x1EDD,
  23759. ohornhookabove: 0x1EDF,
  23760. ohorntilde: 0x1EE1,
  23761. ohungarumlaut: 0x0151,
  23762. oi: 0x01A3,
  23763. oinvertedbreve: 0x020F,
  23764. okatakana: 0x30AA,
  23765. okatakanahalfwidth: 0xFF75,
  23766. okorean: 0x3157,
  23767. olehebrew: 0x05AB,
  23768. omacron: 0x014D,
  23769. omacronacute: 0x1E53,
  23770. omacrongrave: 0x1E51,
  23771. omdeva: 0x0950,
  23772. omega: 0x03C9,
  23773. omega1: 0x03D6,
  23774. omegacyrillic: 0x0461,
  23775. omegalatinclosed: 0x0277,
  23776. omegaroundcyrillic: 0x047B,
  23777. omegatitlocyrillic: 0x047D,
  23778. omegatonos: 0x03CE,
  23779. omgujarati: 0x0AD0,
  23780. omicron: 0x03BF,
  23781. omicrontonos: 0x03CC,
  23782. omonospace: 0xFF4F,
  23783. one: 0x0031,
  23784. onearabic: 0x0661,
  23785. onebengali: 0x09E7,
  23786. onecircle: 0x2460,
  23787. onecircleinversesansserif: 0x278A,
  23788. onedeva: 0x0967,
  23789. onedotenleader: 0x2024,
  23790. oneeighth: 0x215B,
  23791. onefitted: 0xF6DC,
  23792. onegujarati: 0x0AE7,
  23793. onegurmukhi: 0x0A67,
  23794. onehackarabic: 0x0661,
  23795. onehalf: 0x00BD,
  23796. onehangzhou: 0x3021,
  23797. oneideographicparen: 0x3220,
  23798. oneinferior: 0x2081,
  23799. onemonospace: 0xFF11,
  23800. onenumeratorbengali: 0x09F4,
  23801. oneoldstyle: 0xF731,
  23802. oneparen: 0x2474,
  23803. oneperiod: 0x2488,
  23804. onepersian: 0x06F1,
  23805. onequarter: 0x00BC,
  23806. oneroman: 0x2170,
  23807. onesuperior: 0x00B9,
  23808. onethai: 0x0E51,
  23809. onethird: 0x2153,
  23810. oogonek: 0x01EB,
  23811. oogonekmacron: 0x01ED,
  23812. oogurmukhi: 0x0A13,
  23813. oomatragurmukhi: 0x0A4B,
  23814. oopen: 0x0254,
  23815. oparen: 0x24AA,
  23816. openbullet: 0x25E6,
  23817. option: 0x2325,
  23818. ordfeminine: 0x00AA,
  23819. ordmasculine: 0x00BA,
  23820. orthogonal: 0x221F,
  23821. oshortdeva: 0x0912,
  23822. oshortvowelsigndeva: 0x094A,
  23823. oslash: 0x00F8,
  23824. oslashacute: 0x01FF,
  23825. osmallhiragana: 0x3049,
  23826. osmallkatakana: 0x30A9,
  23827. osmallkatakanahalfwidth: 0xFF6B,
  23828. ostrokeacute: 0x01FF,
  23829. osuperior: 0xF6F0,
  23830. otcyrillic: 0x047F,
  23831. otilde: 0x00F5,
  23832. otildeacute: 0x1E4D,
  23833. otildedieresis: 0x1E4F,
  23834. oubopomofo: 0x3121,
  23835. overline: 0x203E,
  23836. overlinecenterline: 0xFE4A,
  23837. overlinecmb: 0x0305,
  23838. overlinedashed: 0xFE49,
  23839. overlinedblwavy: 0xFE4C,
  23840. overlinewavy: 0xFE4B,
  23841. overscore: 0x00AF,
  23842. ovowelsignbengali: 0x09CB,
  23843. ovowelsigndeva: 0x094B,
  23844. ovowelsigngujarati: 0x0ACB,
  23845. p: 0x0070,
  23846. paampssquare: 0x3380,
  23847. paasentosquare: 0x332B,
  23848. pabengali: 0x09AA,
  23849. pacute: 0x1E55,
  23850. padeva: 0x092A,
  23851. pagedown: 0x21DF,
  23852. pageup: 0x21DE,
  23853. pagujarati: 0x0AAA,
  23854. pagurmukhi: 0x0A2A,
  23855. pahiragana: 0x3071,
  23856. paiyannoithai: 0x0E2F,
  23857. pakatakana: 0x30D1,
  23858. palatalizationcyrilliccmb: 0x0484,
  23859. palochkacyrillic: 0x04C0,
  23860. pansioskorean: 0x317F,
  23861. paragraph: 0x00B6,
  23862. parallel: 0x2225,
  23863. parenleft: 0x0028,
  23864. parenleftaltonearabic: 0xFD3E,
  23865. parenleftbt: 0xF8ED,
  23866. parenleftex: 0xF8EC,
  23867. parenleftinferior: 0x208D,
  23868. parenleftmonospace: 0xFF08,
  23869. parenleftsmall: 0xFE59,
  23870. parenleftsuperior: 0x207D,
  23871. parenlefttp: 0xF8EB,
  23872. parenleftvertical: 0xFE35,
  23873. parenright: 0x0029,
  23874. parenrightaltonearabic: 0xFD3F,
  23875. parenrightbt: 0xF8F8,
  23876. parenrightex: 0xF8F7,
  23877. parenrightinferior: 0x208E,
  23878. parenrightmonospace: 0xFF09,
  23879. parenrightsmall: 0xFE5A,
  23880. parenrightsuperior: 0x207E,
  23881. parenrighttp: 0xF8F6,
  23882. parenrightvertical: 0xFE36,
  23883. partialdiff: 0x2202,
  23884. paseqhebrew: 0x05C0,
  23885. pashtahebrew: 0x0599,
  23886. pasquare: 0x33A9,
  23887. patah: 0x05B7,
  23888. patah11: 0x05B7,
  23889. patah1d: 0x05B7,
  23890. patah2a: 0x05B7,
  23891. patahhebrew: 0x05B7,
  23892. patahnarrowhebrew: 0x05B7,
  23893. patahquarterhebrew: 0x05B7,
  23894. patahwidehebrew: 0x05B7,
  23895. pazerhebrew: 0x05A1,
  23896. pbopomofo: 0x3106,
  23897. pcircle: 0x24DF,
  23898. pdotaccent: 0x1E57,
  23899. pe: 0x05E4,
  23900. pecyrillic: 0x043F,
  23901. pedagesh: 0xFB44,
  23902. pedageshhebrew: 0xFB44,
  23903. peezisquare: 0x333B,
  23904. pefinaldageshhebrew: 0xFB43,
  23905. peharabic: 0x067E,
  23906. peharmenian: 0x057A,
  23907. pehebrew: 0x05E4,
  23908. pehfinalarabic: 0xFB57,
  23909. pehinitialarabic: 0xFB58,
  23910. pehiragana: 0x307A,
  23911. pehmedialarabic: 0xFB59,
  23912. pekatakana: 0x30DA,
  23913. pemiddlehookcyrillic: 0x04A7,
  23914. perafehebrew: 0xFB4E,
  23915. percent: 0x0025,
  23916. percentarabic: 0x066A,
  23917. percentmonospace: 0xFF05,
  23918. percentsmall: 0xFE6A,
  23919. period: 0x002E,
  23920. periodarmenian: 0x0589,
  23921. periodcentered: 0x00B7,
  23922. periodhalfwidth: 0xFF61,
  23923. periodinferior: 0xF6E7,
  23924. periodmonospace: 0xFF0E,
  23925. periodsmall: 0xFE52,
  23926. periodsuperior: 0xF6E8,
  23927. perispomenigreekcmb: 0x0342,
  23928. perpendicular: 0x22A5,
  23929. perthousand: 0x2030,
  23930. peseta: 0x20A7,
  23931. pfsquare: 0x338A,
  23932. phabengali: 0x09AB,
  23933. phadeva: 0x092B,
  23934. phagujarati: 0x0AAB,
  23935. phagurmukhi: 0x0A2B,
  23936. phi: 0x03C6,
  23937. phi1: 0x03D5,
  23938. phieuphacirclekorean: 0x327A,
  23939. phieuphaparenkorean: 0x321A,
  23940. phieuphcirclekorean: 0x326C,
  23941. phieuphkorean: 0x314D,
  23942. phieuphparenkorean: 0x320C,
  23943. philatin: 0x0278,
  23944. phinthuthai: 0x0E3A,
  23945. phisymbolgreek: 0x03D5,
  23946. phook: 0x01A5,
  23947. phophanthai: 0x0E1E,
  23948. phophungthai: 0x0E1C,
  23949. phosamphaothai: 0x0E20,
  23950. pi: 0x03C0,
  23951. pieupacirclekorean: 0x3273,
  23952. pieupaparenkorean: 0x3213,
  23953. pieupcieuckorean: 0x3176,
  23954. pieupcirclekorean: 0x3265,
  23955. pieupkiyeokkorean: 0x3172,
  23956. pieupkorean: 0x3142,
  23957. pieupparenkorean: 0x3205,
  23958. pieupsioskiyeokkorean: 0x3174,
  23959. pieupsioskorean: 0x3144,
  23960. pieupsiostikeutkorean: 0x3175,
  23961. pieupthieuthkorean: 0x3177,
  23962. pieuptikeutkorean: 0x3173,
  23963. pihiragana: 0x3074,
  23964. pikatakana: 0x30D4,
  23965. pisymbolgreek: 0x03D6,
  23966. piwrarmenian: 0x0583,
  23967. plus: 0x002B,
  23968. plusbelowcmb: 0x031F,
  23969. pluscircle: 0x2295,
  23970. plusminus: 0x00B1,
  23971. plusmod: 0x02D6,
  23972. plusmonospace: 0xFF0B,
  23973. plussmall: 0xFE62,
  23974. plussuperior: 0x207A,
  23975. pmonospace: 0xFF50,
  23976. pmsquare: 0x33D8,
  23977. pohiragana: 0x307D,
  23978. pointingindexdownwhite: 0x261F,
  23979. pointingindexleftwhite: 0x261C,
  23980. pointingindexrightwhite: 0x261E,
  23981. pointingindexupwhite: 0x261D,
  23982. pokatakana: 0x30DD,
  23983. poplathai: 0x0E1B,
  23984. postalmark: 0x3012,
  23985. postalmarkface: 0x3020,
  23986. pparen: 0x24AB,
  23987. precedes: 0x227A,
  23988. prescription: 0x211E,
  23989. primemod: 0x02B9,
  23990. primereversed: 0x2035,
  23991. product: 0x220F,
  23992. projective: 0x2305,
  23993. prolongedkana: 0x30FC,
  23994. propellor: 0x2318,
  23995. propersubset: 0x2282,
  23996. propersuperset: 0x2283,
  23997. proportion: 0x2237,
  23998. proportional: 0x221D,
  23999. psi: 0x03C8,
  24000. psicyrillic: 0x0471,
  24001. psilipneumatacyrilliccmb: 0x0486,
  24002. pssquare: 0x33B0,
  24003. puhiragana: 0x3077,
  24004. pukatakana: 0x30D7,
  24005. pvsquare: 0x33B4,
  24006. pwsquare: 0x33BA,
  24007. q: 0x0071,
  24008. qadeva: 0x0958,
  24009. qadmahebrew: 0x05A8,
  24010. qafarabic: 0x0642,
  24011. qaffinalarabic: 0xFED6,
  24012. qafinitialarabic: 0xFED7,
  24013. qafmedialarabic: 0xFED8,
  24014. qamats: 0x05B8,
  24015. qamats10: 0x05B8,
  24016. qamats1a: 0x05B8,
  24017. qamats1c: 0x05B8,
  24018. qamats27: 0x05B8,
  24019. qamats29: 0x05B8,
  24020. qamats33: 0x05B8,
  24021. qamatsde: 0x05B8,
  24022. qamatshebrew: 0x05B8,
  24023. qamatsnarrowhebrew: 0x05B8,
  24024. qamatsqatanhebrew: 0x05B8,
  24025. qamatsqatannarrowhebrew: 0x05B8,
  24026. qamatsqatanquarterhebrew: 0x05B8,
  24027. qamatsqatanwidehebrew: 0x05B8,
  24028. qamatsquarterhebrew: 0x05B8,
  24029. qamatswidehebrew: 0x05B8,
  24030. qarneyparahebrew: 0x059F,
  24031. qbopomofo: 0x3111,
  24032. qcircle: 0x24E0,
  24033. qhook: 0x02A0,
  24034. qmonospace: 0xFF51,
  24035. qof: 0x05E7,
  24036. qofdagesh: 0xFB47,
  24037. qofdageshhebrew: 0xFB47,
  24038. qofhebrew: 0x05E7,
  24039. qparen: 0x24AC,
  24040. quarternote: 0x2669,
  24041. qubuts: 0x05BB,
  24042. qubuts18: 0x05BB,
  24043. qubuts25: 0x05BB,
  24044. qubuts31: 0x05BB,
  24045. qubutshebrew: 0x05BB,
  24046. qubutsnarrowhebrew: 0x05BB,
  24047. qubutsquarterhebrew: 0x05BB,
  24048. qubutswidehebrew: 0x05BB,
  24049. question: 0x003F,
  24050. questionarabic: 0x061F,
  24051. questionarmenian: 0x055E,
  24052. questiondown: 0x00BF,
  24053. questiondownsmall: 0xF7BF,
  24054. questiongreek: 0x037E,
  24055. questionmonospace: 0xFF1F,
  24056. questionsmall: 0xF73F,
  24057. quotedbl: 0x0022,
  24058. quotedblbase: 0x201E,
  24059. quotedblleft: 0x201C,
  24060. quotedblmonospace: 0xFF02,
  24061. quotedblprime: 0x301E,
  24062. quotedblprimereversed: 0x301D,
  24063. quotedblright: 0x201D,
  24064. quoteleft: 0x2018,
  24065. quoteleftreversed: 0x201B,
  24066. quotereversed: 0x201B,
  24067. quoteright: 0x2019,
  24068. quoterightn: 0x0149,
  24069. quotesinglbase: 0x201A,
  24070. quotesingle: 0x0027,
  24071. quotesinglemonospace: 0xFF07,
  24072. r: 0x0072,
  24073. raarmenian: 0x057C,
  24074. rabengali: 0x09B0,
  24075. racute: 0x0155,
  24076. radeva: 0x0930,
  24077. radical: 0x221A,
  24078. radicalex: 0xF8E5,
  24079. radoverssquare: 0x33AE,
  24080. radoverssquaredsquare: 0x33AF,
  24081. radsquare: 0x33AD,
  24082. rafe: 0x05BF,
  24083. rafehebrew: 0x05BF,
  24084. ragujarati: 0x0AB0,
  24085. ragurmukhi: 0x0A30,
  24086. rahiragana: 0x3089,
  24087. rakatakana: 0x30E9,
  24088. rakatakanahalfwidth: 0xFF97,
  24089. ralowerdiagonalbengali: 0x09F1,
  24090. ramiddlediagonalbengali: 0x09F0,
  24091. ramshorn: 0x0264,
  24092. ratio: 0x2236,
  24093. rbopomofo: 0x3116,
  24094. rcaron: 0x0159,
  24095. rcedilla: 0x0157,
  24096. rcircle: 0x24E1,
  24097. rcommaaccent: 0x0157,
  24098. rdblgrave: 0x0211,
  24099. rdotaccent: 0x1E59,
  24100. rdotbelow: 0x1E5B,
  24101. rdotbelowmacron: 0x1E5D,
  24102. referencemark: 0x203B,
  24103. reflexsubset: 0x2286,
  24104. reflexsuperset: 0x2287,
  24105. registered: 0x00AE,
  24106. registersans: 0xF8E8,
  24107. registerserif: 0xF6DA,
  24108. reharabic: 0x0631,
  24109. reharmenian: 0x0580,
  24110. rehfinalarabic: 0xFEAE,
  24111. rehiragana: 0x308C,
  24112. rekatakana: 0x30EC,
  24113. rekatakanahalfwidth: 0xFF9A,
  24114. resh: 0x05E8,
  24115. reshdageshhebrew: 0xFB48,
  24116. reshhebrew: 0x05E8,
  24117. reversedtilde: 0x223D,
  24118. reviahebrew: 0x0597,
  24119. reviamugrashhebrew: 0x0597,
  24120. revlogicalnot: 0x2310,
  24121. rfishhook: 0x027E,
  24122. rfishhookreversed: 0x027F,
  24123. rhabengali: 0x09DD,
  24124. rhadeva: 0x095D,
  24125. rho: 0x03C1,
  24126. rhook: 0x027D,
  24127. rhookturned: 0x027B,
  24128. rhookturnedsuperior: 0x02B5,
  24129. rhosymbolgreek: 0x03F1,
  24130. rhotichookmod: 0x02DE,
  24131. rieulacirclekorean: 0x3271,
  24132. rieulaparenkorean: 0x3211,
  24133. rieulcirclekorean: 0x3263,
  24134. rieulhieuhkorean: 0x3140,
  24135. rieulkiyeokkorean: 0x313A,
  24136. rieulkiyeoksioskorean: 0x3169,
  24137. rieulkorean: 0x3139,
  24138. rieulmieumkorean: 0x313B,
  24139. rieulpansioskorean: 0x316C,
  24140. rieulparenkorean: 0x3203,
  24141. rieulphieuphkorean: 0x313F,
  24142. rieulpieupkorean: 0x313C,
  24143. rieulpieupsioskorean: 0x316B,
  24144. rieulsioskorean: 0x313D,
  24145. rieulthieuthkorean: 0x313E,
  24146. rieultikeutkorean: 0x316A,
  24147. rieulyeorinhieuhkorean: 0x316D,
  24148. rightangle: 0x221F,
  24149. righttackbelowcmb: 0x0319,
  24150. righttriangle: 0x22BF,
  24151. rihiragana: 0x308A,
  24152. rikatakana: 0x30EA,
  24153. rikatakanahalfwidth: 0xFF98,
  24154. ring: 0x02DA,
  24155. ringbelowcmb: 0x0325,
  24156. ringcmb: 0x030A,
  24157. ringhalfleft: 0x02BF,
  24158. ringhalfleftarmenian: 0x0559,
  24159. ringhalfleftbelowcmb: 0x031C,
  24160. ringhalfleftcentered: 0x02D3,
  24161. ringhalfright: 0x02BE,
  24162. ringhalfrightbelowcmb: 0x0339,
  24163. ringhalfrightcentered: 0x02D2,
  24164. rinvertedbreve: 0x0213,
  24165. rittorusquare: 0x3351,
  24166. rlinebelow: 0x1E5F,
  24167. rlongleg: 0x027C,
  24168. rlonglegturned: 0x027A,
  24169. rmonospace: 0xFF52,
  24170. rohiragana: 0x308D,
  24171. rokatakana: 0x30ED,
  24172. rokatakanahalfwidth: 0xFF9B,
  24173. roruathai: 0x0E23,
  24174. rparen: 0x24AD,
  24175. rrabengali: 0x09DC,
  24176. rradeva: 0x0931,
  24177. rragurmukhi: 0x0A5C,
  24178. rreharabic: 0x0691,
  24179. rrehfinalarabic: 0xFB8D,
  24180. rrvocalicbengali: 0x09E0,
  24181. rrvocalicdeva: 0x0960,
  24182. rrvocalicgujarati: 0x0AE0,
  24183. rrvocalicvowelsignbengali: 0x09C4,
  24184. rrvocalicvowelsigndeva: 0x0944,
  24185. rrvocalicvowelsigngujarati: 0x0AC4,
  24186. rsuperior: 0xF6F1,
  24187. rtblock: 0x2590,
  24188. rturned: 0x0279,
  24189. rturnedsuperior: 0x02B4,
  24190. ruhiragana: 0x308B,
  24191. rukatakana: 0x30EB,
  24192. rukatakanahalfwidth: 0xFF99,
  24193. rupeemarkbengali: 0x09F2,
  24194. rupeesignbengali: 0x09F3,
  24195. rupiah: 0xF6DD,
  24196. ruthai: 0x0E24,
  24197. rvocalicbengali: 0x098B,
  24198. rvocalicdeva: 0x090B,
  24199. rvocalicgujarati: 0x0A8B,
  24200. rvocalicvowelsignbengali: 0x09C3,
  24201. rvocalicvowelsigndeva: 0x0943,
  24202. rvocalicvowelsigngujarati: 0x0AC3,
  24203. s: 0x0073,
  24204. sabengali: 0x09B8,
  24205. sacute: 0x015B,
  24206. sacutedotaccent: 0x1E65,
  24207. sadarabic: 0x0635,
  24208. sadeva: 0x0938,
  24209. sadfinalarabic: 0xFEBA,
  24210. sadinitialarabic: 0xFEBB,
  24211. sadmedialarabic: 0xFEBC,
  24212. sagujarati: 0x0AB8,
  24213. sagurmukhi: 0x0A38,
  24214. sahiragana: 0x3055,
  24215. sakatakana: 0x30B5,
  24216. sakatakanahalfwidth: 0xFF7B,
  24217. sallallahoualayhewasallamarabic: 0xFDFA,
  24218. samekh: 0x05E1,
  24219. samekhdagesh: 0xFB41,
  24220. samekhdageshhebrew: 0xFB41,
  24221. samekhhebrew: 0x05E1,
  24222. saraaathai: 0x0E32,
  24223. saraaethai: 0x0E41,
  24224. saraaimaimalaithai: 0x0E44,
  24225. saraaimaimuanthai: 0x0E43,
  24226. saraamthai: 0x0E33,
  24227. saraathai: 0x0E30,
  24228. saraethai: 0x0E40,
  24229. saraiileftthai: 0xF886,
  24230. saraiithai: 0x0E35,
  24231. saraileftthai: 0xF885,
  24232. saraithai: 0x0E34,
  24233. saraothai: 0x0E42,
  24234. saraueeleftthai: 0xF888,
  24235. saraueethai: 0x0E37,
  24236. saraueleftthai: 0xF887,
  24237. sarauethai: 0x0E36,
  24238. sarauthai: 0x0E38,
  24239. sarauuthai: 0x0E39,
  24240. sbopomofo: 0x3119,
  24241. scaron: 0x0161,
  24242. scarondotaccent: 0x1E67,
  24243. scedilla: 0x015F,
  24244. schwa: 0x0259,
  24245. schwacyrillic: 0x04D9,
  24246. schwadieresiscyrillic: 0x04DB,
  24247. schwahook: 0x025A,
  24248. scircle: 0x24E2,
  24249. scircumflex: 0x015D,
  24250. scommaaccent: 0x0219,
  24251. sdotaccent: 0x1E61,
  24252. sdotbelow: 0x1E63,
  24253. sdotbelowdotaccent: 0x1E69,
  24254. seagullbelowcmb: 0x033C,
  24255. second: 0x2033,
  24256. secondtonechinese: 0x02CA,
  24257. section: 0x00A7,
  24258. seenarabic: 0x0633,
  24259. seenfinalarabic: 0xFEB2,
  24260. seeninitialarabic: 0xFEB3,
  24261. seenmedialarabic: 0xFEB4,
  24262. segol: 0x05B6,
  24263. segol13: 0x05B6,
  24264. segol1f: 0x05B6,
  24265. segol2c: 0x05B6,
  24266. segolhebrew: 0x05B6,
  24267. segolnarrowhebrew: 0x05B6,
  24268. segolquarterhebrew: 0x05B6,
  24269. segoltahebrew: 0x0592,
  24270. segolwidehebrew: 0x05B6,
  24271. seharmenian: 0x057D,
  24272. sehiragana: 0x305B,
  24273. sekatakana: 0x30BB,
  24274. sekatakanahalfwidth: 0xFF7E,
  24275. semicolon: 0x003B,
  24276. semicolonarabic: 0x061B,
  24277. semicolonmonospace: 0xFF1B,
  24278. semicolonsmall: 0xFE54,
  24279. semivoicedmarkkana: 0x309C,
  24280. semivoicedmarkkanahalfwidth: 0xFF9F,
  24281. sentisquare: 0x3322,
  24282. sentosquare: 0x3323,
  24283. seven: 0x0037,
  24284. sevenarabic: 0x0667,
  24285. sevenbengali: 0x09ED,
  24286. sevencircle: 0x2466,
  24287. sevencircleinversesansserif: 0x2790,
  24288. sevendeva: 0x096D,
  24289. seveneighths: 0x215E,
  24290. sevengujarati: 0x0AED,
  24291. sevengurmukhi: 0x0A6D,
  24292. sevenhackarabic: 0x0667,
  24293. sevenhangzhou: 0x3027,
  24294. sevenideographicparen: 0x3226,
  24295. seveninferior: 0x2087,
  24296. sevenmonospace: 0xFF17,
  24297. sevenoldstyle: 0xF737,
  24298. sevenparen: 0x247A,
  24299. sevenperiod: 0x248E,
  24300. sevenpersian: 0x06F7,
  24301. sevenroman: 0x2176,
  24302. sevensuperior: 0x2077,
  24303. seventeencircle: 0x2470,
  24304. seventeenparen: 0x2484,
  24305. seventeenperiod: 0x2498,
  24306. seventhai: 0x0E57,
  24307. sfthyphen: 0x00AD,
  24308. shaarmenian: 0x0577,
  24309. shabengali: 0x09B6,
  24310. shacyrillic: 0x0448,
  24311. shaddaarabic: 0x0651,
  24312. shaddadammaarabic: 0xFC61,
  24313. shaddadammatanarabic: 0xFC5E,
  24314. shaddafathaarabic: 0xFC60,
  24315. shaddakasraarabic: 0xFC62,
  24316. shaddakasratanarabic: 0xFC5F,
  24317. shade: 0x2592,
  24318. shadedark: 0x2593,
  24319. shadelight: 0x2591,
  24320. shademedium: 0x2592,
  24321. shadeva: 0x0936,
  24322. shagujarati: 0x0AB6,
  24323. shagurmukhi: 0x0A36,
  24324. shalshelethebrew: 0x0593,
  24325. shbopomofo: 0x3115,
  24326. shchacyrillic: 0x0449,
  24327. sheenarabic: 0x0634,
  24328. sheenfinalarabic: 0xFEB6,
  24329. sheeninitialarabic: 0xFEB7,
  24330. sheenmedialarabic: 0xFEB8,
  24331. sheicoptic: 0x03E3,
  24332. sheqel: 0x20AA,
  24333. sheqelhebrew: 0x20AA,
  24334. sheva: 0x05B0,
  24335. sheva115: 0x05B0,
  24336. sheva15: 0x05B0,
  24337. sheva22: 0x05B0,
  24338. sheva2e: 0x05B0,
  24339. shevahebrew: 0x05B0,
  24340. shevanarrowhebrew: 0x05B0,
  24341. shevaquarterhebrew: 0x05B0,
  24342. shevawidehebrew: 0x05B0,
  24343. shhacyrillic: 0x04BB,
  24344. shimacoptic: 0x03ED,
  24345. shin: 0x05E9,
  24346. shindagesh: 0xFB49,
  24347. shindageshhebrew: 0xFB49,
  24348. shindageshshindot: 0xFB2C,
  24349. shindageshshindothebrew: 0xFB2C,
  24350. shindageshsindot: 0xFB2D,
  24351. shindageshsindothebrew: 0xFB2D,
  24352. shindothebrew: 0x05C1,
  24353. shinhebrew: 0x05E9,
  24354. shinshindot: 0xFB2A,
  24355. shinshindothebrew: 0xFB2A,
  24356. shinsindot: 0xFB2B,
  24357. shinsindothebrew: 0xFB2B,
  24358. shook: 0x0282,
  24359. sigma: 0x03C3,
  24360. sigma1: 0x03C2,
  24361. sigmafinal: 0x03C2,
  24362. sigmalunatesymbolgreek: 0x03F2,
  24363. sihiragana: 0x3057,
  24364. sikatakana: 0x30B7,
  24365. sikatakanahalfwidth: 0xFF7C,
  24366. siluqhebrew: 0x05BD,
  24367. siluqlefthebrew: 0x05BD,
  24368. similar: 0x223C,
  24369. sindothebrew: 0x05C2,
  24370. siosacirclekorean: 0x3274,
  24371. siosaparenkorean: 0x3214,
  24372. sioscieuckorean: 0x317E,
  24373. sioscirclekorean: 0x3266,
  24374. sioskiyeokkorean: 0x317A,
  24375. sioskorean: 0x3145,
  24376. siosnieunkorean: 0x317B,
  24377. siosparenkorean: 0x3206,
  24378. siospieupkorean: 0x317D,
  24379. siostikeutkorean: 0x317C,
  24380. six: 0x0036,
  24381. sixarabic: 0x0666,
  24382. sixbengali: 0x09EC,
  24383. sixcircle: 0x2465,
  24384. sixcircleinversesansserif: 0x278F,
  24385. sixdeva: 0x096C,
  24386. sixgujarati: 0x0AEC,
  24387. sixgurmukhi: 0x0A6C,
  24388. sixhackarabic: 0x0666,
  24389. sixhangzhou: 0x3026,
  24390. sixideographicparen: 0x3225,
  24391. sixinferior: 0x2086,
  24392. sixmonospace: 0xFF16,
  24393. sixoldstyle: 0xF736,
  24394. sixparen: 0x2479,
  24395. sixperiod: 0x248D,
  24396. sixpersian: 0x06F6,
  24397. sixroman: 0x2175,
  24398. sixsuperior: 0x2076,
  24399. sixteencircle: 0x246F,
  24400. sixteencurrencydenominatorbengali: 0x09F9,
  24401. sixteenparen: 0x2483,
  24402. sixteenperiod: 0x2497,
  24403. sixthai: 0x0E56,
  24404. slash: 0x002F,
  24405. slashmonospace: 0xFF0F,
  24406. slong: 0x017F,
  24407. slongdotaccent: 0x1E9B,
  24408. smileface: 0x263A,
  24409. smonospace: 0xFF53,
  24410. sofpasuqhebrew: 0x05C3,
  24411. softhyphen: 0x00AD,
  24412. softsigncyrillic: 0x044C,
  24413. sohiragana: 0x305D,
  24414. sokatakana: 0x30BD,
  24415. sokatakanahalfwidth: 0xFF7F,
  24416. soliduslongoverlaycmb: 0x0338,
  24417. solidusshortoverlaycmb: 0x0337,
  24418. sorusithai: 0x0E29,
  24419. sosalathai: 0x0E28,
  24420. sosothai: 0x0E0B,
  24421. sosuathai: 0x0E2A,
  24422. space: 0x0020,
  24423. spacehackarabic: 0x0020,
  24424. spade: 0x2660,
  24425. spadesuitblack: 0x2660,
  24426. spadesuitwhite: 0x2664,
  24427. sparen: 0x24AE,
  24428. squarebelowcmb: 0x033B,
  24429. squarecc: 0x33C4,
  24430. squarecm: 0x339D,
  24431. squarediagonalcrosshatchfill: 0x25A9,
  24432. squarehorizontalfill: 0x25A4,
  24433. squarekg: 0x338F,
  24434. squarekm: 0x339E,
  24435. squarekmcapital: 0x33CE,
  24436. squareln: 0x33D1,
  24437. squarelog: 0x33D2,
  24438. squaremg: 0x338E,
  24439. squaremil: 0x33D5,
  24440. squaremm: 0x339C,
  24441. squaremsquared: 0x33A1,
  24442. squareorthogonalcrosshatchfill: 0x25A6,
  24443. squareupperlefttolowerrightfill: 0x25A7,
  24444. squareupperrighttolowerleftfill: 0x25A8,
  24445. squareverticalfill: 0x25A5,
  24446. squarewhitewithsmallblack: 0x25A3,
  24447. srsquare: 0x33DB,
  24448. ssabengali: 0x09B7,
  24449. ssadeva: 0x0937,
  24450. ssagujarati: 0x0AB7,
  24451. ssangcieuckorean: 0x3149,
  24452. ssanghieuhkorean: 0x3185,
  24453. ssangieungkorean: 0x3180,
  24454. ssangkiyeokkorean: 0x3132,
  24455. ssangnieunkorean: 0x3165,
  24456. ssangpieupkorean: 0x3143,
  24457. ssangsioskorean: 0x3146,
  24458. ssangtikeutkorean: 0x3138,
  24459. ssuperior: 0xF6F2,
  24460. sterling: 0x00A3,
  24461. sterlingmonospace: 0xFFE1,
  24462. strokelongoverlaycmb: 0x0336,
  24463. strokeshortoverlaycmb: 0x0335,
  24464. subset: 0x2282,
  24465. subsetnotequal: 0x228A,
  24466. subsetorequal: 0x2286,
  24467. succeeds: 0x227B,
  24468. suchthat: 0x220B,
  24469. suhiragana: 0x3059,
  24470. sukatakana: 0x30B9,
  24471. sukatakanahalfwidth: 0xFF7D,
  24472. sukunarabic: 0x0652,
  24473. summation: 0x2211,
  24474. sun: 0x263C,
  24475. superset: 0x2283,
  24476. supersetnotequal: 0x228B,
  24477. supersetorequal: 0x2287,
  24478. svsquare: 0x33DC,
  24479. syouwaerasquare: 0x337C,
  24480. t: 0x0074,
  24481. tabengali: 0x09A4,
  24482. tackdown: 0x22A4,
  24483. tackleft: 0x22A3,
  24484. tadeva: 0x0924,
  24485. tagujarati: 0x0AA4,
  24486. tagurmukhi: 0x0A24,
  24487. taharabic: 0x0637,
  24488. tahfinalarabic: 0xFEC2,
  24489. tahinitialarabic: 0xFEC3,
  24490. tahiragana: 0x305F,
  24491. tahmedialarabic: 0xFEC4,
  24492. taisyouerasquare: 0x337D,
  24493. takatakana: 0x30BF,
  24494. takatakanahalfwidth: 0xFF80,
  24495. tatweelarabic: 0x0640,
  24496. tau: 0x03C4,
  24497. tav: 0x05EA,
  24498. tavdages: 0xFB4A,
  24499. tavdagesh: 0xFB4A,
  24500. tavdageshhebrew: 0xFB4A,
  24501. tavhebrew: 0x05EA,
  24502. tbar: 0x0167,
  24503. tbopomofo: 0x310A,
  24504. tcaron: 0x0165,
  24505. tccurl: 0x02A8,
  24506. tcedilla: 0x0163,
  24507. tcheharabic: 0x0686,
  24508. tchehfinalarabic: 0xFB7B,
  24509. tchehinitialarabic: 0xFB7C,
  24510. tchehmedialarabic: 0xFB7D,
  24511. tcircle: 0x24E3,
  24512. tcircumflexbelow: 0x1E71,
  24513. tcommaaccent: 0x0163,
  24514. tdieresis: 0x1E97,
  24515. tdotaccent: 0x1E6B,
  24516. tdotbelow: 0x1E6D,
  24517. tecyrillic: 0x0442,
  24518. tedescendercyrillic: 0x04AD,
  24519. teharabic: 0x062A,
  24520. tehfinalarabic: 0xFE96,
  24521. tehhahinitialarabic: 0xFCA2,
  24522. tehhahisolatedarabic: 0xFC0C,
  24523. tehinitialarabic: 0xFE97,
  24524. tehiragana: 0x3066,
  24525. tehjeeminitialarabic: 0xFCA1,
  24526. tehjeemisolatedarabic: 0xFC0B,
  24527. tehmarbutaarabic: 0x0629,
  24528. tehmarbutafinalarabic: 0xFE94,
  24529. tehmedialarabic: 0xFE98,
  24530. tehmeeminitialarabic: 0xFCA4,
  24531. tehmeemisolatedarabic: 0xFC0E,
  24532. tehnoonfinalarabic: 0xFC73,
  24533. tekatakana: 0x30C6,
  24534. tekatakanahalfwidth: 0xFF83,
  24535. telephone: 0x2121,
  24536. telephoneblack: 0x260E,
  24537. telishagedolahebrew: 0x05A0,
  24538. telishaqetanahebrew: 0x05A9,
  24539. tencircle: 0x2469,
  24540. tenideographicparen: 0x3229,
  24541. tenparen: 0x247D,
  24542. tenperiod: 0x2491,
  24543. tenroman: 0x2179,
  24544. tesh: 0x02A7,
  24545. tet: 0x05D8,
  24546. tetdagesh: 0xFB38,
  24547. tetdageshhebrew: 0xFB38,
  24548. tethebrew: 0x05D8,
  24549. tetsecyrillic: 0x04B5,
  24550. tevirhebrew: 0x059B,
  24551. tevirlefthebrew: 0x059B,
  24552. thabengali: 0x09A5,
  24553. thadeva: 0x0925,
  24554. thagujarati: 0x0AA5,
  24555. thagurmukhi: 0x0A25,
  24556. thalarabic: 0x0630,
  24557. thalfinalarabic: 0xFEAC,
  24558. thanthakhatlowleftthai: 0xF898,
  24559. thanthakhatlowrightthai: 0xF897,
  24560. thanthakhatthai: 0x0E4C,
  24561. thanthakhatupperleftthai: 0xF896,
  24562. theharabic: 0x062B,
  24563. thehfinalarabic: 0xFE9A,
  24564. thehinitialarabic: 0xFE9B,
  24565. thehmedialarabic: 0xFE9C,
  24566. thereexists: 0x2203,
  24567. therefore: 0x2234,
  24568. theta: 0x03B8,
  24569. theta1: 0x03D1,
  24570. thetasymbolgreek: 0x03D1,
  24571. thieuthacirclekorean: 0x3279,
  24572. thieuthaparenkorean: 0x3219,
  24573. thieuthcirclekorean: 0x326B,
  24574. thieuthkorean: 0x314C,
  24575. thieuthparenkorean: 0x320B,
  24576. thirteencircle: 0x246C,
  24577. thirteenparen: 0x2480,
  24578. thirteenperiod: 0x2494,
  24579. thonangmonthothai: 0x0E11,
  24580. thook: 0x01AD,
  24581. thophuthaothai: 0x0E12,
  24582. thorn: 0x00FE,
  24583. thothahanthai: 0x0E17,
  24584. thothanthai: 0x0E10,
  24585. thothongthai: 0x0E18,
  24586. thothungthai: 0x0E16,
  24587. thousandcyrillic: 0x0482,
  24588. thousandsseparatorarabic: 0x066C,
  24589. thousandsseparatorpersian: 0x066C,
  24590. three: 0x0033,
  24591. threearabic: 0x0663,
  24592. threebengali: 0x09E9,
  24593. threecircle: 0x2462,
  24594. threecircleinversesansserif: 0x278C,
  24595. threedeva: 0x0969,
  24596. threeeighths: 0x215C,
  24597. threegujarati: 0x0AE9,
  24598. threegurmukhi: 0x0A69,
  24599. threehackarabic: 0x0663,
  24600. threehangzhou: 0x3023,
  24601. threeideographicparen: 0x3222,
  24602. threeinferior: 0x2083,
  24603. threemonospace: 0xFF13,
  24604. threenumeratorbengali: 0x09F6,
  24605. threeoldstyle: 0xF733,
  24606. threeparen: 0x2476,
  24607. threeperiod: 0x248A,
  24608. threepersian: 0x06F3,
  24609. threequarters: 0x00BE,
  24610. threequartersemdash: 0xF6DE,
  24611. threeroman: 0x2172,
  24612. threesuperior: 0x00B3,
  24613. threethai: 0x0E53,
  24614. thzsquare: 0x3394,
  24615. tihiragana: 0x3061,
  24616. tikatakana: 0x30C1,
  24617. tikatakanahalfwidth: 0xFF81,
  24618. tikeutacirclekorean: 0x3270,
  24619. tikeutaparenkorean: 0x3210,
  24620. tikeutcirclekorean: 0x3262,
  24621. tikeutkorean: 0x3137,
  24622. tikeutparenkorean: 0x3202,
  24623. tilde: 0x02DC,
  24624. tildebelowcmb: 0x0330,
  24625. tildecmb: 0x0303,
  24626. tildecomb: 0x0303,
  24627. tildedoublecmb: 0x0360,
  24628. tildeoperator: 0x223C,
  24629. tildeoverlaycmb: 0x0334,
  24630. tildeverticalcmb: 0x033E,
  24631. timescircle: 0x2297,
  24632. tipehahebrew: 0x0596,
  24633. tipehalefthebrew: 0x0596,
  24634. tippigurmukhi: 0x0A70,
  24635. titlocyrilliccmb: 0x0483,
  24636. tiwnarmenian: 0x057F,
  24637. tlinebelow: 0x1E6F,
  24638. tmonospace: 0xFF54,
  24639. toarmenian: 0x0569,
  24640. tohiragana: 0x3068,
  24641. tokatakana: 0x30C8,
  24642. tokatakanahalfwidth: 0xFF84,
  24643. tonebarextrahighmod: 0x02E5,
  24644. tonebarextralowmod: 0x02E9,
  24645. tonebarhighmod: 0x02E6,
  24646. tonebarlowmod: 0x02E8,
  24647. tonebarmidmod: 0x02E7,
  24648. tonefive: 0x01BD,
  24649. tonesix: 0x0185,
  24650. tonetwo: 0x01A8,
  24651. tonos: 0x0384,
  24652. tonsquare: 0x3327,
  24653. topatakthai: 0x0E0F,
  24654. tortoiseshellbracketleft: 0x3014,
  24655. tortoiseshellbracketleftsmall: 0xFE5D,
  24656. tortoiseshellbracketleftvertical: 0xFE39,
  24657. tortoiseshellbracketright: 0x3015,
  24658. tortoiseshellbracketrightsmall: 0xFE5E,
  24659. tortoiseshellbracketrightvertical: 0xFE3A,
  24660. totaothai: 0x0E15,
  24661. tpalatalhook: 0x01AB,
  24662. tparen: 0x24AF,
  24663. trademark: 0x2122,
  24664. trademarksans: 0xF8EA,
  24665. trademarkserif: 0xF6DB,
  24666. tretroflexhook: 0x0288,
  24667. triagdn: 0x25BC,
  24668. triaglf: 0x25C4,
  24669. triagrt: 0x25BA,
  24670. triagup: 0x25B2,
  24671. ts: 0x02A6,
  24672. tsadi: 0x05E6,
  24673. tsadidagesh: 0xFB46,
  24674. tsadidageshhebrew: 0xFB46,
  24675. tsadihebrew: 0x05E6,
  24676. tsecyrillic: 0x0446,
  24677. tsere: 0x05B5,
  24678. tsere12: 0x05B5,
  24679. tsere1e: 0x05B5,
  24680. tsere2b: 0x05B5,
  24681. tserehebrew: 0x05B5,
  24682. tserenarrowhebrew: 0x05B5,
  24683. tserequarterhebrew: 0x05B5,
  24684. tserewidehebrew: 0x05B5,
  24685. tshecyrillic: 0x045B,
  24686. tsuperior: 0xF6F3,
  24687. ttabengali: 0x099F,
  24688. ttadeva: 0x091F,
  24689. ttagujarati: 0x0A9F,
  24690. ttagurmukhi: 0x0A1F,
  24691. tteharabic: 0x0679,
  24692. ttehfinalarabic: 0xFB67,
  24693. ttehinitialarabic: 0xFB68,
  24694. ttehmedialarabic: 0xFB69,
  24695. tthabengali: 0x09A0,
  24696. tthadeva: 0x0920,
  24697. tthagujarati: 0x0AA0,
  24698. tthagurmukhi: 0x0A20,
  24699. tturned: 0x0287,
  24700. tuhiragana: 0x3064,
  24701. tukatakana: 0x30C4,
  24702. tukatakanahalfwidth: 0xFF82,
  24703. tusmallhiragana: 0x3063,
  24704. tusmallkatakana: 0x30C3,
  24705. tusmallkatakanahalfwidth: 0xFF6F,
  24706. twelvecircle: 0x246B,
  24707. twelveparen: 0x247F,
  24708. twelveperiod: 0x2493,
  24709. twelveroman: 0x217B,
  24710. twentycircle: 0x2473,
  24711. twentyhangzhou: 0x5344,
  24712. twentyparen: 0x2487,
  24713. twentyperiod: 0x249B,
  24714. two: 0x0032,
  24715. twoarabic: 0x0662,
  24716. twobengali: 0x09E8,
  24717. twocircle: 0x2461,
  24718. twocircleinversesansserif: 0x278B,
  24719. twodeva: 0x0968,
  24720. twodotenleader: 0x2025,
  24721. twodotleader: 0x2025,
  24722. twodotleadervertical: 0xFE30,
  24723. twogujarati: 0x0AE8,
  24724. twogurmukhi: 0x0A68,
  24725. twohackarabic: 0x0662,
  24726. twohangzhou: 0x3022,
  24727. twoideographicparen: 0x3221,
  24728. twoinferior: 0x2082,
  24729. twomonospace: 0xFF12,
  24730. twonumeratorbengali: 0x09F5,
  24731. twooldstyle: 0xF732,
  24732. twoparen: 0x2475,
  24733. twoperiod: 0x2489,
  24734. twopersian: 0x06F2,
  24735. tworoman: 0x2171,
  24736. twostroke: 0x01BB,
  24737. twosuperior: 0x00B2,
  24738. twothai: 0x0E52,
  24739. twothirds: 0x2154,
  24740. u: 0x0075,
  24741. uacute: 0x00FA,
  24742. ubar: 0x0289,
  24743. ubengali: 0x0989,
  24744. ubopomofo: 0x3128,
  24745. ubreve: 0x016D,
  24746. ucaron: 0x01D4,
  24747. ucircle: 0x24E4,
  24748. ucircumflex: 0x00FB,
  24749. ucircumflexbelow: 0x1E77,
  24750. ucyrillic: 0x0443,
  24751. udattadeva: 0x0951,
  24752. udblacute: 0x0171,
  24753. udblgrave: 0x0215,
  24754. udeva: 0x0909,
  24755. udieresis: 0x00FC,
  24756. udieresisacute: 0x01D8,
  24757. udieresisbelow: 0x1E73,
  24758. udieresiscaron: 0x01DA,
  24759. udieresiscyrillic: 0x04F1,
  24760. udieresisgrave: 0x01DC,
  24761. udieresismacron: 0x01D6,
  24762. udotbelow: 0x1EE5,
  24763. ugrave: 0x00F9,
  24764. ugujarati: 0x0A89,
  24765. ugurmukhi: 0x0A09,
  24766. uhiragana: 0x3046,
  24767. uhookabove: 0x1EE7,
  24768. uhorn: 0x01B0,
  24769. uhornacute: 0x1EE9,
  24770. uhorndotbelow: 0x1EF1,
  24771. uhorngrave: 0x1EEB,
  24772. uhornhookabove: 0x1EED,
  24773. uhorntilde: 0x1EEF,
  24774. uhungarumlaut: 0x0171,
  24775. uhungarumlautcyrillic: 0x04F3,
  24776. uinvertedbreve: 0x0217,
  24777. ukatakana: 0x30A6,
  24778. ukatakanahalfwidth: 0xFF73,
  24779. ukcyrillic: 0x0479,
  24780. ukorean: 0x315C,
  24781. umacron: 0x016B,
  24782. umacroncyrillic: 0x04EF,
  24783. umacrondieresis: 0x1E7B,
  24784. umatragurmukhi: 0x0A41,
  24785. umonospace: 0xFF55,
  24786. underscore: 0x005F,
  24787. underscoredbl: 0x2017,
  24788. underscoremonospace: 0xFF3F,
  24789. underscorevertical: 0xFE33,
  24790. underscorewavy: 0xFE4F,
  24791. union: 0x222A,
  24792. universal: 0x2200,
  24793. uogonek: 0x0173,
  24794. uparen: 0x24B0,
  24795. upblock: 0x2580,
  24796. upperdothebrew: 0x05C4,
  24797. upsilon: 0x03C5,
  24798. upsilondieresis: 0x03CB,
  24799. upsilondieresistonos: 0x03B0,
  24800. upsilonlatin: 0x028A,
  24801. upsilontonos: 0x03CD,
  24802. uptackbelowcmb: 0x031D,
  24803. uptackmod: 0x02D4,
  24804. uragurmukhi: 0x0A73,
  24805. uring: 0x016F,
  24806. ushortcyrillic: 0x045E,
  24807. usmallhiragana: 0x3045,
  24808. usmallkatakana: 0x30A5,
  24809. usmallkatakanahalfwidth: 0xFF69,
  24810. ustraightcyrillic: 0x04AF,
  24811. ustraightstrokecyrillic: 0x04B1,
  24812. utilde: 0x0169,
  24813. utildeacute: 0x1E79,
  24814. utildebelow: 0x1E75,
  24815. uubengali: 0x098A,
  24816. uudeva: 0x090A,
  24817. uugujarati: 0x0A8A,
  24818. uugurmukhi: 0x0A0A,
  24819. uumatragurmukhi: 0x0A42,
  24820. uuvowelsignbengali: 0x09C2,
  24821. uuvowelsigndeva: 0x0942,
  24822. uuvowelsigngujarati: 0x0AC2,
  24823. uvowelsignbengali: 0x09C1,
  24824. uvowelsigndeva: 0x0941,
  24825. uvowelsigngujarati: 0x0AC1,
  24826. v: 0x0076,
  24827. vadeva: 0x0935,
  24828. vagujarati: 0x0AB5,
  24829. vagurmukhi: 0x0A35,
  24830. vakatakana: 0x30F7,
  24831. vav: 0x05D5,
  24832. vavdagesh: 0xFB35,
  24833. vavdagesh65: 0xFB35,
  24834. vavdageshhebrew: 0xFB35,
  24835. vavhebrew: 0x05D5,
  24836. vavholam: 0xFB4B,
  24837. vavholamhebrew: 0xFB4B,
  24838. vavvavhebrew: 0x05F0,
  24839. vavyodhebrew: 0x05F1,
  24840. vcircle: 0x24E5,
  24841. vdotbelow: 0x1E7F,
  24842. vecyrillic: 0x0432,
  24843. veharabic: 0x06A4,
  24844. vehfinalarabic: 0xFB6B,
  24845. vehinitialarabic: 0xFB6C,
  24846. vehmedialarabic: 0xFB6D,
  24847. vekatakana: 0x30F9,
  24848. venus: 0x2640,
  24849. verticalbar: 0x007C,
  24850. verticallineabovecmb: 0x030D,
  24851. verticallinebelowcmb: 0x0329,
  24852. verticallinelowmod: 0x02CC,
  24853. verticallinemod: 0x02C8,
  24854. vewarmenian: 0x057E,
  24855. vhook: 0x028B,
  24856. vikatakana: 0x30F8,
  24857. viramabengali: 0x09CD,
  24858. viramadeva: 0x094D,
  24859. viramagujarati: 0x0ACD,
  24860. visargabengali: 0x0983,
  24861. visargadeva: 0x0903,
  24862. visargagujarati: 0x0A83,
  24863. vmonospace: 0xFF56,
  24864. voarmenian: 0x0578,
  24865. voicediterationhiragana: 0x309E,
  24866. voicediterationkatakana: 0x30FE,
  24867. voicedmarkkana: 0x309B,
  24868. voicedmarkkanahalfwidth: 0xFF9E,
  24869. vokatakana: 0x30FA,
  24870. vparen: 0x24B1,
  24871. vtilde: 0x1E7D,
  24872. vturned: 0x028C,
  24873. vuhiragana: 0x3094,
  24874. vukatakana: 0x30F4,
  24875. w: 0x0077,
  24876. wacute: 0x1E83,
  24877. waekorean: 0x3159,
  24878. wahiragana: 0x308F,
  24879. wakatakana: 0x30EF,
  24880. wakatakanahalfwidth: 0xFF9C,
  24881. wakorean: 0x3158,
  24882. wasmallhiragana: 0x308E,
  24883. wasmallkatakana: 0x30EE,
  24884. wattosquare: 0x3357,
  24885. wavedash: 0x301C,
  24886. wavyunderscorevertical: 0xFE34,
  24887. wawarabic: 0x0648,
  24888. wawfinalarabic: 0xFEEE,
  24889. wawhamzaabovearabic: 0x0624,
  24890. wawhamzaabovefinalarabic: 0xFE86,
  24891. wbsquare: 0x33DD,
  24892. wcircle: 0x24E6,
  24893. wcircumflex: 0x0175,
  24894. wdieresis: 0x1E85,
  24895. wdotaccent: 0x1E87,
  24896. wdotbelow: 0x1E89,
  24897. wehiragana: 0x3091,
  24898. weierstrass: 0x2118,
  24899. wekatakana: 0x30F1,
  24900. wekorean: 0x315E,
  24901. weokorean: 0x315D,
  24902. wgrave: 0x1E81,
  24903. whitebullet: 0x25E6,
  24904. whitecircle: 0x25CB,
  24905. whitecircleinverse: 0x25D9,
  24906. whitecornerbracketleft: 0x300E,
  24907. whitecornerbracketleftvertical: 0xFE43,
  24908. whitecornerbracketright: 0x300F,
  24909. whitecornerbracketrightvertical: 0xFE44,
  24910. whitediamond: 0x25C7,
  24911. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24912. whitedownpointingsmalltriangle: 0x25BF,
  24913. whitedownpointingtriangle: 0x25BD,
  24914. whiteleftpointingsmalltriangle: 0x25C3,
  24915. whiteleftpointingtriangle: 0x25C1,
  24916. whitelenticularbracketleft: 0x3016,
  24917. whitelenticularbracketright: 0x3017,
  24918. whiterightpointingsmalltriangle: 0x25B9,
  24919. whiterightpointingtriangle: 0x25B7,
  24920. whitesmallsquare: 0x25AB,
  24921. whitesmilingface: 0x263A,
  24922. whitesquare: 0x25A1,
  24923. whitestar: 0x2606,
  24924. whitetelephone: 0x260F,
  24925. whitetortoiseshellbracketleft: 0x3018,
  24926. whitetortoiseshellbracketright: 0x3019,
  24927. whiteuppointingsmalltriangle: 0x25B5,
  24928. whiteuppointingtriangle: 0x25B3,
  24929. wihiragana: 0x3090,
  24930. wikatakana: 0x30F0,
  24931. wikorean: 0x315F,
  24932. wmonospace: 0xFF57,
  24933. wohiragana: 0x3092,
  24934. wokatakana: 0x30F2,
  24935. wokatakanahalfwidth: 0xFF66,
  24936. won: 0x20A9,
  24937. wonmonospace: 0xFFE6,
  24938. wowaenthai: 0x0E27,
  24939. wparen: 0x24B2,
  24940. wring: 0x1E98,
  24941. wsuperior: 0x02B7,
  24942. wturned: 0x028D,
  24943. wynn: 0x01BF,
  24944. x: 0x0078,
  24945. xabovecmb: 0x033D,
  24946. xbopomofo: 0x3112,
  24947. xcircle: 0x24E7,
  24948. xdieresis: 0x1E8D,
  24949. xdotaccent: 0x1E8B,
  24950. xeharmenian: 0x056D,
  24951. xi: 0x03BE,
  24952. xmonospace: 0xFF58,
  24953. xparen: 0x24B3,
  24954. xsuperior: 0x02E3,
  24955. y: 0x0079,
  24956. yaadosquare: 0x334E,
  24957. yabengali: 0x09AF,
  24958. yacute: 0x00FD,
  24959. yadeva: 0x092F,
  24960. yaekorean: 0x3152,
  24961. yagujarati: 0x0AAF,
  24962. yagurmukhi: 0x0A2F,
  24963. yahiragana: 0x3084,
  24964. yakatakana: 0x30E4,
  24965. yakatakanahalfwidth: 0xFF94,
  24966. yakorean: 0x3151,
  24967. yamakkanthai: 0x0E4E,
  24968. yasmallhiragana: 0x3083,
  24969. yasmallkatakana: 0x30E3,
  24970. yasmallkatakanahalfwidth: 0xFF6C,
  24971. yatcyrillic: 0x0463,
  24972. ycircle: 0x24E8,
  24973. ycircumflex: 0x0177,
  24974. ydieresis: 0x00FF,
  24975. ydotaccent: 0x1E8F,
  24976. ydotbelow: 0x1EF5,
  24977. yeharabic: 0x064A,
  24978. yehbarreearabic: 0x06D2,
  24979. yehbarreefinalarabic: 0xFBAF,
  24980. yehfinalarabic: 0xFEF2,
  24981. yehhamzaabovearabic: 0x0626,
  24982. yehhamzaabovefinalarabic: 0xFE8A,
  24983. yehhamzaaboveinitialarabic: 0xFE8B,
  24984. yehhamzaabovemedialarabic: 0xFE8C,
  24985. yehinitialarabic: 0xFEF3,
  24986. yehmedialarabic: 0xFEF4,
  24987. yehmeeminitialarabic: 0xFCDD,
  24988. yehmeemisolatedarabic: 0xFC58,
  24989. yehnoonfinalarabic: 0xFC94,
  24990. yehthreedotsbelowarabic: 0x06D1,
  24991. yekorean: 0x3156,
  24992. yen: 0x00A5,
  24993. yenmonospace: 0xFFE5,
  24994. yeokorean: 0x3155,
  24995. yeorinhieuhkorean: 0x3186,
  24996. yerahbenyomohebrew: 0x05AA,
  24997. yerahbenyomolefthebrew: 0x05AA,
  24998. yericyrillic: 0x044B,
  24999. yerudieresiscyrillic: 0x04F9,
  25000. yesieungkorean: 0x3181,
  25001. yesieungpansioskorean: 0x3183,
  25002. yesieungsioskorean: 0x3182,
  25003. yetivhebrew: 0x059A,
  25004. ygrave: 0x1EF3,
  25005. yhook: 0x01B4,
  25006. yhookabove: 0x1EF7,
  25007. yiarmenian: 0x0575,
  25008. yicyrillic: 0x0457,
  25009. yikorean: 0x3162,
  25010. yinyang: 0x262F,
  25011. yiwnarmenian: 0x0582,
  25012. ymonospace: 0xFF59,
  25013. yod: 0x05D9,
  25014. yoddagesh: 0xFB39,
  25015. yoddageshhebrew: 0xFB39,
  25016. yodhebrew: 0x05D9,
  25017. yodyodhebrew: 0x05F2,
  25018. yodyodpatahhebrew: 0xFB1F,
  25019. yohiragana: 0x3088,
  25020. yoikorean: 0x3189,
  25021. yokatakana: 0x30E8,
  25022. yokatakanahalfwidth: 0xFF96,
  25023. yokorean: 0x315B,
  25024. yosmallhiragana: 0x3087,
  25025. yosmallkatakana: 0x30E7,
  25026. yosmallkatakanahalfwidth: 0xFF6E,
  25027. yotgreek: 0x03F3,
  25028. yoyaekorean: 0x3188,
  25029. yoyakorean: 0x3187,
  25030. yoyakthai: 0x0E22,
  25031. yoyingthai: 0x0E0D,
  25032. yparen: 0x24B4,
  25033. ypogegrammeni: 0x037A,
  25034. ypogegrammenigreekcmb: 0x0345,
  25035. yr: 0x01A6,
  25036. yring: 0x1E99,
  25037. ysuperior: 0x02B8,
  25038. ytilde: 0x1EF9,
  25039. yturned: 0x028E,
  25040. yuhiragana: 0x3086,
  25041. yuikorean: 0x318C,
  25042. yukatakana: 0x30E6,
  25043. yukatakanahalfwidth: 0xFF95,
  25044. yukorean: 0x3160,
  25045. yusbigcyrillic: 0x046B,
  25046. yusbigiotifiedcyrillic: 0x046D,
  25047. yuslittlecyrillic: 0x0467,
  25048. yuslittleiotifiedcyrillic: 0x0469,
  25049. yusmallhiragana: 0x3085,
  25050. yusmallkatakana: 0x30E5,
  25051. yusmallkatakanahalfwidth: 0xFF6D,
  25052. yuyekorean: 0x318B,
  25053. yuyeokorean: 0x318A,
  25054. yyabengali: 0x09DF,
  25055. yyadeva: 0x095F,
  25056. z: 0x007A,
  25057. zaarmenian: 0x0566,
  25058. zacute: 0x017A,
  25059. zadeva: 0x095B,
  25060. zagurmukhi: 0x0A5B,
  25061. zaharabic: 0x0638,
  25062. zahfinalarabic: 0xFEC6,
  25063. zahinitialarabic: 0xFEC7,
  25064. zahiragana: 0x3056,
  25065. zahmedialarabic: 0xFEC8,
  25066. zainarabic: 0x0632,
  25067. zainfinalarabic: 0xFEB0,
  25068. zakatakana: 0x30B6,
  25069. zaqefgadolhebrew: 0x0595,
  25070. zaqefqatanhebrew: 0x0594,
  25071. zarqahebrew: 0x0598,
  25072. zayin: 0x05D6,
  25073. zayindagesh: 0xFB36,
  25074. zayindageshhebrew: 0xFB36,
  25075. zayinhebrew: 0x05D6,
  25076. zbopomofo: 0x3117,
  25077. zcaron: 0x017E,
  25078. zcircle: 0x24E9,
  25079. zcircumflex: 0x1E91,
  25080. zcurl: 0x0291,
  25081. zdot: 0x017C,
  25082. zdotaccent: 0x017C,
  25083. zdotbelow: 0x1E93,
  25084. zecyrillic: 0x0437,
  25085. zedescendercyrillic: 0x0499,
  25086. zedieresiscyrillic: 0x04DF,
  25087. zehiragana: 0x305C,
  25088. zekatakana: 0x30BC,
  25089. zero: 0x0030,
  25090. zeroarabic: 0x0660,
  25091. zerobengali: 0x09E6,
  25092. zerodeva: 0x0966,
  25093. zerogujarati: 0x0AE6,
  25094. zerogurmukhi: 0x0A66,
  25095. zerohackarabic: 0x0660,
  25096. zeroinferior: 0x2080,
  25097. zeromonospace: 0xFF10,
  25098. zerooldstyle: 0xF730,
  25099. zeropersian: 0x06F0,
  25100. zerosuperior: 0x2070,
  25101. zerothai: 0x0E50,
  25102. zerowidthjoiner: 0xFEFF,
  25103. zerowidthnonjoiner: 0x200C,
  25104. zerowidthspace: 0x200B,
  25105. zeta: 0x03B6,
  25106. zhbopomofo: 0x3113,
  25107. zhearmenian: 0x056A,
  25108. zhebrevecyrillic: 0x04C2,
  25109. zhecyrillic: 0x0436,
  25110. zhedescendercyrillic: 0x0497,
  25111. zhedieresiscyrillic: 0x04DD,
  25112. zihiragana: 0x3058,
  25113. zikatakana: 0x30B8,
  25114. zinorhebrew: 0x05AE,
  25115. zlinebelow: 0x1E95,
  25116. zmonospace: 0xFF5A,
  25117. zohiragana: 0x305E,
  25118. zokatakana: 0x30BE,
  25119. zparen: 0x24B5,
  25120. zretroflexhook: 0x0290,
  25121. zstroke: 0x01B6,
  25122. zuhiragana: 0x305A,
  25123. zukatakana: 0x30BA,
  25124. '.notdef': 0x0000
  25125. };
  25126. var DingbatsGlyphsUnicode = {
  25127. space: 0x0020,
  25128. a1: 0x2701,
  25129. a2: 0x2702,
  25130. a202: 0x2703,
  25131. a3: 0x2704,
  25132. a4: 0x260E,
  25133. a5: 0x2706,
  25134. a119: 0x2707,
  25135. a118: 0x2708,
  25136. a117: 0x2709,
  25137. a11: 0x261B,
  25138. a12: 0x261E,
  25139. a13: 0x270C,
  25140. a14: 0x270D,
  25141. a15: 0x270E,
  25142. a16: 0x270F,
  25143. a105: 0x2710,
  25144. a17: 0x2711,
  25145. a18: 0x2712,
  25146. a19: 0x2713,
  25147. a20: 0x2714,
  25148. a21: 0x2715,
  25149. a22: 0x2716,
  25150. a23: 0x2717,
  25151. a24: 0x2718,
  25152. a25: 0x2719,
  25153. a26: 0x271A,
  25154. a27: 0x271B,
  25155. a28: 0x271C,
  25156. a6: 0x271D,
  25157. a7: 0x271E,
  25158. a8: 0x271F,
  25159. a9: 0x2720,
  25160. a10: 0x2721,
  25161. a29: 0x2722,
  25162. a30: 0x2723,
  25163. a31: 0x2724,
  25164. a32: 0x2725,
  25165. a33: 0x2726,
  25166. a34: 0x2727,
  25167. a35: 0x2605,
  25168. a36: 0x2729,
  25169. a37: 0x272A,
  25170. a38: 0x272B,
  25171. a39: 0x272C,
  25172. a40: 0x272D,
  25173. a41: 0x272E,
  25174. a42: 0x272F,
  25175. a43: 0x2730,
  25176. a44: 0x2731,
  25177. a45: 0x2732,
  25178. a46: 0x2733,
  25179. a47: 0x2734,
  25180. a48: 0x2735,
  25181. a49: 0x2736,
  25182. a50: 0x2737,
  25183. a51: 0x2738,
  25184. a52: 0x2739,
  25185. a53: 0x273A,
  25186. a54: 0x273B,
  25187. a55: 0x273C,
  25188. a56: 0x273D,
  25189. a57: 0x273E,
  25190. a58: 0x273F,
  25191. a59: 0x2740,
  25192. a60: 0x2741,
  25193. a61: 0x2742,
  25194. a62: 0x2743,
  25195. a63: 0x2744,
  25196. a64: 0x2745,
  25197. a65: 0x2746,
  25198. a66: 0x2747,
  25199. a67: 0x2748,
  25200. a68: 0x2749,
  25201. a69: 0x274A,
  25202. a70: 0x274B,
  25203. a71: 0x25CF,
  25204. a72: 0x274D,
  25205. a73: 0x25A0,
  25206. a74: 0x274F,
  25207. a203: 0x2750,
  25208. a75: 0x2751,
  25209. a204: 0x2752,
  25210. a76: 0x25B2,
  25211. a77: 0x25BC,
  25212. a78: 0x25C6,
  25213. a79: 0x2756,
  25214. a81: 0x25D7,
  25215. a82: 0x2758,
  25216. a83: 0x2759,
  25217. a84: 0x275A,
  25218. a97: 0x275B,
  25219. a98: 0x275C,
  25220. a99: 0x275D,
  25221. a100: 0x275E,
  25222. a101: 0x2761,
  25223. a102: 0x2762,
  25224. a103: 0x2763,
  25225. a104: 0x2764,
  25226. a106: 0x2765,
  25227. a107: 0x2766,
  25228. a108: 0x2767,
  25229. a112: 0x2663,
  25230. a111: 0x2666,
  25231. a110: 0x2665,
  25232. a109: 0x2660,
  25233. a120: 0x2460,
  25234. a121: 0x2461,
  25235. a122: 0x2462,
  25236. a123: 0x2463,
  25237. a124: 0x2464,
  25238. a125: 0x2465,
  25239. a126: 0x2466,
  25240. a127: 0x2467,
  25241. a128: 0x2468,
  25242. a129: 0x2469,
  25243. a130: 0x2776,
  25244. a131: 0x2777,
  25245. a132: 0x2778,
  25246. a133: 0x2779,
  25247. a134: 0x277A,
  25248. a135: 0x277B,
  25249. a136: 0x277C,
  25250. a137: 0x277D,
  25251. a138: 0x277E,
  25252. a139: 0x277F,
  25253. a140: 0x2780,
  25254. a141: 0x2781,
  25255. a142: 0x2782,
  25256. a143: 0x2783,
  25257. a144: 0x2784,
  25258. a145: 0x2785,
  25259. a146: 0x2786,
  25260. a147: 0x2787,
  25261. a148: 0x2788,
  25262. a149: 0x2789,
  25263. a150: 0x278A,
  25264. a151: 0x278B,
  25265. a152: 0x278C,
  25266. a153: 0x278D,
  25267. a154: 0x278E,
  25268. a155: 0x278F,
  25269. a156: 0x2790,
  25270. a157: 0x2791,
  25271. a158: 0x2792,
  25272. a159: 0x2793,
  25273. a160: 0x2794,
  25274. a161: 0x2192,
  25275. a163: 0x2194,
  25276. a164: 0x2195,
  25277. a196: 0x2798,
  25278. a165: 0x2799,
  25279. a192: 0x279A,
  25280. a166: 0x279B,
  25281. a167: 0x279C,
  25282. a168: 0x279D,
  25283. a169: 0x279E,
  25284. a170: 0x279F,
  25285. a171: 0x27A0,
  25286. a172: 0x27A1,
  25287. a173: 0x27A2,
  25288. a162: 0x27A3,
  25289. a174: 0x27A4,
  25290. a175: 0x27A5,
  25291. a176: 0x27A6,
  25292. a177: 0x27A7,
  25293. a178: 0x27A8,
  25294. a179: 0x27A9,
  25295. a193: 0x27AA,
  25296. a180: 0x27AB,
  25297. a199: 0x27AC,
  25298. a181: 0x27AD,
  25299. a200: 0x27AE,
  25300. a182: 0x27AF,
  25301. a201: 0x27B1,
  25302. a183: 0x27B2,
  25303. a184: 0x27B3,
  25304. a197: 0x27B4,
  25305. a185: 0x27B5,
  25306. a194: 0x27B6,
  25307. a198: 0x27B7,
  25308. a186: 0x27B8,
  25309. a195: 0x27B9,
  25310. a187: 0x27BA,
  25311. a188: 0x27BB,
  25312. a189: 0x27BC,
  25313. a190: 0x27BD,
  25314. a191: 0x27BE,
  25315. a89: 0x2768, // 0xF8D7
  25316. a90: 0x2769, // 0xF8D8
  25317. a93: 0x276A, // 0xF8D9
  25318. a94: 0x276B, // 0xF8DA
  25319. a91: 0x276C, // 0xF8DB
  25320. a92: 0x276D, // 0xF8DC
  25321. a205: 0x276E, // 0xF8DD
  25322. a85: 0x276F, // 0xF8DE
  25323. a206: 0x2770, // 0xF8DF
  25324. a86: 0x2771, // 0xF8E0
  25325. a87: 0x2772, // 0xF8E1
  25326. a88: 0x2773, // 0xF8E2
  25327. a95: 0x2774, // 0xF8E3
  25328. a96: 0x2775, // 0xF8E4
  25329. '.notdef': 0x0000
  25330. };
  25331. var PDFImage = (function PDFImageClosure() {
  25332. /**
  25333. * Decode the image in the main thread if it supported. Resovles the promise
  25334. * when the image data is ready.
  25335. */
  25336. function handleImageData(handler, xref, res, image) {
  25337. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  25338. // For natively supported jpegs send them to the main thread for decoding.
  25339. var dict = image.dict;
  25340. var colorSpace = dict.get('ColorSpace', 'CS');
  25341. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25342. var numComps = colorSpace.numComps;
  25343. var decodePromise = handler.sendWithPromise('JpegDecode',
  25344. [image.getIR(), numComps]);
  25345. return decodePromise.then(function (message) {
  25346. var data = message.data;
  25347. return new Stream(data, 0, data.length, image.dict);
  25348. });
  25349. } else {
  25350. return Promise.resolve(image);
  25351. }
  25352. }
  25353. /**
  25354. * Decode and clamp a value. The formula is different from the spec because we
  25355. * don't decode to float range [0,1], we decode it in the [0,max] range.
  25356. */
  25357. function decodeAndClamp(value, addend, coefficient, max) {
  25358. value = addend + value * coefficient;
  25359. // Clamp the value to the range
  25360. return (value < 0 ? 0 : (value > max ? max : value));
  25361. }
  25362. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  25363. this.image = image;
  25364. var dict = image.dict;
  25365. if (dict.has('Filter')) {
  25366. var filter = dict.get('Filter').name;
  25367. if (filter === 'JPXDecode') {
  25368. var jpxImage = new JpxImage();
  25369. jpxImage.parseImageProperties(image.stream);
  25370. image.stream.reset();
  25371. image.bitsPerComponent = jpxImage.bitsPerComponent;
  25372. image.numComps = jpxImage.componentsCount;
  25373. } else if (filter === 'JBIG2Decode') {
  25374. image.bitsPerComponent = 1;
  25375. image.numComps = 1;
  25376. }
  25377. }
  25378. // TODO cache rendered images?
  25379. this.width = dict.get('Width', 'W');
  25380. this.height = dict.get('Height', 'H');
  25381. if (this.width < 1 || this.height < 1) {
  25382. error('Invalid image width: ' + this.width + ' or height: ' +
  25383. this.height);
  25384. }
  25385. this.interpolate = dict.get('Interpolate', 'I') || false;
  25386. this.imageMask = dict.get('ImageMask', 'IM') || false;
  25387. this.matte = dict.get('Matte') || false;
  25388. var bitsPerComponent = image.bitsPerComponent;
  25389. if (!bitsPerComponent) {
  25390. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  25391. if (!bitsPerComponent) {
  25392. if (this.imageMask) {
  25393. bitsPerComponent = 1;
  25394. } else {
  25395. error('Bits per component missing in image: ' + this.imageMask);
  25396. }
  25397. }
  25398. }
  25399. this.bpc = bitsPerComponent;
  25400. if (!this.imageMask) {
  25401. var colorSpace = dict.get('ColorSpace', 'CS');
  25402. if (!colorSpace) {
  25403. info('JPX images (which do not require color spaces)');
  25404. switch (image.numComps) {
  25405. case 1:
  25406. colorSpace = Name.get('DeviceGray');
  25407. break;
  25408. case 3:
  25409. colorSpace = Name.get('DeviceRGB');
  25410. break;
  25411. case 4:
  25412. colorSpace = Name.get('DeviceCMYK');
  25413. break;
  25414. default:
  25415. error('JPX images with ' + this.numComps +
  25416. ' color components not supported.');
  25417. }
  25418. }
  25419. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25420. this.numComps = this.colorSpace.numComps;
  25421. }
  25422. this.decode = dict.get('Decode', 'D');
  25423. this.needsDecode = false;
  25424. if (this.decode &&
  25425. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  25426. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  25427. this.needsDecode = true;
  25428. // Do some preprocessing to avoid more math.
  25429. var max = (1 << bitsPerComponent) - 1;
  25430. this.decodeCoefficients = [];
  25431. this.decodeAddends = [];
  25432. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  25433. var dmin = this.decode[i];
  25434. var dmax = this.decode[i + 1];
  25435. this.decodeCoefficients[j] = dmax - dmin;
  25436. this.decodeAddends[j] = max * dmin;
  25437. }
  25438. }
  25439. if (smask) {
  25440. this.smask = new PDFImage(xref, res, smask, false);
  25441. } else if (mask) {
  25442. if (isStream(mask)) {
  25443. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  25444. if (!imageMask) {
  25445. warn('Ignoring /Mask in image without /ImageMask.');
  25446. } else {
  25447. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  25448. }
  25449. } else {
  25450. // Color key mask (just an array).
  25451. this.mask = mask;
  25452. }
  25453. }
  25454. }
  25455. /**
  25456. * Handles processing of image data and returns the Promise that is resolved
  25457. * with a PDFImage when the image is ready to be used.
  25458. */
  25459. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  25460. res, image, inline) {
  25461. var imagePromise = handleImageData(handler, xref, res, image);
  25462. var smaskPromise;
  25463. var maskPromise;
  25464. var smask = image.dict.get('SMask');
  25465. var mask = image.dict.get('Mask');
  25466. if (smask) {
  25467. smaskPromise = handleImageData(handler, xref, res, smask);
  25468. maskPromise = Promise.resolve(null);
  25469. } else {
  25470. smaskPromise = Promise.resolve(null);
  25471. if (mask) {
  25472. if (isStream(mask)) {
  25473. maskPromise = handleImageData(handler, xref, res, mask);
  25474. } else if (isArray(mask)) {
  25475. maskPromise = Promise.resolve(mask);
  25476. } else {
  25477. warn('Unsupported mask format.');
  25478. maskPromise = Promise.resolve(null);
  25479. }
  25480. } else {
  25481. maskPromise = Promise.resolve(null);
  25482. }
  25483. }
  25484. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25485. function(results) {
  25486. var imageData = results[0];
  25487. var smaskData = results[1];
  25488. var maskData = results[2];
  25489. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25490. });
  25491. };
  25492. /**
  25493. * Resize an image using the nearest neighbor algorithm. Currently only
  25494. * supports one and three component images.
  25495. * @param {TypedArray} pixels The original image with one component.
  25496. * @param {Number} bpc Number of bits per component.
  25497. * @param {Number} components Number of color components, 1 or 3 is supported.
  25498. * @param {Number} w1 Original width.
  25499. * @param {Number} h1 Original height.
  25500. * @param {Number} w2 New width.
  25501. * @param {Number} h2 New height.
  25502. * @param {TypedArray} dest (Optional) The destination buffer.
  25503. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25504. * @return {TypedArray} Resized image data.
  25505. */
  25506. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25507. w1, h1, w2, h2, dest, alpha01) {
  25508. if (components !== 1 && components !== 3) {
  25509. error('Unsupported component count for resizing.');
  25510. }
  25511. var length = w2 * h2 * components;
  25512. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25513. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25514. var xRatio = w1 / w2;
  25515. var yRatio = h1 / h2;
  25516. var i, j, py, newIndex = 0, oldIndex;
  25517. var xScaled = new Uint16Array(w2);
  25518. var w1Scanline = w1 * components;
  25519. if (alpha01 !== 1) {
  25520. alpha01 = 0;
  25521. }
  25522. for (j = 0; j < w2; j++) {
  25523. xScaled[j] = Math.floor(j * xRatio) * components;
  25524. }
  25525. if (components === 1) {
  25526. for (i = 0; i < h2; i++) {
  25527. py = Math.floor(i * yRatio) * w1Scanline;
  25528. for (j = 0; j < w2; j++) {
  25529. oldIndex = py + xScaled[j];
  25530. temp[newIndex++] = pixels[oldIndex];
  25531. }
  25532. }
  25533. } else if (components === 3) {
  25534. for (i = 0; i < h2; i++) {
  25535. py = Math.floor(i * yRatio) * w1Scanline;
  25536. for (j = 0; j < w2; j++) {
  25537. oldIndex = py + xScaled[j];
  25538. temp[newIndex++] = pixels[oldIndex++];
  25539. temp[newIndex++] = pixels[oldIndex++];
  25540. temp[newIndex++] = pixels[oldIndex++];
  25541. newIndex += alpha01;
  25542. }
  25543. }
  25544. }
  25545. return temp;
  25546. };
  25547. PDFImage.createMask =
  25548. function PDFImage_createMask(imgArray, width, height,
  25549. imageIsFromDecodeStream, inverseDecode) {
  25550. // |imgArray| might not contain full data for every pixel of the mask, so
  25551. // we need to distinguish between |computedLength| and |actualLength|.
  25552. // In particular, if inverseDecode is true, then the array we return must
  25553. // have a length of |computedLength|.
  25554. var computedLength = ((width + 7) >> 3) * height;
  25555. var actualLength = imgArray.byteLength;
  25556. var haveFullData = computedLength === actualLength;
  25557. var data, i;
  25558. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25559. // imgArray came from a DecodeStream and its data is in an appropriate
  25560. // form, so we can just transfer it.
  25561. data = imgArray;
  25562. } else if (!inverseDecode) {
  25563. data = new Uint8Array(actualLength);
  25564. data.set(imgArray);
  25565. } else {
  25566. data = new Uint8Array(computedLength);
  25567. data.set(imgArray);
  25568. for (i = actualLength; i < computedLength; i++) {
  25569. data[i] = 0xff;
  25570. }
  25571. }
  25572. // If necessary, invert the original mask data (but not any extra we might
  25573. // have added above). It's safe to modify the array -- whether it's the
  25574. // original or a copy, we're about to transfer it anyway, so nothing else
  25575. // in this thread can be relying on its contents.
  25576. if (inverseDecode) {
  25577. for (i = 0; i < actualLength; i++) {
  25578. data[i] = ~data[i];
  25579. }
  25580. }
  25581. return {data: data, width: width, height: height};
  25582. };
  25583. PDFImage.prototype = {
  25584. get drawWidth() {
  25585. return Math.max(this.width,
  25586. this.smask && this.smask.width || 0,
  25587. this.mask && this.mask.width || 0);
  25588. },
  25589. get drawHeight() {
  25590. return Math.max(this.height,
  25591. this.smask && this.smask.height || 0,
  25592. this.mask && this.mask.height || 0);
  25593. },
  25594. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25595. var bpc = this.bpc;
  25596. var numComps = this.numComps;
  25597. var decodeAddends = this.decodeAddends;
  25598. var decodeCoefficients = this.decodeCoefficients;
  25599. var max = (1 << bpc) - 1;
  25600. var i, ii;
  25601. if (bpc === 1) {
  25602. // If the buffer needed decode that means it just needs to be inverted.
  25603. for (i = 0, ii = buffer.length; i < ii; i++) {
  25604. buffer[i] = +!(buffer[i]);
  25605. }
  25606. return;
  25607. }
  25608. var index = 0;
  25609. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25610. for (var j = 0; j < numComps; j++) {
  25611. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25612. decodeCoefficients[j], max);
  25613. index++;
  25614. }
  25615. }
  25616. },
  25617. getComponents: function PDFImage_getComponents(buffer) {
  25618. var bpc = this.bpc;
  25619. // This image doesn't require any extra work.
  25620. if (bpc === 8) {
  25621. return buffer;
  25622. }
  25623. var width = this.width;
  25624. var height = this.height;
  25625. var numComps = this.numComps;
  25626. var length = width * height * numComps;
  25627. var bufferPos = 0;
  25628. var output = (bpc <= 8 ? new Uint8Array(length) :
  25629. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25630. var rowComps = width * numComps;
  25631. var max = (1 << bpc) - 1;
  25632. var i = 0, ii, buf;
  25633. if (bpc === 1) {
  25634. // Optimization for reading 1 bpc images.
  25635. var mask, loop1End, loop2End;
  25636. for (var j = 0; j < height; j++) {
  25637. loop1End = i + (rowComps & ~7);
  25638. loop2End = i + rowComps;
  25639. // unroll loop for all full bytes
  25640. while (i < loop1End) {
  25641. buf = buffer[bufferPos++];
  25642. output[i] = (buf >> 7) & 1;
  25643. output[i + 1] = (buf >> 6) & 1;
  25644. output[i + 2] = (buf >> 5) & 1;
  25645. output[i + 3] = (buf >> 4) & 1;
  25646. output[i + 4] = (buf >> 3) & 1;
  25647. output[i + 5] = (buf >> 2) & 1;
  25648. output[i + 6] = (buf >> 1) & 1;
  25649. output[i + 7] = buf & 1;
  25650. i += 8;
  25651. }
  25652. // handle remaing bits
  25653. if (i < loop2End) {
  25654. buf = buffer[bufferPos++];
  25655. mask = 128;
  25656. while (i < loop2End) {
  25657. output[i++] = +!!(buf & mask);
  25658. mask >>= 1;
  25659. }
  25660. }
  25661. }
  25662. } else {
  25663. // The general case that handles all other bpc values.
  25664. var bits = 0;
  25665. buf = 0;
  25666. for (i = 0, ii = length; i < ii; ++i) {
  25667. if (i % rowComps === 0) {
  25668. buf = 0;
  25669. bits = 0;
  25670. }
  25671. while (bits < bpc) {
  25672. buf = (buf << 8) | buffer[bufferPos++];
  25673. bits += 8;
  25674. }
  25675. var remainingBits = bits - bpc;
  25676. var value = buf >> remainingBits;
  25677. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25678. buf = buf & ((1 << remainingBits) - 1);
  25679. bits = remainingBits;
  25680. }
  25681. }
  25682. return output;
  25683. },
  25684. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25685. actualHeight, image) {
  25686. var smask = this.smask;
  25687. var mask = this.mask;
  25688. var alphaBuf, sw, sh, i, ii, j;
  25689. if (smask) {
  25690. sw = smask.width;
  25691. sh = smask.height;
  25692. alphaBuf = new Uint8Array(sw * sh);
  25693. smask.fillGrayBuffer(alphaBuf);
  25694. if (sw !== width || sh !== height) {
  25695. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25696. height);
  25697. }
  25698. } else if (mask) {
  25699. if (mask instanceof PDFImage) {
  25700. sw = mask.width;
  25701. sh = mask.height;
  25702. alphaBuf = new Uint8Array(sw * sh);
  25703. mask.numComps = 1;
  25704. mask.fillGrayBuffer(alphaBuf);
  25705. // Need to invert values in rgbaBuf
  25706. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25707. alphaBuf[i] = 255 - alphaBuf[i];
  25708. }
  25709. if (sw !== width || sh !== height) {
  25710. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25711. height);
  25712. }
  25713. } else if (isArray(mask)) {
  25714. // Color key mask: if any of the compontents are outside the range
  25715. // then they should be painted.
  25716. alphaBuf = new Uint8Array(width * height);
  25717. var numComps = this.numComps;
  25718. for (i = 0, ii = width * height; i < ii; ++i) {
  25719. var opacity = 0;
  25720. var imageOffset = i * numComps;
  25721. for (j = 0; j < numComps; ++j) {
  25722. var color = image[imageOffset + j];
  25723. var maskOffset = j * 2;
  25724. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25725. opacity = 255;
  25726. break;
  25727. }
  25728. }
  25729. alphaBuf[i] = opacity;
  25730. }
  25731. } else {
  25732. error('Unknown mask format.');
  25733. }
  25734. }
  25735. if (alphaBuf) {
  25736. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25737. rgbaBuf[j] = alphaBuf[i];
  25738. }
  25739. } else {
  25740. // No mask.
  25741. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25742. rgbaBuf[j] = 255;
  25743. }
  25744. }
  25745. },
  25746. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25747. var matte = this.smask && this.smask.matte;
  25748. if (!matte) {
  25749. return;
  25750. }
  25751. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25752. var matteR = matteRgb[0];
  25753. var matteG = matteRgb[1];
  25754. var matteB = matteRgb[2];
  25755. var length = width * height * 4;
  25756. var r, g, b;
  25757. for (var i = 0; i < length; i += 4) {
  25758. var alpha = buffer[i + 3];
  25759. if (alpha === 0) {
  25760. // according formula we have to get Infinity in all components
  25761. // making it white (typical paper color) should be okay
  25762. buffer[i] = 255;
  25763. buffer[i + 1] = 255;
  25764. buffer[i + 2] = 255;
  25765. continue;
  25766. }
  25767. var k = 255 / alpha;
  25768. r = (buffer[i] - matteR) * k + matteR;
  25769. g = (buffer[i + 1] - matteG) * k + matteG;
  25770. b = (buffer[i + 2] - matteB) * k + matteB;
  25771. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25772. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25773. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25774. }
  25775. },
  25776. createImageData: function PDFImage_createImageData(forceRGBA) {
  25777. var drawWidth = this.drawWidth;
  25778. var drawHeight = this.drawHeight;
  25779. var imgData = { // other fields are filled in below
  25780. width: drawWidth,
  25781. height: drawHeight
  25782. };
  25783. var numComps = this.numComps;
  25784. var originalWidth = this.width;
  25785. var originalHeight = this.height;
  25786. var bpc = this.bpc;
  25787. // Rows start at byte boundary.
  25788. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25789. var imgArray;
  25790. if (!forceRGBA) {
  25791. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25792. // without any complications, we pass a same-sized copy to the main
  25793. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25794. // of memory for many scanned documents. It's also much faster.
  25795. //
  25796. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25797. // complications, we avoid expanding by 1.333x to RGBA form.
  25798. var kind;
  25799. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25800. kind = ImageKind.GRAYSCALE_1BPP;
  25801. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25802. !this.needsDecode) {
  25803. kind = ImageKind.RGB_24BPP;
  25804. }
  25805. if (kind && !this.smask && !this.mask &&
  25806. drawWidth === originalWidth && drawHeight === originalHeight) {
  25807. imgData.kind = kind;
  25808. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25809. // If imgArray came from a DecodeStream, we're safe to transfer it
  25810. // (and thus neuter it) because it will constitute the entire
  25811. // DecodeStream's data. But if it came from a Stream, we need to
  25812. // copy it because it'll only be a portion of the Stream's data, and
  25813. // the rest will be read later on.
  25814. if (this.image instanceof DecodeStream) {
  25815. imgData.data = imgArray;
  25816. } else {
  25817. var newArray = new Uint8Array(imgArray.length);
  25818. newArray.set(imgArray);
  25819. imgData.data = newArray;
  25820. }
  25821. if (this.needsDecode) {
  25822. // Invert the buffer (which must be grayscale if we reached here).
  25823. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25824. var buffer = imgData.data;
  25825. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25826. buffer[i] ^= 0xff;
  25827. }
  25828. }
  25829. return imgData;
  25830. }
  25831. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  25832. (this.colorSpace.name === 'DeviceGray' ||
  25833. this.colorSpace.name === 'DeviceRGB' ||
  25834. this.colorSpace.name === 'DeviceCMYK')) {
  25835. imgData.kind = ImageKind.RGB_24BPP;
  25836. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25837. drawWidth, drawHeight, true);
  25838. return imgData;
  25839. }
  25840. }
  25841. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25842. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25843. var actualHeight = 0 | (imgArray.length / rowBytes *
  25844. drawHeight / originalHeight);
  25845. var comps = this.getComponents(imgArray);
  25846. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25847. // more compact RGB_24BPP form if allowable.
  25848. var alpha01, maybeUndoPreblend;
  25849. if (!forceRGBA && !this.smask && !this.mask) {
  25850. imgData.kind = ImageKind.RGB_24BPP;
  25851. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25852. alpha01 = 0;
  25853. maybeUndoPreblend = false;
  25854. } else {
  25855. imgData.kind = ImageKind.RGBA_32BPP;
  25856. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25857. alpha01 = 1;
  25858. maybeUndoPreblend = true;
  25859. // Color key masking (opacity) must be performed before decoding.
  25860. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25861. comps);
  25862. }
  25863. if (this.needsDecode) {
  25864. this.decodeBuffer(comps);
  25865. }
  25866. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25867. drawWidth, drawHeight, actualHeight, bpc, comps,
  25868. alpha01);
  25869. if (maybeUndoPreblend) {
  25870. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25871. }
  25872. return imgData;
  25873. },
  25874. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25875. var numComps = this.numComps;
  25876. if (numComps !== 1) {
  25877. error('Reading gray scale from a color image: ' + numComps);
  25878. }
  25879. var width = this.width;
  25880. var height = this.height;
  25881. var bpc = this.bpc;
  25882. // rows start at byte boundary
  25883. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25884. var imgArray = this.getImageBytes(height * rowBytes);
  25885. var comps = this.getComponents(imgArray);
  25886. var i, length;
  25887. if (bpc === 1) {
  25888. // inline decoding (= inversion) for 1 bpc images
  25889. length = width * height;
  25890. if (this.needsDecode) {
  25891. // invert and scale to {0, 255}
  25892. for (i = 0; i < length; ++i) {
  25893. buffer[i] = (comps[i] - 1) & 255;
  25894. }
  25895. } else {
  25896. // scale to {0, 255}
  25897. for (i = 0; i < length; ++i) {
  25898. buffer[i] = (-comps[i]) & 255;
  25899. }
  25900. }
  25901. return;
  25902. }
  25903. if (this.needsDecode) {
  25904. this.decodeBuffer(comps);
  25905. }
  25906. length = width * height;
  25907. // we aren't using a colorspace so we need to scale the value
  25908. var scale = 255 / ((1 << bpc) - 1);
  25909. for (i = 0; i < length; ++i) {
  25910. buffer[i] = (scale * comps[i]) | 0;
  25911. }
  25912. },
  25913. getImageBytes: function PDFImage_getImageBytes(length,
  25914. drawWidth, drawHeight,
  25915. forceRGB) {
  25916. this.image.reset();
  25917. this.image.drawWidth = drawWidth || this.width;
  25918. this.image.drawHeight = drawHeight || this.height;
  25919. this.image.forceRGB = !!forceRGB;
  25920. return this.image.getBytes(length);
  25921. }
  25922. };
  25923. return PDFImage;
  25924. })();
  25925. // The Metrics object contains glyph widths (in glyph space units).
  25926. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25927. // space unit corresponds to 1/1000th of text space unit.
  25928. var Metrics = {
  25929. 'Courier': 600,
  25930. 'Courier-Bold': 600,
  25931. 'Courier-BoldOblique': 600,
  25932. 'Courier-Oblique': 600,
  25933. 'Helvetica' : {
  25934. 'space': 278,
  25935. 'exclam': 278,
  25936. 'quotedbl': 355,
  25937. 'numbersign': 556,
  25938. 'dollar': 556,
  25939. 'percent': 889,
  25940. 'ampersand': 667,
  25941. 'quoteright': 222,
  25942. 'parenleft': 333,
  25943. 'parenright': 333,
  25944. 'asterisk': 389,
  25945. 'plus': 584,
  25946. 'comma': 278,
  25947. 'hyphen': 333,
  25948. 'period': 278,
  25949. 'slash': 278,
  25950. 'zero': 556,
  25951. 'one': 556,
  25952. 'two': 556,
  25953. 'three': 556,
  25954. 'four': 556,
  25955. 'five': 556,
  25956. 'six': 556,
  25957. 'seven': 556,
  25958. 'eight': 556,
  25959. 'nine': 556,
  25960. 'colon': 278,
  25961. 'semicolon': 278,
  25962. 'less': 584,
  25963. 'equal': 584,
  25964. 'greater': 584,
  25965. 'question': 556,
  25966. 'at': 1015,
  25967. 'A': 667,
  25968. 'B': 667,
  25969. 'C': 722,
  25970. 'D': 722,
  25971. 'E': 667,
  25972. 'F': 611,
  25973. 'G': 778,
  25974. 'H': 722,
  25975. 'I': 278,
  25976. 'J': 500,
  25977. 'K': 667,
  25978. 'L': 556,
  25979. 'M': 833,
  25980. 'N': 722,
  25981. 'O': 778,
  25982. 'P': 667,
  25983. 'Q': 778,
  25984. 'R': 722,
  25985. 'S': 667,
  25986. 'T': 611,
  25987. 'U': 722,
  25988. 'V': 667,
  25989. 'W': 944,
  25990. 'X': 667,
  25991. 'Y': 667,
  25992. 'Z': 611,
  25993. 'bracketleft': 278,
  25994. 'backslash': 278,
  25995. 'bracketright': 278,
  25996. 'asciicircum': 469,
  25997. 'underscore': 556,
  25998. 'quoteleft': 222,
  25999. 'a': 556,
  26000. 'b': 556,
  26001. 'c': 500,
  26002. 'd': 556,
  26003. 'e': 556,
  26004. 'f': 278,
  26005. 'g': 556,
  26006. 'h': 556,
  26007. 'i': 222,
  26008. 'j': 222,
  26009. 'k': 500,
  26010. 'l': 222,
  26011. 'm': 833,
  26012. 'n': 556,
  26013. 'o': 556,
  26014. 'p': 556,
  26015. 'q': 556,
  26016. 'r': 333,
  26017. 's': 500,
  26018. 't': 278,
  26019. 'u': 556,
  26020. 'v': 500,
  26021. 'w': 722,
  26022. 'x': 500,
  26023. 'y': 500,
  26024. 'z': 500,
  26025. 'braceleft': 334,
  26026. 'bar': 260,
  26027. 'braceright': 334,
  26028. 'asciitilde': 584,
  26029. 'exclamdown': 333,
  26030. 'cent': 556,
  26031. 'sterling': 556,
  26032. 'fraction': 167,
  26033. 'yen': 556,
  26034. 'florin': 556,
  26035. 'section': 556,
  26036. 'currency': 556,
  26037. 'quotesingle': 191,
  26038. 'quotedblleft': 333,
  26039. 'guillemotleft': 556,
  26040. 'guilsinglleft': 333,
  26041. 'guilsinglright': 333,
  26042. 'fi': 500,
  26043. 'fl': 500,
  26044. 'endash': 556,
  26045. 'dagger': 556,
  26046. 'daggerdbl': 556,
  26047. 'periodcentered': 278,
  26048. 'paragraph': 537,
  26049. 'bullet': 350,
  26050. 'quotesinglbase': 222,
  26051. 'quotedblbase': 333,
  26052. 'quotedblright': 333,
  26053. 'guillemotright': 556,
  26054. 'ellipsis': 1000,
  26055. 'perthousand': 1000,
  26056. 'questiondown': 611,
  26057. 'grave': 333,
  26058. 'acute': 333,
  26059. 'circumflex': 333,
  26060. 'tilde': 333,
  26061. 'macron': 333,
  26062. 'breve': 333,
  26063. 'dotaccent': 333,
  26064. 'dieresis': 333,
  26065. 'ring': 333,
  26066. 'cedilla': 333,
  26067. 'hungarumlaut': 333,
  26068. 'ogonek': 333,
  26069. 'caron': 333,
  26070. 'emdash': 1000,
  26071. 'AE': 1000,
  26072. 'ordfeminine': 370,
  26073. 'Lslash': 556,
  26074. 'Oslash': 778,
  26075. 'OE': 1000,
  26076. 'ordmasculine': 365,
  26077. 'ae': 889,
  26078. 'dotlessi': 278,
  26079. 'lslash': 222,
  26080. 'oslash': 611,
  26081. 'oe': 944,
  26082. 'germandbls': 611,
  26083. 'Idieresis': 278,
  26084. 'eacute': 556,
  26085. 'abreve': 556,
  26086. 'uhungarumlaut': 556,
  26087. 'ecaron': 556,
  26088. 'Ydieresis': 667,
  26089. 'divide': 584,
  26090. 'Yacute': 667,
  26091. 'Acircumflex': 667,
  26092. 'aacute': 556,
  26093. 'Ucircumflex': 722,
  26094. 'yacute': 500,
  26095. 'scommaaccent': 500,
  26096. 'ecircumflex': 556,
  26097. 'Uring': 722,
  26098. 'Udieresis': 722,
  26099. 'aogonek': 556,
  26100. 'Uacute': 722,
  26101. 'uogonek': 556,
  26102. 'Edieresis': 667,
  26103. 'Dcroat': 722,
  26104. 'commaaccent': 250,
  26105. 'copyright': 737,
  26106. 'Emacron': 667,
  26107. 'ccaron': 500,
  26108. 'aring': 556,
  26109. 'Ncommaaccent': 722,
  26110. 'lacute': 222,
  26111. 'agrave': 556,
  26112. 'Tcommaaccent': 611,
  26113. 'Cacute': 722,
  26114. 'atilde': 556,
  26115. 'Edotaccent': 667,
  26116. 'scaron': 500,
  26117. 'scedilla': 500,
  26118. 'iacute': 278,
  26119. 'lozenge': 471,
  26120. 'Rcaron': 722,
  26121. 'Gcommaaccent': 778,
  26122. 'ucircumflex': 556,
  26123. 'acircumflex': 556,
  26124. 'Amacron': 667,
  26125. 'rcaron': 333,
  26126. 'ccedilla': 500,
  26127. 'Zdotaccent': 611,
  26128. 'Thorn': 667,
  26129. 'Omacron': 778,
  26130. 'Racute': 722,
  26131. 'Sacute': 667,
  26132. 'dcaron': 643,
  26133. 'Umacron': 722,
  26134. 'uring': 556,
  26135. 'threesuperior': 333,
  26136. 'Ograve': 778,
  26137. 'Agrave': 667,
  26138. 'Abreve': 667,
  26139. 'multiply': 584,
  26140. 'uacute': 556,
  26141. 'Tcaron': 611,
  26142. 'partialdiff': 476,
  26143. 'ydieresis': 500,
  26144. 'Nacute': 722,
  26145. 'icircumflex': 278,
  26146. 'Ecircumflex': 667,
  26147. 'adieresis': 556,
  26148. 'edieresis': 556,
  26149. 'cacute': 500,
  26150. 'nacute': 556,
  26151. 'umacron': 556,
  26152. 'Ncaron': 722,
  26153. 'Iacute': 278,
  26154. 'plusminus': 584,
  26155. 'brokenbar': 260,
  26156. 'registered': 737,
  26157. 'Gbreve': 778,
  26158. 'Idotaccent': 278,
  26159. 'summation': 600,
  26160. 'Egrave': 667,
  26161. 'racute': 333,
  26162. 'omacron': 556,
  26163. 'Zacute': 611,
  26164. 'Zcaron': 611,
  26165. 'greaterequal': 549,
  26166. 'Eth': 722,
  26167. 'Ccedilla': 722,
  26168. 'lcommaaccent': 222,
  26169. 'tcaron': 317,
  26170. 'eogonek': 556,
  26171. 'Uogonek': 722,
  26172. 'Aacute': 667,
  26173. 'Adieresis': 667,
  26174. 'egrave': 556,
  26175. 'zacute': 500,
  26176. 'iogonek': 222,
  26177. 'Oacute': 778,
  26178. 'oacute': 556,
  26179. 'amacron': 556,
  26180. 'sacute': 500,
  26181. 'idieresis': 278,
  26182. 'Ocircumflex': 778,
  26183. 'Ugrave': 722,
  26184. 'Delta': 612,
  26185. 'thorn': 556,
  26186. 'twosuperior': 333,
  26187. 'Odieresis': 778,
  26188. 'mu': 556,
  26189. 'igrave': 278,
  26190. 'ohungarumlaut': 556,
  26191. 'Eogonek': 667,
  26192. 'dcroat': 556,
  26193. 'threequarters': 834,
  26194. 'Scedilla': 667,
  26195. 'lcaron': 299,
  26196. 'Kcommaaccent': 667,
  26197. 'Lacute': 556,
  26198. 'trademark': 1000,
  26199. 'edotaccent': 556,
  26200. 'Igrave': 278,
  26201. 'Imacron': 278,
  26202. 'Lcaron': 556,
  26203. 'onehalf': 834,
  26204. 'lessequal': 549,
  26205. 'ocircumflex': 556,
  26206. 'ntilde': 556,
  26207. 'Uhungarumlaut': 722,
  26208. 'Eacute': 667,
  26209. 'emacron': 556,
  26210. 'gbreve': 556,
  26211. 'onequarter': 834,
  26212. 'Scaron': 667,
  26213. 'Scommaaccent': 667,
  26214. 'Ohungarumlaut': 778,
  26215. 'degree': 400,
  26216. 'ograve': 556,
  26217. 'Ccaron': 722,
  26218. 'ugrave': 556,
  26219. 'radical': 453,
  26220. 'Dcaron': 722,
  26221. 'rcommaaccent': 333,
  26222. 'Ntilde': 722,
  26223. 'otilde': 556,
  26224. 'Rcommaaccent': 722,
  26225. 'Lcommaaccent': 556,
  26226. 'Atilde': 667,
  26227. 'Aogonek': 667,
  26228. 'Aring': 667,
  26229. 'Otilde': 778,
  26230. 'zdotaccent': 500,
  26231. 'Ecaron': 667,
  26232. 'Iogonek': 278,
  26233. 'kcommaaccent': 500,
  26234. 'minus': 584,
  26235. 'Icircumflex': 278,
  26236. 'ncaron': 556,
  26237. 'tcommaaccent': 278,
  26238. 'logicalnot': 584,
  26239. 'odieresis': 556,
  26240. 'udieresis': 556,
  26241. 'notequal': 549,
  26242. 'gcommaaccent': 556,
  26243. 'eth': 556,
  26244. 'zcaron': 500,
  26245. 'ncommaaccent': 556,
  26246. 'onesuperior': 333,
  26247. 'imacron': 278,
  26248. 'Euro': 556
  26249. },
  26250. 'Helvetica-Bold': {
  26251. 'space': 278,
  26252. 'exclam': 333,
  26253. 'quotedbl': 474,
  26254. 'numbersign': 556,
  26255. 'dollar': 556,
  26256. 'percent': 889,
  26257. 'ampersand': 722,
  26258. 'quoteright': 278,
  26259. 'parenleft': 333,
  26260. 'parenright': 333,
  26261. 'asterisk': 389,
  26262. 'plus': 584,
  26263. 'comma': 278,
  26264. 'hyphen': 333,
  26265. 'period': 278,
  26266. 'slash': 278,
  26267. 'zero': 556,
  26268. 'one': 556,
  26269. 'two': 556,
  26270. 'three': 556,
  26271. 'four': 556,
  26272. 'five': 556,
  26273. 'six': 556,
  26274. 'seven': 556,
  26275. 'eight': 556,
  26276. 'nine': 556,
  26277. 'colon': 333,
  26278. 'semicolon': 333,
  26279. 'less': 584,
  26280. 'equal': 584,
  26281. 'greater': 584,
  26282. 'question': 611,
  26283. 'at': 975,
  26284. 'A': 722,
  26285. 'B': 722,
  26286. 'C': 722,
  26287. 'D': 722,
  26288. 'E': 667,
  26289. 'F': 611,
  26290. 'G': 778,
  26291. 'H': 722,
  26292. 'I': 278,
  26293. 'J': 556,
  26294. 'K': 722,
  26295. 'L': 611,
  26296. 'M': 833,
  26297. 'N': 722,
  26298. 'O': 778,
  26299. 'P': 667,
  26300. 'Q': 778,
  26301. 'R': 722,
  26302. 'S': 667,
  26303. 'T': 611,
  26304. 'U': 722,
  26305. 'V': 667,
  26306. 'W': 944,
  26307. 'X': 667,
  26308. 'Y': 667,
  26309. 'Z': 611,
  26310. 'bracketleft': 333,
  26311. 'backslash': 278,
  26312. 'bracketright': 333,
  26313. 'asciicircum': 584,
  26314. 'underscore': 556,
  26315. 'quoteleft': 278,
  26316. 'a': 556,
  26317. 'b': 611,
  26318. 'c': 556,
  26319. 'd': 611,
  26320. 'e': 556,
  26321. 'f': 333,
  26322. 'g': 611,
  26323. 'h': 611,
  26324. 'i': 278,
  26325. 'j': 278,
  26326. 'k': 556,
  26327. 'l': 278,
  26328. 'm': 889,
  26329. 'n': 611,
  26330. 'o': 611,
  26331. 'p': 611,
  26332. 'q': 611,
  26333. 'r': 389,
  26334. 's': 556,
  26335. 't': 333,
  26336. 'u': 611,
  26337. 'v': 556,
  26338. 'w': 778,
  26339. 'x': 556,
  26340. 'y': 556,
  26341. 'z': 500,
  26342. 'braceleft': 389,
  26343. 'bar': 280,
  26344. 'braceright': 389,
  26345. 'asciitilde': 584,
  26346. 'exclamdown': 333,
  26347. 'cent': 556,
  26348. 'sterling': 556,
  26349. 'fraction': 167,
  26350. 'yen': 556,
  26351. 'florin': 556,
  26352. 'section': 556,
  26353. 'currency': 556,
  26354. 'quotesingle': 238,
  26355. 'quotedblleft': 500,
  26356. 'guillemotleft': 556,
  26357. 'guilsinglleft': 333,
  26358. 'guilsinglright': 333,
  26359. 'fi': 611,
  26360. 'fl': 611,
  26361. 'endash': 556,
  26362. 'dagger': 556,
  26363. 'daggerdbl': 556,
  26364. 'periodcentered': 278,
  26365. 'paragraph': 556,
  26366. 'bullet': 350,
  26367. 'quotesinglbase': 278,
  26368. 'quotedblbase': 500,
  26369. 'quotedblright': 500,
  26370. 'guillemotright': 556,
  26371. 'ellipsis': 1000,
  26372. 'perthousand': 1000,
  26373. 'questiondown': 611,
  26374. 'grave': 333,
  26375. 'acute': 333,
  26376. 'circumflex': 333,
  26377. 'tilde': 333,
  26378. 'macron': 333,
  26379. 'breve': 333,
  26380. 'dotaccent': 333,
  26381. 'dieresis': 333,
  26382. 'ring': 333,
  26383. 'cedilla': 333,
  26384. 'hungarumlaut': 333,
  26385. 'ogonek': 333,
  26386. 'caron': 333,
  26387. 'emdash': 1000,
  26388. 'AE': 1000,
  26389. 'ordfeminine': 370,
  26390. 'Lslash': 611,
  26391. 'Oslash': 778,
  26392. 'OE': 1000,
  26393. 'ordmasculine': 365,
  26394. 'ae': 889,
  26395. 'dotlessi': 278,
  26396. 'lslash': 278,
  26397. 'oslash': 611,
  26398. 'oe': 944,
  26399. 'germandbls': 611,
  26400. 'Idieresis': 278,
  26401. 'eacute': 556,
  26402. 'abreve': 556,
  26403. 'uhungarumlaut': 611,
  26404. 'ecaron': 556,
  26405. 'Ydieresis': 667,
  26406. 'divide': 584,
  26407. 'Yacute': 667,
  26408. 'Acircumflex': 722,
  26409. 'aacute': 556,
  26410. 'Ucircumflex': 722,
  26411. 'yacute': 556,
  26412. 'scommaaccent': 556,
  26413. 'ecircumflex': 556,
  26414. 'Uring': 722,
  26415. 'Udieresis': 722,
  26416. 'aogonek': 556,
  26417. 'Uacute': 722,
  26418. 'uogonek': 611,
  26419. 'Edieresis': 667,
  26420. 'Dcroat': 722,
  26421. 'commaaccent': 250,
  26422. 'copyright': 737,
  26423. 'Emacron': 667,
  26424. 'ccaron': 556,
  26425. 'aring': 556,
  26426. 'Ncommaaccent': 722,
  26427. 'lacute': 278,
  26428. 'agrave': 556,
  26429. 'Tcommaaccent': 611,
  26430. 'Cacute': 722,
  26431. 'atilde': 556,
  26432. 'Edotaccent': 667,
  26433. 'scaron': 556,
  26434. 'scedilla': 556,
  26435. 'iacute': 278,
  26436. 'lozenge': 494,
  26437. 'Rcaron': 722,
  26438. 'Gcommaaccent': 778,
  26439. 'ucircumflex': 611,
  26440. 'acircumflex': 556,
  26441. 'Amacron': 722,
  26442. 'rcaron': 389,
  26443. 'ccedilla': 556,
  26444. 'Zdotaccent': 611,
  26445. 'Thorn': 667,
  26446. 'Omacron': 778,
  26447. 'Racute': 722,
  26448. 'Sacute': 667,
  26449. 'dcaron': 743,
  26450. 'Umacron': 722,
  26451. 'uring': 611,
  26452. 'threesuperior': 333,
  26453. 'Ograve': 778,
  26454. 'Agrave': 722,
  26455. 'Abreve': 722,
  26456. 'multiply': 584,
  26457. 'uacute': 611,
  26458. 'Tcaron': 611,
  26459. 'partialdiff': 494,
  26460. 'ydieresis': 556,
  26461. 'Nacute': 722,
  26462. 'icircumflex': 278,
  26463. 'Ecircumflex': 667,
  26464. 'adieresis': 556,
  26465. 'edieresis': 556,
  26466. 'cacute': 556,
  26467. 'nacute': 611,
  26468. 'umacron': 611,
  26469. 'Ncaron': 722,
  26470. 'Iacute': 278,
  26471. 'plusminus': 584,
  26472. 'brokenbar': 280,
  26473. 'registered': 737,
  26474. 'Gbreve': 778,
  26475. 'Idotaccent': 278,
  26476. 'summation': 600,
  26477. 'Egrave': 667,
  26478. 'racute': 389,
  26479. 'omacron': 611,
  26480. 'Zacute': 611,
  26481. 'Zcaron': 611,
  26482. 'greaterequal': 549,
  26483. 'Eth': 722,
  26484. 'Ccedilla': 722,
  26485. 'lcommaaccent': 278,
  26486. 'tcaron': 389,
  26487. 'eogonek': 556,
  26488. 'Uogonek': 722,
  26489. 'Aacute': 722,
  26490. 'Adieresis': 722,
  26491. 'egrave': 556,
  26492. 'zacute': 500,
  26493. 'iogonek': 278,
  26494. 'Oacute': 778,
  26495. 'oacute': 611,
  26496. 'amacron': 556,
  26497. 'sacute': 556,
  26498. 'idieresis': 278,
  26499. 'Ocircumflex': 778,
  26500. 'Ugrave': 722,
  26501. 'Delta': 612,
  26502. 'thorn': 611,
  26503. 'twosuperior': 333,
  26504. 'Odieresis': 778,
  26505. 'mu': 611,
  26506. 'igrave': 278,
  26507. 'ohungarumlaut': 611,
  26508. 'Eogonek': 667,
  26509. 'dcroat': 611,
  26510. 'threequarters': 834,
  26511. 'Scedilla': 667,
  26512. 'lcaron': 400,
  26513. 'Kcommaaccent': 722,
  26514. 'Lacute': 611,
  26515. 'trademark': 1000,
  26516. 'edotaccent': 556,
  26517. 'Igrave': 278,
  26518. 'Imacron': 278,
  26519. 'Lcaron': 611,
  26520. 'onehalf': 834,
  26521. 'lessequal': 549,
  26522. 'ocircumflex': 611,
  26523. 'ntilde': 611,
  26524. 'Uhungarumlaut': 722,
  26525. 'Eacute': 667,
  26526. 'emacron': 556,
  26527. 'gbreve': 611,
  26528. 'onequarter': 834,
  26529. 'Scaron': 667,
  26530. 'Scommaaccent': 667,
  26531. 'Ohungarumlaut': 778,
  26532. 'degree': 400,
  26533. 'ograve': 611,
  26534. 'Ccaron': 722,
  26535. 'ugrave': 611,
  26536. 'radical': 549,
  26537. 'Dcaron': 722,
  26538. 'rcommaaccent': 389,
  26539. 'Ntilde': 722,
  26540. 'otilde': 611,
  26541. 'Rcommaaccent': 722,
  26542. 'Lcommaaccent': 611,
  26543. 'Atilde': 722,
  26544. 'Aogonek': 722,
  26545. 'Aring': 722,
  26546. 'Otilde': 778,
  26547. 'zdotaccent': 500,
  26548. 'Ecaron': 667,
  26549. 'Iogonek': 278,
  26550. 'kcommaaccent': 556,
  26551. 'minus': 584,
  26552. 'Icircumflex': 278,
  26553. 'ncaron': 611,
  26554. 'tcommaaccent': 333,
  26555. 'logicalnot': 584,
  26556. 'odieresis': 611,
  26557. 'udieresis': 611,
  26558. 'notequal': 549,
  26559. 'gcommaaccent': 611,
  26560. 'eth': 611,
  26561. 'zcaron': 500,
  26562. 'ncommaaccent': 611,
  26563. 'onesuperior': 333,
  26564. 'imacron': 278,
  26565. 'Euro': 556
  26566. },
  26567. 'Helvetica-BoldOblique': {
  26568. 'space': 278,
  26569. 'exclam': 333,
  26570. 'quotedbl': 474,
  26571. 'numbersign': 556,
  26572. 'dollar': 556,
  26573. 'percent': 889,
  26574. 'ampersand': 722,
  26575. 'quoteright': 278,
  26576. 'parenleft': 333,
  26577. 'parenright': 333,
  26578. 'asterisk': 389,
  26579. 'plus': 584,
  26580. 'comma': 278,
  26581. 'hyphen': 333,
  26582. 'period': 278,
  26583. 'slash': 278,
  26584. 'zero': 556,
  26585. 'one': 556,
  26586. 'two': 556,
  26587. 'three': 556,
  26588. 'four': 556,
  26589. 'five': 556,
  26590. 'six': 556,
  26591. 'seven': 556,
  26592. 'eight': 556,
  26593. 'nine': 556,
  26594. 'colon': 333,
  26595. 'semicolon': 333,
  26596. 'less': 584,
  26597. 'equal': 584,
  26598. 'greater': 584,
  26599. 'question': 611,
  26600. 'at': 975,
  26601. 'A': 722,
  26602. 'B': 722,
  26603. 'C': 722,
  26604. 'D': 722,
  26605. 'E': 667,
  26606. 'F': 611,
  26607. 'G': 778,
  26608. 'H': 722,
  26609. 'I': 278,
  26610. 'J': 556,
  26611. 'K': 722,
  26612. 'L': 611,
  26613. 'M': 833,
  26614. 'N': 722,
  26615. 'O': 778,
  26616. 'P': 667,
  26617. 'Q': 778,
  26618. 'R': 722,
  26619. 'S': 667,
  26620. 'T': 611,
  26621. 'U': 722,
  26622. 'V': 667,
  26623. 'W': 944,
  26624. 'X': 667,
  26625. 'Y': 667,
  26626. 'Z': 611,
  26627. 'bracketleft': 333,
  26628. 'backslash': 278,
  26629. 'bracketright': 333,
  26630. 'asciicircum': 584,
  26631. 'underscore': 556,
  26632. 'quoteleft': 278,
  26633. 'a': 556,
  26634. 'b': 611,
  26635. 'c': 556,
  26636. 'd': 611,
  26637. 'e': 556,
  26638. 'f': 333,
  26639. 'g': 611,
  26640. 'h': 611,
  26641. 'i': 278,
  26642. 'j': 278,
  26643. 'k': 556,
  26644. 'l': 278,
  26645. 'm': 889,
  26646. 'n': 611,
  26647. 'o': 611,
  26648. 'p': 611,
  26649. 'q': 611,
  26650. 'r': 389,
  26651. 's': 556,
  26652. 't': 333,
  26653. 'u': 611,
  26654. 'v': 556,
  26655. 'w': 778,
  26656. 'x': 556,
  26657. 'y': 556,
  26658. 'z': 500,
  26659. 'braceleft': 389,
  26660. 'bar': 280,
  26661. 'braceright': 389,
  26662. 'asciitilde': 584,
  26663. 'exclamdown': 333,
  26664. 'cent': 556,
  26665. 'sterling': 556,
  26666. 'fraction': 167,
  26667. 'yen': 556,
  26668. 'florin': 556,
  26669. 'section': 556,
  26670. 'currency': 556,
  26671. 'quotesingle': 238,
  26672. 'quotedblleft': 500,
  26673. 'guillemotleft': 556,
  26674. 'guilsinglleft': 333,
  26675. 'guilsinglright': 333,
  26676. 'fi': 611,
  26677. 'fl': 611,
  26678. 'endash': 556,
  26679. 'dagger': 556,
  26680. 'daggerdbl': 556,
  26681. 'periodcentered': 278,
  26682. 'paragraph': 556,
  26683. 'bullet': 350,
  26684. 'quotesinglbase': 278,
  26685. 'quotedblbase': 500,
  26686. 'quotedblright': 500,
  26687. 'guillemotright': 556,
  26688. 'ellipsis': 1000,
  26689. 'perthousand': 1000,
  26690. 'questiondown': 611,
  26691. 'grave': 333,
  26692. 'acute': 333,
  26693. 'circumflex': 333,
  26694. 'tilde': 333,
  26695. 'macron': 333,
  26696. 'breve': 333,
  26697. 'dotaccent': 333,
  26698. 'dieresis': 333,
  26699. 'ring': 333,
  26700. 'cedilla': 333,
  26701. 'hungarumlaut': 333,
  26702. 'ogonek': 333,
  26703. 'caron': 333,
  26704. 'emdash': 1000,
  26705. 'AE': 1000,
  26706. 'ordfeminine': 370,
  26707. 'Lslash': 611,
  26708. 'Oslash': 778,
  26709. 'OE': 1000,
  26710. 'ordmasculine': 365,
  26711. 'ae': 889,
  26712. 'dotlessi': 278,
  26713. 'lslash': 278,
  26714. 'oslash': 611,
  26715. 'oe': 944,
  26716. 'germandbls': 611,
  26717. 'Idieresis': 278,
  26718. 'eacute': 556,
  26719. 'abreve': 556,
  26720. 'uhungarumlaut': 611,
  26721. 'ecaron': 556,
  26722. 'Ydieresis': 667,
  26723. 'divide': 584,
  26724. 'Yacute': 667,
  26725. 'Acircumflex': 722,
  26726. 'aacute': 556,
  26727. 'Ucircumflex': 722,
  26728. 'yacute': 556,
  26729. 'scommaaccent': 556,
  26730. 'ecircumflex': 556,
  26731. 'Uring': 722,
  26732. 'Udieresis': 722,
  26733. 'aogonek': 556,
  26734. 'Uacute': 722,
  26735. 'uogonek': 611,
  26736. 'Edieresis': 667,
  26737. 'Dcroat': 722,
  26738. 'commaaccent': 250,
  26739. 'copyright': 737,
  26740. 'Emacron': 667,
  26741. 'ccaron': 556,
  26742. 'aring': 556,
  26743. 'Ncommaaccent': 722,
  26744. 'lacute': 278,
  26745. 'agrave': 556,
  26746. 'Tcommaaccent': 611,
  26747. 'Cacute': 722,
  26748. 'atilde': 556,
  26749. 'Edotaccent': 667,
  26750. 'scaron': 556,
  26751. 'scedilla': 556,
  26752. 'iacute': 278,
  26753. 'lozenge': 494,
  26754. 'Rcaron': 722,
  26755. 'Gcommaaccent': 778,
  26756. 'ucircumflex': 611,
  26757. 'acircumflex': 556,
  26758. 'Amacron': 722,
  26759. 'rcaron': 389,
  26760. 'ccedilla': 556,
  26761. 'Zdotaccent': 611,
  26762. 'Thorn': 667,
  26763. 'Omacron': 778,
  26764. 'Racute': 722,
  26765. 'Sacute': 667,
  26766. 'dcaron': 743,
  26767. 'Umacron': 722,
  26768. 'uring': 611,
  26769. 'threesuperior': 333,
  26770. 'Ograve': 778,
  26771. 'Agrave': 722,
  26772. 'Abreve': 722,
  26773. 'multiply': 584,
  26774. 'uacute': 611,
  26775. 'Tcaron': 611,
  26776. 'partialdiff': 494,
  26777. 'ydieresis': 556,
  26778. 'Nacute': 722,
  26779. 'icircumflex': 278,
  26780. 'Ecircumflex': 667,
  26781. 'adieresis': 556,
  26782. 'edieresis': 556,
  26783. 'cacute': 556,
  26784. 'nacute': 611,
  26785. 'umacron': 611,
  26786. 'Ncaron': 722,
  26787. 'Iacute': 278,
  26788. 'plusminus': 584,
  26789. 'brokenbar': 280,
  26790. 'registered': 737,
  26791. 'Gbreve': 778,
  26792. 'Idotaccent': 278,
  26793. 'summation': 600,
  26794. 'Egrave': 667,
  26795. 'racute': 389,
  26796. 'omacron': 611,
  26797. 'Zacute': 611,
  26798. 'Zcaron': 611,
  26799. 'greaterequal': 549,
  26800. 'Eth': 722,
  26801. 'Ccedilla': 722,
  26802. 'lcommaaccent': 278,
  26803. 'tcaron': 389,
  26804. 'eogonek': 556,
  26805. 'Uogonek': 722,
  26806. 'Aacute': 722,
  26807. 'Adieresis': 722,
  26808. 'egrave': 556,
  26809. 'zacute': 500,
  26810. 'iogonek': 278,
  26811. 'Oacute': 778,
  26812. 'oacute': 611,
  26813. 'amacron': 556,
  26814. 'sacute': 556,
  26815. 'idieresis': 278,
  26816. 'Ocircumflex': 778,
  26817. 'Ugrave': 722,
  26818. 'Delta': 612,
  26819. 'thorn': 611,
  26820. 'twosuperior': 333,
  26821. 'Odieresis': 778,
  26822. 'mu': 611,
  26823. 'igrave': 278,
  26824. 'ohungarumlaut': 611,
  26825. 'Eogonek': 667,
  26826. 'dcroat': 611,
  26827. 'threequarters': 834,
  26828. 'Scedilla': 667,
  26829. 'lcaron': 400,
  26830. 'Kcommaaccent': 722,
  26831. 'Lacute': 611,
  26832. 'trademark': 1000,
  26833. 'edotaccent': 556,
  26834. 'Igrave': 278,
  26835. 'Imacron': 278,
  26836. 'Lcaron': 611,
  26837. 'onehalf': 834,
  26838. 'lessequal': 549,
  26839. 'ocircumflex': 611,
  26840. 'ntilde': 611,
  26841. 'Uhungarumlaut': 722,
  26842. 'Eacute': 667,
  26843. 'emacron': 556,
  26844. 'gbreve': 611,
  26845. 'onequarter': 834,
  26846. 'Scaron': 667,
  26847. 'Scommaaccent': 667,
  26848. 'Ohungarumlaut': 778,
  26849. 'degree': 400,
  26850. 'ograve': 611,
  26851. 'Ccaron': 722,
  26852. 'ugrave': 611,
  26853. 'radical': 549,
  26854. 'Dcaron': 722,
  26855. 'rcommaaccent': 389,
  26856. 'Ntilde': 722,
  26857. 'otilde': 611,
  26858. 'Rcommaaccent': 722,
  26859. 'Lcommaaccent': 611,
  26860. 'Atilde': 722,
  26861. 'Aogonek': 722,
  26862. 'Aring': 722,
  26863. 'Otilde': 778,
  26864. 'zdotaccent': 500,
  26865. 'Ecaron': 667,
  26866. 'Iogonek': 278,
  26867. 'kcommaaccent': 556,
  26868. 'minus': 584,
  26869. 'Icircumflex': 278,
  26870. 'ncaron': 611,
  26871. 'tcommaaccent': 333,
  26872. 'logicalnot': 584,
  26873. 'odieresis': 611,
  26874. 'udieresis': 611,
  26875. 'notequal': 549,
  26876. 'gcommaaccent': 611,
  26877. 'eth': 611,
  26878. 'zcaron': 500,
  26879. 'ncommaaccent': 611,
  26880. 'onesuperior': 333,
  26881. 'imacron': 278,
  26882. 'Euro': 556
  26883. },
  26884. 'Helvetica-Oblique' : {
  26885. 'space': 278,
  26886. 'exclam': 278,
  26887. 'quotedbl': 355,
  26888. 'numbersign': 556,
  26889. 'dollar': 556,
  26890. 'percent': 889,
  26891. 'ampersand': 667,
  26892. 'quoteright': 222,
  26893. 'parenleft': 333,
  26894. 'parenright': 333,
  26895. 'asterisk': 389,
  26896. 'plus': 584,
  26897. 'comma': 278,
  26898. 'hyphen': 333,
  26899. 'period': 278,
  26900. 'slash': 278,
  26901. 'zero': 556,
  26902. 'one': 556,
  26903. 'two': 556,
  26904. 'three': 556,
  26905. 'four': 556,
  26906. 'five': 556,
  26907. 'six': 556,
  26908. 'seven': 556,
  26909. 'eight': 556,
  26910. 'nine': 556,
  26911. 'colon': 278,
  26912. 'semicolon': 278,
  26913. 'less': 584,
  26914. 'equal': 584,
  26915. 'greater': 584,
  26916. 'question': 556,
  26917. 'at': 1015,
  26918. 'A': 667,
  26919. 'B': 667,
  26920. 'C': 722,
  26921. 'D': 722,
  26922. 'E': 667,
  26923. 'F': 611,
  26924. 'G': 778,
  26925. 'H': 722,
  26926. 'I': 278,
  26927. 'J': 500,
  26928. 'K': 667,
  26929. 'L': 556,
  26930. 'M': 833,
  26931. 'N': 722,
  26932. 'O': 778,
  26933. 'P': 667,
  26934. 'Q': 778,
  26935. 'R': 722,
  26936. 'S': 667,
  26937. 'T': 611,
  26938. 'U': 722,
  26939. 'V': 667,
  26940. 'W': 944,
  26941. 'X': 667,
  26942. 'Y': 667,
  26943. 'Z': 611,
  26944. 'bracketleft': 278,
  26945. 'backslash': 278,
  26946. 'bracketright': 278,
  26947. 'asciicircum': 469,
  26948. 'underscore': 556,
  26949. 'quoteleft': 222,
  26950. 'a': 556,
  26951. 'b': 556,
  26952. 'c': 500,
  26953. 'd': 556,
  26954. 'e': 556,
  26955. 'f': 278,
  26956. 'g': 556,
  26957. 'h': 556,
  26958. 'i': 222,
  26959. 'j': 222,
  26960. 'k': 500,
  26961. 'l': 222,
  26962. 'm': 833,
  26963. 'n': 556,
  26964. 'o': 556,
  26965. 'p': 556,
  26966. 'q': 556,
  26967. 'r': 333,
  26968. 's': 500,
  26969. 't': 278,
  26970. 'u': 556,
  26971. 'v': 500,
  26972. 'w': 722,
  26973. 'x': 500,
  26974. 'y': 500,
  26975. 'z': 500,
  26976. 'braceleft': 334,
  26977. 'bar': 260,
  26978. 'braceright': 334,
  26979. 'asciitilde': 584,
  26980. 'exclamdown': 333,
  26981. 'cent': 556,
  26982. 'sterling': 556,
  26983. 'fraction': 167,
  26984. 'yen': 556,
  26985. 'florin': 556,
  26986. 'section': 556,
  26987. 'currency': 556,
  26988. 'quotesingle': 191,
  26989. 'quotedblleft': 333,
  26990. 'guillemotleft': 556,
  26991. 'guilsinglleft': 333,
  26992. 'guilsinglright': 333,
  26993. 'fi': 500,
  26994. 'fl': 500,
  26995. 'endash': 556,
  26996. 'dagger': 556,
  26997. 'daggerdbl': 556,
  26998. 'periodcentered': 278,
  26999. 'paragraph': 537,
  27000. 'bullet': 350,
  27001. 'quotesinglbase': 222,
  27002. 'quotedblbase': 333,
  27003. 'quotedblright': 333,
  27004. 'guillemotright': 556,
  27005. 'ellipsis': 1000,
  27006. 'perthousand': 1000,
  27007. 'questiondown': 611,
  27008. 'grave': 333,
  27009. 'acute': 333,
  27010. 'circumflex': 333,
  27011. 'tilde': 333,
  27012. 'macron': 333,
  27013. 'breve': 333,
  27014. 'dotaccent': 333,
  27015. 'dieresis': 333,
  27016. 'ring': 333,
  27017. 'cedilla': 333,
  27018. 'hungarumlaut': 333,
  27019. 'ogonek': 333,
  27020. 'caron': 333,
  27021. 'emdash': 1000,
  27022. 'AE': 1000,
  27023. 'ordfeminine': 370,
  27024. 'Lslash': 556,
  27025. 'Oslash': 778,
  27026. 'OE': 1000,
  27027. 'ordmasculine': 365,
  27028. 'ae': 889,
  27029. 'dotlessi': 278,
  27030. 'lslash': 222,
  27031. 'oslash': 611,
  27032. 'oe': 944,
  27033. 'germandbls': 611,
  27034. 'Idieresis': 278,
  27035. 'eacute': 556,
  27036. 'abreve': 556,
  27037. 'uhungarumlaut': 556,
  27038. 'ecaron': 556,
  27039. 'Ydieresis': 667,
  27040. 'divide': 584,
  27041. 'Yacute': 667,
  27042. 'Acircumflex': 667,
  27043. 'aacute': 556,
  27044. 'Ucircumflex': 722,
  27045. 'yacute': 500,
  27046. 'scommaaccent': 500,
  27047. 'ecircumflex': 556,
  27048. 'Uring': 722,
  27049. 'Udieresis': 722,
  27050. 'aogonek': 556,
  27051. 'Uacute': 722,
  27052. 'uogonek': 556,
  27053. 'Edieresis': 667,
  27054. 'Dcroat': 722,
  27055. 'commaaccent': 250,
  27056. 'copyright': 737,
  27057. 'Emacron': 667,
  27058. 'ccaron': 500,
  27059. 'aring': 556,
  27060. 'Ncommaaccent': 722,
  27061. 'lacute': 222,
  27062. 'agrave': 556,
  27063. 'Tcommaaccent': 611,
  27064. 'Cacute': 722,
  27065. 'atilde': 556,
  27066. 'Edotaccent': 667,
  27067. 'scaron': 500,
  27068. 'scedilla': 500,
  27069. 'iacute': 278,
  27070. 'lozenge': 471,
  27071. 'Rcaron': 722,
  27072. 'Gcommaaccent': 778,
  27073. 'ucircumflex': 556,
  27074. 'acircumflex': 556,
  27075. 'Amacron': 667,
  27076. 'rcaron': 333,
  27077. 'ccedilla': 500,
  27078. 'Zdotaccent': 611,
  27079. 'Thorn': 667,
  27080. 'Omacron': 778,
  27081. 'Racute': 722,
  27082. 'Sacute': 667,
  27083. 'dcaron': 643,
  27084. 'Umacron': 722,
  27085. 'uring': 556,
  27086. 'threesuperior': 333,
  27087. 'Ograve': 778,
  27088. 'Agrave': 667,
  27089. 'Abreve': 667,
  27090. 'multiply': 584,
  27091. 'uacute': 556,
  27092. 'Tcaron': 611,
  27093. 'partialdiff': 476,
  27094. 'ydieresis': 500,
  27095. 'Nacute': 722,
  27096. 'icircumflex': 278,
  27097. 'Ecircumflex': 667,
  27098. 'adieresis': 556,
  27099. 'edieresis': 556,
  27100. 'cacute': 500,
  27101. 'nacute': 556,
  27102. 'umacron': 556,
  27103. 'Ncaron': 722,
  27104. 'Iacute': 278,
  27105. 'plusminus': 584,
  27106. 'brokenbar': 260,
  27107. 'registered': 737,
  27108. 'Gbreve': 778,
  27109. 'Idotaccent': 278,
  27110. 'summation': 600,
  27111. 'Egrave': 667,
  27112. 'racute': 333,
  27113. 'omacron': 556,
  27114. 'Zacute': 611,
  27115. 'Zcaron': 611,
  27116. 'greaterequal': 549,
  27117. 'Eth': 722,
  27118. 'Ccedilla': 722,
  27119. 'lcommaaccent': 222,
  27120. 'tcaron': 317,
  27121. 'eogonek': 556,
  27122. 'Uogonek': 722,
  27123. 'Aacute': 667,
  27124. 'Adieresis': 667,
  27125. 'egrave': 556,
  27126. 'zacute': 500,
  27127. 'iogonek': 222,
  27128. 'Oacute': 778,
  27129. 'oacute': 556,
  27130. 'amacron': 556,
  27131. 'sacute': 500,
  27132. 'idieresis': 278,
  27133. 'Ocircumflex': 778,
  27134. 'Ugrave': 722,
  27135. 'Delta': 612,
  27136. 'thorn': 556,
  27137. 'twosuperior': 333,
  27138. 'Odieresis': 778,
  27139. 'mu': 556,
  27140. 'igrave': 278,
  27141. 'ohungarumlaut': 556,
  27142. 'Eogonek': 667,
  27143. 'dcroat': 556,
  27144. 'threequarters': 834,
  27145. 'Scedilla': 667,
  27146. 'lcaron': 299,
  27147. 'Kcommaaccent': 667,
  27148. 'Lacute': 556,
  27149. 'trademark': 1000,
  27150. 'edotaccent': 556,
  27151. 'Igrave': 278,
  27152. 'Imacron': 278,
  27153. 'Lcaron': 556,
  27154. 'onehalf': 834,
  27155. 'lessequal': 549,
  27156. 'ocircumflex': 556,
  27157. 'ntilde': 556,
  27158. 'Uhungarumlaut': 722,
  27159. 'Eacute': 667,
  27160. 'emacron': 556,
  27161. 'gbreve': 556,
  27162. 'onequarter': 834,
  27163. 'Scaron': 667,
  27164. 'Scommaaccent': 667,
  27165. 'Ohungarumlaut': 778,
  27166. 'degree': 400,
  27167. 'ograve': 556,
  27168. 'Ccaron': 722,
  27169. 'ugrave': 556,
  27170. 'radical': 453,
  27171. 'Dcaron': 722,
  27172. 'rcommaaccent': 333,
  27173. 'Ntilde': 722,
  27174. 'otilde': 556,
  27175. 'Rcommaaccent': 722,
  27176. 'Lcommaaccent': 556,
  27177. 'Atilde': 667,
  27178. 'Aogonek': 667,
  27179. 'Aring': 667,
  27180. 'Otilde': 778,
  27181. 'zdotaccent': 500,
  27182. 'Ecaron': 667,
  27183. 'Iogonek': 278,
  27184. 'kcommaaccent': 500,
  27185. 'minus': 584,
  27186. 'Icircumflex': 278,
  27187. 'ncaron': 556,
  27188. 'tcommaaccent': 278,
  27189. 'logicalnot': 584,
  27190. 'odieresis': 556,
  27191. 'udieresis': 556,
  27192. 'notequal': 549,
  27193. 'gcommaaccent': 556,
  27194. 'eth': 556,
  27195. 'zcaron': 500,
  27196. 'ncommaaccent': 556,
  27197. 'onesuperior': 333,
  27198. 'imacron': 278,
  27199. 'Euro': 556
  27200. },
  27201. 'Symbol': {
  27202. 'space': 250,
  27203. 'exclam': 333,
  27204. 'universal': 713,
  27205. 'numbersign': 500,
  27206. 'existential': 549,
  27207. 'percent': 833,
  27208. 'ampersand': 778,
  27209. 'suchthat': 439,
  27210. 'parenleft': 333,
  27211. 'parenright': 333,
  27212. 'asteriskmath': 500,
  27213. 'plus': 549,
  27214. 'comma': 250,
  27215. 'minus': 549,
  27216. 'period': 250,
  27217. 'slash': 278,
  27218. 'zero': 500,
  27219. 'one': 500,
  27220. 'two': 500,
  27221. 'three': 500,
  27222. 'four': 500,
  27223. 'five': 500,
  27224. 'six': 500,
  27225. 'seven': 500,
  27226. 'eight': 500,
  27227. 'nine': 500,
  27228. 'colon': 278,
  27229. 'semicolon': 278,
  27230. 'less': 549,
  27231. 'equal': 549,
  27232. 'greater': 549,
  27233. 'question': 444,
  27234. 'congruent': 549,
  27235. 'Alpha': 722,
  27236. 'Beta': 667,
  27237. 'Chi': 722,
  27238. 'Delta': 612,
  27239. 'Epsilon': 611,
  27240. 'Phi': 763,
  27241. 'Gamma': 603,
  27242. 'Eta': 722,
  27243. 'Iota': 333,
  27244. 'theta1': 631,
  27245. 'Kappa': 722,
  27246. 'Lambda': 686,
  27247. 'Mu': 889,
  27248. 'Nu': 722,
  27249. 'Omicron': 722,
  27250. 'Pi': 768,
  27251. 'Theta': 741,
  27252. 'Rho': 556,
  27253. 'Sigma': 592,
  27254. 'Tau': 611,
  27255. 'Upsilon': 690,
  27256. 'sigma1': 439,
  27257. 'Omega': 768,
  27258. 'Xi': 645,
  27259. 'Psi': 795,
  27260. 'Zeta': 611,
  27261. 'bracketleft': 333,
  27262. 'therefore': 863,
  27263. 'bracketright': 333,
  27264. 'perpendicular': 658,
  27265. 'underscore': 500,
  27266. 'radicalex': 500,
  27267. 'alpha': 631,
  27268. 'beta': 549,
  27269. 'chi': 549,
  27270. 'delta': 494,
  27271. 'epsilon': 439,
  27272. 'phi': 521,
  27273. 'gamma': 411,
  27274. 'eta': 603,
  27275. 'iota': 329,
  27276. 'phi1': 603,
  27277. 'kappa': 549,
  27278. 'lambda': 549,
  27279. 'mu': 576,
  27280. 'nu': 521,
  27281. 'omicron': 549,
  27282. 'pi': 549,
  27283. 'theta': 521,
  27284. 'rho': 549,
  27285. 'sigma': 603,
  27286. 'tau': 439,
  27287. 'upsilon': 576,
  27288. 'omega1': 713,
  27289. 'omega': 686,
  27290. 'xi': 493,
  27291. 'psi': 686,
  27292. 'zeta': 494,
  27293. 'braceleft': 480,
  27294. 'bar': 200,
  27295. 'braceright': 480,
  27296. 'similar': 549,
  27297. 'Euro': 750,
  27298. 'Upsilon1': 620,
  27299. 'minute': 247,
  27300. 'lessequal': 549,
  27301. 'fraction': 167,
  27302. 'infinity': 713,
  27303. 'florin': 500,
  27304. 'club': 753,
  27305. 'diamond': 753,
  27306. 'heart': 753,
  27307. 'spade': 753,
  27308. 'arrowboth': 1042,
  27309. 'arrowleft': 987,
  27310. 'arrowup': 603,
  27311. 'arrowright': 987,
  27312. 'arrowdown': 603,
  27313. 'degree': 400,
  27314. 'plusminus': 549,
  27315. 'second': 411,
  27316. 'greaterequal': 549,
  27317. 'multiply': 549,
  27318. 'proportional': 713,
  27319. 'partialdiff': 494,
  27320. 'bullet': 460,
  27321. 'divide': 549,
  27322. 'notequal': 549,
  27323. 'equivalence': 549,
  27324. 'approxequal': 549,
  27325. 'ellipsis': 1000,
  27326. 'arrowvertex': 603,
  27327. 'arrowhorizex': 1000,
  27328. 'carriagereturn': 658,
  27329. 'aleph': 823,
  27330. 'Ifraktur': 686,
  27331. 'Rfraktur': 795,
  27332. 'weierstrass': 987,
  27333. 'circlemultiply': 768,
  27334. 'circleplus': 768,
  27335. 'emptyset': 823,
  27336. 'intersection': 768,
  27337. 'union': 768,
  27338. 'propersuperset': 713,
  27339. 'reflexsuperset': 713,
  27340. 'notsubset': 713,
  27341. 'propersubset': 713,
  27342. 'reflexsubset': 713,
  27343. 'element': 713,
  27344. 'notelement': 713,
  27345. 'angle': 768,
  27346. 'gradient': 713,
  27347. 'registerserif': 790,
  27348. 'copyrightserif': 790,
  27349. 'trademarkserif': 890,
  27350. 'product': 823,
  27351. 'radical': 549,
  27352. 'dotmath': 250,
  27353. 'logicalnot': 713,
  27354. 'logicaland': 603,
  27355. 'logicalor': 603,
  27356. 'arrowdblboth': 1042,
  27357. 'arrowdblleft': 987,
  27358. 'arrowdblup': 603,
  27359. 'arrowdblright': 987,
  27360. 'arrowdbldown': 603,
  27361. 'lozenge': 494,
  27362. 'angleleft': 329,
  27363. 'registersans': 790,
  27364. 'copyrightsans': 790,
  27365. 'trademarksans': 786,
  27366. 'summation': 713,
  27367. 'parenlefttp': 384,
  27368. 'parenleftex': 384,
  27369. 'parenleftbt': 384,
  27370. 'bracketlefttp': 384,
  27371. 'bracketleftex': 384,
  27372. 'bracketleftbt': 384,
  27373. 'bracelefttp': 494,
  27374. 'braceleftmid': 494,
  27375. 'braceleftbt': 494,
  27376. 'braceex': 494,
  27377. 'angleright': 329,
  27378. 'integral': 274,
  27379. 'integraltp': 686,
  27380. 'integralex': 686,
  27381. 'integralbt': 686,
  27382. 'parenrighttp': 384,
  27383. 'parenrightex': 384,
  27384. 'parenrightbt': 384,
  27385. 'bracketrighttp': 384,
  27386. 'bracketrightex': 384,
  27387. 'bracketrightbt': 384,
  27388. 'bracerighttp': 494,
  27389. 'bracerightmid': 494,
  27390. 'bracerightbt': 494,
  27391. 'apple': 790
  27392. },
  27393. 'Times-Roman': {
  27394. 'space': 250,
  27395. 'exclam': 333,
  27396. 'quotedbl': 408,
  27397. 'numbersign': 500,
  27398. 'dollar': 500,
  27399. 'percent': 833,
  27400. 'ampersand': 778,
  27401. 'quoteright': 333,
  27402. 'parenleft': 333,
  27403. 'parenright': 333,
  27404. 'asterisk': 500,
  27405. 'plus': 564,
  27406. 'comma': 250,
  27407. 'hyphen': 333,
  27408. 'period': 250,
  27409. 'slash': 278,
  27410. 'zero': 500,
  27411. 'one': 500,
  27412. 'two': 500,
  27413. 'three': 500,
  27414. 'four': 500,
  27415. 'five': 500,
  27416. 'six': 500,
  27417. 'seven': 500,
  27418. 'eight': 500,
  27419. 'nine': 500,
  27420. 'colon': 278,
  27421. 'semicolon': 278,
  27422. 'less': 564,
  27423. 'equal': 564,
  27424. 'greater': 564,
  27425. 'question': 444,
  27426. 'at': 921,
  27427. 'A': 722,
  27428. 'B': 667,
  27429. 'C': 667,
  27430. 'D': 722,
  27431. 'E': 611,
  27432. 'F': 556,
  27433. 'G': 722,
  27434. 'H': 722,
  27435. 'I': 333,
  27436. 'J': 389,
  27437. 'K': 722,
  27438. 'L': 611,
  27439. 'M': 889,
  27440. 'N': 722,
  27441. 'O': 722,
  27442. 'P': 556,
  27443. 'Q': 722,
  27444. 'R': 667,
  27445. 'S': 556,
  27446. 'T': 611,
  27447. 'U': 722,
  27448. 'V': 722,
  27449. 'W': 944,
  27450. 'X': 722,
  27451. 'Y': 722,
  27452. 'Z': 611,
  27453. 'bracketleft': 333,
  27454. 'backslash': 278,
  27455. 'bracketright': 333,
  27456. 'asciicircum': 469,
  27457. 'underscore': 500,
  27458. 'quoteleft': 333,
  27459. 'a': 444,
  27460. 'b': 500,
  27461. 'c': 444,
  27462. 'd': 500,
  27463. 'e': 444,
  27464. 'f': 333,
  27465. 'g': 500,
  27466. 'h': 500,
  27467. 'i': 278,
  27468. 'j': 278,
  27469. 'k': 500,
  27470. 'l': 278,
  27471. 'm': 778,
  27472. 'n': 500,
  27473. 'o': 500,
  27474. 'p': 500,
  27475. 'q': 500,
  27476. 'r': 333,
  27477. 's': 389,
  27478. 't': 278,
  27479. 'u': 500,
  27480. 'v': 500,
  27481. 'w': 722,
  27482. 'x': 500,
  27483. 'y': 500,
  27484. 'z': 444,
  27485. 'braceleft': 480,
  27486. 'bar': 200,
  27487. 'braceright': 480,
  27488. 'asciitilde': 541,
  27489. 'exclamdown': 333,
  27490. 'cent': 500,
  27491. 'sterling': 500,
  27492. 'fraction': 167,
  27493. 'yen': 500,
  27494. 'florin': 500,
  27495. 'section': 500,
  27496. 'currency': 500,
  27497. 'quotesingle': 180,
  27498. 'quotedblleft': 444,
  27499. 'guillemotleft': 500,
  27500. 'guilsinglleft': 333,
  27501. 'guilsinglright': 333,
  27502. 'fi': 556,
  27503. 'fl': 556,
  27504. 'endash': 500,
  27505. 'dagger': 500,
  27506. 'daggerdbl': 500,
  27507. 'periodcentered': 250,
  27508. 'paragraph': 453,
  27509. 'bullet': 350,
  27510. 'quotesinglbase': 333,
  27511. 'quotedblbase': 444,
  27512. 'quotedblright': 444,
  27513. 'guillemotright': 500,
  27514. 'ellipsis': 1000,
  27515. 'perthousand': 1000,
  27516. 'questiondown': 444,
  27517. 'grave': 333,
  27518. 'acute': 333,
  27519. 'circumflex': 333,
  27520. 'tilde': 333,
  27521. 'macron': 333,
  27522. 'breve': 333,
  27523. 'dotaccent': 333,
  27524. 'dieresis': 333,
  27525. 'ring': 333,
  27526. 'cedilla': 333,
  27527. 'hungarumlaut': 333,
  27528. 'ogonek': 333,
  27529. 'caron': 333,
  27530. 'emdash': 1000,
  27531. 'AE': 889,
  27532. 'ordfeminine': 276,
  27533. 'Lslash': 611,
  27534. 'Oslash': 722,
  27535. 'OE': 889,
  27536. 'ordmasculine': 310,
  27537. 'ae': 667,
  27538. 'dotlessi': 278,
  27539. 'lslash': 278,
  27540. 'oslash': 500,
  27541. 'oe': 722,
  27542. 'germandbls': 500,
  27543. 'Idieresis': 333,
  27544. 'eacute': 444,
  27545. 'abreve': 444,
  27546. 'uhungarumlaut': 500,
  27547. 'ecaron': 444,
  27548. 'Ydieresis': 722,
  27549. 'divide': 564,
  27550. 'Yacute': 722,
  27551. 'Acircumflex': 722,
  27552. 'aacute': 444,
  27553. 'Ucircumflex': 722,
  27554. 'yacute': 500,
  27555. 'scommaaccent': 389,
  27556. 'ecircumflex': 444,
  27557. 'Uring': 722,
  27558. 'Udieresis': 722,
  27559. 'aogonek': 444,
  27560. 'Uacute': 722,
  27561. 'uogonek': 500,
  27562. 'Edieresis': 611,
  27563. 'Dcroat': 722,
  27564. 'commaaccent': 250,
  27565. 'copyright': 760,
  27566. 'Emacron': 611,
  27567. 'ccaron': 444,
  27568. 'aring': 444,
  27569. 'Ncommaaccent': 722,
  27570. 'lacute': 278,
  27571. 'agrave': 444,
  27572. 'Tcommaaccent': 611,
  27573. 'Cacute': 667,
  27574. 'atilde': 444,
  27575. 'Edotaccent': 611,
  27576. 'scaron': 389,
  27577. 'scedilla': 389,
  27578. 'iacute': 278,
  27579. 'lozenge': 471,
  27580. 'Rcaron': 667,
  27581. 'Gcommaaccent': 722,
  27582. 'ucircumflex': 500,
  27583. 'acircumflex': 444,
  27584. 'Amacron': 722,
  27585. 'rcaron': 333,
  27586. 'ccedilla': 444,
  27587. 'Zdotaccent': 611,
  27588. 'Thorn': 556,
  27589. 'Omacron': 722,
  27590. 'Racute': 667,
  27591. 'Sacute': 556,
  27592. 'dcaron': 588,
  27593. 'Umacron': 722,
  27594. 'uring': 500,
  27595. 'threesuperior': 300,
  27596. 'Ograve': 722,
  27597. 'Agrave': 722,
  27598. 'Abreve': 722,
  27599. 'multiply': 564,
  27600. 'uacute': 500,
  27601. 'Tcaron': 611,
  27602. 'partialdiff': 476,
  27603. 'ydieresis': 500,
  27604. 'Nacute': 722,
  27605. 'icircumflex': 278,
  27606. 'Ecircumflex': 611,
  27607. 'adieresis': 444,
  27608. 'edieresis': 444,
  27609. 'cacute': 444,
  27610. 'nacute': 500,
  27611. 'umacron': 500,
  27612. 'Ncaron': 722,
  27613. 'Iacute': 333,
  27614. 'plusminus': 564,
  27615. 'brokenbar': 200,
  27616. 'registered': 760,
  27617. 'Gbreve': 722,
  27618. 'Idotaccent': 333,
  27619. 'summation': 600,
  27620. 'Egrave': 611,
  27621. 'racute': 333,
  27622. 'omacron': 500,
  27623. 'Zacute': 611,
  27624. 'Zcaron': 611,
  27625. 'greaterequal': 549,
  27626. 'Eth': 722,
  27627. 'Ccedilla': 667,
  27628. 'lcommaaccent': 278,
  27629. 'tcaron': 326,
  27630. 'eogonek': 444,
  27631. 'Uogonek': 722,
  27632. 'Aacute': 722,
  27633. 'Adieresis': 722,
  27634. 'egrave': 444,
  27635. 'zacute': 444,
  27636. 'iogonek': 278,
  27637. 'Oacute': 722,
  27638. 'oacute': 500,
  27639. 'amacron': 444,
  27640. 'sacute': 389,
  27641. 'idieresis': 278,
  27642. 'Ocircumflex': 722,
  27643. 'Ugrave': 722,
  27644. 'Delta': 612,
  27645. 'thorn': 500,
  27646. 'twosuperior': 300,
  27647. 'Odieresis': 722,
  27648. 'mu': 500,
  27649. 'igrave': 278,
  27650. 'ohungarumlaut': 500,
  27651. 'Eogonek': 611,
  27652. 'dcroat': 500,
  27653. 'threequarters': 750,
  27654. 'Scedilla': 556,
  27655. 'lcaron': 344,
  27656. 'Kcommaaccent': 722,
  27657. 'Lacute': 611,
  27658. 'trademark': 980,
  27659. 'edotaccent': 444,
  27660. 'Igrave': 333,
  27661. 'Imacron': 333,
  27662. 'Lcaron': 611,
  27663. 'onehalf': 750,
  27664. 'lessequal': 549,
  27665. 'ocircumflex': 500,
  27666. 'ntilde': 500,
  27667. 'Uhungarumlaut': 722,
  27668. 'Eacute': 611,
  27669. 'emacron': 444,
  27670. 'gbreve': 500,
  27671. 'onequarter': 750,
  27672. 'Scaron': 556,
  27673. 'Scommaaccent': 556,
  27674. 'Ohungarumlaut': 722,
  27675. 'degree': 400,
  27676. 'ograve': 500,
  27677. 'Ccaron': 667,
  27678. 'ugrave': 500,
  27679. 'radical': 453,
  27680. 'Dcaron': 722,
  27681. 'rcommaaccent': 333,
  27682. 'Ntilde': 722,
  27683. 'otilde': 500,
  27684. 'Rcommaaccent': 667,
  27685. 'Lcommaaccent': 611,
  27686. 'Atilde': 722,
  27687. 'Aogonek': 722,
  27688. 'Aring': 722,
  27689. 'Otilde': 722,
  27690. 'zdotaccent': 444,
  27691. 'Ecaron': 611,
  27692. 'Iogonek': 333,
  27693. 'kcommaaccent': 500,
  27694. 'minus': 564,
  27695. 'Icircumflex': 333,
  27696. 'ncaron': 500,
  27697. 'tcommaaccent': 278,
  27698. 'logicalnot': 564,
  27699. 'odieresis': 500,
  27700. 'udieresis': 500,
  27701. 'notequal': 549,
  27702. 'gcommaaccent': 500,
  27703. 'eth': 500,
  27704. 'zcaron': 444,
  27705. 'ncommaaccent': 500,
  27706. 'onesuperior': 300,
  27707. 'imacron': 278,
  27708. 'Euro': 500
  27709. },
  27710. 'Times-Bold': {
  27711. 'space': 250,
  27712. 'exclam': 333,
  27713. 'quotedbl': 555,
  27714. 'numbersign': 500,
  27715. 'dollar': 500,
  27716. 'percent': 1000,
  27717. 'ampersand': 833,
  27718. 'quoteright': 333,
  27719. 'parenleft': 333,
  27720. 'parenright': 333,
  27721. 'asterisk': 500,
  27722. 'plus': 570,
  27723. 'comma': 250,
  27724. 'hyphen': 333,
  27725. 'period': 250,
  27726. 'slash': 278,
  27727. 'zero': 500,
  27728. 'one': 500,
  27729. 'two': 500,
  27730. 'three': 500,
  27731. 'four': 500,
  27732. 'five': 500,
  27733. 'six': 500,
  27734. 'seven': 500,
  27735. 'eight': 500,
  27736. 'nine': 500,
  27737. 'colon': 333,
  27738. 'semicolon': 333,
  27739. 'less': 570,
  27740. 'equal': 570,
  27741. 'greater': 570,
  27742. 'question': 500,
  27743. 'at': 930,
  27744. 'A': 722,
  27745. 'B': 667,
  27746. 'C': 722,
  27747. 'D': 722,
  27748. 'E': 667,
  27749. 'F': 611,
  27750. 'G': 778,
  27751. 'H': 778,
  27752. 'I': 389,
  27753. 'J': 500,
  27754. 'K': 778,
  27755. 'L': 667,
  27756. 'M': 944,
  27757. 'N': 722,
  27758. 'O': 778,
  27759. 'P': 611,
  27760. 'Q': 778,
  27761. 'R': 722,
  27762. 'S': 556,
  27763. 'T': 667,
  27764. 'U': 722,
  27765. 'V': 722,
  27766. 'W': 1000,
  27767. 'X': 722,
  27768. 'Y': 722,
  27769. 'Z': 667,
  27770. 'bracketleft': 333,
  27771. 'backslash': 278,
  27772. 'bracketright': 333,
  27773. 'asciicircum': 581,
  27774. 'underscore': 500,
  27775. 'quoteleft': 333,
  27776. 'a': 500,
  27777. 'b': 556,
  27778. 'c': 444,
  27779. 'd': 556,
  27780. 'e': 444,
  27781. 'f': 333,
  27782. 'g': 500,
  27783. 'h': 556,
  27784. 'i': 278,
  27785. 'j': 333,
  27786. 'k': 556,
  27787. 'l': 278,
  27788. 'm': 833,
  27789. 'n': 556,
  27790. 'o': 500,
  27791. 'p': 556,
  27792. 'q': 556,
  27793. 'r': 444,
  27794. 's': 389,
  27795. 't': 333,
  27796. 'u': 556,
  27797. 'v': 500,
  27798. 'w': 722,
  27799. 'x': 500,
  27800. 'y': 500,
  27801. 'z': 444,
  27802. 'braceleft': 394,
  27803. 'bar': 220,
  27804. 'braceright': 394,
  27805. 'asciitilde': 520,
  27806. 'exclamdown': 333,
  27807. 'cent': 500,
  27808. 'sterling': 500,
  27809. 'fraction': 167,
  27810. 'yen': 500,
  27811. 'florin': 500,
  27812. 'section': 500,
  27813. 'currency': 500,
  27814. 'quotesingle': 278,
  27815. 'quotedblleft': 500,
  27816. 'guillemotleft': 500,
  27817. 'guilsinglleft': 333,
  27818. 'guilsinglright': 333,
  27819. 'fi': 556,
  27820. 'fl': 556,
  27821. 'endash': 500,
  27822. 'dagger': 500,
  27823. 'daggerdbl': 500,
  27824. 'periodcentered': 250,
  27825. 'paragraph': 540,
  27826. 'bullet': 350,
  27827. 'quotesinglbase': 333,
  27828. 'quotedblbase': 500,
  27829. 'quotedblright': 500,
  27830. 'guillemotright': 500,
  27831. 'ellipsis': 1000,
  27832. 'perthousand': 1000,
  27833. 'questiondown': 500,
  27834. 'grave': 333,
  27835. 'acute': 333,
  27836. 'circumflex': 333,
  27837. 'tilde': 333,
  27838. 'macron': 333,
  27839. 'breve': 333,
  27840. 'dotaccent': 333,
  27841. 'dieresis': 333,
  27842. 'ring': 333,
  27843. 'cedilla': 333,
  27844. 'hungarumlaut': 333,
  27845. 'ogonek': 333,
  27846. 'caron': 333,
  27847. 'emdash': 1000,
  27848. 'AE': 1000,
  27849. 'ordfeminine': 300,
  27850. 'Lslash': 667,
  27851. 'Oslash': 778,
  27852. 'OE': 1000,
  27853. 'ordmasculine': 330,
  27854. 'ae': 722,
  27855. 'dotlessi': 278,
  27856. 'lslash': 278,
  27857. 'oslash': 500,
  27858. 'oe': 722,
  27859. 'germandbls': 556,
  27860. 'Idieresis': 389,
  27861. 'eacute': 444,
  27862. 'abreve': 500,
  27863. 'uhungarumlaut': 556,
  27864. 'ecaron': 444,
  27865. 'Ydieresis': 722,
  27866. 'divide': 570,
  27867. 'Yacute': 722,
  27868. 'Acircumflex': 722,
  27869. 'aacute': 500,
  27870. 'Ucircumflex': 722,
  27871. 'yacute': 500,
  27872. 'scommaaccent': 389,
  27873. 'ecircumflex': 444,
  27874. 'Uring': 722,
  27875. 'Udieresis': 722,
  27876. 'aogonek': 500,
  27877. 'Uacute': 722,
  27878. 'uogonek': 556,
  27879. 'Edieresis': 667,
  27880. 'Dcroat': 722,
  27881. 'commaaccent': 250,
  27882. 'copyright': 747,
  27883. 'Emacron': 667,
  27884. 'ccaron': 444,
  27885. 'aring': 500,
  27886. 'Ncommaaccent': 722,
  27887. 'lacute': 278,
  27888. 'agrave': 500,
  27889. 'Tcommaaccent': 667,
  27890. 'Cacute': 722,
  27891. 'atilde': 500,
  27892. 'Edotaccent': 667,
  27893. 'scaron': 389,
  27894. 'scedilla': 389,
  27895. 'iacute': 278,
  27896. 'lozenge': 494,
  27897. 'Rcaron': 722,
  27898. 'Gcommaaccent': 778,
  27899. 'ucircumflex': 556,
  27900. 'acircumflex': 500,
  27901. 'Amacron': 722,
  27902. 'rcaron': 444,
  27903. 'ccedilla': 444,
  27904. 'Zdotaccent': 667,
  27905. 'Thorn': 611,
  27906. 'Omacron': 778,
  27907. 'Racute': 722,
  27908. 'Sacute': 556,
  27909. 'dcaron': 672,
  27910. 'Umacron': 722,
  27911. 'uring': 556,
  27912. 'threesuperior': 300,
  27913. 'Ograve': 778,
  27914. 'Agrave': 722,
  27915. 'Abreve': 722,
  27916. 'multiply': 570,
  27917. 'uacute': 556,
  27918. 'Tcaron': 667,
  27919. 'partialdiff': 494,
  27920. 'ydieresis': 500,
  27921. 'Nacute': 722,
  27922. 'icircumflex': 278,
  27923. 'Ecircumflex': 667,
  27924. 'adieresis': 500,
  27925. 'edieresis': 444,
  27926. 'cacute': 444,
  27927. 'nacute': 556,
  27928. 'umacron': 556,
  27929. 'Ncaron': 722,
  27930. 'Iacute': 389,
  27931. 'plusminus': 570,
  27932. 'brokenbar': 220,
  27933. 'registered': 747,
  27934. 'Gbreve': 778,
  27935. 'Idotaccent': 389,
  27936. 'summation': 600,
  27937. 'Egrave': 667,
  27938. 'racute': 444,
  27939. 'omacron': 500,
  27940. 'Zacute': 667,
  27941. 'Zcaron': 667,
  27942. 'greaterequal': 549,
  27943. 'Eth': 722,
  27944. 'Ccedilla': 722,
  27945. 'lcommaaccent': 278,
  27946. 'tcaron': 416,
  27947. 'eogonek': 444,
  27948. 'Uogonek': 722,
  27949. 'Aacute': 722,
  27950. 'Adieresis': 722,
  27951. 'egrave': 444,
  27952. 'zacute': 444,
  27953. 'iogonek': 278,
  27954. 'Oacute': 778,
  27955. 'oacute': 500,
  27956. 'amacron': 500,
  27957. 'sacute': 389,
  27958. 'idieresis': 278,
  27959. 'Ocircumflex': 778,
  27960. 'Ugrave': 722,
  27961. 'Delta': 612,
  27962. 'thorn': 556,
  27963. 'twosuperior': 300,
  27964. 'Odieresis': 778,
  27965. 'mu': 556,
  27966. 'igrave': 278,
  27967. 'ohungarumlaut': 500,
  27968. 'Eogonek': 667,
  27969. 'dcroat': 556,
  27970. 'threequarters': 750,
  27971. 'Scedilla': 556,
  27972. 'lcaron': 394,
  27973. 'Kcommaaccent': 778,
  27974. 'Lacute': 667,
  27975. 'trademark': 1000,
  27976. 'edotaccent': 444,
  27977. 'Igrave': 389,
  27978. 'Imacron': 389,
  27979. 'Lcaron': 667,
  27980. 'onehalf': 750,
  27981. 'lessequal': 549,
  27982. 'ocircumflex': 500,
  27983. 'ntilde': 556,
  27984. 'Uhungarumlaut': 722,
  27985. 'Eacute': 667,
  27986. 'emacron': 444,
  27987. 'gbreve': 500,
  27988. 'onequarter': 750,
  27989. 'Scaron': 556,
  27990. 'Scommaaccent': 556,
  27991. 'Ohungarumlaut': 778,
  27992. 'degree': 400,
  27993. 'ograve': 500,
  27994. 'Ccaron': 722,
  27995. 'ugrave': 556,
  27996. 'radical': 549,
  27997. 'Dcaron': 722,
  27998. 'rcommaaccent': 444,
  27999. 'Ntilde': 722,
  28000. 'otilde': 500,
  28001. 'Rcommaaccent': 722,
  28002. 'Lcommaaccent': 667,
  28003. 'Atilde': 722,
  28004. 'Aogonek': 722,
  28005. 'Aring': 722,
  28006. 'Otilde': 778,
  28007. 'zdotaccent': 444,
  28008. 'Ecaron': 667,
  28009. 'Iogonek': 389,
  28010. 'kcommaaccent': 556,
  28011. 'minus': 570,
  28012. 'Icircumflex': 389,
  28013. 'ncaron': 556,
  28014. 'tcommaaccent': 333,
  28015. 'logicalnot': 570,
  28016. 'odieresis': 500,
  28017. 'udieresis': 556,
  28018. 'notequal': 549,
  28019. 'gcommaaccent': 500,
  28020. 'eth': 500,
  28021. 'zcaron': 444,
  28022. 'ncommaaccent': 556,
  28023. 'onesuperior': 300,
  28024. 'imacron': 278,
  28025. 'Euro': 500
  28026. },
  28027. 'Times-BoldItalic': {
  28028. 'space': 250,
  28029. 'exclam': 389,
  28030. 'quotedbl': 555,
  28031. 'numbersign': 500,
  28032. 'dollar': 500,
  28033. 'percent': 833,
  28034. 'ampersand': 778,
  28035. 'quoteright': 333,
  28036. 'parenleft': 333,
  28037. 'parenright': 333,
  28038. 'asterisk': 500,
  28039. 'plus': 570,
  28040. 'comma': 250,
  28041. 'hyphen': 333,
  28042. 'period': 250,
  28043. 'slash': 278,
  28044. 'zero': 500,
  28045. 'one': 500,
  28046. 'two': 500,
  28047. 'three': 500,
  28048. 'four': 500,
  28049. 'five': 500,
  28050. 'six': 500,
  28051. 'seven': 500,
  28052. 'eight': 500,
  28053. 'nine': 500,
  28054. 'colon': 333,
  28055. 'semicolon': 333,
  28056. 'less': 570,
  28057. 'equal': 570,
  28058. 'greater': 570,
  28059. 'question': 500,
  28060. 'at': 832,
  28061. 'A': 667,
  28062. 'B': 667,
  28063. 'C': 667,
  28064. 'D': 722,
  28065. 'E': 667,
  28066. 'F': 667,
  28067. 'G': 722,
  28068. 'H': 778,
  28069. 'I': 389,
  28070. 'J': 500,
  28071. 'K': 667,
  28072. 'L': 611,
  28073. 'M': 889,
  28074. 'N': 722,
  28075. 'O': 722,
  28076. 'P': 611,
  28077. 'Q': 722,
  28078. 'R': 667,
  28079. 'S': 556,
  28080. 'T': 611,
  28081. 'U': 722,
  28082. 'V': 667,
  28083. 'W': 889,
  28084. 'X': 667,
  28085. 'Y': 611,
  28086. 'Z': 611,
  28087. 'bracketleft': 333,
  28088. 'backslash': 278,
  28089. 'bracketright': 333,
  28090. 'asciicircum': 570,
  28091. 'underscore': 500,
  28092. 'quoteleft': 333,
  28093. 'a': 500,
  28094. 'b': 500,
  28095. 'c': 444,
  28096. 'd': 500,
  28097. 'e': 444,
  28098. 'f': 333,
  28099. 'g': 500,
  28100. 'h': 556,
  28101. 'i': 278,
  28102. 'j': 278,
  28103. 'k': 500,
  28104. 'l': 278,
  28105. 'm': 778,
  28106. 'n': 556,
  28107. 'o': 500,
  28108. 'p': 500,
  28109. 'q': 500,
  28110. 'r': 389,
  28111. 's': 389,
  28112. 't': 278,
  28113. 'u': 556,
  28114. 'v': 444,
  28115. 'w': 667,
  28116. 'x': 500,
  28117. 'y': 444,
  28118. 'z': 389,
  28119. 'braceleft': 348,
  28120. 'bar': 220,
  28121. 'braceright': 348,
  28122. 'asciitilde': 570,
  28123. 'exclamdown': 389,
  28124. 'cent': 500,
  28125. 'sterling': 500,
  28126. 'fraction': 167,
  28127. 'yen': 500,
  28128. 'florin': 500,
  28129. 'section': 500,
  28130. 'currency': 500,
  28131. 'quotesingle': 278,
  28132. 'quotedblleft': 500,
  28133. 'guillemotleft': 500,
  28134. 'guilsinglleft': 333,
  28135. 'guilsinglright': 333,
  28136. 'fi': 556,
  28137. 'fl': 556,
  28138. 'endash': 500,
  28139. 'dagger': 500,
  28140. 'daggerdbl': 500,
  28141. 'periodcentered': 250,
  28142. 'paragraph': 500,
  28143. 'bullet': 350,
  28144. 'quotesinglbase': 333,
  28145. 'quotedblbase': 500,
  28146. 'quotedblright': 500,
  28147. 'guillemotright': 500,
  28148. 'ellipsis': 1000,
  28149. 'perthousand': 1000,
  28150. 'questiondown': 500,
  28151. 'grave': 333,
  28152. 'acute': 333,
  28153. 'circumflex': 333,
  28154. 'tilde': 333,
  28155. 'macron': 333,
  28156. 'breve': 333,
  28157. 'dotaccent': 333,
  28158. 'dieresis': 333,
  28159. 'ring': 333,
  28160. 'cedilla': 333,
  28161. 'hungarumlaut': 333,
  28162. 'ogonek': 333,
  28163. 'caron': 333,
  28164. 'emdash': 1000,
  28165. 'AE': 944,
  28166. 'ordfeminine': 266,
  28167. 'Lslash': 611,
  28168. 'Oslash': 722,
  28169. 'OE': 944,
  28170. 'ordmasculine': 300,
  28171. 'ae': 722,
  28172. 'dotlessi': 278,
  28173. 'lslash': 278,
  28174. 'oslash': 500,
  28175. 'oe': 722,
  28176. 'germandbls': 500,
  28177. 'Idieresis': 389,
  28178. 'eacute': 444,
  28179. 'abreve': 500,
  28180. 'uhungarumlaut': 556,
  28181. 'ecaron': 444,
  28182. 'Ydieresis': 611,
  28183. 'divide': 570,
  28184. 'Yacute': 611,
  28185. 'Acircumflex': 667,
  28186. 'aacute': 500,
  28187. 'Ucircumflex': 722,
  28188. 'yacute': 444,
  28189. 'scommaaccent': 389,
  28190. 'ecircumflex': 444,
  28191. 'Uring': 722,
  28192. 'Udieresis': 722,
  28193. 'aogonek': 500,
  28194. 'Uacute': 722,
  28195. 'uogonek': 556,
  28196. 'Edieresis': 667,
  28197. 'Dcroat': 722,
  28198. 'commaaccent': 250,
  28199. 'copyright': 747,
  28200. 'Emacron': 667,
  28201. 'ccaron': 444,
  28202. 'aring': 500,
  28203. 'Ncommaaccent': 722,
  28204. 'lacute': 278,
  28205. 'agrave': 500,
  28206. 'Tcommaaccent': 611,
  28207. 'Cacute': 667,
  28208. 'atilde': 500,
  28209. 'Edotaccent': 667,
  28210. 'scaron': 389,
  28211. 'scedilla': 389,
  28212. 'iacute': 278,
  28213. 'lozenge': 494,
  28214. 'Rcaron': 667,
  28215. 'Gcommaaccent': 722,
  28216. 'ucircumflex': 556,
  28217. 'acircumflex': 500,
  28218. 'Amacron': 667,
  28219. 'rcaron': 389,
  28220. 'ccedilla': 444,
  28221. 'Zdotaccent': 611,
  28222. 'Thorn': 611,
  28223. 'Omacron': 722,
  28224. 'Racute': 667,
  28225. 'Sacute': 556,
  28226. 'dcaron': 608,
  28227. 'Umacron': 722,
  28228. 'uring': 556,
  28229. 'threesuperior': 300,
  28230. 'Ograve': 722,
  28231. 'Agrave': 667,
  28232. 'Abreve': 667,
  28233. 'multiply': 570,
  28234. 'uacute': 556,
  28235. 'Tcaron': 611,
  28236. 'partialdiff': 494,
  28237. 'ydieresis': 444,
  28238. 'Nacute': 722,
  28239. 'icircumflex': 278,
  28240. 'Ecircumflex': 667,
  28241. 'adieresis': 500,
  28242. 'edieresis': 444,
  28243. 'cacute': 444,
  28244. 'nacute': 556,
  28245. 'umacron': 556,
  28246. 'Ncaron': 722,
  28247. 'Iacute': 389,
  28248. 'plusminus': 570,
  28249. 'brokenbar': 220,
  28250. 'registered': 747,
  28251. 'Gbreve': 722,
  28252. 'Idotaccent': 389,
  28253. 'summation': 600,
  28254. 'Egrave': 667,
  28255. 'racute': 389,
  28256. 'omacron': 500,
  28257. 'Zacute': 611,
  28258. 'Zcaron': 611,
  28259. 'greaterequal': 549,
  28260. 'Eth': 722,
  28261. 'Ccedilla': 667,
  28262. 'lcommaaccent': 278,
  28263. 'tcaron': 366,
  28264. 'eogonek': 444,
  28265. 'Uogonek': 722,
  28266. 'Aacute': 667,
  28267. 'Adieresis': 667,
  28268. 'egrave': 444,
  28269. 'zacute': 389,
  28270. 'iogonek': 278,
  28271. 'Oacute': 722,
  28272. 'oacute': 500,
  28273. 'amacron': 500,
  28274. 'sacute': 389,
  28275. 'idieresis': 278,
  28276. 'Ocircumflex': 722,
  28277. 'Ugrave': 722,
  28278. 'Delta': 612,
  28279. 'thorn': 500,
  28280. 'twosuperior': 300,
  28281. 'Odieresis': 722,
  28282. 'mu': 576,
  28283. 'igrave': 278,
  28284. 'ohungarumlaut': 500,
  28285. 'Eogonek': 667,
  28286. 'dcroat': 500,
  28287. 'threequarters': 750,
  28288. 'Scedilla': 556,
  28289. 'lcaron': 382,
  28290. 'Kcommaaccent': 667,
  28291. 'Lacute': 611,
  28292. 'trademark': 1000,
  28293. 'edotaccent': 444,
  28294. 'Igrave': 389,
  28295. 'Imacron': 389,
  28296. 'Lcaron': 611,
  28297. 'onehalf': 750,
  28298. 'lessequal': 549,
  28299. 'ocircumflex': 500,
  28300. 'ntilde': 556,
  28301. 'Uhungarumlaut': 722,
  28302. 'Eacute': 667,
  28303. 'emacron': 444,
  28304. 'gbreve': 500,
  28305. 'onequarter': 750,
  28306. 'Scaron': 556,
  28307. 'Scommaaccent': 556,
  28308. 'Ohungarumlaut': 722,
  28309. 'degree': 400,
  28310. 'ograve': 500,
  28311. 'Ccaron': 667,
  28312. 'ugrave': 556,
  28313. 'radical': 549,
  28314. 'Dcaron': 722,
  28315. 'rcommaaccent': 389,
  28316. 'Ntilde': 722,
  28317. 'otilde': 500,
  28318. 'Rcommaaccent': 667,
  28319. 'Lcommaaccent': 611,
  28320. 'Atilde': 667,
  28321. 'Aogonek': 667,
  28322. 'Aring': 667,
  28323. 'Otilde': 722,
  28324. 'zdotaccent': 389,
  28325. 'Ecaron': 667,
  28326. 'Iogonek': 389,
  28327. 'kcommaaccent': 500,
  28328. 'minus': 606,
  28329. 'Icircumflex': 389,
  28330. 'ncaron': 556,
  28331. 'tcommaaccent': 278,
  28332. 'logicalnot': 606,
  28333. 'odieresis': 500,
  28334. 'udieresis': 556,
  28335. 'notequal': 549,
  28336. 'gcommaaccent': 500,
  28337. 'eth': 500,
  28338. 'zcaron': 389,
  28339. 'ncommaaccent': 556,
  28340. 'onesuperior': 300,
  28341. 'imacron': 278,
  28342. 'Euro': 500
  28343. },
  28344. 'Times-Italic': {
  28345. 'space': 250,
  28346. 'exclam': 333,
  28347. 'quotedbl': 420,
  28348. 'numbersign': 500,
  28349. 'dollar': 500,
  28350. 'percent': 833,
  28351. 'ampersand': 778,
  28352. 'quoteright': 333,
  28353. 'parenleft': 333,
  28354. 'parenright': 333,
  28355. 'asterisk': 500,
  28356. 'plus': 675,
  28357. 'comma': 250,
  28358. 'hyphen': 333,
  28359. 'period': 250,
  28360. 'slash': 278,
  28361. 'zero': 500,
  28362. 'one': 500,
  28363. 'two': 500,
  28364. 'three': 500,
  28365. 'four': 500,
  28366. 'five': 500,
  28367. 'six': 500,
  28368. 'seven': 500,
  28369. 'eight': 500,
  28370. 'nine': 500,
  28371. 'colon': 333,
  28372. 'semicolon': 333,
  28373. 'less': 675,
  28374. 'equal': 675,
  28375. 'greater': 675,
  28376. 'question': 500,
  28377. 'at': 920,
  28378. 'A': 611,
  28379. 'B': 611,
  28380. 'C': 667,
  28381. 'D': 722,
  28382. 'E': 611,
  28383. 'F': 611,
  28384. 'G': 722,
  28385. 'H': 722,
  28386. 'I': 333,
  28387. 'J': 444,
  28388. 'K': 667,
  28389. 'L': 556,
  28390. 'M': 833,
  28391. 'N': 667,
  28392. 'O': 722,
  28393. 'P': 611,
  28394. 'Q': 722,
  28395. 'R': 611,
  28396. 'S': 500,
  28397. 'T': 556,
  28398. 'U': 722,
  28399. 'V': 611,
  28400. 'W': 833,
  28401. 'X': 611,
  28402. 'Y': 556,
  28403. 'Z': 556,
  28404. 'bracketleft': 389,
  28405. 'backslash': 278,
  28406. 'bracketright': 389,
  28407. 'asciicircum': 422,
  28408. 'underscore': 500,
  28409. 'quoteleft': 333,
  28410. 'a': 500,
  28411. 'b': 500,
  28412. 'c': 444,
  28413. 'd': 500,
  28414. 'e': 444,
  28415. 'f': 278,
  28416. 'g': 500,
  28417. 'h': 500,
  28418. 'i': 278,
  28419. 'j': 278,
  28420. 'k': 444,
  28421. 'l': 278,
  28422. 'm': 722,
  28423. 'n': 500,
  28424. 'o': 500,
  28425. 'p': 500,
  28426. 'q': 500,
  28427. 'r': 389,
  28428. 's': 389,
  28429. 't': 278,
  28430. 'u': 500,
  28431. 'v': 444,
  28432. 'w': 667,
  28433. 'x': 444,
  28434. 'y': 444,
  28435. 'z': 389,
  28436. 'braceleft': 400,
  28437. 'bar': 275,
  28438. 'braceright': 400,
  28439. 'asciitilde': 541,
  28440. 'exclamdown': 389,
  28441. 'cent': 500,
  28442. 'sterling': 500,
  28443. 'fraction': 167,
  28444. 'yen': 500,
  28445. 'florin': 500,
  28446. 'section': 500,
  28447. 'currency': 500,
  28448. 'quotesingle': 214,
  28449. 'quotedblleft': 556,
  28450. 'guillemotleft': 500,
  28451. 'guilsinglleft': 333,
  28452. 'guilsinglright': 333,
  28453. 'fi': 500,
  28454. 'fl': 500,
  28455. 'endash': 500,
  28456. 'dagger': 500,
  28457. 'daggerdbl': 500,
  28458. 'periodcentered': 250,
  28459. 'paragraph': 523,
  28460. 'bullet': 350,
  28461. 'quotesinglbase': 333,
  28462. 'quotedblbase': 556,
  28463. 'quotedblright': 556,
  28464. 'guillemotright': 500,
  28465. 'ellipsis': 889,
  28466. 'perthousand': 1000,
  28467. 'questiondown': 500,
  28468. 'grave': 333,
  28469. 'acute': 333,
  28470. 'circumflex': 333,
  28471. 'tilde': 333,
  28472. 'macron': 333,
  28473. 'breve': 333,
  28474. 'dotaccent': 333,
  28475. 'dieresis': 333,
  28476. 'ring': 333,
  28477. 'cedilla': 333,
  28478. 'hungarumlaut': 333,
  28479. 'ogonek': 333,
  28480. 'caron': 333,
  28481. 'emdash': 889,
  28482. 'AE': 889,
  28483. 'ordfeminine': 276,
  28484. 'Lslash': 556,
  28485. 'Oslash': 722,
  28486. 'OE': 944,
  28487. 'ordmasculine': 310,
  28488. 'ae': 667,
  28489. 'dotlessi': 278,
  28490. 'lslash': 278,
  28491. 'oslash': 500,
  28492. 'oe': 667,
  28493. 'germandbls': 500,
  28494. 'Idieresis': 333,
  28495. 'eacute': 444,
  28496. 'abreve': 500,
  28497. 'uhungarumlaut': 500,
  28498. 'ecaron': 444,
  28499. 'Ydieresis': 556,
  28500. 'divide': 675,
  28501. 'Yacute': 556,
  28502. 'Acircumflex': 611,
  28503. 'aacute': 500,
  28504. 'Ucircumflex': 722,
  28505. 'yacute': 444,
  28506. 'scommaaccent': 389,
  28507. 'ecircumflex': 444,
  28508. 'Uring': 722,
  28509. 'Udieresis': 722,
  28510. 'aogonek': 500,
  28511. 'Uacute': 722,
  28512. 'uogonek': 500,
  28513. 'Edieresis': 611,
  28514. 'Dcroat': 722,
  28515. 'commaaccent': 250,
  28516. 'copyright': 760,
  28517. 'Emacron': 611,
  28518. 'ccaron': 444,
  28519. 'aring': 500,
  28520. 'Ncommaaccent': 667,
  28521. 'lacute': 278,
  28522. 'agrave': 500,
  28523. 'Tcommaaccent': 556,
  28524. 'Cacute': 667,
  28525. 'atilde': 500,
  28526. 'Edotaccent': 611,
  28527. 'scaron': 389,
  28528. 'scedilla': 389,
  28529. 'iacute': 278,
  28530. 'lozenge': 471,
  28531. 'Rcaron': 611,
  28532. 'Gcommaaccent': 722,
  28533. 'ucircumflex': 500,
  28534. 'acircumflex': 500,
  28535. 'Amacron': 611,
  28536. 'rcaron': 389,
  28537. 'ccedilla': 444,
  28538. 'Zdotaccent': 556,
  28539. 'Thorn': 611,
  28540. 'Omacron': 722,
  28541. 'Racute': 611,
  28542. 'Sacute': 500,
  28543. 'dcaron': 544,
  28544. 'Umacron': 722,
  28545. 'uring': 500,
  28546. 'threesuperior': 300,
  28547. 'Ograve': 722,
  28548. 'Agrave': 611,
  28549. 'Abreve': 611,
  28550. 'multiply': 675,
  28551. 'uacute': 500,
  28552. 'Tcaron': 556,
  28553. 'partialdiff': 476,
  28554. 'ydieresis': 444,
  28555. 'Nacute': 667,
  28556. 'icircumflex': 278,
  28557. 'Ecircumflex': 611,
  28558. 'adieresis': 500,
  28559. 'edieresis': 444,
  28560. 'cacute': 444,
  28561. 'nacute': 500,
  28562. 'umacron': 500,
  28563. 'Ncaron': 667,
  28564. 'Iacute': 333,
  28565. 'plusminus': 675,
  28566. 'brokenbar': 275,
  28567. 'registered': 760,
  28568. 'Gbreve': 722,
  28569. 'Idotaccent': 333,
  28570. 'summation': 600,
  28571. 'Egrave': 611,
  28572. 'racute': 389,
  28573. 'omacron': 500,
  28574. 'Zacute': 556,
  28575. 'Zcaron': 556,
  28576. 'greaterequal': 549,
  28577. 'Eth': 722,
  28578. 'Ccedilla': 667,
  28579. 'lcommaaccent': 278,
  28580. 'tcaron': 300,
  28581. 'eogonek': 444,
  28582. 'Uogonek': 722,
  28583. 'Aacute': 611,
  28584. 'Adieresis': 611,
  28585. 'egrave': 444,
  28586. 'zacute': 389,
  28587. 'iogonek': 278,
  28588. 'Oacute': 722,
  28589. 'oacute': 500,
  28590. 'amacron': 500,
  28591. 'sacute': 389,
  28592. 'idieresis': 278,
  28593. 'Ocircumflex': 722,
  28594. 'Ugrave': 722,
  28595. 'Delta': 612,
  28596. 'thorn': 500,
  28597. 'twosuperior': 300,
  28598. 'Odieresis': 722,
  28599. 'mu': 500,
  28600. 'igrave': 278,
  28601. 'ohungarumlaut': 500,
  28602. 'Eogonek': 611,
  28603. 'dcroat': 500,
  28604. 'threequarters': 750,
  28605. 'Scedilla': 500,
  28606. 'lcaron': 300,
  28607. 'Kcommaaccent': 667,
  28608. 'Lacute': 556,
  28609. 'trademark': 980,
  28610. 'edotaccent': 444,
  28611. 'Igrave': 333,
  28612. 'Imacron': 333,
  28613. 'Lcaron': 611,
  28614. 'onehalf': 750,
  28615. 'lessequal': 549,
  28616. 'ocircumflex': 500,
  28617. 'ntilde': 500,
  28618. 'Uhungarumlaut': 722,
  28619. 'Eacute': 611,
  28620. 'emacron': 444,
  28621. 'gbreve': 500,
  28622. 'onequarter': 750,
  28623. 'Scaron': 500,
  28624. 'Scommaaccent': 500,
  28625. 'Ohungarumlaut': 722,
  28626. 'degree': 400,
  28627. 'ograve': 500,
  28628. 'Ccaron': 667,
  28629. 'ugrave': 500,
  28630. 'radical': 453,
  28631. 'Dcaron': 722,
  28632. 'rcommaaccent': 389,
  28633. 'Ntilde': 667,
  28634. 'otilde': 500,
  28635. 'Rcommaaccent': 611,
  28636. 'Lcommaaccent': 556,
  28637. 'Atilde': 611,
  28638. 'Aogonek': 611,
  28639. 'Aring': 611,
  28640. 'Otilde': 722,
  28641. 'zdotaccent': 389,
  28642. 'Ecaron': 611,
  28643. 'Iogonek': 333,
  28644. 'kcommaaccent': 444,
  28645. 'minus': 675,
  28646. 'Icircumflex': 333,
  28647. 'ncaron': 500,
  28648. 'tcommaaccent': 278,
  28649. 'logicalnot': 675,
  28650. 'odieresis': 500,
  28651. 'udieresis': 500,
  28652. 'notequal': 549,
  28653. 'gcommaaccent': 500,
  28654. 'eth': 500,
  28655. 'zcaron': 389,
  28656. 'ncommaaccent': 500,
  28657. 'onesuperior': 300,
  28658. 'imacron': 278,
  28659. 'Euro': 500
  28660. },
  28661. 'ZapfDingbats': {
  28662. 'space': 278,
  28663. 'a1': 974,
  28664. 'a2': 961,
  28665. 'a202': 974,
  28666. 'a3': 980,
  28667. 'a4': 719,
  28668. 'a5': 789,
  28669. 'a119': 790,
  28670. 'a118': 791,
  28671. 'a117': 690,
  28672. 'a11': 960,
  28673. 'a12': 939,
  28674. 'a13': 549,
  28675. 'a14': 855,
  28676. 'a15': 911,
  28677. 'a16': 933,
  28678. 'a105': 911,
  28679. 'a17': 945,
  28680. 'a18': 974,
  28681. 'a19': 755,
  28682. 'a20': 846,
  28683. 'a21': 762,
  28684. 'a22': 761,
  28685. 'a23': 571,
  28686. 'a24': 677,
  28687. 'a25': 763,
  28688. 'a26': 760,
  28689. 'a27': 759,
  28690. 'a28': 754,
  28691. 'a6': 494,
  28692. 'a7': 552,
  28693. 'a8': 537,
  28694. 'a9': 577,
  28695. 'a10': 692,
  28696. 'a29': 786,
  28697. 'a30': 788,
  28698. 'a31': 788,
  28699. 'a32': 790,
  28700. 'a33': 793,
  28701. 'a34': 794,
  28702. 'a35': 816,
  28703. 'a36': 823,
  28704. 'a37': 789,
  28705. 'a38': 841,
  28706. 'a39': 823,
  28707. 'a40': 833,
  28708. 'a41': 816,
  28709. 'a42': 831,
  28710. 'a43': 923,
  28711. 'a44': 744,
  28712. 'a45': 723,
  28713. 'a46': 749,
  28714. 'a47': 790,
  28715. 'a48': 792,
  28716. 'a49': 695,
  28717. 'a50': 776,
  28718. 'a51': 768,
  28719. 'a52': 792,
  28720. 'a53': 759,
  28721. 'a54': 707,
  28722. 'a55': 708,
  28723. 'a56': 682,
  28724. 'a57': 701,
  28725. 'a58': 826,
  28726. 'a59': 815,
  28727. 'a60': 789,
  28728. 'a61': 789,
  28729. 'a62': 707,
  28730. 'a63': 687,
  28731. 'a64': 696,
  28732. 'a65': 689,
  28733. 'a66': 786,
  28734. 'a67': 787,
  28735. 'a68': 713,
  28736. 'a69': 791,
  28737. 'a70': 785,
  28738. 'a71': 791,
  28739. 'a72': 873,
  28740. 'a73': 761,
  28741. 'a74': 762,
  28742. 'a203': 762,
  28743. 'a75': 759,
  28744. 'a204': 759,
  28745. 'a76': 892,
  28746. 'a77': 892,
  28747. 'a78': 788,
  28748. 'a79': 784,
  28749. 'a81': 438,
  28750. 'a82': 138,
  28751. 'a83': 277,
  28752. 'a84': 415,
  28753. 'a97': 392,
  28754. 'a98': 392,
  28755. 'a99': 668,
  28756. 'a100': 668,
  28757. 'a89': 390,
  28758. 'a90': 390,
  28759. 'a93': 317,
  28760. 'a94': 317,
  28761. 'a91': 276,
  28762. 'a92': 276,
  28763. 'a205': 509,
  28764. 'a85': 509,
  28765. 'a206': 410,
  28766. 'a86': 410,
  28767. 'a87': 234,
  28768. 'a88': 234,
  28769. 'a95': 334,
  28770. 'a96': 334,
  28771. 'a101': 732,
  28772. 'a102': 544,
  28773. 'a103': 544,
  28774. 'a104': 910,
  28775. 'a106': 667,
  28776. 'a107': 760,
  28777. 'a108': 760,
  28778. 'a112': 776,
  28779. 'a111': 595,
  28780. 'a110': 694,
  28781. 'a109': 626,
  28782. 'a120': 788,
  28783. 'a121': 788,
  28784. 'a122': 788,
  28785. 'a123': 788,
  28786. 'a124': 788,
  28787. 'a125': 788,
  28788. 'a126': 788,
  28789. 'a127': 788,
  28790. 'a128': 788,
  28791. 'a129': 788,
  28792. 'a130': 788,
  28793. 'a131': 788,
  28794. 'a132': 788,
  28795. 'a133': 788,
  28796. 'a134': 788,
  28797. 'a135': 788,
  28798. 'a136': 788,
  28799. 'a137': 788,
  28800. 'a138': 788,
  28801. 'a139': 788,
  28802. 'a140': 788,
  28803. 'a141': 788,
  28804. 'a142': 788,
  28805. 'a143': 788,
  28806. 'a144': 788,
  28807. 'a145': 788,
  28808. 'a146': 788,
  28809. 'a147': 788,
  28810. 'a148': 788,
  28811. 'a149': 788,
  28812. 'a150': 788,
  28813. 'a151': 788,
  28814. 'a152': 788,
  28815. 'a153': 788,
  28816. 'a154': 788,
  28817. 'a155': 788,
  28818. 'a156': 788,
  28819. 'a157': 788,
  28820. 'a158': 788,
  28821. 'a159': 788,
  28822. 'a160': 894,
  28823. 'a161': 838,
  28824. 'a163': 1016,
  28825. 'a164': 458,
  28826. 'a196': 748,
  28827. 'a165': 924,
  28828. 'a192': 748,
  28829. 'a166': 918,
  28830. 'a167': 927,
  28831. 'a168': 928,
  28832. 'a169': 928,
  28833. 'a170': 834,
  28834. 'a171': 873,
  28835. 'a172': 828,
  28836. 'a173': 924,
  28837. 'a162': 924,
  28838. 'a174': 917,
  28839. 'a175': 930,
  28840. 'a176': 931,
  28841. 'a177': 463,
  28842. 'a178': 883,
  28843. 'a179': 836,
  28844. 'a193': 836,
  28845. 'a180': 867,
  28846. 'a199': 867,
  28847. 'a181': 696,
  28848. 'a200': 696,
  28849. 'a182': 874,
  28850. 'a201': 874,
  28851. 'a183': 760,
  28852. 'a184': 946,
  28853. 'a197': 771,
  28854. 'a185': 865,
  28855. 'a194': 771,
  28856. 'a198': 888,
  28857. 'a186': 967,
  28858. 'a195': 888,
  28859. 'a187': 831,
  28860. 'a188': 873,
  28861. 'a189': 927,
  28862. 'a190': 970,
  28863. 'a191': 918
  28864. }
  28865. };
  28866. var EOF = {};
  28867. function isEOF(v) {
  28868. return (v === EOF);
  28869. }
  28870. var MAX_LENGTH_TO_CACHE = 1000;
  28871. var Parser = (function ParserClosure() {
  28872. function Parser(lexer, allowStreams, xref) {
  28873. this.lexer = lexer;
  28874. this.allowStreams = allowStreams;
  28875. this.xref = xref;
  28876. this.imageCache = {};
  28877. this.refill();
  28878. }
  28879. Parser.prototype = {
  28880. refill: function Parser_refill() {
  28881. this.buf1 = this.lexer.getObj();
  28882. this.buf2 = this.lexer.getObj();
  28883. },
  28884. shift: function Parser_shift() {
  28885. if (isCmd(this.buf2, 'ID')) {
  28886. this.buf1 = this.buf2;
  28887. this.buf2 = null;
  28888. } else {
  28889. this.buf1 = this.buf2;
  28890. this.buf2 = this.lexer.getObj();
  28891. }
  28892. },
  28893. tryShift: function Parser_tryShift() {
  28894. try {
  28895. this.shift();
  28896. return true;
  28897. } catch (e) {
  28898. if (e instanceof MissingDataException) {
  28899. throw e;
  28900. }
  28901. // Upon failure, the caller should reset this.lexer.pos to a known good
  28902. // state and call this.shift() twice to reset the buffers.
  28903. return false;
  28904. }
  28905. },
  28906. getObj: function Parser_getObj(cipherTransform) {
  28907. var buf1 = this.buf1;
  28908. this.shift();
  28909. if (buf1 instanceof Cmd) {
  28910. switch (buf1.cmd) {
  28911. case 'BI': // inline image
  28912. return this.makeInlineImage(cipherTransform);
  28913. case '[': // array
  28914. var array = [];
  28915. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28916. array.push(this.getObj(cipherTransform));
  28917. }
  28918. if (isEOF(this.buf1)) {
  28919. error('End of file inside array');
  28920. }
  28921. this.shift();
  28922. return array;
  28923. case '<<': // dictionary or stream
  28924. var dict = new Dict(this.xref);
  28925. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28926. if (!isName(this.buf1)) {
  28927. info('Malformed dictionary: key must be a name object');
  28928. this.shift();
  28929. continue;
  28930. }
  28931. var key = this.buf1.name;
  28932. this.shift();
  28933. if (isEOF(this.buf1)) {
  28934. break;
  28935. }
  28936. dict.set(key, this.getObj(cipherTransform));
  28937. }
  28938. if (isEOF(this.buf1)) {
  28939. error('End of file inside dictionary');
  28940. }
  28941. // Stream objects are not allowed inside content streams or
  28942. // object streams.
  28943. if (isCmd(this.buf2, 'stream')) {
  28944. return (this.allowStreams ?
  28945. this.makeStream(dict, cipherTransform) : dict);
  28946. }
  28947. this.shift();
  28948. return dict;
  28949. default: // simple object
  28950. return buf1;
  28951. }
  28952. }
  28953. if (isInt(buf1)) { // indirect reference or integer
  28954. var num = buf1;
  28955. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28956. var ref = new Ref(num, this.buf1);
  28957. this.shift();
  28958. this.shift();
  28959. return ref;
  28960. }
  28961. return num;
  28962. }
  28963. if (isString(buf1)) { // string
  28964. var str = buf1;
  28965. if (cipherTransform) {
  28966. str = cipherTransform.decryptString(str);
  28967. }
  28968. return str;
  28969. }
  28970. // simple object
  28971. return buf1;
  28972. },
  28973. /**
  28974. * Find the end of the stream by searching for the /EI\s/.
  28975. * @returns {number} The inline stream length.
  28976. */
  28977. findDefaultInlineStreamEnd:
  28978. function Parser_findDefaultInlineStreamEnd(stream) {
  28979. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28980. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28981. while ((ch = stream.getByte()) !== -1) {
  28982. if (state === 0) {
  28983. state = (ch === E) ? 1 : 0;
  28984. } else if (state === 1) {
  28985. state = (ch === I) ? 2 : 0;
  28986. } else {
  28987. assert(state === 2);
  28988. if (ch === SPACE || ch === LF || ch === CR) {
  28989. // Let's check the next five bytes are ASCII... just be sure.
  28990. n = 5;
  28991. followingBytes = stream.peekBytes(n);
  28992. for (i = 0; i < n; i++) {
  28993. ch = followingBytes[i];
  28994. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28995. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28996. // it's binary stuff. Resetting the state.
  28997. state = 0;
  28998. break;
  28999. }
  29000. }
  29001. if (state === 2) {
  29002. break; // Finished!
  29003. }
  29004. } else {
  29005. state = 0;
  29006. }
  29007. }
  29008. }
  29009. return ((stream.pos - 4) - startPos);
  29010. },
  29011. /**
  29012. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  29013. * @returns {number} The inline stream length.
  29014. */
  29015. findDCTDecodeInlineStreamEnd:
  29016. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  29017. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  29018. while ((b = stream.getByte()) !== -1) {
  29019. if (b !== 0xFF) { // Not a valid marker.
  29020. continue;
  29021. }
  29022. switch (stream.getByte()) {
  29023. case 0x00: // Byte stuffing.
  29024. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  29025. break;
  29026. case 0xFF: // Fill byte.
  29027. // Avoid skipping a valid marker, resetting the stream position.
  29028. stream.skip(-1);
  29029. break;
  29030. case 0xD9: // EOI
  29031. foundEOI = true;
  29032. break;
  29033. case 0xC0: // SOF0
  29034. case 0xC1: // SOF1
  29035. case 0xC2: // SOF2
  29036. case 0xC3: // SOF3
  29037. case 0xC5: // SOF5
  29038. case 0xC6: // SOF6
  29039. case 0xC7: // SOF7
  29040. case 0xC9: // SOF9
  29041. case 0xCA: // SOF10
  29042. case 0xCB: // SOF11
  29043. case 0xCD: // SOF13
  29044. case 0xCE: // SOF14
  29045. case 0xCF: // SOF15
  29046. case 0xC4: // DHT
  29047. case 0xCC: // DAC
  29048. case 0xDA: // SOS
  29049. case 0xDB: // DQT
  29050. case 0xDC: // DNL
  29051. case 0xDD: // DRI
  29052. case 0xDE: // DHP
  29053. case 0xDF: // EXP
  29054. case 0xE0: // APP0
  29055. case 0xE1: // APP1
  29056. case 0xE2: // APP2
  29057. case 0xE3: // APP3
  29058. case 0xE4: // APP4
  29059. case 0xE5: // APP5
  29060. case 0xE6: // APP6
  29061. case 0xE7: // APP7
  29062. case 0xE8: // APP8
  29063. case 0xE9: // APP9
  29064. case 0xEA: // APP10
  29065. case 0xEB: // APP11
  29066. case 0xEC: // APP12
  29067. case 0xED: // APP13
  29068. case 0xEE: // APP14
  29069. case 0xEF: // APP15
  29070. case 0xFE: // COM
  29071. // The marker should be followed by the length of the segment.
  29072. markerLength = stream.getUint16();
  29073. if (markerLength > 2) {
  29074. // |markerLength| contains the byte length of the marker segment,
  29075. // including its own length (2 bytes) and excluding the marker.
  29076. stream.skip(markerLength - 2); // Jump to the next marker.
  29077. } else {
  29078. // The marker length is invalid, resetting the stream position.
  29079. stream.skip(-2);
  29080. }
  29081. break;
  29082. }
  29083. if (foundEOI) {
  29084. break;
  29085. }
  29086. }
  29087. length = stream.pos - startPos;
  29088. if (b === -1) {
  29089. warn('Inline DCTDecode image stream: ' +
  29090. 'EOI marker not found, searching for /EI/ instead.');
  29091. stream.skip(-length); // Reset the stream position.
  29092. return this.findDefaultInlineStreamEnd(stream);
  29093. }
  29094. this.inlineStreamSkipEI(stream);
  29095. return length;
  29096. },
  29097. /**
  29098. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  29099. * @returns {number} The inline stream length.
  29100. */
  29101. findASCII85DecodeInlineStreamEnd:
  29102. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  29103. var TILDE = 0x7E, GT = 0x3E;
  29104. var startPos = stream.pos, ch, length;
  29105. while ((ch = stream.getByte()) !== -1) {
  29106. if (ch === TILDE && stream.peekByte() === GT) {
  29107. stream.skip();
  29108. break;
  29109. }
  29110. }
  29111. length = stream.pos - startPos;
  29112. if (ch === -1) {
  29113. warn('Inline ASCII85Decode image stream: ' +
  29114. 'EOD marker not found, searching for /EI/ instead.');
  29115. stream.skip(-length); // Reset the stream position.
  29116. return this.findDefaultInlineStreamEnd(stream);
  29117. }
  29118. this.inlineStreamSkipEI(stream);
  29119. return length;
  29120. },
  29121. /**
  29122. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  29123. * @returns {number} The inline stream length.
  29124. */
  29125. findASCIIHexDecodeInlineStreamEnd:
  29126. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  29127. var GT = 0x3E;
  29128. var startPos = stream.pos, ch, length;
  29129. while ((ch = stream.getByte()) !== -1) {
  29130. if (ch === GT) {
  29131. break;
  29132. }
  29133. }
  29134. length = stream.pos - startPos;
  29135. if (ch === -1) {
  29136. warn('Inline ASCIIHexDecode image stream: ' +
  29137. 'EOD marker not found, searching for /EI/ instead.');
  29138. stream.skip(-length); // Reset the stream position.
  29139. return this.findDefaultInlineStreamEnd(stream);
  29140. }
  29141. this.inlineStreamSkipEI(stream);
  29142. return length;
  29143. },
  29144. /**
  29145. * Skip over the /EI/ for streams where we search for an EOD marker.
  29146. */
  29147. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  29148. var E = 0x45, I = 0x49;
  29149. var state = 0, ch;
  29150. while ((ch = stream.getByte()) !== -1) {
  29151. if (state === 0) {
  29152. state = (ch === E) ? 1 : 0;
  29153. } else if (state === 1) {
  29154. state = (ch === I) ? 2 : 0;
  29155. } else if (state === 2) {
  29156. break;
  29157. }
  29158. }
  29159. },
  29160. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  29161. var lexer = this.lexer;
  29162. var stream = lexer.stream;
  29163. // Parse dictionary.
  29164. var dict = new Dict(this.xref);
  29165. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  29166. if (!isName(this.buf1)) {
  29167. error('Dictionary key must be a name object');
  29168. }
  29169. var key = this.buf1.name;
  29170. this.shift();
  29171. if (isEOF(this.buf1)) {
  29172. break;
  29173. }
  29174. dict.set(key, this.getObj(cipherTransform));
  29175. }
  29176. // Extract the name of the first (i.e. the current) image filter.
  29177. var filter = dict.get('Filter', 'F'), filterName;
  29178. if (isName(filter)) {
  29179. filterName = filter.name;
  29180. } else if (isArray(filter) && isName(filter[0])) {
  29181. filterName = filter[0].name;
  29182. }
  29183. // Parse image stream.
  29184. var startPos = stream.pos, length, i, ii;
  29185. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  29186. length = this.findDCTDecodeInlineStreamEnd(stream);
  29187. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  29188. length = this.findASCII85DecodeInlineStreamEnd(stream);
  29189. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  29190. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  29191. } else {
  29192. length = this.findDefaultInlineStreamEnd(stream);
  29193. }
  29194. var imageStream = stream.makeSubStream(startPos, length, dict);
  29195. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  29196. // adler32 checksum.
  29197. var adler32;
  29198. if (length < MAX_LENGTH_TO_CACHE) {
  29199. var imageBytes = imageStream.getBytes();
  29200. imageStream.reset();
  29201. var a = 1;
  29202. var b = 0;
  29203. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  29204. // No modulo required in the loop if imageBytes.length < 5552.
  29205. a += imageBytes[i] & 0xff;
  29206. b += a;
  29207. }
  29208. adler32 = ((b % 65521) << 16) | (a % 65521);
  29209. if (this.imageCache.adler32 === adler32) {
  29210. this.buf2 = Cmd.get('EI');
  29211. this.shift();
  29212. this.imageCache[adler32].reset();
  29213. return this.imageCache[adler32];
  29214. }
  29215. }
  29216. if (cipherTransform) {
  29217. imageStream = cipherTransform.createStream(imageStream, length);
  29218. }
  29219. imageStream = this.filter(imageStream, dict, length);
  29220. imageStream.dict = dict;
  29221. if (adler32 !== undefined) {
  29222. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  29223. this.imageCache[adler32] = imageStream;
  29224. }
  29225. this.buf2 = Cmd.get('EI');
  29226. this.shift();
  29227. return imageStream;
  29228. },
  29229. makeStream: function Parser_makeStream(dict, cipherTransform) {
  29230. var lexer = this.lexer;
  29231. var stream = lexer.stream;
  29232. // get stream start position
  29233. lexer.skipToNextLine();
  29234. var pos = stream.pos - 1;
  29235. // get length
  29236. var length = dict.get('Length');
  29237. if (!isInt(length)) {
  29238. info('Bad ' + length + ' attribute in stream');
  29239. length = 0;
  29240. }
  29241. // skip over the stream data
  29242. stream.pos = pos + length;
  29243. lexer.nextChar();
  29244. // Shift '>>' and check whether the new object marks the end of the stream
  29245. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  29246. this.shift(); // 'stream'
  29247. } else {
  29248. // bad stream length, scanning for endstream
  29249. stream.pos = pos;
  29250. var SCAN_BLOCK_SIZE = 2048;
  29251. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  29252. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  29253. 0x61, 0x6D];
  29254. var skipped = 0, found = false, i, j;
  29255. while (stream.pos < stream.end) {
  29256. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  29257. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  29258. if (scanLength <= 0) {
  29259. break;
  29260. }
  29261. found = false;
  29262. for (i = 0, j = 0; i < scanLength; i++) {
  29263. var b = scanBytes[i];
  29264. if (b !== ENDSTREAM_SIGNATURE[j]) {
  29265. i -= j;
  29266. j = 0;
  29267. } else {
  29268. j++;
  29269. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  29270. i++;
  29271. found = true;
  29272. break;
  29273. }
  29274. }
  29275. }
  29276. if (found) {
  29277. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  29278. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  29279. break;
  29280. }
  29281. skipped += scanLength;
  29282. stream.pos += scanLength;
  29283. }
  29284. if (!found) {
  29285. error('Missing endstream');
  29286. }
  29287. length = skipped;
  29288. lexer.nextChar();
  29289. this.shift();
  29290. this.shift();
  29291. }
  29292. this.shift(); // 'endstream'
  29293. stream = stream.makeSubStream(pos, length, dict);
  29294. if (cipherTransform) {
  29295. stream = cipherTransform.createStream(stream, length);
  29296. }
  29297. stream = this.filter(stream, dict, length);
  29298. stream.dict = dict;
  29299. return stream;
  29300. },
  29301. filter: function Parser_filter(stream, dict, length) {
  29302. var filter = dict.get('Filter', 'F');
  29303. var params = dict.get('DecodeParms', 'DP');
  29304. if (isName(filter)) {
  29305. return this.makeFilter(stream, filter.name, length, params);
  29306. }
  29307. var maybeLength = length;
  29308. if (isArray(filter)) {
  29309. var filterArray = filter;
  29310. var paramsArray = params;
  29311. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  29312. filter = filterArray[i];
  29313. if (!isName(filter)) {
  29314. error('Bad filter name: ' + filter);
  29315. }
  29316. params = null;
  29317. if (isArray(paramsArray) && (i in paramsArray)) {
  29318. params = paramsArray[i];
  29319. }
  29320. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  29321. // after the first stream the length variable is invalid
  29322. maybeLength = null;
  29323. }
  29324. }
  29325. return stream;
  29326. },
  29327. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  29328. if (stream.dict.get('Length') === 0 && !maybeLength) {
  29329. warn('Empty "' + name + '" stream.');
  29330. return new NullStream(stream);
  29331. }
  29332. try {
  29333. if (params && this.xref) {
  29334. params = this.xref.fetchIfRef(params);
  29335. }
  29336. var xrefStreamStats = this.xref.stats.streamTypes;
  29337. if (name === 'FlateDecode' || name === 'Fl') {
  29338. xrefStreamStats[StreamType.FLATE] = true;
  29339. if (params) {
  29340. return new PredictorStream(new FlateStream(stream, maybeLength),
  29341. maybeLength, params);
  29342. }
  29343. return new FlateStream(stream, maybeLength);
  29344. }
  29345. if (name === 'LZWDecode' || name === 'LZW') {
  29346. xrefStreamStats[StreamType.LZW] = true;
  29347. var earlyChange = 1;
  29348. if (params) {
  29349. if (params.has('EarlyChange')) {
  29350. earlyChange = params.get('EarlyChange');
  29351. }
  29352. return new PredictorStream(
  29353. new LZWStream(stream, maybeLength, earlyChange),
  29354. maybeLength, params);
  29355. }
  29356. return new LZWStream(stream, maybeLength, earlyChange);
  29357. }
  29358. if (name === 'DCTDecode' || name === 'DCT') {
  29359. xrefStreamStats[StreamType.DCT] = true;
  29360. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  29361. }
  29362. if (name === 'JPXDecode' || name === 'JPX') {
  29363. xrefStreamStats[StreamType.JPX] = true;
  29364. return new JpxStream(stream, maybeLength, stream.dict);
  29365. }
  29366. if (name === 'ASCII85Decode' || name === 'A85') {
  29367. xrefStreamStats[StreamType.A85] = true;
  29368. return new Ascii85Stream(stream, maybeLength);
  29369. }
  29370. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  29371. xrefStreamStats[StreamType.AHX] = true;
  29372. return new AsciiHexStream(stream, maybeLength);
  29373. }
  29374. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  29375. xrefStreamStats[StreamType.CCF] = true;
  29376. return new CCITTFaxStream(stream, maybeLength, params);
  29377. }
  29378. if (name === 'RunLengthDecode' || name === 'RL') {
  29379. xrefStreamStats[StreamType.RL] = true;
  29380. return new RunLengthStream(stream, maybeLength);
  29381. }
  29382. if (name === 'JBIG2Decode') {
  29383. xrefStreamStats[StreamType.JBIG] = true;
  29384. return new Jbig2Stream(stream, maybeLength, stream.dict);
  29385. }
  29386. warn('filter "' + name + '" not supported yet');
  29387. return stream;
  29388. } catch (ex) {
  29389. if (ex instanceof MissingDataException) {
  29390. throw ex;
  29391. }
  29392. warn('Invalid stream: \"' + ex + '\"');
  29393. return new NullStream(stream);
  29394. }
  29395. }
  29396. };
  29397. return Parser;
  29398. })();
  29399. var Lexer = (function LexerClosure() {
  29400. function Lexer(stream, knownCommands) {
  29401. this.stream = stream;
  29402. this.nextChar();
  29403. // While lexing, we build up many strings one char at a time. Using += for
  29404. // this can result in lots of garbage strings. It's better to build an
  29405. // array of single-char strings and then join() them together at the end.
  29406. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  29407. // purpose uses less memory than using a new array for each string.
  29408. this.strBuf = [];
  29409. // The PDFs might have "glued" commands with other commands, operands or
  29410. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  29411. // commands and their prefixes. The prefixes are built the following way:
  29412. // if there a command that is a prefix of the other valid command or
  29413. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  29414. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  29415. // other commands or literals as a prefix. The knowCommands is optional.
  29416. this.knownCommands = knownCommands;
  29417. }
  29418. Lexer.isSpace = function Lexer_isSpace(ch) {
  29419. // Space is one of the following characters: SPACE, TAB, CR or LF.
  29420. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  29421. };
  29422. // A '1' in this array means the character is white space. A '1' or
  29423. // '2' means the character ends a name or command.
  29424. var specialChars = [
  29425. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  29426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  29427. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  29428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  29429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  29430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  29431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  29432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  29433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  29434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  29435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  29436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  29437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  29438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  29439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  29440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  29441. ];
  29442. function toHexDigit(ch) {
  29443. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29444. return ch & 0x0F;
  29445. }
  29446. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29447. // 'A'-'F', 'a'-'f'
  29448. return (ch & 0x0F) + 9;
  29449. }
  29450. return -1;
  29451. }
  29452. Lexer.prototype = {
  29453. nextChar: function Lexer_nextChar() {
  29454. return (this.currentChar = this.stream.getByte());
  29455. },
  29456. peekChar: function Lexer_peekChar() {
  29457. return this.stream.peekByte();
  29458. },
  29459. getNumber: function Lexer_getNumber() {
  29460. var ch = this.currentChar;
  29461. var eNotation = false;
  29462. var divideBy = 0; // different from 0 if it's a floating point value
  29463. var sign = 1;
  29464. if (ch === 0x2D) { // '-'
  29465. sign = -1;
  29466. ch = this.nextChar();
  29467. if (ch === 0x2D) { // '-'
  29468. // Ignore double negative (this is consistent with Adobe Reader).
  29469. ch = this.nextChar();
  29470. }
  29471. } else if (ch === 0x2B) { // '+'
  29472. ch = this.nextChar();
  29473. }
  29474. if (ch === 0x2E) { // '.'
  29475. divideBy = 10;
  29476. ch = this.nextChar();
  29477. }
  29478. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29479. error('Invalid number: ' + String.fromCharCode(ch));
  29480. return 0;
  29481. }
  29482. var baseValue = ch - 0x30; // '0'
  29483. var powerValue = 0;
  29484. var powerValueSign = 1;
  29485. while ((ch = this.nextChar()) >= 0) {
  29486. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  29487. var currentDigit = ch - 0x30; // '0'
  29488. if (eNotation) { // We are after an 'e' or 'E'
  29489. powerValue = powerValue * 10 + currentDigit;
  29490. } else {
  29491. if (divideBy !== 0) { // We are after a point
  29492. divideBy *= 10;
  29493. }
  29494. baseValue = baseValue * 10 + currentDigit;
  29495. }
  29496. } else if (ch === 0x2E) { // '.'
  29497. if (divideBy === 0) {
  29498. divideBy = 1;
  29499. } else {
  29500. // A number can have only one '.'
  29501. break;
  29502. }
  29503. } else if (ch === 0x2D) { // '-'
  29504. // ignore minus signs in the middle of numbers to match
  29505. // Adobe's behavior
  29506. warn('Badly formated number');
  29507. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29508. // 'E' can be either a scientific notation or the beginning of a new
  29509. // operator
  29510. ch = this.peekChar();
  29511. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29512. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29513. this.nextChar(); // Consume the sign character
  29514. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29515. // The 'E' must be the beginning of a new operator
  29516. break;
  29517. }
  29518. eNotation = true;
  29519. } else {
  29520. // the last character doesn't belong to us
  29521. break;
  29522. }
  29523. }
  29524. if (divideBy !== 0) {
  29525. baseValue /= divideBy;
  29526. }
  29527. if (eNotation) {
  29528. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29529. }
  29530. return sign * baseValue;
  29531. },
  29532. getString: function Lexer_getString() {
  29533. var numParen = 1;
  29534. var done = false;
  29535. var strBuf = this.strBuf;
  29536. strBuf.length = 0;
  29537. var ch = this.nextChar();
  29538. while (true) {
  29539. var charBuffered = false;
  29540. switch (ch | 0) {
  29541. case -1:
  29542. warn('Unterminated string');
  29543. done = true;
  29544. break;
  29545. case 0x28: // '('
  29546. ++numParen;
  29547. strBuf.push('(');
  29548. break;
  29549. case 0x29: // ')'
  29550. if (--numParen === 0) {
  29551. this.nextChar(); // consume strings ')'
  29552. done = true;
  29553. } else {
  29554. strBuf.push(')');
  29555. }
  29556. break;
  29557. case 0x5C: // '\\'
  29558. ch = this.nextChar();
  29559. switch (ch) {
  29560. case -1:
  29561. warn('Unterminated string');
  29562. done = true;
  29563. break;
  29564. case 0x6E: // 'n'
  29565. strBuf.push('\n');
  29566. break;
  29567. case 0x72: // 'r'
  29568. strBuf.push('\r');
  29569. break;
  29570. case 0x74: // 't'
  29571. strBuf.push('\t');
  29572. break;
  29573. case 0x62: // 'b'
  29574. strBuf.push('\b');
  29575. break;
  29576. case 0x66: // 'f'
  29577. strBuf.push('\f');
  29578. break;
  29579. case 0x5C: // '\'
  29580. case 0x28: // '('
  29581. case 0x29: // ')'
  29582. strBuf.push(String.fromCharCode(ch));
  29583. break;
  29584. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29585. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29586. var x = ch & 0x0F;
  29587. ch = this.nextChar();
  29588. charBuffered = true;
  29589. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29590. x = (x << 3) + (ch & 0x0F);
  29591. ch = this.nextChar();
  29592. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29593. charBuffered = false;
  29594. x = (x << 3) + (ch & 0x0F);
  29595. }
  29596. }
  29597. strBuf.push(String.fromCharCode(x));
  29598. break;
  29599. case 0x0D: // CR
  29600. if (this.peekChar() === 0x0A) { // LF
  29601. this.nextChar();
  29602. }
  29603. break;
  29604. case 0x0A: // LF
  29605. break;
  29606. default:
  29607. strBuf.push(String.fromCharCode(ch));
  29608. break;
  29609. }
  29610. break;
  29611. default:
  29612. strBuf.push(String.fromCharCode(ch));
  29613. break;
  29614. }
  29615. if (done) {
  29616. break;
  29617. }
  29618. if (!charBuffered) {
  29619. ch = this.nextChar();
  29620. }
  29621. }
  29622. return strBuf.join('');
  29623. },
  29624. getName: function Lexer_getName() {
  29625. var ch;
  29626. var strBuf = this.strBuf;
  29627. strBuf.length = 0;
  29628. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29629. if (ch === 0x23) { // '#'
  29630. ch = this.nextChar();
  29631. var x = toHexDigit(ch);
  29632. if (x !== -1) {
  29633. var x2 = toHexDigit(this.nextChar());
  29634. if (x2 === -1) {
  29635. error('Illegal digit in hex char in name: ' + x2);
  29636. }
  29637. strBuf.push(String.fromCharCode((x << 4) | x2));
  29638. } else {
  29639. strBuf.push('#', String.fromCharCode(ch));
  29640. }
  29641. } else {
  29642. strBuf.push(String.fromCharCode(ch));
  29643. }
  29644. }
  29645. if (strBuf.length > 127) {
  29646. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  29647. }
  29648. return Name.get(strBuf.join(''));
  29649. },
  29650. getHexString: function Lexer_getHexString() {
  29651. var strBuf = this.strBuf;
  29652. strBuf.length = 0;
  29653. var ch = this.currentChar;
  29654. var isFirstHex = true;
  29655. var firstDigit;
  29656. var secondDigit;
  29657. while (true) {
  29658. if (ch < 0) {
  29659. warn('Unterminated hex string');
  29660. break;
  29661. } else if (ch === 0x3E) { // '>'
  29662. this.nextChar();
  29663. break;
  29664. } else if (specialChars[ch] === 1) {
  29665. ch = this.nextChar();
  29666. continue;
  29667. } else {
  29668. if (isFirstHex) {
  29669. firstDigit = toHexDigit(ch);
  29670. if (firstDigit === -1) {
  29671. warn('Ignoring invalid character "' + ch + '" in hex string');
  29672. ch = this.nextChar();
  29673. continue;
  29674. }
  29675. } else {
  29676. secondDigit = toHexDigit(ch);
  29677. if (secondDigit === -1) {
  29678. warn('Ignoring invalid character "' + ch + '" in hex string');
  29679. ch = this.nextChar();
  29680. continue;
  29681. }
  29682. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29683. }
  29684. isFirstHex = !isFirstHex;
  29685. ch = this.nextChar();
  29686. }
  29687. }
  29688. return strBuf.join('');
  29689. },
  29690. getObj: function Lexer_getObj() {
  29691. // skip whitespace and comments
  29692. var comment = false;
  29693. var ch = this.currentChar;
  29694. while (true) {
  29695. if (ch < 0) {
  29696. return EOF;
  29697. }
  29698. if (comment) {
  29699. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29700. comment = false;
  29701. }
  29702. } else if (ch === 0x25) { // '%'
  29703. comment = true;
  29704. } else if (specialChars[ch] !== 1) {
  29705. break;
  29706. }
  29707. ch = this.nextChar();
  29708. }
  29709. // start reading token
  29710. switch (ch | 0) {
  29711. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29712. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29713. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29714. return this.getNumber();
  29715. case 0x28: // '('
  29716. return this.getString();
  29717. case 0x2F: // '/'
  29718. return this.getName();
  29719. // array punctuation
  29720. case 0x5B: // '['
  29721. this.nextChar();
  29722. return Cmd.get('[');
  29723. case 0x5D: // ']'
  29724. this.nextChar();
  29725. return Cmd.get(']');
  29726. // hex string or dict punctuation
  29727. case 0x3C: // '<'
  29728. ch = this.nextChar();
  29729. if (ch === 0x3C) {
  29730. // dict punctuation
  29731. this.nextChar();
  29732. return Cmd.get('<<');
  29733. }
  29734. return this.getHexString();
  29735. // dict punctuation
  29736. case 0x3E: // '>'
  29737. ch = this.nextChar();
  29738. if (ch === 0x3E) {
  29739. this.nextChar();
  29740. return Cmd.get('>>');
  29741. }
  29742. return Cmd.get('>');
  29743. case 0x7B: // '{'
  29744. this.nextChar();
  29745. return Cmd.get('{');
  29746. case 0x7D: // '}'
  29747. this.nextChar();
  29748. return Cmd.get('}');
  29749. case 0x29: // ')'
  29750. error('Illegal character: ' + ch);
  29751. break;
  29752. }
  29753. // command
  29754. var str = String.fromCharCode(ch);
  29755. var knownCommands = this.knownCommands;
  29756. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29757. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29758. // stop if known command is found and next character does not make
  29759. // the str a command
  29760. var possibleCommand = str + String.fromCharCode(ch);
  29761. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29762. break;
  29763. }
  29764. if (str.length === 128) {
  29765. error('Command token too long: ' + str.length);
  29766. }
  29767. str = possibleCommand;
  29768. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29769. }
  29770. if (str === 'true') {
  29771. return true;
  29772. }
  29773. if (str === 'false') {
  29774. return false;
  29775. }
  29776. if (str === 'null') {
  29777. return null;
  29778. }
  29779. return Cmd.get(str);
  29780. },
  29781. skipToNextLine: function Lexer_skipToNextLine() {
  29782. var ch = this.currentChar;
  29783. while (ch >= 0) {
  29784. if (ch === 0x0D) { // CR
  29785. ch = this.nextChar();
  29786. if (ch === 0x0A) { // LF
  29787. this.nextChar();
  29788. }
  29789. break;
  29790. } else if (ch === 0x0A) { // LF
  29791. this.nextChar();
  29792. break;
  29793. }
  29794. ch = this.nextChar();
  29795. }
  29796. }
  29797. };
  29798. return Lexer;
  29799. })();
  29800. var Linearization = {
  29801. create: function LinearizationCreate(stream) {
  29802. function getInt(name, allowZeroValue) {
  29803. var obj = linDict.get(name);
  29804. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29805. return obj;
  29806. }
  29807. throw new Error('The "' + name + '" parameter in the linearization ' +
  29808. 'dictionary is invalid.');
  29809. }
  29810. function getHints() {
  29811. var hints = linDict.get('H'), hintsLength, item;
  29812. if (isArray(hints) &&
  29813. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29814. for (var index = 0; index < hintsLength; index++) {
  29815. if (!(isInt(item = hints[index]) && item > 0)) {
  29816. throw new Error('Hint (' + index +
  29817. ') in the linearization dictionary is invalid.');
  29818. }
  29819. }
  29820. return hints;
  29821. }
  29822. throw new Error('Hint array in the linearization dictionary is invalid.');
  29823. }
  29824. var parser = new Parser(new Lexer(stream), false, null);
  29825. var obj1 = parser.getObj();
  29826. var obj2 = parser.getObj();
  29827. var obj3 = parser.getObj();
  29828. var linDict = parser.getObj();
  29829. var obj, length;
  29830. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29831. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29832. return null; // No valid linearization dictionary found.
  29833. } else if ((length = getInt('L')) !== stream.length) {
  29834. throw new Error('The "L" parameter in the linearization dictionary ' +
  29835. 'does not equal the stream length.');
  29836. }
  29837. return {
  29838. length: length,
  29839. hints: getHints(),
  29840. objectNumberFirst: getInt('O'),
  29841. endFirst: getInt('E'),
  29842. numPages: getInt('N'),
  29843. mainXRefEntriesOffset: getInt('T'),
  29844. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29845. };
  29846. }
  29847. };
  29848. var PostScriptParser = (function PostScriptParserClosure() {
  29849. function PostScriptParser(lexer) {
  29850. this.lexer = lexer;
  29851. this.operators = [];
  29852. this.token = null;
  29853. this.prev = null;
  29854. }
  29855. PostScriptParser.prototype = {
  29856. nextToken: function PostScriptParser_nextToken() {
  29857. this.prev = this.token;
  29858. this.token = this.lexer.getToken();
  29859. },
  29860. accept: function PostScriptParser_accept(type) {
  29861. if (this.token.type === type) {
  29862. this.nextToken();
  29863. return true;
  29864. }
  29865. return false;
  29866. },
  29867. expect: function PostScriptParser_expect(type) {
  29868. if (this.accept(type)) {
  29869. return true;
  29870. }
  29871. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29872. type + '.');
  29873. },
  29874. parse: function PostScriptParser_parse() {
  29875. this.nextToken();
  29876. this.expect(PostScriptTokenTypes.LBRACE);
  29877. this.parseBlock();
  29878. this.expect(PostScriptTokenTypes.RBRACE);
  29879. return this.operators;
  29880. },
  29881. parseBlock: function PostScriptParser_parseBlock() {
  29882. while (true) {
  29883. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29884. this.operators.push(this.prev.value);
  29885. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29886. this.operators.push(this.prev.value);
  29887. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29888. this.parseCondition();
  29889. } else {
  29890. return;
  29891. }
  29892. }
  29893. },
  29894. parseCondition: function PostScriptParser_parseCondition() {
  29895. // Add two place holders that will be updated later
  29896. var conditionLocation = this.operators.length;
  29897. this.operators.push(null, null);
  29898. this.parseBlock();
  29899. this.expect(PostScriptTokenTypes.RBRACE);
  29900. if (this.accept(PostScriptTokenTypes.IF)) {
  29901. // The true block is right after the 'if' so it just falls through on
  29902. // true else it jumps and skips the true block.
  29903. this.operators[conditionLocation] = this.operators.length;
  29904. this.operators[conditionLocation + 1] = 'jz';
  29905. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29906. var jumpLocation = this.operators.length;
  29907. this.operators.push(null, null);
  29908. var endOfTrue = this.operators.length;
  29909. this.parseBlock();
  29910. this.expect(PostScriptTokenTypes.RBRACE);
  29911. this.expect(PostScriptTokenTypes.IFELSE);
  29912. // The jump is added at the end of the true block to skip the false
  29913. // block.
  29914. this.operators[jumpLocation] = this.operators.length;
  29915. this.operators[jumpLocation + 1] = 'j';
  29916. this.operators[conditionLocation] = endOfTrue;
  29917. this.operators[conditionLocation + 1] = 'jz';
  29918. } else {
  29919. error('PS Function: error parsing conditional.');
  29920. }
  29921. }
  29922. };
  29923. return PostScriptParser;
  29924. })();
  29925. var PostScriptTokenTypes = {
  29926. LBRACE: 0,
  29927. RBRACE: 1,
  29928. NUMBER: 2,
  29929. OPERATOR: 3,
  29930. IF: 4,
  29931. IFELSE: 5
  29932. };
  29933. var PostScriptToken = (function PostScriptTokenClosure() {
  29934. function PostScriptToken(type, value) {
  29935. this.type = type;
  29936. this.value = value;
  29937. }
  29938. var opCache = {};
  29939. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29940. var opValue = opCache[op];
  29941. if (opValue) {
  29942. return opValue;
  29943. }
  29944. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29945. };
  29946. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29947. '{');
  29948. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29949. '}');
  29950. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29951. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29952. 'IFELSE');
  29953. return PostScriptToken;
  29954. })();
  29955. var PostScriptLexer = (function PostScriptLexerClosure() {
  29956. function PostScriptLexer(stream) {
  29957. this.stream = stream;
  29958. this.nextChar();
  29959. this.strBuf = [];
  29960. }
  29961. PostScriptLexer.prototype = {
  29962. nextChar: function PostScriptLexer_nextChar() {
  29963. return (this.currentChar = this.stream.getByte());
  29964. },
  29965. getToken: function PostScriptLexer_getToken() {
  29966. var comment = false;
  29967. var ch = this.currentChar;
  29968. // skip comments
  29969. while (true) {
  29970. if (ch < 0) {
  29971. return EOF;
  29972. }
  29973. if (comment) {
  29974. if (ch === 0x0A || ch === 0x0D) {
  29975. comment = false;
  29976. }
  29977. } else if (ch === 0x25) { // '%'
  29978. comment = true;
  29979. } else if (!Lexer.isSpace(ch)) {
  29980. break;
  29981. }
  29982. ch = this.nextChar();
  29983. }
  29984. switch (ch | 0) {
  29985. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29986. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29987. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29988. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29989. this.getNumber());
  29990. case 0x7B: // '{'
  29991. this.nextChar();
  29992. return PostScriptToken.LBRACE;
  29993. case 0x7D: // '}'
  29994. this.nextChar();
  29995. return PostScriptToken.RBRACE;
  29996. }
  29997. // operator
  29998. var strBuf = this.strBuf;
  29999. strBuf.length = 0;
  30000. strBuf[0] = String.fromCharCode(ch);
  30001. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  30002. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  30003. strBuf.push(String.fromCharCode(ch));
  30004. }
  30005. var str = strBuf.join('');
  30006. switch (str.toLowerCase()) {
  30007. case 'if':
  30008. return PostScriptToken.IF;
  30009. case 'ifelse':
  30010. return PostScriptToken.IFELSE;
  30011. default:
  30012. return PostScriptToken.getOperator(str);
  30013. }
  30014. },
  30015. getNumber: function PostScriptLexer_getNumber() {
  30016. var ch = this.currentChar;
  30017. var strBuf = this.strBuf;
  30018. strBuf.length = 0;
  30019. strBuf[0] = String.fromCharCode(ch);
  30020. while ((ch = this.nextChar()) >= 0) {
  30021. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  30022. ch === 0x2D || ch === 0x2E) { // '-', '.'
  30023. strBuf.push(String.fromCharCode(ch));
  30024. } else {
  30025. break;
  30026. }
  30027. }
  30028. var value = parseFloat(strBuf.join(''));
  30029. if (isNaN(value)) {
  30030. error('Invalid floating point number: ' + value);
  30031. }
  30032. return value;
  30033. }
  30034. };
  30035. return PostScriptLexer;
  30036. })();
  30037. var Stream = (function StreamClosure() {
  30038. function Stream(arrayBuffer, start, length, dict) {
  30039. this.bytes = (arrayBuffer instanceof Uint8Array ?
  30040. arrayBuffer : new Uint8Array(arrayBuffer));
  30041. this.start = start || 0;
  30042. this.pos = this.start;
  30043. this.end = (start + length) || this.bytes.length;
  30044. this.dict = dict;
  30045. }
  30046. // required methods for a stream. if a particular stream does not
  30047. // implement these, an error should be thrown
  30048. Stream.prototype = {
  30049. get length() {
  30050. return this.end - this.start;
  30051. },
  30052. get isEmpty() {
  30053. return this.length === 0;
  30054. },
  30055. getByte: function Stream_getByte() {
  30056. if (this.pos >= this.end) {
  30057. return -1;
  30058. }
  30059. return this.bytes[this.pos++];
  30060. },
  30061. getUint16: function Stream_getUint16() {
  30062. var b0 = this.getByte();
  30063. var b1 = this.getByte();
  30064. if (b0 === -1 || b1 === -1) {
  30065. return -1;
  30066. }
  30067. return (b0 << 8) + b1;
  30068. },
  30069. getInt32: function Stream_getInt32() {
  30070. var b0 = this.getByte();
  30071. var b1 = this.getByte();
  30072. var b2 = this.getByte();
  30073. var b3 = this.getByte();
  30074. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30075. },
  30076. // returns subarray of original buffer
  30077. // should only be read
  30078. getBytes: function Stream_getBytes(length) {
  30079. var bytes = this.bytes;
  30080. var pos = this.pos;
  30081. var strEnd = this.end;
  30082. if (!length) {
  30083. return bytes.subarray(pos, strEnd);
  30084. }
  30085. var end = pos + length;
  30086. if (end > strEnd) {
  30087. end = strEnd;
  30088. }
  30089. this.pos = end;
  30090. return bytes.subarray(pos, end);
  30091. },
  30092. peekByte: function Stream_peekByte() {
  30093. var peekedByte = this.getByte();
  30094. this.pos--;
  30095. return peekedByte;
  30096. },
  30097. peekBytes: function Stream_peekBytes(length) {
  30098. var bytes = this.getBytes(length);
  30099. this.pos -= bytes.length;
  30100. return bytes;
  30101. },
  30102. skip: function Stream_skip(n) {
  30103. if (!n) {
  30104. n = 1;
  30105. }
  30106. this.pos += n;
  30107. },
  30108. reset: function Stream_reset() {
  30109. this.pos = this.start;
  30110. },
  30111. moveStart: function Stream_moveStart() {
  30112. this.start = this.pos;
  30113. },
  30114. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  30115. return new Stream(this.bytes.buffer, start, length, dict);
  30116. },
  30117. isStream: true
  30118. };
  30119. return Stream;
  30120. })();
  30121. var StringStream = (function StringStreamClosure() {
  30122. function StringStream(str) {
  30123. var length = str.length;
  30124. var bytes = new Uint8Array(length);
  30125. for (var n = 0; n < length; ++n) {
  30126. bytes[n] = str.charCodeAt(n);
  30127. }
  30128. Stream.call(this, bytes);
  30129. }
  30130. StringStream.prototype = Stream.prototype;
  30131. return StringStream;
  30132. })();
  30133. // super class for the decoding streams
  30134. var DecodeStream = (function DecodeStreamClosure() {
  30135. // Lots of DecodeStreams are created whose buffers are never used. For these
  30136. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  30137. // having special cases that would be required if we used |null| for an empty
  30138. // buffer.
  30139. var emptyBuffer = new Uint8Array(0);
  30140. function DecodeStream(maybeMinBufferLength) {
  30141. this.pos = 0;
  30142. this.bufferLength = 0;
  30143. this.eof = false;
  30144. this.buffer = emptyBuffer;
  30145. this.minBufferLength = 512;
  30146. if (maybeMinBufferLength) {
  30147. // Compute the first power of two that is as big as maybeMinBufferLength.
  30148. while (this.minBufferLength < maybeMinBufferLength) {
  30149. this.minBufferLength *= 2;
  30150. }
  30151. }
  30152. }
  30153. DecodeStream.prototype = {
  30154. get isEmpty() {
  30155. while (!this.eof && this.bufferLength === 0) {
  30156. this.readBlock();
  30157. }
  30158. return this.bufferLength === 0;
  30159. },
  30160. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  30161. var buffer = this.buffer;
  30162. if (requested <= buffer.byteLength) {
  30163. return buffer;
  30164. }
  30165. var size = this.minBufferLength;
  30166. while (size < requested) {
  30167. size *= 2;
  30168. }
  30169. var buffer2 = new Uint8Array(size);
  30170. buffer2.set(buffer);
  30171. return (this.buffer = buffer2);
  30172. },
  30173. getByte: function DecodeStream_getByte() {
  30174. var pos = this.pos;
  30175. while (this.bufferLength <= pos) {
  30176. if (this.eof) {
  30177. return -1;
  30178. }
  30179. this.readBlock();
  30180. }
  30181. return this.buffer[this.pos++];
  30182. },
  30183. getUint16: function DecodeStream_getUint16() {
  30184. var b0 = this.getByte();
  30185. var b1 = this.getByte();
  30186. if (b0 === -1 || b1 === -1) {
  30187. return -1;
  30188. }
  30189. return (b0 << 8) + b1;
  30190. },
  30191. getInt32: function DecodeStream_getInt32() {
  30192. var b0 = this.getByte();
  30193. var b1 = this.getByte();
  30194. var b2 = this.getByte();
  30195. var b3 = this.getByte();
  30196. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30197. },
  30198. getBytes: function DecodeStream_getBytes(length) {
  30199. var end, pos = this.pos;
  30200. if (length) {
  30201. this.ensureBuffer(pos + length);
  30202. end = pos + length;
  30203. while (!this.eof && this.bufferLength < end) {
  30204. this.readBlock();
  30205. }
  30206. var bufEnd = this.bufferLength;
  30207. if (end > bufEnd) {
  30208. end = bufEnd;
  30209. }
  30210. } else {
  30211. while (!this.eof) {
  30212. this.readBlock();
  30213. }
  30214. end = this.bufferLength;
  30215. }
  30216. this.pos = end;
  30217. return this.buffer.subarray(pos, end);
  30218. },
  30219. peekByte: function DecodeStream_peekByte() {
  30220. var peekedByte = this.getByte();
  30221. this.pos--;
  30222. return peekedByte;
  30223. },
  30224. peekBytes: function DecodeStream_peekBytes(length) {
  30225. var bytes = this.getBytes(length);
  30226. this.pos -= bytes.length;
  30227. return bytes;
  30228. },
  30229. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  30230. var end = start + length;
  30231. while (this.bufferLength <= end && !this.eof) {
  30232. this.readBlock();
  30233. }
  30234. return new Stream(this.buffer, start, length, dict);
  30235. },
  30236. skip: function DecodeStream_skip(n) {
  30237. if (!n) {
  30238. n = 1;
  30239. }
  30240. this.pos += n;
  30241. },
  30242. reset: function DecodeStream_reset() {
  30243. this.pos = 0;
  30244. },
  30245. getBaseStreams: function DecodeStream_getBaseStreams() {
  30246. if (this.str && this.str.getBaseStreams) {
  30247. return this.str.getBaseStreams();
  30248. }
  30249. return [];
  30250. }
  30251. };
  30252. return DecodeStream;
  30253. })();
  30254. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  30255. function StreamsSequenceStream(streams) {
  30256. this.streams = streams;
  30257. DecodeStream.call(this, /* maybeLength = */ null);
  30258. }
  30259. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  30260. StreamsSequenceStream.prototype.readBlock =
  30261. function streamSequenceStreamReadBlock() {
  30262. var streams = this.streams;
  30263. if (streams.length === 0) {
  30264. this.eof = true;
  30265. return;
  30266. }
  30267. var stream = streams.shift();
  30268. var chunk = stream.getBytes();
  30269. var bufferLength = this.bufferLength;
  30270. var newLength = bufferLength + chunk.length;
  30271. var buffer = this.ensureBuffer(newLength);
  30272. buffer.set(chunk, bufferLength);
  30273. this.bufferLength = newLength;
  30274. };
  30275. StreamsSequenceStream.prototype.getBaseStreams =
  30276. function StreamsSequenceStream_getBaseStreams() {
  30277. var baseStreams = [];
  30278. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  30279. var stream = this.streams[i];
  30280. if (stream.getBaseStreams) {
  30281. Util.appendToArray(baseStreams, stream.getBaseStreams());
  30282. }
  30283. }
  30284. return baseStreams;
  30285. };
  30286. return StreamsSequenceStream;
  30287. })();
  30288. var FlateStream = (function FlateStreamClosure() {
  30289. var codeLenCodeMap = new Int32Array([
  30290. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  30291. ]);
  30292. var lengthDecode = new Int32Array([
  30293. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  30294. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  30295. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  30296. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  30297. ]);
  30298. var distDecode = new Int32Array([
  30299. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  30300. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  30301. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  30302. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  30303. ]);
  30304. var fixedLitCodeTab = [new Int32Array([
  30305. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  30306. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  30307. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  30308. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  30309. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  30310. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  30311. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  30312. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  30313. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  30314. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  30315. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  30316. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  30317. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  30318. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  30319. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  30320. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  30321. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  30322. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  30323. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  30324. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  30325. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  30326. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  30327. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  30328. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  30329. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  30330. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  30331. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  30332. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  30333. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  30334. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  30335. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  30336. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  30337. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  30338. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  30339. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  30340. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  30341. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  30342. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  30343. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  30344. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  30345. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  30346. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  30347. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  30348. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  30349. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  30350. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  30351. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  30352. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  30353. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  30354. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  30355. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  30356. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  30357. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  30358. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  30359. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  30360. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  30361. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  30362. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  30363. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  30364. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  30365. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  30366. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  30367. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  30368. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  30369. ]), 9];
  30370. var fixedDistCodeTab = [new Int32Array([
  30371. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  30372. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  30373. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  30374. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  30375. ]), 5];
  30376. function FlateStream(str, maybeLength) {
  30377. this.str = str;
  30378. this.dict = str.dict;
  30379. var cmf = str.getByte();
  30380. var flg = str.getByte();
  30381. if (cmf === -1 || flg === -1) {
  30382. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  30383. }
  30384. if ((cmf & 0x0f) !== 0x08) {
  30385. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  30386. }
  30387. if ((((cmf << 8) + flg) % 31) !== 0) {
  30388. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  30389. }
  30390. if (flg & 0x20) {
  30391. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  30392. }
  30393. this.codeSize = 0;
  30394. this.codeBuf = 0;
  30395. DecodeStream.call(this, maybeLength);
  30396. }
  30397. FlateStream.prototype = Object.create(DecodeStream.prototype);
  30398. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  30399. var str = this.str;
  30400. var codeSize = this.codeSize;
  30401. var codeBuf = this.codeBuf;
  30402. var b;
  30403. while (codeSize < bits) {
  30404. if ((b = str.getByte()) === -1) {
  30405. error('Bad encoding in flate stream');
  30406. }
  30407. codeBuf |= b << codeSize;
  30408. codeSize += 8;
  30409. }
  30410. b = codeBuf & ((1 << bits) - 1);
  30411. this.codeBuf = codeBuf >> bits;
  30412. this.codeSize = codeSize -= bits;
  30413. return b;
  30414. };
  30415. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  30416. var str = this.str;
  30417. var codes = table[0];
  30418. var maxLen = table[1];
  30419. var codeSize = this.codeSize;
  30420. var codeBuf = this.codeBuf;
  30421. var b;
  30422. while (codeSize < maxLen) {
  30423. if ((b = str.getByte()) === -1) {
  30424. // premature end of stream. code might however still be valid.
  30425. // codeSize < codeLen check below guards against incomplete codeVal.
  30426. break;
  30427. }
  30428. codeBuf |= (b << codeSize);
  30429. codeSize += 8;
  30430. }
  30431. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  30432. var codeLen = code >> 16;
  30433. var codeVal = code & 0xffff;
  30434. if (codeLen < 1 || codeSize < codeLen) {
  30435. error('Bad encoding in flate stream');
  30436. }
  30437. this.codeBuf = (codeBuf >> codeLen);
  30438. this.codeSize = (codeSize - codeLen);
  30439. return codeVal;
  30440. };
  30441. FlateStream.prototype.generateHuffmanTable =
  30442. function flateStreamGenerateHuffmanTable(lengths) {
  30443. var n = lengths.length;
  30444. // find max code length
  30445. var maxLen = 0;
  30446. var i;
  30447. for (i = 0; i < n; ++i) {
  30448. if (lengths[i] > maxLen) {
  30449. maxLen = lengths[i];
  30450. }
  30451. }
  30452. // build the table
  30453. var size = 1 << maxLen;
  30454. var codes = new Int32Array(size);
  30455. for (var len = 1, code = 0, skip = 2;
  30456. len <= maxLen;
  30457. ++len, code <<= 1, skip <<= 1) {
  30458. for (var val = 0; val < n; ++val) {
  30459. if (lengths[val] === len) {
  30460. // bit-reverse the code
  30461. var code2 = 0;
  30462. var t = code;
  30463. for (i = 0; i < len; ++i) {
  30464. code2 = (code2 << 1) | (t & 1);
  30465. t >>= 1;
  30466. }
  30467. // fill the table entries
  30468. for (i = code2; i < size; i += skip) {
  30469. codes[i] = (len << 16) | val;
  30470. }
  30471. ++code;
  30472. }
  30473. }
  30474. }
  30475. return [codes, maxLen];
  30476. };
  30477. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  30478. var buffer, len;
  30479. var str = this.str;
  30480. // read block header
  30481. var hdr = this.getBits(3);
  30482. if (hdr & 1) {
  30483. this.eof = true;
  30484. }
  30485. hdr >>= 1;
  30486. if (hdr === 0) { // uncompressed block
  30487. var b;
  30488. if ((b = str.getByte()) === -1) {
  30489. error('Bad block header in flate stream');
  30490. }
  30491. var blockLen = b;
  30492. if ((b = str.getByte()) === -1) {
  30493. error('Bad block header in flate stream');
  30494. }
  30495. blockLen |= (b << 8);
  30496. if ((b = str.getByte()) === -1) {
  30497. error('Bad block header in flate stream');
  30498. }
  30499. var check = b;
  30500. if ((b = str.getByte()) === -1) {
  30501. error('Bad block header in flate stream');
  30502. }
  30503. check |= (b << 8);
  30504. if (check !== (~blockLen & 0xffff) &&
  30505. (blockLen !== 0 || check !== 0)) {
  30506. // Ignoring error for bad "empty" block (see issue 1277)
  30507. error('Bad uncompressed block length in flate stream');
  30508. }
  30509. this.codeBuf = 0;
  30510. this.codeSize = 0;
  30511. var bufferLength = this.bufferLength;
  30512. buffer = this.ensureBuffer(bufferLength + blockLen);
  30513. var end = bufferLength + blockLen;
  30514. this.bufferLength = end;
  30515. if (blockLen === 0) {
  30516. if (str.peekByte() === -1) {
  30517. this.eof = true;
  30518. }
  30519. } else {
  30520. for (var n = bufferLength; n < end; ++n) {
  30521. if ((b = str.getByte()) === -1) {
  30522. this.eof = true;
  30523. break;
  30524. }
  30525. buffer[n] = b;
  30526. }
  30527. }
  30528. return;
  30529. }
  30530. var litCodeTable;
  30531. var distCodeTable;
  30532. if (hdr === 1) { // compressed block, fixed codes
  30533. litCodeTable = fixedLitCodeTab;
  30534. distCodeTable = fixedDistCodeTab;
  30535. } else if (hdr === 2) { // compressed block, dynamic codes
  30536. var numLitCodes = this.getBits(5) + 257;
  30537. var numDistCodes = this.getBits(5) + 1;
  30538. var numCodeLenCodes = this.getBits(4) + 4;
  30539. // build the code lengths code table
  30540. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30541. var i;
  30542. for (i = 0; i < numCodeLenCodes; ++i) {
  30543. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30544. }
  30545. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30546. // build the literal and distance code tables
  30547. len = 0;
  30548. i = 0;
  30549. var codes = numLitCodes + numDistCodes;
  30550. var codeLengths = new Uint8Array(codes);
  30551. var bitsLength, bitsOffset, what;
  30552. while (i < codes) {
  30553. var code = this.getCode(codeLenCodeTab);
  30554. if (code === 16) {
  30555. bitsLength = 2; bitsOffset = 3; what = len;
  30556. } else if (code === 17) {
  30557. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30558. } else if (code === 18) {
  30559. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30560. } else {
  30561. codeLengths[i++] = len = code;
  30562. continue;
  30563. }
  30564. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30565. while (repeatLength-- > 0) {
  30566. codeLengths[i++] = what;
  30567. }
  30568. }
  30569. litCodeTable =
  30570. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30571. distCodeTable =
  30572. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30573. } else {
  30574. error('Unknown block type in flate stream');
  30575. }
  30576. buffer = this.buffer;
  30577. var limit = buffer ? buffer.length : 0;
  30578. var pos = this.bufferLength;
  30579. while (true) {
  30580. var code1 = this.getCode(litCodeTable);
  30581. if (code1 < 256) {
  30582. if (pos + 1 >= limit) {
  30583. buffer = this.ensureBuffer(pos + 1);
  30584. limit = buffer.length;
  30585. }
  30586. buffer[pos++] = code1;
  30587. continue;
  30588. }
  30589. if (code1 === 256) {
  30590. this.bufferLength = pos;
  30591. return;
  30592. }
  30593. code1 -= 257;
  30594. code1 = lengthDecode[code1];
  30595. var code2 = code1 >> 16;
  30596. if (code2 > 0) {
  30597. code2 = this.getBits(code2);
  30598. }
  30599. len = (code1 & 0xffff) + code2;
  30600. code1 = this.getCode(distCodeTable);
  30601. code1 = distDecode[code1];
  30602. code2 = code1 >> 16;
  30603. if (code2 > 0) {
  30604. code2 = this.getBits(code2);
  30605. }
  30606. var dist = (code1 & 0xffff) + code2;
  30607. if (pos + len >= limit) {
  30608. buffer = this.ensureBuffer(pos + len);
  30609. limit = buffer.length;
  30610. }
  30611. for (var k = 0; k < len; ++k, ++pos) {
  30612. buffer[pos] = buffer[pos - dist];
  30613. }
  30614. }
  30615. };
  30616. return FlateStream;
  30617. })();
  30618. var PredictorStream = (function PredictorStreamClosure() {
  30619. function PredictorStream(str, maybeLength, params) {
  30620. var predictor = this.predictor = params.get('Predictor') || 1;
  30621. if (predictor <= 1) {
  30622. return str; // no prediction
  30623. }
  30624. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30625. error('Unsupported predictor: ' + predictor);
  30626. }
  30627. if (predictor === 2) {
  30628. this.readBlock = this.readBlockTiff;
  30629. } else {
  30630. this.readBlock = this.readBlockPng;
  30631. }
  30632. this.str = str;
  30633. this.dict = str.dict;
  30634. var colors = this.colors = params.get('Colors') || 1;
  30635. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30636. var columns = this.columns = params.get('Columns') || 1;
  30637. this.pixBytes = (colors * bits + 7) >> 3;
  30638. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30639. DecodeStream.call(this, maybeLength);
  30640. return this;
  30641. }
  30642. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30643. PredictorStream.prototype.readBlockTiff =
  30644. function predictorStreamReadBlockTiff() {
  30645. var rowBytes = this.rowBytes;
  30646. var bufferLength = this.bufferLength;
  30647. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30648. var bits = this.bits;
  30649. var colors = this.colors;
  30650. var rawBytes = this.str.getBytes(rowBytes);
  30651. this.eof = !rawBytes.length;
  30652. if (this.eof) {
  30653. return;
  30654. }
  30655. var inbuf = 0, outbuf = 0;
  30656. var inbits = 0, outbits = 0;
  30657. var pos = bufferLength;
  30658. var i;
  30659. if (bits === 1) {
  30660. for (i = 0; i < rowBytes; ++i) {
  30661. var c = rawBytes[i];
  30662. inbuf = (inbuf << 8) | c;
  30663. // bitwise addition is exclusive or
  30664. // first shift inbuf and then add
  30665. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30666. // truncate inbuf (assumes colors < 16)
  30667. inbuf &= 0xFFFF;
  30668. }
  30669. } else if (bits === 8) {
  30670. for (i = 0; i < colors; ++i) {
  30671. buffer[pos++] = rawBytes[i];
  30672. }
  30673. for (; i < rowBytes; ++i) {
  30674. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30675. pos++;
  30676. }
  30677. } else {
  30678. var compArray = new Uint8Array(colors + 1);
  30679. var bitMask = (1 << bits) - 1;
  30680. var j = 0, k = bufferLength;
  30681. var columns = this.columns;
  30682. for (i = 0; i < columns; ++i) {
  30683. for (var kk = 0; kk < colors; ++kk) {
  30684. if (inbits < bits) {
  30685. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30686. inbits += 8;
  30687. }
  30688. compArray[kk] = (compArray[kk] +
  30689. (inbuf >> (inbits - bits))) & bitMask;
  30690. inbits -= bits;
  30691. outbuf = (outbuf << bits) | compArray[kk];
  30692. outbits += bits;
  30693. if (outbits >= 8) {
  30694. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30695. outbits -= 8;
  30696. }
  30697. }
  30698. }
  30699. if (outbits > 0) {
  30700. buffer[k++] = (outbuf << (8 - outbits)) +
  30701. (inbuf & ((1 << (8 - outbits)) - 1));
  30702. }
  30703. }
  30704. this.bufferLength += rowBytes;
  30705. };
  30706. PredictorStream.prototype.readBlockPng =
  30707. function predictorStreamReadBlockPng() {
  30708. var rowBytes = this.rowBytes;
  30709. var pixBytes = this.pixBytes;
  30710. var predictor = this.str.getByte();
  30711. var rawBytes = this.str.getBytes(rowBytes);
  30712. this.eof = !rawBytes.length;
  30713. if (this.eof) {
  30714. return;
  30715. }
  30716. var bufferLength = this.bufferLength;
  30717. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30718. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30719. if (prevRow.length === 0) {
  30720. prevRow = new Uint8Array(rowBytes);
  30721. }
  30722. var i, j = bufferLength, up, c;
  30723. switch (predictor) {
  30724. case 0:
  30725. for (i = 0; i < rowBytes; ++i) {
  30726. buffer[j++] = rawBytes[i];
  30727. }
  30728. break;
  30729. case 1:
  30730. for (i = 0; i < pixBytes; ++i) {
  30731. buffer[j++] = rawBytes[i];
  30732. }
  30733. for (; i < rowBytes; ++i) {
  30734. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30735. j++;
  30736. }
  30737. break;
  30738. case 2:
  30739. for (i = 0; i < rowBytes; ++i) {
  30740. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30741. }
  30742. break;
  30743. case 3:
  30744. for (i = 0; i < pixBytes; ++i) {
  30745. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30746. }
  30747. for (; i < rowBytes; ++i) {
  30748. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30749. rawBytes[i]) & 0xFF;
  30750. j++;
  30751. }
  30752. break;
  30753. case 4:
  30754. // we need to save the up left pixels values. the simplest way
  30755. // is to create a new buffer
  30756. for (i = 0; i < pixBytes; ++i) {
  30757. up = prevRow[i];
  30758. c = rawBytes[i];
  30759. buffer[j++] = up + c;
  30760. }
  30761. for (; i < rowBytes; ++i) {
  30762. up = prevRow[i];
  30763. var upLeft = prevRow[i - pixBytes];
  30764. var left = buffer[j - pixBytes];
  30765. var p = left + up - upLeft;
  30766. var pa = p - left;
  30767. if (pa < 0) {
  30768. pa = -pa;
  30769. }
  30770. var pb = p - up;
  30771. if (pb < 0) {
  30772. pb = -pb;
  30773. }
  30774. var pc = p - upLeft;
  30775. if (pc < 0) {
  30776. pc = -pc;
  30777. }
  30778. c = rawBytes[i];
  30779. if (pa <= pb && pa <= pc) {
  30780. buffer[j++] = left + c;
  30781. } else if (pb <= pc) {
  30782. buffer[j++] = up + c;
  30783. } else {
  30784. buffer[j++] = upLeft + c;
  30785. }
  30786. }
  30787. break;
  30788. default:
  30789. error('Unsupported predictor: ' + predictor);
  30790. }
  30791. this.bufferLength += rowBytes;
  30792. };
  30793. return PredictorStream;
  30794. })();
  30795. /**
  30796. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30797. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30798. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30799. * a library to decode these images and the stream behaves like all the other
  30800. * DecodeStreams.
  30801. */
  30802. var JpegStream = (function JpegStreamClosure() {
  30803. function JpegStream(stream, maybeLength, dict, xref) {
  30804. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30805. // Note: this seems to mainly affect inline images.
  30806. var ch;
  30807. while ((ch = stream.getByte()) !== -1) {
  30808. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30809. stream.skip(-1); // Reset the stream position to the SOI.
  30810. break;
  30811. }
  30812. }
  30813. this.stream = stream;
  30814. this.maybeLength = maybeLength;
  30815. this.dict = dict;
  30816. DecodeStream.call(this, maybeLength);
  30817. }
  30818. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30819. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30820. get: function JpegStream_bytes() {
  30821. // If this.maybeLength is null, we'll get the entire stream.
  30822. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30823. },
  30824. configurable: true
  30825. });
  30826. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30827. if (this.bufferLength) {
  30828. return;
  30829. }
  30830. try {
  30831. var jpegImage = new JpegImage();
  30832. // checking if values needs to be transformed before conversion
  30833. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30834. var decodeArr = this.dict.get('Decode');
  30835. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30836. var decodeArrLength = decodeArr.length;
  30837. var transform = new Int32Array(decodeArrLength);
  30838. var transformNeeded = false;
  30839. var maxValue = (1 << bitsPerComponent) - 1;
  30840. for (var i = 0; i < decodeArrLength; i += 2) {
  30841. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30842. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30843. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30844. transformNeeded = true;
  30845. }
  30846. }
  30847. if (transformNeeded) {
  30848. jpegImage.decodeTransform = transform;
  30849. }
  30850. }
  30851. jpegImage.parse(this.bytes);
  30852. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30853. this.forceRGB);
  30854. this.buffer = data;
  30855. this.bufferLength = data.length;
  30856. this.eof = true;
  30857. } catch (e) {
  30858. error('JPEG error: ' + e);
  30859. }
  30860. };
  30861. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30862. this.ensureBuffer();
  30863. return this.buffer;
  30864. };
  30865. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30866. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30867. };
  30868. /**
  30869. * Checks if the image can be decoded and displayed by the browser without any
  30870. * further processing such as color space conversions.
  30871. */
  30872. JpegStream.prototype.isNativelySupported =
  30873. function JpegStream_isNativelySupported(xref, res) {
  30874. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30875. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  30876. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  30877. };
  30878. /**
  30879. * Checks if the image can be decoded by the browser.
  30880. */
  30881. JpegStream.prototype.isNativelyDecodable =
  30882. function JpegStream_isNativelyDecodable(xref, res) {
  30883. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30884. return (cs.numComps === 1 || cs.numComps === 3) &&
  30885. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  30886. };
  30887. return JpegStream;
  30888. })();
  30889. /**
  30890. * For JPEG 2000's we use a library to decode these images and
  30891. * the stream behaves like all the other DecodeStreams.
  30892. */
  30893. var JpxStream = (function JpxStreamClosure() {
  30894. function JpxStream(stream, maybeLength, dict) {
  30895. this.stream = stream;
  30896. this.maybeLength = maybeLength;
  30897. this.dict = dict;
  30898. DecodeStream.call(this, maybeLength);
  30899. }
  30900. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30901. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30902. get: function JpxStream_bytes() {
  30903. // If this.maybeLength is null, we'll get the entire stream.
  30904. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30905. },
  30906. configurable: true
  30907. });
  30908. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30909. if (this.bufferLength) {
  30910. return;
  30911. }
  30912. var jpxImage = new JpxImage();
  30913. jpxImage.parse(this.bytes);
  30914. var width = jpxImage.width;
  30915. var height = jpxImage.height;
  30916. var componentsCount = jpxImage.componentsCount;
  30917. var tileCount = jpxImage.tiles.length;
  30918. if (tileCount === 1) {
  30919. this.buffer = jpxImage.tiles[0].items;
  30920. } else {
  30921. var data = new Uint8Array(width * height * componentsCount);
  30922. for (var k = 0; k < tileCount; k++) {
  30923. var tileComponents = jpxImage.tiles[k];
  30924. var tileWidth = tileComponents.width;
  30925. var tileHeight = tileComponents.height;
  30926. var tileLeft = tileComponents.left;
  30927. var tileTop = tileComponents.top;
  30928. var src = tileComponents.items;
  30929. var srcPosition = 0;
  30930. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30931. var imgRowSize = width * componentsCount;
  30932. var tileRowSize = tileWidth * componentsCount;
  30933. for (var j = 0; j < tileHeight; j++) {
  30934. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30935. data.set(rowBytes, dataPosition);
  30936. srcPosition += tileRowSize;
  30937. dataPosition += imgRowSize;
  30938. }
  30939. }
  30940. this.buffer = data;
  30941. }
  30942. this.bufferLength = this.buffer.length;
  30943. this.eof = true;
  30944. };
  30945. return JpxStream;
  30946. })();
  30947. /**
  30948. * For JBIG2's we use a library to decode these images and
  30949. * the stream behaves like all the other DecodeStreams.
  30950. */
  30951. var Jbig2Stream = (function Jbig2StreamClosure() {
  30952. function Jbig2Stream(stream, maybeLength, dict) {
  30953. this.stream = stream;
  30954. this.maybeLength = maybeLength;
  30955. this.dict = dict;
  30956. DecodeStream.call(this, maybeLength);
  30957. }
  30958. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30959. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30960. get: function Jbig2Stream_bytes() {
  30961. // If this.maybeLength is null, we'll get the entire stream.
  30962. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30963. },
  30964. configurable: true
  30965. });
  30966. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30967. if (this.bufferLength) {
  30968. return;
  30969. }
  30970. var jbig2Image = new Jbig2Image();
  30971. var chunks = [], xref = this.dict.xref;
  30972. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30973. // According to the PDF specification, DecodeParms can be either
  30974. // a dictionary, or an array whose elements are dictionaries.
  30975. if (isArray(decodeParams)) {
  30976. if (decodeParams.length > 1) {
  30977. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30978. 'not supported.');
  30979. }
  30980. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30981. }
  30982. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30983. var globalsStream = decodeParams.get('JBIG2Globals');
  30984. var globals = globalsStream.getBytes();
  30985. chunks.push({data: globals, start: 0, end: globals.length});
  30986. }
  30987. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30988. var data = jbig2Image.parseChunks(chunks);
  30989. var dataLength = data.length;
  30990. // JBIG2 had black as 1 and white as 0, inverting the colors
  30991. for (var i = 0; i < dataLength; i++) {
  30992. data[i] ^= 0xFF;
  30993. }
  30994. this.buffer = data;
  30995. this.bufferLength = dataLength;
  30996. this.eof = true;
  30997. };
  30998. return Jbig2Stream;
  30999. })();
  31000. var DecryptStream = (function DecryptStreamClosure() {
  31001. function DecryptStream(str, maybeLength, decrypt) {
  31002. this.str = str;
  31003. this.dict = str.dict;
  31004. this.decrypt = decrypt;
  31005. this.nextChunk = null;
  31006. this.initialized = false;
  31007. DecodeStream.call(this, maybeLength);
  31008. }
  31009. var chunkSize = 512;
  31010. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  31011. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  31012. var chunk;
  31013. if (this.initialized) {
  31014. chunk = this.nextChunk;
  31015. } else {
  31016. chunk = this.str.getBytes(chunkSize);
  31017. this.initialized = true;
  31018. }
  31019. if (!chunk || chunk.length === 0) {
  31020. this.eof = true;
  31021. return;
  31022. }
  31023. this.nextChunk = this.str.getBytes(chunkSize);
  31024. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  31025. var decrypt = this.decrypt;
  31026. chunk = decrypt(chunk, !hasMoreData);
  31027. var bufferLength = this.bufferLength;
  31028. var i, n = chunk.length;
  31029. var buffer = this.ensureBuffer(bufferLength + n);
  31030. for (i = 0; i < n; i++) {
  31031. buffer[bufferLength++] = chunk[i];
  31032. }
  31033. this.bufferLength = bufferLength;
  31034. };
  31035. return DecryptStream;
  31036. })();
  31037. var Ascii85Stream = (function Ascii85StreamClosure() {
  31038. function Ascii85Stream(str, maybeLength) {
  31039. this.str = str;
  31040. this.dict = str.dict;
  31041. this.input = new Uint8Array(5);
  31042. // Most streams increase in size when decoded, but Ascii85 streams
  31043. // typically shrink by ~20%.
  31044. if (maybeLength) {
  31045. maybeLength = 0.8 * maybeLength;
  31046. }
  31047. DecodeStream.call(this, maybeLength);
  31048. }
  31049. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  31050. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  31051. var TILDA_CHAR = 0x7E; // '~'
  31052. var Z_LOWER_CHAR = 0x7A; // 'z'
  31053. var EOF = -1;
  31054. var str = this.str;
  31055. var c = str.getByte();
  31056. while (Lexer.isSpace(c)) {
  31057. c = str.getByte();
  31058. }
  31059. if (c === EOF || c === TILDA_CHAR) {
  31060. this.eof = true;
  31061. return;
  31062. }
  31063. var bufferLength = this.bufferLength, buffer;
  31064. var i;
  31065. // special code for z
  31066. if (c === Z_LOWER_CHAR) {
  31067. buffer = this.ensureBuffer(bufferLength + 4);
  31068. for (i = 0; i < 4; ++i) {
  31069. buffer[bufferLength + i] = 0;
  31070. }
  31071. this.bufferLength += 4;
  31072. } else {
  31073. var input = this.input;
  31074. input[0] = c;
  31075. for (i = 1; i < 5; ++i) {
  31076. c = str.getByte();
  31077. while (Lexer.isSpace(c)) {
  31078. c = str.getByte();
  31079. }
  31080. input[i] = c;
  31081. if (c === EOF || c === TILDA_CHAR) {
  31082. break;
  31083. }
  31084. }
  31085. buffer = this.ensureBuffer(bufferLength + i - 1);
  31086. this.bufferLength += i - 1;
  31087. // partial ending;
  31088. if (i < 5) {
  31089. for (; i < 5; ++i) {
  31090. input[i] = 0x21 + 84;
  31091. }
  31092. this.eof = true;
  31093. }
  31094. var t = 0;
  31095. for (i = 0; i < 5; ++i) {
  31096. t = t * 85 + (input[i] - 0x21);
  31097. }
  31098. for (i = 3; i >= 0; --i) {
  31099. buffer[bufferLength + i] = t & 0xFF;
  31100. t >>= 8;
  31101. }
  31102. }
  31103. };
  31104. return Ascii85Stream;
  31105. })();
  31106. var AsciiHexStream = (function AsciiHexStreamClosure() {
  31107. function AsciiHexStream(str, maybeLength) {
  31108. this.str = str;
  31109. this.dict = str.dict;
  31110. this.firstDigit = -1;
  31111. // Most streams increase in size when decoded, but AsciiHex streams shrink
  31112. // by 50%.
  31113. if (maybeLength) {
  31114. maybeLength = 0.5 * maybeLength;
  31115. }
  31116. DecodeStream.call(this, maybeLength);
  31117. }
  31118. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  31119. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  31120. var UPSTREAM_BLOCK_SIZE = 8000;
  31121. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  31122. if (!bytes.length) {
  31123. this.eof = true;
  31124. return;
  31125. }
  31126. var maxDecodeLength = (bytes.length + 1) >> 1;
  31127. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  31128. var bufferLength = this.bufferLength;
  31129. var firstDigit = this.firstDigit;
  31130. for (var i = 0, ii = bytes.length; i < ii; i++) {
  31131. var ch = bytes[i], digit;
  31132. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  31133. digit = ch & 0x0F;
  31134. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  31135. // 'A'-'Z', 'a'-'z'
  31136. digit = (ch & 0x0F) + 9;
  31137. } else if (ch === 0x3E) { // '>'
  31138. this.eof = true;
  31139. break;
  31140. } else { // probably whitespace
  31141. continue; // ignoring
  31142. }
  31143. if (firstDigit < 0) {
  31144. firstDigit = digit;
  31145. } else {
  31146. buffer[bufferLength++] = (firstDigit << 4) | digit;
  31147. firstDigit = -1;
  31148. }
  31149. }
  31150. if (firstDigit >= 0 && this.eof) {
  31151. // incomplete byte
  31152. buffer[bufferLength++] = (firstDigit << 4);
  31153. firstDigit = -1;
  31154. }
  31155. this.firstDigit = firstDigit;
  31156. this.bufferLength = bufferLength;
  31157. };
  31158. return AsciiHexStream;
  31159. })();
  31160. var RunLengthStream = (function RunLengthStreamClosure() {
  31161. function RunLengthStream(str, maybeLength) {
  31162. this.str = str;
  31163. this.dict = str.dict;
  31164. DecodeStream.call(this, maybeLength);
  31165. }
  31166. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  31167. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  31168. // The repeatHeader has following format. The first byte defines type of run
  31169. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  31170. // (in addition to the second byte from the header), n = 129 through 255 -
  31171. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  31172. var repeatHeader = this.str.getBytes(2);
  31173. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  31174. this.eof = true;
  31175. return;
  31176. }
  31177. var buffer;
  31178. var bufferLength = this.bufferLength;
  31179. var n = repeatHeader[0];
  31180. if (n < 128) {
  31181. // copy n bytes
  31182. buffer = this.ensureBuffer(bufferLength + n + 1);
  31183. buffer[bufferLength++] = repeatHeader[1];
  31184. if (n > 0) {
  31185. var source = this.str.getBytes(n);
  31186. buffer.set(source, bufferLength);
  31187. bufferLength += n;
  31188. }
  31189. } else {
  31190. n = 257 - n;
  31191. var b = repeatHeader[1];
  31192. buffer = this.ensureBuffer(bufferLength + n + 1);
  31193. for (var i = 0; i < n; i++) {
  31194. buffer[bufferLength++] = b;
  31195. }
  31196. }
  31197. this.bufferLength = bufferLength;
  31198. };
  31199. return RunLengthStream;
  31200. })();
  31201. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  31202. var ccittEOL = -2;
  31203. var twoDimPass = 0;
  31204. var twoDimHoriz = 1;
  31205. var twoDimVert0 = 2;
  31206. var twoDimVertR1 = 3;
  31207. var twoDimVertL1 = 4;
  31208. var twoDimVertR2 = 5;
  31209. var twoDimVertL2 = 6;
  31210. var twoDimVertR3 = 7;
  31211. var twoDimVertL3 = 8;
  31212. var twoDimTable = [
  31213. [-1, -1], [-1, -1], // 000000x
  31214. [7, twoDimVertL3], // 0000010
  31215. [7, twoDimVertR3], // 0000011
  31216. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  31217. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  31218. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  31219. [4, twoDimPass], [4, twoDimPass],
  31220. [4, twoDimPass], [4, twoDimPass],
  31221. [4, twoDimPass], [4, twoDimPass],
  31222. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  31223. [3, twoDimHoriz], [3, twoDimHoriz],
  31224. [3, twoDimHoriz], [3, twoDimHoriz],
  31225. [3, twoDimHoriz], [3, twoDimHoriz],
  31226. [3, twoDimHoriz], [3, twoDimHoriz],
  31227. [3, twoDimHoriz], [3, twoDimHoriz],
  31228. [3, twoDimHoriz], [3, twoDimHoriz],
  31229. [3, twoDimHoriz], [3, twoDimHoriz],
  31230. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  31231. [3, twoDimVertL1], [3, twoDimVertL1],
  31232. [3, twoDimVertL1], [3, twoDimVertL1],
  31233. [3, twoDimVertL1], [3, twoDimVertL1],
  31234. [3, twoDimVertL1], [3, twoDimVertL1],
  31235. [3, twoDimVertL1], [3, twoDimVertL1],
  31236. [3, twoDimVertL1], [3, twoDimVertL1],
  31237. [3, twoDimVertL1], [3, twoDimVertL1],
  31238. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  31239. [3, twoDimVertR1], [3, twoDimVertR1],
  31240. [3, twoDimVertR1], [3, twoDimVertR1],
  31241. [3, twoDimVertR1], [3, twoDimVertR1],
  31242. [3, twoDimVertR1], [3, twoDimVertR1],
  31243. [3, twoDimVertR1], [3, twoDimVertR1],
  31244. [3, twoDimVertR1], [3, twoDimVertR1],
  31245. [3, twoDimVertR1], [3, twoDimVertR1],
  31246. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  31247. [1, twoDimVert0], [1, twoDimVert0],
  31248. [1, twoDimVert0], [1, twoDimVert0],
  31249. [1, twoDimVert0], [1, twoDimVert0],
  31250. [1, twoDimVert0], [1, twoDimVert0],
  31251. [1, twoDimVert0], [1, twoDimVert0],
  31252. [1, twoDimVert0], [1, twoDimVert0],
  31253. [1, twoDimVert0], [1, twoDimVert0],
  31254. [1, twoDimVert0], [1, twoDimVert0],
  31255. [1, twoDimVert0], [1, twoDimVert0],
  31256. [1, twoDimVert0], [1, twoDimVert0],
  31257. [1, twoDimVert0], [1, twoDimVert0],
  31258. [1, twoDimVert0], [1, twoDimVert0],
  31259. [1, twoDimVert0], [1, twoDimVert0],
  31260. [1, twoDimVert0], [1, twoDimVert0],
  31261. [1, twoDimVert0], [1, twoDimVert0],
  31262. [1, twoDimVert0], [1, twoDimVert0],
  31263. [1, twoDimVert0], [1, twoDimVert0],
  31264. [1, twoDimVert0], [1, twoDimVert0],
  31265. [1, twoDimVert0], [1, twoDimVert0],
  31266. [1, twoDimVert0], [1, twoDimVert0],
  31267. [1, twoDimVert0], [1, twoDimVert0],
  31268. [1, twoDimVert0], [1, twoDimVert0],
  31269. [1, twoDimVert0], [1, twoDimVert0],
  31270. [1, twoDimVert0], [1, twoDimVert0],
  31271. [1, twoDimVert0], [1, twoDimVert0],
  31272. [1, twoDimVert0], [1, twoDimVert0],
  31273. [1, twoDimVert0], [1, twoDimVert0],
  31274. [1, twoDimVert0], [1, twoDimVert0],
  31275. [1, twoDimVert0], [1, twoDimVert0],
  31276. [1, twoDimVert0], [1, twoDimVert0],
  31277. [1, twoDimVert0], [1, twoDimVert0]
  31278. ];
  31279. var whiteTable1 = [
  31280. [-1, -1], // 00000
  31281. [12, ccittEOL], // 00001
  31282. [-1, -1], [-1, -1], // 0001x
  31283. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  31284. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  31285. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  31286. [11, 1792], [11, 1792], // 1000x
  31287. [12, 1984], // 10010
  31288. [12, 2048], // 10011
  31289. [12, 2112], // 10100
  31290. [12, 2176], // 10101
  31291. [12, 2240], // 10110
  31292. [12, 2304], // 10111
  31293. [11, 1856], [11, 1856], // 1100x
  31294. [11, 1920], [11, 1920], // 1101x
  31295. [12, 2368], // 11100
  31296. [12, 2432], // 11101
  31297. [12, 2496], // 11110
  31298. [12, 2560] // 11111
  31299. ];
  31300. var whiteTable2 = [
  31301. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  31302. [8, 29], [8, 29], // 00000010x
  31303. [8, 30], [8, 30], // 00000011x
  31304. [8, 45], [8, 45], // 00000100x
  31305. [8, 46], [8, 46], // 00000101x
  31306. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  31307. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  31308. [8, 47], [8, 47], // 00001010x
  31309. [8, 48], [8, 48], // 00001011x
  31310. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  31311. [6, 13], [6, 13], [6, 13], [6, 13],
  31312. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  31313. [8, 33], [8, 33], // 00010010x
  31314. [8, 34], [8, 34], // 00010011x
  31315. [8, 35], [8, 35], // 00010100x
  31316. [8, 36], [8, 36], // 00010101x
  31317. [8, 37], [8, 37], // 00010110x
  31318. [8, 38], [8, 38], // 00010111x
  31319. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  31320. [8, 31], [8, 31], // 00011010x
  31321. [8, 32], [8, 32], // 00011011x
  31322. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  31323. [6, 1], [6, 1], [6, 1], [6, 1],
  31324. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  31325. [6, 12], [6, 12], [6, 12], [6, 12],
  31326. [8, 53], [8, 53], // 00100100x
  31327. [8, 54], [8, 54], // 00100101x
  31328. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  31329. [8, 39], [8, 39], // 00101000x
  31330. [8, 40], [8, 40], // 00101001x
  31331. [8, 41], [8, 41], // 00101010x
  31332. [8, 42], [8, 42], // 00101011x
  31333. [8, 43], [8, 43], // 00101100x
  31334. [8, 44], [8, 44], // 00101101x
  31335. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  31336. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  31337. [8, 61], [8, 61], // 00110010x
  31338. [8, 62], [8, 62], // 00110011x
  31339. [8, 63], [8, 63], // 00110100x
  31340. [8, 0], [8, 0], // 00110101x
  31341. [8, 320], [8, 320], // 00110110x
  31342. [8, 384], [8, 384], // 00110111x
  31343. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  31344. [5, 10], [5, 10], [5, 10], [5, 10],
  31345. [5, 10], [5, 10], [5, 10], [5, 10],
  31346. [5, 10], [5, 10], [5, 10], [5, 10],
  31347. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  31348. [5, 11], [5, 11], [5, 11], [5, 11],
  31349. [5, 11], [5, 11], [5, 11], [5, 11],
  31350. [5, 11], [5, 11], [5, 11], [5, 11],
  31351. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  31352. [8, 59], [8, 59], // 01001010x
  31353. [8, 60], [8, 60], // 01001011x
  31354. [9, 1472], // 010011000
  31355. [9, 1536], // 010011001
  31356. [9, 1600], // 010011010
  31357. [9, 1728], // 010011011
  31358. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  31359. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  31360. [8, 49], [8, 49], // 01010010x
  31361. [8, 50], [8, 50], // 01010011x
  31362. [8, 51], [8, 51], // 01010100x
  31363. [8, 52], [8, 52], // 01010101x
  31364. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  31365. [8, 55], [8, 55], // 01011000x
  31366. [8, 56], [8, 56], // 01011001x
  31367. [8, 57], [8, 57], // 01011010x
  31368. [8, 58], [8, 58], // 01011011x
  31369. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  31370. [6, 192], [6, 192], [6, 192], [6, 192],
  31371. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  31372. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  31373. [8, 448], [8, 448], // 01100100x
  31374. [8, 512], [8, 512], // 01100101x
  31375. [9, 704], // 011001100
  31376. [9, 768], // 011001101
  31377. [8, 640], [8, 640], // 01100111x
  31378. [8, 576], [8, 576], // 01101000x
  31379. [9, 832], // 011010010
  31380. [9, 896], // 011010011
  31381. [9, 960], // 011010100
  31382. [9, 1024], // 011010101
  31383. [9, 1088], // 011010110
  31384. [9, 1152], // 011010111
  31385. [9, 1216], // 011011000
  31386. [9, 1280], // 011011001
  31387. [9, 1344], // 011011010
  31388. [9, 1408], // 011011011
  31389. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  31390. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  31391. [4, 2], [4, 2], [4, 2], [4, 2],
  31392. [4, 2], [4, 2], [4, 2], [4, 2],
  31393. [4, 2], [4, 2], [4, 2], [4, 2],
  31394. [4, 2], [4, 2], [4, 2], [4, 2],
  31395. [4, 2], [4, 2], [4, 2], [4, 2],
  31396. [4, 2], [4, 2], [4, 2], [4, 2],
  31397. [4, 2], [4, 2], [4, 2], [4, 2],
  31398. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  31399. [4, 3], [4, 3], [4, 3], [4, 3],
  31400. [4, 3], [4, 3], [4, 3], [4, 3],
  31401. [4, 3], [4, 3], [4, 3], [4, 3],
  31402. [4, 3], [4, 3], [4, 3], [4, 3],
  31403. [4, 3], [4, 3], [4, 3], [4, 3],
  31404. [4, 3], [4, 3], [4, 3], [4, 3],
  31405. [4, 3], [4, 3], [4, 3], [4, 3],
  31406. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  31407. [5, 128], [5, 128], [5, 128], [5, 128],
  31408. [5, 128], [5, 128], [5, 128], [5, 128],
  31409. [5, 128], [5, 128], [5, 128], [5, 128],
  31410. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  31411. [5, 8], [5, 8], [5, 8], [5, 8],
  31412. [5, 8], [5, 8], [5, 8], [5, 8],
  31413. [5, 8], [5, 8], [5, 8], [5, 8],
  31414. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  31415. [5, 9], [5, 9], [5, 9], [5, 9],
  31416. [5, 9], [5, 9], [5, 9], [5, 9],
  31417. [5, 9], [5, 9], [5, 9], [5, 9],
  31418. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  31419. [6, 16], [6, 16], [6, 16], [6, 16],
  31420. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  31421. [6, 17], [6, 17], [6, 17], [6, 17],
  31422. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  31423. [4, 4], [4, 4], [4, 4], [4, 4],
  31424. [4, 4], [4, 4], [4, 4], [4, 4],
  31425. [4, 4], [4, 4], [4, 4], [4, 4],
  31426. [4, 4], [4, 4], [4, 4], [4, 4],
  31427. [4, 4], [4, 4], [4, 4], [4, 4],
  31428. [4, 4], [4, 4], [4, 4], [4, 4],
  31429. [4, 4], [4, 4], [4, 4], [4, 4],
  31430. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  31431. [4, 5], [4, 5], [4, 5], [4, 5],
  31432. [4, 5], [4, 5], [4, 5], [4, 5],
  31433. [4, 5], [4, 5], [4, 5], [4, 5],
  31434. [4, 5], [4, 5], [4, 5], [4, 5],
  31435. [4, 5], [4, 5], [4, 5], [4, 5],
  31436. [4, 5], [4, 5], [4, 5], [4, 5],
  31437. [4, 5], [4, 5], [4, 5], [4, 5],
  31438. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  31439. [6, 14], [6, 14], [6, 14], [6, 14],
  31440. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  31441. [6, 15], [6, 15], [6, 15], [6, 15],
  31442. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  31443. [5, 64], [5, 64], [5, 64], [5, 64],
  31444. [5, 64], [5, 64], [5, 64], [5, 64],
  31445. [5, 64], [5, 64], [5, 64], [5, 64],
  31446. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  31447. [4, 6], [4, 6], [4, 6], [4, 6],
  31448. [4, 6], [4, 6], [4, 6], [4, 6],
  31449. [4, 6], [4, 6], [4, 6], [4, 6],
  31450. [4, 6], [4, 6], [4, 6], [4, 6],
  31451. [4, 6], [4, 6], [4, 6], [4, 6],
  31452. [4, 6], [4, 6], [4, 6], [4, 6],
  31453. [4, 6], [4, 6], [4, 6], [4, 6],
  31454. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  31455. [4, 7], [4, 7], [4, 7], [4, 7],
  31456. [4, 7], [4, 7], [4, 7], [4, 7],
  31457. [4, 7], [4, 7], [4, 7], [4, 7],
  31458. [4, 7], [4, 7], [4, 7], [4, 7],
  31459. [4, 7], [4, 7], [4, 7], [4, 7],
  31460. [4, 7], [4, 7], [4, 7], [4, 7],
  31461. [4, 7], [4, 7], [4, 7], [4, 7]
  31462. ];
  31463. var blackTable1 = [
  31464. [-1, -1], [-1, -1], // 000000000000x
  31465. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  31466. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  31467. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  31468. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  31469. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  31470. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  31471. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  31472. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  31473. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  31474. [12, 1984], [12, 1984], // 000000010010x
  31475. [12, 2048], [12, 2048], // 000000010011x
  31476. [12, 2112], [12, 2112], // 000000010100x
  31477. [12, 2176], [12, 2176], // 000000010101x
  31478. [12, 2240], [12, 2240], // 000000010110x
  31479. [12, 2304], [12, 2304], // 000000010111x
  31480. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  31481. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  31482. [12, 2368], [12, 2368], // 000000011100x
  31483. [12, 2432], [12, 2432], // 000000011101x
  31484. [12, 2496], [12, 2496], // 000000011110x
  31485. [12, 2560], [12, 2560], // 000000011111x
  31486. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  31487. [10, 18], [10, 18], [10, 18], [10, 18],
  31488. [12, 52], [12, 52], // 000000100100x
  31489. [13, 640], // 0000001001010
  31490. [13, 704], // 0000001001011
  31491. [13, 768], // 0000001001100
  31492. [13, 832], // 0000001001101
  31493. [12, 55], [12, 55], // 000000100111x
  31494. [12, 56], [12, 56], // 000000101000x
  31495. [13, 1280], // 0000001010010
  31496. [13, 1344], // 0000001010011
  31497. [13, 1408], // 0000001010100
  31498. [13, 1472], // 0000001010101
  31499. [12, 59], [12, 59], // 000000101011x
  31500. [12, 60], [12, 60], // 000000101100x
  31501. [13, 1536], // 0000001011010
  31502. [13, 1600], // 0000001011011
  31503. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31504. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31505. [13, 1664], // 0000001100100
  31506. [13, 1728], // 0000001100101
  31507. [12, 320], [12, 320], // 000000110011x
  31508. [12, 384], [12, 384], // 000000110100x
  31509. [12, 448], [12, 448], // 000000110101x
  31510. [13, 512], // 0000001101100
  31511. [13, 576], // 0000001101101
  31512. [12, 53], [12, 53], // 000000110111x
  31513. [12, 54], [12, 54], // 000000111000x
  31514. [13, 896], // 0000001110010
  31515. [13, 960], // 0000001110011
  31516. [13, 1024], // 0000001110100
  31517. [13, 1088], // 0000001110101
  31518. [13, 1152], // 0000001110110
  31519. [13, 1216], // 0000001110111
  31520. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31521. [10, 64], [10, 64], [10, 64], [10, 64]
  31522. ];
  31523. var blackTable2 = [
  31524. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31525. [8, 13], [8, 13], [8, 13], [8, 13],
  31526. [8, 13], [8, 13], [8, 13], [8, 13],
  31527. [8, 13], [8, 13], [8, 13], [8, 13],
  31528. [11, 23], [11, 23], // 00000101000x
  31529. [12, 50], // 000001010010
  31530. [12, 51], // 000001010011
  31531. [12, 44], // 000001010100
  31532. [12, 45], // 000001010101
  31533. [12, 46], // 000001010110
  31534. [12, 47], // 000001010111
  31535. [12, 57], // 000001011000
  31536. [12, 58], // 000001011001
  31537. [12, 61], // 000001011010
  31538. [12, 256], // 000001011011
  31539. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31540. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31541. [12, 48], // 000001100100
  31542. [12, 49], // 000001100101
  31543. [12, 62], // 000001100110
  31544. [12, 63], // 000001100111
  31545. [12, 30], // 000001101000
  31546. [12, 31], // 000001101001
  31547. [12, 32], // 000001101010
  31548. [12, 33], // 000001101011
  31549. [12, 40], // 000001101100
  31550. [12, 41], // 000001101101
  31551. [11, 22], [11, 22], // 00000110111x
  31552. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31553. [8, 14], [8, 14], [8, 14], [8, 14],
  31554. [8, 14], [8, 14], [8, 14], [8, 14],
  31555. [8, 14], [8, 14], [8, 14], [8, 14],
  31556. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31557. [7, 10], [7, 10], [7, 10], [7, 10],
  31558. [7, 10], [7, 10], [7, 10], [7, 10],
  31559. [7, 10], [7, 10], [7, 10], [7, 10],
  31560. [7, 10], [7, 10], [7, 10], [7, 10],
  31561. [7, 10], [7, 10], [7, 10], [7, 10],
  31562. [7, 10], [7, 10], [7, 10], [7, 10],
  31563. [7, 10], [7, 10], [7, 10], [7, 10],
  31564. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31565. [7, 11], [7, 11], [7, 11], [7, 11],
  31566. [7, 11], [7, 11], [7, 11], [7, 11],
  31567. [7, 11], [7, 11], [7, 11], [7, 11],
  31568. [7, 11], [7, 11], [7, 11], [7, 11],
  31569. [7, 11], [7, 11], [7, 11], [7, 11],
  31570. [7, 11], [7, 11], [7, 11], [7, 11],
  31571. [7, 11], [7, 11], [7, 11], [7, 11],
  31572. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31573. [9, 15], [9, 15], [9, 15], [9, 15],
  31574. [12, 128], // 000011001000
  31575. [12, 192], // 000011001001
  31576. [12, 26], // 000011001010
  31577. [12, 27], // 000011001011
  31578. [12, 28], // 000011001100
  31579. [12, 29], // 000011001101
  31580. [11, 19], [11, 19], // 00001100111x
  31581. [11, 20], [11, 20], // 00001101000x
  31582. [12, 34], // 000011010010
  31583. [12, 35], // 000011010011
  31584. [12, 36], // 000011010100
  31585. [12, 37], // 000011010101
  31586. [12, 38], // 000011010110
  31587. [12, 39], // 000011010111
  31588. [11, 21], [11, 21], // 00001101100x
  31589. [12, 42], // 000011011010
  31590. [12, 43], // 000011011011
  31591. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31592. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31593. [7, 12], [7, 12], [7, 12], [7, 12],
  31594. [7, 12], [7, 12], [7, 12], [7, 12],
  31595. [7, 12], [7, 12], [7, 12], [7, 12],
  31596. [7, 12], [7, 12], [7, 12], [7, 12],
  31597. [7, 12], [7, 12], [7, 12], [7, 12],
  31598. [7, 12], [7, 12], [7, 12], [7, 12],
  31599. [7, 12], [7, 12], [7, 12], [7, 12]
  31600. ];
  31601. var blackTable3 = [
  31602. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31603. [6, 9], // 000100
  31604. [6, 8], // 000101
  31605. [5, 7], [5, 7], // 00011x
  31606. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31607. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31608. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31609. [3, 1], [3, 1], [3, 1], [3, 1],
  31610. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31611. [3, 4], [3, 4], [3, 4], [3, 4],
  31612. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31613. [2, 3], [2, 3], [2, 3], [2, 3],
  31614. [2, 3], [2, 3], [2, 3], [2, 3],
  31615. [2, 3], [2, 3], [2, 3], [2, 3],
  31616. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31617. [2, 2], [2, 2], [2, 2], [2, 2],
  31618. [2, 2], [2, 2], [2, 2], [2, 2],
  31619. [2, 2], [2, 2], [2, 2], [2, 2]
  31620. ];
  31621. function CCITTFaxStream(str, maybeLength, params) {
  31622. this.str = str;
  31623. this.dict = str.dict;
  31624. params = params || Dict.empty;
  31625. this.encoding = params.get('K') || 0;
  31626. this.eoline = params.get('EndOfLine') || false;
  31627. this.byteAlign = params.get('EncodedByteAlign') || false;
  31628. this.columns = params.get('Columns') || 1728;
  31629. this.rows = params.get('Rows') || 0;
  31630. var eoblock = params.get('EndOfBlock');
  31631. if (eoblock === null || eoblock === undefined) {
  31632. eoblock = true;
  31633. }
  31634. this.eoblock = eoblock;
  31635. this.black = params.get('BlackIs1') || false;
  31636. this.codingLine = new Uint32Array(this.columns + 1);
  31637. this.refLine = new Uint32Array(this.columns + 2);
  31638. this.codingLine[0] = this.columns;
  31639. this.codingPos = 0;
  31640. this.row = 0;
  31641. this.nextLine2D = this.encoding < 0;
  31642. this.inputBits = 0;
  31643. this.inputBuf = 0;
  31644. this.outputBits = 0;
  31645. var code1;
  31646. while ((code1 = this.lookBits(12)) === 0) {
  31647. this.eatBits(1);
  31648. }
  31649. if (code1 === 1) {
  31650. this.eatBits(12);
  31651. }
  31652. if (this.encoding > 0) {
  31653. this.nextLine2D = !this.lookBits(1);
  31654. this.eatBits(1);
  31655. }
  31656. DecodeStream.call(this, maybeLength);
  31657. }
  31658. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31659. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31660. while (!this.eof) {
  31661. var c = this.lookChar();
  31662. this.ensureBuffer(this.bufferLength + 1);
  31663. this.buffer[this.bufferLength++] = c;
  31664. }
  31665. };
  31666. CCITTFaxStream.prototype.addPixels =
  31667. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31668. var codingLine = this.codingLine;
  31669. var codingPos = this.codingPos;
  31670. if (a1 > codingLine[codingPos]) {
  31671. if (a1 > this.columns) {
  31672. info('row is wrong length');
  31673. this.err = true;
  31674. a1 = this.columns;
  31675. }
  31676. if ((codingPos & 1) ^ blackPixels) {
  31677. ++codingPos;
  31678. }
  31679. codingLine[codingPos] = a1;
  31680. }
  31681. this.codingPos = codingPos;
  31682. };
  31683. CCITTFaxStream.prototype.addPixelsNeg =
  31684. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31685. var codingLine = this.codingLine;
  31686. var codingPos = this.codingPos;
  31687. if (a1 > codingLine[codingPos]) {
  31688. if (a1 > this.columns) {
  31689. info('row is wrong length');
  31690. this.err = true;
  31691. a1 = this.columns;
  31692. }
  31693. if ((codingPos & 1) ^ blackPixels) {
  31694. ++codingPos;
  31695. }
  31696. codingLine[codingPos] = a1;
  31697. } else if (a1 < codingLine[codingPos]) {
  31698. if (a1 < 0) {
  31699. info('invalid code');
  31700. this.err = true;
  31701. a1 = 0;
  31702. }
  31703. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31704. --codingPos;
  31705. }
  31706. codingLine[codingPos] = a1;
  31707. }
  31708. this.codingPos = codingPos;
  31709. };
  31710. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31711. var refLine = this.refLine;
  31712. var codingLine = this.codingLine;
  31713. var columns = this.columns;
  31714. var refPos, blackPixels, bits, i;
  31715. if (this.outputBits === 0) {
  31716. if (this.eof) {
  31717. return null;
  31718. }
  31719. this.err = false;
  31720. var code1, code2, code3;
  31721. if (this.nextLine2D) {
  31722. for (i = 0; codingLine[i] < columns; ++i) {
  31723. refLine[i] = codingLine[i];
  31724. }
  31725. refLine[i++] = columns;
  31726. refLine[i] = columns;
  31727. codingLine[0] = 0;
  31728. this.codingPos = 0;
  31729. refPos = 0;
  31730. blackPixels = 0;
  31731. while (codingLine[this.codingPos] < columns) {
  31732. code1 = this.getTwoDimCode();
  31733. switch (code1) {
  31734. case twoDimPass:
  31735. this.addPixels(refLine[refPos + 1], blackPixels);
  31736. if (refLine[refPos + 1] < columns) {
  31737. refPos += 2;
  31738. }
  31739. break;
  31740. case twoDimHoriz:
  31741. code1 = code2 = 0;
  31742. if (blackPixels) {
  31743. do {
  31744. code1 += (code3 = this.getBlackCode());
  31745. } while (code3 >= 64);
  31746. do {
  31747. code2 += (code3 = this.getWhiteCode());
  31748. } while (code3 >= 64);
  31749. } else {
  31750. do {
  31751. code1 += (code3 = this.getWhiteCode());
  31752. } while (code3 >= 64);
  31753. do {
  31754. code2 += (code3 = this.getBlackCode());
  31755. } while (code3 >= 64);
  31756. }
  31757. this.addPixels(codingLine[this.codingPos] +
  31758. code1, blackPixels);
  31759. if (codingLine[this.codingPos] < columns) {
  31760. this.addPixels(codingLine[this.codingPos] + code2,
  31761. blackPixels ^ 1);
  31762. }
  31763. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31764. refLine[refPos] < columns) {
  31765. refPos += 2;
  31766. }
  31767. break;
  31768. case twoDimVertR3:
  31769. this.addPixels(refLine[refPos] + 3, blackPixels);
  31770. blackPixels ^= 1;
  31771. if (codingLine[this.codingPos] < columns) {
  31772. ++refPos;
  31773. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31774. refLine[refPos] < columns) {
  31775. refPos += 2;
  31776. }
  31777. }
  31778. break;
  31779. case twoDimVertR2:
  31780. this.addPixels(refLine[refPos] + 2, blackPixels);
  31781. blackPixels ^= 1;
  31782. if (codingLine[this.codingPos] < columns) {
  31783. ++refPos;
  31784. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31785. refLine[refPos] < columns) {
  31786. refPos += 2;
  31787. }
  31788. }
  31789. break;
  31790. case twoDimVertR1:
  31791. this.addPixels(refLine[refPos] + 1, blackPixels);
  31792. blackPixels ^= 1;
  31793. if (codingLine[this.codingPos] < columns) {
  31794. ++refPos;
  31795. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31796. refLine[refPos] < columns) {
  31797. refPos += 2;
  31798. }
  31799. }
  31800. break;
  31801. case twoDimVert0:
  31802. this.addPixels(refLine[refPos], blackPixels);
  31803. blackPixels ^= 1;
  31804. if (codingLine[this.codingPos] < columns) {
  31805. ++refPos;
  31806. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31807. refLine[refPos] < columns) {
  31808. refPos += 2;
  31809. }
  31810. }
  31811. break;
  31812. case twoDimVertL3:
  31813. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31814. blackPixels ^= 1;
  31815. if (codingLine[this.codingPos] < columns) {
  31816. if (refPos > 0) {
  31817. --refPos;
  31818. } else {
  31819. ++refPos;
  31820. }
  31821. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31822. refLine[refPos] < columns) {
  31823. refPos += 2;
  31824. }
  31825. }
  31826. break;
  31827. case twoDimVertL2:
  31828. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31829. blackPixels ^= 1;
  31830. if (codingLine[this.codingPos] < columns) {
  31831. if (refPos > 0) {
  31832. --refPos;
  31833. } else {
  31834. ++refPos;
  31835. }
  31836. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31837. refLine[refPos] < columns) {
  31838. refPos += 2;
  31839. }
  31840. }
  31841. break;
  31842. case twoDimVertL1:
  31843. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31844. blackPixels ^= 1;
  31845. if (codingLine[this.codingPos] < columns) {
  31846. if (refPos > 0) {
  31847. --refPos;
  31848. } else {
  31849. ++refPos;
  31850. }
  31851. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31852. refLine[refPos] < columns) {
  31853. refPos += 2;
  31854. }
  31855. }
  31856. break;
  31857. case EOF:
  31858. this.addPixels(columns, 0);
  31859. this.eof = true;
  31860. break;
  31861. default:
  31862. info('bad 2d code');
  31863. this.addPixels(columns, 0);
  31864. this.err = true;
  31865. }
  31866. }
  31867. } else {
  31868. codingLine[0] = 0;
  31869. this.codingPos = 0;
  31870. blackPixels = 0;
  31871. while (codingLine[this.codingPos] < columns) {
  31872. code1 = 0;
  31873. if (blackPixels) {
  31874. do {
  31875. code1 += (code3 = this.getBlackCode());
  31876. } while (code3 >= 64);
  31877. } else {
  31878. do {
  31879. code1 += (code3 = this.getWhiteCode());
  31880. } while (code3 >= 64);
  31881. }
  31882. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31883. blackPixels ^= 1;
  31884. }
  31885. }
  31886. var gotEOL = false;
  31887. if (this.byteAlign) {
  31888. this.inputBits &= ~7;
  31889. }
  31890. if (!this.eoblock && this.row === this.rows - 1) {
  31891. this.eof = true;
  31892. } else {
  31893. code1 = this.lookBits(12);
  31894. if (this.eoline) {
  31895. while (code1 !== EOF && code1 !== 1) {
  31896. this.eatBits(1);
  31897. code1 = this.lookBits(12);
  31898. }
  31899. } else {
  31900. while (code1 === 0) {
  31901. this.eatBits(1);
  31902. code1 = this.lookBits(12);
  31903. }
  31904. }
  31905. if (code1 === 1) {
  31906. this.eatBits(12);
  31907. gotEOL = true;
  31908. } else if (code1 === EOF) {
  31909. this.eof = true;
  31910. }
  31911. }
  31912. if (!this.eof && this.encoding > 0) {
  31913. this.nextLine2D = !this.lookBits(1);
  31914. this.eatBits(1);
  31915. }
  31916. if (this.eoblock && gotEOL && this.byteAlign) {
  31917. code1 = this.lookBits(12);
  31918. if (code1 === 1) {
  31919. this.eatBits(12);
  31920. if (this.encoding > 0) {
  31921. this.lookBits(1);
  31922. this.eatBits(1);
  31923. }
  31924. if (this.encoding >= 0) {
  31925. for (i = 0; i < 4; ++i) {
  31926. code1 = this.lookBits(12);
  31927. if (code1 !== 1) {
  31928. info('bad rtc code: ' + code1);
  31929. }
  31930. this.eatBits(12);
  31931. if (this.encoding > 0) {
  31932. this.lookBits(1);
  31933. this.eatBits(1);
  31934. }
  31935. }
  31936. }
  31937. this.eof = true;
  31938. }
  31939. } else if (this.err && this.eoline) {
  31940. while (true) {
  31941. code1 = this.lookBits(13);
  31942. if (code1 === EOF) {
  31943. this.eof = true;
  31944. return null;
  31945. }
  31946. if ((code1 >> 1) === 1) {
  31947. break;
  31948. }
  31949. this.eatBits(1);
  31950. }
  31951. this.eatBits(12);
  31952. if (this.encoding > 0) {
  31953. this.eatBits(1);
  31954. this.nextLine2D = !(code1 & 1);
  31955. }
  31956. }
  31957. if (codingLine[0] > 0) {
  31958. this.outputBits = codingLine[this.codingPos = 0];
  31959. } else {
  31960. this.outputBits = codingLine[this.codingPos = 1];
  31961. }
  31962. this.row++;
  31963. }
  31964. var c;
  31965. if (this.outputBits >= 8) {
  31966. c = (this.codingPos & 1) ? 0 : 0xFF;
  31967. this.outputBits -= 8;
  31968. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31969. this.codingPos++;
  31970. this.outputBits = (codingLine[this.codingPos] -
  31971. codingLine[this.codingPos - 1]);
  31972. }
  31973. } else {
  31974. bits = 8;
  31975. c = 0;
  31976. do {
  31977. if (this.outputBits > bits) {
  31978. c <<= bits;
  31979. if (!(this.codingPos & 1)) {
  31980. c |= 0xFF >> (8 - bits);
  31981. }
  31982. this.outputBits -= bits;
  31983. bits = 0;
  31984. } else {
  31985. c <<= this.outputBits;
  31986. if (!(this.codingPos & 1)) {
  31987. c |= 0xFF >> (8 - this.outputBits);
  31988. }
  31989. bits -= this.outputBits;
  31990. this.outputBits = 0;
  31991. if (codingLine[this.codingPos] < columns) {
  31992. this.codingPos++;
  31993. this.outputBits = (codingLine[this.codingPos] -
  31994. codingLine[this.codingPos - 1]);
  31995. } else if (bits > 0) {
  31996. c <<= bits;
  31997. bits = 0;
  31998. }
  31999. }
  32000. } while (bits);
  32001. }
  32002. if (this.black) {
  32003. c ^= 0xFF;
  32004. }
  32005. return c;
  32006. };
  32007. // This functions returns the code found from the table.
  32008. // The start and end parameters set the boundaries for searching the table.
  32009. // The limit parameter is optional. Function returns an array with three
  32010. // values. The first array element indicates whether a valid code is being
  32011. // returned. The second array element is the actual code. The third array
  32012. // element indicates whether EOF was reached.
  32013. CCITTFaxStream.prototype.findTableCode =
  32014. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  32015. var limitValue = limit || 0;
  32016. for (var i = start; i <= end; ++i) {
  32017. var code = this.lookBits(i);
  32018. if (code === EOF) {
  32019. return [true, 1, false];
  32020. }
  32021. if (i < end) {
  32022. code <<= end - i;
  32023. }
  32024. if (!limitValue || code >= limitValue) {
  32025. var p = table[code - limitValue];
  32026. if (p[0] === i) {
  32027. this.eatBits(i);
  32028. return [true, p[1], true];
  32029. }
  32030. }
  32031. }
  32032. return [false, 0, false];
  32033. };
  32034. CCITTFaxStream.prototype.getTwoDimCode =
  32035. function ccittFaxStreamGetTwoDimCode() {
  32036. var code = 0;
  32037. var p;
  32038. if (this.eoblock) {
  32039. code = this.lookBits(7);
  32040. p = twoDimTable[code];
  32041. if (p && p[0] > 0) {
  32042. this.eatBits(p[0]);
  32043. return p[1];
  32044. }
  32045. } else {
  32046. var result = this.findTableCode(1, 7, twoDimTable);
  32047. if (result[0] && result[2]) {
  32048. return result[1];
  32049. }
  32050. }
  32051. info('Bad two dim code');
  32052. return EOF;
  32053. };
  32054. CCITTFaxStream.prototype.getWhiteCode =
  32055. function ccittFaxStreamGetWhiteCode() {
  32056. var code = 0;
  32057. var p;
  32058. if (this.eoblock) {
  32059. code = this.lookBits(12);
  32060. if (code === EOF) {
  32061. return 1;
  32062. }
  32063. if ((code >> 5) === 0) {
  32064. p = whiteTable1[code];
  32065. } else {
  32066. p = whiteTable2[code >> 3];
  32067. }
  32068. if (p[0] > 0) {
  32069. this.eatBits(p[0]);
  32070. return p[1];
  32071. }
  32072. } else {
  32073. var result = this.findTableCode(1, 9, whiteTable2);
  32074. if (result[0]) {
  32075. return result[1];
  32076. }
  32077. result = this.findTableCode(11, 12, whiteTable1);
  32078. if (result[0]) {
  32079. return result[1];
  32080. }
  32081. }
  32082. info('bad white code');
  32083. this.eatBits(1);
  32084. return 1;
  32085. };
  32086. CCITTFaxStream.prototype.getBlackCode =
  32087. function ccittFaxStreamGetBlackCode() {
  32088. var code, p;
  32089. if (this.eoblock) {
  32090. code = this.lookBits(13);
  32091. if (code === EOF) {
  32092. return 1;
  32093. }
  32094. if ((code >> 7) === 0) {
  32095. p = blackTable1[code];
  32096. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  32097. p = blackTable2[(code >> 1) - 64];
  32098. } else {
  32099. p = blackTable3[code >> 7];
  32100. }
  32101. if (p[0] > 0) {
  32102. this.eatBits(p[0]);
  32103. return p[1];
  32104. }
  32105. } else {
  32106. var result = this.findTableCode(2, 6, blackTable3);
  32107. if (result[0]) {
  32108. return result[1];
  32109. }
  32110. result = this.findTableCode(7, 12, blackTable2, 64);
  32111. if (result[0]) {
  32112. return result[1];
  32113. }
  32114. result = this.findTableCode(10, 13, blackTable1);
  32115. if (result[0]) {
  32116. return result[1];
  32117. }
  32118. }
  32119. info('bad black code');
  32120. this.eatBits(1);
  32121. return 1;
  32122. };
  32123. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  32124. var c;
  32125. while (this.inputBits < n) {
  32126. if ((c = this.str.getByte()) === -1) {
  32127. if (this.inputBits === 0) {
  32128. return EOF;
  32129. }
  32130. return ((this.inputBuf << (n - this.inputBits)) &
  32131. (0xFFFF >> (16 - n)));
  32132. }
  32133. this.inputBuf = (this.inputBuf << 8) + c;
  32134. this.inputBits += 8;
  32135. }
  32136. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  32137. };
  32138. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32139. if ((this.inputBits -= n) < 0) {
  32140. this.inputBits = 0;
  32141. }
  32142. };
  32143. return CCITTFaxStream;
  32144. })();
  32145. var LZWStream = (function LZWStreamClosure() {
  32146. function LZWStream(str, maybeLength, earlyChange) {
  32147. this.str = str;
  32148. this.dict = str.dict;
  32149. this.cachedData = 0;
  32150. this.bitsCached = 0;
  32151. var maxLzwDictionarySize = 4096;
  32152. var lzwState = {
  32153. earlyChange: earlyChange,
  32154. codeLength: 9,
  32155. nextCode: 258,
  32156. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32157. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32158. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32159. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32160. currentSequenceLength: 0
  32161. };
  32162. for (var i = 0; i < 256; ++i) {
  32163. lzwState.dictionaryValues[i] = i;
  32164. lzwState.dictionaryLengths[i] = 1;
  32165. }
  32166. this.lzwState = lzwState;
  32167. DecodeStream.call(this, maybeLength);
  32168. }
  32169. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32170. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32171. var bitsCached = this.bitsCached;
  32172. var cachedData = this.cachedData;
  32173. while (bitsCached < n) {
  32174. var c = this.str.getByte();
  32175. if (c === -1) {
  32176. this.eof = true;
  32177. return null;
  32178. }
  32179. cachedData = (cachedData << 8) | c;
  32180. bitsCached += 8;
  32181. }
  32182. this.bitsCached = (bitsCached -= n);
  32183. this.cachedData = cachedData;
  32184. this.lastCode = null;
  32185. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  32186. };
  32187. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32188. var blockSize = 512;
  32189. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32190. var i, j, q;
  32191. var lzwState = this.lzwState;
  32192. if (!lzwState) {
  32193. return; // eof was found
  32194. }
  32195. var earlyChange = lzwState.earlyChange;
  32196. var nextCode = lzwState.nextCode;
  32197. var dictionaryValues = lzwState.dictionaryValues;
  32198. var dictionaryLengths = lzwState.dictionaryLengths;
  32199. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32200. var codeLength = lzwState.codeLength;
  32201. var prevCode = lzwState.prevCode;
  32202. var currentSequence = lzwState.currentSequence;
  32203. var currentSequenceLength = lzwState.currentSequenceLength;
  32204. var decodedLength = 0;
  32205. var currentBufferLength = this.bufferLength;
  32206. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32207. for (i = 0; i < blockSize; i++) {
  32208. var code = this.readBits(codeLength);
  32209. var hasPrev = currentSequenceLength > 0;
  32210. if (code < 256) {
  32211. currentSequence[0] = code;
  32212. currentSequenceLength = 1;
  32213. } else if (code >= 258) {
  32214. if (code < nextCode) {
  32215. currentSequenceLength = dictionaryLengths[code];
  32216. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32217. currentSequence[j] = dictionaryValues[q];
  32218. q = dictionaryPrevCodes[q];
  32219. }
  32220. } else {
  32221. currentSequence[currentSequenceLength++] = currentSequence[0];
  32222. }
  32223. } else if (code === 256) {
  32224. codeLength = 9;
  32225. nextCode = 258;
  32226. currentSequenceLength = 0;
  32227. continue;
  32228. } else {
  32229. this.eof = true;
  32230. delete this.lzwState;
  32231. break;
  32232. }
  32233. if (hasPrev) {
  32234. dictionaryPrevCodes[nextCode] = prevCode;
  32235. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32236. dictionaryValues[nextCode] = currentSequence[0];
  32237. nextCode++;
  32238. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  32239. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  32240. 0.6931471805599453 + 1, 12) | 0;
  32241. }
  32242. prevCode = code;
  32243. decodedLength += currentSequenceLength;
  32244. if (estimatedDecodedSize < decodedLength) {
  32245. do {
  32246. estimatedDecodedSize += decodedSizeDelta;
  32247. } while (estimatedDecodedSize < decodedLength);
  32248. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32249. }
  32250. for (j = 0; j < currentSequenceLength; j++) {
  32251. buffer[currentBufferLength++] = currentSequence[j];
  32252. }
  32253. }
  32254. lzwState.nextCode = nextCode;
  32255. lzwState.codeLength = codeLength;
  32256. lzwState.prevCode = prevCode;
  32257. lzwState.currentSequenceLength = currentSequenceLength;
  32258. this.bufferLength = currentBufferLength;
  32259. };
  32260. return LZWStream;
  32261. })();
  32262. var NullStream = (function NullStreamClosure() {
  32263. function NullStream() {
  32264. Stream.call(this, new Uint8Array(0));
  32265. }
  32266. NullStream.prototype = Stream.prototype;
  32267. return NullStream;
  32268. })();
  32269. var WorkerTask = (function WorkerTaskClosure() {
  32270. function WorkerTask(name) {
  32271. this.name = name;
  32272. this.terminated = false;
  32273. this._capability = createPromiseCapability();
  32274. }
  32275. WorkerTask.prototype = {
  32276. get finished() {
  32277. return this._capability.promise;
  32278. },
  32279. finish: function () {
  32280. this._capability.resolve();
  32281. },
  32282. terminate: function () {
  32283. this.terminated = true;
  32284. },
  32285. ensureNotTerminated: function () {
  32286. if (this.terminated) {
  32287. throw new Error('Worker task was terminated');
  32288. }
  32289. }
  32290. };
  32291. return WorkerTask;
  32292. })();
  32293. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  32294. setup: function wphSetup(handler) {
  32295. var pdfManager;
  32296. var terminated = false;
  32297. var cancelXHRs = null;
  32298. var WorkerTasks = [];
  32299. function ensureNotTerminated() {
  32300. if (terminated) {
  32301. throw new Error('Worker was terminated');
  32302. }
  32303. }
  32304. function startWorkerTask(task) {
  32305. WorkerTasks.push(task);
  32306. }
  32307. function finishWorkerTask(task) {
  32308. task.finish();
  32309. var i = WorkerTasks.indexOf(task);
  32310. WorkerTasks.splice(i, 1);
  32311. }
  32312. function loadDocument(recoveryMode) {
  32313. var loadDocumentCapability = createPromiseCapability();
  32314. var parseSuccess = function parseSuccess() {
  32315. var numPagesPromise = pdfManager.ensureDoc('numPages');
  32316. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  32317. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  32318. Promise.all([numPagesPromise, fingerprintPromise,
  32319. encryptedPromise]).then(function onDocReady(results) {
  32320. var doc = {
  32321. numPages: results[0],
  32322. fingerprint: results[1],
  32323. encrypted: !!results[2],
  32324. };
  32325. loadDocumentCapability.resolve(doc);
  32326. },
  32327. parseFailure);
  32328. };
  32329. var parseFailure = function parseFailure(e) {
  32330. loadDocumentCapability.reject(e);
  32331. };
  32332. pdfManager.ensureDoc('checkHeader', []).then(function() {
  32333. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  32334. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  32335. parseSuccess, parseFailure);
  32336. }, parseFailure);
  32337. }, parseFailure);
  32338. return loadDocumentCapability.promise;
  32339. }
  32340. function getPdfManager(data) {
  32341. var pdfManagerCapability = createPromiseCapability();
  32342. var pdfManager;
  32343. var source = data.source;
  32344. var disableRange = data.disableRange;
  32345. if (source.data) {
  32346. try {
  32347. pdfManager = new LocalPdfManager(source.data, source.password);
  32348. pdfManagerCapability.resolve(pdfManager);
  32349. } catch (ex) {
  32350. pdfManagerCapability.reject(ex);
  32351. }
  32352. return pdfManagerCapability.promise;
  32353. } else if (source.chunkedViewerLoading) {
  32354. try {
  32355. pdfManager = new NetworkPdfManager(source, handler);
  32356. pdfManagerCapability.resolve(pdfManager);
  32357. } catch (ex) {
  32358. pdfManagerCapability.reject(ex);
  32359. }
  32360. return pdfManagerCapability.promise;
  32361. }
  32362. var networkManager = new NetworkManager(source.url, {
  32363. httpHeaders: source.httpHeaders,
  32364. withCredentials: source.withCredentials
  32365. });
  32366. var cachedChunks = [];
  32367. var fullRequestXhrId = networkManager.requestFull({
  32368. onHeadersReceived: function onHeadersReceived() {
  32369. if (disableRange) {
  32370. return;
  32371. }
  32372. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  32373. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  32374. return;
  32375. }
  32376. var contentEncoding =
  32377. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  32378. if (contentEncoding !== 'identity') {
  32379. return;
  32380. }
  32381. var length = fullRequestXhr.getResponseHeader('Content-Length');
  32382. length = parseInt(length, 10);
  32383. if (!isInt(length)) {
  32384. return;
  32385. }
  32386. source.length = length;
  32387. if (length <= 2 * source.rangeChunkSize) {
  32388. // The file size is smaller than the size of two chunks, so it does
  32389. // not make any sense to abort the request and retry with a range
  32390. // request.
  32391. return;
  32392. }
  32393. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  32394. // We can continue fetching when progressive loading is enabled,
  32395. // and we don't need the autoFetch feature.
  32396. source.disableAutoFetch = true;
  32397. } else {
  32398. // NOTE: by cancelling the full request, and then issuing range
  32399. // requests, there will be an issue for sites where you can only
  32400. // request the pdf once. However, if this is the case, then the
  32401. // server should not be returning that it can support range
  32402. // requests.
  32403. networkManager.abortRequest(fullRequestXhrId);
  32404. }
  32405. try {
  32406. pdfManager = new NetworkPdfManager(source, handler);
  32407. pdfManagerCapability.resolve(pdfManager);
  32408. } catch (ex) {
  32409. pdfManagerCapability.reject(ex);
  32410. }
  32411. cancelXHRs = null;
  32412. },
  32413. onProgressiveData: source.disableStream ? null :
  32414. function onProgressiveData(chunk) {
  32415. if (!pdfManager) {
  32416. cachedChunks.push(chunk);
  32417. return;
  32418. }
  32419. pdfManager.sendProgressiveData(chunk);
  32420. },
  32421. onDone: function onDone(args) {
  32422. if (pdfManager) {
  32423. return; // already processed
  32424. }
  32425. var pdfFile;
  32426. if (args === null) {
  32427. // TODO add some streaming manager, e.g. for unknown length files.
  32428. // The data was returned in the onProgressiveData, combining...
  32429. var pdfFileLength = 0, pos = 0;
  32430. cachedChunks.forEach(function (chunk) {
  32431. pdfFileLength += chunk.byteLength;
  32432. });
  32433. if (source.length && pdfFileLength !== source.length) {
  32434. warn('reported HTTP length is different from actual');
  32435. }
  32436. var pdfFileArray = new Uint8Array(pdfFileLength);
  32437. cachedChunks.forEach(function (chunk) {
  32438. pdfFileArray.set(new Uint8Array(chunk), pos);
  32439. pos += chunk.byteLength;
  32440. });
  32441. pdfFile = pdfFileArray.buffer;
  32442. } else {
  32443. pdfFile = args.chunk;
  32444. }
  32445. // the data is array, instantiating directly from it
  32446. try {
  32447. pdfManager = new LocalPdfManager(pdfFile, source.password);
  32448. pdfManagerCapability.resolve(pdfManager);
  32449. } catch (ex) {
  32450. pdfManagerCapability.reject(ex);
  32451. }
  32452. cancelXHRs = null;
  32453. },
  32454. onError: function onError(status) {
  32455. var exception;
  32456. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  32457. exception = new MissingPDFException('Missing PDF "' +
  32458. source.url + '".');
  32459. handler.send('MissingPDF', exception);
  32460. } else {
  32461. exception = new UnexpectedResponseException(
  32462. 'Unexpected server response (' + status +
  32463. ') while retrieving PDF "' + source.url + '".', status);
  32464. handler.send('UnexpectedResponse', exception);
  32465. }
  32466. cancelXHRs = null;
  32467. },
  32468. onProgress: function onProgress(evt) {
  32469. handler.send('DocProgress', {
  32470. loaded: evt.loaded,
  32471. total: evt.lengthComputable ? evt.total : source.length
  32472. });
  32473. }
  32474. });
  32475. cancelXHRs = function () {
  32476. networkManager.abortRequest(fullRequestXhrId);
  32477. };
  32478. return pdfManagerCapability.promise;
  32479. }
  32480. handler.on('test', function wphSetupTest(data) {
  32481. // check if Uint8Array can be sent to worker
  32482. if (!(data instanceof Uint8Array)) {
  32483. handler.send('test', false);
  32484. return;
  32485. }
  32486. // making sure postMessage transfers are working
  32487. var supportTransfers = data[0] === 255;
  32488. handler.postMessageTransfers = supportTransfers;
  32489. // check if the response property is supported by xhr
  32490. var xhr = new XMLHttpRequest();
  32491. var responseExists = 'response' in xhr;
  32492. // check if the property is actually implemented
  32493. try {
  32494. var dummy = xhr.responseType;
  32495. } catch (e) {
  32496. responseExists = false;
  32497. }
  32498. if (!responseExists) {
  32499. handler.send('test', false);
  32500. return;
  32501. }
  32502. handler.send('test', {
  32503. supportTypedArray: true,
  32504. supportTransfers: supportTransfers
  32505. });
  32506. });
  32507. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32508. var onSuccess = function(doc) {
  32509. ensureNotTerminated();
  32510. handler.send('GetDoc', { pdfInfo: doc });
  32511. };
  32512. var onFailure = function(e) {
  32513. if (e instanceof PasswordException) {
  32514. if (e.code === PasswordResponses.NEED_PASSWORD) {
  32515. handler.send('NeedPassword', e);
  32516. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  32517. handler.send('IncorrectPassword', e);
  32518. }
  32519. } else if (e instanceof InvalidPDFException) {
  32520. handler.send('InvalidPDF', e);
  32521. } else if (e instanceof MissingPDFException) {
  32522. handler.send('MissingPDF', e);
  32523. } else if (e instanceof UnexpectedResponseException) {
  32524. handler.send('UnexpectedResponse', e);
  32525. } else {
  32526. handler.send('UnknownError',
  32527. new UnknownErrorException(e.message, e.toString()));
  32528. }
  32529. };
  32530. ensureNotTerminated();
  32531. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  32532. -1 : data.maxImageSize;
  32533. PDFJS.disableFontFace = data.disableFontFace;
  32534. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  32535. PDFJS.verbosity = data.verbosity;
  32536. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  32537. null : data.cMapUrl;
  32538. PDFJS.cMapPacked = data.cMapPacked === true;
  32539. getPdfManager(data).then(function (newPdfManager) {
  32540. if (terminated) {
  32541. // We were in a process of setting up the manager, but it got
  32542. // terminated in the middle.
  32543. newPdfManager.terminate();
  32544. throw new Error('Worker was terminated');
  32545. }
  32546. pdfManager = newPdfManager;
  32547. handler.send('PDFManagerReady', null);
  32548. pdfManager.onLoadedStream().then(function(stream) {
  32549. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  32550. });
  32551. }).then(function pdfManagerReady() {
  32552. ensureNotTerminated();
  32553. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32554. ensureNotTerminated();
  32555. // Try again with recoveryMode == true
  32556. if (!(ex instanceof XRefParseException)) {
  32557. if (ex instanceof PasswordException) {
  32558. // after password exception prepare to receive a new password
  32559. // to repeat loading
  32560. pdfManager.passwordChanged().then(pdfManagerReady);
  32561. }
  32562. onFailure(ex);
  32563. return;
  32564. }
  32565. pdfManager.requestLoadedStream();
  32566. pdfManager.onLoadedStream().then(function() {
  32567. ensureNotTerminated();
  32568. loadDocument(true).then(onSuccess, onFailure);
  32569. });
  32570. }, onFailure);
  32571. }, onFailure);
  32572. });
  32573. handler.on('GetPage', function wphSetupGetPage(data) {
  32574. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32575. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32576. var refPromise = pdfManager.ensure(page, 'ref');
  32577. var viewPromise = pdfManager.ensure(page, 'view');
  32578. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32579. function(results) {
  32580. return {
  32581. rotate: results[0],
  32582. ref: results[1],
  32583. view: results[2]
  32584. };
  32585. });
  32586. });
  32587. });
  32588. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32589. var ref = new Ref(data.ref.num, data.ref.gen);
  32590. var catalog = pdfManager.pdfDocument.catalog;
  32591. return catalog.getPageIndex(ref);
  32592. });
  32593. handler.on('GetDestinations',
  32594. function wphSetupGetDestinations(data) {
  32595. return pdfManager.ensureCatalog('destinations');
  32596. }
  32597. );
  32598. handler.on('GetDestination',
  32599. function wphSetupGetDestination(data) {
  32600. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32601. }
  32602. );
  32603. handler.on('GetAttachments',
  32604. function wphSetupGetAttachments(data) {
  32605. return pdfManager.ensureCatalog('attachments');
  32606. }
  32607. );
  32608. handler.on('GetJavaScript',
  32609. function wphSetupGetJavaScript(data) {
  32610. return pdfManager.ensureCatalog('javaScript');
  32611. }
  32612. );
  32613. handler.on('GetOutline',
  32614. function wphSetupGetOutline(data) {
  32615. return pdfManager.ensureCatalog('documentOutline');
  32616. }
  32617. );
  32618. handler.on('GetMetadata',
  32619. function wphSetupGetMetadata(data) {
  32620. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32621. pdfManager.ensureCatalog('metadata')]);
  32622. }
  32623. );
  32624. handler.on('GetData', function wphSetupGetData(data) {
  32625. pdfManager.requestLoadedStream();
  32626. return pdfManager.onLoadedStream().then(function(stream) {
  32627. return stream.bytes;
  32628. });
  32629. });
  32630. handler.on('GetStats',
  32631. function wphSetupGetStats(data) {
  32632. return pdfManager.pdfDocument.xref.stats;
  32633. }
  32634. );
  32635. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32636. pdfManager.updatePassword(data);
  32637. });
  32638. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32639. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32640. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32641. });
  32642. });
  32643. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32644. var pageIndex = data.pageIndex;
  32645. pdfManager.getPage(pageIndex).then(function(page) {
  32646. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  32647. startWorkerTask(task);
  32648. var pageNum = pageIndex + 1;
  32649. var start = Date.now();
  32650. // Pre compile the pdf page and fetch the fonts/images.
  32651. page.getOperatorList(handler, task, data.intent).then(
  32652. function(operatorList) {
  32653. finishWorkerTask(task);
  32654. info('page=' + pageNum + ' - getOperatorList: time=' +
  32655. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  32656. }, function(e) {
  32657. finishWorkerTask(task);
  32658. if (task.terminated) {
  32659. return; // ignoring errors from the terminated thread
  32660. }
  32661. var minimumStackMessage =
  32662. 'worker.js: while trying to getPage() and getOperatorList()';
  32663. var wrappedException;
  32664. // Turn the error into an obj that can be serialized
  32665. if (typeof e === 'string') {
  32666. wrappedException = {
  32667. message: e,
  32668. stack: minimumStackMessage
  32669. };
  32670. } else if (typeof e === 'object') {
  32671. wrappedException = {
  32672. message: e.message || e.toString(),
  32673. stack: e.stack || minimumStackMessage
  32674. };
  32675. } else {
  32676. wrappedException = {
  32677. message: 'Unknown exception type: ' + (typeof e),
  32678. stack: minimumStackMessage
  32679. };
  32680. }
  32681. handler.send('PageError', {
  32682. pageNum: pageNum,
  32683. error: wrappedException,
  32684. intent: data.intent
  32685. });
  32686. });
  32687. });
  32688. }, this);
  32689. handler.on('GetTextContent', function wphExtractText(data) {
  32690. var pageIndex = data.pageIndex;
  32691. return pdfManager.getPage(pageIndex).then(function(page) {
  32692. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  32693. startWorkerTask(task);
  32694. var pageNum = pageIndex + 1;
  32695. var start = Date.now();
  32696. return page.extractTextContent(task).then(function(textContent) {
  32697. finishWorkerTask(task);
  32698. info('text indexing: page=' + pageNum + ' - time=' +
  32699. (Date.now() - start) + 'ms');
  32700. return textContent;
  32701. }, function (reason) {
  32702. finishWorkerTask(task);
  32703. if (task.terminated) {
  32704. return; // ignoring errors from the terminated thread
  32705. }
  32706. throw reason;
  32707. });
  32708. });
  32709. });
  32710. handler.on('Cleanup', function wphCleanup(data) {
  32711. return pdfManager.cleanup();
  32712. });
  32713. handler.on('Terminate', function wphTerminate(data) {
  32714. terminated = true;
  32715. if (pdfManager) {
  32716. pdfManager.terminate();
  32717. pdfManager = null;
  32718. }
  32719. if (cancelXHRs) {
  32720. cancelXHRs();
  32721. }
  32722. var waitOn = [];
  32723. WorkerTasks.forEach(function (task) {
  32724. waitOn.push(task.finished);
  32725. task.terminate();
  32726. });
  32727. return Promise.all(waitOn).then(function () {});
  32728. });
  32729. }
  32730. };
  32731. var consoleTimer = {};
  32732. var workerConsole = {
  32733. log: function log() {
  32734. var args = Array.prototype.slice.call(arguments);
  32735. globalScope.postMessage({
  32736. action: 'console_log',
  32737. data: args
  32738. });
  32739. },
  32740. error: function error() {
  32741. var args = Array.prototype.slice.call(arguments);
  32742. globalScope.postMessage({
  32743. action: 'console_error',
  32744. data: args
  32745. });
  32746. throw 'pdf.js execution error';
  32747. },
  32748. time: function time(name) {
  32749. consoleTimer[name] = Date.now();
  32750. },
  32751. timeEnd: function timeEnd(name) {
  32752. var time = consoleTimer[name];
  32753. if (!time) {
  32754. error('Unknown timer name ' + name);
  32755. }
  32756. this.log('Timer:', name, Date.now() - time);
  32757. }
  32758. };
  32759. // Worker thread?
  32760. if (typeof window === 'undefined') {
  32761. if (!('console' in globalScope)) {
  32762. globalScope.console = workerConsole;
  32763. }
  32764. // Listen for unsupported features so we can pass them on to the main thread.
  32765. PDFJS.UnsupportedManager.listen(function (msg) {
  32766. globalScope.postMessage({
  32767. action: '_unsupported_feature',
  32768. data: msg
  32769. });
  32770. });
  32771. var handler = new MessageHandler('worker_processor', this);
  32772. WorkerMessageHandler.setup(handler);
  32773. }
  32774. /* This class implements the QM Coder decoding as defined in
  32775. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32776. * Annex C.3 Arithmetic decoding procedure
  32777. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32778. *
  32779. * The arithmetic decoder is used in conjunction with context models to decode
  32780. * JPEG2000 and JBIG2 streams.
  32781. */
  32782. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32783. // Table C-2
  32784. var QeTable = [
  32785. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32786. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32787. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32788. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32789. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32790. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32791. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32792. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32793. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32794. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32795. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32796. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32797. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32798. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32799. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32800. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32801. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32802. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32803. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32804. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32805. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32806. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32807. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32808. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32809. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32810. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32811. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32812. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32813. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32814. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32815. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32816. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32817. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32818. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32819. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32820. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32821. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32822. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32823. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32824. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32825. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32826. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32827. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32828. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32829. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32830. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32831. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32832. ];
  32833. // C.3.5 Initialisation of the decoder (INITDEC)
  32834. function ArithmeticDecoder(data, start, end) {
  32835. this.data = data;
  32836. this.bp = start;
  32837. this.dataEnd = end;
  32838. this.chigh = data[start];
  32839. this.clow = 0;
  32840. this.byteIn();
  32841. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32842. this.clow = (this.clow << 7) & 0xFFFF;
  32843. this.ct -= 7;
  32844. this.a = 0x8000;
  32845. }
  32846. ArithmeticDecoder.prototype = {
  32847. // C.3.4 Compressed data input (BYTEIN)
  32848. byteIn: function ArithmeticDecoder_byteIn() {
  32849. var data = this.data;
  32850. var bp = this.bp;
  32851. if (data[bp] === 0xFF) {
  32852. var b1 = data[bp + 1];
  32853. if (b1 > 0x8F) {
  32854. this.clow += 0xFF00;
  32855. this.ct = 8;
  32856. } else {
  32857. bp++;
  32858. this.clow += (data[bp] << 9);
  32859. this.ct = 7;
  32860. this.bp = bp;
  32861. }
  32862. } else {
  32863. bp++;
  32864. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32865. this.ct = 8;
  32866. this.bp = bp;
  32867. }
  32868. if (this.clow > 0xFFFF) {
  32869. this.chigh += (this.clow >> 16);
  32870. this.clow &= 0xFFFF;
  32871. }
  32872. },
  32873. // C.3.2 Decoding a decision (DECODE)
  32874. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32875. // contexts are packed into 1 byte:
  32876. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32877. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32878. var qeTableIcx = QeTable[cx_index];
  32879. var qeIcx = qeTableIcx.qe;
  32880. var d;
  32881. var a = this.a - qeIcx;
  32882. if (this.chigh < qeIcx) {
  32883. // exchangeLps
  32884. if (a < qeIcx) {
  32885. a = qeIcx;
  32886. d = cx_mps;
  32887. cx_index = qeTableIcx.nmps;
  32888. } else {
  32889. a = qeIcx;
  32890. d = 1 ^ cx_mps;
  32891. if (qeTableIcx.switchFlag === 1) {
  32892. cx_mps = d;
  32893. }
  32894. cx_index = qeTableIcx.nlps;
  32895. }
  32896. } else {
  32897. this.chigh -= qeIcx;
  32898. if ((a & 0x8000) !== 0) {
  32899. this.a = a;
  32900. return cx_mps;
  32901. }
  32902. // exchangeMps
  32903. if (a < qeIcx) {
  32904. d = 1 ^ cx_mps;
  32905. if (qeTableIcx.switchFlag === 1) {
  32906. cx_mps = d;
  32907. }
  32908. cx_index = qeTableIcx.nlps;
  32909. } else {
  32910. d = cx_mps;
  32911. cx_index = qeTableIcx.nmps;
  32912. }
  32913. }
  32914. // C.3.3 renormD;
  32915. do {
  32916. if (this.ct === 0) {
  32917. this.byteIn();
  32918. }
  32919. a <<= 1;
  32920. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32921. this.clow = (this.clow << 1) & 0xFFFF;
  32922. this.ct--;
  32923. } while ((a & 0x8000) === 0);
  32924. this.a = a;
  32925. contexts[pos] = cx_index << 1 | cx_mps;
  32926. return d;
  32927. }
  32928. };
  32929. return ArithmeticDecoder;
  32930. })();
  32931. var JpegImage = (function jpegImage() {
  32932. var dctZigZag = new Uint8Array([
  32933. 0,
  32934. 1, 8,
  32935. 16, 9, 2,
  32936. 3, 10, 17, 24,
  32937. 32, 25, 18, 11, 4,
  32938. 5, 12, 19, 26, 33, 40,
  32939. 48, 41, 34, 27, 20, 13, 6,
  32940. 7, 14, 21, 28, 35, 42, 49, 56,
  32941. 57, 50, 43, 36, 29, 22, 15,
  32942. 23, 30, 37, 44, 51, 58,
  32943. 59, 52, 45, 38, 31,
  32944. 39, 46, 53, 60,
  32945. 61, 54, 47,
  32946. 55, 62,
  32947. 63
  32948. ]);
  32949. var dctCos1 = 4017; // cos(pi/16)
  32950. var dctSin1 = 799; // sin(pi/16)
  32951. var dctCos3 = 3406; // cos(3*pi/16)
  32952. var dctSin3 = 2276; // sin(3*pi/16)
  32953. var dctCos6 = 1567; // cos(6*pi/16)
  32954. var dctSin6 = 3784; // sin(6*pi/16)
  32955. var dctSqrt2 = 5793; // sqrt(2)
  32956. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32957. function constructor() {
  32958. }
  32959. function buildHuffmanTable(codeLengths, values) {
  32960. var k = 0, code = [], i, j, length = 16;
  32961. while (length > 0 && !codeLengths[length - 1]) {
  32962. length--;
  32963. }
  32964. code.push({children: [], index: 0});
  32965. var p = code[0], q;
  32966. for (i = 0; i < length; i++) {
  32967. for (j = 0; j < codeLengths[i]; j++) {
  32968. p = code.pop();
  32969. p.children[p.index] = values[k];
  32970. while (p.index > 0) {
  32971. p = code.pop();
  32972. }
  32973. p.index++;
  32974. code.push(p);
  32975. while (code.length <= i) {
  32976. code.push(q = {children: [], index: 0});
  32977. p.children[p.index] = q.children;
  32978. p = q;
  32979. }
  32980. k++;
  32981. }
  32982. if (i + 1 < length) {
  32983. // p here points to last code
  32984. code.push(q = {children: [], index: 0});
  32985. p.children[p.index] = q.children;
  32986. p = q;
  32987. }
  32988. }
  32989. return code[0].children;
  32990. }
  32991. function getBlockBufferOffset(component, row, col) {
  32992. return 64 * ((component.blocksPerLine + 1) * row + col);
  32993. }
  32994. function decodeScan(data, offset, frame, components, resetInterval,
  32995. spectralStart, spectralEnd, successivePrev, successive) {
  32996. var precision = frame.precision;
  32997. var samplesPerLine = frame.samplesPerLine;
  32998. var scanLines = frame.scanLines;
  32999. var mcusPerLine = frame.mcusPerLine;
  33000. var progressive = frame.progressive;
  33001. var maxH = frame.maxH, maxV = frame.maxV;
  33002. var startOffset = offset, bitsData = 0, bitsCount = 0;
  33003. function readBit() {
  33004. if (bitsCount > 0) {
  33005. bitsCount--;
  33006. return (bitsData >> bitsCount) & 1;
  33007. }
  33008. bitsData = data[offset++];
  33009. if (bitsData === 0xFF) {
  33010. var nextByte = data[offset++];
  33011. if (nextByte) {
  33012. throw 'unexpected marker: ' +
  33013. ((bitsData << 8) | nextByte).toString(16);
  33014. }
  33015. // unstuff 0
  33016. }
  33017. bitsCount = 7;
  33018. return bitsData >>> 7;
  33019. }
  33020. function decodeHuffman(tree) {
  33021. var node = tree;
  33022. while (true) {
  33023. node = node[readBit()];
  33024. if (typeof node === 'number') {
  33025. return node;
  33026. }
  33027. if (typeof node !== 'object') {
  33028. throw 'invalid huffman sequence';
  33029. }
  33030. }
  33031. }
  33032. function receive(length) {
  33033. var n = 0;
  33034. while (length > 0) {
  33035. n = (n << 1) | readBit();
  33036. length--;
  33037. }
  33038. return n;
  33039. }
  33040. function receiveAndExtend(length) {
  33041. if (length === 1) {
  33042. return readBit() === 1 ? 1 : -1;
  33043. }
  33044. var n = receive(length);
  33045. if (n >= 1 << (length - 1)) {
  33046. return n;
  33047. }
  33048. return n + (-1 << length) + 1;
  33049. }
  33050. function decodeBaseline(component, offset) {
  33051. var t = decodeHuffman(component.huffmanTableDC);
  33052. var diff = t === 0 ? 0 : receiveAndExtend(t);
  33053. component.blockData[offset] = (component.pred += diff);
  33054. var k = 1;
  33055. while (k < 64) {
  33056. var rs = decodeHuffman(component.huffmanTableAC);
  33057. var s = rs & 15, r = rs >> 4;
  33058. if (s === 0) {
  33059. if (r < 15) {
  33060. break;
  33061. }
  33062. k += 16;
  33063. continue;
  33064. }
  33065. k += r;
  33066. var z = dctZigZag[k];
  33067. component.blockData[offset + z] = receiveAndExtend(s);
  33068. k++;
  33069. }
  33070. }
  33071. function decodeDCFirst(component, offset) {
  33072. var t = decodeHuffman(component.huffmanTableDC);
  33073. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  33074. component.blockData[offset] = (component.pred += diff);
  33075. }
  33076. function decodeDCSuccessive(component, offset) {
  33077. component.blockData[offset] |= readBit() << successive;
  33078. }
  33079. var eobrun = 0;
  33080. function decodeACFirst(component, offset) {
  33081. if (eobrun > 0) {
  33082. eobrun--;
  33083. return;
  33084. }
  33085. var k = spectralStart, e = spectralEnd;
  33086. while (k <= e) {
  33087. var rs = decodeHuffman(component.huffmanTableAC);
  33088. var s = rs & 15, r = rs >> 4;
  33089. if (s === 0) {
  33090. if (r < 15) {
  33091. eobrun = receive(r) + (1 << r) - 1;
  33092. break;
  33093. }
  33094. k += 16;
  33095. continue;
  33096. }
  33097. k += r;
  33098. var z = dctZigZag[k];
  33099. component.blockData[offset + z] =
  33100. receiveAndExtend(s) * (1 << successive);
  33101. k++;
  33102. }
  33103. }
  33104. var successiveACState = 0, successiveACNextValue;
  33105. function decodeACSuccessive(component, offset) {
  33106. var k = spectralStart;
  33107. var e = spectralEnd;
  33108. var r = 0;
  33109. var s;
  33110. var rs;
  33111. while (k <= e) {
  33112. var z = dctZigZag[k];
  33113. switch (successiveACState) {
  33114. case 0: // initial state
  33115. rs = decodeHuffman(component.huffmanTableAC);
  33116. s = rs & 15;
  33117. r = rs >> 4;
  33118. if (s === 0) {
  33119. if (r < 15) {
  33120. eobrun = receive(r) + (1 << r);
  33121. successiveACState = 4;
  33122. } else {
  33123. r = 16;
  33124. successiveACState = 1;
  33125. }
  33126. } else {
  33127. if (s !== 1) {
  33128. throw 'invalid ACn encoding';
  33129. }
  33130. successiveACNextValue = receiveAndExtend(s);
  33131. successiveACState = r ? 2 : 3;
  33132. }
  33133. continue;
  33134. case 1: // skipping r zero items
  33135. case 2:
  33136. if (component.blockData[offset + z]) {
  33137. component.blockData[offset + z] += (readBit() << successive);
  33138. } else {
  33139. r--;
  33140. if (r === 0) {
  33141. successiveACState = successiveACState === 2 ? 3 : 0;
  33142. }
  33143. }
  33144. break;
  33145. case 3: // set value for a zero item
  33146. if (component.blockData[offset + z]) {
  33147. component.blockData[offset + z] += (readBit() << successive);
  33148. } else {
  33149. component.blockData[offset + z] =
  33150. successiveACNextValue << successive;
  33151. successiveACState = 0;
  33152. }
  33153. break;
  33154. case 4: // eob
  33155. if (component.blockData[offset + z]) {
  33156. component.blockData[offset + z] += (readBit() << successive);
  33157. }
  33158. break;
  33159. }
  33160. k++;
  33161. }
  33162. if (successiveACState === 4) {
  33163. eobrun--;
  33164. if (eobrun === 0) {
  33165. successiveACState = 0;
  33166. }
  33167. }
  33168. }
  33169. function decodeMcu(component, decode, mcu, row, col) {
  33170. var mcuRow = (mcu / mcusPerLine) | 0;
  33171. var mcuCol = mcu % mcusPerLine;
  33172. var blockRow = mcuRow * component.v + row;
  33173. var blockCol = mcuCol * component.h + col;
  33174. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33175. decode(component, offset);
  33176. }
  33177. function decodeBlock(component, decode, mcu) {
  33178. var blockRow = (mcu / component.blocksPerLine) | 0;
  33179. var blockCol = mcu % component.blocksPerLine;
  33180. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33181. decode(component, offset);
  33182. }
  33183. var componentsLength = components.length;
  33184. var component, i, j, k, n;
  33185. var decodeFn;
  33186. if (progressive) {
  33187. if (spectralStart === 0) {
  33188. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  33189. } else {
  33190. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  33191. }
  33192. } else {
  33193. decodeFn = decodeBaseline;
  33194. }
  33195. var mcu = 0, marker;
  33196. var mcuExpected;
  33197. if (componentsLength === 1) {
  33198. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  33199. } else {
  33200. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  33201. }
  33202. if (!resetInterval) {
  33203. resetInterval = mcuExpected;
  33204. }
  33205. var h, v;
  33206. while (mcu < mcuExpected) {
  33207. // reset interval stuff
  33208. for (i = 0; i < componentsLength; i++) {
  33209. components[i].pred = 0;
  33210. }
  33211. eobrun = 0;
  33212. if (componentsLength === 1) {
  33213. component = components[0];
  33214. for (n = 0; n < resetInterval; n++) {
  33215. decodeBlock(component, decodeFn, mcu);
  33216. mcu++;
  33217. }
  33218. } else {
  33219. for (n = 0; n < resetInterval; n++) {
  33220. for (i = 0; i < componentsLength; i++) {
  33221. component = components[i];
  33222. h = component.h;
  33223. v = component.v;
  33224. for (j = 0; j < v; j++) {
  33225. for (k = 0; k < h; k++) {
  33226. decodeMcu(component, decodeFn, mcu, j, k);
  33227. }
  33228. }
  33229. }
  33230. mcu++;
  33231. }
  33232. }
  33233. // find marker
  33234. bitsCount = 0;
  33235. marker = (data[offset] << 8) | data[offset + 1];
  33236. if (marker <= 0xFF00) {
  33237. throw 'marker was not found';
  33238. }
  33239. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  33240. offset += 2;
  33241. } else {
  33242. break;
  33243. }
  33244. }
  33245. return offset - startOffset;
  33246. }
  33247. // A port of poppler's IDCT method which in turn is taken from:
  33248. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  33249. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  33250. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  33251. // 988-991.
  33252. function quantizeAndInverse(component, blockBufferOffset, p) {
  33253. var qt = component.quantizationTable, blockData = component.blockData;
  33254. var v0, v1, v2, v3, v4, v5, v6, v7;
  33255. var p0, p1, p2, p3, p4, p5, p6, p7;
  33256. var t;
  33257. // inverse DCT on rows
  33258. for (var row = 0; row < 64; row += 8) {
  33259. // gather block data
  33260. p0 = blockData[blockBufferOffset + row];
  33261. p1 = blockData[blockBufferOffset + row + 1];
  33262. p2 = blockData[blockBufferOffset + row + 2];
  33263. p3 = blockData[blockBufferOffset + row + 3];
  33264. p4 = blockData[blockBufferOffset + row + 4];
  33265. p5 = blockData[blockBufferOffset + row + 5];
  33266. p6 = blockData[blockBufferOffset + row + 6];
  33267. p7 = blockData[blockBufferOffset + row + 7];
  33268. // dequant p0
  33269. p0 *= qt[row];
  33270. // check for all-zero AC coefficients
  33271. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33272. t = (dctSqrt2 * p0 + 512) >> 10;
  33273. p[row] = t;
  33274. p[row + 1] = t;
  33275. p[row + 2] = t;
  33276. p[row + 3] = t;
  33277. p[row + 4] = t;
  33278. p[row + 5] = t;
  33279. p[row + 6] = t;
  33280. p[row + 7] = t;
  33281. continue;
  33282. }
  33283. // dequant p1 ... p7
  33284. p1 *= qt[row + 1];
  33285. p2 *= qt[row + 2];
  33286. p3 *= qt[row + 3];
  33287. p4 *= qt[row + 4];
  33288. p5 *= qt[row + 5];
  33289. p6 *= qt[row + 6];
  33290. p7 *= qt[row + 7];
  33291. // stage 4
  33292. v0 = (dctSqrt2 * p0 + 128) >> 8;
  33293. v1 = (dctSqrt2 * p4 + 128) >> 8;
  33294. v2 = p2;
  33295. v3 = p6;
  33296. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  33297. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  33298. v5 = p3 << 4;
  33299. v6 = p5 << 4;
  33300. // stage 3
  33301. v0 = (v0 + v1 + 1) >> 1;
  33302. v1 = v0 - v1;
  33303. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  33304. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  33305. v3 = t;
  33306. v4 = (v4 + v6 + 1) >> 1;
  33307. v6 = v4 - v6;
  33308. v7 = (v7 + v5 + 1) >> 1;
  33309. v5 = v7 - v5;
  33310. // stage 2
  33311. v0 = (v0 + v3 + 1) >> 1;
  33312. v3 = v0 - v3;
  33313. v1 = (v1 + v2 + 1) >> 1;
  33314. v2 = v1 - v2;
  33315. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33316. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33317. v7 = t;
  33318. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33319. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33320. v6 = t;
  33321. // stage 1
  33322. p[row] = v0 + v7;
  33323. p[row + 7] = v0 - v7;
  33324. p[row + 1] = v1 + v6;
  33325. p[row + 6] = v1 - v6;
  33326. p[row + 2] = v2 + v5;
  33327. p[row + 5] = v2 - v5;
  33328. p[row + 3] = v3 + v4;
  33329. p[row + 4] = v3 - v4;
  33330. }
  33331. // inverse DCT on columns
  33332. for (var col = 0; col < 8; ++col) {
  33333. p0 = p[col];
  33334. p1 = p[col + 8];
  33335. p2 = p[col + 16];
  33336. p3 = p[col + 24];
  33337. p4 = p[col + 32];
  33338. p5 = p[col + 40];
  33339. p6 = p[col + 48];
  33340. p7 = p[col + 56];
  33341. // check for all-zero AC coefficients
  33342. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33343. t = (dctSqrt2 * p0 + 8192) >> 14;
  33344. // convert to 8 bit
  33345. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  33346. blockData[blockBufferOffset + col] = t;
  33347. blockData[blockBufferOffset + col + 8] = t;
  33348. blockData[blockBufferOffset + col + 16] = t;
  33349. blockData[blockBufferOffset + col + 24] = t;
  33350. blockData[blockBufferOffset + col + 32] = t;
  33351. blockData[blockBufferOffset + col + 40] = t;
  33352. blockData[blockBufferOffset + col + 48] = t;
  33353. blockData[blockBufferOffset + col + 56] = t;
  33354. continue;
  33355. }
  33356. // stage 4
  33357. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  33358. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  33359. v2 = p2;
  33360. v3 = p6;
  33361. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  33362. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  33363. v5 = p3;
  33364. v6 = p5;
  33365. // stage 3
  33366. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  33367. // converting to UInt8 range later.
  33368. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  33369. v1 = v0 - v1;
  33370. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  33371. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  33372. v3 = t;
  33373. v4 = (v4 + v6 + 1) >> 1;
  33374. v6 = v4 - v6;
  33375. v7 = (v7 + v5 + 1) >> 1;
  33376. v5 = v7 - v5;
  33377. // stage 2
  33378. v0 = (v0 + v3 + 1) >> 1;
  33379. v3 = v0 - v3;
  33380. v1 = (v1 + v2 + 1) >> 1;
  33381. v2 = v1 - v2;
  33382. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33383. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33384. v7 = t;
  33385. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33386. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33387. v6 = t;
  33388. // stage 1
  33389. p0 = v0 + v7;
  33390. p7 = v0 - v7;
  33391. p1 = v1 + v6;
  33392. p6 = v1 - v6;
  33393. p2 = v2 + v5;
  33394. p5 = v2 - v5;
  33395. p3 = v3 + v4;
  33396. p4 = v3 - v4;
  33397. // convert to 8-bit integers
  33398. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  33399. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  33400. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  33401. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  33402. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  33403. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  33404. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  33405. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  33406. // store block data
  33407. blockData[blockBufferOffset + col] = p0;
  33408. blockData[blockBufferOffset + col + 8] = p1;
  33409. blockData[blockBufferOffset + col + 16] = p2;
  33410. blockData[blockBufferOffset + col + 24] = p3;
  33411. blockData[blockBufferOffset + col + 32] = p4;
  33412. blockData[blockBufferOffset + col + 40] = p5;
  33413. blockData[blockBufferOffset + col + 48] = p6;
  33414. blockData[blockBufferOffset + col + 56] = p7;
  33415. }
  33416. }
  33417. function buildComponentData(frame, component) {
  33418. var blocksPerLine = component.blocksPerLine;
  33419. var blocksPerColumn = component.blocksPerColumn;
  33420. var computationBuffer = new Int16Array(64);
  33421. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  33422. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  33423. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33424. quantizeAndInverse(component, offset, computationBuffer);
  33425. }
  33426. }
  33427. return component.blockData;
  33428. }
  33429. function clamp0to255(a) {
  33430. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  33431. }
  33432. constructor.prototype = {
  33433. parse: function parse(data) {
  33434. function readUint16() {
  33435. var value = (data[offset] << 8) | data[offset + 1];
  33436. offset += 2;
  33437. return value;
  33438. }
  33439. function readDataBlock() {
  33440. var length = readUint16();
  33441. var array = data.subarray(offset, offset + length - 2);
  33442. offset += array.length;
  33443. return array;
  33444. }
  33445. function prepareComponents(frame) {
  33446. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  33447. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  33448. for (var i = 0; i < frame.components.length; i++) {
  33449. component = frame.components[i];
  33450. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  33451. component.h / frame.maxH);
  33452. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  33453. component.v / frame.maxV);
  33454. var blocksPerLineForMcu = mcusPerLine * component.h;
  33455. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  33456. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  33457. (blocksPerLineForMcu + 1);
  33458. component.blockData = new Int16Array(blocksBufferSize);
  33459. component.blocksPerLine = blocksPerLine;
  33460. component.blocksPerColumn = blocksPerColumn;
  33461. }
  33462. frame.mcusPerLine = mcusPerLine;
  33463. frame.mcusPerColumn = mcusPerColumn;
  33464. }
  33465. var offset = 0, length = data.length;
  33466. var jfif = null;
  33467. var adobe = null;
  33468. var pixels = null;
  33469. var frame, resetInterval;
  33470. var quantizationTables = [];
  33471. var huffmanTablesAC = [], huffmanTablesDC = [];
  33472. var fileMarker = readUint16();
  33473. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  33474. throw 'SOI not found';
  33475. }
  33476. fileMarker = readUint16();
  33477. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  33478. var i, j, l;
  33479. switch(fileMarker) {
  33480. case 0xFFE0: // APP0 (Application Specific)
  33481. case 0xFFE1: // APP1
  33482. case 0xFFE2: // APP2
  33483. case 0xFFE3: // APP3
  33484. case 0xFFE4: // APP4
  33485. case 0xFFE5: // APP5
  33486. case 0xFFE6: // APP6
  33487. case 0xFFE7: // APP7
  33488. case 0xFFE8: // APP8
  33489. case 0xFFE9: // APP9
  33490. case 0xFFEA: // APP10
  33491. case 0xFFEB: // APP11
  33492. case 0xFFEC: // APP12
  33493. case 0xFFED: // APP13
  33494. case 0xFFEE: // APP14
  33495. case 0xFFEF: // APP15
  33496. case 0xFFFE: // COM (Comment)
  33497. var appData = readDataBlock();
  33498. if (fileMarker === 0xFFE0) {
  33499. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  33500. appData[2] === 0x49 && appData[3] === 0x46 &&
  33501. appData[4] === 0) { // 'JFIF\x00'
  33502. jfif = {
  33503. version: { major: appData[5], minor: appData[6] },
  33504. densityUnits: appData[7],
  33505. xDensity: (appData[8] << 8) | appData[9],
  33506. yDensity: (appData[10] << 8) | appData[11],
  33507. thumbWidth: appData[12],
  33508. thumbHeight: appData[13],
  33509. thumbData: appData.subarray(14, 14 +
  33510. 3 * appData[12] * appData[13])
  33511. };
  33512. }
  33513. }
  33514. // TODO APP1 - Exif
  33515. if (fileMarker === 0xFFEE) {
  33516. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  33517. appData[2] === 0x6F && appData[3] === 0x62 &&
  33518. appData[4] === 0x65) { // 'Adobe'
  33519. adobe = {
  33520. version: (appData[5] << 8) | appData[6],
  33521. flags0: (appData[7] << 8) | appData[8],
  33522. flags1: (appData[9] << 8) | appData[10],
  33523. transformCode: appData[11]
  33524. };
  33525. }
  33526. }
  33527. break;
  33528. case 0xFFDB: // DQT (Define Quantization Tables)
  33529. var quantizationTablesLength = readUint16();
  33530. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  33531. var z;
  33532. while (offset < quantizationTablesEnd) {
  33533. var quantizationTableSpec = data[offset++];
  33534. var tableData = new Uint16Array(64);
  33535. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  33536. for (j = 0; j < 64; j++) {
  33537. z = dctZigZag[j];
  33538. tableData[z] = data[offset++];
  33539. }
  33540. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  33541. for (j = 0; j < 64; j++) {
  33542. z = dctZigZag[j];
  33543. tableData[z] = readUint16();
  33544. }
  33545. } else {
  33546. throw 'DQT: invalid table spec';
  33547. }
  33548. quantizationTables[quantizationTableSpec & 15] = tableData;
  33549. }
  33550. break;
  33551. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  33552. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  33553. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  33554. if (frame) {
  33555. throw 'Only single frame JPEGs supported';
  33556. }
  33557. readUint16(); // skip data length
  33558. frame = {};
  33559. frame.extended = (fileMarker === 0xFFC1);
  33560. frame.progressive = (fileMarker === 0xFFC2);
  33561. frame.precision = data[offset++];
  33562. frame.scanLines = readUint16();
  33563. frame.samplesPerLine = readUint16();
  33564. frame.components = [];
  33565. frame.componentIds = {};
  33566. var componentsCount = data[offset++], componentId;
  33567. var maxH = 0, maxV = 0;
  33568. for (i = 0; i < componentsCount; i++) {
  33569. componentId = data[offset];
  33570. var h = data[offset + 1] >> 4;
  33571. var v = data[offset + 1] & 15;
  33572. if (maxH < h) {
  33573. maxH = h;
  33574. }
  33575. if (maxV < v) {
  33576. maxV = v;
  33577. }
  33578. var qId = data[offset + 2];
  33579. l = frame.components.push({
  33580. h: h,
  33581. v: v,
  33582. quantizationTable: quantizationTables[qId]
  33583. });
  33584. frame.componentIds[componentId] = l - 1;
  33585. offset += 3;
  33586. }
  33587. frame.maxH = maxH;
  33588. frame.maxV = maxV;
  33589. prepareComponents(frame);
  33590. break;
  33591. case 0xFFC4: // DHT (Define Huffman Tables)
  33592. var huffmanLength = readUint16();
  33593. for (i = 2; i < huffmanLength;) {
  33594. var huffmanTableSpec = data[offset++];
  33595. var codeLengths = new Uint8Array(16);
  33596. var codeLengthSum = 0;
  33597. for (j = 0; j < 16; j++, offset++) {
  33598. codeLengthSum += (codeLengths[j] = data[offset]);
  33599. }
  33600. var huffmanValues = new Uint8Array(codeLengthSum);
  33601. for (j = 0; j < codeLengthSum; j++, offset++) {
  33602. huffmanValues[j] = data[offset];
  33603. }
  33604. i += 17 + codeLengthSum;
  33605. ((huffmanTableSpec >> 4) === 0 ?
  33606. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33607. buildHuffmanTable(codeLengths, huffmanValues);
  33608. }
  33609. break;
  33610. case 0xFFDD: // DRI (Define Restart Interval)
  33611. readUint16(); // skip data length
  33612. resetInterval = readUint16();
  33613. break;
  33614. case 0xFFDA: // SOS (Start of Scan)
  33615. var scanLength = readUint16();
  33616. var selectorsCount = data[offset++];
  33617. var components = [], component;
  33618. for (i = 0; i < selectorsCount; i++) {
  33619. var componentIndex = frame.componentIds[data[offset++]];
  33620. component = frame.components[componentIndex];
  33621. var tableSpec = data[offset++];
  33622. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33623. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33624. components.push(component);
  33625. }
  33626. var spectralStart = data[offset++];
  33627. var spectralEnd = data[offset++];
  33628. var successiveApproximation = data[offset++];
  33629. var processed = decodeScan(data, offset,
  33630. frame, components, resetInterval,
  33631. spectralStart, spectralEnd,
  33632. successiveApproximation >> 4, successiveApproximation & 15);
  33633. offset += processed;
  33634. break;
  33635. case 0xFFFF: // Fill bytes
  33636. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33637. offset--;
  33638. }
  33639. break;
  33640. default:
  33641. if (data[offset - 3] === 0xFF &&
  33642. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33643. // could be incorrect encoding -- last 0xFF byte of the previous
  33644. // block was eaten by the encoder
  33645. offset -= 3;
  33646. break;
  33647. }
  33648. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33649. }
  33650. fileMarker = readUint16();
  33651. }
  33652. this.width = frame.samplesPerLine;
  33653. this.height = frame.scanLines;
  33654. this.jfif = jfif;
  33655. this.adobe = adobe;
  33656. this.components = [];
  33657. for (i = 0; i < frame.components.length; i++) {
  33658. component = frame.components[i];
  33659. this.components.push({
  33660. output: buildComponentData(frame, component),
  33661. scaleX: component.h / frame.maxH,
  33662. scaleY: component.v / frame.maxV,
  33663. blocksPerLine: component.blocksPerLine,
  33664. blocksPerColumn: component.blocksPerColumn
  33665. });
  33666. }
  33667. this.numComponents = this.components.length;
  33668. },
  33669. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33670. var scaleX = this.width / width, scaleY = this.height / height;
  33671. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33672. var x, y, i, j, k;
  33673. var index;
  33674. var offset = 0;
  33675. var output;
  33676. var numComponents = this.components.length;
  33677. var dataLength = width * height * numComponents;
  33678. var data = new Uint8Array(dataLength);
  33679. var xScaleBlockOffset = new Uint32Array(width);
  33680. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33681. for (i = 0; i < numComponents; i++) {
  33682. component = this.components[i];
  33683. componentScaleX = component.scaleX * scaleX;
  33684. componentScaleY = component.scaleY * scaleY;
  33685. offset = i;
  33686. output = component.output;
  33687. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33688. // precalculate the xScaleBlockOffset
  33689. for (x = 0; x < width; x++) {
  33690. j = 0 | (x * componentScaleX);
  33691. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33692. }
  33693. // linearize the blocks of the component
  33694. for (y = 0; y < height; y++) {
  33695. j = 0 | (y * componentScaleY);
  33696. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33697. for (x = 0; x < width; x++) {
  33698. data[offset] = output[index + xScaleBlockOffset[x]];
  33699. offset += numComponents;
  33700. }
  33701. }
  33702. }
  33703. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33704. var transform = this.decodeTransform;
  33705. if (transform) {
  33706. for (i = 0; i < dataLength;) {
  33707. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33708. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33709. }
  33710. }
  33711. }
  33712. return data;
  33713. },
  33714. _isColorConversionNeeded: function isColorConversionNeeded() {
  33715. if (this.adobe && this.adobe.transformCode) {
  33716. // The adobe transform marker overrides any previous setting
  33717. return true;
  33718. } else if (this.numComponents === 3) {
  33719. return true;
  33720. } else {
  33721. return false;
  33722. }
  33723. },
  33724. _convertYccToRgb: function convertYccToRgb(data) {
  33725. var Y, Cb, Cr;
  33726. for (var i = 0, length = data.length; i < length; i += 3) {
  33727. Y = data[i ];
  33728. Cb = data[i + 1];
  33729. Cr = data[i + 2];
  33730. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33731. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33732. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33733. }
  33734. return data;
  33735. },
  33736. _convertYcckToRgb: function convertYcckToRgb(data) {
  33737. var Y, Cb, Cr, k;
  33738. var offset = 0;
  33739. for (var i = 0, length = data.length; i < length; i += 4) {
  33740. Y = data[i];
  33741. Cb = data[i + 1];
  33742. Cr = data[i + 2];
  33743. k = data[i + 3];
  33744. var r = -122.67195406894 +
  33745. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33746. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33747. 0.154362151871126) +
  33748. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33749. 0.00477271405408747 * k + 1.53380253221734) +
  33750. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33751. 0.48357088451265) +
  33752. k * (-0.000336197177618394 * k + 0.484791561490776);
  33753. var g = 107.268039397724 +
  33754. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33755. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33756. 0.176491792462875) +
  33757. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33758. 0.000770482631801132 * k - 0.151051492775562) +
  33759. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33760. 0.25802910206845) +
  33761. k * (-0.000318913117588328 * k - 0.213742400323665);
  33762. var b = -20.810012546947 +
  33763. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33764. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33765. 0.814272968359295) +
  33766. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33767. 0.000560833691242812 * k - 0.195152027534049) +
  33768. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33769. 0.116935020465145) +
  33770. k * (-0.000343531996510555 * k + 0.24165260232407);
  33771. data[offset++] = clamp0to255(r);
  33772. data[offset++] = clamp0to255(g);
  33773. data[offset++] = clamp0to255(b);
  33774. }
  33775. return data;
  33776. },
  33777. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33778. var Y, Cb, Cr;
  33779. for (var i = 0, length = data.length; i < length; i += 4) {
  33780. Y = data[i];
  33781. Cb = data[i + 1];
  33782. Cr = data[i + 2];
  33783. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33784. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33785. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33786. // K in data[i + 3] is unchanged
  33787. }
  33788. return data;
  33789. },
  33790. _convertCmykToRgb: function convertCmykToRgb(data) {
  33791. var c, m, y, k;
  33792. var offset = 0;
  33793. var min = -255 * 255 * 255;
  33794. var scale = 1 / 255 / 255;
  33795. for (var i = 0, length = data.length; i < length; i += 4) {
  33796. c = data[i];
  33797. m = data[i + 1];
  33798. y = data[i + 2];
  33799. k = data[i + 3];
  33800. var r =
  33801. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33802. 18.82290502165302 * y + 212.25662451639585 * k -
  33803. 72734.4411664936) +
  33804. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33805. 17.873870861415444 * k - 1401.7366389350734) +
  33806. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33807. 4465.541406466231) -
  33808. k * (21.86122147463605 * k + 48317.86113160301);
  33809. var g =
  33810. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33811. 6.871425592049007 * y + 31.159100130055922 * k -
  33812. 20220.756542821975) +
  33813. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33814. 131.35250912493976 * k - 48691.05921601825) +
  33815. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33816. 6341.191035517494) -
  33817. k * (20.737325471181034 * k + 47890.15695978492);
  33818. var b =
  33819. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33820. 30.89978309703729 * y - 0.23883238689178934 * k -
  33821. 3616.812083916688) +
  33822. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33823. 50.606957656360734 * k - 28620.90484698408) +
  33824. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33825. 49363.43385999684) -
  33826. k * (22.33816807309886 * k + 45932.16563550634);
  33827. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33828. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33829. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33830. }
  33831. return data;
  33832. },
  33833. getData: function getData(width, height, forceRGBoutput) {
  33834. if (this.numComponents > 4) {
  33835. throw 'Unsupported color mode';
  33836. }
  33837. // type of data: Uint8Array(width * height * numComponents)
  33838. var data = this._getLinearizedBlockData(width, height);
  33839. if (this.numComponents === 3) {
  33840. return this._convertYccToRgb(data);
  33841. } else if (this.numComponents === 4) {
  33842. if (this._isColorConversionNeeded()) {
  33843. if (forceRGBoutput) {
  33844. return this._convertYcckToRgb(data);
  33845. } else {
  33846. return this._convertYcckToCmyk(data);
  33847. }
  33848. } else if (forceRGBoutput) {
  33849. return this._convertCmykToRgb(data);
  33850. }
  33851. }
  33852. return data;
  33853. }
  33854. };
  33855. return constructor;
  33856. })();
  33857. var JpxImage = (function JpxImageClosure() {
  33858. // Table E.1
  33859. var SubbandsGainLog2 = {
  33860. 'LL': 0,
  33861. 'LH': 1,
  33862. 'HL': 1,
  33863. 'HH': 2
  33864. };
  33865. function JpxImage() {
  33866. this.failOnCorruptedImage = false;
  33867. }
  33868. JpxImage.prototype = {
  33869. parse: function JpxImage_parse(data) {
  33870. var head = readUint16(data, 0);
  33871. // No box header, immediate start of codestream (SOC)
  33872. if (head === 0xFF4F) {
  33873. this.parseCodestream(data, 0, data.length);
  33874. return;
  33875. }
  33876. var position = 0, length = data.length;
  33877. while (position < length) {
  33878. var headerSize = 8;
  33879. var lbox = readUint32(data, position);
  33880. var tbox = readUint32(data, position + 4);
  33881. position += headerSize;
  33882. if (lbox === 1) {
  33883. // XLBox: read UInt64 according to spec.
  33884. // JavaScript's int precision of 53 bit should be sufficient here.
  33885. lbox = readUint32(data, position) * 4294967296 +
  33886. readUint32(data, position + 4);
  33887. position += 8;
  33888. headerSize += 8;
  33889. }
  33890. if (lbox === 0) {
  33891. lbox = length - position + headerSize;
  33892. }
  33893. if (lbox < headerSize) {
  33894. throw new Error('JPX Error: Invalid box field size');
  33895. }
  33896. var dataLength = lbox - headerSize;
  33897. var jumpDataLength = true;
  33898. switch (tbox) {
  33899. case 0x6A703268: // 'jp2h'
  33900. jumpDataLength = false; // parsing child boxes
  33901. break;
  33902. case 0x636F6C72: // 'colr'
  33903. // Colorspaces are not used, the CS from the PDF is used.
  33904. var method = data[position];
  33905. var precedence = data[position + 1];
  33906. var approximation = data[position + 2];
  33907. if (method === 1) {
  33908. // enumerated colorspace
  33909. var colorspace = readUint32(data, position + 3);
  33910. switch (colorspace) {
  33911. case 16: // this indicates a sRGB colorspace
  33912. case 17: // this indicates a grayscale colorspace
  33913. case 18: // this indicates a YUV colorspace
  33914. break;
  33915. default:
  33916. warn('Unknown colorspace ' + colorspace);
  33917. break;
  33918. }
  33919. } else if (method === 2) {
  33920. info('ICC profile not supported');
  33921. }
  33922. break;
  33923. case 0x6A703263: // 'jp2c'
  33924. this.parseCodestream(data, position, position + dataLength);
  33925. break;
  33926. case 0x6A502020: // 'jP\024\024'
  33927. if (0x0d0a870a !== readUint32(data, position)) {
  33928. warn('Invalid JP2 signature');
  33929. }
  33930. break;
  33931. // The following header types are valid but currently not used:
  33932. case 0x6A501A1A: // 'jP\032\032'
  33933. case 0x66747970: // 'ftyp'
  33934. case 0x72726571: // 'rreq'
  33935. case 0x72657320: // 'res '
  33936. case 0x69686472: // 'ihdr'
  33937. break;
  33938. default:
  33939. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33940. (tbox >> 16) & 0xFF,
  33941. (tbox >> 8) & 0xFF,
  33942. tbox & 0xFF);
  33943. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33944. break;
  33945. }
  33946. if (jumpDataLength) {
  33947. position += dataLength;
  33948. }
  33949. }
  33950. },
  33951. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33952. var newByte = stream.getByte();
  33953. while (newByte >= 0) {
  33954. var oldByte = newByte;
  33955. newByte = stream.getByte();
  33956. var code = (oldByte << 8) | newByte;
  33957. // Image and tile size (SIZ)
  33958. if (code === 0xFF51) {
  33959. stream.skip(4);
  33960. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33961. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33962. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33963. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33964. stream.skip(16);
  33965. var Csiz = stream.getUint16(); // Byte 36
  33966. this.width = Xsiz - XOsiz;
  33967. this.height = Ysiz - YOsiz;
  33968. this.componentsCount = Csiz;
  33969. // Results are always returned as Uint8Arrays
  33970. this.bitsPerComponent = 8;
  33971. return;
  33972. }
  33973. }
  33974. throw new Error('JPX Error: No size marker found in JPX stream');
  33975. },
  33976. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33977. var context = {};
  33978. try {
  33979. var doNotRecover = false;
  33980. var position = start;
  33981. while (position + 1 < end) {
  33982. var code = readUint16(data, position);
  33983. position += 2;
  33984. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33985. switch (code) {
  33986. case 0xFF4F: // Start of codestream (SOC)
  33987. context.mainHeader = true;
  33988. break;
  33989. case 0xFFD9: // End of codestream (EOC)
  33990. break;
  33991. case 0xFF51: // Image and tile size (SIZ)
  33992. length = readUint16(data, position);
  33993. var siz = {};
  33994. siz.Xsiz = readUint32(data, position + 4);
  33995. siz.Ysiz = readUint32(data, position + 8);
  33996. siz.XOsiz = readUint32(data, position + 12);
  33997. siz.YOsiz = readUint32(data, position + 16);
  33998. siz.XTsiz = readUint32(data, position + 20);
  33999. siz.YTsiz = readUint32(data, position + 24);
  34000. siz.XTOsiz = readUint32(data, position + 28);
  34001. siz.YTOsiz = readUint32(data, position + 32);
  34002. var componentsCount = readUint16(data, position + 36);
  34003. siz.Csiz = componentsCount;
  34004. var components = [];
  34005. j = position + 38;
  34006. for (var i = 0; i < componentsCount; i++) {
  34007. var component = {
  34008. precision: (data[j] & 0x7F) + 1,
  34009. isSigned: !!(data[j] & 0x80),
  34010. XRsiz: data[j + 1],
  34011. YRsiz: data[j + 1]
  34012. };
  34013. calculateComponentDimensions(component, siz);
  34014. components.push(component);
  34015. }
  34016. context.SIZ = siz;
  34017. context.components = components;
  34018. calculateTileGrids(context, components);
  34019. context.QCC = [];
  34020. context.COC = [];
  34021. break;
  34022. case 0xFF5C: // Quantization default (QCD)
  34023. length = readUint16(data, position);
  34024. var qcd = {};
  34025. j = position + 2;
  34026. sqcd = data[j++];
  34027. switch (sqcd & 0x1F) {
  34028. case 0:
  34029. spqcdSize = 8;
  34030. scalarExpounded = true;
  34031. break;
  34032. case 1:
  34033. spqcdSize = 16;
  34034. scalarExpounded = false;
  34035. break;
  34036. case 2:
  34037. spqcdSize = 16;
  34038. scalarExpounded = true;
  34039. break;
  34040. default:
  34041. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  34042. }
  34043. qcd.noQuantization = (spqcdSize === 8);
  34044. qcd.scalarExpounded = scalarExpounded;
  34045. qcd.guardBits = sqcd >> 5;
  34046. spqcds = [];
  34047. while (j < length + position) {
  34048. var spqcd = {};
  34049. if (spqcdSize === 8) {
  34050. spqcd.epsilon = data[j++] >> 3;
  34051. spqcd.mu = 0;
  34052. } else {
  34053. spqcd.epsilon = data[j] >> 3;
  34054. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  34055. j += 2;
  34056. }
  34057. spqcds.push(spqcd);
  34058. }
  34059. qcd.SPqcds = spqcds;
  34060. if (context.mainHeader) {
  34061. context.QCD = qcd;
  34062. } else {
  34063. context.currentTile.QCD = qcd;
  34064. context.currentTile.QCC = [];
  34065. }
  34066. break;
  34067. case 0xFF5D: // Quantization component (QCC)
  34068. length = readUint16(data, position);
  34069. var qcc = {};
  34070. j = position + 2;
  34071. var cqcc;
  34072. if (context.SIZ.Csiz < 257) {
  34073. cqcc = data[j++];
  34074. } else {
  34075. cqcc = readUint16(data, j);
  34076. j += 2;
  34077. }
  34078. sqcd = data[j++];
  34079. switch (sqcd & 0x1F) {
  34080. case 0:
  34081. spqcdSize = 8;
  34082. scalarExpounded = true;
  34083. break;
  34084. case 1:
  34085. spqcdSize = 16;
  34086. scalarExpounded = false;
  34087. break;
  34088. case 2:
  34089. spqcdSize = 16;
  34090. scalarExpounded = true;
  34091. break;
  34092. default:
  34093. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  34094. }
  34095. qcc.noQuantization = (spqcdSize === 8);
  34096. qcc.scalarExpounded = scalarExpounded;
  34097. qcc.guardBits = sqcd >> 5;
  34098. spqcds = [];
  34099. while (j < (length + position)) {
  34100. spqcd = {};
  34101. if (spqcdSize === 8) {
  34102. spqcd.epsilon = data[j++] >> 3;
  34103. spqcd.mu = 0;
  34104. } else {
  34105. spqcd.epsilon = data[j] >> 3;
  34106. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  34107. j += 2;
  34108. }
  34109. spqcds.push(spqcd);
  34110. }
  34111. qcc.SPqcds = spqcds;
  34112. if (context.mainHeader) {
  34113. context.QCC[cqcc] = qcc;
  34114. } else {
  34115. context.currentTile.QCC[cqcc] = qcc;
  34116. }
  34117. break;
  34118. case 0xFF52: // Coding style default (COD)
  34119. length = readUint16(data, position);
  34120. var cod = {};
  34121. j = position + 2;
  34122. var scod = data[j++];
  34123. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  34124. cod.sopMarkerUsed = !!(scod & 2);
  34125. cod.ephMarkerUsed = !!(scod & 4);
  34126. cod.progressionOrder = data[j++];
  34127. cod.layersCount = readUint16(data, j);
  34128. j += 2;
  34129. cod.multipleComponentTransform = data[j++];
  34130. cod.decompositionLevelsCount = data[j++];
  34131. cod.xcb = (data[j++] & 0xF) + 2;
  34132. cod.ycb = (data[j++] & 0xF) + 2;
  34133. var blockStyle = data[j++];
  34134. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  34135. cod.resetContextProbabilities = !!(blockStyle & 2);
  34136. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  34137. cod.verticalyStripe = !!(blockStyle & 8);
  34138. cod.predictableTermination = !!(blockStyle & 16);
  34139. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  34140. cod.reversibleTransformation = data[j++];
  34141. if (cod.entropyCoderWithCustomPrecincts) {
  34142. var precinctsSizes = [];
  34143. while (j < length + position) {
  34144. var precinctsSize = data[j++];
  34145. precinctsSizes.push({
  34146. PPx: precinctsSize & 0xF,
  34147. PPy: precinctsSize >> 4
  34148. });
  34149. }
  34150. cod.precinctsSizes = precinctsSizes;
  34151. }
  34152. var unsupported = [];
  34153. if (cod.selectiveArithmeticCodingBypass) {
  34154. unsupported.push('selectiveArithmeticCodingBypass');
  34155. }
  34156. if (cod.resetContextProbabilities) {
  34157. unsupported.push('resetContextProbabilities');
  34158. }
  34159. if (cod.terminationOnEachCodingPass) {
  34160. unsupported.push('terminationOnEachCodingPass');
  34161. }
  34162. if (cod.verticalyStripe) {
  34163. unsupported.push('verticalyStripe');
  34164. }
  34165. if (cod.predictableTermination) {
  34166. unsupported.push('predictableTermination');
  34167. }
  34168. if (unsupported.length > 0) {
  34169. doNotRecover = true;
  34170. throw new Error('JPX Error: Unsupported COD options (' +
  34171. unsupported.join(', ') + ')');
  34172. }
  34173. if (context.mainHeader) {
  34174. context.COD = cod;
  34175. } else {
  34176. context.currentTile.COD = cod;
  34177. context.currentTile.COC = [];
  34178. }
  34179. break;
  34180. case 0xFF90: // Start of tile-part (SOT)
  34181. length = readUint16(data, position);
  34182. tile = {};
  34183. tile.index = readUint16(data, position + 2);
  34184. tile.length = readUint32(data, position + 4);
  34185. tile.dataEnd = tile.length + position - 2;
  34186. tile.partIndex = data[position + 8];
  34187. tile.partsCount = data[position + 9];
  34188. context.mainHeader = false;
  34189. if (tile.partIndex === 0) {
  34190. // reset component specific settings
  34191. tile.COD = context.COD;
  34192. tile.COC = context.COC.slice(0); // clone of the global COC
  34193. tile.QCD = context.QCD;
  34194. tile.QCC = context.QCC.slice(0); // clone of the global COC
  34195. }
  34196. context.currentTile = tile;
  34197. break;
  34198. case 0xFF93: // Start of data (SOD)
  34199. tile = context.currentTile;
  34200. if (tile.partIndex === 0) {
  34201. initializeTile(context, tile.index);
  34202. buildPackets(context);
  34203. }
  34204. // moving to the end of the data
  34205. length = tile.dataEnd - position;
  34206. parseTilePackets(context, data, position, length);
  34207. break;
  34208. case 0xFF55: // Tile-part lengths, main header (TLM)
  34209. case 0xFF57: // Packet length, main header (PLM)
  34210. case 0xFF58: // Packet length, tile-part header (PLT)
  34211. case 0xFF64: // Comment (COM)
  34212. length = readUint16(data, position);
  34213. // skipping content
  34214. break;
  34215. case 0xFF53: // Coding style component (COC)
  34216. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  34217. 'not implemented');
  34218. default:
  34219. throw new Error('JPX Error: Unknown codestream code: ' +
  34220. code.toString(16));
  34221. }
  34222. position += length;
  34223. }
  34224. } catch (e) {
  34225. if (doNotRecover || this.failOnCorruptedImage) {
  34226. throw e;
  34227. } else {
  34228. warn('Trying to recover from ' + e.message);
  34229. }
  34230. }
  34231. this.tiles = transformComponents(context);
  34232. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  34233. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  34234. this.componentsCount = context.SIZ.Csiz;
  34235. }
  34236. };
  34237. function calculateComponentDimensions(component, siz) {
  34238. // Section B.2 Component mapping
  34239. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  34240. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  34241. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  34242. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  34243. component.width = component.x1 - component.x0;
  34244. component.height = component.y1 - component.y0;
  34245. }
  34246. function calculateTileGrids(context, components) {
  34247. var siz = context.SIZ;
  34248. // Section B.3 Division into tile and tile-components
  34249. var tile, tiles = [];
  34250. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  34251. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  34252. for (var q = 0; q < numYtiles; q++) {
  34253. for (var p = 0; p < numXtiles; p++) {
  34254. tile = {};
  34255. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  34256. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  34257. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  34258. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  34259. tile.width = tile.tx1 - tile.tx0;
  34260. tile.height = tile.ty1 - tile.ty0;
  34261. tile.components = [];
  34262. tiles.push(tile);
  34263. }
  34264. }
  34265. context.tiles = tiles;
  34266. var componentsCount = siz.Csiz;
  34267. for (var i = 0, ii = componentsCount; i < ii; i++) {
  34268. var component = components[i];
  34269. for (var j = 0, jj = tiles.length; j < jj; j++) {
  34270. var tileComponent = {};
  34271. tile = tiles[j];
  34272. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  34273. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  34274. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  34275. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  34276. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  34277. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  34278. tile.components[i] = tileComponent;
  34279. }
  34280. }
  34281. }
  34282. function getBlocksDimensions(context, component, r) {
  34283. var codOrCoc = component.codingStyleParameters;
  34284. var result = {};
  34285. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  34286. result.PPx = 15;
  34287. result.PPy = 15;
  34288. } else {
  34289. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  34290. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  34291. }
  34292. // calculate codeblock size as described in section B.7
  34293. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  34294. Math.min(codOrCoc.xcb, result.PPx));
  34295. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  34296. Math.min(codOrCoc.ycb, result.PPy));
  34297. return result;
  34298. }
  34299. function buildPrecincts(context, resolution, dimensions) {
  34300. // Section B.6 Division resolution to precincts
  34301. var precinctWidth = 1 << dimensions.PPx;
  34302. var precinctHeight = 1 << dimensions.PPy;
  34303. // Jasper introduces codeblock groups for mapping each subband codeblocks
  34304. // to precincts. Precinct partition divides a resolution according to width
  34305. // and height parameters. The subband that belongs to the resolution level
  34306. // has a different size than the level, unless it is the zero resolution.
  34307. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  34308. // The precinct partitioning for a particular subband is derived from a
  34309. // partitioning of its parent LL band (i.e., the LL band at the next higher
  34310. // resolution level)... The LL band associated with each resolution level is
  34311. // divided into precincts... Each of the resulting precinct regions is then
  34312. // mapped into its child subbands (if any) at the next lower resolution
  34313. // level. This is accomplished by using the coordinate transformation
  34314. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  34315. // coordinates of a point in the LL band and child subband, respectively.
  34316. var isZeroRes = resolution.resLevel === 0;
  34317. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  34318. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  34319. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  34320. Math.ceil(resolution.trx1 / precinctWidth) -
  34321. Math.floor(resolution.trx0 / precinctWidth) : 0);
  34322. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  34323. Math.ceil(resolution.try1 / precinctHeight) -
  34324. Math.floor(resolution.try0 / precinctHeight) : 0);
  34325. var numprecincts = numprecinctswide * numprecinctshigh;
  34326. resolution.precinctParameters = {
  34327. precinctWidth: precinctWidth,
  34328. precinctHeight: precinctHeight,
  34329. numprecinctswide: numprecinctswide,
  34330. numprecinctshigh: numprecinctshigh,
  34331. numprecincts: numprecincts,
  34332. precinctWidthInSubband: precinctWidthInSubband,
  34333. precinctHeightInSubband: precinctHeightInSubband
  34334. };
  34335. }
  34336. function buildCodeblocks(context, subband, dimensions) {
  34337. // Section B.7 Division sub-band into code-blocks
  34338. var xcb_ = dimensions.xcb_;
  34339. var ycb_ = dimensions.ycb_;
  34340. var codeblockWidth = 1 << xcb_;
  34341. var codeblockHeight = 1 << ycb_;
  34342. var cbx0 = subband.tbx0 >> xcb_;
  34343. var cby0 = subband.tby0 >> ycb_;
  34344. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  34345. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  34346. var precinctParameters = subband.resolution.precinctParameters;
  34347. var codeblocks = [];
  34348. var precincts = [];
  34349. var i, j, codeblock, precinctNumber;
  34350. for (j = cby0; j < cby1; j++) {
  34351. for (i = cbx0; i < cbx1; i++) {
  34352. codeblock = {
  34353. cbx: i,
  34354. cby: j,
  34355. tbx0: codeblockWidth * i,
  34356. tby0: codeblockHeight * j,
  34357. tbx1: codeblockWidth * (i + 1),
  34358. tby1: codeblockHeight * (j + 1)
  34359. };
  34360. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  34361. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  34362. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  34363. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  34364. // Calculate precinct number for this codeblock, codeblock position
  34365. // should be relative to its subband, use actual dimension and position
  34366. // See comment about codeblock group width and height
  34367. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  34368. precinctParameters.precinctWidthInSubband);
  34369. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  34370. precinctParameters.precinctHeightInSubband);
  34371. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  34372. codeblock.precinctNumber = precinctNumber;
  34373. codeblock.subbandType = subband.type;
  34374. codeblock.Lblock = 3;
  34375. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  34376. codeblock.tby1_ <= codeblock.tby0_) {
  34377. continue;
  34378. }
  34379. codeblocks.push(codeblock);
  34380. // building precinct for the sub-band
  34381. var precinct = precincts[precinctNumber];
  34382. if (precinct !== undefined) {
  34383. if (i < precinct.cbxMin) {
  34384. precinct.cbxMin = i;
  34385. } else if (i > precinct.cbxMax) {
  34386. precinct.cbxMax = i;
  34387. }
  34388. if (j < precinct.cbyMin) {
  34389. precinct.cbxMin = j;
  34390. } else if (j > precinct.cbyMax) {
  34391. precinct.cbyMax = j;
  34392. }
  34393. } else {
  34394. precincts[precinctNumber] = precinct = {
  34395. cbxMin: i,
  34396. cbyMin: j,
  34397. cbxMax: i,
  34398. cbyMax: j
  34399. };
  34400. }
  34401. codeblock.precinct = precinct;
  34402. }
  34403. }
  34404. subband.codeblockParameters = {
  34405. codeblockWidth: xcb_,
  34406. codeblockHeight: ycb_,
  34407. numcodeblockwide: cbx1 - cbx0 + 1,
  34408. numcodeblockhigh: cby1 - cby0 + 1
  34409. };
  34410. subband.codeblocks = codeblocks;
  34411. subband.precincts = precincts;
  34412. }
  34413. function createPacket(resolution, precinctNumber, layerNumber) {
  34414. var precinctCodeblocks = [];
  34415. // Section B.10.8 Order of info in packet
  34416. var subbands = resolution.subbands;
  34417. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  34418. for (var i = 0, ii = subbands.length; i < ii; i++) {
  34419. var subband = subbands[i];
  34420. var codeblocks = subband.codeblocks;
  34421. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  34422. var codeblock = codeblocks[j];
  34423. if (codeblock.precinctNumber !== precinctNumber) {
  34424. continue;
  34425. }
  34426. precinctCodeblocks.push(codeblock);
  34427. }
  34428. }
  34429. return {
  34430. layerNumber: layerNumber,
  34431. codeblocks: precinctCodeblocks
  34432. };
  34433. }
  34434. function LayerResolutionComponentPositionIterator(context) {
  34435. var siz = context.SIZ;
  34436. var tileIndex = context.currentTile.index;
  34437. var tile = context.tiles[tileIndex];
  34438. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34439. var componentsCount = siz.Csiz;
  34440. var maxDecompositionLevelsCount = 0;
  34441. for (var q = 0; q < componentsCount; q++) {
  34442. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34443. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34444. }
  34445. var l = 0, r = 0, i = 0, k = 0;
  34446. this.nextPacket = function JpxImage_nextPacket() {
  34447. // Section B.12.1.1 Layer-resolution-component-position
  34448. for (; l < layersCount; l++) {
  34449. for (; r <= maxDecompositionLevelsCount; r++) {
  34450. for (; i < componentsCount; i++) {
  34451. var component = tile.components[i];
  34452. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34453. continue;
  34454. }
  34455. var resolution = component.resolutions[r];
  34456. var numprecincts = resolution.precinctParameters.numprecincts;
  34457. for (; k < numprecincts;) {
  34458. var packet = createPacket(resolution, k, l);
  34459. k++;
  34460. return packet;
  34461. }
  34462. k = 0;
  34463. }
  34464. i = 0;
  34465. }
  34466. r = 0;
  34467. }
  34468. throw new Error('JPX Error: Out of packets');
  34469. };
  34470. }
  34471. function ResolutionLayerComponentPositionIterator(context) {
  34472. var siz = context.SIZ;
  34473. var tileIndex = context.currentTile.index;
  34474. var tile = context.tiles[tileIndex];
  34475. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34476. var componentsCount = siz.Csiz;
  34477. var maxDecompositionLevelsCount = 0;
  34478. for (var q = 0; q < componentsCount; q++) {
  34479. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34480. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34481. }
  34482. var r = 0, l = 0, i = 0, k = 0;
  34483. this.nextPacket = function JpxImage_nextPacket() {
  34484. // Section B.12.1.2 Resolution-layer-component-position
  34485. for (; r <= maxDecompositionLevelsCount; r++) {
  34486. for (; l < layersCount; l++) {
  34487. for (; i < componentsCount; i++) {
  34488. var component = tile.components[i];
  34489. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34490. continue;
  34491. }
  34492. var resolution = component.resolutions[r];
  34493. var numprecincts = resolution.precinctParameters.numprecincts;
  34494. for (; k < numprecincts;) {
  34495. var packet = createPacket(resolution, k, l);
  34496. k++;
  34497. return packet;
  34498. }
  34499. k = 0;
  34500. }
  34501. i = 0;
  34502. }
  34503. l = 0;
  34504. }
  34505. throw new Error('JPX Error: Out of packets');
  34506. };
  34507. }
  34508. function ResolutionPositionComponentLayerIterator(context) {
  34509. var siz = context.SIZ;
  34510. var tileIndex = context.currentTile.index;
  34511. var tile = context.tiles[tileIndex];
  34512. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34513. var componentsCount = siz.Csiz;
  34514. var l, r, c, p;
  34515. var maxDecompositionLevelsCount = 0;
  34516. for (c = 0; c < componentsCount; c++) {
  34517. var component = tile.components[c];
  34518. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34519. component.codingStyleParameters.decompositionLevelsCount);
  34520. }
  34521. var maxNumPrecinctsInLevel = new Int32Array(
  34522. maxDecompositionLevelsCount + 1);
  34523. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  34524. var maxNumPrecincts = 0;
  34525. for (c = 0; c < componentsCount; ++c) {
  34526. var resolutions = tile.components[c].resolutions;
  34527. if (r < resolutions.length) {
  34528. maxNumPrecincts = Math.max(maxNumPrecincts,
  34529. resolutions[r].precinctParameters.numprecincts);
  34530. }
  34531. }
  34532. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  34533. }
  34534. l = 0;
  34535. r = 0;
  34536. c = 0;
  34537. p = 0;
  34538. this.nextPacket = function JpxImage_nextPacket() {
  34539. // Section B.12.1.3 Resolution-position-component-layer
  34540. for (; r <= maxDecompositionLevelsCount; r++) {
  34541. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  34542. for (; c < componentsCount; c++) {
  34543. var component = tile.components[c];
  34544. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34545. continue;
  34546. }
  34547. var resolution = component.resolutions[r];
  34548. var numprecincts = resolution.precinctParameters.numprecincts;
  34549. if (p >= numprecincts) {
  34550. continue;
  34551. }
  34552. for (; l < layersCount;) {
  34553. var packet = createPacket(resolution, p, l);
  34554. l++;
  34555. return packet;
  34556. }
  34557. l = 0;
  34558. }
  34559. c = 0;
  34560. }
  34561. p = 0;
  34562. }
  34563. throw new Error('JPX Error: Out of packets');
  34564. };
  34565. }
  34566. function PositionComponentResolutionLayerIterator(context) {
  34567. var siz = context.SIZ;
  34568. var tileIndex = context.currentTile.index;
  34569. var tile = context.tiles[tileIndex];
  34570. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34571. var componentsCount = siz.Csiz;
  34572. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34573. var precinctsIterationSizes = precinctsSizes;
  34574. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34575. this.nextPacket = function JpxImage_nextPacket() {
  34576. // Section B.12.1.4 Position-component-resolution-layer
  34577. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34578. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34579. for (; c < componentsCount; c++) {
  34580. var component = tile.components[c];
  34581. var decompositionLevelsCount =
  34582. component.codingStyleParameters.decompositionLevelsCount;
  34583. for (; r <= decompositionLevelsCount; r++) {
  34584. var resolution = component.resolutions[r];
  34585. var sizeInImageScale =
  34586. precinctsSizes.components[c].resolutions[r];
  34587. var k = getPrecinctIndexIfExist(
  34588. px,
  34589. py,
  34590. sizeInImageScale,
  34591. precinctsIterationSizes,
  34592. resolution);
  34593. if (k === null) {
  34594. continue;
  34595. }
  34596. for (; l < layersCount;) {
  34597. var packet = createPacket(resolution, k, l);
  34598. l++;
  34599. return packet;
  34600. }
  34601. l = 0;
  34602. }
  34603. r = 0;
  34604. }
  34605. c = 0;
  34606. }
  34607. px = 0;
  34608. }
  34609. throw new Error('JPX Error: Out of packets');
  34610. };
  34611. }
  34612. function ComponentPositionResolutionLayerIterator(context) {
  34613. var siz = context.SIZ;
  34614. var tileIndex = context.currentTile.index;
  34615. var tile = context.tiles[tileIndex];
  34616. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34617. var componentsCount = siz.Csiz;
  34618. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34619. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34620. this.nextPacket = function JpxImage_nextPacket() {
  34621. // Section B.12.1.5 Component-position-resolution-layer
  34622. for (; c < componentsCount; ++c) {
  34623. var component = tile.components[c];
  34624. var precinctsIterationSizes = precinctsSizes.components[c];
  34625. var decompositionLevelsCount =
  34626. component.codingStyleParameters.decompositionLevelsCount;
  34627. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34628. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34629. for (; r <= decompositionLevelsCount; r++) {
  34630. var resolution = component.resolutions[r];
  34631. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34632. var k = getPrecinctIndexIfExist(
  34633. px,
  34634. py,
  34635. sizeInImageScale,
  34636. precinctsIterationSizes,
  34637. resolution);
  34638. if (k === null) {
  34639. continue;
  34640. }
  34641. for (; l < layersCount;) {
  34642. var packet = createPacket(resolution, k, l);
  34643. l++;
  34644. return packet;
  34645. }
  34646. l = 0;
  34647. }
  34648. r = 0;
  34649. }
  34650. px = 0;
  34651. }
  34652. py = 0;
  34653. }
  34654. throw new Error('JPX Error: Out of packets');
  34655. };
  34656. }
  34657. function getPrecinctIndexIfExist(
  34658. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34659. var posX = pxIndex * precinctIterationSizes.minWidth;
  34660. var posY = pyIndex * precinctIterationSizes.minHeight;
  34661. if (posX % sizeInImageScale.width !== 0 ||
  34662. posY % sizeInImageScale.height !== 0) {
  34663. return null;
  34664. }
  34665. var startPrecinctRowIndex =
  34666. (posY / sizeInImageScale.width) *
  34667. resolution.precinctParameters.numprecinctswide;
  34668. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34669. }
  34670. function getPrecinctSizesInImageScale(tile) {
  34671. var componentsCount = tile.components.length;
  34672. var minWidth = Number.MAX_VALUE;
  34673. var minHeight = Number.MAX_VALUE;
  34674. var maxNumWide = 0;
  34675. var maxNumHigh = 0;
  34676. var sizePerComponent = new Array(componentsCount);
  34677. for (var c = 0; c < componentsCount; c++) {
  34678. var component = tile.components[c];
  34679. var decompositionLevelsCount =
  34680. component.codingStyleParameters.decompositionLevelsCount;
  34681. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34682. var minWidthCurrentComponent = Number.MAX_VALUE;
  34683. var minHeightCurrentComponent = Number.MAX_VALUE;
  34684. var maxNumWideCurrentComponent = 0;
  34685. var maxNumHighCurrentComponent = 0;
  34686. var scale = 1;
  34687. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34688. var resolution = component.resolutions[r];
  34689. var widthCurrentResolution =
  34690. scale * resolution.precinctParameters.precinctWidth;
  34691. var heightCurrentResolution =
  34692. scale * resolution.precinctParameters.precinctHeight;
  34693. minWidthCurrentComponent = Math.min(
  34694. minWidthCurrentComponent,
  34695. widthCurrentResolution);
  34696. minHeightCurrentComponent = Math.min(
  34697. minHeightCurrentComponent,
  34698. heightCurrentResolution);
  34699. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34700. resolution.precinctParameters.numprecinctswide);
  34701. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34702. resolution.precinctParameters.numprecinctshigh);
  34703. sizePerResolution[r] = {
  34704. width: widthCurrentResolution,
  34705. height: heightCurrentResolution
  34706. };
  34707. scale <<= 1;
  34708. }
  34709. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34710. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34711. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34712. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34713. sizePerComponent[c] = {
  34714. resolutions: sizePerResolution,
  34715. minWidth: minWidthCurrentComponent,
  34716. minHeight: minHeightCurrentComponent,
  34717. maxNumWide: maxNumWideCurrentComponent,
  34718. maxNumHigh: maxNumHighCurrentComponent
  34719. };
  34720. }
  34721. return {
  34722. components: sizePerComponent,
  34723. minWidth: minWidth,
  34724. minHeight: minHeight,
  34725. maxNumWide: maxNumWide,
  34726. maxNumHigh: maxNumHigh
  34727. };
  34728. }
  34729. function buildPackets(context) {
  34730. var siz = context.SIZ;
  34731. var tileIndex = context.currentTile.index;
  34732. var tile = context.tiles[tileIndex];
  34733. var componentsCount = siz.Csiz;
  34734. // Creating resolutions and sub-bands for each component
  34735. for (var c = 0; c < componentsCount; c++) {
  34736. var component = tile.components[c];
  34737. var decompositionLevelsCount =
  34738. component.codingStyleParameters.decompositionLevelsCount;
  34739. // Section B.5 Resolution levels and sub-bands
  34740. var resolutions = [];
  34741. var subbands = [];
  34742. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34743. var blocksDimensions = getBlocksDimensions(context, component, r);
  34744. var resolution = {};
  34745. var scale = 1 << (decompositionLevelsCount - r);
  34746. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34747. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34748. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34749. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34750. resolution.resLevel = r;
  34751. buildPrecincts(context, resolution, blocksDimensions);
  34752. resolutions.push(resolution);
  34753. var subband;
  34754. if (r === 0) {
  34755. // one sub-band (LL) with last decomposition
  34756. subband = {};
  34757. subband.type = 'LL';
  34758. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34759. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34760. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34761. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34762. subband.resolution = resolution;
  34763. buildCodeblocks(context, subband, blocksDimensions);
  34764. subbands.push(subband);
  34765. resolution.subbands = [subband];
  34766. } else {
  34767. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34768. var resolutionSubbands = [];
  34769. // three sub-bands (HL, LH and HH) with rest of decompositions
  34770. subband = {};
  34771. subband.type = 'HL';
  34772. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34773. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34774. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34775. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34776. subband.resolution = resolution;
  34777. buildCodeblocks(context, subband, blocksDimensions);
  34778. subbands.push(subband);
  34779. resolutionSubbands.push(subband);
  34780. subband = {};
  34781. subband.type = 'LH';
  34782. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34783. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34784. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34785. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34786. subband.resolution = resolution;
  34787. buildCodeblocks(context, subband, blocksDimensions);
  34788. subbands.push(subband);
  34789. resolutionSubbands.push(subband);
  34790. subband = {};
  34791. subband.type = 'HH';
  34792. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34793. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34794. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34795. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34796. subband.resolution = resolution;
  34797. buildCodeblocks(context, subband, blocksDimensions);
  34798. subbands.push(subband);
  34799. resolutionSubbands.push(subband);
  34800. resolution.subbands = resolutionSubbands;
  34801. }
  34802. }
  34803. component.resolutions = resolutions;
  34804. component.subbands = subbands;
  34805. }
  34806. // Generate the packets sequence
  34807. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34808. switch (progressionOrder) {
  34809. case 0:
  34810. tile.packetsIterator =
  34811. new LayerResolutionComponentPositionIterator(context);
  34812. break;
  34813. case 1:
  34814. tile.packetsIterator =
  34815. new ResolutionLayerComponentPositionIterator(context);
  34816. break;
  34817. case 2:
  34818. tile.packetsIterator =
  34819. new ResolutionPositionComponentLayerIterator(context);
  34820. break;
  34821. case 3:
  34822. tile.packetsIterator =
  34823. new PositionComponentResolutionLayerIterator(context);
  34824. break;
  34825. case 4:
  34826. tile.packetsIterator =
  34827. new ComponentPositionResolutionLayerIterator(context);
  34828. break;
  34829. default:
  34830. throw new Error('JPX Error: Unsupported progression order ' +
  34831. progressionOrder);
  34832. }
  34833. }
  34834. function parseTilePackets(context, data, offset, dataLength) {
  34835. var position = 0;
  34836. var buffer, bufferSize = 0, skipNextBit = false;
  34837. function readBits(count) {
  34838. while (bufferSize < count) {
  34839. var b = data[offset + position];
  34840. position++;
  34841. if (skipNextBit) {
  34842. buffer = (buffer << 7) | b;
  34843. bufferSize += 7;
  34844. skipNextBit = false;
  34845. } else {
  34846. buffer = (buffer << 8) | b;
  34847. bufferSize += 8;
  34848. }
  34849. if (b === 0xFF) {
  34850. skipNextBit = true;
  34851. }
  34852. }
  34853. bufferSize -= count;
  34854. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34855. }
  34856. function skipMarkerIfEqual(value) {
  34857. if (data[offset + position - 1] === 0xFF &&
  34858. data[offset + position] === value) {
  34859. skipBytes(1);
  34860. return true;
  34861. } else if (data[offset + position] === 0xFF &&
  34862. data[offset + position + 1] === value) {
  34863. skipBytes(2);
  34864. return true;
  34865. }
  34866. return false;
  34867. }
  34868. function skipBytes(count) {
  34869. position += count;
  34870. }
  34871. function alignToByte() {
  34872. bufferSize = 0;
  34873. if (skipNextBit) {
  34874. position++;
  34875. skipNextBit = false;
  34876. }
  34877. }
  34878. function readCodingpasses() {
  34879. if (readBits(1) === 0) {
  34880. return 1;
  34881. }
  34882. if (readBits(1) === 0) {
  34883. return 2;
  34884. }
  34885. var value = readBits(2);
  34886. if (value < 3) {
  34887. return value + 3;
  34888. }
  34889. value = readBits(5);
  34890. if (value < 31) {
  34891. return value + 6;
  34892. }
  34893. value = readBits(7);
  34894. return value + 37;
  34895. }
  34896. var tileIndex = context.currentTile.index;
  34897. var tile = context.tiles[tileIndex];
  34898. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34899. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34900. var packetsIterator = tile.packetsIterator;
  34901. while (position < dataLength) {
  34902. alignToByte();
  34903. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34904. // Skip also marker segment length and packet sequence ID
  34905. skipBytes(4);
  34906. }
  34907. var packet = packetsIterator.nextPacket();
  34908. if (!readBits(1)) {
  34909. continue;
  34910. }
  34911. var layerNumber = packet.layerNumber;
  34912. var queue = [], codeblock;
  34913. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34914. codeblock = packet.codeblocks[i];
  34915. var precinct = codeblock.precinct;
  34916. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34917. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34918. var codeblockIncluded = false;
  34919. var firstTimeInclusion = false;
  34920. var valueReady;
  34921. if (codeblock['included'] !== undefined) {
  34922. codeblockIncluded = !!readBits(1);
  34923. } else {
  34924. // reading inclusion tree
  34925. precinct = codeblock.precinct;
  34926. var inclusionTree, zeroBitPlanesTree;
  34927. if (precinct['inclusionTree'] !== undefined) {
  34928. inclusionTree = precinct.inclusionTree;
  34929. } else {
  34930. // building inclusion and zero bit-planes trees
  34931. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34932. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34933. inclusionTree = new InclusionTree(width, height, layerNumber);
  34934. zeroBitPlanesTree = new TagTree(width, height);
  34935. precinct.inclusionTree = inclusionTree;
  34936. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34937. }
  34938. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34939. while (true) {
  34940. if (readBits(1)) {
  34941. valueReady = !inclusionTree.nextLevel();
  34942. if (valueReady) {
  34943. codeblock.included = true;
  34944. codeblockIncluded = firstTimeInclusion = true;
  34945. break;
  34946. }
  34947. } else {
  34948. inclusionTree.incrementValue(layerNumber);
  34949. break;
  34950. }
  34951. }
  34952. }
  34953. }
  34954. if (!codeblockIncluded) {
  34955. continue;
  34956. }
  34957. if (firstTimeInclusion) {
  34958. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34959. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34960. while (true) {
  34961. if (readBits(1)) {
  34962. valueReady = !zeroBitPlanesTree.nextLevel();
  34963. if (valueReady) {
  34964. break;
  34965. }
  34966. } else {
  34967. zeroBitPlanesTree.incrementValue();
  34968. }
  34969. }
  34970. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34971. }
  34972. var codingpasses = readCodingpasses();
  34973. while (readBits(1)) {
  34974. codeblock.Lblock++;
  34975. }
  34976. var codingpassesLog2 = log2(codingpasses);
  34977. // rounding down log2
  34978. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34979. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34980. var codedDataLength = readBits(bits);
  34981. queue.push({
  34982. codeblock: codeblock,
  34983. codingpasses: codingpasses,
  34984. dataLength: codedDataLength
  34985. });
  34986. }
  34987. alignToByte();
  34988. if (ephMarkerUsed) {
  34989. skipMarkerIfEqual(0x92);
  34990. }
  34991. while (queue.length > 0) {
  34992. var packetItem = queue.shift();
  34993. codeblock = packetItem.codeblock;
  34994. if (codeblock['data'] === undefined) {
  34995. codeblock.data = [];
  34996. }
  34997. codeblock.data.push({
  34998. data: data,
  34999. start: offset + position,
  35000. end: offset + position + packetItem.dataLength,
  35001. codingpasses: packetItem.codingpasses
  35002. });
  35003. position += packetItem.dataLength;
  35004. }
  35005. }
  35006. return position;
  35007. }
  35008. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  35009. delta, mb, reversible, segmentationSymbolUsed) {
  35010. var x0 = subband.tbx0;
  35011. var y0 = subband.tby0;
  35012. var width = subband.tbx1 - subband.tbx0;
  35013. var codeblocks = subband.codeblocks;
  35014. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  35015. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  35016. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  35017. var codeblock = codeblocks[i];
  35018. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  35019. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  35020. if (blockWidth === 0 || blockHeight === 0) {
  35021. continue;
  35022. }
  35023. if (codeblock['data'] === undefined) {
  35024. continue;
  35025. }
  35026. var bitModel, currentCodingpassType;
  35027. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  35028. codeblock.zeroBitPlanes, mb);
  35029. currentCodingpassType = 2; // first bit plane starts from cleanup
  35030. // collect data
  35031. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  35032. var j, jj, dataItem;
  35033. for (j = 0, jj = data.length; j < jj; j++) {
  35034. dataItem = data[j];
  35035. totalLength += dataItem.end - dataItem.start;
  35036. codingpasses += dataItem.codingpasses;
  35037. }
  35038. var encodedData = new Uint8Array(totalLength);
  35039. var position = 0;
  35040. for (j = 0, jj = data.length; j < jj; j++) {
  35041. dataItem = data[j];
  35042. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  35043. encodedData.set(chunk, position);
  35044. position += chunk.length;
  35045. }
  35046. // decoding the item
  35047. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  35048. bitModel.setDecoder(decoder);
  35049. for (j = 0; j < codingpasses; j++) {
  35050. switch (currentCodingpassType) {
  35051. case 0:
  35052. bitModel.runSignificancePropogationPass();
  35053. break;
  35054. case 1:
  35055. bitModel.runMagnitudeRefinementPass();
  35056. break;
  35057. case 2:
  35058. bitModel.runCleanupPass();
  35059. if (segmentationSymbolUsed) {
  35060. bitModel.checkSegmentationSymbol();
  35061. }
  35062. break;
  35063. }
  35064. currentCodingpassType = (currentCodingpassType + 1) % 3;
  35065. }
  35066. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  35067. var sign = bitModel.coefficentsSign;
  35068. var magnitude = bitModel.coefficentsMagnitude;
  35069. var bitsDecoded = bitModel.bitsDecoded;
  35070. var magnitudeCorrection = reversible ? 0 : 0.5;
  35071. var k, n, nb;
  35072. position = 0;
  35073. // Do the interleaving of Section F.3.3 here, so we do not need
  35074. // to copy later. LL level is not interleaved, just copied.
  35075. var interleave = (subband.type !== 'LL');
  35076. for (j = 0; j < blockHeight; j++) {
  35077. var row = (offset / width) | 0; // row in the non-interleaved subband
  35078. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  35079. for (k = 0; k < blockWidth; k++) {
  35080. n = magnitude[position];
  35081. if (n !== 0) {
  35082. n = (n + magnitudeCorrection) * delta;
  35083. if (sign[position] !== 0) {
  35084. n = -n;
  35085. }
  35086. nb = bitsDecoded[position];
  35087. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  35088. if (reversible && (nb >= mb)) {
  35089. coefficients[pos] = n;
  35090. } else {
  35091. coefficients[pos] = n * (1 << (mb - nb));
  35092. }
  35093. }
  35094. offset++;
  35095. position++;
  35096. }
  35097. offset += width - blockWidth;
  35098. }
  35099. }
  35100. }
  35101. function transformTile(context, tile, c) {
  35102. var component = tile.components[c];
  35103. var codingStyleParameters = component.codingStyleParameters;
  35104. var quantizationParameters = component.quantizationParameters;
  35105. var decompositionLevelsCount =
  35106. codingStyleParameters.decompositionLevelsCount;
  35107. var spqcds = quantizationParameters.SPqcds;
  35108. var scalarExpounded = quantizationParameters.scalarExpounded;
  35109. var guardBits = quantizationParameters.guardBits;
  35110. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  35111. var precision = context.components[c].precision;
  35112. var reversible = codingStyleParameters.reversibleTransformation;
  35113. var transform = (reversible ? new ReversibleTransform() :
  35114. new IrreversibleTransform());
  35115. var subbandCoefficients = [];
  35116. var b = 0;
  35117. for (var i = 0; i <= decompositionLevelsCount; i++) {
  35118. var resolution = component.resolutions[i];
  35119. var width = resolution.trx1 - resolution.trx0;
  35120. var height = resolution.try1 - resolution.try0;
  35121. // Allocate space for the whole sublevel.
  35122. var coefficients = new Float32Array(width * height);
  35123. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  35124. var mu, epsilon;
  35125. if (!scalarExpounded) {
  35126. // formula E-5
  35127. mu = spqcds[0].mu;
  35128. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  35129. } else {
  35130. mu = spqcds[b].mu;
  35131. epsilon = spqcds[b].epsilon;
  35132. b++;
  35133. }
  35134. var subband = resolution.subbands[j];
  35135. var gainLog2 = SubbandsGainLog2[subband.type];
  35136. // calulate quantization coefficient (Section E.1.1.1)
  35137. var delta = (reversible ? 1 :
  35138. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  35139. var mb = (guardBits + epsilon - 1);
  35140. // In the first resolution level, copyCoefficients will fill the
  35141. // whole array with coefficients. In the succeding passes,
  35142. // copyCoefficients will consecutively fill in the values that belong
  35143. // to the interleaved positions of the HL, LH, and HH coefficients.
  35144. // The LL coefficients will then be interleaved in Transform.iterate().
  35145. copyCoefficients(coefficients, width, height, subband, delta, mb,
  35146. reversible, segmentationSymbolUsed);
  35147. }
  35148. subbandCoefficients.push({
  35149. width: width,
  35150. height: height,
  35151. items: coefficients
  35152. });
  35153. }
  35154. var result = transform.calculate(subbandCoefficients,
  35155. component.tcx0, component.tcy0);
  35156. return {
  35157. left: component.tcx0,
  35158. top: component.tcy0,
  35159. width: result.width,
  35160. height: result.height,
  35161. items: result.items
  35162. };
  35163. }
  35164. function transformComponents(context) {
  35165. var siz = context.SIZ;
  35166. var components = context.components;
  35167. var componentsCount = siz.Csiz;
  35168. var resultImages = [];
  35169. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  35170. var tile = context.tiles[i];
  35171. var transformedTiles = [];
  35172. var c;
  35173. for (c = 0; c < componentsCount; c++) {
  35174. transformedTiles[c] = transformTile(context, tile, c);
  35175. }
  35176. var tile0 = transformedTiles[0];
  35177. var out = new Uint8Array(tile0.items.length * componentsCount);
  35178. var result = {
  35179. left: tile0.left,
  35180. top: tile0.top,
  35181. width: tile0.width,
  35182. height: tile0.height,
  35183. items: out
  35184. };
  35185. // Section G.2.2 Inverse multi component transform
  35186. var shift, offset, max, min, maxK;
  35187. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  35188. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  35189. var fourComponents = componentsCount === 4;
  35190. var y0items = transformedTiles[0].items;
  35191. var y1items = transformedTiles[1].items;
  35192. var y2items = transformedTiles[2].items;
  35193. var y3items = fourComponents ? transformedTiles[3].items : null;
  35194. // HACK: The multiple component transform formulas below assume that
  35195. // all components have the same precision. With this in mind, we
  35196. // compute shift and offset only once.
  35197. shift = components[0].precision - 8;
  35198. offset = (128 << shift) + 0.5;
  35199. max = 255 * (1 << shift);
  35200. maxK = max * 0.5;
  35201. min = -maxK;
  35202. var component0 = tile.components[0];
  35203. var alpha01 = componentsCount - 3;
  35204. jj = y0items.length;
  35205. if (!component0.codingStyleParameters.reversibleTransformation) {
  35206. // inverse irreversible multiple component transform
  35207. for (j = 0; j < jj; j++, pos += alpha01) {
  35208. y0 = y0items[j] + offset;
  35209. y1 = y1items[j];
  35210. y2 = y2items[j];
  35211. r = y0 + 1.402 * y2;
  35212. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  35213. b = y0 + 1.772 * y1;
  35214. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  35215. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  35216. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  35217. }
  35218. } else {
  35219. // inverse reversible multiple component transform
  35220. for (j = 0; j < jj; j++, pos += alpha01) {
  35221. y0 = y0items[j] + offset;
  35222. y1 = y1items[j];
  35223. y2 = y2items[j];
  35224. g = y0 - ((y2 + y1) >> 2);
  35225. r = g + y2;
  35226. b = g + y1;
  35227. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  35228. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  35229. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  35230. }
  35231. }
  35232. if (fourComponents) {
  35233. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  35234. k = y3items[j];
  35235. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  35236. }
  35237. }
  35238. } else { // no multi-component transform
  35239. for (c = 0; c < componentsCount; c++) {
  35240. var items = transformedTiles[c].items;
  35241. shift = components[c].precision - 8;
  35242. offset = (128 << shift) + 0.5;
  35243. max = (127.5 * (1 << shift));
  35244. min = -max;
  35245. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  35246. val = items[j];
  35247. out[pos] = val <= min ? 0 :
  35248. val >= max ? 255 : (val + offset) >> shift;
  35249. pos += componentsCount;
  35250. }
  35251. }
  35252. }
  35253. resultImages.push(result);
  35254. }
  35255. return resultImages;
  35256. }
  35257. function initializeTile(context, tileIndex) {
  35258. var siz = context.SIZ;
  35259. var componentsCount = siz.Csiz;
  35260. var tile = context.tiles[tileIndex];
  35261. for (var c = 0; c < componentsCount; c++) {
  35262. var component = tile.components[c];
  35263. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  35264. context.currentTile.QCC[c] : context.currentTile.QCD);
  35265. component.quantizationParameters = qcdOrQcc;
  35266. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  35267. context.currentTile.COC[c] : context.currentTile.COD);
  35268. component.codingStyleParameters = codOrCoc;
  35269. }
  35270. tile.codingStyleDefaultParameters = context.currentTile.COD;
  35271. }
  35272. // Section B.10.2 Tag trees
  35273. var TagTree = (function TagTreeClosure() {
  35274. function TagTree(width, height) {
  35275. var levelsLength = log2(Math.max(width, height)) + 1;
  35276. this.levels = [];
  35277. for (var i = 0; i < levelsLength; i++) {
  35278. var level = {
  35279. width: width,
  35280. height: height,
  35281. items: []
  35282. };
  35283. this.levels.push(level);
  35284. width = Math.ceil(width / 2);
  35285. height = Math.ceil(height / 2);
  35286. }
  35287. }
  35288. TagTree.prototype = {
  35289. reset: function TagTree_reset(i, j) {
  35290. var currentLevel = 0, value = 0, level;
  35291. while (currentLevel < this.levels.length) {
  35292. level = this.levels[currentLevel];
  35293. var index = i + j * level.width;
  35294. if (level.items[index] !== undefined) {
  35295. value = level.items[index];
  35296. break;
  35297. }
  35298. level.index = index;
  35299. i >>= 1;
  35300. j >>= 1;
  35301. currentLevel++;
  35302. }
  35303. currentLevel--;
  35304. level = this.levels[currentLevel];
  35305. level.items[level.index] = value;
  35306. this.currentLevel = currentLevel;
  35307. delete this.value;
  35308. },
  35309. incrementValue: function TagTree_incrementValue() {
  35310. var level = this.levels[this.currentLevel];
  35311. level.items[level.index]++;
  35312. },
  35313. nextLevel: function TagTree_nextLevel() {
  35314. var currentLevel = this.currentLevel;
  35315. var level = this.levels[currentLevel];
  35316. var value = level.items[level.index];
  35317. currentLevel--;
  35318. if (currentLevel < 0) {
  35319. this.value = value;
  35320. return false;
  35321. }
  35322. this.currentLevel = currentLevel;
  35323. level = this.levels[currentLevel];
  35324. level.items[level.index] = value;
  35325. return true;
  35326. }
  35327. };
  35328. return TagTree;
  35329. })();
  35330. var InclusionTree = (function InclusionTreeClosure() {
  35331. function InclusionTree(width, height, defaultValue) {
  35332. var levelsLength = log2(Math.max(width, height)) + 1;
  35333. this.levels = [];
  35334. for (var i = 0; i < levelsLength; i++) {
  35335. var items = new Uint8Array(width * height);
  35336. for (var j = 0, jj = items.length; j < jj; j++) {
  35337. items[j] = defaultValue;
  35338. }
  35339. var level = {
  35340. width: width,
  35341. height: height,
  35342. items: items
  35343. };
  35344. this.levels.push(level);
  35345. width = Math.ceil(width / 2);
  35346. height = Math.ceil(height / 2);
  35347. }
  35348. }
  35349. InclusionTree.prototype = {
  35350. reset: function InclusionTree_reset(i, j, stopValue) {
  35351. var currentLevel = 0;
  35352. while (currentLevel < this.levels.length) {
  35353. var level = this.levels[currentLevel];
  35354. var index = i + j * level.width;
  35355. level.index = index;
  35356. var value = level.items[index];
  35357. if (value === 0xFF) {
  35358. break;
  35359. }
  35360. if (value > stopValue) {
  35361. this.currentLevel = currentLevel;
  35362. // already know about this one, propagating the value to top levels
  35363. this.propagateValues();
  35364. return false;
  35365. }
  35366. i >>= 1;
  35367. j >>= 1;
  35368. currentLevel++;
  35369. }
  35370. this.currentLevel = currentLevel - 1;
  35371. return true;
  35372. },
  35373. incrementValue: function InclusionTree_incrementValue(stopValue) {
  35374. var level = this.levels[this.currentLevel];
  35375. level.items[level.index] = stopValue + 1;
  35376. this.propagateValues();
  35377. },
  35378. propagateValues: function InclusionTree_propagateValues() {
  35379. var levelIndex = this.currentLevel;
  35380. var level = this.levels[levelIndex];
  35381. var currentValue = level.items[level.index];
  35382. while (--levelIndex >= 0) {
  35383. level = this.levels[levelIndex];
  35384. level.items[level.index] = currentValue;
  35385. }
  35386. },
  35387. nextLevel: function InclusionTree_nextLevel() {
  35388. var currentLevel = this.currentLevel;
  35389. var level = this.levels[currentLevel];
  35390. var value = level.items[level.index];
  35391. level.items[level.index] = 0xFF;
  35392. currentLevel--;
  35393. if (currentLevel < 0) {
  35394. return false;
  35395. }
  35396. this.currentLevel = currentLevel;
  35397. level = this.levels[currentLevel];
  35398. level.items[level.index] = value;
  35399. return true;
  35400. }
  35401. };
  35402. return InclusionTree;
  35403. })();
  35404. // Section D. Coefficient bit modeling
  35405. var BitModel = (function BitModelClosure() {
  35406. var UNIFORM_CONTEXT = 17;
  35407. var RUNLENGTH_CONTEXT = 18;
  35408. // Table D-1
  35409. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  35410. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  35411. var LLAndLHContextsLabel = new Uint8Array([
  35412. 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,
  35413. 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,
  35414. 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
  35415. ]);
  35416. var HLContextLabel = new Uint8Array([
  35417. 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,
  35418. 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,
  35419. 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
  35420. ]);
  35421. var HHContextLabel = new Uint8Array([
  35422. 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,
  35423. 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,
  35424. 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
  35425. ]);
  35426. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  35427. this.width = width;
  35428. this.height = height;
  35429. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  35430. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  35431. var coefficientCount = width * height;
  35432. // coefficients outside the encoding region treated as insignificant
  35433. // add border state cells for significanceState
  35434. this.neighborsSignificance = new Uint8Array(coefficientCount);
  35435. this.coefficentsSign = new Uint8Array(coefficientCount);
  35436. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  35437. mb > 6 ? new Uint16Array(coefficientCount) :
  35438. new Uint8Array(coefficientCount);
  35439. this.processingFlags = new Uint8Array(coefficientCount);
  35440. var bitsDecoded = new Uint8Array(coefficientCount);
  35441. if (zeroBitPlanes !== 0) {
  35442. for (var i = 0; i < coefficientCount; i++) {
  35443. bitsDecoded[i] = zeroBitPlanes;
  35444. }
  35445. }
  35446. this.bitsDecoded = bitsDecoded;
  35447. this.reset();
  35448. }
  35449. BitModel.prototype = {
  35450. setDecoder: function BitModel_setDecoder(decoder) {
  35451. this.decoder = decoder;
  35452. },
  35453. reset: function BitModel_reset() {
  35454. // We have 17 contexts that are accessed via context labels,
  35455. // plus the uniform and runlength context.
  35456. this.contexts = new Int8Array(19);
  35457. // Contexts are packed into 1 byte:
  35458. // highest 7 bits carry the index, lowest bit carries mps
  35459. this.contexts[0] = (4 << 1) | 0;
  35460. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  35461. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  35462. },
  35463. setNeighborsSignificance:
  35464. function BitModel_setNeighborsSignificance(row, column, index) {
  35465. var neighborsSignificance = this.neighborsSignificance;
  35466. var width = this.width, height = this.height;
  35467. var left = (column > 0);
  35468. var right = (column + 1 < width);
  35469. var i;
  35470. if (row > 0) {
  35471. i = index - width;
  35472. if (left) {
  35473. neighborsSignificance[i - 1] += 0x10;
  35474. }
  35475. if (right) {
  35476. neighborsSignificance[i + 1] += 0x10;
  35477. }
  35478. neighborsSignificance[i] += 0x04;
  35479. }
  35480. if (row + 1 < height) {
  35481. i = index + width;
  35482. if (left) {
  35483. neighborsSignificance[i - 1] += 0x10;
  35484. }
  35485. if (right) {
  35486. neighborsSignificance[i + 1] += 0x10;
  35487. }
  35488. neighborsSignificance[i] += 0x04;
  35489. }
  35490. if (left) {
  35491. neighborsSignificance[index - 1] += 0x01;
  35492. }
  35493. if (right) {
  35494. neighborsSignificance[index + 1] += 0x01;
  35495. }
  35496. neighborsSignificance[index] |= 0x80;
  35497. },
  35498. runSignificancePropogationPass:
  35499. function BitModel_runSignificancePropogationPass() {
  35500. var decoder = this.decoder;
  35501. var width = this.width, height = this.height;
  35502. var coefficentsMagnitude = this.coefficentsMagnitude;
  35503. var coefficentsSign = this.coefficentsSign;
  35504. var neighborsSignificance = this.neighborsSignificance;
  35505. var processingFlags = this.processingFlags;
  35506. var contexts = this.contexts;
  35507. var labels = this.contextLabelTable;
  35508. var bitsDecoded = this.bitsDecoded;
  35509. var processedInverseMask = ~1;
  35510. var processedMask = 1;
  35511. var firstMagnitudeBitMask = 2;
  35512. for (var i0 = 0; i0 < height; i0 += 4) {
  35513. for (var j = 0; j < width; j++) {
  35514. var index = i0 * width + j;
  35515. for (var i1 = 0; i1 < 4; i1++, index += width) {
  35516. var i = i0 + i1;
  35517. if (i >= height) {
  35518. break;
  35519. }
  35520. // clear processed flag first
  35521. processingFlags[index] &= processedInverseMask;
  35522. if (coefficentsMagnitude[index] ||
  35523. !neighborsSignificance[index]) {
  35524. continue;
  35525. }
  35526. var contextLabel = labels[neighborsSignificance[index]];
  35527. var decision = decoder.readBit(contexts, contextLabel);
  35528. if (decision) {
  35529. var sign = this.decodeSignBit(i, j, index);
  35530. coefficentsSign[index] = sign;
  35531. coefficentsMagnitude[index] = 1;
  35532. this.setNeighborsSignificance(i, j, index);
  35533. processingFlags[index] |= firstMagnitudeBitMask;
  35534. }
  35535. bitsDecoded[index]++;
  35536. processingFlags[index] |= processedMask;
  35537. }
  35538. }
  35539. }
  35540. },
  35541. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  35542. var width = this.width, height = this.height;
  35543. var coefficentsMagnitude = this.coefficentsMagnitude;
  35544. var coefficentsSign = this.coefficentsSign;
  35545. var contribution, sign0, sign1, significance1;
  35546. var contextLabel, decoded;
  35547. // calculate horizontal contribution
  35548. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  35549. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  35550. sign1 = coefficentsSign[index + 1];
  35551. if (significance1) {
  35552. sign0 = coefficentsSign[index - 1];
  35553. contribution = 1 - sign1 - sign0;
  35554. } else {
  35555. contribution = 1 - sign1 - sign1;
  35556. }
  35557. } else if (significance1) {
  35558. sign0 = coefficentsSign[index - 1];
  35559. contribution = 1 - sign0 - sign0;
  35560. } else {
  35561. contribution = 0;
  35562. }
  35563. var horizontalContribution = 3 * contribution;
  35564. // calculate vertical contribution and combine with the horizontal
  35565. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  35566. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  35567. sign1 = coefficentsSign[index + width];
  35568. if (significance1) {
  35569. sign0 = coefficentsSign[index - width];
  35570. contribution = 1 - sign1 - sign0 + horizontalContribution;
  35571. } else {
  35572. contribution = 1 - sign1 - sign1 + horizontalContribution;
  35573. }
  35574. } else if (significance1) {
  35575. sign0 = coefficentsSign[index - width];
  35576. contribution = 1 - sign0 - sign0 + horizontalContribution;
  35577. } else {
  35578. contribution = horizontalContribution;
  35579. }
  35580. if (contribution >= 0) {
  35581. contextLabel = 9 + contribution;
  35582. decoded = this.decoder.readBit(this.contexts, contextLabel);
  35583. } else {
  35584. contextLabel = 9 - contribution;
  35585. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  35586. }
  35587. return decoded;
  35588. },
  35589. runMagnitudeRefinementPass:
  35590. function BitModel_runMagnitudeRefinementPass() {
  35591. var decoder = this.decoder;
  35592. var width = this.width, height = this.height;
  35593. var coefficentsMagnitude = this.coefficentsMagnitude;
  35594. var neighborsSignificance = this.neighborsSignificance;
  35595. var contexts = this.contexts;
  35596. var bitsDecoded = this.bitsDecoded;
  35597. var processingFlags = this.processingFlags;
  35598. var processedMask = 1;
  35599. var firstMagnitudeBitMask = 2;
  35600. var length = width * height;
  35601. var width4 = width * 4;
  35602. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35603. indexNext = Math.min(length, index0 + width4);
  35604. for (var j = 0; j < width; j++) {
  35605. for (var index = index0 + j; index < indexNext; index += width) {
  35606. // significant but not those that have just become
  35607. if (!coefficentsMagnitude[index] ||
  35608. (processingFlags[index] & processedMask) !== 0) {
  35609. continue;
  35610. }
  35611. var contextLabel = 16;
  35612. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35613. processingFlags[index] ^= firstMagnitudeBitMask;
  35614. // first refinement
  35615. var significance = neighborsSignificance[index] & 127;
  35616. contextLabel = significance === 0 ? 15 : 14;
  35617. }
  35618. var bit = decoder.readBit(contexts, contextLabel);
  35619. coefficentsMagnitude[index] =
  35620. (coefficentsMagnitude[index] << 1) | bit;
  35621. bitsDecoded[index]++;
  35622. processingFlags[index] |= processedMask;
  35623. }
  35624. }
  35625. }
  35626. },
  35627. runCleanupPass: function BitModel_runCleanupPass() {
  35628. var decoder = this.decoder;
  35629. var width = this.width, height = this.height;
  35630. var neighborsSignificance = this.neighborsSignificance;
  35631. var coefficentsMagnitude = this.coefficentsMagnitude;
  35632. var coefficentsSign = this.coefficentsSign;
  35633. var contexts = this.contexts;
  35634. var labels = this.contextLabelTable;
  35635. var bitsDecoded = this.bitsDecoded;
  35636. var processingFlags = this.processingFlags;
  35637. var processedMask = 1;
  35638. var firstMagnitudeBitMask = 2;
  35639. var oneRowDown = width;
  35640. var twoRowsDown = width * 2;
  35641. var threeRowsDown = width * 3;
  35642. var iNext;
  35643. for (var i0 = 0; i0 < height; i0 = iNext) {
  35644. iNext = Math.min(i0 + 4, height);
  35645. var indexBase = i0 * width;
  35646. var checkAllEmpty = i0 + 3 < height;
  35647. for (var j = 0; j < width; j++) {
  35648. var index0 = indexBase + j;
  35649. // using the property: labels[neighborsSignificance[index]] === 0
  35650. // when neighborsSignificance[index] === 0
  35651. var allEmpty = (checkAllEmpty &&
  35652. processingFlags[index0] === 0 &&
  35653. processingFlags[index0 + oneRowDown] === 0 &&
  35654. processingFlags[index0 + twoRowsDown] === 0 &&
  35655. processingFlags[index0 + threeRowsDown] === 0 &&
  35656. neighborsSignificance[index0] === 0 &&
  35657. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35658. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35659. neighborsSignificance[index0 + threeRowsDown] === 0);
  35660. var i1 = 0, index = index0;
  35661. var i = i0, sign;
  35662. if (allEmpty) {
  35663. var hasSignificantCoefficent =
  35664. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35665. if (!hasSignificantCoefficent) {
  35666. bitsDecoded[index0]++;
  35667. bitsDecoded[index0 + oneRowDown]++;
  35668. bitsDecoded[index0 + twoRowsDown]++;
  35669. bitsDecoded[index0 + threeRowsDown]++;
  35670. continue; // next column
  35671. }
  35672. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35673. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35674. if (i1 !== 0) {
  35675. i = i0 + i1;
  35676. index += i1 * width;
  35677. }
  35678. sign = this.decodeSignBit(i, j, index);
  35679. coefficentsSign[index] = sign;
  35680. coefficentsMagnitude[index] = 1;
  35681. this.setNeighborsSignificance(i, j, index);
  35682. processingFlags[index] |= firstMagnitudeBitMask;
  35683. index = index0;
  35684. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35685. bitsDecoded[index]++;
  35686. }
  35687. i1++;
  35688. }
  35689. for (i = i0 + i1; i < iNext; i++, index += width) {
  35690. if (coefficentsMagnitude[index] ||
  35691. (processingFlags[index] & processedMask) !== 0) {
  35692. continue;
  35693. }
  35694. var contextLabel = labels[neighborsSignificance[index]];
  35695. var decision = decoder.readBit(contexts, contextLabel);
  35696. if (decision === 1) {
  35697. sign = this.decodeSignBit(i, j, index);
  35698. coefficentsSign[index] = sign;
  35699. coefficentsMagnitude[index] = 1;
  35700. this.setNeighborsSignificance(i, j, index);
  35701. processingFlags[index] |= firstMagnitudeBitMask;
  35702. }
  35703. bitsDecoded[index]++;
  35704. }
  35705. }
  35706. }
  35707. },
  35708. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35709. var decoder = this.decoder;
  35710. var contexts = this.contexts;
  35711. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35712. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35713. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35714. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35715. if (symbol !== 0xA) {
  35716. throw new Error('JPX Error: Invalid segmentation symbol');
  35717. }
  35718. }
  35719. };
  35720. return BitModel;
  35721. })();
  35722. // Section F, Discrete wavelet transformation
  35723. var Transform = (function TransformClosure() {
  35724. function Transform() {}
  35725. Transform.prototype.calculate =
  35726. function transformCalculate(subbands, u0, v0) {
  35727. var ll = subbands[0];
  35728. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35729. ll = this.iterate(ll, subbands[i], u0, v0);
  35730. }
  35731. return ll;
  35732. };
  35733. Transform.prototype.extend = function extend(buffer, offset, size) {
  35734. // Section F.3.7 extending... using max extension of 4
  35735. var i1 = offset - 1, j1 = offset + 1;
  35736. var i2 = offset + size - 2, j2 = offset + size;
  35737. buffer[i1--] = buffer[j1++];
  35738. buffer[j2++] = buffer[i2--];
  35739. buffer[i1--] = buffer[j1++];
  35740. buffer[j2++] = buffer[i2--];
  35741. buffer[i1--] = buffer[j1++];
  35742. buffer[j2++] = buffer[i2--];
  35743. buffer[i1] = buffer[j1];
  35744. buffer[j2] = buffer[i2];
  35745. };
  35746. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35747. u0, v0) {
  35748. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35749. var width = hl_lh_hh.width;
  35750. var height = hl_lh_hh.height;
  35751. var items = hl_lh_hh.items;
  35752. var i, j, k, l, u, v;
  35753. // Interleave LL according to Section F.3.3
  35754. for (k = 0, i = 0; i < llHeight; i++) {
  35755. l = i * 2 * width;
  35756. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35757. items[l] = llItems[k];
  35758. }
  35759. }
  35760. // The LL band is not needed anymore.
  35761. llItems = ll.items = null;
  35762. var bufferPadding = 4;
  35763. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35764. // Section F.3.4 HOR_SR
  35765. if (width === 1) {
  35766. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35767. if ((u0 & 1) !== 0) {
  35768. for (v = 0, k = 0; v < height; v++, k += width) {
  35769. items[k] *= 0.5;
  35770. }
  35771. }
  35772. } else {
  35773. for (v = 0, k = 0; v < height; v++, k += width) {
  35774. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35775. this.extend(rowBuffer, bufferPadding, width);
  35776. this.filter(rowBuffer, bufferPadding, width);
  35777. items.set(
  35778. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35779. k);
  35780. }
  35781. }
  35782. // Accesses to the items array can take long, because it may not fit into
  35783. // CPU cache and has to be fetched from main memory. Since subsequent
  35784. // accesses to the items array are not local when reading columns, we
  35785. // have a cache miss every time. To reduce cache misses, get up to
  35786. // 'numBuffers' items at a time and store them into the individual
  35787. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35788. var numBuffers = 16;
  35789. var colBuffers = [];
  35790. for (i = 0; i < numBuffers; i++) {
  35791. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35792. }
  35793. var b, currentBuffer = 0;
  35794. ll = bufferPadding + height;
  35795. // Section F.3.5 VER_SR
  35796. if (height === 1) {
  35797. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35798. if ((v0 & 1) !== 0) {
  35799. for (u = 0; u < width; u++) {
  35800. items[u] *= 0.5;
  35801. }
  35802. }
  35803. } else {
  35804. for (u = 0; u < width; u++) {
  35805. // if we ran out of buffers, copy several image columns at once
  35806. if (currentBuffer === 0) {
  35807. numBuffers = Math.min(width - u, numBuffers);
  35808. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35809. for (b = 0; b < numBuffers; b++) {
  35810. colBuffers[b][l] = items[k + b];
  35811. }
  35812. }
  35813. currentBuffer = numBuffers;
  35814. }
  35815. currentBuffer--;
  35816. var buffer = colBuffers[currentBuffer];
  35817. this.extend(buffer, bufferPadding, height);
  35818. this.filter(buffer, bufferPadding, height);
  35819. // If this is last buffer in this group of buffers, flush all buffers.
  35820. if (currentBuffer === 0) {
  35821. k = u - numBuffers + 1;
  35822. for (l = bufferPadding; l < ll; k += width, l++) {
  35823. for (b = 0; b < numBuffers; b++) {
  35824. items[k + b] = colBuffers[b][l];
  35825. }
  35826. }
  35827. }
  35828. }
  35829. }
  35830. return {
  35831. width: width,
  35832. height: height,
  35833. items: items
  35834. };
  35835. };
  35836. return Transform;
  35837. })();
  35838. // Section 3.8.2 Irreversible 9-7 filter
  35839. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35840. function IrreversibleTransform() {
  35841. Transform.call(this);
  35842. }
  35843. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35844. IrreversibleTransform.prototype.filter =
  35845. function irreversibleTransformFilter(x, offset, length) {
  35846. var len = length >> 1;
  35847. offset = offset | 0;
  35848. var j, n, current, next;
  35849. var alpha = -1.586134342059924;
  35850. var beta = -0.052980118572961;
  35851. var gamma = 0.882911075530934;
  35852. var delta = 0.443506852043971;
  35853. var K = 1.230174104914001;
  35854. var K_ = 1 / K;
  35855. // step 1 is combined with step 3
  35856. // step 2
  35857. j = offset - 3;
  35858. for (n = len + 4; n--; j += 2) {
  35859. x[j] *= K_;
  35860. }
  35861. // step 1 & 3
  35862. j = offset - 2;
  35863. current = delta * x[j -1];
  35864. for (n = len + 3; n--; j += 2) {
  35865. next = delta * x[j + 1];
  35866. x[j] = K * x[j] - current - next;
  35867. if (n--) {
  35868. j += 2;
  35869. current = delta * x[j + 1];
  35870. x[j] = K * x[j] - current - next;
  35871. } else {
  35872. break;
  35873. }
  35874. }
  35875. // step 4
  35876. j = offset - 1;
  35877. current = gamma * x[j - 1];
  35878. for (n = len + 2; n--; j += 2) {
  35879. next = gamma * x[j + 1];
  35880. x[j] -= current + next;
  35881. if (n--) {
  35882. j += 2;
  35883. current = gamma * x[j + 1];
  35884. x[j] -= current + next;
  35885. } else {
  35886. break;
  35887. }
  35888. }
  35889. // step 5
  35890. j = offset;
  35891. current = beta * x[j - 1];
  35892. for (n = len + 1; n--; j += 2) {
  35893. next = beta * x[j + 1];
  35894. x[j] -= current + next;
  35895. if (n--) {
  35896. j += 2;
  35897. current = beta * x[j + 1];
  35898. x[j] -= current + next;
  35899. } else {
  35900. break;
  35901. }
  35902. }
  35903. // step 6
  35904. if (len !== 0) {
  35905. j = offset + 1;
  35906. current = alpha * x[j - 1];
  35907. for (n = len; n--; j += 2) {
  35908. next = alpha * x[j + 1];
  35909. x[j] -= current + next;
  35910. if (n--) {
  35911. j += 2;
  35912. current = alpha * x[j + 1];
  35913. x[j] -= current + next;
  35914. } else {
  35915. break;
  35916. }
  35917. }
  35918. }
  35919. };
  35920. return IrreversibleTransform;
  35921. })();
  35922. // Section 3.8.1 Reversible 5-3 filter
  35923. var ReversibleTransform = (function ReversibleTransformClosure() {
  35924. function ReversibleTransform() {
  35925. Transform.call(this);
  35926. }
  35927. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35928. ReversibleTransform.prototype.filter =
  35929. function reversibleTransformFilter(x, offset, length) {
  35930. var len = length >> 1;
  35931. offset = offset | 0;
  35932. var j, n;
  35933. for (j = offset, n = len + 1; n--; j += 2) {
  35934. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35935. }
  35936. for (j = offset + 1, n = len; n--; j += 2) {
  35937. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35938. }
  35939. };
  35940. return ReversibleTransform;
  35941. })();
  35942. return JpxImage;
  35943. })();
  35944. var Jbig2Image = (function Jbig2ImageClosure() {
  35945. // Utility data structures
  35946. function ContextCache() {}
  35947. ContextCache.prototype = {
  35948. getContexts: function(id) {
  35949. if (id in this) {
  35950. return this[id];
  35951. }
  35952. return (this[id] = new Int8Array(1 << 16));
  35953. }
  35954. };
  35955. function DecodingContext(data, start, end) {
  35956. this.data = data;
  35957. this.start = start;
  35958. this.end = end;
  35959. }
  35960. DecodingContext.prototype = {
  35961. get decoder() {
  35962. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35963. return shadow(this, 'decoder', decoder);
  35964. },
  35965. get contextCache() {
  35966. var cache = new ContextCache();
  35967. return shadow(this, 'contextCache', cache);
  35968. }
  35969. };
  35970. // Annex A. Arithmetic Integer Decoding Procedure
  35971. // A.2 Procedure for decoding values
  35972. function decodeInteger(contextCache, procedure, decoder) {
  35973. var contexts = contextCache.getContexts(procedure);
  35974. var prev = 1;
  35975. function readBits(length) {
  35976. var v = 0;
  35977. for (var i = 0; i < length; i++) {
  35978. var bit = decoder.readBit(contexts, prev);
  35979. prev = (prev < 256 ? (prev << 1) | bit :
  35980. (((prev << 1) | bit) & 511) | 256);
  35981. v = (v << 1) | bit;
  35982. }
  35983. return v >>> 0;
  35984. }
  35985. var sign = readBits(1);
  35986. var value = readBits(1) ?
  35987. (readBits(1) ?
  35988. (readBits(1) ?
  35989. (readBits(1) ?
  35990. (readBits(1) ?
  35991. (readBits(32) + 4436) :
  35992. readBits(12) + 340) :
  35993. readBits(8) + 84) :
  35994. readBits(6) + 20) :
  35995. readBits(4) + 4) :
  35996. readBits(2);
  35997. return (sign === 0 ? value : (value > 0 ? -value : null));
  35998. }
  35999. // A.3 The IAID decoding procedure
  36000. function decodeIAID(contextCache, decoder, codeLength) {
  36001. var contexts = contextCache.getContexts('IAID');
  36002. var prev = 1;
  36003. for (var i = 0; i < codeLength; i++) {
  36004. var bit = decoder.readBit(contexts, prev);
  36005. prev = (prev << 1) | bit;
  36006. }
  36007. if (codeLength < 31) {
  36008. return prev & ((1 << codeLength) - 1);
  36009. }
  36010. return prev & 0x7FFFFFFF;
  36011. }
  36012. // 7.3 Segment types
  36013. var SegmentTypes = [
  36014. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  36015. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  36016. null, null, null, null, null, 'patternDictionary', null, null, null,
  36017. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  36018. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  36019. null, null, null, null, null, 'IntermediateGenericRegion', null,
  36020. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  36021. 'IntermediateGenericRefinementRegion', null,
  36022. 'ImmediateGenericRefinementRegion',
  36023. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  36024. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  36025. 'Tables', null, null, null, null, null, null, null, null,
  36026. 'Extension'
  36027. ];
  36028. var CodingTemplates = [
  36029. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  36030. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  36031. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  36032. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  36033. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  36034. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  36035. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  36036. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  36037. {x: -1, y: 0}],
  36038. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  36039. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  36040. ];
  36041. var RefinementTemplates = [
  36042. {
  36043. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  36044. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  36045. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  36046. },
  36047. {
  36048. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  36049. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  36050. {x: 0, y: 1}, {x: 1, y: 1}]
  36051. }
  36052. ];
  36053. // See 6.2.5.7 Decoding the bitmap.
  36054. var ReusedContexts = [
  36055. 0x9B25, // 10011 0110010 0101
  36056. 0x0795, // 0011 110010 101
  36057. 0x00E5, // 001 11001 01
  36058. 0x0195 // 011001 0101
  36059. ];
  36060. var RefinementReusedContexts = [
  36061. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  36062. 0x0008 // '0000' + '001000'
  36063. ];
  36064. function decodeBitmapTemplate0(width, height, decodingContext) {
  36065. var decoder = decodingContext.decoder;
  36066. var contexts = decodingContext.contextCache.getContexts('GB');
  36067. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  36068. // ...ooooo....
  36069. // ..ooooooo... Context template for current pixel (X)
  36070. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  36071. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  36072. for (i = 0; i < height; i++) {
  36073. row = bitmap[i] = new Uint8Array(width);
  36074. row1 = (i < 1) ? row : bitmap[i - 1];
  36075. row2 = (i < 2) ? row : bitmap[i - 2];
  36076. // At the beginning of each row:
  36077. // Fill contextLabel with pixels that are above/right of (X)
  36078. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  36079. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  36080. (row1[3] << 4);
  36081. for (j = 0; j < width; j++) {
  36082. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  36083. // At each pixel: Clear contextLabel pixels that are shifted
  36084. // out of the context, then add new ones.
  36085. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  36086. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  36087. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  36088. }
  36089. }
  36090. return bitmap;
  36091. }
  36092. // 6.2 Generic Region Decoding Procedure
  36093. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  36094. decodingContext) {
  36095. if (mmr) {
  36096. error('JBIG2 error: MMR encoding is not supported');
  36097. }
  36098. // Use optimized version for the most common case
  36099. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  36100. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  36101. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  36102. return decodeBitmapTemplate0(width, height, decodingContext);
  36103. }
  36104. var useskip = !!skip;
  36105. var template = CodingTemplates[templateIndex].concat(at);
  36106. // Sorting is non-standard, and it is not required. But sorting increases
  36107. // the number of template bits that can be reused from the previous
  36108. // contextLabel in the main loop.
  36109. template.sort(function (a, b) {
  36110. return (a.y - b.y) || (a.x - b.x);
  36111. });
  36112. var templateLength = template.length;
  36113. var templateX = new Int8Array(templateLength);
  36114. var templateY = new Int8Array(templateLength);
  36115. var changingTemplateEntries = [];
  36116. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  36117. var c, k;
  36118. for (k = 0; k < templateLength; k++) {
  36119. templateX[k] = template[k].x;
  36120. templateY[k] = template[k].y;
  36121. minX = Math.min(minX, template[k].x);
  36122. maxX = Math.max(maxX, template[k].x);
  36123. minY = Math.min(minY, template[k].y);
  36124. // Check if the template pixel appears in two consecutive context labels,
  36125. // so it can be reused. Otherwise, we add it to the list of changing
  36126. // template entries.
  36127. if (k < templateLength - 1 &&
  36128. template[k].y === template[k + 1].y &&
  36129. template[k].x === template[k + 1].x - 1) {
  36130. reuseMask |= 1 << (templateLength - 1 - k);
  36131. } else {
  36132. changingTemplateEntries.push(k);
  36133. }
  36134. }
  36135. var changingEntriesLength = changingTemplateEntries.length;
  36136. var changingTemplateX = new Int8Array(changingEntriesLength);
  36137. var changingTemplateY = new Int8Array(changingEntriesLength);
  36138. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  36139. for (c = 0; c < changingEntriesLength; c++) {
  36140. k = changingTemplateEntries[c];
  36141. changingTemplateX[c] = template[k].x;
  36142. changingTemplateY[c] = template[k].y;
  36143. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  36144. }
  36145. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  36146. var sbb_left = -minX;
  36147. var sbb_top = -minY;
  36148. var sbb_right = width - maxX;
  36149. var pseudoPixelContext = ReusedContexts[templateIndex];
  36150. var row = new Uint8Array(width);
  36151. var bitmap = [];
  36152. var decoder = decodingContext.decoder;
  36153. var contexts = decodingContext.contextCache.getContexts('GB');
  36154. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  36155. for (var i = 0; i < height; i++) {
  36156. if (prediction) {
  36157. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  36158. ltp ^= sltp;
  36159. if (ltp) {
  36160. bitmap.push(row); // duplicate previous row
  36161. continue;
  36162. }
  36163. }
  36164. row = new Uint8Array(row);
  36165. bitmap.push(row);
  36166. for (j = 0; j < width; j++) {
  36167. if (useskip && skip[i][j]) {
  36168. row[j] = 0;
  36169. continue;
  36170. }
  36171. // Are we in the middle of a scanline, so we can reuse contextLabel
  36172. // bits?
  36173. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  36174. // If yes, we can just shift the bits that are reusable and only
  36175. // fetch the remaining ones.
  36176. contextLabel = (contextLabel << 1) & reuseMask;
  36177. for (k = 0; k < changingEntriesLength; k++) {
  36178. i0 = i + changingTemplateY[k];
  36179. j0 = j + changingTemplateX[k];
  36180. bit = bitmap[i0][j0];
  36181. if (bit) {
  36182. bit = changingTemplateBit[k];
  36183. contextLabel |= bit;
  36184. }
  36185. }
  36186. } else {
  36187. // compute the contextLabel from scratch
  36188. contextLabel = 0;
  36189. shift = templateLength - 1;
  36190. for (k = 0; k < templateLength; k++, shift--) {
  36191. j0 = j + templateX[k];
  36192. if (j0 >= 0 && j0 < width) {
  36193. i0 = i + templateY[k];
  36194. if (i0 >= 0) {
  36195. bit = bitmap[i0][j0];
  36196. if (bit) {
  36197. contextLabel |= bit << shift;
  36198. }
  36199. }
  36200. }
  36201. }
  36202. }
  36203. var pixel = decoder.readBit(contexts, contextLabel);
  36204. row[j] = pixel;
  36205. }
  36206. }
  36207. return bitmap;
  36208. }
  36209. // 6.3.2 Generic Refinement Region Decoding Procedure
  36210. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  36211. offsetX, offsetY, prediction, at,
  36212. decodingContext) {
  36213. var codingTemplate = RefinementTemplates[templateIndex].coding;
  36214. if (templateIndex === 0) {
  36215. codingTemplate = codingTemplate.concat([at[0]]);
  36216. }
  36217. var codingTemplateLength = codingTemplate.length;
  36218. var codingTemplateX = new Int32Array(codingTemplateLength);
  36219. var codingTemplateY = new Int32Array(codingTemplateLength);
  36220. var k;
  36221. for (k = 0; k < codingTemplateLength; k++) {
  36222. codingTemplateX[k] = codingTemplate[k].x;
  36223. codingTemplateY[k] = codingTemplate[k].y;
  36224. }
  36225. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  36226. if (templateIndex === 0) {
  36227. referenceTemplate = referenceTemplate.concat([at[1]]);
  36228. }
  36229. var referenceTemplateLength = referenceTemplate.length;
  36230. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  36231. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  36232. for (k = 0; k < referenceTemplateLength; k++) {
  36233. referenceTemplateX[k] = referenceTemplate[k].x;
  36234. referenceTemplateY[k] = referenceTemplate[k].y;
  36235. }
  36236. var referenceWidth = referenceBitmap[0].length;
  36237. var referenceHeight = referenceBitmap.length;
  36238. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  36239. var bitmap = [];
  36240. var decoder = decodingContext.decoder;
  36241. var contexts = decodingContext.contextCache.getContexts('GR');
  36242. var ltp = 0;
  36243. for (var i = 0; i < height; i++) {
  36244. if (prediction) {
  36245. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  36246. ltp ^= sltp;
  36247. if (ltp) {
  36248. error('JBIG2 error: prediction is not supported');
  36249. }
  36250. }
  36251. var row = new Uint8Array(width);
  36252. bitmap.push(row);
  36253. for (var j = 0; j < width; j++) {
  36254. var i0, j0;
  36255. var contextLabel = 0;
  36256. for (k = 0; k < codingTemplateLength; k++) {
  36257. i0 = i + codingTemplateY[k];
  36258. j0 = j + codingTemplateX[k];
  36259. if (i0 < 0 || j0 < 0 || j0 >= width) {
  36260. contextLabel <<= 1; // out of bound pixel
  36261. } else {
  36262. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  36263. }
  36264. }
  36265. for (k = 0; k < referenceTemplateLength; k++) {
  36266. i0 = i + referenceTemplateY[k] + offsetY;
  36267. j0 = j + referenceTemplateX[k] + offsetX;
  36268. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  36269. j0 >= referenceWidth) {
  36270. contextLabel <<= 1; // out of bound pixel
  36271. } else {
  36272. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  36273. }
  36274. }
  36275. var pixel = decoder.readBit(contexts, contextLabel);
  36276. row[j] = pixel;
  36277. }
  36278. }
  36279. return bitmap;
  36280. }
  36281. // 6.5.5 Decoding the symbol dictionary
  36282. function decodeSymbolDictionary(huffman, refinement, symbols,
  36283. numberOfNewSymbols, numberOfExportedSymbols,
  36284. huffmanTables, templateIndex, at,
  36285. refinementTemplateIndex, refinementAt,
  36286. decodingContext) {
  36287. if (huffman) {
  36288. error('JBIG2 error: huffman is not supported');
  36289. }
  36290. var newSymbols = [];
  36291. var currentHeight = 0;
  36292. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  36293. var decoder = decodingContext.decoder;
  36294. var contextCache = decodingContext.contextCache;
  36295. while (newSymbols.length < numberOfNewSymbols) {
  36296. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  36297. currentHeight += deltaHeight;
  36298. var currentWidth = 0;
  36299. var totalWidth = 0;
  36300. while (true) {
  36301. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  36302. if (deltaWidth === null) {
  36303. break; // OOB
  36304. }
  36305. currentWidth += deltaWidth;
  36306. totalWidth += currentWidth;
  36307. var bitmap;
  36308. if (refinement) {
  36309. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  36310. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  36311. if (numberOfInstances > 1) {
  36312. bitmap = decodeTextRegion(huffman, refinement,
  36313. currentWidth, currentHeight, 0,
  36314. numberOfInstances, 1, //strip size
  36315. symbols.concat(newSymbols),
  36316. symbolCodeLength,
  36317. 0, //transposed
  36318. 0, //ds offset
  36319. 1, //top left 7.4.3.1.1
  36320. 0, //OR operator
  36321. huffmanTables,
  36322. refinementTemplateIndex, refinementAt,
  36323. decodingContext);
  36324. } else {
  36325. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36326. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36327. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36328. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  36329. newSymbols[symbolId - symbols.length]);
  36330. bitmap = decodeRefinement(currentWidth, currentHeight,
  36331. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  36332. decodingContext);
  36333. }
  36334. } else {
  36335. // 6.5.8.1 Direct-coded symbol bitmap
  36336. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  36337. templateIndex, false, null, at, decodingContext);
  36338. }
  36339. newSymbols.push(bitmap);
  36340. }
  36341. }
  36342. // 6.5.10 Exported symbols
  36343. var exportedSymbols = [];
  36344. var flags = [], currentFlag = false;
  36345. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  36346. while (flags.length < totalSymbolsLength) {
  36347. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  36348. while (runLength--) {
  36349. flags.push(currentFlag);
  36350. }
  36351. currentFlag = !currentFlag;
  36352. }
  36353. for (var i = 0, ii = symbols.length; i < ii; i++) {
  36354. if (flags[i]) {
  36355. exportedSymbols.push(symbols[i]);
  36356. }
  36357. }
  36358. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  36359. if (flags[i]) {
  36360. exportedSymbols.push(newSymbols[j]);
  36361. }
  36362. }
  36363. return exportedSymbols;
  36364. }
  36365. function decodeTextRegion(huffman, refinement, width, height,
  36366. defaultPixelValue, numberOfSymbolInstances,
  36367. stripSize, inputSymbols, symbolCodeLength,
  36368. transposed, dsOffset, referenceCorner,
  36369. combinationOperator, huffmanTables,
  36370. refinementTemplateIndex, refinementAt,
  36371. decodingContext) {
  36372. if (huffman) {
  36373. error('JBIG2 error: huffman is not supported');
  36374. }
  36375. // Prepare bitmap
  36376. var bitmap = [];
  36377. var i, row;
  36378. for (i = 0; i < height; i++) {
  36379. row = new Uint8Array(width);
  36380. if (defaultPixelValue) {
  36381. for (var j = 0; j < width; j++) {
  36382. row[j] = defaultPixelValue;
  36383. }
  36384. }
  36385. bitmap.push(row);
  36386. }
  36387. var decoder = decodingContext.decoder;
  36388. var contextCache = decodingContext.contextCache;
  36389. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36390. var firstS = 0;
  36391. i = 0;
  36392. while (i < numberOfSymbolInstances) {
  36393. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36394. stripT += deltaT;
  36395. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  36396. firstS += deltaFirstS;
  36397. var currentS = firstS;
  36398. do {
  36399. var currentT = (stripSize === 1 ? 0 :
  36400. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  36401. var t = stripSize * stripT + currentT;
  36402. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36403. var applyRefinement = (refinement &&
  36404. decodeInteger(contextCache, 'IARI', decoder));
  36405. var symbolBitmap = inputSymbols[symbolId];
  36406. var symbolWidth = symbolBitmap[0].length;
  36407. var symbolHeight = symbolBitmap.length;
  36408. if (applyRefinement) {
  36409. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  36410. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  36411. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36412. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36413. symbolWidth += rdw;
  36414. symbolHeight += rdh;
  36415. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  36416. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  36417. (rdh >> 1) + rdy, false, refinementAt,
  36418. decodingContext);
  36419. }
  36420. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  36421. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  36422. var s2, t2, symbolRow;
  36423. if (transposed) {
  36424. // Place Symbol Bitmap from T1,S1
  36425. for (s2 = 0; s2 < symbolHeight; s2++) {
  36426. row = bitmap[offsetS + s2];
  36427. if (!row) {
  36428. continue;
  36429. }
  36430. symbolRow = symbolBitmap[s2];
  36431. // To ignore Parts of Symbol bitmap which goes
  36432. // outside bitmap region
  36433. var maxWidth = Math.min(width - offsetT, symbolWidth);
  36434. switch (combinationOperator) {
  36435. case 0: // OR
  36436. for (t2 = 0; t2 < maxWidth; t2++) {
  36437. row[offsetT + t2] |= symbolRow[t2];
  36438. }
  36439. break;
  36440. case 2: // XOR
  36441. for (t2 = 0; t2 < maxWidth; t2++) {
  36442. row[offsetT + t2] ^= symbolRow[t2];
  36443. }
  36444. break;
  36445. default:
  36446. error('JBIG2 error: operator ' + combinationOperator +
  36447. ' is not supported');
  36448. }
  36449. }
  36450. currentS += symbolHeight - 1;
  36451. } else {
  36452. for (t2 = 0; t2 < symbolHeight; t2++) {
  36453. row = bitmap[offsetT + t2];
  36454. if (!row) {
  36455. continue;
  36456. }
  36457. symbolRow = symbolBitmap[t2];
  36458. switch (combinationOperator) {
  36459. case 0: // OR
  36460. for (s2 = 0; s2 < symbolWidth; s2++) {
  36461. row[offsetS + s2] |= symbolRow[s2];
  36462. }
  36463. break;
  36464. case 2: // XOR
  36465. for (s2 = 0; s2 < symbolWidth; s2++) {
  36466. row[offsetS + s2] ^= symbolRow[s2];
  36467. }
  36468. break;
  36469. default:
  36470. error('JBIG2 error: operator ' + combinationOperator +
  36471. ' is not supported');
  36472. }
  36473. }
  36474. currentS += symbolWidth - 1;
  36475. }
  36476. i++;
  36477. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  36478. if (deltaS === null) {
  36479. break; // OOB
  36480. }
  36481. currentS += deltaS + dsOffset;
  36482. } while (true);
  36483. }
  36484. return bitmap;
  36485. }
  36486. function readSegmentHeader(data, start) {
  36487. var segmentHeader = {};
  36488. segmentHeader.number = readUint32(data, start);
  36489. var flags = data[start + 4];
  36490. var segmentType = flags & 0x3F;
  36491. if (!SegmentTypes[segmentType]) {
  36492. error('JBIG2 error: invalid segment type: ' + segmentType);
  36493. }
  36494. segmentHeader.type = segmentType;
  36495. segmentHeader.typeName = SegmentTypes[segmentType];
  36496. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  36497. var pageAssociationFieldSize = !!(flags & 0x40);
  36498. var referredFlags = data[start + 5];
  36499. var referredToCount = (referredFlags >> 5) & 7;
  36500. var retainBits = [referredFlags & 31];
  36501. var position = start + 6;
  36502. if (referredFlags === 7) {
  36503. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  36504. position += 3;
  36505. var bytes = (referredToCount + 7) >> 3;
  36506. retainBits[0] = data[position++];
  36507. while (--bytes > 0) {
  36508. retainBits.push(data[position++]);
  36509. }
  36510. } else if (referredFlags === 5 || referredFlags === 6) {
  36511. error('JBIG2 error: invalid referred-to flags');
  36512. }
  36513. segmentHeader.retainBits = retainBits;
  36514. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  36515. (segmentHeader.number <= 65536 ? 2 : 4));
  36516. var referredTo = [];
  36517. var i, ii;
  36518. for (i = 0; i < referredToCount; i++) {
  36519. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  36520. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  36521. readUint32(data, position)));
  36522. referredTo.push(number);
  36523. position += referredToSegmentNumberSize;
  36524. }
  36525. segmentHeader.referredTo = referredTo;
  36526. if (!pageAssociationFieldSize) {
  36527. segmentHeader.pageAssociation = data[position++];
  36528. } else {
  36529. segmentHeader.pageAssociation = readUint32(data, position);
  36530. position += 4;
  36531. }
  36532. segmentHeader.length = readUint32(data, position);
  36533. position += 4;
  36534. if (segmentHeader.length === 0xFFFFFFFF) {
  36535. // 7.2.7 Segment data length, unknown segment length
  36536. if (segmentType === 38) { // ImmediateGenericRegion
  36537. var genericRegionInfo = readRegionSegmentInformation(data, position);
  36538. var genericRegionSegmentFlags = data[position +
  36539. RegionSegmentInformationFieldLength];
  36540. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  36541. // searching for the segment end
  36542. var searchPatternLength = 6;
  36543. var searchPattern = new Uint8Array(searchPatternLength);
  36544. if (!genericRegionMmr) {
  36545. searchPattern[0] = 0xFF;
  36546. searchPattern[1] = 0xAC;
  36547. }
  36548. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  36549. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  36550. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  36551. searchPattern[5] = genericRegionInfo.height & 0xFF;
  36552. for (i = position, ii = data.length; i < ii; i++) {
  36553. var j = 0;
  36554. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  36555. j++;
  36556. }
  36557. if (j === searchPatternLength) {
  36558. segmentHeader.length = i + searchPatternLength;
  36559. break;
  36560. }
  36561. }
  36562. if (segmentHeader.length === 0xFFFFFFFF) {
  36563. error('JBIG2 error: segment end was not found');
  36564. }
  36565. } else {
  36566. error('JBIG2 error: invalid unknown segment length');
  36567. }
  36568. }
  36569. segmentHeader.headerEnd = position;
  36570. return segmentHeader;
  36571. }
  36572. function readSegments(header, data, start, end) {
  36573. var segments = [];
  36574. var position = start;
  36575. while (position < end) {
  36576. var segmentHeader = readSegmentHeader(data, position);
  36577. position = segmentHeader.headerEnd;
  36578. var segment = {
  36579. header: segmentHeader,
  36580. data: data
  36581. };
  36582. if (!header.randomAccess) {
  36583. segment.start = position;
  36584. position += segmentHeader.length;
  36585. segment.end = position;
  36586. }
  36587. segments.push(segment);
  36588. if (segmentHeader.type === 51) {
  36589. break; // end of file is found
  36590. }
  36591. }
  36592. if (header.randomAccess) {
  36593. for (var i = 0, ii = segments.length; i < ii; i++) {
  36594. segments[i].start = position;
  36595. position += segments[i].header.length;
  36596. segments[i].end = position;
  36597. }
  36598. }
  36599. return segments;
  36600. }
  36601. // 7.4.1 Region segment information field
  36602. function readRegionSegmentInformation(data, start) {
  36603. return {
  36604. width: readUint32(data, start),
  36605. height: readUint32(data, start + 4),
  36606. x: readUint32(data, start + 8),
  36607. y: readUint32(data, start + 12),
  36608. combinationOperator: data[start + 16] & 7
  36609. };
  36610. }
  36611. var RegionSegmentInformationFieldLength = 17;
  36612. function processSegment(segment, visitor) {
  36613. var header = segment.header;
  36614. var data = segment.data, position = segment.start, end = segment.end;
  36615. var args, at, i, atLength;
  36616. switch (header.type) {
  36617. case 0: // SymbolDictionary
  36618. // 7.4.2 Symbol dictionary segment syntax
  36619. var dictionary = {};
  36620. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36621. dictionary.huffman = !!(dictionaryFlags & 1);
  36622. dictionary.refinement = !!(dictionaryFlags & 2);
  36623. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36624. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36625. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36626. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36627. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36628. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36629. dictionary.template = (dictionaryFlags >> 10) & 3;
  36630. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36631. position += 2;
  36632. if (!dictionary.huffman) {
  36633. atLength = dictionary.template === 0 ? 4 : 1;
  36634. at = [];
  36635. for (i = 0; i < atLength; i++) {
  36636. at.push({
  36637. x: readInt8(data, position),
  36638. y: readInt8(data, position + 1)
  36639. });
  36640. position += 2;
  36641. }
  36642. dictionary.at = at;
  36643. }
  36644. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36645. at = [];
  36646. for (i = 0; i < 2; i++) {
  36647. at.push({
  36648. x: readInt8(data, position),
  36649. y: readInt8(data, position + 1)
  36650. });
  36651. position += 2;
  36652. }
  36653. dictionary.refinementAt = at;
  36654. }
  36655. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36656. position += 4;
  36657. dictionary.numberOfNewSymbols = readUint32(data, position);
  36658. position += 4;
  36659. args = [dictionary, header.number, header.referredTo,
  36660. data, position, end];
  36661. break;
  36662. case 6: // ImmediateTextRegion
  36663. case 7: // ImmediateLosslessTextRegion
  36664. var textRegion = {};
  36665. textRegion.info = readRegionSegmentInformation(data, position);
  36666. position += RegionSegmentInformationFieldLength;
  36667. var textRegionSegmentFlags = readUint16(data, position);
  36668. position += 2;
  36669. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36670. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36671. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36672. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36673. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36674. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36675. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36676. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36677. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36678. if (textRegion.huffman) {
  36679. var textRegionHuffmanFlags = readUint16(data, position);
  36680. position += 2;
  36681. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36682. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36683. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36684. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36685. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36686. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36687. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36688. textRegion.huffmanRefinementSizeSelector =
  36689. !!(textRegionHuffmanFlags & 14);
  36690. }
  36691. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36692. at = [];
  36693. for (i = 0; i < 2; i++) {
  36694. at.push({
  36695. x: readInt8(data, position),
  36696. y: readInt8(data, position + 1)
  36697. });
  36698. position += 2;
  36699. }
  36700. textRegion.refinementAt = at;
  36701. }
  36702. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36703. position += 4;
  36704. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36705. if (textRegion.huffman) {
  36706. error('JBIG2 error: huffman is not supported');
  36707. }
  36708. args = [textRegion, header.referredTo, data, position, end];
  36709. break;
  36710. case 38: // ImmediateGenericRegion
  36711. case 39: // ImmediateLosslessGenericRegion
  36712. var genericRegion = {};
  36713. genericRegion.info = readRegionSegmentInformation(data, position);
  36714. position += RegionSegmentInformationFieldLength;
  36715. var genericRegionSegmentFlags = data[position++];
  36716. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36717. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36718. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36719. if (!genericRegion.mmr) {
  36720. atLength = genericRegion.template === 0 ? 4 : 1;
  36721. at = [];
  36722. for (i = 0; i < atLength; i++) {
  36723. at.push({
  36724. x: readInt8(data, position),
  36725. y: readInt8(data, position + 1)
  36726. });
  36727. position += 2;
  36728. }
  36729. genericRegion.at = at;
  36730. }
  36731. args = [genericRegion, data, position, end];
  36732. break;
  36733. case 48: // PageInformation
  36734. var pageInfo = {
  36735. width: readUint32(data, position),
  36736. height: readUint32(data, position + 4),
  36737. resolutionX: readUint32(data, position + 8),
  36738. resolutionY: readUint32(data, position + 12)
  36739. };
  36740. if (pageInfo.height === 0xFFFFFFFF) {
  36741. delete pageInfo.height;
  36742. }
  36743. var pageSegmentFlags = data[position + 16];
  36744. var pageStripingInformatiom = readUint16(data, position + 17);
  36745. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36746. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36747. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36748. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36749. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36750. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36751. args = [pageInfo];
  36752. break;
  36753. case 49: // EndOfPage
  36754. break;
  36755. case 50: // EndOfStripe
  36756. break;
  36757. case 51: // EndOfFile
  36758. break;
  36759. case 62: // 7.4.15 defines 2 extension types which
  36760. // are comments and can be ignored.
  36761. break;
  36762. default:
  36763. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36764. header.type + ') is not implemented');
  36765. }
  36766. var callbackName = 'on' + header.typeName;
  36767. if (callbackName in visitor) {
  36768. visitor[callbackName].apply(visitor, args);
  36769. }
  36770. }
  36771. function processSegments(segments, visitor) {
  36772. for (var i = 0, ii = segments.length; i < ii; i++) {
  36773. processSegment(segments[i], visitor);
  36774. }
  36775. }
  36776. function parseJbig2(data, start, end) {
  36777. var position = start;
  36778. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36779. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36780. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36781. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36782. error('JBIG2 error: invalid header');
  36783. }
  36784. var header = {};
  36785. position += 8;
  36786. var flags = data[position++];
  36787. header.randomAccess = !(flags & 1);
  36788. if (!(flags & 2)) {
  36789. header.numberOfPages = readUint32(data, position);
  36790. position += 4;
  36791. }
  36792. var segments = readSegments(header, data, position, end);
  36793. error('Not implemented');
  36794. // processSegments(segments, new SimpleSegmentVisitor());
  36795. }
  36796. function parseJbig2Chunks(chunks) {
  36797. var visitor = new SimpleSegmentVisitor();
  36798. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36799. var chunk = chunks[i];
  36800. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36801. processSegments(segments, visitor);
  36802. }
  36803. return visitor.buffer;
  36804. }
  36805. function SimpleSegmentVisitor() {}
  36806. SimpleSegmentVisitor.prototype = {
  36807. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36808. this.currentPageInfo = info;
  36809. var rowSize = (info.width + 7) >> 3;
  36810. var buffer = new Uint8Array(rowSize * info.height);
  36811. // The contents of ArrayBuffers are initialized to 0.
  36812. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36813. if (info.defaultPixelValue) {
  36814. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36815. buffer[i] = 0xFF;
  36816. }
  36817. }
  36818. this.buffer = buffer;
  36819. },
  36820. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36821. var pageInfo = this.currentPageInfo;
  36822. var width = regionInfo.width, height = regionInfo.height;
  36823. var rowSize = (pageInfo.width + 7) >> 3;
  36824. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36825. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36826. var buffer = this.buffer;
  36827. var mask0 = 128 >> (regionInfo.x & 7);
  36828. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36829. var i, j, mask, offset;
  36830. switch (combinationOperator) {
  36831. case 0: // OR
  36832. for (i = 0; i < height; i++) {
  36833. mask = mask0;
  36834. offset = offset0;
  36835. for (j = 0; j < width; j++) {
  36836. if (bitmap[i][j]) {
  36837. buffer[offset] |= mask;
  36838. }
  36839. mask >>= 1;
  36840. if (!mask) {
  36841. mask = 128;
  36842. offset++;
  36843. }
  36844. }
  36845. offset0 += rowSize;
  36846. }
  36847. break;
  36848. case 2: // XOR
  36849. for (i = 0; i < height; i++) {
  36850. mask = mask0;
  36851. offset = offset0;
  36852. for (j = 0; j < width; j++) {
  36853. if (bitmap[i][j]) {
  36854. buffer[offset] ^= mask;
  36855. }
  36856. mask >>= 1;
  36857. if (!mask) {
  36858. mask = 128;
  36859. offset++;
  36860. }
  36861. }
  36862. offset0 += rowSize;
  36863. }
  36864. break;
  36865. default:
  36866. error('JBIG2 error: operator ' + combinationOperator +
  36867. ' is not supported');
  36868. }
  36869. },
  36870. onImmediateGenericRegion:
  36871. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36872. start, end) {
  36873. var regionInfo = region.info;
  36874. var decodingContext = new DecodingContext(data, start, end);
  36875. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36876. region.template, region.prediction, null,
  36877. region.at, decodingContext);
  36878. this.drawBitmap(regionInfo, bitmap);
  36879. },
  36880. onImmediateLosslessGenericRegion:
  36881. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36882. this.onImmediateGenericRegion.apply(this, arguments);
  36883. },
  36884. onSymbolDictionary:
  36885. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36886. currentSegment,
  36887. referredSegments,
  36888. data, start, end) {
  36889. var huffmanTables;
  36890. if (dictionary.huffman) {
  36891. error('JBIG2 error: huffman is not supported');
  36892. }
  36893. // Combines exported symbols from all referred segments
  36894. var symbols = this.symbols;
  36895. if (!symbols) {
  36896. this.symbols = symbols = {};
  36897. }
  36898. var inputSymbols = [];
  36899. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36900. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36901. }
  36902. var decodingContext = new DecodingContext(data, start, end);
  36903. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36904. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36905. dictionary.numberOfExportedSymbols, huffmanTables,
  36906. dictionary.template, dictionary.at,
  36907. dictionary.refinementTemplate, dictionary.refinementAt,
  36908. decodingContext);
  36909. },
  36910. onImmediateTextRegion:
  36911. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36912. referredSegments,
  36913. data, start, end) {
  36914. var regionInfo = region.info;
  36915. var huffmanTables;
  36916. // Combines exported symbols from all referred segments
  36917. var symbols = this.symbols;
  36918. var inputSymbols = [];
  36919. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36920. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36921. }
  36922. var symbolCodeLength = log2(inputSymbols.length);
  36923. var decodingContext = new DecodingContext(data, start, end);
  36924. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36925. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36926. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36927. symbolCodeLength, region.transposed, region.dsOffset,
  36928. region.referenceCorner, region.combinationOperator, huffmanTables,
  36929. region.refinementTemplate, region.refinementAt, decodingContext);
  36930. this.drawBitmap(regionInfo, bitmap);
  36931. },
  36932. onImmediateLosslessTextRegion:
  36933. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36934. this.onImmediateTextRegion.apply(this, arguments);
  36935. }
  36936. };
  36937. function Jbig2Image() {}
  36938. Jbig2Image.prototype = {
  36939. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36940. return parseJbig2Chunks(chunks);
  36941. }
  36942. };
  36943. return Jbig2Image;
  36944. })();
  36945. var bidi = PDFJS.bidi = (function bidiClosure() {
  36946. // Character types for symbols from 0000 to 00FF.
  36947. var baseTypes = [
  36948. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36949. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36950. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36951. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36952. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36953. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36954. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36955. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36956. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36957. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36958. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36959. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36960. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36961. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36962. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36963. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36964. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36965. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36966. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36967. ];
  36968. // Character types for symbols from 0600 to 06FF
  36969. var arabicTypes = [
  36970. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36971. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36972. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36973. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36974. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36975. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36976. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36977. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36978. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36979. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36980. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36981. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36982. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36983. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36984. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36985. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36986. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36987. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36988. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36989. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36990. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36991. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36992. ];
  36993. function isOdd(i) {
  36994. return (i & 1) !== 0;
  36995. }
  36996. function isEven(i) {
  36997. return (i & 1) === 0;
  36998. }
  36999. function findUnequal(arr, start, value) {
  37000. for (var j = start, jj = arr.length; j < jj; ++j) {
  37001. if (arr[j] !== value) {
  37002. return j;
  37003. }
  37004. }
  37005. return j;
  37006. }
  37007. function setValues(arr, start, end, value) {
  37008. for (var j = start; j < end; ++j) {
  37009. arr[j] = value;
  37010. }
  37011. }
  37012. function reverseValues(arr, start, end) {
  37013. for (var i = start, j = end - 1; i < j; ++i, --j) {
  37014. var temp = arr[i];
  37015. arr[i] = arr[j];
  37016. arr[j] = temp;
  37017. }
  37018. }
  37019. function createBidiText(str, isLTR, vertical) {
  37020. return {
  37021. str: str,
  37022. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  37023. };
  37024. }
  37025. // These are used in bidi(), which is called frequently. We re-use them on
  37026. // each call to avoid unnecessary allocations.
  37027. var chars = [];
  37028. var types = [];
  37029. function bidi(str, startLevel, vertical) {
  37030. var isLTR = true;
  37031. var strLength = str.length;
  37032. if (strLength === 0 || vertical) {
  37033. return createBidiText(str, isLTR, vertical);
  37034. }
  37035. // Get types and fill arrays
  37036. chars.length = strLength;
  37037. types.length = strLength;
  37038. var numBidi = 0;
  37039. var i, ii;
  37040. for (i = 0; i < strLength; ++i) {
  37041. chars[i] = str.charAt(i);
  37042. var charCode = str.charCodeAt(i);
  37043. var charType = 'L';
  37044. if (charCode <= 0x00ff) {
  37045. charType = baseTypes[charCode];
  37046. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  37047. charType = 'R';
  37048. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  37049. charType = arabicTypes[charCode & 0xff];
  37050. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  37051. charType = 'AL';
  37052. }
  37053. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  37054. numBidi++;
  37055. }
  37056. types[i] = charType;
  37057. }
  37058. // Detect the bidi method
  37059. // - If there are no rtl characters then no bidi needed
  37060. // - If less than 30% chars are rtl then string is primarily ltr
  37061. // - If more than 30% chars are rtl then string is primarily rtl
  37062. if (numBidi === 0) {
  37063. isLTR = true;
  37064. return createBidiText(str, isLTR);
  37065. }
  37066. if (startLevel === -1) {
  37067. if ((strLength / numBidi) < 0.3) {
  37068. isLTR = true;
  37069. startLevel = 0;
  37070. } else {
  37071. isLTR = false;
  37072. startLevel = 1;
  37073. }
  37074. }
  37075. var levels = [];
  37076. for (i = 0; i < strLength; ++i) {
  37077. levels[i] = startLevel;
  37078. }
  37079. /*
  37080. X1-X10: skip most of this, since we are NOT doing the embeddings.
  37081. */
  37082. var e = (isOdd(startLevel) ? 'R' : 'L');
  37083. var sor = e;
  37084. var eor = sor;
  37085. /*
  37086. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  37087. type of the NSM to the type of the previous character. If the NSM is at the
  37088. start of the level run, it will get the type of sor.
  37089. */
  37090. var lastType = sor;
  37091. for (i = 0; i < strLength; ++i) {
  37092. if (types[i] === 'NSM') {
  37093. types[i] = lastType;
  37094. } else {
  37095. lastType = types[i];
  37096. }
  37097. }
  37098. /*
  37099. W2. Search backwards from each instance of a European number until the
  37100. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  37101. the type of the European number to Arabic number.
  37102. */
  37103. lastType = sor;
  37104. var t;
  37105. for (i = 0; i < strLength; ++i) {
  37106. t = types[i];
  37107. if (t === 'EN') {
  37108. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  37109. } else if (t === 'R' || t === 'L' || t === 'AL') {
  37110. lastType = t;
  37111. }
  37112. }
  37113. /*
  37114. W3. Change all ALs to R.
  37115. */
  37116. for (i = 0; i < strLength; ++i) {
  37117. t = types[i];
  37118. if (t === 'AL') {
  37119. types[i] = 'R';
  37120. }
  37121. }
  37122. /*
  37123. W4. A single European separator between two European numbers changes to a
  37124. European number. A single common separator between two numbers of the same
  37125. type changes to that type:
  37126. */
  37127. for (i = 1; i < strLength - 1; ++i) {
  37128. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  37129. types[i] = 'EN';
  37130. }
  37131. if (types[i] === 'CS' &&
  37132. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  37133. types[i + 1] === types[i - 1]) {
  37134. types[i] = types[i - 1];
  37135. }
  37136. }
  37137. /*
  37138. W5. A sequence of European terminators adjacent to European numbers changes
  37139. to all European numbers:
  37140. */
  37141. for (i = 0; i < strLength; ++i) {
  37142. if (types[i] === 'EN') {
  37143. // do before
  37144. var j;
  37145. for (j = i - 1; j >= 0; --j) {
  37146. if (types[j] !== 'ET') {
  37147. break;
  37148. }
  37149. types[j] = 'EN';
  37150. }
  37151. // do after
  37152. for (j = i + 1; j < strLength; --j) {
  37153. if (types[j] !== 'ET') {
  37154. break;
  37155. }
  37156. types[j] = 'EN';
  37157. }
  37158. }
  37159. }
  37160. /*
  37161. W6. Otherwise, separators and terminators change to Other Neutral:
  37162. */
  37163. for (i = 0; i < strLength; ++i) {
  37164. t = types[i];
  37165. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  37166. types[i] = 'ON';
  37167. }
  37168. }
  37169. /*
  37170. W7. Search backwards from each instance of a European number until the
  37171. first strong type (R, L, or sor) is found. If an L is found, then change
  37172. the type of the European number to L.
  37173. */
  37174. lastType = sor;
  37175. for (i = 0; i < strLength; ++i) {
  37176. t = types[i];
  37177. if (t === 'EN') {
  37178. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  37179. } else if (t === 'R' || t === 'L') {
  37180. lastType = t;
  37181. }
  37182. }
  37183. /*
  37184. N1. A sequence of neutrals takes the direction of the surrounding strong
  37185. text if the text on both sides has the same direction. European and Arabic
  37186. numbers are treated as though they were R. Start-of-level-run (sor) and
  37187. end-of-level-run (eor) are used at level run boundaries.
  37188. */
  37189. for (i = 0; i < strLength; ++i) {
  37190. if (types[i] === 'ON') {
  37191. var end = findUnequal(types, i + 1, 'ON');
  37192. var before = sor;
  37193. if (i > 0) {
  37194. before = types[i - 1];
  37195. }
  37196. var after = eor;
  37197. if (end + 1 < strLength) {
  37198. after = types[end + 1];
  37199. }
  37200. if (before !== 'L') {
  37201. before = 'R';
  37202. }
  37203. if (after !== 'L') {
  37204. after = 'R';
  37205. }
  37206. if (before === after) {
  37207. setValues(types, i, end, before);
  37208. }
  37209. i = end - 1; // reset to end (-1 so next iteration is ok)
  37210. }
  37211. }
  37212. /*
  37213. N2. Any remaining neutrals take the embedding direction.
  37214. */
  37215. for (i = 0; i < strLength; ++i) {
  37216. if (types[i] === 'ON') {
  37217. types[i] = e;
  37218. }
  37219. }
  37220. /*
  37221. I1. For all characters with an even (left-to-right) embedding direction,
  37222. those of type R go up one level and those of type AN or EN go up two
  37223. levels.
  37224. I2. For all characters with an odd (right-to-left) embedding direction,
  37225. those of type L, EN or AN go up one level.
  37226. */
  37227. for (i = 0; i < strLength; ++i) {
  37228. t = types[i];
  37229. if (isEven(levels[i])) {
  37230. if (t === 'R') {
  37231. levels[i] += 1;
  37232. } else if (t === 'AN' || t === 'EN') {
  37233. levels[i] += 2;
  37234. }
  37235. } else { // isOdd
  37236. if (t === 'L' || t === 'AN' || t === 'EN') {
  37237. levels[i] += 1;
  37238. }
  37239. }
  37240. }
  37241. /*
  37242. L1. On each line, reset the embedding level of the following characters to
  37243. the paragraph embedding level:
  37244. segment separators,
  37245. paragraph separators,
  37246. any sequence of whitespace characters preceding a segment separator or
  37247. paragraph separator, and any sequence of white space characters at the end
  37248. of the line.
  37249. */
  37250. // don't bother as text is only single line
  37251. /*
  37252. L2. From the highest level found in the text to the lowest odd level on
  37253. each line, reverse any contiguous sequence of characters that are at that
  37254. level or higher.
  37255. */
  37256. // find highest level & lowest odd level
  37257. var highestLevel = -1;
  37258. var lowestOddLevel = 99;
  37259. var level;
  37260. for (i = 0, ii = levels.length; i < ii; ++i) {
  37261. level = levels[i];
  37262. if (highestLevel < level) {
  37263. highestLevel = level;
  37264. }
  37265. if (lowestOddLevel > level && isOdd(level)) {
  37266. lowestOddLevel = level;
  37267. }
  37268. }
  37269. // now reverse between those limits
  37270. for (level = highestLevel; level >= lowestOddLevel; --level) {
  37271. // find segments to reverse
  37272. var start = -1;
  37273. for (i = 0, ii = levels.length; i < ii; ++i) {
  37274. if (levels[i] < level) {
  37275. if (start >= 0) {
  37276. reverseValues(chars, start, i);
  37277. start = -1;
  37278. }
  37279. } else if (start < 0) {
  37280. start = i;
  37281. }
  37282. }
  37283. if (start >= 0) {
  37284. reverseValues(chars, start, levels.length);
  37285. }
  37286. }
  37287. /*
  37288. L3. Combining marks applied to a right-to-left base character will at this
  37289. point precede their base character. If the rendering engine expects them to
  37290. follow the base characters in the final display process, then the ordering
  37291. of the marks and the base character must be reversed.
  37292. */
  37293. // don't bother for now
  37294. /*
  37295. L4. A character that possesses the mirrored property as specified by
  37296. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  37297. directionality of that character is R.
  37298. */
  37299. // don't mirror as characters are already mirrored in the pdf
  37300. // Finally, return string
  37301. for (i = 0, ii = chars.length; i < ii; ++i) {
  37302. var ch = chars[i];
  37303. if (ch === '<' || ch === '>') {
  37304. chars[i] = '';
  37305. }
  37306. }
  37307. return createBidiText(chars.join(''), isLTR);
  37308. }
  37309. return bidi;
  37310. })();
  37311. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  37312. // Workaround for missing math precison in JS.
  37313. var MASK_HIGH = 0xffff0000;
  37314. var MASK_LOW = 0xffff;
  37315. function MurmurHash3_64 (seed) {
  37316. var SEED = 0xc3d2e1f0;
  37317. this.h1 = seed ? seed & 0xffffffff : SEED;
  37318. this.h2 = seed ? seed & 0xffffffff : SEED;
  37319. }
  37320. var alwaysUseUint32ArrayView = false;
  37321. // old webkits have issues with non-aligned arrays
  37322. try {
  37323. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  37324. } catch (e) {
  37325. alwaysUseUint32ArrayView = true;
  37326. }
  37327. MurmurHash3_64.prototype = {
  37328. update: function MurmurHash3_64_update(input) {
  37329. var useUint32ArrayView = alwaysUseUint32ArrayView;
  37330. var i;
  37331. if (typeof input === 'string') {
  37332. var data = new Uint8Array(input.length * 2);
  37333. var length = 0;
  37334. for (i = 0; i < input.length; i++) {
  37335. var code = input.charCodeAt(i);
  37336. if (code <= 0xff) {
  37337. data[length++] = code;
  37338. }
  37339. else {
  37340. data[length++] = code >>> 8;
  37341. data[length++] = code & 0xff;
  37342. }
  37343. }
  37344. } else if (input instanceof Uint8Array) {
  37345. data = input;
  37346. length = data.length;
  37347. } else if (typeof input === 'object' && ('length' in input)) {
  37348. // processing regular arrays as well, e.g. for IE9
  37349. data = input;
  37350. length = data.length;
  37351. useUint32ArrayView = true;
  37352. } else {
  37353. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  37354. 'Input must be a string or array.');
  37355. }
  37356. var blockCounts = length >> 2;
  37357. var tailLength = length - blockCounts * 4;
  37358. // we don't care about endianness here
  37359. var dataUint32 = useUint32ArrayView ?
  37360. new Uint32ArrayView(data, blockCounts) :
  37361. new Uint32Array(data.buffer, 0, blockCounts);
  37362. var k1 = 0;
  37363. var k2 = 0;
  37364. var h1 = this.h1;
  37365. var h2 = this.h2;
  37366. var C1 = 0xcc9e2d51;
  37367. var C2 = 0x1b873593;
  37368. var C1_LOW = C1 & MASK_LOW;
  37369. var C2_LOW = C2 & MASK_LOW;
  37370. for (i = 0; i < blockCounts; i++) {
  37371. if (i & 1) {
  37372. k1 = dataUint32[i];
  37373. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37374. k1 = k1 << 15 | k1 >>> 17;
  37375. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37376. h1 ^= k1;
  37377. h1 = h1 << 13 | h1 >>> 19;
  37378. h1 = h1 * 5 + 0xe6546b64;
  37379. } else {
  37380. k2 = dataUint32[i];
  37381. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  37382. k2 = k2 << 15 | k2 >>> 17;
  37383. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  37384. h2 ^= k2;
  37385. h2 = h2 << 13 | h2 >>> 19;
  37386. h2 = h2 * 5 + 0xe6546b64;
  37387. }
  37388. }
  37389. k1 = 0;
  37390. switch (tailLength) {
  37391. case 3:
  37392. k1 ^= data[blockCounts * 4 + 2] << 16;
  37393. /* falls through */
  37394. case 2:
  37395. k1 ^= data[blockCounts * 4 + 1] << 8;
  37396. /* falls through */
  37397. case 1:
  37398. k1 ^= data[blockCounts * 4];
  37399. /* falls through */
  37400. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37401. k1 = k1 << 15 | k1 >>> 17;
  37402. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37403. if (blockCounts & 1) {
  37404. h1 ^= k1;
  37405. } else {
  37406. h2 ^= k1;
  37407. }
  37408. }
  37409. this.h1 = h1;
  37410. this.h2 = h2;
  37411. return this;
  37412. },
  37413. hexdigest: function MurmurHash3_64_hexdigest () {
  37414. var h1 = this.h1;
  37415. var h2 = this.h2;
  37416. h1 ^= h2 >>> 1;
  37417. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  37418. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  37419. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  37420. h1 ^= h2 >>> 1;
  37421. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  37422. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  37423. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  37424. h1 ^= h2 >>> 1;
  37425. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  37426. var hex = (arr[i] >>> 0).toString(16);
  37427. while (hex.length < 8) {
  37428. hex = '0' + hex;
  37429. }
  37430. str += hex;
  37431. }
  37432. return str;
  37433. }
  37434. };
  37435. return MurmurHash3_64;
  37436. })();
  37437. }).call((typeof window === 'undefined') ? this : window);
  37438. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  37439. // workerSrc is not set -- using last script url to define default location
  37440. PDFJS.workerSrc = (function () {
  37441. 'use strict';
  37442. var pdfJsSrc = document.currentScript.src;
  37443. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  37444. })();
  37445. }