pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.136';
  24. PDFJS.build = 'd7aa95d';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  223. console.log('Error: ' + msg);
  224. console.log(backtrace());
  225. }
  226. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  227. throw new Error(msg);
  228. }
  229. function backtrace() {
  230. try {
  231. throw new Error();
  232. } catch (e) {
  233. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  234. }
  235. }
  236. function assert(cond, msg) {
  237. if (!cond) {
  238. error(msg);
  239. }
  240. }
  241. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  242. unknown: 'unknown',
  243. forms: 'forms',
  244. javaScript: 'javaScript',
  245. smask: 'smask',
  246. shadingPattern: 'shadingPattern',
  247. font: 'font'
  248. };
  249. var UnsupportedManager = PDFJS.UnsupportedManager =
  250. (function UnsupportedManagerClosure() {
  251. var listeners = [];
  252. return {
  253. listen: function (cb) {
  254. listeners.push(cb);
  255. },
  256. notify: function (featureId) {
  257. warn('Unsupported feature "' + featureId + '"');
  258. for (var i = 0, ii = listeners.length; i < ii; i++) {
  259. listeners[i](featureId);
  260. }
  261. }
  262. };
  263. })();
  264. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  265. // absolute URL, it will be returned as is.
  266. function combineUrl(baseUrl, url) {
  267. if (!url) {
  268. return baseUrl;
  269. }
  270. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  271. return url;
  272. }
  273. var i;
  274. if (url.charAt(0) === '/') {
  275. // absolute path
  276. i = baseUrl.indexOf('://');
  277. if (url.charAt(1) === '/') {
  278. ++i;
  279. } else {
  280. i = baseUrl.indexOf('/', i + 3);
  281. }
  282. return baseUrl.substring(0, i) + url;
  283. } else {
  284. // relative path
  285. var pathLength = baseUrl.length;
  286. i = baseUrl.lastIndexOf('#');
  287. pathLength = i >= 0 ? i : pathLength;
  288. i = baseUrl.lastIndexOf('?', pathLength);
  289. pathLength = i >= 0 ? i : pathLength;
  290. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  291. return baseUrl.substring(0, prefixLength + 1) + url;
  292. }
  293. }
  294. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  295. function isValidUrl(url, allowRelative) {
  296. if (!url) {
  297. return false;
  298. }
  299. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  300. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  301. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  302. if (!protocol) {
  303. return allowRelative;
  304. }
  305. protocol = protocol[0].toLowerCase();
  306. switch (protocol) {
  307. case 'http':
  308. case 'https':
  309. case 'ftp':
  310. case 'mailto':
  311. case 'tel':
  312. return true;
  313. default:
  314. return false;
  315. }
  316. }
  317. PDFJS.isValidUrl = isValidUrl;
  318. function shadow(obj, prop, value) {
  319. Object.defineProperty(obj, prop, { value: value,
  320. enumerable: true,
  321. configurable: true,
  322. writable: false });
  323. return value;
  324. }
  325. PDFJS.shadow = shadow;
  326. var PasswordResponses = PDFJS.PasswordResponses = {
  327. NEED_PASSWORD: 1,
  328. INCORRECT_PASSWORD: 2
  329. };
  330. var PasswordException = (function PasswordExceptionClosure() {
  331. function PasswordException(msg, code) {
  332. this.name = 'PasswordException';
  333. this.message = msg;
  334. this.code = code;
  335. }
  336. PasswordException.prototype = new Error();
  337. PasswordException.constructor = PasswordException;
  338. return PasswordException;
  339. })();
  340. PDFJS.PasswordException = PasswordException;
  341. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  342. function UnknownErrorException(msg, details) {
  343. this.name = 'UnknownErrorException';
  344. this.message = msg;
  345. this.details = details;
  346. }
  347. UnknownErrorException.prototype = new Error();
  348. UnknownErrorException.constructor = UnknownErrorException;
  349. return UnknownErrorException;
  350. })();
  351. PDFJS.UnknownErrorException = UnknownErrorException;
  352. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  353. function InvalidPDFException(msg) {
  354. this.name = 'InvalidPDFException';
  355. this.message = msg;
  356. }
  357. InvalidPDFException.prototype = new Error();
  358. InvalidPDFException.constructor = InvalidPDFException;
  359. return InvalidPDFException;
  360. })();
  361. PDFJS.InvalidPDFException = InvalidPDFException;
  362. var MissingPDFException = (function MissingPDFExceptionClosure() {
  363. function MissingPDFException(msg) {
  364. this.name = 'MissingPDFException';
  365. this.message = msg;
  366. }
  367. MissingPDFException.prototype = new Error();
  368. MissingPDFException.constructor = MissingPDFException;
  369. return MissingPDFException;
  370. })();
  371. PDFJS.MissingPDFException = MissingPDFException;
  372. var UnexpectedResponseException =
  373. (function UnexpectedResponseExceptionClosure() {
  374. function UnexpectedResponseException(msg, status) {
  375. this.name = 'UnexpectedResponseException';
  376. this.message = msg;
  377. this.status = status;
  378. }
  379. UnexpectedResponseException.prototype = new Error();
  380. UnexpectedResponseException.constructor = UnexpectedResponseException;
  381. return UnexpectedResponseException;
  382. })();
  383. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  384. var NotImplementedException = (function NotImplementedExceptionClosure() {
  385. function NotImplementedException(msg) {
  386. this.message = msg;
  387. }
  388. NotImplementedException.prototype = new Error();
  389. NotImplementedException.prototype.name = 'NotImplementedException';
  390. NotImplementedException.constructor = NotImplementedException;
  391. return NotImplementedException;
  392. })();
  393. var MissingDataException = (function MissingDataExceptionClosure() {
  394. function MissingDataException(begin, end) {
  395. this.begin = begin;
  396. this.end = end;
  397. this.message = 'Missing data [' + begin + ', ' + end + ')';
  398. }
  399. MissingDataException.prototype = new Error();
  400. MissingDataException.prototype.name = 'MissingDataException';
  401. MissingDataException.constructor = MissingDataException;
  402. return MissingDataException;
  403. })();
  404. var XRefParseException = (function XRefParseExceptionClosure() {
  405. function XRefParseException(msg) {
  406. this.message = msg;
  407. }
  408. XRefParseException.prototype = new Error();
  409. XRefParseException.prototype.name = 'XRefParseException';
  410. XRefParseException.constructor = XRefParseException;
  411. return XRefParseException;
  412. })();
  413. function bytesToString(bytes) {
  414. assert(bytes !== null && typeof bytes === 'object' &&
  415. bytes.length !== undefined, 'Invalid argument for bytesToString');
  416. var length = bytes.length;
  417. var MAX_ARGUMENT_COUNT = 8192;
  418. if (length < MAX_ARGUMENT_COUNT) {
  419. return String.fromCharCode.apply(null, bytes);
  420. }
  421. var strBuf = [];
  422. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  423. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  424. var chunk = bytes.subarray(i, chunkEnd);
  425. strBuf.push(String.fromCharCode.apply(null, chunk));
  426. }
  427. return strBuf.join('');
  428. }
  429. function stringToBytes(str) {
  430. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  431. var length = str.length;
  432. var bytes = new Uint8Array(length);
  433. for (var i = 0; i < length; ++i) {
  434. bytes[i] = str.charCodeAt(i) & 0xFF;
  435. }
  436. return bytes;
  437. }
  438. function string32(value) {
  439. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  440. (value >> 8) & 0xff, value & 0xff);
  441. }
  442. function log2(x) {
  443. var n = 1, i = 0;
  444. while (x > n) {
  445. n <<= 1;
  446. i++;
  447. }
  448. return i;
  449. }
  450. function readInt8(data, start) {
  451. return (data[start] << 24) >> 24;
  452. }
  453. function readUint16(data, offset) {
  454. return (data[offset] << 8) | data[offset + 1];
  455. }
  456. function readUint32(data, offset) {
  457. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  458. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  459. }
  460. // Lazy test the endianness of the platform
  461. // NOTE: This will be 'true' for simulated TypedArrays
  462. function isLittleEndian() {
  463. var buffer8 = new Uint8Array(2);
  464. buffer8[0] = 1;
  465. var buffer16 = new Uint16Array(buffer8.buffer);
  466. return (buffer16[0] === 1);
  467. }
  468. Object.defineProperty(PDFJS, 'isLittleEndian', {
  469. configurable: true,
  470. get: function PDFJS_isLittleEndian() {
  471. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  472. }
  473. });
  474. // Lazy test if the userAgant support CanvasTypedArrays
  475. function hasCanvasTypedArrays() {
  476. var canvas = document.createElement('canvas');
  477. canvas.width = canvas.height = 1;
  478. var ctx = canvas.getContext('2d');
  479. var imageData = ctx.createImageData(1, 1);
  480. return (typeof imageData.data.buffer !== 'undefined');
  481. }
  482. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  483. configurable: true,
  484. get: function PDFJS_hasCanvasTypedArrays() {
  485. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  486. }
  487. });
  488. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  489. function Uint32ArrayView(buffer, length) {
  490. this.buffer = buffer;
  491. this.byteLength = buffer.length;
  492. this.length = length === undefined ? (this.byteLength >> 2) : length;
  493. ensureUint32ArrayViewProps(this.length);
  494. }
  495. Uint32ArrayView.prototype = Object.create(null);
  496. var uint32ArrayViewSetters = 0;
  497. function createUint32ArrayProp(index) {
  498. return {
  499. get: function () {
  500. var buffer = this.buffer, offset = index << 2;
  501. return (buffer[offset] | (buffer[offset + 1] << 8) |
  502. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  503. },
  504. set: function (value) {
  505. var buffer = this.buffer, offset = index << 2;
  506. buffer[offset] = value & 255;
  507. buffer[offset + 1] = (value >> 8) & 255;
  508. buffer[offset + 2] = (value >> 16) & 255;
  509. buffer[offset + 3] = (value >>> 24) & 255;
  510. }
  511. };
  512. }
  513. function ensureUint32ArrayViewProps(length) {
  514. while (uint32ArrayViewSetters < length) {
  515. Object.defineProperty(Uint32ArrayView.prototype,
  516. uint32ArrayViewSetters,
  517. createUint32ArrayProp(uint32ArrayViewSetters));
  518. uint32ArrayViewSetters++;
  519. }
  520. }
  521. return Uint32ArrayView;
  522. })();
  523. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  524. var Util = PDFJS.Util = (function UtilClosure() {
  525. function Util() {}
  526. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  527. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  528. // creating many intermediate strings.
  529. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  530. rgbBuf[1] = r;
  531. rgbBuf[3] = g;
  532. rgbBuf[5] = b;
  533. return rgbBuf.join('');
  534. };
  535. // Concatenates two transformation matrices together and returns the result.
  536. Util.transform = function Util_transform(m1, m2) {
  537. return [
  538. m1[0] * m2[0] + m1[2] * m2[1],
  539. m1[1] * m2[0] + m1[3] * m2[1],
  540. m1[0] * m2[2] + m1[2] * m2[3],
  541. m1[1] * m2[2] + m1[3] * m2[3],
  542. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  543. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  544. ];
  545. };
  546. // For 2d affine transforms
  547. Util.applyTransform = function Util_applyTransform(p, m) {
  548. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  549. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  550. return [xt, yt];
  551. };
  552. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  553. var d = m[0] * m[3] - m[1] * m[2];
  554. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  555. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  556. return [xt, yt];
  557. };
  558. // Applies the transform to the rectangle and finds the minimum axially
  559. // aligned bounding box.
  560. Util.getAxialAlignedBoundingBox =
  561. function Util_getAxialAlignedBoundingBox(r, m) {
  562. var p1 = Util.applyTransform(r, m);
  563. var p2 = Util.applyTransform(r.slice(2, 4), m);
  564. var p3 = Util.applyTransform([r[0], r[3]], m);
  565. var p4 = Util.applyTransform([r[2], r[1]], m);
  566. return [
  567. Math.min(p1[0], p2[0], p3[0], p4[0]),
  568. Math.min(p1[1], p2[1], p3[1], p4[1]),
  569. Math.max(p1[0], p2[0], p3[0], p4[0]),
  570. Math.max(p1[1], p2[1], p3[1], p4[1])
  571. ];
  572. };
  573. Util.inverseTransform = function Util_inverseTransform(m) {
  574. var d = m[0] * m[3] - m[1] * m[2];
  575. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  576. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  577. };
  578. // Apply a generic 3d matrix M on a 3-vector v:
  579. // | a b c | | X |
  580. // | d e f | x | Y |
  581. // | g h i | | Z |
  582. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  583. // with v as [X,Y,Z]
  584. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  585. return [
  586. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  587. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  588. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  589. ];
  590. };
  591. // This calculation uses Singular Value Decomposition.
  592. // The SVD can be represented with formula A = USV. We are interested in the
  593. // matrix S here because it represents the scale values.
  594. Util.singularValueDecompose2dScale =
  595. function Util_singularValueDecompose2dScale(m) {
  596. var transpose = [m[0], m[2], m[1], m[3]];
  597. // Multiply matrix m with its transpose.
  598. var a = m[0] * transpose[0] + m[1] * transpose[2];
  599. var b = m[0] * transpose[1] + m[1] * transpose[3];
  600. var c = m[2] * transpose[0] + m[3] * transpose[2];
  601. var d = m[2] * transpose[1] + m[3] * transpose[3];
  602. // Solve the second degree polynomial to get roots.
  603. var first = (a + d) / 2;
  604. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  605. var sx = first + second || 1;
  606. var sy = first - second || 1;
  607. // Scale values are the square roots of the eigenvalues.
  608. return [Math.sqrt(sx), Math.sqrt(sy)];
  609. };
  610. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  611. // For coordinate systems whose origin lies in the bottom-left, this
  612. // means normalization to (BL,TR) ordering. For systems with origin in the
  613. // top-left, this means (TL,BR) ordering.
  614. Util.normalizeRect = function Util_normalizeRect(rect) {
  615. var r = rect.slice(0); // clone rect
  616. if (rect[0] > rect[2]) {
  617. r[0] = rect[2];
  618. r[2] = rect[0];
  619. }
  620. if (rect[1] > rect[3]) {
  621. r[1] = rect[3];
  622. r[3] = rect[1];
  623. }
  624. return r;
  625. };
  626. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  627. // intersection of rect1 and rect2. If no intersection, returns 'false'
  628. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  629. Util.intersect = function Util_intersect(rect1, rect2) {
  630. function compare(a, b) {
  631. return a - b;
  632. }
  633. // Order points along the axes
  634. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  635. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  636. result = [];
  637. rect1 = Util.normalizeRect(rect1);
  638. rect2 = Util.normalizeRect(rect2);
  639. // X: first and second points belong to different rectangles?
  640. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  641. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  642. // Intersection must be between second and third points
  643. result[0] = orderedX[1];
  644. result[2] = orderedX[2];
  645. } else {
  646. return false;
  647. }
  648. // Y: first and second points belong to different rectangles?
  649. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  650. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  651. // Intersection must be between second and third points
  652. result[1] = orderedY[1];
  653. result[3] = orderedY[2];
  654. } else {
  655. return false;
  656. }
  657. return result;
  658. };
  659. Util.sign = function Util_sign(num) {
  660. return num < 0 ? -1 : 1;
  661. };
  662. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  663. Array.prototype.push.apply(arr1, arr2);
  664. };
  665. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  666. Array.prototype.unshift.apply(arr1, arr2);
  667. };
  668. Util.extendObj = function extendObj(obj1, obj2) {
  669. for (var key in obj2) {
  670. obj1[key] = obj2[key];
  671. }
  672. };
  673. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  674. name) {
  675. while (dict && !dict.has(name)) {
  676. dict = dict.get('Parent');
  677. }
  678. if (!dict) {
  679. return null;
  680. }
  681. return dict.get(name);
  682. };
  683. Util.inherit = function Util_inherit(sub, base, prototype) {
  684. sub.prototype = Object.create(base.prototype);
  685. sub.prototype.constructor = sub;
  686. for (var prop in prototype) {
  687. sub.prototype[prop] = prototype[prop];
  688. }
  689. };
  690. Util.loadScript = function Util_loadScript(src, callback) {
  691. var script = document.createElement('script');
  692. var loaded = false;
  693. script.setAttribute('src', src);
  694. if (callback) {
  695. script.onload = function() {
  696. if (!loaded) {
  697. callback();
  698. }
  699. loaded = true;
  700. };
  701. }
  702. document.getElementsByTagName('head')[0].appendChild(script);
  703. };
  704. return Util;
  705. })();
  706. /**
  707. * PDF page viewport created based on scale, rotation and offset.
  708. * @class
  709. * @alias PDFJS.PageViewport
  710. */
  711. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  712. /**
  713. * @constructor
  714. * @private
  715. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  716. * @param scale {number} scale of the viewport.
  717. * @param rotation {number} rotations of the viewport in degrees.
  718. * @param offsetX {number} offset X
  719. * @param offsetY {number} offset Y
  720. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  721. */
  722. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  723. this.viewBox = viewBox;
  724. this.scale = scale;
  725. this.rotation = rotation;
  726. this.offsetX = offsetX;
  727. this.offsetY = offsetY;
  728. // creating transform to convert pdf coordinate system to the normal
  729. // canvas like coordinates taking in account scale and rotation
  730. var centerX = (viewBox[2] + viewBox[0]) / 2;
  731. var centerY = (viewBox[3] + viewBox[1]) / 2;
  732. var rotateA, rotateB, rotateC, rotateD;
  733. rotation = rotation % 360;
  734. rotation = rotation < 0 ? rotation + 360 : rotation;
  735. switch (rotation) {
  736. case 180:
  737. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  738. break;
  739. case 90:
  740. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  741. break;
  742. case 270:
  743. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  744. break;
  745. //case 0:
  746. default:
  747. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  748. break;
  749. }
  750. if (dontFlip) {
  751. rotateC = -rotateC; rotateD = -rotateD;
  752. }
  753. var offsetCanvasX, offsetCanvasY;
  754. var width, height;
  755. if (rotateA === 0) {
  756. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  757. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  758. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  760. } else {
  761. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  762. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  763. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  764. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  765. }
  766. // creating transform for the following operations:
  767. // translate(-centerX, -centerY), rotate and flip vertically,
  768. // scale, and translate(offsetCanvasX, offsetCanvasY)
  769. this.transform = [
  770. rotateA * scale,
  771. rotateB * scale,
  772. rotateC * scale,
  773. rotateD * scale,
  774. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  775. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  776. ];
  777. this.width = width;
  778. this.height = height;
  779. this.fontScale = scale;
  780. }
  781. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  782. /**
  783. * Clones viewport with additional properties.
  784. * @param args {Object} (optional) If specified, may contain the 'scale' or
  785. * 'rotation' properties to override the corresponding properties in
  786. * the cloned viewport.
  787. * @returns {PDFJS.PageViewport} Cloned viewport.
  788. */
  789. clone: function PageViewPort_clone(args) {
  790. args = args || {};
  791. var scale = 'scale' in args ? args.scale : this.scale;
  792. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  793. return new PageViewport(this.viewBox.slice(), scale, rotation,
  794. this.offsetX, this.offsetY, args.dontFlip);
  795. },
  796. /**
  797. * Converts PDF point to the viewport coordinates. For examples, useful for
  798. * converting PDF location into canvas pixel coordinates.
  799. * @param x {number} X coordinate.
  800. * @param y {number} Y coordinate.
  801. * @returns {Object} Object that contains 'x' and 'y' properties of the
  802. * point in the viewport coordinate space.
  803. * @see {@link convertToPdfPoint}
  804. * @see {@link convertToViewportRectangle}
  805. */
  806. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  807. return Util.applyTransform([x, y], this.transform);
  808. },
  809. /**
  810. * Converts PDF rectangle to the viewport coordinates.
  811. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  812. * @returns {Array} Contains corresponding coordinates of the rectangle
  813. * in the viewport coordinate space.
  814. * @see {@link convertToViewportPoint}
  815. */
  816. convertToViewportRectangle:
  817. function PageViewport_convertToViewportRectangle(rect) {
  818. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  819. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  820. return [tl[0], tl[1], br[0], br[1]];
  821. },
  822. /**
  823. * Converts viewport coordinates to the PDF location. For examples, useful
  824. * for converting canvas pixel location into PDF one.
  825. * @param x {number} X coordinate.
  826. * @param y {number} Y coordinate.
  827. * @returns {Object} Object that contains 'x' and 'y' properties of the
  828. * point in the PDF coordinate space.
  829. * @see {@link convertToViewportPoint}
  830. */
  831. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  832. return Util.applyInverseTransform([x, y], this.transform);
  833. }
  834. };
  835. return PageViewport;
  836. })();
  837. var PDFStringTranslateTable = [
  838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  839. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  841. 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,
  842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  844. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  845. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  846. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  847. ];
  848. function stringToPDFString(str) {
  849. var i, n = str.length, strBuf = [];
  850. if (str[0] === '\xFE' && str[1] === '\xFF') {
  851. // UTF16BE BOM
  852. for (i = 2; i < n; i += 2) {
  853. strBuf.push(String.fromCharCode(
  854. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  855. }
  856. } else {
  857. for (i = 0; i < n; ++i) {
  858. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  859. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  860. }
  861. }
  862. return strBuf.join('');
  863. }
  864. function stringToUTF8String(str) {
  865. return decodeURIComponent(escape(str));
  866. }
  867. function isEmptyObj(obj) {
  868. for (var key in obj) {
  869. return false;
  870. }
  871. return true;
  872. }
  873. function isBool(v) {
  874. return typeof v === 'boolean';
  875. }
  876. function isInt(v) {
  877. return typeof v === 'number' && ((v | 0) === v);
  878. }
  879. function isNum(v) {
  880. return typeof v === 'number';
  881. }
  882. function isString(v) {
  883. return typeof v === 'string';
  884. }
  885. function isName(v) {
  886. return v instanceof Name;
  887. }
  888. function isCmd(v, cmd) {
  889. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  890. }
  891. function isDict(v, type) {
  892. if (!(v instanceof Dict)) {
  893. return false;
  894. }
  895. if (!type) {
  896. return true;
  897. }
  898. var dictType = v.get('Type');
  899. return isName(dictType) && dictType.name === type;
  900. }
  901. function isArray(v) {
  902. return v instanceof Array;
  903. }
  904. function isStream(v) {
  905. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  906. }
  907. function isArrayBuffer(v) {
  908. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  909. }
  910. function isRef(v) {
  911. return v instanceof Ref;
  912. }
  913. /**
  914. * Promise Capability object.
  915. *
  916. * @typedef {Object} PromiseCapability
  917. * @property {Promise} promise - A promise object.
  918. * @property {function} resolve - Fullfills the promise.
  919. * @property {function} reject - Rejects the promise.
  920. */
  921. /**
  922. * Creates a promise capability object.
  923. * @alias PDFJS.createPromiseCapability
  924. *
  925. * @return {PromiseCapability} A capability object contains:
  926. * - a Promise, resolve and reject methods.
  927. */
  928. function createPromiseCapability() {
  929. var capability = {};
  930. capability.promise = new Promise(function (resolve, reject) {
  931. capability.resolve = resolve;
  932. capability.reject = reject;
  933. });
  934. return capability;
  935. }
  936. PDFJS.createPromiseCapability = createPromiseCapability;
  937. /**
  938. * Polyfill for Promises:
  939. * The following promise implementation tries to generally implement the
  940. * Promise/A+ spec. Some notable differences from other promise libaries are:
  941. * - There currently isn't a seperate deferred and promise object.
  942. * - Unhandled rejections eventually show an error if they aren't handled.
  943. *
  944. * Based off of the work in:
  945. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  946. */
  947. (function PromiseClosure() {
  948. if (globalScope.Promise) {
  949. // Promises existing in the DOM/Worker, checking presence of all/resolve
  950. if (typeof globalScope.Promise.all !== 'function') {
  951. globalScope.Promise.all = function (iterable) {
  952. var count = 0, results = [], resolve, reject;
  953. var promise = new globalScope.Promise(function (resolve_, reject_) {
  954. resolve = resolve_;
  955. reject = reject_;
  956. });
  957. iterable.forEach(function (p, i) {
  958. count++;
  959. p.then(function (result) {
  960. results[i] = result;
  961. count--;
  962. if (count === 0) {
  963. resolve(results);
  964. }
  965. }, reject);
  966. });
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. return promise;
  971. };
  972. }
  973. if (typeof globalScope.Promise.resolve !== 'function') {
  974. globalScope.Promise.resolve = function (value) {
  975. return new globalScope.Promise(function (resolve) { resolve(value); });
  976. };
  977. }
  978. if (typeof globalScope.Promise.reject !== 'function') {
  979. globalScope.Promise.reject = function (reason) {
  980. return new globalScope.Promise(function (resolve, reject) {
  981. reject(reason);
  982. });
  983. };
  984. }
  985. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  986. globalScope.Promise.prototype.catch = function (onReject) {
  987. return globalScope.Promise.prototype.then(undefined, onReject);
  988. };
  989. }
  990. return;
  991. }
  992. var STATUS_PENDING = 0;
  993. var STATUS_RESOLVED = 1;
  994. var STATUS_REJECTED = 2;
  995. // In an attempt to avoid silent exceptions, unhandled rejections are
  996. // tracked and if they aren't handled in a certain amount of time an
  997. // error is logged.
  998. var REJECTION_TIMEOUT = 500;
  999. var HandlerManager = {
  1000. handlers: [],
  1001. running: false,
  1002. unhandledRejections: [],
  1003. pendingRejectionCheck: false,
  1004. scheduleHandlers: function scheduleHandlers(promise) {
  1005. if (promise._status === STATUS_PENDING) {
  1006. return;
  1007. }
  1008. this.handlers = this.handlers.concat(promise._handlers);
  1009. promise._handlers = [];
  1010. if (this.running) {
  1011. return;
  1012. }
  1013. this.running = true;
  1014. setTimeout(this.runHandlers.bind(this), 0);
  1015. },
  1016. runHandlers: function runHandlers() {
  1017. var RUN_TIMEOUT = 1; // ms
  1018. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1019. while (this.handlers.length > 0) {
  1020. var handler = this.handlers.shift();
  1021. var nextStatus = handler.thisPromise._status;
  1022. var nextValue = handler.thisPromise._value;
  1023. try {
  1024. if (nextStatus === STATUS_RESOLVED) {
  1025. if (typeof handler.onResolve === 'function') {
  1026. nextValue = handler.onResolve(nextValue);
  1027. }
  1028. } else if (typeof handler.onReject === 'function') {
  1029. nextValue = handler.onReject(nextValue);
  1030. nextStatus = STATUS_RESOLVED;
  1031. if (handler.thisPromise._unhandledRejection) {
  1032. this.removeUnhandeledRejection(handler.thisPromise);
  1033. }
  1034. }
  1035. } catch (ex) {
  1036. nextStatus = STATUS_REJECTED;
  1037. nextValue = ex;
  1038. }
  1039. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1040. if (Date.now() >= timeoutAt) {
  1041. break;
  1042. }
  1043. }
  1044. if (this.handlers.length > 0) {
  1045. setTimeout(this.runHandlers.bind(this), 0);
  1046. return;
  1047. }
  1048. this.running = false;
  1049. },
  1050. addUnhandledRejection: function addUnhandledRejection(promise) {
  1051. this.unhandledRejections.push({
  1052. promise: promise,
  1053. time: Date.now()
  1054. });
  1055. this.scheduleRejectionCheck();
  1056. },
  1057. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1058. promise._unhandledRejection = false;
  1059. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1060. if (this.unhandledRejections[i].promise === promise) {
  1061. this.unhandledRejections.splice(i);
  1062. i--;
  1063. }
  1064. }
  1065. },
  1066. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1067. if (this.pendingRejectionCheck) {
  1068. return;
  1069. }
  1070. this.pendingRejectionCheck = true;
  1071. setTimeout(function rejectionCheck() {
  1072. this.pendingRejectionCheck = false;
  1073. var now = Date.now();
  1074. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1075. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1076. var unhandled = this.unhandledRejections[i].promise._value;
  1077. var msg = 'Unhandled rejection: ' + unhandled;
  1078. if (unhandled.stack) {
  1079. msg += '\n' + unhandled.stack;
  1080. }
  1081. warn(msg);
  1082. this.unhandledRejections.splice(i);
  1083. i--;
  1084. }
  1085. }
  1086. if (this.unhandledRejections.length) {
  1087. this.scheduleRejectionCheck();
  1088. }
  1089. }.bind(this), REJECTION_TIMEOUT);
  1090. }
  1091. };
  1092. function Promise(resolver) {
  1093. this._status = STATUS_PENDING;
  1094. this._handlers = [];
  1095. try {
  1096. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1097. } catch (e) {
  1098. this._reject(e);
  1099. }
  1100. }
  1101. /**
  1102. * Builds a promise that is resolved when all the passed in promises are
  1103. * resolved.
  1104. * @param {array} array of data and/or promises to wait for.
  1105. * @return {Promise} New dependant promise.
  1106. */
  1107. Promise.all = function Promise_all(promises) {
  1108. var resolveAll, rejectAll;
  1109. var deferred = new Promise(function (resolve, reject) {
  1110. resolveAll = resolve;
  1111. rejectAll = reject;
  1112. });
  1113. var unresolved = promises.length;
  1114. var results = [];
  1115. if (unresolved === 0) {
  1116. resolveAll(results);
  1117. return deferred;
  1118. }
  1119. function reject(reason) {
  1120. if (deferred._status === STATUS_REJECTED) {
  1121. return;
  1122. }
  1123. results = [];
  1124. rejectAll(reason);
  1125. }
  1126. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1127. var promise = promises[i];
  1128. var resolve = (function(i) {
  1129. return function(value) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results[i] = value;
  1134. unresolved--;
  1135. if (unresolved === 0) {
  1136. resolveAll(results);
  1137. }
  1138. };
  1139. })(i);
  1140. if (Promise.isPromise(promise)) {
  1141. promise.then(resolve, reject);
  1142. } else {
  1143. resolve(promise);
  1144. }
  1145. }
  1146. return deferred;
  1147. };
  1148. /**
  1149. * Checks if the value is likely a promise (has a 'then' function).
  1150. * @return {boolean} true if value is thenable
  1151. */
  1152. Promise.isPromise = function Promise_isPromise(value) {
  1153. return value && typeof value.then === 'function';
  1154. };
  1155. /**
  1156. * Creates resolved promise
  1157. * @param value resolve value
  1158. * @returns {Promise}
  1159. */
  1160. Promise.resolve = function Promise_resolve(value) {
  1161. return new Promise(function (resolve) { resolve(value); });
  1162. };
  1163. /**
  1164. * Creates rejected promise
  1165. * @param reason rejection value
  1166. * @returns {Promise}
  1167. */
  1168. Promise.reject = function Promise_reject(reason) {
  1169. return new Promise(function (resolve, reject) { reject(reason); });
  1170. };
  1171. Promise.prototype = {
  1172. _status: null,
  1173. _value: null,
  1174. _handlers: null,
  1175. _unhandledRejection: null,
  1176. _updateStatus: function Promise__updateStatus(status, value) {
  1177. if (this._status === STATUS_RESOLVED ||
  1178. this._status === STATUS_REJECTED) {
  1179. return;
  1180. }
  1181. if (status === STATUS_RESOLVED &&
  1182. Promise.isPromise(value)) {
  1183. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1184. this._updateStatus.bind(this, STATUS_REJECTED));
  1185. return;
  1186. }
  1187. this._status = status;
  1188. this._value = value;
  1189. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1190. this._unhandledRejection = true;
  1191. HandlerManager.addUnhandledRejection(this);
  1192. }
  1193. HandlerManager.scheduleHandlers(this);
  1194. },
  1195. _resolve: function Promise_resolve(value) {
  1196. this._updateStatus(STATUS_RESOLVED, value);
  1197. },
  1198. _reject: function Promise_reject(reason) {
  1199. this._updateStatus(STATUS_REJECTED, reason);
  1200. },
  1201. then: function Promise_then(onResolve, onReject) {
  1202. var nextPromise = new Promise(function (resolve, reject) {
  1203. this.resolve = resolve;
  1204. this.reject = reject;
  1205. });
  1206. this._handlers.push({
  1207. thisPromise: this,
  1208. onResolve: onResolve,
  1209. onReject: onReject,
  1210. nextPromise: nextPromise
  1211. });
  1212. HandlerManager.scheduleHandlers(this);
  1213. return nextPromise;
  1214. },
  1215. catch: function Promise_catch(onReject) {
  1216. return this.then(undefined, onReject);
  1217. }
  1218. };
  1219. globalScope.Promise = Promise;
  1220. })();
  1221. var StatTimer = (function StatTimerClosure() {
  1222. function rpad(str, pad, length) {
  1223. while (str.length < length) {
  1224. str += pad;
  1225. }
  1226. return str;
  1227. }
  1228. function StatTimer() {
  1229. this.started = {};
  1230. this.times = [];
  1231. this.enabled = true;
  1232. }
  1233. StatTimer.prototype = {
  1234. time: function StatTimer_time(name) {
  1235. if (!this.enabled) {
  1236. return;
  1237. }
  1238. if (name in this.started) {
  1239. warn('Timer is already running for ' + name);
  1240. }
  1241. this.started[name] = Date.now();
  1242. },
  1243. timeEnd: function StatTimer_timeEnd(name) {
  1244. if (!this.enabled) {
  1245. return;
  1246. }
  1247. if (!(name in this.started)) {
  1248. warn('Timer has not been started for ' + name);
  1249. }
  1250. this.times.push({
  1251. 'name': name,
  1252. 'start': this.started[name],
  1253. 'end': Date.now()
  1254. });
  1255. // Remove timer from started so it can be called again.
  1256. delete this.started[name];
  1257. },
  1258. toString: function StatTimer_toString() {
  1259. var i, ii;
  1260. var times = this.times;
  1261. var out = '';
  1262. // Find the longest name for padding purposes.
  1263. var longest = 0;
  1264. for (i = 0, ii = times.length; i < ii; ++i) {
  1265. var name = times[i]['name'];
  1266. if (name.length > longest) {
  1267. longest = name.length;
  1268. }
  1269. }
  1270. for (i = 0, ii = times.length; i < ii; ++i) {
  1271. var span = times[i];
  1272. var duration = span.end - span.start;
  1273. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1274. }
  1275. return out;
  1276. }
  1277. };
  1278. return StatTimer;
  1279. })();
  1280. PDFJS.createBlob = function createBlob(data, contentType) {
  1281. if (typeof Blob !== 'undefined') {
  1282. return new Blob([data], { type: contentType });
  1283. }
  1284. // Blob builder is deprecated in FF14 and removed in FF18.
  1285. var bb = new MozBlobBuilder();
  1286. bb.append(data);
  1287. return bb.getBlob(contentType);
  1288. };
  1289. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1290. // Blob/createObjectURL is not available, falling back to data schema.
  1291. var digits =
  1292. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1293. return function createObjectURL(data, contentType) {
  1294. if (!PDFJS.disableCreateObjectURL &&
  1295. typeof URL !== 'undefined' && URL.createObjectURL) {
  1296. var blob = PDFJS.createBlob(data, contentType);
  1297. return URL.createObjectURL(blob);
  1298. }
  1299. var buffer = 'data:' + contentType + ';base64,';
  1300. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1301. var b1 = data[i] & 0xFF;
  1302. var b2 = data[i + 1] & 0xFF;
  1303. var b3 = data[i + 2] & 0xFF;
  1304. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1305. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1306. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1307. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1308. }
  1309. return buffer;
  1310. };
  1311. })();
  1312. function MessageHandler(name, comObj) {
  1313. this.name = name;
  1314. this.comObj = comObj;
  1315. this.callbackIndex = 1;
  1316. this.postMessageTransfers = true;
  1317. var callbacksCapabilities = this.callbacksCapabilities = {};
  1318. var ah = this.actionHandler = {};
  1319. ah['console_log'] = [function ahConsoleLog(data) {
  1320. console.log.apply(console, data);
  1321. }];
  1322. ah['console_error'] = [function ahConsoleError(data) {
  1323. console.error.apply(console, data);
  1324. }];
  1325. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1326. UnsupportedManager.notify(data);
  1327. }];
  1328. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1329. var data = event.data;
  1330. if (data.isReply) {
  1331. var callbackId = data.callbackId;
  1332. if (data.callbackId in callbacksCapabilities) {
  1333. var callback = callbacksCapabilities[callbackId];
  1334. delete callbacksCapabilities[callbackId];
  1335. if ('error' in data) {
  1336. callback.reject(data.error);
  1337. } else {
  1338. callback.resolve(data.data);
  1339. }
  1340. } else {
  1341. error('Cannot resolve callback ' + callbackId);
  1342. }
  1343. } else if (data.action in ah) {
  1344. var action = ah[data.action];
  1345. if (data.callbackId) {
  1346. Promise.resolve().then(function () {
  1347. return action[0].call(action[1], data.data);
  1348. }).then(function (result) {
  1349. comObj.postMessage({
  1350. isReply: true,
  1351. callbackId: data.callbackId,
  1352. data: result
  1353. });
  1354. }, function (reason) {
  1355. comObj.postMessage({
  1356. isReply: true,
  1357. callbackId: data.callbackId,
  1358. error: reason
  1359. });
  1360. });
  1361. } else {
  1362. action[0].call(action[1], data.data);
  1363. }
  1364. } else {
  1365. error('Unknown action from worker: ' + data.action);
  1366. }
  1367. };
  1368. }
  1369. MessageHandler.prototype = {
  1370. on: function messageHandlerOn(actionName, handler, scope) {
  1371. var ah = this.actionHandler;
  1372. if (ah[actionName]) {
  1373. error('There is already an actionName called "' + actionName + '"');
  1374. }
  1375. ah[actionName] = [handler, scope];
  1376. },
  1377. /**
  1378. * Sends a message to the comObj to invoke the action with the supplied data.
  1379. * @param {String} actionName Action to call.
  1380. * @param {JSON} data JSON data to send.
  1381. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1382. */
  1383. send: function messageHandlerSend(actionName, data, transfers) {
  1384. var message = {
  1385. action: actionName,
  1386. data: data
  1387. };
  1388. this.postMessage(message, transfers);
  1389. },
  1390. /**
  1391. * Sends a message to the comObj to invoke the action with the supplied data.
  1392. * Expects that other side will callback with the response.
  1393. * @param {String} actionName Action to call.
  1394. * @param {JSON} data JSON data to send.
  1395. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1396. * @returns {Promise} Promise to be resolved with response data.
  1397. */
  1398. sendWithPromise:
  1399. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1400. var callbackId = this.callbackIndex++;
  1401. var message = {
  1402. action: actionName,
  1403. data: data,
  1404. callbackId: callbackId
  1405. };
  1406. var capability = createPromiseCapability();
  1407. this.callbacksCapabilities[callbackId] = capability;
  1408. try {
  1409. this.postMessage(message, transfers);
  1410. } catch (e) {
  1411. capability.reject(e);
  1412. }
  1413. return capability.promise;
  1414. },
  1415. /**
  1416. * Sends raw message to the comObj.
  1417. * @private
  1418. * @param message {Object} Raw message.
  1419. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1420. */
  1421. postMessage: function (message, transfers) {
  1422. if (transfers && this.postMessageTransfers) {
  1423. this.comObj.postMessage(message, transfers);
  1424. } else {
  1425. this.comObj.postMessage(message);
  1426. }
  1427. }
  1428. };
  1429. function loadJpegStream(id, imageUrl, objs) {
  1430. var img = new Image();
  1431. img.onload = (function loadJpegStream_onloadClosure() {
  1432. objs.resolve(id, img);
  1433. });
  1434. img.onerror = (function loadJpegStream_onerrorClosure() {
  1435. objs.resolve(id, null);
  1436. warn('Error during JPEG image loading');
  1437. });
  1438. img.src = imageUrl;
  1439. }
  1440. var NetworkManager = (function NetworkManagerClosure() {
  1441. var OK_RESPONSE = 200;
  1442. var PARTIAL_CONTENT_RESPONSE = 206;
  1443. function NetworkManager(url, args) {
  1444. this.url = url;
  1445. args = args || {};
  1446. this.isHttp = /^https?:/i.test(url);
  1447. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1448. this.withCredentials = args.withCredentials || false;
  1449. this.getXhr = args.getXhr ||
  1450. function NetworkManager_getXhr() {
  1451. return new XMLHttpRequest();
  1452. };
  1453. this.currXhrId = 0;
  1454. this.pendingRequests = {};
  1455. this.loadedRequests = {};
  1456. }
  1457. function getArrayBuffer(xhr) {
  1458. var data = xhr.response;
  1459. if (typeof data !== 'string') {
  1460. return data;
  1461. }
  1462. var length = data.length;
  1463. var array = new Uint8Array(length);
  1464. for (var i = 0; i < length; i++) {
  1465. array[i] = data.charCodeAt(i) & 0xFF;
  1466. }
  1467. return array.buffer;
  1468. }
  1469. NetworkManager.prototype = {
  1470. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1471. var args = {
  1472. begin: begin,
  1473. end: end
  1474. };
  1475. for (var prop in listeners) {
  1476. args[prop] = listeners[prop];
  1477. }
  1478. return this.request(args);
  1479. },
  1480. requestFull: function NetworkManager_requestFull(listeners) {
  1481. return this.request(listeners);
  1482. },
  1483. request: function NetworkManager_request(args) {
  1484. var xhr = this.getXhr();
  1485. var xhrId = this.currXhrId++;
  1486. var pendingRequest = this.pendingRequests[xhrId] = {
  1487. xhr: xhr
  1488. };
  1489. xhr.open('GET', this.url);
  1490. xhr.withCredentials = this.withCredentials;
  1491. for (var property in this.httpHeaders) {
  1492. var value = this.httpHeaders[property];
  1493. if (typeof value === 'undefined') {
  1494. continue;
  1495. }
  1496. xhr.setRequestHeader(property, value);
  1497. }
  1498. if (this.isHttp && 'begin' in args && 'end' in args) {
  1499. var rangeStr = args.begin + '-' + (args.end - 1);
  1500. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1501. pendingRequest.expectedStatus = 206;
  1502. } else {
  1503. pendingRequest.expectedStatus = 200;
  1504. }
  1505. if (args.onProgressiveData) {
  1506. // Some legacy browsers might throw an exception.
  1507. try {
  1508. xhr.responseType = 'moz-chunked-arraybuffer';
  1509. } catch(e) {}
  1510. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1511. pendingRequest.onProgressiveData = args.onProgressiveData;
  1512. pendingRequest.mozChunked = true;
  1513. } else {
  1514. xhr.responseType = 'arraybuffer';
  1515. }
  1516. } else {
  1517. xhr.responseType = 'arraybuffer';
  1518. }
  1519. if (args.onError) {
  1520. xhr.onerror = function(evt) {
  1521. args.onError(xhr.status);
  1522. };
  1523. }
  1524. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1525. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1526. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1527. pendingRequest.onDone = args.onDone;
  1528. pendingRequest.onError = args.onError;
  1529. pendingRequest.onProgress = args.onProgress;
  1530. xhr.send(null);
  1531. return xhrId;
  1532. },
  1533. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1534. var pendingRequest = this.pendingRequests[xhrId];
  1535. if (!pendingRequest) {
  1536. // Maybe abortRequest was called...
  1537. return;
  1538. }
  1539. if (pendingRequest.mozChunked) {
  1540. var chunk = getArrayBuffer(pendingRequest.xhr);
  1541. pendingRequest.onProgressiveData(chunk);
  1542. }
  1543. var onProgress = pendingRequest.onProgress;
  1544. if (onProgress) {
  1545. onProgress(evt);
  1546. }
  1547. },
  1548. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1549. var pendingRequest = this.pendingRequests[xhrId];
  1550. if (!pendingRequest) {
  1551. // Maybe abortRequest was called...
  1552. return;
  1553. }
  1554. var xhr = pendingRequest.xhr;
  1555. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1556. pendingRequest.onHeadersReceived();
  1557. delete pendingRequest.onHeadersReceived;
  1558. }
  1559. if (xhr.readyState !== 4) {
  1560. return;
  1561. }
  1562. if (!(xhrId in this.pendingRequests)) {
  1563. // The XHR request might have been aborted in onHeadersReceived()
  1564. // callback, in which case we should abort request
  1565. return;
  1566. }
  1567. delete this.pendingRequests[xhrId];
  1568. // success status == 0 can be on ftp, file and other protocols
  1569. if (xhr.status === 0 && this.isHttp) {
  1570. if (pendingRequest.onError) {
  1571. pendingRequest.onError(xhr.status);
  1572. }
  1573. return;
  1574. }
  1575. var xhrStatus = xhr.status || OK_RESPONSE;
  1576. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1577. // "A server MAY ignore the Range header". This means it's possible to
  1578. // get a 200 rather than a 206 response from a range request.
  1579. var ok_response_on_range_request =
  1580. xhrStatus === OK_RESPONSE &&
  1581. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1582. if (!ok_response_on_range_request &&
  1583. xhrStatus !== pendingRequest.expectedStatus) {
  1584. if (pendingRequest.onError) {
  1585. pendingRequest.onError(xhr.status);
  1586. }
  1587. return;
  1588. }
  1589. this.loadedRequests[xhrId] = true;
  1590. var chunk = getArrayBuffer(xhr);
  1591. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1592. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1593. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1594. var begin = parseInt(matches[1], 10);
  1595. pendingRequest.onDone({
  1596. begin: begin,
  1597. chunk: chunk
  1598. });
  1599. } else if (pendingRequest.onProgressiveData) {
  1600. pendingRequest.onDone(null);
  1601. } else {
  1602. pendingRequest.onDone({
  1603. begin: 0,
  1604. chunk: chunk
  1605. });
  1606. }
  1607. },
  1608. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1609. for (var xhrId in this.pendingRequests) {
  1610. return true;
  1611. }
  1612. return false;
  1613. },
  1614. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1615. return this.pendingRequests[xhrId].xhr;
  1616. },
  1617. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1618. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1619. },
  1620. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1621. return xhrId in this.pendingRequests;
  1622. },
  1623. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1624. return xhrId in this.loadedRequests;
  1625. },
  1626. abortAllRequests: function NetworkManager_abortAllRequests() {
  1627. for (var xhrId in this.pendingRequests) {
  1628. this.abortRequest(xhrId | 0);
  1629. }
  1630. },
  1631. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1632. var xhr = this.pendingRequests[xhrId].xhr;
  1633. delete this.pendingRequests[xhrId];
  1634. xhr.abort();
  1635. }
  1636. };
  1637. return NetworkManager;
  1638. })();
  1639. var ChunkedStream = (function ChunkedStreamClosure() {
  1640. function ChunkedStream(length, chunkSize, manager) {
  1641. this.bytes = new Uint8Array(length);
  1642. this.start = 0;
  1643. this.pos = 0;
  1644. this.end = length;
  1645. this.chunkSize = chunkSize;
  1646. this.loadedChunks = [];
  1647. this.numChunksLoaded = 0;
  1648. this.numChunks = Math.ceil(length / chunkSize);
  1649. this.manager = manager;
  1650. this.progressiveDataLength = 0;
  1651. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1652. }
  1653. // required methods for a stream. if a particular stream does not
  1654. // implement these, an error should be thrown
  1655. ChunkedStream.prototype = {
  1656. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1657. var chunks = [];
  1658. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1659. if (!this.loadedChunks[chunk]) {
  1660. chunks.push(chunk);
  1661. }
  1662. }
  1663. return chunks;
  1664. },
  1665. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1666. return [this];
  1667. },
  1668. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1669. return this.numChunksLoaded === this.numChunks;
  1670. },
  1671. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1672. var end = begin + chunk.byteLength;
  1673. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1674. // Using this.length is inaccurate here since this.start can be moved
  1675. // See ChunkedStream.moveStart()
  1676. var length = this.bytes.length;
  1677. assert(end % this.chunkSize === 0 || end === length,
  1678. 'Bad end offset: ' + end);
  1679. this.bytes.set(new Uint8Array(chunk), begin);
  1680. var chunkSize = this.chunkSize;
  1681. var beginChunk = Math.floor(begin / chunkSize);
  1682. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1683. var curChunk;
  1684. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1685. if (!this.loadedChunks[curChunk]) {
  1686. this.loadedChunks[curChunk] = true;
  1687. ++this.numChunksLoaded;
  1688. }
  1689. }
  1690. },
  1691. onReceiveProgressiveData:
  1692. function ChunkedStream_onReceiveProgressiveData(data) {
  1693. var position = this.progressiveDataLength;
  1694. var beginChunk = Math.floor(position / this.chunkSize);
  1695. this.bytes.set(new Uint8Array(data), position);
  1696. position += data.byteLength;
  1697. this.progressiveDataLength = position;
  1698. var endChunk = position >= this.end ? this.numChunks :
  1699. Math.floor(position / this.chunkSize);
  1700. var curChunk;
  1701. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1702. if (!this.loadedChunks[curChunk]) {
  1703. this.loadedChunks[curChunk] = true;
  1704. ++this.numChunksLoaded;
  1705. }
  1706. }
  1707. },
  1708. ensureByte: function ChunkedStream_ensureByte(pos) {
  1709. var chunk = Math.floor(pos / this.chunkSize);
  1710. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1711. return;
  1712. }
  1713. if (!this.loadedChunks[chunk]) {
  1714. throw new MissingDataException(pos, pos + 1);
  1715. }
  1716. this.lastSuccessfulEnsureByteChunk = chunk;
  1717. },
  1718. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1719. if (begin >= end) {
  1720. return;
  1721. }
  1722. if (end <= this.progressiveDataLength) {
  1723. return;
  1724. }
  1725. var chunkSize = this.chunkSize;
  1726. var beginChunk = Math.floor(begin / chunkSize);
  1727. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1728. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1729. if (!this.loadedChunks[chunk]) {
  1730. throw new MissingDataException(begin, end);
  1731. }
  1732. }
  1733. },
  1734. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1735. var chunk, n;
  1736. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1737. if (!this.loadedChunks[chunk]) {
  1738. return chunk;
  1739. }
  1740. }
  1741. // Wrap around to beginning
  1742. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1743. if (!this.loadedChunks[chunk]) {
  1744. return chunk;
  1745. }
  1746. }
  1747. return null;
  1748. },
  1749. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1750. return !!this.loadedChunks[chunk];
  1751. },
  1752. get length() {
  1753. return this.end - this.start;
  1754. },
  1755. get isEmpty() {
  1756. return this.length === 0;
  1757. },
  1758. getByte: function ChunkedStream_getByte() {
  1759. var pos = this.pos;
  1760. if (pos >= this.end) {
  1761. return -1;
  1762. }
  1763. this.ensureByte(pos);
  1764. return this.bytes[this.pos++];
  1765. },
  1766. getUint16: function ChunkedStream_getUint16() {
  1767. var b0 = this.getByte();
  1768. var b1 = this.getByte();
  1769. if (b0 === -1 || b1 === -1) {
  1770. return -1;
  1771. }
  1772. return (b0 << 8) + b1;
  1773. },
  1774. getInt32: function ChunkedStream_getInt32() {
  1775. var b0 = this.getByte();
  1776. var b1 = this.getByte();
  1777. var b2 = this.getByte();
  1778. var b3 = this.getByte();
  1779. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1780. },
  1781. // returns subarray of original buffer
  1782. // should only be read
  1783. getBytes: function ChunkedStream_getBytes(length) {
  1784. var bytes = this.bytes;
  1785. var pos = this.pos;
  1786. var strEnd = this.end;
  1787. if (!length) {
  1788. this.ensureRange(pos, strEnd);
  1789. return bytes.subarray(pos, strEnd);
  1790. }
  1791. var end = pos + length;
  1792. if (end > strEnd) {
  1793. end = strEnd;
  1794. }
  1795. this.ensureRange(pos, end);
  1796. this.pos = end;
  1797. return bytes.subarray(pos, end);
  1798. },
  1799. peekByte: function ChunkedStream_peekByte() {
  1800. var peekedByte = this.getByte();
  1801. this.pos--;
  1802. return peekedByte;
  1803. },
  1804. peekBytes: function ChunkedStream_peekBytes(length) {
  1805. var bytes = this.getBytes(length);
  1806. this.pos -= bytes.length;
  1807. return bytes;
  1808. },
  1809. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1810. this.ensureRange(begin, end);
  1811. return this.bytes.subarray(begin, end);
  1812. },
  1813. skip: function ChunkedStream_skip(n) {
  1814. if (!n) {
  1815. n = 1;
  1816. }
  1817. this.pos += n;
  1818. },
  1819. reset: function ChunkedStream_reset() {
  1820. this.pos = this.start;
  1821. },
  1822. moveStart: function ChunkedStream_moveStart() {
  1823. this.start = this.pos;
  1824. },
  1825. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1826. this.ensureRange(start, start + length);
  1827. function ChunkedStreamSubstream() {}
  1828. ChunkedStreamSubstream.prototype = Object.create(this);
  1829. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1830. var chunkSize = this.chunkSize;
  1831. var beginChunk = Math.floor(this.start / chunkSize);
  1832. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1833. var missingChunks = [];
  1834. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1835. if (!this.loadedChunks[chunk]) {
  1836. missingChunks.push(chunk);
  1837. }
  1838. }
  1839. return missingChunks;
  1840. };
  1841. var subStream = new ChunkedStreamSubstream();
  1842. subStream.pos = subStream.start = start;
  1843. subStream.end = start + length || this.end;
  1844. subStream.dict = dict;
  1845. return subStream;
  1846. },
  1847. isStream: true
  1848. };
  1849. return ChunkedStream;
  1850. })();
  1851. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1852. function ChunkedStreamManager(length, chunkSize, url, args) {
  1853. this.stream = new ChunkedStream(length, chunkSize, this);
  1854. this.length = length;
  1855. this.chunkSize = chunkSize;
  1856. this.url = url;
  1857. this.disableAutoFetch = args.disableAutoFetch;
  1858. var msgHandler = this.msgHandler = args.msgHandler;
  1859. if (args.chunkedViewerLoading) {
  1860. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1861. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1862. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1863. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1864. };
  1865. } else {
  1866. var getXhr = function getXhr() {
  1867. return new XMLHttpRequest();
  1868. };
  1869. this.networkManager = new NetworkManager(this.url, {
  1870. getXhr: getXhr,
  1871. httpHeaders: args.httpHeaders,
  1872. withCredentials: args.withCredentials
  1873. });
  1874. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1875. this.networkManager.requestRange(begin, end, {
  1876. onDone: this.onReceiveData.bind(this),
  1877. onProgress: this.onProgress.bind(this)
  1878. });
  1879. };
  1880. }
  1881. this.currRequestId = 0;
  1882. this.chunksNeededByRequest = {};
  1883. this.requestsByChunk = {};
  1884. this.callbacksByRequest = {};
  1885. this.progressiveDataLength = 0;
  1886. this._loadedStreamCapability = createPromiseCapability();
  1887. if (args.initialData) {
  1888. this.onReceiveData({chunk: args.initialData});
  1889. }
  1890. }
  1891. ChunkedStreamManager.prototype = {
  1892. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1893. return this._loadedStreamCapability.promise;
  1894. },
  1895. // Get all the chunks that are not yet loaded and groups them into
  1896. // contiguous ranges to load in as few requests as possible
  1897. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1898. var missingChunks = this.stream.getMissingChunks();
  1899. this.requestChunks(missingChunks);
  1900. return this._loadedStreamCapability.promise;
  1901. },
  1902. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1903. callback) {
  1904. var requestId = this.currRequestId++;
  1905. var chunksNeeded;
  1906. var i, ii;
  1907. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1908. for (i = 0, ii = chunks.length; i < ii; i++) {
  1909. if (!this.stream.hasChunk(chunks[i])) {
  1910. chunksNeeded[chunks[i]] = true;
  1911. }
  1912. }
  1913. if (isEmptyObj(chunksNeeded)) {
  1914. if (callback) {
  1915. callback();
  1916. }
  1917. return;
  1918. }
  1919. this.callbacksByRequest[requestId] = callback;
  1920. var chunksToRequest = [];
  1921. for (var chunk in chunksNeeded) {
  1922. chunk = chunk | 0;
  1923. if (!(chunk in this.requestsByChunk)) {
  1924. this.requestsByChunk[chunk] = [];
  1925. chunksToRequest.push(chunk);
  1926. }
  1927. this.requestsByChunk[chunk].push(requestId);
  1928. }
  1929. if (!chunksToRequest.length) {
  1930. return;
  1931. }
  1932. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1933. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1934. var groupedChunk = groupedChunksToRequest[i];
  1935. var begin = groupedChunk.beginChunk * this.chunkSize;
  1936. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1937. this.sendRequest(begin, end);
  1938. }
  1939. },
  1940. getStream: function ChunkedStreamManager_getStream() {
  1941. return this.stream;
  1942. },
  1943. // Loads any chunks in the requested range that are not yet loaded
  1944. requestRange: function ChunkedStreamManager_requestRange(
  1945. begin, end, callback) {
  1946. end = Math.min(end, this.length);
  1947. var beginChunk = this.getBeginChunk(begin);
  1948. var endChunk = this.getEndChunk(end);
  1949. var chunks = [];
  1950. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1951. chunks.push(chunk);
  1952. }
  1953. this.requestChunks(chunks, callback);
  1954. },
  1955. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1956. callback) {
  1957. ranges = ranges || [];
  1958. var chunksToRequest = [];
  1959. for (var i = 0; i < ranges.length; i++) {
  1960. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1961. var endChunk = this.getEndChunk(ranges[i].end);
  1962. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1963. if (chunksToRequest.indexOf(chunk) < 0) {
  1964. chunksToRequest.push(chunk);
  1965. }
  1966. }
  1967. }
  1968. chunksToRequest.sort(function(a, b) { return a - b; });
  1969. this.requestChunks(chunksToRequest, callback);
  1970. },
  1971. // Groups a sorted array of chunks into as few continguous larger
  1972. // chunks as possible
  1973. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1974. var groupedChunks = [];
  1975. var beginChunk = -1;
  1976. var prevChunk = -1;
  1977. for (var i = 0; i < chunks.length; ++i) {
  1978. var chunk = chunks[i];
  1979. if (beginChunk < 0) {
  1980. beginChunk = chunk;
  1981. }
  1982. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1983. groupedChunks.push({ beginChunk: beginChunk,
  1984. endChunk: prevChunk + 1 });
  1985. beginChunk = chunk;
  1986. }
  1987. if (i + 1 === chunks.length) {
  1988. groupedChunks.push({ beginChunk: beginChunk,
  1989. endChunk: chunk + 1 });
  1990. }
  1991. prevChunk = chunk;
  1992. }
  1993. return groupedChunks;
  1994. },
  1995. onProgress: function ChunkedStreamManager_onProgress(args) {
  1996. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1997. args.loaded);
  1998. this.msgHandler.send('DocProgress', {
  1999. loaded: bytesLoaded,
  2000. total: this.length
  2001. });
  2002. },
  2003. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2004. var chunk = args.chunk;
  2005. var isProgressive = args.begin === undefined;
  2006. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2007. var end = begin + chunk.byteLength;
  2008. var beginChunk = Math.floor(begin / this.chunkSize);
  2009. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2010. Math.ceil(end / this.chunkSize);
  2011. if (isProgressive) {
  2012. this.stream.onReceiveProgressiveData(chunk);
  2013. this.progressiveDataLength = end;
  2014. } else {
  2015. this.stream.onReceiveData(begin, chunk);
  2016. }
  2017. if (this.stream.allChunksLoaded()) {
  2018. this._loadedStreamCapability.resolve(this.stream);
  2019. }
  2020. var loadedRequests = [];
  2021. var i, requestId;
  2022. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2023. // The server might return more chunks than requested
  2024. var requestIds = this.requestsByChunk[chunk] || [];
  2025. delete this.requestsByChunk[chunk];
  2026. for (i = 0; i < requestIds.length; ++i) {
  2027. requestId = requestIds[i];
  2028. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2029. if (chunk in chunksNeeded) {
  2030. delete chunksNeeded[chunk];
  2031. }
  2032. if (!isEmptyObj(chunksNeeded)) {
  2033. continue;
  2034. }
  2035. loadedRequests.push(requestId);
  2036. }
  2037. }
  2038. // If there are no pending requests, automatically fetch the next
  2039. // unfetched chunk of the PDF
  2040. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2041. var nextEmptyChunk;
  2042. if (this.stream.numChunksLoaded === 1) {
  2043. // This is a special optimization so that after fetching the first
  2044. // chunk, rather than fetching the second chunk, we fetch the last
  2045. // chunk.
  2046. var lastChunk = this.stream.numChunks - 1;
  2047. if (!this.stream.hasChunk(lastChunk)) {
  2048. nextEmptyChunk = lastChunk;
  2049. }
  2050. } else {
  2051. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2052. }
  2053. if (isInt(nextEmptyChunk)) {
  2054. this.requestChunks([nextEmptyChunk]);
  2055. }
  2056. }
  2057. for (i = 0; i < loadedRequests.length; ++i) {
  2058. requestId = loadedRequests[i];
  2059. var callback = this.callbacksByRequest[requestId];
  2060. delete this.callbacksByRequest[requestId];
  2061. if (callback) {
  2062. callback();
  2063. }
  2064. }
  2065. this.msgHandler.send('DocProgress', {
  2066. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2067. total: this.length
  2068. });
  2069. },
  2070. onError: function ChunkedStreamManager_onError(err) {
  2071. this._loadedStreamCapability.reject(err);
  2072. },
  2073. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2074. var chunk = Math.floor(begin / this.chunkSize);
  2075. return chunk;
  2076. },
  2077. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2078. if (end % this.chunkSize === 0) {
  2079. return end / this.chunkSize;
  2080. }
  2081. // 0 -> 0
  2082. // 1 -> 1
  2083. // 99 -> 1
  2084. // 100 -> 1
  2085. // 101 -> 2
  2086. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2087. return chunk;
  2088. }
  2089. };
  2090. return ChunkedStreamManager;
  2091. })();
  2092. // The maximum number of bytes fetched per range request
  2093. var RANGE_CHUNK_SIZE = 65536;
  2094. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2095. var BasePdfManager = (function BasePdfManagerClosure() {
  2096. function BasePdfManager() {
  2097. throw new Error('Cannot initialize BaseManagerManager');
  2098. }
  2099. BasePdfManager.prototype = {
  2100. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2101. throw new NotImplementedException();
  2102. },
  2103. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2104. return this.ensure(this.pdfDocument, prop, args);
  2105. },
  2106. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2107. return this.ensure(this.pdfDocument.xref, prop, args);
  2108. },
  2109. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2110. return this.ensure(this.pdfDocument.catalog, prop, args);
  2111. },
  2112. getPage: function BasePdfManager_pagePage(pageIndex) {
  2113. return this.pdfDocument.getPage(pageIndex);
  2114. },
  2115. cleanup: function BasePdfManager_cleanup() {
  2116. return this.pdfDocument.cleanup();
  2117. },
  2118. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2119. return new NotImplementedException();
  2120. },
  2121. requestRange: function BasePdfManager_ensure(begin, end) {
  2122. return new NotImplementedException();
  2123. },
  2124. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2125. return new NotImplementedException();
  2126. },
  2127. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2128. return new NotImplementedException();
  2129. },
  2130. updatePassword: function BasePdfManager_updatePassword(password) {
  2131. this.pdfDocument.xref.password = this.password = password;
  2132. if (this._passwordChangedCapability) {
  2133. this._passwordChangedCapability.resolve();
  2134. }
  2135. },
  2136. passwordChanged: function BasePdfManager_passwordChanged() {
  2137. this._passwordChangedCapability = createPromiseCapability();
  2138. return this._passwordChangedCapability.promise;
  2139. },
  2140. terminate: function BasePdfManager_terminate() {
  2141. return new NotImplementedException();
  2142. }
  2143. };
  2144. return BasePdfManager;
  2145. })();
  2146. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2147. function LocalPdfManager(data, password) {
  2148. var stream = new Stream(data);
  2149. this.pdfDocument = new PDFDocument(this, stream, password);
  2150. this._loadedStreamCapability = createPromiseCapability();
  2151. this._loadedStreamCapability.resolve(stream);
  2152. }
  2153. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2154. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2155. LocalPdfManager.prototype.ensure =
  2156. function LocalPdfManager_ensure(obj, prop, args) {
  2157. return new Promise(function (resolve, reject) {
  2158. try {
  2159. var value = obj[prop];
  2160. var result;
  2161. if (typeof value === 'function') {
  2162. result = value.apply(obj, args);
  2163. } else {
  2164. result = value;
  2165. }
  2166. resolve(result);
  2167. } catch (e) {
  2168. reject(e);
  2169. }
  2170. });
  2171. };
  2172. LocalPdfManager.prototype.requestRange =
  2173. function LocalPdfManager_requestRange(begin, end) {
  2174. return Promise.resolve();
  2175. };
  2176. LocalPdfManager.prototype.requestLoadedStream =
  2177. function LocalPdfManager_requestLoadedStream() {
  2178. };
  2179. LocalPdfManager.prototype.onLoadedStream =
  2180. function LocalPdfManager_getLoadedStream() {
  2181. return this._loadedStreamCapability.promise;
  2182. };
  2183. LocalPdfManager.prototype.terminate =
  2184. function LocalPdfManager_terminate() {
  2185. return;
  2186. };
  2187. return LocalPdfManager;
  2188. })();
  2189. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2190. function NetworkPdfManager(args, msgHandler) {
  2191. this.msgHandler = msgHandler;
  2192. var params = {
  2193. msgHandler: msgHandler,
  2194. httpHeaders: args.httpHeaders,
  2195. withCredentials: args.withCredentials,
  2196. chunkedViewerLoading: args.chunkedViewerLoading,
  2197. disableAutoFetch: args.disableAutoFetch,
  2198. initialData: args.initialData
  2199. };
  2200. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2201. args.url, params);
  2202. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2203. args.password);
  2204. }
  2205. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2206. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2207. NetworkPdfManager.prototype.ensure =
  2208. function NetworkPdfManager_ensure(obj, prop, args) {
  2209. var pdfManager = this;
  2210. return new Promise(function (resolve, reject) {
  2211. function ensureHelper() {
  2212. try {
  2213. var result;
  2214. var value = obj[prop];
  2215. if (typeof value === 'function') {
  2216. result = value.apply(obj, args);
  2217. } else {
  2218. result = value;
  2219. }
  2220. resolve(result);
  2221. } catch(e) {
  2222. if (!(e instanceof MissingDataException)) {
  2223. reject(e);
  2224. return;
  2225. }
  2226. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2227. }
  2228. }
  2229. ensureHelper();
  2230. });
  2231. };
  2232. NetworkPdfManager.prototype.requestRange =
  2233. function NetworkPdfManager_requestRange(begin, end) {
  2234. return new Promise(function (resolve) {
  2235. this.streamManager.requestRange(begin, end, function() {
  2236. resolve();
  2237. });
  2238. }.bind(this));
  2239. };
  2240. NetworkPdfManager.prototype.requestLoadedStream =
  2241. function NetworkPdfManager_requestLoadedStream() {
  2242. this.streamManager.requestAllChunks();
  2243. };
  2244. NetworkPdfManager.prototype.sendProgressiveData =
  2245. function NetworkPdfManager_sendProgressiveData(chunk) {
  2246. this.streamManager.onReceiveData({ chunk: chunk });
  2247. };
  2248. NetworkPdfManager.prototype.onLoadedStream =
  2249. function NetworkPdfManager_getLoadedStream() {
  2250. return this.streamManager.onLoadedStream();
  2251. };
  2252. NetworkPdfManager.prototype.terminate =
  2253. function NetworkPdfManager_terminate() {
  2254. this.streamManager.networkManager.abortAllRequests();
  2255. };
  2256. return NetworkPdfManager;
  2257. })();
  2258. var Page = (function PageClosure() {
  2259. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2260. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2261. this.pdfManager = pdfManager;
  2262. this.pageIndex = pageIndex;
  2263. this.pageDict = pageDict;
  2264. this.xref = xref;
  2265. this.ref = ref;
  2266. this.fontCache = fontCache;
  2267. this.idCounters = {
  2268. obj: 0
  2269. };
  2270. this.resourcesPromise = null;
  2271. }
  2272. Page.prototype = {
  2273. getPageProp: function Page_getPageProp(key) {
  2274. return this.pageDict.get(key);
  2275. },
  2276. getInheritedPageProp: function Page_inheritPageProp(key) {
  2277. var dict = this.pageDict;
  2278. var value = dict.get(key);
  2279. while (value === undefined) {
  2280. dict = dict.get('Parent');
  2281. if (!dict) {
  2282. break;
  2283. }
  2284. value = dict.get(key);
  2285. }
  2286. return value;
  2287. },
  2288. get content() {
  2289. return this.getPageProp('Contents');
  2290. },
  2291. get resources() {
  2292. var value = this.getInheritedPageProp('Resources');
  2293. // For robustness: The spec states that a \Resources entry has to be
  2294. // present, but can be empty. Some document omit it still. In this case
  2295. // return an empty dictionary:
  2296. if (value === undefined) {
  2297. value = Dict.empty;
  2298. }
  2299. return shadow(this, 'resources', value);
  2300. },
  2301. get mediaBox() {
  2302. var obj = this.getInheritedPageProp('MediaBox');
  2303. // Reset invalid media box to letter size.
  2304. if (!isArray(obj) || obj.length !== 4) {
  2305. obj = LETTER_SIZE_MEDIABOX;
  2306. }
  2307. return shadow(this, 'mediaBox', obj);
  2308. },
  2309. get view() {
  2310. var mediaBox = this.mediaBox;
  2311. var cropBox = this.getInheritedPageProp('CropBox');
  2312. if (!isArray(cropBox) || cropBox.length !== 4) {
  2313. return shadow(this, 'view', mediaBox);
  2314. }
  2315. // From the spec, 6th ed., p.963:
  2316. // "The crop, bleed, trim, and art boxes should not ordinarily
  2317. // extend beyond the boundaries of the media box. If they do, they are
  2318. // effectively reduced to their intersection with the media box."
  2319. cropBox = Util.intersect(cropBox, mediaBox);
  2320. if (!cropBox) {
  2321. return shadow(this, 'view', mediaBox);
  2322. }
  2323. return shadow(this, 'view', cropBox);
  2324. },
  2325. get annotationRefs() {
  2326. return shadow(this, 'annotationRefs',
  2327. this.getInheritedPageProp('Annots'));
  2328. },
  2329. get rotate() {
  2330. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2331. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2332. if (rotate % 90 !== 0) {
  2333. rotate = 0;
  2334. } else if (rotate >= 360) {
  2335. rotate = rotate % 360;
  2336. } else if (rotate < 0) {
  2337. // The spec doesn't cover negatives, assume its counterclockwise
  2338. // rotation. The following is the other implementation of modulo.
  2339. rotate = ((rotate % 360) + 360) % 360;
  2340. }
  2341. return shadow(this, 'rotate', rotate);
  2342. },
  2343. getContentStream: function Page_getContentStream() {
  2344. var content = this.content;
  2345. var stream;
  2346. if (isArray(content)) {
  2347. // fetching items
  2348. var xref = this.xref;
  2349. var i, n = content.length;
  2350. var streams = [];
  2351. for (i = 0; i < n; ++i) {
  2352. streams.push(xref.fetchIfRef(content[i]));
  2353. }
  2354. stream = new StreamsSequenceStream(streams);
  2355. } else if (isStream(content)) {
  2356. stream = content;
  2357. } else {
  2358. // replacing non-existent page content with empty one
  2359. stream = new NullStream();
  2360. }
  2361. return stream;
  2362. },
  2363. loadResources: function Page_loadResources(keys) {
  2364. if (!this.resourcesPromise) {
  2365. // TODO: add async getInheritedPageProp and remove this.
  2366. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2367. }
  2368. return this.resourcesPromise.then(function resourceSuccess() {
  2369. var objectLoader = new ObjectLoader(this.resources.map,
  2370. keys,
  2371. this.xref);
  2372. return objectLoader.load();
  2373. }.bind(this));
  2374. },
  2375. getOperatorList: function Page_getOperatorList(handler, intent) {
  2376. var self = this;
  2377. var pdfManager = this.pdfManager;
  2378. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2379. []);
  2380. var resourcesPromise = this.loadResources([
  2381. 'ExtGState',
  2382. 'ColorSpace',
  2383. 'Pattern',
  2384. 'Shading',
  2385. 'XObject',
  2386. 'Font'
  2387. // ProcSet
  2388. // Properties
  2389. ]);
  2390. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2391. handler, this.pageIndex,
  2392. 'p' + this.pageIndex + '_',
  2393. this.idCounters,
  2394. this.fontCache);
  2395. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2396. var pageListPromise = dataPromises.then(function(data) {
  2397. var contentStream = data[0];
  2398. var opList = new OperatorList(intent, handler, self.pageIndex);
  2399. handler.send('StartRenderPage', {
  2400. transparency: partialEvaluator.hasBlendModes(self.resources),
  2401. pageIndex: self.pageIndex,
  2402. intent: intent
  2403. });
  2404. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2405. opList).then(function () {
  2406. return opList;
  2407. });
  2408. });
  2409. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2410. return Promise.all([pageListPromise, annotationsPromise]).then(
  2411. function(datas) {
  2412. var pageOpList = datas[0];
  2413. var annotations = datas[1];
  2414. if (annotations.length === 0) {
  2415. pageOpList.flush(true);
  2416. return pageOpList;
  2417. }
  2418. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2419. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2420. return annotationsReadyPromise.then(function () {
  2421. pageOpList.flush(true);
  2422. return pageOpList;
  2423. });
  2424. });
  2425. },
  2426. extractTextContent: function Page_extractTextContent() {
  2427. var handler = {
  2428. on: function nullHandlerOn() {},
  2429. send: function nullHandlerSend() {}
  2430. };
  2431. var self = this;
  2432. var pdfManager = this.pdfManager;
  2433. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2434. []);
  2435. var resourcesPromise = this.loadResources([
  2436. 'ExtGState',
  2437. 'XObject',
  2438. 'Font'
  2439. ]);
  2440. var dataPromises = Promise.all([contentStreamPromise,
  2441. resourcesPromise]);
  2442. return dataPromises.then(function(data) {
  2443. var contentStream = data[0];
  2444. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2445. handler, self.pageIndex,
  2446. 'p' + self.pageIndex + '_',
  2447. self.idCounters,
  2448. self.fontCache);
  2449. return partialEvaluator.getTextContent(contentStream,
  2450. self.resources);
  2451. });
  2452. },
  2453. getAnnotationsData: function Page_getAnnotationsData() {
  2454. var annotations = this.annotations;
  2455. var annotationsData = [];
  2456. for (var i = 0, n = annotations.length; i < n; ++i) {
  2457. annotationsData.push(annotations[i].getData());
  2458. }
  2459. return annotationsData;
  2460. },
  2461. get annotations() {
  2462. var annotations = [];
  2463. var annotationRefs = (this.annotationRefs || []);
  2464. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2465. var annotationRef = annotationRefs[i];
  2466. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2467. if (annotation) {
  2468. annotations.push(annotation);
  2469. }
  2470. }
  2471. return shadow(this, 'annotations', annotations);
  2472. }
  2473. };
  2474. return Page;
  2475. })();
  2476. /**
  2477. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2478. * `PDFDoc`, this one doesn't have any job management code.
  2479. * Right now there exists one PDFDocument on the main thread + one object
  2480. * for each worker. If there is no worker support enabled, there are two
  2481. * `PDFDocument` objects on the main thread created.
  2482. */
  2483. var PDFDocument = (function PDFDocumentClosure() {
  2484. var FINGERPRINT_FIRST_BYTES = 1024;
  2485. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2486. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2487. function PDFDocument(pdfManager, arg, password) {
  2488. if (isStream(arg)) {
  2489. init.call(this, pdfManager, arg, password);
  2490. } else if (isArrayBuffer(arg)) {
  2491. init.call(this, pdfManager, new Stream(arg), password);
  2492. } else {
  2493. error('PDFDocument: Unknown argument type');
  2494. }
  2495. }
  2496. function init(pdfManager, stream, password) {
  2497. assert(stream.length > 0, 'stream must have data');
  2498. this.pdfManager = pdfManager;
  2499. this.stream = stream;
  2500. var xref = new XRef(this.stream, password, pdfManager);
  2501. this.xref = xref;
  2502. }
  2503. function find(stream, needle, limit, backwards) {
  2504. var pos = stream.pos;
  2505. var end = stream.end;
  2506. var strBuf = [];
  2507. if (pos + limit > end) {
  2508. limit = end - pos;
  2509. }
  2510. for (var n = 0; n < limit; ++n) {
  2511. strBuf.push(String.fromCharCode(stream.getByte()));
  2512. }
  2513. var str = strBuf.join('');
  2514. stream.pos = pos;
  2515. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2516. if (index === -1) {
  2517. return false; /* not found */
  2518. }
  2519. stream.pos += index;
  2520. return true; /* found */
  2521. }
  2522. var DocumentInfoValidators = {
  2523. get entries() {
  2524. // Lazily build this since all the validation functions below are not
  2525. // defined until after this file loads.
  2526. return shadow(this, 'entries', {
  2527. Title: isString,
  2528. Author: isString,
  2529. Subject: isString,
  2530. Keywords: isString,
  2531. Creator: isString,
  2532. Producer: isString,
  2533. CreationDate: isString,
  2534. ModDate: isString,
  2535. Trapped: isName
  2536. });
  2537. }
  2538. };
  2539. PDFDocument.prototype = {
  2540. parse: function PDFDocument_parse(recoveryMode) {
  2541. this.setup(recoveryMode);
  2542. try {
  2543. // checking if AcroForm is present
  2544. this.acroForm = this.catalog.catDict.get('AcroForm');
  2545. if (this.acroForm) {
  2546. this.xfa = this.acroForm.get('XFA');
  2547. var fields = this.acroForm.get('Fields');
  2548. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2549. !this.xfa) {
  2550. // no fields and no XFA -- not a form (?)
  2551. this.acroForm = null;
  2552. }
  2553. }
  2554. } catch (ex) {
  2555. info('Something wrong with AcroForm entry');
  2556. this.acroForm = null;
  2557. }
  2558. },
  2559. get linearization() {
  2560. var linearization = null;
  2561. if (this.stream.length) {
  2562. try {
  2563. linearization = Linearization.create(this.stream);
  2564. } catch (err) {
  2565. if (err instanceof MissingDataException) {
  2566. throw err;
  2567. }
  2568. info(err);
  2569. }
  2570. }
  2571. // shadow the prototype getter with a data property
  2572. return shadow(this, 'linearization', linearization);
  2573. },
  2574. get startXRef() {
  2575. var stream = this.stream;
  2576. var startXRef = 0;
  2577. var linearization = this.linearization;
  2578. if (linearization) {
  2579. // Find end of first obj.
  2580. stream.reset();
  2581. if (find(stream, 'endobj', 1024)) {
  2582. startXRef = stream.pos + 6;
  2583. }
  2584. } else {
  2585. // Find startxref by jumping backward from the end of the file.
  2586. var step = 1024;
  2587. var found = false, pos = stream.end;
  2588. while (!found && pos > 0) {
  2589. pos -= step - 'startxref'.length;
  2590. if (pos < 0) {
  2591. pos = 0;
  2592. }
  2593. stream.pos = pos;
  2594. found = find(stream, 'startxref', step, true);
  2595. }
  2596. if (found) {
  2597. stream.skip(9);
  2598. var ch;
  2599. do {
  2600. ch = stream.getByte();
  2601. } while (Lexer.isSpace(ch));
  2602. var str = '';
  2603. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2604. str += String.fromCharCode(ch);
  2605. ch = stream.getByte();
  2606. }
  2607. startXRef = parseInt(str, 10);
  2608. if (isNaN(startXRef)) {
  2609. startXRef = 0;
  2610. }
  2611. }
  2612. }
  2613. // shadow the prototype getter with a data property
  2614. return shadow(this, 'startXRef', startXRef);
  2615. },
  2616. get mainXRefEntriesOffset() {
  2617. var mainXRefEntriesOffset = 0;
  2618. var linearization = this.linearization;
  2619. if (linearization) {
  2620. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2621. }
  2622. // shadow the prototype getter with a data property
  2623. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2624. },
  2625. // Find the header, remove leading garbage and setup the stream
  2626. // starting from the header.
  2627. checkHeader: function PDFDocument_checkHeader() {
  2628. var stream = this.stream;
  2629. stream.reset();
  2630. if (find(stream, '%PDF-', 1024)) {
  2631. // Found the header, trim off any garbage before it.
  2632. stream.moveStart();
  2633. // Reading file format version
  2634. var MAX_VERSION_LENGTH = 12;
  2635. var version = '', ch;
  2636. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2637. if (version.length >= MAX_VERSION_LENGTH) {
  2638. break;
  2639. }
  2640. version += String.fromCharCode(ch);
  2641. }
  2642. // removing "%PDF-"-prefix
  2643. this.pdfFormatVersion = version.substring(5);
  2644. return;
  2645. }
  2646. // May not be a PDF file, continue anyway.
  2647. },
  2648. parseStartXRef: function PDFDocument_parseStartXRef() {
  2649. var startXRef = this.startXRef;
  2650. this.xref.setStartXRef(startXRef);
  2651. },
  2652. setup: function PDFDocument_setup(recoveryMode) {
  2653. this.xref.parse(recoveryMode);
  2654. this.catalog = new Catalog(this.pdfManager, this.xref);
  2655. },
  2656. get numPages() {
  2657. var linearization = this.linearization;
  2658. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2659. // shadow the prototype getter
  2660. return shadow(this, 'numPages', num);
  2661. },
  2662. get documentInfo() {
  2663. var docInfo = {
  2664. PDFFormatVersion: this.pdfFormatVersion,
  2665. IsAcroFormPresent: !!this.acroForm,
  2666. IsXFAPresent: !!this.xfa
  2667. };
  2668. var infoDict;
  2669. try {
  2670. infoDict = this.xref.trailer.get('Info');
  2671. } catch (err) {
  2672. info('The document information dictionary is invalid.');
  2673. }
  2674. if (infoDict) {
  2675. var validEntries = DocumentInfoValidators.entries;
  2676. // Only fill the document info with valid entries from the spec.
  2677. for (var key in validEntries) {
  2678. if (infoDict.has(key)) {
  2679. var value = infoDict.get(key);
  2680. // Make sure the value conforms to the spec.
  2681. if (validEntries[key](value)) {
  2682. docInfo[key] = (typeof value !== 'string' ?
  2683. value : stringToPDFString(value));
  2684. } else {
  2685. info('Bad value in document info for "' + key + '"');
  2686. }
  2687. }
  2688. }
  2689. }
  2690. return shadow(this, 'documentInfo', docInfo);
  2691. },
  2692. get fingerprint() {
  2693. var xref = this.xref, idArray, hash, fileID = '';
  2694. if (xref.trailer.has('ID')) {
  2695. idArray = xref.trailer.get('ID');
  2696. }
  2697. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2698. hash = stringToBytes(idArray[0]);
  2699. } else {
  2700. if (this.stream.ensureRange) {
  2701. this.stream.ensureRange(0,
  2702. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2703. }
  2704. hash = calculateMD5(this.stream.bytes.subarray(0,
  2705. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2706. }
  2707. for (var i = 0, n = hash.length; i < n; i++) {
  2708. var hex = hash[i].toString(16);
  2709. fileID += hex.length === 1 ? '0' + hex : hex;
  2710. }
  2711. return shadow(this, 'fingerprint', fileID);
  2712. },
  2713. getPage: function PDFDocument_getPage(pageIndex) {
  2714. return this.catalog.getPage(pageIndex);
  2715. },
  2716. cleanup: function PDFDocument_cleanup() {
  2717. return this.catalog.cleanup();
  2718. }
  2719. };
  2720. return PDFDocument;
  2721. })();
  2722. var Name = (function NameClosure() {
  2723. function Name(name) {
  2724. this.name = name;
  2725. }
  2726. Name.prototype = {};
  2727. var nameCache = {};
  2728. Name.get = function Name_get(name) {
  2729. var nameValue = nameCache[name];
  2730. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2731. };
  2732. return Name;
  2733. })();
  2734. var Cmd = (function CmdClosure() {
  2735. function Cmd(cmd) {
  2736. this.cmd = cmd;
  2737. }
  2738. Cmd.prototype = {};
  2739. var cmdCache = {};
  2740. Cmd.get = function Cmd_get(cmd) {
  2741. var cmdValue = cmdCache[cmd];
  2742. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2743. };
  2744. return Cmd;
  2745. })();
  2746. var Dict = (function DictClosure() {
  2747. var nonSerializable = function nonSerializableClosure() {
  2748. return nonSerializable; // creating closure on some variable
  2749. };
  2750. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2751. 'Background': true,
  2752. 'ExtGState': true,
  2753. 'Halftone': true,
  2754. 'Layout': true,
  2755. 'Mask': true,
  2756. 'Pagination': true,
  2757. 'Printing': true
  2758. };
  2759. function isRecursionAllowedFor(dict) {
  2760. if (!isName(dict.Type)) {
  2761. return true;
  2762. }
  2763. var dictType = dict.Type.name;
  2764. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2765. }
  2766. // xref is optional
  2767. function Dict(xref) {
  2768. // Map should only be used internally, use functions below to access.
  2769. this.map = Object.create(null);
  2770. this.xref = xref;
  2771. this.objId = null;
  2772. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2773. }
  2774. Dict.prototype = {
  2775. assignXref: function Dict_assignXref(newXref) {
  2776. this.xref = newXref;
  2777. },
  2778. // automatically dereferences Ref objects
  2779. get: function Dict_get(key1, key2, key3) {
  2780. var value;
  2781. var xref = this.xref;
  2782. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2783. typeof key2 === 'undefined') {
  2784. return xref ? xref.fetchIfRef(value) : value;
  2785. }
  2786. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2787. typeof key3 === 'undefined') {
  2788. return xref ? xref.fetchIfRef(value) : value;
  2789. }
  2790. value = this.map[key3] || null;
  2791. return xref ? xref.fetchIfRef(value) : value;
  2792. },
  2793. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2794. getAsync: function Dict_getAsync(key1, key2, key3) {
  2795. var value;
  2796. var xref = this.xref;
  2797. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2798. typeof key2 === 'undefined') {
  2799. if (xref) {
  2800. return xref.fetchIfRefAsync(value);
  2801. }
  2802. return Promise.resolve(value);
  2803. }
  2804. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2805. typeof key3 === 'undefined') {
  2806. if (xref) {
  2807. return xref.fetchIfRefAsync(value);
  2808. }
  2809. return Promise.resolve(value);
  2810. }
  2811. value = this.map[key3] || null;
  2812. if (xref) {
  2813. return xref.fetchIfRefAsync(value);
  2814. }
  2815. return Promise.resolve(value);
  2816. },
  2817. // no dereferencing
  2818. getRaw: function Dict_getRaw(key) {
  2819. return this.map[key];
  2820. },
  2821. // creates new map and dereferences all Refs
  2822. getAll: function Dict_getAll() {
  2823. var all = Object.create(null);
  2824. var queue = null;
  2825. var key, obj;
  2826. for (key in this.map) {
  2827. obj = this.get(key);
  2828. if (obj instanceof Dict) {
  2829. if (isRecursionAllowedFor(obj)) {
  2830. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2831. } else {
  2832. all[key] = this.getRaw(key);
  2833. }
  2834. } else {
  2835. all[key] = obj;
  2836. }
  2837. }
  2838. if (!queue) {
  2839. return all;
  2840. }
  2841. // trying to take cyclic references into the account
  2842. var processed = Object.create(null);
  2843. while (queue.length > 0) {
  2844. var item = queue.shift();
  2845. var itemObj = item.obj;
  2846. var objId = itemObj.objId;
  2847. if (objId && objId in processed) {
  2848. item.target[item.key] = processed[objId];
  2849. continue;
  2850. }
  2851. var dereferenced = Object.create(null);
  2852. for (key in itemObj.map) {
  2853. obj = itemObj.get(key);
  2854. if (obj instanceof Dict) {
  2855. if (isRecursionAllowedFor(obj)) {
  2856. queue.push({target: dereferenced, key: key, obj: obj});
  2857. } else {
  2858. dereferenced[key] = itemObj.getRaw(key);
  2859. }
  2860. } else {
  2861. dereferenced[key] = obj;
  2862. }
  2863. }
  2864. if (objId) {
  2865. processed[objId] = dereferenced;
  2866. }
  2867. item.target[item.key] = dereferenced;
  2868. }
  2869. return all;
  2870. },
  2871. getKeys: function Dict_getKeys() {
  2872. return Object.keys(this.map);
  2873. },
  2874. set: function Dict_set(key, value) {
  2875. this.map[key] = value;
  2876. },
  2877. has: function Dict_has(key) {
  2878. return key in this.map;
  2879. },
  2880. forEach: function Dict_forEach(callback) {
  2881. for (var key in this.map) {
  2882. callback(key, this.get(key));
  2883. }
  2884. }
  2885. };
  2886. Dict.empty = new Dict(null);
  2887. return Dict;
  2888. })();
  2889. var Ref = (function RefClosure() {
  2890. function Ref(num, gen) {
  2891. this.num = num;
  2892. this.gen = gen;
  2893. }
  2894. Ref.prototype = {
  2895. toString: function Ref_toString() {
  2896. // This function is hot, so we make the string as compact as possible.
  2897. // |this.gen| is almost always zero, so we treat that case specially.
  2898. var str = this.num + 'R';
  2899. if (this.gen !== 0) {
  2900. str += this.gen;
  2901. }
  2902. return str;
  2903. }
  2904. };
  2905. return Ref;
  2906. })();
  2907. // The reference is identified by number and generation.
  2908. // This structure stores only one instance of the reference.
  2909. var RefSet = (function RefSetClosure() {
  2910. function RefSet() {
  2911. this.dict = {};
  2912. }
  2913. RefSet.prototype = {
  2914. has: function RefSet_has(ref) {
  2915. return ref.toString() in this.dict;
  2916. },
  2917. put: function RefSet_put(ref) {
  2918. this.dict[ref.toString()] = true;
  2919. },
  2920. remove: function RefSet_remove(ref) {
  2921. delete this.dict[ref.toString()];
  2922. }
  2923. };
  2924. return RefSet;
  2925. })();
  2926. var RefSetCache = (function RefSetCacheClosure() {
  2927. function RefSetCache() {
  2928. this.dict = Object.create(null);
  2929. }
  2930. RefSetCache.prototype = {
  2931. get: function RefSetCache_get(ref) {
  2932. return this.dict[ref.toString()];
  2933. },
  2934. has: function RefSetCache_has(ref) {
  2935. return ref.toString() in this.dict;
  2936. },
  2937. put: function RefSetCache_put(ref, obj) {
  2938. this.dict[ref.toString()] = obj;
  2939. },
  2940. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2941. this.dict[ref.toString()] = this.get(aliasRef);
  2942. },
  2943. forEach: function RefSetCache_forEach(fn, thisArg) {
  2944. for (var i in this.dict) {
  2945. fn.call(thisArg, this.dict[i]);
  2946. }
  2947. },
  2948. clear: function RefSetCache_clear() {
  2949. this.dict = Object.create(null);
  2950. }
  2951. };
  2952. return RefSetCache;
  2953. })();
  2954. var Catalog = (function CatalogClosure() {
  2955. function Catalog(pdfManager, xref) {
  2956. this.pdfManager = pdfManager;
  2957. this.xref = xref;
  2958. this.catDict = xref.getCatalogObj();
  2959. this.fontCache = new RefSetCache();
  2960. assert(isDict(this.catDict),
  2961. 'catalog object is not a dictionary');
  2962. this.pagePromises = [];
  2963. }
  2964. Catalog.prototype = {
  2965. get metadata() {
  2966. var streamRef = this.catDict.getRaw('Metadata');
  2967. if (!isRef(streamRef)) {
  2968. return shadow(this, 'metadata', null);
  2969. }
  2970. var encryptMetadata = (!this.xref.encrypt ? false :
  2971. this.xref.encrypt.encryptMetadata);
  2972. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2973. var metadata;
  2974. if (stream && isDict(stream.dict)) {
  2975. var type = stream.dict.get('Type');
  2976. var subtype = stream.dict.get('Subtype');
  2977. if (isName(type) && isName(subtype) &&
  2978. type.name === 'Metadata' && subtype.name === 'XML') {
  2979. // XXX: This should examine the charset the XML document defines,
  2980. // however since there are currently no real means to decode
  2981. // arbitrary charsets, let's just hope that the author of the PDF
  2982. // was reasonable enough to stick with the XML default charset,
  2983. // which is UTF-8.
  2984. try {
  2985. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2986. } catch (e) {
  2987. info('Skipping invalid metadata.');
  2988. }
  2989. }
  2990. }
  2991. return shadow(this, 'metadata', metadata);
  2992. },
  2993. get toplevelPagesDict() {
  2994. var pagesObj = this.catDict.get('Pages');
  2995. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2996. // shadow the prototype getter
  2997. return shadow(this, 'toplevelPagesDict', pagesObj);
  2998. },
  2999. get documentOutline() {
  3000. var obj = null;
  3001. try {
  3002. obj = this.readDocumentOutline();
  3003. } catch (ex) {
  3004. if (ex instanceof MissingDataException) {
  3005. throw ex;
  3006. }
  3007. warn('Unable to read document outline');
  3008. }
  3009. return shadow(this, 'documentOutline', obj);
  3010. },
  3011. readDocumentOutline: function Catalog_readDocumentOutline() {
  3012. var xref = this.xref;
  3013. var obj = this.catDict.get('Outlines');
  3014. var root = { items: [] };
  3015. if (isDict(obj)) {
  3016. obj = obj.getRaw('First');
  3017. var processed = new RefSet();
  3018. if (isRef(obj)) {
  3019. var queue = [{obj: obj, parent: root}];
  3020. // to avoid recursion keeping track of the items
  3021. // in the processed dictionary
  3022. processed.put(obj);
  3023. while (queue.length > 0) {
  3024. var i = queue.shift();
  3025. var outlineDict = xref.fetchIfRef(i.obj);
  3026. if (outlineDict === null) {
  3027. continue;
  3028. }
  3029. if (!outlineDict.has('Title')) {
  3030. error('Invalid outline item');
  3031. }
  3032. var dest = outlineDict.get('A');
  3033. if (dest) {
  3034. dest = dest.get('D');
  3035. } else if (outlineDict.has('Dest')) {
  3036. dest = outlineDict.getRaw('Dest');
  3037. if (isName(dest)) {
  3038. dest = dest.name;
  3039. }
  3040. }
  3041. var title = outlineDict.get('Title');
  3042. var outlineItem = {
  3043. dest: dest,
  3044. title: stringToPDFString(title),
  3045. color: outlineDict.get('C') || [0, 0, 0],
  3046. count: outlineDict.get('Count'),
  3047. bold: !!(outlineDict.get('F') & 2),
  3048. italic: !!(outlineDict.get('F') & 1),
  3049. items: []
  3050. };
  3051. i.parent.items.push(outlineItem);
  3052. obj = outlineDict.getRaw('First');
  3053. if (isRef(obj) && !processed.has(obj)) {
  3054. queue.push({obj: obj, parent: outlineItem});
  3055. processed.put(obj);
  3056. }
  3057. obj = outlineDict.getRaw('Next');
  3058. if (isRef(obj) && !processed.has(obj)) {
  3059. queue.push({obj: obj, parent: i.parent});
  3060. processed.put(obj);
  3061. }
  3062. }
  3063. }
  3064. }
  3065. return (root.items.length > 0 ? root.items : null);
  3066. },
  3067. get numPages() {
  3068. var obj = this.toplevelPagesDict.get('Count');
  3069. assert(
  3070. isInt(obj),
  3071. 'page count in top level pages object is not an integer'
  3072. );
  3073. // shadow the prototype getter
  3074. return shadow(this, 'num', obj);
  3075. },
  3076. get destinations() {
  3077. function fetchDestination(dest) {
  3078. return isDict(dest) ? dest.get('D') : dest;
  3079. }
  3080. var xref = this.xref;
  3081. var dests = {}, nameTreeRef, nameDictionaryRef;
  3082. var obj = this.catDict.get('Names');
  3083. if (obj && obj.has('Dests')) {
  3084. nameTreeRef = obj.getRaw('Dests');
  3085. } else if (this.catDict.has('Dests')) {
  3086. nameDictionaryRef = this.catDict.get('Dests');
  3087. }
  3088. if (nameDictionaryRef) {
  3089. // reading simple destination dictionary
  3090. obj = nameDictionaryRef;
  3091. obj.forEach(function catalogForEach(key, value) {
  3092. if (!value) {
  3093. return;
  3094. }
  3095. dests[key] = fetchDestination(value);
  3096. });
  3097. }
  3098. if (nameTreeRef) {
  3099. var nameTree = new NameTree(nameTreeRef, xref);
  3100. var names = nameTree.getAll();
  3101. for (var name in names) {
  3102. if (!names.hasOwnProperty(name)) {
  3103. continue;
  3104. }
  3105. dests[name] = fetchDestination(names[name]);
  3106. }
  3107. }
  3108. return shadow(this, 'destinations', dests);
  3109. },
  3110. getDestination: function Catalog_getDestination(destinationId) {
  3111. function fetchDestination(dest) {
  3112. return isDict(dest) ? dest.get('D') : dest;
  3113. }
  3114. var xref = this.xref;
  3115. var dest, nameTreeRef, nameDictionaryRef;
  3116. var obj = this.catDict.get('Names');
  3117. if (obj && obj.has('Dests')) {
  3118. nameTreeRef = obj.getRaw('Dests');
  3119. } else if (this.catDict.has('Dests')) {
  3120. nameDictionaryRef = this.catDict.get('Dests');
  3121. }
  3122. if (nameDictionaryRef) {
  3123. // reading simple destination dictionary
  3124. obj = nameDictionaryRef;
  3125. obj.forEach(function catalogForEach(key, value) {
  3126. if (!value) {
  3127. return;
  3128. }
  3129. if (key === destinationId) {
  3130. dest = fetchDestination(value);
  3131. }
  3132. });
  3133. }
  3134. if (nameTreeRef) {
  3135. var nameTree = new NameTree(nameTreeRef, xref);
  3136. dest = fetchDestination(nameTree.get(destinationId));
  3137. }
  3138. return dest;
  3139. },
  3140. get attachments() {
  3141. var xref = this.xref;
  3142. var attachments = null, nameTreeRef;
  3143. var obj = this.catDict.get('Names');
  3144. if (obj) {
  3145. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3146. }
  3147. if (nameTreeRef) {
  3148. var nameTree = new NameTree(nameTreeRef, xref);
  3149. var names = nameTree.getAll();
  3150. for (var name in names) {
  3151. if (!names.hasOwnProperty(name)) {
  3152. continue;
  3153. }
  3154. var fs = new FileSpec(names[name], xref);
  3155. if (!attachments) {
  3156. attachments = {};
  3157. }
  3158. attachments[stringToPDFString(name)] = fs.serializable;
  3159. }
  3160. }
  3161. return shadow(this, 'attachments', attachments);
  3162. },
  3163. get javaScript() {
  3164. var xref = this.xref;
  3165. var obj = this.catDict.get('Names');
  3166. var javaScript = [];
  3167. if (obj && obj.has('JavaScript')) {
  3168. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3169. var names = nameTree.getAll();
  3170. for (var name in names) {
  3171. if (!names.hasOwnProperty(name)) {
  3172. continue;
  3173. }
  3174. // We don't really use the JavaScript right now. This code is
  3175. // defensive so we don't cause errors on document load.
  3176. var jsDict = names[name];
  3177. if (!isDict(jsDict)) {
  3178. continue;
  3179. }
  3180. var type = jsDict.get('S');
  3181. if (!isName(type) || type.name !== 'JavaScript') {
  3182. continue;
  3183. }
  3184. var js = jsDict.get('JS');
  3185. if (!isString(js) && !isStream(js)) {
  3186. continue;
  3187. }
  3188. if (isStream(js)) {
  3189. js = bytesToString(js.getBytes());
  3190. }
  3191. javaScript.push(stringToPDFString(js));
  3192. }
  3193. }
  3194. // Append OpenAction actions to javaScript array
  3195. var openactionDict = this.catDict.get('OpenAction');
  3196. if (isDict(openactionDict)) {
  3197. var objType = openactionDict.get('Type');
  3198. var actionType = openactionDict.get('S');
  3199. var action = openactionDict.get('N');
  3200. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3201. isName(actionType) && actionType.name === 'Named' &&
  3202. isName(action) && action.name === 'Print');
  3203. if (isPrintAction) {
  3204. javaScript.push('print(true);');
  3205. }
  3206. }
  3207. return shadow(this, 'javaScript', javaScript);
  3208. },
  3209. cleanup: function Catalog_cleanup() {
  3210. var promises = [];
  3211. this.fontCache.forEach(function (promise) {
  3212. promises.push(promise);
  3213. });
  3214. return Promise.all(promises).then(function (translatedFonts) {
  3215. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3216. var font = translatedFonts[i].dict;
  3217. delete font.translated;
  3218. }
  3219. this.fontCache.clear();
  3220. }.bind(this));
  3221. },
  3222. getPage: function Catalog_getPage(pageIndex) {
  3223. if (!(pageIndex in this.pagePromises)) {
  3224. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3225. function (a) {
  3226. var dict = a[0];
  3227. var ref = a[1];
  3228. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3229. this.fontCache);
  3230. }.bind(this)
  3231. );
  3232. }
  3233. return this.pagePromises[pageIndex];
  3234. },
  3235. getPageDict: function Catalog_getPageDict(pageIndex) {
  3236. var capability = createPromiseCapability();
  3237. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3238. var currentPageIndex = 0;
  3239. var xref = this.xref;
  3240. var checkAllKids = false;
  3241. function next() {
  3242. while (nodesToVisit.length) {
  3243. var currentNode = nodesToVisit.pop();
  3244. if (isRef(currentNode)) {
  3245. xref.fetchAsync(currentNode).then(function (obj) {
  3246. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3247. if (pageIndex === currentPageIndex) {
  3248. capability.resolve([obj, currentNode]);
  3249. } else {
  3250. currentPageIndex++;
  3251. next();
  3252. }
  3253. return;
  3254. }
  3255. nodesToVisit.push(obj);
  3256. next();
  3257. }, capability.reject);
  3258. return;
  3259. }
  3260. // Must be a child page dictionary.
  3261. assert(
  3262. isDict(currentNode),
  3263. 'page dictionary kid reference points to wrong type of object'
  3264. );
  3265. var count = currentNode.get('Count');
  3266. // If the current node doesn't have any children, avoid getting stuck
  3267. // in an empty node further down in the tree (see issue5644.pdf).
  3268. if (count === 0) {
  3269. checkAllKids = true;
  3270. }
  3271. // Skip nodes where the page can't be.
  3272. if (currentPageIndex + count <= pageIndex) {
  3273. currentPageIndex += count;
  3274. continue;
  3275. }
  3276. var kids = currentNode.get('Kids');
  3277. assert(isArray(kids), 'page dictionary kids object is not an array');
  3278. if (!checkAllKids && count === kids.length) {
  3279. // Nodes that don't have the page have been skipped and this is the
  3280. // bottom of the tree which means the page requested must be a
  3281. // descendant of this pages node. Ideally we would just resolve the
  3282. // promise with the page ref here, but there is the case where more
  3283. // pages nodes could link to single a page (see issue 3666 pdf). To
  3284. // handle this push it back on the queue so if it is a pages node it
  3285. // will be descended into.
  3286. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3287. currentPageIndex = pageIndex;
  3288. continue;
  3289. } else {
  3290. for (var last = kids.length - 1; last >= 0; last--) {
  3291. nodesToVisit.push(kids[last]);
  3292. }
  3293. }
  3294. }
  3295. capability.reject('Page index ' + pageIndex + ' not found.');
  3296. }
  3297. next();
  3298. return capability.promise;
  3299. },
  3300. getPageIndex: function Catalog_getPageIndex(ref) {
  3301. // The page tree nodes have the count of all the leaves below them. To get
  3302. // how many pages are before we just have to walk up the tree and keep
  3303. // adding the count of siblings to the left of the node.
  3304. var xref = this.xref;
  3305. function pagesBeforeRef(kidRef) {
  3306. var total = 0;
  3307. var parentRef;
  3308. return xref.fetchAsync(kidRef).then(function (node) {
  3309. if (!node) {
  3310. return null;
  3311. }
  3312. parentRef = node.getRaw('Parent');
  3313. return node.getAsync('Parent');
  3314. }).then(function (parent) {
  3315. if (!parent) {
  3316. return null;
  3317. }
  3318. return parent.getAsync('Kids');
  3319. }).then(function (kids) {
  3320. if (!kids) {
  3321. return null;
  3322. }
  3323. var kidPromises = [];
  3324. var found = false;
  3325. for (var i = 0; i < kids.length; i++) {
  3326. var kid = kids[i];
  3327. assert(isRef(kid), 'kids must be a ref');
  3328. if (kid.num === kidRef.num) {
  3329. found = true;
  3330. break;
  3331. }
  3332. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3333. if (kid.has('Count')) {
  3334. var count = kid.get('Count');
  3335. total += count;
  3336. } else { // page leaf node
  3337. total++;
  3338. }
  3339. }));
  3340. }
  3341. if (!found) {
  3342. error('kid ref not found in parents kids');
  3343. }
  3344. return Promise.all(kidPromises).then(function () {
  3345. return [total, parentRef];
  3346. });
  3347. });
  3348. }
  3349. var total = 0;
  3350. function next(ref) {
  3351. return pagesBeforeRef(ref).then(function (args) {
  3352. if (!args) {
  3353. return total;
  3354. }
  3355. var count = args[0];
  3356. var parentRef = args[1];
  3357. total += count;
  3358. return next(parentRef);
  3359. });
  3360. }
  3361. return next(ref);
  3362. }
  3363. };
  3364. return Catalog;
  3365. })();
  3366. var XRef = (function XRefClosure() {
  3367. function XRef(stream, password) {
  3368. this.stream = stream;
  3369. this.entries = [];
  3370. this.xrefstms = {};
  3371. // prepare the XRef cache
  3372. this.cache = [];
  3373. this.password = password;
  3374. this.stats = {
  3375. streamTypes: [],
  3376. fontTypes: []
  3377. };
  3378. }
  3379. XRef.prototype = {
  3380. setStartXRef: function XRef_setStartXRef(startXRef) {
  3381. // Store the starting positions of xref tables as we process them
  3382. // so we can recover from missing data errors
  3383. this.startXRefQueue = [startXRef];
  3384. },
  3385. parse: function XRef_parse(recoveryMode) {
  3386. var trailerDict;
  3387. if (!recoveryMode) {
  3388. trailerDict = this.readXRef();
  3389. } else {
  3390. warn('Indexing all PDF objects');
  3391. trailerDict = this.indexObjects();
  3392. }
  3393. trailerDict.assignXref(this);
  3394. this.trailer = trailerDict;
  3395. var encrypt = trailerDict.get('Encrypt');
  3396. if (encrypt) {
  3397. var ids = trailerDict.get('ID');
  3398. var fileId = (ids && ids.length) ? ids[0] : '';
  3399. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3400. this.password);
  3401. }
  3402. // get the root dictionary (catalog) object
  3403. if (!(this.root = trailerDict.get('Root'))) {
  3404. error('Invalid root reference');
  3405. }
  3406. },
  3407. processXRefTable: function XRef_processXRefTable(parser) {
  3408. if (!('tableState' in this)) {
  3409. // Stores state of the table as we process it so we can resume
  3410. // from middle of table in case of missing data error
  3411. this.tableState = {
  3412. entryNum: 0,
  3413. streamPos: parser.lexer.stream.pos,
  3414. parserBuf1: parser.buf1,
  3415. parserBuf2: parser.buf2
  3416. };
  3417. }
  3418. var obj = this.readXRefTable(parser);
  3419. // Sanity check
  3420. if (!isCmd(obj, 'trailer')) {
  3421. error('Invalid XRef table: could not find trailer dictionary');
  3422. }
  3423. // Read trailer dictionary, e.g.
  3424. // trailer
  3425. // << /Size 22
  3426. // /Root 20R
  3427. // /Info 10R
  3428. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3429. // >>
  3430. // The parser goes through the entire stream << ... >> and provides
  3431. // a getter interface for the key-value table
  3432. var dict = parser.getObj();
  3433. // The pdflib PDF generator can generate a nested trailer dictionary
  3434. if (!isDict(dict) && dict.dict) {
  3435. dict = dict.dict;
  3436. }
  3437. if (!isDict(dict)) {
  3438. error('Invalid XRef table: could not parse trailer dictionary');
  3439. }
  3440. delete this.tableState;
  3441. return dict;
  3442. },
  3443. readXRefTable: function XRef_readXRefTable(parser) {
  3444. // Example of cross-reference table:
  3445. // xref
  3446. // 0 1 <-- subsection header (first obj #, obj count)
  3447. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3448. // 23 2 <-- subsection header ... and so on ...
  3449. // 0000025518 00002 n
  3450. // 0000025635 00000 n
  3451. // trailer
  3452. // ...
  3453. var stream = parser.lexer.stream;
  3454. var tableState = this.tableState;
  3455. stream.pos = tableState.streamPos;
  3456. parser.buf1 = tableState.parserBuf1;
  3457. parser.buf2 = tableState.parserBuf2;
  3458. // Outer loop is over subsection headers
  3459. var obj;
  3460. while (true) {
  3461. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3462. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3463. break;
  3464. }
  3465. tableState.firstEntryNum = obj;
  3466. tableState.entryCount = parser.getObj();
  3467. }
  3468. var first = tableState.firstEntryNum;
  3469. var count = tableState.entryCount;
  3470. if (!isInt(first) || !isInt(count)) {
  3471. error('Invalid XRef table: wrong types in subsection header');
  3472. }
  3473. // Inner loop is over objects themselves
  3474. for (var i = tableState.entryNum; i < count; i++) {
  3475. tableState.streamPos = stream.pos;
  3476. tableState.entryNum = i;
  3477. tableState.parserBuf1 = parser.buf1;
  3478. tableState.parserBuf2 = parser.buf2;
  3479. var entry = {};
  3480. entry.offset = parser.getObj();
  3481. entry.gen = parser.getObj();
  3482. var type = parser.getObj();
  3483. if (isCmd(type, 'f')) {
  3484. entry.free = true;
  3485. } else if (isCmd(type, 'n')) {
  3486. entry.uncompressed = true;
  3487. }
  3488. // Validate entry obj
  3489. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3490. !(entry.free || entry.uncompressed)) {
  3491. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3492. }
  3493. if (!this.entries[i + first]) {
  3494. this.entries[i + first] = entry;
  3495. }
  3496. }
  3497. tableState.entryNum = 0;
  3498. tableState.streamPos = stream.pos;
  3499. tableState.parserBuf1 = parser.buf1;
  3500. tableState.parserBuf2 = parser.buf2;
  3501. delete tableState.firstEntryNum;
  3502. delete tableState.entryCount;
  3503. }
  3504. // Per issue 3248: hp scanners generate bad XRef
  3505. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3506. // shifting the entries
  3507. this.entries.shift();
  3508. }
  3509. // Sanity check: as per spec, first object must be free
  3510. if (this.entries[0] && !this.entries[0].free) {
  3511. error('Invalid XRef table: unexpected first object');
  3512. }
  3513. return obj;
  3514. },
  3515. processXRefStream: function XRef_processXRefStream(stream) {
  3516. if (!('streamState' in this)) {
  3517. // Stores state of the stream as we process it so we can resume
  3518. // from middle of stream in case of missing data error
  3519. var streamParameters = stream.dict;
  3520. var byteWidths = streamParameters.get('W');
  3521. var range = streamParameters.get('Index');
  3522. if (!range) {
  3523. range = [0, streamParameters.get('Size')];
  3524. }
  3525. this.streamState = {
  3526. entryRanges: range,
  3527. byteWidths: byteWidths,
  3528. entryNum: 0,
  3529. streamPos: stream.pos
  3530. };
  3531. }
  3532. this.readXRefStream(stream);
  3533. delete this.streamState;
  3534. return stream.dict;
  3535. },
  3536. readXRefStream: function XRef_readXRefStream(stream) {
  3537. var i, j;
  3538. var streamState = this.streamState;
  3539. stream.pos = streamState.streamPos;
  3540. var byteWidths = streamState.byteWidths;
  3541. var typeFieldWidth = byteWidths[0];
  3542. var offsetFieldWidth = byteWidths[1];
  3543. var generationFieldWidth = byteWidths[2];
  3544. var entryRanges = streamState.entryRanges;
  3545. while (entryRanges.length > 0) {
  3546. var first = entryRanges[0];
  3547. var n = entryRanges[1];
  3548. if (!isInt(first) || !isInt(n)) {
  3549. error('Invalid XRef range fields: ' + first + ', ' + n);
  3550. }
  3551. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3552. !isInt(generationFieldWidth)) {
  3553. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3554. }
  3555. for (i = streamState.entryNum; i < n; ++i) {
  3556. streamState.entryNum = i;
  3557. streamState.streamPos = stream.pos;
  3558. var type = 0, offset = 0, generation = 0;
  3559. for (j = 0; j < typeFieldWidth; ++j) {
  3560. type = (type << 8) | stream.getByte();
  3561. }
  3562. // if type field is absent, its default value is 1
  3563. if (typeFieldWidth === 0) {
  3564. type = 1;
  3565. }
  3566. for (j = 0; j < offsetFieldWidth; ++j) {
  3567. offset = (offset << 8) | stream.getByte();
  3568. }
  3569. for (j = 0; j < generationFieldWidth; ++j) {
  3570. generation = (generation << 8) | stream.getByte();
  3571. }
  3572. var entry = {};
  3573. entry.offset = offset;
  3574. entry.gen = generation;
  3575. switch (type) {
  3576. case 0:
  3577. entry.free = true;
  3578. break;
  3579. case 1:
  3580. entry.uncompressed = true;
  3581. break;
  3582. case 2:
  3583. break;
  3584. default:
  3585. error('Invalid XRef entry type: ' + type);
  3586. }
  3587. if (!this.entries[first + i]) {
  3588. this.entries[first + i] = entry;
  3589. }
  3590. }
  3591. streamState.entryNum = 0;
  3592. streamState.streamPos = stream.pos;
  3593. entryRanges.splice(0, 2);
  3594. }
  3595. },
  3596. indexObjects: function XRef_indexObjects() {
  3597. // Simple scan through the PDF content to find objects,
  3598. // trailers and XRef streams.
  3599. function readToken(data, offset) {
  3600. var token = '', ch = data[offset];
  3601. while (ch !== 13 && ch !== 10) {
  3602. if (++offset >= data.length) {
  3603. break;
  3604. }
  3605. token += String.fromCharCode(ch);
  3606. ch = data[offset];
  3607. }
  3608. return token;
  3609. }
  3610. function skipUntil(data, offset, what) {
  3611. var length = what.length, dataLength = data.length;
  3612. var skipped = 0;
  3613. // finding byte sequence
  3614. while (offset < dataLength) {
  3615. var i = 0;
  3616. while (i < length && data[offset + i] === what[i]) {
  3617. ++i;
  3618. }
  3619. if (i >= length) {
  3620. break; // sequence found
  3621. }
  3622. offset++;
  3623. skipped++;
  3624. }
  3625. return skipped;
  3626. }
  3627. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3628. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3629. 101, 102]);
  3630. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3631. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3632. var stream = this.stream;
  3633. stream.pos = 0;
  3634. var buffer = stream.getBytes();
  3635. var position = stream.start, length = buffer.length;
  3636. var trailers = [], xrefStms = [];
  3637. while (position < length) {
  3638. var ch = buffer[position];
  3639. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3640. ++position;
  3641. continue;
  3642. }
  3643. if (ch === 37) { // %-comment
  3644. do {
  3645. ++position;
  3646. if (position >= length) {
  3647. break;
  3648. }
  3649. ch = buffer[position];
  3650. } while (ch !== 13 && ch !== 10);
  3651. continue;
  3652. }
  3653. var token = readToken(buffer, position);
  3654. var m;
  3655. if (token === 'xref') {
  3656. position += skipUntil(buffer, position, trailerBytes);
  3657. trailers.push(position);
  3658. position += skipUntil(buffer, position, startxrefBytes);
  3659. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3660. if (typeof this.entries[m[1]] === 'undefined') {
  3661. this.entries[m[1]] = {
  3662. offset: position,
  3663. gen: m[2] | 0,
  3664. uncompressed: true
  3665. };
  3666. }
  3667. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3668. var content = buffer.subarray(position, position + contentLength);
  3669. // checking XRef stream suspect
  3670. // (it shall have '/XRef' and next char is not a letter)
  3671. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3672. if (xrefTagOffset < contentLength &&
  3673. content[xrefTagOffset + 5] < 64) {
  3674. xrefStms.push(position);
  3675. this.xrefstms[position] = 1; // don't read it recursively
  3676. }
  3677. position += contentLength;
  3678. } else {
  3679. position += token.length + 1;
  3680. }
  3681. }
  3682. // reading XRef streams
  3683. var i, ii;
  3684. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3685. this.startXRefQueue.push(xrefStms[i]);
  3686. this.readXRef(/* recoveryMode */ true);
  3687. }
  3688. // finding main trailer
  3689. var dict;
  3690. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3691. stream.pos = trailers[i];
  3692. var parser = new Parser(new Lexer(stream), true, this);
  3693. var obj = parser.getObj();
  3694. if (!isCmd(obj, 'trailer')) {
  3695. continue;
  3696. }
  3697. // read the trailer dictionary
  3698. if (!isDict(dict = parser.getObj())) {
  3699. continue;
  3700. }
  3701. // taking the first one with 'ID'
  3702. if (dict.has('ID')) {
  3703. return dict;
  3704. }
  3705. }
  3706. // no tailer with 'ID', taking last one (if exists)
  3707. if (dict) {
  3708. return dict;
  3709. }
  3710. // nothing helps
  3711. // calling error() would reject worker with an UnknownErrorException.
  3712. throw new InvalidPDFException('Invalid PDF structure');
  3713. },
  3714. readXRef: function XRef_readXRef(recoveryMode) {
  3715. var stream = this.stream;
  3716. try {
  3717. while (this.startXRefQueue.length) {
  3718. var startXRef = this.startXRefQueue[0];
  3719. stream.pos = startXRef + stream.start;
  3720. var parser = new Parser(new Lexer(stream), true, this);
  3721. var obj = parser.getObj();
  3722. var dict;
  3723. // Get dictionary
  3724. if (isCmd(obj, 'xref')) {
  3725. // Parse end-of-file XRef
  3726. dict = this.processXRefTable(parser);
  3727. if (!this.topDict) {
  3728. this.topDict = dict;
  3729. }
  3730. // Recursively get other XRefs 'XRefStm', if any
  3731. obj = dict.get('XRefStm');
  3732. if (isInt(obj)) {
  3733. var pos = obj;
  3734. // ignore previously loaded xref streams
  3735. // (possible infinite recursion)
  3736. if (!(pos in this.xrefstms)) {
  3737. this.xrefstms[pos] = 1;
  3738. this.startXRefQueue.push(pos);
  3739. }
  3740. }
  3741. } else if (isInt(obj)) {
  3742. // Parse in-stream XRef
  3743. if (!isInt(parser.getObj()) ||
  3744. !isCmd(parser.getObj(), 'obj') ||
  3745. !isStream(obj = parser.getObj())) {
  3746. error('Invalid XRef stream');
  3747. }
  3748. dict = this.processXRefStream(obj);
  3749. if (!this.topDict) {
  3750. this.topDict = dict;
  3751. }
  3752. if (!dict) {
  3753. error('Failed to read XRef stream');
  3754. }
  3755. } else {
  3756. error('Invalid XRef stream header');
  3757. }
  3758. // Recursively get previous dictionary, if any
  3759. obj = dict.get('Prev');
  3760. if (isInt(obj)) {
  3761. this.startXRefQueue.push(obj);
  3762. } else if (isRef(obj)) {
  3763. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3764. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3765. this.startXRefQueue.push(obj.num);
  3766. }
  3767. this.startXRefQueue.shift();
  3768. }
  3769. return this.topDict;
  3770. } catch (e) {
  3771. if (e instanceof MissingDataException) {
  3772. throw e;
  3773. }
  3774. info('(while reading XRef): ' + e);
  3775. }
  3776. if (recoveryMode) {
  3777. return;
  3778. }
  3779. throw new XRefParseException();
  3780. },
  3781. getEntry: function XRef_getEntry(i) {
  3782. var xrefEntry = this.entries[i];
  3783. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3784. return xrefEntry;
  3785. }
  3786. return null;
  3787. },
  3788. fetchIfRef: function XRef_fetchIfRef(obj) {
  3789. if (!isRef(obj)) {
  3790. return obj;
  3791. }
  3792. return this.fetch(obj);
  3793. },
  3794. fetch: function XRef_fetch(ref, suppressEncryption) {
  3795. assert(isRef(ref), 'ref object is not a reference');
  3796. var num = ref.num;
  3797. if (num in this.cache) {
  3798. var cacheEntry = this.cache[num];
  3799. return cacheEntry;
  3800. }
  3801. var xrefEntry = this.getEntry(num);
  3802. // the referenced entry can be free
  3803. if (xrefEntry === null) {
  3804. return (this.cache[num] = null);
  3805. }
  3806. if (xrefEntry.uncompressed) {
  3807. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3808. } else {
  3809. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3810. }
  3811. if (isDict(xrefEntry)){
  3812. xrefEntry.objId = ref.toString();
  3813. } else if (isStream(xrefEntry)) {
  3814. xrefEntry.dict.objId = ref.toString();
  3815. }
  3816. return xrefEntry;
  3817. },
  3818. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3819. suppressEncryption) {
  3820. var gen = ref.gen;
  3821. var num = ref.num;
  3822. if (xrefEntry.gen !== gen) {
  3823. error('inconsistent generation in XRef');
  3824. }
  3825. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3826. this.stream.start);
  3827. var parser = new Parser(new Lexer(stream), true, this);
  3828. var obj1 = parser.getObj();
  3829. var obj2 = parser.getObj();
  3830. var obj3 = parser.getObj();
  3831. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3832. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3833. !isCmd(obj3)) {
  3834. error('bad XRef entry');
  3835. }
  3836. if (!isCmd(obj3, 'obj')) {
  3837. // some bad PDFs use "obj1234" and really mean 1234
  3838. if (obj3.cmd.indexOf('obj') === 0) {
  3839. num = parseInt(obj3.cmd.substring(3), 10);
  3840. if (!isNaN(num)) {
  3841. return num;
  3842. }
  3843. }
  3844. error('bad XRef entry');
  3845. }
  3846. if (this.encrypt && !suppressEncryption) {
  3847. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3848. } else {
  3849. xrefEntry = parser.getObj();
  3850. }
  3851. if (!isStream(xrefEntry)) {
  3852. this.cache[num] = xrefEntry;
  3853. }
  3854. return xrefEntry;
  3855. },
  3856. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3857. suppressEncryption) {
  3858. var tableOffset = xrefEntry.offset;
  3859. var stream = this.fetch(new Ref(tableOffset, 0));
  3860. if (!isStream(stream)) {
  3861. error('bad ObjStm stream');
  3862. }
  3863. var first = stream.dict.get('First');
  3864. var n = stream.dict.get('N');
  3865. if (!isInt(first) || !isInt(n)) {
  3866. error('invalid first and n parameters for ObjStm stream');
  3867. }
  3868. var parser = new Parser(new Lexer(stream), false, this);
  3869. parser.allowStreams = true;
  3870. var i, entries = [], num, nums = [];
  3871. // read the object numbers to populate cache
  3872. for (i = 0; i < n; ++i) {
  3873. num = parser.getObj();
  3874. if (!isInt(num)) {
  3875. error('invalid object number in the ObjStm stream: ' + num);
  3876. }
  3877. nums.push(num);
  3878. var offset = parser.getObj();
  3879. if (!isInt(offset)) {
  3880. error('invalid object offset in the ObjStm stream: ' + offset);
  3881. }
  3882. }
  3883. // read stream objects for cache
  3884. for (i = 0; i < n; ++i) {
  3885. entries.push(parser.getObj());
  3886. num = nums[i];
  3887. var entry = this.entries[num];
  3888. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3889. this.cache[num] = entries[i];
  3890. }
  3891. }
  3892. xrefEntry = entries[xrefEntry.gen];
  3893. if (xrefEntry === undefined) {
  3894. error('bad XRef entry for compressed object');
  3895. }
  3896. return xrefEntry;
  3897. },
  3898. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3899. if (!isRef(obj)) {
  3900. return Promise.resolve(obj);
  3901. }
  3902. return this.fetchAsync(obj);
  3903. },
  3904. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3905. var streamManager = this.stream.manager;
  3906. var xref = this;
  3907. return new Promise(function tryFetch(resolve, reject) {
  3908. try {
  3909. resolve(xref.fetch(ref, suppressEncryption));
  3910. } catch (e) {
  3911. if (e instanceof MissingDataException) {
  3912. streamManager.requestRange(e.begin, e.end, function () {
  3913. tryFetch(resolve, reject);
  3914. });
  3915. return;
  3916. }
  3917. reject(e);
  3918. }
  3919. });
  3920. },
  3921. getCatalogObj: function XRef_getCatalogObj() {
  3922. return this.root;
  3923. }
  3924. };
  3925. return XRef;
  3926. })();
  3927. /**
  3928. * A NameTree is like a Dict but has some advantageous properties, see the
  3929. * spec (7.9.6) for more details.
  3930. * TODO: implement all the Dict functions and make this more efficent.
  3931. */
  3932. var NameTree = (function NameTreeClosure() {
  3933. function NameTree(root, xref) {
  3934. this.root = root;
  3935. this.xref = xref;
  3936. }
  3937. NameTree.prototype = {
  3938. getAll: function NameTree_getAll() {
  3939. var dict = {};
  3940. if (!this.root) {
  3941. return dict;
  3942. }
  3943. var xref = this.xref;
  3944. // reading name tree
  3945. var processed = new RefSet();
  3946. processed.put(this.root);
  3947. var queue = [this.root];
  3948. while (queue.length > 0) {
  3949. var i, n;
  3950. var obj = xref.fetchIfRef(queue.shift());
  3951. if (!isDict(obj)) {
  3952. continue;
  3953. }
  3954. if (obj.has('Kids')) {
  3955. var kids = obj.get('Kids');
  3956. for (i = 0, n = kids.length; i < n; i++) {
  3957. var kid = kids[i];
  3958. if (processed.has(kid)) {
  3959. error('invalid destinations');
  3960. }
  3961. queue.push(kid);
  3962. processed.put(kid);
  3963. }
  3964. continue;
  3965. }
  3966. var names = obj.get('Names');
  3967. if (names) {
  3968. for (i = 0, n = names.length; i < n; i += 2) {
  3969. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3970. }
  3971. }
  3972. }
  3973. return dict;
  3974. },
  3975. get: function NameTree_get(destinationId) {
  3976. if (!this.root) {
  3977. return null;
  3978. }
  3979. var xref = this.xref;
  3980. var kidsOrNames = xref.fetchIfRef(this.root);
  3981. var loopCount = 0;
  3982. var MAX_NAMES_LEVELS = 10;
  3983. var l, r, m;
  3984. // Perform a binary search to quickly find the entry that
  3985. // contains the named destination we are looking for.
  3986. while (kidsOrNames.has('Kids')) {
  3987. loopCount++;
  3988. if (loopCount > MAX_NAMES_LEVELS) {
  3989. warn('Search depth limit for named destionations has been reached.');
  3990. return null;
  3991. }
  3992. var kids = kidsOrNames.get('Kids');
  3993. if (!isArray(kids)) {
  3994. return null;
  3995. }
  3996. l = 0;
  3997. r = kids.length - 1;
  3998. while (l <= r) {
  3999. m = (l + r) >> 1;
  4000. var kid = xref.fetchIfRef(kids[m]);
  4001. var limits = kid.get('Limits');
  4002. if (destinationId < limits[0]) {
  4003. r = m - 1;
  4004. } else if (destinationId > limits[1]) {
  4005. l = m + 1;
  4006. } else {
  4007. kidsOrNames = xref.fetchIfRef(kids[m]);
  4008. break;
  4009. }
  4010. }
  4011. if (l > r) {
  4012. return null;
  4013. }
  4014. }
  4015. // If we get here, then we have found the right entry. Now
  4016. // go through the named destinations in the Named dictionary
  4017. // until we find the exact destination we're looking for.
  4018. var names = kidsOrNames.get('Names');
  4019. if (isArray(names)) {
  4020. // Perform a binary search to reduce the lookup time.
  4021. l = 0;
  4022. r = names.length - 2;
  4023. while (l <= r) {
  4024. // Check only even indices (0, 2, 4, ...) because the
  4025. // odd indices contain the actual D array.
  4026. m = (l + r) & ~1;
  4027. if (destinationId < names[m]) {
  4028. r = m - 2;
  4029. } else if (destinationId > names[m]) {
  4030. l = m + 2;
  4031. } else {
  4032. return xref.fetchIfRef(names[m + 1]);
  4033. }
  4034. }
  4035. }
  4036. return null;
  4037. }
  4038. };
  4039. return NameTree;
  4040. })();
  4041. /**
  4042. * "A PDF file can refer to the contents of another file by using a File
  4043. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4044. * NOTE: Only embedded files are supported (as part of the attachments support)
  4045. * TODO: support the 'URL' file system (with caching if !/V), portable
  4046. * collections attributes and related files (/RF)
  4047. */
  4048. var FileSpec = (function FileSpecClosure() {
  4049. function FileSpec(root, xref) {
  4050. if (!root || !isDict(root)) {
  4051. return;
  4052. }
  4053. this.xref = xref;
  4054. this.root = root;
  4055. if (root.has('FS')) {
  4056. this.fs = root.get('FS');
  4057. }
  4058. this.description = root.has('Desc') ?
  4059. stringToPDFString(root.get('Desc')) :
  4060. '';
  4061. if (root.has('RF')) {
  4062. warn('Related file specifications are not supported');
  4063. }
  4064. this.contentAvailable = true;
  4065. if (!root.has('EF')) {
  4066. this.contentAvailable = false;
  4067. warn('Non-embedded file specifications are not supported');
  4068. }
  4069. }
  4070. function pickPlatformItem(dict) {
  4071. // Look for the filename in this order:
  4072. // UF, F, Unix, Mac, DOS
  4073. if (dict.has('UF')) {
  4074. return dict.get('UF');
  4075. } else if (dict.has('F')) {
  4076. return dict.get('F');
  4077. } else if (dict.has('Unix')) {
  4078. return dict.get('Unix');
  4079. } else if (dict.has('Mac')) {
  4080. return dict.get('Mac');
  4081. } else if (dict.has('DOS')) {
  4082. return dict.get('DOS');
  4083. } else {
  4084. return null;
  4085. }
  4086. }
  4087. FileSpec.prototype = {
  4088. get filename() {
  4089. if (!this._filename && this.root) {
  4090. var filename = pickPlatformItem(this.root) || 'unnamed';
  4091. this._filename = stringToPDFString(filename).
  4092. replace(/\\\\/g, '\\').
  4093. replace(/\\\//g, '/').
  4094. replace(/\\/g, '/');
  4095. }
  4096. return this._filename;
  4097. },
  4098. get content() {
  4099. if (!this.contentAvailable) {
  4100. return null;
  4101. }
  4102. if (!this.contentRef && this.root) {
  4103. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4104. }
  4105. var content = null;
  4106. if (this.contentRef) {
  4107. var xref = this.xref;
  4108. var fileObj = xref.fetchIfRef(this.contentRef);
  4109. if (fileObj && isStream(fileObj)) {
  4110. content = fileObj.getBytes();
  4111. } else {
  4112. warn('Embedded file specification points to non-existing/invalid ' +
  4113. 'content');
  4114. }
  4115. } else {
  4116. warn('Embedded file specification does not have a content');
  4117. }
  4118. return content;
  4119. },
  4120. get serializable() {
  4121. return {
  4122. filename: this.filename,
  4123. content: this.content
  4124. };
  4125. }
  4126. };
  4127. return FileSpec;
  4128. })();
  4129. /**
  4130. * A helper for loading missing data in object graphs. It traverses the graph
  4131. * depth first and queues up any objects that have missing data. Once it has
  4132. * has traversed as many objects that are available it attempts to bundle the
  4133. * missing data requests and then resume from the nodes that weren't ready.
  4134. *
  4135. * NOTE: It provides protection from circular references by keeping track of
  4136. * of loaded references. However, you must be careful not to load any graphs
  4137. * that have references to the catalog or other pages since that will cause the
  4138. * entire PDF document object graph to be traversed.
  4139. */
  4140. var ObjectLoader = (function() {
  4141. function mayHaveChildren(value) {
  4142. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4143. }
  4144. function addChildren(node, nodesToVisit) {
  4145. var value;
  4146. if (isDict(node) || isStream(node)) {
  4147. var map;
  4148. if (isDict(node)) {
  4149. map = node.map;
  4150. } else {
  4151. map = node.dict.map;
  4152. }
  4153. for (var key in map) {
  4154. value = map[key];
  4155. if (mayHaveChildren(value)) {
  4156. nodesToVisit.push(value);
  4157. }
  4158. }
  4159. } else if (isArray(node)) {
  4160. for (var i = 0, ii = node.length; i < ii; i++) {
  4161. value = node[i];
  4162. if (mayHaveChildren(value)) {
  4163. nodesToVisit.push(value);
  4164. }
  4165. }
  4166. }
  4167. }
  4168. function ObjectLoader(obj, keys, xref) {
  4169. this.obj = obj;
  4170. this.keys = keys;
  4171. this.xref = xref;
  4172. this.refSet = null;
  4173. }
  4174. ObjectLoader.prototype = {
  4175. load: function ObjectLoader_load() {
  4176. var keys = this.keys;
  4177. this.capability = createPromiseCapability();
  4178. // Don't walk the graph if all the data is already loaded.
  4179. if (!(this.xref.stream instanceof ChunkedStream) ||
  4180. this.xref.stream.getMissingChunks().length === 0) {
  4181. this.capability.resolve();
  4182. return this.capability.promise;
  4183. }
  4184. this.refSet = new RefSet();
  4185. // Setup the initial nodes to visit.
  4186. var nodesToVisit = [];
  4187. for (var i = 0; i < keys.length; i++) {
  4188. nodesToVisit.push(this.obj[keys[i]]);
  4189. }
  4190. this.walk(nodesToVisit);
  4191. return this.capability.promise;
  4192. },
  4193. walk: function ObjectLoader_walk(nodesToVisit) {
  4194. var nodesToRevisit = [];
  4195. var pendingRequests = [];
  4196. // DFS walk of the object graph.
  4197. while (nodesToVisit.length) {
  4198. var currentNode = nodesToVisit.pop();
  4199. // Only references or chunked streams can cause missing data exceptions.
  4200. if (isRef(currentNode)) {
  4201. // Skip nodes that have already been visited.
  4202. if (this.refSet.has(currentNode)) {
  4203. continue;
  4204. }
  4205. try {
  4206. var ref = currentNode;
  4207. this.refSet.put(ref);
  4208. currentNode = this.xref.fetch(currentNode);
  4209. } catch (e) {
  4210. if (!(e instanceof MissingDataException)) {
  4211. throw e;
  4212. }
  4213. nodesToRevisit.push(currentNode);
  4214. pendingRequests.push({ begin: e.begin, end: e.end });
  4215. }
  4216. }
  4217. if (currentNode && currentNode.getBaseStreams) {
  4218. var baseStreams = currentNode.getBaseStreams();
  4219. var foundMissingData = false;
  4220. for (var i = 0; i < baseStreams.length; i++) {
  4221. var stream = baseStreams[i];
  4222. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4223. foundMissingData = true;
  4224. pendingRequests.push({
  4225. begin: stream.start,
  4226. end: stream.end
  4227. });
  4228. }
  4229. }
  4230. if (foundMissingData) {
  4231. nodesToRevisit.push(currentNode);
  4232. }
  4233. }
  4234. addChildren(currentNode, nodesToVisit);
  4235. }
  4236. if (pendingRequests.length) {
  4237. this.xref.stream.manager.requestRanges(pendingRequests,
  4238. function pendingRequestCallback() {
  4239. nodesToVisit = nodesToRevisit;
  4240. for (var i = 0; i < nodesToRevisit.length; i++) {
  4241. var node = nodesToRevisit[i];
  4242. // Remove any reference nodes from the currrent refset so they
  4243. // aren't skipped when we revist them.
  4244. if (isRef(node)) {
  4245. this.refSet.remove(node);
  4246. }
  4247. }
  4248. this.walk(nodesToVisit);
  4249. }.bind(this));
  4250. return;
  4251. }
  4252. // Everything is loaded.
  4253. this.refSet = null;
  4254. this.capability.resolve();
  4255. }
  4256. };
  4257. return ObjectLoader;
  4258. })();
  4259. var ISOAdobeCharset = [
  4260. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4261. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4262. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4263. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4264. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4265. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4266. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4267. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4268. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4269. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4270. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4271. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4272. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4273. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4274. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4275. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4276. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4277. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4278. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4279. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4280. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4281. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4282. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4283. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4284. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4285. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4286. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4287. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4288. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4289. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4290. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4291. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4292. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4293. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4294. ];
  4295. var ExpertCharset = [
  4296. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4297. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4298. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4299. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4300. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4301. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4302. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4303. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4304. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4305. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4306. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4307. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4308. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4309. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4310. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4311. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4312. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4313. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4314. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4315. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4316. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4317. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4318. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4319. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4320. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4321. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4322. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4323. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4324. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4325. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4326. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4327. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4328. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4329. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4330. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4331. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4332. 'Ydieresissmall'
  4333. ];
  4334. var ExpertSubsetCharset = [
  4335. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4336. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4337. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4338. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4339. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4340. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4341. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4342. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4343. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4344. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4345. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4346. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4347. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4348. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4349. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4350. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4351. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4352. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4353. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4354. 'periodinferior', 'commainferior'
  4355. ];
  4356. var DEFAULT_ICON_SIZE = 22; // px
  4357. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4358. var Annotation = (function AnnotationClosure() {
  4359. // 12.5.5: Algorithm: Appearance streams
  4360. function getTransformMatrix(rect, bbox, matrix) {
  4361. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4362. var minX = bounds[0];
  4363. var minY = bounds[1];
  4364. var maxX = bounds[2];
  4365. var maxY = bounds[3];
  4366. if (minX === maxX || minY === maxY) {
  4367. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4368. // just apply the transform for rect
  4369. return [1, 0, 0, 1, rect[0], rect[1]];
  4370. }
  4371. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4372. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4373. return [
  4374. xRatio,
  4375. 0,
  4376. 0,
  4377. yRatio,
  4378. rect[0] - minX * xRatio,
  4379. rect[1] - minY * yRatio
  4380. ];
  4381. }
  4382. function getDefaultAppearance(dict) {
  4383. var appearanceState = dict.get('AP');
  4384. if (!isDict(appearanceState)) {
  4385. return;
  4386. }
  4387. var appearance;
  4388. var appearances = appearanceState.get('N');
  4389. if (isDict(appearances)) {
  4390. var as = dict.get('AS');
  4391. if (as && appearances.has(as.name)) {
  4392. appearance = appearances.get(as.name);
  4393. }
  4394. } else {
  4395. appearance = appearances;
  4396. }
  4397. return appearance;
  4398. }
  4399. function Annotation(params) {
  4400. var dict = params.dict;
  4401. var data = this.data = {};
  4402. data.subtype = dict.get('Subtype').name;
  4403. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4404. data.rect = Util.normalizeRect(rect);
  4405. data.annotationFlags = dict.get('F');
  4406. var color = dict.get('C');
  4407. if (!color) {
  4408. // The PDF spec does not mention how a missing color array is interpreted.
  4409. // Adobe Reader seems to default to black in this case.
  4410. data.color = [0, 0, 0];
  4411. } else if (isArray(color)) {
  4412. switch (color.length) {
  4413. case 0:
  4414. // Empty array denotes transparent border.
  4415. data.color = null;
  4416. break;
  4417. case 1:
  4418. // TODO: implement DeviceGray
  4419. break;
  4420. case 3:
  4421. data.color = color;
  4422. break;
  4423. case 4:
  4424. // TODO: implement DeviceCMYK
  4425. break;
  4426. }
  4427. }
  4428. // Some types of annotations have border style dict which has more
  4429. // info than the border array
  4430. if (dict.has('BS')) {
  4431. var borderStyle = dict.get('BS');
  4432. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4433. } else {
  4434. var borderArray = dict.get('Border') || [0, 0, 1];
  4435. data.borderWidth = borderArray[2] || 0;
  4436. // TODO: implement proper support for annotations with line dash patterns.
  4437. var dashArray = borderArray[3];
  4438. if (data.borderWidth > 0 && dashArray) {
  4439. if (!isArray(dashArray)) {
  4440. // Ignore the border if dashArray is not actually an array,
  4441. // this is consistent with the behaviour in Adobe Reader.
  4442. data.borderWidth = 0;
  4443. } else {
  4444. var dashArrayLength = dashArray.length;
  4445. if (dashArrayLength > 0) {
  4446. // According to the PDF specification: the elements in a dashArray
  4447. // shall be numbers that are nonnegative and not all equal to zero.
  4448. var isInvalid = false;
  4449. var numPositive = 0;
  4450. for (var i = 0; i < dashArrayLength; i++) {
  4451. var validNumber = (+dashArray[i] >= 0);
  4452. if (!validNumber) {
  4453. isInvalid = true;
  4454. break;
  4455. } else if (dashArray[i] > 0) {
  4456. numPositive++;
  4457. }
  4458. }
  4459. if (isInvalid || numPositive === 0) {
  4460. data.borderWidth = 0;
  4461. }
  4462. }
  4463. }
  4464. }
  4465. }
  4466. this.appearance = getDefaultAppearance(dict);
  4467. data.hasAppearance = !!this.appearance;
  4468. data.id = params.ref.num;
  4469. }
  4470. Annotation.prototype = {
  4471. getData: function Annotation_getData() {
  4472. return this.data;
  4473. },
  4474. isInvisible: function Annotation_isInvisible() {
  4475. var data = this.data;
  4476. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4477. return false;
  4478. } else {
  4479. return !!(data &&
  4480. data.annotationFlags && // Default: not invisible
  4481. data.annotationFlags & 0x1); // Invisible
  4482. }
  4483. },
  4484. isViewable: function Annotation_isViewable() {
  4485. var data = this.data;
  4486. return !!(!this.isInvisible() &&
  4487. data &&
  4488. (!data.annotationFlags ||
  4489. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4490. data.rect); // rectangle is necessary
  4491. },
  4492. isPrintable: function Annotation_isPrintable() {
  4493. var data = this.data;
  4494. return !!(!this.isInvisible() &&
  4495. data &&
  4496. data.annotationFlags && // Default: not printable
  4497. data.annotationFlags & 0x4 && // Print
  4498. !(data.annotationFlags & 0x2) && // Hidden
  4499. data.rect); // rectangle is necessary
  4500. },
  4501. loadResources: function Annotation_loadResources(keys) {
  4502. return new Promise(function (resolve, reject) {
  4503. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4504. if (!resources) {
  4505. resolve();
  4506. return;
  4507. }
  4508. var objectLoader = new ObjectLoader(resources.map,
  4509. keys,
  4510. resources.xref);
  4511. objectLoader.load().then(function() {
  4512. resolve(resources);
  4513. }, reject);
  4514. }, reject);
  4515. }.bind(this));
  4516. },
  4517. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4518. if (!this.appearance) {
  4519. return Promise.resolve(new OperatorList());
  4520. }
  4521. var data = this.data;
  4522. var appearanceDict = this.appearance.dict;
  4523. var resourcesPromise = this.loadResources([
  4524. 'ExtGState',
  4525. 'ColorSpace',
  4526. 'Pattern',
  4527. 'Shading',
  4528. 'XObject',
  4529. 'Font'
  4530. // ProcSet
  4531. // Properties
  4532. ]);
  4533. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4534. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4535. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4536. var self = this;
  4537. return resourcesPromise.then(function(resources) {
  4538. var opList = new OperatorList();
  4539. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4540. return evaluator.getOperatorList(self.appearance, resources, opList).
  4541. then(function () {
  4542. opList.addOp(OPS.endAnnotation, []);
  4543. self.appearance.reset();
  4544. return opList;
  4545. });
  4546. });
  4547. }
  4548. };
  4549. Annotation.getConstructor =
  4550. function Annotation_getConstructor(subtype, fieldType) {
  4551. if (!subtype) {
  4552. return;
  4553. }
  4554. // TODO(mack): Implement FreeText annotations
  4555. if (subtype === 'Link') {
  4556. return LinkAnnotation;
  4557. } else if (subtype === 'Text') {
  4558. return TextAnnotation;
  4559. } else if (subtype === 'Widget') {
  4560. if (!fieldType) {
  4561. return;
  4562. }
  4563. if (fieldType === 'Tx') {
  4564. return TextWidgetAnnotation;
  4565. } else {
  4566. return WidgetAnnotation;
  4567. }
  4568. } else {
  4569. return Annotation;
  4570. }
  4571. };
  4572. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4573. var dict = xref.fetchIfRef(ref);
  4574. if (!isDict(dict)) {
  4575. return;
  4576. }
  4577. var subtype = dict.get('Subtype');
  4578. subtype = isName(subtype) ? subtype.name : '';
  4579. if (!subtype) {
  4580. return;
  4581. }
  4582. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4583. fieldType = isName(fieldType) ? fieldType.name : '';
  4584. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4585. if (!Constructor) {
  4586. return;
  4587. }
  4588. var params = {
  4589. dict: dict,
  4590. ref: ref,
  4591. };
  4592. var annotation = new Constructor(params);
  4593. if (annotation.isViewable() || annotation.isPrintable()) {
  4594. return annotation;
  4595. } else {
  4596. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4597. warn('unimplemented annotation type: ' + subtype);
  4598. }
  4599. }
  4600. };
  4601. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4602. annotations, opList, pdfManager, partialEvaluator, intent) {
  4603. function reject(e) {
  4604. annotationsReadyCapability.reject(e);
  4605. }
  4606. var annotationsReadyCapability = createPromiseCapability();
  4607. var annotationPromises = [];
  4608. for (var i = 0, n = annotations.length; i < n; ++i) {
  4609. if (intent === 'display' && annotations[i].isViewable() ||
  4610. intent === 'print' && annotations[i].isPrintable()) {
  4611. annotationPromises.push(
  4612. annotations[i].getOperatorList(partialEvaluator));
  4613. }
  4614. }
  4615. Promise.all(annotationPromises).then(function(datas) {
  4616. opList.addOp(OPS.beginAnnotations, []);
  4617. for (var i = 0, n = datas.length; i < n; ++i) {
  4618. var annotOpList = datas[i];
  4619. opList.addOpList(annotOpList);
  4620. }
  4621. opList.addOp(OPS.endAnnotations, []);
  4622. annotationsReadyCapability.resolve();
  4623. }, reject);
  4624. return annotationsReadyCapability.promise;
  4625. };
  4626. return Annotation;
  4627. })();
  4628. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4629. function WidgetAnnotation(params) {
  4630. Annotation.call(this, params);
  4631. var dict = params.dict;
  4632. var data = this.data;
  4633. data.fieldValue = stringToPDFString(
  4634. Util.getInheritableProperty(dict, 'V') || '');
  4635. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4636. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4637. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4638. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4639. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4640. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4641. // Building the full field name by collecting the field and
  4642. // its ancestors 'T' data and joining them using '.'.
  4643. var fieldName = [];
  4644. var namedItem = dict;
  4645. var ref = params.ref;
  4646. while (namedItem) {
  4647. var parent = namedItem.get('Parent');
  4648. var parentRef = namedItem.getRaw('Parent');
  4649. var name = namedItem.get('T');
  4650. if (name) {
  4651. fieldName.unshift(stringToPDFString(name));
  4652. } else if (parent && ref) {
  4653. // The field name is absent, that means more than one field
  4654. // with the same name may exist. Replacing the empty name
  4655. // with the '`' plus index in the parent's 'Kids' array.
  4656. // This is not in the PDF spec but necessary to id the
  4657. // the input controls.
  4658. var kids = parent.get('Kids');
  4659. var j, jj;
  4660. for (j = 0, jj = kids.length; j < jj; j++) {
  4661. var kidRef = kids[j];
  4662. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4663. break;
  4664. }
  4665. }
  4666. fieldName.unshift('`' + j);
  4667. }
  4668. namedItem = parent;
  4669. ref = parentRef;
  4670. }
  4671. data.fullName = fieldName.join('.');
  4672. }
  4673. var parent = Annotation.prototype;
  4674. Util.inherit(WidgetAnnotation, Annotation, {
  4675. isViewable: function WidgetAnnotation_isViewable() {
  4676. if (this.data.fieldType === 'Sig') {
  4677. warn('unimplemented annotation type: Widget signature');
  4678. return false;
  4679. }
  4680. return parent.isViewable.call(this);
  4681. }
  4682. });
  4683. return WidgetAnnotation;
  4684. })();
  4685. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4686. function TextWidgetAnnotation(params) {
  4687. WidgetAnnotation.call(this, params);
  4688. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4689. this.data.annotationType = AnnotationType.WIDGET;
  4690. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4691. }
  4692. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4693. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4694. if (this.appearance) {
  4695. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4696. }
  4697. var opList = new OperatorList();
  4698. var data = this.data;
  4699. // Even if there is an appearance stream, ignore it. This is the
  4700. // behaviour used by Adobe Reader.
  4701. if (!data.defaultAppearance) {
  4702. return Promise.resolve(opList);
  4703. }
  4704. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4705. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4706. then(function () {
  4707. return opList;
  4708. });
  4709. }
  4710. });
  4711. return TextWidgetAnnotation;
  4712. })();
  4713. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4714. function InteractiveAnnotation(params) {
  4715. Annotation.call(this, params);
  4716. this.data.hasHtml = true;
  4717. }
  4718. Util.inherit(InteractiveAnnotation, Annotation, { });
  4719. return InteractiveAnnotation;
  4720. })();
  4721. var TextAnnotation = (function TextAnnotationClosure() {
  4722. function TextAnnotation(params) {
  4723. InteractiveAnnotation.call(this, params);
  4724. var dict = params.dict;
  4725. var data = this.data;
  4726. var content = dict.get('Contents');
  4727. var title = dict.get('T');
  4728. data.annotationType = AnnotationType.TEXT;
  4729. data.content = stringToPDFString(content || '');
  4730. data.title = stringToPDFString(title || '');
  4731. if (data.hasAppearance) {
  4732. data.name = 'NoIcon';
  4733. } else {
  4734. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4735. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4736. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4737. }
  4738. if (dict.has('C')) {
  4739. data.hasBgColor = true;
  4740. }
  4741. }
  4742. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4743. return TextAnnotation;
  4744. })();
  4745. var LinkAnnotation = (function LinkAnnotationClosure() {
  4746. function LinkAnnotation(params) {
  4747. InteractiveAnnotation.call(this, params);
  4748. var dict = params.dict;
  4749. var data = this.data;
  4750. data.annotationType = AnnotationType.LINK;
  4751. var action = dict.get('A');
  4752. if (action && isDict(action)) {
  4753. var linkType = action.get('S').name;
  4754. if (linkType === 'URI') {
  4755. var url = action.get('URI');
  4756. if (isName(url)) {
  4757. // Some bad PDFs do not put parentheses around relative URLs.
  4758. url = '/' + url.name;
  4759. } else if (url) {
  4760. url = addDefaultProtocolToUrl(url);
  4761. }
  4762. // TODO: pdf spec mentions urls can be relative to a Base
  4763. // entry in the dictionary.
  4764. if (!isValidUrl(url, false)) {
  4765. url = '';
  4766. }
  4767. // According to ISO 32000-1:2008, section 12.6.4.7,
  4768. // URI should to be encoded in 7-bit ASCII.
  4769. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4770. try {
  4771. data.url = stringToUTF8String(url);
  4772. } catch (e) {
  4773. // Fall back to a simple copy.
  4774. data.url = url;
  4775. }
  4776. } else if (linkType === 'GoTo') {
  4777. data.dest = action.get('D');
  4778. } else if (linkType === 'GoToR') {
  4779. var urlDict = action.get('F');
  4780. if (isDict(urlDict)) {
  4781. // We assume that the 'url' is a Filspec dictionary
  4782. // and fetch the url without checking any further
  4783. url = urlDict.get('F') || '';
  4784. }
  4785. // TODO: pdf reference says that GoToR
  4786. // can also have 'NewWindow' attribute
  4787. if (!isValidUrl(url, false)) {
  4788. url = '';
  4789. }
  4790. data.url = url;
  4791. data.dest = action.get('D');
  4792. } else if (linkType === 'Named') {
  4793. data.action = action.get('N').name;
  4794. } else {
  4795. warn('unrecognized link type: ' + linkType);
  4796. }
  4797. } else if (dict.has('Dest')) {
  4798. // simple destination link
  4799. var dest = dict.get('Dest');
  4800. data.dest = isName(dest) ? dest.name : dest;
  4801. }
  4802. }
  4803. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4804. function addDefaultProtocolToUrl(url) {
  4805. if (url && url.indexOf('www.') === 0) {
  4806. return ('http://' + url);
  4807. }
  4808. return url;
  4809. }
  4810. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4811. return LinkAnnotation;
  4812. })();
  4813. var PDFFunction = (function PDFFunctionClosure() {
  4814. var CONSTRUCT_SAMPLED = 0;
  4815. var CONSTRUCT_INTERPOLATED = 2;
  4816. var CONSTRUCT_STICHED = 3;
  4817. var CONSTRUCT_POSTSCRIPT = 4;
  4818. return {
  4819. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4820. str) {
  4821. var i, ii;
  4822. var length = 1;
  4823. for (i = 0, ii = size.length; i < ii; i++) {
  4824. length *= size[i];
  4825. }
  4826. length *= outputSize;
  4827. var array = new Array(length);
  4828. var codeSize = 0;
  4829. var codeBuf = 0;
  4830. // 32 is a valid bps so shifting won't work
  4831. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4832. var strBytes = str.getBytes((length * bps + 7) / 8);
  4833. var strIdx = 0;
  4834. for (i = 0; i < length; i++) {
  4835. while (codeSize < bps) {
  4836. codeBuf <<= 8;
  4837. codeBuf |= strBytes[strIdx++];
  4838. codeSize += 8;
  4839. }
  4840. codeSize -= bps;
  4841. array[i] = (codeBuf >> codeSize) * sampleMul;
  4842. codeBuf &= (1 << codeSize) - 1;
  4843. }
  4844. return array;
  4845. },
  4846. getIR: function PDFFunction_getIR(xref, fn) {
  4847. var dict = fn.dict;
  4848. if (!dict) {
  4849. dict = fn;
  4850. }
  4851. var types = [this.constructSampled,
  4852. null,
  4853. this.constructInterpolated,
  4854. this.constructStiched,
  4855. this.constructPostScript];
  4856. var typeNum = dict.get('FunctionType');
  4857. var typeFn = types[typeNum];
  4858. if (!typeFn) {
  4859. error('Unknown type of function');
  4860. }
  4861. return typeFn.call(this, fn, dict, xref);
  4862. },
  4863. fromIR: function PDFFunction_fromIR(IR) {
  4864. var type = IR[0];
  4865. switch (type) {
  4866. case CONSTRUCT_SAMPLED:
  4867. return this.constructSampledFromIR(IR);
  4868. case CONSTRUCT_INTERPOLATED:
  4869. return this.constructInterpolatedFromIR(IR);
  4870. case CONSTRUCT_STICHED:
  4871. return this.constructStichedFromIR(IR);
  4872. //case CONSTRUCT_POSTSCRIPT:
  4873. default:
  4874. return this.constructPostScriptFromIR(IR);
  4875. }
  4876. },
  4877. parse: function PDFFunction_parse(xref, fn) {
  4878. var IR = this.getIR(xref, fn);
  4879. return this.fromIR(IR);
  4880. },
  4881. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4882. if (!isArray(fnObj)) {
  4883. // not an array -- parsing as regular function
  4884. return this.parse(xref, fnObj);
  4885. }
  4886. var fnArray = [];
  4887. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4888. var obj = xref.fetchIfRef(fnObj[j]);
  4889. fnArray.push(PDFFunction.parse(xref, obj));
  4890. }
  4891. return function (src, srcOffset, dest, destOffset) {
  4892. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4893. fnArray[i](src, srcOffset, dest, destOffset + i);
  4894. }
  4895. };
  4896. },
  4897. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4898. function toMultiArray(arr) {
  4899. var inputLength = arr.length;
  4900. var out = [];
  4901. var index = 0;
  4902. for (var i = 0; i < inputLength; i += 2) {
  4903. out[index] = [arr[i], arr[i + 1]];
  4904. ++index;
  4905. }
  4906. return out;
  4907. }
  4908. var domain = dict.get('Domain');
  4909. var range = dict.get('Range');
  4910. if (!domain || !range) {
  4911. error('No domain or range');
  4912. }
  4913. var inputSize = domain.length / 2;
  4914. var outputSize = range.length / 2;
  4915. domain = toMultiArray(domain);
  4916. range = toMultiArray(range);
  4917. var size = dict.get('Size');
  4918. var bps = dict.get('BitsPerSample');
  4919. var order = dict.get('Order') || 1;
  4920. if (order !== 1) {
  4921. // No description how cubic spline interpolation works in PDF32000:2008
  4922. // As in poppler, ignoring order, linear interpolation may work as good
  4923. info('No support for cubic spline interpolation: ' + order);
  4924. }
  4925. var encode = dict.get('Encode');
  4926. if (!encode) {
  4927. encode = [];
  4928. for (var i = 0; i < inputSize; ++i) {
  4929. encode.push(0);
  4930. encode.push(size[i] - 1);
  4931. }
  4932. }
  4933. encode = toMultiArray(encode);
  4934. var decode = dict.get('Decode');
  4935. if (!decode) {
  4936. decode = range;
  4937. } else {
  4938. decode = toMultiArray(decode);
  4939. }
  4940. var samples = this.getSampleArray(size, outputSize, bps, str);
  4941. return [
  4942. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4943. outputSize, Math.pow(2, bps) - 1, range
  4944. ];
  4945. },
  4946. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4947. // See chapter 3, page 109 of the PDF reference
  4948. function interpolate(x, xmin, xmax, ymin, ymax) {
  4949. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4950. }
  4951. return function constructSampledFromIRResult(src, srcOffset,
  4952. dest, destOffset) {
  4953. // See chapter 3, page 110 of the PDF reference.
  4954. var m = IR[1];
  4955. var domain = IR[2];
  4956. var encode = IR[3];
  4957. var decode = IR[4];
  4958. var samples = IR[5];
  4959. var size = IR[6];
  4960. var n = IR[7];
  4961. //var mask = IR[8];
  4962. var range = IR[9];
  4963. // Building the cube vertices: its part and sample index
  4964. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4965. var cubeVertices = 1 << m;
  4966. var cubeN = new Float64Array(cubeVertices);
  4967. var cubeVertex = new Uint32Array(cubeVertices);
  4968. var i, j;
  4969. for (j = 0; j < cubeVertices; j++) {
  4970. cubeN[j] = 1;
  4971. }
  4972. var k = n, pos = 1;
  4973. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4974. for (i = 0; i < m; ++i) {
  4975. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4976. var domain_2i = domain[i][0];
  4977. var domain_2i_1 = domain[i][1];
  4978. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4979. domain_2i_1);
  4980. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4981. // Encode_2i, Encode_2i+1)
  4982. var e = interpolate(xi, domain_2i, domain_2i_1,
  4983. encode[i][0], encode[i][1]);
  4984. // e_i' = min(max(e_i, 0), Size_i - 1)
  4985. var size_i = size[i];
  4986. e = Math.min(Math.max(e, 0), size_i - 1);
  4987. // Adjusting the cube: N and vertex sample index
  4988. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4989. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4990. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4991. var offset0 = e0 * k;
  4992. var offset1 = offset0 + k; // e1 * k
  4993. for (j = 0; j < cubeVertices; j++) {
  4994. if (j & pos) {
  4995. cubeN[j] *= n1;
  4996. cubeVertex[j] += offset1;
  4997. } else {
  4998. cubeN[j] *= n0;
  4999. cubeVertex[j] += offset0;
  5000. }
  5001. }
  5002. k *= size_i;
  5003. pos <<= 1;
  5004. }
  5005. for (j = 0; j < n; ++j) {
  5006. // Sum all cube vertices' samples portions
  5007. var rj = 0;
  5008. for (i = 0; i < cubeVertices; i++) {
  5009. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5010. }
  5011. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5012. // Decode_2j, Decode_2j+1)
  5013. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5014. // y_j = min(max(r_j, range_2j), range_2j+1)
  5015. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5016. range[j][1]);
  5017. }
  5018. };
  5019. },
  5020. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5021. dict) {
  5022. var c0 = dict.get('C0') || [0];
  5023. var c1 = dict.get('C1') || [1];
  5024. var n = dict.get('N');
  5025. if (!isArray(c0) || !isArray(c1)) {
  5026. error('Illegal dictionary for interpolated function');
  5027. }
  5028. var length = c0.length;
  5029. var diff = [];
  5030. for (var i = 0; i < length; ++i) {
  5031. diff.push(c1[i] - c0[i]);
  5032. }
  5033. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5034. },
  5035. constructInterpolatedFromIR:
  5036. function PDFFunction_constructInterpolatedFromIR(IR) {
  5037. var c0 = IR[1];
  5038. var diff = IR[2];
  5039. var n = IR[3];
  5040. var length = diff.length;
  5041. return function constructInterpolatedFromIRResult(src, srcOffset,
  5042. dest, destOffset) {
  5043. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5044. for (var j = 0; j < length; ++j) {
  5045. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5046. }
  5047. };
  5048. },
  5049. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5050. var domain = dict.get('Domain');
  5051. if (!domain) {
  5052. error('No domain');
  5053. }
  5054. var inputSize = domain.length / 2;
  5055. if (inputSize !== 1) {
  5056. error('Bad domain for stiched function');
  5057. }
  5058. var fnRefs = dict.get('Functions');
  5059. var fns = [];
  5060. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5061. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5062. }
  5063. var bounds = dict.get('Bounds');
  5064. var encode = dict.get('Encode');
  5065. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5066. },
  5067. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5068. var domain = IR[1];
  5069. var bounds = IR[2];
  5070. var encode = IR[3];
  5071. var fnsIR = IR[4];
  5072. var fns = [];
  5073. var tmpBuf = new Float32Array(1);
  5074. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5075. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5076. }
  5077. return function constructStichedFromIRResult(src, srcOffset,
  5078. dest, destOffset) {
  5079. var clip = function constructStichedFromIRClip(v, min, max) {
  5080. if (v > max) {
  5081. v = max;
  5082. } else if (v < min) {
  5083. v = min;
  5084. }
  5085. return v;
  5086. };
  5087. // clip to domain
  5088. var v = clip(src[srcOffset], domain[0], domain[1]);
  5089. // calulate which bound the value is in
  5090. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5091. if (v < bounds[i]) {
  5092. break;
  5093. }
  5094. }
  5095. // encode value into domain of function
  5096. var dmin = domain[0];
  5097. if (i > 0) {
  5098. dmin = bounds[i - 1];
  5099. }
  5100. var dmax = domain[1];
  5101. if (i < bounds.length) {
  5102. dmax = bounds[i];
  5103. }
  5104. var rmin = encode[2 * i];
  5105. var rmax = encode[2 * i + 1];
  5106. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5107. // call the appropriate function
  5108. fns[i](tmpBuf, 0, dest, destOffset);
  5109. };
  5110. },
  5111. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5112. xref) {
  5113. var domain = dict.get('Domain');
  5114. var range = dict.get('Range');
  5115. if (!domain) {
  5116. error('No domain.');
  5117. }
  5118. if (!range) {
  5119. error('No range.');
  5120. }
  5121. var lexer = new PostScriptLexer(fn);
  5122. var parser = new PostScriptParser(lexer);
  5123. var code = parser.parse();
  5124. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5125. },
  5126. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5127. IR) {
  5128. var domain = IR[1];
  5129. var range = IR[2];
  5130. var code = IR[3];
  5131. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5132. if (compiled) {
  5133. // Compiled function consists of simple expressions such as addition,
  5134. // subtraction, Math.max, and also contains 'var' and 'return'
  5135. // statements. See the generation in the PostScriptCompiler below.
  5136. /*jshint -W054 */
  5137. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5138. }
  5139. info('Unable to compile PS function');
  5140. var numOutputs = range.length >> 1;
  5141. var numInputs = domain.length >> 1;
  5142. var evaluator = new PostScriptEvaluator(code);
  5143. // Cache the values for a big speed up, the cache size is limited though
  5144. // since the number of possible values can be huge from a PS function.
  5145. var cache = {};
  5146. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5147. // seen in our tests.
  5148. var MAX_CACHE_SIZE = 2048 * 4;
  5149. var cache_available = MAX_CACHE_SIZE;
  5150. var tmpBuf = new Float32Array(numInputs);
  5151. return function constructPostScriptFromIRResult(src, srcOffset,
  5152. dest, destOffset) {
  5153. var i, value;
  5154. var key = '';
  5155. var input = tmpBuf;
  5156. for (i = 0; i < numInputs; i++) {
  5157. value = src[srcOffset + i];
  5158. input[i] = value;
  5159. key += value + '_';
  5160. }
  5161. var cachedValue = cache[key];
  5162. if (cachedValue !== undefined) {
  5163. dest.set(cachedValue, destOffset);
  5164. return;
  5165. }
  5166. var output = new Float32Array(numOutputs);
  5167. var stack = evaluator.execute(input);
  5168. var stackIndex = stack.length - numOutputs;
  5169. for (i = 0; i < numOutputs; i++) {
  5170. value = stack[stackIndex + i];
  5171. var bound = range[i * 2];
  5172. if (value < bound) {
  5173. value = bound;
  5174. } else {
  5175. bound = range[i * 2 +1];
  5176. if (value > bound) {
  5177. value = bound;
  5178. }
  5179. }
  5180. output[i] = value;
  5181. }
  5182. if (cache_available > 0) {
  5183. cache_available--;
  5184. cache[key] = output;
  5185. }
  5186. dest.set(output, destOffset);
  5187. };
  5188. }
  5189. };
  5190. })();
  5191. function isPDFFunction(v) {
  5192. var fnDict;
  5193. if (typeof v !== 'object') {
  5194. return false;
  5195. } else if (isDict(v)) {
  5196. fnDict = v;
  5197. } else if (isStream(v)) {
  5198. fnDict = v.dict;
  5199. } else {
  5200. return false;
  5201. }
  5202. return fnDict.has('FunctionType');
  5203. }
  5204. var PostScriptStack = (function PostScriptStackClosure() {
  5205. var MAX_STACK_SIZE = 100;
  5206. function PostScriptStack(initialStack) {
  5207. this.stack = !initialStack ? [] :
  5208. Array.prototype.slice.call(initialStack, 0);
  5209. }
  5210. PostScriptStack.prototype = {
  5211. push: function PostScriptStack_push(value) {
  5212. if (this.stack.length >= MAX_STACK_SIZE) {
  5213. error('PostScript function stack overflow.');
  5214. }
  5215. this.stack.push(value);
  5216. },
  5217. pop: function PostScriptStack_pop() {
  5218. if (this.stack.length <= 0) {
  5219. error('PostScript function stack underflow.');
  5220. }
  5221. return this.stack.pop();
  5222. },
  5223. copy: function PostScriptStack_copy(n) {
  5224. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5225. error('PostScript function stack overflow.');
  5226. }
  5227. var stack = this.stack;
  5228. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5229. stack.push(stack[i]);
  5230. }
  5231. },
  5232. index: function PostScriptStack_index(n) {
  5233. this.push(this.stack[this.stack.length - n - 1]);
  5234. },
  5235. // rotate the last n stack elements p times
  5236. roll: function PostScriptStack_roll(n, p) {
  5237. var stack = this.stack;
  5238. var l = stack.length - n;
  5239. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5240. for (i = l, j = r; i < j; i++, j--) {
  5241. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5242. }
  5243. for (i = l, j = c - 1; i < j; i++, j--) {
  5244. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5245. }
  5246. for (i = c, j = r; i < j; i++, j--) {
  5247. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5248. }
  5249. }
  5250. };
  5251. return PostScriptStack;
  5252. })();
  5253. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5254. function PostScriptEvaluator(operators) {
  5255. this.operators = operators;
  5256. }
  5257. PostScriptEvaluator.prototype = {
  5258. execute: function PostScriptEvaluator_execute(initialStack) {
  5259. var stack = new PostScriptStack(initialStack);
  5260. var counter = 0;
  5261. var operators = this.operators;
  5262. var length = operators.length;
  5263. var operator, a, b;
  5264. while (counter < length) {
  5265. operator = operators[counter++];
  5266. if (typeof operator === 'number') {
  5267. // Operator is really an operand and should be pushed to the stack.
  5268. stack.push(operator);
  5269. continue;
  5270. }
  5271. switch (operator) {
  5272. // non standard ps operators
  5273. case 'jz': // jump if false
  5274. b = stack.pop();
  5275. a = stack.pop();
  5276. if (!a) {
  5277. counter = b;
  5278. }
  5279. break;
  5280. case 'j': // jump
  5281. a = stack.pop();
  5282. counter = a;
  5283. break;
  5284. // all ps operators in alphabetical order (excluding if/ifelse)
  5285. case 'abs':
  5286. a = stack.pop();
  5287. stack.push(Math.abs(a));
  5288. break;
  5289. case 'add':
  5290. b = stack.pop();
  5291. a = stack.pop();
  5292. stack.push(a + b);
  5293. break;
  5294. case 'and':
  5295. b = stack.pop();
  5296. a = stack.pop();
  5297. if (isBool(a) && isBool(b)) {
  5298. stack.push(a && b);
  5299. } else {
  5300. stack.push(a & b);
  5301. }
  5302. break;
  5303. case 'atan':
  5304. a = stack.pop();
  5305. stack.push(Math.atan(a));
  5306. break;
  5307. case 'bitshift':
  5308. b = stack.pop();
  5309. a = stack.pop();
  5310. if (a > 0) {
  5311. stack.push(a << b);
  5312. } else {
  5313. stack.push(a >> b);
  5314. }
  5315. break;
  5316. case 'ceiling':
  5317. a = stack.pop();
  5318. stack.push(Math.ceil(a));
  5319. break;
  5320. case 'copy':
  5321. a = stack.pop();
  5322. stack.copy(a);
  5323. break;
  5324. case 'cos':
  5325. a = stack.pop();
  5326. stack.push(Math.cos(a));
  5327. break;
  5328. case 'cvi':
  5329. a = stack.pop() | 0;
  5330. stack.push(a);
  5331. break;
  5332. case 'cvr':
  5333. // noop
  5334. break;
  5335. case 'div':
  5336. b = stack.pop();
  5337. a = stack.pop();
  5338. stack.push(a / b);
  5339. break;
  5340. case 'dup':
  5341. stack.copy(1);
  5342. break;
  5343. case 'eq':
  5344. b = stack.pop();
  5345. a = stack.pop();
  5346. stack.push(a === b);
  5347. break;
  5348. case 'exch':
  5349. stack.roll(2, 1);
  5350. break;
  5351. case 'exp':
  5352. b = stack.pop();
  5353. a = stack.pop();
  5354. stack.push(Math.pow(a, b));
  5355. break;
  5356. case 'false':
  5357. stack.push(false);
  5358. break;
  5359. case 'floor':
  5360. a = stack.pop();
  5361. stack.push(Math.floor(a));
  5362. break;
  5363. case 'ge':
  5364. b = stack.pop();
  5365. a = stack.pop();
  5366. stack.push(a >= b);
  5367. break;
  5368. case 'gt':
  5369. b = stack.pop();
  5370. a = stack.pop();
  5371. stack.push(a > b);
  5372. break;
  5373. case 'idiv':
  5374. b = stack.pop();
  5375. a = stack.pop();
  5376. stack.push((a / b) | 0);
  5377. break;
  5378. case 'index':
  5379. a = stack.pop();
  5380. stack.index(a);
  5381. break;
  5382. case 'le':
  5383. b = stack.pop();
  5384. a = stack.pop();
  5385. stack.push(a <= b);
  5386. break;
  5387. case 'ln':
  5388. a = stack.pop();
  5389. stack.push(Math.log(a));
  5390. break;
  5391. case 'log':
  5392. a = stack.pop();
  5393. stack.push(Math.log(a) / Math.LN10);
  5394. break;
  5395. case 'lt':
  5396. b = stack.pop();
  5397. a = stack.pop();
  5398. stack.push(a < b);
  5399. break;
  5400. case 'mod':
  5401. b = stack.pop();
  5402. a = stack.pop();
  5403. stack.push(a % b);
  5404. break;
  5405. case 'mul':
  5406. b = stack.pop();
  5407. a = stack.pop();
  5408. stack.push(a * b);
  5409. break;
  5410. case 'ne':
  5411. b = stack.pop();
  5412. a = stack.pop();
  5413. stack.push(a !== b);
  5414. break;
  5415. case 'neg':
  5416. a = stack.pop();
  5417. stack.push(-a);
  5418. break;
  5419. case 'not':
  5420. a = stack.pop();
  5421. if (isBool(a)) {
  5422. stack.push(!a);
  5423. } else {
  5424. stack.push(~a);
  5425. }
  5426. break;
  5427. case 'or':
  5428. b = stack.pop();
  5429. a = stack.pop();
  5430. if (isBool(a) && isBool(b)) {
  5431. stack.push(a || b);
  5432. } else {
  5433. stack.push(a | b);
  5434. }
  5435. break;
  5436. case 'pop':
  5437. stack.pop();
  5438. break;
  5439. case 'roll':
  5440. b = stack.pop();
  5441. a = stack.pop();
  5442. stack.roll(a, b);
  5443. break;
  5444. case 'round':
  5445. a = stack.pop();
  5446. stack.push(Math.round(a));
  5447. break;
  5448. case 'sin':
  5449. a = stack.pop();
  5450. stack.push(Math.sin(a));
  5451. break;
  5452. case 'sqrt':
  5453. a = stack.pop();
  5454. stack.push(Math.sqrt(a));
  5455. break;
  5456. case 'sub':
  5457. b = stack.pop();
  5458. a = stack.pop();
  5459. stack.push(a - b);
  5460. break;
  5461. case 'true':
  5462. stack.push(true);
  5463. break;
  5464. case 'truncate':
  5465. a = stack.pop();
  5466. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5467. stack.push(a);
  5468. break;
  5469. case 'xor':
  5470. b = stack.pop();
  5471. a = stack.pop();
  5472. if (isBool(a) && isBool(b)) {
  5473. stack.push(a !== b);
  5474. } else {
  5475. stack.push(a ^ b);
  5476. }
  5477. break;
  5478. default:
  5479. error('Unknown operator ' + operator);
  5480. break;
  5481. }
  5482. }
  5483. return stack.stack;
  5484. }
  5485. };
  5486. return PostScriptEvaluator;
  5487. })();
  5488. // Most of the PDFs functions consist of simple operations such as:
  5489. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5490. //
  5491. // We can compile most of such programs, and at the same moment, we can
  5492. // optimize some expressions using basic math properties. Keeping track of
  5493. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5494. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5495. function AstNode(type) {
  5496. this.type = type;
  5497. }
  5498. AstNode.prototype.visit = function (visitor) {
  5499. throw new Error('abstract method');
  5500. };
  5501. function AstArgument(index, min, max) {
  5502. AstNode.call(this, 'args');
  5503. this.index = index;
  5504. this.min = min;
  5505. this.max = max;
  5506. }
  5507. AstArgument.prototype = Object.create(AstNode.prototype);
  5508. AstArgument.prototype.visit = function (visitor) {
  5509. visitor.visitArgument(this);
  5510. };
  5511. function AstLiteral(number) {
  5512. AstNode.call(this, 'literal');
  5513. this.number = number;
  5514. this.min = number;
  5515. this.max = number;
  5516. }
  5517. AstLiteral.prototype = Object.create(AstNode.prototype);
  5518. AstLiteral.prototype.visit = function (visitor) {
  5519. visitor.visitLiteral(this);
  5520. };
  5521. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5522. AstNode.call(this, 'binary');
  5523. this.op = op;
  5524. this.arg1 = arg1;
  5525. this.arg2 = arg2;
  5526. this.min = min;
  5527. this.max = max;
  5528. }
  5529. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5530. AstBinaryOperation.prototype.visit = function (visitor) {
  5531. visitor.visitBinaryOperation(this);
  5532. };
  5533. function AstMin(arg, max) {
  5534. AstNode.call(this, 'max');
  5535. this.arg = arg;
  5536. this.min = arg.min;
  5537. this.max = max;
  5538. }
  5539. AstMin.prototype = Object.create(AstNode.prototype);
  5540. AstMin.prototype.visit = function (visitor) {
  5541. visitor.visitMin(this);
  5542. };
  5543. function AstVariable(index, min, max) {
  5544. AstNode.call(this, 'var');
  5545. this.index = index;
  5546. this.min = min;
  5547. this.max = max;
  5548. }
  5549. AstVariable.prototype = Object.create(AstNode.prototype);
  5550. AstVariable.prototype.visit = function (visitor) {
  5551. visitor.visitVariable(this);
  5552. };
  5553. function AstVariableDefinition(variable, arg) {
  5554. AstNode.call(this, 'definition');
  5555. this.variable = variable;
  5556. this.arg = arg;
  5557. }
  5558. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5559. AstVariableDefinition.prototype.visit = function (visitor) {
  5560. visitor.visitVariableDefinition(this);
  5561. };
  5562. function ExpressionBuilderVisitor() {
  5563. this.parts = [];
  5564. }
  5565. ExpressionBuilderVisitor.prototype = {
  5566. visitArgument: function (arg) {
  5567. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5568. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5569. },
  5570. visitVariable: function (variable) {
  5571. this.parts.push('v', variable.index);
  5572. },
  5573. visitLiteral: function (literal) {
  5574. this.parts.push(literal.number);
  5575. },
  5576. visitBinaryOperation: function (operation) {
  5577. this.parts.push('(');
  5578. operation.arg1.visit(this);
  5579. this.parts.push(' ', operation.op, ' ');
  5580. operation.arg2.visit(this);
  5581. this.parts.push(')');
  5582. },
  5583. visitVariableDefinition: function (definition) {
  5584. this.parts.push('var ');
  5585. definition.variable.visit(this);
  5586. this.parts.push(' = ');
  5587. definition.arg.visit(this);
  5588. this.parts.push(';');
  5589. },
  5590. visitMin: function (max) {
  5591. this.parts.push('Math.min(');
  5592. max.arg.visit(this);
  5593. this.parts.push(', ', max.max, ')');
  5594. },
  5595. toString: function () {
  5596. return this.parts.join('');
  5597. }
  5598. };
  5599. function buildAddOperation(num1, num2) {
  5600. if (num2.type === 'literal' && num2.number === 0) {
  5601. // optimization: second operand is 0
  5602. return num1;
  5603. }
  5604. if (num1.type === 'literal' && num1.number === 0) {
  5605. // optimization: first operand is 0
  5606. return num2;
  5607. }
  5608. if (num2.type === 'literal' && num1.type === 'literal') {
  5609. // optimization: operands operand are literals
  5610. return new AstLiteral(num1.number + num2.number);
  5611. }
  5612. return new AstBinaryOperation('+', num1, num2,
  5613. num1.min + num2.min, num1.max + num2.max);
  5614. }
  5615. function buildMulOperation(num1, num2) {
  5616. if (num2.type === 'literal') {
  5617. // optimization: second operands is a literal...
  5618. if (num2.number === 0) {
  5619. return new AstLiteral(0); // and it's 0
  5620. } else if (num2.number === 1) {
  5621. return num1; // and it's 1
  5622. } else if (num1.type === 'literal') {
  5623. // ... and first operands is a literal too
  5624. return new AstLiteral(num1.number * num2.number);
  5625. }
  5626. }
  5627. if (num1.type === 'literal') {
  5628. // optimization: first operands is a literal...
  5629. if (num1.number === 0) {
  5630. return new AstLiteral(0); // and it's 0
  5631. } else if (num1.number === 1) {
  5632. return num2; // and it's 1
  5633. }
  5634. }
  5635. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5636. num1.max * num2.min, num1.max * num2.max);
  5637. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5638. num1.max * num2.min, num1.max * num2.max);
  5639. return new AstBinaryOperation('*', num1, num2, min, max);
  5640. }
  5641. function buildSubOperation(num1, num2) {
  5642. if (num2.type === 'literal') {
  5643. // optimization: second operands is a literal...
  5644. if (num2.number === 0) {
  5645. return num1; // ... and it's 0
  5646. } else if (num1.type === 'literal') {
  5647. // ... and first operands is a literal too
  5648. return new AstLiteral(num1.number - num2.number);
  5649. }
  5650. }
  5651. if (num2.type === 'binary' && num2.op === '-' &&
  5652. num1.type === 'literal' && num1.number === 1 &&
  5653. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5654. // optimization for case: 1 - (1 - x)
  5655. return num2.arg2;
  5656. }
  5657. return new AstBinaryOperation('-', num1, num2,
  5658. num1.min - num2.max, num1.max - num2.min);
  5659. }
  5660. function buildMinOperation(num1, max) {
  5661. if (num1.min >= max) {
  5662. // optimization: num1 min value is not less than required max
  5663. return new AstLiteral(max); // just returning max
  5664. } else if (num1.max <= max) {
  5665. // optimization: num1 max value is not greater than required max
  5666. return num1; // just returning an argument
  5667. }
  5668. return new AstMin(num1, max);
  5669. }
  5670. function PostScriptCompiler() {}
  5671. PostScriptCompiler.prototype = {
  5672. compile: function PostScriptCompiler_compile(code, domain, range) {
  5673. var stack = [];
  5674. var i, ii;
  5675. var instructions = [];
  5676. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5677. var lastRegister = 0;
  5678. var n, j, min, max;
  5679. var num1, num2, ast1, ast2, tmpVar, item;
  5680. for (i = 0; i < inputSize; i++) {
  5681. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5682. }
  5683. for (i = 0, ii = code.length; i < ii; i++) {
  5684. item = code[i];
  5685. if (typeof item === 'number') {
  5686. stack.push(new AstLiteral(item));
  5687. continue;
  5688. }
  5689. switch (item) {
  5690. case 'add':
  5691. if (stack.length < 2) {
  5692. return null;
  5693. }
  5694. num2 = stack.pop();
  5695. num1 = stack.pop();
  5696. stack.push(buildAddOperation(num1, num2));
  5697. break;
  5698. case 'cvr':
  5699. if (stack.length < 1) {
  5700. return null;
  5701. }
  5702. break;
  5703. case 'mul':
  5704. if (stack.length < 2) {
  5705. return null;
  5706. }
  5707. num2 = stack.pop();
  5708. num1 = stack.pop();
  5709. stack.push(buildMulOperation(num1, num2));
  5710. break;
  5711. case 'sub':
  5712. if (stack.length < 2) {
  5713. return null;
  5714. }
  5715. num2 = stack.pop();
  5716. num1 = stack.pop();
  5717. stack.push(buildSubOperation(num1, num2));
  5718. break;
  5719. case 'exch':
  5720. if (stack.length < 2) {
  5721. return null;
  5722. }
  5723. ast1 = stack.pop(); ast2 = stack.pop();
  5724. stack.push(ast1, ast2);
  5725. break;
  5726. case 'pop':
  5727. if (stack.length < 1) {
  5728. return null;
  5729. }
  5730. stack.pop();
  5731. break;
  5732. case 'index':
  5733. if (stack.length < 1) {
  5734. return null;
  5735. }
  5736. num1 = stack.pop();
  5737. if (num1.type !== 'literal') {
  5738. return null;
  5739. }
  5740. n = num1.number;
  5741. if (n < 0 || (n|0) !== n || stack.length < n) {
  5742. return null;
  5743. }
  5744. ast1 = stack[stack.length - n - 1];
  5745. if (ast1.type === 'literal' || ast1.type === 'var') {
  5746. stack.push(ast1);
  5747. break;
  5748. }
  5749. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5750. stack[stack.length - n - 1] = tmpVar;
  5751. stack.push(tmpVar);
  5752. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5753. break;
  5754. case 'dup':
  5755. if (stack.length < 1) {
  5756. return null;
  5757. }
  5758. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5759. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5760. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5761. // special case of the commands sequence for the min operation
  5762. num1 = stack.pop();
  5763. stack.push(buildMinOperation(num1, code[i + 1]));
  5764. i += 6;
  5765. break;
  5766. }
  5767. ast1 = stack[stack.length - 1];
  5768. if (ast1.type === 'literal' || ast1.type === 'var') {
  5769. // we don't have to save into intermediate variable a literal or
  5770. // variable.
  5771. stack.push(ast1);
  5772. break;
  5773. }
  5774. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5775. stack[stack.length - 1] = tmpVar;
  5776. stack.push(tmpVar);
  5777. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5778. break;
  5779. case 'roll':
  5780. if (stack.length < 2) {
  5781. return null;
  5782. }
  5783. num2 = stack.pop();
  5784. num1 = stack.pop();
  5785. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5786. // both roll operands must be numbers
  5787. return null;
  5788. }
  5789. j = num2.number;
  5790. n = num1.number;
  5791. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5792. // ... and integers
  5793. return null;
  5794. }
  5795. j = ((j % n) + n) % n;
  5796. if (j === 0) {
  5797. break; // just skipping -- there are nothing to rotate
  5798. }
  5799. Array.prototype.push.apply(stack,
  5800. stack.splice(stack.length - n, n - j));
  5801. break;
  5802. default:
  5803. return null; // unsupported operator
  5804. }
  5805. }
  5806. if (stack.length !== outputSize) {
  5807. return null;
  5808. }
  5809. var result = [];
  5810. instructions.forEach(function (instruction) {
  5811. var statementBuilder = new ExpressionBuilderVisitor();
  5812. instruction.visit(statementBuilder);
  5813. result.push(statementBuilder.toString());
  5814. });
  5815. stack.forEach(function (expr, i) {
  5816. var statementBuilder = new ExpressionBuilderVisitor();
  5817. expr.visit(statementBuilder);
  5818. var min = range[i * 2], max = range[i * 2 + 1];
  5819. var out = [statementBuilder.toString()];
  5820. if (min > expr.min) {
  5821. out.unshift('Math.max(', min, ', ');
  5822. out.push(')');
  5823. }
  5824. if (max < expr.max) {
  5825. out.unshift('Math.min(', max, ', ');
  5826. out.push(')');
  5827. }
  5828. out.unshift('dest[destOffset + ', i, '] = ');
  5829. out.push(';');
  5830. result.push(out.join(''));
  5831. });
  5832. return result.join('\n');
  5833. }
  5834. };
  5835. return PostScriptCompiler;
  5836. })();
  5837. var ColorSpace = (function ColorSpaceClosure() {
  5838. // Constructor should define this.numComps, this.defaultColor, this.name
  5839. function ColorSpace() {
  5840. error('should not call ColorSpace constructor');
  5841. }
  5842. ColorSpace.prototype = {
  5843. /**
  5844. * Converts the color value to the RGB color. The color components are
  5845. * located in the src array starting from the srcOffset. Returns the array
  5846. * of the rgb components, each value ranging from [0,255].
  5847. */
  5848. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5849. var rgb = new Uint8Array(3);
  5850. this.getRgbItem(src, srcOffset, rgb, 0);
  5851. return rgb;
  5852. },
  5853. /**
  5854. * Converts the color value to the RGB color, similar to the getRgb method.
  5855. * The result placed into the dest array starting from the destOffset.
  5856. */
  5857. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5858. dest, destOffset) {
  5859. error('Should not call ColorSpace.getRgbItem');
  5860. },
  5861. /**
  5862. * Converts the specified number of the color values to the RGB colors.
  5863. * The colors are located in the src array starting from the srcOffset.
  5864. * The result is placed into the dest array starting from the destOffset.
  5865. * The src array items shall be in [0,2^bits) range, the dest array items
  5866. * will be in [0,255] range. alpha01 indicates how many alpha components
  5867. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5868. * array).
  5869. */
  5870. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5871. dest, destOffset, bits,
  5872. alpha01) {
  5873. error('Should not call ColorSpace.getRgbBuffer');
  5874. },
  5875. /**
  5876. * Determines the number of bytes required to store the result of the
  5877. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5878. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5879. */
  5880. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5881. alpha01) {
  5882. error('Should not call ColorSpace.getOutputLength');
  5883. },
  5884. /**
  5885. * Returns true if source data will be equal the result/output data.
  5886. */
  5887. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5888. return false;
  5889. },
  5890. /**
  5891. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5892. * how many alpha components there are in the dest array; it will be either
  5893. * 0 (RGB array) or 1 (RGBA array).
  5894. */
  5895. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5896. originalHeight, width, height,
  5897. actualHeight, bpc, comps, alpha01) {
  5898. var count = originalWidth * originalHeight;
  5899. var rgbBuf = null;
  5900. var numComponentColors = 1 << bpc;
  5901. var needsResizing = originalHeight !== height || originalWidth !== width;
  5902. var i, ii;
  5903. if (this.isPassthrough(bpc)) {
  5904. rgbBuf = comps;
  5905. } else if (this.numComps === 1 && count > numComponentColors &&
  5906. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5907. // Optimization: create a color map when there is just one component and
  5908. // we are converting more colors than the size of the color map. We
  5909. // don't build the map if the colorspace is gray or rgb since those
  5910. // methods are faster than building a map. This mainly offers big speed
  5911. // ups for indexed and alternate colorspaces.
  5912. //
  5913. // TODO it may be worth while to cache the color map. While running
  5914. // testing I never hit a cache so I will leave that out for now (perhaps
  5915. // we are reparsing colorspaces too much?).
  5916. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5917. new Uint16Array(numComponentColors);
  5918. var key;
  5919. for (i = 0; i < numComponentColors; i++) {
  5920. allColors[i] = i;
  5921. }
  5922. var colorMap = new Uint8Array(numComponentColors * 3);
  5923. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5924. /* alpha01 = */ 0);
  5925. var destPos, rgbPos;
  5926. if (!needsResizing) {
  5927. // Fill in the RGB values directly into |dest|.
  5928. destPos = 0;
  5929. for (i = 0; i < count; ++i) {
  5930. key = comps[i] * 3;
  5931. dest[destPos++] = colorMap[key];
  5932. dest[destPos++] = colorMap[key + 1];
  5933. dest[destPos++] = colorMap[key + 2];
  5934. destPos += alpha01;
  5935. }
  5936. } else {
  5937. rgbBuf = new Uint8Array(count * 3);
  5938. rgbPos = 0;
  5939. for (i = 0; i < count; ++i) {
  5940. key = comps[i] * 3;
  5941. rgbBuf[rgbPos++] = colorMap[key];
  5942. rgbBuf[rgbPos++] = colorMap[key + 1];
  5943. rgbBuf[rgbPos++] = colorMap[key + 2];
  5944. }
  5945. }
  5946. } else {
  5947. if (!needsResizing) {
  5948. // Fill in the RGB values directly into |dest|.
  5949. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5950. alpha01);
  5951. } else {
  5952. rgbBuf = new Uint8Array(count * 3);
  5953. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5954. /* alpha01 = */ 0);
  5955. }
  5956. }
  5957. if (rgbBuf) {
  5958. if (needsResizing) {
  5959. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5960. height, dest, alpha01);
  5961. } else {
  5962. rgbPos = 0;
  5963. destPos = 0;
  5964. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5965. dest[destPos++] = rgbBuf[rgbPos++];
  5966. dest[destPos++] = rgbBuf[rgbPos++];
  5967. dest[destPos++] = rgbBuf[rgbPos++];
  5968. destPos += alpha01;
  5969. }
  5970. }
  5971. }
  5972. },
  5973. /**
  5974. * True if the colorspace has components in the default range of [0, 1].
  5975. * This should be true for all colorspaces except for lab color spaces
  5976. * which are [0,100], [-128, 127], [-128, 127].
  5977. */
  5978. usesZeroToOneRange: true
  5979. };
  5980. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5981. var IR = ColorSpace.parseToIR(cs, xref, res);
  5982. if (IR instanceof AlternateCS) {
  5983. return IR;
  5984. }
  5985. return ColorSpace.fromIR(IR);
  5986. };
  5987. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5988. var name = isArray(IR) ? IR[0] : IR;
  5989. var whitePoint, blackPoint, gamma;
  5990. switch (name) {
  5991. case 'DeviceGrayCS':
  5992. return this.singletons.gray;
  5993. case 'DeviceRgbCS':
  5994. return this.singletons.rgb;
  5995. case 'DeviceCmykCS':
  5996. return this.singletons.cmyk;
  5997. case 'CalGrayCS':
  5998. whitePoint = IR[1].WhitePoint;
  5999. blackPoint = IR[1].BlackPoint;
  6000. gamma = IR[1].Gamma;
  6001. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6002. case 'CalRGBCS':
  6003. whitePoint = IR[1].WhitePoint;
  6004. blackPoint = IR[1].BlackPoint;
  6005. gamma = IR[1].Gamma;
  6006. var matrix = IR[1].Matrix;
  6007. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6008. case 'PatternCS':
  6009. var basePatternCS = IR[1];
  6010. if (basePatternCS) {
  6011. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6012. }
  6013. return new PatternCS(basePatternCS);
  6014. case 'IndexedCS':
  6015. var baseIndexedCS = IR[1];
  6016. var hiVal = IR[2];
  6017. var lookup = IR[3];
  6018. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6019. case 'AlternateCS':
  6020. var numComps = IR[1];
  6021. var alt = IR[2];
  6022. var tintFnIR = IR[3];
  6023. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6024. PDFFunction.fromIR(tintFnIR));
  6025. case 'LabCS':
  6026. whitePoint = IR[1].WhitePoint;
  6027. blackPoint = IR[1].BlackPoint;
  6028. var range = IR[1].Range;
  6029. return new LabCS(whitePoint, blackPoint, range);
  6030. default:
  6031. error('Unknown name ' + name);
  6032. }
  6033. return null;
  6034. };
  6035. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6036. if (isName(cs)) {
  6037. var colorSpaces = res.get('ColorSpace');
  6038. if (isDict(colorSpaces)) {
  6039. var refcs = colorSpaces.get(cs.name);
  6040. if (refcs) {
  6041. cs = refcs;
  6042. }
  6043. }
  6044. }
  6045. cs = xref.fetchIfRef(cs);
  6046. var mode;
  6047. if (isName(cs)) {
  6048. mode = cs.name;
  6049. this.mode = mode;
  6050. switch (mode) {
  6051. case 'DeviceGray':
  6052. case 'G':
  6053. return 'DeviceGrayCS';
  6054. case 'DeviceRGB':
  6055. case 'RGB':
  6056. return 'DeviceRgbCS';
  6057. case 'DeviceCMYK':
  6058. case 'CMYK':
  6059. return 'DeviceCmykCS';
  6060. case 'Pattern':
  6061. return ['PatternCS', null];
  6062. default:
  6063. error('unrecognized colorspace ' + mode);
  6064. }
  6065. } else if (isArray(cs)) {
  6066. mode = cs[0].name;
  6067. this.mode = mode;
  6068. var numComps, params;
  6069. switch (mode) {
  6070. case 'DeviceGray':
  6071. case 'G':
  6072. return 'DeviceGrayCS';
  6073. case 'DeviceRGB':
  6074. case 'RGB':
  6075. return 'DeviceRgbCS';
  6076. case 'DeviceCMYK':
  6077. case 'CMYK':
  6078. return 'DeviceCmykCS';
  6079. case 'CalGray':
  6080. params = xref.fetchIfRef(cs[1]).getAll();
  6081. return ['CalGrayCS', params];
  6082. case 'CalRGB':
  6083. params = xref.fetchIfRef(cs[1]).getAll();
  6084. return ['CalRGBCS', params];
  6085. case 'ICCBased':
  6086. var stream = xref.fetchIfRef(cs[1]);
  6087. var dict = stream.dict;
  6088. numComps = dict.get('N');
  6089. if (numComps === 1) {
  6090. return 'DeviceGrayCS';
  6091. } else if (numComps === 3) {
  6092. return 'DeviceRgbCS';
  6093. } else if (numComps === 4) {
  6094. return 'DeviceCmykCS';
  6095. }
  6096. break;
  6097. case 'Pattern':
  6098. var basePatternCS = cs[1];
  6099. if (basePatternCS) {
  6100. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6101. }
  6102. return ['PatternCS', basePatternCS];
  6103. case 'Indexed':
  6104. case 'I':
  6105. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6106. var hiVal = cs[2] + 1;
  6107. var lookup = xref.fetchIfRef(cs[3]);
  6108. if (isStream(lookup)) {
  6109. lookup = lookup.getBytes();
  6110. }
  6111. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6112. case 'Separation':
  6113. case 'DeviceN':
  6114. var name = cs[1];
  6115. numComps = 1;
  6116. if (isName(name)) {
  6117. numComps = 1;
  6118. } else if (isArray(name)) {
  6119. numComps = name.length;
  6120. }
  6121. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6122. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6123. return ['AlternateCS', numComps, alt, tintFnIR];
  6124. case 'Lab':
  6125. params = cs[1].getAll();
  6126. return ['LabCS', params];
  6127. default:
  6128. error('unimplemented color space object "' + mode + '"');
  6129. }
  6130. } else {
  6131. error('unrecognized color space object: "' + cs + '"');
  6132. }
  6133. return null;
  6134. };
  6135. /**
  6136. * Checks if a decode map matches the default decode map for a color space.
  6137. * This handles the general decode maps where there are two values per
  6138. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6139. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6140. * slightly different.
  6141. * @param {Array} decode Decode map (usually from an image).
  6142. * @param {Number} n Number of components the color space has.
  6143. */
  6144. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6145. if (!decode) {
  6146. return true;
  6147. }
  6148. if (n * 2 !== decode.length) {
  6149. warn('The decode map is not the correct length');
  6150. return true;
  6151. }
  6152. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6153. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6154. return false;
  6155. }
  6156. }
  6157. return true;
  6158. };
  6159. ColorSpace.singletons = {
  6160. get gray() {
  6161. return shadow(this, 'gray', new DeviceGrayCS());
  6162. },
  6163. get rgb() {
  6164. return shadow(this, 'rgb', new DeviceRgbCS());
  6165. },
  6166. get cmyk() {
  6167. return shadow(this, 'cmyk', new DeviceCmykCS());
  6168. }
  6169. };
  6170. return ColorSpace;
  6171. })();
  6172. /**
  6173. * Alternate color space handles both Separation and DeviceN color spaces. A
  6174. * Separation color space is actually just a DeviceN with one color component.
  6175. * Both color spaces use a tinting function to convert colors to a base color
  6176. * space.
  6177. */
  6178. var AlternateCS = (function AlternateCSClosure() {
  6179. function AlternateCS(numComps, base, tintFn) {
  6180. this.name = 'Alternate';
  6181. this.numComps = numComps;
  6182. this.defaultColor = new Float32Array(numComps);
  6183. for (var i = 0; i < numComps; ++i) {
  6184. this.defaultColor[i] = 1;
  6185. }
  6186. this.base = base;
  6187. this.tintFn = tintFn;
  6188. this.tmpBuf = new Float32Array(base.numComps);
  6189. }
  6190. AlternateCS.prototype = {
  6191. getRgb: ColorSpace.prototype.getRgb,
  6192. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6193. dest, destOffset) {
  6194. var tmpBuf = this.tmpBuf;
  6195. this.tintFn(src, srcOffset, tmpBuf, 0);
  6196. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6197. },
  6198. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6199. dest, destOffset, bits,
  6200. alpha01) {
  6201. var tintFn = this.tintFn;
  6202. var base = this.base;
  6203. var scale = 1 / ((1 << bits) - 1);
  6204. var baseNumComps = base.numComps;
  6205. var usesZeroToOneRange = base.usesZeroToOneRange;
  6206. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6207. alpha01 === 0;
  6208. var pos = isPassthrough ? destOffset : 0;
  6209. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6210. var numComps = this.numComps;
  6211. var scaled = new Float32Array(numComps);
  6212. var tinted = new Float32Array(baseNumComps);
  6213. var i, j;
  6214. if (usesZeroToOneRange) {
  6215. for (i = 0; i < count; i++) {
  6216. for (j = 0; j < numComps; j++) {
  6217. scaled[j] = src[srcOffset++] * scale;
  6218. }
  6219. tintFn(scaled, 0, tinted, 0);
  6220. for (j = 0; j < baseNumComps; j++) {
  6221. baseBuf[pos++] = tinted[j] * 255;
  6222. }
  6223. }
  6224. } else {
  6225. for (i = 0; i < count; i++) {
  6226. for (j = 0; j < numComps; j++) {
  6227. scaled[j] = src[srcOffset++] * scale;
  6228. }
  6229. tintFn(scaled, 0, tinted, 0);
  6230. base.getRgbItem(tinted, 0, baseBuf, pos);
  6231. pos += baseNumComps;
  6232. }
  6233. }
  6234. if (!isPassthrough) {
  6235. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6236. }
  6237. },
  6238. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6239. alpha01) {
  6240. return this.base.getOutputLength(inputLength *
  6241. this.base.numComps / this.numComps,
  6242. alpha01);
  6243. },
  6244. isPassthrough: ColorSpace.prototype.isPassthrough,
  6245. fillRgb: ColorSpace.prototype.fillRgb,
  6246. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6247. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6248. },
  6249. usesZeroToOneRange: true
  6250. };
  6251. return AlternateCS;
  6252. })();
  6253. var PatternCS = (function PatternCSClosure() {
  6254. function PatternCS(baseCS) {
  6255. this.name = 'Pattern';
  6256. this.base = baseCS;
  6257. }
  6258. PatternCS.prototype = {};
  6259. return PatternCS;
  6260. })();
  6261. var IndexedCS = (function IndexedCSClosure() {
  6262. function IndexedCS(base, highVal, lookup) {
  6263. this.name = 'Indexed';
  6264. this.numComps = 1;
  6265. this.defaultColor = new Uint8Array([0]);
  6266. this.base = base;
  6267. this.highVal = highVal;
  6268. var baseNumComps = base.numComps;
  6269. var length = baseNumComps * highVal;
  6270. var lookupArray;
  6271. if (isStream(lookup)) {
  6272. lookupArray = new Uint8Array(length);
  6273. var bytes = lookup.getBytes(length);
  6274. lookupArray.set(bytes);
  6275. } else if (isString(lookup)) {
  6276. lookupArray = new Uint8Array(length);
  6277. for (var i = 0; i < length; ++i) {
  6278. lookupArray[i] = lookup.charCodeAt(i);
  6279. }
  6280. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6281. lookupArray = lookup;
  6282. } else {
  6283. error('Unrecognized lookup table: ' + lookup);
  6284. }
  6285. this.lookup = lookupArray;
  6286. }
  6287. IndexedCS.prototype = {
  6288. getRgb: ColorSpace.prototype.getRgb,
  6289. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6290. dest, destOffset) {
  6291. var numComps = this.base.numComps;
  6292. var start = src[srcOffset] * numComps;
  6293. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6294. },
  6295. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6296. dest, destOffset, bits,
  6297. alpha01) {
  6298. var base = this.base;
  6299. var numComps = base.numComps;
  6300. var outputDelta = base.getOutputLength(numComps, alpha01);
  6301. var lookup = this.lookup;
  6302. for (var i = 0; i < count; ++i) {
  6303. var lookupPos = src[srcOffset++] * numComps;
  6304. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6305. destOffset += outputDelta;
  6306. }
  6307. },
  6308. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6309. return this.base.getOutputLength(inputLength * this.base.numComps,
  6310. alpha01);
  6311. },
  6312. isPassthrough: ColorSpace.prototype.isPassthrough,
  6313. fillRgb: ColorSpace.prototype.fillRgb,
  6314. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6315. // indexed color maps shouldn't be changed
  6316. return true;
  6317. },
  6318. usesZeroToOneRange: true
  6319. };
  6320. return IndexedCS;
  6321. })();
  6322. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6323. function DeviceGrayCS() {
  6324. this.name = 'DeviceGray';
  6325. this.numComps = 1;
  6326. this.defaultColor = new Float32Array([0]);
  6327. }
  6328. DeviceGrayCS.prototype = {
  6329. getRgb: ColorSpace.prototype.getRgb,
  6330. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6331. dest, destOffset) {
  6332. var c = (src[srcOffset] * 255) | 0;
  6333. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6334. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6335. },
  6336. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6337. dest, destOffset, bits,
  6338. alpha01) {
  6339. var scale = 255 / ((1 << bits) - 1);
  6340. var j = srcOffset, q = destOffset;
  6341. for (var i = 0; i < count; ++i) {
  6342. var c = (scale * src[j++]) | 0;
  6343. dest[q++] = c;
  6344. dest[q++] = c;
  6345. dest[q++] = c;
  6346. q += alpha01;
  6347. }
  6348. },
  6349. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6350. alpha01) {
  6351. return inputLength * (3 + alpha01);
  6352. },
  6353. isPassthrough: ColorSpace.prototype.isPassthrough,
  6354. fillRgb: ColorSpace.prototype.fillRgb,
  6355. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6356. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6357. },
  6358. usesZeroToOneRange: true
  6359. };
  6360. return DeviceGrayCS;
  6361. })();
  6362. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6363. function DeviceRgbCS() {
  6364. this.name = 'DeviceRGB';
  6365. this.numComps = 3;
  6366. this.defaultColor = new Float32Array([0, 0, 0]);
  6367. }
  6368. DeviceRgbCS.prototype = {
  6369. getRgb: ColorSpace.prototype.getRgb,
  6370. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6371. dest, destOffset) {
  6372. var r = (src[srcOffset] * 255) | 0;
  6373. var g = (src[srcOffset + 1] * 255) | 0;
  6374. var b = (src[srcOffset + 2] * 255) | 0;
  6375. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6376. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6377. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6378. },
  6379. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6380. dest, destOffset, bits,
  6381. alpha01) {
  6382. if (bits === 8 && alpha01 === 0) {
  6383. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6384. return;
  6385. }
  6386. var scale = 255 / ((1 << bits) - 1);
  6387. var j = srcOffset, q = destOffset;
  6388. for (var i = 0; i < count; ++i) {
  6389. dest[q++] = (scale * src[j++]) | 0;
  6390. dest[q++] = (scale * src[j++]) | 0;
  6391. dest[q++] = (scale * src[j++]) | 0;
  6392. q += alpha01;
  6393. }
  6394. },
  6395. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6396. alpha01) {
  6397. return (inputLength * (3 + alpha01) / 3) | 0;
  6398. },
  6399. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6400. return bits === 8;
  6401. },
  6402. fillRgb: ColorSpace.prototype.fillRgb,
  6403. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6404. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6405. },
  6406. usesZeroToOneRange: true
  6407. };
  6408. return DeviceRgbCS;
  6409. })();
  6410. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6411. // The coefficients below was found using numerical analysis: the method of
  6412. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6413. // where color_value is the tabular value from the table of sampled RGB colors
  6414. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6415. // CMYK color conversion using the estimation below:
  6416. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6417. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6418. var c = src[srcOffset + 0] * srcScale;
  6419. var m = src[srcOffset + 1] * srcScale;
  6420. var y = src[srcOffset + 2] * srcScale;
  6421. var k = src[srcOffset + 3] * srcScale;
  6422. var r =
  6423. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6424. 18.82290502165302 * y + 212.25662451639585 * k +
  6425. -285.2331026137004) +
  6426. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6427. -17.873870861415444 * k - 5.497006427196366) +
  6428. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6429. 17.5119270841813) +
  6430. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6431. var g =
  6432. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6433. 6.871425592049007 * y + 31.159100130055922 * k +
  6434. -79.2970844816548) +
  6435. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6436. 131.35250912493976 * k - 190.9453302588951) +
  6437. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6438. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6439. var b =
  6440. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6441. 30.89978309703729 * y - 0.23883238689178934 * k +
  6442. -14.183576799673286) +
  6443. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6444. 50.606957656360734 * k - 112.23884253719248) +
  6445. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6446. -193.58209356861505) +
  6447. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6448. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6449. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6450. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6451. }
  6452. function DeviceCmykCS() {
  6453. this.name = 'DeviceCMYK';
  6454. this.numComps = 4;
  6455. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6456. }
  6457. DeviceCmykCS.prototype = {
  6458. getRgb: ColorSpace.prototype.getRgb,
  6459. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6460. dest, destOffset) {
  6461. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6462. },
  6463. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6464. dest, destOffset, bits,
  6465. alpha01) {
  6466. var scale = 1 / ((1 << bits) - 1);
  6467. for (var i = 0; i < count; i++) {
  6468. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6469. srcOffset += 4;
  6470. destOffset += 3 + alpha01;
  6471. }
  6472. },
  6473. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6474. alpha01) {
  6475. return (inputLength / 4 * (3 + alpha01)) | 0;
  6476. },
  6477. isPassthrough: ColorSpace.prototype.isPassthrough,
  6478. fillRgb: ColorSpace.prototype.fillRgb,
  6479. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6480. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6481. },
  6482. usesZeroToOneRange: true
  6483. };
  6484. return DeviceCmykCS;
  6485. })();
  6486. //
  6487. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6488. //
  6489. var CalGrayCS = (function CalGrayCSClosure() {
  6490. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6491. this.name = 'CalGray';
  6492. this.numComps = 1;
  6493. this.defaultColor = new Float32Array([0]);
  6494. if (!whitePoint) {
  6495. error('WhitePoint missing - required for color space CalGray');
  6496. }
  6497. blackPoint = blackPoint || [0, 0, 0];
  6498. gamma = gamma || 1;
  6499. // Translate arguments to spec variables.
  6500. this.XW = whitePoint[0];
  6501. this.YW = whitePoint[1];
  6502. this.ZW = whitePoint[2];
  6503. this.XB = blackPoint[0];
  6504. this.YB = blackPoint[1];
  6505. this.ZB = blackPoint[2];
  6506. this.G = gamma;
  6507. // Validate variables as per spec.
  6508. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6509. error('Invalid WhitePoint components for ' + this.name +
  6510. ', no fallback available');
  6511. }
  6512. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6513. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6514. this.XB = this.YB = this.ZB = 0;
  6515. }
  6516. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6517. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6518. ', ZB: ' + this.ZB + ', only default values are supported.');
  6519. }
  6520. if (this.G < 1) {
  6521. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6522. ', falling back to default');
  6523. this.G = 1;
  6524. }
  6525. }
  6526. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6527. // A represents a gray component of a calibrated gray space.
  6528. // A <---> AG in the spec
  6529. var A = src[srcOffset] * scale;
  6530. var AG = Math.pow(A, cs.G);
  6531. // Computes L as per spec. ( = cs.YW * AG )
  6532. // Except if other than default BlackPoint values are used.
  6533. var L = cs.YW * AG;
  6534. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6535. // Convert values to rgb range [0, 255].
  6536. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6537. dest[destOffset] = val;
  6538. dest[destOffset + 1] = val;
  6539. dest[destOffset + 2] = val;
  6540. }
  6541. CalGrayCS.prototype = {
  6542. getRgb: ColorSpace.prototype.getRgb,
  6543. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6544. dest, destOffset) {
  6545. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6546. },
  6547. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6548. dest, destOffset, bits,
  6549. alpha01) {
  6550. var scale = 1 / ((1 << bits) - 1);
  6551. for (var i = 0; i < count; ++i) {
  6552. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6553. srcOffset += 1;
  6554. destOffset += 3 + alpha01;
  6555. }
  6556. },
  6557. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6558. return inputLength * (3 + alpha01);
  6559. },
  6560. isPassthrough: ColorSpace.prototype.isPassthrough,
  6561. fillRgb: ColorSpace.prototype.fillRgb,
  6562. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6563. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6564. },
  6565. usesZeroToOneRange: true
  6566. };
  6567. return CalGrayCS;
  6568. })();
  6569. //
  6570. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6571. //
  6572. var CalRGBCS = (function CalRGBCSClosure() {
  6573. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6574. // matrices.
  6575. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6576. 0.8951, 0.2664, -0.1614,
  6577. -0.7502, 1.7135, 0.0367,
  6578. 0.0389, -0.0685, 1.0296]);
  6579. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6580. 0.9869929, -0.1470543, 0.1599627,
  6581. 0.4323053, 0.5183603, 0.0492912,
  6582. -0.0085287, 0.0400428, 0.9684867]);
  6583. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6584. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6585. 3.2404542, -1.5371385, -0.4985314,
  6586. -0.9692660, 1.8760108, 0.0415560,
  6587. 0.0556434, -0.2040259, 1.0572252]);
  6588. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6589. var tempNormalizeMatrix = new Float32Array(3);
  6590. var tempConvertMatrix1 = new Float32Array(3);
  6591. var tempConvertMatrix2 = new Float32Array(3);
  6592. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6593. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6594. this.name = 'CalRGB';
  6595. this.numComps = 3;
  6596. this.defaultColor = new Float32Array(3);
  6597. if (!whitePoint) {
  6598. error('WhitePoint missing - required for color space CalRGB');
  6599. }
  6600. blackPoint = blackPoint || new Float32Array(3);
  6601. gamma = gamma || new Float32Array([1, 1, 1]);
  6602. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6603. // Translate arguments to spec variables.
  6604. var XW = whitePoint[0];
  6605. var YW = whitePoint[1];
  6606. var ZW = whitePoint[2];
  6607. this.whitePoint = whitePoint;
  6608. var XB = blackPoint[0];
  6609. var YB = blackPoint[1];
  6610. var ZB = blackPoint[2];
  6611. this.blackPoint = blackPoint;
  6612. this.GR = gamma[0];
  6613. this.GG = gamma[1];
  6614. this.GB = gamma[2];
  6615. this.MXA = matrix[0];
  6616. this.MYA = matrix[1];
  6617. this.MZA = matrix[2];
  6618. this.MXB = matrix[3];
  6619. this.MYB = matrix[4];
  6620. this.MZB = matrix[5];
  6621. this.MXC = matrix[6];
  6622. this.MYC = matrix[7];
  6623. this.MZC = matrix[8];
  6624. // Validate variables as per spec.
  6625. if (XW < 0 || ZW < 0 || YW !== 1) {
  6626. error('Invalid WhitePoint components for ' + this.name +
  6627. ', no fallback available');
  6628. }
  6629. if (XB < 0 || YB < 0 || ZB < 0) {
  6630. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6631. ', ' + ZB + '], falling back to default');
  6632. this.blackPoint = new Float32Array(3);
  6633. }
  6634. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6635. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6636. '] for ' + this.name + ', falling back to default');
  6637. this.GR = this.GG = this.GB = 1;
  6638. }
  6639. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6640. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6641. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6642. info('Invalid Matrix for ' + this.name + ' [' +
  6643. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6644. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6645. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6646. '], falling back to default');
  6647. this.MXA = this.MYB = this.MZC = 1;
  6648. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6649. }
  6650. }
  6651. function matrixProduct(a, b, result) {
  6652. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6653. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6654. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6655. }
  6656. function convertToFlat(sourceWhitePoint, LMS, result) {
  6657. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6658. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6659. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6660. }
  6661. function convertToD65(sourceWhitePoint, LMS, result) {
  6662. var D65X = 0.95047;
  6663. var D65Y = 1;
  6664. var D65Z = 1.08883;
  6665. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6666. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6667. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6668. }
  6669. function sRGBTransferFunction(color) {
  6670. // See http://en.wikipedia.org/wiki/SRGB.
  6671. if (color <= 0.0031308){
  6672. return adjustToRange(0, 1, 12.92 * color);
  6673. }
  6674. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6675. }
  6676. function adjustToRange(min, max, value) {
  6677. return Math.max(min, Math.min(max, value));
  6678. }
  6679. function decodeL(L) {
  6680. if (L < 0) {
  6681. return -decodeL(-L);
  6682. }
  6683. if (L > 8.0) {
  6684. return Math.pow(((L + 16) / 116), 3);
  6685. }
  6686. return L * DECODE_L_CONSTANT;
  6687. }
  6688. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6689. // In case the blackPoint is already the default blackPoint then there is
  6690. // no need to do compensation.
  6691. if (sourceBlackPoint[0] === 0 &&
  6692. sourceBlackPoint[1] === 0 &&
  6693. sourceBlackPoint[2] === 0) {
  6694. result[0] = XYZ_Flat[0];
  6695. result[1] = XYZ_Flat[1];
  6696. result[2] = XYZ_Flat[2];
  6697. return;
  6698. }
  6699. // For the blackPoint calculation details, please see
  6700. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6701. // AdobeBPC.pdf.
  6702. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6703. var zeroDecodeL = decodeL(0);
  6704. var X_DST = zeroDecodeL;
  6705. var X_SRC = decodeL(sourceBlackPoint[0]);
  6706. var Y_DST = zeroDecodeL;
  6707. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6708. var Z_DST = zeroDecodeL;
  6709. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6710. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6711. var X_Offset = 1 - X_Scale;
  6712. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6713. var Y_Offset = 1 - Y_Scale;
  6714. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6715. var Z_Offset = 1 - Z_Scale;
  6716. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6717. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6718. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6719. }
  6720. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6721. // In case the whitePoint is already flat then there is no need to do
  6722. // normalization.
  6723. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6724. result[0] = XYZ_In[0];
  6725. result[1] = XYZ_In[1];
  6726. result[2] = XYZ_In[2];
  6727. return;
  6728. }
  6729. var LMS = result;
  6730. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6731. var LMS_Flat = tempNormalizeMatrix;
  6732. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6733. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6734. }
  6735. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6736. var LMS = result;
  6737. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6738. var LMS_D65 = tempNormalizeMatrix;
  6739. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6740. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6741. }
  6742. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6743. // A, B and C represent a red, green and blue components of a calibrated
  6744. // rgb space.
  6745. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6746. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6747. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6748. // A <---> AGR in the spec
  6749. // B <---> BGG in the spec
  6750. // C <---> CGB in the spec
  6751. var AGR = Math.pow(A, cs.GR);
  6752. var BGG = Math.pow(B, cs.GG);
  6753. var CGB = Math.pow(C, cs.GB);
  6754. // Computes intermediate variables L, M, N as per spec.
  6755. // To decode X, Y, Z values map L, M, N directly to them.
  6756. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6757. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6758. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6759. // The following calculations are based on this document:
  6760. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6761. // AdobeBPC.pdf.
  6762. var XYZ = tempConvertMatrix1;
  6763. XYZ[0] = X;
  6764. XYZ[1] = Y;
  6765. XYZ[2] = Z;
  6766. var XYZ_Flat = tempConvertMatrix2;
  6767. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6768. var XYZ_Black = tempConvertMatrix1;
  6769. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6770. var XYZ_D65 = tempConvertMatrix2;
  6771. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6772. var SRGB = tempConvertMatrix1;
  6773. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6774. var sR = sRGBTransferFunction(SRGB[0]);
  6775. var sG = sRGBTransferFunction(SRGB[1]);
  6776. var sB = sRGBTransferFunction(SRGB[2]);
  6777. // Convert the values to rgb range [0, 255].
  6778. dest[destOffset] = Math.round(sR * 255);
  6779. dest[destOffset + 1] = Math.round(sG * 255);
  6780. dest[destOffset + 2] = Math.round(sB * 255);
  6781. }
  6782. CalRGBCS.prototype = {
  6783. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6784. var rgb = new Uint8Array(3);
  6785. this.getRgbItem(src, srcOffset, rgb, 0);
  6786. return rgb;
  6787. },
  6788. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6789. dest, destOffset) {
  6790. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6791. },
  6792. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6793. dest, destOffset, bits,
  6794. alpha01) {
  6795. var scale = 1 / ((1 << bits) - 1);
  6796. for (var i = 0; i < count; ++i) {
  6797. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6798. srcOffset += 3;
  6799. destOffset += 3 + alpha01;
  6800. }
  6801. },
  6802. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6803. return (inputLength * (3 + alpha01) / 3) | 0;
  6804. },
  6805. isPassthrough: ColorSpace.prototype.isPassthrough,
  6806. fillRgb: ColorSpace.prototype.fillRgb,
  6807. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6808. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6809. },
  6810. usesZeroToOneRange: true
  6811. };
  6812. return CalRGBCS;
  6813. })();
  6814. //
  6815. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6816. //
  6817. var LabCS = (function LabCSClosure() {
  6818. function LabCS(whitePoint, blackPoint, range) {
  6819. this.name = 'Lab';
  6820. this.numComps = 3;
  6821. this.defaultColor = new Float32Array([0, 0, 0]);
  6822. if (!whitePoint) {
  6823. error('WhitePoint missing - required for color space Lab');
  6824. }
  6825. blackPoint = blackPoint || [0, 0, 0];
  6826. range = range || [-100, 100, -100, 100];
  6827. // Translate args to spec variables
  6828. this.XW = whitePoint[0];
  6829. this.YW = whitePoint[1];
  6830. this.ZW = whitePoint[2];
  6831. this.amin = range[0];
  6832. this.amax = range[1];
  6833. this.bmin = range[2];
  6834. this.bmax = range[3];
  6835. // These are here just for completeness - the spec doesn't offer any
  6836. // formulas that use BlackPoint in Lab
  6837. this.XB = blackPoint[0];
  6838. this.YB = blackPoint[1];
  6839. this.ZB = blackPoint[2];
  6840. // Validate vars as per spec
  6841. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6842. error('Invalid WhitePoint components, no fallback available');
  6843. }
  6844. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6845. info('Invalid BlackPoint, falling back to default');
  6846. this.XB = this.YB = this.ZB = 0;
  6847. }
  6848. if (this.amin > this.amax || this.bmin > this.bmax) {
  6849. info('Invalid Range, falling back to defaults');
  6850. this.amin = -100;
  6851. this.amax = 100;
  6852. this.bmin = -100;
  6853. this.bmax = 100;
  6854. }
  6855. }
  6856. // Function g(x) from spec
  6857. function fn_g(x) {
  6858. if (x >= 6 / 29) {
  6859. return x * x * x;
  6860. } else {
  6861. return (108 / 841) * (x - 4 / 29);
  6862. }
  6863. }
  6864. function decode(value, high1, low2, high2) {
  6865. return low2 + (value) * (high2 - low2) / (high1);
  6866. }
  6867. // If decoding is needed maxVal should be 2^bits per component - 1.
  6868. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6869. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6870. // not the usual [0, 1]. If a command like setFillColor is used the src
  6871. // values will already be within the correct range. However, if we are
  6872. // converting an image we have to map the values to the correct range given
  6873. // above.
  6874. // Ls,as,bs <---> L*,a*,b* in the spec
  6875. var Ls = src[srcOffset];
  6876. var as = src[srcOffset + 1];
  6877. var bs = src[srcOffset + 2];
  6878. if (maxVal !== false) {
  6879. Ls = decode(Ls, maxVal, 0, 100);
  6880. as = decode(as, maxVal, cs.amin, cs.amax);
  6881. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6882. }
  6883. // Adjust limits of 'as' and 'bs'
  6884. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6885. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6886. // Computes intermediate variables X,Y,Z as per spec
  6887. var M = (Ls + 16) / 116;
  6888. var L = M + (as / 500);
  6889. var N = M - (bs / 200);
  6890. var X = cs.XW * fn_g(L);
  6891. var Y = cs.YW * fn_g(M);
  6892. var Z = cs.ZW * fn_g(N);
  6893. var r, g, b;
  6894. // Using different conversions for D50 and D65 white points,
  6895. // per http://www.color.org/srgb.pdf
  6896. if (cs.ZW < 1) {
  6897. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6898. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6899. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6900. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6901. } else {
  6902. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6903. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6904. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6905. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6906. }
  6907. // clamp color values to [0,1] range then convert to [0,255] range.
  6908. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6909. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6910. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6911. }
  6912. LabCS.prototype = {
  6913. getRgb: ColorSpace.prototype.getRgb,
  6914. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6915. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6916. },
  6917. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6918. dest, destOffset, bits,
  6919. alpha01) {
  6920. var maxVal = (1 << bits) - 1;
  6921. for (var i = 0; i < count; i++) {
  6922. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6923. srcOffset += 3;
  6924. destOffset += 3 + alpha01;
  6925. }
  6926. },
  6927. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6928. return (inputLength * (3 + alpha01) / 3) | 0;
  6929. },
  6930. isPassthrough: ColorSpace.prototype.isPassthrough,
  6931. fillRgb: ColorSpace.prototype.fillRgb,
  6932. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6933. // XXX: Decoding is handled with the lab conversion because of the strange
  6934. // ranges that are used.
  6935. return true;
  6936. },
  6937. usesZeroToOneRange: false
  6938. };
  6939. return LabCS;
  6940. })();
  6941. var ARCFourCipher = (function ARCFourCipherClosure() {
  6942. function ARCFourCipher(key) {
  6943. this.a = 0;
  6944. this.b = 0;
  6945. var s = new Uint8Array(256);
  6946. var i, j = 0, tmp, keyLength = key.length;
  6947. for (i = 0; i < 256; ++i) {
  6948. s[i] = i;
  6949. }
  6950. for (i = 0; i < 256; ++i) {
  6951. tmp = s[i];
  6952. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6953. s[i] = s[j];
  6954. s[j] = tmp;
  6955. }
  6956. this.s = s;
  6957. }
  6958. ARCFourCipher.prototype = {
  6959. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6960. var i, n = data.length, tmp, tmp2;
  6961. var a = this.a, b = this.b, s = this.s;
  6962. var output = new Uint8Array(n);
  6963. for (i = 0; i < n; ++i) {
  6964. a = (a + 1) & 0xFF;
  6965. tmp = s[a];
  6966. b = (b + tmp) & 0xFF;
  6967. tmp2 = s[b];
  6968. s[a] = tmp2;
  6969. s[b] = tmp;
  6970. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6971. }
  6972. this.a = a;
  6973. this.b = b;
  6974. return output;
  6975. }
  6976. };
  6977. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6978. return ARCFourCipher;
  6979. })();
  6980. var calculateMD5 = (function calculateMD5Closure() {
  6981. var r = new Uint8Array([
  6982. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6983. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6984. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6985. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6986. var k = new Int32Array([
  6987. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6988. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6989. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6990. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6991. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6992. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6993. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6994. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6995. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6996. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6997. -145523070, -1120210379, 718787259, -343485551]);
  6998. function hash(data, offset, length) {
  6999. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7000. // pre-processing
  7001. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7002. var padded = new Uint8Array(paddedLength);
  7003. var i, j, n;
  7004. for (i = 0; i < length; ++i) {
  7005. padded[i] = data[offset++];
  7006. }
  7007. padded[i++] = 0x80;
  7008. n = paddedLength - 8;
  7009. while (i < n) {
  7010. padded[i++] = 0;
  7011. }
  7012. padded[i++] = (length << 3) & 0xFF;
  7013. padded[i++] = (length >> 5) & 0xFF;
  7014. padded[i++] = (length >> 13) & 0xFF;
  7015. padded[i++] = (length >> 21) & 0xFF;
  7016. padded[i++] = (length >>> 29) & 0xFF;
  7017. padded[i++] = 0;
  7018. padded[i++] = 0;
  7019. padded[i++] = 0;
  7020. var w = new Int32Array(16);
  7021. for (i = 0; i < paddedLength;) {
  7022. for (j = 0; j < 16; ++j, i += 4) {
  7023. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7024. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7025. }
  7026. var a = h0, b = h1, c = h2, d = h3, f, g;
  7027. for (j = 0; j < 64; ++j) {
  7028. if (j < 16) {
  7029. f = (b & c) | ((~b) & d);
  7030. g = j;
  7031. } else if (j < 32) {
  7032. f = (d & b) | ((~d) & c);
  7033. g = (5 * j + 1) & 15;
  7034. } else if (j < 48) {
  7035. f = b ^ c ^ d;
  7036. g = (3 * j + 5) & 15;
  7037. } else {
  7038. f = c ^ (b | (~d));
  7039. g = (7 * j) & 15;
  7040. }
  7041. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7042. d = c;
  7043. c = b;
  7044. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7045. a = tmp;
  7046. }
  7047. h0 = (h0 + a) | 0;
  7048. h1 = (h1 + b) | 0;
  7049. h2 = (h2 + c) | 0;
  7050. h3 = (h3 + d) | 0;
  7051. }
  7052. return new Uint8Array([
  7053. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7054. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7055. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7056. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7057. ]);
  7058. }
  7059. return hash;
  7060. })();
  7061. var Word64 = (function Word64Closure() {
  7062. function Word64(highInteger, lowInteger) {
  7063. this.high = highInteger | 0;
  7064. this.low = lowInteger | 0;
  7065. }
  7066. Word64.prototype = {
  7067. and: function Word64_and(word) {
  7068. this.high &= word.high;
  7069. this.low &= word.low;
  7070. },
  7071. xor: function Word64_xor(word) {
  7072. this.high ^= word.high;
  7073. this.low ^= word.low;
  7074. },
  7075. or: function Word64_or(word) {
  7076. this.high |= word.high;
  7077. this.low |= word.low;
  7078. },
  7079. shiftRight: function Word64_shiftRight(places) {
  7080. if (places >= 32) {
  7081. this.low = (this.high >>> (places - 32)) | 0;
  7082. this.high = 0;
  7083. } else {
  7084. this.low = (this.low >>> places) | (this.high << (32 - places));
  7085. this.high = (this.high >>> places) | 0;
  7086. }
  7087. },
  7088. shiftLeft: function Word64_shiftLeft(places) {
  7089. if (places >= 32) {
  7090. this.high = this.low << (places - 32);
  7091. this.low = 0;
  7092. } else {
  7093. this.high = (this.high << places) | (this.low >>> (32 - places));
  7094. this.low = this.low << places;
  7095. }
  7096. },
  7097. rotateRight: function Word64_rotateRight(places) {
  7098. var low, high;
  7099. if (places & 32) {
  7100. high = this.low;
  7101. low = this.high;
  7102. } else {
  7103. low = this.low;
  7104. high = this.high;
  7105. }
  7106. places &= 31;
  7107. this.low = (low >>> places) | (high << (32 - places));
  7108. this.high = (high >>> places) | (low << (32 - places));
  7109. },
  7110. not: function Word64_not() {
  7111. this.high = ~this.high;
  7112. this.low = ~this.low;
  7113. },
  7114. add: function Word64_add(word) {
  7115. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7116. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7117. if (lowAdd > 0xFFFFFFFF) {
  7118. highAdd += 1;
  7119. }
  7120. this.low = lowAdd | 0;
  7121. this.high = highAdd | 0;
  7122. },
  7123. copyTo: function Word64_copyTo(bytes, offset) {
  7124. bytes[offset] = (this.high >>> 24) & 0xFF;
  7125. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7126. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7127. bytes[offset + 3] = this.high & 0xFF;
  7128. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7129. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7130. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7131. bytes[offset + 7] = this.low & 0xFF;
  7132. },
  7133. assign: function Word64_assign(word) {
  7134. this.high = word.high;
  7135. this.low = word.low;
  7136. }
  7137. };
  7138. return Word64;
  7139. })();
  7140. var calculateSHA256 = (function calculateSHA256Closure() {
  7141. function rotr(x, n) {
  7142. return (x >>> n) | (x << 32 - n);
  7143. }
  7144. function ch(x, y, z) {
  7145. return (x & y) ^ (~x & z);
  7146. }
  7147. function maj(x, y, z) {
  7148. return (x & y) ^ (x & z) ^ (y & z);
  7149. }
  7150. function sigma(x) {
  7151. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7152. }
  7153. function sigmaPrime(x) {
  7154. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7155. }
  7156. function littleSigma(x) {
  7157. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7158. }
  7159. function littleSigmaPrime(x) {
  7160. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7161. }
  7162. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7163. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7164. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7165. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7166. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7167. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7168. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7169. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7170. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7171. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7172. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7173. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7174. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7175. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7176. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7177. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7178. function hash(data, offset, length) {
  7179. // initial hash values
  7180. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7181. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7182. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7183. // pre-processing
  7184. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7185. var padded = new Uint8Array(paddedLength);
  7186. var i, j, n;
  7187. for (i = 0; i < length; ++i) {
  7188. padded[i] = data[offset++];
  7189. }
  7190. padded[i++] = 0x80;
  7191. n = paddedLength - 8;
  7192. while (i < n) {
  7193. padded[i++] = 0;
  7194. }
  7195. padded[i++] = 0;
  7196. padded[i++] = 0;
  7197. padded[i++] = 0;
  7198. padded[i++] = (length >>> 29) & 0xFF;
  7199. padded[i++] = (length >> 21) & 0xFF;
  7200. padded[i++] = (length >> 13) & 0xFF;
  7201. padded[i++] = (length >> 5) & 0xFF;
  7202. padded[i++] = (length << 3) & 0xFF;
  7203. var w = new Uint32Array(64);
  7204. // for each 512 bit block
  7205. for (i = 0; i < paddedLength;) {
  7206. for (j = 0; j < 16; ++j) {
  7207. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7208. (padded[i + 2] << 8) | (padded[i + 3]));
  7209. i += 4;
  7210. }
  7211. for (j = 16; j < 64; ++j) {
  7212. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7213. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7214. }
  7215. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7216. f = h5, g = h6, h = h7, t1, t2;
  7217. for (j = 0; j < 64; ++j) {
  7218. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7219. t2 = sigma(a) + maj(a, b, c);
  7220. h = g;
  7221. g = f;
  7222. f = e;
  7223. e = (d + t1) | 0;
  7224. d = c;
  7225. c = b;
  7226. b = a;
  7227. a = (t1 + t2) | 0;
  7228. }
  7229. h0 = (h0 + a) | 0;
  7230. h1 = (h1 + b) | 0;
  7231. h2 = (h2 + c) | 0;
  7232. h3 = (h3 + d) | 0;
  7233. h4 = (h4 + e) | 0;
  7234. h5 = (h5 + f) | 0;
  7235. h6 = (h6 + g) | 0;
  7236. h7 = (h7 + h) | 0;
  7237. }
  7238. return new Uint8Array([
  7239. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7240. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7241. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7242. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7243. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7244. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7245. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7246. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7247. ]);
  7248. }
  7249. return hash;
  7250. })();
  7251. var calculateSHA512 = (function calculateSHA512Closure() {
  7252. function ch(result, x, y, z, tmp) {
  7253. result.assign(x);
  7254. result.and(y);
  7255. tmp.assign(x);
  7256. tmp.not();
  7257. tmp.and(z);
  7258. result.xor(tmp);
  7259. }
  7260. function maj(result, x, y, z, tmp) {
  7261. result.assign(x);
  7262. result.and(y);
  7263. tmp.assign(x);
  7264. tmp.and(z);
  7265. result.xor(tmp);
  7266. tmp.assign(y);
  7267. tmp.and(z);
  7268. result.xor(tmp);
  7269. }
  7270. function sigma(result, x, tmp) {
  7271. result.assign(x);
  7272. result.rotateRight(28);
  7273. tmp.assign(x);
  7274. tmp.rotateRight(34);
  7275. result.xor(tmp);
  7276. tmp.assign(x);
  7277. tmp.rotateRight(39);
  7278. result.xor(tmp);
  7279. }
  7280. function sigmaPrime(result, x, tmp) {
  7281. result.assign(x);
  7282. result.rotateRight(14);
  7283. tmp.assign(x);
  7284. tmp.rotateRight(18);
  7285. result.xor(tmp);
  7286. tmp.assign(x);
  7287. tmp.rotateRight(41);
  7288. result.xor(tmp);
  7289. }
  7290. function littleSigma(result, x, tmp) {
  7291. result.assign(x);
  7292. result.rotateRight(1);
  7293. tmp.assign(x);
  7294. tmp.rotateRight(8);
  7295. result.xor(tmp);
  7296. tmp.assign(x);
  7297. tmp.shiftRight(7);
  7298. result.xor(tmp);
  7299. }
  7300. function littleSigmaPrime(result, x, tmp) {
  7301. result.assign(x);
  7302. result.rotateRight(19);
  7303. tmp.assign(x);
  7304. tmp.rotateRight(61);
  7305. result.xor(tmp);
  7306. tmp.assign(x);
  7307. tmp.shiftRight(6);
  7308. result.xor(tmp);
  7309. }
  7310. var k = [
  7311. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7312. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7313. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7314. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7315. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7316. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7317. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7318. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7319. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7320. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7321. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7322. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7323. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7324. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7325. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7326. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7327. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7328. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7329. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7330. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7331. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7332. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7333. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7334. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7335. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7336. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7337. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7338. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7339. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7340. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7341. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7342. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7343. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7344. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7345. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7346. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7347. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7348. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7349. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7350. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7351. function hash(data, offset, length, mode384) {
  7352. mode384 = !!mode384;
  7353. // initial hash values
  7354. var h0, h1, h2, h3, h4, h5, h6, h7;
  7355. if (!mode384) {
  7356. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7357. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7358. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7359. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7360. h4 = new Word64(0x510e527f, 0xade682d1);
  7361. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7362. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7363. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7364. }
  7365. else {
  7366. // SHA384 is exactly the same
  7367. // except with different starting values and a trimmed result
  7368. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7369. h1 = new Word64(0x629a292a, 0x367cd507);
  7370. h2 = new Word64(0x9159015a, 0x3070dd17);
  7371. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7372. h4 = new Word64(0x67332667, 0xffc00b31);
  7373. h5 = new Word64(0x8eb44a87, 0x68581511);
  7374. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7375. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7376. }
  7377. // pre-processing
  7378. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7379. var padded = new Uint8Array(paddedLength);
  7380. var i, j, n;
  7381. for (i = 0; i < length; ++i) {
  7382. padded[i] = data[offset++];
  7383. }
  7384. padded[i++] = 0x80;
  7385. n = paddedLength - 16;
  7386. while (i < n) {
  7387. padded[i++] = 0;
  7388. }
  7389. padded[i++] = 0;
  7390. padded[i++] = 0;
  7391. padded[i++] = 0;
  7392. padded[i++] = 0;
  7393. padded[i++] = 0;
  7394. padded[i++] = 0;
  7395. padded[i++] = 0;
  7396. padded[i++] = 0;
  7397. padded[i++] = 0;
  7398. padded[i++] = 0;
  7399. padded[i++] = 0;
  7400. padded[i++] = (length >>> 29) & 0xFF;
  7401. padded[i++] = (length >> 21) & 0xFF;
  7402. padded[i++] = (length >> 13) & 0xFF;
  7403. padded[i++] = (length >> 5) & 0xFF;
  7404. padded[i++] = (length << 3) & 0xFF;
  7405. var w = new Array(80);
  7406. for (i = 0; i < 80; i++) {
  7407. w[i] = new Word64(0, 0);
  7408. }
  7409. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7410. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7411. var g = new Word64(0, 0), h = new Word64(0, 0);
  7412. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7413. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7414. // for each 1024 bit block
  7415. for (i = 0; i < paddedLength;) {
  7416. for (j = 0; j < 16; ++j) {
  7417. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7418. (padded[i + 2] << 8) | (padded[i + 3]);
  7419. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7420. (padded[i + 6]) << 8 | (padded[i + 7]);
  7421. i += 8;
  7422. }
  7423. for (j = 16; j < 80; ++j) {
  7424. tmp3 = w[j];
  7425. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7426. tmp3.add(w[j - 7]);
  7427. littleSigma(tmp1, w[j - 15], tmp2);
  7428. tmp3.add(tmp1);
  7429. tmp3.add(w[j - 16]);
  7430. }
  7431. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7432. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7433. for (j = 0; j < 80; ++j) {
  7434. t1.assign(h);
  7435. sigmaPrime(tmp1, e, tmp2);
  7436. t1.add(tmp1);
  7437. ch(tmp1, e, f, g, tmp2);
  7438. t1.add(tmp1);
  7439. t1.add(k[j]);
  7440. t1.add(w[j]);
  7441. sigma(t2, a, tmp2);
  7442. maj(tmp1, a, b, c, tmp2);
  7443. t2.add(tmp1);
  7444. tmp3 = h;
  7445. h = g;
  7446. g = f;
  7447. f = e;
  7448. d.add(t1);
  7449. e = d;
  7450. d = c;
  7451. c = b;
  7452. b = a;
  7453. tmp3.assign(t1);
  7454. tmp3.add(t2);
  7455. a = tmp3;
  7456. }
  7457. h0.add(a);
  7458. h1.add(b);
  7459. h2.add(c);
  7460. h3.add(d);
  7461. h4.add(e);
  7462. h5.add(f);
  7463. h6.add(g);
  7464. h7.add(h);
  7465. }
  7466. var result;
  7467. if (!mode384) {
  7468. result = new Uint8Array(64);
  7469. h0.copyTo(result,0);
  7470. h1.copyTo(result,8);
  7471. h2.copyTo(result,16);
  7472. h3.copyTo(result,24);
  7473. h4.copyTo(result,32);
  7474. h5.copyTo(result,40);
  7475. h6.copyTo(result,48);
  7476. h7.copyTo(result,56);
  7477. }
  7478. else {
  7479. result = new Uint8Array(48);
  7480. h0.copyTo(result,0);
  7481. h1.copyTo(result,8);
  7482. h2.copyTo(result,16);
  7483. h3.copyTo(result,24);
  7484. h4.copyTo(result,32);
  7485. h5.copyTo(result,40);
  7486. }
  7487. return result;
  7488. }
  7489. return hash;
  7490. })();
  7491. var calculateSHA384 = (function calculateSHA384Closure() {
  7492. function hash(data, offset, length) {
  7493. return calculateSHA512(data, offset, length, true);
  7494. }
  7495. return hash;
  7496. })();
  7497. var NullCipher = (function NullCipherClosure() {
  7498. function NullCipher() {
  7499. }
  7500. NullCipher.prototype = {
  7501. decryptBlock: function NullCipher_decryptBlock(data) {
  7502. return data;
  7503. }
  7504. };
  7505. return NullCipher;
  7506. })();
  7507. var AES128Cipher = (function AES128CipherClosure() {
  7508. var rcon = new Uint8Array([
  7509. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7510. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7511. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7512. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7513. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7514. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7515. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7516. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7517. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7518. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7519. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7520. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7521. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7522. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7523. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7524. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7525. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7526. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7527. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7528. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7529. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7530. 0x74, 0xe8, 0xcb, 0x8d]);
  7531. var s = new Uint8Array([
  7532. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7533. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7534. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7535. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7536. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7537. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7538. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7539. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7540. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7541. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7542. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7543. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7544. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7545. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7546. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7547. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7548. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7549. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7550. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7551. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7552. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7553. 0xb0, 0x54, 0xbb, 0x16]);
  7554. var inv_s = new Uint8Array([
  7555. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7556. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7557. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7558. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7559. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7560. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7561. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7562. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7563. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7564. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7565. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7566. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7567. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7568. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7569. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7570. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7571. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7572. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7573. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7574. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7575. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7576. 0x55, 0x21, 0x0c, 0x7d]);
  7577. var mixCol = new Uint8Array(256);
  7578. for (var i = 0; i < 256; i++) {
  7579. if (i < 128) {
  7580. mixCol[i] = i << 1;
  7581. } else {
  7582. mixCol[i] = (i << 1) ^ 0x1b;
  7583. }
  7584. }
  7585. var mix = new Uint32Array([
  7586. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7587. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7588. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7589. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7590. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7591. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7592. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7593. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7594. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7595. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7596. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7597. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7598. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7599. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7600. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7601. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7602. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7603. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7604. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7605. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7606. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7607. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7608. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7609. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7610. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7611. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7612. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7613. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7614. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7615. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7616. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7617. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7618. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7619. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7620. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7621. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7622. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7623. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7624. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7625. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7626. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7627. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7628. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7629. function expandKey128(cipherKey) {
  7630. var b = 176, result = new Uint8Array(b);
  7631. result.set(cipherKey);
  7632. for (var j = 16, i = 1; j < b; ++i) {
  7633. // RotWord
  7634. var t1 = result[j - 3], t2 = result[j - 2],
  7635. t3 = result[j - 1], t4 = result[j - 4];
  7636. // SubWord
  7637. t1 = s[t1];
  7638. t2 = s[t2];
  7639. t3 = s[t3];
  7640. t4 = s[t4];
  7641. // Rcon
  7642. t1 = t1 ^ rcon[i];
  7643. for (var n = 0; n < 4; ++n) {
  7644. result[j] = (t1 ^= result[j - 16]);
  7645. j++;
  7646. result[j] = (t2 ^= result[j - 16]);
  7647. j++;
  7648. result[j] = (t3 ^= result[j - 16]);
  7649. j++;
  7650. result[j] = (t4 ^= result[j - 16]);
  7651. j++;
  7652. }
  7653. }
  7654. return result;
  7655. }
  7656. function decrypt128(input, key) {
  7657. var state = new Uint8Array(16);
  7658. state.set(input);
  7659. var i, j, k;
  7660. var t, u, v;
  7661. // AddRoundKey
  7662. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7663. state[j] ^= key[k];
  7664. }
  7665. for (i = 9; i >= 1; --i) {
  7666. // InvShiftRows
  7667. t = state[13];
  7668. state[13] = state[9];
  7669. state[9] = state[5];
  7670. state[5] = state[1];
  7671. state[1] = t;
  7672. t = state[14];
  7673. u = state[10];
  7674. state[14] = state[6];
  7675. state[10] = state[2];
  7676. state[6] = t;
  7677. state[2] = u;
  7678. t = state[15];
  7679. u = state[11];
  7680. v = state[7];
  7681. state[15] = state[3];
  7682. state[11] = t;
  7683. state[7] = u;
  7684. state[3] = v;
  7685. // InvSubBytes
  7686. for (j = 0; j < 16; ++j) {
  7687. state[j] = inv_s[state[j]];
  7688. }
  7689. // AddRoundKey
  7690. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7691. state[j] ^= key[k];
  7692. }
  7693. // InvMixColumns
  7694. for (j = 0; j < 16; j += 4) {
  7695. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7696. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7697. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7698. (s3 >>> 24) ^ (s3 << 8));
  7699. state[j] = (t >>> 24) & 0xFF;
  7700. state[j + 1] = (t >> 16) & 0xFF;
  7701. state[j + 2] = (t >> 8) & 0xFF;
  7702. state[j + 3] = t & 0xFF;
  7703. }
  7704. }
  7705. // InvShiftRows
  7706. t = state[13];
  7707. state[13] = state[9];
  7708. state[9] = state[5];
  7709. state[5] = state[1];
  7710. state[1] = t;
  7711. t = state[14];
  7712. u = state[10];
  7713. state[14] = state[6];
  7714. state[10] = state[2];
  7715. state[6] = t;
  7716. state[2] = u;
  7717. t = state[15];
  7718. u = state[11];
  7719. v = state[7];
  7720. state[15] = state[3];
  7721. state[11] = t;
  7722. state[7] = u;
  7723. state[3] = v;
  7724. for (j = 0; j < 16; ++j) {
  7725. // InvSubBytes
  7726. state[j] = inv_s[state[j]];
  7727. // AddRoundKey
  7728. state[j] ^= key[j];
  7729. }
  7730. return state;
  7731. }
  7732. function encrypt128(input, key) {
  7733. var t, u, v, k;
  7734. var state = new Uint8Array(16);
  7735. state.set(input);
  7736. for (j = 0; j < 16; ++j) {
  7737. // AddRoundKey
  7738. state[j] ^= key[j];
  7739. }
  7740. for (i = 1; i < 10; i++) {
  7741. //SubBytes
  7742. for (j = 0; j < 16; ++j) {
  7743. state[j] = s[state[j]];
  7744. }
  7745. //ShiftRows
  7746. v = state[1];
  7747. state[1] = state[5];
  7748. state[5] = state[9];
  7749. state[9] = state[13];
  7750. state[13] = v;
  7751. v = state[2];
  7752. u = state[6];
  7753. state[2] = state[10];
  7754. state[6] = state[14];
  7755. state[10] = v;
  7756. state[14] = u;
  7757. v = state[3];
  7758. u = state[7];
  7759. t = state[11];
  7760. state[3] = state[15];
  7761. state[7] = v;
  7762. state[11] = u;
  7763. state[15] = t;
  7764. //MixColumns
  7765. for (var j = 0; j < 16; j += 4) {
  7766. var s0 = state[j + 0], s1 = state[j + 1];
  7767. var s2 = state[j + 2], s3 = state[j + 3];
  7768. t = s0 ^ s1 ^ s2 ^ s3;
  7769. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7770. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7771. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7772. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7773. }
  7774. //AddRoundKey
  7775. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7776. state[j] ^= key[k];
  7777. }
  7778. }
  7779. //SubBytes
  7780. for (j = 0; j < 16; ++j) {
  7781. state[j] = s[state[j]];
  7782. }
  7783. //ShiftRows
  7784. v = state[1];
  7785. state[1] = state[5];
  7786. state[5] = state[9];
  7787. state[9] = state[13];
  7788. state[13] = v;
  7789. v = state[2];
  7790. u = state[6];
  7791. state[2] = state[10];
  7792. state[6] = state[14];
  7793. state[10] = v;
  7794. state[14] = u;
  7795. v = state[3];
  7796. u = state[7];
  7797. t = state[11];
  7798. state[3] = state[15];
  7799. state[7] = v;
  7800. state[11] = u;
  7801. state[15] = t;
  7802. //AddRoundKey
  7803. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7804. state[j] ^= key[k];
  7805. }
  7806. return state;
  7807. }
  7808. function AES128Cipher(key) {
  7809. this.key = expandKey128(key);
  7810. this.buffer = new Uint8Array(16);
  7811. this.bufferPosition = 0;
  7812. }
  7813. function decryptBlock2(data, finalize) {
  7814. var i, j, ii, sourceLength = data.length,
  7815. buffer = this.buffer, bufferLength = this.bufferPosition,
  7816. result = [], iv = this.iv;
  7817. for (i = 0; i < sourceLength; ++i) {
  7818. buffer[bufferLength] = data[i];
  7819. ++bufferLength;
  7820. if (bufferLength < 16) {
  7821. continue;
  7822. }
  7823. // buffer is full, decrypting
  7824. var plain = decrypt128(buffer, this.key);
  7825. // xor-ing the IV vector to get plain text
  7826. for (j = 0; j < 16; ++j) {
  7827. plain[j] ^= iv[j];
  7828. }
  7829. iv = buffer;
  7830. result.push(plain);
  7831. buffer = new Uint8Array(16);
  7832. bufferLength = 0;
  7833. }
  7834. // saving incomplete buffer
  7835. this.buffer = buffer;
  7836. this.bufferLength = bufferLength;
  7837. this.iv = iv;
  7838. if (result.length === 0) {
  7839. return new Uint8Array([]);
  7840. }
  7841. // combining plain text blocks into one
  7842. var outputLength = 16 * result.length;
  7843. if (finalize) {
  7844. // undo a padding that is described in RFC 2898
  7845. var lastBlock = result[result.length - 1];
  7846. var psLen = lastBlock[15];
  7847. if (psLen <= 16) {
  7848. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7849. if (lastBlock[i] !== psLen) {
  7850. // Invalid padding, assume that the block has no padding.
  7851. psLen = 0;
  7852. break;
  7853. }
  7854. }
  7855. outputLength -= psLen;
  7856. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7857. }
  7858. }
  7859. var output = new Uint8Array(outputLength);
  7860. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7861. output.set(result[i], j);
  7862. }
  7863. return output;
  7864. }
  7865. AES128Cipher.prototype = {
  7866. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7867. var i, sourceLength = data.length;
  7868. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7869. // waiting for IV values -- they are at the start of the stream
  7870. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7871. buffer[bufferLength] = data[i];
  7872. }
  7873. if (bufferLength < 16) {
  7874. // need more data
  7875. this.bufferLength = bufferLength;
  7876. return new Uint8Array([]);
  7877. }
  7878. this.iv = buffer;
  7879. this.buffer = new Uint8Array(16);
  7880. this.bufferLength = 0;
  7881. // starting decryption
  7882. this.decryptBlock = decryptBlock2;
  7883. return this.decryptBlock(data.subarray(16), finalize);
  7884. },
  7885. encrypt: function AES128Cipher_encrypt(data, iv) {
  7886. var i, j, ii, sourceLength = data.length,
  7887. buffer = this.buffer, bufferLength = this.bufferPosition,
  7888. result = [];
  7889. if (!iv) {
  7890. iv = new Uint8Array(16);
  7891. }
  7892. for (i = 0; i < sourceLength; ++i) {
  7893. buffer[bufferLength] = data[i];
  7894. ++bufferLength;
  7895. if (bufferLength < 16) {
  7896. continue;
  7897. }
  7898. for (j = 0; j < 16; ++j) {
  7899. buffer[j] ^= iv[j];
  7900. }
  7901. // buffer is full, encrypting
  7902. var cipher = encrypt128(buffer, this.key);
  7903. iv = cipher;
  7904. result.push(cipher);
  7905. buffer = new Uint8Array(16);
  7906. bufferLength = 0;
  7907. }
  7908. // saving incomplete buffer
  7909. this.buffer = buffer;
  7910. this.bufferLength = bufferLength;
  7911. this.iv = iv;
  7912. if (result.length === 0) {
  7913. return new Uint8Array([]);
  7914. }
  7915. // combining plain text blocks into one
  7916. var outputLength = 16 * result.length;
  7917. var output = new Uint8Array(outputLength);
  7918. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7919. output.set(result[i], j);
  7920. }
  7921. return output;
  7922. }
  7923. };
  7924. return AES128Cipher;
  7925. })();
  7926. var AES256Cipher = (function AES256CipherClosure() {
  7927. var rcon = new Uint8Array([
  7928. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7929. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7930. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7931. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7932. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7933. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7934. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7935. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7936. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7937. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7938. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7939. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7940. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7941. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7942. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7943. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7944. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7945. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7946. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7947. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7948. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7949. 0x74, 0xe8, 0xcb, 0x8d]);
  7950. var s = new Uint8Array([
  7951. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7952. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7953. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7954. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7955. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7956. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7957. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7958. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7959. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7960. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7961. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7962. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7963. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7964. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7965. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7966. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7967. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7968. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7969. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7970. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7971. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7972. 0xb0, 0x54, 0xbb, 0x16]);
  7973. var inv_s = new Uint8Array([
  7974. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7975. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7976. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7977. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7978. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7979. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7980. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7981. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7982. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7983. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7984. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7985. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7986. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7987. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7988. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7989. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7990. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7991. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7992. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7993. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7994. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7995. 0x55, 0x21, 0x0c, 0x7d]);
  7996. var mixCol = new Uint8Array(256);
  7997. for (var i = 0; i < 256; i++) {
  7998. if (i < 128) {
  7999. mixCol[i] = i << 1;
  8000. } else {
  8001. mixCol[i] = (i << 1) ^ 0x1b;
  8002. }
  8003. }
  8004. var mix = new Uint32Array([
  8005. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8006. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8007. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8008. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8009. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8010. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8011. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8012. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8013. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8014. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8015. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8016. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8017. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8018. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8019. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8020. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8021. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8022. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8023. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8024. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8025. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8026. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8027. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8028. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8029. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8030. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8031. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8032. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8033. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8034. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8035. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8036. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8037. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8038. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8039. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8040. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8041. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8042. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8043. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8044. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8045. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8046. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8047. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8048. function expandKey256(cipherKey) {
  8049. var b = 240, result = new Uint8Array(b);
  8050. var r = 1;
  8051. result.set(cipherKey);
  8052. for (var j = 32, i = 1; j < b; ++i) {
  8053. if (j % 32 === 16) {
  8054. t1 = s[t1];
  8055. t2 = s[t2];
  8056. t3 = s[t3];
  8057. t4 = s[t4];
  8058. } else if (j % 32 === 0) {
  8059. // RotWord
  8060. var t1 = result[j - 3], t2 = result[j - 2],
  8061. t3 = result[j - 1], t4 = result[j - 4];
  8062. // SubWord
  8063. t1 = s[t1];
  8064. t2 = s[t2];
  8065. t3 = s[t3];
  8066. t4 = s[t4];
  8067. // Rcon
  8068. t1 = t1 ^ r;
  8069. if ((r <<= 1) >= 256) {
  8070. r = (r ^ 0x1b) & 0xFF;
  8071. }
  8072. }
  8073. for (var n = 0; n < 4; ++n) {
  8074. result[j] = (t1 ^= result[j - 32]);
  8075. j++;
  8076. result[j] = (t2 ^= result[j - 32]);
  8077. j++;
  8078. result[j] = (t3 ^= result[j - 32]);
  8079. j++;
  8080. result[j] = (t4 ^= result[j - 32]);
  8081. j++;
  8082. }
  8083. }
  8084. return result;
  8085. }
  8086. function decrypt256(input, key) {
  8087. var state = new Uint8Array(16);
  8088. state.set(input);
  8089. var i, j, k;
  8090. var t, u, v;
  8091. // AddRoundKey
  8092. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8093. state[j] ^= key[k];
  8094. }
  8095. for (i = 13; i >= 1; --i) {
  8096. // InvShiftRows
  8097. t = state[13];
  8098. state[13] = state[9];
  8099. state[9] = state[5];
  8100. state[5] = state[1];
  8101. state[1] = t;
  8102. t = state[14];
  8103. u = state[10];
  8104. state[14] = state[6];
  8105. state[10] = state[2];
  8106. state[6] = t;
  8107. state[2] = u;
  8108. t = state[15];
  8109. u = state[11];
  8110. v = state[7];
  8111. state[15] = state[3];
  8112. state[11] = t;
  8113. state[7] = u;
  8114. state[3] = v;
  8115. // InvSubBytes
  8116. for (j = 0; j < 16; ++j) {
  8117. state[j] = inv_s[state[j]];
  8118. }
  8119. // AddRoundKey
  8120. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8121. state[j] ^= key[k];
  8122. }
  8123. // InvMixColumns
  8124. for (j = 0; j < 16; j += 4) {
  8125. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8126. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8127. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8128. (s3 >>> 24) ^ (s3 << 8));
  8129. state[j] = (t >>> 24) & 0xFF;
  8130. state[j + 1] = (t >> 16) & 0xFF;
  8131. state[j + 2] = (t >> 8) & 0xFF;
  8132. state[j + 3] = t & 0xFF;
  8133. }
  8134. }
  8135. // InvShiftRows
  8136. t = state[13];
  8137. state[13] = state[9];
  8138. state[9] = state[5];
  8139. state[5] = state[1];
  8140. state[1] = t;
  8141. t = state[14];
  8142. u = state[10];
  8143. state[14] = state[6];
  8144. state[10] = state[2];
  8145. state[6] = t;
  8146. state[2] = u;
  8147. t = state[15];
  8148. u = state[11];
  8149. v = state[7];
  8150. state[15] = state[3];
  8151. state[11] = t;
  8152. state[7] = u;
  8153. state[3] = v;
  8154. for (j = 0; j < 16; ++j) {
  8155. // InvSubBytes
  8156. state[j] = inv_s[state[j]];
  8157. // AddRoundKey
  8158. state[j] ^= key[j];
  8159. }
  8160. return state;
  8161. }
  8162. function encrypt256(input, key) {
  8163. var t, u, v, k;
  8164. var state = new Uint8Array(16);
  8165. state.set(input);
  8166. for (j = 0; j < 16; ++j) {
  8167. // AddRoundKey
  8168. state[j] ^= key[j];
  8169. }
  8170. for (i = 1; i < 14; i++) {
  8171. //SubBytes
  8172. for (j = 0; j < 16; ++j) {
  8173. state[j] = s[state[j]];
  8174. }
  8175. //ShiftRows
  8176. v = state[1];
  8177. state[1] = state[5];
  8178. state[5] = state[9];
  8179. state[9] = state[13];
  8180. state[13] = v;
  8181. v = state[2];
  8182. u = state[6];
  8183. state[2] = state[10];
  8184. state[6] = state[14];
  8185. state[10] = v;
  8186. state[14] = u;
  8187. v = state[3];
  8188. u = state[7];
  8189. t = state[11];
  8190. state[3] = state[15];
  8191. state[7] = v;
  8192. state[11] = u;
  8193. state[15] = t;
  8194. //MixColumns
  8195. for (var j = 0; j < 16; j += 4) {
  8196. var s0 = state[j + 0], s1 = state[j + 1];
  8197. var s2 = state[j + 2], s3 = state[j + 3];
  8198. t = s0 ^ s1 ^ s2 ^ s3;
  8199. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8200. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8201. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8202. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8203. }
  8204. //AddRoundKey
  8205. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8206. state[j] ^= key[k];
  8207. }
  8208. }
  8209. //SubBytes
  8210. for (j = 0; j < 16; ++j) {
  8211. state[j] = s[state[j]];
  8212. }
  8213. //ShiftRows
  8214. v = state[1];
  8215. state[1] = state[5];
  8216. state[5] = state[9];
  8217. state[9] = state[13];
  8218. state[13] = v;
  8219. v = state[2];
  8220. u = state[6];
  8221. state[2] = state[10];
  8222. state[6] = state[14];
  8223. state[10] = v;
  8224. state[14] = u;
  8225. v = state[3];
  8226. u = state[7];
  8227. t = state[11];
  8228. state[3] = state[15];
  8229. state[7] = v;
  8230. state[11] = u;
  8231. state[15] = t;
  8232. //AddRoundKey
  8233. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8234. state[j] ^= key[k];
  8235. }
  8236. return state;
  8237. }
  8238. function AES256Cipher(key) {
  8239. this.key = expandKey256(key);
  8240. this.buffer = new Uint8Array(16);
  8241. this.bufferPosition = 0;
  8242. }
  8243. function decryptBlock2(data, finalize) {
  8244. var i, j, ii, sourceLength = data.length,
  8245. buffer = this.buffer, bufferLength = this.bufferPosition,
  8246. result = [], iv = this.iv;
  8247. for (i = 0; i < sourceLength; ++i) {
  8248. buffer[bufferLength] = data[i];
  8249. ++bufferLength;
  8250. if (bufferLength < 16) {
  8251. continue;
  8252. }
  8253. // buffer is full, decrypting
  8254. var plain = decrypt256(buffer, this.key);
  8255. // xor-ing the IV vector to get plain text
  8256. for (j = 0; j < 16; ++j) {
  8257. plain[j] ^= iv[j];
  8258. }
  8259. iv = buffer;
  8260. result.push(plain);
  8261. buffer = new Uint8Array(16);
  8262. bufferLength = 0;
  8263. }
  8264. // saving incomplete buffer
  8265. this.buffer = buffer;
  8266. this.bufferLength = bufferLength;
  8267. this.iv = iv;
  8268. if (result.length === 0) {
  8269. return new Uint8Array([]);
  8270. }
  8271. // combining plain text blocks into one
  8272. var outputLength = 16 * result.length;
  8273. if (finalize) {
  8274. // undo a padding that is described in RFC 2898
  8275. var lastBlock = result[result.length - 1];
  8276. var psLen = lastBlock[15];
  8277. if (psLen <= 16) {
  8278. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8279. if (lastBlock[i] !== psLen) {
  8280. // Invalid padding, assume that the block has no padding.
  8281. psLen = 0;
  8282. break;
  8283. }
  8284. }
  8285. outputLength -= psLen;
  8286. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8287. }
  8288. }
  8289. var output = new Uint8Array(outputLength);
  8290. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8291. output.set(result[i], j);
  8292. }
  8293. return output;
  8294. }
  8295. AES256Cipher.prototype = {
  8296. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8297. var i, sourceLength = data.length;
  8298. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8299. // if not supplied an IV wait for IV values
  8300. // they are at the start of the stream
  8301. if (iv) {
  8302. this.iv = iv;
  8303. } else {
  8304. for (i = 0; bufferLength < 16 &&
  8305. i < sourceLength; ++i, ++bufferLength) {
  8306. buffer[bufferLength] = data[i];
  8307. }
  8308. if (bufferLength < 16) {
  8309. //need more data
  8310. this.bufferLength = bufferLength;
  8311. return new Uint8Array([]);
  8312. }
  8313. this.iv = buffer;
  8314. data = data.subarray(16);
  8315. }
  8316. this.buffer = new Uint8Array(16);
  8317. this.bufferLength = 0;
  8318. // starting decryption
  8319. this.decryptBlock = decryptBlock2;
  8320. return this.decryptBlock(data, finalize);
  8321. },
  8322. encrypt: function AES256Cipher_encrypt(data, iv) {
  8323. var i, j, ii, sourceLength = data.length,
  8324. buffer = this.buffer, bufferLength = this.bufferPosition,
  8325. result = [];
  8326. if (!iv) {
  8327. iv = new Uint8Array(16);
  8328. }
  8329. for (i = 0; i < sourceLength; ++i) {
  8330. buffer[bufferLength] = data[i];
  8331. ++bufferLength;
  8332. if (bufferLength < 16) {
  8333. continue;
  8334. }
  8335. for (j = 0; j < 16; ++j) {
  8336. buffer[j] ^= iv[j];
  8337. }
  8338. // buffer is full, encrypting
  8339. var cipher = encrypt256(buffer, this.key);
  8340. this.iv = cipher;
  8341. result.push(cipher);
  8342. buffer = new Uint8Array(16);
  8343. bufferLength = 0;
  8344. }
  8345. // saving incomplete buffer
  8346. this.buffer = buffer;
  8347. this.bufferLength = bufferLength;
  8348. this.iv = iv;
  8349. if (result.length === 0) {
  8350. return new Uint8Array([]);
  8351. }
  8352. // combining plain text blocks into one
  8353. var outputLength = 16 * result.length;
  8354. var output = new Uint8Array(outputLength);
  8355. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8356. output.set(result[i], j);
  8357. }
  8358. return output;
  8359. }
  8360. };
  8361. return AES256Cipher;
  8362. })();
  8363. var PDF17 = (function PDF17Closure() {
  8364. function compareByteArrays(array1, array2) {
  8365. if (array1.length !== array2.length) {
  8366. return false;
  8367. }
  8368. for (var i = 0; i < array1.length; i++) {
  8369. if (array1[i] !== array2[i]) {
  8370. return false;
  8371. }
  8372. }
  8373. return true;
  8374. }
  8375. function PDF17() {
  8376. }
  8377. PDF17.prototype = {
  8378. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8379. ownerValidationSalt,
  8380. userBytes,
  8381. ownerPassword) {
  8382. var hashData = new Uint8Array(password.length + 56);
  8383. hashData.set(password, 0);
  8384. hashData.set(ownerValidationSalt, password.length);
  8385. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8386. var result = calculateSHA256(hashData, 0, hashData.length);
  8387. return compareByteArrays(result, ownerPassword);
  8388. },
  8389. checkUserPassword: function PDF17_checkUserPassword(password,
  8390. userValidationSalt,
  8391. userPassword) {
  8392. var hashData = new Uint8Array(password.length + 8);
  8393. hashData.set(password, 0);
  8394. hashData.set(userValidationSalt, password.length);
  8395. var result = calculateSHA256(hashData, 0, hashData.length);
  8396. return compareByteArrays(result, userPassword);
  8397. },
  8398. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8399. ownerEncryption) {
  8400. var hashData = new Uint8Array(password.length + 56);
  8401. hashData.set(password, 0);
  8402. hashData.set(ownerKeySalt, password.length);
  8403. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8404. var key = calculateSHA256(hashData, 0, hashData.length);
  8405. var cipher = new AES256Cipher(key);
  8406. return cipher.decryptBlock(ownerEncryption,
  8407. false,
  8408. new Uint8Array(16));
  8409. },
  8410. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8411. userEncryption) {
  8412. var hashData = new Uint8Array(password.length + 8);
  8413. hashData.set(password, 0);
  8414. hashData.set(userKeySalt, password.length);
  8415. //key is the decryption key for the UE string
  8416. var key = calculateSHA256(hashData, 0, hashData.length);
  8417. var cipher = new AES256Cipher(key);
  8418. return cipher.decryptBlock(userEncryption,
  8419. false,
  8420. new Uint8Array(16));
  8421. }
  8422. };
  8423. return PDF17;
  8424. })();
  8425. var PDF20 = (function PDF20Closure() {
  8426. function concatArrays(array1, array2) {
  8427. var t = new Uint8Array(array1.length + array2.length);
  8428. t.set(array1, 0);
  8429. t.set(array2, array1.length);
  8430. return t;
  8431. }
  8432. function calculatePDF20Hash(password, input, userBytes) {
  8433. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8434. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8435. var e = [0];
  8436. var i = 0;
  8437. while (i < 64 || e[e.length - 1] > i - 32) {
  8438. var arrayLength = password.length + k.length + userBytes.length;
  8439. var k1 = new Uint8Array(arrayLength * 64);
  8440. var array = concatArrays(password, k);
  8441. array = concatArrays(array, userBytes);
  8442. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8443. k1.set(array, pos);
  8444. }
  8445. //AES128 CBC NO PADDING with
  8446. //first 16 bytes of k as the key and the second 16 as the iv.
  8447. var cipher = new AES128Cipher(k.subarray(0, 16));
  8448. e = cipher.encrypt(k1, k.subarray(16, 32));
  8449. //Now we have to take the first 16 bytes of an unsigned
  8450. //big endian integer... and compute the remainder
  8451. //modulo 3.... That is a fairly large number and
  8452. //JavaScript isn't going to handle that well...
  8453. //So we're using a trick that allows us to perform
  8454. //modulo math byte by byte
  8455. var remainder = 0;
  8456. for (var z = 0; z < 16; z++) {
  8457. remainder *= (256 % 3);
  8458. remainder %= 3;
  8459. remainder += ((e[z] >>> 0) % 3);
  8460. remainder %= 3;
  8461. }
  8462. if (remainder === 0) {
  8463. k = calculateSHA256(e, 0, e.length);
  8464. }
  8465. else if (remainder === 1) {
  8466. k = calculateSHA384(e, 0, e.length);
  8467. }
  8468. else if (remainder === 2) {
  8469. k = calculateSHA512(e, 0, e.length);
  8470. }
  8471. i++;
  8472. }
  8473. return k.subarray(0, 32);
  8474. }
  8475. function PDF20() {
  8476. }
  8477. function compareByteArrays(array1, array2) {
  8478. if (array1.length !== array2.length) {
  8479. return false;
  8480. }
  8481. for (var i = 0; i < array1.length; i++) {
  8482. if (array1[i] !== array2[i]) {
  8483. return false;
  8484. }
  8485. }
  8486. return true;
  8487. }
  8488. PDF20.prototype = {
  8489. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8490. return calculatePDF20Hash(password, concatBytes, userBytes);
  8491. },
  8492. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8493. ownerValidationSalt,
  8494. userBytes,
  8495. ownerPassword) {
  8496. var hashData = new Uint8Array(password.length + 56);
  8497. hashData.set(password, 0);
  8498. hashData.set(ownerValidationSalt, password.length);
  8499. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8500. var result = calculatePDF20Hash(password, hashData, userBytes);
  8501. return compareByteArrays(result, ownerPassword);
  8502. },
  8503. checkUserPassword: function PDF20_checkUserPassword(password,
  8504. userValidationSalt,
  8505. userPassword) {
  8506. var hashData = new Uint8Array(password.length + 8);
  8507. hashData.set(password, 0);
  8508. hashData.set(userValidationSalt, password.length);
  8509. var result = calculatePDF20Hash(password, hashData, []);
  8510. return compareByteArrays(result, userPassword);
  8511. },
  8512. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8513. ownerEncryption) {
  8514. var hashData = new Uint8Array(password.length + 56);
  8515. hashData.set(password, 0);
  8516. hashData.set(ownerKeySalt, password.length);
  8517. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8518. var key = calculatePDF20Hash(password, hashData, userBytes);
  8519. var cipher = new AES256Cipher(key);
  8520. return cipher.decryptBlock(ownerEncryption,
  8521. false,
  8522. new Uint8Array(16));
  8523. },
  8524. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8525. userEncryption) {
  8526. var hashData = new Uint8Array(password.length + 8);
  8527. hashData.set(password, 0);
  8528. hashData.set(userKeySalt, password.length);
  8529. //key is the decryption key for the UE string
  8530. var key = calculatePDF20Hash(password, hashData, []);
  8531. var cipher = new AES256Cipher(key);
  8532. return cipher.decryptBlock(userEncryption,
  8533. false,
  8534. new Uint8Array(16));
  8535. }
  8536. };
  8537. return PDF20;
  8538. })();
  8539. var CipherTransform = (function CipherTransformClosure() {
  8540. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8541. this.stringCipherConstructor = stringCipherConstructor;
  8542. this.streamCipherConstructor = streamCipherConstructor;
  8543. }
  8544. CipherTransform.prototype = {
  8545. createStream: function CipherTransform_createStream(stream, length) {
  8546. var cipher = new this.streamCipherConstructor();
  8547. return new DecryptStream(stream, length,
  8548. function cipherTransformDecryptStream(data, finalize) {
  8549. return cipher.decryptBlock(data, finalize);
  8550. }
  8551. );
  8552. },
  8553. decryptString: function CipherTransform_decryptString(s) {
  8554. var cipher = new this.stringCipherConstructor();
  8555. var data = stringToBytes(s);
  8556. data = cipher.decryptBlock(data, true);
  8557. return bytesToString(data);
  8558. }
  8559. };
  8560. return CipherTransform;
  8561. })();
  8562. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8563. var defaultPasswordBytes = new Uint8Array([
  8564. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8565. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8566. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8567. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8568. function createEncryptionKey20(revision, password, ownerPassword,
  8569. ownerValidationSalt, ownerKeySalt, uBytes,
  8570. userPassword, userValidationSalt, userKeySalt,
  8571. ownerEncryption, userEncryption, perms) {
  8572. if (password) {
  8573. var passwordLength = Math.min(127, password.length);
  8574. password = password.subarray(0, passwordLength);
  8575. } else {
  8576. password = [];
  8577. }
  8578. var pdfAlgorithm;
  8579. if (revision === 6) {
  8580. pdfAlgorithm = new PDF20();
  8581. } else {
  8582. pdfAlgorithm = new PDF17();
  8583. }
  8584. if (pdfAlgorithm) {
  8585. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8586. userPassword)) {
  8587. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8588. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8589. uBytes,
  8590. ownerPassword)) {
  8591. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8592. ownerEncryption);
  8593. }
  8594. }
  8595. return null;
  8596. }
  8597. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8598. flags, revision, keyLength, encryptMetadata) {
  8599. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8600. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8601. if (password) {
  8602. n = Math.min(32, password.length);
  8603. for (; i < n; ++i) {
  8604. hashData[i] = password[i];
  8605. }
  8606. }
  8607. j = 0;
  8608. while (i < 32) {
  8609. hashData[i++] = defaultPasswordBytes[j++];
  8610. }
  8611. // as now the padded password in the hashData[0..i]
  8612. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8613. hashData[i++] = ownerPassword[j];
  8614. }
  8615. hashData[i++] = flags & 0xFF;
  8616. hashData[i++] = (flags >> 8) & 0xFF;
  8617. hashData[i++] = (flags >> 16) & 0xFF;
  8618. hashData[i++] = (flags >>> 24) & 0xFF;
  8619. for (j = 0, n = fileId.length; j < n; ++j) {
  8620. hashData[i++] = fileId[j];
  8621. }
  8622. if (revision >= 4 && !encryptMetadata) {
  8623. hashData[i++] = 0xFF;
  8624. hashData[i++] = 0xFF;
  8625. hashData[i++] = 0xFF;
  8626. hashData[i++] = 0xFF;
  8627. }
  8628. var hash = calculateMD5(hashData, 0, i);
  8629. var keyLengthInBytes = keyLength >> 3;
  8630. if (revision >= 3) {
  8631. for (j = 0; j < 50; ++j) {
  8632. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8633. }
  8634. }
  8635. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8636. var cipher, checkData;
  8637. if (revision >= 3) {
  8638. for (i = 0; i < 32; ++i) {
  8639. hashData[i] = defaultPasswordBytes[i];
  8640. }
  8641. for (j = 0, n = fileId.length; j < n; ++j) {
  8642. hashData[i++] = fileId[j];
  8643. }
  8644. cipher = new ARCFourCipher(encryptionKey);
  8645. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8646. n = encryptionKey.length;
  8647. var derivedKey = new Uint8Array(n), k;
  8648. for (j = 1; j <= 19; ++j) {
  8649. for (k = 0; k < n; ++k) {
  8650. derivedKey[k] = encryptionKey[k] ^ j;
  8651. }
  8652. cipher = new ARCFourCipher(derivedKey);
  8653. checkData = cipher.encryptBlock(checkData);
  8654. }
  8655. for (j = 0, n = checkData.length; j < n; ++j) {
  8656. if (userPassword[j] !== checkData[j]) {
  8657. return null;
  8658. }
  8659. }
  8660. } else {
  8661. cipher = new ARCFourCipher(encryptionKey);
  8662. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8663. for (j = 0, n = checkData.length; j < n; ++j) {
  8664. if (userPassword[j] !== checkData[j]) {
  8665. return null;
  8666. }
  8667. }
  8668. }
  8669. return encryptionKey;
  8670. }
  8671. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8672. var hashData = new Uint8Array(32), i = 0, j, n;
  8673. n = Math.min(32, password.length);
  8674. for (; i < n; ++i) {
  8675. hashData[i] = password[i];
  8676. }
  8677. j = 0;
  8678. while (i < 32) {
  8679. hashData[i++] = defaultPasswordBytes[j++];
  8680. }
  8681. var hash = calculateMD5(hashData, 0, i);
  8682. var keyLengthInBytes = keyLength >> 3;
  8683. if (revision >= 3) {
  8684. for (j = 0; j < 50; ++j) {
  8685. hash = calculateMD5(hash, 0, hash.length);
  8686. }
  8687. }
  8688. var cipher, userPassword;
  8689. if (revision >= 3) {
  8690. userPassword = ownerPassword;
  8691. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8692. for (j = 19; j >= 0; j--) {
  8693. for (k = 0; k < keyLengthInBytes; ++k) {
  8694. derivedKey[k] = hash[k] ^ j;
  8695. }
  8696. cipher = new ARCFourCipher(derivedKey);
  8697. userPassword = cipher.encryptBlock(userPassword);
  8698. }
  8699. } else {
  8700. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8701. userPassword = cipher.encryptBlock(ownerPassword);
  8702. }
  8703. return userPassword;
  8704. }
  8705. var identityName = Name.get('Identity');
  8706. function CipherTransformFactory(dict, fileId, password) {
  8707. var filter = dict.get('Filter');
  8708. if (!isName(filter) || filter.name !== 'Standard') {
  8709. error('unknown encryption method');
  8710. }
  8711. this.dict = dict;
  8712. var algorithm = dict.get('V');
  8713. if (!isInt(algorithm) ||
  8714. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8715. algorithm !== 5)) {
  8716. error('unsupported encryption algorithm');
  8717. }
  8718. this.algorithm = algorithm;
  8719. var keyLength = dict.get('Length') || 40;
  8720. if (!isInt(keyLength) ||
  8721. keyLength < 40 || (keyLength % 8) !== 0) {
  8722. error('invalid key length');
  8723. }
  8724. // prepare keys
  8725. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8726. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8727. var flags = dict.get('P');
  8728. var revision = dict.get('R');
  8729. // meaningful when V is 4 or 5
  8730. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8731. dict.get('EncryptMetadata') !== false);
  8732. this.encryptMetadata = encryptMetadata;
  8733. var fileIdBytes = stringToBytes(fileId);
  8734. var passwordBytes;
  8735. if (password) {
  8736. passwordBytes = stringToBytes(password);
  8737. }
  8738. var encryptionKey;
  8739. if (algorithm !== 5) {
  8740. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8741. ownerPassword, userPassword, flags,
  8742. revision, keyLength, encryptMetadata);
  8743. }
  8744. else {
  8745. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8746. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8747. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8748. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8749. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8750. var ownerEncryption = stringToBytes(dict.get('OE'));
  8751. var userEncryption = stringToBytes(dict.get('UE'));
  8752. var perms = stringToBytes(dict.get('Perms'));
  8753. encryptionKey =
  8754. createEncryptionKey20(revision, passwordBytes,
  8755. ownerPassword, ownerValidationSalt,
  8756. ownerKeySalt, uBytes,
  8757. userPassword, userValidationSalt,
  8758. userKeySalt, ownerEncryption,
  8759. userEncryption, perms);
  8760. }
  8761. if (!encryptionKey && !password) {
  8762. throw new PasswordException('No password given',
  8763. PasswordResponses.NEED_PASSWORD);
  8764. } else if (!encryptionKey && password) {
  8765. // Attempting use the password as an owner password
  8766. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8767. revision, keyLength);
  8768. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8769. ownerPassword, userPassword, flags,
  8770. revision, keyLength, encryptMetadata);
  8771. }
  8772. if (!encryptionKey) {
  8773. throw new PasswordException('Incorrect Password',
  8774. PasswordResponses.INCORRECT_PASSWORD);
  8775. }
  8776. this.encryptionKey = encryptionKey;
  8777. if (algorithm >= 4) {
  8778. this.cf = dict.get('CF');
  8779. this.stmf = dict.get('StmF') || identityName;
  8780. this.strf = dict.get('StrF') || identityName;
  8781. this.eff = dict.get('EFF') || this.stmf;
  8782. }
  8783. }
  8784. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8785. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8786. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8787. key[i] = encryptionKey[i];
  8788. }
  8789. key[i++] = num & 0xFF;
  8790. key[i++] = (num >> 8) & 0xFF;
  8791. key[i++] = (num >> 16) & 0xFF;
  8792. key[i++] = gen & 0xFF;
  8793. key[i++] = (gen >> 8) & 0xFF;
  8794. if (isAes) {
  8795. key[i++] = 0x73;
  8796. key[i++] = 0x41;
  8797. key[i++] = 0x6C;
  8798. key[i++] = 0x54;
  8799. }
  8800. var hash = calculateMD5(key, 0, i);
  8801. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8802. }
  8803. function buildCipherConstructor(cf, name, num, gen, key) {
  8804. var cryptFilter = cf.get(name.name);
  8805. var cfm;
  8806. if (cryptFilter !== null && cryptFilter !== undefined) {
  8807. cfm = cryptFilter.get('CFM');
  8808. }
  8809. if (!cfm || cfm.name === 'None') {
  8810. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8811. return new NullCipher();
  8812. };
  8813. }
  8814. if ('V2' === cfm.name) {
  8815. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8816. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8817. };
  8818. }
  8819. if ('AESV2' === cfm.name) {
  8820. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8821. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8822. };
  8823. }
  8824. if ('AESV3' === cfm.name) {
  8825. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8826. return new AES256Cipher(key);
  8827. };
  8828. }
  8829. error('Unknown crypto method');
  8830. }
  8831. CipherTransformFactory.prototype = {
  8832. createCipherTransform:
  8833. function CipherTransformFactory_createCipherTransform(num, gen) {
  8834. if (this.algorithm === 4 || this.algorithm === 5) {
  8835. return new CipherTransform(
  8836. buildCipherConstructor(this.cf, this.stmf,
  8837. num, gen, this.encryptionKey),
  8838. buildCipherConstructor(this.cf, this.strf,
  8839. num, gen, this.encryptionKey));
  8840. }
  8841. // algorithms 1 and 2
  8842. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8843. var cipherConstructor = function buildCipherCipherConstructor() {
  8844. return new ARCFourCipher(key);
  8845. };
  8846. return new CipherTransform(cipherConstructor, cipherConstructor);
  8847. }
  8848. };
  8849. return CipherTransformFactory;
  8850. })();
  8851. var PatternType = {
  8852. FUNCTION_BASED: 1,
  8853. AXIAL: 2,
  8854. RADIAL: 3,
  8855. FREE_FORM_MESH: 4,
  8856. LATTICE_FORM_MESH: 5,
  8857. COONS_PATCH_MESH: 6,
  8858. TENSOR_PATCH_MESH: 7
  8859. };
  8860. var Pattern = (function PatternClosure() {
  8861. // Constructor should define this.getPattern
  8862. function Pattern() {
  8863. error('should not call Pattern constructor');
  8864. }
  8865. Pattern.prototype = {
  8866. // Input: current Canvas context
  8867. // Output: the appropriate fillStyle or strokeStyle
  8868. getPattern: function Pattern_getPattern(ctx) {
  8869. error('Should not call Pattern.getStyle: ' + ctx);
  8870. }
  8871. };
  8872. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8873. res) {
  8874. var dict = isStream(shading) ? shading.dict : shading;
  8875. var type = dict.get('ShadingType');
  8876. try {
  8877. switch (type) {
  8878. case PatternType.AXIAL:
  8879. case PatternType.RADIAL:
  8880. // Both radial and axial shadings are handled by RadialAxial shading.
  8881. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8882. case PatternType.FREE_FORM_MESH:
  8883. case PatternType.LATTICE_FORM_MESH:
  8884. case PatternType.COONS_PATCH_MESH:
  8885. case PatternType.TENSOR_PATCH_MESH:
  8886. return new Shadings.Mesh(shading, matrix, xref, res);
  8887. default:
  8888. throw new Error('Unknown PatternType: ' + type);
  8889. }
  8890. } catch (ex) {
  8891. if (ex instanceof MissingDataException) {
  8892. throw ex;
  8893. }
  8894. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8895. warn(ex);
  8896. return new Shadings.Dummy();
  8897. }
  8898. };
  8899. return Pattern;
  8900. })();
  8901. var Shadings = {};
  8902. // A small number to offset the first/last color stops so we can insert ones to
  8903. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8904. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8905. // internally so we have to go bigger.
  8906. Shadings.SMALL_NUMBER = 1e-2;
  8907. // Radial and axial shading have very similar implementations
  8908. // If needed, the implementations can be broken into two classes
  8909. Shadings.RadialAxial = (function RadialAxialClosure() {
  8910. function RadialAxial(dict, matrix, xref, res) {
  8911. this.matrix = matrix;
  8912. this.coordsArr = dict.get('Coords');
  8913. this.shadingType = dict.get('ShadingType');
  8914. this.type = 'Pattern';
  8915. var cs = dict.get('ColorSpace', 'CS');
  8916. cs = ColorSpace.parse(cs, xref, res);
  8917. this.cs = cs;
  8918. var t0 = 0.0, t1 = 1.0;
  8919. if (dict.has('Domain')) {
  8920. var domainArr = dict.get('Domain');
  8921. t0 = domainArr[0];
  8922. t1 = domainArr[1];
  8923. }
  8924. var extendStart = false, extendEnd = false;
  8925. if (dict.has('Extend')) {
  8926. var extendArr = dict.get('Extend');
  8927. extendStart = extendArr[0];
  8928. extendEnd = extendArr[1];
  8929. }
  8930. if (this.shadingType === PatternType.RADIAL &&
  8931. (!extendStart || !extendEnd)) {
  8932. // Radial gradient only currently works if either circle is fully within
  8933. // the other circle.
  8934. var x1 = this.coordsArr[0];
  8935. var y1 = this.coordsArr[1];
  8936. var r1 = this.coordsArr[2];
  8937. var x2 = this.coordsArr[3];
  8938. var y2 = this.coordsArr[4];
  8939. var r2 = this.coordsArr[5];
  8940. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8941. if (r1 <= r2 + distance &&
  8942. r2 <= r1 + distance) {
  8943. warn('Unsupported radial gradient.');
  8944. }
  8945. }
  8946. this.extendStart = extendStart;
  8947. this.extendEnd = extendEnd;
  8948. var fnObj = dict.get('Function');
  8949. var fn = PDFFunction.parseArray(xref, fnObj);
  8950. // 10 samples seems good enough for now, but probably won't work
  8951. // if there are sharp color changes. Ideally, we would implement
  8952. // the spec faithfully and add lossless optimizations.
  8953. var diff = t1 - t0;
  8954. var step = diff / 10;
  8955. var colorStops = this.colorStops = [];
  8956. // Protect against bad domains so we don't end up in an infinte loop below.
  8957. if (t0 >= t1 || step <= 0) {
  8958. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8959. // now.
  8960. info('Bad shading domain.');
  8961. return;
  8962. }
  8963. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8964. var rgbColor;
  8965. for (var i = t0; i <= t1; i += step) {
  8966. ratio[0] = i;
  8967. fn(ratio, 0, color, 0);
  8968. rgbColor = cs.getRgb(color, 0);
  8969. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8970. colorStops.push([(i - t0) / diff, cssColor]);
  8971. }
  8972. var background = 'transparent';
  8973. if (dict.has('Background')) {
  8974. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8975. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8976. }
  8977. if (!extendStart) {
  8978. // Insert a color stop at the front and offset the first real color stop
  8979. // so it doesn't conflict with the one we insert.
  8980. colorStops.unshift([0, background]);
  8981. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8982. }
  8983. if (!extendEnd) {
  8984. // Same idea as above in extendStart but for the end.
  8985. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8986. colorStops.push([1, background]);
  8987. }
  8988. this.colorStops = colorStops;
  8989. }
  8990. RadialAxial.prototype = {
  8991. getIR: function RadialAxial_getIR() {
  8992. var coordsArr = this.coordsArr;
  8993. var shadingType = this.shadingType;
  8994. var type, p0, p1, r0, r1;
  8995. if (shadingType === PatternType.AXIAL) {
  8996. p0 = [coordsArr[0], coordsArr[1]];
  8997. p1 = [coordsArr[2], coordsArr[3]];
  8998. r0 = null;
  8999. r1 = null;
  9000. type = 'axial';
  9001. } else if (shadingType === PatternType.RADIAL) {
  9002. p0 = [coordsArr[0], coordsArr[1]];
  9003. p1 = [coordsArr[3], coordsArr[4]];
  9004. r0 = coordsArr[2];
  9005. r1 = coordsArr[5];
  9006. type = 'radial';
  9007. } else {
  9008. error('getPattern type unknown: ' + shadingType);
  9009. }
  9010. var matrix = this.matrix;
  9011. if (matrix) {
  9012. p0 = Util.applyTransform(p0, matrix);
  9013. p1 = Util.applyTransform(p1, matrix);
  9014. }
  9015. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9016. }
  9017. };
  9018. return RadialAxial;
  9019. })();
  9020. // All mesh shading. For now, they will be presented as set of the triangles
  9021. // to be drawn on the canvas and rgb color for each vertex.
  9022. Shadings.Mesh = (function MeshClosure() {
  9023. function MeshStreamReader(stream, context) {
  9024. this.stream = stream;
  9025. this.context = context;
  9026. this.buffer = 0;
  9027. this.bufferLength = 0;
  9028. var numComps = context.numComps;
  9029. this.tmpCompsBuf = new Float32Array(numComps);
  9030. var csNumComps = context.colorSpace;
  9031. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9032. this.tmpCompsBuf;
  9033. }
  9034. MeshStreamReader.prototype = {
  9035. get hasData() {
  9036. if (this.stream.end) {
  9037. return this.stream.pos < this.stream.end;
  9038. }
  9039. if (this.bufferLength > 0) {
  9040. return true;
  9041. }
  9042. var nextByte = this.stream.getByte();
  9043. if (nextByte < 0) {
  9044. return false;
  9045. }
  9046. this.buffer = nextByte;
  9047. this.bufferLength = 8;
  9048. return true;
  9049. },
  9050. readBits: function MeshStreamReader_readBits(n) {
  9051. var buffer = this.buffer;
  9052. var bufferLength = this.bufferLength;
  9053. if (n === 32) {
  9054. if (bufferLength === 0) {
  9055. return ((this.stream.getByte() << 24) |
  9056. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9057. this.stream.getByte()) >>> 0;
  9058. }
  9059. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9060. (this.stream.getByte() << 8) | this.stream.getByte();
  9061. var nextByte = this.stream.getByte();
  9062. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9063. return ((buffer << (8 - bufferLength)) |
  9064. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9065. }
  9066. if (n === 8 && bufferLength === 0) {
  9067. return this.stream.getByte();
  9068. }
  9069. while (bufferLength < n) {
  9070. buffer = (buffer << 8) | this.stream.getByte();
  9071. bufferLength += 8;
  9072. }
  9073. bufferLength -= n;
  9074. this.bufferLength = bufferLength;
  9075. this.buffer = buffer & ((1 << bufferLength) - 1);
  9076. return buffer >> bufferLength;
  9077. },
  9078. align: function MeshStreamReader_align() {
  9079. this.buffer = 0;
  9080. this.bufferLength = 0;
  9081. },
  9082. readFlag: function MeshStreamReader_readFlag() {
  9083. return this.readBits(this.context.bitsPerFlag);
  9084. },
  9085. readCoordinate: function MeshStreamReader_readCoordinate() {
  9086. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9087. var xi = this.readBits(bitsPerCoordinate);
  9088. var yi = this.readBits(bitsPerCoordinate);
  9089. var decode = this.context.decode;
  9090. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9091. 2.3283064365386963e-10; // 2 ^ -32
  9092. return [
  9093. xi * scale * (decode[1] - decode[0]) + decode[0],
  9094. yi * scale * (decode[3] - decode[2]) + decode[2]
  9095. ];
  9096. },
  9097. readComponents: function MeshStreamReader_readComponents() {
  9098. var numComps = this.context.numComps;
  9099. var bitsPerComponent = this.context.bitsPerComponent;
  9100. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9101. 2.3283064365386963e-10; // 2 ^ -32
  9102. var decode = this.context.decode;
  9103. var components = this.tmpCompsBuf;
  9104. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9105. var ci = this.readBits(bitsPerComponent);
  9106. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9107. }
  9108. var color = this.tmpCsCompsBuf;
  9109. if (this.context.colorFn) {
  9110. this.context.colorFn(components, 0, color, 0);
  9111. }
  9112. return this.context.colorSpace.getRgb(color, 0);
  9113. }
  9114. };
  9115. function decodeType4Shading(mesh, reader) {
  9116. var coords = mesh.coords;
  9117. var colors = mesh.colors;
  9118. var operators = [];
  9119. var ps = []; // not maintaining cs since that will match ps
  9120. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9121. while (reader.hasData) {
  9122. var f = reader.readFlag();
  9123. var coord = reader.readCoordinate();
  9124. var color = reader.readComponents();
  9125. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9126. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9127. switch (f) {
  9128. case 0:
  9129. verticesLeft = 3;
  9130. break;
  9131. case 1:
  9132. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9133. verticesLeft = 1;
  9134. break;
  9135. case 2:
  9136. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9137. verticesLeft = 1;
  9138. break;
  9139. }
  9140. operators.push(f);
  9141. }
  9142. ps.push(coords.length);
  9143. coords.push(coord);
  9144. colors.push(color);
  9145. verticesLeft--;
  9146. reader.align();
  9147. }
  9148. var psPacked = new Int32Array(ps);
  9149. mesh.figures.push({
  9150. type: 'triangles',
  9151. coords: psPacked,
  9152. colors: psPacked
  9153. });
  9154. }
  9155. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9156. var coords = mesh.coords;
  9157. var colors = mesh.colors;
  9158. var ps = []; // not maintaining cs since that will match ps
  9159. while (reader.hasData) {
  9160. var coord = reader.readCoordinate();
  9161. var color = reader.readComponents();
  9162. ps.push(coords.length);
  9163. coords.push(coord);
  9164. colors.push(color);
  9165. }
  9166. var psPacked = new Int32Array(ps);
  9167. mesh.figures.push({
  9168. type: 'lattice',
  9169. coords: psPacked,
  9170. colors: psPacked,
  9171. verticesPerRow: verticesPerRow
  9172. });
  9173. }
  9174. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9175. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9176. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9177. var getB = (function getBClosure() {
  9178. function buildB(count) {
  9179. var lut = [];
  9180. for (var i = 0; i <= count; i++) {
  9181. var t = i / count, t_ = 1 - t;
  9182. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9183. 3 * t * t * t_, t * t * t]));
  9184. }
  9185. return lut;
  9186. }
  9187. var cache = [];
  9188. return function getB(count) {
  9189. if (!cache[count]) {
  9190. cache[count] = buildB(count);
  9191. }
  9192. return cache[count];
  9193. };
  9194. })();
  9195. function buildFigureFromPatch(mesh, index) {
  9196. var figure = mesh.figures[index];
  9197. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9198. var coords = mesh.coords, colors = mesh.colors;
  9199. var pi = figure.coords;
  9200. var ci = figure.colors;
  9201. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9202. coords[pi[12]][0], coords[pi[15]][0]);
  9203. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9204. coords[pi[12]][1], coords[pi[15]][1]);
  9205. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9206. coords[pi[12]][0], coords[pi[15]][0]);
  9207. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9208. coords[pi[12]][1], coords[pi[15]][1]);
  9209. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9210. (mesh.bounds[2] - mesh.bounds[0]));
  9211. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9212. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9213. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9214. (mesh.bounds[3] - mesh.bounds[1]));
  9215. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9216. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9217. var verticesPerRow = splitXBy + 1;
  9218. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9219. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9220. var k = 0;
  9221. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9222. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9223. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9224. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9225. for (var row = 0; row <= splitYBy; row++) {
  9226. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9227. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9228. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9229. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9230. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9231. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9232. for (var col = 0; col <= splitXBy; col++, k++) {
  9233. if ((row === 0 || row === splitYBy) &&
  9234. (col === 0 || col === splitXBy)) {
  9235. continue;
  9236. }
  9237. var x = 0, y = 0;
  9238. var q = 0;
  9239. for (var i = 0; i <= 3; i++) {
  9240. for (var j = 0; j <= 3; j++, q++) {
  9241. var m = bRow[row][i] * bCol[col][j];
  9242. x += coords[pi[q]][0] * m;
  9243. y += coords[pi[q]][1] * m;
  9244. }
  9245. }
  9246. figureCoords[k] = coords.length;
  9247. coords.push([x, y]);
  9248. figureColors[k] = colors.length;
  9249. var newColor = new Uint8Array(3);
  9250. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9251. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9252. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9253. colors.push(newColor);
  9254. }
  9255. }
  9256. figureCoords[0] = pi[0];
  9257. figureColors[0] = ci[0];
  9258. figureCoords[splitXBy] = pi[3];
  9259. figureColors[splitXBy] = ci[1];
  9260. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9261. figureColors[verticesPerRow * splitYBy] = ci[2];
  9262. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9263. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9264. mesh.figures[index] = {
  9265. type: 'lattice',
  9266. coords: figureCoords,
  9267. colors: figureColors,
  9268. verticesPerRow: verticesPerRow
  9269. };
  9270. }
  9271. function decodeType6Shading(mesh, reader) {
  9272. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9273. var coords = mesh.coords;
  9274. var colors = mesh.colors;
  9275. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9276. var cs = new Int32Array(4); // c00, c30, c03, c33
  9277. while (reader.hasData) {
  9278. var f = reader.readFlag();
  9279. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9280. var i, ii;
  9281. var pi = coords.length;
  9282. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9283. coords.push(reader.readCoordinate());
  9284. }
  9285. var ci = colors.length;
  9286. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9287. colors.push(reader.readComponents());
  9288. }
  9289. var tmp1, tmp2, tmp3, tmp4;
  9290. switch (f) {
  9291. case 0:
  9292. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9293. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9294. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9295. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9296. cs[2] = ci + 1; cs[3] = ci + 2;
  9297. cs[0] = ci; cs[1] = ci + 3;
  9298. break;
  9299. case 1:
  9300. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9301. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9302. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9303. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9304. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9305. tmp1 = cs[2]; tmp2 = cs[3];
  9306. cs[2] = ci + 1; cs[3] = ci;
  9307. cs[0] = tmp1; cs[1] = tmp2;
  9308. break;
  9309. case 2:
  9310. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9311. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9312. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9313. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9314. cs[2] = cs[3]; cs[3] = ci + 1;
  9315. cs[0] = cs[1]; cs[1] = ci;
  9316. break;
  9317. case 3:
  9318. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9319. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9320. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9321. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9322. cs[2] = cs[0]; cs[3] = cs[1];
  9323. cs[0] = ci; cs[1] = ci + 1;
  9324. break;
  9325. }
  9326. // set p11, p12, p21, p22
  9327. ps[5] = coords.length;
  9328. coords.push([
  9329. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9330. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9331. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9332. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9333. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9334. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9335. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9336. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9337. ]);
  9338. ps[6] = coords.length;
  9339. coords.push([
  9340. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9341. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9342. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9343. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9344. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9345. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9346. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9347. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9348. ]);
  9349. ps[9] = coords.length;
  9350. coords.push([
  9351. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9352. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9353. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9354. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9355. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9356. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9357. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9358. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9359. ]);
  9360. ps[10] = coords.length;
  9361. coords.push([
  9362. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9363. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9364. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9365. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9366. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9367. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9368. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9369. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9370. ]);
  9371. mesh.figures.push({
  9372. type: 'patch',
  9373. coords: new Int32Array(ps), // making copies of ps and cs
  9374. colors: new Int32Array(cs)
  9375. });
  9376. }
  9377. }
  9378. function decodeType7Shading(mesh, reader) {
  9379. var coords = mesh.coords;
  9380. var colors = mesh.colors;
  9381. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9382. var cs = new Int32Array(4); // c00, c30, c03, c33
  9383. while (reader.hasData) {
  9384. var f = reader.readFlag();
  9385. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9386. var i, ii;
  9387. var pi = coords.length;
  9388. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9389. coords.push(reader.readCoordinate());
  9390. }
  9391. var ci = colors.length;
  9392. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9393. colors.push(reader.readComponents());
  9394. }
  9395. var tmp1, tmp2, tmp3, tmp4;
  9396. switch (f) {
  9397. case 0:
  9398. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9399. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9400. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9401. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9402. cs[2] = ci + 1; cs[3] = ci + 2;
  9403. cs[0] = ci; cs[1] = ci + 3;
  9404. break;
  9405. case 1:
  9406. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9407. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9408. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9409. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9410. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9411. tmp1 = cs[2]; tmp2 = cs[3];
  9412. cs[2] = ci + 1; cs[3] = ci;
  9413. cs[0] = tmp1; cs[1] = tmp2;
  9414. break;
  9415. case 2:
  9416. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9417. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9418. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9419. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9420. cs[2] = cs[3]; cs[3] = ci + 1;
  9421. cs[0] = cs[1]; cs[1] = ci;
  9422. break;
  9423. case 3:
  9424. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9425. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9426. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9427. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9428. cs[2] = cs[0]; cs[3] = cs[1];
  9429. cs[0] = ci; cs[1] = ci + 1;
  9430. break;
  9431. }
  9432. mesh.figures.push({
  9433. type: 'patch',
  9434. coords: new Int32Array(ps), // making copies of ps and cs
  9435. colors: new Int32Array(cs)
  9436. });
  9437. }
  9438. }
  9439. function updateBounds(mesh) {
  9440. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9441. maxX = minX, maxY = minY;
  9442. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9443. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9444. minX = minX > x ? x : minX;
  9445. minY = minY > y ? y : minY;
  9446. maxX = maxX < x ? x : maxX;
  9447. maxY = maxY < y ? y : maxY;
  9448. }
  9449. mesh.bounds = [minX, minY, maxX, maxY];
  9450. }
  9451. function packData(mesh) {
  9452. var i, ii, j, jj;
  9453. var coords = mesh.coords;
  9454. var coordsPacked = new Float32Array(coords.length * 2);
  9455. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9456. var xy = coords[i];
  9457. coordsPacked[j++] = xy[0];
  9458. coordsPacked[j++] = xy[1];
  9459. }
  9460. mesh.coords = coordsPacked;
  9461. var colors = mesh.colors;
  9462. var colorsPacked = new Uint8Array(colors.length * 3);
  9463. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9464. var c = colors[i];
  9465. colorsPacked[j++] = c[0];
  9466. colorsPacked[j++] = c[1];
  9467. colorsPacked[j++] = c[2];
  9468. }
  9469. mesh.colors = colorsPacked;
  9470. var figures = mesh.figures;
  9471. for (i = 0, ii = figures.length; i < ii; i++) {
  9472. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9473. for (j = 0, jj = ps.length; j < jj; j++) {
  9474. ps[j] *= 2;
  9475. cs[j] *= 3;
  9476. }
  9477. }
  9478. }
  9479. function Mesh(stream, matrix, xref, res) {
  9480. assert(isStream(stream), 'Mesh data is not a stream');
  9481. var dict = stream.dict;
  9482. this.matrix = matrix;
  9483. this.shadingType = dict.get('ShadingType');
  9484. this.type = 'Pattern';
  9485. this.bbox = dict.get('BBox');
  9486. var cs = dict.get('ColorSpace', 'CS');
  9487. cs = ColorSpace.parse(cs, xref, res);
  9488. this.cs = cs;
  9489. this.background = dict.has('Background') ?
  9490. cs.getRgb(dict.get('Background'), 0) : null;
  9491. var fnObj = dict.get('Function');
  9492. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9493. this.coords = [];
  9494. this.colors = [];
  9495. this.figures = [];
  9496. var decodeContext = {
  9497. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9498. bitsPerComponent: dict.get('BitsPerComponent'),
  9499. bitsPerFlag: dict.get('BitsPerFlag'),
  9500. decode: dict.get('Decode'),
  9501. colorFn: fn,
  9502. colorSpace: cs,
  9503. numComps: fn ? 1 : cs.numComps
  9504. };
  9505. var reader = new MeshStreamReader(stream, decodeContext);
  9506. var patchMesh = false;
  9507. switch (this.shadingType) {
  9508. case PatternType.FREE_FORM_MESH:
  9509. decodeType4Shading(this, reader);
  9510. break;
  9511. case PatternType.LATTICE_FORM_MESH:
  9512. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9513. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9514. decodeType5Shading(this, reader, verticesPerRow);
  9515. break;
  9516. case PatternType.COONS_PATCH_MESH:
  9517. decodeType6Shading(this, reader);
  9518. patchMesh = true;
  9519. break;
  9520. case PatternType.TENSOR_PATCH_MESH:
  9521. decodeType7Shading(this, reader);
  9522. patchMesh = true;
  9523. break;
  9524. default:
  9525. error('Unsupported mesh type.');
  9526. break;
  9527. }
  9528. if (patchMesh) {
  9529. // dirty bounds calculation for determining, how dense shall be triangles
  9530. updateBounds(this);
  9531. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9532. buildFigureFromPatch(this, i);
  9533. }
  9534. }
  9535. // calculate bounds
  9536. updateBounds(this);
  9537. packData(this);
  9538. }
  9539. Mesh.prototype = {
  9540. getIR: function Mesh_getIR() {
  9541. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9542. this.bounds, this.matrix, this.bbox, this.background];
  9543. }
  9544. };
  9545. return Mesh;
  9546. })();
  9547. Shadings.Dummy = (function DummyClosure() {
  9548. function Dummy() {
  9549. this.type = 'Pattern';
  9550. }
  9551. Dummy.prototype = {
  9552. getIR: function Dummy_getIR() {
  9553. return ['Dummy'];
  9554. }
  9555. };
  9556. return Dummy;
  9557. })();
  9558. function getTilingPatternIR(operatorList, dict, args) {
  9559. var matrix = dict.get('Matrix');
  9560. var bbox = dict.get('BBox');
  9561. var xstep = dict.get('XStep');
  9562. var ystep = dict.get('YStep');
  9563. var paintType = dict.get('PaintType');
  9564. var tilingType = dict.get('TilingType');
  9565. return [
  9566. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9567. paintType, tilingType
  9568. ];
  9569. }
  9570. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9571. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9572. uniquePrefix, idCounters, fontCache) {
  9573. this.pdfManager = pdfManager;
  9574. this.xref = xref;
  9575. this.handler = handler;
  9576. this.pageIndex = pageIndex;
  9577. this.uniquePrefix = uniquePrefix;
  9578. this.idCounters = idCounters;
  9579. this.fontCache = fontCache;
  9580. }
  9581. // Trying to minimize Date.now() usage and check every 100 time
  9582. var TIME_SLOT_DURATION_MS = 20;
  9583. var CHECK_TIME_EVERY = 100;
  9584. function TimeSlotManager() {
  9585. this.reset();
  9586. }
  9587. TimeSlotManager.prototype = {
  9588. check: function TimeSlotManager_check() {
  9589. if (++this.checked < CHECK_TIME_EVERY) {
  9590. return false;
  9591. }
  9592. this.checked = 0;
  9593. return this.endTime <= Date.now();
  9594. },
  9595. reset: function TimeSlotManager_reset() {
  9596. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9597. this.checked = 0;
  9598. }
  9599. };
  9600. var deferred = Promise.resolve();
  9601. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9602. PartialEvaluator.prototype = {
  9603. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9604. if (!isDict(resources)) {
  9605. return false;
  9606. }
  9607. var processed = Object.create(null);
  9608. if (resources.objId) {
  9609. processed[resources.objId] = true;
  9610. }
  9611. var nodes = [resources];
  9612. while (nodes.length) {
  9613. var key;
  9614. var node = nodes.shift();
  9615. // First check the current resources for blend modes.
  9616. var graphicStates = node.get('ExtGState');
  9617. if (isDict(graphicStates)) {
  9618. graphicStates = graphicStates.getAll();
  9619. for (key in graphicStates) {
  9620. var graphicState = graphicStates[key];
  9621. var bm = graphicState['BM'];
  9622. if (isName(bm) && bm.name !== 'Normal') {
  9623. return true;
  9624. }
  9625. }
  9626. }
  9627. // Descend into the XObjects to look for more resources and blend modes.
  9628. var xObjects = node.get('XObject');
  9629. if (!isDict(xObjects)) {
  9630. continue;
  9631. }
  9632. xObjects = xObjects.getAll();
  9633. for (key in xObjects) {
  9634. var xObject = xObjects[key];
  9635. if (!isStream(xObject)) {
  9636. continue;
  9637. }
  9638. if (xObject.dict.objId) {
  9639. if (processed[xObject.dict.objId]) {
  9640. // stream has objId and is processed already
  9641. continue;
  9642. }
  9643. processed[xObject.dict.objId] = true;
  9644. }
  9645. var xResources = xObject.dict.get('Resources');
  9646. // Checking objId to detect an infinite loop.
  9647. if (isDict(xResources) &&
  9648. (!xResources.objId || !processed[xResources.objId])) {
  9649. nodes.push(xResources);
  9650. if (xResources.objId) {
  9651. processed[xResources.objId] = true;
  9652. }
  9653. }
  9654. }
  9655. }
  9656. return false;
  9657. },
  9658. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9659. xobj, smask,
  9660. operatorList,
  9661. initialState) {
  9662. var matrix = xobj.dict.get('Matrix');
  9663. var bbox = xobj.dict.get('BBox');
  9664. var group = xobj.dict.get('Group');
  9665. if (group) {
  9666. var groupOptions = {
  9667. matrix: matrix,
  9668. bbox: bbox,
  9669. smask: smask,
  9670. isolated: false,
  9671. knockout: false
  9672. };
  9673. var groupSubtype = group.get('S');
  9674. var colorSpace;
  9675. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9676. groupOptions.isolated = (group.get('I') || false);
  9677. groupOptions.knockout = (group.get('K') || false);
  9678. colorSpace = (group.has('CS') ?
  9679. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9680. }
  9681. if (smask && smask.backdrop) {
  9682. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9683. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9684. }
  9685. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9686. }
  9687. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9688. return this.getOperatorList(xobj,
  9689. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9690. then(function () {
  9691. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9692. if (group) {
  9693. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9694. }
  9695. });
  9696. },
  9697. buildPaintImageXObject:
  9698. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9699. inline, operatorList,
  9700. cacheKey, imageCache) {
  9701. var self = this;
  9702. var dict = image.dict;
  9703. var w = dict.get('Width', 'W');
  9704. var h = dict.get('Height', 'H');
  9705. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9706. warn('Image dimensions are missing, or not numbers.');
  9707. return;
  9708. }
  9709. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9710. warn('Image exceeded maximum allowed size and was removed.');
  9711. return;
  9712. }
  9713. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9714. var imgData, args;
  9715. if (imageMask) {
  9716. // This depends on a tmpCanvas being filled with the
  9717. // current fillStyle, such that processing the pixel
  9718. // data can't be done here. Instead of creating a
  9719. // complete PDFImage, only read the information needed
  9720. // for later.
  9721. var width = dict.get('Width', 'W');
  9722. var height = dict.get('Height', 'H');
  9723. var bitStrideLength = (width + 7) >> 3;
  9724. var imgArray = image.getBytes(bitStrideLength * height);
  9725. var decode = dict.get('Decode', 'D');
  9726. var inverseDecode = (!!decode && decode[0] > 0);
  9727. imgData = PDFImage.createMask(imgArray, width, height,
  9728. image instanceof DecodeStream,
  9729. inverseDecode);
  9730. imgData.cached = true;
  9731. args = [imgData];
  9732. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9733. if (cacheKey) {
  9734. imageCache[cacheKey] = {
  9735. fn: OPS.paintImageMaskXObject,
  9736. args: args
  9737. };
  9738. }
  9739. return;
  9740. }
  9741. var softMask = (dict.get('SMask', 'SM') || false);
  9742. var mask = (dict.get('Mask') || false);
  9743. var SMALL_IMAGE_DIMENSIONS = 200;
  9744. // Inlining small images into the queue as RGB data
  9745. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9746. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9747. var imageObj = new PDFImage(this.xref, resources, image,
  9748. inline, null, null);
  9749. // We force the use of RGBA_32BPP images here, because we can't handle
  9750. // any other kind.
  9751. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9752. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9753. return;
  9754. }
  9755. // If there is no imageMask, create the PDFImage and a lot
  9756. // of image processing can be done here.
  9757. var uniquePrefix = (this.uniquePrefix || '');
  9758. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9759. operatorList.addDependency(objId);
  9760. args = [objId, w, h];
  9761. if (!softMask && !mask && image instanceof JpegStream &&
  9762. image.isNativelySupported(this.xref, resources)) {
  9763. // These JPEGs don't need any more processing so we can just send it.
  9764. operatorList.addOp(OPS.paintJpegXObject, args);
  9765. this.handler.send('obj',
  9766. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9767. return;
  9768. }
  9769. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9770. then(function(imageObj) {
  9771. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9772. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9773. [imgData.data.buffer]);
  9774. }).then(undefined, function (reason) {
  9775. warn('Unable to decode image: ' + reason);
  9776. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9777. });
  9778. operatorList.addOp(OPS.paintImageXObject, args);
  9779. if (cacheKey) {
  9780. imageCache[cacheKey] = {
  9781. fn: OPS.paintImageXObject,
  9782. args: args
  9783. };
  9784. }
  9785. },
  9786. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9787. operatorList,
  9788. stateManager) {
  9789. var smaskContent = smask.get('G');
  9790. var smaskOptions = {
  9791. subtype: smask.get('S').name,
  9792. backdrop: smask.get('BC')
  9793. };
  9794. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9795. operatorList, stateManager.state.clone());
  9796. },
  9797. handleTilingType:
  9798. function PartialEvaluator_handleTilingType(fn, args, resources,
  9799. pattern, patternDict,
  9800. operatorList) {
  9801. // Create an IR of the pattern code.
  9802. var tilingOpList = new OperatorList();
  9803. return this.getOperatorList(pattern,
  9804. (patternDict.get('Resources') || resources), tilingOpList).
  9805. then(function () {
  9806. // Add the dependencies to the parent operator list so they are
  9807. // resolved before sub operator list is executed synchronously.
  9808. operatorList.addDependencies(tilingOpList.dependencies);
  9809. operatorList.addOp(fn, getTilingPatternIR({
  9810. fnArray: tilingOpList.fnArray,
  9811. argsArray: tilingOpList.argsArray
  9812. }, patternDict, args));
  9813. });
  9814. },
  9815. handleSetFont:
  9816. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9817. operatorList, state) {
  9818. // TODO(mack): Not needed?
  9819. var fontName;
  9820. if (fontArgs) {
  9821. fontArgs = fontArgs.slice();
  9822. fontName = fontArgs[0].name;
  9823. }
  9824. var self = this;
  9825. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9826. function (translated) {
  9827. if (!translated.font.isType3Font) {
  9828. return translated;
  9829. }
  9830. return translated.loadType3Data(self, resources, operatorList).then(
  9831. function () {
  9832. return translated;
  9833. });
  9834. }).then(function (translated) {
  9835. state.font = translated.font;
  9836. translated.send(self.handler);
  9837. return translated.loadedName;
  9838. });
  9839. },
  9840. handleText: function PartialEvaluator_handleText(chars, state) {
  9841. var font = state.font;
  9842. var glyphs = font.charsToGlyphs(chars);
  9843. var isAddToPathSet = !!(state.textRenderingMode &
  9844. TextRenderingMode.ADD_TO_PATH_FLAG);
  9845. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9846. var buildPath = function (fontChar) {
  9847. if (!font.renderer.hasBuiltPath(fontChar)) {
  9848. var path = font.renderer.getPathJs(fontChar);
  9849. this.handler.send('commonobj', [
  9850. font.loadedName + '_path_' + fontChar,
  9851. 'FontPath',
  9852. path
  9853. ]);
  9854. }
  9855. }.bind(this);
  9856. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9857. var glyph = glyphs[i];
  9858. if (glyph === null) {
  9859. continue;
  9860. }
  9861. buildPath(glyph.fontChar);
  9862. // If the glyph has an accent we need to build a path for its
  9863. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9864. var accent = glyph.accent;
  9865. if (accent && accent.fontChar) {
  9866. buildPath(accent.fontChar);
  9867. }
  9868. }
  9869. }
  9870. return glyphs;
  9871. },
  9872. setGState: function PartialEvaluator_setGState(resources, gState,
  9873. operatorList, xref,
  9874. stateManager) {
  9875. // This array holds the converted/processed state data.
  9876. var gStateObj = [];
  9877. var gStateMap = gState.map;
  9878. var self = this;
  9879. var promise = Promise.resolve();
  9880. for (var key in gStateMap) {
  9881. var value = gStateMap[key];
  9882. switch (key) {
  9883. case 'Type':
  9884. break;
  9885. case 'LW':
  9886. case 'LC':
  9887. case 'LJ':
  9888. case 'ML':
  9889. case 'D':
  9890. case 'RI':
  9891. case 'FL':
  9892. case 'CA':
  9893. case 'ca':
  9894. gStateObj.push([key, value]);
  9895. break;
  9896. case 'Font':
  9897. promise = promise.then(function () {
  9898. return self.handleSetFont(resources, null, value[0],
  9899. operatorList, stateManager.state).
  9900. then(function (loadedName) {
  9901. operatorList.addDependency(loadedName);
  9902. gStateObj.push([key, [loadedName, value[1]]]);
  9903. });
  9904. });
  9905. break;
  9906. case 'BM':
  9907. gStateObj.push([key, value]);
  9908. break;
  9909. case 'SMask':
  9910. if (isName(value) && value.name === 'None') {
  9911. gStateObj.push([key, false]);
  9912. break;
  9913. }
  9914. var dict = xref.fetchIfRef(value);
  9915. if (isDict(dict)) {
  9916. promise = promise.then(function () {
  9917. return self.handleSMask(dict, resources, operatorList,
  9918. stateManager);
  9919. });
  9920. gStateObj.push([key, true]);
  9921. } else {
  9922. warn('Unsupported SMask type');
  9923. }
  9924. break;
  9925. // Only generate info log messages for the following since
  9926. // they are unlikely to have a big impact on the rendering.
  9927. case 'OP':
  9928. case 'op':
  9929. case 'OPM':
  9930. case 'BG':
  9931. case 'BG2':
  9932. case 'UCR':
  9933. case 'UCR2':
  9934. case 'TR':
  9935. case 'TR2':
  9936. case 'HT':
  9937. case 'SM':
  9938. case 'SA':
  9939. case 'AIS':
  9940. case 'TK':
  9941. // TODO implement these operators.
  9942. info('graphic state operator ' + key);
  9943. break;
  9944. default:
  9945. info('Unknown graphic state operator ' + key);
  9946. break;
  9947. }
  9948. }
  9949. return promise.then(function () {
  9950. if (gStateObj.length >= 0) {
  9951. operatorList.addOp(OPS.setGState, [gStateObj]);
  9952. }
  9953. });
  9954. },
  9955. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9956. resources) {
  9957. function errorFont() {
  9958. return Promise.resolve(new TranslatedFont('g_font_error',
  9959. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9960. }
  9961. var fontRef;
  9962. if (font) { // Loading by ref.
  9963. assert(isRef(font));
  9964. fontRef = font;
  9965. } else { // Loading by name.
  9966. var fontRes = resources.get('Font');
  9967. if (fontRes) {
  9968. fontRef = fontRes.getRaw(fontName);
  9969. } else {
  9970. warn('fontRes not available');
  9971. return errorFont();
  9972. }
  9973. }
  9974. if (!fontRef) {
  9975. warn('fontRef not available');
  9976. return errorFont();
  9977. }
  9978. if (this.fontCache.has(fontRef)) {
  9979. return this.fontCache.get(fontRef);
  9980. }
  9981. font = xref.fetchIfRef(fontRef);
  9982. if (!isDict(font)) {
  9983. return errorFont();
  9984. }
  9985. // We are holding font.translated references just for fontRef that are not
  9986. // dictionaries (Dict). See explanation below.
  9987. if (font.translated) {
  9988. return font.translated;
  9989. }
  9990. var fontCapability = createPromiseCapability();
  9991. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9992. var descriptor = preEvaluatedFont.descriptor;
  9993. var fontID = fontRef.num + '_' + fontRef.gen;
  9994. if (isDict(descriptor)) {
  9995. if (!descriptor.fontAliases) {
  9996. descriptor.fontAliases = Object.create(null);
  9997. }
  9998. var fontAliases = descriptor.fontAliases;
  9999. var hash = preEvaluatedFont.hash;
  10000. if (fontAliases[hash]) {
  10001. var aliasFontRef = fontAliases[hash].aliasRef;
  10002. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10003. this.fontCache.putAlias(fontRef, aliasFontRef);
  10004. return this.fontCache.get(fontRef);
  10005. }
  10006. }
  10007. if (!fontAliases[hash]) {
  10008. fontAliases[hash] = {
  10009. fontID: Font.getFontID()
  10010. };
  10011. }
  10012. fontAliases[hash].aliasRef = fontRef;
  10013. fontID = fontAliases[hash].fontID;
  10014. }
  10015. // Workaround for bad PDF generators that don't reference fonts
  10016. // properly, i.e. by not using an object identifier.
  10017. // Check if the fontRef is a Dict (as opposed to a standard object),
  10018. // in which case we don't cache the font and instead reference it by
  10019. // fontName in font.loadedName below.
  10020. var fontRefIsDict = isDict(fontRef);
  10021. if (!fontRefIsDict) {
  10022. this.fontCache.put(fontRef, fontCapability.promise);
  10023. }
  10024. // Keep track of each font we translated so the caller can
  10025. // load them asynchronously before calling display on a page.
  10026. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10027. fontName.replace(/\W/g, '') : fontID);
  10028. font.translated = fontCapability.promise;
  10029. // TODO move promises into translate font
  10030. var translatedPromise;
  10031. try {
  10032. translatedPromise = Promise.resolve(
  10033. this.translateFont(preEvaluatedFont, xref));
  10034. } catch (e) {
  10035. translatedPromise = Promise.reject(e);
  10036. }
  10037. translatedPromise.then(function (translatedFont) {
  10038. if (translatedFont.fontType !== undefined) {
  10039. var xrefFontStats = xref.stats.fontTypes;
  10040. xrefFontStats[translatedFont.fontType] = true;
  10041. }
  10042. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10043. translatedFont, font));
  10044. }, function (reason) {
  10045. // TODO fontCapability.reject?
  10046. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10047. try {
  10048. // error, but it's still nice to have font type reported
  10049. var descriptor = preEvaluatedFont.descriptor;
  10050. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10051. var subtype = fontFile3 && fontFile3.get('Subtype');
  10052. var fontType = getFontType(preEvaluatedFont.type,
  10053. subtype && subtype.name);
  10054. var xrefFontStats = xref.stats.fontTypes;
  10055. xrefFontStats[fontType] = true;
  10056. } catch (ex) { }
  10057. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10058. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10059. font));
  10060. });
  10061. return fontCapability.promise;
  10062. },
  10063. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10064. var lastIndex = operatorList.length - 1;
  10065. if (!args) {
  10066. args = [];
  10067. }
  10068. if (lastIndex < 0 ||
  10069. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10070. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10071. } else {
  10072. var opArgs = operatorList.argsArray[lastIndex];
  10073. opArgs[0].push(fn);
  10074. Array.prototype.push.apply(opArgs[1], args);
  10075. }
  10076. },
  10077. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10078. cs, patterns, resources, xref) {
  10079. // compile tiling patterns
  10080. var patternName = args[args.length - 1];
  10081. // SCN/scn applies patterns along with normal colors
  10082. var pattern;
  10083. if (isName(patternName) &&
  10084. (pattern = patterns.get(patternName.name))) {
  10085. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10086. var typeNum = dict.get('PatternType');
  10087. if (typeNum === TILING_PATTERN) {
  10088. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10089. return this.handleTilingType(fn, color, resources, pattern,
  10090. dict, operatorList);
  10091. } else if (typeNum === SHADING_PATTERN) {
  10092. var shading = dict.get('Shading');
  10093. var matrix = dict.get('Matrix');
  10094. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10095. operatorList.addOp(fn, pattern.getIR());
  10096. return Promise.resolve();
  10097. } else {
  10098. return Promise.reject('Unknown PatternType: ' + typeNum);
  10099. }
  10100. }
  10101. // TODO shall we fail here?
  10102. operatorList.addOp(fn, args);
  10103. return Promise.resolve();
  10104. },
  10105. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10106. resources,
  10107. operatorList,
  10108. initialState) {
  10109. var self = this;
  10110. var xref = this.xref;
  10111. var imageCache = {};
  10112. assert(operatorList);
  10113. resources = (resources || Dict.empty);
  10114. var xobjs = (resources.get('XObject') || Dict.empty);
  10115. var patterns = (resources.get('Pattern') || Dict.empty);
  10116. var stateManager = new StateManager(initialState || new EvalState());
  10117. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10118. var timeSlotManager = new TimeSlotManager();
  10119. return new Promise(function next(resolve, reject) {
  10120. timeSlotManager.reset();
  10121. var stop, operation = {}, i, ii, cs;
  10122. while (!(stop = timeSlotManager.check())) {
  10123. // The arguments parsed by read() are used beyond this loop, so we
  10124. // cannot reuse the same array on each iteration. Therefore we pass
  10125. // in |null| as the initial value (see the comment on
  10126. // EvaluatorPreprocessor_read() for why).
  10127. operation.args = null;
  10128. if (!(preprocessor.read(operation))) {
  10129. break;
  10130. }
  10131. var args = operation.args;
  10132. var fn = operation.fn;
  10133. switch (fn | 0) {
  10134. case OPS.paintXObject:
  10135. if (args[0].code) {
  10136. break;
  10137. }
  10138. // eagerly compile XForm objects
  10139. var name = args[0].name;
  10140. if (imageCache[name] !== undefined) {
  10141. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10142. args = null;
  10143. continue;
  10144. }
  10145. var xobj = xobjs.get(name);
  10146. if (xobj) {
  10147. assert(isStream(xobj), 'XObject should be a stream');
  10148. var type = xobj.dict.get('Subtype');
  10149. assert(isName(type),
  10150. 'XObject should have a Name subtype');
  10151. if (type.name === 'Form') {
  10152. stateManager.save();
  10153. return self.buildFormXObject(resources, xobj, null,
  10154. operatorList,
  10155. stateManager.state.clone()).
  10156. then(function () {
  10157. stateManager.restore();
  10158. next(resolve, reject);
  10159. }, reject);
  10160. } else if (type.name === 'Image') {
  10161. self.buildPaintImageXObject(resources, xobj, false,
  10162. operatorList, name, imageCache);
  10163. args = null;
  10164. continue;
  10165. } else if (type.name === 'PS') {
  10166. // PostScript XObjects are unused when viewing documents.
  10167. // See section 4.7.1 of Adobe's PDF reference.
  10168. info('Ignored XObject subtype PS');
  10169. continue;
  10170. } else {
  10171. error('Unhandled XObject subtype ' + type.name);
  10172. }
  10173. }
  10174. break;
  10175. case OPS.setFont:
  10176. var fontSize = args[1];
  10177. // eagerly collect all fonts
  10178. return self.handleSetFont(resources, args, null,
  10179. operatorList, stateManager.state).
  10180. then(function (loadedName) {
  10181. operatorList.addDependency(loadedName);
  10182. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10183. next(resolve, reject);
  10184. }, reject);
  10185. case OPS.endInlineImage:
  10186. var cacheKey = args[0].cacheKey;
  10187. if (cacheKey) {
  10188. var cacheEntry = imageCache[cacheKey];
  10189. if (cacheEntry !== undefined) {
  10190. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10191. args = null;
  10192. continue;
  10193. }
  10194. }
  10195. self.buildPaintImageXObject(resources, args[0], true,
  10196. operatorList, cacheKey, imageCache);
  10197. args = null;
  10198. continue;
  10199. case OPS.showText:
  10200. args[0] = self.handleText(args[0], stateManager.state);
  10201. break;
  10202. case OPS.showSpacedText:
  10203. var arr = args[0];
  10204. var combinedGlyphs = [];
  10205. var arrLength = arr.length;
  10206. for (i = 0; i < arrLength; ++i) {
  10207. var arrItem = arr[i];
  10208. if (isString(arrItem)) {
  10209. Array.prototype.push.apply(combinedGlyphs,
  10210. self.handleText(arrItem, stateManager.state));
  10211. } else if (isNum(arrItem)) {
  10212. combinedGlyphs.push(arrItem);
  10213. }
  10214. }
  10215. args[0] = combinedGlyphs;
  10216. fn = OPS.showText;
  10217. break;
  10218. case OPS.nextLineShowText:
  10219. operatorList.addOp(OPS.nextLine);
  10220. args[0] = self.handleText(args[0], stateManager.state);
  10221. fn = OPS.showText;
  10222. break;
  10223. case OPS.nextLineSetSpacingShowText:
  10224. operatorList.addOp(OPS.nextLine);
  10225. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10226. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10227. args[0] = self.handleText(args[0], stateManager.state);
  10228. fn = OPS.showText;
  10229. break;
  10230. case OPS.setTextRenderingMode:
  10231. stateManager.state.textRenderingMode = args[0];
  10232. break;
  10233. case OPS.setFillColorSpace:
  10234. stateManager.state.fillColorSpace =
  10235. ColorSpace.parse(args[0], xref, resources);
  10236. continue;
  10237. case OPS.setStrokeColorSpace:
  10238. stateManager.state.strokeColorSpace =
  10239. ColorSpace.parse(args[0], xref, resources);
  10240. continue;
  10241. case OPS.setFillColor:
  10242. cs = stateManager.state.fillColorSpace;
  10243. args = cs.getRgb(args, 0);
  10244. fn = OPS.setFillRGBColor;
  10245. break;
  10246. case OPS.setStrokeColor:
  10247. cs = stateManager.state.strokeColorSpace;
  10248. args = cs.getRgb(args, 0);
  10249. fn = OPS.setStrokeRGBColor;
  10250. break;
  10251. case OPS.setFillGray:
  10252. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10253. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10254. fn = OPS.setFillRGBColor;
  10255. break;
  10256. case OPS.setStrokeGray:
  10257. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10258. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10259. fn = OPS.setStrokeRGBColor;
  10260. break;
  10261. case OPS.setFillCMYKColor:
  10262. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10263. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10264. fn = OPS.setFillRGBColor;
  10265. break;
  10266. case OPS.setStrokeCMYKColor:
  10267. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10268. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10269. fn = OPS.setStrokeRGBColor;
  10270. break;
  10271. case OPS.setFillRGBColor:
  10272. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10273. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10274. break;
  10275. case OPS.setStrokeRGBColor:
  10276. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10277. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10278. break;
  10279. case OPS.setFillColorN:
  10280. cs = stateManager.state.fillColorSpace;
  10281. if (cs.name === 'Pattern') {
  10282. return self.handleColorN(operatorList, OPS.setFillColorN,
  10283. args, cs, patterns, resources, xref).then(function() {
  10284. next(resolve, reject);
  10285. }, reject);
  10286. }
  10287. args = cs.getRgb(args, 0);
  10288. fn = OPS.setFillRGBColor;
  10289. break;
  10290. case OPS.setStrokeColorN:
  10291. cs = stateManager.state.strokeColorSpace;
  10292. if (cs.name === 'Pattern') {
  10293. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10294. args, cs, patterns, resources, xref).then(function() {
  10295. next(resolve, reject);
  10296. }, reject);
  10297. }
  10298. args = cs.getRgb(args, 0);
  10299. fn = OPS.setStrokeRGBColor;
  10300. break;
  10301. case OPS.shadingFill:
  10302. var shadingRes = resources.get('Shading');
  10303. if (!shadingRes) {
  10304. error('No shading resource found');
  10305. }
  10306. var shading = shadingRes.get(args[0].name);
  10307. if (!shading) {
  10308. error('No shading object found');
  10309. }
  10310. var shadingFill = Pattern.parseShading(shading, null, xref,
  10311. resources);
  10312. var patternIR = shadingFill.getIR();
  10313. args = [patternIR];
  10314. fn = OPS.shadingFill;
  10315. break;
  10316. case OPS.setGState:
  10317. var dictName = args[0];
  10318. var extGState = resources.get('ExtGState');
  10319. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10320. break;
  10321. }
  10322. var gState = extGState.get(dictName.name);
  10323. return self.setGState(resources, gState, operatorList, xref,
  10324. stateManager).then(function() {
  10325. next(resolve, reject);
  10326. }, reject);
  10327. case OPS.moveTo:
  10328. case OPS.lineTo:
  10329. case OPS.curveTo:
  10330. case OPS.curveTo2:
  10331. case OPS.curveTo3:
  10332. case OPS.closePath:
  10333. self.buildPath(operatorList, fn, args);
  10334. continue;
  10335. case OPS.rectangle:
  10336. self.buildPath(operatorList, fn, args);
  10337. continue;
  10338. }
  10339. operatorList.addOp(fn, args);
  10340. }
  10341. if (stop) {
  10342. deferred.then(function () {
  10343. next(resolve, reject);
  10344. });
  10345. return;
  10346. }
  10347. // Some PDFs don't close all restores inside object/form.
  10348. // Closing those for them.
  10349. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10350. operatorList.addOp(OPS.restore, []);
  10351. }
  10352. resolve();
  10353. });
  10354. },
  10355. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10356. stateManager) {
  10357. stateManager = (stateManager || new StateManager(new TextState()));
  10358. var textContent = {
  10359. items: [],
  10360. styles: Object.create(null)
  10361. };
  10362. var bidiTexts = textContent.items;
  10363. var SPACE_FACTOR = 0.3;
  10364. var MULTI_SPACE_FACTOR = 1.5;
  10365. var self = this;
  10366. var xref = this.xref;
  10367. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10368. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10369. var xobjs = null;
  10370. var xobjsCache = {};
  10371. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10372. var textState;
  10373. function newTextChunk() {
  10374. var font = textState.font;
  10375. if (!(font.loadedName in textContent.styles)) {
  10376. textContent.styles[font.loadedName] = {
  10377. fontFamily: font.fallbackName,
  10378. ascent: font.ascent,
  10379. descent: font.descent,
  10380. vertical: font.vertical
  10381. };
  10382. }
  10383. return {
  10384. // |str| is initially an array which we push individual chars to, and
  10385. // then runBidi() overwrites it with the final string.
  10386. str: [],
  10387. dir: null,
  10388. width: 0,
  10389. height: 0,
  10390. transform: null,
  10391. fontName: font.loadedName
  10392. };
  10393. }
  10394. function runBidi(textChunk) {
  10395. var str = textChunk.str.join('');
  10396. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10397. textChunk.str = bidiResult.str;
  10398. textChunk.dir = bidiResult.dir;
  10399. return textChunk;
  10400. }
  10401. function handleSetFont(fontName, fontRef) {
  10402. return self.loadFont(fontName, fontRef, xref, resources).
  10403. then(function (translated) {
  10404. textState.font = translated.font;
  10405. textState.fontMatrix = translated.font.fontMatrix ||
  10406. FONT_IDENTITY_MATRIX;
  10407. });
  10408. }
  10409. function buildTextGeometry(chars, textChunk) {
  10410. var font = textState.font;
  10411. textChunk = textChunk || newTextChunk();
  10412. if (!textChunk.transform) {
  10413. // 9.4.4 Text Space Details
  10414. var tsm = [textState.fontSize * textState.textHScale, 0,
  10415. 0, textState.fontSize,
  10416. 0, textState.textRise];
  10417. if (font.isType3Font &&
  10418. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10419. textState.fontSize === 1) {
  10420. var glyphHeight = font.bbox[3] - font.bbox[1];
  10421. if (glyphHeight > 0) {
  10422. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10423. tsm[3] *= glyphHeight;
  10424. }
  10425. }
  10426. var trm = textChunk.transform = Util.transform(textState.ctm,
  10427. Util.transform(textState.textMatrix, tsm));
  10428. if (!font.vertical) {
  10429. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10430. } else {
  10431. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10432. }
  10433. }
  10434. var width = 0;
  10435. var height = 0;
  10436. var glyphs = font.charsToGlyphs(chars);
  10437. var defaultVMetrics = font.defaultVMetrics;
  10438. for (var i = 0; i < glyphs.length; i++) {
  10439. var glyph = glyphs[i];
  10440. if (!glyph) { // Previous glyph was a space.
  10441. width += textState.wordSpacing * textState.textHScale;
  10442. continue;
  10443. }
  10444. var vMetricX = null;
  10445. var vMetricY = null;
  10446. var glyphWidth = null;
  10447. if (font.vertical) {
  10448. if (glyph.vmetric) {
  10449. glyphWidth = glyph.vmetric[0];
  10450. vMetricX = glyph.vmetric[1];
  10451. vMetricY = glyph.vmetric[2];
  10452. } else {
  10453. glyphWidth = glyph.width;
  10454. vMetricX = glyph.width * 0.5;
  10455. vMetricY = defaultVMetrics[2];
  10456. }
  10457. } else {
  10458. glyphWidth = glyph.width;
  10459. }
  10460. var glyphUnicode = glyph.unicode;
  10461. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10462. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10463. }
  10464. glyphUnicode = reverseIfRtl(glyphUnicode);
  10465. // The following will calculate the x and y of the individual glyphs.
  10466. // if (font.vertical) {
  10467. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10468. // textState.fontMatrix[0];
  10469. // tsm[5] -= vMetricY * textState.fontSize *
  10470. // textState.fontMatrix[0];
  10471. // }
  10472. // var trm = Util.transform(textState.textMatrix, tsm);
  10473. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10474. // var x = pt[0];
  10475. // var y = pt[1];
  10476. var tx = 0;
  10477. var ty = 0;
  10478. if (!font.vertical) {
  10479. var w0 = glyphWidth * textState.fontMatrix[0];
  10480. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10481. textState.textHScale;
  10482. width += tx;
  10483. } else {
  10484. var w1 = glyphWidth * textState.fontMatrix[0];
  10485. ty = w1 * textState.fontSize + textState.charSpacing;
  10486. height += ty;
  10487. }
  10488. textState.translateTextMatrix(tx, ty);
  10489. textChunk.str.push(glyphUnicode);
  10490. }
  10491. var a = textState.textLineMatrix[0];
  10492. var b = textState.textLineMatrix[1];
  10493. var scaleLineX = Math.sqrt(a * a + b * b);
  10494. a = textState.ctm[0];
  10495. b = textState.ctm[1];
  10496. var scaleCtmX = Math.sqrt(a * a + b * b);
  10497. if (!font.vertical) {
  10498. textChunk.width += width * scaleCtmX * scaleLineX;
  10499. } else {
  10500. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10501. }
  10502. return textChunk;
  10503. }
  10504. var timeSlotManager = new TimeSlotManager();
  10505. return new Promise(function next(resolve, reject) {
  10506. timeSlotManager.reset();
  10507. var stop, operation = {}, args = [];
  10508. while (!(stop = timeSlotManager.check())) {
  10509. // The arguments parsed by read() are not used beyond this loop, so
  10510. // we can reuse the same array on every iteration, thus avoiding
  10511. // unnecessary allocations.
  10512. args.length = 0;
  10513. operation.args = args;
  10514. if (!(preprocessor.read(operation))) {
  10515. break;
  10516. }
  10517. textState = stateManager.state;
  10518. var fn = operation.fn;
  10519. args = operation.args;
  10520. switch (fn | 0) {
  10521. case OPS.setFont:
  10522. textState.fontSize = args[1];
  10523. return handleSetFont(args[0].name).then(function() {
  10524. next(resolve, reject);
  10525. }, reject);
  10526. case OPS.setTextRise:
  10527. textState.textRise = args[0];
  10528. break;
  10529. case OPS.setHScale:
  10530. textState.textHScale = args[0] / 100;
  10531. break;
  10532. case OPS.setLeading:
  10533. textState.leading = args[0];
  10534. break;
  10535. case OPS.moveText:
  10536. textState.translateTextLineMatrix(args[0], args[1]);
  10537. textState.textMatrix = textState.textLineMatrix.slice();
  10538. break;
  10539. case OPS.setLeadingMoveText:
  10540. textState.leading = -args[1];
  10541. textState.translateTextLineMatrix(args[0], args[1]);
  10542. textState.textMatrix = textState.textLineMatrix.slice();
  10543. break;
  10544. case OPS.nextLine:
  10545. textState.carriageReturn();
  10546. break;
  10547. case OPS.setTextMatrix:
  10548. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10549. args[4], args[5]);
  10550. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10551. args[4], args[5]);
  10552. break;
  10553. case OPS.setCharSpacing:
  10554. textState.charSpacing = args[0];
  10555. break;
  10556. case OPS.setWordSpacing:
  10557. textState.wordSpacing = args[0];
  10558. break;
  10559. case OPS.beginText:
  10560. textState.textMatrix = IDENTITY_MATRIX.slice();
  10561. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10562. break;
  10563. case OPS.showSpacedText:
  10564. var items = args[0];
  10565. var textChunk = newTextChunk();
  10566. var offset;
  10567. for (var j = 0, jj = items.length; j < jj; j++) {
  10568. if (typeof items[j] === 'string') {
  10569. buildTextGeometry(items[j], textChunk);
  10570. } else {
  10571. var val = items[j] / 1000;
  10572. if (!textState.font.vertical) {
  10573. offset = -val * textState.fontSize * textState.textHScale *
  10574. textState.textMatrix[0];
  10575. textState.translateTextMatrix(offset, 0);
  10576. textChunk.width += offset;
  10577. } else {
  10578. offset = -val * textState.fontSize *
  10579. textState.textMatrix[3];
  10580. textState.translateTextMatrix(0, offset);
  10581. textChunk.height += offset;
  10582. }
  10583. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10584. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10585. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10586. fakeSpaces = Math.round(fakeSpaces);
  10587. while (fakeSpaces--) {
  10588. textChunk.str.push(' ');
  10589. }
  10590. } else if (fakeSpaces > SPACE_FACTOR) {
  10591. textChunk.str.push(' ');
  10592. }
  10593. }
  10594. }
  10595. }
  10596. bidiTexts.push(runBidi(textChunk));
  10597. break;
  10598. case OPS.showText:
  10599. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10600. break;
  10601. case OPS.nextLineShowText:
  10602. textState.carriageReturn();
  10603. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10604. break;
  10605. case OPS.nextLineSetSpacingShowText:
  10606. textState.wordSpacing = args[0];
  10607. textState.charSpacing = args[1];
  10608. textState.carriageReturn();
  10609. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10610. break;
  10611. case OPS.paintXObject:
  10612. if (args[0].code) {
  10613. break;
  10614. }
  10615. if (!xobjs) {
  10616. xobjs = (resources.get('XObject') || Dict.empty);
  10617. }
  10618. var name = args[0].name;
  10619. if (xobjsCache.key === name) {
  10620. if (xobjsCache.texts) {
  10621. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10622. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10623. }
  10624. break;
  10625. }
  10626. var xobj = xobjs.get(name);
  10627. if (!xobj) {
  10628. break;
  10629. }
  10630. assert(isStream(xobj), 'XObject should be a stream');
  10631. var type = xobj.dict.get('Subtype');
  10632. assert(isName(type),
  10633. 'XObject should have a Name subtype');
  10634. if ('Form' !== type.name) {
  10635. xobjsCache.key = name;
  10636. xobjsCache.texts = null;
  10637. break;
  10638. }
  10639. stateManager.save();
  10640. var matrix = xobj.dict.get('Matrix');
  10641. if (isArray(matrix) && matrix.length === 6) {
  10642. stateManager.transform(matrix);
  10643. }
  10644. return self.getTextContent(xobj,
  10645. xobj.dict.get('Resources') || resources, stateManager).
  10646. then(function (formTextContent) {
  10647. Util.appendToArray(bidiTexts, formTextContent.items);
  10648. Util.extendObj(textContent.styles, formTextContent.styles);
  10649. stateManager.restore();
  10650. xobjsCache.key = name;
  10651. xobjsCache.texts = formTextContent;
  10652. next(resolve, reject);
  10653. }, reject);
  10654. case OPS.setGState:
  10655. var dictName = args[0];
  10656. var extGState = resources.get('ExtGState');
  10657. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10658. break;
  10659. }
  10660. var gsStateMap = extGState.get(dictName.name);
  10661. var gsStateFont = null;
  10662. for (var key in gsStateMap) {
  10663. if (key === 'Font') {
  10664. assert(!gsStateFont);
  10665. gsStateFont = gsStateMap[key];
  10666. }
  10667. }
  10668. if (gsStateFont) {
  10669. textState.fontSize = gsStateFont[1];
  10670. return handleSetFont(gsStateFont[0]).then(function() {
  10671. next(resolve, reject);
  10672. }, reject);
  10673. }
  10674. break;
  10675. } // switch
  10676. } // while
  10677. if (stop) {
  10678. deferred.then(function () {
  10679. next(resolve, reject);
  10680. });
  10681. return;
  10682. }
  10683. resolve(textContent);
  10684. });
  10685. },
  10686. extractDataStructures: function
  10687. partialEvaluatorExtractDataStructures(dict, baseDict,
  10688. xref, properties) {
  10689. // 9.10.2
  10690. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10691. if (toUnicode) {
  10692. properties.toUnicode = this.readToUnicode(toUnicode);
  10693. }
  10694. if (properties.composite) {
  10695. // CIDSystemInfo helps to match CID to glyphs
  10696. var cidSystemInfo = dict.get('CIDSystemInfo');
  10697. if (isDict(cidSystemInfo)) {
  10698. properties.cidSystemInfo = {
  10699. registry: cidSystemInfo.get('Registry'),
  10700. ordering: cidSystemInfo.get('Ordering'),
  10701. supplement: cidSystemInfo.get('Supplement')
  10702. };
  10703. }
  10704. var cidToGidMap = dict.get('CIDToGIDMap');
  10705. if (isStream(cidToGidMap)) {
  10706. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10707. }
  10708. }
  10709. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10710. // and depends on the font type. The base encoding and differences are
  10711. // read here, but the encoding that is actually used is chosen during
  10712. // glyph mapping in the font.
  10713. // TODO: Loading the built in encoding in the font would allow the
  10714. // differences to be merged in here not require us to hold on to it.
  10715. var differences = [];
  10716. var baseEncodingName = null;
  10717. var encoding;
  10718. if (dict.has('Encoding')) {
  10719. encoding = dict.get('Encoding');
  10720. if (isDict(encoding)) {
  10721. baseEncodingName = encoding.get('BaseEncoding');
  10722. baseEncodingName = (isName(baseEncodingName) ?
  10723. baseEncodingName.name : null);
  10724. // Load the differences between the base and original
  10725. if (encoding.has('Differences')) {
  10726. var diffEncoding = encoding.get('Differences');
  10727. var index = 0;
  10728. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10729. var data = diffEncoding[j];
  10730. if (isNum(data)) {
  10731. index = data;
  10732. } else if (isName(data)) {
  10733. differences[index++] = data.name;
  10734. } else if (isRef(data)) {
  10735. diffEncoding[j--] = xref.fetch(data);
  10736. continue;
  10737. } else {
  10738. error('Invalid entry in \'Differences\' array: ' + data);
  10739. }
  10740. }
  10741. }
  10742. } else if (isName(encoding)) {
  10743. baseEncodingName = encoding.name;
  10744. } else {
  10745. error('Encoding is not a Name nor a Dict');
  10746. }
  10747. // According to table 114 if the encoding is a named encoding it must be
  10748. // one of these predefined encodings.
  10749. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10750. baseEncodingName !== 'MacExpertEncoding' &&
  10751. baseEncodingName !== 'WinAnsiEncoding')) {
  10752. baseEncodingName = null;
  10753. }
  10754. }
  10755. if (baseEncodingName) {
  10756. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10757. } else {
  10758. encoding = (properties.type === 'TrueType' ?
  10759. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10760. // The Symbolic attribute can be misused for regular fonts
  10761. // Heuristic: we have to check if the font is a standard one also
  10762. if (!!(properties.flags & FontFlags.Symbolic)) {
  10763. encoding = Encodings.MacRomanEncoding;
  10764. if (!properties.file) {
  10765. if (/Symbol/i.test(properties.name)) {
  10766. encoding = Encodings.SymbolSetEncoding;
  10767. } else if (/Dingbats/i.test(properties.name)) {
  10768. encoding = Encodings.ZapfDingbatsEncoding;
  10769. }
  10770. }
  10771. }
  10772. properties.defaultEncoding = encoding;
  10773. }
  10774. properties.differences = differences;
  10775. properties.baseEncodingName = baseEncodingName;
  10776. properties.dict = dict;
  10777. },
  10778. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10779. var cmap, cmapObj = toUnicode;
  10780. if (isName(cmapObj)) {
  10781. cmap = CMapFactory.create(cmapObj,
  10782. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10783. if (cmap instanceof IdentityCMap) {
  10784. return new IdentityToUnicodeMap(0, 0xFFFF);
  10785. }
  10786. return new ToUnicodeMap(cmap.getMap());
  10787. } else if (isStream(cmapObj)) {
  10788. cmap = CMapFactory.create(cmapObj,
  10789. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10790. if (cmap instanceof IdentityCMap) {
  10791. return new IdentityToUnicodeMap(0, 0xFFFF);
  10792. }
  10793. cmap = cmap.getMap();
  10794. // Convert UTF-16BE
  10795. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10796. // to iterate over all keys.
  10797. cmap.forEach(function(token, i) {
  10798. var str = [];
  10799. for (var k = 0; k < token.length; k += 2) {
  10800. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10801. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10802. str.push(w1);
  10803. continue;
  10804. }
  10805. k += 2;
  10806. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10807. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10808. }
  10809. cmap[i] = String.fromCharCode.apply(String, str);
  10810. });
  10811. return new ToUnicodeMap(cmap);
  10812. }
  10813. return null;
  10814. },
  10815. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10816. // Extract the encoding from the CIDToGIDMap
  10817. var glyphsData = cidToGidStream.getBytes();
  10818. // Set encoding 0 to later verify the font has an encoding
  10819. var result = [];
  10820. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10821. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10822. if (glyphID === 0) {
  10823. continue;
  10824. }
  10825. var code = j >> 1;
  10826. result[code] = glyphID;
  10827. }
  10828. return result;
  10829. },
  10830. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10831. descriptor,
  10832. properties) {
  10833. var glyphsWidths = [];
  10834. var defaultWidth = 0;
  10835. var glyphsVMetrics = [];
  10836. var defaultVMetrics;
  10837. var i, ii, j, jj, start, code, widths;
  10838. if (properties.composite) {
  10839. defaultWidth = dict.get('DW') || 1000;
  10840. widths = dict.get('W');
  10841. if (widths) {
  10842. for (i = 0, ii = widths.length; i < ii; i++) {
  10843. start = widths[i++];
  10844. code = xref.fetchIfRef(widths[i]);
  10845. if (isArray(code)) {
  10846. for (j = 0, jj = code.length; j < jj; j++) {
  10847. glyphsWidths[start++] = code[j];
  10848. }
  10849. } else {
  10850. var width = widths[++i];
  10851. for (j = start; j <= code; j++) {
  10852. glyphsWidths[j] = width;
  10853. }
  10854. }
  10855. }
  10856. }
  10857. if (properties.vertical) {
  10858. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10859. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10860. vmetrics = dict.get('W2');
  10861. if (vmetrics) {
  10862. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10863. start = vmetrics[i++];
  10864. code = xref.fetchIfRef(vmetrics[i]);
  10865. if (isArray(code)) {
  10866. for (j = 0, jj = code.length; j < jj; j++) {
  10867. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10868. }
  10869. } else {
  10870. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10871. for (j = start; j <= code; j++) {
  10872. glyphsVMetrics[j] = vmetric;
  10873. }
  10874. }
  10875. }
  10876. }
  10877. }
  10878. } else {
  10879. var firstChar = properties.firstChar;
  10880. widths = dict.get('Widths');
  10881. if (widths) {
  10882. j = firstChar;
  10883. for (i = 0, ii = widths.length; i < ii; i++) {
  10884. glyphsWidths[j++] = widths[i];
  10885. }
  10886. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10887. } else {
  10888. // Trying get the BaseFont metrics (see comment above).
  10889. var baseFontName = dict.get('BaseFont');
  10890. if (isName(baseFontName)) {
  10891. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10892. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10893. properties);
  10894. defaultWidth = metrics.defaultWidth;
  10895. }
  10896. }
  10897. }
  10898. // Heuristic: detection of monospace font by checking all non-zero widths
  10899. var isMonospace = true;
  10900. var firstWidth = defaultWidth;
  10901. for (var glyph in glyphsWidths) {
  10902. var glyphWidth = glyphsWidths[glyph];
  10903. if (!glyphWidth) {
  10904. continue;
  10905. }
  10906. if (!firstWidth) {
  10907. firstWidth = glyphWidth;
  10908. continue;
  10909. }
  10910. if (firstWidth !== glyphWidth) {
  10911. isMonospace = false;
  10912. break;
  10913. }
  10914. }
  10915. if (isMonospace) {
  10916. properties.flags |= FontFlags.FixedPitch;
  10917. }
  10918. properties.defaultWidth = defaultWidth;
  10919. properties.widths = glyphsWidths;
  10920. properties.defaultVMetrics = defaultVMetrics;
  10921. properties.vmetrics = glyphsVMetrics;
  10922. },
  10923. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10924. // Simulating descriptor flags attribute
  10925. var fontNameWoStyle = baseFontName.split('-')[0];
  10926. return (fontNameWoStyle in serifFonts) ||
  10927. (fontNameWoStyle.search(/serif/gi) !== -1);
  10928. },
  10929. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10930. var defaultWidth = 0;
  10931. var widths = [];
  10932. var monospace = false;
  10933. var lookupName = (stdFontMap[name] || name);
  10934. if (!(lookupName in Metrics)) {
  10935. // Use default fonts for looking up font metrics if the passed
  10936. // font is not a base font
  10937. if (this.isSerifFont(name)) {
  10938. lookupName = 'Times-Roman';
  10939. } else {
  10940. lookupName = 'Helvetica';
  10941. }
  10942. }
  10943. var glyphWidths = Metrics[lookupName];
  10944. if (isNum(glyphWidths)) {
  10945. defaultWidth = glyphWidths;
  10946. monospace = true;
  10947. } else {
  10948. widths = glyphWidths;
  10949. }
  10950. return {
  10951. defaultWidth: defaultWidth,
  10952. monospace: monospace,
  10953. widths: widths
  10954. };
  10955. },
  10956. buildCharCodeToWidth:
  10957. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10958. properties) {
  10959. var widths = Object.create(null);
  10960. var differences = properties.differences;
  10961. var encoding = properties.defaultEncoding;
  10962. for (var charCode = 0; charCode < 256; charCode++) {
  10963. if (charCode in differences &&
  10964. widthsByGlyphName[differences[charCode]]) {
  10965. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10966. continue;
  10967. }
  10968. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10969. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10970. continue;
  10971. }
  10972. }
  10973. return widths;
  10974. },
  10975. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10976. var baseDict = dict;
  10977. var type = dict.get('Subtype');
  10978. assert(isName(type), 'invalid font Subtype');
  10979. var composite = false;
  10980. var uint8array;
  10981. if (type.name === 'Type0') {
  10982. // If font is a composite
  10983. // - get the descendant font
  10984. // - set the type according to the descendant font
  10985. // - get the FontDescriptor from the descendant font
  10986. var df = dict.get('DescendantFonts');
  10987. if (!df) {
  10988. error('Descendant fonts are not specified');
  10989. }
  10990. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10991. type = dict.get('Subtype');
  10992. assert(isName(type), 'invalid font Subtype');
  10993. composite = true;
  10994. }
  10995. var descriptor = dict.get('FontDescriptor');
  10996. if (descriptor) {
  10997. var hash = new MurmurHash3_64();
  10998. var encoding = baseDict.getRaw('Encoding');
  10999. if (isName(encoding)) {
  11000. hash.update(encoding.name);
  11001. } else if (isRef(encoding)) {
  11002. hash.update(encoding.num + '_' + encoding.gen);
  11003. } else if (isDict(encoding)) {
  11004. var keys = encoding.getKeys();
  11005. for (var i = 0, ii = keys.length; i < ii; i++) {
  11006. var entry = encoding.getRaw(keys[i]);
  11007. if (isName(entry)) {
  11008. hash.update(entry.name);
  11009. } else if (isRef(entry)) {
  11010. hash.update(entry.num + '_' + entry.gen);
  11011. } else if (isArray(entry)) { // 'Differences' entry.
  11012. // Ideally we should check the contents of the array, but to avoid
  11013. // parsing it here and then again in |extractDataStructures|,
  11014. // we only use the array length for now (fixes bug1157493.pdf).
  11015. hash.update(entry.length.toString());
  11016. }
  11017. }
  11018. }
  11019. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11020. if (isStream(toUnicode)) {
  11021. var stream = toUnicode.str || toUnicode;
  11022. uint8array = stream.buffer ?
  11023. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11024. new Uint8Array(stream.bytes.buffer,
  11025. stream.start, stream.end - stream.start);
  11026. hash.update(uint8array);
  11027. } else if (isName(toUnicode)) {
  11028. hash.update(toUnicode.name);
  11029. }
  11030. var widths = dict.get('Widths') || baseDict.get('Widths');
  11031. if (widths) {
  11032. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11033. hash.update(uint8array);
  11034. }
  11035. }
  11036. return {
  11037. descriptor: descriptor,
  11038. dict: dict,
  11039. baseDict: baseDict,
  11040. composite: composite,
  11041. type: type.name,
  11042. hash: hash ? hash.hexdigest() : ''
  11043. };
  11044. },
  11045. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11046. xref) {
  11047. var baseDict = preEvaluatedFont.baseDict;
  11048. var dict = preEvaluatedFont.dict;
  11049. var composite = preEvaluatedFont.composite;
  11050. var descriptor = preEvaluatedFont.descriptor;
  11051. var type = preEvaluatedFont.type;
  11052. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11053. var properties;
  11054. if (!descriptor) {
  11055. if (type === 'Type3') {
  11056. // FontDescriptor is only required for Type3 fonts when the document
  11057. // is a tagged pdf. Create a barbebones one to get by.
  11058. descriptor = new Dict(null);
  11059. descriptor.set('FontName', Name.get(type));
  11060. descriptor.set('FontBBox', dict.get('FontBBox'));
  11061. } else {
  11062. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11063. // FontDescriptor was not required.
  11064. // This case is here for compatibility.
  11065. var baseFontName = dict.get('BaseFont');
  11066. if (!isName(baseFontName)) {
  11067. error('Base font is not specified');
  11068. }
  11069. // Using base font name as a font name.
  11070. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11071. var metrics = this.getBaseFontMetrics(baseFontName);
  11072. // Simulating descriptor flags attribute
  11073. var fontNameWoStyle = baseFontName.split('-')[0];
  11074. var flags =
  11075. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11076. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11077. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11078. FontFlags.Nonsymbolic);
  11079. properties = {
  11080. type: type,
  11081. name: baseFontName,
  11082. widths: metrics.widths,
  11083. defaultWidth: metrics.defaultWidth,
  11084. flags: flags,
  11085. firstChar: 0,
  11086. lastChar: maxCharIndex
  11087. };
  11088. this.extractDataStructures(dict, dict, xref, properties);
  11089. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11090. properties);
  11091. return new Font(baseFontName, null, properties);
  11092. }
  11093. }
  11094. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11095. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11096. // to ignore this rule when a variant of a standart font is used.
  11097. // TODO Fill the width array depending on which of the base font this is
  11098. // a variant.
  11099. var firstChar = (dict.get('FirstChar') || 0);
  11100. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11101. var fontName = descriptor.get('FontName');
  11102. var baseFont = dict.get('BaseFont');
  11103. // Some bad PDFs have a string as the font name.
  11104. if (isString(fontName)) {
  11105. fontName = Name.get(fontName);
  11106. }
  11107. if (isString(baseFont)) {
  11108. baseFont = Name.get(baseFont);
  11109. }
  11110. if (type !== 'Type3') {
  11111. var fontNameStr = fontName && fontName.name;
  11112. var baseFontStr = baseFont && baseFont.name;
  11113. if (fontNameStr !== baseFontStr) {
  11114. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11115. '" but should be the same as the Font\'s BaseFont "' +
  11116. baseFontStr + '"');
  11117. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11118. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11119. if (fontNameStr && baseFontStr &&
  11120. baseFontStr.indexOf(fontNameStr) === 0) {
  11121. fontName = baseFont;
  11122. }
  11123. }
  11124. }
  11125. fontName = (fontName || baseFont);
  11126. assert(isName(fontName), 'invalid font name');
  11127. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11128. if (fontFile) {
  11129. if (fontFile.dict) {
  11130. var subtype = fontFile.dict.get('Subtype');
  11131. if (subtype) {
  11132. subtype = subtype.name;
  11133. }
  11134. var length1 = fontFile.dict.get('Length1');
  11135. var length2 = fontFile.dict.get('Length2');
  11136. }
  11137. }
  11138. properties = {
  11139. type: type,
  11140. name: fontName.name,
  11141. subtype: subtype,
  11142. file: fontFile,
  11143. length1: length1,
  11144. length2: length2,
  11145. loadedName: baseDict.loadedName,
  11146. composite: composite,
  11147. wideChars: composite,
  11148. fixedPitch: false,
  11149. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11150. firstChar: firstChar || 0,
  11151. lastChar: (lastChar || maxCharIndex),
  11152. bbox: descriptor.get('FontBBox'),
  11153. ascent: descriptor.get('Ascent'),
  11154. descent: descriptor.get('Descent'),
  11155. xHeight: descriptor.get('XHeight'),
  11156. capHeight: descriptor.get('CapHeight'),
  11157. flags: descriptor.get('Flags'),
  11158. italicAngle: descriptor.get('ItalicAngle'),
  11159. coded: false
  11160. };
  11161. if (composite) {
  11162. var cidEncoding = baseDict.get('Encoding');
  11163. if (isName(cidEncoding)) {
  11164. properties.cidEncoding = cidEncoding.name;
  11165. }
  11166. properties.cMap = CMapFactory.create(cidEncoding,
  11167. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11168. properties.vertical = properties.cMap.vertical;
  11169. }
  11170. this.extractDataStructures(dict, baseDict, xref, properties);
  11171. this.extractWidths(dict, xref, descriptor, properties);
  11172. if (type === 'Type3') {
  11173. properties.isType3Font = true;
  11174. }
  11175. return new Font(fontName.name, fontFile, properties);
  11176. }
  11177. };
  11178. return PartialEvaluator;
  11179. })();
  11180. var TranslatedFont = (function TranslatedFontClosure() {
  11181. function TranslatedFont(loadedName, font, dict) {
  11182. this.loadedName = loadedName;
  11183. this.font = font;
  11184. this.dict = dict;
  11185. this.type3Loaded = null;
  11186. this.sent = false;
  11187. }
  11188. TranslatedFont.prototype = {
  11189. send: function (handler) {
  11190. if (this.sent) {
  11191. return;
  11192. }
  11193. var fontData = this.font.exportData();
  11194. handler.send('commonobj', [
  11195. this.loadedName,
  11196. 'Font',
  11197. fontData
  11198. ]);
  11199. this.sent = true;
  11200. },
  11201. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11202. assert(this.font.isType3Font);
  11203. if (this.type3Loaded) {
  11204. return this.type3Loaded;
  11205. }
  11206. var translatedFont = this.font;
  11207. var loadCharProcsPromise = Promise.resolve();
  11208. var charProcs = this.dict.get('CharProcs').getAll();
  11209. var fontResources = this.dict.get('Resources') || resources;
  11210. var charProcKeys = Object.keys(charProcs);
  11211. var charProcOperatorList = {};
  11212. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11213. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11214. var glyphStream = charProcs[key];
  11215. var operatorList = new OperatorList();
  11216. return evaluator.getOperatorList(glyphStream, fontResources,
  11217. operatorList).then(function () {
  11218. charProcOperatorList[key] = operatorList.getIR();
  11219. // Add the dependencies to the parent operator list so they are
  11220. // resolved before sub operator list is executed synchronously.
  11221. parentOperatorList.addDependencies(operatorList.dependencies);
  11222. }, function (reason) {
  11223. warn('Type3 font resource \"' + key + '\" is not available');
  11224. var operatorList = new OperatorList();
  11225. charProcOperatorList[key] = operatorList.getIR();
  11226. });
  11227. }.bind(this, charProcKeys[i]));
  11228. }
  11229. this.type3Loaded = loadCharProcsPromise.then(function () {
  11230. translatedFont.charProcOperatorList = charProcOperatorList;
  11231. });
  11232. return this.type3Loaded;
  11233. }
  11234. };
  11235. return TranslatedFont;
  11236. })();
  11237. var OperatorList = (function OperatorListClosure() {
  11238. var CHUNK_SIZE = 1000;
  11239. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11240. function getTransfers(queue) {
  11241. var transfers = [];
  11242. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11243. for (var i = 0, ii = queue.length; i < ii; i++) {
  11244. switch (fnArray[i]) {
  11245. case OPS.paintInlineImageXObject:
  11246. case OPS.paintInlineImageXObjectGroup:
  11247. case OPS.paintImageMaskXObject:
  11248. var arg = argsArray[i][0]; // first param in imgData
  11249. if (!arg.cached) {
  11250. transfers.push(arg.data.buffer);
  11251. }
  11252. break;
  11253. }
  11254. }
  11255. return transfers;
  11256. }
  11257. function OperatorList(intent, messageHandler, pageIndex) {
  11258. this.messageHandler = messageHandler;
  11259. this.fnArray = [];
  11260. this.argsArray = [];
  11261. this.dependencies = {};
  11262. this.pageIndex = pageIndex;
  11263. this.intent = intent;
  11264. }
  11265. OperatorList.prototype = {
  11266. get length() {
  11267. return this.argsArray.length;
  11268. },
  11269. addOp: function(fn, args) {
  11270. this.fnArray.push(fn);
  11271. this.argsArray.push(args);
  11272. if (this.messageHandler) {
  11273. if (this.fnArray.length >= CHUNK_SIZE) {
  11274. this.flush();
  11275. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11276. (fn === OPS.restore || fn === OPS.endText)) {
  11277. // heuristic to flush on boundary of restore or endText
  11278. this.flush();
  11279. }
  11280. }
  11281. },
  11282. addDependency: function(dependency) {
  11283. if (dependency in this.dependencies) {
  11284. return;
  11285. }
  11286. this.dependencies[dependency] = true;
  11287. this.addOp(OPS.dependency, [dependency]);
  11288. },
  11289. addDependencies: function(dependencies) {
  11290. for (var key in dependencies) {
  11291. this.addDependency(key);
  11292. }
  11293. },
  11294. addOpList: function(opList) {
  11295. Util.extendObj(this.dependencies, opList.dependencies);
  11296. for (var i = 0, ii = opList.length; i < ii; i++) {
  11297. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11298. }
  11299. },
  11300. getIR: function() {
  11301. return {
  11302. fnArray: this.fnArray,
  11303. argsArray: this.argsArray,
  11304. length: this.length
  11305. };
  11306. },
  11307. flush: function(lastChunk) {
  11308. if (this.intent !== 'oplist') {
  11309. new QueueOptimizer().optimize(this);
  11310. }
  11311. var transfers = getTransfers(this);
  11312. this.messageHandler.send('RenderPageChunk', {
  11313. operatorList: {
  11314. fnArray: this.fnArray,
  11315. argsArray: this.argsArray,
  11316. lastChunk: lastChunk,
  11317. length: this.length
  11318. },
  11319. pageIndex: this.pageIndex,
  11320. intent: this.intent
  11321. }, transfers);
  11322. this.dependencies = {};
  11323. this.fnArray.length = 0;
  11324. this.argsArray.length = 0;
  11325. }
  11326. };
  11327. return OperatorList;
  11328. })();
  11329. var StateManager = (function StateManagerClosure() {
  11330. function StateManager(initialState) {
  11331. this.state = initialState;
  11332. this.stateStack = [];
  11333. }
  11334. StateManager.prototype = {
  11335. save: function () {
  11336. var old = this.state;
  11337. this.stateStack.push(this.state);
  11338. this.state = old.clone();
  11339. },
  11340. restore: function () {
  11341. var prev = this.stateStack.pop();
  11342. if (prev) {
  11343. this.state = prev;
  11344. }
  11345. },
  11346. transform: function (args) {
  11347. this.state.ctm = Util.transform(this.state.ctm, args);
  11348. }
  11349. };
  11350. return StateManager;
  11351. })();
  11352. var TextState = (function TextStateClosure() {
  11353. function TextState() {
  11354. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11355. this.fontSize = 0;
  11356. this.font = null;
  11357. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11358. this.textMatrix = IDENTITY_MATRIX.slice();
  11359. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11360. this.charSpacing = 0;
  11361. this.wordSpacing = 0;
  11362. this.leading = 0;
  11363. this.textHScale = 1;
  11364. this.textRise = 0;
  11365. }
  11366. TextState.prototype = {
  11367. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11368. var m = this.textMatrix;
  11369. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11370. },
  11371. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11372. var m = this.textLineMatrix;
  11373. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11374. },
  11375. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11376. var m = this.textMatrix;
  11377. m[4] = m[0] * x + m[2] * y + m[4];
  11378. m[5] = m[1] * x + m[3] * y + m[5];
  11379. },
  11380. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11381. var m = this.textLineMatrix;
  11382. m[4] = m[0] * x + m[2] * y + m[4];
  11383. m[5] = m[1] * x + m[3] * y + m[5];
  11384. },
  11385. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11386. // 9.4.4 Text Space Details
  11387. var tsm = [this.fontSize * this.textHScale, 0,
  11388. 0, this.fontSize,
  11389. 0, this.textRise];
  11390. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11391. },
  11392. carriageReturn: function TextState_carriageReturn() {
  11393. this.translateTextLineMatrix(0, -this.leading);
  11394. this.textMatrix = this.textLineMatrix.slice();
  11395. },
  11396. clone: function TextState_clone() {
  11397. var clone = Object.create(this);
  11398. clone.textMatrix = this.textMatrix.slice();
  11399. clone.textLineMatrix = this.textLineMatrix.slice();
  11400. clone.fontMatrix = this.fontMatrix.slice();
  11401. return clone;
  11402. }
  11403. };
  11404. return TextState;
  11405. })();
  11406. var EvalState = (function EvalStateClosure() {
  11407. function EvalState() {
  11408. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11409. this.font = null;
  11410. this.textRenderingMode = TextRenderingMode.FILL;
  11411. this.fillColorSpace = ColorSpace.singletons.gray;
  11412. this.strokeColorSpace = ColorSpace.singletons.gray;
  11413. }
  11414. EvalState.prototype = {
  11415. clone: function CanvasExtraState_clone() {
  11416. return Object.create(this);
  11417. },
  11418. };
  11419. return EvalState;
  11420. })();
  11421. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11422. // Specifies properties for each command
  11423. //
  11424. // If variableArgs === true: [0, `numArgs`] expected
  11425. // If variableArgs === false: exactly `numArgs` expected
  11426. var OP_MAP = {
  11427. // Graphic state
  11428. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11429. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11430. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11431. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11432. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11433. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11434. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11435. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11436. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11437. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11438. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11439. // Path
  11440. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11441. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11442. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11443. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11444. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11445. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11446. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11447. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11448. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11449. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11450. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11451. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11452. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11453. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11454. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11455. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11456. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11457. // Clipping
  11458. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11459. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11460. // Text
  11461. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11462. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11463. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11464. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11465. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11466. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11467. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11468. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11469. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11470. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11471. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11472. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11473. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11474. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11475. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11476. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11477. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11478. variableArgs: false },
  11479. // Type3 fonts
  11480. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11481. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11482. // Color
  11483. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11484. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11485. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11486. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11487. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11488. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11489. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11490. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11491. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11492. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11493. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11494. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11495. // Shading
  11496. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11497. // Images
  11498. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11499. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11500. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11501. // XObjects
  11502. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11503. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11504. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11505. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11506. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11507. variableArgs: false },
  11508. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11509. // Compatibility
  11510. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11511. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11512. // (reserved partial commands for the lexer)
  11513. BM: null,
  11514. BD: null,
  11515. 'true': null,
  11516. fa: null,
  11517. fal: null,
  11518. fals: null,
  11519. 'false': null,
  11520. nu: null,
  11521. nul: null,
  11522. 'null': null
  11523. };
  11524. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11525. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11526. // dictionary
  11527. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11528. this.stateManager = stateManager;
  11529. this.nonProcessedArgs = [];
  11530. }
  11531. EvaluatorPreprocessor.prototype = {
  11532. get savedStatesDepth() {
  11533. return this.stateManager.stateStack.length;
  11534. },
  11535. // |operation| is an object with two fields:
  11536. //
  11537. // - |fn| is an out param.
  11538. //
  11539. // - |args| is an inout param. On entry, it should have one of two values.
  11540. //
  11541. // - An empty array. This indicates that the caller is providing the
  11542. // array in which the args will be stored in. The caller should use
  11543. // this value if it can reuse a single array for each call to read().
  11544. //
  11545. // - |null|. This indicates that the caller needs this function to create
  11546. // the array in which any args are stored in. If there are zero args,
  11547. // this function will leave |operation.args| as |null| (thus avoiding
  11548. // allocations that would occur if we used an empty array to represent
  11549. // zero arguments). Otherwise, it will replace |null| with a new array
  11550. // containing the arguments. The caller should use this value if it
  11551. // cannot reuse an array for each call to read().
  11552. //
  11553. // These two modes are present because this function is very hot and so
  11554. // avoiding allocations where possible is worthwhile.
  11555. //
  11556. read: function EvaluatorPreprocessor_read(operation) {
  11557. var args = operation.args;
  11558. while (true) {
  11559. var obj = this.parser.getObj();
  11560. if (isCmd(obj)) {
  11561. var cmd = obj.cmd;
  11562. // Check that the command is valid
  11563. var opSpec = OP_MAP[cmd];
  11564. if (!opSpec) {
  11565. warn('Unknown command "' + cmd + '"');
  11566. continue;
  11567. }
  11568. var fn = opSpec.id;
  11569. var numArgs = opSpec.numArgs;
  11570. var argsLength = args !== null ? args.length : 0;
  11571. if (!opSpec.variableArgs) {
  11572. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11573. if (argsLength !== numArgs) {
  11574. var nonProcessedArgs = this.nonProcessedArgs;
  11575. while (argsLength > numArgs) {
  11576. nonProcessedArgs.push(args.shift());
  11577. argsLength--;
  11578. }
  11579. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11580. if (!args) {
  11581. args = [];
  11582. }
  11583. args.unshift(nonProcessedArgs.pop());
  11584. argsLength++;
  11585. }
  11586. }
  11587. if (argsLength < numArgs) {
  11588. // If we receive too few args, it's not possible to possible
  11589. // to execute the command, so skip the command
  11590. info('Command ' + fn + ': because expected ' +
  11591. numArgs + ' args, but received ' + argsLength +
  11592. ' args; skipping');
  11593. args = null;
  11594. continue;
  11595. }
  11596. } else if (argsLength > numArgs) {
  11597. info('Command ' + fn + ': expected [0,' + numArgs +
  11598. '] args, but received ' + argsLength + ' args');
  11599. }
  11600. // TODO figure out how to type-check vararg functions
  11601. this.preprocessCommand(fn, args);
  11602. operation.fn = fn;
  11603. operation.args = args;
  11604. return true;
  11605. } else {
  11606. if (isEOF(obj)) {
  11607. return false; // no more commands
  11608. }
  11609. // argument
  11610. if (obj !== null) {
  11611. if (!args) {
  11612. args = [];
  11613. }
  11614. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11615. assert(args.length <= 33, 'Too many arguments');
  11616. }
  11617. }
  11618. }
  11619. },
  11620. preprocessCommand:
  11621. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11622. switch (fn | 0) {
  11623. case OPS.save:
  11624. this.stateManager.save();
  11625. break;
  11626. case OPS.restore:
  11627. this.stateManager.restore();
  11628. break;
  11629. case OPS.transform:
  11630. this.stateManager.transform(args);
  11631. break;
  11632. }
  11633. }
  11634. };
  11635. return EvaluatorPreprocessor;
  11636. })();
  11637. var QueueOptimizer = (function QueueOptimizerClosure() {
  11638. function addState(parentState, pattern, fn) {
  11639. var state = parentState;
  11640. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11641. var item = pattern[i];
  11642. state = (state[item] || (state[item] = []));
  11643. }
  11644. state[pattern[pattern.length - 1]] = fn;
  11645. }
  11646. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11647. argsArray) {
  11648. // Handles special case of mainly LaTeX documents which use image masks to
  11649. // draw lines with the current fill style.
  11650. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11651. // have been found at iFirstSave.
  11652. var iFirstPIMXO = iFirstSave + 2;
  11653. for (var i = 0; i < count; i++) {
  11654. var arg = argsArray[iFirstPIMXO + 4 * i];
  11655. var imageMask = arg.length === 1 && arg[0];
  11656. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11657. (!imageMask.data.length ||
  11658. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11659. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11660. continue;
  11661. }
  11662. break;
  11663. }
  11664. return count - i;
  11665. }
  11666. var InitialState = [];
  11667. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11668. // sequences with one |paintInlineImageXObjectGroup| operation.
  11669. addState(InitialState,
  11670. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11671. function foundInlineImageGroup(context) {
  11672. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11673. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11674. var MAX_WIDTH = 1000;
  11675. var IMAGE_PADDING = 1;
  11676. var fnArray = context.fnArray, argsArray = context.argsArray;
  11677. var curr = context.iCurr;
  11678. var iFirstSave = curr - 3;
  11679. var iFirstTransform = curr - 2;
  11680. var iFirstPIIXO = curr - 1;
  11681. // Look for the quartets.
  11682. var i = iFirstSave + 4;
  11683. var ii = fnArray.length;
  11684. while (i + 3 < ii) {
  11685. if (fnArray[i] !== OPS.save ||
  11686. fnArray[i + 1] !== OPS.transform ||
  11687. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11688. fnArray[i + 3] !== OPS.restore) {
  11689. break; // ops don't match
  11690. }
  11691. i += 4;
  11692. }
  11693. // At this point, i is the index of the first op past the last valid
  11694. // quartet.
  11695. var count = Math.min((i - iFirstSave) / 4,
  11696. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11697. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11698. return i;
  11699. }
  11700. // assuming that heights of those image is too small (~1 pixel)
  11701. // packing as much as possible by lines
  11702. var maxX = 0;
  11703. var map = [], maxLineHeight = 0;
  11704. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11705. var q;
  11706. for (q = 0; q < count; q++) {
  11707. var transform = argsArray[iFirstTransform + (q << 2)];
  11708. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11709. if (currentX + img.width > MAX_WIDTH) {
  11710. // starting new line
  11711. maxX = Math.max(maxX, currentX);
  11712. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11713. currentX = 0;
  11714. maxLineHeight = 0;
  11715. }
  11716. map.push({
  11717. transform: transform,
  11718. x: currentX, y: currentY,
  11719. w: img.width, h: img.height
  11720. });
  11721. currentX += img.width + 2 * IMAGE_PADDING;
  11722. maxLineHeight = Math.max(maxLineHeight, img.height);
  11723. }
  11724. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11725. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11726. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11727. var imgRowSize = imgWidth << 2;
  11728. for (q = 0; q < count; q++) {
  11729. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11730. // Copy image by lines and extends pixels into padding.
  11731. var rowSize = map[q].w << 2;
  11732. var dataOffset = 0;
  11733. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11734. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11735. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11736. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11737. dataOffset += rowSize;
  11738. offset += imgRowSize;
  11739. }
  11740. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11741. while (offset >= 0) {
  11742. data[offset - 4] = data[offset];
  11743. data[offset - 3] = data[offset + 1];
  11744. data[offset - 2] = data[offset + 2];
  11745. data[offset - 1] = data[offset + 3];
  11746. data[offset + rowSize] = data[offset + rowSize - 4];
  11747. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11748. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11749. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11750. offset -= imgRowSize;
  11751. }
  11752. }
  11753. // Replace queue items.
  11754. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11755. argsArray.splice(iFirstSave, count * 4,
  11756. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11757. data: imgData }, map]);
  11758. return iFirstSave + 1;
  11759. });
  11760. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11761. // sequences with one |paintImageMaskXObjectGroup| or one
  11762. // |paintImageMaskXObjectRepeat| operation.
  11763. addState(InitialState,
  11764. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11765. function foundImageMaskGroup(context) {
  11766. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11767. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11768. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11769. var fnArray = context.fnArray, argsArray = context.argsArray;
  11770. var curr = context.iCurr;
  11771. var iFirstSave = curr - 3;
  11772. var iFirstTransform = curr - 2;
  11773. var iFirstPIMXO = curr - 1;
  11774. // Look for the quartets.
  11775. var i = iFirstSave + 4;
  11776. var ii = fnArray.length;
  11777. while (i + 3 < ii) {
  11778. if (fnArray[i] !== OPS.save ||
  11779. fnArray[i + 1] !== OPS.transform ||
  11780. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11781. fnArray[i + 3] !== OPS.restore) {
  11782. break; // ops don't match
  11783. }
  11784. i += 4;
  11785. }
  11786. // At this point, i is the index of the first op past the last valid
  11787. // quartet.
  11788. var count = (i - iFirstSave) / 4;
  11789. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11790. argsArray);
  11791. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11792. return i;
  11793. }
  11794. var q;
  11795. var isSameImage = false;
  11796. var iTransform, transformArgs;
  11797. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11798. if (argsArray[iFirstTransform][1] === 0 &&
  11799. argsArray[iFirstTransform][2] === 0) {
  11800. isSameImage = true;
  11801. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11802. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11803. iTransform = iFirstTransform + 4;
  11804. var iPIMXO = iFirstPIMXO + 4;
  11805. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11806. transformArgs = argsArray[iTransform];
  11807. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11808. transformArgs[0] !== firstTransformArg0 ||
  11809. transformArgs[1] !== 0 ||
  11810. transformArgs[2] !== 0 ||
  11811. transformArgs[3] !== firstTransformArg3) {
  11812. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11813. isSameImage = false;
  11814. } else {
  11815. count = q;
  11816. }
  11817. break; // different image or transform
  11818. }
  11819. }
  11820. }
  11821. if (isSameImage) {
  11822. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11823. var positions = new Float32Array(count * 2);
  11824. iTransform = iFirstTransform;
  11825. for (q = 0; q < count; q++, iTransform += 4) {
  11826. transformArgs = argsArray[iTransform];
  11827. positions[(q << 1)] = transformArgs[4];
  11828. positions[(q << 1) + 1] = transformArgs[5];
  11829. }
  11830. // Replace queue items.
  11831. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11832. argsArray.splice(iFirstSave, count * 4,
  11833. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11834. } else {
  11835. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11836. var images = [];
  11837. for (q = 0; q < count; q++) {
  11838. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11839. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11840. images.push({ data: maskParams.data, width: maskParams.width,
  11841. height: maskParams.height,
  11842. transform: transformArgs });
  11843. }
  11844. // Replace queue items.
  11845. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11846. argsArray.splice(iFirstSave, count * 4, [images]);
  11847. }
  11848. return iFirstSave + 1;
  11849. });
  11850. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11851. // with one paintImageXObjectRepeat operation, if the |transform| and
  11852. // |paintImageXObjectRepeat| ops are appropriate.
  11853. addState(InitialState,
  11854. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11855. function (context) {
  11856. var MIN_IMAGES_IN_BLOCK = 3;
  11857. var MAX_IMAGES_IN_BLOCK = 1000;
  11858. var fnArray = context.fnArray, argsArray = context.argsArray;
  11859. var curr = context.iCurr;
  11860. var iFirstSave = curr - 3;
  11861. var iFirstTransform = curr - 2;
  11862. var iFirstPIXO = curr - 1;
  11863. var iFirstRestore = curr;
  11864. if (argsArray[iFirstTransform][1] !== 0 ||
  11865. argsArray[iFirstTransform][2] !== 0) {
  11866. return iFirstRestore + 1; // transform has the wrong form
  11867. }
  11868. // Look for the quartets.
  11869. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11870. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11871. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11872. var i = iFirstSave + 4;
  11873. var ii = fnArray.length;
  11874. while (i + 3 < ii) {
  11875. if (fnArray[i] !== OPS.save ||
  11876. fnArray[i + 1] !== OPS.transform ||
  11877. fnArray[i + 2] !== OPS.paintImageXObject ||
  11878. fnArray[i + 3] !== OPS.restore) {
  11879. break; // ops don't match
  11880. }
  11881. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11882. argsArray[i + 1][1] !== 0 ||
  11883. argsArray[i + 1][2] !== 0 ||
  11884. argsArray[i + 1][3] !== firstTransformArg3) {
  11885. break; // transforms don't match
  11886. }
  11887. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11888. break; // images don't match
  11889. }
  11890. i += 4;
  11891. }
  11892. // At this point, i is the index of the first op past the last valid
  11893. // quartet.
  11894. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11895. if (count < MIN_IMAGES_IN_BLOCK) {
  11896. return i;
  11897. }
  11898. // Extract the (x,y) positions from all of the matching transforms.
  11899. var positions = new Float32Array(count * 2);
  11900. var iTransform = iFirstTransform;
  11901. for (var q = 0; q < count; q++, iTransform += 4) {
  11902. var transformArgs = argsArray[iTransform];
  11903. positions[(q << 1)] = transformArgs[4];
  11904. positions[(q << 1) + 1] = transformArgs[5];
  11905. }
  11906. // Replace queue items.
  11907. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11908. positions];
  11909. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11910. argsArray.splice(iFirstSave, count * 4, args);
  11911. return iFirstSave + 1;
  11912. });
  11913. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11914. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11915. // sequences, if the font for each one is the same.
  11916. addState(InitialState,
  11917. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11918. function (context) {
  11919. var MIN_CHARS_IN_BLOCK = 3;
  11920. var MAX_CHARS_IN_BLOCK = 1000;
  11921. var fnArray = context.fnArray, argsArray = context.argsArray;
  11922. var curr = context.iCurr;
  11923. var iFirstBeginText = curr - 4;
  11924. var iFirstSetFont = curr - 3;
  11925. var iFirstSetTextMatrix = curr - 2;
  11926. var iFirstShowText = curr - 1;
  11927. var iFirstEndText = curr;
  11928. // Look for the quintets.
  11929. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11930. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11931. var i = iFirstBeginText + 5;
  11932. var ii = fnArray.length;
  11933. while (i + 4 < ii) {
  11934. if (fnArray[i] !== OPS.beginText ||
  11935. fnArray[i + 1] !== OPS.setFont ||
  11936. fnArray[i + 2] !== OPS.setTextMatrix ||
  11937. fnArray[i + 3] !== OPS.showText ||
  11938. fnArray[i + 4] !== OPS.endText) {
  11939. break; // ops don't match
  11940. }
  11941. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11942. argsArray[i + 1][1] !== firstSetFontArg1) {
  11943. break; // fonts don't match
  11944. }
  11945. i += 5;
  11946. }
  11947. // At this point, i is the index of the first op past the last valid
  11948. // quintet.
  11949. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11950. if (count < MIN_CHARS_IN_BLOCK) {
  11951. return i;
  11952. }
  11953. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11954. // showText, endText), include that as well. (E.g. <something> might be
  11955. // |dependency|.)
  11956. var iFirst = iFirstBeginText;
  11957. if (iFirstBeginText >= 4 &&
  11958. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11959. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11960. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11961. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11962. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11963. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11964. count++;
  11965. iFirst -= 5;
  11966. }
  11967. // Remove (endText, beginText, setFont) trios.
  11968. var iEndText = iFirst + 4;
  11969. for (var q = 1; q < count; q++) {
  11970. fnArray.splice(iEndText, 3);
  11971. argsArray.splice(iEndText, 3);
  11972. iEndText += 2;
  11973. }
  11974. return iEndText + 1;
  11975. });
  11976. function QueueOptimizer() {}
  11977. QueueOptimizer.prototype = {
  11978. optimize: function QueueOptimizer_optimize(queue) {
  11979. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11980. var context = {
  11981. iCurr: 0,
  11982. fnArray: fnArray,
  11983. argsArray: argsArray
  11984. };
  11985. var state;
  11986. var i = 0, ii = fnArray.length;
  11987. while (i < ii) {
  11988. state = (state || InitialState)[fnArray[i]];
  11989. if (typeof state === 'function') { // we found some handler
  11990. context.iCurr = i;
  11991. // state() returns the index of the first non-matching op (if we
  11992. // didn't match) or the first op past the modified ops (if we did
  11993. // match and replace).
  11994. i = state(context);
  11995. state = undefined; // reset the state machine
  11996. ii = context.fnArray.length;
  11997. } else {
  11998. i++;
  11999. }
  12000. }
  12001. }
  12002. };
  12003. return QueueOptimizer;
  12004. })();
  12005. var BUILT_IN_CMAPS = [
  12006. // << Start unicode maps.
  12007. 'Adobe-GB1-UCS2',
  12008. 'Adobe-CNS1-UCS2',
  12009. 'Adobe-Japan1-UCS2',
  12010. 'Adobe-Korea1-UCS2',
  12011. // >> End unicode maps.
  12012. '78-EUC-H',
  12013. '78-EUC-V',
  12014. '78-H',
  12015. '78-RKSJ-H',
  12016. '78-RKSJ-V',
  12017. '78-V',
  12018. '78ms-RKSJ-H',
  12019. '78ms-RKSJ-V',
  12020. '83pv-RKSJ-H',
  12021. '90ms-RKSJ-H',
  12022. '90ms-RKSJ-V',
  12023. '90msp-RKSJ-H',
  12024. '90msp-RKSJ-V',
  12025. '90pv-RKSJ-H',
  12026. '90pv-RKSJ-V',
  12027. 'Add-H',
  12028. 'Add-RKSJ-H',
  12029. 'Add-RKSJ-V',
  12030. 'Add-V',
  12031. 'Adobe-CNS1-0',
  12032. 'Adobe-CNS1-1',
  12033. 'Adobe-CNS1-2',
  12034. 'Adobe-CNS1-3',
  12035. 'Adobe-CNS1-4',
  12036. 'Adobe-CNS1-5',
  12037. 'Adobe-CNS1-6',
  12038. 'Adobe-GB1-0',
  12039. 'Adobe-GB1-1',
  12040. 'Adobe-GB1-2',
  12041. 'Adobe-GB1-3',
  12042. 'Adobe-GB1-4',
  12043. 'Adobe-GB1-5',
  12044. 'Adobe-Japan1-0',
  12045. 'Adobe-Japan1-1',
  12046. 'Adobe-Japan1-2',
  12047. 'Adobe-Japan1-3',
  12048. 'Adobe-Japan1-4',
  12049. 'Adobe-Japan1-5',
  12050. 'Adobe-Japan1-6',
  12051. 'Adobe-Korea1-0',
  12052. 'Adobe-Korea1-1',
  12053. 'Adobe-Korea1-2',
  12054. 'B5-H',
  12055. 'B5-V',
  12056. 'B5pc-H',
  12057. 'B5pc-V',
  12058. 'CNS-EUC-H',
  12059. 'CNS-EUC-V',
  12060. 'CNS1-H',
  12061. 'CNS1-V',
  12062. 'CNS2-H',
  12063. 'CNS2-V',
  12064. 'ETHK-B5-H',
  12065. 'ETHK-B5-V',
  12066. 'ETen-B5-H',
  12067. 'ETen-B5-V',
  12068. 'ETenms-B5-H',
  12069. 'ETenms-B5-V',
  12070. 'EUC-H',
  12071. 'EUC-V',
  12072. 'Ext-H',
  12073. 'Ext-RKSJ-H',
  12074. 'Ext-RKSJ-V',
  12075. 'Ext-V',
  12076. 'GB-EUC-H',
  12077. 'GB-EUC-V',
  12078. 'GB-H',
  12079. 'GB-V',
  12080. 'GBK-EUC-H',
  12081. 'GBK-EUC-V',
  12082. 'GBK2K-H',
  12083. 'GBK2K-V',
  12084. 'GBKp-EUC-H',
  12085. 'GBKp-EUC-V',
  12086. 'GBT-EUC-H',
  12087. 'GBT-EUC-V',
  12088. 'GBT-H',
  12089. 'GBT-V',
  12090. 'GBTpc-EUC-H',
  12091. 'GBTpc-EUC-V',
  12092. 'GBpc-EUC-H',
  12093. 'GBpc-EUC-V',
  12094. 'H',
  12095. 'HKdla-B5-H',
  12096. 'HKdla-B5-V',
  12097. 'HKdlb-B5-H',
  12098. 'HKdlb-B5-V',
  12099. 'HKgccs-B5-H',
  12100. 'HKgccs-B5-V',
  12101. 'HKm314-B5-H',
  12102. 'HKm314-B5-V',
  12103. 'HKm471-B5-H',
  12104. 'HKm471-B5-V',
  12105. 'HKscs-B5-H',
  12106. 'HKscs-B5-V',
  12107. 'Hankaku',
  12108. 'Hiragana',
  12109. 'KSC-EUC-H',
  12110. 'KSC-EUC-V',
  12111. 'KSC-H',
  12112. 'KSC-Johab-H',
  12113. 'KSC-Johab-V',
  12114. 'KSC-V',
  12115. 'KSCms-UHC-H',
  12116. 'KSCms-UHC-HW-H',
  12117. 'KSCms-UHC-HW-V',
  12118. 'KSCms-UHC-V',
  12119. 'KSCpc-EUC-H',
  12120. 'KSCpc-EUC-V',
  12121. 'Katakana',
  12122. 'NWP-H',
  12123. 'NWP-V',
  12124. 'RKSJ-H',
  12125. 'RKSJ-V',
  12126. 'Roman',
  12127. 'UniCNS-UCS2-H',
  12128. 'UniCNS-UCS2-V',
  12129. 'UniCNS-UTF16-H',
  12130. 'UniCNS-UTF16-V',
  12131. 'UniCNS-UTF32-H',
  12132. 'UniCNS-UTF32-V',
  12133. 'UniCNS-UTF8-H',
  12134. 'UniCNS-UTF8-V',
  12135. 'UniGB-UCS2-H',
  12136. 'UniGB-UCS2-V',
  12137. 'UniGB-UTF16-H',
  12138. 'UniGB-UTF16-V',
  12139. 'UniGB-UTF32-H',
  12140. 'UniGB-UTF32-V',
  12141. 'UniGB-UTF8-H',
  12142. 'UniGB-UTF8-V',
  12143. 'UniJIS-UCS2-H',
  12144. 'UniJIS-UCS2-HW-H',
  12145. 'UniJIS-UCS2-HW-V',
  12146. 'UniJIS-UCS2-V',
  12147. 'UniJIS-UTF16-H',
  12148. 'UniJIS-UTF16-V',
  12149. 'UniJIS-UTF32-H',
  12150. 'UniJIS-UTF32-V',
  12151. 'UniJIS-UTF8-H',
  12152. 'UniJIS-UTF8-V',
  12153. 'UniJIS2004-UTF16-H',
  12154. 'UniJIS2004-UTF16-V',
  12155. 'UniJIS2004-UTF32-H',
  12156. 'UniJIS2004-UTF32-V',
  12157. 'UniJIS2004-UTF8-H',
  12158. 'UniJIS2004-UTF8-V',
  12159. 'UniJISPro-UCS2-HW-V',
  12160. 'UniJISPro-UCS2-V',
  12161. 'UniJISPro-UTF8-V',
  12162. 'UniJISX0213-UTF32-H',
  12163. 'UniJISX0213-UTF32-V',
  12164. 'UniJISX02132004-UTF32-H',
  12165. 'UniJISX02132004-UTF32-V',
  12166. 'UniKS-UCS2-H',
  12167. 'UniKS-UCS2-V',
  12168. 'UniKS-UTF16-H',
  12169. 'UniKS-UTF16-V',
  12170. 'UniKS-UTF32-H',
  12171. 'UniKS-UTF32-V',
  12172. 'UniKS-UTF8-H',
  12173. 'UniKS-UTF8-V',
  12174. 'V',
  12175. 'WP-Symbol'];
  12176. // CMap, not to be confused with TrueType's cmap.
  12177. var CMap = (function CMapClosure() {
  12178. function CMap(builtInCMap) {
  12179. // Codespace ranges are stored as follows:
  12180. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12181. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12182. this.codespaceRanges = [[], [], [], []];
  12183. this.numCodespaceRanges = 0;
  12184. // Map entries have one of two forms.
  12185. // - cid chars are 16-bit unsigned integers, stored as integers.
  12186. // - bf chars are variable-length byte sequences, stored as strings, with
  12187. // one byte per character.
  12188. this._map = [];
  12189. this.name = '';
  12190. this.vertical = false;
  12191. this.useCMap = null;
  12192. this.builtInCMap = builtInCMap;
  12193. }
  12194. CMap.prototype = {
  12195. addCodespaceRange: function(n, low, high) {
  12196. this.codespaceRanges[n - 1].push(low, high);
  12197. this.numCodespaceRanges++;
  12198. },
  12199. mapCidRange: function(low, high, dstLow) {
  12200. while (low <= high) {
  12201. this._map[low++] = dstLow++;
  12202. }
  12203. },
  12204. mapBfRange: function(low, high, dstLow) {
  12205. var lastByte = dstLow.length - 1;
  12206. while (low <= high) {
  12207. this._map[low++] = dstLow;
  12208. // Only the last byte has to be incremented.
  12209. dstLow = dstLow.substr(0, lastByte) +
  12210. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12211. }
  12212. },
  12213. mapBfRangeToArray: function(low, high, array) {
  12214. var i = 0, ii = array.length;
  12215. while (low <= high && i < ii) {
  12216. this._map[low] = array[i++];
  12217. ++low;
  12218. }
  12219. },
  12220. // This is used for both bf and cid chars.
  12221. mapOne: function(src, dst) {
  12222. this._map[src] = dst;
  12223. },
  12224. lookup: function(code) {
  12225. return this._map[code];
  12226. },
  12227. contains: function(code) {
  12228. return this._map[code] !== undefined;
  12229. },
  12230. forEach: function(callback) {
  12231. // Most maps have fewer than 65536 entries, and for those we use normal
  12232. // array iteration. But really sparse tables are possible -- e.g. with
  12233. // indices in the *billions*. For such tables we use for..in, which isn't
  12234. // ideal because it stringifies the indices for all present elements, but
  12235. // it does avoid iterating over every undefined entry.
  12236. var map = this._map;
  12237. var length = map.length;
  12238. var i;
  12239. if (length <= 0x10000) {
  12240. for (i = 0; i < length; i++) {
  12241. if (map[i] !== undefined) {
  12242. callback(i, map[i]);
  12243. }
  12244. }
  12245. } else {
  12246. for (i in this._map) {
  12247. callback(i, map[i]);
  12248. }
  12249. }
  12250. },
  12251. charCodeOf: function(value) {
  12252. return this._map.indexOf(value);
  12253. },
  12254. getMap: function() {
  12255. return this._map;
  12256. },
  12257. readCharCode: function(str, offset, out) {
  12258. var c = 0;
  12259. var codespaceRanges = this.codespaceRanges;
  12260. var codespaceRangesLen = this.codespaceRanges.length;
  12261. // 9.7.6.2 CMap Mapping
  12262. // The code length is at most 4.
  12263. for (var n = 0; n < codespaceRangesLen; n++) {
  12264. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12265. // Check each codespace range to see if it falls within.
  12266. var codespaceRange = codespaceRanges[n];
  12267. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12268. var low = codespaceRange[k++];
  12269. var high = codespaceRange[k++];
  12270. if (c >= low && c <= high) {
  12271. out.charcode = c;
  12272. out.length = n + 1;
  12273. return;
  12274. }
  12275. }
  12276. }
  12277. out.charcode = 0;
  12278. out.length = 1;
  12279. },
  12280. get isIdentityCMap() {
  12281. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12282. return false;
  12283. }
  12284. if (this._map.length !== 0x10000) {
  12285. return false;
  12286. }
  12287. for (var i = 0; i < 0x10000; i++) {
  12288. if (this._map[i] !== i) {
  12289. return false;
  12290. }
  12291. }
  12292. return true;
  12293. }
  12294. };
  12295. return CMap;
  12296. })();
  12297. // A special case of CMap, where the _map array implicitly has a length of
  12298. // 65536 and each element is equal to its index.
  12299. var IdentityCMap = (function IdentityCMapClosure() {
  12300. function IdentityCMap(vertical, n) {
  12301. CMap.call(this);
  12302. this.vertical = vertical;
  12303. this.addCodespaceRange(n, 0, 0xffff);
  12304. }
  12305. Util.inherit(IdentityCMap, CMap, {});
  12306. IdentityCMap.prototype = {
  12307. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12308. mapCidRange: function(low, high, dstLow) {
  12309. error('should not call mapCidRange');
  12310. },
  12311. mapBfRange: function(low, high, dstLow) {
  12312. error('should not call mapBfRange');
  12313. },
  12314. mapBfRangeToArray: function(low, high, array) {
  12315. error('should not call mapBfRangeToArray');
  12316. },
  12317. mapOne: function(src, dst) {
  12318. error('should not call mapCidOne');
  12319. },
  12320. lookup: function(code) {
  12321. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12322. },
  12323. contains: function(code) {
  12324. return isInt(code) && code <= 0xffff;
  12325. },
  12326. forEach: function(callback) {
  12327. for (var i = 0; i <= 0xffff; i++) {
  12328. callback(i, i);
  12329. }
  12330. },
  12331. charCodeOf: function(value) {
  12332. return (isInt(value) && value <= 0xffff) ? value : -1;
  12333. },
  12334. getMap: function() {
  12335. // Sometimes identity maps must be instantiated, but it's rare.
  12336. var map = new Array(0x10000);
  12337. for (var i = 0; i <= 0xffff; i++) {
  12338. map[i] = i;
  12339. }
  12340. return map;
  12341. },
  12342. readCharCode: CMap.prototype.readCharCode,
  12343. get isIdentityCMap() {
  12344. error('should not access .isIdentityCMap');
  12345. }
  12346. };
  12347. return IdentityCMap;
  12348. })();
  12349. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12350. function fetchBinaryData(url) {
  12351. var nonBinaryRequest = PDFJS.disableWorker;
  12352. var request = new XMLHttpRequest();
  12353. request.open('GET', url, false);
  12354. if (!nonBinaryRequest) {
  12355. try {
  12356. request.responseType = 'arraybuffer';
  12357. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12358. } catch (e) {
  12359. nonBinaryRequest = true;
  12360. }
  12361. }
  12362. if (nonBinaryRequest && request.overrideMimeType) {
  12363. request.overrideMimeType('text/plain; charset=x-user-defined');
  12364. }
  12365. request.send(null);
  12366. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12367. error('Unable to get binary cMap at: ' + url);
  12368. }
  12369. if (nonBinaryRequest) {
  12370. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12371. return ch.charCodeAt(0) & 255;
  12372. });
  12373. return new Uint8Array(data);
  12374. }
  12375. return new Uint8Array(request.response);
  12376. }
  12377. function hexToInt(a, size) {
  12378. var n = 0;
  12379. for (var i = 0; i <= size; i++) {
  12380. n = (n << 8) | a[i];
  12381. }
  12382. return n >>> 0;
  12383. }
  12384. function hexToStr(a, size) {
  12385. // This code is hot. Special-case some common values to avoid creating an
  12386. // object with subarray().
  12387. if (size === 1) {
  12388. return String.fromCharCode(a[0], a[1]);
  12389. }
  12390. if (size === 3) {
  12391. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12392. }
  12393. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12394. }
  12395. function addHex(a, b, size) {
  12396. var c = 0;
  12397. for (var i = size; i >= 0; i--) {
  12398. c += a[i] + b[i];
  12399. a[i] = c & 255;
  12400. c >>= 8;
  12401. }
  12402. }
  12403. function incHex(a, size) {
  12404. var c = 1;
  12405. for (var i = size; i >= 0 && c > 0; i--) {
  12406. c += a[i];
  12407. a[i] = c & 255;
  12408. c >>= 8;
  12409. }
  12410. }
  12411. var MAX_NUM_SIZE = 16;
  12412. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12413. function BinaryCMapStream(data) {
  12414. this.buffer = data;
  12415. this.pos = 0;
  12416. this.end = data.length;
  12417. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12418. }
  12419. BinaryCMapStream.prototype = {
  12420. readByte: function () {
  12421. if (this.pos >= this.end) {
  12422. return -1;
  12423. }
  12424. return this.buffer[this.pos++];
  12425. },
  12426. readNumber: function () {
  12427. var n = 0;
  12428. var last;
  12429. do {
  12430. var b = this.readByte();
  12431. if (b < 0) {
  12432. error('unexpected EOF in bcmap');
  12433. }
  12434. last = !(b & 0x80);
  12435. n = (n << 7) | (b & 0x7F);
  12436. } while (!last);
  12437. return n;
  12438. },
  12439. readSigned: function () {
  12440. var n = this.readNumber();
  12441. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12442. },
  12443. readHex: function (num, size) {
  12444. num.set(this.buffer.subarray(this.pos,
  12445. this.pos + size + 1));
  12446. this.pos += size + 1;
  12447. },
  12448. readHexNumber: function (num, size) {
  12449. var last;
  12450. var stack = this.tmpBuf, sp = 0;
  12451. do {
  12452. var b = this.readByte();
  12453. if (b < 0) {
  12454. error('unexpected EOF in bcmap');
  12455. }
  12456. last = !(b & 0x80);
  12457. stack[sp++] = b & 0x7F;
  12458. } while (!last);
  12459. var i = size, buffer = 0, bufferSize = 0;
  12460. while (i >= 0) {
  12461. while (bufferSize < 8 && stack.length > 0) {
  12462. buffer = (stack[--sp] << bufferSize) | buffer;
  12463. bufferSize += 7;
  12464. }
  12465. num[i] = buffer & 255;
  12466. i--;
  12467. buffer >>= 8;
  12468. bufferSize -= 8;
  12469. }
  12470. },
  12471. readHexSigned: function (num, size) {
  12472. this.readHexNumber(num, size);
  12473. var sign = num[size] & 1 ? 255 : 0;
  12474. var c = 0;
  12475. for (var i = 0; i <= size; i++) {
  12476. c = ((c & 1) << 8) | num[i];
  12477. num[i] = (c >> 1) ^ sign;
  12478. }
  12479. },
  12480. readString: function () {
  12481. var len = this.readNumber();
  12482. var s = '';
  12483. for (var i = 0; i < len; i++) {
  12484. s += String.fromCharCode(this.readNumber());
  12485. }
  12486. return s;
  12487. }
  12488. };
  12489. function processBinaryCMap(url, cMap, extend) {
  12490. var data = fetchBinaryData(url);
  12491. var stream = new BinaryCMapStream(data);
  12492. var header = stream.readByte();
  12493. cMap.vertical = !!(header & 1);
  12494. var useCMap = null;
  12495. var start = new Uint8Array(MAX_NUM_SIZE);
  12496. var end = new Uint8Array(MAX_NUM_SIZE);
  12497. var char = new Uint8Array(MAX_NUM_SIZE);
  12498. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12499. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12500. var code;
  12501. var b;
  12502. while ((b = stream.readByte()) >= 0) {
  12503. var type = b >> 5;
  12504. if (type === 7) { // metadata, e.g. comment or usecmap
  12505. switch (b & 0x1F) {
  12506. case 0:
  12507. stream.readString(); // skipping comment
  12508. break;
  12509. case 1:
  12510. useCMap = stream.readString();
  12511. break;
  12512. }
  12513. continue;
  12514. }
  12515. var sequence = !!(b & 0x10);
  12516. var dataSize = b & 15;
  12517. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12518. var ucs2DataSize = 1;
  12519. var subitemsCount = stream.readNumber();
  12520. var i;
  12521. switch (type) {
  12522. case 0: // codespacerange
  12523. stream.readHex(start, dataSize);
  12524. stream.readHexNumber(end, dataSize);
  12525. addHex(end, start, dataSize);
  12526. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12527. hexToInt(end, dataSize));
  12528. for (i = 1; i < subitemsCount; i++) {
  12529. incHex(end, dataSize);
  12530. stream.readHexNumber(start, dataSize);
  12531. addHex(start, end, dataSize);
  12532. stream.readHexNumber(end, dataSize);
  12533. addHex(end, start, dataSize);
  12534. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12535. hexToInt(end, dataSize));
  12536. }
  12537. break;
  12538. case 1: // notdefrange
  12539. stream.readHex(start, dataSize);
  12540. stream.readHexNumber(end, dataSize);
  12541. addHex(end, start, dataSize);
  12542. code = stream.readNumber();
  12543. // undefined range, skipping
  12544. for (i = 1; i < subitemsCount; i++) {
  12545. incHex(end, dataSize);
  12546. stream.readHexNumber(start, dataSize);
  12547. addHex(start, end, dataSize);
  12548. stream.readHexNumber(end, dataSize);
  12549. addHex(end, start, dataSize);
  12550. code = stream.readNumber();
  12551. // nop
  12552. }
  12553. break;
  12554. case 2: // cidchar
  12555. stream.readHex(char, dataSize);
  12556. code = stream.readNumber();
  12557. cMap.mapOne(hexToInt(char, dataSize), code);
  12558. for (i = 1; i < subitemsCount; i++) {
  12559. incHex(char, dataSize);
  12560. if (!sequence) {
  12561. stream.readHexNumber(tmp, dataSize);
  12562. addHex(char, tmp, dataSize);
  12563. }
  12564. code = stream.readSigned() + (code + 1);
  12565. cMap.mapOne(hexToInt(char, dataSize), code);
  12566. }
  12567. break;
  12568. case 3: // cidrange
  12569. stream.readHex(start, dataSize);
  12570. stream.readHexNumber(end, dataSize);
  12571. addHex(end, start, dataSize);
  12572. code = stream.readNumber();
  12573. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12574. code);
  12575. for (i = 1; i < subitemsCount; i++) {
  12576. incHex(end, dataSize);
  12577. if (!sequence) {
  12578. stream.readHexNumber(start, dataSize);
  12579. addHex(start, end, dataSize);
  12580. } else {
  12581. start.set(end);
  12582. }
  12583. stream.readHexNumber(end, dataSize);
  12584. addHex(end, start, dataSize);
  12585. code = stream.readNumber();
  12586. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12587. code);
  12588. }
  12589. break;
  12590. case 4: // bfchar
  12591. stream.readHex(char, ucs2DataSize);
  12592. stream.readHex(charCode, dataSize);
  12593. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12594. hexToStr(charCode, dataSize));
  12595. for (i = 1; i < subitemsCount; i++) {
  12596. incHex(char, ucs2DataSize);
  12597. if (!sequence) {
  12598. stream.readHexNumber(tmp, ucs2DataSize);
  12599. addHex(char, tmp, ucs2DataSize);
  12600. }
  12601. incHex(charCode, dataSize);
  12602. stream.readHexSigned(tmp, dataSize);
  12603. addHex(charCode, tmp, dataSize);
  12604. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12605. hexToStr(charCode, dataSize));
  12606. }
  12607. break;
  12608. case 5: // bfrange
  12609. stream.readHex(start, ucs2DataSize);
  12610. stream.readHexNumber(end, ucs2DataSize);
  12611. addHex(end, start, ucs2DataSize);
  12612. stream.readHex(charCode, dataSize);
  12613. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12614. hexToInt(end, ucs2DataSize),
  12615. hexToStr(charCode, dataSize));
  12616. for (i = 1; i < subitemsCount; i++) {
  12617. incHex(end, ucs2DataSize);
  12618. if (!sequence) {
  12619. stream.readHexNumber(start, ucs2DataSize);
  12620. addHex(start, end, ucs2DataSize);
  12621. } else {
  12622. start.set(end);
  12623. }
  12624. stream.readHexNumber(end, ucs2DataSize);
  12625. addHex(end, start, ucs2DataSize);
  12626. stream.readHex(charCode, dataSize);
  12627. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12628. hexToInt(end, ucs2DataSize),
  12629. hexToStr(charCode, dataSize));
  12630. }
  12631. break;
  12632. default:
  12633. error('Unknown type: ' + type);
  12634. break;
  12635. }
  12636. }
  12637. if (useCMap) {
  12638. extend(useCMap);
  12639. }
  12640. return cMap;
  12641. }
  12642. function BinaryCMapReader() {}
  12643. BinaryCMapReader.prototype = {
  12644. read: processBinaryCMap
  12645. };
  12646. return BinaryCMapReader;
  12647. })();
  12648. var CMapFactory = (function CMapFactoryClosure() {
  12649. function strToInt(str) {
  12650. var a = 0;
  12651. for (var i = 0; i < str.length; i++) {
  12652. a = (a << 8) | str.charCodeAt(i);
  12653. }
  12654. return a >>> 0;
  12655. }
  12656. function expectString(obj) {
  12657. if (!isString(obj)) {
  12658. error('Malformed CMap: expected string.');
  12659. }
  12660. }
  12661. function expectInt(obj) {
  12662. if (!isInt(obj)) {
  12663. error('Malformed CMap: expected int.');
  12664. }
  12665. }
  12666. function parseBfChar(cMap, lexer) {
  12667. while (true) {
  12668. var obj = lexer.getObj();
  12669. if (isEOF(obj)) {
  12670. break;
  12671. }
  12672. if (isCmd(obj, 'endbfchar')) {
  12673. return;
  12674. }
  12675. expectString(obj);
  12676. var src = strToInt(obj);
  12677. obj = lexer.getObj();
  12678. // TODO are /dstName used?
  12679. expectString(obj);
  12680. var dst = obj;
  12681. cMap.mapOne(src, dst);
  12682. }
  12683. }
  12684. function parseBfRange(cMap, lexer) {
  12685. while (true) {
  12686. var obj = lexer.getObj();
  12687. if (isEOF(obj)) {
  12688. break;
  12689. }
  12690. if (isCmd(obj, 'endbfrange')) {
  12691. return;
  12692. }
  12693. expectString(obj);
  12694. var low = strToInt(obj);
  12695. obj = lexer.getObj();
  12696. expectString(obj);
  12697. var high = strToInt(obj);
  12698. obj = lexer.getObj();
  12699. if (isInt(obj) || isString(obj)) {
  12700. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12701. cMap.mapBfRange(low, high, dstLow);
  12702. } else if (isCmd(obj, '[')) {
  12703. obj = lexer.getObj();
  12704. var array = [];
  12705. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12706. array.push(obj);
  12707. obj = lexer.getObj();
  12708. }
  12709. cMap.mapBfRangeToArray(low, high, array);
  12710. } else {
  12711. break;
  12712. }
  12713. }
  12714. error('Invalid bf range.');
  12715. }
  12716. function parseCidChar(cMap, lexer) {
  12717. while (true) {
  12718. var obj = lexer.getObj();
  12719. if (isEOF(obj)) {
  12720. break;
  12721. }
  12722. if (isCmd(obj, 'endcidchar')) {
  12723. return;
  12724. }
  12725. expectString(obj);
  12726. var src = strToInt(obj);
  12727. obj = lexer.getObj();
  12728. expectInt(obj);
  12729. var dst = obj;
  12730. cMap.mapOne(src, dst);
  12731. }
  12732. }
  12733. function parseCidRange(cMap, lexer) {
  12734. while (true) {
  12735. var obj = lexer.getObj();
  12736. if (isEOF(obj)) {
  12737. break;
  12738. }
  12739. if (isCmd(obj, 'endcidrange')) {
  12740. return;
  12741. }
  12742. expectString(obj);
  12743. var low = strToInt(obj);
  12744. obj = lexer.getObj();
  12745. expectString(obj);
  12746. var high = strToInt(obj);
  12747. obj = lexer.getObj();
  12748. expectInt(obj);
  12749. var dstLow = obj;
  12750. cMap.mapCidRange(low, high, dstLow);
  12751. }
  12752. }
  12753. function parseCodespaceRange(cMap, lexer) {
  12754. while (true) {
  12755. var obj = lexer.getObj();
  12756. if (isEOF(obj)) {
  12757. break;
  12758. }
  12759. if (isCmd(obj, 'endcodespacerange')) {
  12760. return;
  12761. }
  12762. if (!isString(obj)) {
  12763. break;
  12764. }
  12765. var low = strToInt(obj);
  12766. obj = lexer.getObj();
  12767. if (!isString(obj)) {
  12768. break;
  12769. }
  12770. var high = strToInt(obj);
  12771. cMap.addCodespaceRange(obj.length, low, high);
  12772. }
  12773. error('Invalid codespace range.');
  12774. }
  12775. function parseWMode(cMap, lexer) {
  12776. var obj = lexer.getObj();
  12777. if (isInt(obj)) {
  12778. cMap.vertical = !!obj;
  12779. }
  12780. }
  12781. function parseCMapName(cMap, lexer) {
  12782. var obj = lexer.getObj();
  12783. if (isName(obj) && isString(obj.name)) {
  12784. cMap.name = obj.name;
  12785. }
  12786. }
  12787. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12788. var previous;
  12789. var embededUseCMap;
  12790. objLoop: while (true) {
  12791. var obj = lexer.getObj();
  12792. if (isEOF(obj)) {
  12793. break;
  12794. } else if (isName(obj)) {
  12795. if (obj.name === 'WMode') {
  12796. parseWMode(cMap, lexer);
  12797. } else if (obj.name === 'CMapName') {
  12798. parseCMapName(cMap, lexer);
  12799. }
  12800. previous = obj;
  12801. } else if (isCmd(obj)) {
  12802. switch (obj.cmd) {
  12803. case 'endcmap':
  12804. break objLoop;
  12805. case 'usecmap':
  12806. if (isName(previous)) {
  12807. embededUseCMap = previous.name;
  12808. }
  12809. break;
  12810. case 'begincodespacerange':
  12811. parseCodespaceRange(cMap, lexer);
  12812. break;
  12813. case 'beginbfchar':
  12814. parseBfChar(cMap, lexer);
  12815. break;
  12816. case 'begincidchar':
  12817. parseCidChar(cMap, lexer);
  12818. break;
  12819. case 'beginbfrange':
  12820. parseBfRange(cMap, lexer);
  12821. break;
  12822. case 'begincidrange':
  12823. parseCidRange(cMap, lexer);
  12824. break;
  12825. }
  12826. }
  12827. }
  12828. if (!useCMap && embededUseCMap) {
  12829. // Load the usecmap definition from the file only if there wasn't one
  12830. // specified.
  12831. useCMap = embededUseCMap;
  12832. }
  12833. if (useCMap) {
  12834. extendCMap(cMap, builtInCMapParams, useCMap);
  12835. }
  12836. }
  12837. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12838. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12839. // If there aren't any code space ranges defined clone all the parent ones
  12840. // into this cMap.
  12841. if (cMap.numCodespaceRanges === 0) {
  12842. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12843. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12844. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12845. }
  12846. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12847. }
  12848. // Merge the map into the current one, making sure not to override
  12849. // any previously defined entries.
  12850. cMap.useCMap.forEach(function(key, value) {
  12851. if (!cMap.contains(key)) {
  12852. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12853. }
  12854. });
  12855. }
  12856. function parseBinaryCMap(name, builtInCMapParams) {
  12857. var url = builtInCMapParams.url + name + '.bcmap';
  12858. var cMap = new CMap(true);
  12859. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12860. extendCMap(cMap, builtInCMapParams, useCMap);
  12861. });
  12862. return cMap;
  12863. }
  12864. function createBuiltInCMap(name, builtInCMapParams) {
  12865. if (name === 'Identity-H') {
  12866. return new IdentityCMap(false, 2);
  12867. } else if (name === 'Identity-V') {
  12868. return new IdentityCMap(true, 2);
  12869. }
  12870. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12871. error('Unknown cMap name: ' + name);
  12872. }
  12873. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12874. if (builtInCMapParams.packed) {
  12875. return parseBinaryCMap(name, builtInCMapParams);
  12876. }
  12877. var request = new XMLHttpRequest();
  12878. var url = builtInCMapParams.url + name;
  12879. request.open('GET', url, false);
  12880. request.send(null);
  12881. if (!request.responseText) {
  12882. error('Unable to get cMap at: ' + url);
  12883. }
  12884. var cMap = new CMap(true);
  12885. var lexer = new Lexer(new StringStream(request.responseText));
  12886. parseCMap(cMap, lexer, builtInCMapParams, null);
  12887. return cMap;
  12888. }
  12889. return {
  12890. create: function (encoding, builtInCMapParams, useCMap) {
  12891. if (isName(encoding)) {
  12892. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12893. } else if (isStream(encoding)) {
  12894. var cMap = new CMap();
  12895. var lexer = new Lexer(encoding);
  12896. try {
  12897. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12898. } catch (e) {
  12899. warn('Invalid CMap data. ' + e);
  12900. }
  12901. if (cMap.isIdentityCMap) {
  12902. return createBuiltInCMap(cMap.name, builtInCMapParams);
  12903. }
  12904. return cMap;
  12905. }
  12906. error('Encoding required.');
  12907. }
  12908. };
  12909. })();
  12910. // Unicode Private Use Area
  12911. var PRIVATE_USE_OFFSET_START = 0xE000;
  12912. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12913. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12914. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12915. // except for Type 3 fonts
  12916. var PDF_GLYPH_SPACE_UNITS = 1000;
  12917. // Hinting is currently disabled due to unknown problems on windows
  12918. // in tracemonkey and various other pdfs with type1 fonts.
  12919. var HINTING_ENABLED = false;
  12920. // Accented charactars are not displayed properly on windows, using this flag
  12921. // to control analysis of seac charstrings.
  12922. var SEAC_ANALYSIS_ENABLED = false;
  12923. var FontFlags = {
  12924. FixedPitch: 1,
  12925. Serif: 2,
  12926. Symbolic: 4,
  12927. Script: 8,
  12928. Nonsymbolic: 32,
  12929. Italic: 64,
  12930. AllCap: 65536,
  12931. SmallCap: 131072,
  12932. ForceBold: 262144
  12933. };
  12934. var Encodings = {
  12935. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12936. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12937. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12938. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12939. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12940. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12941. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12942. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12943. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12944. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12945. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12946. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12947. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12948. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12949. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12950. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12951. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12952. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12953. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12954. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12955. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12956. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12957. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12958. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12959. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12960. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12961. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12962. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12963. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12964. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12965. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12966. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12967. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12968. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12969. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12970. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12971. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12972. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12973. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12974. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12975. 'Ydieresissmall'],
  12976. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12977. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12978. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12979. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12980. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12981. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12982. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12983. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12984. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12985. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12986. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12987. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12988. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12989. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12990. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12991. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12992. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12993. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12994. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12995. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12996. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12997. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12998. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12999. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13000. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13001. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13002. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13003. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13004. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13005. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13006. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13007. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13008. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13009. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13010. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13011. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13012. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13013. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13014. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13015. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13016. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13017. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13018. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13019. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13020. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13021. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13022. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13023. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13024. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13025. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13026. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13027. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13028. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13029. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13030. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13031. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13032. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13033. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13034. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13035. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13036. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13037. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13038. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13039. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13040. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13041. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13042. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13043. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13044. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13045. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13046. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13047. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13048. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13049. 'ogonek', 'caron'],
  13050. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13051. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13052. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13053. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13054. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13055. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13056. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13057. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13058. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13059. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13060. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13061. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13062. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13063. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13064. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13065. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13066. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13067. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13068. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13069. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13070. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13071. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13072. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13073. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13074. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13075. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13076. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13077. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13078. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13079. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13080. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13081. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13082. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13083. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13084. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13085. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13086. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13087. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13088. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13089. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13090. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13091. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13092. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13093. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13094. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13095. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13096. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13097. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13098. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13099. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13100. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13101. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13102. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13103. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13104. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13105. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13106. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13107. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13108. 'ydieresis'],
  13109. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13110. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13111. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13112. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13113. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13114. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13115. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13116. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13117. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13118. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13119. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13120. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13121. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13122. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13123. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13124. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13125. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13126. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13127. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13128. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13129. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13130. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13131. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13132. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13133. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13134. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13135. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13136. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13137. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13138. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13139. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13140. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13141. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13142. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13143. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13144. 'bracerightbt'],
  13145. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13146. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13147. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13148. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13149. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13150. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13151. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13152. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13153. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13154. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13155. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13156. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13157. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13158. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13159. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13160. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13161. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13162. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13163. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13164. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13165. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13166. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13167. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13168. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13169. };
  13170. /**
  13171. * Hold a map of decoded fonts and of the standard fourteen Type1
  13172. * fonts and their acronyms.
  13173. */
  13174. var stdFontMap = {
  13175. 'ArialNarrow': 'Helvetica',
  13176. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13177. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13178. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13179. 'ArialBlack': 'Helvetica',
  13180. 'ArialBlack-Bold': 'Helvetica-Bold',
  13181. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13182. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13183. 'Arial': 'Helvetica',
  13184. 'Arial-Bold': 'Helvetica-Bold',
  13185. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13186. 'Arial-Italic': 'Helvetica-Oblique',
  13187. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13188. 'Arial-BoldMT': 'Helvetica-Bold',
  13189. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13190. 'ArialMT': 'Helvetica',
  13191. 'Courier-Bold': 'Courier-Bold',
  13192. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13193. 'Courier-Italic': 'Courier-Oblique',
  13194. 'CourierNew': 'Courier',
  13195. 'CourierNew-Bold': 'Courier-Bold',
  13196. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13197. 'CourierNew-Italic': 'Courier-Oblique',
  13198. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13199. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13200. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13201. 'CourierNewPSMT': 'Courier',
  13202. 'Helvetica': 'Helvetica',
  13203. 'Helvetica-Bold': 'Helvetica-Bold',
  13204. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13205. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13206. 'Helvetica-Italic': 'Helvetica-Oblique',
  13207. 'Helvetica-Oblique':'Helvetica-Oblique',
  13208. 'Symbol-Bold': 'Symbol',
  13209. 'Symbol-BoldItalic': 'Symbol',
  13210. 'Symbol-Italic': 'Symbol',
  13211. 'TimesNewRoman': 'Times-Roman',
  13212. 'TimesNewRoman-Bold': 'Times-Bold',
  13213. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13214. 'TimesNewRoman-Italic': 'Times-Italic',
  13215. 'TimesNewRomanPS': 'Times-Roman',
  13216. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13217. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13218. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13219. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13220. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13221. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13222. 'TimesNewRomanPSMT': 'Times-Roman',
  13223. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13224. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13225. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13226. };
  13227. /**
  13228. * Holds the map of the non-standard fonts that might be included as a standard
  13229. * fonts without glyph data.
  13230. */
  13231. var nonStdFontMap = {
  13232. 'CenturyGothic': 'Helvetica',
  13233. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13234. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13235. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13236. 'ComicSansMS': 'Comic Sans MS',
  13237. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13238. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13239. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13240. 'LucidaConsole': 'Courier',
  13241. 'LucidaConsole-Bold': 'Courier-Bold',
  13242. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13243. 'LucidaConsole-Italic': 'Courier-Oblique',
  13244. 'MS-Gothic': 'MS Gothic',
  13245. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13246. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13247. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13248. 'MS-Mincho': 'MS Mincho',
  13249. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13250. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13251. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13252. 'MS-PGothic': 'MS PGothic',
  13253. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13254. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13255. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13256. 'MS-PMincho': 'MS PMincho',
  13257. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13258. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13259. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13260. 'Wingdings': 'ZapfDingbats'
  13261. };
  13262. var serifFonts = {
  13263. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13264. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13265. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13266. 'Arno': true, 'Aster': true, 'Aurora': true,
  13267. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13268. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13269. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13270. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13271. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13272. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13273. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13274. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13275. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13276. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13277. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13278. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13279. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13280. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13281. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13282. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13283. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13284. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13285. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13286. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13287. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13288. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13289. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13290. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13291. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13292. 'Miller': true, 'Minion': true, 'Modern': true,
  13293. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13294. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13295. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13296. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13297. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13298. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13299. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13300. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13301. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13302. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13303. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13304. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13305. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13306. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13307. };
  13308. var symbolsFonts = {
  13309. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13310. };
  13311. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13312. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13313. // glyphs, but common for some set of the standard fonts.
  13314. var GlyphMapForStandardFonts = {
  13315. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13316. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13317. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13318. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13319. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13320. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13321. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13322. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13323. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13324. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13325. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13326. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13327. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13328. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13329. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13330. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13331. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13332. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13333. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13334. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13335. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13336. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13337. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13338. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13339. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13340. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13341. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13342. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13343. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13344. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13345. '298': 380, '305': 963,
  13346. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13347. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13348. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13349. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13350. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13351. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13352. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13353. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13354. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13355. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13356. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13357. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13358. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13359. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13360. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13361. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13362. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13363. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13364. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13365. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13366. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13367. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13368. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13369. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13370. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13371. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13372. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13373. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13374. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13375. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13376. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13377. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13378. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13379. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13380. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13381. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13382. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13383. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13384. };
  13385. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13386. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13387. // to the similar equivalents in the normal characters range.
  13388. var SpecialPUASymbols = {
  13389. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13390. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13391. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13392. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13393. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13394. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13395. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13396. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13397. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13398. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13399. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13400. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13401. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13402. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13403. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13404. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13405. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13406. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13407. '63723': 0x239B, // parenlefttp (0xF8EB)
  13408. '63724': 0x239C, // parenleftex (0xF8EC)
  13409. '63725': 0x239D, // parenleftbt (0xF8ED)
  13410. '63734': 0x239E, // parenrighttp (0xF8F6)
  13411. '63735': 0x239F, // parenrightex (0xF8F7)
  13412. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13413. };
  13414. function mapSpecialUnicodeValues(code) {
  13415. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13416. return 0;
  13417. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13418. return (SpecialPUASymbols[code] || code);
  13419. }
  13420. return code;
  13421. }
  13422. var UnicodeRanges = [
  13423. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13424. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13425. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13426. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13427. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13428. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13429. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13430. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13431. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13432. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13433. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13434. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13435. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13436. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13437. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13438. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13439. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13440. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13441. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13442. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13443. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13444. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13445. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13446. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13447. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13448. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13449. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13450. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13451. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13452. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13453. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13454. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13455. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13456. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13457. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13458. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13459. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13460. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13461. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13462. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13463. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13464. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13465. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13466. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13467. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13468. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13469. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13470. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13471. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13472. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13473. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13474. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13475. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13476. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13477. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13478. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13479. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13480. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13481. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13482. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13483. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13484. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13485. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13486. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13487. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13488. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13489. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13490. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13491. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13492. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13493. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13494. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13495. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13496. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13497. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13498. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13499. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13500. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13501. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13502. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13503. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13504. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13505. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13506. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13507. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13508. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13509. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13510. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13511. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13512. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13513. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13514. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13515. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13516. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13517. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13518. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13519. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13520. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13521. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13522. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13523. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13524. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13525. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13526. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13527. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13528. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13529. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13530. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13531. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13532. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13533. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13534. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13535. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13536. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13537. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13538. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13539. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13540. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13541. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13542. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13543. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13544. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13545. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13546. ];
  13547. var MacStandardGlyphOrdering = [
  13548. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13549. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13550. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13551. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13552. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13553. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13554. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13555. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13556. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13557. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13558. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13559. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13560. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13561. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13562. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13563. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13564. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13565. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13566. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13567. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13568. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13569. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13570. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13571. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13572. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13573. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13574. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13575. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13576. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13577. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13578. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13579. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13580. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13581. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13582. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13583. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13584. function getUnicodeRangeFor(value) {
  13585. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13586. var range = UnicodeRanges[i];
  13587. if (value >= range.begin && value < range.end) {
  13588. return i;
  13589. }
  13590. }
  13591. return -1;
  13592. }
  13593. function isRTLRangeFor(value) {
  13594. var range = UnicodeRanges[13];
  13595. if (value >= range.begin && value < range.end) {
  13596. return true;
  13597. }
  13598. range = UnicodeRanges[11];
  13599. if (value >= range.begin && value < range.end) {
  13600. return true;
  13601. }
  13602. return false;
  13603. }
  13604. // The normalization table is obtained by filtering the Unicode characters
  13605. // database with <compat> entries.
  13606. var NormalizedUnicodes = {
  13607. '\u00A8': '\u0020\u0308',
  13608. '\u00AF': '\u0020\u0304',
  13609. '\u00B4': '\u0020\u0301',
  13610. '\u00B5': '\u03BC',
  13611. '\u00B8': '\u0020\u0327',
  13612. '\u0132': '\u0049\u004A',
  13613. '\u0133': '\u0069\u006A',
  13614. '\u013F': '\u004C\u00B7',
  13615. '\u0140': '\u006C\u00B7',
  13616. '\u0149': '\u02BC\u006E',
  13617. '\u017F': '\u0073',
  13618. '\u01C4': '\u0044\u017D',
  13619. '\u01C5': '\u0044\u017E',
  13620. '\u01C6': '\u0064\u017E',
  13621. '\u01C7': '\u004C\u004A',
  13622. '\u01C8': '\u004C\u006A',
  13623. '\u01C9': '\u006C\u006A',
  13624. '\u01CA': '\u004E\u004A',
  13625. '\u01CB': '\u004E\u006A',
  13626. '\u01CC': '\u006E\u006A',
  13627. '\u01F1': '\u0044\u005A',
  13628. '\u01F2': '\u0044\u007A',
  13629. '\u01F3': '\u0064\u007A',
  13630. '\u02D8': '\u0020\u0306',
  13631. '\u02D9': '\u0020\u0307',
  13632. '\u02DA': '\u0020\u030A',
  13633. '\u02DB': '\u0020\u0328',
  13634. '\u02DC': '\u0020\u0303',
  13635. '\u02DD': '\u0020\u030B',
  13636. '\u037A': '\u0020\u0345',
  13637. '\u0384': '\u0020\u0301',
  13638. '\u03D0': '\u03B2',
  13639. '\u03D1': '\u03B8',
  13640. '\u03D2': '\u03A5',
  13641. '\u03D5': '\u03C6',
  13642. '\u03D6': '\u03C0',
  13643. '\u03F0': '\u03BA',
  13644. '\u03F1': '\u03C1',
  13645. '\u03F2': '\u03C2',
  13646. '\u03F4': '\u0398',
  13647. '\u03F5': '\u03B5',
  13648. '\u03F9': '\u03A3',
  13649. '\u0587': '\u0565\u0582',
  13650. '\u0675': '\u0627\u0674',
  13651. '\u0676': '\u0648\u0674',
  13652. '\u0677': '\u06C7\u0674',
  13653. '\u0678': '\u064A\u0674',
  13654. '\u0E33': '\u0E4D\u0E32',
  13655. '\u0EB3': '\u0ECD\u0EB2',
  13656. '\u0EDC': '\u0EAB\u0E99',
  13657. '\u0EDD': '\u0EAB\u0EA1',
  13658. '\u0F77': '\u0FB2\u0F81',
  13659. '\u0F79': '\u0FB3\u0F81',
  13660. '\u1E9A': '\u0061\u02BE',
  13661. '\u1FBD': '\u0020\u0313',
  13662. '\u1FBF': '\u0020\u0313',
  13663. '\u1FC0': '\u0020\u0342',
  13664. '\u1FFE': '\u0020\u0314',
  13665. '\u2002': '\u0020',
  13666. '\u2003': '\u0020',
  13667. '\u2004': '\u0020',
  13668. '\u2005': '\u0020',
  13669. '\u2006': '\u0020',
  13670. '\u2008': '\u0020',
  13671. '\u2009': '\u0020',
  13672. '\u200A': '\u0020',
  13673. '\u2017': '\u0020\u0333',
  13674. '\u2024': '\u002E',
  13675. '\u2025': '\u002E\u002E',
  13676. '\u2026': '\u002E\u002E\u002E',
  13677. '\u2033': '\u2032\u2032',
  13678. '\u2034': '\u2032\u2032\u2032',
  13679. '\u2036': '\u2035\u2035',
  13680. '\u2037': '\u2035\u2035\u2035',
  13681. '\u203C': '\u0021\u0021',
  13682. '\u203E': '\u0020\u0305',
  13683. '\u2047': '\u003F\u003F',
  13684. '\u2048': '\u003F\u0021',
  13685. '\u2049': '\u0021\u003F',
  13686. '\u2057': '\u2032\u2032\u2032\u2032',
  13687. '\u205F': '\u0020',
  13688. '\u20A8': '\u0052\u0073',
  13689. '\u2100': '\u0061\u002F\u0063',
  13690. '\u2101': '\u0061\u002F\u0073',
  13691. '\u2103': '\u00B0\u0043',
  13692. '\u2105': '\u0063\u002F\u006F',
  13693. '\u2106': '\u0063\u002F\u0075',
  13694. '\u2107': '\u0190',
  13695. '\u2109': '\u00B0\u0046',
  13696. '\u2116': '\u004E\u006F',
  13697. '\u2121': '\u0054\u0045\u004C',
  13698. '\u2135': '\u05D0',
  13699. '\u2136': '\u05D1',
  13700. '\u2137': '\u05D2',
  13701. '\u2138': '\u05D3',
  13702. '\u213B': '\u0046\u0041\u0058',
  13703. '\u2160': '\u0049',
  13704. '\u2161': '\u0049\u0049',
  13705. '\u2162': '\u0049\u0049\u0049',
  13706. '\u2163': '\u0049\u0056',
  13707. '\u2164': '\u0056',
  13708. '\u2165': '\u0056\u0049',
  13709. '\u2166': '\u0056\u0049\u0049',
  13710. '\u2167': '\u0056\u0049\u0049\u0049',
  13711. '\u2168': '\u0049\u0058',
  13712. '\u2169': '\u0058',
  13713. '\u216A': '\u0058\u0049',
  13714. '\u216B': '\u0058\u0049\u0049',
  13715. '\u216C': '\u004C',
  13716. '\u216D': '\u0043',
  13717. '\u216E': '\u0044',
  13718. '\u216F': '\u004D',
  13719. '\u2170': '\u0069',
  13720. '\u2171': '\u0069\u0069',
  13721. '\u2172': '\u0069\u0069\u0069',
  13722. '\u2173': '\u0069\u0076',
  13723. '\u2174': '\u0076',
  13724. '\u2175': '\u0076\u0069',
  13725. '\u2176': '\u0076\u0069\u0069',
  13726. '\u2177': '\u0076\u0069\u0069\u0069',
  13727. '\u2178': '\u0069\u0078',
  13728. '\u2179': '\u0078',
  13729. '\u217A': '\u0078\u0069',
  13730. '\u217B': '\u0078\u0069\u0069',
  13731. '\u217C': '\u006C',
  13732. '\u217D': '\u0063',
  13733. '\u217E': '\u0064',
  13734. '\u217F': '\u006D',
  13735. '\u222C': '\u222B\u222B',
  13736. '\u222D': '\u222B\u222B\u222B',
  13737. '\u222F': '\u222E\u222E',
  13738. '\u2230': '\u222E\u222E\u222E',
  13739. '\u2474': '\u0028\u0031\u0029',
  13740. '\u2475': '\u0028\u0032\u0029',
  13741. '\u2476': '\u0028\u0033\u0029',
  13742. '\u2477': '\u0028\u0034\u0029',
  13743. '\u2478': '\u0028\u0035\u0029',
  13744. '\u2479': '\u0028\u0036\u0029',
  13745. '\u247A': '\u0028\u0037\u0029',
  13746. '\u247B': '\u0028\u0038\u0029',
  13747. '\u247C': '\u0028\u0039\u0029',
  13748. '\u247D': '\u0028\u0031\u0030\u0029',
  13749. '\u247E': '\u0028\u0031\u0031\u0029',
  13750. '\u247F': '\u0028\u0031\u0032\u0029',
  13751. '\u2480': '\u0028\u0031\u0033\u0029',
  13752. '\u2481': '\u0028\u0031\u0034\u0029',
  13753. '\u2482': '\u0028\u0031\u0035\u0029',
  13754. '\u2483': '\u0028\u0031\u0036\u0029',
  13755. '\u2484': '\u0028\u0031\u0037\u0029',
  13756. '\u2485': '\u0028\u0031\u0038\u0029',
  13757. '\u2486': '\u0028\u0031\u0039\u0029',
  13758. '\u2487': '\u0028\u0032\u0030\u0029',
  13759. '\u2488': '\u0031\u002E',
  13760. '\u2489': '\u0032\u002E',
  13761. '\u248A': '\u0033\u002E',
  13762. '\u248B': '\u0034\u002E',
  13763. '\u248C': '\u0035\u002E',
  13764. '\u248D': '\u0036\u002E',
  13765. '\u248E': '\u0037\u002E',
  13766. '\u248F': '\u0038\u002E',
  13767. '\u2490': '\u0039\u002E',
  13768. '\u2491': '\u0031\u0030\u002E',
  13769. '\u2492': '\u0031\u0031\u002E',
  13770. '\u2493': '\u0031\u0032\u002E',
  13771. '\u2494': '\u0031\u0033\u002E',
  13772. '\u2495': '\u0031\u0034\u002E',
  13773. '\u2496': '\u0031\u0035\u002E',
  13774. '\u2497': '\u0031\u0036\u002E',
  13775. '\u2498': '\u0031\u0037\u002E',
  13776. '\u2499': '\u0031\u0038\u002E',
  13777. '\u249A': '\u0031\u0039\u002E',
  13778. '\u249B': '\u0032\u0030\u002E',
  13779. '\u249C': '\u0028\u0061\u0029',
  13780. '\u249D': '\u0028\u0062\u0029',
  13781. '\u249E': '\u0028\u0063\u0029',
  13782. '\u249F': '\u0028\u0064\u0029',
  13783. '\u24A0': '\u0028\u0065\u0029',
  13784. '\u24A1': '\u0028\u0066\u0029',
  13785. '\u24A2': '\u0028\u0067\u0029',
  13786. '\u24A3': '\u0028\u0068\u0029',
  13787. '\u24A4': '\u0028\u0069\u0029',
  13788. '\u24A5': '\u0028\u006A\u0029',
  13789. '\u24A6': '\u0028\u006B\u0029',
  13790. '\u24A7': '\u0028\u006C\u0029',
  13791. '\u24A8': '\u0028\u006D\u0029',
  13792. '\u24A9': '\u0028\u006E\u0029',
  13793. '\u24AA': '\u0028\u006F\u0029',
  13794. '\u24AB': '\u0028\u0070\u0029',
  13795. '\u24AC': '\u0028\u0071\u0029',
  13796. '\u24AD': '\u0028\u0072\u0029',
  13797. '\u24AE': '\u0028\u0073\u0029',
  13798. '\u24AF': '\u0028\u0074\u0029',
  13799. '\u24B0': '\u0028\u0075\u0029',
  13800. '\u24B1': '\u0028\u0076\u0029',
  13801. '\u24B2': '\u0028\u0077\u0029',
  13802. '\u24B3': '\u0028\u0078\u0029',
  13803. '\u24B4': '\u0028\u0079\u0029',
  13804. '\u24B5': '\u0028\u007A\u0029',
  13805. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13806. '\u2A74': '\u003A\u003A\u003D',
  13807. '\u2A75': '\u003D\u003D',
  13808. '\u2A76': '\u003D\u003D\u003D',
  13809. '\u2E9F': '\u6BCD',
  13810. '\u2EF3': '\u9F9F',
  13811. '\u2F00': '\u4E00',
  13812. '\u2F01': '\u4E28',
  13813. '\u2F02': '\u4E36',
  13814. '\u2F03': '\u4E3F',
  13815. '\u2F04': '\u4E59',
  13816. '\u2F05': '\u4E85',
  13817. '\u2F06': '\u4E8C',
  13818. '\u2F07': '\u4EA0',
  13819. '\u2F08': '\u4EBA',
  13820. '\u2F09': '\u513F',
  13821. '\u2F0A': '\u5165',
  13822. '\u2F0B': '\u516B',
  13823. '\u2F0C': '\u5182',
  13824. '\u2F0D': '\u5196',
  13825. '\u2F0E': '\u51AB',
  13826. '\u2F0F': '\u51E0',
  13827. '\u2F10': '\u51F5',
  13828. '\u2F11': '\u5200',
  13829. '\u2F12': '\u529B',
  13830. '\u2F13': '\u52F9',
  13831. '\u2F14': '\u5315',
  13832. '\u2F15': '\u531A',
  13833. '\u2F16': '\u5338',
  13834. '\u2F17': '\u5341',
  13835. '\u2F18': '\u535C',
  13836. '\u2F19': '\u5369',
  13837. '\u2F1A': '\u5382',
  13838. '\u2F1B': '\u53B6',
  13839. '\u2F1C': '\u53C8',
  13840. '\u2F1D': '\u53E3',
  13841. '\u2F1E': '\u56D7',
  13842. '\u2F1F': '\u571F',
  13843. '\u2F20': '\u58EB',
  13844. '\u2F21': '\u5902',
  13845. '\u2F22': '\u590A',
  13846. '\u2F23': '\u5915',
  13847. '\u2F24': '\u5927',
  13848. '\u2F25': '\u5973',
  13849. '\u2F26': '\u5B50',
  13850. '\u2F27': '\u5B80',
  13851. '\u2F28': '\u5BF8',
  13852. '\u2F29': '\u5C0F',
  13853. '\u2F2A': '\u5C22',
  13854. '\u2F2B': '\u5C38',
  13855. '\u2F2C': '\u5C6E',
  13856. '\u2F2D': '\u5C71',
  13857. '\u2F2E': '\u5DDB',
  13858. '\u2F2F': '\u5DE5',
  13859. '\u2F30': '\u5DF1',
  13860. '\u2F31': '\u5DFE',
  13861. '\u2F32': '\u5E72',
  13862. '\u2F33': '\u5E7A',
  13863. '\u2F34': '\u5E7F',
  13864. '\u2F35': '\u5EF4',
  13865. '\u2F36': '\u5EFE',
  13866. '\u2F37': '\u5F0B',
  13867. '\u2F38': '\u5F13',
  13868. '\u2F39': '\u5F50',
  13869. '\u2F3A': '\u5F61',
  13870. '\u2F3B': '\u5F73',
  13871. '\u2F3C': '\u5FC3',
  13872. '\u2F3D': '\u6208',
  13873. '\u2F3E': '\u6236',
  13874. '\u2F3F': '\u624B',
  13875. '\u2F40': '\u652F',
  13876. '\u2F41': '\u6534',
  13877. '\u2F42': '\u6587',
  13878. '\u2F43': '\u6597',
  13879. '\u2F44': '\u65A4',
  13880. '\u2F45': '\u65B9',
  13881. '\u2F46': '\u65E0',
  13882. '\u2F47': '\u65E5',
  13883. '\u2F48': '\u66F0',
  13884. '\u2F49': '\u6708',
  13885. '\u2F4A': '\u6728',
  13886. '\u2F4B': '\u6B20',
  13887. '\u2F4C': '\u6B62',
  13888. '\u2F4D': '\u6B79',
  13889. '\u2F4E': '\u6BB3',
  13890. '\u2F4F': '\u6BCB',
  13891. '\u2F50': '\u6BD4',
  13892. '\u2F51': '\u6BDB',
  13893. '\u2F52': '\u6C0F',
  13894. '\u2F53': '\u6C14',
  13895. '\u2F54': '\u6C34',
  13896. '\u2F55': '\u706B',
  13897. '\u2F56': '\u722A',
  13898. '\u2F57': '\u7236',
  13899. '\u2F58': '\u723B',
  13900. '\u2F59': '\u723F',
  13901. '\u2F5A': '\u7247',
  13902. '\u2F5B': '\u7259',
  13903. '\u2F5C': '\u725B',
  13904. '\u2F5D': '\u72AC',
  13905. '\u2F5E': '\u7384',
  13906. '\u2F5F': '\u7389',
  13907. '\u2F60': '\u74DC',
  13908. '\u2F61': '\u74E6',
  13909. '\u2F62': '\u7518',
  13910. '\u2F63': '\u751F',
  13911. '\u2F64': '\u7528',
  13912. '\u2F65': '\u7530',
  13913. '\u2F66': '\u758B',
  13914. '\u2F67': '\u7592',
  13915. '\u2F68': '\u7676',
  13916. '\u2F69': '\u767D',
  13917. '\u2F6A': '\u76AE',
  13918. '\u2F6B': '\u76BF',
  13919. '\u2F6C': '\u76EE',
  13920. '\u2F6D': '\u77DB',
  13921. '\u2F6E': '\u77E2',
  13922. '\u2F6F': '\u77F3',
  13923. '\u2F70': '\u793A',
  13924. '\u2F71': '\u79B8',
  13925. '\u2F72': '\u79BE',
  13926. '\u2F73': '\u7A74',
  13927. '\u2F74': '\u7ACB',
  13928. '\u2F75': '\u7AF9',
  13929. '\u2F76': '\u7C73',
  13930. '\u2F77': '\u7CF8',
  13931. '\u2F78': '\u7F36',
  13932. '\u2F79': '\u7F51',
  13933. '\u2F7A': '\u7F8A',
  13934. '\u2F7B': '\u7FBD',
  13935. '\u2F7C': '\u8001',
  13936. '\u2F7D': '\u800C',
  13937. '\u2F7E': '\u8012',
  13938. '\u2F7F': '\u8033',
  13939. '\u2F80': '\u807F',
  13940. '\u2F81': '\u8089',
  13941. '\u2F82': '\u81E3',
  13942. '\u2F83': '\u81EA',
  13943. '\u2F84': '\u81F3',
  13944. '\u2F85': '\u81FC',
  13945. '\u2F86': '\u820C',
  13946. '\u2F87': '\u821B',
  13947. '\u2F88': '\u821F',
  13948. '\u2F89': '\u826E',
  13949. '\u2F8A': '\u8272',
  13950. '\u2F8B': '\u8278',
  13951. '\u2F8C': '\u864D',
  13952. '\u2F8D': '\u866B',
  13953. '\u2F8E': '\u8840',
  13954. '\u2F8F': '\u884C',
  13955. '\u2F90': '\u8863',
  13956. '\u2F91': '\u897E',
  13957. '\u2F92': '\u898B',
  13958. '\u2F93': '\u89D2',
  13959. '\u2F94': '\u8A00',
  13960. '\u2F95': '\u8C37',
  13961. '\u2F96': '\u8C46',
  13962. '\u2F97': '\u8C55',
  13963. '\u2F98': '\u8C78',
  13964. '\u2F99': '\u8C9D',
  13965. '\u2F9A': '\u8D64',
  13966. '\u2F9B': '\u8D70',
  13967. '\u2F9C': '\u8DB3',
  13968. '\u2F9D': '\u8EAB',
  13969. '\u2F9E': '\u8ECA',
  13970. '\u2F9F': '\u8F9B',
  13971. '\u2FA0': '\u8FB0',
  13972. '\u2FA1': '\u8FB5',
  13973. '\u2FA2': '\u9091',
  13974. '\u2FA3': '\u9149',
  13975. '\u2FA4': '\u91C6',
  13976. '\u2FA5': '\u91CC',
  13977. '\u2FA6': '\u91D1',
  13978. '\u2FA7': '\u9577',
  13979. '\u2FA8': '\u9580',
  13980. '\u2FA9': '\u961C',
  13981. '\u2FAA': '\u96B6',
  13982. '\u2FAB': '\u96B9',
  13983. '\u2FAC': '\u96E8',
  13984. '\u2FAD': '\u9751',
  13985. '\u2FAE': '\u975E',
  13986. '\u2FAF': '\u9762',
  13987. '\u2FB0': '\u9769',
  13988. '\u2FB1': '\u97CB',
  13989. '\u2FB2': '\u97ED',
  13990. '\u2FB3': '\u97F3',
  13991. '\u2FB4': '\u9801',
  13992. '\u2FB5': '\u98A8',
  13993. '\u2FB6': '\u98DB',
  13994. '\u2FB7': '\u98DF',
  13995. '\u2FB8': '\u9996',
  13996. '\u2FB9': '\u9999',
  13997. '\u2FBA': '\u99AC',
  13998. '\u2FBB': '\u9AA8',
  13999. '\u2FBC': '\u9AD8',
  14000. '\u2FBD': '\u9ADF',
  14001. '\u2FBE': '\u9B25',
  14002. '\u2FBF': '\u9B2F',
  14003. '\u2FC0': '\u9B32',
  14004. '\u2FC1': '\u9B3C',
  14005. '\u2FC2': '\u9B5A',
  14006. '\u2FC3': '\u9CE5',
  14007. '\u2FC4': '\u9E75',
  14008. '\u2FC5': '\u9E7F',
  14009. '\u2FC6': '\u9EA5',
  14010. '\u2FC7': '\u9EBB',
  14011. '\u2FC8': '\u9EC3',
  14012. '\u2FC9': '\u9ECD',
  14013. '\u2FCA': '\u9ED1',
  14014. '\u2FCB': '\u9EF9',
  14015. '\u2FCC': '\u9EFD',
  14016. '\u2FCD': '\u9F0E',
  14017. '\u2FCE': '\u9F13',
  14018. '\u2FCF': '\u9F20',
  14019. '\u2FD0': '\u9F3B',
  14020. '\u2FD1': '\u9F4A',
  14021. '\u2FD2': '\u9F52',
  14022. '\u2FD3': '\u9F8D',
  14023. '\u2FD4': '\u9F9C',
  14024. '\u2FD5': '\u9FA0',
  14025. '\u3036': '\u3012',
  14026. '\u3038': '\u5341',
  14027. '\u3039': '\u5344',
  14028. '\u303A': '\u5345',
  14029. '\u309B': '\u0020\u3099',
  14030. '\u309C': '\u0020\u309A',
  14031. '\u3131': '\u1100',
  14032. '\u3132': '\u1101',
  14033. '\u3133': '\u11AA',
  14034. '\u3134': '\u1102',
  14035. '\u3135': '\u11AC',
  14036. '\u3136': '\u11AD',
  14037. '\u3137': '\u1103',
  14038. '\u3138': '\u1104',
  14039. '\u3139': '\u1105',
  14040. '\u313A': '\u11B0',
  14041. '\u313B': '\u11B1',
  14042. '\u313C': '\u11B2',
  14043. '\u313D': '\u11B3',
  14044. '\u313E': '\u11B4',
  14045. '\u313F': '\u11B5',
  14046. '\u3140': '\u111A',
  14047. '\u3141': '\u1106',
  14048. '\u3142': '\u1107',
  14049. '\u3143': '\u1108',
  14050. '\u3144': '\u1121',
  14051. '\u3145': '\u1109',
  14052. '\u3146': '\u110A',
  14053. '\u3147': '\u110B',
  14054. '\u3148': '\u110C',
  14055. '\u3149': '\u110D',
  14056. '\u314A': '\u110E',
  14057. '\u314B': '\u110F',
  14058. '\u314C': '\u1110',
  14059. '\u314D': '\u1111',
  14060. '\u314E': '\u1112',
  14061. '\u314F': '\u1161',
  14062. '\u3150': '\u1162',
  14063. '\u3151': '\u1163',
  14064. '\u3152': '\u1164',
  14065. '\u3153': '\u1165',
  14066. '\u3154': '\u1166',
  14067. '\u3155': '\u1167',
  14068. '\u3156': '\u1168',
  14069. '\u3157': '\u1169',
  14070. '\u3158': '\u116A',
  14071. '\u3159': '\u116B',
  14072. '\u315A': '\u116C',
  14073. '\u315B': '\u116D',
  14074. '\u315C': '\u116E',
  14075. '\u315D': '\u116F',
  14076. '\u315E': '\u1170',
  14077. '\u315F': '\u1171',
  14078. '\u3160': '\u1172',
  14079. '\u3161': '\u1173',
  14080. '\u3162': '\u1174',
  14081. '\u3163': '\u1175',
  14082. '\u3164': '\u1160',
  14083. '\u3165': '\u1114',
  14084. '\u3166': '\u1115',
  14085. '\u3167': '\u11C7',
  14086. '\u3168': '\u11C8',
  14087. '\u3169': '\u11CC',
  14088. '\u316A': '\u11CE',
  14089. '\u316B': '\u11D3',
  14090. '\u316C': '\u11D7',
  14091. '\u316D': '\u11D9',
  14092. '\u316E': '\u111C',
  14093. '\u316F': '\u11DD',
  14094. '\u3170': '\u11DF',
  14095. '\u3171': '\u111D',
  14096. '\u3172': '\u111E',
  14097. '\u3173': '\u1120',
  14098. '\u3174': '\u1122',
  14099. '\u3175': '\u1123',
  14100. '\u3176': '\u1127',
  14101. '\u3177': '\u1129',
  14102. '\u3178': '\u112B',
  14103. '\u3179': '\u112C',
  14104. '\u317A': '\u112D',
  14105. '\u317B': '\u112E',
  14106. '\u317C': '\u112F',
  14107. '\u317D': '\u1132',
  14108. '\u317E': '\u1136',
  14109. '\u317F': '\u1140',
  14110. '\u3180': '\u1147',
  14111. '\u3181': '\u114C',
  14112. '\u3182': '\u11F1',
  14113. '\u3183': '\u11F2',
  14114. '\u3184': '\u1157',
  14115. '\u3185': '\u1158',
  14116. '\u3186': '\u1159',
  14117. '\u3187': '\u1184',
  14118. '\u3188': '\u1185',
  14119. '\u3189': '\u1188',
  14120. '\u318A': '\u1191',
  14121. '\u318B': '\u1192',
  14122. '\u318C': '\u1194',
  14123. '\u318D': '\u119E',
  14124. '\u318E': '\u11A1',
  14125. '\u3200': '\u0028\u1100\u0029',
  14126. '\u3201': '\u0028\u1102\u0029',
  14127. '\u3202': '\u0028\u1103\u0029',
  14128. '\u3203': '\u0028\u1105\u0029',
  14129. '\u3204': '\u0028\u1106\u0029',
  14130. '\u3205': '\u0028\u1107\u0029',
  14131. '\u3206': '\u0028\u1109\u0029',
  14132. '\u3207': '\u0028\u110B\u0029',
  14133. '\u3208': '\u0028\u110C\u0029',
  14134. '\u3209': '\u0028\u110E\u0029',
  14135. '\u320A': '\u0028\u110F\u0029',
  14136. '\u320B': '\u0028\u1110\u0029',
  14137. '\u320C': '\u0028\u1111\u0029',
  14138. '\u320D': '\u0028\u1112\u0029',
  14139. '\u320E': '\u0028\u1100\u1161\u0029',
  14140. '\u320F': '\u0028\u1102\u1161\u0029',
  14141. '\u3210': '\u0028\u1103\u1161\u0029',
  14142. '\u3211': '\u0028\u1105\u1161\u0029',
  14143. '\u3212': '\u0028\u1106\u1161\u0029',
  14144. '\u3213': '\u0028\u1107\u1161\u0029',
  14145. '\u3214': '\u0028\u1109\u1161\u0029',
  14146. '\u3215': '\u0028\u110B\u1161\u0029',
  14147. '\u3216': '\u0028\u110C\u1161\u0029',
  14148. '\u3217': '\u0028\u110E\u1161\u0029',
  14149. '\u3218': '\u0028\u110F\u1161\u0029',
  14150. '\u3219': '\u0028\u1110\u1161\u0029',
  14151. '\u321A': '\u0028\u1111\u1161\u0029',
  14152. '\u321B': '\u0028\u1112\u1161\u0029',
  14153. '\u321C': '\u0028\u110C\u116E\u0029',
  14154. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14155. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14156. '\u3220': '\u0028\u4E00\u0029',
  14157. '\u3221': '\u0028\u4E8C\u0029',
  14158. '\u3222': '\u0028\u4E09\u0029',
  14159. '\u3223': '\u0028\u56DB\u0029',
  14160. '\u3224': '\u0028\u4E94\u0029',
  14161. '\u3225': '\u0028\u516D\u0029',
  14162. '\u3226': '\u0028\u4E03\u0029',
  14163. '\u3227': '\u0028\u516B\u0029',
  14164. '\u3228': '\u0028\u4E5D\u0029',
  14165. '\u3229': '\u0028\u5341\u0029',
  14166. '\u322A': '\u0028\u6708\u0029',
  14167. '\u322B': '\u0028\u706B\u0029',
  14168. '\u322C': '\u0028\u6C34\u0029',
  14169. '\u322D': '\u0028\u6728\u0029',
  14170. '\u322E': '\u0028\u91D1\u0029',
  14171. '\u322F': '\u0028\u571F\u0029',
  14172. '\u3230': '\u0028\u65E5\u0029',
  14173. '\u3231': '\u0028\u682A\u0029',
  14174. '\u3232': '\u0028\u6709\u0029',
  14175. '\u3233': '\u0028\u793E\u0029',
  14176. '\u3234': '\u0028\u540D\u0029',
  14177. '\u3235': '\u0028\u7279\u0029',
  14178. '\u3236': '\u0028\u8CA1\u0029',
  14179. '\u3237': '\u0028\u795D\u0029',
  14180. '\u3238': '\u0028\u52B4\u0029',
  14181. '\u3239': '\u0028\u4EE3\u0029',
  14182. '\u323A': '\u0028\u547C\u0029',
  14183. '\u323B': '\u0028\u5B66\u0029',
  14184. '\u323C': '\u0028\u76E3\u0029',
  14185. '\u323D': '\u0028\u4F01\u0029',
  14186. '\u323E': '\u0028\u8CC7\u0029',
  14187. '\u323F': '\u0028\u5354\u0029',
  14188. '\u3240': '\u0028\u796D\u0029',
  14189. '\u3241': '\u0028\u4F11\u0029',
  14190. '\u3242': '\u0028\u81EA\u0029',
  14191. '\u3243': '\u0028\u81F3\u0029',
  14192. '\u32C0': '\u0031\u6708',
  14193. '\u32C1': '\u0032\u6708',
  14194. '\u32C2': '\u0033\u6708',
  14195. '\u32C3': '\u0034\u6708',
  14196. '\u32C4': '\u0035\u6708',
  14197. '\u32C5': '\u0036\u6708',
  14198. '\u32C6': '\u0037\u6708',
  14199. '\u32C7': '\u0038\u6708',
  14200. '\u32C8': '\u0039\u6708',
  14201. '\u32C9': '\u0031\u0030\u6708',
  14202. '\u32CA': '\u0031\u0031\u6708',
  14203. '\u32CB': '\u0031\u0032\u6708',
  14204. '\u3358': '\u0030\u70B9',
  14205. '\u3359': '\u0031\u70B9',
  14206. '\u335A': '\u0032\u70B9',
  14207. '\u335B': '\u0033\u70B9',
  14208. '\u335C': '\u0034\u70B9',
  14209. '\u335D': '\u0035\u70B9',
  14210. '\u335E': '\u0036\u70B9',
  14211. '\u335F': '\u0037\u70B9',
  14212. '\u3360': '\u0038\u70B9',
  14213. '\u3361': '\u0039\u70B9',
  14214. '\u3362': '\u0031\u0030\u70B9',
  14215. '\u3363': '\u0031\u0031\u70B9',
  14216. '\u3364': '\u0031\u0032\u70B9',
  14217. '\u3365': '\u0031\u0033\u70B9',
  14218. '\u3366': '\u0031\u0034\u70B9',
  14219. '\u3367': '\u0031\u0035\u70B9',
  14220. '\u3368': '\u0031\u0036\u70B9',
  14221. '\u3369': '\u0031\u0037\u70B9',
  14222. '\u336A': '\u0031\u0038\u70B9',
  14223. '\u336B': '\u0031\u0039\u70B9',
  14224. '\u336C': '\u0032\u0030\u70B9',
  14225. '\u336D': '\u0032\u0031\u70B9',
  14226. '\u336E': '\u0032\u0032\u70B9',
  14227. '\u336F': '\u0032\u0033\u70B9',
  14228. '\u3370': '\u0032\u0034\u70B9',
  14229. '\u33E0': '\u0031\u65E5',
  14230. '\u33E1': '\u0032\u65E5',
  14231. '\u33E2': '\u0033\u65E5',
  14232. '\u33E3': '\u0034\u65E5',
  14233. '\u33E4': '\u0035\u65E5',
  14234. '\u33E5': '\u0036\u65E5',
  14235. '\u33E6': '\u0037\u65E5',
  14236. '\u33E7': '\u0038\u65E5',
  14237. '\u33E8': '\u0039\u65E5',
  14238. '\u33E9': '\u0031\u0030\u65E5',
  14239. '\u33EA': '\u0031\u0031\u65E5',
  14240. '\u33EB': '\u0031\u0032\u65E5',
  14241. '\u33EC': '\u0031\u0033\u65E5',
  14242. '\u33ED': '\u0031\u0034\u65E5',
  14243. '\u33EE': '\u0031\u0035\u65E5',
  14244. '\u33EF': '\u0031\u0036\u65E5',
  14245. '\u33F0': '\u0031\u0037\u65E5',
  14246. '\u33F1': '\u0031\u0038\u65E5',
  14247. '\u33F2': '\u0031\u0039\u65E5',
  14248. '\u33F3': '\u0032\u0030\u65E5',
  14249. '\u33F4': '\u0032\u0031\u65E5',
  14250. '\u33F5': '\u0032\u0032\u65E5',
  14251. '\u33F6': '\u0032\u0033\u65E5',
  14252. '\u33F7': '\u0032\u0034\u65E5',
  14253. '\u33F8': '\u0032\u0035\u65E5',
  14254. '\u33F9': '\u0032\u0036\u65E5',
  14255. '\u33FA': '\u0032\u0037\u65E5',
  14256. '\u33FB': '\u0032\u0038\u65E5',
  14257. '\u33FC': '\u0032\u0039\u65E5',
  14258. '\u33FD': '\u0033\u0030\u65E5',
  14259. '\u33FE': '\u0033\u0031\u65E5',
  14260. '\uFB00': '\u0066\u0066',
  14261. '\uFB01': '\u0066\u0069',
  14262. '\uFB02': '\u0066\u006C',
  14263. '\uFB03': '\u0066\u0066\u0069',
  14264. '\uFB04': '\u0066\u0066\u006C',
  14265. '\uFB05': '\u017F\u0074',
  14266. '\uFB06': '\u0073\u0074',
  14267. '\uFB13': '\u0574\u0576',
  14268. '\uFB14': '\u0574\u0565',
  14269. '\uFB15': '\u0574\u056B',
  14270. '\uFB16': '\u057E\u0576',
  14271. '\uFB17': '\u0574\u056D',
  14272. '\uFB4F': '\u05D0\u05DC',
  14273. '\uFB50': '\u0671',
  14274. '\uFB51': '\u0671',
  14275. '\uFB52': '\u067B',
  14276. '\uFB53': '\u067B',
  14277. '\uFB54': '\u067B',
  14278. '\uFB55': '\u067B',
  14279. '\uFB56': '\u067E',
  14280. '\uFB57': '\u067E',
  14281. '\uFB58': '\u067E',
  14282. '\uFB59': '\u067E',
  14283. '\uFB5A': '\u0680',
  14284. '\uFB5B': '\u0680',
  14285. '\uFB5C': '\u0680',
  14286. '\uFB5D': '\u0680',
  14287. '\uFB5E': '\u067A',
  14288. '\uFB5F': '\u067A',
  14289. '\uFB60': '\u067A',
  14290. '\uFB61': '\u067A',
  14291. '\uFB62': '\u067F',
  14292. '\uFB63': '\u067F',
  14293. '\uFB64': '\u067F',
  14294. '\uFB65': '\u067F',
  14295. '\uFB66': '\u0679',
  14296. '\uFB67': '\u0679',
  14297. '\uFB68': '\u0679',
  14298. '\uFB69': '\u0679',
  14299. '\uFB6A': '\u06A4',
  14300. '\uFB6B': '\u06A4',
  14301. '\uFB6C': '\u06A4',
  14302. '\uFB6D': '\u06A4',
  14303. '\uFB6E': '\u06A6',
  14304. '\uFB6F': '\u06A6',
  14305. '\uFB70': '\u06A6',
  14306. '\uFB71': '\u06A6',
  14307. '\uFB72': '\u0684',
  14308. '\uFB73': '\u0684',
  14309. '\uFB74': '\u0684',
  14310. '\uFB75': '\u0684',
  14311. '\uFB76': '\u0683',
  14312. '\uFB77': '\u0683',
  14313. '\uFB78': '\u0683',
  14314. '\uFB79': '\u0683',
  14315. '\uFB7A': '\u0686',
  14316. '\uFB7B': '\u0686',
  14317. '\uFB7C': '\u0686',
  14318. '\uFB7D': '\u0686',
  14319. '\uFB7E': '\u0687',
  14320. '\uFB7F': '\u0687',
  14321. '\uFB80': '\u0687',
  14322. '\uFB81': '\u0687',
  14323. '\uFB82': '\u068D',
  14324. '\uFB83': '\u068D',
  14325. '\uFB84': '\u068C',
  14326. '\uFB85': '\u068C',
  14327. '\uFB86': '\u068E',
  14328. '\uFB87': '\u068E',
  14329. '\uFB88': '\u0688',
  14330. '\uFB89': '\u0688',
  14331. '\uFB8A': '\u0698',
  14332. '\uFB8B': '\u0698',
  14333. '\uFB8C': '\u0691',
  14334. '\uFB8D': '\u0691',
  14335. '\uFB8E': '\u06A9',
  14336. '\uFB8F': '\u06A9',
  14337. '\uFB90': '\u06A9',
  14338. '\uFB91': '\u06A9',
  14339. '\uFB92': '\u06AF',
  14340. '\uFB93': '\u06AF',
  14341. '\uFB94': '\u06AF',
  14342. '\uFB95': '\u06AF',
  14343. '\uFB96': '\u06B3',
  14344. '\uFB97': '\u06B3',
  14345. '\uFB98': '\u06B3',
  14346. '\uFB99': '\u06B3',
  14347. '\uFB9A': '\u06B1',
  14348. '\uFB9B': '\u06B1',
  14349. '\uFB9C': '\u06B1',
  14350. '\uFB9D': '\u06B1',
  14351. '\uFB9E': '\u06BA',
  14352. '\uFB9F': '\u06BA',
  14353. '\uFBA0': '\u06BB',
  14354. '\uFBA1': '\u06BB',
  14355. '\uFBA2': '\u06BB',
  14356. '\uFBA3': '\u06BB',
  14357. '\uFBA4': '\u06C0',
  14358. '\uFBA5': '\u06C0',
  14359. '\uFBA6': '\u06C1',
  14360. '\uFBA7': '\u06C1',
  14361. '\uFBA8': '\u06C1',
  14362. '\uFBA9': '\u06C1',
  14363. '\uFBAA': '\u06BE',
  14364. '\uFBAB': '\u06BE',
  14365. '\uFBAC': '\u06BE',
  14366. '\uFBAD': '\u06BE',
  14367. '\uFBAE': '\u06D2',
  14368. '\uFBAF': '\u06D2',
  14369. '\uFBB0': '\u06D3',
  14370. '\uFBB1': '\u06D3',
  14371. '\uFBD3': '\u06AD',
  14372. '\uFBD4': '\u06AD',
  14373. '\uFBD5': '\u06AD',
  14374. '\uFBD6': '\u06AD',
  14375. '\uFBD7': '\u06C7',
  14376. '\uFBD8': '\u06C7',
  14377. '\uFBD9': '\u06C6',
  14378. '\uFBDA': '\u06C6',
  14379. '\uFBDB': '\u06C8',
  14380. '\uFBDC': '\u06C8',
  14381. '\uFBDD': '\u0677',
  14382. '\uFBDE': '\u06CB',
  14383. '\uFBDF': '\u06CB',
  14384. '\uFBE0': '\u06C5',
  14385. '\uFBE1': '\u06C5',
  14386. '\uFBE2': '\u06C9',
  14387. '\uFBE3': '\u06C9',
  14388. '\uFBE4': '\u06D0',
  14389. '\uFBE5': '\u06D0',
  14390. '\uFBE6': '\u06D0',
  14391. '\uFBE7': '\u06D0',
  14392. '\uFBE8': '\u0649',
  14393. '\uFBE9': '\u0649',
  14394. '\uFBEA': '\u0626\u0627',
  14395. '\uFBEB': '\u0626\u0627',
  14396. '\uFBEC': '\u0626\u06D5',
  14397. '\uFBED': '\u0626\u06D5',
  14398. '\uFBEE': '\u0626\u0648',
  14399. '\uFBEF': '\u0626\u0648',
  14400. '\uFBF0': '\u0626\u06C7',
  14401. '\uFBF1': '\u0626\u06C7',
  14402. '\uFBF2': '\u0626\u06C6',
  14403. '\uFBF3': '\u0626\u06C6',
  14404. '\uFBF4': '\u0626\u06C8',
  14405. '\uFBF5': '\u0626\u06C8',
  14406. '\uFBF6': '\u0626\u06D0',
  14407. '\uFBF7': '\u0626\u06D0',
  14408. '\uFBF8': '\u0626\u06D0',
  14409. '\uFBF9': '\u0626\u0649',
  14410. '\uFBFA': '\u0626\u0649',
  14411. '\uFBFB': '\u0626\u0649',
  14412. '\uFBFC': '\u06CC',
  14413. '\uFBFD': '\u06CC',
  14414. '\uFBFE': '\u06CC',
  14415. '\uFBFF': '\u06CC',
  14416. '\uFC00': '\u0626\u062C',
  14417. '\uFC01': '\u0626\u062D',
  14418. '\uFC02': '\u0626\u0645',
  14419. '\uFC03': '\u0626\u0649',
  14420. '\uFC04': '\u0626\u064A',
  14421. '\uFC05': '\u0628\u062C',
  14422. '\uFC06': '\u0628\u062D',
  14423. '\uFC07': '\u0628\u062E',
  14424. '\uFC08': '\u0628\u0645',
  14425. '\uFC09': '\u0628\u0649',
  14426. '\uFC0A': '\u0628\u064A',
  14427. '\uFC0B': '\u062A\u062C',
  14428. '\uFC0C': '\u062A\u062D',
  14429. '\uFC0D': '\u062A\u062E',
  14430. '\uFC0E': '\u062A\u0645',
  14431. '\uFC0F': '\u062A\u0649',
  14432. '\uFC10': '\u062A\u064A',
  14433. '\uFC11': '\u062B\u062C',
  14434. '\uFC12': '\u062B\u0645',
  14435. '\uFC13': '\u062B\u0649',
  14436. '\uFC14': '\u062B\u064A',
  14437. '\uFC15': '\u062C\u062D',
  14438. '\uFC16': '\u062C\u0645',
  14439. '\uFC17': '\u062D\u062C',
  14440. '\uFC18': '\u062D\u0645',
  14441. '\uFC19': '\u062E\u062C',
  14442. '\uFC1A': '\u062E\u062D',
  14443. '\uFC1B': '\u062E\u0645',
  14444. '\uFC1C': '\u0633\u062C',
  14445. '\uFC1D': '\u0633\u062D',
  14446. '\uFC1E': '\u0633\u062E',
  14447. '\uFC1F': '\u0633\u0645',
  14448. '\uFC20': '\u0635\u062D',
  14449. '\uFC21': '\u0635\u0645',
  14450. '\uFC22': '\u0636\u062C',
  14451. '\uFC23': '\u0636\u062D',
  14452. '\uFC24': '\u0636\u062E',
  14453. '\uFC25': '\u0636\u0645',
  14454. '\uFC26': '\u0637\u062D',
  14455. '\uFC27': '\u0637\u0645',
  14456. '\uFC28': '\u0638\u0645',
  14457. '\uFC29': '\u0639\u062C',
  14458. '\uFC2A': '\u0639\u0645',
  14459. '\uFC2B': '\u063A\u062C',
  14460. '\uFC2C': '\u063A\u0645',
  14461. '\uFC2D': '\u0641\u062C',
  14462. '\uFC2E': '\u0641\u062D',
  14463. '\uFC2F': '\u0641\u062E',
  14464. '\uFC30': '\u0641\u0645',
  14465. '\uFC31': '\u0641\u0649',
  14466. '\uFC32': '\u0641\u064A',
  14467. '\uFC33': '\u0642\u062D',
  14468. '\uFC34': '\u0642\u0645',
  14469. '\uFC35': '\u0642\u0649',
  14470. '\uFC36': '\u0642\u064A',
  14471. '\uFC37': '\u0643\u0627',
  14472. '\uFC38': '\u0643\u062C',
  14473. '\uFC39': '\u0643\u062D',
  14474. '\uFC3A': '\u0643\u062E',
  14475. '\uFC3B': '\u0643\u0644',
  14476. '\uFC3C': '\u0643\u0645',
  14477. '\uFC3D': '\u0643\u0649',
  14478. '\uFC3E': '\u0643\u064A',
  14479. '\uFC3F': '\u0644\u062C',
  14480. '\uFC40': '\u0644\u062D',
  14481. '\uFC41': '\u0644\u062E',
  14482. '\uFC42': '\u0644\u0645',
  14483. '\uFC43': '\u0644\u0649',
  14484. '\uFC44': '\u0644\u064A',
  14485. '\uFC45': '\u0645\u062C',
  14486. '\uFC46': '\u0645\u062D',
  14487. '\uFC47': '\u0645\u062E',
  14488. '\uFC48': '\u0645\u0645',
  14489. '\uFC49': '\u0645\u0649',
  14490. '\uFC4A': '\u0645\u064A',
  14491. '\uFC4B': '\u0646\u062C',
  14492. '\uFC4C': '\u0646\u062D',
  14493. '\uFC4D': '\u0646\u062E',
  14494. '\uFC4E': '\u0646\u0645',
  14495. '\uFC4F': '\u0646\u0649',
  14496. '\uFC50': '\u0646\u064A',
  14497. '\uFC51': '\u0647\u062C',
  14498. '\uFC52': '\u0647\u0645',
  14499. '\uFC53': '\u0647\u0649',
  14500. '\uFC54': '\u0647\u064A',
  14501. '\uFC55': '\u064A\u062C',
  14502. '\uFC56': '\u064A\u062D',
  14503. '\uFC57': '\u064A\u062E',
  14504. '\uFC58': '\u064A\u0645',
  14505. '\uFC59': '\u064A\u0649',
  14506. '\uFC5A': '\u064A\u064A',
  14507. '\uFC5B': '\u0630\u0670',
  14508. '\uFC5C': '\u0631\u0670',
  14509. '\uFC5D': '\u0649\u0670',
  14510. '\uFC5E': '\u0020\u064C\u0651',
  14511. '\uFC5F': '\u0020\u064D\u0651',
  14512. '\uFC60': '\u0020\u064E\u0651',
  14513. '\uFC61': '\u0020\u064F\u0651',
  14514. '\uFC62': '\u0020\u0650\u0651',
  14515. '\uFC63': '\u0020\u0651\u0670',
  14516. '\uFC64': '\u0626\u0631',
  14517. '\uFC65': '\u0626\u0632',
  14518. '\uFC66': '\u0626\u0645',
  14519. '\uFC67': '\u0626\u0646',
  14520. '\uFC68': '\u0626\u0649',
  14521. '\uFC69': '\u0626\u064A',
  14522. '\uFC6A': '\u0628\u0631',
  14523. '\uFC6B': '\u0628\u0632',
  14524. '\uFC6C': '\u0628\u0645',
  14525. '\uFC6D': '\u0628\u0646',
  14526. '\uFC6E': '\u0628\u0649',
  14527. '\uFC6F': '\u0628\u064A',
  14528. '\uFC70': '\u062A\u0631',
  14529. '\uFC71': '\u062A\u0632',
  14530. '\uFC72': '\u062A\u0645',
  14531. '\uFC73': '\u062A\u0646',
  14532. '\uFC74': '\u062A\u0649',
  14533. '\uFC75': '\u062A\u064A',
  14534. '\uFC76': '\u062B\u0631',
  14535. '\uFC77': '\u062B\u0632',
  14536. '\uFC78': '\u062B\u0645',
  14537. '\uFC79': '\u062B\u0646',
  14538. '\uFC7A': '\u062B\u0649',
  14539. '\uFC7B': '\u062B\u064A',
  14540. '\uFC7C': '\u0641\u0649',
  14541. '\uFC7D': '\u0641\u064A',
  14542. '\uFC7E': '\u0642\u0649',
  14543. '\uFC7F': '\u0642\u064A',
  14544. '\uFC80': '\u0643\u0627',
  14545. '\uFC81': '\u0643\u0644',
  14546. '\uFC82': '\u0643\u0645',
  14547. '\uFC83': '\u0643\u0649',
  14548. '\uFC84': '\u0643\u064A',
  14549. '\uFC85': '\u0644\u0645',
  14550. '\uFC86': '\u0644\u0649',
  14551. '\uFC87': '\u0644\u064A',
  14552. '\uFC88': '\u0645\u0627',
  14553. '\uFC89': '\u0645\u0645',
  14554. '\uFC8A': '\u0646\u0631',
  14555. '\uFC8B': '\u0646\u0632',
  14556. '\uFC8C': '\u0646\u0645',
  14557. '\uFC8D': '\u0646\u0646',
  14558. '\uFC8E': '\u0646\u0649',
  14559. '\uFC8F': '\u0646\u064A',
  14560. '\uFC90': '\u0649\u0670',
  14561. '\uFC91': '\u064A\u0631',
  14562. '\uFC92': '\u064A\u0632',
  14563. '\uFC93': '\u064A\u0645',
  14564. '\uFC94': '\u064A\u0646',
  14565. '\uFC95': '\u064A\u0649',
  14566. '\uFC96': '\u064A\u064A',
  14567. '\uFC97': '\u0626\u062C',
  14568. '\uFC98': '\u0626\u062D',
  14569. '\uFC99': '\u0626\u062E',
  14570. '\uFC9A': '\u0626\u0645',
  14571. '\uFC9B': '\u0626\u0647',
  14572. '\uFC9C': '\u0628\u062C',
  14573. '\uFC9D': '\u0628\u062D',
  14574. '\uFC9E': '\u0628\u062E',
  14575. '\uFC9F': '\u0628\u0645',
  14576. '\uFCA0': '\u0628\u0647',
  14577. '\uFCA1': '\u062A\u062C',
  14578. '\uFCA2': '\u062A\u062D',
  14579. '\uFCA3': '\u062A\u062E',
  14580. '\uFCA4': '\u062A\u0645',
  14581. '\uFCA5': '\u062A\u0647',
  14582. '\uFCA6': '\u062B\u0645',
  14583. '\uFCA7': '\u062C\u062D',
  14584. '\uFCA8': '\u062C\u0645',
  14585. '\uFCA9': '\u062D\u062C',
  14586. '\uFCAA': '\u062D\u0645',
  14587. '\uFCAB': '\u062E\u062C',
  14588. '\uFCAC': '\u062E\u0645',
  14589. '\uFCAD': '\u0633\u062C',
  14590. '\uFCAE': '\u0633\u062D',
  14591. '\uFCAF': '\u0633\u062E',
  14592. '\uFCB0': '\u0633\u0645',
  14593. '\uFCB1': '\u0635\u062D',
  14594. '\uFCB2': '\u0635\u062E',
  14595. '\uFCB3': '\u0635\u0645',
  14596. '\uFCB4': '\u0636\u062C',
  14597. '\uFCB5': '\u0636\u062D',
  14598. '\uFCB6': '\u0636\u062E',
  14599. '\uFCB7': '\u0636\u0645',
  14600. '\uFCB8': '\u0637\u062D',
  14601. '\uFCB9': '\u0638\u0645',
  14602. '\uFCBA': '\u0639\u062C',
  14603. '\uFCBB': '\u0639\u0645',
  14604. '\uFCBC': '\u063A\u062C',
  14605. '\uFCBD': '\u063A\u0645',
  14606. '\uFCBE': '\u0641\u062C',
  14607. '\uFCBF': '\u0641\u062D',
  14608. '\uFCC0': '\u0641\u062E',
  14609. '\uFCC1': '\u0641\u0645',
  14610. '\uFCC2': '\u0642\u062D',
  14611. '\uFCC3': '\u0642\u0645',
  14612. '\uFCC4': '\u0643\u062C',
  14613. '\uFCC5': '\u0643\u062D',
  14614. '\uFCC6': '\u0643\u062E',
  14615. '\uFCC7': '\u0643\u0644',
  14616. '\uFCC8': '\u0643\u0645',
  14617. '\uFCC9': '\u0644\u062C',
  14618. '\uFCCA': '\u0644\u062D',
  14619. '\uFCCB': '\u0644\u062E',
  14620. '\uFCCC': '\u0644\u0645',
  14621. '\uFCCD': '\u0644\u0647',
  14622. '\uFCCE': '\u0645\u062C',
  14623. '\uFCCF': '\u0645\u062D',
  14624. '\uFCD0': '\u0645\u062E',
  14625. '\uFCD1': '\u0645\u0645',
  14626. '\uFCD2': '\u0646\u062C',
  14627. '\uFCD3': '\u0646\u062D',
  14628. '\uFCD4': '\u0646\u062E',
  14629. '\uFCD5': '\u0646\u0645',
  14630. '\uFCD6': '\u0646\u0647',
  14631. '\uFCD7': '\u0647\u062C',
  14632. '\uFCD8': '\u0647\u0645',
  14633. '\uFCD9': '\u0647\u0670',
  14634. '\uFCDA': '\u064A\u062C',
  14635. '\uFCDB': '\u064A\u062D',
  14636. '\uFCDC': '\u064A\u062E',
  14637. '\uFCDD': '\u064A\u0645',
  14638. '\uFCDE': '\u064A\u0647',
  14639. '\uFCDF': '\u0626\u0645',
  14640. '\uFCE0': '\u0626\u0647',
  14641. '\uFCE1': '\u0628\u0645',
  14642. '\uFCE2': '\u0628\u0647',
  14643. '\uFCE3': '\u062A\u0645',
  14644. '\uFCE4': '\u062A\u0647',
  14645. '\uFCE5': '\u062B\u0645',
  14646. '\uFCE6': '\u062B\u0647',
  14647. '\uFCE7': '\u0633\u0645',
  14648. '\uFCE8': '\u0633\u0647',
  14649. '\uFCE9': '\u0634\u0645',
  14650. '\uFCEA': '\u0634\u0647',
  14651. '\uFCEB': '\u0643\u0644',
  14652. '\uFCEC': '\u0643\u0645',
  14653. '\uFCED': '\u0644\u0645',
  14654. '\uFCEE': '\u0646\u0645',
  14655. '\uFCEF': '\u0646\u0647',
  14656. '\uFCF0': '\u064A\u0645',
  14657. '\uFCF1': '\u064A\u0647',
  14658. '\uFCF2': '\u0640\u064E\u0651',
  14659. '\uFCF3': '\u0640\u064F\u0651',
  14660. '\uFCF4': '\u0640\u0650\u0651',
  14661. '\uFCF5': '\u0637\u0649',
  14662. '\uFCF6': '\u0637\u064A',
  14663. '\uFCF7': '\u0639\u0649',
  14664. '\uFCF8': '\u0639\u064A',
  14665. '\uFCF9': '\u063A\u0649',
  14666. '\uFCFA': '\u063A\u064A',
  14667. '\uFCFB': '\u0633\u0649',
  14668. '\uFCFC': '\u0633\u064A',
  14669. '\uFCFD': '\u0634\u0649',
  14670. '\uFCFE': '\u0634\u064A',
  14671. '\uFCFF': '\u062D\u0649',
  14672. '\uFD00': '\u062D\u064A',
  14673. '\uFD01': '\u062C\u0649',
  14674. '\uFD02': '\u062C\u064A',
  14675. '\uFD03': '\u062E\u0649',
  14676. '\uFD04': '\u062E\u064A',
  14677. '\uFD05': '\u0635\u0649',
  14678. '\uFD06': '\u0635\u064A',
  14679. '\uFD07': '\u0636\u0649',
  14680. '\uFD08': '\u0636\u064A',
  14681. '\uFD09': '\u0634\u062C',
  14682. '\uFD0A': '\u0634\u062D',
  14683. '\uFD0B': '\u0634\u062E',
  14684. '\uFD0C': '\u0634\u0645',
  14685. '\uFD0D': '\u0634\u0631',
  14686. '\uFD0E': '\u0633\u0631',
  14687. '\uFD0F': '\u0635\u0631',
  14688. '\uFD10': '\u0636\u0631',
  14689. '\uFD11': '\u0637\u0649',
  14690. '\uFD12': '\u0637\u064A',
  14691. '\uFD13': '\u0639\u0649',
  14692. '\uFD14': '\u0639\u064A',
  14693. '\uFD15': '\u063A\u0649',
  14694. '\uFD16': '\u063A\u064A',
  14695. '\uFD17': '\u0633\u0649',
  14696. '\uFD18': '\u0633\u064A',
  14697. '\uFD19': '\u0634\u0649',
  14698. '\uFD1A': '\u0634\u064A',
  14699. '\uFD1B': '\u062D\u0649',
  14700. '\uFD1C': '\u062D\u064A',
  14701. '\uFD1D': '\u062C\u0649',
  14702. '\uFD1E': '\u062C\u064A',
  14703. '\uFD1F': '\u062E\u0649',
  14704. '\uFD20': '\u062E\u064A',
  14705. '\uFD21': '\u0635\u0649',
  14706. '\uFD22': '\u0635\u064A',
  14707. '\uFD23': '\u0636\u0649',
  14708. '\uFD24': '\u0636\u064A',
  14709. '\uFD25': '\u0634\u062C',
  14710. '\uFD26': '\u0634\u062D',
  14711. '\uFD27': '\u0634\u062E',
  14712. '\uFD28': '\u0634\u0645',
  14713. '\uFD29': '\u0634\u0631',
  14714. '\uFD2A': '\u0633\u0631',
  14715. '\uFD2B': '\u0635\u0631',
  14716. '\uFD2C': '\u0636\u0631',
  14717. '\uFD2D': '\u0634\u062C',
  14718. '\uFD2E': '\u0634\u062D',
  14719. '\uFD2F': '\u0634\u062E',
  14720. '\uFD30': '\u0634\u0645',
  14721. '\uFD31': '\u0633\u0647',
  14722. '\uFD32': '\u0634\u0647',
  14723. '\uFD33': '\u0637\u0645',
  14724. '\uFD34': '\u0633\u062C',
  14725. '\uFD35': '\u0633\u062D',
  14726. '\uFD36': '\u0633\u062E',
  14727. '\uFD37': '\u0634\u062C',
  14728. '\uFD38': '\u0634\u062D',
  14729. '\uFD39': '\u0634\u062E',
  14730. '\uFD3A': '\u0637\u0645',
  14731. '\uFD3B': '\u0638\u0645',
  14732. '\uFD3C': '\u0627\u064B',
  14733. '\uFD3D': '\u0627\u064B',
  14734. '\uFD50': '\u062A\u062C\u0645',
  14735. '\uFD51': '\u062A\u062D\u062C',
  14736. '\uFD52': '\u062A\u062D\u062C',
  14737. '\uFD53': '\u062A\u062D\u0645',
  14738. '\uFD54': '\u062A\u062E\u0645',
  14739. '\uFD55': '\u062A\u0645\u062C',
  14740. '\uFD56': '\u062A\u0645\u062D',
  14741. '\uFD57': '\u062A\u0645\u062E',
  14742. '\uFD58': '\u062C\u0645\u062D',
  14743. '\uFD59': '\u062C\u0645\u062D',
  14744. '\uFD5A': '\u062D\u0645\u064A',
  14745. '\uFD5B': '\u062D\u0645\u0649',
  14746. '\uFD5C': '\u0633\u062D\u062C',
  14747. '\uFD5D': '\u0633\u062C\u062D',
  14748. '\uFD5E': '\u0633\u062C\u0649',
  14749. '\uFD5F': '\u0633\u0645\u062D',
  14750. '\uFD60': '\u0633\u0645\u062D',
  14751. '\uFD61': '\u0633\u0645\u062C',
  14752. '\uFD62': '\u0633\u0645\u0645',
  14753. '\uFD63': '\u0633\u0645\u0645',
  14754. '\uFD64': '\u0635\u062D\u062D',
  14755. '\uFD65': '\u0635\u062D\u062D',
  14756. '\uFD66': '\u0635\u0645\u0645',
  14757. '\uFD67': '\u0634\u062D\u0645',
  14758. '\uFD68': '\u0634\u062D\u0645',
  14759. '\uFD69': '\u0634\u062C\u064A',
  14760. '\uFD6A': '\u0634\u0645\u062E',
  14761. '\uFD6B': '\u0634\u0645\u062E',
  14762. '\uFD6C': '\u0634\u0645\u0645',
  14763. '\uFD6D': '\u0634\u0645\u0645',
  14764. '\uFD6E': '\u0636\u062D\u0649',
  14765. '\uFD6F': '\u0636\u062E\u0645',
  14766. '\uFD70': '\u0636\u062E\u0645',
  14767. '\uFD71': '\u0637\u0645\u062D',
  14768. '\uFD72': '\u0637\u0645\u062D',
  14769. '\uFD73': '\u0637\u0645\u0645',
  14770. '\uFD74': '\u0637\u0645\u064A',
  14771. '\uFD75': '\u0639\u062C\u0645',
  14772. '\uFD76': '\u0639\u0645\u0645',
  14773. '\uFD77': '\u0639\u0645\u0645',
  14774. '\uFD78': '\u0639\u0645\u0649',
  14775. '\uFD79': '\u063A\u0645\u0645',
  14776. '\uFD7A': '\u063A\u0645\u064A',
  14777. '\uFD7B': '\u063A\u0645\u0649',
  14778. '\uFD7C': '\u0641\u062E\u0645',
  14779. '\uFD7D': '\u0641\u062E\u0645',
  14780. '\uFD7E': '\u0642\u0645\u062D',
  14781. '\uFD7F': '\u0642\u0645\u0645',
  14782. '\uFD80': '\u0644\u062D\u0645',
  14783. '\uFD81': '\u0644\u062D\u064A',
  14784. '\uFD82': '\u0644\u062D\u0649',
  14785. '\uFD83': '\u0644\u062C\u062C',
  14786. '\uFD84': '\u0644\u062C\u062C',
  14787. '\uFD85': '\u0644\u062E\u0645',
  14788. '\uFD86': '\u0644\u062E\u0645',
  14789. '\uFD87': '\u0644\u0645\u062D',
  14790. '\uFD88': '\u0644\u0645\u062D',
  14791. '\uFD89': '\u0645\u062D\u062C',
  14792. '\uFD8A': '\u0645\u062D\u0645',
  14793. '\uFD8B': '\u0645\u062D\u064A',
  14794. '\uFD8C': '\u0645\u062C\u062D',
  14795. '\uFD8D': '\u0645\u062C\u0645',
  14796. '\uFD8E': '\u0645\u062E\u062C',
  14797. '\uFD8F': '\u0645\u062E\u0645',
  14798. '\uFD92': '\u0645\u062C\u062E',
  14799. '\uFD93': '\u0647\u0645\u062C',
  14800. '\uFD94': '\u0647\u0645\u0645',
  14801. '\uFD95': '\u0646\u062D\u0645',
  14802. '\uFD96': '\u0646\u062D\u0649',
  14803. '\uFD97': '\u0646\u062C\u0645',
  14804. '\uFD98': '\u0646\u062C\u0645',
  14805. '\uFD99': '\u0646\u062C\u0649',
  14806. '\uFD9A': '\u0646\u0645\u064A',
  14807. '\uFD9B': '\u0646\u0645\u0649',
  14808. '\uFD9C': '\u064A\u0645\u0645',
  14809. '\uFD9D': '\u064A\u0645\u0645',
  14810. '\uFD9E': '\u0628\u062E\u064A',
  14811. '\uFD9F': '\u062A\u062C\u064A',
  14812. '\uFDA0': '\u062A\u062C\u0649',
  14813. '\uFDA1': '\u062A\u062E\u064A',
  14814. '\uFDA2': '\u062A\u062E\u0649',
  14815. '\uFDA3': '\u062A\u0645\u064A',
  14816. '\uFDA4': '\u062A\u0645\u0649',
  14817. '\uFDA5': '\u062C\u0645\u064A',
  14818. '\uFDA6': '\u062C\u062D\u0649',
  14819. '\uFDA7': '\u062C\u0645\u0649',
  14820. '\uFDA8': '\u0633\u062E\u0649',
  14821. '\uFDA9': '\u0635\u062D\u064A',
  14822. '\uFDAA': '\u0634\u062D\u064A',
  14823. '\uFDAB': '\u0636\u062D\u064A',
  14824. '\uFDAC': '\u0644\u062C\u064A',
  14825. '\uFDAD': '\u0644\u0645\u064A',
  14826. '\uFDAE': '\u064A\u062D\u064A',
  14827. '\uFDAF': '\u064A\u062C\u064A',
  14828. '\uFDB0': '\u064A\u0645\u064A',
  14829. '\uFDB1': '\u0645\u0645\u064A',
  14830. '\uFDB2': '\u0642\u0645\u064A',
  14831. '\uFDB3': '\u0646\u062D\u064A',
  14832. '\uFDB4': '\u0642\u0645\u062D',
  14833. '\uFDB5': '\u0644\u062D\u0645',
  14834. '\uFDB6': '\u0639\u0645\u064A',
  14835. '\uFDB7': '\u0643\u0645\u064A',
  14836. '\uFDB8': '\u0646\u062C\u062D',
  14837. '\uFDB9': '\u0645\u062E\u064A',
  14838. '\uFDBA': '\u0644\u062C\u0645',
  14839. '\uFDBB': '\u0643\u0645\u0645',
  14840. '\uFDBC': '\u0644\u062C\u0645',
  14841. '\uFDBD': '\u0646\u062C\u062D',
  14842. '\uFDBE': '\u062C\u062D\u064A',
  14843. '\uFDBF': '\u062D\u062C\u064A',
  14844. '\uFDC0': '\u0645\u062C\u064A',
  14845. '\uFDC1': '\u0641\u0645\u064A',
  14846. '\uFDC2': '\u0628\u062D\u064A',
  14847. '\uFDC3': '\u0643\u0645\u0645',
  14848. '\uFDC4': '\u0639\u062C\u0645',
  14849. '\uFDC5': '\u0635\u0645\u0645',
  14850. '\uFDC6': '\u0633\u062E\u064A',
  14851. '\uFDC7': '\u0646\u062C\u064A',
  14852. '\uFE49': '\u203E',
  14853. '\uFE4A': '\u203E',
  14854. '\uFE4B': '\u203E',
  14855. '\uFE4C': '\u203E',
  14856. '\uFE4D': '\u005F',
  14857. '\uFE4E': '\u005F',
  14858. '\uFE4F': '\u005F',
  14859. '\uFE80': '\u0621',
  14860. '\uFE81': '\u0622',
  14861. '\uFE82': '\u0622',
  14862. '\uFE83': '\u0623',
  14863. '\uFE84': '\u0623',
  14864. '\uFE85': '\u0624',
  14865. '\uFE86': '\u0624',
  14866. '\uFE87': '\u0625',
  14867. '\uFE88': '\u0625',
  14868. '\uFE89': '\u0626',
  14869. '\uFE8A': '\u0626',
  14870. '\uFE8B': '\u0626',
  14871. '\uFE8C': '\u0626',
  14872. '\uFE8D': '\u0627',
  14873. '\uFE8E': '\u0627',
  14874. '\uFE8F': '\u0628',
  14875. '\uFE90': '\u0628',
  14876. '\uFE91': '\u0628',
  14877. '\uFE92': '\u0628',
  14878. '\uFE93': '\u0629',
  14879. '\uFE94': '\u0629',
  14880. '\uFE95': '\u062A',
  14881. '\uFE96': '\u062A',
  14882. '\uFE97': '\u062A',
  14883. '\uFE98': '\u062A',
  14884. '\uFE99': '\u062B',
  14885. '\uFE9A': '\u062B',
  14886. '\uFE9B': '\u062B',
  14887. '\uFE9C': '\u062B',
  14888. '\uFE9D': '\u062C',
  14889. '\uFE9E': '\u062C',
  14890. '\uFE9F': '\u062C',
  14891. '\uFEA0': '\u062C',
  14892. '\uFEA1': '\u062D',
  14893. '\uFEA2': '\u062D',
  14894. '\uFEA3': '\u062D',
  14895. '\uFEA4': '\u062D',
  14896. '\uFEA5': '\u062E',
  14897. '\uFEA6': '\u062E',
  14898. '\uFEA7': '\u062E',
  14899. '\uFEA8': '\u062E',
  14900. '\uFEA9': '\u062F',
  14901. '\uFEAA': '\u062F',
  14902. '\uFEAB': '\u0630',
  14903. '\uFEAC': '\u0630',
  14904. '\uFEAD': '\u0631',
  14905. '\uFEAE': '\u0631',
  14906. '\uFEAF': '\u0632',
  14907. '\uFEB0': '\u0632',
  14908. '\uFEB1': '\u0633',
  14909. '\uFEB2': '\u0633',
  14910. '\uFEB3': '\u0633',
  14911. '\uFEB4': '\u0633',
  14912. '\uFEB5': '\u0634',
  14913. '\uFEB6': '\u0634',
  14914. '\uFEB7': '\u0634',
  14915. '\uFEB8': '\u0634',
  14916. '\uFEB9': '\u0635',
  14917. '\uFEBA': '\u0635',
  14918. '\uFEBB': '\u0635',
  14919. '\uFEBC': '\u0635',
  14920. '\uFEBD': '\u0636',
  14921. '\uFEBE': '\u0636',
  14922. '\uFEBF': '\u0636',
  14923. '\uFEC0': '\u0636',
  14924. '\uFEC1': '\u0637',
  14925. '\uFEC2': '\u0637',
  14926. '\uFEC3': '\u0637',
  14927. '\uFEC4': '\u0637',
  14928. '\uFEC5': '\u0638',
  14929. '\uFEC6': '\u0638',
  14930. '\uFEC7': '\u0638',
  14931. '\uFEC8': '\u0638',
  14932. '\uFEC9': '\u0639',
  14933. '\uFECA': '\u0639',
  14934. '\uFECB': '\u0639',
  14935. '\uFECC': '\u0639',
  14936. '\uFECD': '\u063A',
  14937. '\uFECE': '\u063A',
  14938. '\uFECF': '\u063A',
  14939. '\uFED0': '\u063A',
  14940. '\uFED1': '\u0641',
  14941. '\uFED2': '\u0641',
  14942. '\uFED3': '\u0641',
  14943. '\uFED4': '\u0641',
  14944. '\uFED5': '\u0642',
  14945. '\uFED6': '\u0642',
  14946. '\uFED7': '\u0642',
  14947. '\uFED8': '\u0642',
  14948. '\uFED9': '\u0643',
  14949. '\uFEDA': '\u0643',
  14950. '\uFEDB': '\u0643',
  14951. '\uFEDC': '\u0643',
  14952. '\uFEDD': '\u0644',
  14953. '\uFEDE': '\u0644',
  14954. '\uFEDF': '\u0644',
  14955. '\uFEE0': '\u0644',
  14956. '\uFEE1': '\u0645',
  14957. '\uFEE2': '\u0645',
  14958. '\uFEE3': '\u0645',
  14959. '\uFEE4': '\u0645',
  14960. '\uFEE5': '\u0646',
  14961. '\uFEE6': '\u0646',
  14962. '\uFEE7': '\u0646',
  14963. '\uFEE8': '\u0646',
  14964. '\uFEE9': '\u0647',
  14965. '\uFEEA': '\u0647',
  14966. '\uFEEB': '\u0647',
  14967. '\uFEEC': '\u0647',
  14968. '\uFEED': '\u0648',
  14969. '\uFEEE': '\u0648',
  14970. '\uFEEF': '\u0649',
  14971. '\uFEF0': '\u0649',
  14972. '\uFEF1': '\u064A',
  14973. '\uFEF2': '\u064A',
  14974. '\uFEF3': '\u064A',
  14975. '\uFEF4': '\u064A',
  14976. '\uFEF5': '\u0644\u0622',
  14977. '\uFEF6': '\u0644\u0622',
  14978. '\uFEF7': '\u0644\u0623',
  14979. '\uFEF8': '\u0644\u0623',
  14980. '\uFEF9': '\u0644\u0625',
  14981. '\uFEFA': '\u0644\u0625',
  14982. '\uFEFB': '\u0644\u0627',
  14983. '\uFEFC': '\u0644\u0627'
  14984. };
  14985. function reverseIfRtl(chars) {
  14986. var charsLength = chars.length;
  14987. //reverse an arabic ligature
  14988. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14989. return chars;
  14990. }
  14991. var s = '';
  14992. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14993. s += chars[ii];
  14994. }
  14995. return s;
  14996. }
  14997. function adjustWidths(properties) {
  14998. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14999. return;
  15000. }
  15001. // adjusting width to fontMatrix scale
  15002. var scale = 0.001 / properties.fontMatrix[0];
  15003. var glyphsWidths = properties.widths;
  15004. for (var glyph in glyphsWidths) {
  15005. glyphsWidths[glyph] *= scale;
  15006. }
  15007. properties.defaultWidth *= scale;
  15008. }
  15009. function getFontType(type, subtype) {
  15010. switch (type) {
  15011. case 'Type1':
  15012. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15013. case 'CIDFontType0':
  15014. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15015. FontType.CIDFONTTYPE0;
  15016. case 'OpenType':
  15017. return FontType.OPENTYPE;
  15018. case 'TrueType':
  15019. return FontType.TRUETYPE;
  15020. case 'CIDFontType2':
  15021. return FontType.CIDFONTTYPE2;
  15022. case 'MMType1':
  15023. return FontType.MMTYPE1;
  15024. case 'Type0':
  15025. return FontType.TYPE0;
  15026. default:
  15027. return FontType.UNKNOWN;
  15028. }
  15029. }
  15030. var Glyph = (function GlyphClosure() {
  15031. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15032. this.fontChar = fontChar;
  15033. this.unicode = unicode;
  15034. this.accent = accent;
  15035. this.width = width;
  15036. this.vmetric = vmetric;
  15037. this.operatorListId = operatorListId;
  15038. }
  15039. Glyph.prototype.matchesForCache =
  15040. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15041. return this.fontChar === fontChar &&
  15042. this.unicode === unicode &&
  15043. this.accent === accent &&
  15044. this.width === width &&
  15045. this.vmetric === vmetric &&
  15046. this.operatorListId === operatorListId;
  15047. };
  15048. return Glyph;
  15049. })();
  15050. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15051. function ToUnicodeMap(cmap) {
  15052. // The elements of this._map can be integers or strings, depending on how
  15053. // |cmap| was created.
  15054. this._map = cmap;
  15055. }
  15056. ToUnicodeMap.prototype = {
  15057. get length() {
  15058. return this._map.length;
  15059. },
  15060. forEach: function(callback) {
  15061. for (var charCode in this._map) {
  15062. callback(charCode, this._map[charCode].charCodeAt(0));
  15063. }
  15064. },
  15065. has: function(i) {
  15066. return this._map[i] !== undefined;
  15067. },
  15068. get: function(i) {
  15069. return this._map[i];
  15070. },
  15071. charCodeOf: function(v) {
  15072. return this._map.indexOf(v);
  15073. }
  15074. };
  15075. return ToUnicodeMap;
  15076. })();
  15077. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15078. function IdentityToUnicodeMap(firstChar, lastChar) {
  15079. this.firstChar = firstChar;
  15080. this.lastChar = lastChar;
  15081. }
  15082. IdentityToUnicodeMap.prototype = {
  15083. get length() {
  15084. return (this.lastChar + 1) - this.firstChar;
  15085. },
  15086. forEach: function (callback) {
  15087. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15088. callback(i, i);
  15089. }
  15090. },
  15091. has: function (i) {
  15092. return this.firstChar <= i && i <= this.lastChar;
  15093. },
  15094. get: function (i) {
  15095. if (this.firstChar <= i && i <= this.lastChar) {
  15096. return String.fromCharCode(i);
  15097. }
  15098. return undefined;
  15099. },
  15100. charCodeOf: function (v) {
  15101. error('should not call .charCodeOf');
  15102. }
  15103. };
  15104. return IdentityToUnicodeMap;
  15105. })();
  15106. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15107. function writeInt16(dest, offset, num) {
  15108. dest[offset] = (num >> 8) & 0xFF;
  15109. dest[offset + 1] = num & 0xFF;
  15110. }
  15111. function writeInt32(dest, offset, num) {
  15112. dest[offset] = (num >> 24) & 0xFF;
  15113. dest[offset + 1] = (num >> 16) & 0xFF;
  15114. dest[offset + 2] = (num >> 8) & 0xFF;
  15115. dest[offset + 3] = num & 0xFF;
  15116. }
  15117. function writeData(dest, offset, data) {
  15118. var i, ii;
  15119. if (data instanceof Uint8Array) {
  15120. dest.set(data, offset);
  15121. } else if (typeof data === 'string') {
  15122. for (i = 0, ii = data.length; i < ii; i++) {
  15123. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15124. }
  15125. } else {
  15126. // treating everything else as array
  15127. for (i = 0, ii = data.length; i < ii; i++) {
  15128. dest[offset++] = data[i] & 0xFF;
  15129. }
  15130. }
  15131. }
  15132. function OpenTypeFileBuilder(sfnt) {
  15133. this.sfnt = sfnt;
  15134. this.tables = Object.create(null);
  15135. }
  15136. OpenTypeFileBuilder.getSearchParams =
  15137. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15138. var maxPower2 = 1, log2 = 0;
  15139. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15140. maxPower2 <<= 1;
  15141. log2++;
  15142. }
  15143. var searchRange = maxPower2 * entrySize;
  15144. return {
  15145. range: searchRange,
  15146. entry: log2,
  15147. rangeShift: entrySize * entriesCount - searchRange
  15148. };
  15149. };
  15150. var OTF_HEADER_SIZE = 12;
  15151. var OTF_TABLE_ENTRY_SIZE = 16;
  15152. OpenTypeFileBuilder.prototype = {
  15153. toArray: function OpenTypeFileBuilder_toArray() {
  15154. var sfnt = this.sfnt;
  15155. // Tables needs to be written by ascendant alphabetic order
  15156. var tables = this.tables;
  15157. var tablesNames = Object.keys(tables);
  15158. tablesNames.sort();
  15159. var numTables = tablesNames.length;
  15160. var i, j, jj, table, tableName;
  15161. // layout the tables data
  15162. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15163. var tableOffsets = [offset];
  15164. for (i = 0; i < numTables; i++) {
  15165. table = tables[tablesNames[i]];
  15166. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15167. offset += paddedLength;
  15168. tableOffsets.push(offset);
  15169. }
  15170. var file = new Uint8Array(offset);
  15171. // write the table data first (mostly for checksum)
  15172. for (i = 0; i < numTables; i++) {
  15173. table = tables[tablesNames[i]];
  15174. writeData(file, tableOffsets[i], table);
  15175. }
  15176. // sfnt version (4 bytes)
  15177. if (sfnt === 'true') {
  15178. // Windows hates the Mac TrueType sfnt version number
  15179. sfnt = string32(0x00010000);
  15180. }
  15181. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15182. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15183. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15184. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15185. // numTables (2 bytes)
  15186. writeInt16(file, 4, numTables);
  15187. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15188. // searchRange (2 bytes)
  15189. writeInt16(file, 6, searchParams.range);
  15190. // entrySelector (2 bytes)
  15191. writeInt16(file, 8, searchParams.entry);
  15192. // rangeShift (2 bytes)
  15193. writeInt16(file, 10, searchParams.rangeShift);
  15194. offset = OTF_HEADER_SIZE;
  15195. // writing table entries
  15196. for (i = 0; i < numTables; i++) {
  15197. tableName = tablesNames[i];
  15198. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15199. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15200. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15201. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15202. // checksum
  15203. var checksum = 0;
  15204. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15205. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15206. (file[j + 2] << 8) + file[j + 3];
  15207. checksum = (checksum + quad) | 0;
  15208. }
  15209. writeInt32(file, offset + 4, checksum);
  15210. // offset
  15211. writeInt32(file, offset + 8, tableOffsets[i]);
  15212. // length
  15213. writeInt32(file, offset + 12, tables[tableName].length);
  15214. offset += OTF_TABLE_ENTRY_SIZE;
  15215. }
  15216. return file;
  15217. },
  15218. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15219. if (tag in this.tables) {
  15220. throw new Error('Table ' + tag + ' already exists');
  15221. }
  15222. this.tables[tag] = data;
  15223. }
  15224. };
  15225. return OpenTypeFileBuilder;
  15226. })();
  15227. /**
  15228. * 'Font' is the class the outside world should use, it encapsulate all the font
  15229. * decoding logics whatever type it is (assuming the font type is supported).
  15230. *
  15231. * For example to read a Type1 font and to attach it to the document:
  15232. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15233. * type1Font.bind();
  15234. */
  15235. var Font = (function FontClosure() {
  15236. function Font(name, file, properties) {
  15237. var charCode, glyphName, fontChar;
  15238. this.name = name;
  15239. this.loadedName = properties.loadedName;
  15240. this.isType3Font = properties.isType3Font;
  15241. this.sizes = [];
  15242. this.glyphCache = {};
  15243. var names = name.split('+');
  15244. names = names.length > 1 ? names[1] : names[0];
  15245. names = names.split(/[-,_]/g)[0];
  15246. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15247. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15248. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15249. var type = properties.type;
  15250. var subtype = properties.subtype;
  15251. this.type = type;
  15252. this.fallbackName = (this.isMonospace ? 'monospace' :
  15253. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15254. this.differences = properties.differences;
  15255. this.widths = properties.widths;
  15256. this.defaultWidth = properties.defaultWidth;
  15257. this.composite = properties.composite;
  15258. this.wideChars = properties.wideChars;
  15259. this.cMap = properties.cMap;
  15260. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15261. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15262. this.fontMatrix = properties.fontMatrix;
  15263. this.bbox = properties.bbox;
  15264. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15265. this.toFontChar = [];
  15266. if (properties.type === 'Type3') {
  15267. for (charCode = 0; charCode < 256; charCode++) {
  15268. this.toFontChar[charCode] = (this.differences[charCode] ||
  15269. properties.defaultEncoding[charCode]);
  15270. }
  15271. this.fontType = FontType.TYPE3;
  15272. return;
  15273. }
  15274. this.cidEncoding = properties.cidEncoding;
  15275. this.vertical = properties.vertical;
  15276. if (this.vertical) {
  15277. this.vmetrics = properties.vmetrics;
  15278. this.defaultVMetrics = properties.defaultVMetrics;
  15279. }
  15280. if (!file || file.isEmpty) {
  15281. if (file) {
  15282. // Some bad PDF generators will include empty font files,
  15283. // attempting to recover by assuming that no file exists.
  15284. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15285. }
  15286. this.missingFile = true;
  15287. // The file data is not specified. Trying to fix the font name
  15288. // to be used with the canvas.font.
  15289. var fontName = name.replace(/[,_]/g, '-');
  15290. var isStandardFont = !!stdFontMap[fontName] ||
  15291. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15292. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15293. this.bold = (fontName.search(/bold/gi) !== -1);
  15294. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15295. (fontName.search(/italic/gi) !== -1));
  15296. // Use 'name' instead of 'fontName' here because the original
  15297. // name ArialBlack for example will be replaced by Helvetica.
  15298. this.black = (name.search(/Black/g) !== -1);
  15299. // if at least one width is present, remeasure all chars when exists
  15300. this.remeasure = Object.keys(this.widths).length > 0;
  15301. if (isStandardFont && type === 'CIDFontType2' &&
  15302. properties.cidEncoding.indexOf('Identity-') === 0) {
  15303. // Standard fonts might be embedded as CID font without glyph mapping.
  15304. // Building one based on GlyphMapForStandardFonts.
  15305. var map = [];
  15306. for (var code in GlyphMapForStandardFonts) {
  15307. map[+code] = GlyphMapForStandardFonts[code];
  15308. }
  15309. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15310. if (!isIdentityUnicode) {
  15311. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15312. map[+charCode] = unicodeCharCode;
  15313. });
  15314. }
  15315. this.toFontChar = map;
  15316. this.toUnicode = new ToUnicodeMap(map);
  15317. } else if (/Symbol/i.test(fontName)) {
  15318. var symbols = Encodings.SymbolSetEncoding;
  15319. for (charCode in symbols) {
  15320. fontChar = GlyphsUnicode[symbols[charCode]];
  15321. if (!fontChar) {
  15322. continue;
  15323. }
  15324. this.toFontChar[charCode] = fontChar;
  15325. }
  15326. for (charCode in properties.differences) {
  15327. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15328. if (!fontChar) {
  15329. continue;
  15330. }
  15331. this.toFontChar[charCode] = fontChar;
  15332. }
  15333. } else if (/Dingbats/i.test(fontName)) {
  15334. if (/Wingdings/i.test(name)) {
  15335. warn('Wingdings font without embedded font file, ' +
  15336. 'falling back to the ZapfDingbats encoding.');
  15337. }
  15338. var dingbats = Encodings.ZapfDingbatsEncoding;
  15339. for (charCode in dingbats) {
  15340. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15341. if (!fontChar) {
  15342. continue;
  15343. }
  15344. this.toFontChar[charCode] = fontChar;
  15345. }
  15346. for (charCode in properties.differences) {
  15347. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15348. if (!fontChar) {
  15349. continue;
  15350. }
  15351. this.toFontChar[charCode] = fontChar;
  15352. }
  15353. } else if (isStandardFont) {
  15354. this.toFontChar = [];
  15355. for (charCode in properties.defaultEncoding) {
  15356. glyphName = (properties.differences[charCode] ||
  15357. properties.defaultEncoding[charCode]);
  15358. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15359. }
  15360. } else {
  15361. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15362. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15363. if (notCidFont) {
  15364. glyphName = (properties.differences[charCode] ||
  15365. properties.defaultEncoding[charCode]);
  15366. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15367. }
  15368. this.toFontChar[charCode] = unicodeCharCode;
  15369. }.bind(this));
  15370. }
  15371. this.loadedName = fontName.split('-')[0];
  15372. this.loading = false;
  15373. this.fontType = getFontType(type, subtype);
  15374. return;
  15375. }
  15376. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15377. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15378. // Some TrueType fonts by mistake claim Type1C
  15379. if (isTrueTypeFile(file)) {
  15380. subtype = 'TrueType';
  15381. } else {
  15382. type = 'Type1';
  15383. }
  15384. }
  15385. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15386. type = 'CIDFontType0';
  15387. }
  15388. if (subtype === 'OpenType') {
  15389. type = 'OpenType';
  15390. }
  15391. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15392. if (type === 'CIDFontType0') {
  15393. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15394. }
  15395. var data;
  15396. switch (type) {
  15397. case 'MMType1':
  15398. info('MMType1 font (' + name + '), falling back to Type1.');
  15399. /* falls through */
  15400. case 'Type1':
  15401. case 'CIDFontType0':
  15402. this.mimetype = 'font/opentype';
  15403. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15404. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15405. adjustWidths(properties);
  15406. // Wrap the CFF data inside an OTF font file
  15407. data = this.convert(name, cff, properties);
  15408. break;
  15409. case 'OpenType':
  15410. case 'TrueType':
  15411. case 'CIDFontType2':
  15412. this.mimetype = 'font/opentype';
  15413. // Repair the TrueType file. It is can be damaged in the point of
  15414. // view of the sanitizer
  15415. data = this.checkAndRepair(name, file, properties);
  15416. if (this.isOpenType) {
  15417. type = 'OpenType';
  15418. }
  15419. break;
  15420. default:
  15421. error('Font ' + type + ' is not supported');
  15422. break;
  15423. }
  15424. this.data = data;
  15425. this.fontType = getFontType(type, subtype);
  15426. // Transfer some properties again that could change during font conversion
  15427. this.fontMatrix = properties.fontMatrix;
  15428. this.widths = properties.widths;
  15429. this.defaultWidth = properties.defaultWidth;
  15430. this.encoding = properties.baseEncoding;
  15431. this.seacMap = properties.seacMap;
  15432. this.loading = true;
  15433. }
  15434. Font.getFontID = (function () {
  15435. var ID = 1;
  15436. return function Font_getFontID() {
  15437. return String(ID++);
  15438. };
  15439. })();
  15440. function int16(b0, b1) {
  15441. return (b0 << 8) + b1;
  15442. }
  15443. function int32(b0, b1, b2, b3) {
  15444. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15445. }
  15446. function string16(value) {
  15447. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15448. }
  15449. function safeString16(value) {
  15450. // clamp value to the 16-bit int range
  15451. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15452. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15453. }
  15454. function isTrueTypeFile(file) {
  15455. var header = file.peekBytes(4);
  15456. return readUint32(header, 0) === 0x00010000;
  15457. }
  15458. function isType1File(file) {
  15459. var header = file.peekBytes(2);
  15460. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15461. if (header[0] === 0x25 && header[1] === 0x21) {
  15462. return true;
  15463. }
  15464. // ... obviously some fonts violate that part of the specification,
  15465. // please refer to the comment in |Type1Font| below.
  15466. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15467. return true;
  15468. }
  15469. return false;
  15470. }
  15471. /**
  15472. * Helper function for |adjustMapping|.
  15473. * @return {boolean}
  15474. */
  15475. function isProblematicUnicodeLocation(code) {
  15476. if (code <= 0x1F) { // Control chars
  15477. return true;
  15478. }
  15479. if (code >= 0x80 && code <= 0x9F) { // Control chars
  15480. return true;
  15481. }
  15482. if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
  15483. (code >= 0x2028 && code <= 0x202F) ||
  15484. (code >= 0x2060 && code <= 0x206F)) {
  15485. return true;
  15486. }
  15487. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
  15488. return true;
  15489. }
  15490. switch (code) {
  15491. case 0x7F: // Control char
  15492. case 0xA0: // Non breaking space
  15493. case 0xAD: // Soft hyphen
  15494. case 0x0E33: // Thai character SARA AM
  15495. case 0x2011: // Non breaking hyphen
  15496. case 0x205F: // Medium mathematical space
  15497. case 0x25CC: // Dotted circle (combining mark)
  15498. return true;
  15499. }
  15500. return false;
  15501. }
  15502. /**
  15503. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15504. * with their unicode value. It also moves char codes that are in known
  15505. * problematic locations.
  15506. * @return {Object} Two properties:
  15507. * 'toFontChar' - maps original char codes(the value that will be read
  15508. * from commands such as show text) to the char codes that will be used in the
  15509. * font that we build
  15510. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15511. */
  15512. function adjustMapping(charCodeToGlyphId, properties) {
  15513. var toUnicode = properties.toUnicode;
  15514. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15515. var isIdentityUnicode =
  15516. properties.toUnicode instanceof IdentityToUnicodeMap;
  15517. var newMap = Object.create(null);
  15518. var toFontChar = [];
  15519. var usedFontCharCodes = [];
  15520. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15521. for (var originalCharCode in charCodeToGlyphId) {
  15522. originalCharCode |= 0;
  15523. var glyphId = charCodeToGlyphId[originalCharCode];
  15524. var fontCharCode = originalCharCode;
  15525. // First try to map the value to a unicode position if a non identity map
  15526. // was created.
  15527. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15528. var unicode = toUnicode.get(fontCharCode);
  15529. // TODO: Try to map ligatures to the correct spot.
  15530. if (unicode.length === 1) {
  15531. fontCharCode = unicode.charCodeAt(0);
  15532. }
  15533. }
  15534. // Try to move control characters, special characters and already mapped
  15535. // characters to the private use area since they will not be drawn by
  15536. // canvas if left in their current position. Also, move characters if the
  15537. // font was symbolic and there is only an identity unicode map since the
  15538. // characters probably aren't in the correct position (fixes an issue
  15539. // with firefox and thuluthfont).
  15540. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15541. isProblematicUnicodeLocation(fontCharCode) ||
  15542. (isSymbolic && isIdentityUnicode)) &&
  15543. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15544. // Loop to try and find a free spot in the private use area.
  15545. do {
  15546. fontCharCode = nextAvailableFontCharCode++;
  15547. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15548. fontCharCode = 0xF020;
  15549. nextAvailableFontCharCode = fontCharCode + 1;
  15550. }
  15551. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15552. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15553. }
  15554. newMap[fontCharCode] = glyphId;
  15555. toFontChar[originalCharCode] = fontCharCode;
  15556. usedFontCharCodes[fontCharCode] = true;
  15557. }
  15558. return {
  15559. toFontChar: toFontChar,
  15560. charCodeToGlyphId: newMap,
  15561. nextAvailableFontCharCode: nextAvailableFontCharCode
  15562. };
  15563. }
  15564. function getRanges(glyphs) {
  15565. // Array.sort() sorts by characters, not numerically, so convert to an
  15566. // array of characters.
  15567. var codes = [];
  15568. for (var charCode in glyphs) {
  15569. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15570. }
  15571. codes.sort(function fontGetRangesSort(a, b) {
  15572. return a.fontCharCode - b.fontCharCode;
  15573. });
  15574. // Split the sorted codes into ranges.
  15575. var ranges = [];
  15576. var length = codes.length;
  15577. for (var n = 0; n < length; ) {
  15578. var start = codes[n].fontCharCode;
  15579. var codeIndices = [codes[n].glyphId];
  15580. ++n;
  15581. var end = start;
  15582. while (n < length && end + 1 === codes[n].fontCharCode) {
  15583. codeIndices.push(codes[n].glyphId);
  15584. ++end;
  15585. ++n;
  15586. if (end === 0xFFFF) {
  15587. break;
  15588. }
  15589. }
  15590. ranges.push([start, end, codeIndices]);
  15591. }
  15592. return ranges;
  15593. }
  15594. function createCmapTable(glyphs) {
  15595. var ranges = getRanges(glyphs);
  15596. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15597. var cmap = '\x00\x00' + // version
  15598. string16(numTables) + // numTables
  15599. '\x00\x03' + // platformID
  15600. '\x00\x01' + // encodingID
  15601. string32(4 + numTables * 8); // start of the table record
  15602. var i, ii, j, jj;
  15603. for (i = ranges.length - 1; i >= 0; --i) {
  15604. if (ranges[i][0] <= 0xFFFF) { break; }
  15605. }
  15606. var bmpLength = i + 1;
  15607. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15608. ranges[i][1] = 0xFFFE;
  15609. }
  15610. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15611. var segCount = bmpLength + trailingRangesCount;
  15612. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15613. // Fill up the 4 parallel arrays describing the segments.
  15614. var startCount = '';
  15615. var endCount = '';
  15616. var idDeltas = '';
  15617. var idRangeOffsets = '';
  15618. var glyphsIds = '';
  15619. var bias = 0;
  15620. var range, start, end, codes;
  15621. for (i = 0, ii = bmpLength; i < ii; i++) {
  15622. range = ranges[i];
  15623. start = range[0];
  15624. end = range[1];
  15625. startCount += string16(start);
  15626. endCount += string16(end);
  15627. codes = range[2];
  15628. var contiguous = true;
  15629. for (j = 1, jj = codes.length; j < jj; ++j) {
  15630. if (codes[j] !== codes[j - 1] + 1) {
  15631. contiguous = false;
  15632. break;
  15633. }
  15634. }
  15635. if (!contiguous) {
  15636. var offset = (segCount - i) * 2 + bias * 2;
  15637. bias += (end - start + 1);
  15638. idDeltas += string16(0);
  15639. idRangeOffsets += string16(offset);
  15640. for (j = 0, jj = codes.length; j < jj; ++j) {
  15641. glyphsIds += string16(codes[j]);
  15642. }
  15643. } else {
  15644. var startCode = codes[0];
  15645. idDeltas += string16((startCode - start) & 0xFFFF);
  15646. idRangeOffsets += string16(0);
  15647. }
  15648. }
  15649. if (trailingRangesCount > 0) {
  15650. endCount += '\xFF\xFF';
  15651. startCount += '\xFF\xFF';
  15652. idDeltas += '\x00\x01';
  15653. idRangeOffsets += '\x00\x00';
  15654. }
  15655. var format314 = '\x00\x00' + // language
  15656. string16(2 * segCount) +
  15657. string16(searchParams.range) +
  15658. string16(searchParams.entry) +
  15659. string16(searchParams.rangeShift) +
  15660. endCount + '\x00\x00' + startCount +
  15661. idDeltas + idRangeOffsets + glyphsIds;
  15662. var format31012 = '';
  15663. var header31012 = '';
  15664. if (numTables > 1) {
  15665. cmap += '\x00\x03' + // platformID
  15666. '\x00\x0A' + // encodingID
  15667. string32(4 + numTables * 8 +
  15668. 4 + format314.length); // start of the table record
  15669. format31012 = '';
  15670. for (i = 0, ii = ranges.length; i < ii; i++) {
  15671. range = ranges[i];
  15672. start = range[0];
  15673. codes = range[2];
  15674. var code = codes[0];
  15675. for (j = 1, jj = codes.length; j < jj; ++j) {
  15676. if (codes[j] !== codes[j - 1] + 1) {
  15677. end = range[0] + j - 1;
  15678. format31012 += string32(start) + // startCharCode
  15679. string32(end) + // endCharCode
  15680. string32(code); // startGlyphID
  15681. start = end + 1;
  15682. code = codes[j];
  15683. }
  15684. }
  15685. format31012 += string32(start) + // startCharCode
  15686. string32(range[1]) + // endCharCode
  15687. string32(code); // startGlyphID
  15688. }
  15689. header31012 = '\x00\x0C' + // format
  15690. '\x00\x00' + // reserved
  15691. string32(format31012.length + 16) + // length
  15692. '\x00\x00\x00\x00' + // language
  15693. string32(format31012.length / 12); // nGroups
  15694. }
  15695. return cmap + '\x00\x04' + // format
  15696. string16(format314.length + 4) + // length
  15697. format314 + header31012 + format31012;
  15698. }
  15699. function validateOS2Table(os2) {
  15700. var stream = new Stream(os2.data);
  15701. var version = stream.getUint16();
  15702. // TODO verify all OS/2 tables fields, but currently we validate only those
  15703. // that give us issues
  15704. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15705. var selection = stream.getUint16();
  15706. if (version < 4 && (selection & 0x0300)) {
  15707. return false;
  15708. }
  15709. var firstChar = stream.getUint16();
  15710. var lastChar = stream.getUint16();
  15711. if (firstChar > lastChar) {
  15712. return false;
  15713. }
  15714. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15715. var usWinAscent = stream.getUint16();
  15716. if (usWinAscent === 0) { // makes font unreadable by windows
  15717. return false;
  15718. }
  15719. // OS/2 appears to be valid, resetting some fields
  15720. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15721. return true;
  15722. }
  15723. function createOS2Table(properties, charstrings, override) {
  15724. override = override || {
  15725. unitsPerEm: 0,
  15726. yMax: 0,
  15727. yMin: 0,
  15728. ascent: 0,
  15729. descent: 0
  15730. };
  15731. var ulUnicodeRange1 = 0;
  15732. var ulUnicodeRange2 = 0;
  15733. var ulUnicodeRange3 = 0;
  15734. var ulUnicodeRange4 = 0;
  15735. var firstCharIndex = null;
  15736. var lastCharIndex = 0;
  15737. if (charstrings) {
  15738. for (var code in charstrings) {
  15739. code |= 0;
  15740. if (firstCharIndex > code || !firstCharIndex) {
  15741. firstCharIndex = code;
  15742. }
  15743. if (lastCharIndex < code) {
  15744. lastCharIndex = code;
  15745. }
  15746. var position = getUnicodeRangeFor(code);
  15747. if (position < 32) {
  15748. ulUnicodeRange1 |= 1 << position;
  15749. } else if (position < 64) {
  15750. ulUnicodeRange2 |= 1 << position - 32;
  15751. } else if (position < 96) {
  15752. ulUnicodeRange3 |= 1 << position - 64;
  15753. } else if (position < 123) {
  15754. ulUnicodeRange4 |= 1 << position - 96;
  15755. } else {
  15756. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15757. }
  15758. }
  15759. } else {
  15760. // TODO
  15761. firstCharIndex = 0;
  15762. lastCharIndex = 255;
  15763. }
  15764. var bbox = properties.bbox || [0, 0, 0, 0];
  15765. var unitsPerEm = (override.unitsPerEm ||
  15766. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15767. // if the font units differ to the PDF glyph space units
  15768. // then scale up the values
  15769. var scale = (properties.ascentScaled ? 1.0 :
  15770. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15771. var typoAscent = (override.ascent ||
  15772. Math.round(scale * (properties.ascent || bbox[3])));
  15773. var typoDescent = (override.descent ||
  15774. Math.round(scale * (properties.descent || bbox[1])));
  15775. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15776. typoDescent = -typoDescent; // fixing incorrect descent
  15777. }
  15778. var winAscent = override.yMax || typoAscent;
  15779. var winDescent = -override.yMin || -typoDescent;
  15780. return '\x00\x03' + // version
  15781. '\x02\x24' + // xAvgCharWidth
  15782. '\x01\xF4' + // usWeightClass
  15783. '\x00\x05' + // usWidthClass
  15784. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15785. '\x02\x8A' + // ySubscriptXSize
  15786. '\x02\xBB' + // ySubscriptYSize
  15787. '\x00\x00' + // ySubscriptXOffset
  15788. '\x00\x8C' + // ySubscriptYOffset
  15789. '\x02\x8A' + // ySuperScriptXSize
  15790. '\x02\xBB' + // ySuperScriptYSize
  15791. '\x00\x00' + // ySuperScriptXOffset
  15792. '\x01\xDF' + // ySuperScriptYOffset
  15793. '\x00\x31' + // yStrikeOutSize
  15794. '\x01\x02' + // yStrikeOutPosition
  15795. '\x00\x00' + // sFamilyClass
  15796. '\x00\x00\x06' +
  15797. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15798. '\x00\x00\x00\x00\x00\x00' + // Panose
  15799. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15800. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15801. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15802. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15803. '\x2A\x32\x31\x2A' + // achVendID
  15804. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15805. string16(firstCharIndex ||
  15806. properties.firstChar) + // usFirstCharIndex
  15807. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15808. string16(typoAscent) + // sTypoAscender
  15809. string16(typoDescent) + // sTypoDescender
  15810. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15811. string16(winAscent) + // usWinAscent
  15812. string16(winDescent) + // usWinDescent
  15813. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15814. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15815. string16(properties.xHeight) + // sxHeight
  15816. string16(properties.capHeight) + // sCapHeight
  15817. string16(0) + // usDefaultChar
  15818. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15819. '\x00\x03'; // usMaxContext
  15820. }
  15821. function createPostTable(properties) {
  15822. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15823. return ('\x00\x03\x00\x00' + // Version number
  15824. string32(angle) + // italicAngle
  15825. '\x00\x00' + // underlinePosition
  15826. '\x00\x00' + // underlineThickness
  15827. string32(properties.fixedPitch) + // isFixedPitch
  15828. '\x00\x00\x00\x00' + // minMemType42
  15829. '\x00\x00\x00\x00' + // maxMemType42
  15830. '\x00\x00\x00\x00' + // minMemType1
  15831. '\x00\x00\x00\x00'); // maxMemType1
  15832. }
  15833. function createNameTable(name, proto) {
  15834. if (!proto) {
  15835. proto = [[], []]; // no strings and unicode strings
  15836. }
  15837. var strings = [
  15838. proto[0][0] || 'Original licence', // 0.Copyright
  15839. proto[0][1] || name, // 1.Font family
  15840. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15841. proto[0][3] || 'uniqueID', // 3.Unique ID
  15842. proto[0][4] || name, // 4.Full font name
  15843. proto[0][5] || 'Version 0.11', // 5.Version
  15844. proto[0][6] || '', // 6.Postscript name
  15845. proto[0][7] || 'Unknown', // 7.Trademark
  15846. proto[0][8] || 'Unknown', // 8.Manufacturer
  15847. proto[0][9] || 'Unknown' // 9.Designer
  15848. ];
  15849. // Mac want 1-byte per character strings while Windows want
  15850. // 2-bytes per character, so duplicate the names table
  15851. var stringsUnicode = [];
  15852. var i, ii, j, jj, str;
  15853. for (i = 0, ii = strings.length; i < ii; i++) {
  15854. str = proto[1][i] || strings[i];
  15855. var strBufUnicode = [];
  15856. for (j = 0, jj = str.length; j < jj; j++) {
  15857. strBufUnicode.push(string16(str.charCodeAt(j)));
  15858. }
  15859. stringsUnicode.push(strBufUnicode.join(''));
  15860. }
  15861. var names = [strings, stringsUnicode];
  15862. var platforms = ['\x00\x01', '\x00\x03'];
  15863. var encodings = ['\x00\x00', '\x00\x01'];
  15864. var languages = ['\x00\x00', '\x04\x09'];
  15865. var namesRecordCount = strings.length * platforms.length;
  15866. var nameTable =
  15867. '\x00\x00' + // format
  15868. string16(namesRecordCount) + // Number of names Record
  15869. string16(namesRecordCount * 12 + 6); // Storage
  15870. // Build the name records field
  15871. var strOffset = 0;
  15872. for (i = 0, ii = platforms.length; i < ii; i++) {
  15873. var strs = names[i];
  15874. for (j = 0, jj = strs.length; j < jj; j++) {
  15875. str = strs[j];
  15876. var nameRecord =
  15877. platforms[i] + // platform ID
  15878. encodings[i] + // encoding ID
  15879. languages[i] + // language ID
  15880. string16(j) + // name ID
  15881. string16(str.length) +
  15882. string16(strOffset);
  15883. nameTable += nameRecord;
  15884. strOffset += str.length;
  15885. }
  15886. }
  15887. nameTable += strings.join('') + stringsUnicode.join('');
  15888. return nameTable;
  15889. }
  15890. Font.prototype = {
  15891. name: null,
  15892. font: null,
  15893. mimetype: null,
  15894. encoding: null,
  15895. get renderer() {
  15896. var renderer = FontRendererFactory.create(this);
  15897. return shadow(this, 'renderer', renderer);
  15898. },
  15899. exportData: function Font_exportData() {
  15900. var data = {};
  15901. for (var i in this) {
  15902. if (this.hasOwnProperty(i)) {
  15903. data[i] = this[i];
  15904. }
  15905. }
  15906. return data;
  15907. },
  15908. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15909. function readTableEntry(file) {
  15910. var tag = bytesToString(file.getBytes(4));
  15911. var checksum = file.getInt32();
  15912. var offset = file.getInt32() >>> 0;
  15913. var length = file.getInt32() >>> 0;
  15914. // Read the table associated data
  15915. var previousPosition = file.pos;
  15916. file.pos = file.start ? file.start : 0;
  15917. file.skip(offset);
  15918. var data = file.getBytes(length);
  15919. file.pos = previousPosition;
  15920. if (tag === 'head') {
  15921. // clearing checksum adjustment
  15922. data[8] = data[9] = data[10] = data[11] = 0;
  15923. data[17] |= 0x20; //Set font optimized for cleartype flag
  15924. }
  15925. return {
  15926. tag: tag,
  15927. checksum: checksum,
  15928. length: length,
  15929. offset: offset,
  15930. data: data
  15931. };
  15932. }
  15933. function readOpenTypeHeader(ttf) {
  15934. return {
  15935. version: bytesToString(ttf.getBytes(4)),
  15936. numTables: ttf.getUint16(),
  15937. searchRange: ttf.getUint16(),
  15938. entrySelector: ttf.getUint16(),
  15939. rangeShift: ttf.getUint16()
  15940. };
  15941. }
  15942. /**
  15943. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15944. * PDF spec
  15945. */
  15946. function readCmapTable(cmap, font, isSymbolicFont) {
  15947. var segment;
  15948. var start = (font.start ? font.start : 0) + cmap.offset;
  15949. font.pos = start;
  15950. var version = font.getUint16();
  15951. var numTables = font.getUint16();
  15952. var potentialTable;
  15953. var canBreak = false;
  15954. // There's an order of preference in terms of which cmap subtable to
  15955. // use:
  15956. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15957. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15958. // The following takes advantage of the fact that the tables are sorted
  15959. // to work.
  15960. for (var i = 0; i < numTables; i++) {
  15961. var platformId = font.getUint16();
  15962. var encodingId = font.getUint16();
  15963. var offset = font.getInt32() >>> 0;
  15964. var useTable = false;
  15965. if (platformId === 0 && encodingId === 0) {
  15966. useTable = true;
  15967. // Continue the loop since there still may be a higher priority
  15968. // table.
  15969. } else if (platformId === 1 && encodingId === 0) {
  15970. useTable = true;
  15971. // Continue the loop since there still may be a higher priority
  15972. // table.
  15973. } else if (platformId === 3 && encodingId === 1 &&
  15974. (!isSymbolicFont || !potentialTable)) {
  15975. useTable = true;
  15976. if (!isSymbolicFont) {
  15977. canBreak = true;
  15978. }
  15979. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15980. useTable = true;
  15981. canBreak = true;
  15982. }
  15983. if (useTable) {
  15984. potentialTable = {
  15985. platformId: platformId,
  15986. encodingId: encodingId,
  15987. offset: offset
  15988. };
  15989. }
  15990. if (canBreak) {
  15991. break;
  15992. }
  15993. }
  15994. if (!potentialTable) {
  15995. warn('Could not find a preferred cmap table.');
  15996. return {
  15997. platformId: -1,
  15998. encodingId: -1,
  15999. mappings: [],
  16000. hasShortCmap: false
  16001. };
  16002. }
  16003. font.pos = start + potentialTable.offset;
  16004. var format = font.getUint16();
  16005. var length = font.getUint16();
  16006. var language = font.getUint16();
  16007. var hasShortCmap = false;
  16008. var mappings = [];
  16009. var j, glyphId;
  16010. // TODO(mack): refactor this cmap subtable reading logic out
  16011. if (format === 0) {
  16012. for (j = 0; j < 256; j++) {
  16013. var index = font.getByte();
  16014. if (!index) {
  16015. continue;
  16016. }
  16017. mappings.push({
  16018. charCode: j,
  16019. glyphId: index
  16020. });
  16021. }
  16022. hasShortCmap = true;
  16023. } else if (format === 4) {
  16024. // re-creating the table in format 4 since the encoding
  16025. // might be changed
  16026. var segCount = (font.getUint16() >> 1);
  16027. font.getBytes(6); // skipping range fields
  16028. var segIndex, segments = [];
  16029. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16030. segments.push({ end: font.getUint16() });
  16031. }
  16032. font.getUint16();
  16033. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16034. segments[segIndex].start = font.getUint16();
  16035. }
  16036. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16037. segments[segIndex].delta = font.getUint16();
  16038. }
  16039. var offsetsCount = 0;
  16040. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16041. segment = segments[segIndex];
  16042. var rangeOffset = font.getUint16();
  16043. if (!rangeOffset) {
  16044. segment.offsetIndex = -1;
  16045. continue;
  16046. }
  16047. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16048. segment.offsetIndex = offsetIndex;
  16049. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16050. segment.end - segment.start + 1);
  16051. }
  16052. var offsets = [];
  16053. for (j = 0; j < offsetsCount; j++) {
  16054. offsets.push(font.getUint16());
  16055. }
  16056. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16057. segment = segments[segIndex];
  16058. start = segment.start;
  16059. var end = segment.end;
  16060. var delta = segment.delta;
  16061. offsetIndex = segment.offsetIndex;
  16062. for (j = start; j <= end; j++) {
  16063. if (j === 0xFFFF) {
  16064. continue;
  16065. }
  16066. glyphId = (offsetIndex < 0 ?
  16067. j : offsets[offsetIndex + j - start]);
  16068. glyphId = (glyphId + delta) & 0xFFFF;
  16069. if (glyphId === 0) {
  16070. continue;
  16071. }
  16072. mappings.push({
  16073. charCode: j,
  16074. glyphId: glyphId
  16075. });
  16076. }
  16077. }
  16078. } else if (format === 6) {
  16079. // Format 6 is a 2-bytes dense mapping, which means the font data
  16080. // lives glue together even if they are pretty far in the unicode
  16081. // table. (This looks weird, so I can have missed something), this
  16082. // works on Linux but seems to fails on Mac so let's rewrite the
  16083. // cmap table to a 3-1-4 style
  16084. var firstCode = font.getUint16();
  16085. var entryCount = font.getUint16();
  16086. for (j = 0; j < entryCount; j++) {
  16087. glyphId = font.getUint16();
  16088. var charCode = firstCode + j;
  16089. mappings.push({
  16090. charCode: charCode,
  16091. glyphId: glyphId
  16092. });
  16093. }
  16094. } else {
  16095. error('cmap table has unsupported format: ' + format);
  16096. }
  16097. // removing duplicate entries
  16098. mappings.sort(function (a, b) {
  16099. return a.charCode - b.charCode;
  16100. });
  16101. for (i = 1; i < mappings.length; i++) {
  16102. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16103. mappings.splice(i, 1);
  16104. i--;
  16105. }
  16106. }
  16107. return {
  16108. platformId: potentialTable.platformId,
  16109. encodingId: potentialTable.encodingId,
  16110. mappings: mappings,
  16111. hasShortCmap: hasShortCmap
  16112. };
  16113. }
  16114. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16115. if (!header) {
  16116. if (metrics) {
  16117. metrics.data = null;
  16118. }
  16119. return;
  16120. }
  16121. font.pos = (font.start ? font.start : 0) + header.offset;
  16122. font.pos += header.length - 2;
  16123. var numOfMetrics = font.getUint16();
  16124. if (numOfMetrics > numGlyphs) {
  16125. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16126. 'greater than the numGlyphs (' + numGlyphs + ')');
  16127. // Reduce numOfMetrics if it is greater than numGlyphs
  16128. numOfMetrics = numGlyphs;
  16129. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16130. header.data[35] = numOfMetrics & 0x00ff;
  16131. }
  16132. var numOfSidebearings = numGlyphs - numOfMetrics;
  16133. var numMissing = numOfSidebearings -
  16134. ((metrics.length - numOfMetrics * 4) >> 1);
  16135. if (numMissing > 0) {
  16136. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16137. // Since we need to add two properties for each glyph, this explains
  16138. // the use of |numMissing * 2| when initializing the typed array.
  16139. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16140. entries.set(metrics.data);
  16141. metrics.data = entries;
  16142. }
  16143. }
  16144. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16145. hintsValid) {
  16146. if (sourceEnd - sourceStart <= 12) {
  16147. // glyph with data less than 12 is invalid one
  16148. return 0;
  16149. }
  16150. var glyf = source.subarray(sourceStart, sourceEnd);
  16151. var contoursCount = (glyf[0] << 8) | glyf[1];
  16152. if (contoursCount & 0x8000) {
  16153. // complex glyph, writing as is
  16154. dest.set(glyf, destStart);
  16155. return glyf.length;
  16156. }
  16157. var i, j = 10, flagsCount = 0;
  16158. for (i = 0; i < contoursCount; i++) {
  16159. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16160. flagsCount = endPoint + 1;
  16161. j += 2;
  16162. }
  16163. // skipping instructions
  16164. var instructionsStart = j;
  16165. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16166. j += 2 + instructionsLength;
  16167. var instructionsEnd = j;
  16168. // validating flags
  16169. var coordinatesLength = 0;
  16170. for (i = 0; i < flagsCount; i++) {
  16171. var flag = glyf[j++];
  16172. if (flag & 0xC0) {
  16173. // reserved flags must be zero, cleaning up
  16174. glyf[j - 1] = flag & 0x3F;
  16175. }
  16176. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16177. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16178. coordinatesLength += xyLength;
  16179. if (flag & 8) {
  16180. var repeat = glyf[j++];
  16181. i += repeat;
  16182. coordinatesLength += repeat * xyLength;
  16183. }
  16184. }
  16185. // glyph without coordinates will be rejected
  16186. if (coordinatesLength === 0) {
  16187. return 0;
  16188. }
  16189. var glyphDataLength = j + coordinatesLength;
  16190. if (glyphDataLength > glyf.length) {
  16191. // not enough data for coordinates
  16192. return 0;
  16193. }
  16194. if (!hintsValid && instructionsLength > 0) {
  16195. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16196. dest.set([0, 0], destStart + instructionsStart);
  16197. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16198. destStart + instructionsStart + 2);
  16199. glyphDataLength -= instructionsLength;
  16200. if (glyf.length - glyphDataLength > 3) {
  16201. glyphDataLength = (glyphDataLength + 3) & ~3;
  16202. }
  16203. return glyphDataLength;
  16204. }
  16205. if (glyf.length - glyphDataLength > 3) {
  16206. // truncating and aligning to 4 bytes the long glyph data
  16207. glyphDataLength = (glyphDataLength + 3) & ~3;
  16208. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16209. return glyphDataLength;
  16210. }
  16211. // glyph data is fine
  16212. dest.set(glyf, destStart);
  16213. return glyf.length;
  16214. }
  16215. function sanitizeHead(head, numGlyphs, locaLength) {
  16216. var data = head.data;
  16217. // Validate version:
  16218. // Should always be 0x00010000
  16219. var version = int32(data[0], data[1], data[2], data[3]);
  16220. if (version >> 16 !== 1) {
  16221. info('Attempting to fix invalid version in head table: ' + version);
  16222. data[0] = 0;
  16223. data[1] = 1;
  16224. data[2] = 0;
  16225. data[3] = 0;
  16226. }
  16227. var indexToLocFormat = int16(data[50], data[51]);
  16228. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16229. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16230. indexToLocFormat);
  16231. // The value of indexToLocFormat should be 0 if the loca table
  16232. // consists of short offsets, and should be 1 if the loca table
  16233. // consists of long offsets.
  16234. //
  16235. // The number of entries in the loca table should be numGlyphs + 1.
  16236. //
  16237. // Using this information, we can work backwards to deduce if the
  16238. // size of each offset in the loca table, and thus figure out the
  16239. // appropriate value for indexToLocFormat.
  16240. var numGlyphsPlusOne = numGlyphs + 1;
  16241. if (locaLength === numGlyphsPlusOne << 1) {
  16242. // 0x0000 indicates the loca table consists of short offsets
  16243. data[50] = 0;
  16244. data[51] = 0;
  16245. } else if (locaLength === numGlyphsPlusOne << 2) {
  16246. // 0x0001 indicates the loca table consists of long offsets
  16247. data[50] = 0;
  16248. data[51] = 1;
  16249. } else {
  16250. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16251. }
  16252. }
  16253. }
  16254. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16255. isGlyphLocationsLong, hintsValid,
  16256. dupFirstEntry) {
  16257. var itemSize, itemDecode, itemEncode;
  16258. if (isGlyphLocationsLong) {
  16259. itemSize = 4;
  16260. itemDecode = function fontItemDecodeLong(data, offset) {
  16261. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16262. (data[offset + 2] << 8) | data[offset + 3];
  16263. };
  16264. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16265. data[offset] = (value >>> 24) & 0xFF;
  16266. data[offset + 1] = (value >> 16) & 0xFF;
  16267. data[offset + 2] = (value >> 8) & 0xFF;
  16268. data[offset + 3] = value & 0xFF;
  16269. };
  16270. } else {
  16271. itemSize = 2;
  16272. itemDecode = function fontItemDecode(data, offset) {
  16273. return (data[offset] << 9) | (data[offset + 1] << 1);
  16274. };
  16275. itemEncode = function fontItemEncode(data, offset, value) {
  16276. data[offset] = (value >> 9) & 0xFF;
  16277. data[offset + 1] = (value >> 1) & 0xFF;
  16278. };
  16279. }
  16280. var locaData = loca.data;
  16281. var locaDataSize = itemSize * (1 + numGlyphs);
  16282. // is loca.data too short or long?
  16283. if (locaData.length !== locaDataSize) {
  16284. locaData = new Uint8Array(locaDataSize);
  16285. locaData.set(loca.data.subarray(0, locaDataSize));
  16286. loca.data = locaData;
  16287. }
  16288. // removing the invalid glyphs
  16289. var oldGlyfData = glyf.data;
  16290. var oldGlyfDataLength = oldGlyfData.length;
  16291. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16292. var startOffset = itemDecode(locaData, 0);
  16293. var writeOffset = 0;
  16294. var missingGlyphData = {};
  16295. itemEncode(locaData, 0, writeOffset);
  16296. var i, j;
  16297. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16298. var endOffset = itemDecode(locaData, j);
  16299. if (endOffset > oldGlyfDataLength &&
  16300. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16301. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16302. // the glyf table size, which makes last glyph out of range.
  16303. endOffset = oldGlyfDataLength;
  16304. }
  16305. if (endOffset > oldGlyfDataLength) {
  16306. // glyph end offset points outside glyf data, rejecting the glyph
  16307. itemEncode(locaData, j, writeOffset);
  16308. startOffset = endOffset;
  16309. continue;
  16310. }
  16311. if (startOffset === endOffset) {
  16312. missingGlyphData[i] = true;
  16313. }
  16314. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16315. newGlyfData, writeOffset, hintsValid);
  16316. writeOffset += newLength;
  16317. itemEncode(locaData, j, writeOffset);
  16318. startOffset = endOffset;
  16319. }
  16320. if (writeOffset === 0) {
  16321. // glyf table cannot be empty -- redoing the glyf and loca tables
  16322. // to have single glyph with one point
  16323. var simpleGlyph = new Uint8Array(
  16324. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16325. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16326. itemEncode(locaData, j, simpleGlyph.length);
  16327. }
  16328. glyf.data = simpleGlyph;
  16329. return missingGlyphData;
  16330. }
  16331. if (dupFirstEntry) {
  16332. var firstEntryLength = itemDecode(locaData, itemSize);
  16333. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16334. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16335. } else {
  16336. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16337. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16338. }
  16339. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16340. itemEncode(loca.data, locaData.length - itemSize,
  16341. writeOffset + firstEntryLength);
  16342. } else {
  16343. glyf.data = newGlyfData.subarray(0, writeOffset);
  16344. }
  16345. return missingGlyphData;
  16346. }
  16347. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16348. var start = (font.start ? font.start : 0) + post.offset;
  16349. font.pos = start;
  16350. var length = post.length, end = start + length;
  16351. var version = font.getInt32();
  16352. // skip rest to the tables
  16353. font.getBytes(28);
  16354. var glyphNames;
  16355. var valid = true;
  16356. var i;
  16357. switch (version) {
  16358. case 0x00010000:
  16359. glyphNames = MacStandardGlyphOrdering;
  16360. break;
  16361. case 0x00020000:
  16362. var numGlyphs = font.getUint16();
  16363. if (numGlyphs !== maxpNumGlyphs) {
  16364. valid = false;
  16365. break;
  16366. }
  16367. var glyphNameIndexes = [];
  16368. for (i = 0; i < numGlyphs; ++i) {
  16369. var index = font.getUint16();
  16370. if (index >= 32768) {
  16371. valid = false;
  16372. break;
  16373. }
  16374. glyphNameIndexes.push(index);
  16375. }
  16376. if (!valid) {
  16377. break;
  16378. }
  16379. var customNames = [];
  16380. var strBuf = [];
  16381. while (font.pos < end) {
  16382. var stringLength = font.getByte();
  16383. strBuf.length = stringLength;
  16384. for (i = 0; i < stringLength; ++i) {
  16385. strBuf[i] = String.fromCharCode(font.getByte());
  16386. }
  16387. customNames.push(strBuf.join(''));
  16388. }
  16389. glyphNames = [];
  16390. for (i = 0; i < numGlyphs; ++i) {
  16391. var j = glyphNameIndexes[i];
  16392. if (j < 258) {
  16393. glyphNames.push(MacStandardGlyphOrdering[j]);
  16394. continue;
  16395. }
  16396. glyphNames.push(customNames[j - 258]);
  16397. }
  16398. break;
  16399. case 0x00030000:
  16400. break;
  16401. default:
  16402. warn('Unknown/unsupported post table version ' + version);
  16403. valid = false;
  16404. break;
  16405. }
  16406. properties.glyphNames = glyphNames;
  16407. return valid;
  16408. }
  16409. function readNameTable(nameTable) {
  16410. var start = (font.start ? font.start : 0) + nameTable.offset;
  16411. font.pos = start;
  16412. var names = [[], []];
  16413. var length = nameTable.length, end = start + length;
  16414. var format = font.getUint16();
  16415. var FORMAT_0_HEADER_LENGTH = 6;
  16416. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16417. // unsupported name table format or table "too" small
  16418. return names;
  16419. }
  16420. var numRecords = font.getUint16();
  16421. var stringsStart = font.getUint16();
  16422. var records = [];
  16423. var NAME_RECORD_LENGTH = 12;
  16424. var i, ii;
  16425. for (i = 0; i < numRecords &&
  16426. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16427. var r = {
  16428. platform: font.getUint16(),
  16429. encoding: font.getUint16(),
  16430. language: font.getUint16(),
  16431. name: font.getUint16(),
  16432. length: font.getUint16(),
  16433. offset: font.getUint16()
  16434. };
  16435. // using only Macintosh and Windows platform/encoding names
  16436. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16437. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16438. records.push(r);
  16439. }
  16440. }
  16441. for (i = 0, ii = records.length; i < ii; i++) {
  16442. var record = records[i];
  16443. var pos = start + stringsStart + record.offset;
  16444. if (pos + record.length > end) {
  16445. continue; // outside of name table, ignoring
  16446. }
  16447. font.pos = pos;
  16448. var nameIndex = record.name;
  16449. if (record.encoding) {
  16450. // unicode
  16451. var str = '';
  16452. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16453. str += String.fromCharCode(font.getUint16());
  16454. }
  16455. names[1][nameIndex] = str;
  16456. } else {
  16457. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16458. }
  16459. }
  16460. return names;
  16461. }
  16462. var TTOpsStackDeltas = [
  16463. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16464. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16465. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16466. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16467. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16468. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16469. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16470. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16471. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16472. // 0xC0-DF == -1 and 0xE0-FF == -2
  16473. function sanitizeTTProgram(table, ttContext) {
  16474. var data = table.data;
  16475. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16476. var stack = [];
  16477. var callstack = [];
  16478. var functionsCalled = [];
  16479. var tooComplexToFollowFunctions =
  16480. ttContext.tooComplexToFollowFunctions;
  16481. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16482. for (var ii = data.length; i < ii;) {
  16483. var op = data[i++];
  16484. // The TrueType instruction set docs can be found at
  16485. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16486. if (op === 0x40) { // NPUSHB - pushes n bytes
  16487. n = data[i++];
  16488. if (inFDEF || inELSE) {
  16489. i += n;
  16490. } else {
  16491. for (j = 0; j < n; j++) {
  16492. stack.push(data[i++]);
  16493. }
  16494. }
  16495. } else if (op === 0x41) { // NPUSHW - pushes n words
  16496. n = data[i++];
  16497. if (inFDEF || inELSE) {
  16498. i += n * 2;
  16499. } else {
  16500. for (j = 0; j < n; j++) {
  16501. b = data[i++];
  16502. stack.push((b << 8) | data[i++]);
  16503. }
  16504. }
  16505. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16506. n = op - 0xB0 + 1;
  16507. if (inFDEF || inELSE) {
  16508. i += n;
  16509. } else {
  16510. for (j = 0; j < n; j++) {
  16511. stack.push(data[i++]);
  16512. }
  16513. }
  16514. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16515. n = op - 0xB8 + 1;
  16516. if (inFDEF || inELSE) {
  16517. i += n * 2;
  16518. } else {
  16519. for (j = 0; j < n; j++) {
  16520. b = data[i++];
  16521. stack.push((b << 8) | data[i++]);
  16522. }
  16523. }
  16524. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16525. if (!inFDEF && !inELSE) {
  16526. // collecting inforamtion about which functions are used
  16527. funcId = stack[stack.length - 1];
  16528. ttContext.functionsUsed[funcId] = true;
  16529. if (funcId in ttContext.functionsStackDeltas) {
  16530. stack.length += ttContext.functionsStackDeltas[funcId];
  16531. } else if (funcId in ttContext.functionsDefined &&
  16532. functionsCalled.indexOf(funcId) < 0) {
  16533. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16534. functionsCalled.push(funcId);
  16535. pc = ttContext.functionsDefined[funcId];
  16536. if (!pc) {
  16537. warn('TT: CALL non-existent function');
  16538. ttContext.hintsValid = false;
  16539. return;
  16540. }
  16541. data = pc.data;
  16542. i = pc.i;
  16543. }
  16544. }
  16545. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16546. if (inFDEF || inELSE) {
  16547. warn('TT: nested FDEFs not allowed');
  16548. tooComplexToFollowFunctions = true;
  16549. }
  16550. inFDEF = true;
  16551. // collecting inforamtion about which functions are defined
  16552. lastDeff = i;
  16553. funcId = stack.pop();
  16554. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16555. } else if (op === 0x2D) { // ENDF - end of function
  16556. if (inFDEF) {
  16557. inFDEF = false;
  16558. lastEndf = i;
  16559. } else {
  16560. pc = callstack.pop();
  16561. if (!pc) {
  16562. warn('TT: ENDF bad stack');
  16563. ttContext.hintsValid = false;
  16564. return;
  16565. }
  16566. funcId = functionsCalled.pop();
  16567. data = pc.data;
  16568. i = pc.i;
  16569. ttContext.functionsStackDeltas[funcId] =
  16570. stack.length - pc.stackTop;
  16571. }
  16572. } else if (op === 0x89) { // IDEF - instruction definition
  16573. if (inFDEF || inELSE) {
  16574. warn('TT: nested IDEFs not allowed');
  16575. tooComplexToFollowFunctions = true;
  16576. }
  16577. inFDEF = true;
  16578. // recording it as a function to track ENDF
  16579. lastDeff = i;
  16580. } else if (op === 0x58) { // IF
  16581. ++ifLevel;
  16582. } else if (op === 0x1B) { // ELSE
  16583. inELSE = ifLevel;
  16584. } else if (op === 0x59) { // EIF
  16585. if (inELSE === ifLevel) {
  16586. inELSE = 0;
  16587. }
  16588. --ifLevel;
  16589. } else if (op === 0x1C) { // JMPR
  16590. if (!inFDEF && !inELSE) {
  16591. var offset = stack[stack.length - 1];
  16592. // only jumping forward to prevent infinite loop
  16593. if (offset > 0) {
  16594. i += offset - 1;
  16595. }
  16596. }
  16597. }
  16598. // Adjusting stack not extactly, but just enough to get function id
  16599. if (!inFDEF && !inELSE) {
  16600. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16601. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16602. if (op >= 0x71 && op <= 0x75) {
  16603. n = stack.pop();
  16604. if (n === n) {
  16605. stackDelta = -n * 2;
  16606. }
  16607. }
  16608. while (stackDelta < 0 && stack.length > 0) {
  16609. stack.pop();
  16610. stackDelta++;
  16611. }
  16612. while (stackDelta > 0) {
  16613. stack.push(NaN); // pushing any number into stack
  16614. stackDelta--;
  16615. }
  16616. }
  16617. }
  16618. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16619. var content = [data];
  16620. if (i > data.length) {
  16621. content.push(new Uint8Array(i - data.length));
  16622. }
  16623. if (lastDeff > lastEndf) {
  16624. warn('TT: complementing a missing function tail');
  16625. // new function definition started, but not finished
  16626. // complete function by [CLEAR, ENDF]
  16627. content.push(new Uint8Array([0x22, 0x2D]));
  16628. }
  16629. foldTTTable(table, content);
  16630. }
  16631. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16632. if (ttContext.tooComplexToFollowFunctions) {
  16633. return;
  16634. }
  16635. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16636. warn('TT: more functions defined than expected');
  16637. ttContext.hintsValid = false;
  16638. return;
  16639. }
  16640. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16641. if (j > maxFunctionDefs) {
  16642. warn('TT: invalid function id: ' + j);
  16643. ttContext.hintsValid = false;
  16644. return;
  16645. }
  16646. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16647. warn('TT: undefined function: ' + j);
  16648. ttContext.hintsValid = false;
  16649. return;
  16650. }
  16651. }
  16652. }
  16653. function foldTTTable(table, content) {
  16654. if (content.length > 1) {
  16655. // concatenating the content items
  16656. var newLength = 0;
  16657. var j, jj;
  16658. for (j = 0, jj = content.length; j < jj; j++) {
  16659. newLength += content[j].length;
  16660. }
  16661. newLength = (newLength + 3) & ~3;
  16662. var result = new Uint8Array(newLength);
  16663. var pos = 0;
  16664. for (j = 0, jj = content.length; j < jj; j++) {
  16665. result.set(content[j], pos);
  16666. pos += content[j].length;
  16667. }
  16668. table.data = result;
  16669. table.length = newLength;
  16670. }
  16671. }
  16672. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16673. var ttContext = {
  16674. functionsDefined: [],
  16675. functionsUsed: [],
  16676. functionsStackDeltas: [],
  16677. tooComplexToFollowFunctions: false,
  16678. hintsValid: true
  16679. };
  16680. if (fpgm) {
  16681. sanitizeTTProgram(fpgm, ttContext);
  16682. }
  16683. if (prep) {
  16684. sanitizeTTProgram(prep, ttContext);
  16685. }
  16686. if (fpgm) {
  16687. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16688. }
  16689. if (cvt && (cvt.length & 1)) {
  16690. var cvtData = new Uint8Array(cvt.length + 1);
  16691. cvtData.set(cvt.data);
  16692. cvt.data = cvtData;
  16693. }
  16694. return ttContext.hintsValid;
  16695. }
  16696. // The following steps modify the original font data, making copy
  16697. font = new Stream(new Uint8Array(font.getBytes()));
  16698. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16699. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16700. var header = readOpenTypeHeader(font);
  16701. var numTables = header.numTables;
  16702. var cff, cffFile;
  16703. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16704. hmtx: null, maxp: null, name: null, post: null };
  16705. var table;
  16706. for (var i = 0; i < numTables; i++) {
  16707. table = readTableEntry(font);
  16708. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16709. continue; // skipping table if it's not a required or optional table
  16710. }
  16711. if (table.length === 0) {
  16712. continue; // skipping empty tables
  16713. }
  16714. tables[table.tag] = table;
  16715. }
  16716. var isTrueType = !tables['CFF '];
  16717. if (!isTrueType) {
  16718. // OpenType font
  16719. if (header.version === 'OTTO' ||
  16720. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16721. // no major tables: throwing everything at CFFFont
  16722. cffFile = new Stream(tables['CFF '].data);
  16723. cff = new CFFFont(cffFile, properties);
  16724. return this.convert(name, cff, properties);
  16725. }
  16726. delete tables.glyf;
  16727. delete tables.loca;
  16728. delete tables.fpgm;
  16729. delete tables.prep;
  16730. delete tables['cvt '];
  16731. this.isOpenType = true;
  16732. } else {
  16733. if (!tables.glyf || !tables.loca) {
  16734. error('Required "glyf" or "loca" tables are not found');
  16735. }
  16736. this.isOpenType = false;
  16737. }
  16738. if (!tables.maxp) {
  16739. error('Required "maxp" table is not found');
  16740. }
  16741. font.pos = (font.start || 0) + tables.maxp.offset;
  16742. var version = font.getInt32();
  16743. var numGlyphs = font.getUint16();
  16744. var maxFunctionDefs = 0;
  16745. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16746. // maxZones can be invalid
  16747. font.pos += 8;
  16748. var maxZones = font.getUint16();
  16749. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16750. tables.maxp.data[14] = 0;
  16751. tables.maxp.data[15] = 2;
  16752. }
  16753. font.pos += 4;
  16754. maxFunctionDefs = font.getUint16();
  16755. }
  16756. var dupFirstEntry = false;
  16757. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16758. properties.toUnicode.get(0) > '\u0000') {
  16759. // oracle's defect (see 3427), duplicating first entry
  16760. dupFirstEntry = true;
  16761. numGlyphs++;
  16762. tables.maxp.data[4] = numGlyphs >> 8;
  16763. tables.maxp.data[5] = numGlyphs & 255;
  16764. }
  16765. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16766. tables['cvt '], maxFunctionDefs);
  16767. if (!hintsValid) {
  16768. delete tables.fpgm;
  16769. delete tables.prep;
  16770. delete tables['cvt '];
  16771. }
  16772. // Ensure the hmtx table contains the advance width and
  16773. // sidebearings information for numGlyphs in the maxp table
  16774. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16775. if (!tables.head) {
  16776. error('Required "head" table is not found');
  16777. }
  16778. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16779. var missingGlyphs = {};
  16780. if (isTrueType) {
  16781. var isGlyphLocationsLong = int16(tables.head.data[50],
  16782. tables.head.data[51]);
  16783. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  16784. numGlyphs, isGlyphLocationsLong,
  16785. hintsValid, dupFirstEntry);
  16786. }
  16787. if (!tables.hhea) {
  16788. error('Required "hhea" table is not found');
  16789. }
  16790. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16791. // Sometimes it's 0. That needs to be fixed
  16792. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16793. tables.hhea.data[10] = 0xFF;
  16794. tables.hhea.data[11] = 0xFF;
  16795. }
  16796. // The 'post' table has glyphs names.
  16797. if (tables.post) {
  16798. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16799. if (!valid) {
  16800. tables.post = null;
  16801. }
  16802. }
  16803. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  16804. function hasGlyph(glyphId, charCode) {
  16805. if (!missingGlyphs[glyphId]) {
  16806. return true;
  16807. }
  16808. if (charCode >= 0 && toUnicode.has(charCode)) {
  16809. return true;
  16810. }
  16811. return false;
  16812. }
  16813. if (properties.type === 'CIDFontType2') {
  16814. var cidToGidMap = properties.cidToGidMap || [];
  16815. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  16816. properties.cMap.forEach(function(charCode, cid) {
  16817. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16818. var glyphId = -1;
  16819. if (isCidToGidMapEmpty) {
  16820. glyphId = charCode;
  16821. } else if (cidToGidMap[cid] !== undefined) {
  16822. glyphId = cidToGidMap[cid];
  16823. }
  16824. if (glyphId >= 0 && glyphId < numGlyphs &&
  16825. hasGlyph(glyphId, charCode)) {
  16826. charCodeToGlyphId[charCode] = glyphId;
  16827. }
  16828. });
  16829. if (dupFirstEntry) {
  16830. charCodeToGlyphId[0] = numGlyphs - 1;
  16831. }
  16832. } else {
  16833. // Most of the following logic in this code branch is based on the
  16834. // 9.6.6.4 of the PDF spec.
  16835. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16836. var cmapPlatformId = cmapTable.platformId;
  16837. var cmapEncodingId = cmapTable.encodingId;
  16838. var cmapMappings = cmapTable.mappings;
  16839. var cmapMappingsLength = cmapMappings.length;
  16840. var hasEncoding = properties.differences.length ||
  16841. !!properties.baseEncodingName;
  16842. // The spec seems to imply that if the font is symbolic the encoding
  16843. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16844. // where the the font is symbolic and it has an encoding.
  16845. if (hasEncoding &&
  16846. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16847. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16848. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16849. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16850. // When no preferred cmap table was found and |baseEncodingName| is
  16851. // one of the predefined encodings, we seem to obtain a better
  16852. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16853. // TODO: Note that this is a hack which should be removed as soon as
  16854. // we have proper support for more exotic cmap tables.
  16855. var baseEncoding = [];
  16856. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16857. properties.baseEncodingName === 'WinAnsiEncoding') {
  16858. baseEncoding = Encodings[properties.baseEncodingName];
  16859. }
  16860. for (charCode = 0; charCode < 256; charCode++) {
  16861. var glyphName;
  16862. if (this.differences && charCode in this.differences) {
  16863. glyphName = this.differences[charCode];
  16864. } else if (charCode in baseEncoding &&
  16865. baseEncoding[charCode] !== '') {
  16866. glyphName = baseEncoding[charCode];
  16867. } else {
  16868. glyphName = Encodings.StandardEncoding[charCode];
  16869. }
  16870. if (!glyphName) {
  16871. continue;
  16872. }
  16873. var unicodeOrCharCode;
  16874. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16875. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16876. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16877. // TODO: the encoding needs to be updated with mac os table.
  16878. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16879. }
  16880. var found = false;
  16881. for (i = 0; i < cmapMappingsLength; ++i) {
  16882. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  16883. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  16884. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16885. found = true;
  16886. break;
  16887. }
  16888. }
  16889. if (!found && properties.glyphNames) {
  16890. // Try to map using the post table. There are currently no known
  16891. // pdfs that this fixes.
  16892. var glyphId = properties.glyphNames.indexOf(glyphName);
  16893. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  16894. charCodeToGlyphId[charCode] = glyphId;
  16895. }
  16896. }
  16897. }
  16898. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  16899. // Default Unicode semantics, use the charcodes as is.
  16900. for (i = 0; i < cmapMappingsLength; ++i) {
  16901. charCodeToGlyphId[cmapMappings[i].charCode] =
  16902. cmapMappings[i].glyphId;
  16903. }
  16904. } else {
  16905. // For (3, 0) cmap tables:
  16906. // The charcode key being stored in charCodeToGlyphId is the lower
  16907. // byte of the two-byte charcodes of the cmap table since according to
  16908. // the spec: 'each byte from the string shall be prepended with the
  16909. // high byte of the range [of charcodes in the cmap table], to form
  16910. // a two-byte character, which shall be used to select the
  16911. // associated glyph description from the subtable'.
  16912. //
  16913. // For (1, 0) cmap tables:
  16914. // 'single bytes from the string shall be used to look up the
  16915. // associated glyph descriptions from the subtable'. This means
  16916. // charcodes in the cmap will be single bytes, so no-op since
  16917. // glyph.charCode & 0xFF === glyph.charCode
  16918. for (i = 0; i < cmapMappingsLength; ++i) {
  16919. charCode = cmapMappings[i].charCode & 0xFF;
  16920. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16921. }
  16922. }
  16923. }
  16924. if (charCodeToGlyphId.length === 0) {
  16925. // defines at least one glyph
  16926. charCodeToGlyphId[0] = 0;
  16927. }
  16928. // Converting glyphs and ids into font's cmap table
  16929. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16930. this.toFontChar = newMapping.toFontChar;
  16931. tables.cmap = {
  16932. tag: 'cmap',
  16933. data: createCmapTable(newMapping.charCodeToGlyphId)
  16934. };
  16935. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16936. // extract some more font properties from the OpenType head and
  16937. // hhea tables; yMin and descent value are always negative
  16938. var override = {
  16939. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16940. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16941. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16942. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16943. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16944. };
  16945. tables['OS/2'] = {
  16946. tag: 'OS/2',
  16947. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16948. override)
  16949. };
  16950. }
  16951. // Rewrite the 'post' table if needed
  16952. if (!tables.post) {
  16953. tables.post = {
  16954. tag: 'post',
  16955. data: createPostTable(properties)
  16956. };
  16957. }
  16958. if (!isTrueType) {
  16959. try {
  16960. // Trying to repair CFF file
  16961. cffFile = new Stream(tables['CFF '].data);
  16962. var parser = new CFFParser(cffFile, properties);
  16963. cff = parser.parse();
  16964. var compiler = new CFFCompiler(cff);
  16965. tables['CFF '].data = compiler.compile();
  16966. } catch (e) {
  16967. warn('Failed to compile font ' + properties.loadedName);
  16968. }
  16969. }
  16970. // Re-creating 'name' table
  16971. if (!tables.name) {
  16972. tables.name = {
  16973. tag: 'name',
  16974. data: createNameTable(this.name)
  16975. };
  16976. } else {
  16977. // ... using existing 'name' table as prototype
  16978. var namePrototype = readNameTable(tables.name);
  16979. tables.name.data = createNameTable(name, namePrototype);
  16980. }
  16981. var builder = new OpenTypeFileBuilder(header.version);
  16982. for (var tableTag in tables) {
  16983. builder.addTable(tableTag, tables[tableTag].data);
  16984. }
  16985. return builder.toArray();
  16986. },
  16987. convert: function Font_convert(fontName, font, properties) {
  16988. // TODO: Check the charstring widths to determine this.
  16989. properties.fixedPitch = false;
  16990. var mapping = font.getGlyphMapping(properties);
  16991. var newMapping = adjustMapping(mapping, properties);
  16992. this.toFontChar = newMapping.toFontChar;
  16993. var numGlyphs = font.numGlyphs;
  16994. function getCharCodes(charCodeToGlyphId, glyphId) {
  16995. var charCodes = null;
  16996. for (var charCode in charCodeToGlyphId) {
  16997. if (glyphId === charCodeToGlyphId[charCode]) {
  16998. if (!charCodes) {
  16999. charCodes = [];
  17000. }
  17001. charCodes.push(charCode | 0);
  17002. }
  17003. }
  17004. return charCodes;
  17005. }
  17006. function createCharCode(charCodeToGlyphId, glyphId) {
  17007. for (var charCode in charCodeToGlyphId) {
  17008. if (glyphId === charCodeToGlyphId[charCode]) {
  17009. return charCode | 0;
  17010. }
  17011. }
  17012. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17013. glyphId;
  17014. return newMapping.nextAvailableFontCharCode++;
  17015. }
  17016. var seacs = font.seacs;
  17017. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17018. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17019. var charset = font.getCharset();
  17020. var seacMap = Object.create(null);
  17021. for (var glyphId in seacs) {
  17022. glyphId |= 0;
  17023. var seac = seacs[glyphId];
  17024. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17025. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17026. var baseGlyphId = charset.indexOf(baseGlyphName);
  17027. var accentGlyphId = charset.indexOf(accentGlyphName);
  17028. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17029. continue;
  17030. }
  17031. var accentOffset = {
  17032. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17033. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17034. };
  17035. var charCodes = getCharCodes(mapping, glyphId);
  17036. if (!charCodes) {
  17037. // There's no point in mapping it if the char code was never mapped
  17038. // to begin with.
  17039. continue;
  17040. }
  17041. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17042. var charCode = charCodes[i];
  17043. // Find a fontCharCode that maps to the base and accent glyphs.
  17044. // If one doesn't exists, create it.
  17045. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17046. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17047. baseGlyphId);
  17048. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17049. accentGlyphId);
  17050. seacMap[charCode] = {
  17051. baseFontCharCode: baseFontCharCode,
  17052. accentFontCharCode: accentFontCharCode,
  17053. accentOffset: accentOffset
  17054. };
  17055. }
  17056. }
  17057. properties.seacMap = seacMap;
  17058. }
  17059. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17060. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17061. // PostScript Font Program
  17062. builder.addTable('CFF ', font.data);
  17063. // OS/2 and Windows Specific metrics
  17064. builder.addTable('OS/2', createOS2Table(properties,
  17065. newMapping.charCodeToGlyphId));
  17066. // Character to glyphs mapping
  17067. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17068. // Font header
  17069. builder.addTable('head',
  17070. '\x00\x01\x00\x00' + // Version number
  17071. '\x00\x00\x10\x00' + // fontRevision
  17072. '\x00\x00\x00\x00' + // checksumAdjustement
  17073. '\x5F\x0F\x3C\xF5' + // magicNumber
  17074. '\x00\x00' + // Flags
  17075. safeString16(unitsPerEm) + // unitsPerEM
  17076. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17077. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17078. '\x00\x00' + // xMin
  17079. safeString16(properties.descent) + // yMin
  17080. '\x0F\xFF' + // xMax
  17081. safeString16(properties.ascent) + // yMax
  17082. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17083. '\x00\x11' + // lowestRecPPEM
  17084. '\x00\x00' + // fontDirectionHint
  17085. '\x00\x00' + // indexToLocFormat
  17086. '\x00\x00'); // glyphDataFormat
  17087. // Horizontal header
  17088. builder.addTable('hhea',
  17089. '\x00\x01\x00\x00' + // Version number
  17090. safeString16(properties.ascent) + // Typographic Ascent
  17091. safeString16(properties.descent) + // Typographic Descent
  17092. '\x00\x00' + // Line Gap
  17093. '\xFF\xFF' + // advanceWidthMax
  17094. '\x00\x00' + // minLeftSidebearing
  17095. '\x00\x00' + // minRightSidebearing
  17096. '\x00\x00' + // xMaxExtent
  17097. safeString16(properties.capHeight) + // caretSlopeRise
  17098. safeString16(Math.tan(properties.italicAngle) *
  17099. properties.xHeight) + // caretSlopeRun
  17100. '\x00\x00' + // caretOffset
  17101. '\x00\x00' + // -reserved-
  17102. '\x00\x00' + // -reserved-
  17103. '\x00\x00' + // -reserved-
  17104. '\x00\x00' + // -reserved-
  17105. '\x00\x00' + // metricDataFormat
  17106. string16(numGlyphs)); // Number of HMetrics
  17107. // Horizontal metrics
  17108. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17109. var charstrings = font.charstrings;
  17110. var cffWidths = font.cff ? font.cff.widths : null;
  17111. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17112. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17113. var width = 0;
  17114. if (charstrings) {
  17115. var charstring = charstrings[i - 1];
  17116. width = 'width' in charstring ? charstring.width : 0;
  17117. } else if (cffWidths) {
  17118. width = Math.ceil(cffWidths[i] || 0);
  17119. }
  17120. hmtx += string16(width) + string16(0);
  17121. }
  17122. return hmtx;
  17123. })());
  17124. // Maximum profile
  17125. builder.addTable('maxp',
  17126. '\x00\x00\x50\x00' + // Version number
  17127. string16(numGlyphs)); // Num of glyphs
  17128. // Naming tables
  17129. builder.addTable('name', createNameTable(fontName));
  17130. // PostScript informations
  17131. builder.addTable('post', createPostTable(properties));
  17132. return builder.toArray();
  17133. },
  17134. /**
  17135. * Builds a char code to unicode map based on section 9.10 of the spec.
  17136. * @param {Object} properties Font properties object.
  17137. * @return {Object} A ToUnicodeMap object.
  17138. */
  17139. buildToUnicode: function Font_buildToUnicode(properties) {
  17140. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17141. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17142. return properties.toUnicode;
  17143. }
  17144. // According to the spec if the font is a simple font we should only map
  17145. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17146. // the differences array only contains adobe standard or symbol set names,
  17147. // in pratice it seems better to always try to create a toUnicode
  17148. // map based of the default encoding.
  17149. var toUnicode, charcode;
  17150. if (!properties.composite /* is simple font */) {
  17151. toUnicode = [];
  17152. var encoding = properties.defaultEncoding.slice();
  17153. var baseEncodingName = properties.baseEncodingName;
  17154. // Merge in the differences array.
  17155. var differences = properties.differences;
  17156. for (charcode in differences) {
  17157. encoding[charcode] = differences[charcode];
  17158. }
  17159. for (charcode in encoding) {
  17160. // a) Map the character code to a character name.
  17161. var glyphName = encoding[charcode];
  17162. // b) Look up the character name in the Adobe Glyph List (see the
  17163. // Bibliography) to obtain the corresponding Unicode value.
  17164. if (glyphName === '') {
  17165. continue;
  17166. } else if (GlyphsUnicode[glyphName] === undefined) {
  17167. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17168. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17169. var code = 0;
  17170. switch (glyphName[0]) {
  17171. case 'G': // Gxx glyph
  17172. if (glyphName.length === 3) {
  17173. code = parseInt(glyphName.substr(1), 16);
  17174. }
  17175. break;
  17176. case 'g': // g00xx glyph
  17177. if (glyphName.length === 5) {
  17178. code = parseInt(glyphName.substr(1), 16);
  17179. }
  17180. break;
  17181. case 'C': // Cddd glyph
  17182. case 'c': // cddd glyph
  17183. if (glyphName.length >= 3) {
  17184. code = +glyphName.substr(1);
  17185. }
  17186. break;
  17187. }
  17188. if (code) {
  17189. // If |baseEncodingName| is one the predefined encodings,
  17190. // and |code| equals |charcode|, using the glyph defined in the
  17191. // baseEncoding seems to yield a better |toUnicode| mapping
  17192. // (fixes issue 5070).
  17193. if (baseEncodingName && code === +charcode) {
  17194. var baseEncoding = Encodings[baseEncodingName];
  17195. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17196. toUnicode[charcode] =
  17197. String.fromCharCode(GlyphsUnicode[glyphName]);
  17198. continue;
  17199. }
  17200. }
  17201. toUnicode[charcode] = String.fromCharCode(code);
  17202. }
  17203. continue;
  17204. }
  17205. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17206. }
  17207. return new ToUnicodeMap(toUnicode);
  17208. }
  17209. // If the font is a composite font that uses one of the predefined CMaps
  17210. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17211. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17212. // Adobe-Korea1 character collection:
  17213. if (properties.composite && (
  17214. (properties.cMap.builtInCMap &&
  17215. !(properties.cMap instanceof IdentityCMap)) ||
  17216. (properties.cidSystemInfo.registry === 'Adobe' &&
  17217. (properties.cidSystemInfo.ordering === 'GB1' ||
  17218. properties.cidSystemInfo.ordering === 'CNS1' ||
  17219. properties.cidSystemInfo.ordering === 'Japan1' ||
  17220. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17221. // Then:
  17222. // a) Map the character code to a character identifier (CID) according
  17223. // to the font’s CMap.
  17224. // b) Obtain the registry and ordering of the character collection used
  17225. // by the font’s CMap (for example, Adobe and Japan1) from its
  17226. // CIDSystemInfo dictionary.
  17227. var registry = properties.cidSystemInfo.registry;
  17228. var ordering = properties.cidSystemInfo.ordering;
  17229. // c) Construct a second CMap name by concatenating the registry and
  17230. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17231. // (for example, Adobe–Japan1–UCS2).
  17232. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17233. // d) Obtain the CMap with the name constructed in step (c) (available
  17234. // from the ASN Web site; see the Bibliography).
  17235. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17236. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17237. var cMap = properties.cMap;
  17238. toUnicode = [];
  17239. cMap.forEach(function(charcode, cid) {
  17240. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17241. // e) Map the CID obtained in step (a) according to the CMap obtained
  17242. // in step (d), producing a Unicode value.
  17243. var ucs2 = ucs2CMap.lookup(cid);
  17244. if (ucs2) {
  17245. toUnicode[charcode] =
  17246. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17247. ucs2.charCodeAt(1));
  17248. }
  17249. });
  17250. return new ToUnicodeMap(toUnicode);
  17251. }
  17252. // The viewer's choice, just use an identity map.
  17253. return new IdentityToUnicodeMap(properties.firstChar,
  17254. properties.lastChar);
  17255. },
  17256. get spaceWidth() {
  17257. if ('_shadowWidth' in this) {
  17258. return this._shadowWidth;
  17259. }
  17260. // trying to estimate space character width
  17261. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17262. var width;
  17263. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17264. var glyphName = possibleSpaceReplacements[i];
  17265. // if possible, getting width by glyph name
  17266. if (glyphName in this.widths) {
  17267. width = this.widths[glyphName];
  17268. break;
  17269. }
  17270. var glyphUnicode = GlyphsUnicode[glyphName];
  17271. // finding the charcode via unicodeToCID map
  17272. var charcode = 0;
  17273. if (this.composite) {
  17274. if (this.cMap.contains(glyphUnicode)) {
  17275. charcode = this.cMap.lookup(glyphUnicode);
  17276. }
  17277. }
  17278. // ... via toUnicode map
  17279. if (!charcode && 'toUnicode' in this) {
  17280. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17281. }
  17282. // setting it to unicode if negative or undefined
  17283. if (charcode <= 0) {
  17284. charcode = glyphUnicode;
  17285. }
  17286. // trying to get width via charcode
  17287. width = this.widths[charcode];
  17288. if (width) {
  17289. break; // the non-zero width found
  17290. }
  17291. }
  17292. width = width || this.defaultWidth;
  17293. // Do not shadow the property here. See discussion:
  17294. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17295. this._shadowWidth = width;
  17296. return width;
  17297. },
  17298. charToGlyph: function Font_charToGlyph(charcode) {
  17299. var fontCharCode, width, operatorListId;
  17300. var widthCode = charcode;
  17301. if (this.cMap && this.cMap.contains(charcode)) {
  17302. widthCode = this.cMap.lookup(charcode);
  17303. }
  17304. width = this.widths[widthCode];
  17305. width = isNum(width) ? width : this.defaultWidth;
  17306. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17307. var unicode = this.toUnicode.get(charcode) || charcode;
  17308. if (typeof unicode === 'number') {
  17309. unicode = String.fromCharCode(unicode);
  17310. }
  17311. // First try the toFontChar map, if it's not there then try falling
  17312. // back to the char code.
  17313. fontCharCode = this.toFontChar[charcode] || charcode;
  17314. if (this.missingFile) {
  17315. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17316. }
  17317. if (this.isType3Font) {
  17318. // Font char code in this case is actually a glyph name.
  17319. operatorListId = fontCharCode;
  17320. }
  17321. var accent = null;
  17322. if (this.seacMap && this.seacMap[charcode]) {
  17323. var seac = this.seacMap[charcode];
  17324. fontCharCode = seac.baseFontCharCode;
  17325. accent = {
  17326. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17327. offset: seac.accentOffset
  17328. };
  17329. }
  17330. var fontChar = String.fromCharCode(fontCharCode);
  17331. var glyph = this.glyphCache[charcode];
  17332. if (!glyph ||
  17333. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17334. operatorListId)) {
  17335. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17336. operatorListId);
  17337. this.glyphCache[charcode] = glyph;
  17338. }
  17339. return glyph;
  17340. },
  17341. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17342. var charsCache = this.charsCache;
  17343. var glyphs, glyph, charcode;
  17344. // if we translated this string before, just grab it from the cache
  17345. if (charsCache) {
  17346. glyphs = charsCache[chars];
  17347. if (glyphs) {
  17348. return glyphs;
  17349. }
  17350. }
  17351. // lazily create the translation cache
  17352. if (!charsCache) {
  17353. charsCache = this.charsCache = Object.create(null);
  17354. }
  17355. glyphs = [];
  17356. var charsCacheKey = chars;
  17357. var i = 0, ii;
  17358. if (this.cMap) {
  17359. // composite fonts have multi-byte strings convert the string from
  17360. // single-byte to multi-byte
  17361. var c = {};
  17362. while (i < chars.length) {
  17363. this.cMap.readCharCode(chars, i, c);
  17364. charcode = c.charcode;
  17365. var length = c.length;
  17366. i += length;
  17367. glyph = this.charToGlyph(charcode);
  17368. glyphs.push(glyph);
  17369. // placing null after each word break charcode (ASCII SPACE)
  17370. // Ignore occurences of 0x20 in multiple-byte codes.
  17371. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17372. glyphs.push(null);
  17373. }
  17374. }
  17375. } else {
  17376. for (i = 0, ii = chars.length; i < ii; ++i) {
  17377. charcode = chars.charCodeAt(i);
  17378. glyph = this.charToGlyph(charcode);
  17379. glyphs.push(glyph);
  17380. if (charcode === 0x20) {
  17381. glyphs.push(null);
  17382. }
  17383. }
  17384. }
  17385. // Enter the translated string into the cache
  17386. return (charsCache[charsCacheKey] = glyphs);
  17387. }
  17388. };
  17389. return Font;
  17390. })();
  17391. var ErrorFont = (function ErrorFontClosure() {
  17392. function ErrorFont(error) {
  17393. this.error = error;
  17394. this.loadedName = 'g_font_error';
  17395. this.loading = false;
  17396. }
  17397. ErrorFont.prototype = {
  17398. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17399. return [];
  17400. },
  17401. exportData: function ErrorFont_exportData() {
  17402. return {error: this.error};
  17403. }
  17404. };
  17405. return ErrorFont;
  17406. })();
  17407. /**
  17408. * Shared logic for building a char code to glyph id mapping for Type1 and
  17409. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17410. * @param {Object} properties Font properties object.
  17411. * @param {Object} builtInEncoding The encoding contained within the actual font
  17412. * data.
  17413. * @param {Array} Array of glyph names where the index is the glyph ID.
  17414. * @returns {Object} A char code to glyph ID map.
  17415. */
  17416. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17417. var charCodeToGlyphId = Object.create(null);
  17418. var glyphId, charCode, baseEncoding;
  17419. if (properties.baseEncodingName) {
  17420. // If a valid base encoding name was used, the mapping is initialized with
  17421. // that.
  17422. baseEncoding = Encodings[properties.baseEncodingName];
  17423. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17424. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17425. if (glyphId >= 0) {
  17426. charCodeToGlyphId[charCode] = glyphId;
  17427. } else {
  17428. charCodeToGlyphId[charCode] = 0; // notdef
  17429. }
  17430. }
  17431. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17432. // For a symbolic font the encoding should be the fonts built-in
  17433. // encoding.
  17434. for (charCode in builtInEncoding) {
  17435. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17436. }
  17437. } else {
  17438. // For non-symbolic fonts that don't have a base encoding the standard
  17439. // encoding should be used.
  17440. baseEncoding = Encodings.StandardEncoding;
  17441. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17442. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17443. if (glyphId >= 0) {
  17444. charCodeToGlyphId[charCode] = glyphId;
  17445. } else {
  17446. charCodeToGlyphId[charCode] = 0; // notdef
  17447. }
  17448. }
  17449. }
  17450. // Lastly, merge in the differences.
  17451. var differences = properties.differences;
  17452. if (differences) {
  17453. for (charCode in differences) {
  17454. var glyphName = differences[charCode];
  17455. glyphId = glyphNames.indexOf(glyphName);
  17456. if (glyphId >= 0) {
  17457. charCodeToGlyphId[charCode] = glyphId;
  17458. } else {
  17459. charCodeToGlyphId[charCode] = 0; // notdef
  17460. }
  17461. }
  17462. }
  17463. return charCodeToGlyphId;
  17464. }
  17465. /*
  17466. * CharStrings are encoded following the the CharString Encoding sequence
  17467. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17468. * The value in a byte indicates a command, a number, or subsequent bytes
  17469. * that are to be interpreted in a special way.
  17470. *
  17471. * CharString Number Encoding:
  17472. * A CharString byte containing the values from 32 through 255 inclusive
  17473. * indicate an integer. These values are decoded in four ranges.
  17474. *
  17475. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17476. * indicate the integer v - 139. Thus, the integer values from -107 through
  17477. * 107 inclusive may be encoded in single byte.
  17478. *
  17479. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17480. * indicates an integer involving the next byte, w, according to the formula:
  17481. * [(v - 247) x 256] + w + 108
  17482. *
  17483. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17484. * indicates an integer involving the next byte, w, according to the formula:
  17485. * -[(v - 251) * 256] - w - 108
  17486. *
  17487. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17488. * are a two complement signed integer. The first of these bytes contains the
  17489. * highest order bits, the second byte contains the next higher order bits
  17490. * and the fourth byte contain the lowest order bits.
  17491. *
  17492. *
  17493. * CharString Command Encoding:
  17494. * CharStrings commands are encoded in 1 or 2 bytes.
  17495. *
  17496. * Single byte commands are encoded in 1 byte that contains a value between
  17497. * 0 and 31 inclusive.
  17498. * If a command byte contains the value 12, then the value in the next byte
  17499. * indicates a command. This "escape" mechanism allows many extra commands
  17500. * to be encoded and this encoding technique helps to minimize the length of
  17501. * the charStrings.
  17502. */
  17503. var Type1CharString = (function Type1CharStringClosure() {
  17504. var COMMAND_MAP = {
  17505. 'hstem': [1],
  17506. 'vstem': [3],
  17507. 'vmoveto': [4],
  17508. 'rlineto': [5],
  17509. 'hlineto': [6],
  17510. 'vlineto': [7],
  17511. 'rrcurveto': [8],
  17512. 'callsubr': [10],
  17513. 'flex': [12, 35],
  17514. 'drop' : [12, 18],
  17515. 'endchar': [14],
  17516. 'rmoveto': [21],
  17517. 'hmoveto': [22],
  17518. 'vhcurveto': [30],
  17519. 'hvcurveto': [31]
  17520. };
  17521. function Type1CharString() {
  17522. this.width = 0;
  17523. this.lsb = 0;
  17524. this.flexing = false;
  17525. this.output = [];
  17526. this.stack = [];
  17527. }
  17528. Type1CharString.prototype = {
  17529. convert: function Type1CharString_convert(encoded, subrs) {
  17530. var count = encoded.length;
  17531. var error = false;
  17532. var wx, sbx, subrNumber;
  17533. for (var i = 0; i < count; i++) {
  17534. var value = encoded[i];
  17535. if (value < 32) {
  17536. if (value === 12) {
  17537. value = (value << 8) + encoded[++i];
  17538. }
  17539. switch (value) {
  17540. case 1: // hstem
  17541. if (!HINTING_ENABLED) {
  17542. this.stack = [];
  17543. break;
  17544. }
  17545. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17546. break;
  17547. case 3: // vstem
  17548. if (!HINTING_ENABLED) {
  17549. this.stack = [];
  17550. break;
  17551. }
  17552. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17553. break;
  17554. case 4: // vmoveto
  17555. if (this.flexing) {
  17556. if (this.stack.length < 1) {
  17557. error = true;
  17558. break;
  17559. }
  17560. // Add the dx for flex and but also swap the values so they are
  17561. // the right order.
  17562. var dy = this.stack.pop();
  17563. this.stack.push(0, dy);
  17564. break;
  17565. }
  17566. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17567. break;
  17568. case 5: // rlineto
  17569. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17570. break;
  17571. case 6: // hlineto
  17572. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17573. break;
  17574. case 7: // vlineto
  17575. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17576. break;
  17577. case 8: // rrcurveto
  17578. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17579. break;
  17580. case 9: // closepath
  17581. // closepath is a Type1 command that does not take argument and is
  17582. // useless in Type2 and it can simply be ignored.
  17583. this.stack = [];
  17584. break;
  17585. case 10: // callsubr
  17586. if (this.stack.length < 1) {
  17587. error = true;
  17588. break;
  17589. }
  17590. subrNumber = this.stack.pop();
  17591. error = this.convert(subrs[subrNumber], subrs);
  17592. break;
  17593. case 11: // return
  17594. return error;
  17595. case 13: // hsbw
  17596. if (this.stack.length < 2) {
  17597. error = true;
  17598. break;
  17599. }
  17600. // To convert to type2 we have to move the width value to the
  17601. // first part of the charstring and then use hmoveto with lsb.
  17602. wx = this.stack.pop();
  17603. sbx = this.stack.pop();
  17604. this.lsb = sbx;
  17605. this.width = wx;
  17606. this.stack.push(wx, sbx);
  17607. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17608. break;
  17609. case 14: // endchar
  17610. this.output.push(COMMAND_MAP.endchar[0]);
  17611. break;
  17612. case 21: // rmoveto
  17613. if (this.flexing) {
  17614. break;
  17615. }
  17616. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17617. break;
  17618. case 22: // hmoveto
  17619. if (this.flexing) {
  17620. // Add the dy for flex.
  17621. this.stack.push(0);
  17622. break;
  17623. }
  17624. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17625. break;
  17626. case 30: // vhcurveto
  17627. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17628. break;
  17629. case 31: // hvcurveto
  17630. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17631. break;
  17632. case (12 << 8) + 0: // dotsection
  17633. // dotsection is a Type1 command to specify some hinting feature
  17634. // for dots that do not take a parameter and it can safely be
  17635. // ignored for Type2.
  17636. this.stack = [];
  17637. break;
  17638. case (12 << 8) + 1: // vstem3
  17639. if (!HINTING_ENABLED) {
  17640. this.stack = [];
  17641. break;
  17642. }
  17643. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17644. // multiple parameters, so instead of returning [vh]stem3 take a
  17645. // shortcut and return [vhstem] instead.
  17646. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17647. break;
  17648. case (12 << 8) + 2: // hstem3
  17649. if (!HINTING_ENABLED) {
  17650. this.stack = [];
  17651. break;
  17652. }
  17653. // See vstem3.
  17654. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17655. break;
  17656. case (12 << 8) + 6: // seac
  17657. // seac is like type 2's special endchar but it doesn't use the
  17658. // first argument asb, so remove it.
  17659. if (SEAC_ANALYSIS_ENABLED) {
  17660. this.seac = this.stack.splice(-4, 4);
  17661. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17662. } else {
  17663. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17664. }
  17665. break;
  17666. case (12 << 8) + 7: // sbw
  17667. if (this.stack.length < 4) {
  17668. error = true;
  17669. break;
  17670. }
  17671. // To convert to type2 we have to move the width value to the
  17672. // first part of the charstring and then use rmoveto with
  17673. // (dx, dy). The height argument will not be used for vmtx and
  17674. // vhea tables reconstruction -- ignoring it.
  17675. var wy = this.stack.pop();
  17676. wx = this.stack.pop();
  17677. var sby = this.stack.pop();
  17678. sbx = this.stack.pop();
  17679. this.lsb = sbx;
  17680. this.width = wx;
  17681. this.stack.push(wx, sbx, sby);
  17682. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17683. break;
  17684. case (12 << 8) + 12: // div
  17685. if (this.stack.length < 2) {
  17686. error = true;
  17687. break;
  17688. }
  17689. var num2 = this.stack.pop();
  17690. var num1 = this.stack.pop();
  17691. this.stack.push(num1 / num2);
  17692. break;
  17693. case (12 << 8) + 16: // callothersubr
  17694. if (this.stack.length < 2) {
  17695. error = true;
  17696. break;
  17697. }
  17698. subrNumber = this.stack.pop();
  17699. var numArgs = this.stack.pop();
  17700. if (subrNumber === 0 && numArgs === 3) {
  17701. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17702. this.stack.push(
  17703. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17704. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17705. flexArgs[4], // bcp2x
  17706. flexArgs[5], // bcp2y
  17707. flexArgs[6], // p2x
  17708. flexArgs[7], // p2y
  17709. flexArgs[8], // bcp3x
  17710. flexArgs[9], // bcp3y
  17711. flexArgs[10], // bcp4x
  17712. flexArgs[11], // bcp4y
  17713. flexArgs[12], // p3x
  17714. flexArgs[13], // p3y
  17715. flexArgs[14] // flexDepth
  17716. // 15 = finalx unused by flex
  17717. // 16 = finaly unused by flex
  17718. );
  17719. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17720. this.flexing = false;
  17721. this.stack.push(flexArgs[15], flexArgs[16]);
  17722. } else if (subrNumber === 1 && numArgs === 0) {
  17723. this.flexing = true;
  17724. }
  17725. break;
  17726. case (12 << 8) + 17: // pop
  17727. // Ignore this since it is only used with othersubr.
  17728. break;
  17729. case (12 << 8) + 33: // setcurrentpoint
  17730. // Ignore for now.
  17731. this.stack = [];
  17732. break;
  17733. default:
  17734. warn('Unknown type 1 charstring command of "' + value + '"');
  17735. break;
  17736. }
  17737. if (error) {
  17738. break;
  17739. }
  17740. continue;
  17741. } else if (value <= 246) {
  17742. value = value - 139;
  17743. } else if (value <= 250) {
  17744. value = ((value - 247) * 256) + encoded[++i] + 108;
  17745. } else if (value <= 254) {
  17746. value = -((value - 251) * 256) - encoded[++i] - 108;
  17747. } else {
  17748. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17749. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17750. }
  17751. this.stack.push(value);
  17752. }
  17753. return error;
  17754. },
  17755. executeCommand: function(howManyArgs, command, keepStack) {
  17756. var stackLength = this.stack.length;
  17757. if (howManyArgs > stackLength) {
  17758. return true;
  17759. }
  17760. var start = stackLength - howManyArgs;
  17761. for (var i = start; i < stackLength; i++) {
  17762. var value = this.stack[i];
  17763. if (value === (value | 0)) { // int
  17764. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17765. } else { // fixed point
  17766. value = (65536 * value) | 0;
  17767. this.output.push(255,
  17768. (value >> 24) & 0xFF,
  17769. (value >> 16) & 0xFF,
  17770. (value >> 8) & 0xFF,
  17771. value & 0xFF);
  17772. }
  17773. }
  17774. this.output.push.apply(this.output, command);
  17775. if (keepStack) {
  17776. this.stack.splice(start, howManyArgs);
  17777. } else {
  17778. this.stack.length = 0;
  17779. }
  17780. return false;
  17781. }
  17782. };
  17783. return Type1CharString;
  17784. })();
  17785. /*
  17786. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17787. * program. Some of its logic depends on the Type2 charstrings
  17788. * structure.
  17789. * Note: this doesn't really parse the font since that would require evaluation
  17790. * of PostScript, but it is possible in most cases to extract what we need
  17791. * without a full parse.
  17792. */
  17793. var Type1Parser = (function Type1ParserClosure() {
  17794. /*
  17795. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17796. * of Plaintext Bytes. The function took a key as a parameter which can be
  17797. * for decrypting the eexec block of for decoding charStrings.
  17798. */
  17799. var EEXEC_ENCRYPT_KEY = 55665;
  17800. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17801. function isHexDigit(code) {
  17802. return code >= 48 && code <= 57 || // '0'-'9'
  17803. code >= 65 && code <= 70 || // 'A'-'F'
  17804. code >= 97 && code <= 102; // 'a'-'f'
  17805. }
  17806. function decrypt(data, key, discardNumber) {
  17807. var r = key | 0, c1 = 52845, c2 = 22719;
  17808. var count = data.length;
  17809. var decrypted = new Uint8Array(count);
  17810. for (var i = 0; i < count; i++) {
  17811. var value = data[i];
  17812. decrypted[i] = value ^ (r >> 8);
  17813. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17814. }
  17815. return Array.prototype.slice.call(decrypted, discardNumber);
  17816. }
  17817. function decryptAscii(data, key, discardNumber) {
  17818. var r = key | 0, c1 = 52845, c2 = 22719;
  17819. var count = data.length, maybeLength = count >>> 1;
  17820. var decrypted = new Uint8Array(maybeLength);
  17821. var i, j;
  17822. for (i = 0, j = 0; i < count; i++) {
  17823. var digit1 = data[i];
  17824. if (!isHexDigit(digit1)) {
  17825. continue;
  17826. }
  17827. i++;
  17828. var digit2;
  17829. while (i < count && !isHexDigit(digit2 = data[i])) {
  17830. i++;
  17831. }
  17832. if (i < count) {
  17833. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17834. decrypted[j++] = value ^ (r >> 8);
  17835. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17836. }
  17837. }
  17838. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17839. }
  17840. function isSpecial(c) {
  17841. return c === 0x2F || // '/'
  17842. c === 0x5B || c === 0x5D || // '[', ']'
  17843. c === 0x7B || c === 0x7D || // '{', '}'
  17844. c === 0x28 || c === 0x29; // '(', ')'
  17845. }
  17846. function Type1Parser(stream, encrypted) {
  17847. if (encrypted) {
  17848. var data = stream.getBytes();
  17849. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17850. isHexDigit(data[2]) && isHexDigit(data[3]));
  17851. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17852. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17853. }
  17854. this.stream = stream;
  17855. this.nextChar();
  17856. }
  17857. Type1Parser.prototype = {
  17858. readNumberArray: function Type1Parser_readNumberArray() {
  17859. this.getToken(); // read '[' or '{' (arrays can start with either)
  17860. var array = [];
  17861. while (true) {
  17862. var token = this.getToken();
  17863. if (token === null || token === ']' || token === '}') {
  17864. break;
  17865. }
  17866. array.push(parseFloat(token || 0));
  17867. }
  17868. return array;
  17869. },
  17870. readNumber: function Type1Parser_readNumber() {
  17871. var token = this.getToken();
  17872. return parseFloat(token || 0);
  17873. },
  17874. readInt: function Type1Parser_readInt() {
  17875. // Use '| 0' to prevent setting a double into length such as the double
  17876. // does not flow into the loop variable.
  17877. var token = this.getToken();
  17878. return parseInt(token || 0, 10) | 0;
  17879. },
  17880. readBoolean: function Type1Parser_readBoolean() {
  17881. var token = this.getToken();
  17882. // Use 1 and 0 since that's what type2 charstrings use.
  17883. return token === 'true' ? 1 : 0;
  17884. },
  17885. nextChar : function Type1_nextChar() {
  17886. return (this.currentChar = this.stream.getByte());
  17887. },
  17888. getToken: function Type1Parser_getToken() {
  17889. // Eat whitespace and comments.
  17890. var comment = false;
  17891. var ch = this.currentChar;
  17892. while (true) {
  17893. if (ch === -1) {
  17894. return null;
  17895. }
  17896. if (comment) {
  17897. if (ch === 0x0A || ch === 0x0D) {
  17898. comment = false;
  17899. }
  17900. } else if (ch === 0x25) { // '%'
  17901. comment = true;
  17902. } else if (!Lexer.isSpace(ch)) {
  17903. break;
  17904. }
  17905. ch = this.nextChar();
  17906. }
  17907. if (isSpecial(ch)) {
  17908. this.nextChar();
  17909. return String.fromCharCode(ch);
  17910. }
  17911. var token = '';
  17912. do {
  17913. token += String.fromCharCode(ch);
  17914. ch = this.nextChar();
  17915. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17916. return token;
  17917. },
  17918. /*
  17919. * Returns an object containing a Subrs array and a CharStrings
  17920. * array extracted from and eexec encrypted block of data
  17921. */
  17922. extractFontProgram: function Type1Parser_extractFontProgram() {
  17923. var stream = this.stream;
  17924. var subrs = [], charstrings = [];
  17925. var program = {
  17926. subrs: [],
  17927. charstrings: [],
  17928. properties: {
  17929. 'privateData': {
  17930. 'lenIV': 4
  17931. }
  17932. }
  17933. };
  17934. var token, length, data, lenIV, encoded;
  17935. while ((token = this.getToken()) !== null) {
  17936. if (token !== '/') {
  17937. continue;
  17938. }
  17939. token = this.getToken();
  17940. switch (token) {
  17941. case 'CharStrings':
  17942. // The number immediately following CharStrings must be greater or
  17943. // equal to the number of CharStrings.
  17944. this.getToken();
  17945. this.getToken(); // read in 'dict'
  17946. this.getToken(); // read in 'dup'
  17947. this.getToken(); // read in 'begin'
  17948. while(true) {
  17949. token = this.getToken();
  17950. if (token === null || token === 'end') {
  17951. break;
  17952. }
  17953. if (token !== '/') {
  17954. continue;
  17955. }
  17956. var glyph = this.getToken();
  17957. length = this.readInt();
  17958. this.getToken(); // read in 'RD' or '-|'
  17959. data = stream.makeSubStream(stream.pos, length);
  17960. lenIV = program.properties.privateData['lenIV'];
  17961. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17962. // Skip past the required space and binary data.
  17963. stream.skip(length);
  17964. this.nextChar();
  17965. token = this.getToken(); // read in 'ND' or '|-'
  17966. if (token === 'noaccess') {
  17967. this.getToken(); // read in 'def'
  17968. }
  17969. charstrings.push({
  17970. glyph: glyph,
  17971. encoded: encoded
  17972. });
  17973. }
  17974. break;
  17975. case 'Subrs':
  17976. var num = this.readInt();
  17977. this.getToken(); // read in 'array'
  17978. while ((token = this.getToken()) === 'dup') {
  17979. var index = this.readInt();
  17980. length = this.readInt();
  17981. this.getToken(); // read in 'RD' or '-|'
  17982. data = stream.makeSubStream(stream.pos, length);
  17983. lenIV = program.properties.privateData['lenIV'];
  17984. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17985. // Skip past the required space and binary data.
  17986. stream.skip(length);
  17987. this.nextChar();
  17988. token = this.getToken(); // read in 'NP' or '|'
  17989. if (token === 'noaccess') {
  17990. this.getToken(); // read in 'put'
  17991. }
  17992. subrs[index] = encoded;
  17993. }
  17994. break;
  17995. case 'BlueValues':
  17996. case 'OtherBlues':
  17997. case 'FamilyBlues':
  17998. case 'FamilyOtherBlues':
  17999. var blueArray = this.readNumberArray();
  18000. // *Blue* values may contain invalid data: disables reading of
  18001. // those values when hinting is disabled.
  18002. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18003. HINTING_ENABLED) {
  18004. program.properties.privateData[token] = blueArray;
  18005. }
  18006. break;
  18007. case 'StemSnapH':
  18008. case 'StemSnapV':
  18009. program.properties.privateData[token] = this.readNumberArray();
  18010. break;
  18011. case 'StdHW':
  18012. case 'StdVW':
  18013. program.properties.privateData[token] =
  18014. this.readNumberArray()[0];
  18015. break;
  18016. case 'BlueShift':
  18017. case 'lenIV':
  18018. case 'BlueFuzz':
  18019. case 'BlueScale':
  18020. case 'LanguageGroup':
  18021. case 'ExpansionFactor':
  18022. program.properties.privateData[token] = this.readNumber();
  18023. break;
  18024. case 'ForceBold':
  18025. program.properties.privateData[token] = this.readBoolean();
  18026. break;
  18027. }
  18028. }
  18029. for (var i = 0; i < charstrings.length; i++) {
  18030. glyph = charstrings[i].glyph;
  18031. encoded = charstrings[i].encoded;
  18032. var charString = new Type1CharString();
  18033. var error = charString.convert(encoded, subrs);
  18034. var output = charString.output;
  18035. if (error) {
  18036. // It seems when FreeType encounters an error while evaluating a glyph
  18037. // that it completely ignores the glyph so we'll mimic that behaviour
  18038. // here and put an endchar to make the validator happy.
  18039. output = [14];
  18040. }
  18041. program.charstrings.push({
  18042. glyphName: glyph,
  18043. charstring: output,
  18044. width: charString.width,
  18045. lsb: charString.lsb,
  18046. seac: charString.seac
  18047. });
  18048. }
  18049. return program;
  18050. },
  18051. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18052. var token;
  18053. while ((token = this.getToken()) !== null) {
  18054. if (token !== '/') {
  18055. continue;
  18056. }
  18057. token = this.getToken();
  18058. switch (token) {
  18059. case 'FontMatrix':
  18060. var matrix = this.readNumberArray();
  18061. properties.fontMatrix = matrix;
  18062. break;
  18063. case 'Encoding':
  18064. var encodingArg = this.getToken();
  18065. var encoding;
  18066. if (!/^\d+$/.test(encodingArg)) {
  18067. // encoding name is specified
  18068. encoding = Encodings[encodingArg];
  18069. } else {
  18070. encoding = [];
  18071. var size = parseInt(encodingArg, 10) | 0;
  18072. this.getToken(); // read in 'array'
  18073. for (var j = 0; j < size; j++) {
  18074. token = this.getToken();
  18075. // skipping till first dup or def (e.g. ignoring for statement)
  18076. while (token !== 'dup' && token !== 'def') {
  18077. token = this.getToken();
  18078. if (token === null) {
  18079. return; // invalid header
  18080. }
  18081. }
  18082. if (token === 'def') {
  18083. break; // read all array data
  18084. }
  18085. var index = this.readInt();
  18086. this.getToken(); // read in '/'
  18087. var glyph = this.getToken();
  18088. encoding[index] = glyph;
  18089. this.getToken(); // read the in 'put'
  18090. }
  18091. }
  18092. properties.builtInEncoding = encoding;
  18093. break;
  18094. case 'FontBBox':
  18095. var fontBBox = this.readNumberArray();
  18096. // adjusting ascent/descent
  18097. properties.ascent = fontBBox[3];
  18098. properties.descent = fontBBox[1];
  18099. properties.ascentScaled = true;
  18100. break;
  18101. }
  18102. }
  18103. }
  18104. };
  18105. return Type1Parser;
  18106. })();
  18107. /**
  18108. * The CFF class takes a Type1 file and wrap it into a
  18109. * 'Compact Font Format' which itself embed Type2 charstrings.
  18110. */
  18111. var CFFStandardStrings = [
  18112. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18113. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18114. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18115. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18116. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18117. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18118. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18119. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18120. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18121. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18122. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18123. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18124. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18125. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18126. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18127. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18128. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18129. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18130. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18131. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18132. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18133. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18134. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18135. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18136. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18137. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18138. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18139. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18140. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18141. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18142. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18143. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18144. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18145. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18146. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18147. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18148. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18149. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18150. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18151. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18152. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18153. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18154. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18155. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18156. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18157. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18158. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18159. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18160. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18161. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18162. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18163. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18164. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18165. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18166. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18167. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18168. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18169. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18170. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18171. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18172. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18173. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18174. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18175. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18176. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18177. ];
  18178. // Type1Font is also a CIDFontType0.
  18179. var Type1Font = function Type1Font(name, file, properties) {
  18180. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18181. // Also, length1 and length2 might be off by 6 bytes as well.
  18182. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18183. var PFB_HEADER_SIZE = 6;
  18184. var headerBlockLength = properties.length1;
  18185. var eexecBlockLength = properties.length2;
  18186. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18187. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18188. if (pfbHeaderPresent) {
  18189. file.skip(PFB_HEADER_SIZE);
  18190. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18191. (pfbHeader[3] << 8) | pfbHeader[2];
  18192. }
  18193. // Get the data block containing glyphs and subrs informations
  18194. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18195. var headerBlockParser = new Type1Parser(headerBlock);
  18196. headerBlockParser.extractFontHeader(properties);
  18197. if (pfbHeaderPresent) {
  18198. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18199. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18200. (pfbHeader[3] << 8) | pfbHeader[2];
  18201. }
  18202. // Decrypt the data blocks and retrieve it's content
  18203. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18204. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18205. var data = eexecBlockParser.extractFontProgram();
  18206. for (var info in data.properties) {
  18207. properties[info] = data.properties[info];
  18208. }
  18209. var charstrings = data.charstrings;
  18210. var type2Charstrings = this.getType2Charstrings(charstrings);
  18211. var subrs = this.getType2Subrs(data.subrs);
  18212. this.charstrings = charstrings;
  18213. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18214. subrs, properties);
  18215. this.seacs = this.getSeacs(data.charstrings);
  18216. };
  18217. Type1Font.prototype = {
  18218. get numGlyphs() {
  18219. return this.charstrings.length + 1;
  18220. },
  18221. getCharset: function Type1Font_getCharset() {
  18222. var charset = ['.notdef'];
  18223. var charstrings = this.charstrings;
  18224. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18225. charset.push(charstrings[glyphId].glyphName);
  18226. }
  18227. return charset;
  18228. },
  18229. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18230. var charstrings = this.charstrings;
  18231. var glyphNames = ['.notdef'], glyphId;
  18232. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18233. glyphNames.push(charstrings[glyphId].glyphName);
  18234. }
  18235. var encoding = properties.builtInEncoding;
  18236. if (encoding) {
  18237. var builtInEncoding = {};
  18238. for (var charCode in encoding) {
  18239. glyphId = glyphNames.indexOf(encoding[charCode]);
  18240. if (glyphId >= 0) {
  18241. builtInEncoding[charCode] = glyphId;
  18242. }
  18243. }
  18244. }
  18245. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18246. },
  18247. getSeacs: function Type1Font_getSeacs(charstrings) {
  18248. var i, ii;
  18249. var seacMap = [];
  18250. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18251. var charstring = charstrings[i];
  18252. if (charstring.seac) {
  18253. // Offset by 1 for .notdef
  18254. seacMap[i + 1] = charstring.seac;
  18255. }
  18256. }
  18257. return seacMap;
  18258. },
  18259. getType2Charstrings: function Type1Font_getType2Charstrings(
  18260. type1Charstrings) {
  18261. var type2Charstrings = [];
  18262. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18263. type2Charstrings.push(type1Charstrings[i].charstring);
  18264. }
  18265. return type2Charstrings;
  18266. },
  18267. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18268. var bias = 0;
  18269. var count = type1Subrs.length;
  18270. if (count < 1133) {
  18271. bias = 107;
  18272. } else if (count < 33769) {
  18273. bias = 1131;
  18274. } else {
  18275. bias = 32768;
  18276. }
  18277. // Add a bunch of empty subrs to deal with the Type2 bias
  18278. var type2Subrs = [];
  18279. var i;
  18280. for (i = 0; i < bias; i++) {
  18281. type2Subrs.push([0x0B]);
  18282. }
  18283. for (i = 0; i < count; i++) {
  18284. type2Subrs.push(type1Subrs[i]);
  18285. }
  18286. return type2Subrs;
  18287. },
  18288. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18289. var cff = new CFF();
  18290. cff.header = new CFFHeader(1, 0, 4, 4);
  18291. cff.names = [name];
  18292. var topDict = new CFFTopDict();
  18293. // CFF strings IDs 0...390 are predefined names, so refering
  18294. // to entries in our own String INDEX starts at SID 391.
  18295. topDict.setByName('version', 391);
  18296. topDict.setByName('Notice', 392);
  18297. topDict.setByName('FullName', 393);
  18298. topDict.setByName('FamilyName', 394);
  18299. topDict.setByName('Weight', 395);
  18300. topDict.setByName('Encoding', null); // placeholder
  18301. topDict.setByName('FontMatrix', properties.fontMatrix);
  18302. topDict.setByName('FontBBox', properties.bbox);
  18303. topDict.setByName('charset', null); // placeholder
  18304. topDict.setByName('CharStrings', null); // placeholder
  18305. topDict.setByName('Private', null); // placeholder
  18306. cff.topDict = topDict;
  18307. var strings = new CFFStrings();
  18308. strings.add('Version 0.11'); // Version
  18309. strings.add('See original notice'); // Notice
  18310. strings.add(name); // FullName
  18311. strings.add(name); // FamilyName
  18312. strings.add('Medium'); // Weight
  18313. cff.strings = strings;
  18314. cff.globalSubrIndex = new CFFIndex();
  18315. var count = glyphs.length;
  18316. var charsetArray = [0];
  18317. var i, ii;
  18318. for (i = 0; i < count; i++) {
  18319. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18320. // TODO: Insert the string and correctly map it. Previously it was
  18321. // thought mapping names that aren't in the standard strings to .notdef
  18322. // was fine, however in issue818 when mapping them all to .notdef the
  18323. // adieresis glyph no longer worked.
  18324. if (index === -1) {
  18325. index = 0;
  18326. }
  18327. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18328. }
  18329. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18330. var charStringsIndex = new CFFIndex();
  18331. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18332. for (i = 0; i < count; i++) {
  18333. charStringsIndex.add(glyphs[i]);
  18334. }
  18335. cff.charStrings = charStringsIndex;
  18336. var privateDict = new CFFPrivateDict();
  18337. privateDict.setByName('Subrs', null); // placeholder
  18338. var fields = [
  18339. 'BlueValues',
  18340. 'OtherBlues',
  18341. 'FamilyBlues',
  18342. 'FamilyOtherBlues',
  18343. 'StemSnapH',
  18344. 'StemSnapV',
  18345. 'BlueShift',
  18346. 'BlueFuzz',
  18347. 'BlueScale',
  18348. 'LanguageGroup',
  18349. 'ExpansionFactor',
  18350. 'ForceBold',
  18351. 'StdHW',
  18352. 'StdVW'
  18353. ];
  18354. for (i = 0, ii = fields.length; i < ii; i++) {
  18355. var field = fields[i];
  18356. if (!properties.privateData.hasOwnProperty(field)) {
  18357. continue;
  18358. }
  18359. var value = properties.privateData[field];
  18360. if (isArray(value)) {
  18361. // All of the private dictionary array data in CFF must be stored as
  18362. // "delta-encoded" numbers.
  18363. for (var j = value.length - 1; j > 0; j--) {
  18364. value[j] -= value[j - 1]; // ... difference from previous value
  18365. }
  18366. }
  18367. privateDict.setByName(field, value);
  18368. }
  18369. cff.topDict.privateDict = privateDict;
  18370. var subrIndex = new CFFIndex();
  18371. for (i = 0, ii = subrs.length; i < ii; i++) {
  18372. subrIndex.add(subrs[i]);
  18373. }
  18374. privateDict.subrsIndex = subrIndex;
  18375. var compiler = new CFFCompiler(cff);
  18376. return compiler.compile();
  18377. }
  18378. };
  18379. var CFFFont = (function CFFFontClosure() {
  18380. function CFFFont(file, properties) {
  18381. this.properties = properties;
  18382. var parser = new CFFParser(file, properties);
  18383. this.cff = parser.parse();
  18384. var compiler = new CFFCompiler(this.cff);
  18385. this.seacs = this.cff.seacs;
  18386. try {
  18387. this.data = compiler.compile();
  18388. } catch (e) {
  18389. warn('Failed to compile font ' + properties.loadedName);
  18390. // There may have just been an issue with the compiler, set the data
  18391. // anyway and hope the font loaded.
  18392. this.data = file;
  18393. }
  18394. }
  18395. CFFFont.prototype = {
  18396. get numGlyphs() {
  18397. return this.cff.charStrings.count;
  18398. },
  18399. getCharset: function CFFFont_getCharset() {
  18400. return this.cff.charset.charset;
  18401. },
  18402. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18403. var cff = this.cff;
  18404. var properties = this.properties;
  18405. var charsets = cff.charset.charset;
  18406. var charCodeToGlyphId;
  18407. var glyphId;
  18408. if (properties.composite) {
  18409. charCodeToGlyphId = Object.create(null);
  18410. if (cff.isCIDFont) {
  18411. // If the font is actually a CID font then we should use the charset
  18412. // to map CIDs to GIDs.
  18413. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18414. var cid = charsets[glyphId];
  18415. var charCode = properties.cMap.charCodeOf(cid);
  18416. charCodeToGlyphId[charCode] = glyphId;
  18417. }
  18418. } else {
  18419. // If it is NOT actually a CID font then CIDs should be mapped
  18420. // directly to GIDs.
  18421. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18422. charCodeToGlyphId[glyphId] = glyphId;
  18423. }
  18424. }
  18425. return charCodeToGlyphId;
  18426. }
  18427. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18428. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18429. return charCodeToGlyphId;
  18430. }
  18431. };
  18432. return CFFFont;
  18433. })();
  18434. var CFFParser = (function CFFParserClosure() {
  18435. var CharstringValidationData = [
  18436. null,
  18437. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18438. null,
  18439. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18440. { id: 'vmoveto', min: 1, stackClearing: true },
  18441. { id: 'rlineto', min: 2, resetStack: true },
  18442. { id: 'hlineto', min: 1, resetStack: true },
  18443. { id: 'vlineto', min: 1, resetStack: true },
  18444. { id: 'rrcurveto', min: 6, resetStack: true },
  18445. null,
  18446. { id: 'callsubr', min: 1, undefStack: true },
  18447. { id: 'return', min: 0, undefStack: true },
  18448. null, // 12
  18449. null,
  18450. { id: 'endchar', min: 0, stackClearing: true },
  18451. null,
  18452. null,
  18453. null,
  18454. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18455. { id: 'hintmask', min: 0, stackClearing: true },
  18456. { id: 'cntrmask', min: 0, stackClearing: true },
  18457. { id: 'rmoveto', min: 2, stackClearing: true },
  18458. { id: 'hmoveto', min: 1, stackClearing: true },
  18459. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18460. { id: 'rcurveline', min: 8, resetStack: true },
  18461. { id: 'rlinecurve', min: 8, resetStack: true },
  18462. { id: 'vvcurveto', min: 4, resetStack: true },
  18463. { id: 'hhcurveto', min: 4, resetStack: true },
  18464. null, // shortint
  18465. { id: 'callgsubr', min: 1, undefStack: true },
  18466. { id: 'vhcurveto', min: 4, resetStack: true },
  18467. { id: 'hvcurveto', min: 4, resetStack: true }
  18468. ];
  18469. var CharstringValidationData12 = [
  18470. null,
  18471. null,
  18472. null,
  18473. { id: 'and', min: 2, stackDelta: -1 },
  18474. { id: 'or', min: 2, stackDelta: -1 },
  18475. { id: 'not', min: 1, stackDelta: 0 },
  18476. null,
  18477. null,
  18478. null,
  18479. { id: 'abs', min: 1, stackDelta: 0 },
  18480. { id: 'add', min: 2, stackDelta: -1,
  18481. stackFn: function stack_div(stack, index) {
  18482. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18483. }
  18484. },
  18485. { id: 'sub', min: 2, stackDelta: -1,
  18486. stackFn: function stack_div(stack, index) {
  18487. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18488. }
  18489. },
  18490. { id: 'div', min: 2, stackDelta: -1,
  18491. stackFn: function stack_div(stack, index) {
  18492. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18493. }
  18494. },
  18495. null,
  18496. { id: 'neg', min: 1, stackDelta: 0,
  18497. stackFn: function stack_div(stack, index) {
  18498. stack[index - 1] = -stack[index - 1];
  18499. }
  18500. },
  18501. { id: 'eq', min: 2, stackDelta: -1 },
  18502. null,
  18503. null,
  18504. { id: 'drop', min: 1, stackDelta: -1 },
  18505. null,
  18506. { id: 'put', min: 2, stackDelta: -2 },
  18507. { id: 'get', min: 1, stackDelta: 0 },
  18508. { id: 'ifelse', min: 4, stackDelta: -3 },
  18509. { id: 'random', min: 0, stackDelta: 1 },
  18510. { id: 'mul', min: 2, stackDelta: -1,
  18511. stackFn: function stack_div(stack, index) {
  18512. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18513. }
  18514. },
  18515. null,
  18516. { id: 'sqrt', min: 1, stackDelta: 0 },
  18517. { id: 'dup', min: 1, stackDelta: 1 },
  18518. { id: 'exch', min: 2, stackDelta: 0 },
  18519. { id: 'index', min: 2, stackDelta: 0 },
  18520. { id: 'roll', min: 3, stackDelta: -2 },
  18521. null,
  18522. null,
  18523. null,
  18524. { id: 'hflex', min: 7, resetStack: true },
  18525. { id: 'flex', min: 13, resetStack: true },
  18526. { id: 'hflex1', min: 9, resetStack: true },
  18527. { id: 'flex1', min: 11, resetStack: true }
  18528. ];
  18529. function CFFParser(file, properties) {
  18530. this.bytes = file.getBytes();
  18531. this.properties = properties;
  18532. }
  18533. CFFParser.prototype = {
  18534. parse: function CFFParser_parse() {
  18535. var properties = this.properties;
  18536. var cff = new CFF();
  18537. this.cff = cff;
  18538. // The first five sections must be in order, all the others are reached
  18539. // via offsets contained in one of the below.
  18540. var header = this.parseHeader();
  18541. var nameIndex = this.parseIndex(header.endPos);
  18542. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18543. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18544. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18545. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18546. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18547. cff.header = header.obj;
  18548. cff.names = this.parseNameIndex(nameIndex.obj);
  18549. cff.strings = this.parseStringIndex(stringIndex.obj);
  18550. cff.topDict = topDict;
  18551. cff.globalSubrIndex = globalSubrIndex.obj;
  18552. this.parsePrivateDict(cff.topDict);
  18553. cff.isCIDFont = topDict.hasName('ROS');
  18554. var charStringOffset = topDict.getByName('CharStrings');
  18555. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18556. cff.charStrings = charStringsAndSeacs.charStrings;
  18557. cff.seacs = charStringsAndSeacs.seacs;
  18558. cff.widths = charStringsAndSeacs.widths;
  18559. var fontMatrix = topDict.getByName('FontMatrix');
  18560. if (fontMatrix) {
  18561. properties.fontMatrix = fontMatrix;
  18562. }
  18563. var fontBBox = topDict.getByName('FontBBox');
  18564. if (fontBBox) {
  18565. // adjusting ascent/descent
  18566. properties.ascent = fontBBox[3];
  18567. properties.descent = fontBBox[1];
  18568. properties.ascentScaled = true;
  18569. }
  18570. var charset, encoding;
  18571. if (cff.isCIDFont) {
  18572. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18573. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18574. var dictRaw = fdArrayIndex.get(i);
  18575. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18576. cff.strings);
  18577. this.parsePrivateDict(fontDict);
  18578. cff.fdArray.push(fontDict);
  18579. }
  18580. // cid fonts don't have an encoding
  18581. encoding = null;
  18582. charset = this.parseCharsets(topDict.getByName('charset'),
  18583. cff.charStrings.count, cff.strings, true);
  18584. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18585. cff.charStrings.count);
  18586. } else {
  18587. charset = this.parseCharsets(topDict.getByName('charset'),
  18588. cff.charStrings.count, cff.strings, false);
  18589. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18590. properties,
  18591. cff.strings, charset.charset);
  18592. }
  18593. cff.charset = charset;
  18594. cff.encoding = encoding;
  18595. return cff;
  18596. },
  18597. parseHeader: function CFFParser_parseHeader() {
  18598. var bytes = this.bytes;
  18599. var bytesLength = bytes.length;
  18600. var offset = 0;
  18601. // Prevent an infinite loop, by checking that the offset is within the
  18602. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18603. while (offset < bytesLength && bytes[offset] !== 1) {
  18604. ++offset;
  18605. }
  18606. if (offset >= bytesLength) {
  18607. error('Invalid CFF header');
  18608. } else if (offset !== 0) {
  18609. info('cff data is shifted');
  18610. bytes = bytes.subarray(offset);
  18611. this.bytes = bytes;
  18612. }
  18613. var major = bytes[0];
  18614. var minor = bytes[1];
  18615. var hdrSize = bytes[2];
  18616. var offSize = bytes[3];
  18617. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18618. return { obj: header, endPos: hdrSize };
  18619. },
  18620. parseDict: function CFFParser_parseDict(dict) {
  18621. var pos = 0;
  18622. function parseOperand() {
  18623. var value = dict[pos++];
  18624. if (value === 30) {
  18625. return parseFloatOperand(pos);
  18626. } else if (value === 28) {
  18627. value = dict[pos++];
  18628. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18629. return value;
  18630. } else if (value === 29) {
  18631. value = dict[pos++];
  18632. value = (value << 8) | dict[pos++];
  18633. value = (value << 8) | dict[pos++];
  18634. value = (value << 8) | dict[pos++];
  18635. return value;
  18636. } else if (value >= 32 && value <= 246) {
  18637. return value - 139;
  18638. } else if (value >= 247 && value <= 250) {
  18639. return ((value - 247) * 256) + dict[pos++] + 108;
  18640. } else if (value >= 251 && value <= 254) {
  18641. return -((value - 251) * 256) - dict[pos++] - 108;
  18642. } else {
  18643. error('255 is not a valid DICT command');
  18644. }
  18645. return -1;
  18646. }
  18647. function parseFloatOperand() {
  18648. var str = '';
  18649. var eof = 15;
  18650. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18651. '9', '.', 'E', 'E-', null, '-'];
  18652. var length = dict.length;
  18653. while (pos < length) {
  18654. var b = dict[pos++];
  18655. var b1 = b >> 4;
  18656. var b2 = b & 15;
  18657. if (b1 === eof) {
  18658. break;
  18659. }
  18660. str += lookup[b1];
  18661. if (b2 === eof) {
  18662. break;
  18663. }
  18664. str += lookup[b2];
  18665. }
  18666. return parseFloat(str);
  18667. }
  18668. var operands = [];
  18669. var entries = [];
  18670. pos = 0;
  18671. var end = dict.length;
  18672. while (pos < end) {
  18673. var b = dict[pos];
  18674. if (b <= 21) {
  18675. if (b === 12) {
  18676. b = (b << 8) | dict[++pos];
  18677. }
  18678. entries.push([b, operands]);
  18679. operands = [];
  18680. ++pos;
  18681. } else {
  18682. operands.push(parseOperand());
  18683. }
  18684. }
  18685. return entries;
  18686. },
  18687. parseIndex: function CFFParser_parseIndex(pos) {
  18688. var cffIndex = new CFFIndex();
  18689. var bytes = this.bytes;
  18690. var count = (bytes[pos++] << 8) | bytes[pos++];
  18691. var offsets = [];
  18692. var end = pos;
  18693. var i, ii;
  18694. if (count !== 0) {
  18695. var offsetSize = bytes[pos++];
  18696. // add 1 for offset to determine size of last object
  18697. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18698. for (i = 0, ii = count + 1; i < ii; ++i) {
  18699. var offset = 0;
  18700. for (var j = 0; j < offsetSize; ++j) {
  18701. offset <<= 8;
  18702. offset += bytes[pos++];
  18703. }
  18704. offsets.push(startPos + offset);
  18705. }
  18706. end = offsets[count];
  18707. }
  18708. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18709. var offsetStart = offsets[i];
  18710. var offsetEnd = offsets[i + 1];
  18711. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18712. }
  18713. return {obj: cffIndex, endPos: end};
  18714. },
  18715. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18716. var names = [];
  18717. for (var i = 0, ii = index.count; i < ii; ++i) {
  18718. var name = index.get(i);
  18719. // OTS doesn't allow names to be over 127 characters.
  18720. var length = Math.min(name.length, 127);
  18721. var data = [];
  18722. // OTS also only permits certain characters in the name.
  18723. for (var j = 0; j < length; ++j) {
  18724. var c = name[j];
  18725. if (j === 0 && c === 0) {
  18726. data[j] = c;
  18727. continue;
  18728. }
  18729. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18730. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18731. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18732. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18733. data[j] = 95;
  18734. continue;
  18735. }
  18736. data[j] = c;
  18737. }
  18738. names.push(bytesToString(data));
  18739. }
  18740. return names;
  18741. },
  18742. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18743. var strings = new CFFStrings();
  18744. for (var i = 0, ii = index.count; i < ii; ++i) {
  18745. var data = index.get(i);
  18746. strings.add(bytesToString(data));
  18747. }
  18748. return strings;
  18749. },
  18750. createDict: function CFFParser_createDict(Type, dict, strings) {
  18751. var cffDict = new Type(strings);
  18752. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18753. var pair = dict[i];
  18754. var key = pair[0];
  18755. var value = pair[1];
  18756. cffDict.setByKey(key, value);
  18757. }
  18758. return cffDict;
  18759. },
  18760. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18761. var charStrings = this.parseIndex(charStringOffset).obj;
  18762. var seacs = [];
  18763. var widths = [];
  18764. var count = charStrings.count;
  18765. for (var i = 0; i < count; i++) {
  18766. var charstring = charStrings.get(i);
  18767. var stackSize = 0;
  18768. var stack = [];
  18769. var undefStack = true;
  18770. var hints = 0;
  18771. var valid = true;
  18772. var data = charstring;
  18773. var length = data.length;
  18774. var firstStackClearing = true;
  18775. for (var j = 0; j < length;) {
  18776. var value = data[j++];
  18777. var validationCommand = null;
  18778. if (value === 12) {
  18779. var q = data[j++];
  18780. if (q === 0) {
  18781. // The CFF specification state that the 'dotsection' command
  18782. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18783. // charstrings processors should support them. Unfortunately
  18784. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18785. // is replaced by a useless (0, hmoveto).
  18786. data[j - 2] = 139;
  18787. data[j - 1] = 22;
  18788. stackSize = 0;
  18789. } else {
  18790. validationCommand = CharstringValidationData12[q];
  18791. }
  18792. } else if (value === 28) { // number (16 bit)
  18793. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18794. j += 2;
  18795. stackSize++;
  18796. } else if (value === 14) {
  18797. if (stackSize >= 4) {
  18798. stackSize -= 4;
  18799. if (SEAC_ANALYSIS_ENABLED) {
  18800. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18801. valid = false;
  18802. }
  18803. }
  18804. validationCommand = CharstringValidationData[value];
  18805. } else if (value >= 32 && value <= 246) { // number
  18806. stack[stackSize] = value - 139;
  18807. stackSize++;
  18808. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18809. stack[stackSize] = (value < 251 ?
  18810. ((value - 247) << 8) + data[j] + 108 :
  18811. -((value - 251) << 8) - data[j] - 108);
  18812. j++;
  18813. stackSize++;
  18814. } else if (value === 255) { // number (32 bit)
  18815. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18816. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18817. j += 4;
  18818. stackSize++;
  18819. } else if (value === 19 || value === 20) {
  18820. hints += stackSize >> 1;
  18821. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18822. stackSize %= 2;
  18823. validationCommand = CharstringValidationData[value];
  18824. } else {
  18825. validationCommand = CharstringValidationData[value];
  18826. }
  18827. if (validationCommand) {
  18828. if (validationCommand.stem) {
  18829. hints += stackSize >> 1;
  18830. }
  18831. if ('min' in validationCommand) {
  18832. if (!undefStack && stackSize < validationCommand.min) {
  18833. warn('Not enough parameters for ' + validationCommand.id +
  18834. '; actual: ' + stackSize +
  18835. ', expected: ' + validationCommand.min);
  18836. valid = false;
  18837. break;
  18838. }
  18839. }
  18840. if (firstStackClearing && validationCommand.stackClearing) {
  18841. firstStackClearing = false;
  18842. // the optional character width can be found before the first
  18843. // stack-clearing command arguments
  18844. stackSize -= validationCommand.min;
  18845. if (stackSize >= 2 && validationCommand.stem) {
  18846. // there are even amount of arguments for stem commands
  18847. stackSize %= 2;
  18848. } else if (stackSize > 1) {
  18849. warn('Found too many parameters for stack-clearing command');
  18850. }
  18851. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18852. widths[i] = stack[stackSize - 1];
  18853. }
  18854. }
  18855. if ('stackDelta' in validationCommand) {
  18856. if ('stackFn' in validationCommand) {
  18857. validationCommand.stackFn(stack, stackSize);
  18858. }
  18859. stackSize += validationCommand.stackDelta;
  18860. } else if (validationCommand.stackClearing) {
  18861. stackSize = 0;
  18862. } else if (validationCommand.resetStack) {
  18863. stackSize = 0;
  18864. undefStack = false;
  18865. } else if (validationCommand.undefStack) {
  18866. stackSize = 0;
  18867. undefStack = true;
  18868. firstStackClearing = false;
  18869. }
  18870. }
  18871. }
  18872. if (!valid) {
  18873. // resetting invalid charstring to single 'endchar'
  18874. charStrings.set(i, new Uint8Array([14]));
  18875. }
  18876. }
  18877. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18878. },
  18879. emptyPrivateDictionary:
  18880. function CFFParser_emptyPrivateDictionary(parentDict) {
  18881. var privateDict = this.createDict(CFFPrivateDict, [],
  18882. parentDict.strings);
  18883. parentDict.setByKey(18, [0, 0]);
  18884. parentDict.privateDict = privateDict;
  18885. },
  18886. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18887. // no private dict, do nothing
  18888. if (!parentDict.hasName('Private')) {
  18889. this.emptyPrivateDictionary(parentDict);
  18890. return;
  18891. }
  18892. var privateOffset = parentDict.getByName('Private');
  18893. // make sure the params are formatted correctly
  18894. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18895. parentDict.removeByName('Private');
  18896. return;
  18897. }
  18898. var size = privateOffset[0];
  18899. var offset = privateOffset[1];
  18900. // remove empty dicts or ones that refer to invalid location
  18901. if (size === 0 || offset >= this.bytes.length) {
  18902. this.emptyPrivateDictionary(parentDict);
  18903. return;
  18904. }
  18905. var privateDictEnd = offset + size;
  18906. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18907. var dict = this.parseDict(dictData);
  18908. var privateDict = this.createDict(CFFPrivateDict, dict,
  18909. parentDict.strings);
  18910. parentDict.privateDict = privateDict;
  18911. // Parse the Subrs index also since it's relative to the private dict.
  18912. if (!privateDict.getByName('Subrs')) {
  18913. return;
  18914. }
  18915. var subrsOffset = privateDict.getByName('Subrs');
  18916. var relativeOffset = offset + subrsOffset;
  18917. // Validate the offset.
  18918. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18919. this.emptyPrivateDictionary(parentDict);
  18920. return;
  18921. }
  18922. var subrsIndex = this.parseIndex(relativeOffset);
  18923. privateDict.subrsIndex = subrsIndex.obj;
  18924. },
  18925. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18926. if (pos === 0) {
  18927. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18928. ISOAdobeCharset);
  18929. } else if (pos === 1) {
  18930. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18931. ExpertCharset);
  18932. } else if (pos === 2) {
  18933. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18934. ExpertSubsetCharset);
  18935. }
  18936. var bytes = this.bytes;
  18937. var start = pos;
  18938. var format = bytes[pos++];
  18939. var charset = ['.notdef'];
  18940. var id, count, i;
  18941. // subtract 1 for the .notdef glyph
  18942. length -= 1;
  18943. switch (format) {
  18944. case 0:
  18945. for (i = 0; i < length; i++) {
  18946. id = (bytes[pos++] << 8) | bytes[pos++];
  18947. charset.push(cid ? id : strings.get(id));
  18948. }
  18949. break;
  18950. case 1:
  18951. while (charset.length <= length) {
  18952. id = (bytes[pos++] << 8) | bytes[pos++];
  18953. count = bytes[pos++];
  18954. for (i = 0; i <= count; i++) {
  18955. charset.push(cid ? id++ : strings.get(id++));
  18956. }
  18957. }
  18958. break;
  18959. case 2:
  18960. while (charset.length <= length) {
  18961. id = (bytes[pos++] << 8) | bytes[pos++];
  18962. count = (bytes[pos++] << 8) | bytes[pos++];
  18963. for (i = 0; i <= count; i++) {
  18964. charset.push(cid ? id++ : strings.get(id++));
  18965. }
  18966. }
  18967. break;
  18968. default:
  18969. error('Unknown charset format');
  18970. }
  18971. // Raw won't be needed if we actually compile the charset.
  18972. var end = pos;
  18973. var raw = bytes.subarray(start, end);
  18974. return new CFFCharset(false, format, charset, raw);
  18975. },
  18976. parseEncoding: function CFFParser_parseEncoding(pos,
  18977. properties,
  18978. strings,
  18979. charset) {
  18980. var encoding = {};
  18981. var bytes = this.bytes;
  18982. var predefined = false;
  18983. var hasSupplement = false;
  18984. var format, i, ii;
  18985. var raw = null;
  18986. function readSupplement() {
  18987. var supplementsCount = bytes[pos++];
  18988. for (i = 0; i < supplementsCount; i++) {
  18989. var code = bytes[pos++];
  18990. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18991. encoding[code] = charset.indexOf(strings.get(sid));
  18992. }
  18993. }
  18994. if (pos === 0 || pos === 1) {
  18995. predefined = true;
  18996. format = pos;
  18997. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18998. Encodings.StandardEncoding;
  18999. for (i = 0, ii = charset.length; i < ii; i++) {
  19000. var index = baseEncoding.indexOf(charset[i]);
  19001. if (index !== -1) {
  19002. encoding[index] = i;
  19003. }
  19004. }
  19005. } else {
  19006. var dataStart = pos;
  19007. format = bytes[pos++];
  19008. switch (format & 0x7f) {
  19009. case 0:
  19010. var glyphsCount = bytes[pos++];
  19011. for (i = 1; i <= glyphsCount; i++) {
  19012. encoding[bytes[pos++]] = i;
  19013. }
  19014. break;
  19015. case 1:
  19016. var rangesCount = bytes[pos++];
  19017. var gid = 1;
  19018. for (i = 0; i < rangesCount; i++) {
  19019. var start = bytes[pos++];
  19020. var left = bytes[pos++];
  19021. for (var j = start; j <= start + left; j++) {
  19022. encoding[j] = gid++;
  19023. }
  19024. }
  19025. break;
  19026. default:
  19027. error('Unknow encoding format: ' + format + ' in CFF');
  19028. break;
  19029. }
  19030. var dataEnd = pos;
  19031. if (format & 0x80) {
  19032. // The font sanitizer does not support CFF encoding with a
  19033. // supplement, since the encoding is not really used to map
  19034. // between gid to glyph, let's overwrite what is declared in
  19035. // the top dictionary to let the sanitizer think the font use
  19036. // StandardEncoding, that's a lie but that's ok.
  19037. bytes[dataStart] &= 0x7f;
  19038. readSupplement();
  19039. hasSupplement = true;
  19040. }
  19041. raw = bytes.subarray(dataStart, dataEnd);
  19042. }
  19043. format = format & 0x7f;
  19044. return new CFFEncoding(predefined, format, encoding, raw);
  19045. },
  19046. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19047. var start = pos;
  19048. var bytes = this.bytes;
  19049. var format = bytes[pos++];
  19050. var fdSelect = [];
  19051. var i;
  19052. switch (format) {
  19053. case 0:
  19054. for (i = 0; i < length; ++i) {
  19055. var id = bytes[pos++];
  19056. fdSelect.push(id);
  19057. }
  19058. break;
  19059. case 3:
  19060. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19061. for (i = 0; i < rangesCount; ++i) {
  19062. var first = (bytes[pos++] << 8) | bytes[pos++];
  19063. var fdIndex = bytes[pos++];
  19064. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19065. for (var j = first; j < next; ++j) {
  19066. fdSelect.push(fdIndex);
  19067. }
  19068. }
  19069. // Advance past the sentinel(next).
  19070. pos += 2;
  19071. break;
  19072. default:
  19073. error('Unknown fdselect format ' + format);
  19074. break;
  19075. }
  19076. var end = pos;
  19077. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19078. }
  19079. };
  19080. return CFFParser;
  19081. })();
  19082. // Compact Font Format
  19083. var CFF = (function CFFClosure() {
  19084. function CFF() {
  19085. this.header = null;
  19086. this.names = [];
  19087. this.topDict = null;
  19088. this.strings = new CFFStrings();
  19089. this.globalSubrIndex = null;
  19090. // The following could really be per font, but since we only have one font
  19091. // store them here.
  19092. this.encoding = null;
  19093. this.charset = null;
  19094. this.charStrings = null;
  19095. this.fdArray = [];
  19096. this.fdSelect = null;
  19097. this.isCIDFont = false;
  19098. }
  19099. return CFF;
  19100. })();
  19101. var CFFHeader = (function CFFHeaderClosure() {
  19102. function CFFHeader(major, minor, hdrSize, offSize) {
  19103. this.major = major;
  19104. this.minor = minor;
  19105. this.hdrSize = hdrSize;
  19106. this.offSize = offSize;
  19107. }
  19108. return CFFHeader;
  19109. })();
  19110. var CFFStrings = (function CFFStringsClosure() {
  19111. function CFFStrings() {
  19112. this.strings = [];
  19113. }
  19114. CFFStrings.prototype = {
  19115. get: function CFFStrings_get(index) {
  19116. if (index >= 0 && index <= 390) {
  19117. return CFFStandardStrings[index];
  19118. }
  19119. if (index - 391 <= this.strings.length) {
  19120. return this.strings[index - 391];
  19121. }
  19122. return CFFStandardStrings[0];
  19123. },
  19124. add: function CFFStrings_add(value) {
  19125. this.strings.push(value);
  19126. },
  19127. get count() {
  19128. return this.strings.length;
  19129. }
  19130. };
  19131. return CFFStrings;
  19132. })();
  19133. var CFFIndex = (function CFFIndexClosure() {
  19134. function CFFIndex() {
  19135. this.objects = [];
  19136. this.length = 0;
  19137. }
  19138. CFFIndex.prototype = {
  19139. add: function CFFIndex_add(data) {
  19140. this.length += data.length;
  19141. this.objects.push(data);
  19142. },
  19143. set: function CFFIndex_set(index, data) {
  19144. this.length += data.length - this.objects[index].length;
  19145. this.objects[index] = data;
  19146. },
  19147. get: function CFFIndex_get(index) {
  19148. return this.objects[index];
  19149. },
  19150. get count() {
  19151. return this.objects.length;
  19152. }
  19153. };
  19154. return CFFIndex;
  19155. })();
  19156. var CFFDict = (function CFFDictClosure() {
  19157. function CFFDict(tables, strings) {
  19158. this.keyToNameMap = tables.keyToNameMap;
  19159. this.nameToKeyMap = tables.nameToKeyMap;
  19160. this.defaults = tables.defaults;
  19161. this.types = tables.types;
  19162. this.opcodes = tables.opcodes;
  19163. this.order = tables.order;
  19164. this.strings = strings;
  19165. this.values = {};
  19166. }
  19167. CFFDict.prototype = {
  19168. // value should always be an array
  19169. setByKey: function CFFDict_setByKey(key, value) {
  19170. if (!(key in this.keyToNameMap)) {
  19171. return false;
  19172. }
  19173. // ignore empty values
  19174. if (value.length === 0) {
  19175. return true;
  19176. }
  19177. var type = this.types[key];
  19178. // remove the array wrapping these types of values
  19179. if (type === 'num' || type === 'sid' || type === 'offset') {
  19180. value = value[0];
  19181. }
  19182. this.values[key] = value;
  19183. return true;
  19184. },
  19185. setByName: function CFFDict_setByName(name, value) {
  19186. if (!(name in this.nameToKeyMap)) {
  19187. error('Invalid dictionary name "' + name + '"');
  19188. }
  19189. this.values[this.nameToKeyMap[name]] = value;
  19190. },
  19191. hasName: function CFFDict_hasName(name) {
  19192. return this.nameToKeyMap[name] in this.values;
  19193. },
  19194. getByName: function CFFDict_getByName(name) {
  19195. if (!(name in this.nameToKeyMap)) {
  19196. error('Invalid dictionary name "' + name + '"');
  19197. }
  19198. var key = this.nameToKeyMap[name];
  19199. if (!(key in this.values)) {
  19200. return this.defaults[key];
  19201. }
  19202. return this.values[key];
  19203. },
  19204. removeByName: function CFFDict_removeByName(name) {
  19205. delete this.values[this.nameToKeyMap[name]];
  19206. }
  19207. };
  19208. CFFDict.createTables = function CFFDict_createTables(layout) {
  19209. var tables = {
  19210. keyToNameMap: {},
  19211. nameToKeyMap: {},
  19212. defaults: {},
  19213. types: {},
  19214. opcodes: {},
  19215. order: []
  19216. };
  19217. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19218. var entry = layout[i];
  19219. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19220. tables.keyToNameMap[key] = entry[1];
  19221. tables.nameToKeyMap[entry[1]] = key;
  19222. tables.types[key] = entry[2];
  19223. tables.defaults[key] = entry[3];
  19224. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19225. tables.order.push(key);
  19226. }
  19227. return tables;
  19228. };
  19229. return CFFDict;
  19230. })();
  19231. var CFFTopDict = (function CFFTopDictClosure() {
  19232. var layout = [
  19233. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19234. [[12, 20], 'SyntheticBase', 'num', null],
  19235. [0, 'version', 'sid', null],
  19236. [1, 'Notice', 'sid', null],
  19237. [[12, 0], 'Copyright', 'sid', null],
  19238. [2, 'FullName', 'sid', null],
  19239. [3, 'FamilyName', 'sid', null],
  19240. [4, 'Weight', 'sid', null],
  19241. [[12, 1], 'isFixedPitch', 'num', 0],
  19242. [[12, 2], 'ItalicAngle', 'num', 0],
  19243. [[12, 3], 'UnderlinePosition', 'num', -100],
  19244. [[12, 4], 'UnderlineThickness', 'num', 50],
  19245. [[12, 5], 'PaintType', 'num', 0],
  19246. [[12, 6], 'CharstringType', 'num', 2],
  19247. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19248. [0.001, 0, 0, 0.001, 0, 0]],
  19249. [13, 'UniqueID', 'num', null],
  19250. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19251. [[12, 8], 'StrokeWidth', 'num', 0],
  19252. [14, 'XUID', 'array', null],
  19253. [15, 'charset', 'offset', 0],
  19254. [16, 'Encoding', 'offset', 0],
  19255. [17, 'CharStrings', 'offset', 0],
  19256. [18, 'Private', ['offset', 'offset'], null],
  19257. [[12, 21], 'PostScript', 'sid', null],
  19258. [[12, 22], 'BaseFontName', 'sid', null],
  19259. [[12, 23], 'BaseFontBlend', 'delta', null],
  19260. [[12, 31], 'CIDFontVersion', 'num', 0],
  19261. [[12, 32], 'CIDFontRevision', 'num', 0],
  19262. [[12, 33], 'CIDFontType', 'num', 0],
  19263. [[12, 34], 'CIDCount', 'num', 8720],
  19264. [[12, 35], 'UIDBase', 'num', null],
  19265. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19266. // before FDArray.
  19267. [[12, 37], 'FDSelect', 'offset', null],
  19268. [[12, 36], 'FDArray', 'offset', null],
  19269. [[12, 38], 'FontName', 'sid', null]
  19270. ];
  19271. var tables = null;
  19272. function CFFTopDict(strings) {
  19273. if (tables === null) {
  19274. tables = CFFDict.createTables(layout);
  19275. }
  19276. CFFDict.call(this, tables, strings);
  19277. this.privateDict = null;
  19278. }
  19279. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19280. return CFFTopDict;
  19281. })();
  19282. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19283. var layout = [
  19284. [6, 'BlueValues', 'delta', null],
  19285. [7, 'OtherBlues', 'delta', null],
  19286. [8, 'FamilyBlues', 'delta', null],
  19287. [9, 'FamilyOtherBlues', 'delta', null],
  19288. [[12, 9], 'BlueScale', 'num', 0.039625],
  19289. [[12, 10], 'BlueShift', 'num', 7],
  19290. [[12, 11], 'BlueFuzz', 'num', 1],
  19291. [10, 'StdHW', 'num', null],
  19292. [11, 'StdVW', 'num', null],
  19293. [[12, 12], 'StemSnapH', 'delta', null],
  19294. [[12, 13], 'StemSnapV', 'delta', null],
  19295. [[12, 14], 'ForceBold', 'num', 0],
  19296. [[12, 17], 'LanguageGroup', 'num', 0],
  19297. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19298. [[12, 19], 'initialRandomSeed', 'num', 0],
  19299. [20, 'defaultWidthX', 'num', 0],
  19300. [21, 'nominalWidthX', 'num', 0],
  19301. [19, 'Subrs', 'offset', null]
  19302. ];
  19303. var tables = null;
  19304. function CFFPrivateDict(strings) {
  19305. if (tables === null) {
  19306. tables = CFFDict.createTables(layout);
  19307. }
  19308. CFFDict.call(this, tables, strings);
  19309. this.subrsIndex = null;
  19310. }
  19311. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19312. return CFFPrivateDict;
  19313. })();
  19314. var CFFCharsetPredefinedTypes = {
  19315. ISO_ADOBE: 0,
  19316. EXPERT: 1,
  19317. EXPERT_SUBSET: 2
  19318. };
  19319. var CFFCharset = (function CFFCharsetClosure() {
  19320. function CFFCharset(predefined, format, charset, raw) {
  19321. this.predefined = predefined;
  19322. this.format = format;
  19323. this.charset = charset;
  19324. this.raw = raw;
  19325. }
  19326. return CFFCharset;
  19327. })();
  19328. var CFFEncoding = (function CFFEncodingClosure() {
  19329. function CFFEncoding(predefined, format, encoding, raw) {
  19330. this.predefined = predefined;
  19331. this.format = format;
  19332. this.encoding = encoding;
  19333. this.raw = raw;
  19334. }
  19335. return CFFEncoding;
  19336. })();
  19337. var CFFFDSelect = (function CFFFDSelectClosure() {
  19338. function CFFFDSelect(fdSelect, raw) {
  19339. this.fdSelect = fdSelect;
  19340. this.raw = raw;
  19341. }
  19342. return CFFFDSelect;
  19343. })();
  19344. // Helper class to keep track of where an offset is within the data and helps
  19345. // filling in that offset once it's known.
  19346. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19347. function CFFOffsetTracker() {
  19348. this.offsets = {};
  19349. }
  19350. CFFOffsetTracker.prototype = {
  19351. isTracking: function CFFOffsetTracker_isTracking(key) {
  19352. return key in this.offsets;
  19353. },
  19354. track: function CFFOffsetTracker_track(key, location) {
  19355. if (key in this.offsets) {
  19356. error('Already tracking location of ' + key);
  19357. }
  19358. this.offsets[key] = location;
  19359. },
  19360. offset: function CFFOffsetTracker_offset(value) {
  19361. for (var key in this.offsets) {
  19362. this.offsets[key] += value;
  19363. }
  19364. },
  19365. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19366. values,
  19367. output) {
  19368. if (!(key in this.offsets)) {
  19369. error('Not tracking location of ' + key);
  19370. }
  19371. var data = output.data;
  19372. var dataOffset = this.offsets[key];
  19373. var size = 5;
  19374. for (var i = 0, ii = values.length; i < ii; ++i) {
  19375. var offset0 = i * size + dataOffset;
  19376. var offset1 = offset0 + 1;
  19377. var offset2 = offset0 + 2;
  19378. var offset3 = offset0 + 3;
  19379. var offset4 = offset0 + 4;
  19380. // It's easy to screw up offsets so perform this sanity check.
  19381. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19382. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19383. error('writing to an offset that is not empty');
  19384. }
  19385. var value = values[i];
  19386. data[offset0] = 0x1d;
  19387. data[offset1] = (value >> 24) & 0xFF;
  19388. data[offset2] = (value >> 16) & 0xFF;
  19389. data[offset3] = (value >> 8) & 0xFF;
  19390. data[offset4] = value & 0xFF;
  19391. }
  19392. }
  19393. };
  19394. return CFFOffsetTracker;
  19395. })();
  19396. // Takes a CFF and converts it to the binary representation.
  19397. var CFFCompiler = (function CFFCompilerClosure() {
  19398. function CFFCompiler(cff) {
  19399. this.cff = cff;
  19400. }
  19401. CFFCompiler.prototype = {
  19402. compile: function CFFCompiler_compile() {
  19403. var cff = this.cff;
  19404. var output = {
  19405. data: [],
  19406. length: 0,
  19407. add: function CFFCompiler_add(data) {
  19408. this.data = this.data.concat(data);
  19409. this.length = this.data.length;
  19410. }
  19411. };
  19412. // Compile the five entries that must be in order.
  19413. var header = this.compileHeader(cff.header);
  19414. output.add(header);
  19415. var nameIndex = this.compileNameIndex(cff.names);
  19416. output.add(nameIndex);
  19417. if (cff.isCIDFont) {
  19418. // The spec is unclear on how font matrices should relate to each other
  19419. // when there is one in the main top dict and the sub top dicts.
  19420. // Windows handles this differently than linux and osx so we have to
  19421. // normalize to work on all.
  19422. // Rules based off of some mailing list discussions:
  19423. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19424. // - If no main font matrix and there is a subfont matrix, use the
  19425. // subfont matrix.
  19426. // - If both have matrices, concat together.
  19427. // - If neither have matrices, use default.
  19428. // To make this work on all platforms we move the top matrix into each
  19429. // sub top dict and concat if necessary.
  19430. if (cff.topDict.hasName('FontMatrix')) {
  19431. var base = cff.topDict.getByName('FontMatrix');
  19432. cff.topDict.removeByName('FontMatrix');
  19433. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19434. var subDict = cff.fdArray[i];
  19435. var matrix = base.slice(0);
  19436. if (subDict.hasName('FontMatrix')) {
  19437. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19438. }
  19439. subDict.setByName('FontMatrix', matrix);
  19440. }
  19441. }
  19442. }
  19443. var compiled = this.compileTopDicts([cff.topDict],
  19444. output.length,
  19445. cff.isCIDFont);
  19446. output.add(compiled.output);
  19447. var topDictTracker = compiled.trackers[0];
  19448. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19449. output.add(stringIndex);
  19450. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19451. output.add(globalSubrIndex);
  19452. // Now start on the other entries that have no specfic order.
  19453. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19454. if (cff.encoding.predefined) {
  19455. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19456. output);
  19457. } else {
  19458. var encoding = this.compileEncoding(cff.encoding);
  19459. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19460. output.add(encoding);
  19461. }
  19462. }
  19463. if (cff.charset && cff.topDict.hasName('charset')) {
  19464. if (cff.charset.predefined) {
  19465. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19466. output);
  19467. } else {
  19468. var charset = this.compileCharset(cff.charset);
  19469. topDictTracker.setEntryLocation('charset', [output.length], output);
  19470. output.add(charset);
  19471. }
  19472. }
  19473. var charStrings = this.compileCharStrings(cff.charStrings);
  19474. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19475. output.add(charStrings);
  19476. if (cff.isCIDFont) {
  19477. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19478. // and linux don't seem to care.
  19479. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19480. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19481. output.add(fdSelect);
  19482. // It is unclear if the sub font dictionary can have CID related
  19483. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19484. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19485. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19486. output.add(compiled.output);
  19487. var fontDictTrackers = compiled.trackers;
  19488. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19489. }
  19490. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19491. // If the font data ends with INDEX whose object data is zero-length,
  19492. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19493. output.add([0]);
  19494. return output.data;
  19495. },
  19496. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19497. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19498. return this.encodeInteger(value);
  19499. } else {
  19500. return this.encodeFloat(value);
  19501. }
  19502. },
  19503. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19504. var value = num.toString();
  19505. // rounding inaccurate doubles
  19506. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19507. if (m) {
  19508. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19509. value = (Math.round(num * epsilon) / epsilon).toString();
  19510. }
  19511. var nibbles = '';
  19512. var i, ii;
  19513. for (i = 0, ii = value.length; i < ii; ++i) {
  19514. var a = value[i];
  19515. if (a === 'e') {
  19516. nibbles += value[++i] === '-' ? 'c' : 'b';
  19517. } else if (a === '.') {
  19518. nibbles += 'a';
  19519. } else if (a === '-') {
  19520. nibbles += 'e';
  19521. } else {
  19522. nibbles += a;
  19523. }
  19524. }
  19525. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19526. var out = [30];
  19527. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19528. out.push(parseInt(nibbles.substr(i, 2), 16));
  19529. }
  19530. return out;
  19531. },
  19532. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19533. var code;
  19534. if (value >= -107 && value <= 107) {
  19535. code = [value + 139];
  19536. } else if (value >= 108 && value <= 1131) {
  19537. value = [value - 108];
  19538. code = [(value >> 8) + 247, value & 0xFF];
  19539. } else if (value >= -1131 && value <= -108) {
  19540. value = -value - 108;
  19541. code = [(value >> 8) + 251, value & 0xFF];
  19542. } else if (value >= -32768 && value <= 32767) {
  19543. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19544. } else {
  19545. code = [0x1d,
  19546. (value >> 24) & 0xFF,
  19547. (value >> 16) & 0xFF,
  19548. (value >> 8) & 0xFF,
  19549. value & 0xFF];
  19550. }
  19551. return code;
  19552. },
  19553. compileHeader: function CFFCompiler_compileHeader(header) {
  19554. return [
  19555. header.major,
  19556. header.minor,
  19557. header.hdrSize,
  19558. header.offSize
  19559. ];
  19560. },
  19561. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19562. var nameIndex = new CFFIndex();
  19563. for (var i = 0, ii = names.length; i < ii; ++i) {
  19564. nameIndex.add(stringToBytes(names[i]));
  19565. }
  19566. return this.compileIndex(nameIndex);
  19567. },
  19568. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19569. length,
  19570. removeCidKeys) {
  19571. var fontDictTrackers = [];
  19572. var fdArrayIndex = new CFFIndex();
  19573. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19574. var fontDict = dicts[i];
  19575. if (removeCidKeys) {
  19576. fontDict.removeByName('CIDFontVersion');
  19577. fontDict.removeByName('CIDFontRevision');
  19578. fontDict.removeByName('CIDFontType');
  19579. fontDict.removeByName('CIDCount');
  19580. fontDict.removeByName('UIDBase');
  19581. }
  19582. var fontDictTracker = new CFFOffsetTracker();
  19583. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19584. fontDictTrackers.push(fontDictTracker);
  19585. fdArrayIndex.add(fontDictData);
  19586. fontDictTracker.offset(length);
  19587. }
  19588. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19589. return {
  19590. trackers: fontDictTrackers,
  19591. output: fdArrayIndex
  19592. };
  19593. },
  19594. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19595. trackers,
  19596. output) {
  19597. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19598. var fontDict = dicts[i];
  19599. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19600. 'There must be an private dictionary.');
  19601. var privateDict = fontDict.privateDict;
  19602. var privateDictTracker = new CFFOffsetTracker();
  19603. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19604. var outputLength = output.length;
  19605. privateDictTracker.offset(outputLength);
  19606. if (!privateDictData.length) {
  19607. // The private dictionary was empty, set the output length to zero to
  19608. // ensure the offset length isn't out of bounds in the eyes of the
  19609. // sanitizer.
  19610. outputLength = 0;
  19611. }
  19612. trackers[i].setEntryLocation('Private',
  19613. [privateDictData.length, outputLength],
  19614. output);
  19615. output.add(privateDictData);
  19616. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19617. var subrs = this.compileIndex(privateDict.subrsIndex);
  19618. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19619. output);
  19620. output.add(subrs);
  19621. }
  19622. }
  19623. },
  19624. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19625. var out = [];
  19626. // The dictionary keys must be in a certain order.
  19627. var order = dict.order;
  19628. for (var i = 0; i < order.length; ++i) {
  19629. var key = order[i];
  19630. if (!(key in dict.values)) {
  19631. continue;
  19632. }
  19633. var values = dict.values[key];
  19634. var types = dict.types[key];
  19635. if (!isArray(types)) {
  19636. types = [types];
  19637. }
  19638. if (!isArray(values)) {
  19639. values = [values];
  19640. }
  19641. // Remove any empty dict values.
  19642. if (values.length === 0) {
  19643. continue;
  19644. }
  19645. for (var j = 0, jj = types.length; j < jj; ++j) {
  19646. var type = types[j];
  19647. var value = values[j];
  19648. switch (type) {
  19649. case 'num':
  19650. case 'sid':
  19651. out = out.concat(this.encodeNumber(value));
  19652. break;
  19653. case 'offset':
  19654. // For offsets we just insert a 32bit integer so we don't have to
  19655. // deal with figuring out the length of the offset when it gets
  19656. // replaced later on by the compiler.
  19657. var name = dict.keyToNameMap[key];
  19658. // Some offsets have the offset and the length, so just record the
  19659. // position of the first one.
  19660. if (!offsetTracker.isTracking(name)) {
  19661. offsetTracker.track(name, out.length);
  19662. }
  19663. out = out.concat([0x1d, 0, 0, 0, 0]);
  19664. break;
  19665. case 'array':
  19666. case 'delta':
  19667. out = out.concat(this.encodeNumber(value));
  19668. for (var k = 1, kk = values.length; k < kk; ++k) {
  19669. out = out.concat(this.encodeNumber(values[k]));
  19670. }
  19671. break;
  19672. default:
  19673. error('Unknown data type of ' + type);
  19674. break;
  19675. }
  19676. }
  19677. out = out.concat(dict.opcodes[key]);
  19678. }
  19679. return out;
  19680. },
  19681. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19682. var stringIndex = new CFFIndex();
  19683. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19684. stringIndex.add(stringToBytes(strings[i]));
  19685. }
  19686. return this.compileIndex(stringIndex);
  19687. },
  19688. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19689. var globalSubrIndex = this.cff.globalSubrIndex;
  19690. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19691. },
  19692. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19693. return this.compileIndex(charStrings);
  19694. },
  19695. compileCharset: function CFFCompiler_compileCharset(charset) {
  19696. return this.compileTypedArray(charset.raw);
  19697. },
  19698. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19699. return this.compileTypedArray(encoding.raw);
  19700. },
  19701. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19702. return this.compileTypedArray(fdSelect);
  19703. },
  19704. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19705. var out = [];
  19706. for (var i = 0, ii = data.length; i < ii; ++i) {
  19707. out[i] = data[i];
  19708. }
  19709. return out;
  19710. },
  19711. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19712. trackers = trackers || [];
  19713. var objects = index.objects;
  19714. // First 2 bytes contains the number of objects contained into this index
  19715. var count = objects.length;
  19716. // If there is no object, just create an index. This technically
  19717. // should just be [0, 0] but OTS has an issue with that.
  19718. if (count === 0) {
  19719. return [0, 0, 0];
  19720. }
  19721. var data = [(count >> 8) & 0xFF, count & 0xff];
  19722. var lastOffset = 1, i;
  19723. for (i = 0; i < count; ++i) {
  19724. lastOffset += objects[i].length;
  19725. }
  19726. var offsetSize;
  19727. if (lastOffset < 0x100) {
  19728. offsetSize = 1;
  19729. } else if (lastOffset < 0x10000) {
  19730. offsetSize = 2;
  19731. } else if (lastOffset < 0x1000000) {
  19732. offsetSize = 3;
  19733. } else {
  19734. offsetSize = 4;
  19735. }
  19736. // Next byte contains the offset size use to reference object in the file
  19737. data.push(offsetSize);
  19738. // Add another offset after this one because we need a new offset
  19739. var relativeOffset = 1;
  19740. for (i = 0; i < count + 1; i++) {
  19741. if (offsetSize === 1) {
  19742. data.push(relativeOffset & 0xFF);
  19743. } else if (offsetSize === 2) {
  19744. data.push((relativeOffset >> 8) & 0xFF,
  19745. relativeOffset & 0xFF);
  19746. } else if (offsetSize === 3) {
  19747. data.push((relativeOffset >> 16) & 0xFF,
  19748. (relativeOffset >> 8) & 0xFF,
  19749. relativeOffset & 0xFF);
  19750. } else {
  19751. data.push((relativeOffset >>> 24) & 0xFF,
  19752. (relativeOffset >> 16) & 0xFF,
  19753. (relativeOffset >> 8) & 0xFF,
  19754. relativeOffset & 0xFF);
  19755. }
  19756. if (objects[i]) {
  19757. relativeOffset += objects[i].length;
  19758. }
  19759. }
  19760. for (i = 0; i < count; i++) {
  19761. // Notify the tracker where the object will be offset in the data.
  19762. if (trackers[i]) {
  19763. trackers[i].offset(data.length);
  19764. }
  19765. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19766. data.push(objects[i][j]);
  19767. }
  19768. }
  19769. return data;
  19770. }
  19771. };
  19772. return CFFCompiler;
  19773. })();
  19774. // Workaround for seac on Windows.
  19775. (function checkSeacSupport() {
  19776. if (/Windows/.test(navigator.userAgent)) {
  19777. SEAC_ANALYSIS_ENABLED = true;
  19778. }
  19779. })();
  19780. // Workaround for Private Use Area characters in Chrome on Windows
  19781. // http://code.google.com/p/chromium/issues/detail?id=122465
  19782. // https://github.com/mozilla/pdf.js/issues/1689
  19783. (function checkChromeWindows() {
  19784. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19785. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19786. }
  19787. })();
  19788. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19789. function getLong(data, offset) {
  19790. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19791. (data[offset + 2] << 8) | data[offset + 3];
  19792. }
  19793. function getUshort(data, offset) {
  19794. return (data[offset] << 8) | data[offset + 1];
  19795. }
  19796. function parseCmap(data, start, end) {
  19797. var offset = (getUshort(data, start + 2) === 1 ?
  19798. getLong(data, start + 8) : getLong(data, start + 16));
  19799. var format = getUshort(data, start + offset);
  19800. var length, ranges, p, i;
  19801. if (format === 4) {
  19802. length = getUshort(data, start + offset + 2);
  19803. var segCount = getUshort(data, start + offset + 6) >> 1;
  19804. p = start + offset + 14;
  19805. ranges = [];
  19806. for (i = 0; i < segCount; i++, p += 2) {
  19807. ranges[i] = {end: getUshort(data, p)};
  19808. }
  19809. p += 2;
  19810. for (i = 0; i < segCount; i++, p += 2) {
  19811. ranges[i].start = getUshort(data, p);
  19812. }
  19813. for (i = 0; i < segCount; i++, p += 2) {
  19814. ranges[i].idDelta = getUshort(data, p);
  19815. }
  19816. for (i = 0; i < segCount; i++, p += 2) {
  19817. var idOffset = getUshort(data, p);
  19818. if (idOffset === 0) {
  19819. continue;
  19820. }
  19821. ranges[i].ids = [];
  19822. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19823. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19824. idOffset += 2;
  19825. }
  19826. }
  19827. return ranges;
  19828. } else if (format === 12) {
  19829. length = getLong(data, start + offset + 4);
  19830. var groups = getLong(data, start + offset + 12);
  19831. p = start + offset + 16;
  19832. ranges = [];
  19833. for (i = 0; i < groups; i++) {
  19834. ranges.push({
  19835. start: getLong(data, p),
  19836. end: getLong(data, p + 4),
  19837. idDelta: getLong(data, p + 8) - getLong(data, p)
  19838. });
  19839. p += 12;
  19840. }
  19841. return ranges;
  19842. }
  19843. error('not supported cmap: ' + format);
  19844. }
  19845. function parseCff(data, start, end) {
  19846. var properties = {};
  19847. var parser = new CFFParser(new Stream(data, start, end - start),
  19848. properties);
  19849. var cff = parser.parse();
  19850. return {
  19851. glyphs: cff.charStrings.objects,
  19852. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19853. cff.topDict.privateDict.subrsIndex.objects),
  19854. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19855. };
  19856. }
  19857. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19858. var itemSize, itemDecode;
  19859. if (isGlyphLocationsLong) {
  19860. itemSize = 4;
  19861. itemDecode = function fontItemDecodeLong(data, offset) {
  19862. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19863. (data[offset + 2] << 8) | data[offset + 3];
  19864. };
  19865. } else {
  19866. itemSize = 2;
  19867. itemDecode = function fontItemDecode(data, offset) {
  19868. return (data[offset] << 9) | (data[offset + 1] << 1);
  19869. };
  19870. }
  19871. var glyphs = [];
  19872. var startOffset = itemDecode(loca, 0);
  19873. for (var j = itemSize; j < loca.length; j += itemSize) {
  19874. var endOffset = itemDecode(loca, j);
  19875. glyphs.push(glyf.subarray(startOffset, endOffset));
  19876. startOffset = endOffset;
  19877. }
  19878. return glyphs;
  19879. }
  19880. function lookupCmap(ranges, unicode) {
  19881. var code = unicode.charCodeAt(0);
  19882. var l = 0, r = ranges.length - 1;
  19883. while (l < r) {
  19884. var c = (l + r + 1) >> 1;
  19885. if (code < ranges[c].start) {
  19886. r = c - 1;
  19887. } else {
  19888. l = c;
  19889. }
  19890. }
  19891. if (ranges[l].start <= code && code <= ranges[l].end) {
  19892. return (ranges[l].idDelta + (ranges[l].ids ?
  19893. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19894. }
  19895. return 0;
  19896. }
  19897. function compileGlyf(code, js, font) {
  19898. function moveTo(x, y) {
  19899. js.push('c.moveTo(' + x + ',' + y + ');');
  19900. }
  19901. function lineTo(x, y) {
  19902. js.push('c.lineTo(' + x + ',' + y + ');');
  19903. }
  19904. function quadraticCurveTo(xa, ya, x, y) {
  19905. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19906. x + ',' + y + ');');
  19907. }
  19908. var i = 0;
  19909. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19910. var flags;
  19911. var x = 0, y = 0;
  19912. i += 10;
  19913. if (numberOfContours < 0) {
  19914. // composite glyph
  19915. do {
  19916. flags = (code[i] << 8) | code[i + 1];
  19917. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19918. i += 4;
  19919. var arg1, arg2;
  19920. if ((flags & 0x01)) {
  19921. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19922. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19923. i += 4;
  19924. } else {
  19925. arg1 = code[i++]; arg2 = code[i++];
  19926. }
  19927. if ((flags & 0x02)) {
  19928. x = arg1;
  19929. y = arg2;
  19930. } else {
  19931. x = 0; y = 0; // TODO "they are points" ?
  19932. }
  19933. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19934. if ((flags & 0x08)) {
  19935. scaleX =
  19936. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19937. i += 2;
  19938. } else if ((flags & 0x40)) {
  19939. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19940. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19941. i += 4;
  19942. } else if ((flags & 0x80)) {
  19943. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19944. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19945. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19946. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19947. i += 8;
  19948. }
  19949. var subglyph = font.glyphs[glyphIndex];
  19950. if (subglyph) {
  19951. js.push('c.save();');
  19952. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19953. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19954. compileGlyf(subglyph, js, font);
  19955. js.push('c.restore();');
  19956. }
  19957. } while ((flags & 0x20));
  19958. } else {
  19959. // simple glyph
  19960. var endPtsOfContours = [];
  19961. var j, jj;
  19962. for (j = 0; j < numberOfContours; j++) {
  19963. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19964. i += 2;
  19965. }
  19966. var instructionLength = (code[i] << 8) | code[i + 1];
  19967. i += 2 + instructionLength; // skipping the instructions
  19968. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19969. var points = [];
  19970. while (points.length < numberOfPoints) {
  19971. flags = code[i++];
  19972. var repeat = 1;
  19973. if ((flags & 0x08)) {
  19974. repeat += code[i++];
  19975. }
  19976. while (repeat-- > 0) {
  19977. points.push({flags: flags});
  19978. }
  19979. }
  19980. for (j = 0; j < numberOfPoints; j++) {
  19981. switch (points[j].flags & 0x12) {
  19982. case 0x00:
  19983. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19984. i += 2;
  19985. break;
  19986. case 0x02:
  19987. x -= code[i++];
  19988. break;
  19989. case 0x12:
  19990. x += code[i++];
  19991. break;
  19992. }
  19993. points[j].x = x;
  19994. }
  19995. for (j = 0; j < numberOfPoints; j++) {
  19996. switch (points[j].flags & 0x24) {
  19997. case 0x00:
  19998. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19999. i += 2;
  20000. break;
  20001. case 0x04:
  20002. y -= code[i++];
  20003. break;
  20004. case 0x24:
  20005. y += code[i++];
  20006. break;
  20007. }
  20008. points[j].y = y;
  20009. }
  20010. var startPoint = 0;
  20011. for (i = 0; i < numberOfContours; i++) {
  20012. var endPoint = endPtsOfContours[i];
  20013. // contours might have implicit points, which is located in the middle
  20014. // between two neighboring off-curve points
  20015. var contour = points.slice(startPoint, endPoint + 1);
  20016. if ((contour[0].flags & 1)) {
  20017. contour.push(contour[0]); // using start point at the contour end
  20018. } else if ((contour[contour.length - 1].flags & 1)) {
  20019. // first is off-curve point, trying to use one from the end
  20020. contour.unshift(contour[contour.length - 1]);
  20021. } else {
  20022. // start and end are off-curve points, creating implicit one
  20023. var p = {
  20024. flags: 1,
  20025. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20026. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20027. };
  20028. contour.unshift(p);
  20029. contour.push(p);
  20030. }
  20031. moveTo(contour[0].x, contour[0].y);
  20032. for (j = 1, jj = contour.length; j < jj; j++) {
  20033. if ((contour[j].flags & 1)) {
  20034. lineTo(contour[j].x, contour[j].y);
  20035. } else if ((contour[j + 1].flags & 1)){
  20036. quadraticCurveTo(contour[j].x, contour[j].y,
  20037. contour[j + 1].x, contour[j + 1].y);
  20038. j++;
  20039. } else {
  20040. quadraticCurveTo(contour[j].x, contour[j].y,
  20041. (contour[j].x + contour[j + 1].x) / 2,
  20042. (contour[j].y + contour[j + 1].y) / 2);
  20043. }
  20044. }
  20045. startPoint = endPoint + 1;
  20046. }
  20047. }
  20048. }
  20049. function compileCharString(code, js, font) {
  20050. var stack = [];
  20051. var x = 0, y = 0;
  20052. var stems = 0;
  20053. function moveTo(x, y) {
  20054. js.push('c.moveTo(' + x + ',' + y + ');');
  20055. }
  20056. function lineTo(x, y) {
  20057. js.push('c.lineTo(' + x + ',' + y + ');');
  20058. }
  20059. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20060. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  20061. x + ',' + y + ');');
  20062. }
  20063. function parse(code) {
  20064. var i = 0;
  20065. while (i < code.length) {
  20066. var stackClean = false;
  20067. var v = code[i++];
  20068. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20069. switch (v) {
  20070. case 1: // hstem
  20071. stems += stack.length >> 1;
  20072. stackClean = true;
  20073. break;
  20074. case 3: // vstem
  20075. stems += stack.length >> 1;
  20076. stackClean = true;
  20077. break;
  20078. case 4: // vmoveto
  20079. y += stack.pop();
  20080. moveTo(x, y);
  20081. stackClean = true;
  20082. break;
  20083. case 5: // rlineto
  20084. while (stack.length > 0) {
  20085. x += stack.shift();
  20086. y += stack.shift();
  20087. lineTo(x, y);
  20088. }
  20089. break;
  20090. case 6: // hlineto
  20091. while (stack.length > 0) {
  20092. x += stack.shift();
  20093. lineTo(x, y);
  20094. if (stack.length === 0) {
  20095. break;
  20096. }
  20097. y += stack.shift();
  20098. lineTo(x, y);
  20099. }
  20100. break;
  20101. case 7: // vlineto
  20102. while (stack.length > 0) {
  20103. y += stack.shift();
  20104. lineTo(x, y);
  20105. if (stack.length === 0) {
  20106. break;
  20107. }
  20108. x += stack.shift();
  20109. lineTo(x, y);
  20110. }
  20111. break;
  20112. case 8: // rrcurveto
  20113. while (stack.length > 0) {
  20114. xa = x + stack.shift(); ya = y + stack.shift();
  20115. xb = xa + stack.shift(); yb = ya + stack.shift();
  20116. x = xb + stack.shift(); y = yb + stack.shift();
  20117. bezierCurveTo(xa, ya, xb, yb, x, y);
  20118. }
  20119. break;
  20120. case 10: // callsubr
  20121. n = stack.pop() + font.subrsBias;
  20122. subrCode = font.subrs[n];
  20123. if (subrCode) {
  20124. parse(subrCode);
  20125. }
  20126. break;
  20127. case 11: // return
  20128. return;
  20129. case 12:
  20130. v = code[i++];
  20131. switch (v) {
  20132. case 34: // flex
  20133. xa = x + stack.shift();
  20134. xb = xa + stack.shift(); y1 = y + stack.shift();
  20135. x = xb + stack.shift();
  20136. bezierCurveTo(xa, y, xb, y1, x, y1);
  20137. xa = x + stack.shift();
  20138. xb = xa + stack.shift();
  20139. x = xb + stack.shift();
  20140. bezierCurveTo(xa, y1, xb, y, x, y);
  20141. break;
  20142. case 35: // flex
  20143. xa = x + stack.shift(); ya = y + stack.shift();
  20144. xb = xa + stack.shift(); yb = ya + stack.shift();
  20145. x = xb + stack.shift(); y = yb + stack.shift();
  20146. bezierCurveTo(xa, ya, xb, yb, x, y);
  20147. xa = x + stack.shift(); ya = y + stack.shift();
  20148. xb = xa + stack.shift(); yb = ya + stack.shift();
  20149. x = xb + stack.shift(); y = yb + stack.shift();
  20150. bezierCurveTo(xa, ya, xb, yb, x, y);
  20151. stack.pop(); // fd
  20152. break;
  20153. case 36: // hflex1
  20154. xa = x + stack.shift(); y1 = y + stack.shift();
  20155. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20156. x = xb + stack.shift();
  20157. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20158. xa = x + stack.shift();
  20159. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20160. x = xb + stack.shift();
  20161. bezierCurveTo(xa, y2, xb, y3, x, y);
  20162. break;
  20163. case 37: // flex1
  20164. var x0 = x, y0 = y;
  20165. xa = x + stack.shift(); ya = y + stack.shift();
  20166. xb = xa + stack.shift(); yb = ya + stack.shift();
  20167. x = xb + stack.shift(); y = yb + stack.shift();
  20168. bezierCurveTo(xa, ya, xb, yb, x, y);
  20169. xa = x + stack.shift(); ya = y + stack.shift();
  20170. xb = xa + stack.shift(); yb = ya + stack.shift();
  20171. x = xb; y = yb;
  20172. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20173. x += stack.shift();
  20174. } else {
  20175. y += stack.shift();
  20176. }
  20177. bezierCurveTo(xa, ya, xb, yb, x, y);
  20178. break;
  20179. default:
  20180. error('unknown operator: 12 ' + v);
  20181. }
  20182. break;
  20183. case 14: // endchar
  20184. if (stack.length >= 4) {
  20185. var achar = stack.pop();
  20186. var bchar = stack.pop();
  20187. y = stack.pop();
  20188. x = stack.pop();
  20189. js.push('c.save();');
  20190. js.push('c.translate('+ x + ',' + y + ');');
  20191. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20192. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20193. compileCharString(font.glyphs[gid], js, font);
  20194. js.push('c.restore();');
  20195. gid = lookupCmap(font.cmap, String.fromCharCode(
  20196. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20197. compileCharString(font.glyphs[gid], js, font);
  20198. }
  20199. return;
  20200. case 18: // hstemhm
  20201. stems += stack.length >> 1;
  20202. stackClean = true;
  20203. break;
  20204. case 19: // hintmask
  20205. stems += stack.length >> 1;
  20206. i += (stems + 7) >> 3;
  20207. stackClean = true;
  20208. break;
  20209. case 20: // cntrmask
  20210. stems += stack.length >> 1;
  20211. i += (stems + 7) >> 3;
  20212. stackClean = true;
  20213. break;
  20214. case 21: // rmoveto
  20215. y += stack.pop();
  20216. x += stack.pop();
  20217. moveTo(x, y);
  20218. stackClean = true;
  20219. break;
  20220. case 22: // hmoveto
  20221. x += stack.pop();
  20222. moveTo(x, y);
  20223. stackClean = true;
  20224. break;
  20225. case 23: // vstemhm
  20226. stems += stack.length >> 1;
  20227. stackClean = true;
  20228. break;
  20229. case 24: // rcurveline
  20230. while (stack.length > 2) {
  20231. xa = x + stack.shift(); ya = y + stack.shift();
  20232. xb = xa + stack.shift(); yb = ya + stack.shift();
  20233. x = xb + stack.shift(); y = yb + stack.shift();
  20234. bezierCurveTo(xa, ya, xb, yb, x, y);
  20235. }
  20236. x += stack.shift();
  20237. y += stack.shift();
  20238. lineTo(x, y);
  20239. break;
  20240. case 25: // rlinecurve
  20241. while (stack.length > 6) {
  20242. x += stack.shift();
  20243. y += stack.shift();
  20244. lineTo(x, y);
  20245. }
  20246. xa = x + stack.shift(); ya = y + stack.shift();
  20247. xb = xa + stack.shift(); yb = ya + stack.shift();
  20248. x = xb + stack.shift(); y = yb + stack.shift();
  20249. bezierCurveTo(xa, ya, xb, yb, x, y);
  20250. break;
  20251. case 26: // vvcurveto
  20252. if (stack.length % 2) {
  20253. x += stack.shift();
  20254. }
  20255. while (stack.length > 0) {
  20256. xa = x; ya = y + stack.shift();
  20257. xb = xa + stack.shift(); yb = ya + stack.shift();
  20258. x = xb; y = yb + stack.shift();
  20259. bezierCurveTo(xa, ya, xb, yb, x, y);
  20260. }
  20261. break;
  20262. case 27: // hhcurveto
  20263. if (stack.length % 2) {
  20264. y += stack.shift();
  20265. }
  20266. while (stack.length > 0) {
  20267. xa = x + stack.shift(); ya = y;
  20268. xb = xa + stack.shift(); yb = ya + stack.shift();
  20269. x = xb + stack.shift(); y = yb;
  20270. bezierCurveTo(xa, ya, xb, yb, x, y);
  20271. }
  20272. break;
  20273. case 28:
  20274. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20275. i += 2;
  20276. break;
  20277. case 29: // callgsubr
  20278. n = stack.pop() + font.gsubrsBias;
  20279. subrCode = font.gsubrs[n];
  20280. if (subrCode) {
  20281. parse(subrCode);
  20282. }
  20283. break;
  20284. case 30: // vhcurveto
  20285. while (stack.length > 0) {
  20286. xa = x; ya = y + stack.shift();
  20287. xb = xa + stack.shift(); yb = ya + stack.shift();
  20288. x = xb + stack.shift();
  20289. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20290. bezierCurveTo(xa, ya, xb, yb, x, y);
  20291. if (stack.length === 0) {
  20292. break;
  20293. }
  20294. xa = x + stack.shift(); ya = y;
  20295. xb = xa + stack.shift(); yb = ya + stack.shift();
  20296. y = yb + stack.shift();
  20297. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20298. bezierCurveTo(xa, ya, xb, yb, x, y);
  20299. }
  20300. break;
  20301. case 31: // hvcurveto
  20302. while (stack.length > 0) {
  20303. xa = x + stack.shift(); ya = y;
  20304. xb = xa + stack.shift(); yb = ya + stack.shift();
  20305. y = yb + stack.shift();
  20306. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20307. bezierCurveTo(xa, ya, xb, yb, x, y);
  20308. if (stack.length === 0) {
  20309. break;
  20310. }
  20311. xa = x; ya = y + stack.shift();
  20312. xb = xa + stack.shift(); yb = ya + stack.shift();
  20313. x = xb + stack.shift();
  20314. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20315. bezierCurveTo(xa, ya, xb, yb, x, y);
  20316. }
  20317. break;
  20318. default:
  20319. if (v < 32) {
  20320. error('unknown operator: ' + v);
  20321. }
  20322. if (v < 247) {
  20323. stack.push(v - 139);
  20324. } else if (v < 251) {
  20325. stack.push((v - 247) * 256 + code[i++] + 108);
  20326. } else if (v < 255) {
  20327. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20328. } else {
  20329. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20330. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20331. i += 4;
  20332. }
  20333. break;
  20334. }
  20335. if (stackClean) {
  20336. stack.length = 0;
  20337. }
  20338. }
  20339. }
  20340. parse(code);
  20341. }
  20342. var noop = '';
  20343. function CompiledFont(fontMatrix) {
  20344. this.compiledGlyphs = {};
  20345. this.fontMatrix = fontMatrix;
  20346. }
  20347. CompiledFont.prototype = {
  20348. getPathJs: function (unicode) {
  20349. var gid = lookupCmap(this.cmap, unicode);
  20350. var fn = this.compiledGlyphs[gid];
  20351. if (!fn) {
  20352. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20353. }
  20354. return fn;
  20355. },
  20356. compileGlyph: function (code) {
  20357. if (!code || code.length === 0 || code[0] === 14) {
  20358. return noop;
  20359. }
  20360. var js = [];
  20361. js.push('c.save();');
  20362. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20363. js.push('c.scale(size, -size);');
  20364. this.compileGlyphImpl(code, js);
  20365. js.push('c.restore();');
  20366. return js.join('\n');
  20367. },
  20368. compileGlyphImpl: function () {
  20369. error('Children classes should implement this.');
  20370. },
  20371. hasBuiltPath: function (unicode) {
  20372. var gid = lookupCmap(this.cmap, unicode);
  20373. return gid in this.compiledGlyphs;
  20374. }
  20375. };
  20376. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20377. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20378. CompiledFont.call(this, fontMatrix);
  20379. this.glyphs = glyphs;
  20380. this.cmap = cmap;
  20381. this.compiledGlyphs = [];
  20382. }
  20383. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20384. compileGlyphImpl: function (code, js) {
  20385. compileGlyf(code, js, this);
  20386. }
  20387. });
  20388. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20389. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20390. CompiledFont.call(this, fontMatrix);
  20391. this.glyphs = cffInfo.glyphs;
  20392. this.gsubrs = cffInfo.gsubrs || [];
  20393. this.subrs = cffInfo.subrs || [];
  20394. this.cmap = cmap;
  20395. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20396. this.compiledGlyphs = [];
  20397. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20398. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20399. this.subrsBias = (this.subrs.length < 1240 ?
  20400. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20401. }
  20402. Util.inherit(Type2Compiled, CompiledFont, {
  20403. compileGlyphImpl: function (code, js) {
  20404. compileCharString(code, js, this);
  20405. }
  20406. });
  20407. return {
  20408. create: function FontRendererFactory_create(font) {
  20409. var data = new Uint8Array(font.data);
  20410. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20411. var numTables = getUshort(data, 4);
  20412. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20413. var tag = bytesToString(data.subarray(p, p + 4));
  20414. var offset = getLong(data, p + 8);
  20415. var length = getLong(data, p + 12);
  20416. switch (tag) {
  20417. case 'cmap':
  20418. cmap = parseCmap(data, offset, offset + length);
  20419. break;
  20420. case 'glyf':
  20421. glyf = data.subarray(offset, offset + length);
  20422. break;
  20423. case 'loca':
  20424. loca = data.subarray(offset, offset + length);
  20425. break;
  20426. case 'head':
  20427. unitsPerEm = getUshort(data, offset + 18);
  20428. indexToLocFormat = getUshort(data, offset + 50);
  20429. break;
  20430. case 'CFF ':
  20431. cff = parseCff(data, offset, offset + length);
  20432. break;
  20433. }
  20434. }
  20435. if (glyf) {
  20436. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20437. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20438. return new TrueTypeCompiled(
  20439. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20440. } else {
  20441. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20442. }
  20443. }
  20444. };
  20445. })();
  20446. var GlyphsUnicode = {
  20447. A: 0x0041,
  20448. AE: 0x00C6,
  20449. AEacute: 0x01FC,
  20450. AEmacron: 0x01E2,
  20451. AEsmall: 0xF7E6,
  20452. Aacute: 0x00C1,
  20453. Aacutesmall: 0xF7E1,
  20454. Abreve: 0x0102,
  20455. Abreveacute: 0x1EAE,
  20456. Abrevecyrillic: 0x04D0,
  20457. Abrevedotbelow: 0x1EB6,
  20458. Abrevegrave: 0x1EB0,
  20459. Abrevehookabove: 0x1EB2,
  20460. Abrevetilde: 0x1EB4,
  20461. Acaron: 0x01CD,
  20462. Acircle: 0x24B6,
  20463. Acircumflex: 0x00C2,
  20464. Acircumflexacute: 0x1EA4,
  20465. Acircumflexdotbelow: 0x1EAC,
  20466. Acircumflexgrave: 0x1EA6,
  20467. Acircumflexhookabove: 0x1EA8,
  20468. Acircumflexsmall: 0xF7E2,
  20469. Acircumflextilde: 0x1EAA,
  20470. Acute: 0xF6C9,
  20471. Acutesmall: 0xF7B4,
  20472. Acyrillic: 0x0410,
  20473. Adblgrave: 0x0200,
  20474. Adieresis: 0x00C4,
  20475. Adieresiscyrillic: 0x04D2,
  20476. Adieresismacron: 0x01DE,
  20477. Adieresissmall: 0xF7E4,
  20478. Adotbelow: 0x1EA0,
  20479. Adotmacron: 0x01E0,
  20480. Agrave: 0x00C0,
  20481. Agravesmall: 0xF7E0,
  20482. Ahookabove: 0x1EA2,
  20483. Aiecyrillic: 0x04D4,
  20484. Ainvertedbreve: 0x0202,
  20485. Alpha: 0x0391,
  20486. Alphatonos: 0x0386,
  20487. Amacron: 0x0100,
  20488. Amonospace: 0xFF21,
  20489. Aogonek: 0x0104,
  20490. Aring: 0x00C5,
  20491. Aringacute: 0x01FA,
  20492. Aringbelow: 0x1E00,
  20493. Aringsmall: 0xF7E5,
  20494. Asmall: 0xF761,
  20495. Atilde: 0x00C3,
  20496. Atildesmall: 0xF7E3,
  20497. Aybarmenian: 0x0531,
  20498. B: 0x0042,
  20499. Bcircle: 0x24B7,
  20500. Bdotaccent: 0x1E02,
  20501. Bdotbelow: 0x1E04,
  20502. Becyrillic: 0x0411,
  20503. Benarmenian: 0x0532,
  20504. Beta: 0x0392,
  20505. Bhook: 0x0181,
  20506. Blinebelow: 0x1E06,
  20507. Bmonospace: 0xFF22,
  20508. Brevesmall: 0xF6F4,
  20509. Bsmall: 0xF762,
  20510. Btopbar: 0x0182,
  20511. C: 0x0043,
  20512. Caarmenian: 0x053E,
  20513. Cacute: 0x0106,
  20514. Caron: 0xF6CA,
  20515. Caronsmall: 0xF6F5,
  20516. Ccaron: 0x010C,
  20517. Ccedilla: 0x00C7,
  20518. Ccedillaacute: 0x1E08,
  20519. Ccedillasmall: 0xF7E7,
  20520. Ccircle: 0x24B8,
  20521. Ccircumflex: 0x0108,
  20522. Cdot: 0x010A,
  20523. Cdotaccent: 0x010A,
  20524. Cedillasmall: 0xF7B8,
  20525. Chaarmenian: 0x0549,
  20526. Cheabkhasiancyrillic: 0x04BC,
  20527. Checyrillic: 0x0427,
  20528. Chedescenderabkhasiancyrillic: 0x04BE,
  20529. Chedescendercyrillic: 0x04B6,
  20530. Chedieresiscyrillic: 0x04F4,
  20531. Cheharmenian: 0x0543,
  20532. Chekhakassiancyrillic: 0x04CB,
  20533. Cheverticalstrokecyrillic: 0x04B8,
  20534. Chi: 0x03A7,
  20535. Chook: 0x0187,
  20536. Circumflexsmall: 0xF6F6,
  20537. Cmonospace: 0xFF23,
  20538. Coarmenian: 0x0551,
  20539. Csmall: 0xF763,
  20540. D: 0x0044,
  20541. DZ: 0x01F1,
  20542. DZcaron: 0x01C4,
  20543. Daarmenian: 0x0534,
  20544. Dafrican: 0x0189,
  20545. Dcaron: 0x010E,
  20546. Dcedilla: 0x1E10,
  20547. Dcircle: 0x24B9,
  20548. Dcircumflexbelow: 0x1E12,
  20549. Dcroat: 0x0110,
  20550. Ddotaccent: 0x1E0A,
  20551. Ddotbelow: 0x1E0C,
  20552. Decyrillic: 0x0414,
  20553. Deicoptic: 0x03EE,
  20554. Delta: 0x2206,
  20555. Deltagreek: 0x0394,
  20556. Dhook: 0x018A,
  20557. Dieresis: 0xF6CB,
  20558. DieresisAcute: 0xF6CC,
  20559. DieresisGrave: 0xF6CD,
  20560. Dieresissmall: 0xF7A8,
  20561. Digammagreek: 0x03DC,
  20562. Djecyrillic: 0x0402,
  20563. Dlinebelow: 0x1E0E,
  20564. Dmonospace: 0xFF24,
  20565. Dotaccentsmall: 0xF6F7,
  20566. Dslash: 0x0110,
  20567. Dsmall: 0xF764,
  20568. Dtopbar: 0x018B,
  20569. Dz: 0x01F2,
  20570. Dzcaron: 0x01C5,
  20571. Dzeabkhasiancyrillic: 0x04E0,
  20572. Dzecyrillic: 0x0405,
  20573. Dzhecyrillic: 0x040F,
  20574. E: 0x0045,
  20575. Eacute: 0x00C9,
  20576. Eacutesmall: 0xF7E9,
  20577. Ebreve: 0x0114,
  20578. Ecaron: 0x011A,
  20579. Ecedillabreve: 0x1E1C,
  20580. Echarmenian: 0x0535,
  20581. Ecircle: 0x24BA,
  20582. Ecircumflex: 0x00CA,
  20583. Ecircumflexacute: 0x1EBE,
  20584. Ecircumflexbelow: 0x1E18,
  20585. Ecircumflexdotbelow: 0x1EC6,
  20586. Ecircumflexgrave: 0x1EC0,
  20587. Ecircumflexhookabove: 0x1EC2,
  20588. Ecircumflexsmall: 0xF7EA,
  20589. Ecircumflextilde: 0x1EC4,
  20590. Ecyrillic: 0x0404,
  20591. Edblgrave: 0x0204,
  20592. Edieresis: 0x00CB,
  20593. Edieresissmall: 0xF7EB,
  20594. Edot: 0x0116,
  20595. Edotaccent: 0x0116,
  20596. Edotbelow: 0x1EB8,
  20597. Efcyrillic: 0x0424,
  20598. Egrave: 0x00C8,
  20599. Egravesmall: 0xF7E8,
  20600. Eharmenian: 0x0537,
  20601. Ehookabove: 0x1EBA,
  20602. Eightroman: 0x2167,
  20603. Einvertedbreve: 0x0206,
  20604. Eiotifiedcyrillic: 0x0464,
  20605. Elcyrillic: 0x041B,
  20606. Elevenroman: 0x216A,
  20607. Emacron: 0x0112,
  20608. Emacronacute: 0x1E16,
  20609. Emacrongrave: 0x1E14,
  20610. Emcyrillic: 0x041C,
  20611. Emonospace: 0xFF25,
  20612. Encyrillic: 0x041D,
  20613. Endescendercyrillic: 0x04A2,
  20614. Eng: 0x014A,
  20615. Enghecyrillic: 0x04A4,
  20616. Enhookcyrillic: 0x04C7,
  20617. Eogonek: 0x0118,
  20618. Eopen: 0x0190,
  20619. Epsilon: 0x0395,
  20620. Epsilontonos: 0x0388,
  20621. Ercyrillic: 0x0420,
  20622. Ereversed: 0x018E,
  20623. Ereversedcyrillic: 0x042D,
  20624. Escyrillic: 0x0421,
  20625. Esdescendercyrillic: 0x04AA,
  20626. Esh: 0x01A9,
  20627. Esmall: 0xF765,
  20628. Eta: 0x0397,
  20629. Etarmenian: 0x0538,
  20630. Etatonos: 0x0389,
  20631. Eth: 0x00D0,
  20632. Ethsmall: 0xF7F0,
  20633. Etilde: 0x1EBC,
  20634. Etildebelow: 0x1E1A,
  20635. Euro: 0x20AC,
  20636. Ezh: 0x01B7,
  20637. Ezhcaron: 0x01EE,
  20638. Ezhreversed: 0x01B8,
  20639. F: 0x0046,
  20640. Fcircle: 0x24BB,
  20641. Fdotaccent: 0x1E1E,
  20642. Feharmenian: 0x0556,
  20643. Feicoptic: 0x03E4,
  20644. Fhook: 0x0191,
  20645. Fitacyrillic: 0x0472,
  20646. Fiveroman: 0x2164,
  20647. Fmonospace: 0xFF26,
  20648. Fourroman: 0x2163,
  20649. Fsmall: 0xF766,
  20650. G: 0x0047,
  20651. GBsquare: 0x3387,
  20652. Gacute: 0x01F4,
  20653. Gamma: 0x0393,
  20654. Gammaafrican: 0x0194,
  20655. Gangiacoptic: 0x03EA,
  20656. Gbreve: 0x011E,
  20657. Gcaron: 0x01E6,
  20658. Gcedilla: 0x0122,
  20659. Gcircle: 0x24BC,
  20660. Gcircumflex: 0x011C,
  20661. Gcommaaccent: 0x0122,
  20662. Gdot: 0x0120,
  20663. Gdotaccent: 0x0120,
  20664. Gecyrillic: 0x0413,
  20665. Ghadarmenian: 0x0542,
  20666. Ghemiddlehookcyrillic: 0x0494,
  20667. Ghestrokecyrillic: 0x0492,
  20668. Gheupturncyrillic: 0x0490,
  20669. Ghook: 0x0193,
  20670. Gimarmenian: 0x0533,
  20671. Gjecyrillic: 0x0403,
  20672. Gmacron: 0x1E20,
  20673. Gmonospace: 0xFF27,
  20674. Grave: 0xF6CE,
  20675. Gravesmall: 0xF760,
  20676. Gsmall: 0xF767,
  20677. Gsmallhook: 0x029B,
  20678. Gstroke: 0x01E4,
  20679. H: 0x0048,
  20680. H18533: 0x25CF,
  20681. H18543: 0x25AA,
  20682. H18551: 0x25AB,
  20683. H22073: 0x25A1,
  20684. HPsquare: 0x33CB,
  20685. Haabkhasiancyrillic: 0x04A8,
  20686. Hadescendercyrillic: 0x04B2,
  20687. Hardsigncyrillic: 0x042A,
  20688. Hbar: 0x0126,
  20689. Hbrevebelow: 0x1E2A,
  20690. Hcedilla: 0x1E28,
  20691. Hcircle: 0x24BD,
  20692. Hcircumflex: 0x0124,
  20693. Hdieresis: 0x1E26,
  20694. Hdotaccent: 0x1E22,
  20695. Hdotbelow: 0x1E24,
  20696. Hmonospace: 0xFF28,
  20697. Hoarmenian: 0x0540,
  20698. Horicoptic: 0x03E8,
  20699. Hsmall: 0xF768,
  20700. Hungarumlaut: 0xF6CF,
  20701. Hungarumlautsmall: 0xF6F8,
  20702. Hzsquare: 0x3390,
  20703. I: 0x0049,
  20704. IAcyrillic: 0x042F,
  20705. IJ: 0x0132,
  20706. IUcyrillic: 0x042E,
  20707. Iacute: 0x00CD,
  20708. Iacutesmall: 0xF7ED,
  20709. Ibreve: 0x012C,
  20710. Icaron: 0x01CF,
  20711. Icircle: 0x24BE,
  20712. Icircumflex: 0x00CE,
  20713. Icircumflexsmall: 0xF7EE,
  20714. Icyrillic: 0x0406,
  20715. Idblgrave: 0x0208,
  20716. Idieresis: 0x00CF,
  20717. Idieresisacute: 0x1E2E,
  20718. Idieresiscyrillic: 0x04E4,
  20719. Idieresissmall: 0xF7EF,
  20720. Idot: 0x0130,
  20721. Idotaccent: 0x0130,
  20722. Idotbelow: 0x1ECA,
  20723. Iebrevecyrillic: 0x04D6,
  20724. Iecyrillic: 0x0415,
  20725. Ifraktur: 0x2111,
  20726. Igrave: 0x00CC,
  20727. Igravesmall: 0xF7EC,
  20728. Ihookabove: 0x1EC8,
  20729. Iicyrillic: 0x0418,
  20730. Iinvertedbreve: 0x020A,
  20731. Iishortcyrillic: 0x0419,
  20732. Imacron: 0x012A,
  20733. Imacroncyrillic: 0x04E2,
  20734. Imonospace: 0xFF29,
  20735. Iniarmenian: 0x053B,
  20736. Iocyrillic: 0x0401,
  20737. Iogonek: 0x012E,
  20738. Iota: 0x0399,
  20739. Iotaafrican: 0x0196,
  20740. Iotadieresis: 0x03AA,
  20741. Iotatonos: 0x038A,
  20742. Ismall: 0xF769,
  20743. Istroke: 0x0197,
  20744. Itilde: 0x0128,
  20745. Itildebelow: 0x1E2C,
  20746. Izhitsacyrillic: 0x0474,
  20747. Izhitsadblgravecyrillic: 0x0476,
  20748. J: 0x004A,
  20749. Jaarmenian: 0x0541,
  20750. Jcircle: 0x24BF,
  20751. Jcircumflex: 0x0134,
  20752. Jecyrillic: 0x0408,
  20753. Jheharmenian: 0x054B,
  20754. Jmonospace: 0xFF2A,
  20755. Jsmall: 0xF76A,
  20756. K: 0x004B,
  20757. KBsquare: 0x3385,
  20758. KKsquare: 0x33CD,
  20759. Kabashkircyrillic: 0x04A0,
  20760. Kacute: 0x1E30,
  20761. Kacyrillic: 0x041A,
  20762. Kadescendercyrillic: 0x049A,
  20763. Kahookcyrillic: 0x04C3,
  20764. Kappa: 0x039A,
  20765. Kastrokecyrillic: 0x049E,
  20766. Kaverticalstrokecyrillic: 0x049C,
  20767. Kcaron: 0x01E8,
  20768. Kcedilla: 0x0136,
  20769. Kcircle: 0x24C0,
  20770. Kcommaaccent: 0x0136,
  20771. Kdotbelow: 0x1E32,
  20772. Keharmenian: 0x0554,
  20773. Kenarmenian: 0x053F,
  20774. Khacyrillic: 0x0425,
  20775. Kheicoptic: 0x03E6,
  20776. Khook: 0x0198,
  20777. Kjecyrillic: 0x040C,
  20778. Klinebelow: 0x1E34,
  20779. Kmonospace: 0xFF2B,
  20780. Koppacyrillic: 0x0480,
  20781. Koppagreek: 0x03DE,
  20782. Ksicyrillic: 0x046E,
  20783. Ksmall: 0xF76B,
  20784. L: 0x004C,
  20785. LJ: 0x01C7,
  20786. LL: 0xF6BF,
  20787. Lacute: 0x0139,
  20788. Lambda: 0x039B,
  20789. Lcaron: 0x013D,
  20790. Lcedilla: 0x013B,
  20791. Lcircle: 0x24C1,
  20792. Lcircumflexbelow: 0x1E3C,
  20793. Lcommaaccent: 0x013B,
  20794. Ldot: 0x013F,
  20795. Ldotaccent: 0x013F,
  20796. Ldotbelow: 0x1E36,
  20797. Ldotbelowmacron: 0x1E38,
  20798. Liwnarmenian: 0x053C,
  20799. Lj: 0x01C8,
  20800. Ljecyrillic: 0x0409,
  20801. Llinebelow: 0x1E3A,
  20802. Lmonospace: 0xFF2C,
  20803. Lslash: 0x0141,
  20804. Lslashsmall: 0xF6F9,
  20805. Lsmall: 0xF76C,
  20806. M: 0x004D,
  20807. MBsquare: 0x3386,
  20808. Macron: 0xF6D0,
  20809. Macronsmall: 0xF7AF,
  20810. Macute: 0x1E3E,
  20811. Mcircle: 0x24C2,
  20812. Mdotaccent: 0x1E40,
  20813. Mdotbelow: 0x1E42,
  20814. Menarmenian: 0x0544,
  20815. Mmonospace: 0xFF2D,
  20816. Msmall: 0xF76D,
  20817. Mturned: 0x019C,
  20818. Mu: 0x039C,
  20819. N: 0x004E,
  20820. NJ: 0x01CA,
  20821. Nacute: 0x0143,
  20822. Ncaron: 0x0147,
  20823. Ncedilla: 0x0145,
  20824. Ncircle: 0x24C3,
  20825. Ncircumflexbelow: 0x1E4A,
  20826. Ncommaaccent: 0x0145,
  20827. Ndotaccent: 0x1E44,
  20828. Ndotbelow: 0x1E46,
  20829. Nhookleft: 0x019D,
  20830. Nineroman: 0x2168,
  20831. Nj: 0x01CB,
  20832. Njecyrillic: 0x040A,
  20833. Nlinebelow: 0x1E48,
  20834. Nmonospace: 0xFF2E,
  20835. Nowarmenian: 0x0546,
  20836. Nsmall: 0xF76E,
  20837. Ntilde: 0x00D1,
  20838. Ntildesmall: 0xF7F1,
  20839. Nu: 0x039D,
  20840. O: 0x004F,
  20841. OE: 0x0152,
  20842. OEsmall: 0xF6FA,
  20843. Oacute: 0x00D3,
  20844. Oacutesmall: 0xF7F3,
  20845. Obarredcyrillic: 0x04E8,
  20846. Obarreddieresiscyrillic: 0x04EA,
  20847. Obreve: 0x014E,
  20848. Ocaron: 0x01D1,
  20849. Ocenteredtilde: 0x019F,
  20850. Ocircle: 0x24C4,
  20851. Ocircumflex: 0x00D4,
  20852. Ocircumflexacute: 0x1ED0,
  20853. Ocircumflexdotbelow: 0x1ED8,
  20854. Ocircumflexgrave: 0x1ED2,
  20855. Ocircumflexhookabove: 0x1ED4,
  20856. Ocircumflexsmall: 0xF7F4,
  20857. Ocircumflextilde: 0x1ED6,
  20858. Ocyrillic: 0x041E,
  20859. Odblacute: 0x0150,
  20860. Odblgrave: 0x020C,
  20861. Odieresis: 0x00D6,
  20862. Odieresiscyrillic: 0x04E6,
  20863. Odieresissmall: 0xF7F6,
  20864. Odotbelow: 0x1ECC,
  20865. Ogoneksmall: 0xF6FB,
  20866. Ograve: 0x00D2,
  20867. Ogravesmall: 0xF7F2,
  20868. Oharmenian: 0x0555,
  20869. Ohm: 0x2126,
  20870. Ohookabove: 0x1ECE,
  20871. Ohorn: 0x01A0,
  20872. Ohornacute: 0x1EDA,
  20873. Ohorndotbelow: 0x1EE2,
  20874. Ohorngrave: 0x1EDC,
  20875. Ohornhookabove: 0x1EDE,
  20876. Ohorntilde: 0x1EE0,
  20877. Ohungarumlaut: 0x0150,
  20878. Oi: 0x01A2,
  20879. Oinvertedbreve: 0x020E,
  20880. Omacron: 0x014C,
  20881. Omacronacute: 0x1E52,
  20882. Omacrongrave: 0x1E50,
  20883. Omega: 0x2126,
  20884. Omegacyrillic: 0x0460,
  20885. Omegagreek: 0x03A9,
  20886. Omegaroundcyrillic: 0x047A,
  20887. Omegatitlocyrillic: 0x047C,
  20888. Omegatonos: 0x038F,
  20889. Omicron: 0x039F,
  20890. Omicrontonos: 0x038C,
  20891. Omonospace: 0xFF2F,
  20892. Oneroman: 0x2160,
  20893. Oogonek: 0x01EA,
  20894. Oogonekmacron: 0x01EC,
  20895. Oopen: 0x0186,
  20896. Oslash: 0x00D8,
  20897. Oslashacute: 0x01FE,
  20898. Oslashsmall: 0xF7F8,
  20899. Osmall: 0xF76F,
  20900. Ostrokeacute: 0x01FE,
  20901. Otcyrillic: 0x047E,
  20902. Otilde: 0x00D5,
  20903. Otildeacute: 0x1E4C,
  20904. Otildedieresis: 0x1E4E,
  20905. Otildesmall: 0xF7F5,
  20906. P: 0x0050,
  20907. Pacute: 0x1E54,
  20908. Pcircle: 0x24C5,
  20909. Pdotaccent: 0x1E56,
  20910. Pecyrillic: 0x041F,
  20911. Peharmenian: 0x054A,
  20912. Pemiddlehookcyrillic: 0x04A6,
  20913. Phi: 0x03A6,
  20914. Phook: 0x01A4,
  20915. Pi: 0x03A0,
  20916. Piwrarmenian: 0x0553,
  20917. Pmonospace: 0xFF30,
  20918. Psi: 0x03A8,
  20919. Psicyrillic: 0x0470,
  20920. Psmall: 0xF770,
  20921. Q: 0x0051,
  20922. Qcircle: 0x24C6,
  20923. Qmonospace: 0xFF31,
  20924. Qsmall: 0xF771,
  20925. R: 0x0052,
  20926. Raarmenian: 0x054C,
  20927. Racute: 0x0154,
  20928. Rcaron: 0x0158,
  20929. Rcedilla: 0x0156,
  20930. Rcircle: 0x24C7,
  20931. Rcommaaccent: 0x0156,
  20932. Rdblgrave: 0x0210,
  20933. Rdotaccent: 0x1E58,
  20934. Rdotbelow: 0x1E5A,
  20935. Rdotbelowmacron: 0x1E5C,
  20936. Reharmenian: 0x0550,
  20937. Rfraktur: 0x211C,
  20938. Rho: 0x03A1,
  20939. Ringsmall: 0xF6FC,
  20940. Rinvertedbreve: 0x0212,
  20941. Rlinebelow: 0x1E5E,
  20942. Rmonospace: 0xFF32,
  20943. Rsmall: 0xF772,
  20944. Rsmallinverted: 0x0281,
  20945. Rsmallinvertedsuperior: 0x02B6,
  20946. S: 0x0053,
  20947. SF010000: 0x250C,
  20948. SF020000: 0x2514,
  20949. SF030000: 0x2510,
  20950. SF040000: 0x2518,
  20951. SF050000: 0x253C,
  20952. SF060000: 0x252C,
  20953. SF070000: 0x2534,
  20954. SF080000: 0x251C,
  20955. SF090000: 0x2524,
  20956. SF100000: 0x2500,
  20957. SF110000: 0x2502,
  20958. SF190000: 0x2561,
  20959. SF200000: 0x2562,
  20960. SF210000: 0x2556,
  20961. SF220000: 0x2555,
  20962. SF230000: 0x2563,
  20963. SF240000: 0x2551,
  20964. SF250000: 0x2557,
  20965. SF260000: 0x255D,
  20966. SF270000: 0x255C,
  20967. SF280000: 0x255B,
  20968. SF360000: 0x255E,
  20969. SF370000: 0x255F,
  20970. SF380000: 0x255A,
  20971. SF390000: 0x2554,
  20972. SF400000: 0x2569,
  20973. SF410000: 0x2566,
  20974. SF420000: 0x2560,
  20975. SF430000: 0x2550,
  20976. SF440000: 0x256C,
  20977. SF450000: 0x2567,
  20978. SF460000: 0x2568,
  20979. SF470000: 0x2564,
  20980. SF480000: 0x2565,
  20981. SF490000: 0x2559,
  20982. SF500000: 0x2558,
  20983. SF510000: 0x2552,
  20984. SF520000: 0x2553,
  20985. SF530000: 0x256B,
  20986. SF540000: 0x256A,
  20987. Sacute: 0x015A,
  20988. Sacutedotaccent: 0x1E64,
  20989. Sampigreek: 0x03E0,
  20990. Scaron: 0x0160,
  20991. Scarondotaccent: 0x1E66,
  20992. Scaronsmall: 0xF6FD,
  20993. Scedilla: 0x015E,
  20994. Schwa: 0x018F,
  20995. Schwacyrillic: 0x04D8,
  20996. Schwadieresiscyrillic: 0x04DA,
  20997. Scircle: 0x24C8,
  20998. Scircumflex: 0x015C,
  20999. Scommaaccent: 0x0218,
  21000. Sdotaccent: 0x1E60,
  21001. Sdotbelow: 0x1E62,
  21002. Sdotbelowdotaccent: 0x1E68,
  21003. Seharmenian: 0x054D,
  21004. Sevenroman: 0x2166,
  21005. Shaarmenian: 0x0547,
  21006. Shacyrillic: 0x0428,
  21007. Shchacyrillic: 0x0429,
  21008. Sheicoptic: 0x03E2,
  21009. Shhacyrillic: 0x04BA,
  21010. Shimacoptic: 0x03EC,
  21011. Sigma: 0x03A3,
  21012. Sixroman: 0x2165,
  21013. Smonospace: 0xFF33,
  21014. Softsigncyrillic: 0x042C,
  21015. Ssmall: 0xF773,
  21016. Stigmagreek: 0x03DA,
  21017. T: 0x0054,
  21018. Tau: 0x03A4,
  21019. Tbar: 0x0166,
  21020. Tcaron: 0x0164,
  21021. Tcedilla: 0x0162,
  21022. Tcircle: 0x24C9,
  21023. Tcircumflexbelow: 0x1E70,
  21024. Tcommaaccent: 0x0162,
  21025. Tdotaccent: 0x1E6A,
  21026. Tdotbelow: 0x1E6C,
  21027. Tecyrillic: 0x0422,
  21028. Tedescendercyrillic: 0x04AC,
  21029. Tenroman: 0x2169,
  21030. Tetsecyrillic: 0x04B4,
  21031. Theta: 0x0398,
  21032. Thook: 0x01AC,
  21033. Thorn: 0x00DE,
  21034. Thornsmall: 0xF7FE,
  21035. Threeroman: 0x2162,
  21036. Tildesmall: 0xF6FE,
  21037. Tiwnarmenian: 0x054F,
  21038. Tlinebelow: 0x1E6E,
  21039. Tmonospace: 0xFF34,
  21040. Toarmenian: 0x0539,
  21041. Tonefive: 0x01BC,
  21042. Tonesix: 0x0184,
  21043. Tonetwo: 0x01A7,
  21044. Tretroflexhook: 0x01AE,
  21045. Tsecyrillic: 0x0426,
  21046. Tshecyrillic: 0x040B,
  21047. Tsmall: 0xF774,
  21048. Twelveroman: 0x216B,
  21049. Tworoman: 0x2161,
  21050. U: 0x0055,
  21051. Uacute: 0x00DA,
  21052. Uacutesmall: 0xF7FA,
  21053. Ubreve: 0x016C,
  21054. Ucaron: 0x01D3,
  21055. Ucircle: 0x24CA,
  21056. Ucircumflex: 0x00DB,
  21057. Ucircumflexbelow: 0x1E76,
  21058. Ucircumflexsmall: 0xF7FB,
  21059. Ucyrillic: 0x0423,
  21060. Udblacute: 0x0170,
  21061. Udblgrave: 0x0214,
  21062. Udieresis: 0x00DC,
  21063. Udieresisacute: 0x01D7,
  21064. Udieresisbelow: 0x1E72,
  21065. Udieresiscaron: 0x01D9,
  21066. Udieresiscyrillic: 0x04F0,
  21067. Udieresisgrave: 0x01DB,
  21068. Udieresismacron: 0x01D5,
  21069. Udieresissmall: 0xF7FC,
  21070. Udotbelow: 0x1EE4,
  21071. Ugrave: 0x00D9,
  21072. Ugravesmall: 0xF7F9,
  21073. Uhookabove: 0x1EE6,
  21074. Uhorn: 0x01AF,
  21075. Uhornacute: 0x1EE8,
  21076. Uhorndotbelow: 0x1EF0,
  21077. Uhorngrave: 0x1EEA,
  21078. Uhornhookabove: 0x1EEC,
  21079. Uhorntilde: 0x1EEE,
  21080. Uhungarumlaut: 0x0170,
  21081. Uhungarumlautcyrillic: 0x04F2,
  21082. Uinvertedbreve: 0x0216,
  21083. Ukcyrillic: 0x0478,
  21084. Umacron: 0x016A,
  21085. Umacroncyrillic: 0x04EE,
  21086. Umacrondieresis: 0x1E7A,
  21087. Umonospace: 0xFF35,
  21088. Uogonek: 0x0172,
  21089. Upsilon: 0x03A5,
  21090. Upsilon1: 0x03D2,
  21091. Upsilonacutehooksymbolgreek: 0x03D3,
  21092. Upsilonafrican: 0x01B1,
  21093. Upsilondieresis: 0x03AB,
  21094. Upsilondieresishooksymbolgreek: 0x03D4,
  21095. Upsilonhooksymbol: 0x03D2,
  21096. Upsilontonos: 0x038E,
  21097. Uring: 0x016E,
  21098. Ushortcyrillic: 0x040E,
  21099. Usmall: 0xF775,
  21100. Ustraightcyrillic: 0x04AE,
  21101. Ustraightstrokecyrillic: 0x04B0,
  21102. Utilde: 0x0168,
  21103. Utildeacute: 0x1E78,
  21104. Utildebelow: 0x1E74,
  21105. V: 0x0056,
  21106. Vcircle: 0x24CB,
  21107. Vdotbelow: 0x1E7E,
  21108. Vecyrillic: 0x0412,
  21109. Vewarmenian: 0x054E,
  21110. Vhook: 0x01B2,
  21111. Vmonospace: 0xFF36,
  21112. Voarmenian: 0x0548,
  21113. Vsmall: 0xF776,
  21114. Vtilde: 0x1E7C,
  21115. W: 0x0057,
  21116. Wacute: 0x1E82,
  21117. Wcircle: 0x24CC,
  21118. Wcircumflex: 0x0174,
  21119. Wdieresis: 0x1E84,
  21120. Wdotaccent: 0x1E86,
  21121. Wdotbelow: 0x1E88,
  21122. Wgrave: 0x1E80,
  21123. Wmonospace: 0xFF37,
  21124. Wsmall: 0xF777,
  21125. X: 0x0058,
  21126. Xcircle: 0x24CD,
  21127. Xdieresis: 0x1E8C,
  21128. Xdotaccent: 0x1E8A,
  21129. Xeharmenian: 0x053D,
  21130. Xi: 0x039E,
  21131. Xmonospace: 0xFF38,
  21132. Xsmall: 0xF778,
  21133. Y: 0x0059,
  21134. Yacute: 0x00DD,
  21135. Yacutesmall: 0xF7FD,
  21136. Yatcyrillic: 0x0462,
  21137. Ycircle: 0x24CE,
  21138. Ycircumflex: 0x0176,
  21139. Ydieresis: 0x0178,
  21140. Ydieresissmall: 0xF7FF,
  21141. Ydotaccent: 0x1E8E,
  21142. Ydotbelow: 0x1EF4,
  21143. Yericyrillic: 0x042B,
  21144. Yerudieresiscyrillic: 0x04F8,
  21145. Ygrave: 0x1EF2,
  21146. Yhook: 0x01B3,
  21147. Yhookabove: 0x1EF6,
  21148. Yiarmenian: 0x0545,
  21149. Yicyrillic: 0x0407,
  21150. Yiwnarmenian: 0x0552,
  21151. Ymonospace: 0xFF39,
  21152. Ysmall: 0xF779,
  21153. Ytilde: 0x1EF8,
  21154. Yusbigcyrillic: 0x046A,
  21155. Yusbigiotifiedcyrillic: 0x046C,
  21156. Yuslittlecyrillic: 0x0466,
  21157. Yuslittleiotifiedcyrillic: 0x0468,
  21158. Z: 0x005A,
  21159. Zaarmenian: 0x0536,
  21160. Zacute: 0x0179,
  21161. Zcaron: 0x017D,
  21162. Zcaronsmall: 0xF6FF,
  21163. Zcircle: 0x24CF,
  21164. Zcircumflex: 0x1E90,
  21165. Zdot: 0x017B,
  21166. Zdotaccent: 0x017B,
  21167. Zdotbelow: 0x1E92,
  21168. Zecyrillic: 0x0417,
  21169. Zedescendercyrillic: 0x0498,
  21170. Zedieresiscyrillic: 0x04DE,
  21171. Zeta: 0x0396,
  21172. Zhearmenian: 0x053A,
  21173. Zhebrevecyrillic: 0x04C1,
  21174. Zhecyrillic: 0x0416,
  21175. Zhedescendercyrillic: 0x0496,
  21176. Zhedieresiscyrillic: 0x04DC,
  21177. Zlinebelow: 0x1E94,
  21178. Zmonospace: 0xFF3A,
  21179. Zsmall: 0xF77A,
  21180. Zstroke: 0x01B5,
  21181. a: 0x0061,
  21182. aabengali: 0x0986,
  21183. aacute: 0x00E1,
  21184. aadeva: 0x0906,
  21185. aagujarati: 0x0A86,
  21186. aagurmukhi: 0x0A06,
  21187. aamatragurmukhi: 0x0A3E,
  21188. aarusquare: 0x3303,
  21189. aavowelsignbengali: 0x09BE,
  21190. aavowelsigndeva: 0x093E,
  21191. aavowelsigngujarati: 0x0ABE,
  21192. abbreviationmarkarmenian: 0x055F,
  21193. abbreviationsigndeva: 0x0970,
  21194. abengali: 0x0985,
  21195. abopomofo: 0x311A,
  21196. abreve: 0x0103,
  21197. abreveacute: 0x1EAF,
  21198. abrevecyrillic: 0x04D1,
  21199. abrevedotbelow: 0x1EB7,
  21200. abrevegrave: 0x1EB1,
  21201. abrevehookabove: 0x1EB3,
  21202. abrevetilde: 0x1EB5,
  21203. acaron: 0x01CE,
  21204. acircle: 0x24D0,
  21205. acircumflex: 0x00E2,
  21206. acircumflexacute: 0x1EA5,
  21207. acircumflexdotbelow: 0x1EAD,
  21208. acircumflexgrave: 0x1EA7,
  21209. acircumflexhookabove: 0x1EA9,
  21210. acircumflextilde: 0x1EAB,
  21211. acute: 0x00B4,
  21212. acutebelowcmb: 0x0317,
  21213. acutecmb: 0x0301,
  21214. acutecomb: 0x0301,
  21215. acutedeva: 0x0954,
  21216. acutelowmod: 0x02CF,
  21217. acutetonecmb: 0x0341,
  21218. acyrillic: 0x0430,
  21219. adblgrave: 0x0201,
  21220. addakgurmukhi: 0x0A71,
  21221. adeva: 0x0905,
  21222. adieresis: 0x00E4,
  21223. adieresiscyrillic: 0x04D3,
  21224. adieresismacron: 0x01DF,
  21225. adotbelow: 0x1EA1,
  21226. adotmacron: 0x01E1,
  21227. ae: 0x00E6,
  21228. aeacute: 0x01FD,
  21229. aekorean: 0x3150,
  21230. aemacron: 0x01E3,
  21231. afii00208: 0x2015,
  21232. afii08941: 0x20A4,
  21233. afii10017: 0x0410,
  21234. afii10018: 0x0411,
  21235. afii10019: 0x0412,
  21236. afii10020: 0x0413,
  21237. afii10021: 0x0414,
  21238. afii10022: 0x0415,
  21239. afii10023: 0x0401,
  21240. afii10024: 0x0416,
  21241. afii10025: 0x0417,
  21242. afii10026: 0x0418,
  21243. afii10027: 0x0419,
  21244. afii10028: 0x041A,
  21245. afii10029: 0x041B,
  21246. afii10030: 0x041C,
  21247. afii10031: 0x041D,
  21248. afii10032: 0x041E,
  21249. afii10033: 0x041F,
  21250. afii10034: 0x0420,
  21251. afii10035: 0x0421,
  21252. afii10036: 0x0422,
  21253. afii10037: 0x0423,
  21254. afii10038: 0x0424,
  21255. afii10039: 0x0425,
  21256. afii10040: 0x0426,
  21257. afii10041: 0x0427,
  21258. afii10042: 0x0428,
  21259. afii10043: 0x0429,
  21260. afii10044: 0x042A,
  21261. afii10045: 0x042B,
  21262. afii10046: 0x042C,
  21263. afii10047: 0x042D,
  21264. afii10048: 0x042E,
  21265. afii10049: 0x042F,
  21266. afii10050: 0x0490,
  21267. afii10051: 0x0402,
  21268. afii10052: 0x0403,
  21269. afii10053: 0x0404,
  21270. afii10054: 0x0405,
  21271. afii10055: 0x0406,
  21272. afii10056: 0x0407,
  21273. afii10057: 0x0408,
  21274. afii10058: 0x0409,
  21275. afii10059: 0x040A,
  21276. afii10060: 0x040B,
  21277. afii10061: 0x040C,
  21278. afii10062: 0x040E,
  21279. afii10063: 0xF6C4,
  21280. afii10064: 0xF6C5,
  21281. afii10065: 0x0430,
  21282. afii10066: 0x0431,
  21283. afii10067: 0x0432,
  21284. afii10068: 0x0433,
  21285. afii10069: 0x0434,
  21286. afii10070: 0x0435,
  21287. afii10071: 0x0451,
  21288. afii10072: 0x0436,
  21289. afii10073: 0x0437,
  21290. afii10074: 0x0438,
  21291. afii10075: 0x0439,
  21292. afii10076: 0x043A,
  21293. afii10077: 0x043B,
  21294. afii10078: 0x043C,
  21295. afii10079: 0x043D,
  21296. afii10080: 0x043E,
  21297. afii10081: 0x043F,
  21298. afii10082: 0x0440,
  21299. afii10083: 0x0441,
  21300. afii10084: 0x0442,
  21301. afii10085: 0x0443,
  21302. afii10086: 0x0444,
  21303. afii10087: 0x0445,
  21304. afii10088: 0x0446,
  21305. afii10089: 0x0447,
  21306. afii10090: 0x0448,
  21307. afii10091: 0x0449,
  21308. afii10092: 0x044A,
  21309. afii10093: 0x044B,
  21310. afii10094: 0x044C,
  21311. afii10095: 0x044D,
  21312. afii10096: 0x044E,
  21313. afii10097: 0x044F,
  21314. afii10098: 0x0491,
  21315. afii10099: 0x0452,
  21316. afii10100: 0x0453,
  21317. afii10101: 0x0454,
  21318. afii10102: 0x0455,
  21319. afii10103: 0x0456,
  21320. afii10104: 0x0457,
  21321. afii10105: 0x0458,
  21322. afii10106: 0x0459,
  21323. afii10107: 0x045A,
  21324. afii10108: 0x045B,
  21325. afii10109: 0x045C,
  21326. afii10110: 0x045E,
  21327. afii10145: 0x040F,
  21328. afii10146: 0x0462,
  21329. afii10147: 0x0472,
  21330. afii10148: 0x0474,
  21331. afii10192: 0xF6C6,
  21332. afii10193: 0x045F,
  21333. afii10194: 0x0463,
  21334. afii10195: 0x0473,
  21335. afii10196: 0x0475,
  21336. afii10831: 0xF6C7,
  21337. afii10832: 0xF6C8,
  21338. afii10846: 0x04D9,
  21339. afii299: 0x200E,
  21340. afii300: 0x200F,
  21341. afii301: 0x200D,
  21342. afii57381: 0x066A,
  21343. afii57388: 0x060C,
  21344. afii57392: 0x0660,
  21345. afii57393: 0x0661,
  21346. afii57394: 0x0662,
  21347. afii57395: 0x0663,
  21348. afii57396: 0x0664,
  21349. afii57397: 0x0665,
  21350. afii57398: 0x0666,
  21351. afii57399: 0x0667,
  21352. afii57400: 0x0668,
  21353. afii57401: 0x0669,
  21354. afii57403: 0x061B,
  21355. afii57407: 0x061F,
  21356. afii57409: 0x0621,
  21357. afii57410: 0x0622,
  21358. afii57411: 0x0623,
  21359. afii57412: 0x0624,
  21360. afii57413: 0x0625,
  21361. afii57414: 0x0626,
  21362. afii57415: 0x0627,
  21363. afii57416: 0x0628,
  21364. afii57417: 0x0629,
  21365. afii57418: 0x062A,
  21366. afii57419: 0x062B,
  21367. afii57420: 0x062C,
  21368. afii57421: 0x062D,
  21369. afii57422: 0x062E,
  21370. afii57423: 0x062F,
  21371. afii57424: 0x0630,
  21372. afii57425: 0x0631,
  21373. afii57426: 0x0632,
  21374. afii57427: 0x0633,
  21375. afii57428: 0x0634,
  21376. afii57429: 0x0635,
  21377. afii57430: 0x0636,
  21378. afii57431: 0x0637,
  21379. afii57432: 0x0638,
  21380. afii57433: 0x0639,
  21381. afii57434: 0x063A,
  21382. afii57440: 0x0640,
  21383. afii57441: 0x0641,
  21384. afii57442: 0x0642,
  21385. afii57443: 0x0643,
  21386. afii57444: 0x0644,
  21387. afii57445: 0x0645,
  21388. afii57446: 0x0646,
  21389. afii57448: 0x0648,
  21390. afii57449: 0x0649,
  21391. afii57450: 0x064A,
  21392. afii57451: 0x064B,
  21393. afii57452: 0x064C,
  21394. afii57453: 0x064D,
  21395. afii57454: 0x064E,
  21396. afii57455: 0x064F,
  21397. afii57456: 0x0650,
  21398. afii57457: 0x0651,
  21399. afii57458: 0x0652,
  21400. afii57470: 0x0647,
  21401. afii57505: 0x06A4,
  21402. afii57506: 0x067E,
  21403. afii57507: 0x0686,
  21404. afii57508: 0x0698,
  21405. afii57509: 0x06AF,
  21406. afii57511: 0x0679,
  21407. afii57512: 0x0688,
  21408. afii57513: 0x0691,
  21409. afii57514: 0x06BA,
  21410. afii57519: 0x06D2,
  21411. afii57534: 0x06D5,
  21412. afii57636: 0x20AA,
  21413. afii57645: 0x05BE,
  21414. afii57658: 0x05C3,
  21415. afii57664: 0x05D0,
  21416. afii57665: 0x05D1,
  21417. afii57666: 0x05D2,
  21418. afii57667: 0x05D3,
  21419. afii57668: 0x05D4,
  21420. afii57669: 0x05D5,
  21421. afii57670: 0x05D6,
  21422. afii57671: 0x05D7,
  21423. afii57672: 0x05D8,
  21424. afii57673: 0x05D9,
  21425. afii57674: 0x05DA,
  21426. afii57675: 0x05DB,
  21427. afii57676: 0x05DC,
  21428. afii57677: 0x05DD,
  21429. afii57678: 0x05DE,
  21430. afii57679: 0x05DF,
  21431. afii57680: 0x05E0,
  21432. afii57681: 0x05E1,
  21433. afii57682: 0x05E2,
  21434. afii57683: 0x05E3,
  21435. afii57684: 0x05E4,
  21436. afii57685: 0x05E5,
  21437. afii57686: 0x05E6,
  21438. afii57687: 0x05E7,
  21439. afii57688: 0x05E8,
  21440. afii57689: 0x05E9,
  21441. afii57690: 0x05EA,
  21442. afii57694: 0xFB2A,
  21443. afii57695: 0xFB2B,
  21444. afii57700: 0xFB4B,
  21445. afii57705: 0xFB1F,
  21446. afii57716: 0x05F0,
  21447. afii57717: 0x05F1,
  21448. afii57718: 0x05F2,
  21449. afii57723: 0xFB35,
  21450. afii57793: 0x05B4,
  21451. afii57794: 0x05B5,
  21452. afii57795: 0x05B6,
  21453. afii57796: 0x05BB,
  21454. afii57797: 0x05B8,
  21455. afii57798: 0x05B7,
  21456. afii57799: 0x05B0,
  21457. afii57800: 0x05B2,
  21458. afii57801: 0x05B1,
  21459. afii57802: 0x05B3,
  21460. afii57803: 0x05C2,
  21461. afii57804: 0x05C1,
  21462. afii57806: 0x05B9,
  21463. afii57807: 0x05BC,
  21464. afii57839: 0x05BD,
  21465. afii57841: 0x05BF,
  21466. afii57842: 0x05C0,
  21467. afii57929: 0x02BC,
  21468. afii61248: 0x2105,
  21469. afii61289: 0x2113,
  21470. afii61352: 0x2116,
  21471. afii61573: 0x202C,
  21472. afii61574: 0x202D,
  21473. afii61575: 0x202E,
  21474. afii61664: 0x200C,
  21475. afii63167: 0x066D,
  21476. afii64937: 0x02BD,
  21477. agrave: 0x00E0,
  21478. agujarati: 0x0A85,
  21479. agurmukhi: 0x0A05,
  21480. ahiragana: 0x3042,
  21481. ahookabove: 0x1EA3,
  21482. aibengali: 0x0990,
  21483. aibopomofo: 0x311E,
  21484. aideva: 0x0910,
  21485. aiecyrillic: 0x04D5,
  21486. aigujarati: 0x0A90,
  21487. aigurmukhi: 0x0A10,
  21488. aimatragurmukhi: 0x0A48,
  21489. ainarabic: 0x0639,
  21490. ainfinalarabic: 0xFECA,
  21491. aininitialarabic: 0xFECB,
  21492. ainmedialarabic: 0xFECC,
  21493. ainvertedbreve: 0x0203,
  21494. aivowelsignbengali: 0x09C8,
  21495. aivowelsigndeva: 0x0948,
  21496. aivowelsigngujarati: 0x0AC8,
  21497. akatakana: 0x30A2,
  21498. akatakanahalfwidth: 0xFF71,
  21499. akorean: 0x314F,
  21500. alef: 0x05D0,
  21501. alefarabic: 0x0627,
  21502. alefdageshhebrew: 0xFB30,
  21503. aleffinalarabic: 0xFE8E,
  21504. alefhamzaabovearabic: 0x0623,
  21505. alefhamzaabovefinalarabic: 0xFE84,
  21506. alefhamzabelowarabic: 0x0625,
  21507. alefhamzabelowfinalarabic: 0xFE88,
  21508. alefhebrew: 0x05D0,
  21509. aleflamedhebrew: 0xFB4F,
  21510. alefmaddaabovearabic: 0x0622,
  21511. alefmaddaabovefinalarabic: 0xFE82,
  21512. alefmaksuraarabic: 0x0649,
  21513. alefmaksurafinalarabic: 0xFEF0,
  21514. alefmaksurainitialarabic: 0xFEF3,
  21515. alefmaksuramedialarabic: 0xFEF4,
  21516. alefpatahhebrew: 0xFB2E,
  21517. alefqamatshebrew: 0xFB2F,
  21518. aleph: 0x2135,
  21519. allequal: 0x224C,
  21520. alpha: 0x03B1,
  21521. alphatonos: 0x03AC,
  21522. amacron: 0x0101,
  21523. amonospace: 0xFF41,
  21524. ampersand: 0x0026,
  21525. ampersandmonospace: 0xFF06,
  21526. ampersandsmall: 0xF726,
  21527. amsquare: 0x33C2,
  21528. anbopomofo: 0x3122,
  21529. angbopomofo: 0x3124,
  21530. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21531. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21532. angkhankhuthai: 0x0E5A,
  21533. angle: 0x2220,
  21534. anglebracketleft: 0x3008,
  21535. anglebracketleftvertical: 0xFE3F,
  21536. anglebracketright: 0x3009,
  21537. anglebracketrightvertical: 0xFE40,
  21538. angleleft: 0x2329,
  21539. angleright: 0x232A,
  21540. angstrom: 0x212B,
  21541. anoteleia: 0x0387,
  21542. anudattadeva: 0x0952,
  21543. anusvarabengali: 0x0982,
  21544. anusvaradeva: 0x0902,
  21545. anusvaragujarati: 0x0A82,
  21546. aogonek: 0x0105,
  21547. apaatosquare: 0x3300,
  21548. aparen: 0x249C,
  21549. apostrophearmenian: 0x055A,
  21550. apostrophemod: 0x02BC,
  21551. apple: 0xF8FF,
  21552. approaches: 0x2250,
  21553. approxequal: 0x2248,
  21554. approxequalorimage: 0x2252,
  21555. approximatelyequal: 0x2245,
  21556. araeaekorean: 0x318E,
  21557. araeakorean: 0x318D,
  21558. arc: 0x2312,
  21559. arighthalfring: 0x1E9A,
  21560. aring: 0x00E5,
  21561. aringacute: 0x01FB,
  21562. aringbelow: 0x1E01,
  21563. arrowboth: 0x2194,
  21564. arrowdashdown: 0x21E3,
  21565. arrowdashleft: 0x21E0,
  21566. arrowdashright: 0x21E2,
  21567. arrowdashup: 0x21E1,
  21568. arrowdblboth: 0x21D4,
  21569. arrowdbldown: 0x21D3,
  21570. arrowdblleft: 0x21D0,
  21571. arrowdblright: 0x21D2,
  21572. arrowdblup: 0x21D1,
  21573. arrowdown: 0x2193,
  21574. arrowdownleft: 0x2199,
  21575. arrowdownright: 0x2198,
  21576. arrowdownwhite: 0x21E9,
  21577. arrowheaddownmod: 0x02C5,
  21578. arrowheadleftmod: 0x02C2,
  21579. arrowheadrightmod: 0x02C3,
  21580. arrowheadupmod: 0x02C4,
  21581. arrowhorizex: 0xF8E7,
  21582. arrowleft: 0x2190,
  21583. arrowleftdbl: 0x21D0,
  21584. arrowleftdblstroke: 0x21CD,
  21585. arrowleftoverright: 0x21C6,
  21586. arrowleftwhite: 0x21E6,
  21587. arrowright: 0x2192,
  21588. arrowrightdblstroke: 0x21CF,
  21589. arrowrightheavy: 0x279E,
  21590. arrowrightoverleft: 0x21C4,
  21591. arrowrightwhite: 0x21E8,
  21592. arrowtableft: 0x21E4,
  21593. arrowtabright: 0x21E5,
  21594. arrowup: 0x2191,
  21595. arrowupdn: 0x2195,
  21596. arrowupdnbse: 0x21A8,
  21597. arrowupdownbase: 0x21A8,
  21598. arrowupleft: 0x2196,
  21599. arrowupleftofdown: 0x21C5,
  21600. arrowupright: 0x2197,
  21601. arrowupwhite: 0x21E7,
  21602. arrowvertex: 0xF8E6,
  21603. asciicircum: 0x005E,
  21604. asciicircummonospace: 0xFF3E,
  21605. asciitilde: 0x007E,
  21606. asciitildemonospace: 0xFF5E,
  21607. ascript: 0x0251,
  21608. ascriptturned: 0x0252,
  21609. asmallhiragana: 0x3041,
  21610. asmallkatakana: 0x30A1,
  21611. asmallkatakanahalfwidth: 0xFF67,
  21612. asterisk: 0x002A,
  21613. asteriskaltonearabic: 0x066D,
  21614. asteriskarabic: 0x066D,
  21615. asteriskmath: 0x2217,
  21616. asteriskmonospace: 0xFF0A,
  21617. asterisksmall: 0xFE61,
  21618. asterism: 0x2042,
  21619. asuperior: 0xF6E9,
  21620. asymptoticallyequal: 0x2243,
  21621. at: 0x0040,
  21622. atilde: 0x00E3,
  21623. atmonospace: 0xFF20,
  21624. atsmall: 0xFE6B,
  21625. aturned: 0x0250,
  21626. aubengali: 0x0994,
  21627. aubopomofo: 0x3120,
  21628. audeva: 0x0914,
  21629. augujarati: 0x0A94,
  21630. augurmukhi: 0x0A14,
  21631. aulengthmarkbengali: 0x09D7,
  21632. aumatragurmukhi: 0x0A4C,
  21633. auvowelsignbengali: 0x09CC,
  21634. auvowelsigndeva: 0x094C,
  21635. auvowelsigngujarati: 0x0ACC,
  21636. avagrahadeva: 0x093D,
  21637. aybarmenian: 0x0561,
  21638. ayin: 0x05E2,
  21639. ayinaltonehebrew: 0xFB20,
  21640. ayinhebrew: 0x05E2,
  21641. b: 0x0062,
  21642. babengali: 0x09AC,
  21643. backslash: 0x005C,
  21644. backslashmonospace: 0xFF3C,
  21645. badeva: 0x092C,
  21646. bagujarati: 0x0AAC,
  21647. bagurmukhi: 0x0A2C,
  21648. bahiragana: 0x3070,
  21649. bahtthai: 0x0E3F,
  21650. bakatakana: 0x30D0,
  21651. bar: 0x007C,
  21652. barmonospace: 0xFF5C,
  21653. bbopomofo: 0x3105,
  21654. bcircle: 0x24D1,
  21655. bdotaccent: 0x1E03,
  21656. bdotbelow: 0x1E05,
  21657. beamedsixteenthnotes: 0x266C,
  21658. because: 0x2235,
  21659. becyrillic: 0x0431,
  21660. beharabic: 0x0628,
  21661. behfinalarabic: 0xFE90,
  21662. behinitialarabic: 0xFE91,
  21663. behiragana: 0x3079,
  21664. behmedialarabic: 0xFE92,
  21665. behmeeminitialarabic: 0xFC9F,
  21666. behmeemisolatedarabic: 0xFC08,
  21667. behnoonfinalarabic: 0xFC6D,
  21668. bekatakana: 0x30D9,
  21669. benarmenian: 0x0562,
  21670. bet: 0x05D1,
  21671. beta: 0x03B2,
  21672. betasymbolgreek: 0x03D0,
  21673. betdagesh: 0xFB31,
  21674. betdageshhebrew: 0xFB31,
  21675. bethebrew: 0x05D1,
  21676. betrafehebrew: 0xFB4C,
  21677. bhabengali: 0x09AD,
  21678. bhadeva: 0x092D,
  21679. bhagujarati: 0x0AAD,
  21680. bhagurmukhi: 0x0A2D,
  21681. bhook: 0x0253,
  21682. bihiragana: 0x3073,
  21683. bikatakana: 0x30D3,
  21684. bilabialclick: 0x0298,
  21685. bindigurmukhi: 0x0A02,
  21686. birusquare: 0x3331,
  21687. blackcircle: 0x25CF,
  21688. blackdiamond: 0x25C6,
  21689. blackdownpointingtriangle: 0x25BC,
  21690. blackleftpointingpointer: 0x25C4,
  21691. blackleftpointingtriangle: 0x25C0,
  21692. blacklenticularbracketleft: 0x3010,
  21693. blacklenticularbracketleftvertical: 0xFE3B,
  21694. blacklenticularbracketright: 0x3011,
  21695. blacklenticularbracketrightvertical: 0xFE3C,
  21696. blacklowerlefttriangle: 0x25E3,
  21697. blacklowerrighttriangle: 0x25E2,
  21698. blackrectangle: 0x25AC,
  21699. blackrightpointingpointer: 0x25BA,
  21700. blackrightpointingtriangle: 0x25B6,
  21701. blacksmallsquare: 0x25AA,
  21702. blacksmilingface: 0x263B,
  21703. blacksquare: 0x25A0,
  21704. blackstar: 0x2605,
  21705. blackupperlefttriangle: 0x25E4,
  21706. blackupperrighttriangle: 0x25E5,
  21707. blackuppointingsmalltriangle: 0x25B4,
  21708. blackuppointingtriangle: 0x25B2,
  21709. blank: 0x2423,
  21710. blinebelow: 0x1E07,
  21711. block: 0x2588,
  21712. bmonospace: 0xFF42,
  21713. bobaimaithai: 0x0E1A,
  21714. bohiragana: 0x307C,
  21715. bokatakana: 0x30DC,
  21716. bparen: 0x249D,
  21717. bqsquare: 0x33C3,
  21718. braceex: 0xF8F4,
  21719. braceleft: 0x007B,
  21720. braceleftbt: 0xF8F3,
  21721. braceleftmid: 0xF8F2,
  21722. braceleftmonospace: 0xFF5B,
  21723. braceleftsmall: 0xFE5B,
  21724. bracelefttp: 0xF8F1,
  21725. braceleftvertical: 0xFE37,
  21726. braceright: 0x007D,
  21727. bracerightbt: 0xF8FE,
  21728. bracerightmid: 0xF8FD,
  21729. bracerightmonospace: 0xFF5D,
  21730. bracerightsmall: 0xFE5C,
  21731. bracerighttp: 0xF8FC,
  21732. bracerightvertical: 0xFE38,
  21733. bracketleft: 0x005B,
  21734. bracketleftbt: 0xF8F0,
  21735. bracketleftex: 0xF8EF,
  21736. bracketleftmonospace: 0xFF3B,
  21737. bracketlefttp: 0xF8EE,
  21738. bracketright: 0x005D,
  21739. bracketrightbt: 0xF8FB,
  21740. bracketrightex: 0xF8FA,
  21741. bracketrightmonospace: 0xFF3D,
  21742. bracketrighttp: 0xF8F9,
  21743. breve: 0x02D8,
  21744. brevebelowcmb: 0x032E,
  21745. brevecmb: 0x0306,
  21746. breveinvertedbelowcmb: 0x032F,
  21747. breveinvertedcmb: 0x0311,
  21748. breveinverteddoublecmb: 0x0361,
  21749. bridgebelowcmb: 0x032A,
  21750. bridgeinvertedbelowcmb: 0x033A,
  21751. brokenbar: 0x00A6,
  21752. bstroke: 0x0180,
  21753. bsuperior: 0xF6EA,
  21754. btopbar: 0x0183,
  21755. buhiragana: 0x3076,
  21756. bukatakana: 0x30D6,
  21757. bullet: 0x2022,
  21758. bulletinverse: 0x25D8,
  21759. bulletoperator: 0x2219,
  21760. bullseye: 0x25CE,
  21761. c: 0x0063,
  21762. caarmenian: 0x056E,
  21763. cabengali: 0x099A,
  21764. cacute: 0x0107,
  21765. cadeva: 0x091A,
  21766. cagujarati: 0x0A9A,
  21767. cagurmukhi: 0x0A1A,
  21768. calsquare: 0x3388,
  21769. candrabindubengali: 0x0981,
  21770. candrabinducmb: 0x0310,
  21771. candrabindudeva: 0x0901,
  21772. candrabindugujarati: 0x0A81,
  21773. capslock: 0x21EA,
  21774. careof: 0x2105,
  21775. caron: 0x02C7,
  21776. caronbelowcmb: 0x032C,
  21777. caroncmb: 0x030C,
  21778. carriagereturn: 0x21B5,
  21779. cbopomofo: 0x3118,
  21780. ccaron: 0x010D,
  21781. ccedilla: 0x00E7,
  21782. ccedillaacute: 0x1E09,
  21783. ccircle: 0x24D2,
  21784. ccircumflex: 0x0109,
  21785. ccurl: 0x0255,
  21786. cdot: 0x010B,
  21787. cdotaccent: 0x010B,
  21788. cdsquare: 0x33C5,
  21789. cedilla: 0x00B8,
  21790. cedillacmb: 0x0327,
  21791. cent: 0x00A2,
  21792. centigrade: 0x2103,
  21793. centinferior: 0xF6DF,
  21794. centmonospace: 0xFFE0,
  21795. centoldstyle: 0xF7A2,
  21796. centsuperior: 0xF6E0,
  21797. chaarmenian: 0x0579,
  21798. chabengali: 0x099B,
  21799. chadeva: 0x091B,
  21800. chagujarati: 0x0A9B,
  21801. chagurmukhi: 0x0A1B,
  21802. chbopomofo: 0x3114,
  21803. cheabkhasiancyrillic: 0x04BD,
  21804. checkmark: 0x2713,
  21805. checyrillic: 0x0447,
  21806. chedescenderabkhasiancyrillic: 0x04BF,
  21807. chedescendercyrillic: 0x04B7,
  21808. chedieresiscyrillic: 0x04F5,
  21809. cheharmenian: 0x0573,
  21810. chekhakassiancyrillic: 0x04CC,
  21811. cheverticalstrokecyrillic: 0x04B9,
  21812. chi: 0x03C7,
  21813. chieuchacirclekorean: 0x3277,
  21814. chieuchaparenkorean: 0x3217,
  21815. chieuchcirclekorean: 0x3269,
  21816. chieuchkorean: 0x314A,
  21817. chieuchparenkorean: 0x3209,
  21818. chochangthai: 0x0E0A,
  21819. chochanthai: 0x0E08,
  21820. chochingthai: 0x0E09,
  21821. chochoethai: 0x0E0C,
  21822. chook: 0x0188,
  21823. cieucacirclekorean: 0x3276,
  21824. cieucaparenkorean: 0x3216,
  21825. cieuccirclekorean: 0x3268,
  21826. cieuckorean: 0x3148,
  21827. cieucparenkorean: 0x3208,
  21828. cieucuparenkorean: 0x321C,
  21829. circle: 0x25CB,
  21830. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21831. circlemultiply: 0x2297,
  21832. circleot: 0x2299,
  21833. circleplus: 0x2295,
  21834. circlepostalmark: 0x3036,
  21835. circlewithlefthalfblack: 0x25D0,
  21836. circlewithrighthalfblack: 0x25D1,
  21837. circumflex: 0x02C6,
  21838. circumflexbelowcmb: 0x032D,
  21839. circumflexcmb: 0x0302,
  21840. clear: 0x2327,
  21841. clickalveolar: 0x01C2,
  21842. clickdental: 0x01C0,
  21843. clicklateral: 0x01C1,
  21844. clickretroflex: 0x01C3,
  21845. club: 0x2663,
  21846. clubsuitblack: 0x2663,
  21847. clubsuitwhite: 0x2667,
  21848. cmcubedsquare: 0x33A4,
  21849. cmonospace: 0xFF43,
  21850. cmsquaredsquare: 0x33A0,
  21851. coarmenian: 0x0581,
  21852. colon: 0x003A,
  21853. colonmonetary: 0x20A1,
  21854. colonmonospace: 0xFF1A,
  21855. colonsign: 0x20A1,
  21856. colonsmall: 0xFE55,
  21857. colontriangularhalfmod: 0x02D1,
  21858. colontriangularmod: 0x02D0,
  21859. comma: 0x002C,
  21860. commaabovecmb: 0x0313,
  21861. commaaboverightcmb: 0x0315,
  21862. commaaccent: 0xF6C3,
  21863. commaarabic: 0x060C,
  21864. commaarmenian: 0x055D,
  21865. commainferior: 0xF6E1,
  21866. commamonospace: 0xFF0C,
  21867. commareversedabovecmb: 0x0314,
  21868. commareversedmod: 0x02BD,
  21869. commasmall: 0xFE50,
  21870. commasuperior: 0xF6E2,
  21871. commaturnedabovecmb: 0x0312,
  21872. commaturnedmod: 0x02BB,
  21873. compass: 0x263C,
  21874. congruent: 0x2245,
  21875. contourintegral: 0x222E,
  21876. control: 0x2303,
  21877. controlACK: 0x0006,
  21878. controlBEL: 0x0007,
  21879. controlBS: 0x0008,
  21880. controlCAN: 0x0018,
  21881. controlCR: 0x000D,
  21882. controlDC1: 0x0011,
  21883. controlDC2: 0x0012,
  21884. controlDC3: 0x0013,
  21885. controlDC4: 0x0014,
  21886. controlDEL: 0x007F,
  21887. controlDLE: 0x0010,
  21888. controlEM: 0x0019,
  21889. controlENQ: 0x0005,
  21890. controlEOT: 0x0004,
  21891. controlESC: 0x001B,
  21892. controlETB: 0x0017,
  21893. controlETX: 0x0003,
  21894. controlFF: 0x000C,
  21895. controlFS: 0x001C,
  21896. controlGS: 0x001D,
  21897. controlHT: 0x0009,
  21898. controlLF: 0x000A,
  21899. controlNAK: 0x0015,
  21900. controlRS: 0x001E,
  21901. controlSI: 0x000F,
  21902. controlSO: 0x000E,
  21903. controlSOT: 0x0002,
  21904. controlSTX: 0x0001,
  21905. controlSUB: 0x001A,
  21906. controlSYN: 0x0016,
  21907. controlUS: 0x001F,
  21908. controlVT: 0x000B,
  21909. copyright: 0x00A9,
  21910. copyrightsans: 0xF8E9,
  21911. copyrightserif: 0xF6D9,
  21912. cornerbracketleft: 0x300C,
  21913. cornerbracketlefthalfwidth: 0xFF62,
  21914. cornerbracketleftvertical: 0xFE41,
  21915. cornerbracketright: 0x300D,
  21916. cornerbracketrighthalfwidth: 0xFF63,
  21917. cornerbracketrightvertical: 0xFE42,
  21918. corporationsquare: 0x337F,
  21919. cosquare: 0x33C7,
  21920. coverkgsquare: 0x33C6,
  21921. cparen: 0x249E,
  21922. cruzeiro: 0x20A2,
  21923. cstretched: 0x0297,
  21924. curlyand: 0x22CF,
  21925. curlyor: 0x22CE,
  21926. currency: 0x00A4,
  21927. cyrBreve: 0xF6D1,
  21928. cyrFlex: 0xF6D2,
  21929. cyrbreve: 0xF6D4,
  21930. cyrflex: 0xF6D5,
  21931. d: 0x0064,
  21932. daarmenian: 0x0564,
  21933. dabengali: 0x09A6,
  21934. dadarabic: 0x0636,
  21935. dadeva: 0x0926,
  21936. dadfinalarabic: 0xFEBE,
  21937. dadinitialarabic: 0xFEBF,
  21938. dadmedialarabic: 0xFEC0,
  21939. dagesh: 0x05BC,
  21940. dageshhebrew: 0x05BC,
  21941. dagger: 0x2020,
  21942. daggerdbl: 0x2021,
  21943. dagujarati: 0x0AA6,
  21944. dagurmukhi: 0x0A26,
  21945. dahiragana: 0x3060,
  21946. dakatakana: 0x30C0,
  21947. dalarabic: 0x062F,
  21948. dalet: 0x05D3,
  21949. daletdagesh: 0xFB33,
  21950. daletdageshhebrew: 0xFB33,
  21951. dalethebrew: 0x05D3,
  21952. dalfinalarabic: 0xFEAA,
  21953. dammaarabic: 0x064F,
  21954. dammalowarabic: 0x064F,
  21955. dammatanaltonearabic: 0x064C,
  21956. dammatanarabic: 0x064C,
  21957. danda: 0x0964,
  21958. dargahebrew: 0x05A7,
  21959. dargalefthebrew: 0x05A7,
  21960. dasiapneumatacyrilliccmb: 0x0485,
  21961. dblGrave: 0xF6D3,
  21962. dblanglebracketleft: 0x300A,
  21963. dblanglebracketleftvertical: 0xFE3D,
  21964. dblanglebracketright: 0x300B,
  21965. dblanglebracketrightvertical: 0xFE3E,
  21966. dblarchinvertedbelowcmb: 0x032B,
  21967. dblarrowleft: 0x21D4,
  21968. dblarrowright: 0x21D2,
  21969. dbldanda: 0x0965,
  21970. dblgrave: 0xF6D6,
  21971. dblgravecmb: 0x030F,
  21972. dblintegral: 0x222C,
  21973. dbllowline: 0x2017,
  21974. dbllowlinecmb: 0x0333,
  21975. dbloverlinecmb: 0x033F,
  21976. dblprimemod: 0x02BA,
  21977. dblverticalbar: 0x2016,
  21978. dblverticallineabovecmb: 0x030E,
  21979. dbopomofo: 0x3109,
  21980. dbsquare: 0x33C8,
  21981. dcaron: 0x010F,
  21982. dcedilla: 0x1E11,
  21983. dcircle: 0x24D3,
  21984. dcircumflexbelow: 0x1E13,
  21985. dcroat: 0x0111,
  21986. ddabengali: 0x09A1,
  21987. ddadeva: 0x0921,
  21988. ddagujarati: 0x0AA1,
  21989. ddagurmukhi: 0x0A21,
  21990. ddalarabic: 0x0688,
  21991. ddalfinalarabic: 0xFB89,
  21992. dddhadeva: 0x095C,
  21993. ddhabengali: 0x09A2,
  21994. ddhadeva: 0x0922,
  21995. ddhagujarati: 0x0AA2,
  21996. ddhagurmukhi: 0x0A22,
  21997. ddotaccent: 0x1E0B,
  21998. ddotbelow: 0x1E0D,
  21999. decimalseparatorarabic: 0x066B,
  22000. decimalseparatorpersian: 0x066B,
  22001. decyrillic: 0x0434,
  22002. degree: 0x00B0,
  22003. dehihebrew: 0x05AD,
  22004. dehiragana: 0x3067,
  22005. deicoptic: 0x03EF,
  22006. dekatakana: 0x30C7,
  22007. deleteleft: 0x232B,
  22008. deleteright: 0x2326,
  22009. delta: 0x03B4,
  22010. deltaturned: 0x018D,
  22011. denominatorminusonenumeratorbengali: 0x09F8,
  22012. dezh: 0x02A4,
  22013. dhabengali: 0x09A7,
  22014. dhadeva: 0x0927,
  22015. dhagujarati: 0x0AA7,
  22016. dhagurmukhi: 0x0A27,
  22017. dhook: 0x0257,
  22018. dialytikatonos: 0x0385,
  22019. dialytikatonoscmb: 0x0344,
  22020. diamond: 0x2666,
  22021. diamondsuitwhite: 0x2662,
  22022. dieresis: 0x00A8,
  22023. dieresisacute: 0xF6D7,
  22024. dieresisbelowcmb: 0x0324,
  22025. dieresiscmb: 0x0308,
  22026. dieresisgrave: 0xF6D8,
  22027. dieresistonos: 0x0385,
  22028. dihiragana: 0x3062,
  22029. dikatakana: 0x30C2,
  22030. dittomark: 0x3003,
  22031. divide: 0x00F7,
  22032. divides: 0x2223,
  22033. divisionslash: 0x2215,
  22034. djecyrillic: 0x0452,
  22035. dkshade: 0x2593,
  22036. dlinebelow: 0x1E0F,
  22037. dlsquare: 0x3397,
  22038. dmacron: 0x0111,
  22039. dmonospace: 0xFF44,
  22040. dnblock: 0x2584,
  22041. dochadathai: 0x0E0E,
  22042. dodekthai: 0x0E14,
  22043. dohiragana: 0x3069,
  22044. dokatakana: 0x30C9,
  22045. dollar: 0x0024,
  22046. dollarinferior: 0xF6E3,
  22047. dollarmonospace: 0xFF04,
  22048. dollaroldstyle: 0xF724,
  22049. dollarsmall: 0xFE69,
  22050. dollarsuperior: 0xF6E4,
  22051. dong: 0x20AB,
  22052. dorusquare: 0x3326,
  22053. dotaccent: 0x02D9,
  22054. dotaccentcmb: 0x0307,
  22055. dotbelowcmb: 0x0323,
  22056. dotbelowcomb: 0x0323,
  22057. dotkatakana: 0x30FB,
  22058. dotlessi: 0x0131,
  22059. dotlessj: 0xF6BE,
  22060. dotlessjstrokehook: 0x0284,
  22061. dotmath: 0x22C5,
  22062. dottedcircle: 0x25CC,
  22063. doubleyodpatah: 0xFB1F,
  22064. doubleyodpatahhebrew: 0xFB1F,
  22065. downtackbelowcmb: 0x031E,
  22066. downtackmod: 0x02D5,
  22067. dparen: 0x249F,
  22068. dsuperior: 0xF6EB,
  22069. dtail: 0x0256,
  22070. dtopbar: 0x018C,
  22071. duhiragana: 0x3065,
  22072. dukatakana: 0x30C5,
  22073. dz: 0x01F3,
  22074. dzaltone: 0x02A3,
  22075. dzcaron: 0x01C6,
  22076. dzcurl: 0x02A5,
  22077. dzeabkhasiancyrillic: 0x04E1,
  22078. dzecyrillic: 0x0455,
  22079. dzhecyrillic: 0x045F,
  22080. e: 0x0065,
  22081. eacute: 0x00E9,
  22082. earth: 0x2641,
  22083. ebengali: 0x098F,
  22084. ebopomofo: 0x311C,
  22085. ebreve: 0x0115,
  22086. ecandradeva: 0x090D,
  22087. ecandragujarati: 0x0A8D,
  22088. ecandravowelsigndeva: 0x0945,
  22089. ecandravowelsigngujarati: 0x0AC5,
  22090. ecaron: 0x011B,
  22091. ecedillabreve: 0x1E1D,
  22092. echarmenian: 0x0565,
  22093. echyiwnarmenian: 0x0587,
  22094. ecircle: 0x24D4,
  22095. ecircumflex: 0x00EA,
  22096. ecircumflexacute: 0x1EBF,
  22097. ecircumflexbelow: 0x1E19,
  22098. ecircumflexdotbelow: 0x1EC7,
  22099. ecircumflexgrave: 0x1EC1,
  22100. ecircumflexhookabove: 0x1EC3,
  22101. ecircumflextilde: 0x1EC5,
  22102. ecyrillic: 0x0454,
  22103. edblgrave: 0x0205,
  22104. edeva: 0x090F,
  22105. edieresis: 0x00EB,
  22106. edot: 0x0117,
  22107. edotaccent: 0x0117,
  22108. edotbelow: 0x1EB9,
  22109. eegurmukhi: 0x0A0F,
  22110. eematragurmukhi: 0x0A47,
  22111. efcyrillic: 0x0444,
  22112. egrave: 0x00E8,
  22113. egujarati: 0x0A8F,
  22114. eharmenian: 0x0567,
  22115. ehbopomofo: 0x311D,
  22116. ehiragana: 0x3048,
  22117. ehookabove: 0x1EBB,
  22118. eibopomofo: 0x311F,
  22119. eight: 0x0038,
  22120. eightarabic: 0x0668,
  22121. eightbengali: 0x09EE,
  22122. eightcircle: 0x2467,
  22123. eightcircleinversesansserif: 0x2791,
  22124. eightdeva: 0x096E,
  22125. eighteencircle: 0x2471,
  22126. eighteenparen: 0x2485,
  22127. eighteenperiod: 0x2499,
  22128. eightgujarati: 0x0AEE,
  22129. eightgurmukhi: 0x0A6E,
  22130. eighthackarabic: 0x0668,
  22131. eighthangzhou: 0x3028,
  22132. eighthnotebeamed: 0x266B,
  22133. eightideographicparen: 0x3227,
  22134. eightinferior: 0x2088,
  22135. eightmonospace: 0xFF18,
  22136. eightoldstyle: 0xF738,
  22137. eightparen: 0x247B,
  22138. eightperiod: 0x248F,
  22139. eightpersian: 0x06F8,
  22140. eightroman: 0x2177,
  22141. eightsuperior: 0x2078,
  22142. eightthai: 0x0E58,
  22143. einvertedbreve: 0x0207,
  22144. eiotifiedcyrillic: 0x0465,
  22145. ekatakana: 0x30A8,
  22146. ekatakanahalfwidth: 0xFF74,
  22147. ekonkargurmukhi: 0x0A74,
  22148. ekorean: 0x3154,
  22149. elcyrillic: 0x043B,
  22150. element: 0x2208,
  22151. elevencircle: 0x246A,
  22152. elevenparen: 0x247E,
  22153. elevenperiod: 0x2492,
  22154. elevenroman: 0x217A,
  22155. ellipsis: 0x2026,
  22156. ellipsisvertical: 0x22EE,
  22157. emacron: 0x0113,
  22158. emacronacute: 0x1E17,
  22159. emacrongrave: 0x1E15,
  22160. emcyrillic: 0x043C,
  22161. emdash: 0x2014,
  22162. emdashvertical: 0xFE31,
  22163. emonospace: 0xFF45,
  22164. emphasismarkarmenian: 0x055B,
  22165. emptyset: 0x2205,
  22166. enbopomofo: 0x3123,
  22167. encyrillic: 0x043D,
  22168. endash: 0x2013,
  22169. endashvertical: 0xFE32,
  22170. endescendercyrillic: 0x04A3,
  22171. eng: 0x014B,
  22172. engbopomofo: 0x3125,
  22173. enghecyrillic: 0x04A5,
  22174. enhookcyrillic: 0x04C8,
  22175. enspace: 0x2002,
  22176. eogonek: 0x0119,
  22177. eokorean: 0x3153,
  22178. eopen: 0x025B,
  22179. eopenclosed: 0x029A,
  22180. eopenreversed: 0x025C,
  22181. eopenreversedclosed: 0x025E,
  22182. eopenreversedhook: 0x025D,
  22183. eparen: 0x24A0,
  22184. epsilon: 0x03B5,
  22185. epsilontonos: 0x03AD,
  22186. equal: 0x003D,
  22187. equalmonospace: 0xFF1D,
  22188. equalsmall: 0xFE66,
  22189. equalsuperior: 0x207C,
  22190. equivalence: 0x2261,
  22191. erbopomofo: 0x3126,
  22192. ercyrillic: 0x0440,
  22193. ereversed: 0x0258,
  22194. ereversedcyrillic: 0x044D,
  22195. escyrillic: 0x0441,
  22196. esdescendercyrillic: 0x04AB,
  22197. esh: 0x0283,
  22198. eshcurl: 0x0286,
  22199. eshortdeva: 0x090E,
  22200. eshortvowelsigndeva: 0x0946,
  22201. eshreversedloop: 0x01AA,
  22202. eshsquatreversed: 0x0285,
  22203. esmallhiragana: 0x3047,
  22204. esmallkatakana: 0x30A7,
  22205. esmallkatakanahalfwidth: 0xFF6A,
  22206. estimated: 0x212E,
  22207. esuperior: 0xF6EC,
  22208. eta: 0x03B7,
  22209. etarmenian: 0x0568,
  22210. etatonos: 0x03AE,
  22211. eth: 0x00F0,
  22212. etilde: 0x1EBD,
  22213. etildebelow: 0x1E1B,
  22214. etnahtafoukhhebrew: 0x0591,
  22215. etnahtafoukhlefthebrew: 0x0591,
  22216. etnahtahebrew: 0x0591,
  22217. etnahtalefthebrew: 0x0591,
  22218. eturned: 0x01DD,
  22219. eukorean: 0x3161,
  22220. euro: 0x20AC,
  22221. evowelsignbengali: 0x09C7,
  22222. evowelsigndeva: 0x0947,
  22223. evowelsigngujarati: 0x0AC7,
  22224. exclam: 0x0021,
  22225. exclamarmenian: 0x055C,
  22226. exclamdbl: 0x203C,
  22227. exclamdown: 0x00A1,
  22228. exclamdownsmall: 0xF7A1,
  22229. exclammonospace: 0xFF01,
  22230. exclamsmall: 0xF721,
  22231. existential: 0x2203,
  22232. ezh: 0x0292,
  22233. ezhcaron: 0x01EF,
  22234. ezhcurl: 0x0293,
  22235. ezhreversed: 0x01B9,
  22236. ezhtail: 0x01BA,
  22237. f: 0x0066,
  22238. fadeva: 0x095E,
  22239. fagurmukhi: 0x0A5E,
  22240. fahrenheit: 0x2109,
  22241. fathaarabic: 0x064E,
  22242. fathalowarabic: 0x064E,
  22243. fathatanarabic: 0x064B,
  22244. fbopomofo: 0x3108,
  22245. fcircle: 0x24D5,
  22246. fdotaccent: 0x1E1F,
  22247. feharabic: 0x0641,
  22248. feharmenian: 0x0586,
  22249. fehfinalarabic: 0xFED2,
  22250. fehinitialarabic: 0xFED3,
  22251. fehmedialarabic: 0xFED4,
  22252. feicoptic: 0x03E5,
  22253. female: 0x2640,
  22254. ff: 0xFB00,
  22255. ffi: 0xFB03,
  22256. ffl: 0xFB04,
  22257. fi: 0xFB01,
  22258. fifteencircle: 0x246E,
  22259. fifteenparen: 0x2482,
  22260. fifteenperiod: 0x2496,
  22261. figuredash: 0x2012,
  22262. filledbox: 0x25A0,
  22263. filledrect: 0x25AC,
  22264. finalkaf: 0x05DA,
  22265. finalkafdagesh: 0xFB3A,
  22266. finalkafdageshhebrew: 0xFB3A,
  22267. finalkafhebrew: 0x05DA,
  22268. finalmem: 0x05DD,
  22269. finalmemhebrew: 0x05DD,
  22270. finalnun: 0x05DF,
  22271. finalnunhebrew: 0x05DF,
  22272. finalpe: 0x05E3,
  22273. finalpehebrew: 0x05E3,
  22274. finaltsadi: 0x05E5,
  22275. finaltsadihebrew: 0x05E5,
  22276. firsttonechinese: 0x02C9,
  22277. fisheye: 0x25C9,
  22278. fitacyrillic: 0x0473,
  22279. five: 0x0035,
  22280. fivearabic: 0x0665,
  22281. fivebengali: 0x09EB,
  22282. fivecircle: 0x2464,
  22283. fivecircleinversesansserif: 0x278E,
  22284. fivedeva: 0x096B,
  22285. fiveeighths: 0x215D,
  22286. fivegujarati: 0x0AEB,
  22287. fivegurmukhi: 0x0A6B,
  22288. fivehackarabic: 0x0665,
  22289. fivehangzhou: 0x3025,
  22290. fiveideographicparen: 0x3224,
  22291. fiveinferior: 0x2085,
  22292. fivemonospace: 0xFF15,
  22293. fiveoldstyle: 0xF735,
  22294. fiveparen: 0x2478,
  22295. fiveperiod: 0x248C,
  22296. fivepersian: 0x06F5,
  22297. fiveroman: 0x2174,
  22298. fivesuperior: 0x2075,
  22299. fivethai: 0x0E55,
  22300. fl: 0xFB02,
  22301. florin: 0x0192,
  22302. fmonospace: 0xFF46,
  22303. fmsquare: 0x3399,
  22304. fofanthai: 0x0E1F,
  22305. fofathai: 0x0E1D,
  22306. fongmanthai: 0x0E4F,
  22307. forall: 0x2200,
  22308. four: 0x0034,
  22309. fourarabic: 0x0664,
  22310. fourbengali: 0x09EA,
  22311. fourcircle: 0x2463,
  22312. fourcircleinversesansserif: 0x278D,
  22313. fourdeva: 0x096A,
  22314. fourgujarati: 0x0AEA,
  22315. fourgurmukhi: 0x0A6A,
  22316. fourhackarabic: 0x0664,
  22317. fourhangzhou: 0x3024,
  22318. fourideographicparen: 0x3223,
  22319. fourinferior: 0x2084,
  22320. fourmonospace: 0xFF14,
  22321. fournumeratorbengali: 0x09F7,
  22322. fouroldstyle: 0xF734,
  22323. fourparen: 0x2477,
  22324. fourperiod: 0x248B,
  22325. fourpersian: 0x06F4,
  22326. fourroman: 0x2173,
  22327. foursuperior: 0x2074,
  22328. fourteencircle: 0x246D,
  22329. fourteenparen: 0x2481,
  22330. fourteenperiod: 0x2495,
  22331. fourthai: 0x0E54,
  22332. fourthtonechinese: 0x02CB,
  22333. fparen: 0x24A1,
  22334. fraction: 0x2044,
  22335. franc: 0x20A3,
  22336. g: 0x0067,
  22337. gabengali: 0x0997,
  22338. gacute: 0x01F5,
  22339. gadeva: 0x0917,
  22340. gafarabic: 0x06AF,
  22341. gaffinalarabic: 0xFB93,
  22342. gafinitialarabic: 0xFB94,
  22343. gafmedialarabic: 0xFB95,
  22344. gagujarati: 0x0A97,
  22345. gagurmukhi: 0x0A17,
  22346. gahiragana: 0x304C,
  22347. gakatakana: 0x30AC,
  22348. gamma: 0x03B3,
  22349. gammalatinsmall: 0x0263,
  22350. gammasuperior: 0x02E0,
  22351. gangiacoptic: 0x03EB,
  22352. gbopomofo: 0x310D,
  22353. gbreve: 0x011F,
  22354. gcaron: 0x01E7,
  22355. gcedilla: 0x0123,
  22356. gcircle: 0x24D6,
  22357. gcircumflex: 0x011D,
  22358. gcommaaccent: 0x0123,
  22359. gdot: 0x0121,
  22360. gdotaccent: 0x0121,
  22361. gecyrillic: 0x0433,
  22362. gehiragana: 0x3052,
  22363. gekatakana: 0x30B2,
  22364. geometricallyequal: 0x2251,
  22365. gereshaccenthebrew: 0x059C,
  22366. gereshhebrew: 0x05F3,
  22367. gereshmuqdamhebrew: 0x059D,
  22368. germandbls: 0x00DF,
  22369. gershayimaccenthebrew: 0x059E,
  22370. gershayimhebrew: 0x05F4,
  22371. getamark: 0x3013,
  22372. ghabengali: 0x0998,
  22373. ghadarmenian: 0x0572,
  22374. ghadeva: 0x0918,
  22375. ghagujarati: 0x0A98,
  22376. ghagurmukhi: 0x0A18,
  22377. ghainarabic: 0x063A,
  22378. ghainfinalarabic: 0xFECE,
  22379. ghaininitialarabic: 0xFECF,
  22380. ghainmedialarabic: 0xFED0,
  22381. ghemiddlehookcyrillic: 0x0495,
  22382. ghestrokecyrillic: 0x0493,
  22383. gheupturncyrillic: 0x0491,
  22384. ghhadeva: 0x095A,
  22385. ghhagurmukhi: 0x0A5A,
  22386. ghook: 0x0260,
  22387. ghzsquare: 0x3393,
  22388. gihiragana: 0x304E,
  22389. gikatakana: 0x30AE,
  22390. gimarmenian: 0x0563,
  22391. gimel: 0x05D2,
  22392. gimeldagesh: 0xFB32,
  22393. gimeldageshhebrew: 0xFB32,
  22394. gimelhebrew: 0x05D2,
  22395. gjecyrillic: 0x0453,
  22396. glottalinvertedstroke: 0x01BE,
  22397. glottalstop: 0x0294,
  22398. glottalstopinverted: 0x0296,
  22399. glottalstopmod: 0x02C0,
  22400. glottalstopreversed: 0x0295,
  22401. glottalstopreversedmod: 0x02C1,
  22402. glottalstopreversedsuperior: 0x02E4,
  22403. glottalstopstroke: 0x02A1,
  22404. glottalstopstrokereversed: 0x02A2,
  22405. gmacron: 0x1E21,
  22406. gmonospace: 0xFF47,
  22407. gohiragana: 0x3054,
  22408. gokatakana: 0x30B4,
  22409. gparen: 0x24A2,
  22410. gpasquare: 0x33AC,
  22411. gradient: 0x2207,
  22412. grave: 0x0060,
  22413. gravebelowcmb: 0x0316,
  22414. gravecmb: 0x0300,
  22415. gravecomb: 0x0300,
  22416. gravedeva: 0x0953,
  22417. gravelowmod: 0x02CE,
  22418. gravemonospace: 0xFF40,
  22419. gravetonecmb: 0x0340,
  22420. greater: 0x003E,
  22421. greaterequal: 0x2265,
  22422. greaterequalorless: 0x22DB,
  22423. greatermonospace: 0xFF1E,
  22424. greaterorequivalent: 0x2273,
  22425. greaterorless: 0x2277,
  22426. greateroverequal: 0x2267,
  22427. greatersmall: 0xFE65,
  22428. gscript: 0x0261,
  22429. gstroke: 0x01E5,
  22430. guhiragana: 0x3050,
  22431. guillemotleft: 0x00AB,
  22432. guillemotright: 0x00BB,
  22433. guilsinglleft: 0x2039,
  22434. guilsinglright: 0x203A,
  22435. gukatakana: 0x30B0,
  22436. guramusquare: 0x3318,
  22437. gysquare: 0x33C9,
  22438. h: 0x0068,
  22439. haabkhasiancyrillic: 0x04A9,
  22440. haaltonearabic: 0x06C1,
  22441. habengali: 0x09B9,
  22442. hadescendercyrillic: 0x04B3,
  22443. hadeva: 0x0939,
  22444. hagujarati: 0x0AB9,
  22445. hagurmukhi: 0x0A39,
  22446. haharabic: 0x062D,
  22447. hahfinalarabic: 0xFEA2,
  22448. hahinitialarabic: 0xFEA3,
  22449. hahiragana: 0x306F,
  22450. hahmedialarabic: 0xFEA4,
  22451. haitusquare: 0x332A,
  22452. hakatakana: 0x30CF,
  22453. hakatakanahalfwidth: 0xFF8A,
  22454. halantgurmukhi: 0x0A4D,
  22455. hamzaarabic: 0x0621,
  22456. hamzalowarabic: 0x0621,
  22457. hangulfiller: 0x3164,
  22458. hardsigncyrillic: 0x044A,
  22459. harpoonleftbarbup: 0x21BC,
  22460. harpoonrightbarbup: 0x21C0,
  22461. hasquare: 0x33CA,
  22462. hatafpatah: 0x05B2,
  22463. hatafpatah16: 0x05B2,
  22464. hatafpatah23: 0x05B2,
  22465. hatafpatah2f: 0x05B2,
  22466. hatafpatahhebrew: 0x05B2,
  22467. hatafpatahnarrowhebrew: 0x05B2,
  22468. hatafpatahquarterhebrew: 0x05B2,
  22469. hatafpatahwidehebrew: 0x05B2,
  22470. hatafqamats: 0x05B3,
  22471. hatafqamats1b: 0x05B3,
  22472. hatafqamats28: 0x05B3,
  22473. hatafqamats34: 0x05B3,
  22474. hatafqamatshebrew: 0x05B3,
  22475. hatafqamatsnarrowhebrew: 0x05B3,
  22476. hatafqamatsquarterhebrew: 0x05B3,
  22477. hatafqamatswidehebrew: 0x05B3,
  22478. hatafsegol: 0x05B1,
  22479. hatafsegol17: 0x05B1,
  22480. hatafsegol24: 0x05B1,
  22481. hatafsegol30: 0x05B1,
  22482. hatafsegolhebrew: 0x05B1,
  22483. hatafsegolnarrowhebrew: 0x05B1,
  22484. hatafsegolquarterhebrew: 0x05B1,
  22485. hatafsegolwidehebrew: 0x05B1,
  22486. hbar: 0x0127,
  22487. hbopomofo: 0x310F,
  22488. hbrevebelow: 0x1E2B,
  22489. hcedilla: 0x1E29,
  22490. hcircle: 0x24D7,
  22491. hcircumflex: 0x0125,
  22492. hdieresis: 0x1E27,
  22493. hdotaccent: 0x1E23,
  22494. hdotbelow: 0x1E25,
  22495. he: 0x05D4,
  22496. heart: 0x2665,
  22497. heartsuitblack: 0x2665,
  22498. heartsuitwhite: 0x2661,
  22499. hedagesh: 0xFB34,
  22500. hedageshhebrew: 0xFB34,
  22501. hehaltonearabic: 0x06C1,
  22502. heharabic: 0x0647,
  22503. hehebrew: 0x05D4,
  22504. hehfinalaltonearabic: 0xFBA7,
  22505. hehfinalalttwoarabic: 0xFEEA,
  22506. hehfinalarabic: 0xFEEA,
  22507. hehhamzaabovefinalarabic: 0xFBA5,
  22508. hehhamzaaboveisolatedarabic: 0xFBA4,
  22509. hehinitialaltonearabic: 0xFBA8,
  22510. hehinitialarabic: 0xFEEB,
  22511. hehiragana: 0x3078,
  22512. hehmedialaltonearabic: 0xFBA9,
  22513. hehmedialarabic: 0xFEEC,
  22514. heiseierasquare: 0x337B,
  22515. hekatakana: 0x30D8,
  22516. hekatakanahalfwidth: 0xFF8D,
  22517. hekutaarusquare: 0x3336,
  22518. henghook: 0x0267,
  22519. herutusquare: 0x3339,
  22520. het: 0x05D7,
  22521. hethebrew: 0x05D7,
  22522. hhook: 0x0266,
  22523. hhooksuperior: 0x02B1,
  22524. hieuhacirclekorean: 0x327B,
  22525. hieuhaparenkorean: 0x321B,
  22526. hieuhcirclekorean: 0x326D,
  22527. hieuhkorean: 0x314E,
  22528. hieuhparenkorean: 0x320D,
  22529. hihiragana: 0x3072,
  22530. hikatakana: 0x30D2,
  22531. hikatakanahalfwidth: 0xFF8B,
  22532. hiriq: 0x05B4,
  22533. hiriq14: 0x05B4,
  22534. hiriq21: 0x05B4,
  22535. hiriq2d: 0x05B4,
  22536. hiriqhebrew: 0x05B4,
  22537. hiriqnarrowhebrew: 0x05B4,
  22538. hiriqquarterhebrew: 0x05B4,
  22539. hiriqwidehebrew: 0x05B4,
  22540. hlinebelow: 0x1E96,
  22541. hmonospace: 0xFF48,
  22542. hoarmenian: 0x0570,
  22543. hohipthai: 0x0E2B,
  22544. hohiragana: 0x307B,
  22545. hokatakana: 0x30DB,
  22546. hokatakanahalfwidth: 0xFF8E,
  22547. holam: 0x05B9,
  22548. holam19: 0x05B9,
  22549. holam26: 0x05B9,
  22550. holam32: 0x05B9,
  22551. holamhebrew: 0x05B9,
  22552. holamnarrowhebrew: 0x05B9,
  22553. holamquarterhebrew: 0x05B9,
  22554. holamwidehebrew: 0x05B9,
  22555. honokhukthai: 0x0E2E,
  22556. hookabovecomb: 0x0309,
  22557. hookcmb: 0x0309,
  22558. hookpalatalizedbelowcmb: 0x0321,
  22559. hookretroflexbelowcmb: 0x0322,
  22560. hoonsquare: 0x3342,
  22561. horicoptic: 0x03E9,
  22562. horizontalbar: 0x2015,
  22563. horncmb: 0x031B,
  22564. hotsprings: 0x2668,
  22565. house: 0x2302,
  22566. hparen: 0x24A3,
  22567. hsuperior: 0x02B0,
  22568. hturned: 0x0265,
  22569. huhiragana: 0x3075,
  22570. huiitosquare: 0x3333,
  22571. hukatakana: 0x30D5,
  22572. hukatakanahalfwidth: 0xFF8C,
  22573. hungarumlaut: 0x02DD,
  22574. hungarumlautcmb: 0x030B,
  22575. hv: 0x0195,
  22576. hyphen: 0x002D,
  22577. hypheninferior: 0xF6E5,
  22578. hyphenmonospace: 0xFF0D,
  22579. hyphensmall: 0xFE63,
  22580. hyphensuperior: 0xF6E6,
  22581. hyphentwo: 0x2010,
  22582. i: 0x0069,
  22583. iacute: 0x00ED,
  22584. iacyrillic: 0x044F,
  22585. ibengali: 0x0987,
  22586. ibopomofo: 0x3127,
  22587. ibreve: 0x012D,
  22588. icaron: 0x01D0,
  22589. icircle: 0x24D8,
  22590. icircumflex: 0x00EE,
  22591. icyrillic: 0x0456,
  22592. idblgrave: 0x0209,
  22593. ideographearthcircle: 0x328F,
  22594. ideographfirecircle: 0x328B,
  22595. ideographicallianceparen: 0x323F,
  22596. ideographiccallparen: 0x323A,
  22597. ideographiccentrecircle: 0x32A5,
  22598. ideographicclose: 0x3006,
  22599. ideographiccomma: 0x3001,
  22600. ideographiccommaleft: 0xFF64,
  22601. ideographiccongratulationparen: 0x3237,
  22602. ideographiccorrectcircle: 0x32A3,
  22603. ideographicearthparen: 0x322F,
  22604. ideographicenterpriseparen: 0x323D,
  22605. ideographicexcellentcircle: 0x329D,
  22606. ideographicfestivalparen: 0x3240,
  22607. ideographicfinancialcircle: 0x3296,
  22608. ideographicfinancialparen: 0x3236,
  22609. ideographicfireparen: 0x322B,
  22610. ideographichaveparen: 0x3232,
  22611. ideographichighcircle: 0x32A4,
  22612. ideographiciterationmark: 0x3005,
  22613. ideographiclaborcircle: 0x3298,
  22614. ideographiclaborparen: 0x3238,
  22615. ideographicleftcircle: 0x32A7,
  22616. ideographiclowcircle: 0x32A6,
  22617. ideographicmedicinecircle: 0x32A9,
  22618. ideographicmetalparen: 0x322E,
  22619. ideographicmoonparen: 0x322A,
  22620. ideographicnameparen: 0x3234,
  22621. ideographicperiod: 0x3002,
  22622. ideographicprintcircle: 0x329E,
  22623. ideographicreachparen: 0x3243,
  22624. ideographicrepresentparen: 0x3239,
  22625. ideographicresourceparen: 0x323E,
  22626. ideographicrightcircle: 0x32A8,
  22627. ideographicsecretcircle: 0x3299,
  22628. ideographicselfparen: 0x3242,
  22629. ideographicsocietyparen: 0x3233,
  22630. ideographicspace: 0x3000,
  22631. ideographicspecialparen: 0x3235,
  22632. ideographicstockparen: 0x3231,
  22633. ideographicstudyparen: 0x323B,
  22634. ideographicsunparen: 0x3230,
  22635. ideographicsuperviseparen: 0x323C,
  22636. ideographicwaterparen: 0x322C,
  22637. ideographicwoodparen: 0x322D,
  22638. ideographiczero: 0x3007,
  22639. ideographmetalcircle: 0x328E,
  22640. ideographmooncircle: 0x328A,
  22641. ideographnamecircle: 0x3294,
  22642. ideographsuncircle: 0x3290,
  22643. ideographwatercircle: 0x328C,
  22644. ideographwoodcircle: 0x328D,
  22645. ideva: 0x0907,
  22646. idieresis: 0x00EF,
  22647. idieresisacute: 0x1E2F,
  22648. idieresiscyrillic: 0x04E5,
  22649. idotbelow: 0x1ECB,
  22650. iebrevecyrillic: 0x04D7,
  22651. iecyrillic: 0x0435,
  22652. ieungacirclekorean: 0x3275,
  22653. ieungaparenkorean: 0x3215,
  22654. ieungcirclekorean: 0x3267,
  22655. ieungkorean: 0x3147,
  22656. ieungparenkorean: 0x3207,
  22657. igrave: 0x00EC,
  22658. igujarati: 0x0A87,
  22659. igurmukhi: 0x0A07,
  22660. ihiragana: 0x3044,
  22661. ihookabove: 0x1EC9,
  22662. iibengali: 0x0988,
  22663. iicyrillic: 0x0438,
  22664. iideva: 0x0908,
  22665. iigujarati: 0x0A88,
  22666. iigurmukhi: 0x0A08,
  22667. iimatragurmukhi: 0x0A40,
  22668. iinvertedbreve: 0x020B,
  22669. iishortcyrillic: 0x0439,
  22670. iivowelsignbengali: 0x09C0,
  22671. iivowelsigndeva: 0x0940,
  22672. iivowelsigngujarati: 0x0AC0,
  22673. ij: 0x0133,
  22674. ikatakana: 0x30A4,
  22675. ikatakanahalfwidth: 0xFF72,
  22676. ikorean: 0x3163,
  22677. ilde: 0x02DC,
  22678. iluyhebrew: 0x05AC,
  22679. imacron: 0x012B,
  22680. imacroncyrillic: 0x04E3,
  22681. imageorapproximatelyequal: 0x2253,
  22682. imatragurmukhi: 0x0A3F,
  22683. imonospace: 0xFF49,
  22684. increment: 0x2206,
  22685. infinity: 0x221E,
  22686. iniarmenian: 0x056B,
  22687. integral: 0x222B,
  22688. integralbottom: 0x2321,
  22689. integralbt: 0x2321,
  22690. integralex: 0xF8F5,
  22691. integraltop: 0x2320,
  22692. integraltp: 0x2320,
  22693. intersection: 0x2229,
  22694. intisquare: 0x3305,
  22695. invbullet: 0x25D8,
  22696. invcircle: 0x25D9,
  22697. invsmileface: 0x263B,
  22698. iocyrillic: 0x0451,
  22699. iogonek: 0x012F,
  22700. iota: 0x03B9,
  22701. iotadieresis: 0x03CA,
  22702. iotadieresistonos: 0x0390,
  22703. iotalatin: 0x0269,
  22704. iotatonos: 0x03AF,
  22705. iparen: 0x24A4,
  22706. irigurmukhi: 0x0A72,
  22707. ismallhiragana: 0x3043,
  22708. ismallkatakana: 0x30A3,
  22709. ismallkatakanahalfwidth: 0xFF68,
  22710. issharbengali: 0x09FA,
  22711. istroke: 0x0268,
  22712. isuperior: 0xF6ED,
  22713. iterationhiragana: 0x309D,
  22714. iterationkatakana: 0x30FD,
  22715. itilde: 0x0129,
  22716. itildebelow: 0x1E2D,
  22717. iubopomofo: 0x3129,
  22718. iucyrillic: 0x044E,
  22719. ivowelsignbengali: 0x09BF,
  22720. ivowelsigndeva: 0x093F,
  22721. ivowelsigngujarati: 0x0ABF,
  22722. izhitsacyrillic: 0x0475,
  22723. izhitsadblgravecyrillic: 0x0477,
  22724. j: 0x006A,
  22725. jaarmenian: 0x0571,
  22726. jabengali: 0x099C,
  22727. jadeva: 0x091C,
  22728. jagujarati: 0x0A9C,
  22729. jagurmukhi: 0x0A1C,
  22730. jbopomofo: 0x3110,
  22731. jcaron: 0x01F0,
  22732. jcircle: 0x24D9,
  22733. jcircumflex: 0x0135,
  22734. jcrossedtail: 0x029D,
  22735. jdotlessstroke: 0x025F,
  22736. jecyrillic: 0x0458,
  22737. jeemarabic: 0x062C,
  22738. jeemfinalarabic: 0xFE9E,
  22739. jeeminitialarabic: 0xFE9F,
  22740. jeemmedialarabic: 0xFEA0,
  22741. jeharabic: 0x0698,
  22742. jehfinalarabic: 0xFB8B,
  22743. jhabengali: 0x099D,
  22744. jhadeva: 0x091D,
  22745. jhagujarati: 0x0A9D,
  22746. jhagurmukhi: 0x0A1D,
  22747. jheharmenian: 0x057B,
  22748. jis: 0x3004,
  22749. jmonospace: 0xFF4A,
  22750. jparen: 0x24A5,
  22751. jsuperior: 0x02B2,
  22752. k: 0x006B,
  22753. kabashkircyrillic: 0x04A1,
  22754. kabengali: 0x0995,
  22755. kacute: 0x1E31,
  22756. kacyrillic: 0x043A,
  22757. kadescendercyrillic: 0x049B,
  22758. kadeva: 0x0915,
  22759. kaf: 0x05DB,
  22760. kafarabic: 0x0643,
  22761. kafdagesh: 0xFB3B,
  22762. kafdageshhebrew: 0xFB3B,
  22763. kaffinalarabic: 0xFEDA,
  22764. kafhebrew: 0x05DB,
  22765. kafinitialarabic: 0xFEDB,
  22766. kafmedialarabic: 0xFEDC,
  22767. kafrafehebrew: 0xFB4D,
  22768. kagujarati: 0x0A95,
  22769. kagurmukhi: 0x0A15,
  22770. kahiragana: 0x304B,
  22771. kahookcyrillic: 0x04C4,
  22772. kakatakana: 0x30AB,
  22773. kakatakanahalfwidth: 0xFF76,
  22774. kappa: 0x03BA,
  22775. kappasymbolgreek: 0x03F0,
  22776. kapyeounmieumkorean: 0x3171,
  22777. kapyeounphieuphkorean: 0x3184,
  22778. kapyeounpieupkorean: 0x3178,
  22779. kapyeounssangpieupkorean: 0x3179,
  22780. karoriisquare: 0x330D,
  22781. kashidaautoarabic: 0x0640,
  22782. kashidaautonosidebearingarabic: 0x0640,
  22783. kasmallkatakana: 0x30F5,
  22784. kasquare: 0x3384,
  22785. kasraarabic: 0x0650,
  22786. kasratanarabic: 0x064D,
  22787. kastrokecyrillic: 0x049F,
  22788. katahiraprolongmarkhalfwidth: 0xFF70,
  22789. kaverticalstrokecyrillic: 0x049D,
  22790. kbopomofo: 0x310E,
  22791. kcalsquare: 0x3389,
  22792. kcaron: 0x01E9,
  22793. kcedilla: 0x0137,
  22794. kcircle: 0x24DA,
  22795. kcommaaccent: 0x0137,
  22796. kdotbelow: 0x1E33,
  22797. keharmenian: 0x0584,
  22798. kehiragana: 0x3051,
  22799. kekatakana: 0x30B1,
  22800. kekatakanahalfwidth: 0xFF79,
  22801. kenarmenian: 0x056F,
  22802. kesmallkatakana: 0x30F6,
  22803. kgreenlandic: 0x0138,
  22804. khabengali: 0x0996,
  22805. khacyrillic: 0x0445,
  22806. khadeva: 0x0916,
  22807. khagujarati: 0x0A96,
  22808. khagurmukhi: 0x0A16,
  22809. khaharabic: 0x062E,
  22810. khahfinalarabic: 0xFEA6,
  22811. khahinitialarabic: 0xFEA7,
  22812. khahmedialarabic: 0xFEA8,
  22813. kheicoptic: 0x03E7,
  22814. khhadeva: 0x0959,
  22815. khhagurmukhi: 0x0A59,
  22816. khieukhacirclekorean: 0x3278,
  22817. khieukhaparenkorean: 0x3218,
  22818. khieukhcirclekorean: 0x326A,
  22819. khieukhkorean: 0x314B,
  22820. khieukhparenkorean: 0x320A,
  22821. khokhaithai: 0x0E02,
  22822. khokhonthai: 0x0E05,
  22823. khokhuatthai: 0x0E03,
  22824. khokhwaithai: 0x0E04,
  22825. khomutthai: 0x0E5B,
  22826. khook: 0x0199,
  22827. khorakhangthai: 0x0E06,
  22828. khzsquare: 0x3391,
  22829. kihiragana: 0x304D,
  22830. kikatakana: 0x30AD,
  22831. kikatakanahalfwidth: 0xFF77,
  22832. kiroguramusquare: 0x3315,
  22833. kiromeetorusquare: 0x3316,
  22834. kirosquare: 0x3314,
  22835. kiyeokacirclekorean: 0x326E,
  22836. kiyeokaparenkorean: 0x320E,
  22837. kiyeokcirclekorean: 0x3260,
  22838. kiyeokkorean: 0x3131,
  22839. kiyeokparenkorean: 0x3200,
  22840. kiyeoksioskorean: 0x3133,
  22841. kjecyrillic: 0x045C,
  22842. klinebelow: 0x1E35,
  22843. klsquare: 0x3398,
  22844. kmcubedsquare: 0x33A6,
  22845. kmonospace: 0xFF4B,
  22846. kmsquaredsquare: 0x33A2,
  22847. kohiragana: 0x3053,
  22848. kohmsquare: 0x33C0,
  22849. kokaithai: 0x0E01,
  22850. kokatakana: 0x30B3,
  22851. kokatakanahalfwidth: 0xFF7A,
  22852. kooposquare: 0x331E,
  22853. koppacyrillic: 0x0481,
  22854. koreanstandardsymbol: 0x327F,
  22855. koroniscmb: 0x0343,
  22856. kparen: 0x24A6,
  22857. kpasquare: 0x33AA,
  22858. ksicyrillic: 0x046F,
  22859. ktsquare: 0x33CF,
  22860. kturned: 0x029E,
  22861. kuhiragana: 0x304F,
  22862. kukatakana: 0x30AF,
  22863. kukatakanahalfwidth: 0xFF78,
  22864. kvsquare: 0x33B8,
  22865. kwsquare: 0x33BE,
  22866. l: 0x006C,
  22867. labengali: 0x09B2,
  22868. lacute: 0x013A,
  22869. ladeva: 0x0932,
  22870. lagujarati: 0x0AB2,
  22871. lagurmukhi: 0x0A32,
  22872. lakkhangyaothai: 0x0E45,
  22873. lamaleffinalarabic: 0xFEFC,
  22874. lamalefhamzaabovefinalarabic: 0xFEF8,
  22875. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22876. lamalefhamzabelowfinalarabic: 0xFEFA,
  22877. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22878. lamalefisolatedarabic: 0xFEFB,
  22879. lamalefmaddaabovefinalarabic: 0xFEF6,
  22880. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22881. lamarabic: 0x0644,
  22882. lambda: 0x03BB,
  22883. lambdastroke: 0x019B,
  22884. lamed: 0x05DC,
  22885. lameddagesh: 0xFB3C,
  22886. lameddageshhebrew: 0xFB3C,
  22887. lamedhebrew: 0x05DC,
  22888. lamfinalarabic: 0xFEDE,
  22889. lamhahinitialarabic: 0xFCCA,
  22890. laminitialarabic: 0xFEDF,
  22891. lamjeeminitialarabic: 0xFCC9,
  22892. lamkhahinitialarabic: 0xFCCB,
  22893. lamlamhehisolatedarabic: 0xFDF2,
  22894. lammedialarabic: 0xFEE0,
  22895. lammeemhahinitialarabic: 0xFD88,
  22896. lammeeminitialarabic: 0xFCCC,
  22897. largecircle: 0x25EF,
  22898. lbar: 0x019A,
  22899. lbelt: 0x026C,
  22900. lbopomofo: 0x310C,
  22901. lcaron: 0x013E,
  22902. lcedilla: 0x013C,
  22903. lcircle: 0x24DB,
  22904. lcircumflexbelow: 0x1E3D,
  22905. lcommaaccent: 0x013C,
  22906. ldot: 0x0140,
  22907. ldotaccent: 0x0140,
  22908. ldotbelow: 0x1E37,
  22909. ldotbelowmacron: 0x1E39,
  22910. leftangleabovecmb: 0x031A,
  22911. lefttackbelowcmb: 0x0318,
  22912. less: 0x003C,
  22913. lessequal: 0x2264,
  22914. lessequalorgreater: 0x22DA,
  22915. lessmonospace: 0xFF1C,
  22916. lessorequivalent: 0x2272,
  22917. lessorgreater: 0x2276,
  22918. lessoverequal: 0x2266,
  22919. lesssmall: 0xFE64,
  22920. lezh: 0x026E,
  22921. lfblock: 0x258C,
  22922. lhookretroflex: 0x026D,
  22923. lira: 0x20A4,
  22924. liwnarmenian: 0x056C,
  22925. lj: 0x01C9,
  22926. ljecyrillic: 0x0459,
  22927. ll: 0xF6C0,
  22928. lladeva: 0x0933,
  22929. llagujarati: 0x0AB3,
  22930. llinebelow: 0x1E3B,
  22931. llladeva: 0x0934,
  22932. llvocalicbengali: 0x09E1,
  22933. llvocalicdeva: 0x0961,
  22934. llvocalicvowelsignbengali: 0x09E3,
  22935. llvocalicvowelsigndeva: 0x0963,
  22936. lmiddletilde: 0x026B,
  22937. lmonospace: 0xFF4C,
  22938. lmsquare: 0x33D0,
  22939. lochulathai: 0x0E2C,
  22940. logicaland: 0x2227,
  22941. logicalnot: 0x00AC,
  22942. logicalnotreversed: 0x2310,
  22943. logicalor: 0x2228,
  22944. lolingthai: 0x0E25,
  22945. longs: 0x017F,
  22946. lowlinecenterline: 0xFE4E,
  22947. lowlinecmb: 0x0332,
  22948. lowlinedashed: 0xFE4D,
  22949. lozenge: 0x25CA,
  22950. lparen: 0x24A7,
  22951. lslash: 0x0142,
  22952. lsquare: 0x2113,
  22953. lsuperior: 0xF6EE,
  22954. ltshade: 0x2591,
  22955. luthai: 0x0E26,
  22956. lvocalicbengali: 0x098C,
  22957. lvocalicdeva: 0x090C,
  22958. lvocalicvowelsignbengali: 0x09E2,
  22959. lvocalicvowelsigndeva: 0x0962,
  22960. lxsquare: 0x33D3,
  22961. m: 0x006D,
  22962. mabengali: 0x09AE,
  22963. macron: 0x00AF,
  22964. macronbelowcmb: 0x0331,
  22965. macroncmb: 0x0304,
  22966. macronlowmod: 0x02CD,
  22967. macronmonospace: 0xFFE3,
  22968. macute: 0x1E3F,
  22969. madeva: 0x092E,
  22970. magujarati: 0x0AAE,
  22971. magurmukhi: 0x0A2E,
  22972. mahapakhhebrew: 0x05A4,
  22973. mahapakhlefthebrew: 0x05A4,
  22974. mahiragana: 0x307E,
  22975. maichattawalowleftthai: 0xF895,
  22976. maichattawalowrightthai: 0xF894,
  22977. maichattawathai: 0x0E4B,
  22978. maichattawaupperleftthai: 0xF893,
  22979. maieklowleftthai: 0xF88C,
  22980. maieklowrightthai: 0xF88B,
  22981. maiekthai: 0x0E48,
  22982. maiekupperleftthai: 0xF88A,
  22983. maihanakatleftthai: 0xF884,
  22984. maihanakatthai: 0x0E31,
  22985. maitaikhuleftthai: 0xF889,
  22986. maitaikhuthai: 0x0E47,
  22987. maitholowleftthai: 0xF88F,
  22988. maitholowrightthai: 0xF88E,
  22989. maithothai: 0x0E49,
  22990. maithoupperleftthai: 0xF88D,
  22991. maitrilowleftthai: 0xF892,
  22992. maitrilowrightthai: 0xF891,
  22993. maitrithai: 0x0E4A,
  22994. maitriupperleftthai: 0xF890,
  22995. maiyamokthai: 0x0E46,
  22996. makatakana: 0x30DE,
  22997. makatakanahalfwidth: 0xFF8F,
  22998. male: 0x2642,
  22999. mansyonsquare: 0x3347,
  23000. maqafhebrew: 0x05BE,
  23001. mars: 0x2642,
  23002. masoracirclehebrew: 0x05AF,
  23003. masquare: 0x3383,
  23004. mbopomofo: 0x3107,
  23005. mbsquare: 0x33D4,
  23006. mcircle: 0x24DC,
  23007. mcubedsquare: 0x33A5,
  23008. mdotaccent: 0x1E41,
  23009. mdotbelow: 0x1E43,
  23010. meemarabic: 0x0645,
  23011. meemfinalarabic: 0xFEE2,
  23012. meeminitialarabic: 0xFEE3,
  23013. meemmedialarabic: 0xFEE4,
  23014. meemmeeminitialarabic: 0xFCD1,
  23015. meemmeemisolatedarabic: 0xFC48,
  23016. meetorusquare: 0x334D,
  23017. mehiragana: 0x3081,
  23018. meizierasquare: 0x337E,
  23019. mekatakana: 0x30E1,
  23020. mekatakanahalfwidth: 0xFF92,
  23021. mem: 0x05DE,
  23022. memdagesh: 0xFB3E,
  23023. memdageshhebrew: 0xFB3E,
  23024. memhebrew: 0x05DE,
  23025. menarmenian: 0x0574,
  23026. merkhahebrew: 0x05A5,
  23027. merkhakefulahebrew: 0x05A6,
  23028. merkhakefulalefthebrew: 0x05A6,
  23029. merkhalefthebrew: 0x05A5,
  23030. mhook: 0x0271,
  23031. mhzsquare: 0x3392,
  23032. middledotkatakanahalfwidth: 0xFF65,
  23033. middot: 0x00B7,
  23034. mieumacirclekorean: 0x3272,
  23035. mieumaparenkorean: 0x3212,
  23036. mieumcirclekorean: 0x3264,
  23037. mieumkorean: 0x3141,
  23038. mieumpansioskorean: 0x3170,
  23039. mieumparenkorean: 0x3204,
  23040. mieumpieupkorean: 0x316E,
  23041. mieumsioskorean: 0x316F,
  23042. mihiragana: 0x307F,
  23043. mikatakana: 0x30DF,
  23044. mikatakanahalfwidth: 0xFF90,
  23045. minus: 0x2212,
  23046. minusbelowcmb: 0x0320,
  23047. minuscircle: 0x2296,
  23048. minusmod: 0x02D7,
  23049. minusplus: 0x2213,
  23050. minute: 0x2032,
  23051. miribaarusquare: 0x334A,
  23052. mirisquare: 0x3349,
  23053. mlonglegturned: 0x0270,
  23054. mlsquare: 0x3396,
  23055. mmcubedsquare: 0x33A3,
  23056. mmonospace: 0xFF4D,
  23057. mmsquaredsquare: 0x339F,
  23058. mohiragana: 0x3082,
  23059. mohmsquare: 0x33C1,
  23060. mokatakana: 0x30E2,
  23061. mokatakanahalfwidth: 0xFF93,
  23062. molsquare: 0x33D6,
  23063. momathai: 0x0E21,
  23064. moverssquare: 0x33A7,
  23065. moverssquaredsquare: 0x33A8,
  23066. mparen: 0x24A8,
  23067. mpasquare: 0x33AB,
  23068. mssquare: 0x33B3,
  23069. msuperior: 0xF6EF,
  23070. mturned: 0x026F,
  23071. mu: 0x00B5,
  23072. mu1: 0x00B5,
  23073. muasquare: 0x3382,
  23074. muchgreater: 0x226B,
  23075. muchless: 0x226A,
  23076. mufsquare: 0x338C,
  23077. mugreek: 0x03BC,
  23078. mugsquare: 0x338D,
  23079. muhiragana: 0x3080,
  23080. mukatakana: 0x30E0,
  23081. mukatakanahalfwidth: 0xFF91,
  23082. mulsquare: 0x3395,
  23083. multiply: 0x00D7,
  23084. mumsquare: 0x339B,
  23085. munahhebrew: 0x05A3,
  23086. munahlefthebrew: 0x05A3,
  23087. musicalnote: 0x266A,
  23088. musicalnotedbl: 0x266B,
  23089. musicflatsign: 0x266D,
  23090. musicsharpsign: 0x266F,
  23091. mussquare: 0x33B2,
  23092. muvsquare: 0x33B6,
  23093. muwsquare: 0x33BC,
  23094. mvmegasquare: 0x33B9,
  23095. mvsquare: 0x33B7,
  23096. mwmegasquare: 0x33BF,
  23097. mwsquare: 0x33BD,
  23098. n: 0x006E,
  23099. nabengali: 0x09A8,
  23100. nabla: 0x2207,
  23101. nacute: 0x0144,
  23102. nadeva: 0x0928,
  23103. nagujarati: 0x0AA8,
  23104. nagurmukhi: 0x0A28,
  23105. nahiragana: 0x306A,
  23106. nakatakana: 0x30CA,
  23107. nakatakanahalfwidth: 0xFF85,
  23108. napostrophe: 0x0149,
  23109. nasquare: 0x3381,
  23110. nbopomofo: 0x310B,
  23111. nbspace: 0x00A0,
  23112. ncaron: 0x0148,
  23113. ncedilla: 0x0146,
  23114. ncircle: 0x24DD,
  23115. ncircumflexbelow: 0x1E4B,
  23116. ncommaaccent: 0x0146,
  23117. ndotaccent: 0x1E45,
  23118. ndotbelow: 0x1E47,
  23119. nehiragana: 0x306D,
  23120. nekatakana: 0x30CD,
  23121. nekatakanahalfwidth: 0xFF88,
  23122. newsheqelsign: 0x20AA,
  23123. nfsquare: 0x338B,
  23124. ngabengali: 0x0999,
  23125. ngadeva: 0x0919,
  23126. ngagujarati: 0x0A99,
  23127. ngagurmukhi: 0x0A19,
  23128. ngonguthai: 0x0E07,
  23129. nhiragana: 0x3093,
  23130. nhookleft: 0x0272,
  23131. nhookretroflex: 0x0273,
  23132. nieunacirclekorean: 0x326F,
  23133. nieunaparenkorean: 0x320F,
  23134. nieuncieuckorean: 0x3135,
  23135. nieuncirclekorean: 0x3261,
  23136. nieunhieuhkorean: 0x3136,
  23137. nieunkorean: 0x3134,
  23138. nieunpansioskorean: 0x3168,
  23139. nieunparenkorean: 0x3201,
  23140. nieunsioskorean: 0x3167,
  23141. nieuntikeutkorean: 0x3166,
  23142. nihiragana: 0x306B,
  23143. nikatakana: 0x30CB,
  23144. nikatakanahalfwidth: 0xFF86,
  23145. nikhahitleftthai: 0xF899,
  23146. nikhahitthai: 0x0E4D,
  23147. nine: 0x0039,
  23148. ninearabic: 0x0669,
  23149. ninebengali: 0x09EF,
  23150. ninecircle: 0x2468,
  23151. ninecircleinversesansserif: 0x2792,
  23152. ninedeva: 0x096F,
  23153. ninegujarati: 0x0AEF,
  23154. ninegurmukhi: 0x0A6F,
  23155. ninehackarabic: 0x0669,
  23156. ninehangzhou: 0x3029,
  23157. nineideographicparen: 0x3228,
  23158. nineinferior: 0x2089,
  23159. ninemonospace: 0xFF19,
  23160. nineoldstyle: 0xF739,
  23161. nineparen: 0x247C,
  23162. nineperiod: 0x2490,
  23163. ninepersian: 0x06F9,
  23164. nineroman: 0x2178,
  23165. ninesuperior: 0x2079,
  23166. nineteencircle: 0x2472,
  23167. nineteenparen: 0x2486,
  23168. nineteenperiod: 0x249A,
  23169. ninethai: 0x0E59,
  23170. nj: 0x01CC,
  23171. njecyrillic: 0x045A,
  23172. nkatakana: 0x30F3,
  23173. nkatakanahalfwidth: 0xFF9D,
  23174. nlegrightlong: 0x019E,
  23175. nlinebelow: 0x1E49,
  23176. nmonospace: 0xFF4E,
  23177. nmsquare: 0x339A,
  23178. nnabengali: 0x09A3,
  23179. nnadeva: 0x0923,
  23180. nnagujarati: 0x0AA3,
  23181. nnagurmukhi: 0x0A23,
  23182. nnnadeva: 0x0929,
  23183. nohiragana: 0x306E,
  23184. nokatakana: 0x30CE,
  23185. nokatakanahalfwidth: 0xFF89,
  23186. nonbreakingspace: 0x00A0,
  23187. nonenthai: 0x0E13,
  23188. nonuthai: 0x0E19,
  23189. noonarabic: 0x0646,
  23190. noonfinalarabic: 0xFEE6,
  23191. noonghunnaarabic: 0x06BA,
  23192. noonghunnafinalarabic: 0xFB9F,
  23193. nooninitialarabic: 0xFEE7,
  23194. noonjeeminitialarabic: 0xFCD2,
  23195. noonjeemisolatedarabic: 0xFC4B,
  23196. noonmedialarabic: 0xFEE8,
  23197. noonmeeminitialarabic: 0xFCD5,
  23198. noonmeemisolatedarabic: 0xFC4E,
  23199. noonnoonfinalarabic: 0xFC8D,
  23200. notcontains: 0x220C,
  23201. notelement: 0x2209,
  23202. notelementof: 0x2209,
  23203. notequal: 0x2260,
  23204. notgreater: 0x226F,
  23205. notgreaternorequal: 0x2271,
  23206. notgreaternorless: 0x2279,
  23207. notidentical: 0x2262,
  23208. notless: 0x226E,
  23209. notlessnorequal: 0x2270,
  23210. notparallel: 0x2226,
  23211. notprecedes: 0x2280,
  23212. notsubset: 0x2284,
  23213. notsucceeds: 0x2281,
  23214. notsuperset: 0x2285,
  23215. nowarmenian: 0x0576,
  23216. nparen: 0x24A9,
  23217. nssquare: 0x33B1,
  23218. nsuperior: 0x207F,
  23219. ntilde: 0x00F1,
  23220. nu: 0x03BD,
  23221. nuhiragana: 0x306C,
  23222. nukatakana: 0x30CC,
  23223. nukatakanahalfwidth: 0xFF87,
  23224. nuktabengali: 0x09BC,
  23225. nuktadeva: 0x093C,
  23226. nuktagujarati: 0x0ABC,
  23227. nuktagurmukhi: 0x0A3C,
  23228. numbersign: 0x0023,
  23229. numbersignmonospace: 0xFF03,
  23230. numbersignsmall: 0xFE5F,
  23231. numeralsigngreek: 0x0374,
  23232. numeralsignlowergreek: 0x0375,
  23233. numero: 0x2116,
  23234. nun: 0x05E0,
  23235. nundagesh: 0xFB40,
  23236. nundageshhebrew: 0xFB40,
  23237. nunhebrew: 0x05E0,
  23238. nvsquare: 0x33B5,
  23239. nwsquare: 0x33BB,
  23240. nyabengali: 0x099E,
  23241. nyadeva: 0x091E,
  23242. nyagujarati: 0x0A9E,
  23243. nyagurmukhi: 0x0A1E,
  23244. o: 0x006F,
  23245. oacute: 0x00F3,
  23246. oangthai: 0x0E2D,
  23247. obarred: 0x0275,
  23248. obarredcyrillic: 0x04E9,
  23249. obarreddieresiscyrillic: 0x04EB,
  23250. obengali: 0x0993,
  23251. obopomofo: 0x311B,
  23252. obreve: 0x014F,
  23253. ocandradeva: 0x0911,
  23254. ocandragujarati: 0x0A91,
  23255. ocandravowelsigndeva: 0x0949,
  23256. ocandravowelsigngujarati: 0x0AC9,
  23257. ocaron: 0x01D2,
  23258. ocircle: 0x24DE,
  23259. ocircumflex: 0x00F4,
  23260. ocircumflexacute: 0x1ED1,
  23261. ocircumflexdotbelow: 0x1ED9,
  23262. ocircumflexgrave: 0x1ED3,
  23263. ocircumflexhookabove: 0x1ED5,
  23264. ocircumflextilde: 0x1ED7,
  23265. ocyrillic: 0x043E,
  23266. odblacute: 0x0151,
  23267. odblgrave: 0x020D,
  23268. odeva: 0x0913,
  23269. odieresis: 0x00F6,
  23270. odieresiscyrillic: 0x04E7,
  23271. odotbelow: 0x1ECD,
  23272. oe: 0x0153,
  23273. oekorean: 0x315A,
  23274. ogonek: 0x02DB,
  23275. ogonekcmb: 0x0328,
  23276. ograve: 0x00F2,
  23277. ogujarati: 0x0A93,
  23278. oharmenian: 0x0585,
  23279. ohiragana: 0x304A,
  23280. ohookabove: 0x1ECF,
  23281. ohorn: 0x01A1,
  23282. ohornacute: 0x1EDB,
  23283. ohorndotbelow: 0x1EE3,
  23284. ohorngrave: 0x1EDD,
  23285. ohornhookabove: 0x1EDF,
  23286. ohorntilde: 0x1EE1,
  23287. ohungarumlaut: 0x0151,
  23288. oi: 0x01A3,
  23289. oinvertedbreve: 0x020F,
  23290. okatakana: 0x30AA,
  23291. okatakanahalfwidth: 0xFF75,
  23292. okorean: 0x3157,
  23293. olehebrew: 0x05AB,
  23294. omacron: 0x014D,
  23295. omacronacute: 0x1E53,
  23296. omacrongrave: 0x1E51,
  23297. omdeva: 0x0950,
  23298. omega: 0x03C9,
  23299. omega1: 0x03D6,
  23300. omegacyrillic: 0x0461,
  23301. omegalatinclosed: 0x0277,
  23302. omegaroundcyrillic: 0x047B,
  23303. omegatitlocyrillic: 0x047D,
  23304. omegatonos: 0x03CE,
  23305. omgujarati: 0x0AD0,
  23306. omicron: 0x03BF,
  23307. omicrontonos: 0x03CC,
  23308. omonospace: 0xFF4F,
  23309. one: 0x0031,
  23310. onearabic: 0x0661,
  23311. onebengali: 0x09E7,
  23312. onecircle: 0x2460,
  23313. onecircleinversesansserif: 0x278A,
  23314. onedeva: 0x0967,
  23315. onedotenleader: 0x2024,
  23316. oneeighth: 0x215B,
  23317. onefitted: 0xF6DC,
  23318. onegujarati: 0x0AE7,
  23319. onegurmukhi: 0x0A67,
  23320. onehackarabic: 0x0661,
  23321. onehalf: 0x00BD,
  23322. onehangzhou: 0x3021,
  23323. oneideographicparen: 0x3220,
  23324. oneinferior: 0x2081,
  23325. onemonospace: 0xFF11,
  23326. onenumeratorbengali: 0x09F4,
  23327. oneoldstyle: 0xF731,
  23328. oneparen: 0x2474,
  23329. oneperiod: 0x2488,
  23330. onepersian: 0x06F1,
  23331. onequarter: 0x00BC,
  23332. oneroman: 0x2170,
  23333. onesuperior: 0x00B9,
  23334. onethai: 0x0E51,
  23335. onethird: 0x2153,
  23336. oogonek: 0x01EB,
  23337. oogonekmacron: 0x01ED,
  23338. oogurmukhi: 0x0A13,
  23339. oomatragurmukhi: 0x0A4B,
  23340. oopen: 0x0254,
  23341. oparen: 0x24AA,
  23342. openbullet: 0x25E6,
  23343. option: 0x2325,
  23344. ordfeminine: 0x00AA,
  23345. ordmasculine: 0x00BA,
  23346. orthogonal: 0x221F,
  23347. oshortdeva: 0x0912,
  23348. oshortvowelsigndeva: 0x094A,
  23349. oslash: 0x00F8,
  23350. oslashacute: 0x01FF,
  23351. osmallhiragana: 0x3049,
  23352. osmallkatakana: 0x30A9,
  23353. osmallkatakanahalfwidth: 0xFF6B,
  23354. ostrokeacute: 0x01FF,
  23355. osuperior: 0xF6F0,
  23356. otcyrillic: 0x047F,
  23357. otilde: 0x00F5,
  23358. otildeacute: 0x1E4D,
  23359. otildedieresis: 0x1E4F,
  23360. oubopomofo: 0x3121,
  23361. overline: 0x203E,
  23362. overlinecenterline: 0xFE4A,
  23363. overlinecmb: 0x0305,
  23364. overlinedashed: 0xFE49,
  23365. overlinedblwavy: 0xFE4C,
  23366. overlinewavy: 0xFE4B,
  23367. overscore: 0x00AF,
  23368. ovowelsignbengali: 0x09CB,
  23369. ovowelsigndeva: 0x094B,
  23370. ovowelsigngujarati: 0x0ACB,
  23371. p: 0x0070,
  23372. paampssquare: 0x3380,
  23373. paasentosquare: 0x332B,
  23374. pabengali: 0x09AA,
  23375. pacute: 0x1E55,
  23376. padeva: 0x092A,
  23377. pagedown: 0x21DF,
  23378. pageup: 0x21DE,
  23379. pagujarati: 0x0AAA,
  23380. pagurmukhi: 0x0A2A,
  23381. pahiragana: 0x3071,
  23382. paiyannoithai: 0x0E2F,
  23383. pakatakana: 0x30D1,
  23384. palatalizationcyrilliccmb: 0x0484,
  23385. palochkacyrillic: 0x04C0,
  23386. pansioskorean: 0x317F,
  23387. paragraph: 0x00B6,
  23388. parallel: 0x2225,
  23389. parenleft: 0x0028,
  23390. parenleftaltonearabic: 0xFD3E,
  23391. parenleftbt: 0xF8ED,
  23392. parenleftex: 0xF8EC,
  23393. parenleftinferior: 0x208D,
  23394. parenleftmonospace: 0xFF08,
  23395. parenleftsmall: 0xFE59,
  23396. parenleftsuperior: 0x207D,
  23397. parenlefttp: 0xF8EB,
  23398. parenleftvertical: 0xFE35,
  23399. parenright: 0x0029,
  23400. parenrightaltonearabic: 0xFD3F,
  23401. parenrightbt: 0xF8F8,
  23402. parenrightex: 0xF8F7,
  23403. parenrightinferior: 0x208E,
  23404. parenrightmonospace: 0xFF09,
  23405. parenrightsmall: 0xFE5A,
  23406. parenrightsuperior: 0x207E,
  23407. parenrighttp: 0xF8F6,
  23408. parenrightvertical: 0xFE36,
  23409. partialdiff: 0x2202,
  23410. paseqhebrew: 0x05C0,
  23411. pashtahebrew: 0x0599,
  23412. pasquare: 0x33A9,
  23413. patah: 0x05B7,
  23414. patah11: 0x05B7,
  23415. patah1d: 0x05B7,
  23416. patah2a: 0x05B7,
  23417. patahhebrew: 0x05B7,
  23418. patahnarrowhebrew: 0x05B7,
  23419. patahquarterhebrew: 0x05B7,
  23420. patahwidehebrew: 0x05B7,
  23421. pazerhebrew: 0x05A1,
  23422. pbopomofo: 0x3106,
  23423. pcircle: 0x24DF,
  23424. pdotaccent: 0x1E57,
  23425. pe: 0x05E4,
  23426. pecyrillic: 0x043F,
  23427. pedagesh: 0xFB44,
  23428. pedageshhebrew: 0xFB44,
  23429. peezisquare: 0x333B,
  23430. pefinaldageshhebrew: 0xFB43,
  23431. peharabic: 0x067E,
  23432. peharmenian: 0x057A,
  23433. pehebrew: 0x05E4,
  23434. pehfinalarabic: 0xFB57,
  23435. pehinitialarabic: 0xFB58,
  23436. pehiragana: 0x307A,
  23437. pehmedialarabic: 0xFB59,
  23438. pekatakana: 0x30DA,
  23439. pemiddlehookcyrillic: 0x04A7,
  23440. perafehebrew: 0xFB4E,
  23441. percent: 0x0025,
  23442. percentarabic: 0x066A,
  23443. percentmonospace: 0xFF05,
  23444. percentsmall: 0xFE6A,
  23445. period: 0x002E,
  23446. periodarmenian: 0x0589,
  23447. periodcentered: 0x00B7,
  23448. periodhalfwidth: 0xFF61,
  23449. periodinferior: 0xF6E7,
  23450. periodmonospace: 0xFF0E,
  23451. periodsmall: 0xFE52,
  23452. periodsuperior: 0xF6E8,
  23453. perispomenigreekcmb: 0x0342,
  23454. perpendicular: 0x22A5,
  23455. perthousand: 0x2030,
  23456. peseta: 0x20A7,
  23457. pfsquare: 0x338A,
  23458. phabengali: 0x09AB,
  23459. phadeva: 0x092B,
  23460. phagujarati: 0x0AAB,
  23461. phagurmukhi: 0x0A2B,
  23462. phi: 0x03C6,
  23463. phi1: 0x03D5,
  23464. phieuphacirclekorean: 0x327A,
  23465. phieuphaparenkorean: 0x321A,
  23466. phieuphcirclekorean: 0x326C,
  23467. phieuphkorean: 0x314D,
  23468. phieuphparenkorean: 0x320C,
  23469. philatin: 0x0278,
  23470. phinthuthai: 0x0E3A,
  23471. phisymbolgreek: 0x03D5,
  23472. phook: 0x01A5,
  23473. phophanthai: 0x0E1E,
  23474. phophungthai: 0x0E1C,
  23475. phosamphaothai: 0x0E20,
  23476. pi: 0x03C0,
  23477. pieupacirclekorean: 0x3273,
  23478. pieupaparenkorean: 0x3213,
  23479. pieupcieuckorean: 0x3176,
  23480. pieupcirclekorean: 0x3265,
  23481. pieupkiyeokkorean: 0x3172,
  23482. pieupkorean: 0x3142,
  23483. pieupparenkorean: 0x3205,
  23484. pieupsioskiyeokkorean: 0x3174,
  23485. pieupsioskorean: 0x3144,
  23486. pieupsiostikeutkorean: 0x3175,
  23487. pieupthieuthkorean: 0x3177,
  23488. pieuptikeutkorean: 0x3173,
  23489. pihiragana: 0x3074,
  23490. pikatakana: 0x30D4,
  23491. pisymbolgreek: 0x03D6,
  23492. piwrarmenian: 0x0583,
  23493. plus: 0x002B,
  23494. plusbelowcmb: 0x031F,
  23495. pluscircle: 0x2295,
  23496. plusminus: 0x00B1,
  23497. plusmod: 0x02D6,
  23498. plusmonospace: 0xFF0B,
  23499. plussmall: 0xFE62,
  23500. plussuperior: 0x207A,
  23501. pmonospace: 0xFF50,
  23502. pmsquare: 0x33D8,
  23503. pohiragana: 0x307D,
  23504. pointingindexdownwhite: 0x261F,
  23505. pointingindexleftwhite: 0x261C,
  23506. pointingindexrightwhite: 0x261E,
  23507. pointingindexupwhite: 0x261D,
  23508. pokatakana: 0x30DD,
  23509. poplathai: 0x0E1B,
  23510. postalmark: 0x3012,
  23511. postalmarkface: 0x3020,
  23512. pparen: 0x24AB,
  23513. precedes: 0x227A,
  23514. prescription: 0x211E,
  23515. primemod: 0x02B9,
  23516. primereversed: 0x2035,
  23517. product: 0x220F,
  23518. projective: 0x2305,
  23519. prolongedkana: 0x30FC,
  23520. propellor: 0x2318,
  23521. propersubset: 0x2282,
  23522. propersuperset: 0x2283,
  23523. proportion: 0x2237,
  23524. proportional: 0x221D,
  23525. psi: 0x03C8,
  23526. psicyrillic: 0x0471,
  23527. psilipneumatacyrilliccmb: 0x0486,
  23528. pssquare: 0x33B0,
  23529. puhiragana: 0x3077,
  23530. pukatakana: 0x30D7,
  23531. pvsquare: 0x33B4,
  23532. pwsquare: 0x33BA,
  23533. q: 0x0071,
  23534. qadeva: 0x0958,
  23535. qadmahebrew: 0x05A8,
  23536. qafarabic: 0x0642,
  23537. qaffinalarabic: 0xFED6,
  23538. qafinitialarabic: 0xFED7,
  23539. qafmedialarabic: 0xFED8,
  23540. qamats: 0x05B8,
  23541. qamats10: 0x05B8,
  23542. qamats1a: 0x05B8,
  23543. qamats1c: 0x05B8,
  23544. qamats27: 0x05B8,
  23545. qamats29: 0x05B8,
  23546. qamats33: 0x05B8,
  23547. qamatsde: 0x05B8,
  23548. qamatshebrew: 0x05B8,
  23549. qamatsnarrowhebrew: 0x05B8,
  23550. qamatsqatanhebrew: 0x05B8,
  23551. qamatsqatannarrowhebrew: 0x05B8,
  23552. qamatsqatanquarterhebrew: 0x05B8,
  23553. qamatsqatanwidehebrew: 0x05B8,
  23554. qamatsquarterhebrew: 0x05B8,
  23555. qamatswidehebrew: 0x05B8,
  23556. qarneyparahebrew: 0x059F,
  23557. qbopomofo: 0x3111,
  23558. qcircle: 0x24E0,
  23559. qhook: 0x02A0,
  23560. qmonospace: 0xFF51,
  23561. qof: 0x05E7,
  23562. qofdagesh: 0xFB47,
  23563. qofdageshhebrew: 0xFB47,
  23564. qofhebrew: 0x05E7,
  23565. qparen: 0x24AC,
  23566. quarternote: 0x2669,
  23567. qubuts: 0x05BB,
  23568. qubuts18: 0x05BB,
  23569. qubuts25: 0x05BB,
  23570. qubuts31: 0x05BB,
  23571. qubutshebrew: 0x05BB,
  23572. qubutsnarrowhebrew: 0x05BB,
  23573. qubutsquarterhebrew: 0x05BB,
  23574. qubutswidehebrew: 0x05BB,
  23575. question: 0x003F,
  23576. questionarabic: 0x061F,
  23577. questionarmenian: 0x055E,
  23578. questiondown: 0x00BF,
  23579. questiondownsmall: 0xF7BF,
  23580. questiongreek: 0x037E,
  23581. questionmonospace: 0xFF1F,
  23582. questionsmall: 0xF73F,
  23583. quotedbl: 0x0022,
  23584. quotedblbase: 0x201E,
  23585. quotedblleft: 0x201C,
  23586. quotedblmonospace: 0xFF02,
  23587. quotedblprime: 0x301E,
  23588. quotedblprimereversed: 0x301D,
  23589. quotedblright: 0x201D,
  23590. quoteleft: 0x2018,
  23591. quoteleftreversed: 0x201B,
  23592. quotereversed: 0x201B,
  23593. quoteright: 0x2019,
  23594. quoterightn: 0x0149,
  23595. quotesinglbase: 0x201A,
  23596. quotesingle: 0x0027,
  23597. quotesinglemonospace: 0xFF07,
  23598. r: 0x0072,
  23599. raarmenian: 0x057C,
  23600. rabengali: 0x09B0,
  23601. racute: 0x0155,
  23602. radeva: 0x0930,
  23603. radical: 0x221A,
  23604. radicalex: 0xF8E5,
  23605. radoverssquare: 0x33AE,
  23606. radoverssquaredsquare: 0x33AF,
  23607. radsquare: 0x33AD,
  23608. rafe: 0x05BF,
  23609. rafehebrew: 0x05BF,
  23610. ragujarati: 0x0AB0,
  23611. ragurmukhi: 0x0A30,
  23612. rahiragana: 0x3089,
  23613. rakatakana: 0x30E9,
  23614. rakatakanahalfwidth: 0xFF97,
  23615. ralowerdiagonalbengali: 0x09F1,
  23616. ramiddlediagonalbengali: 0x09F0,
  23617. ramshorn: 0x0264,
  23618. ratio: 0x2236,
  23619. rbopomofo: 0x3116,
  23620. rcaron: 0x0159,
  23621. rcedilla: 0x0157,
  23622. rcircle: 0x24E1,
  23623. rcommaaccent: 0x0157,
  23624. rdblgrave: 0x0211,
  23625. rdotaccent: 0x1E59,
  23626. rdotbelow: 0x1E5B,
  23627. rdotbelowmacron: 0x1E5D,
  23628. referencemark: 0x203B,
  23629. reflexsubset: 0x2286,
  23630. reflexsuperset: 0x2287,
  23631. registered: 0x00AE,
  23632. registersans: 0xF8E8,
  23633. registerserif: 0xF6DA,
  23634. reharabic: 0x0631,
  23635. reharmenian: 0x0580,
  23636. rehfinalarabic: 0xFEAE,
  23637. rehiragana: 0x308C,
  23638. rekatakana: 0x30EC,
  23639. rekatakanahalfwidth: 0xFF9A,
  23640. resh: 0x05E8,
  23641. reshdageshhebrew: 0xFB48,
  23642. reshhebrew: 0x05E8,
  23643. reversedtilde: 0x223D,
  23644. reviahebrew: 0x0597,
  23645. reviamugrashhebrew: 0x0597,
  23646. revlogicalnot: 0x2310,
  23647. rfishhook: 0x027E,
  23648. rfishhookreversed: 0x027F,
  23649. rhabengali: 0x09DD,
  23650. rhadeva: 0x095D,
  23651. rho: 0x03C1,
  23652. rhook: 0x027D,
  23653. rhookturned: 0x027B,
  23654. rhookturnedsuperior: 0x02B5,
  23655. rhosymbolgreek: 0x03F1,
  23656. rhotichookmod: 0x02DE,
  23657. rieulacirclekorean: 0x3271,
  23658. rieulaparenkorean: 0x3211,
  23659. rieulcirclekorean: 0x3263,
  23660. rieulhieuhkorean: 0x3140,
  23661. rieulkiyeokkorean: 0x313A,
  23662. rieulkiyeoksioskorean: 0x3169,
  23663. rieulkorean: 0x3139,
  23664. rieulmieumkorean: 0x313B,
  23665. rieulpansioskorean: 0x316C,
  23666. rieulparenkorean: 0x3203,
  23667. rieulphieuphkorean: 0x313F,
  23668. rieulpieupkorean: 0x313C,
  23669. rieulpieupsioskorean: 0x316B,
  23670. rieulsioskorean: 0x313D,
  23671. rieulthieuthkorean: 0x313E,
  23672. rieultikeutkorean: 0x316A,
  23673. rieulyeorinhieuhkorean: 0x316D,
  23674. rightangle: 0x221F,
  23675. righttackbelowcmb: 0x0319,
  23676. righttriangle: 0x22BF,
  23677. rihiragana: 0x308A,
  23678. rikatakana: 0x30EA,
  23679. rikatakanahalfwidth: 0xFF98,
  23680. ring: 0x02DA,
  23681. ringbelowcmb: 0x0325,
  23682. ringcmb: 0x030A,
  23683. ringhalfleft: 0x02BF,
  23684. ringhalfleftarmenian: 0x0559,
  23685. ringhalfleftbelowcmb: 0x031C,
  23686. ringhalfleftcentered: 0x02D3,
  23687. ringhalfright: 0x02BE,
  23688. ringhalfrightbelowcmb: 0x0339,
  23689. ringhalfrightcentered: 0x02D2,
  23690. rinvertedbreve: 0x0213,
  23691. rittorusquare: 0x3351,
  23692. rlinebelow: 0x1E5F,
  23693. rlongleg: 0x027C,
  23694. rlonglegturned: 0x027A,
  23695. rmonospace: 0xFF52,
  23696. rohiragana: 0x308D,
  23697. rokatakana: 0x30ED,
  23698. rokatakanahalfwidth: 0xFF9B,
  23699. roruathai: 0x0E23,
  23700. rparen: 0x24AD,
  23701. rrabengali: 0x09DC,
  23702. rradeva: 0x0931,
  23703. rragurmukhi: 0x0A5C,
  23704. rreharabic: 0x0691,
  23705. rrehfinalarabic: 0xFB8D,
  23706. rrvocalicbengali: 0x09E0,
  23707. rrvocalicdeva: 0x0960,
  23708. rrvocalicgujarati: 0x0AE0,
  23709. rrvocalicvowelsignbengali: 0x09C4,
  23710. rrvocalicvowelsigndeva: 0x0944,
  23711. rrvocalicvowelsigngujarati: 0x0AC4,
  23712. rsuperior: 0xF6F1,
  23713. rtblock: 0x2590,
  23714. rturned: 0x0279,
  23715. rturnedsuperior: 0x02B4,
  23716. ruhiragana: 0x308B,
  23717. rukatakana: 0x30EB,
  23718. rukatakanahalfwidth: 0xFF99,
  23719. rupeemarkbengali: 0x09F2,
  23720. rupeesignbengali: 0x09F3,
  23721. rupiah: 0xF6DD,
  23722. ruthai: 0x0E24,
  23723. rvocalicbengali: 0x098B,
  23724. rvocalicdeva: 0x090B,
  23725. rvocalicgujarati: 0x0A8B,
  23726. rvocalicvowelsignbengali: 0x09C3,
  23727. rvocalicvowelsigndeva: 0x0943,
  23728. rvocalicvowelsigngujarati: 0x0AC3,
  23729. s: 0x0073,
  23730. sabengali: 0x09B8,
  23731. sacute: 0x015B,
  23732. sacutedotaccent: 0x1E65,
  23733. sadarabic: 0x0635,
  23734. sadeva: 0x0938,
  23735. sadfinalarabic: 0xFEBA,
  23736. sadinitialarabic: 0xFEBB,
  23737. sadmedialarabic: 0xFEBC,
  23738. sagujarati: 0x0AB8,
  23739. sagurmukhi: 0x0A38,
  23740. sahiragana: 0x3055,
  23741. sakatakana: 0x30B5,
  23742. sakatakanahalfwidth: 0xFF7B,
  23743. sallallahoualayhewasallamarabic: 0xFDFA,
  23744. samekh: 0x05E1,
  23745. samekhdagesh: 0xFB41,
  23746. samekhdageshhebrew: 0xFB41,
  23747. samekhhebrew: 0x05E1,
  23748. saraaathai: 0x0E32,
  23749. saraaethai: 0x0E41,
  23750. saraaimaimalaithai: 0x0E44,
  23751. saraaimaimuanthai: 0x0E43,
  23752. saraamthai: 0x0E33,
  23753. saraathai: 0x0E30,
  23754. saraethai: 0x0E40,
  23755. saraiileftthai: 0xF886,
  23756. saraiithai: 0x0E35,
  23757. saraileftthai: 0xF885,
  23758. saraithai: 0x0E34,
  23759. saraothai: 0x0E42,
  23760. saraueeleftthai: 0xF888,
  23761. saraueethai: 0x0E37,
  23762. saraueleftthai: 0xF887,
  23763. sarauethai: 0x0E36,
  23764. sarauthai: 0x0E38,
  23765. sarauuthai: 0x0E39,
  23766. sbopomofo: 0x3119,
  23767. scaron: 0x0161,
  23768. scarondotaccent: 0x1E67,
  23769. scedilla: 0x015F,
  23770. schwa: 0x0259,
  23771. schwacyrillic: 0x04D9,
  23772. schwadieresiscyrillic: 0x04DB,
  23773. schwahook: 0x025A,
  23774. scircle: 0x24E2,
  23775. scircumflex: 0x015D,
  23776. scommaaccent: 0x0219,
  23777. sdotaccent: 0x1E61,
  23778. sdotbelow: 0x1E63,
  23779. sdotbelowdotaccent: 0x1E69,
  23780. seagullbelowcmb: 0x033C,
  23781. second: 0x2033,
  23782. secondtonechinese: 0x02CA,
  23783. section: 0x00A7,
  23784. seenarabic: 0x0633,
  23785. seenfinalarabic: 0xFEB2,
  23786. seeninitialarabic: 0xFEB3,
  23787. seenmedialarabic: 0xFEB4,
  23788. segol: 0x05B6,
  23789. segol13: 0x05B6,
  23790. segol1f: 0x05B6,
  23791. segol2c: 0x05B6,
  23792. segolhebrew: 0x05B6,
  23793. segolnarrowhebrew: 0x05B6,
  23794. segolquarterhebrew: 0x05B6,
  23795. segoltahebrew: 0x0592,
  23796. segolwidehebrew: 0x05B6,
  23797. seharmenian: 0x057D,
  23798. sehiragana: 0x305B,
  23799. sekatakana: 0x30BB,
  23800. sekatakanahalfwidth: 0xFF7E,
  23801. semicolon: 0x003B,
  23802. semicolonarabic: 0x061B,
  23803. semicolonmonospace: 0xFF1B,
  23804. semicolonsmall: 0xFE54,
  23805. semivoicedmarkkana: 0x309C,
  23806. semivoicedmarkkanahalfwidth: 0xFF9F,
  23807. sentisquare: 0x3322,
  23808. sentosquare: 0x3323,
  23809. seven: 0x0037,
  23810. sevenarabic: 0x0667,
  23811. sevenbengali: 0x09ED,
  23812. sevencircle: 0x2466,
  23813. sevencircleinversesansserif: 0x2790,
  23814. sevendeva: 0x096D,
  23815. seveneighths: 0x215E,
  23816. sevengujarati: 0x0AED,
  23817. sevengurmukhi: 0x0A6D,
  23818. sevenhackarabic: 0x0667,
  23819. sevenhangzhou: 0x3027,
  23820. sevenideographicparen: 0x3226,
  23821. seveninferior: 0x2087,
  23822. sevenmonospace: 0xFF17,
  23823. sevenoldstyle: 0xF737,
  23824. sevenparen: 0x247A,
  23825. sevenperiod: 0x248E,
  23826. sevenpersian: 0x06F7,
  23827. sevenroman: 0x2176,
  23828. sevensuperior: 0x2077,
  23829. seventeencircle: 0x2470,
  23830. seventeenparen: 0x2484,
  23831. seventeenperiod: 0x2498,
  23832. seventhai: 0x0E57,
  23833. sfthyphen: 0x00AD,
  23834. shaarmenian: 0x0577,
  23835. shabengali: 0x09B6,
  23836. shacyrillic: 0x0448,
  23837. shaddaarabic: 0x0651,
  23838. shaddadammaarabic: 0xFC61,
  23839. shaddadammatanarabic: 0xFC5E,
  23840. shaddafathaarabic: 0xFC60,
  23841. shaddakasraarabic: 0xFC62,
  23842. shaddakasratanarabic: 0xFC5F,
  23843. shade: 0x2592,
  23844. shadedark: 0x2593,
  23845. shadelight: 0x2591,
  23846. shademedium: 0x2592,
  23847. shadeva: 0x0936,
  23848. shagujarati: 0x0AB6,
  23849. shagurmukhi: 0x0A36,
  23850. shalshelethebrew: 0x0593,
  23851. shbopomofo: 0x3115,
  23852. shchacyrillic: 0x0449,
  23853. sheenarabic: 0x0634,
  23854. sheenfinalarabic: 0xFEB6,
  23855. sheeninitialarabic: 0xFEB7,
  23856. sheenmedialarabic: 0xFEB8,
  23857. sheicoptic: 0x03E3,
  23858. sheqel: 0x20AA,
  23859. sheqelhebrew: 0x20AA,
  23860. sheva: 0x05B0,
  23861. sheva115: 0x05B0,
  23862. sheva15: 0x05B0,
  23863. sheva22: 0x05B0,
  23864. sheva2e: 0x05B0,
  23865. shevahebrew: 0x05B0,
  23866. shevanarrowhebrew: 0x05B0,
  23867. shevaquarterhebrew: 0x05B0,
  23868. shevawidehebrew: 0x05B0,
  23869. shhacyrillic: 0x04BB,
  23870. shimacoptic: 0x03ED,
  23871. shin: 0x05E9,
  23872. shindagesh: 0xFB49,
  23873. shindageshhebrew: 0xFB49,
  23874. shindageshshindot: 0xFB2C,
  23875. shindageshshindothebrew: 0xFB2C,
  23876. shindageshsindot: 0xFB2D,
  23877. shindageshsindothebrew: 0xFB2D,
  23878. shindothebrew: 0x05C1,
  23879. shinhebrew: 0x05E9,
  23880. shinshindot: 0xFB2A,
  23881. shinshindothebrew: 0xFB2A,
  23882. shinsindot: 0xFB2B,
  23883. shinsindothebrew: 0xFB2B,
  23884. shook: 0x0282,
  23885. sigma: 0x03C3,
  23886. sigma1: 0x03C2,
  23887. sigmafinal: 0x03C2,
  23888. sigmalunatesymbolgreek: 0x03F2,
  23889. sihiragana: 0x3057,
  23890. sikatakana: 0x30B7,
  23891. sikatakanahalfwidth: 0xFF7C,
  23892. siluqhebrew: 0x05BD,
  23893. siluqlefthebrew: 0x05BD,
  23894. similar: 0x223C,
  23895. sindothebrew: 0x05C2,
  23896. siosacirclekorean: 0x3274,
  23897. siosaparenkorean: 0x3214,
  23898. sioscieuckorean: 0x317E,
  23899. sioscirclekorean: 0x3266,
  23900. sioskiyeokkorean: 0x317A,
  23901. sioskorean: 0x3145,
  23902. siosnieunkorean: 0x317B,
  23903. siosparenkorean: 0x3206,
  23904. siospieupkorean: 0x317D,
  23905. siostikeutkorean: 0x317C,
  23906. six: 0x0036,
  23907. sixarabic: 0x0666,
  23908. sixbengali: 0x09EC,
  23909. sixcircle: 0x2465,
  23910. sixcircleinversesansserif: 0x278F,
  23911. sixdeva: 0x096C,
  23912. sixgujarati: 0x0AEC,
  23913. sixgurmukhi: 0x0A6C,
  23914. sixhackarabic: 0x0666,
  23915. sixhangzhou: 0x3026,
  23916. sixideographicparen: 0x3225,
  23917. sixinferior: 0x2086,
  23918. sixmonospace: 0xFF16,
  23919. sixoldstyle: 0xF736,
  23920. sixparen: 0x2479,
  23921. sixperiod: 0x248D,
  23922. sixpersian: 0x06F6,
  23923. sixroman: 0x2175,
  23924. sixsuperior: 0x2076,
  23925. sixteencircle: 0x246F,
  23926. sixteencurrencydenominatorbengali: 0x09F9,
  23927. sixteenparen: 0x2483,
  23928. sixteenperiod: 0x2497,
  23929. sixthai: 0x0E56,
  23930. slash: 0x002F,
  23931. slashmonospace: 0xFF0F,
  23932. slong: 0x017F,
  23933. slongdotaccent: 0x1E9B,
  23934. smileface: 0x263A,
  23935. smonospace: 0xFF53,
  23936. sofpasuqhebrew: 0x05C3,
  23937. softhyphen: 0x00AD,
  23938. softsigncyrillic: 0x044C,
  23939. sohiragana: 0x305D,
  23940. sokatakana: 0x30BD,
  23941. sokatakanahalfwidth: 0xFF7F,
  23942. soliduslongoverlaycmb: 0x0338,
  23943. solidusshortoverlaycmb: 0x0337,
  23944. sorusithai: 0x0E29,
  23945. sosalathai: 0x0E28,
  23946. sosothai: 0x0E0B,
  23947. sosuathai: 0x0E2A,
  23948. space: 0x0020,
  23949. spacehackarabic: 0x0020,
  23950. spade: 0x2660,
  23951. spadesuitblack: 0x2660,
  23952. spadesuitwhite: 0x2664,
  23953. sparen: 0x24AE,
  23954. squarebelowcmb: 0x033B,
  23955. squarecc: 0x33C4,
  23956. squarecm: 0x339D,
  23957. squarediagonalcrosshatchfill: 0x25A9,
  23958. squarehorizontalfill: 0x25A4,
  23959. squarekg: 0x338F,
  23960. squarekm: 0x339E,
  23961. squarekmcapital: 0x33CE,
  23962. squareln: 0x33D1,
  23963. squarelog: 0x33D2,
  23964. squaremg: 0x338E,
  23965. squaremil: 0x33D5,
  23966. squaremm: 0x339C,
  23967. squaremsquared: 0x33A1,
  23968. squareorthogonalcrosshatchfill: 0x25A6,
  23969. squareupperlefttolowerrightfill: 0x25A7,
  23970. squareupperrighttolowerleftfill: 0x25A8,
  23971. squareverticalfill: 0x25A5,
  23972. squarewhitewithsmallblack: 0x25A3,
  23973. srsquare: 0x33DB,
  23974. ssabengali: 0x09B7,
  23975. ssadeva: 0x0937,
  23976. ssagujarati: 0x0AB7,
  23977. ssangcieuckorean: 0x3149,
  23978. ssanghieuhkorean: 0x3185,
  23979. ssangieungkorean: 0x3180,
  23980. ssangkiyeokkorean: 0x3132,
  23981. ssangnieunkorean: 0x3165,
  23982. ssangpieupkorean: 0x3143,
  23983. ssangsioskorean: 0x3146,
  23984. ssangtikeutkorean: 0x3138,
  23985. ssuperior: 0xF6F2,
  23986. sterling: 0x00A3,
  23987. sterlingmonospace: 0xFFE1,
  23988. strokelongoverlaycmb: 0x0336,
  23989. strokeshortoverlaycmb: 0x0335,
  23990. subset: 0x2282,
  23991. subsetnotequal: 0x228A,
  23992. subsetorequal: 0x2286,
  23993. succeeds: 0x227B,
  23994. suchthat: 0x220B,
  23995. suhiragana: 0x3059,
  23996. sukatakana: 0x30B9,
  23997. sukatakanahalfwidth: 0xFF7D,
  23998. sukunarabic: 0x0652,
  23999. summation: 0x2211,
  24000. sun: 0x263C,
  24001. superset: 0x2283,
  24002. supersetnotequal: 0x228B,
  24003. supersetorequal: 0x2287,
  24004. svsquare: 0x33DC,
  24005. syouwaerasquare: 0x337C,
  24006. t: 0x0074,
  24007. tabengali: 0x09A4,
  24008. tackdown: 0x22A4,
  24009. tackleft: 0x22A3,
  24010. tadeva: 0x0924,
  24011. tagujarati: 0x0AA4,
  24012. tagurmukhi: 0x0A24,
  24013. taharabic: 0x0637,
  24014. tahfinalarabic: 0xFEC2,
  24015. tahinitialarabic: 0xFEC3,
  24016. tahiragana: 0x305F,
  24017. tahmedialarabic: 0xFEC4,
  24018. taisyouerasquare: 0x337D,
  24019. takatakana: 0x30BF,
  24020. takatakanahalfwidth: 0xFF80,
  24021. tatweelarabic: 0x0640,
  24022. tau: 0x03C4,
  24023. tav: 0x05EA,
  24024. tavdages: 0xFB4A,
  24025. tavdagesh: 0xFB4A,
  24026. tavdageshhebrew: 0xFB4A,
  24027. tavhebrew: 0x05EA,
  24028. tbar: 0x0167,
  24029. tbopomofo: 0x310A,
  24030. tcaron: 0x0165,
  24031. tccurl: 0x02A8,
  24032. tcedilla: 0x0163,
  24033. tcheharabic: 0x0686,
  24034. tchehfinalarabic: 0xFB7B,
  24035. tchehinitialarabic: 0xFB7C,
  24036. tchehmedialarabic: 0xFB7D,
  24037. tcircle: 0x24E3,
  24038. tcircumflexbelow: 0x1E71,
  24039. tcommaaccent: 0x0163,
  24040. tdieresis: 0x1E97,
  24041. tdotaccent: 0x1E6B,
  24042. tdotbelow: 0x1E6D,
  24043. tecyrillic: 0x0442,
  24044. tedescendercyrillic: 0x04AD,
  24045. teharabic: 0x062A,
  24046. tehfinalarabic: 0xFE96,
  24047. tehhahinitialarabic: 0xFCA2,
  24048. tehhahisolatedarabic: 0xFC0C,
  24049. tehinitialarabic: 0xFE97,
  24050. tehiragana: 0x3066,
  24051. tehjeeminitialarabic: 0xFCA1,
  24052. tehjeemisolatedarabic: 0xFC0B,
  24053. tehmarbutaarabic: 0x0629,
  24054. tehmarbutafinalarabic: 0xFE94,
  24055. tehmedialarabic: 0xFE98,
  24056. tehmeeminitialarabic: 0xFCA4,
  24057. tehmeemisolatedarabic: 0xFC0E,
  24058. tehnoonfinalarabic: 0xFC73,
  24059. tekatakana: 0x30C6,
  24060. tekatakanahalfwidth: 0xFF83,
  24061. telephone: 0x2121,
  24062. telephoneblack: 0x260E,
  24063. telishagedolahebrew: 0x05A0,
  24064. telishaqetanahebrew: 0x05A9,
  24065. tencircle: 0x2469,
  24066. tenideographicparen: 0x3229,
  24067. tenparen: 0x247D,
  24068. tenperiod: 0x2491,
  24069. tenroman: 0x2179,
  24070. tesh: 0x02A7,
  24071. tet: 0x05D8,
  24072. tetdagesh: 0xFB38,
  24073. tetdageshhebrew: 0xFB38,
  24074. tethebrew: 0x05D8,
  24075. tetsecyrillic: 0x04B5,
  24076. tevirhebrew: 0x059B,
  24077. tevirlefthebrew: 0x059B,
  24078. thabengali: 0x09A5,
  24079. thadeva: 0x0925,
  24080. thagujarati: 0x0AA5,
  24081. thagurmukhi: 0x0A25,
  24082. thalarabic: 0x0630,
  24083. thalfinalarabic: 0xFEAC,
  24084. thanthakhatlowleftthai: 0xF898,
  24085. thanthakhatlowrightthai: 0xF897,
  24086. thanthakhatthai: 0x0E4C,
  24087. thanthakhatupperleftthai: 0xF896,
  24088. theharabic: 0x062B,
  24089. thehfinalarabic: 0xFE9A,
  24090. thehinitialarabic: 0xFE9B,
  24091. thehmedialarabic: 0xFE9C,
  24092. thereexists: 0x2203,
  24093. therefore: 0x2234,
  24094. theta: 0x03B8,
  24095. theta1: 0x03D1,
  24096. thetasymbolgreek: 0x03D1,
  24097. thieuthacirclekorean: 0x3279,
  24098. thieuthaparenkorean: 0x3219,
  24099. thieuthcirclekorean: 0x326B,
  24100. thieuthkorean: 0x314C,
  24101. thieuthparenkorean: 0x320B,
  24102. thirteencircle: 0x246C,
  24103. thirteenparen: 0x2480,
  24104. thirteenperiod: 0x2494,
  24105. thonangmonthothai: 0x0E11,
  24106. thook: 0x01AD,
  24107. thophuthaothai: 0x0E12,
  24108. thorn: 0x00FE,
  24109. thothahanthai: 0x0E17,
  24110. thothanthai: 0x0E10,
  24111. thothongthai: 0x0E18,
  24112. thothungthai: 0x0E16,
  24113. thousandcyrillic: 0x0482,
  24114. thousandsseparatorarabic: 0x066C,
  24115. thousandsseparatorpersian: 0x066C,
  24116. three: 0x0033,
  24117. threearabic: 0x0663,
  24118. threebengali: 0x09E9,
  24119. threecircle: 0x2462,
  24120. threecircleinversesansserif: 0x278C,
  24121. threedeva: 0x0969,
  24122. threeeighths: 0x215C,
  24123. threegujarati: 0x0AE9,
  24124. threegurmukhi: 0x0A69,
  24125. threehackarabic: 0x0663,
  24126. threehangzhou: 0x3023,
  24127. threeideographicparen: 0x3222,
  24128. threeinferior: 0x2083,
  24129. threemonospace: 0xFF13,
  24130. threenumeratorbengali: 0x09F6,
  24131. threeoldstyle: 0xF733,
  24132. threeparen: 0x2476,
  24133. threeperiod: 0x248A,
  24134. threepersian: 0x06F3,
  24135. threequarters: 0x00BE,
  24136. threequartersemdash: 0xF6DE,
  24137. threeroman: 0x2172,
  24138. threesuperior: 0x00B3,
  24139. threethai: 0x0E53,
  24140. thzsquare: 0x3394,
  24141. tihiragana: 0x3061,
  24142. tikatakana: 0x30C1,
  24143. tikatakanahalfwidth: 0xFF81,
  24144. tikeutacirclekorean: 0x3270,
  24145. tikeutaparenkorean: 0x3210,
  24146. tikeutcirclekorean: 0x3262,
  24147. tikeutkorean: 0x3137,
  24148. tikeutparenkorean: 0x3202,
  24149. tilde: 0x02DC,
  24150. tildebelowcmb: 0x0330,
  24151. tildecmb: 0x0303,
  24152. tildecomb: 0x0303,
  24153. tildedoublecmb: 0x0360,
  24154. tildeoperator: 0x223C,
  24155. tildeoverlaycmb: 0x0334,
  24156. tildeverticalcmb: 0x033E,
  24157. timescircle: 0x2297,
  24158. tipehahebrew: 0x0596,
  24159. tipehalefthebrew: 0x0596,
  24160. tippigurmukhi: 0x0A70,
  24161. titlocyrilliccmb: 0x0483,
  24162. tiwnarmenian: 0x057F,
  24163. tlinebelow: 0x1E6F,
  24164. tmonospace: 0xFF54,
  24165. toarmenian: 0x0569,
  24166. tohiragana: 0x3068,
  24167. tokatakana: 0x30C8,
  24168. tokatakanahalfwidth: 0xFF84,
  24169. tonebarextrahighmod: 0x02E5,
  24170. tonebarextralowmod: 0x02E9,
  24171. tonebarhighmod: 0x02E6,
  24172. tonebarlowmod: 0x02E8,
  24173. tonebarmidmod: 0x02E7,
  24174. tonefive: 0x01BD,
  24175. tonesix: 0x0185,
  24176. tonetwo: 0x01A8,
  24177. tonos: 0x0384,
  24178. tonsquare: 0x3327,
  24179. topatakthai: 0x0E0F,
  24180. tortoiseshellbracketleft: 0x3014,
  24181. tortoiseshellbracketleftsmall: 0xFE5D,
  24182. tortoiseshellbracketleftvertical: 0xFE39,
  24183. tortoiseshellbracketright: 0x3015,
  24184. tortoiseshellbracketrightsmall: 0xFE5E,
  24185. tortoiseshellbracketrightvertical: 0xFE3A,
  24186. totaothai: 0x0E15,
  24187. tpalatalhook: 0x01AB,
  24188. tparen: 0x24AF,
  24189. trademark: 0x2122,
  24190. trademarksans: 0xF8EA,
  24191. trademarkserif: 0xF6DB,
  24192. tretroflexhook: 0x0288,
  24193. triagdn: 0x25BC,
  24194. triaglf: 0x25C4,
  24195. triagrt: 0x25BA,
  24196. triagup: 0x25B2,
  24197. ts: 0x02A6,
  24198. tsadi: 0x05E6,
  24199. tsadidagesh: 0xFB46,
  24200. tsadidageshhebrew: 0xFB46,
  24201. tsadihebrew: 0x05E6,
  24202. tsecyrillic: 0x0446,
  24203. tsere: 0x05B5,
  24204. tsere12: 0x05B5,
  24205. tsere1e: 0x05B5,
  24206. tsere2b: 0x05B5,
  24207. tserehebrew: 0x05B5,
  24208. tserenarrowhebrew: 0x05B5,
  24209. tserequarterhebrew: 0x05B5,
  24210. tserewidehebrew: 0x05B5,
  24211. tshecyrillic: 0x045B,
  24212. tsuperior: 0xF6F3,
  24213. ttabengali: 0x099F,
  24214. ttadeva: 0x091F,
  24215. ttagujarati: 0x0A9F,
  24216. ttagurmukhi: 0x0A1F,
  24217. tteharabic: 0x0679,
  24218. ttehfinalarabic: 0xFB67,
  24219. ttehinitialarabic: 0xFB68,
  24220. ttehmedialarabic: 0xFB69,
  24221. tthabengali: 0x09A0,
  24222. tthadeva: 0x0920,
  24223. tthagujarati: 0x0AA0,
  24224. tthagurmukhi: 0x0A20,
  24225. tturned: 0x0287,
  24226. tuhiragana: 0x3064,
  24227. tukatakana: 0x30C4,
  24228. tukatakanahalfwidth: 0xFF82,
  24229. tusmallhiragana: 0x3063,
  24230. tusmallkatakana: 0x30C3,
  24231. tusmallkatakanahalfwidth: 0xFF6F,
  24232. twelvecircle: 0x246B,
  24233. twelveparen: 0x247F,
  24234. twelveperiod: 0x2493,
  24235. twelveroman: 0x217B,
  24236. twentycircle: 0x2473,
  24237. twentyhangzhou: 0x5344,
  24238. twentyparen: 0x2487,
  24239. twentyperiod: 0x249B,
  24240. two: 0x0032,
  24241. twoarabic: 0x0662,
  24242. twobengali: 0x09E8,
  24243. twocircle: 0x2461,
  24244. twocircleinversesansserif: 0x278B,
  24245. twodeva: 0x0968,
  24246. twodotenleader: 0x2025,
  24247. twodotleader: 0x2025,
  24248. twodotleadervertical: 0xFE30,
  24249. twogujarati: 0x0AE8,
  24250. twogurmukhi: 0x0A68,
  24251. twohackarabic: 0x0662,
  24252. twohangzhou: 0x3022,
  24253. twoideographicparen: 0x3221,
  24254. twoinferior: 0x2082,
  24255. twomonospace: 0xFF12,
  24256. twonumeratorbengali: 0x09F5,
  24257. twooldstyle: 0xF732,
  24258. twoparen: 0x2475,
  24259. twoperiod: 0x2489,
  24260. twopersian: 0x06F2,
  24261. tworoman: 0x2171,
  24262. twostroke: 0x01BB,
  24263. twosuperior: 0x00B2,
  24264. twothai: 0x0E52,
  24265. twothirds: 0x2154,
  24266. u: 0x0075,
  24267. uacute: 0x00FA,
  24268. ubar: 0x0289,
  24269. ubengali: 0x0989,
  24270. ubopomofo: 0x3128,
  24271. ubreve: 0x016D,
  24272. ucaron: 0x01D4,
  24273. ucircle: 0x24E4,
  24274. ucircumflex: 0x00FB,
  24275. ucircumflexbelow: 0x1E77,
  24276. ucyrillic: 0x0443,
  24277. udattadeva: 0x0951,
  24278. udblacute: 0x0171,
  24279. udblgrave: 0x0215,
  24280. udeva: 0x0909,
  24281. udieresis: 0x00FC,
  24282. udieresisacute: 0x01D8,
  24283. udieresisbelow: 0x1E73,
  24284. udieresiscaron: 0x01DA,
  24285. udieresiscyrillic: 0x04F1,
  24286. udieresisgrave: 0x01DC,
  24287. udieresismacron: 0x01D6,
  24288. udotbelow: 0x1EE5,
  24289. ugrave: 0x00F9,
  24290. ugujarati: 0x0A89,
  24291. ugurmukhi: 0x0A09,
  24292. uhiragana: 0x3046,
  24293. uhookabove: 0x1EE7,
  24294. uhorn: 0x01B0,
  24295. uhornacute: 0x1EE9,
  24296. uhorndotbelow: 0x1EF1,
  24297. uhorngrave: 0x1EEB,
  24298. uhornhookabove: 0x1EED,
  24299. uhorntilde: 0x1EEF,
  24300. uhungarumlaut: 0x0171,
  24301. uhungarumlautcyrillic: 0x04F3,
  24302. uinvertedbreve: 0x0217,
  24303. ukatakana: 0x30A6,
  24304. ukatakanahalfwidth: 0xFF73,
  24305. ukcyrillic: 0x0479,
  24306. ukorean: 0x315C,
  24307. umacron: 0x016B,
  24308. umacroncyrillic: 0x04EF,
  24309. umacrondieresis: 0x1E7B,
  24310. umatragurmukhi: 0x0A41,
  24311. umonospace: 0xFF55,
  24312. underscore: 0x005F,
  24313. underscoredbl: 0x2017,
  24314. underscoremonospace: 0xFF3F,
  24315. underscorevertical: 0xFE33,
  24316. underscorewavy: 0xFE4F,
  24317. union: 0x222A,
  24318. universal: 0x2200,
  24319. uogonek: 0x0173,
  24320. uparen: 0x24B0,
  24321. upblock: 0x2580,
  24322. upperdothebrew: 0x05C4,
  24323. upsilon: 0x03C5,
  24324. upsilondieresis: 0x03CB,
  24325. upsilondieresistonos: 0x03B0,
  24326. upsilonlatin: 0x028A,
  24327. upsilontonos: 0x03CD,
  24328. uptackbelowcmb: 0x031D,
  24329. uptackmod: 0x02D4,
  24330. uragurmukhi: 0x0A73,
  24331. uring: 0x016F,
  24332. ushortcyrillic: 0x045E,
  24333. usmallhiragana: 0x3045,
  24334. usmallkatakana: 0x30A5,
  24335. usmallkatakanahalfwidth: 0xFF69,
  24336. ustraightcyrillic: 0x04AF,
  24337. ustraightstrokecyrillic: 0x04B1,
  24338. utilde: 0x0169,
  24339. utildeacute: 0x1E79,
  24340. utildebelow: 0x1E75,
  24341. uubengali: 0x098A,
  24342. uudeva: 0x090A,
  24343. uugujarati: 0x0A8A,
  24344. uugurmukhi: 0x0A0A,
  24345. uumatragurmukhi: 0x0A42,
  24346. uuvowelsignbengali: 0x09C2,
  24347. uuvowelsigndeva: 0x0942,
  24348. uuvowelsigngujarati: 0x0AC2,
  24349. uvowelsignbengali: 0x09C1,
  24350. uvowelsigndeva: 0x0941,
  24351. uvowelsigngujarati: 0x0AC1,
  24352. v: 0x0076,
  24353. vadeva: 0x0935,
  24354. vagujarati: 0x0AB5,
  24355. vagurmukhi: 0x0A35,
  24356. vakatakana: 0x30F7,
  24357. vav: 0x05D5,
  24358. vavdagesh: 0xFB35,
  24359. vavdagesh65: 0xFB35,
  24360. vavdageshhebrew: 0xFB35,
  24361. vavhebrew: 0x05D5,
  24362. vavholam: 0xFB4B,
  24363. vavholamhebrew: 0xFB4B,
  24364. vavvavhebrew: 0x05F0,
  24365. vavyodhebrew: 0x05F1,
  24366. vcircle: 0x24E5,
  24367. vdotbelow: 0x1E7F,
  24368. vecyrillic: 0x0432,
  24369. veharabic: 0x06A4,
  24370. vehfinalarabic: 0xFB6B,
  24371. vehinitialarabic: 0xFB6C,
  24372. vehmedialarabic: 0xFB6D,
  24373. vekatakana: 0x30F9,
  24374. venus: 0x2640,
  24375. verticalbar: 0x007C,
  24376. verticallineabovecmb: 0x030D,
  24377. verticallinebelowcmb: 0x0329,
  24378. verticallinelowmod: 0x02CC,
  24379. verticallinemod: 0x02C8,
  24380. vewarmenian: 0x057E,
  24381. vhook: 0x028B,
  24382. vikatakana: 0x30F8,
  24383. viramabengali: 0x09CD,
  24384. viramadeva: 0x094D,
  24385. viramagujarati: 0x0ACD,
  24386. visargabengali: 0x0983,
  24387. visargadeva: 0x0903,
  24388. visargagujarati: 0x0A83,
  24389. vmonospace: 0xFF56,
  24390. voarmenian: 0x0578,
  24391. voicediterationhiragana: 0x309E,
  24392. voicediterationkatakana: 0x30FE,
  24393. voicedmarkkana: 0x309B,
  24394. voicedmarkkanahalfwidth: 0xFF9E,
  24395. vokatakana: 0x30FA,
  24396. vparen: 0x24B1,
  24397. vtilde: 0x1E7D,
  24398. vturned: 0x028C,
  24399. vuhiragana: 0x3094,
  24400. vukatakana: 0x30F4,
  24401. w: 0x0077,
  24402. wacute: 0x1E83,
  24403. waekorean: 0x3159,
  24404. wahiragana: 0x308F,
  24405. wakatakana: 0x30EF,
  24406. wakatakanahalfwidth: 0xFF9C,
  24407. wakorean: 0x3158,
  24408. wasmallhiragana: 0x308E,
  24409. wasmallkatakana: 0x30EE,
  24410. wattosquare: 0x3357,
  24411. wavedash: 0x301C,
  24412. wavyunderscorevertical: 0xFE34,
  24413. wawarabic: 0x0648,
  24414. wawfinalarabic: 0xFEEE,
  24415. wawhamzaabovearabic: 0x0624,
  24416. wawhamzaabovefinalarabic: 0xFE86,
  24417. wbsquare: 0x33DD,
  24418. wcircle: 0x24E6,
  24419. wcircumflex: 0x0175,
  24420. wdieresis: 0x1E85,
  24421. wdotaccent: 0x1E87,
  24422. wdotbelow: 0x1E89,
  24423. wehiragana: 0x3091,
  24424. weierstrass: 0x2118,
  24425. wekatakana: 0x30F1,
  24426. wekorean: 0x315E,
  24427. weokorean: 0x315D,
  24428. wgrave: 0x1E81,
  24429. whitebullet: 0x25E6,
  24430. whitecircle: 0x25CB,
  24431. whitecircleinverse: 0x25D9,
  24432. whitecornerbracketleft: 0x300E,
  24433. whitecornerbracketleftvertical: 0xFE43,
  24434. whitecornerbracketright: 0x300F,
  24435. whitecornerbracketrightvertical: 0xFE44,
  24436. whitediamond: 0x25C7,
  24437. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24438. whitedownpointingsmalltriangle: 0x25BF,
  24439. whitedownpointingtriangle: 0x25BD,
  24440. whiteleftpointingsmalltriangle: 0x25C3,
  24441. whiteleftpointingtriangle: 0x25C1,
  24442. whitelenticularbracketleft: 0x3016,
  24443. whitelenticularbracketright: 0x3017,
  24444. whiterightpointingsmalltriangle: 0x25B9,
  24445. whiterightpointingtriangle: 0x25B7,
  24446. whitesmallsquare: 0x25AB,
  24447. whitesmilingface: 0x263A,
  24448. whitesquare: 0x25A1,
  24449. whitestar: 0x2606,
  24450. whitetelephone: 0x260F,
  24451. whitetortoiseshellbracketleft: 0x3018,
  24452. whitetortoiseshellbracketright: 0x3019,
  24453. whiteuppointingsmalltriangle: 0x25B5,
  24454. whiteuppointingtriangle: 0x25B3,
  24455. wihiragana: 0x3090,
  24456. wikatakana: 0x30F0,
  24457. wikorean: 0x315F,
  24458. wmonospace: 0xFF57,
  24459. wohiragana: 0x3092,
  24460. wokatakana: 0x30F2,
  24461. wokatakanahalfwidth: 0xFF66,
  24462. won: 0x20A9,
  24463. wonmonospace: 0xFFE6,
  24464. wowaenthai: 0x0E27,
  24465. wparen: 0x24B2,
  24466. wring: 0x1E98,
  24467. wsuperior: 0x02B7,
  24468. wturned: 0x028D,
  24469. wynn: 0x01BF,
  24470. x: 0x0078,
  24471. xabovecmb: 0x033D,
  24472. xbopomofo: 0x3112,
  24473. xcircle: 0x24E7,
  24474. xdieresis: 0x1E8D,
  24475. xdotaccent: 0x1E8B,
  24476. xeharmenian: 0x056D,
  24477. xi: 0x03BE,
  24478. xmonospace: 0xFF58,
  24479. xparen: 0x24B3,
  24480. xsuperior: 0x02E3,
  24481. y: 0x0079,
  24482. yaadosquare: 0x334E,
  24483. yabengali: 0x09AF,
  24484. yacute: 0x00FD,
  24485. yadeva: 0x092F,
  24486. yaekorean: 0x3152,
  24487. yagujarati: 0x0AAF,
  24488. yagurmukhi: 0x0A2F,
  24489. yahiragana: 0x3084,
  24490. yakatakana: 0x30E4,
  24491. yakatakanahalfwidth: 0xFF94,
  24492. yakorean: 0x3151,
  24493. yamakkanthai: 0x0E4E,
  24494. yasmallhiragana: 0x3083,
  24495. yasmallkatakana: 0x30E3,
  24496. yasmallkatakanahalfwidth: 0xFF6C,
  24497. yatcyrillic: 0x0463,
  24498. ycircle: 0x24E8,
  24499. ycircumflex: 0x0177,
  24500. ydieresis: 0x00FF,
  24501. ydotaccent: 0x1E8F,
  24502. ydotbelow: 0x1EF5,
  24503. yeharabic: 0x064A,
  24504. yehbarreearabic: 0x06D2,
  24505. yehbarreefinalarabic: 0xFBAF,
  24506. yehfinalarabic: 0xFEF2,
  24507. yehhamzaabovearabic: 0x0626,
  24508. yehhamzaabovefinalarabic: 0xFE8A,
  24509. yehhamzaaboveinitialarabic: 0xFE8B,
  24510. yehhamzaabovemedialarabic: 0xFE8C,
  24511. yehinitialarabic: 0xFEF3,
  24512. yehmedialarabic: 0xFEF4,
  24513. yehmeeminitialarabic: 0xFCDD,
  24514. yehmeemisolatedarabic: 0xFC58,
  24515. yehnoonfinalarabic: 0xFC94,
  24516. yehthreedotsbelowarabic: 0x06D1,
  24517. yekorean: 0x3156,
  24518. yen: 0x00A5,
  24519. yenmonospace: 0xFFE5,
  24520. yeokorean: 0x3155,
  24521. yeorinhieuhkorean: 0x3186,
  24522. yerahbenyomohebrew: 0x05AA,
  24523. yerahbenyomolefthebrew: 0x05AA,
  24524. yericyrillic: 0x044B,
  24525. yerudieresiscyrillic: 0x04F9,
  24526. yesieungkorean: 0x3181,
  24527. yesieungpansioskorean: 0x3183,
  24528. yesieungsioskorean: 0x3182,
  24529. yetivhebrew: 0x059A,
  24530. ygrave: 0x1EF3,
  24531. yhook: 0x01B4,
  24532. yhookabove: 0x1EF7,
  24533. yiarmenian: 0x0575,
  24534. yicyrillic: 0x0457,
  24535. yikorean: 0x3162,
  24536. yinyang: 0x262F,
  24537. yiwnarmenian: 0x0582,
  24538. ymonospace: 0xFF59,
  24539. yod: 0x05D9,
  24540. yoddagesh: 0xFB39,
  24541. yoddageshhebrew: 0xFB39,
  24542. yodhebrew: 0x05D9,
  24543. yodyodhebrew: 0x05F2,
  24544. yodyodpatahhebrew: 0xFB1F,
  24545. yohiragana: 0x3088,
  24546. yoikorean: 0x3189,
  24547. yokatakana: 0x30E8,
  24548. yokatakanahalfwidth: 0xFF96,
  24549. yokorean: 0x315B,
  24550. yosmallhiragana: 0x3087,
  24551. yosmallkatakana: 0x30E7,
  24552. yosmallkatakanahalfwidth: 0xFF6E,
  24553. yotgreek: 0x03F3,
  24554. yoyaekorean: 0x3188,
  24555. yoyakorean: 0x3187,
  24556. yoyakthai: 0x0E22,
  24557. yoyingthai: 0x0E0D,
  24558. yparen: 0x24B4,
  24559. ypogegrammeni: 0x037A,
  24560. ypogegrammenigreekcmb: 0x0345,
  24561. yr: 0x01A6,
  24562. yring: 0x1E99,
  24563. ysuperior: 0x02B8,
  24564. ytilde: 0x1EF9,
  24565. yturned: 0x028E,
  24566. yuhiragana: 0x3086,
  24567. yuikorean: 0x318C,
  24568. yukatakana: 0x30E6,
  24569. yukatakanahalfwidth: 0xFF95,
  24570. yukorean: 0x3160,
  24571. yusbigcyrillic: 0x046B,
  24572. yusbigiotifiedcyrillic: 0x046D,
  24573. yuslittlecyrillic: 0x0467,
  24574. yuslittleiotifiedcyrillic: 0x0469,
  24575. yusmallhiragana: 0x3085,
  24576. yusmallkatakana: 0x30E5,
  24577. yusmallkatakanahalfwidth: 0xFF6D,
  24578. yuyekorean: 0x318B,
  24579. yuyeokorean: 0x318A,
  24580. yyabengali: 0x09DF,
  24581. yyadeva: 0x095F,
  24582. z: 0x007A,
  24583. zaarmenian: 0x0566,
  24584. zacute: 0x017A,
  24585. zadeva: 0x095B,
  24586. zagurmukhi: 0x0A5B,
  24587. zaharabic: 0x0638,
  24588. zahfinalarabic: 0xFEC6,
  24589. zahinitialarabic: 0xFEC7,
  24590. zahiragana: 0x3056,
  24591. zahmedialarabic: 0xFEC8,
  24592. zainarabic: 0x0632,
  24593. zainfinalarabic: 0xFEB0,
  24594. zakatakana: 0x30B6,
  24595. zaqefgadolhebrew: 0x0595,
  24596. zaqefqatanhebrew: 0x0594,
  24597. zarqahebrew: 0x0598,
  24598. zayin: 0x05D6,
  24599. zayindagesh: 0xFB36,
  24600. zayindageshhebrew: 0xFB36,
  24601. zayinhebrew: 0x05D6,
  24602. zbopomofo: 0x3117,
  24603. zcaron: 0x017E,
  24604. zcircle: 0x24E9,
  24605. zcircumflex: 0x1E91,
  24606. zcurl: 0x0291,
  24607. zdot: 0x017C,
  24608. zdotaccent: 0x017C,
  24609. zdotbelow: 0x1E93,
  24610. zecyrillic: 0x0437,
  24611. zedescendercyrillic: 0x0499,
  24612. zedieresiscyrillic: 0x04DF,
  24613. zehiragana: 0x305C,
  24614. zekatakana: 0x30BC,
  24615. zero: 0x0030,
  24616. zeroarabic: 0x0660,
  24617. zerobengali: 0x09E6,
  24618. zerodeva: 0x0966,
  24619. zerogujarati: 0x0AE6,
  24620. zerogurmukhi: 0x0A66,
  24621. zerohackarabic: 0x0660,
  24622. zeroinferior: 0x2080,
  24623. zeromonospace: 0xFF10,
  24624. zerooldstyle: 0xF730,
  24625. zeropersian: 0x06F0,
  24626. zerosuperior: 0x2070,
  24627. zerothai: 0x0E50,
  24628. zerowidthjoiner: 0xFEFF,
  24629. zerowidthnonjoiner: 0x200C,
  24630. zerowidthspace: 0x200B,
  24631. zeta: 0x03B6,
  24632. zhbopomofo: 0x3113,
  24633. zhearmenian: 0x056A,
  24634. zhebrevecyrillic: 0x04C2,
  24635. zhecyrillic: 0x0436,
  24636. zhedescendercyrillic: 0x0497,
  24637. zhedieresiscyrillic: 0x04DD,
  24638. zihiragana: 0x3058,
  24639. zikatakana: 0x30B8,
  24640. zinorhebrew: 0x05AE,
  24641. zlinebelow: 0x1E95,
  24642. zmonospace: 0xFF5A,
  24643. zohiragana: 0x305E,
  24644. zokatakana: 0x30BE,
  24645. zparen: 0x24B5,
  24646. zretroflexhook: 0x0290,
  24647. zstroke: 0x01B6,
  24648. zuhiragana: 0x305A,
  24649. zukatakana: 0x30BA,
  24650. '.notdef': 0x0000
  24651. };
  24652. var DingbatsGlyphsUnicode = {
  24653. space: 0x0020,
  24654. a1: 0x2701,
  24655. a2: 0x2702,
  24656. a202: 0x2703,
  24657. a3: 0x2704,
  24658. a4: 0x260E,
  24659. a5: 0x2706,
  24660. a119: 0x2707,
  24661. a118: 0x2708,
  24662. a117: 0x2709,
  24663. a11: 0x261B,
  24664. a12: 0x261E,
  24665. a13: 0x270C,
  24666. a14: 0x270D,
  24667. a15: 0x270E,
  24668. a16: 0x270F,
  24669. a105: 0x2710,
  24670. a17: 0x2711,
  24671. a18: 0x2712,
  24672. a19: 0x2713,
  24673. a20: 0x2714,
  24674. a21: 0x2715,
  24675. a22: 0x2716,
  24676. a23: 0x2717,
  24677. a24: 0x2718,
  24678. a25: 0x2719,
  24679. a26: 0x271A,
  24680. a27: 0x271B,
  24681. a28: 0x271C,
  24682. a6: 0x271D,
  24683. a7: 0x271E,
  24684. a8: 0x271F,
  24685. a9: 0x2720,
  24686. a10: 0x2721,
  24687. a29: 0x2722,
  24688. a30: 0x2723,
  24689. a31: 0x2724,
  24690. a32: 0x2725,
  24691. a33: 0x2726,
  24692. a34: 0x2727,
  24693. a35: 0x2605,
  24694. a36: 0x2729,
  24695. a37: 0x272A,
  24696. a38: 0x272B,
  24697. a39: 0x272C,
  24698. a40: 0x272D,
  24699. a41: 0x272E,
  24700. a42: 0x272F,
  24701. a43: 0x2730,
  24702. a44: 0x2731,
  24703. a45: 0x2732,
  24704. a46: 0x2733,
  24705. a47: 0x2734,
  24706. a48: 0x2735,
  24707. a49: 0x2736,
  24708. a50: 0x2737,
  24709. a51: 0x2738,
  24710. a52: 0x2739,
  24711. a53: 0x273A,
  24712. a54: 0x273B,
  24713. a55: 0x273C,
  24714. a56: 0x273D,
  24715. a57: 0x273E,
  24716. a58: 0x273F,
  24717. a59: 0x2740,
  24718. a60: 0x2741,
  24719. a61: 0x2742,
  24720. a62: 0x2743,
  24721. a63: 0x2744,
  24722. a64: 0x2745,
  24723. a65: 0x2746,
  24724. a66: 0x2747,
  24725. a67: 0x2748,
  24726. a68: 0x2749,
  24727. a69: 0x274A,
  24728. a70: 0x274B,
  24729. a71: 0x25CF,
  24730. a72: 0x274D,
  24731. a73: 0x25A0,
  24732. a74: 0x274F,
  24733. a203: 0x2750,
  24734. a75: 0x2751,
  24735. a204: 0x2752,
  24736. a76: 0x25B2,
  24737. a77: 0x25BC,
  24738. a78: 0x25C6,
  24739. a79: 0x2756,
  24740. a81: 0x25D7,
  24741. a82: 0x2758,
  24742. a83: 0x2759,
  24743. a84: 0x275A,
  24744. a97: 0x275B,
  24745. a98: 0x275C,
  24746. a99: 0x275D,
  24747. a100: 0x275E,
  24748. a101: 0x2761,
  24749. a102: 0x2762,
  24750. a103: 0x2763,
  24751. a104: 0x2764,
  24752. a106: 0x2765,
  24753. a107: 0x2766,
  24754. a108: 0x2767,
  24755. a112: 0x2663,
  24756. a111: 0x2666,
  24757. a110: 0x2665,
  24758. a109: 0x2660,
  24759. a120: 0x2460,
  24760. a121: 0x2461,
  24761. a122: 0x2462,
  24762. a123: 0x2463,
  24763. a124: 0x2464,
  24764. a125: 0x2465,
  24765. a126: 0x2466,
  24766. a127: 0x2467,
  24767. a128: 0x2468,
  24768. a129: 0x2469,
  24769. a130: 0x2776,
  24770. a131: 0x2777,
  24771. a132: 0x2778,
  24772. a133: 0x2779,
  24773. a134: 0x277A,
  24774. a135: 0x277B,
  24775. a136: 0x277C,
  24776. a137: 0x277D,
  24777. a138: 0x277E,
  24778. a139: 0x277F,
  24779. a140: 0x2780,
  24780. a141: 0x2781,
  24781. a142: 0x2782,
  24782. a143: 0x2783,
  24783. a144: 0x2784,
  24784. a145: 0x2785,
  24785. a146: 0x2786,
  24786. a147: 0x2787,
  24787. a148: 0x2788,
  24788. a149: 0x2789,
  24789. a150: 0x278A,
  24790. a151: 0x278B,
  24791. a152: 0x278C,
  24792. a153: 0x278D,
  24793. a154: 0x278E,
  24794. a155: 0x278F,
  24795. a156: 0x2790,
  24796. a157: 0x2791,
  24797. a158: 0x2792,
  24798. a159: 0x2793,
  24799. a160: 0x2794,
  24800. a161: 0x2192,
  24801. a163: 0x2194,
  24802. a164: 0x2195,
  24803. a196: 0x2798,
  24804. a165: 0x2799,
  24805. a192: 0x279A,
  24806. a166: 0x279B,
  24807. a167: 0x279C,
  24808. a168: 0x279D,
  24809. a169: 0x279E,
  24810. a170: 0x279F,
  24811. a171: 0x27A0,
  24812. a172: 0x27A1,
  24813. a173: 0x27A2,
  24814. a162: 0x27A3,
  24815. a174: 0x27A4,
  24816. a175: 0x27A5,
  24817. a176: 0x27A6,
  24818. a177: 0x27A7,
  24819. a178: 0x27A8,
  24820. a179: 0x27A9,
  24821. a193: 0x27AA,
  24822. a180: 0x27AB,
  24823. a199: 0x27AC,
  24824. a181: 0x27AD,
  24825. a200: 0x27AE,
  24826. a182: 0x27AF,
  24827. a201: 0x27B1,
  24828. a183: 0x27B2,
  24829. a184: 0x27B3,
  24830. a197: 0x27B4,
  24831. a185: 0x27B5,
  24832. a194: 0x27B6,
  24833. a198: 0x27B7,
  24834. a186: 0x27B8,
  24835. a195: 0x27B9,
  24836. a187: 0x27BA,
  24837. a188: 0x27BB,
  24838. a189: 0x27BC,
  24839. a190: 0x27BD,
  24840. a191: 0x27BE,
  24841. a89: 0x2768, // 0xF8D7
  24842. a90: 0x2769, // 0xF8D8
  24843. a93: 0x276A, // 0xF8D9
  24844. a94: 0x276B, // 0xF8DA
  24845. a91: 0x276C, // 0xF8DB
  24846. a92: 0x276D, // 0xF8DC
  24847. a205: 0x276E, // 0xF8DD
  24848. a85: 0x276F, // 0xF8DE
  24849. a206: 0x2770, // 0xF8DF
  24850. a86: 0x2771, // 0xF8E0
  24851. a87: 0x2772, // 0xF8E1
  24852. a88: 0x2773, // 0xF8E2
  24853. a95: 0x2774, // 0xF8E3
  24854. a96: 0x2775, // 0xF8E4
  24855. '.notdef': 0x0000
  24856. };
  24857. var PDFImage = (function PDFImageClosure() {
  24858. /**
  24859. * Decode the image in the main thread if it supported. Resovles the promise
  24860. * when the image data is ready.
  24861. */
  24862. function handleImageData(handler, xref, res, image) {
  24863. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24864. // For natively supported jpegs send them to the main thread for decoding.
  24865. var dict = image.dict;
  24866. var colorSpace = dict.get('ColorSpace', 'CS');
  24867. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24868. var numComps = colorSpace.numComps;
  24869. var decodePromise = handler.sendWithPromise('JpegDecode',
  24870. [image.getIR(), numComps]);
  24871. return decodePromise.then(function (message) {
  24872. var data = message.data;
  24873. return new Stream(data, 0, data.length, image.dict);
  24874. });
  24875. } else {
  24876. return Promise.resolve(image);
  24877. }
  24878. }
  24879. /**
  24880. * Decode and clamp a value. The formula is different from the spec because we
  24881. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24882. */
  24883. function decodeAndClamp(value, addend, coefficient, max) {
  24884. value = addend + value * coefficient;
  24885. // Clamp the value to the range
  24886. return (value < 0 ? 0 : (value > max ? max : value));
  24887. }
  24888. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24889. this.image = image;
  24890. var dict = image.dict;
  24891. if (dict.has('Filter')) {
  24892. var filter = dict.get('Filter').name;
  24893. if (filter === 'JPXDecode') {
  24894. var jpxImage = new JpxImage();
  24895. jpxImage.parseImageProperties(image.stream);
  24896. image.stream.reset();
  24897. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24898. image.numComps = jpxImage.componentsCount;
  24899. } else if (filter === 'JBIG2Decode') {
  24900. image.bitsPerComponent = 1;
  24901. image.numComps = 1;
  24902. }
  24903. }
  24904. // TODO cache rendered images?
  24905. this.width = dict.get('Width', 'W');
  24906. this.height = dict.get('Height', 'H');
  24907. if (this.width < 1 || this.height < 1) {
  24908. error('Invalid image width: ' + this.width + ' or height: ' +
  24909. this.height);
  24910. }
  24911. this.interpolate = dict.get('Interpolate', 'I') || false;
  24912. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24913. this.matte = dict.get('Matte') || false;
  24914. var bitsPerComponent = image.bitsPerComponent;
  24915. if (!bitsPerComponent) {
  24916. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24917. if (!bitsPerComponent) {
  24918. if (this.imageMask) {
  24919. bitsPerComponent = 1;
  24920. } else {
  24921. error('Bits per component missing in image: ' + this.imageMask);
  24922. }
  24923. }
  24924. }
  24925. this.bpc = bitsPerComponent;
  24926. if (!this.imageMask) {
  24927. var colorSpace = dict.get('ColorSpace', 'CS');
  24928. if (!colorSpace) {
  24929. info('JPX images (which do not require color spaces)');
  24930. switch (image.numComps) {
  24931. case 1:
  24932. colorSpace = Name.get('DeviceGray');
  24933. break;
  24934. case 3:
  24935. colorSpace = Name.get('DeviceRGB');
  24936. break;
  24937. case 4:
  24938. colorSpace = Name.get('DeviceCMYK');
  24939. break;
  24940. default:
  24941. error('JPX images with ' + this.numComps +
  24942. ' color components not supported.');
  24943. }
  24944. }
  24945. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24946. this.numComps = this.colorSpace.numComps;
  24947. }
  24948. this.decode = dict.get('Decode', 'D');
  24949. this.needsDecode = false;
  24950. if (this.decode &&
  24951. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24952. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24953. this.needsDecode = true;
  24954. // Do some preprocessing to avoid more math.
  24955. var max = (1 << bitsPerComponent) - 1;
  24956. this.decodeCoefficients = [];
  24957. this.decodeAddends = [];
  24958. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24959. var dmin = this.decode[i];
  24960. var dmax = this.decode[i + 1];
  24961. this.decodeCoefficients[j] = dmax - dmin;
  24962. this.decodeAddends[j] = max * dmin;
  24963. }
  24964. }
  24965. if (smask) {
  24966. this.smask = new PDFImage(xref, res, smask, false);
  24967. } else if (mask) {
  24968. if (isStream(mask)) {
  24969. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24970. } else {
  24971. // Color key mask (just an array).
  24972. this.mask = mask;
  24973. }
  24974. }
  24975. }
  24976. /**
  24977. * Handles processing of image data and returns the Promise that is resolved
  24978. * with a PDFImage when the image is ready to be used.
  24979. */
  24980. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24981. res, image, inline) {
  24982. var imagePromise = handleImageData(handler, xref, res, image);
  24983. var smaskPromise;
  24984. var maskPromise;
  24985. var smask = image.dict.get('SMask');
  24986. var mask = image.dict.get('Mask');
  24987. if (smask) {
  24988. smaskPromise = handleImageData(handler, xref, res, smask);
  24989. maskPromise = Promise.resolve(null);
  24990. } else {
  24991. smaskPromise = Promise.resolve(null);
  24992. if (mask) {
  24993. if (isStream(mask)) {
  24994. maskPromise = handleImageData(handler, xref, res, mask);
  24995. } else if (isArray(mask)) {
  24996. maskPromise = Promise.resolve(mask);
  24997. } else {
  24998. warn('Unsupported mask format.');
  24999. maskPromise = Promise.resolve(null);
  25000. }
  25001. } else {
  25002. maskPromise = Promise.resolve(null);
  25003. }
  25004. }
  25005. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25006. function(results) {
  25007. var imageData = results[0];
  25008. var smaskData = results[1];
  25009. var maskData = results[2];
  25010. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25011. });
  25012. };
  25013. /**
  25014. * Resize an image using the nearest neighbor algorithm. Currently only
  25015. * supports one and three component images.
  25016. * @param {TypedArray} pixels The original image with one component.
  25017. * @param {Number} bpc Number of bits per component.
  25018. * @param {Number} components Number of color components, 1 or 3 is supported.
  25019. * @param {Number} w1 Original width.
  25020. * @param {Number} h1 Original height.
  25021. * @param {Number} w2 New width.
  25022. * @param {Number} h2 New height.
  25023. * @param {TypedArray} dest (Optional) The destination buffer.
  25024. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25025. * @return {TypedArray} Resized image data.
  25026. */
  25027. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25028. w1, h1, w2, h2, dest, alpha01) {
  25029. if (components !== 1 && components !== 3) {
  25030. error('Unsupported component count for resizing.');
  25031. }
  25032. var length = w2 * h2 * components;
  25033. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25034. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25035. var xRatio = w1 / w2;
  25036. var yRatio = h1 / h2;
  25037. var i, j, py, newIndex = 0, oldIndex;
  25038. var xScaled = new Uint16Array(w2);
  25039. var w1Scanline = w1 * components;
  25040. if (alpha01 !== 1) {
  25041. alpha01 = 0;
  25042. }
  25043. for (j = 0; j < w2; j++) {
  25044. xScaled[j] = Math.floor(j * xRatio) * components;
  25045. }
  25046. if (components === 1) {
  25047. for (i = 0; i < h2; i++) {
  25048. py = Math.floor(i * yRatio) * w1Scanline;
  25049. for (j = 0; j < w2; j++) {
  25050. oldIndex = py + xScaled[j];
  25051. temp[newIndex++] = pixels[oldIndex];
  25052. }
  25053. }
  25054. } else if (components === 3) {
  25055. for (i = 0; i < h2; i++) {
  25056. py = Math.floor(i * yRatio) * w1Scanline;
  25057. for (j = 0; j < w2; j++) {
  25058. oldIndex = py + xScaled[j];
  25059. temp[newIndex++] = pixels[oldIndex++];
  25060. temp[newIndex++] = pixels[oldIndex++];
  25061. temp[newIndex++] = pixels[oldIndex++];
  25062. newIndex += alpha01;
  25063. }
  25064. }
  25065. }
  25066. return temp;
  25067. };
  25068. PDFImage.createMask =
  25069. function PDFImage_createMask(imgArray, width, height,
  25070. imageIsFromDecodeStream, inverseDecode) {
  25071. // |imgArray| might not contain full data for every pixel of the mask, so
  25072. // we need to distinguish between |computedLength| and |actualLength|.
  25073. // In particular, if inverseDecode is true, then the array we return must
  25074. // have a length of |computedLength|.
  25075. var computedLength = ((width + 7) >> 3) * height;
  25076. var actualLength = imgArray.byteLength;
  25077. var haveFullData = computedLength === actualLength;
  25078. var data, i;
  25079. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25080. // imgArray came from a DecodeStream and its data is in an appropriate
  25081. // form, so we can just transfer it.
  25082. data = imgArray;
  25083. } else if (!inverseDecode) {
  25084. data = new Uint8Array(actualLength);
  25085. data.set(imgArray);
  25086. } else {
  25087. data = new Uint8Array(computedLength);
  25088. data.set(imgArray);
  25089. for (i = actualLength; i < computedLength; i++) {
  25090. data[i] = 0xff;
  25091. }
  25092. }
  25093. // If necessary, invert the original mask data (but not any extra we might
  25094. // have added above). It's safe to modify the array -- whether it's the
  25095. // original or a copy, we're about to transfer it anyway, so nothing else
  25096. // in this thread can be relying on its contents.
  25097. if (inverseDecode) {
  25098. for (i = 0; i < actualLength; i++) {
  25099. data[i] = ~data[i];
  25100. }
  25101. }
  25102. return {data: data, width: width, height: height};
  25103. };
  25104. PDFImage.prototype = {
  25105. get drawWidth() {
  25106. return Math.max(this.width,
  25107. this.smask && this.smask.width || 0,
  25108. this.mask && this.mask.width || 0);
  25109. },
  25110. get drawHeight() {
  25111. return Math.max(this.height,
  25112. this.smask && this.smask.height || 0,
  25113. this.mask && this.mask.height || 0);
  25114. },
  25115. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25116. var bpc = this.bpc;
  25117. var numComps = this.numComps;
  25118. var decodeAddends = this.decodeAddends;
  25119. var decodeCoefficients = this.decodeCoefficients;
  25120. var max = (1 << bpc) - 1;
  25121. var i, ii;
  25122. if (bpc === 1) {
  25123. // If the buffer needed decode that means it just needs to be inverted.
  25124. for (i = 0, ii = buffer.length; i < ii; i++) {
  25125. buffer[i] = +!(buffer[i]);
  25126. }
  25127. return;
  25128. }
  25129. var index = 0;
  25130. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25131. for (var j = 0; j < numComps; j++) {
  25132. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25133. decodeCoefficients[j], max);
  25134. index++;
  25135. }
  25136. }
  25137. },
  25138. getComponents: function PDFImage_getComponents(buffer) {
  25139. var bpc = this.bpc;
  25140. // This image doesn't require any extra work.
  25141. if (bpc === 8) {
  25142. return buffer;
  25143. }
  25144. var width = this.width;
  25145. var height = this.height;
  25146. var numComps = this.numComps;
  25147. var length = width * height * numComps;
  25148. var bufferPos = 0;
  25149. var output = (bpc <= 8 ? new Uint8Array(length) :
  25150. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25151. var rowComps = width * numComps;
  25152. var max = (1 << bpc) - 1;
  25153. var i = 0, ii, buf;
  25154. if (bpc === 1) {
  25155. // Optimization for reading 1 bpc images.
  25156. var mask, loop1End, loop2End;
  25157. for (var j = 0; j < height; j++) {
  25158. loop1End = i + (rowComps & ~7);
  25159. loop2End = i + rowComps;
  25160. // unroll loop for all full bytes
  25161. while (i < loop1End) {
  25162. buf = buffer[bufferPos++];
  25163. output[i] = (buf >> 7) & 1;
  25164. output[i + 1] = (buf >> 6) & 1;
  25165. output[i + 2] = (buf >> 5) & 1;
  25166. output[i + 3] = (buf >> 4) & 1;
  25167. output[i + 4] = (buf >> 3) & 1;
  25168. output[i + 5] = (buf >> 2) & 1;
  25169. output[i + 6] = (buf >> 1) & 1;
  25170. output[i + 7] = buf & 1;
  25171. i += 8;
  25172. }
  25173. // handle remaing bits
  25174. if (i < loop2End) {
  25175. buf = buffer[bufferPos++];
  25176. mask = 128;
  25177. while (i < loop2End) {
  25178. output[i++] = +!!(buf & mask);
  25179. mask >>= 1;
  25180. }
  25181. }
  25182. }
  25183. } else {
  25184. // The general case that handles all other bpc values.
  25185. var bits = 0;
  25186. buf = 0;
  25187. for (i = 0, ii = length; i < ii; ++i) {
  25188. if (i % rowComps === 0) {
  25189. buf = 0;
  25190. bits = 0;
  25191. }
  25192. while (bits < bpc) {
  25193. buf = (buf << 8) | buffer[bufferPos++];
  25194. bits += 8;
  25195. }
  25196. var remainingBits = bits - bpc;
  25197. var value = buf >> remainingBits;
  25198. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25199. buf = buf & ((1 << remainingBits) - 1);
  25200. bits = remainingBits;
  25201. }
  25202. }
  25203. return output;
  25204. },
  25205. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25206. actualHeight, image) {
  25207. var smask = this.smask;
  25208. var mask = this.mask;
  25209. var alphaBuf, sw, sh, i, ii, j;
  25210. if (smask) {
  25211. sw = smask.width;
  25212. sh = smask.height;
  25213. alphaBuf = new Uint8Array(sw * sh);
  25214. smask.fillGrayBuffer(alphaBuf);
  25215. if (sw !== width || sh !== height) {
  25216. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25217. height);
  25218. }
  25219. } else if (mask) {
  25220. if (mask instanceof PDFImage) {
  25221. sw = mask.width;
  25222. sh = mask.height;
  25223. alphaBuf = new Uint8Array(sw * sh);
  25224. mask.numComps = 1;
  25225. mask.fillGrayBuffer(alphaBuf);
  25226. // Need to invert values in rgbaBuf
  25227. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25228. alphaBuf[i] = 255 - alphaBuf[i];
  25229. }
  25230. if (sw !== width || sh !== height) {
  25231. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25232. height);
  25233. }
  25234. } else if (isArray(mask)) {
  25235. // Color key mask: if any of the compontents are outside the range
  25236. // then they should be painted.
  25237. alphaBuf = new Uint8Array(width * height);
  25238. var numComps = this.numComps;
  25239. for (i = 0, ii = width * height; i < ii; ++i) {
  25240. var opacity = 0;
  25241. var imageOffset = i * numComps;
  25242. for (j = 0; j < numComps; ++j) {
  25243. var color = image[imageOffset + j];
  25244. var maskOffset = j * 2;
  25245. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25246. opacity = 255;
  25247. break;
  25248. }
  25249. }
  25250. alphaBuf[i] = opacity;
  25251. }
  25252. } else {
  25253. error('Unknown mask format.');
  25254. }
  25255. }
  25256. if (alphaBuf) {
  25257. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25258. rgbaBuf[j] = alphaBuf[i];
  25259. }
  25260. } else {
  25261. // No mask.
  25262. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25263. rgbaBuf[j] = 255;
  25264. }
  25265. }
  25266. },
  25267. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25268. var matte = this.smask && this.smask.matte;
  25269. if (!matte) {
  25270. return;
  25271. }
  25272. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25273. var matteR = matteRgb[0];
  25274. var matteG = matteRgb[1];
  25275. var matteB = matteRgb[2];
  25276. var length = width * height * 4;
  25277. var r, g, b;
  25278. for (var i = 0; i < length; i += 4) {
  25279. var alpha = buffer[i + 3];
  25280. if (alpha === 0) {
  25281. // according formula we have to get Infinity in all components
  25282. // making it white (typical paper color) should be okay
  25283. buffer[i] = 255;
  25284. buffer[i + 1] = 255;
  25285. buffer[i + 2] = 255;
  25286. continue;
  25287. }
  25288. var k = 255 / alpha;
  25289. r = (buffer[i] - matteR) * k + matteR;
  25290. g = (buffer[i + 1] - matteG) * k + matteG;
  25291. b = (buffer[i + 2] - matteB) * k + matteB;
  25292. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25293. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25294. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25295. }
  25296. },
  25297. createImageData: function PDFImage_createImageData(forceRGBA) {
  25298. var drawWidth = this.drawWidth;
  25299. var drawHeight = this.drawHeight;
  25300. var imgData = { // other fields are filled in below
  25301. width: drawWidth,
  25302. height: drawHeight
  25303. };
  25304. var numComps = this.numComps;
  25305. var originalWidth = this.width;
  25306. var originalHeight = this.height;
  25307. var bpc = this.bpc;
  25308. // Rows start at byte boundary.
  25309. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25310. var imgArray;
  25311. if (!forceRGBA) {
  25312. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25313. // without any complications, we pass a same-sized copy to the main
  25314. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25315. // of memory for many scanned documents. It's also much faster.
  25316. //
  25317. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25318. // complications, we avoid expanding by 1.333x to RGBA form.
  25319. var kind;
  25320. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25321. kind = ImageKind.GRAYSCALE_1BPP;
  25322. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25323. !this.needsDecode) {
  25324. kind = ImageKind.RGB_24BPP;
  25325. }
  25326. if (kind && !this.smask && !this.mask &&
  25327. drawWidth === originalWidth && drawHeight === originalHeight) {
  25328. imgData.kind = kind;
  25329. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25330. // If imgArray came from a DecodeStream, we're safe to transfer it
  25331. // (and thus neuter it) because it will constitute the entire
  25332. // DecodeStream's data. But if it came from a Stream, we need to
  25333. // copy it because it'll only be a portion of the Stream's data, and
  25334. // the rest will be read later on.
  25335. if (this.image instanceof DecodeStream) {
  25336. imgData.data = imgArray;
  25337. } else {
  25338. var newArray = new Uint8Array(imgArray.length);
  25339. newArray.set(imgArray);
  25340. imgData.data = newArray;
  25341. }
  25342. if (this.needsDecode) {
  25343. // Invert the buffer (which must be grayscale if we reached here).
  25344. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25345. var buffer = imgData.data;
  25346. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25347. buffer[i] ^= 0xff;
  25348. }
  25349. }
  25350. return imgData;
  25351. }
  25352. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25353. imgData.kind = ImageKind.RGB_24BPP;
  25354. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25355. drawWidth, drawHeight, true);
  25356. return imgData;
  25357. }
  25358. }
  25359. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25360. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25361. var actualHeight = 0 | (imgArray.length / rowBytes *
  25362. drawHeight / originalHeight);
  25363. var comps = this.getComponents(imgArray);
  25364. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25365. // more compact RGB_24BPP form if allowable.
  25366. var alpha01, maybeUndoPreblend;
  25367. if (!forceRGBA && !this.smask && !this.mask) {
  25368. imgData.kind = ImageKind.RGB_24BPP;
  25369. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25370. alpha01 = 0;
  25371. maybeUndoPreblend = false;
  25372. } else {
  25373. imgData.kind = ImageKind.RGBA_32BPP;
  25374. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25375. alpha01 = 1;
  25376. maybeUndoPreblend = true;
  25377. // Color key masking (opacity) must be performed before decoding.
  25378. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25379. comps);
  25380. }
  25381. if (this.needsDecode) {
  25382. this.decodeBuffer(comps);
  25383. }
  25384. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25385. drawWidth, drawHeight, actualHeight, bpc, comps,
  25386. alpha01);
  25387. if (maybeUndoPreblend) {
  25388. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25389. }
  25390. return imgData;
  25391. },
  25392. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25393. var numComps = this.numComps;
  25394. if (numComps !== 1) {
  25395. error('Reading gray scale from a color image: ' + numComps);
  25396. }
  25397. var width = this.width;
  25398. var height = this.height;
  25399. var bpc = this.bpc;
  25400. // rows start at byte boundary
  25401. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25402. var imgArray = this.getImageBytes(height * rowBytes);
  25403. var comps = this.getComponents(imgArray);
  25404. var i, length;
  25405. if (bpc === 1) {
  25406. // inline decoding (= inversion) for 1 bpc images
  25407. length = width * height;
  25408. if (this.needsDecode) {
  25409. // invert and scale to {0, 255}
  25410. for (i = 0; i < length; ++i) {
  25411. buffer[i] = (comps[i] - 1) & 255;
  25412. }
  25413. } else {
  25414. // scale to {0, 255}
  25415. for (i = 0; i < length; ++i) {
  25416. buffer[i] = (-comps[i]) & 255;
  25417. }
  25418. }
  25419. return;
  25420. }
  25421. if (this.needsDecode) {
  25422. this.decodeBuffer(comps);
  25423. }
  25424. length = width * height;
  25425. // we aren't using a colorspace so we need to scale the value
  25426. var scale = 255 / ((1 << bpc) - 1);
  25427. for (i = 0; i < length; ++i) {
  25428. buffer[i] = (scale * comps[i]) | 0;
  25429. }
  25430. },
  25431. getImageBytes: function PDFImage_getImageBytes(length,
  25432. drawWidth, drawHeight,
  25433. forceRGB) {
  25434. this.image.reset();
  25435. this.image.drawWidth = drawWidth || this.width;
  25436. this.image.drawHeight = drawHeight || this.height;
  25437. this.image.forceRGB = !!forceRGB;
  25438. return this.image.getBytes(length);
  25439. }
  25440. };
  25441. return PDFImage;
  25442. })();
  25443. // The Metrics object contains glyph widths (in glyph space units).
  25444. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25445. // space unit corresponds to 1/1000th of text space unit.
  25446. var Metrics = {
  25447. 'Courier': 600,
  25448. 'Courier-Bold': 600,
  25449. 'Courier-BoldOblique': 600,
  25450. 'Courier-Oblique': 600,
  25451. 'Helvetica' : {
  25452. 'space': 278,
  25453. 'exclam': 278,
  25454. 'quotedbl': 355,
  25455. 'numbersign': 556,
  25456. 'dollar': 556,
  25457. 'percent': 889,
  25458. 'ampersand': 667,
  25459. 'quoteright': 222,
  25460. 'parenleft': 333,
  25461. 'parenright': 333,
  25462. 'asterisk': 389,
  25463. 'plus': 584,
  25464. 'comma': 278,
  25465. 'hyphen': 333,
  25466. 'period': 278,
  25467. 'slash': 278,
  25468. 'zero': 556,
  25469. 'one': 556,
  25470. 'two': 556,
  25471. 'three': 556,
  25472. 'four': 556,
  25473. 'five': 556,
  25474. 'six': 556,
  25475. 'seven': 556,
  25476. 'eight': 556,
  25477. 'nine': 556,
  25478. 'colon': 278,
  25479. 'semicolon': 278,
  25480. 'less': 584,
  25481. 'equal': 584,
  25482. 'greater': 584,
  25483. 'question': 556,
  25484. 'at': 1015,
  25485. 'A': 667,
  25486. 'B': 667,
  25487. 'C': 722,
  25488. 'D': 722,
  25489. 'E': 667,
  25490. 'F': 611,
  25491. 'G': 778,
  25492. 'H': 722,
  25493. 'I': 278,
  25494. 'J': 500,
  25495. 'K': 667,
  25496. 'L': 556,
  25497. 'M': 833,
  25498. 'N': 722,
  25499. 'O': 778,
  25500. 'P': 667,
  25501. 'Q': 778,
  25502. 'R': 722,
  25503. 'S': 667,
  25504. 'T': 611,
  25505. 'U': 722,
  25506. 'V': 667,
  25507. 'W': 944,
  25508. 'X': 667,
  25509. 'Y': 667,
  25510. 'Z': 611,
  25511. 'bracketleft': 278,
  25512. 'backslash': 278,
  25513. 'bracketright': 278,
  25514. 'asciicircum': 469,
  25515. 'underscore': 556,
  25516. 'quoteleft': 222,
  25517. 'a': 556,
  25518. 'b': 556,
  25519. 'c': 500,
  25520. 'd': 556,
  25521. 'e': 556,
  25522. 'f': 278,
  25523. 'g': 556,
  25524. 'h': 556,
  25525. 'i': 222,
  25526. 'j': 222,
  25527. 'k': 500,
  25528. 'l': 222,
  25529. 'm': 833,
  25530. 'n': 556,
  25531. 'o': 556,
  25532. 'p': 556,
  25533. 'q': 556,
  25534. 'r': 333,
  25535. 's': 500,
  25536. 't': 278,
  25537. 'u': 556,
  25538. 'v': 500,
  25539. 'w': 722,
  25540. 'x': 500,
  25541. 'y': 500,
  25542. 'z': 500,
  25543. 'braceleft': 334,
  25544. 'bar': 260,
  25545. 'braceright': 334,
  25546. 'asciitilde': 584,
  25547. 'exclamdown': 333,
  25548. 'cent': 556,
  25549. 'sterling': 556,
  25550. 'fraction': 167,
  25551. 'yen': 556,
  25552. 'florin': 556,
  25553. 'section': 556,
  25554. 'currency': 556,
  25555. 'quotesingle': 191,
  25556. 'quotedblleft': 333,
  25557. 'guillemotleft': 556,
  25558. 'guilsinglleft': 333,
  25559. 'guilsinglright': 333,
  25560. 'fi': 500,
  25561. 'fl': 500,
  25562. 'endash': 556,
  25563. 'dagger': 556,
  25564. 'daggerdbl': 556,
  25565. 'periodcentered': 278,
  25566. 'paragraph': 537,
  25567. 'bullet': 350,
  25568. 'quotesinglbase': 222,
  25569. 'quotedblbase': 333,
  25570. 'quotedblright': 333,
  25571. 'guillemotright': 556,
  25572. 'ellipsis': 1000,
  25573. 'perthousand': 1000,
  25574. 'questiondown': 611,
  25575. 'grave': 333,
  25576. 'acute': 333,
  25577. 'circumflex': 333,
  25578. 'tilde': 333,
  25579. 'macron': 333,
  25580. 'breve': 333,
  25581. 'dotaccent': 333,
  25582. 'dieresis': 333,
  25583. 'ring': 333,
  25584. 'cedilla': 333,
  25585. 'hungarumlaut': 333,
  25586. 'ogonek': 333,
  25587. 'caron': 333,
  25588. 'emdash': 1000,
  25589. 'AE': 1000,
  25590. 'ordfeminine': 370,
  25591. 'Lslash': 556,
  25592. 'Oslash': 778,
  25593. 'OE': 1000,
  25594. 'ordmasculine': 365,
  25595. 'ae': 889,
  25596. 'dotlessi': 278,
  25597. 'lslash': 222,
  25598. 'oslash': 611,
  25599. 'oe': 944,
  25600. 'germandbls': 611,
  25601. 'Idieresis': 278,
  25602. 'eacute': 556,
  25603. 'abreve': 556,
  25604. 'uhungarumlaut': 556,
  25605. 'ecaron': 556,
  25606. 'Ydieresis': 667,
  25607. 'divide': 584,
  25608. 'Yacute': 667,
  25609. 'Acircumflex': 667,
  25610. 'aacute': 556,
  25611. 'Ucircumflex': 722,
  25612. 'yacute': 500,
  25613. 'scommaaccent': 500,
  25614. 'ecircumflex': 556,
  25615. 'Uring': 722,
  25616. 'Udieresis': 722,
  25617. 'aogonek': 556,
  25618. 'Uacute': 722,
  25619. 'uogonek': 556,
  25620. 'Edieresis': 667,
  25621. 'Dcroat': 722,
  25622. 'commaaccent': 250,
  25623. 'copyright': 737,
  25624. 'Emacron': 667,
  25625. 'ccaron': 500,
  25626. 'aring': 556,
  25627. 'Ncommaaccent': 722,
  25628. 'lacute': 222,
  25629. 'agrave': 556,
  25630. 'Tcommaaccent': 611,
  25631. 'Cacute': 722,
  25632. 'atilde': 556,
  25633. 'Edotaccent': 667,
  25634. 'scaron': 500,
  25635. 'scedilla': 500,
  25636. 'iacute': 278,
  25637. 'lozenge': 471,
  25638. 'Rcaron': 722,
  25639. 'Gcommaaccent': 778,
  25640. 'ucircumflex': 556,
  25641. 'acircumflex': 556,
  25642. 'Amacron': 667,
  25643. 'rcaron': 333,
  25644. 'ccedilla': 500,
  25645. 'Zdotaccent': 611,
  25646. 'Thorn': 667,
  25647. 'Omacron': 778,
  25648. 'Racute': 722,
  25649. 'Sacute': 667,
  25650. 'dcaron': 643,
  25651. 'Umacron': 722,
  25652. 'uring': 556,
  25653. 'threesuperior': 333,
  25654. 'Ograve': 778,
  25655. 'Agrave': 667,
  25656. 'Abreve': 667,
  25657. 'multiply': 584,
  25658. 'uacute': 556,
  25659. 'Tcaron': 611,
  25660. 'partialdiff': 476,
  25661. 'ydieresis': 500,
  25662. 'Nacute': 722,
  25663. 'icircumflex': 278,
  25664. 'Ecircumflex': 667,
  25665. 'adieresis': 556,
  25666. 'edieresis': 556,
  25667. 'cacute': 500,
  25668. 'nacute': 556,
  25669. 'umacron': 556,
  25670. 'Ncaron': 722,
  25671. 'Iacute': 278,
  25672. 'plusminus': 584,
  25673. 'brokenbar': 260,
  25674. 'registered': 737,
  25675. 'Gbreve': 778,
  25676. 'Idotaccent': 278,
  25677. 'summation': 600,
  25678. 'Egrave': 667,
  25679. 'racute': 333,
  25680. 'omacron': 556,
  25681. 'Zacute': 611,
  25682. 'Zcaron': 611,
  25683. 'greaterequal': 549,
  25684. 'Eth': 722,
  25685. 'Ccedilla': 722,
  25686. 'lcommaaccent': 222,
  25687. 'tcaron': 317,
  25688. 'eogonek': 556,
  25689. 'Uogonek': 722,
  25690. 'Aacute': 667,
  25691. 'Adieresis': 667,
  25692. 'egrave': 556,
  25693. 'zacute': 500,
  25694. 'iogonek': 222,
  25695. 'Oacute': 778,
  25696. 'oacute': 556,
  25697. 'amacron': 556,
  25698. 'sacute': 500,
  25699. 'idieresis': 278,
  25700. 'Ocircumflex': 778,
  25701. 'Ugrave': 722,
  25702. 'Delta': 612,
  25703. 'thorn': 556,
  25704. 'twosuperior': 333,
  25705. 'Odieresis': 778,
  25706. 'mu': 556,
  25707. 'igrave': 278,
  25708. 'ohungarumlaut': 556,
  25709. 'Eogonek': 667,
  25710. 'dcroat': 556,
  25711. 'threequarters': 834,
  25712. 'Scedilla': 667,
  25713. 'lcaron': 299,
  25714. 'Kcommaaccent': 667,
  25715. 'Lacute': 556,
  25716. 'trademark': 1000,
  25717. 'edotaccent': 556,
  25718. 'Igrave': 278,
  25719. 'Imacron': 278,
  25720. 'Lcaron': 556,
  25721. 'onehalf': 834,
  25722. 'lessequal': 549,
  25723. 'ocircumflex': 556,
  25724. 'ntilde': 556,
  25725. 'Uhungarumlaut': 722,
  25726. 'Eacute': 667,
  25727. 'emacron': 556,
  25728. 'gbreve': 556,
  25729. 'onequarter': 834,
  25730. 'Scaron': 667,
  25731. 'Scommaaccent': 667,
  25732. 'Ohungarumlaut': 778,
  25733. 'degree': 400,
  25734. 'ograve': 556,
  25735. 'Ccaron': 722,
  25736. 'ugrave': 556,
  25737. 'radical': 453,
  25738. 'Dcaron': 722,
  25739. 'rcommaaccent': 333,
  25740. 'Ntilde': 722,
  25741. 'otilde': 556,
  25742. 'Rcommaaccent': 722,
  25743. 'Lcommaaccent': 556,
  25744. 'Atilde': 667,
  25745. 'Aogonek': 667,
  25746. 'Aring': 667,
  25747. 'Otilde': 778,
  25748. 'zdotaccent': 500,
  25749. 'Ecaron': 667,
  25750. 'Iogonek': 278,
  25751. 'kcommaaccent': 500,
  25752. 'minus': 584,
  25753. 'Icircumflex': 278,
  25754. 'ncaron': 556,
  25755. 'tcommaaccent': 278,
  25756. 'logicalnot': 584,
  25757. 'odieresis': 556,
  25758. 'udieresis': 556,
  25759. 'notequal': 549,
  25760. 'gcommaaccent': 556,
  25761. 'eth': 556,
  25762. 'zcaron': 500,
  25763. 'ncommaaccent': 556,
  25764. 'onesuperior': 333,
  25765. 'imacron': 278,
  25766. 'Euro': 556
  25767. },
  25768. 'Helvetica-Bold': {
  25769. 'space': 278,
  25770. 'exclam': 333,
  25771. 'quotedbl': 474,
  25772. 'numbersign': 556,
  25773. 'dollar': 556,
  25774. 'percent': 889,
  25775. 'ampersand': 722,
  25776. 'quoteright': 278,
  25777. 'parenleft': 333,
  25778. 'parenright': 333,
  25779. 'asterisk': 389,
  25780. 'plus': 584,
  25781. 'comma': 278,
  25782. 'hyphen': 333,
  25783. 'period': 278,
  25784. 'slash': 278,
  25785. 'zero': 556,
  25786. 'one': 556,
  25787. 'two': 556,
  25788. 'three': 556,
  25789. 'four': 556,
  25790. 'five': 556,
  25791. 'six': 556,
  25792. 'seven': 556,
  25793. 'eight': 556,
  25794. 'nine': 556,
  25795. 'colon': 333,
  25796. 'semicolon': 333,
  25797. 'less': 584,
  25798. 'equal': 584,
  25799. 'greater': 584,
  25800. 'question': 611,
  25801. 'at': 975,
  25802. 'A': 722,
  25803. 'B': 722,
  25804. 'C': 722,
  25805. 'D': 722,
  25806. 'E': 667,
  25807. 'F': 611,
  25808. 'G': 778,
  25809. 'H': 722,
  25810. 'I': 278,
  25811. 'J': 556,
  25812. 'K': 722,
  25813. 'L': 611,
  25814. 'M': 833,
  25815. 'N': 722,
  25816. 'O': 778,
  25817. 'P': 667,
  25818. 'Q': 778,
  25819. 'R': 722,
  25820. 'S': 667,
  25821. 'T': 611,
  25822. 'U': 722,
  25823. 'V': 667,
  25824. 'W': 944,
  25825. 'X': 667,
  25826. 'Y': 667,
  25827. 'Z': 611,
  25828. 'bracketleft': 333,
  25829. 'backslash': 278,
  25830. 'bracketright': 333,
  25831. 'asciicircum': 584,
  25832. 'underscore': 556,
  25833. 'quoteleft': 278,
  25834. 'a': 556,
  25835. 'b': 611,
  25836. 'c': 556,
  25837. 'd': 611,
  25838. 'e': 556,
  25839. 'f': 333,
  25840. 'g': 611,
  25841. 'h': 611,
  25842. 'i': 278,
  25843. 'j': 278,
  25844. 'k': 556,
  25845. 'l': 278,
  25846. 'm': 889,
  25847. 'n': 611,
  25848. 'o': 611,
  25849. 'p': 611,
  25850. 'q': 611,
  25851. 'r': 389,
  25852. 's': 556,
  25853. 't': 333,
  25854. 'u': 611,
  25855. 'v': 556,
  25856. 'w': 778,
  25857. 'x': 556,
  25858. 'y': 556,
  25859. 'z': 500,
  25860. 'braceleft': 389,
  25861. 'bar': 280,
  25862. 'braceright': 389,
  25863. 'asciitilde': 584,
  25864. 'exclamdown': 333,
  25865. 'cent': 556,
  25866. 'sterling': 556,
  25867. 'fraction': 167,
  25868. 'yen': 556,
  25869. 'florin': 556,
  25870. 'section': 556,
  25871. 'currency': 556,
  25872. 'quotesingle': 238,
  25873. 'quotedblleft': 500,
  25874. 'guillemotleft': 556,
  25875. 'guilsinglleft': 333,
  25876. 'guilsinglright': 333,
  25877. 'fi': 611,
  25878. 'fl': 611,
  25879. 'endash': 556,
  25880. 'dagger': 556,
  25881. 'daggerdbl': 556,
  25882. 'periodcentered': 278,
  25883. 'paragraph': 556,
  25884. 'bullet': 350,
  25885. 'quotesinglbase': 278,
  25886. 'quotedblbase': 500,
  25887. 'quotedblright': 500,
  25888. 'guillemotright': 556,
  25889. 'ellipsis': 1000,
  25890. 'perthousand': 1000,
  25891. 'questiondown': 611,
  25892. 'grave': 333,
  25893. 'acute': 333,
  25894. 'circumflex': 333,
  25895. 'tilde': 333,
  25896. 'macron': 333,
  25897. 'breve': 333,
  25898. 'dotaccent': 333,
  25899. 'dieresis': 333,
  25900. 'ring': 333,
  25901. 'cedilla': 333,
  25902. 'hungarumlaut': 333,
  25903. 'ogonek': 333,
  25904. 'caron': 333,
  25905. 'emdash': 1000,
  25906. 'AE': 1000,
  25907. 'ordfeminine': 370,
  25908. 'Lslash': 611,
  25909. 'Oslash': 778,
  25910. 'OE': 1000,
  25911. 'ordmasculine': 365,
  25912. 'ae': 889,
  25913. 'dotlessi': 278,
  25914. 'lslash': 278,
  25915. 'oslash': 611,
  25916. 'oe': 944,
  25917. 'germandbls': 611,
  25918. 'Idieresis': 278,
  25919. 'eacute': 556,
  25920. 'abreve': 556,
  25921. 'uhungarumlaut': 611,
  25922. 'ecaron': 556,
  25923. 'Ydieresis': 667,
  25924. 'divide': 584,
  25925. 'Yacute': 667,
  25926. 'Acircumflex': 722,
  25927. 'aacute': 556,
  25928. 'Ucircumflex': 722,
  25929. 'yacute': 556,
  25930. 'scommaaccent': 556,
  25931. 'ecircumflex': 556,
  25932. 'Uring': 722,
  25933. 'Udieresis': 722,
  25934. 'aogonek': 556,
  25935. 'Uacute': 722,
  25936. 'uogonek': 611,
  25937. 'Edieresis': 667,
  25938. 'Dcroat': 722,
  25939. 'commaaccent': 250,
  25940. 'copyright': 737,
  25941. 'Emacron': 667,
  25942. 'ccaron': 556,
  25943. 'aring': 556,
  25944. 'Ncommaaccent': 722,
  25945. 'lacute': 278,
  25946. 'agrave': 556,
  25947. 'Tcommaaccent': 611,
  25948. 'Cacute': 722,
  25949. 'atilde': 556,
  25950. 'Edotaccent': 667,
  25951. 'scaron': 556,
  25952. 'scedilla': 556,
  25953. 'iacute': 278,
  25954. 'lozenge': 494,
  25955. 'Rcaron': 722,
  25956. 'Gcommaaccent': 778,
  25957. 'ucircumflex': 611,
  25958. 'acircumflex': 556,
  25959. 'Amacron': 722,
  25960. 'rcaron': 389,
  25961. 'ccedilla': 556,
  25962. 'Zdotaccent': 611,
  25963. 'Thorn': 667,
  25964. 'Omacron': 778,
  25965. 'Racute': 722,
  25966. 'Sacute': 667,
  25967. 'dcaron': 743,
  25968. 'Umacron': 722,
  25969. 'uring': 611,
  25970. 'threesuperior': 333,
  25971. 'Ograve': 778,
  25972. 'Agrave': 722,
  25973. 'Abreve': 722,
  25974. 'multiply': 584,
  25975. 'uacute': 611,
  25976. 'Tcaron': 611,
  25977. 'partialdiff': 494,
  25978. 'ydieresis': 556,
  25979. 'Nacute': 722,
  25980. 'icircumflex': 278,
  25981. 'Ecircumflex': 667,
  25982. 'adieresis': 556,
  25983. 'edieresis': 556,
  25984. 'cacute': 556,
  25985. 'nacute': 611,
  25986. 'umacron': 611,
  25987. 'Ncaron': 722,
  25988. 'Iacute': 278,
  25989. 'plusminus': 584,
  25990. 'brokenbar': 280,
  25991. 'registered': 737,
  25992. 'Gbreve': 778,
  25993. 'Idotaccent': 278,
  25994. 'summation': 600,
  25995. 'Egrave': 667,
  25996. 'racute': 389,
  25997. 'omacron': 611,
  25998. 'Zacute': 611,
  25999. 'Zcaron': 611,
  26000. 'greaterequal': 549,
  26001. 'Eth': 722,
  26002. 'Ccedilla': 722,
  26003. 'lcommaaccent': 278,
  26004. 'tcaron': 389,
  26005. 'eogonek': 556,
  26006. 'Uogonek': 722,
  26007. 'Aacute': 722,
  26008. 'Adieresis': 722,
  26009. 'egrave': 556,
  26010. 'zacute': 500,
  26011. 'iogonek': 278,
  26012. 'Oacute': 778,
  26013. 'oacute': 611,
  26014. 'amacron': 556,
  26015. 'sacute': 556,
  26016. 'idieresis': 278,
  26017. 'Ocircumflex': 778,
  26018. 'Ugrave': 722,
  26019. 'Delta': 612,
  26020. 'thorn': 611,
  26021. 'twosuperior': 333,
  26022. 'Odieresis': 778,
  26023. 'mu': 611,
  26024. 'igrave': 278,
  26025. 'ohungarumlaut': 611,
  26026. 'Eogonek': 667,
  26027. 'dcroat': 611,
  26028. 'threequarters': 834,
  26029. 'Scedilla': 667,
  26030. 'lcaron': 400,
  26031. 'Kcommaaccent': 722,
  26032. 'Lacute': 611,
  26033. 'trademark': 1000,
  26034. 'edotaccent': 556,
  26035. 'Igrave': 278,
  26036. 'Imacron': 278,
  26037. 'Lcaron': 611,
  26038. 'onehalf': 834,
  26039. 'lessequal': 549,
  26040. 'ocircumflex': 611,
  26041. 'ntilde': 611,
  26042. 'Uhungarumlaut': 722,
  26043. 'Eacute': 667,
  26044. 'emacron': 556,
  26045. 'gbreve': 611,
  26046. 'onequarter': 834,
  26047. 'Scaron': 667,
  26048. 'Scommaaccent': 667,
  26049. 'Ohungarumlaut': 778,
  26050. 'degree': 400,
  26051. 'ograve': 611,
  26052. 'Ccaron': 722,
  26053. 'ugrave': 611,
  26054. 'radical': 549,
  26055. 'Dcaron': 722,
  26056. 'rcommaaccent': 389,
  26057. 'Ntilde': 722,
  26058. 'otilde': 611,
  26059. 'Rcommaaccent': 722,
  26060. 'Lcommaaccent': 611,
  26061. 'Atilde': 722,
  26062. 'Aogonek': 722,
  26063. 'Aring': 722,
  26064. 'Otilde': 778,
  26065. 'zdotaccent': 500,
  26066. 'Ecaron': 667,
  26067. 'Iogonek': 278,
  26068. 'kcommaaccent': 556,
  26069. 'minus': 584,
  26070. 'Icircumflex': 278,
  26071. 'ncaron': 611,
  26072. 'tcommaaccent': 333,
  26073. 'logicalnot': 584,
  26074. 'odieresis': 611,
  26075. 'udieresis': 611,
  26076. 'notequal': 549,
  26077. 'gcommaaccent': 611,
  26078. 'eth': 611,
  26079. 'zcaron': 500,
  26080. 'ncommaaccent': 611,
  26081. 'onesuperior': 333,
  26082. 'imacron': 278,
  26083. 'Euro': 556
  26084. },
  26085. 'Helvetica-BoldOblique': {
  26086. 'space': 278,
  26087. 'exclam': 333,
  26088. 'quotedbl': 474,
  26089. 'numbersign': 556,
  26090. 'dollar': 556,
  26091. 'percent': 889,
  26092. 'ampersand': 722,
  26093. 'quoteright': 278,
  26094. 'parenleft': 333,
  26095. 'parenright': 333,
  26096. 'asterisk': 389,
  26097. 'plus': 584,
  26098. 'comma': 278,
  26099. 'hyphen': 333,
  26100. 'period': 278,
  26101. 'slash': 278,
  26102. 'zero': 556,
  26103. 'one': 556,
  26104. 'two': 556,
  26105. 'three': 556,
  26106. 'four': 556,
  26107. 'five': 556,
  26108. 'six': 556,
  26109. 'seven': 556,
  26110. 'eight': 556,
  26111. 'nine': 556,
  26112. 'colon': 333,
  26113. 'semicolon': 333,
  26114. 'less': 584,
  26115. 'equal': 584,
  26116. 'greater': 584,
  26117. 'question': 611,
  26118. 'at': 975,
  26119. 'A': 722,
  26120. 'B': 722,
  26121. 'C': 722,
  26122. 'D': 722,
  26123. 'E': 667,
  26124. 'F': 611,
  26125. 'G': 778,
  26126. 'H': 722,
  26127. 'I': 278,
  26128. 'J': 556,
  26129. 'K': 722,
  26130. 'L': 611,
  26131. 'M': 833,
  26132. 'N': 722,
  26133. 'O': 778,
  26134. 'P': 667,
  26135. 'Q': 778,
  26136. 'R': 722,
  26137. 'S': 667,
  26138. 'T': 611,
  26139. 'U': 722,
  26140. 'V': 667,
  26141. 'W': 944,
  26142. 'X': 667,
  26143. 'Y': 667,
  26144. 'Z': 611,
  26145. 'bracketleft': 333,
  26146. 'backslash': 278,
  26147. 'bracketright': 333,
  26148. 'asciicircum': 584,
  26149. 'underscore': 556,
  26150. 'quoteleft': 278,
  26151. 'a': 556,
  26152. 'b': 611,
  26153. 'c': 556,
  26154. 'd': 611,
  26155. 'e': 556,
  26156. 'f': 333,
  26157. 'g': 611,
  26158. 'h': 611,
  26159. 'i': 278,
  26160. 'j': 278,
  26161. 'k': 556,
  26162. 'l': 278,
  26163. 'm': 889,
  26164. 'n': 611,
  26165. 'o': 611,
  26166. 'p': 611,
  26167. 'q': 611,
  26168. 'r': 389,
  26169. 's': 556,
  26170. 't': 333,
  26171. 'u': 611,
  26172. 'v': 556,
  26173. 'w': 778,
  26174. 'x': 556,
  26175. 'y': 556,
  26176. 'z': 500,
  26177. 'braceleft': 389,
  26178. 'bar': 280,
  26179. 'braceright': 389,
  26180. 'asciitilde': 584,
  26181. 'exclamdown': 333,
  26182. 'cent': 556,
  26183. 'sterling': 556,
  26184. 'fraction': 167,
  26185. 'yen': 556,
  26186. 'florin': 556,
  26187. 'section': 556,
  26188. 'currency': 556,
  26189. 'quotesingle': 238,
  26190. 'quotedblleft': 500,
  26191. 'guillemotleft': 556,
  26192. 'guilsinglleft': 333,
  26193. 'guilsinglright': 333,
  26194. 'fi': 611,
  26195. 'fl': 611,
  26196. 'endash': 556,
  26197. 'dagger': 556,
  26198. 'daggerdbl': 556,
  26199. 'periodcentered': 278,
  26200. 'paragraph': 556,
  26201. 'bullet': 350,
  26202. 'quotesinglbase': 278,
  26203. 'quotedblbase': 500,
  26204. 'quotedblright': 500,
  26205. 'guillemotright': 556,
  26206. 'ellipsis': 1000,
  26207. 'perthousand': 1000,
  26208. 'questiondown': 611,
  26209. 'grave': 333,
  26210. 'acute': 333,
  26211. 'circumflex': 333,
  26212. 'tilde': 333,
  26213. 'macron': 333,
  26214. 'breve': 333,
  26215. 'dotaccent': 333,
  26216. 'dieresis': 333,
  26217. 'ring': 333,
  26218. 'cedilla': 333,
  26219. 'hungarumlaut': 333,
  26220. 'ogonek': 333,
  26221. 'caron': 333,
  26222. 'emdash': 1000,
  26223. 'AE': 1000,
  26224. 'ordfeminine': 370,
  26225. 'Lslash': 611,
  26226. 'Oslash': 778,
  26227. 'OE': 1000,
  26228. 'ordmasculine': 365,
  26229. 'ae': 889,
  26230. 'dotlessi': 278,
  26231. 'lslash': 278,
  26232. 'oslash': 611,
  26233. 'oe': 944,
  26234. 'germandbls': 611,
  26235. 'Idieresis': 278,
  26236. 'eacute': 556,
  26237. 'abreve': 556,
  26238. 'uhungarumlaut': 611,
  26239. 'ecaron': 556,
  26240. 'Ydieresis': 667,
  26241. 'divide': 584,
  26242. 'Yacute': 667,
  26243. 'Acircumflex': 722,
  26244. 'aacute': 556,
  26245. 'Ucircumflex': 722,
  26246. 'yacute': 556,
  26247. 'scommaaccent': 556,
  26248. 'ecircumflex': 556,
  26249. 'Uring': 722,
  26250. 'Udieresis': 722,
  26251. 'aogonek': 556,
  26252. 'Uacute': 722,
  26253. 'uogonek': 611,
  26254. 'Edieresis': 667,
  26255. 'Dcroat': 722,
  26256. 'commaaccent': 250,
  26257. 'copyright': 737,
  26258. 'Emacron': 667,
  26259. 'ccaron': 556,
  26260. 'aring': 556,
  26261. 'Ncommaaccent': 722,
  26262. 'lacute': 278,
  26263. 'agrave': 556,
  26264. 'Tcommaaccent': 611,
  26265. 'Cacute': 722,
  26266. 'atilde': 556,
  26267. 'Edotaccent': 667,
  26268. 'scaron': 556,
  26269. 'scedilla': 556,
  26270. 'iacute': 278,
  26271. 'lozenge': 494,
  26272. 'Rcaron': 722,
  26273. 'Gcommaaccent': 778,
  26274. 'ucircumflex': 611,
  26275. 'acircumflex': 556,
  26276. 'Amacron': 722,
  26277. 'rcaron': 389,
  26278. 'ccedilla': 556,
  26279. 'Zdotaccent': 611,
  26280. 'Thorn': 667,
  26281. 'Omacron': 778,
  26282. 'Racute': 722,
  26283. 'Sacute': 667,
  26284. 'dcaron': 743,
  26285. 'Umacron': 722,
  26286. 'uring': 611,
  26287. 'threesuperior': 333,
  26288. 'Ograve': 778,
  26289. 'Agrave': 722,
  26290. 'Abreve': 722,
  26291. 'multiply': 584,
  26292. 'uacute': 611,
  26293. 'Tcaron': 611,
  26294. 'partialdiff': 494,
  26295. 'ydieresis': 556,
  26296. 'Nacute': 722,
  26297. 'icircumflex': 278,
  26298. 'Ecircumflex': 667,
  26299. 'adieresis': 556,
  26300. 'edieresis': 556,
  26301. 'cacute': 556,
  26302. 'nacute': 611,
  26303. 'umacron': 611,
  26304. 'Ncaron': 722,
  26305. 'Iacute': 278,
  26306. 'plusminus': 584,
  26307. 'brokenbar': 280,
  26308. 'registered': 737,
  26309. 'Gbreve': 778,
  26310. 'Idotaccent': 278,
  26311. 'summation': 600,
  26312. 'Egrave': 667,
  26313. 'racute': 389,
  26314. 'omacron': 611,
  26315. 'Zacute': 611,
  26316. 'Zcaron': 611,
  26317. 'greaterequal': 549,
  26318. 'Eth': 722,
  26319. 'Ccedilla': 722,
  26320. 'lcommaaccent': 278,
  26321. 'tcaron': 389,
  26322. 'eogonek': 556,
  26323. 'Uogonek': 722,
  26324. 'Aacute': 722,
  26325. 'Adieresis': 722,
  26326. 'egrave': 556,
  26327. 'zacute': 500,
  26328. 'iogonek': 278,
  26329. 'Oacute': 778,
  26330. 'oacute': 611,
  26331. 'amacron': 556,
  26332. 'sacute': 556,
  26333. 'idieresis': 278,
  26334. 'Ocircumflex': 778,
  26335. 'Ugrave': 722,
  26336. 'Delta': 612,
  26337. 'thorn': 611,
  26338. 'twosuperior': 333,
  26339. 'Odieresis': 778,
  26340. 'mu': 611,
  26341. 'igrave': 278,
  26342. 'ohungarumlaut': 611,
  26343. 'Eogonek': 667,
  26344. 'dcroat': 611,
  26345. 'threequarters': 834,
  26346. 'Scedilla': 667,
  26347. 'lcaron': 400,
  26348. 'Kcommaaccent': 722,
  26349. 'Lacute': 611,
  26350. 'trademark': 1000,
  26351. 'edotaccent': 556,
  26352. 'Igrave': 278,
  26353. 'Imacron': 278,
  26354. 'Lcaron': 611,
  26355. 'onehalf': 834,
  26356. 'lessequal': 549,
  26357. 'ocircumflex': 611,
  26358. 'ntilde': 611,
  26359. 'Uhungarumlaut': 722,
  26360. 'Eacute': 667,
  26361. 'emacron': 556,
  26362. 'gbreve': 611,
  26363. 'onequarter': 834,
  26364. 'Scaron': 667,
  26365. 'Scommaaccent': 667,
  26366. 'Ohungarumlaut': 778,
  26367. 'degree': 400,
  26368. 'ograve': 611,
  26369. 'Ccaron': 722,
  26370. 'ugrave': 611,
  26371. 'radical': 549,
  26372. 'Dcaron': 722,
  26373. 'rcommaaccent': 389,
  26374. 'Ntilde': 722,
  26375. 'otilde': 611,
  26376. 'Rcommaaccent': 722,
  26377. 'Lcommaaccent': 611,
  26378. 'Atilde': 722,
  26379. 'Aogonek': 722,
  26380. 'Aring': 722,
  26381. 'Otilde': 778,
  26382. 'zdotaccent': 500,
  26383. 'Ecaron': 667,
  26384. 'Iogonek': 278,
  26385. 'kcommaaccent': 556,
  26386. 'minus': 584,
  26387. 'Icircumflex': 278,
  26388. 'ncaron': 611,
  26389. 'tcommaaccent': 333,
  26390. 'logicalnot': 584,
  26391. 'odieresis': 611,
  26392. 'udieresis': 611,
  26393. 'notequal': 549,
  26394. 'gcommaaccent': 611,
  26395. 'eth': 611,
  26396. 'zcaron': 500,
  26397. 'ncommaaccent': 611,
  26398. 'onesuperior': 333,
  26399. 'imacron': 278,
  26400. 'Euro': 556
  26401. },
  26402. 'Helvetica-Oblique' : {
  26403. 'space': 278,
  26404. 'exclam': 278,
  26405. 'quotedbl': 355,
  26406. 'numbersign': 556,
  26407. 'dollar': 556,
  26408. 'percent': 889,
  26409. 'ampersand': 667,
  26410. 'quoteright': 222,
  26411. 'parenleft': 333,
  26412. 'parenright': 333,
  26413. 'asterisk': 389,
  26414. 'plus': 584,
  26415. 'comma': 278,
  26416. 'hyphen': 333,
  26417. 'period': 278,
  26418. 'slash': 278,
  26419. 'zero': 556,
  26420. 'one': 556,
  26421. 'two': 556,
  26422. 'three': 556,
  26423. 'four': 556,
  26424. 'five': 556,
  26425. 'six': 556,
  26426. 'seven': 556,
  26427. 'eight': 556,
  26428. 'nine': 556,
  26429. 'colon': 278,
  26430. 'semicolon': 278,
  26431. 'less': 584,
  26432. 'equal': 584,
  26433. 'greater': 584,
  26434. 'question': 556,
  26435. 'at': 1015,
  26436. 'A': 667,
  26437. 'B': 667,
  26438. 'C': 722,
  26439. 'D': 722,
  26440. 'E': 667,
  26441. 'F': 611,
  26442. 'G': 778,
  26443. 'H': 722,
  26444. 'I': 278,
  26445. 'J': 500,
  26446. 'K': 667,
  26447. 'L': 556,
  26448. 'M': 833,
  26449. 'N': 722,
  26450. 'O': 778,
  26451. 'P': 667,
  26452. 'Q': 778,
  26453. 'R': 722,
  26454. 'S': 667,
  26455. 'T': 611,
  26456. 'U': 722,
  26457. 'V': 667,
  26458. 'W': 944,
  26459. 'X': 667,
  26460. 'Y': 667,
  26461. 'Z': 611,
  26462. 'bracketleft': 278,
  26463. 'backslash': 278,
  26464. 'bracketright': 278,
  26465. 'asciicircum': 469,
  26466. 'underscore': 556,
  26467. 'quoteleft': 222,
  26468. 'a': 556,
  26469. 'b': 556,
  26470. 'c': 500,
  26471. 'd': 556,
  26472. 'e': 556,
  26473. 'f': 278,
  26474. 'g': 556,
  26475. 'h': 556,
  26476. 'i': 222,
  26477. 'j': 222,
  26478. 'k': 500,
  26479. 'l': 222,
  26480. 'm': 833,
  26481. 'n': 556,
  26482. 'o': 556,
  26483. 'p': 556,
  26484. 'q': 556,
  26485. 'r': 333,
  26486. 's': 500,
  26487. 't': 278,
  26488. 'u': 556,
  26489. 'v': 500,
  26490. 'w': 722,
  26491. 'x': 500,
  26492. 'y': 500,
  26493. 'z': 500,
  26494. 'braceleft': 334,
  26495. 'bar': 260,
  26496. 'braceright': 334,
  26497. 'asciitilde': 584,
  26498. 'exclamdown': 333,
  26499. 'cent': 556,
  26500. 'sterling': 556,
  26501. 'fraction': 167,
  26502. 'yen': 556,
  26503. 'florin': 556,
  26504. 'section': 556,
  26505. 'currency': 556,
  26506. 'quotesingle': 191,
  26507. 'quotedblleft': 333,
  26508. 'guillemotleft': 556,
  26509. 'guilsinglleft': 333,
  26510. 'guilsinglright': 333,
  26511. 'fi': 500,
  26512. 'fl': 500,
  26513. 'endash': 556,
  26514. 'dagger': 556,
  26515. 'daggerdbl': 556,
  26516. 'periodcentered': 278,
  26517. 'paragraph': 537,
  26518. 'bullet': 350,
  26519. 'quotesinglbase': 222,
  26520. 'quotedblbase': 333,
  26521. 'quotedblright': 333,
  26522. 'guillemotright': 556,
  26523. 'ellipsis': 1000,
  26524. 'perthousand': 1000,
  26525. 'questiondown': 611,
  26526. 'grave': 333,
  26527. 'acute': 333,
  26528. 'circumflex': 333,
  26529. 'tilde': 333,
  26530. 'macron': 333,
  26531. 'breve': 333,
  26532. 'dotaccent': 333,
  26533. 'dieresis': 333,
  26534. 'ring': 333,
  26535. 'cedilla': 333,
  26536. 'hungarumlaut': 333,
  26537. 'ogonek': 333,
  26538. 'caron': 333,
  26539. 'emdash': 1000,
  26540. 'AE': 1000,
  26541. 'ordfeminine': 370,
  26542. 'Lslash': 556,
  26543. 'Oslash': 778,
  26544. 'OE': 1000,
  26545. 'ordmasculine': 365,
  26546. 'ae': 889,
  26547. 'dotlessi': 278,
  26548. 'lslash': 222,
  26549. 'oslash': 611,
  26550. 'oe': 944,
  26551. 'germandbls': 611,
  26552. 'Idieresis': 278,
  26553. 'eacute': 556,
  26554. 'abreve': 556,
  26555. 'uhungarumlaut': 556,
  26556. 'ecaron': 556,
  26557. 'Ydieresis': 667,
  26558. 'divide': 584,
  26559. 'Yacute': 667,
  26560. 'Acircumflex': 667,
  26561. 'aacute': 556,
  26562. 'Ucircumflex': 722,
  26563. 'yacute': 500,
  26564. 'scommaaccent': 500,
  26565. 'ecircumflex': 556,
  26566. 'Uring': 722,
  26567. 'Udieresis': 722,
  26568. 'aogonek': 556,
  26569. 'Uacute': 722,
  26570. 'uogonek': 556,
  26571. 'Edieresis': 667,
  26572. 'Dcroat': 722,
  26573. 'commaaccent': 250,
  26574. 'copyright': 737,
  26575. 'Emacron': 667,
  26576. 'ccaron': 500,
  26577. 'aring': 556,
  26578. 'Ncommaaccent': 722,
  26579. 'lacute': 222,
  26580. 'agrave': 556,
  26581. 'Tcommaaccent': 611,
  26582. 'Cacute': 722,
  26583. 'atilde': 556,
  26584. 'Edotaccent': 667,
  26585. 'scaron': 500,
  26586. 'scedilla': 500,
  26587. 'iacute': 278,
  26588. 'lozenge': 471,
  26589. 'Rcaron': 722,
  26590. 'Gcommaaccent': 778,
  26591. 'ucircumflex': 556,
  26592. 'acircumflex': 556,
  26593. 'Amacron': 667,
  26594. 'rcaron': 333,
  26595. 'ccedilla': 500,
  26596. 'Zdotaccent': 611,
  26597. 'Thorn': 667,
  26598. 'Omacron': 778,
  26599. 'Racute': 722,
  26600. 'Sacute': 667,
  26601. 'dcaron': 643,
  26602. 'Umacron': 722,
  26603. 'uring': 556,
  26604. 'threesuperior': 333,
  26605. 'Ograve': 778,
  26606. 'Agrave': 667,
  26607. 'Abreve': 667,
  26608. 'multiply': 584,
  26609. 'uacute': 556,
  26610. 'Tcaron': 611,
  26611. 'partialdiff': 476,
  26612. 'ydieresis': 500,
  26613. 'Nacute': 722,
  26614. 'icircumflex': 278,
  26615. 'Ecircumflex': 667,
  26616. 'adieresis': 556,
  26617. 'edieresis': 556,
  26618. 'cacute': 500,
  26619. 'nacute': 556,
  26620. 'umacron': 556,
  26621. 'Ncaron': 722,
  26622. 'Iacute': 278,
  26623. 'plusminus': 584,
  26624. 'brokenbar': 260,
  26625. 'registered': 737,
  26626. 'Gbreve': 778,
  26627. 'Idotaccent': 278,
  26628. 'summation': 600,
  26629. 'Egrave': 667,
  26630. 'racute': 333,
  26631. 'omacron': 556,
  26632. 'Zacute': 611,
  26633. 'Zcaron': 611,
  26634. 'greaterequal': 549,
  26635. 'Eth': 722,
  26636. 'Ccedilla': 722,
  26637. 'lcommaaccent': 222,
  26638. 'tcaron': 317,
  26639. 'eogonek': 556,
  26640. 'Uogonek': 722,
  26641. 'Aacute': 667,
  26642. 'Adieresis': 667,
  26643. 'egrave': 556,
  26644. 'zacute': 500,
  26645. 'iogonek': 222,
  26646. 'Oacute': 778,
  26647. 'oacute': 556,
  26648. 'amacron': 556,
  26649. 'sacute': 500,
  26650. 'idieresis': 278,
  26651. 'Ocircumflex': 778,
  26652. 'Ugrave': 722,
  26653. 'Delta': 612,
  26654. 'thorn': 556,
  26655. 'twosuperior': 333,
  26656. 'Odieresis': 778,
  26657. 'mu': 556,
  26658. 'igrave': 278,
  26659. 'ohungarumlaut': 556,
  26660. 'Eogonek': 667,
  26661. 'dcroat': 556,
  26662. 'threequarters': 834,
  26663. 'Scedilla': 667,
  26664. 'lcaron': 299,
  26665. 'Kcommaaccent': 667,
  26666. 'Lacute': 556,
  26667. 'trademark': 1000,
  26668. 'edotaccent': 556,
  26669. 'Igrave': 278,
  26670. 'Imacron': 278,
  26671. 'Lcaron': 556,
  26672. 'onehalf': 834,
  26673. 'lessequal': 549,
  26674. 'ocircumflex': 556,
  26675. 'ntilde': 556,
  26676. 'Uhungarumlaut': 722,
  26677. 'Eacute': 667,
  26678. 'emacron': 556,
  26679. 'gbreve': 556,
  26680. 'onequarter': 834,
  26681. 'Scaron': 667,
  26682. 'Scommaaccent': 667,
  26683. 'Ohungarumlaut': 778,
  26684. 'degree': 400,
  26685. 'ograve': 556,
  26686. 'Ccaron': 722,
  26687. 'ugrave': 556,
  26688. 'radical': 453,
  26689. 'Dcaron': 722,
  26690. 'rcommaaccent': 333,
  26691. 'Ntilde': 722,
  26692. 'otilde': 556,
  26693. 'Rcommaaccent': 722,
  26694. 'Lcommaaccent': 556,
  26695. 'Atilde': 667,
  26696. 'Aogonek': 667,
  26697. 'Aring': 667,
  26698. 'Otilde': 778,
  26699. 'zdotaccent': 500,
  26700. 'Ecaron': 667,
  26701. 'Iogonek': 278,
  26702. 'kcommaaccent': 500,
  26703. 'minus': 584,
  26704. 'Icircumflex': 278,
  26705. 'ncaron': 556,
  26706. 'tcommaaccent': 278,
  26707. 'logicalnot': 584,
  26708. 'odieresis': 556,
  26709. 'udieresis': 556,
  26710. 'notequal': 549,
  26711. 'gcommaaccent': 556,
  26712. 'eth': 556,
  26713. 'zcaron': 500,
  26714. 'ncommaaccent': 556,
  26715. 'onesuperior': 333,
  26716. 'imacron': 278,
  26717. 'Euro': 556
  26718. },
  26719. 'Symbol': {
  26720. 'space': 250,
  26721. 'exclam': 333,
  26722. 'universal': 713,
  26723. 'numbersign': 500,
  26724. 'existential': 549,
  26725. 'percent': 833,
  26726. 'ampersand': 778,
  26727. 'suchthat': 439,
  26728. 'parenleft': 333,
  26729. 'parenright': 333,
  26730. 'asteriskmath': 500,
  26731. 'plus': 549,
  26732. 'comma': 250,
  26733. 'minus': 549,
  26734. 'period': 250,
  26735. 'slash': 278,
  26736. 'zero': 500,
  26737. 'one': 500,
  26738. 'two': 500,
  26739. 'three': 500,
  26740. 'four': 500,
  26741. 'five': 500,
  26742. 'six': 500,
  26743. 'seven': 500,
  26744. 'eight': 500,
  26745. 'nine': 500,
  26746. 'colon': 278,
  26747. 'semicolon': 278,
  26748. 'less': 549,
  26749. 'equal': 549,
  26750. 'greater': 549,
  26751. 'question': 444,
  26752. 'congruent': 549,
  26753. 'Alpha': 722,
  26754. 'Beta': 667,
  26755. 'Chi': 722,
  26756. 'Delta': 612,
  26757. 'Epsilon': 611,
  26758. 'Phi': 763,
  26759. 'Gamma': 603,
  26760. 'Eta': 722,
  26761. 'Iota': 333,
  26762. 'theta1': 631,
  26763. 'Kappa': 722,
  26764. 'Lambda': 686,
  26765. 'Mu': 889,
  26766. 'Nu': 722,
  26767. 'Omicron': 722,
  26768. 'Pi': 768,
  26769. 'Theta': 741,
  26770. 'Rho': 556,
  26771. 'Sigma': 592,
  26772. 'Tau': 611,
  26773. 'Upsilon': 690,
  26774. 'sigma1': 439,
  26775. 'Omega': 768,
  26776. 'Xi': 645,
  26777. 'Psi': 795,
  26778. 'Zeta': 611,
  26779. 'bracketleft': 333,
  26780. 'therefore': 863,
  26781. 'bracketright': 333,
  26782. 'perpendicular': 658,
  26783. 'underscore': 500,
  26784. 'radicalex': 500,
  26785. 'alpha': 631,
  26786. 'beta': 549,
  26787. 'chi': 549,
  26788. 'delta': 494,
  26789. 'epsilon': 439,
  26790. 'phi': 521,
  26791. 'gamma': 411,
  26792. 'eta': 603,
  26793. 'iota': 329,
  26794. 'phi1': 603,
  26795. 'kappa': 549,
  26796. 'lambda': 549,
  26797. 'mu': 576,
  26798. 'nu': 521,
  26799. 'omicron': 549,
  26800. 'pi': 549,
  26801. 'theta': 521,
  26802. 'rho': 549,
  26803. 'sigma': 603,
  26804. 'tau': 439,
  26805. 'upsilon': 576,
  26806. 'omega1': 713,
  26807. 'omega': 686,
  26808. 'xi': 493,
  26809. 'psi': 686,
  26810. 'zeta': 494,
  26811. 'braceleft': 480,
  26812. 'bar': 200,
  26813. 'braceright': 480,
  26814. 'similar': 549,
  26815. 'Euro': 750,
  26816. 'Upsilon1': 620,
  26817. 'minute': 247,
  26818. 'lessequal': 549,
  26819. 'fraction': 167,
  26820. 'infinity': 713,
  26821. 'florin': 500,
  26822. 'club': 753,
  26823. 'diamond': 753,
  26824. 'heart': 753,
  26825. 'spade': 753,
  26826. 'arrowboth': 1042,
  26827. 'arrowleft': 987,
  26828. 'arrowup': 603,
  26829. 'arrowright': 987,
  26830. 'arrowdown': 603,
  26831. 'degree': 400,
  26832. 'plusminus': 549,
  26833. 'second': 411,
  26834. 'greaterequal': 549,
  26835. 'multiply': 549,
  26836. 'proportional': 713,
  26837. 'partialdiff': 494,
  26838. 'bullet': 460,
  26839. 'divide': 549,
  26840. 'notequal': 549,
  26841. 'equivalence': 549,
  26842. 'approxequal': 549,
  26843. 'ellipsis': 1000,
  26844. 'arrowvertex': 603,
  26845. 'arrowhorizex': 1000,
  26846. 'carriagereturn': 658,
  26847. 'aleph': 823,
  26848. 'Ifraktur': 686,
  26849. 'Rfraktur': 795,
  26850. 'weierstrass': 987,
  26851. 'circlemultiply': 768,
  26852. 'circleplus': 768,
  26853. 'emptyset': 823,
  26854. 'intersection': 768,
  26855. 'union': 768,
  26856. 'propersuperset': 713,
  26857. 'reflexsuperset': 713,
  26858. 'notsubset': 713,
  26859. 'propersubset': 713,
  26860. 'reflexsubset': 713,
  26861. 'element': 713,
  26862. 'notelement': 713,
  26863. 'angle': 768,
  26864. 'gradient': 713,
  26865. 'registerserif': 790,
  26866. 'copyrightserif': 790,
  26867. 'trademarkserif': 890,
  26868. 'product': 823,
  26869. 'radical': 549,
  26870. 'dotmath': 250,
  26871. 'logicalnot': 713,
  26872. 'logicaland': 603,
  26873. 'logicalor': 603,
  26874. 'arrowdblboth': 1042,
  26875. 'arrowdblleft': 987,
  26876. 'arrowdblup': 603,
  26877. 'arrowdblright': 987,
  26878. 'arrowdbldown': 603,
  26879. 'lozenge': 494,
  26880. 'angleleft': 329,
  26881. 'registersans': 790,
  26882. 'copyrightsans': 790,
  26883. 'trademarksans': 786,
  26884. 'summation': 713,
  26885. 'parenlefttp': 384,
  26886. 'parenleftex': 384,
  26887. 'parenleftbt': 384,
  26888. 'bracketlefttp': 384,
  26889. 'bracketleftex': 384,
  26890. 'bracketleftbt': 384,
  26891. 'bracelefttp': 494,
  26892. 'braceleftmid': 494,
  26893. 'braceleftbt': 494,
  26894. 'braceex': 494,
  26895. 'angleright': 329,
  26896. 'integral': 274,
  26897. 'integraltp': 686,
  26898. 'integralex': 686,
  26899. 'integralbt': 686,
  26900. 'parenrighttp': 384,
  26901. 'parenrightex': 384,
  26902. 'parenrightbt': 384,
  26903. 'bracketrighttp': 384,
  26904. 'bracketrightex': 384,
  26905. 'bracketrightbt': 384,
  26906. 'bracerighttp': 494,
  26907. 'bracerightmid': 494,
  26908. 'bracerightbt': 494,
  26909. 'apple': 790
  26910. },
  26911. 'Times-Roman': {
  26912. 'space': 250,
  26913. 'exclam': 333,
  26914. 'quotedbl': 408,
  26915. 'numbersign': 500,
  26916. 'dollar': 500,
  26917. 'percent': 833,
  26918. 'ampersand': 778,
  26919. 'quoteright': 333,
  26920. 'parenleft': 333,
  26921. 'parenright': 333,
  26922. 'asterisk': 500,
  26923. 'plus': 564,
  26924. 'comma': 250,
  26925. 'hyphen': 333,
  26926. 'period': 250,
  26927. 'slash': 278,
  26928. 'zero': 500,
  26929. 'one': 500,
  26930. 'two': 500,
  26931. 'three': 500,
  26932. 'four': 500,
  26933. 'five': 500,
  26934. 'six': 500,
  26935. 'seven': 500,
  26936. 'eight': 500,
  26937. 'nine': 500,
  26938. 'colon': 278,
  26939. 'semicolon': 278,
  26940. 'less': 564,
  26941. 'equal': 564,
  26942. 'greater': 564,
  26943. 'question': 444,
  26944. 'at': 921,
  26945. 'A': 722,
  26946. 'B': 667,
  26947. 'C': 667,
  26948. 'D': 722,
  26949. 'E': 611,
  26950. 'F': 556,
  26951. 'G': 722,
  26952. 'H': 722,
  26953. 'I': 333,
  26954. 'J': 389,
  26955. 'K': 722,
  26956. 'L': 611,
  26957. 'M': 889,
  26958. 'N': 722,
  26959. 'O': 722,
  26960. 'P': 556,
  26961. 'Q': 722,
  26962. 'R': 667,
  26963. 'S': 556,
  26964. 'T': 611,
  26965. 'U': 722,
  26966. 'V': 722,
  26967. 'W': 944,
  26968. 'X': 722,
  26969. 'Y': 722,
  26970. 'Z': 611,
  26971. 'bracketleft': 333,
  26972. 'backslash': 278,
  26973. 'bracketright': 333,
  26974. 'asciicircum': 469,
  26975. 'underscore': 500,
  26976. 'quoteleft': 333,
  26977. 'a': 444,
  26978. 'b': 500,
  26979. 'c': 444,
  26980. 'd': 500,
  26981. 'e': 444,
  26982. 'f': 333,
  26983. 'g': 500,
  26984. 'h': 500,
  26985. 'i': 278,
  26986. 'j': 278,
  26987. 'k': 500,
  26988. 'l': 278,
  26989. 'm': 778,
  26990. 'n': 500,
  26991. 'o': 500,
  26992. 'p': 500,
  26993. 'q': 500,
  26994. 'r': 333,
  26995. 's': 389,
  26996. 't': 278,
  26997. 'u': 500,
  26998. 'v': 500,
  26999. 'w': 722,
  27000. 'x': 500,
  27001. 'y': 500,
  27002. 'z': 444,
  27003. 'braceleft': 480,
  27004. 'bar': 200,
  27005. 'braceright': 480,
  27006. 'asciitilde': 541,
  27007. 'exclamdown': 333,
  27008. 'cent': 500,
  27009. 'sterling': 500,
  27010. 'fraction': 167,
  27011. 'yen': 500,
  27012. 'florin': 500,
  27013. 'section': 500,
  27014. 'currency': 500,
  27015. 'quotesingle': 180,
  27016. 'quotedblleft': 444,
  27017. 'guillemotleft': 500,
  27018. 'guilsinglleft': 333,
  27019. 'guilsinglright': 333,
  27020. 'fi': 556,
  27021. 'fl': 556,
  27022. 'endash': 500,
  27023. 'dagger': 500,
  27024. 'daggerdbl': 500,
  27025. 'periodcentered': 250,
  27026. 'paragraph': 453,
  27027. 'bullet': 350,
  27028. 'quotesinglbase': 333,
  27029. 'quotedblbase': 444,
  27030. 'quotedblright': 444,
  27031. 'guillemotright': 500,
  27032. 'ellipsis': 1000,
  27033. 'perthousand': 1000,
  27034. 'questiondown': 444,
  27035. 'grave': 333,
  27036. 'acute': 333,
  27037. 'circumflex': 333,
  27038. 'tilde': 333,
  27039. 'macron': 333,
  27040. 'breve': 333,
  27041. 'dotaccent': 333,
  27042. 'dieresis': 333,
  27043. 'ring': 333,
  27044. 'cedilla': 333,
  27045. 'hungarumlaut': 333,
  27046. 'ogonek': 333,
  27047. 'caron': 333,
  27048. 'emdash': 1000,
  27049. 'AE': 889,
  27050. 'ordfeminine': 276,
  27051. 'Lslash': 611,
  27052. 'Oslash': 722,
  27053. 'OE': 889,
  27054. 'ordmasculine': 310,
  27055. 'ae': 667,
  27056. 'dotlessi': 278,
  27057. 'lslash': 278,
  27058. 'oslash': 500,
  27059. 'oe': 722,
  27060. 'germandbls': 500,
  27061. 'Idieresis': 333,
  27062. 'eacute': 444,
  27063. 'abreve': 444,
  27064. 'uhungarumlaut': 500,
  27065. 'ecaron': 444,
  27066. 'Ydieresis': 722,
  27067. 'divide': 564,
  27068. 'Yacute': 722,
  27069. 'Acircumflex': 722,
  27070. 'aacute': 444,
  27071. 'Ucircumflex': 722,
  27072. 'yacute': 500,
  27073. 'scommaaccent': 389,
  27074. 'ecircumflex': 444,
  27075. 'Uring': 722,
  27076. 'Udieresis': 722,
  27077. 'aogonek': 444,
  27078. 'Uacute': 722,
  27079. 'uogonek': 500,
  27080. 'Edieresis': 611,
  27081. 'Dcroat': 722,
  27082. 'commaaccent': 250,
  27083. 'copyright': 760,
  27084. 'Emacron': 611,
  27085. 'ccaron': 444,
  27086. 'aring': 444,
  27087. 'Ncommaaccent': 722,
  27088. 'lacute': 278,
  27089. 'agrave': 444,
  27090. 'Tcommaaccent': 611,
  27091. 'Cacute': 667,
  27092. 'atilde': 444,
  27093. 'Edotaccent': 611,
  27094. 'scaron': 389,
  27095. 'scedilla': 389,
  27096. 'iacute': 278,
  27097. 'lozenge': 471,
  27098. 'Rcaron': 667,
  27099. 'Gcommaaccent': 722,
  27100. 'ucircumflex': 500,
  27101. 'acircumflex': 444,
  27102. 'Amacron': 722,
  27103. 'rcaron': 333,
  27104. 'ccedilla': 444,
  27105. 'Zdotaccent': 611,
  27106. 'Thorn': 556,
  27107. 'Omacron': 722,
  27108. 'Racute': 667,
  27109. 'Sacute': 556,
  27110. 'dcaron': 588,
  27111. 'Umacron': 722,
  27112. 'uring': 500,
  27113. 'threesuperior': 300,
  27114. 'Ograve': 722,
  27115. 'Agrave': 722,
  27116. 'Abreve': 722,
  27117. 'multiply': 564,
  27118. 'uacute': 500,
  27119. 'Tcaron': 611,
  27120. 'partialdiff': 476,
  27121. 'ydieresis': 500,
  27122. 'Nacute': 722,
  27123. 'icircumflex': 278,
  27124. 'Ecircumflex': 611,
  27125. 'adieresis': 444,
  27126. 'edieresis': 444,
  27127. 'cacute': 444,
  27128. 'nacute': 500,
  27129. 'umacron': 500,
  27130. 'Ncaron': 722,
  27131. 'Iacute': 333,
  27132. 'plusminus': 564,
  27133. 'brokenbar': 200,
  27134. 'registered': 760,
  27135. 'Gbreve': 722,
  27136. 'Idotaccent': 333,
  27137. 'summation': 600,
  27138. 'Egrave': 611,
  27139. 'racute': 333,
  27140. 'omacron': 500,
  27141. 'Zacute': 611,
  27142. 'Zcaron': 611,
  27143. 'greaterequal': 549,
  27144. 'Eth': 722,
  27145. 'Ccedilla': 667,
  27146. 'lcommaaccent': 278,
  27147. 'tcaron': 326,
  27148. 'eogonek': 444,
  27149. 'Uogonek': 722,
  27150. 'Aacute': 722,
  27151. 'Adieresis': 722,
  27152. 'egrave': 444,
  27153. 'zacute': 444,
  27154. 'iogonek': 278,
  27155. 'Oacute': 722,
  27156. 'oacute': 500,
  27157. 'amacron': 444,
  27158. 'sacute': 389,
  27159. 'idieresis': 278,
  27160. 'Ocircumflex': 722,
  27161. 'Ugrave': 722,
  27162. 'Delta': 612,
  27163. 'thorn': 500,
  27164. 'twosuperior': 300,
  27165. 'Odieresis': 722,
  27166. 'mu': 500,
  27167. 'igrave': 278,
  27168. 'ohungarumlaut': 500,
  27169. 'Eogonek': 611,
  27170. 'dcroat': 500,
  27171. 'threequarters': 750,
  27172. 'Scedilla': 556,
  27173. 'lcaron': 344,
  27174. 'Kcommaaccent': 722,
  27175. 'Lacute': 611,
  27176. 'trademark': 980,
  27177. 'edotaccent': 444,
  27178. 'Igrave': 333,
  27179. 'Imacron': 333,
  27180. 'Lcaron': 611,
  27181. 'onehalf': 750,
  27182. 'lessequal': 549,
  27183. 'ocircumflex': 500,
  27184. 'ntilde': 500,
  27185. 'Uhungarumlaut': 722,
  27186. 'Eacute': 611,
  27187. 'emacron': 444,
  27188. 'gbreve': 500,
  27189. 'onequarter': 750,
  27190. 'Scaron': 556,
  27191. 'Scommaaccent': 556,
  27192. 'Ohungarumlaut': 722,
  27193. 'degree': 400,
  27194. 'ograve': 500,
  27195. 'Ccaron': 667,
  27196. 'ugrave': 500,
  27197. 'radical': 453,
  27198. 'Dcaron': 722,
  27199. 'rcommaaccent': 333,
  27200. 'Ntilde': 722,
  27201. 'otilde': 500,
  27202. 'Rcommaaccent': 667,
  27203. 'Lcommaaccent': 611,
  27204. 'Atilde': 722,
  27205. 'Aogonek': 722,
  27206. 'Aring': 722,
  27207. 'Otilde': 722,
  27208. 'zdotaccent': 444,
  27209. 'Ecaron': 611,
  27210. 'Iogonek': 333,
  27211. 'kcommaaccent': 500,
  27212. 'minus': 564,
  27213. 'Icircumflex': 333,
  27214. 'ncaron': 500,
  27215. 'tcommaaccent': 278,
  27216. 'logicalnot': 564,
  27217. 'odieresis': 500,
  27218. 'udieresis': 500,
  27219. 'notequal': 549,
  27220. 'gcommaaccent': 500,
  27221. 'eth': 500,
  27222. 'zcaron': 444,
  27223. 'ncommaaccent': 500,
  27224. 'onesuperior': 300,
  27225. 'imacron': 278,
  27226. 'Euro': 500
  27227. },
  27228. 'Times-Bold': {
  27229. 'space': 250,
  27230. 'exclam': 333,
  27231. 'quotedbl': 555,
  27232. 'numbersign': 500,
  27233. 'dollar': 500,
  27234. 'percent': 1000,
  27235. 'ampersand': 833,
  27236. 'quoteright': 333,
  27237. 'parenleft': 333,
  27238. 'parenright': 333,
  27239. 'asterisk': 500,
  27240. 'plus': 570,
  27241. 'comma': 250,
  27242. 'hyphen': 333,
  27243. 'period': 250,
  27244. 'slash': 278,
  27245. 'zero': 500,
  27246. 'one': 500,
  27247. 'two': 500,
  27248. 'three': 500,
  27249. 'four': 500,
  27250. 'five': 500,
  27251. 'six': 500,
  27252. 'seven': 500,
  27253. 'eight': 500,
  27254. 'nine': 500,
  27255. 'colon': 333,
  27256. 'semicolon': 333,
  27257. 'less': 570,
  27258. 'equal': 570,
  27259. 'greater': 570,
  27260. 'question': 500,
  27261. 'at': 930,
  27262. 'A': 722,
  27263. 'B': 667,
  27264. 'C': 722,
  27265. 'D': 722,
  27266. 'E': 667,
  27267. 'F': 611,
  27268. 'G': 778,
  27269. 'H': 778,
  27270. 'I': 389,
  27271. 'J': 500,
  27272. 'K': 778,
  27273. 'L': 667,
  27274. 'M': 944,
  27275. 'N': 722,
  27276. 'O': 778,
  27277. 'P': 611,
  27278. 'Q': 778,
  27279. 'R': 722,
  27280. 'S': 556,
  27281. 'T': 667,
  27282. 'U': 722,
  27283. 'V': 722,
  27284. 'W': 1000,
  27285. 'X': 722,
  27286. 'Y': 722,
  27287. 'Z': 667,
  27288. 'bracketleft': 333,
  27289. 'backslash': 278,
  27290. 'bracketright': 333,
  27291. 'asciicircum': 581,
  27292. 'underscore': 500,
  27293. 'quoteleft': 333,
  27294. 'a': 500,
  27295. 'b': 556,
  27296. 'c': 444,
  27297. 'd': 556,
  27298. 'e': 444,
  27299. 'f': 333,
  27300. 'g': 500,
  27301. 'h': 556,
  27302. 'i': 278,
  27303. 'j': 333,
  27304. 'k': 556,
  27305. 'l': 278,
  27306. 'm': 833,
  27307. 'n': 556,
  27308. 'o': 500,
  27309. 'p': 556,
  27310. 'q': 556,
  27311. 'r': 444,
  27312. 's': 389,
  27313. 't': 333,
  27314. 'u': 556,
  27315. 'v': 500,
  27316. 'w': 722,
  27317. 'x': 500,
  27318. 'y': 500,
  27319. 'z': 444,
  27320. 'braceleft': 394,
  27321. 'bar': 220,
  27322. 'braceright': 394,
  27323. 'asciitilde': 520,
  27324. 'exclamdown': 333,
  27325. 'cent': 500,
  27326. 'sterling': 500,
  27327. 'fraction': 167,
  27328. 'yen': 500,
  27329. 'florin': 500,
  27330. 'section': 500,
  27331. 'currency': 500,
  27332. 'quotesingle': 278,
  27333. 'quotedblleft': 500,
  27334. 'guillemotleft': 500,
  27335. 'guilsinglleft': 333,
  27336. 'guilsinglright': 333,
  27337. 'fi': 556,
  27338. 'fl': 556,
  27339. 'endash': 500,
  27340. 'dagger': 500,
  27341. 'daggerdbl': 500,
  27342. 'periodcentered': 250,
  27343. 'paragraph': 540,
  27344. 'bullet': 350,
  27345. 'quotesinglbase': 333,
  27346. 'quotedblbase': 500,
  27347. 'quotedblright': 500,
  27348. 'guillemotright': 500,
  27349. 'ellipsis': 1000,
  27350. 'perthousand': 1000,
  27351. 'questiondown': 500,
  27352. 'grave': 333,
  27353. 'acute': 333,
  27354. 'circumflex': 333,
  27355. 'tilde': 333,
  27356. 'macron': 333,
  27357. 'breve': 333,
  27358. 'dotaccent': 333,
  27359. 'dieresis': 333,
  27360. 'ring': 333,
  27361. 'cedilla': 333,
  27362. 'hungarumlaut': 333,
  27363. 'ogonek': 333,
  27364. 'caron': 333,
  27365. 'emdash': 1000,
  27366. 'AE': 1000,
  27367. 'ordfeminine': 300,
  27368. 'Lslash': 667,
  27369. 'Oslash': 778,
  27370. 'OE': 1000,
  27371. 'ordmasculine': 330,
  27372. 'ae': 722,
  27373. 'dotlessi': 278,
  27374. 'lslash': 278,
  27375. 'oslash': 500,
  27376. 'oe': 722,
  27377. 'germandbls': 556,
  27378. 'Idieresis': 389,
  27379. 'eacute': 444,
  27380. 'abreve': 500,
  27381. 'uhungarumlaut': 556,
  27382. 'ecaron': 444,
  27383. 'Ydieresis': 722,
  27384. 'divide': 570,
  27385. 'Yacute': 722,
  27386. 'Acircumflex': 722,
  27387. 'aacute': 500,
  27388. 'Ucircumflex': 722,
  27389. 'yacute': 500,
  27390. 'scommaaccent': 389,
  27391. 'ecircumflex': 444,
  27392. 'Uring': 722,
  27393. 'Udieresis': 722,
  27394. 'aogonek': 500,
  27395. 'Uacute': 722,
  27396. 'uogonek': 556,
  27397. 'Edieresis': 667,
  27398. 'Dcroat': 722,
  27399. 'commaaccent': 250,
  27400. 'copyright': 747,
  27401. 'Emacron': 667,
  27402. 'ccaron': 444,
  27403. 'aring': 500,
  27404. 'Ncommaaccent': 722,
  27405. 'lacute': 278,
  27406. 'agrave': 500,
  27407. 'Tcommaaccent': 667,
  27408. 'Cacute': 722,
  27409. 'atilde': 500,
  27410. 'Edotaccent': 667,
  27411. 'scaron': 389,
  27412. 'scedilla': 389,
  27413. 'iacute': 278,
  27414. 'lozenge': 494,
  27415. 'Rcaron': 722,
  27416. 'Gcommaaccent': 778,
  27417. 'ucircumflex': 556,
  27418. 'acircumflex': 500,
  27419. 'Amacron': 722,
  27420. 'rcaron': 444,
  27421. 'ccedilla': 444,
  27422. 'Zdotaccent': 667,
  27423. 'Thorn': 611,
  27424. 'Omacron': 778,
  27425. 'Racute': 722,
  27426. 'Sacute': 556,
  27427. 'dcaron': 672,
  27428. 'Umacron': 722,
  27429. 'uring': 556,
  27430. 'threesuperior': 300,
  27431. 'Ograve': 778,
  27432. 'Agrave': 722,
  27433. 'Abreve': 722,
  27434. 'multiply': 570,
  27435. 'uacute': 556,
  27436. 'Tcaron': 667,
  27437. 'partialdiff': 494,
  27438. 'ydieresis': 500,
  27439. 'Nacute': 722,
  27440. 'icircumflex': 278,
  27441. 'Ecircumflex': 667,
  27442. 'adieresis': 500,
  27443. 'edieresis': 444,
  27444. 'cacute': 444,
  27445. 'nacute': 556,
  27446. 'umacron': 556,
  27447. 'Ncaron': 722,
  27448. 'Iacute': 389,
  27449. 'plusminus': 570,
  27450. 'brokenbar': 220,
  27451. 'registered': 747,
  27452. 'Gbreve': 778,
  27453. 'Idotaccent': 389,
  27454. 'summation': 600,
  27455. 'Egrave': 667,
  27456. 'racute': 444,
  27457. 'omacron': 500,
  27458. 'Zacute': 667,
  27459. 'Zcaron': 667,
  27460. 'greaterequal': 549,
  27461. 'Eth': 722,
  27462. 'Ccedilla': 722,
  27463. 'lcommaaccent': 278,
  27464. 'tcaron': 416,
  27465. 'eogonek': 444,
  27466. 'Uogonek': 722,
  27467. 'Aacute': 722,
  27468. 'Adieresis': 722,
  27469. 'egrave': 444,
  27470. 'zacute': 444,
  27471. 'iogonek': 278,
  27472. 'Oacute': 778,
  27473. 'oacute': 500,
  27474. 'amacron': 500,
  27475. 'sacute': 389,
  27476. 'idieresis': 278,
  27477. 'Ocircumflex': 778,
  27478. 'Ugrave': 722,
  27479. 'Delta': 612,
  27480. 'thorn': 556,
  27481. 'twosuperior': 300,
  27482. 'Odieresis': 778,
  27483. 'mu': 556,
  27484. 'igrave': 278,
  27485. 'ohungarumlaut': 500,
  27486. 'Eogonek': 667,
  27487. 'dcroat': 556,
  27488. 'threequarters': 750,
  27489. 'Scedilla': 556,
  27490. 'lcaron': 394,
  27491. 'Kcommaaccent': 778,
  27492. 'Lacute': 667,
  27493. 'trademark': 1000,
  27494. 'edotaccent': 444,
  27495. 'Igrave': 389,
  27496. 'Imacron': 389,
  27497. 'Lcaron': 667,
  27498. 'onehalf': 750,
  27499. 'lessequal': 549,
  27500. 'ocircumflex': 500,
  27501. 'ntilde': 556,
  27502. 'Uhungarumlaut': 722,
  27503. 'Eacute': 667,
  27504. 'emacron': 444,
  27505. 'gbreve': 500,
  27506. 'onequarter': 750,
  27507. 'Scaron': 556,
  27508. 'Scommaaccent': 556,
  27509. 'Ohungarumlaut': 778,
  27510. 'degree': 400,
  27511. 'ograve': 500,
  27512. 'Ccaron': 722,
  27513. 'ugrave': 556,
  27514. 'radical': 549,
  27515. 'Dcaron': 722,
  27516. 'rcommaaccent': 444,
  27517. 'Ntilde': 722,
  27518. 'otilde': 500,
  27519. 'Rcommaaccent': 722,
  27520. 'Lcommaaccent': 667,
  27521. 'Atilde': 722,
  27522. 'Aogonek': 722,
  27523. 'Aring': 722,
  27524. 'Otilde': 778,
  27525. 'zdotaccent': 444,
  27526. 'Ecaron': 667,
  27527. 'Iogonek': 389,
  27528. 'kcommaaccent': 556,
  27529. 'minus': 570,
  27530. 'Icircumflex': 389,
  27531. 'ncaron': 556,
  27532. 'tcommaaccent': 333,
  27533. 'logicalnot': 570,
  27534. 'odieresis': 500,
  27535. 'udieresis': 556,
  27536. 'notequal': 549,
  27537. 'gcommaaccent': 500,
  27538. 'eth': 500,
  27539. 'zcaron': 444,
  27540. 'ncommaaccent': 556,
  27541. 'onesuperior': 300,
  27542. 'imacron': 278,
  27543. 'Euro': 500
  27544. },
  27545. 'Times-BoldItalic': {
  27546. 'space': 250,
  27547. 'exclam': 389,
  27548. 'quotedbl': 555,
  27549. 'numbersign': 500,
  27550. 'dollar': 500,
  27551. 'percent': 833,
  27552. 'ampersand': 778,
  27553. 'quoteright': 333,
  27554. 'parenleft': 333,
  27555. 'parenright': 333,
  27556. 'asterisk': 500,
  27557. 'plus': 570,
  27558. 'comma': 250,
  27559. 'hyphen': 333,
  27560. 'period': 250,
  27561. 'slash': 278,
  27562. 'zero': 500,
  27563. 'one': 500,
  27564. 'two': 500,
  27565. 'three': 500,
  27566. 'four': 500,
  27567. 'five': 500,
  27568. 'six': 500,
  27569. 'seven': 500,
  27570. 'eight': 500,
  27571. 'nine': 500,
  27572. 'colon': 333,
  27573. 'semicolon': 333,
  27574. 'less': 570,
  27575. 'equal': 570,
  27576. 'greater': 570,
  27577. 'question': 500,
  27578. 'at': 832,
  27579. 'A': 667,
  27580. 'B': 667,
  27581. 'C': 667,
  27582. 'D': 722,
  27583. 'E': 667,
  27584. 'F': 667,
  27585. 'G': 722,
  27586. 'H': 778,
  27587. 'I': 389,
  27588. 'J': 500,
  27589. 'K': 667,
  27590. 'L': 611,
  27591. 'M': 889,
  27592. 'N': 722,
  27593. 'O': 722,
  27594. 'P': 611,
  27595. 'Q': 722,
  27596. 'R': 667,
  27597. 'S': 556,
  27598. 'T': 611,
  27599. 'U': 722,
  27600. 'V': 667,
  27601. 'W': 889,
  27602. 'X': 667,
  27603. 'Y': 611,
  27604. 'Z': 611,
  27605. 'bracketleft': 333,
  27606. 'backslash': 278,
  27607. 'bracketright': 333,
  27608. 'asciicircum': 570,
  27609. 'underscore': 500,
  27610. 'quoteleft': 333,
  27611. 'a': 500,
  27612. 'b': 500,
  27613. 'c': 444,
  27614. 'd': 500,
  27615. 'e': 444,
  27616. 'f': 333,
  27617. 'g': 500,
  27618. 'h': 556,
  27619. 'i': 278,
  27620. 'j': 278,
  27621. 'k': 500,
  27622. 'l': 278,
  27623. 'm': 778,
  27624. 'n': 556,
  27625. 'o': 500,
  27626. 'p': 500,
  27627. 'q': 500,
  27628. 'r': 389,
  27629. 's': 389,
  27630. 't': 278,
  27631. 'u': 556,
  27632. 'v': 444,
  27633. 'w': 667,
  27634. 'x': 500,
  27635. 'y': 444,
  27636. 'z': 389,
  27637. 'braceleft': 348,
  27638. 'bar': 220,
  27639. 'braceright': 348,
  27640. 'asciitilde': 570,
  27641. 'exclamdown': 389,
  27642. 'cent': 500,
  27643. 'sterling': 500,
  27644. 'fraction': 167,
  27645. 'yen': 500,
  27646. 'florin': 500,
  27647. 'section': 500,
  27648. 'currency': 500,
  27649. 'quotesingle': 278,
  27650. 'quotedblleft': 500,
  27651. 'guillemotleft': 500,
  27652. 'guilsinglleft': 333,
  27653. 'guilsinglright': 333,
  27654. 'fi': 556,
  27655. 'fl': 556,
  27656. 'endash': 500,
  27657. 'dagger': 500,
  27658. 'daggerdbl': 500,
  27659. 'periodcentered': 250,
  27660. 'paragraph': 500,
  27661. 'bullet': 350,
  27662. 'quotesinglbase': 333,
  27663. 'quotedblbase': 500,
  27664. 'quotedblright': 500,
  27665. 'guillemotright': 500,
  27666. 'ellipsis': 1000,
  27667. 'perthousand': 1000,
  27668. 'questiondown': 500,
  27669. 'grave': 333,
  27670. 'acute': 333,
  27671. 'circumflex': 333,
  27672. 'tilde': 333,
  27673. 'macron': 333,
  27674. 'breve': 333,
  27675. 'dotaccent': 333,
  27676. 'dieresis': 333,
  27677. 'ring': 333,
  27678. 'cedilla': 333,
  27679. 'hungarumlaut': 333,
  27680. 'ogonek': 333,
  27681. 'caron': 333,
  27682. 'emdash': 1000,
  27683. 'AE': 944,
  27684. 'ordfeminine': 266,
  27685. 'Lslash': 611,
  27686. 'Oslash': 722,
  27687. 'OE': 944,
  27688. 'ordmasculine': 300,
  27689. 'ae': 722,
  27690. 'dotlessi': 278,
  27691. 'lslash': 278,
  27692. 'oslash': 500,
  27693. 'oe': 722,
  27694. 'germandbls': 500,
  27695. 'Idieresis': 389,
  27696. 'eacute': 444,
  27697. 'abreve': 500,
  27698. 'uhungarumlaut': 556,
  27699. 'ecaron': 444,
  27700. 'Ydieresis': 611,
  27701. 'divide': 570,
  27702. 'Yacute': 611,
  27703. 'Acircumflex': 667,
  27704. 'aacute': 500,
  27705. 'Ucircumflex': 722,
  27706. 'yacute': 444,
  27707. 'scommaaccent': 389,
  27708. 'ecircumflex': 444,
  27709. 'Uring': 722,
  27710. 'Udieresis': 722,
  27711. 'aogonek': 500,
  27712. 'Uacute': 722,
  27713. 'uogonek': 556,
  27714. 'Edieresis': 667,
  27715. 'Dcroat': 722,
  27716. 'commaaccent': 250,
  27717. 'copyright': 747,
  27718. 'Emacron': 667,
  27719. 'ccaron': 444,
  27720. 'aring': 500,
  27721. 'Ncommaaccent': 722,
  27722. 'lacute': 278,
  27723. 'agrave': 500,
  27724. 'Tcommaaccent': 611,
  27725. 'Cacute': 667,
  27726. 'atilde': 500,
  27727. 'Edotaccent': 667,
  27728. 'scaron': 389,
  27729. 'scedilla': 389,
  27730. 'iacute': 278,
  27731. 'lozenge': 494,
  27732. 'Rcaron': 667,
  27733. 'Gcommaaccent': 722,
  27734. 'ucircumflex': 556,
  27735. 'acircumflex': 500,
  27736. 'Amacron': 667,
  27737. 'rcaron': 389,
  27738. 'ccedilla': 444,
  27739. 'Zdotaccent': 611,
  27740. 'Thorn': 611,
  27741. 'Omacron': 722,
  27742. 'Racute': 667,
  27743. 'Sacute': 556,
  27744. 'dcaron': 608,
  27745. 'Umacron': 722,
  27746. 'uring': 556,
  27747. 'threesuperior': 300,
  27748. 'Ograve': 722,
  27749. 'Agrave': 667,
  27750. 'Abreve': 667,
  27751. 'multiply': 570,
  27752. 'uacute': 556,
  27753. 'Tcaron': 611,
  27754. 'partialdiff': 494,
  27755. 'ydieresis': 444,
  27756. 'Nacute': 722,
  27757. 'icircumflex': 278,
  27758. 'Ecircumflex': 667,
  27759. 'adieresis': 500,
  27760. 'edieresis': 444,
  27761. 'cacute': 444,
  27762. 'nacute': 556,
  27763. 'umacron': 556,
  27764. 'Ncaron': 722,
  27765. 'Iacute': 389,
  27766. 'plusminus': 570,
  27767. 'brokenbar': 220,
  27768. 'registered': 747,
  27769. 'Gbreve': 722,
  27770. 'Idotaccent': 389,
  27771. 'summation': 600,
  27772. 'Egrave': 667,
  27773. 'racute': 389,
  27774. 'omacron': 500,
  27775. 'Zacute': 611,
  27776. 'Zcaron': 611,
  27777. 'greaterequal': 549,
  27778. 'Eth': 722,
  27779. 'Ccedilla': 667,
  27780. 'lcommaaccent': 278,
  27781. 'tcaron': 366,
  27782. 'eogonek': 444,
  27783. 'Uogonek': 722,
  27784. 'Aacute': 667,
  27785. 'Adieresis': 667,
  27786. 'egrave': 444,
  27787. 'zacute': 389,
  27788. 'iogonek': 278,
  27789. 'Oacute': 722,
  27790. 'oacute': 500,
  27791. 'amacron': 500,
  27792. 'sacute': 389,
  27793. 'idieresis': 278,
  27794. 'Ocircumflex': 722,
  27795. 'Ugrave': 722,
  27796. 'Delta': 612,
  27797. 'thorn': 500,
  27798. 'twosuperior': 300,
  27799. 'Odieresis': 722,
  27800. 'mu': 576,
  27801. 'igrave': 278,
  27802. 'ohungarumlaut': 500,
  27803. 'Eogonek': 667,
  27804. 'dcroat': 500,
  27805. 'threequarters': 750,
  27806. 'Scedilla': 556,
  27807. 'lcaron': 382,
  27808. 'Kcommaaccent': 667,
  27809. 'Lacute': 611,
  27810. 'trademark': 1000,
  27811. 'edotaccent': 444,
  27812. 'Igrave': 389,
  27813. 'Imacron': 389,
  27814. 'Lcaron': 611,
  27815. 'onehalf': 750,
  27816. 'lessequal': 549,
  27817. 'ocircumflex': 500,
  27818. 'ntilde': 556,
  27819. 'Uhungarumlaut': 722,
  27820. 'Eacute': 667,
  27821. 'emacron': 444,
  27822. 'gbreve': 500,
  27823. 'onequarter': 750,
  27824. 'Scaron': 556,
  27825. 'Scommaaccent': 556,
  27826. 'Ohungarumlaut': 722,
  27827. 'degree': 400,
  27828. 'ograve': 500,
  27829. 'Ccaron': 667,
  27830. 'ugrave': 556,
  27831. 'radical': 549,
  27832. 'Dcaron': 722,
  27833. 'rcommaaccent': 389,
  27834. 'Ntilde': 722,
  27835. 'otilde': 500,
  27836. 'Rcommaaccent': 667,
  27837. 'Lcommaaccent': 611,
  27838. 'Atilde': 667,
  27839. 'Aogonek': 667,
  27840. 'Aring': 667,
  27841. 'Otilde': 722,
  27842. 'zdotaccent': 389,
  27843. 'Ecaron': 667,
  27844. 'Iogonek': 389,
  27845. 'kcommaaccent': 500,
  27846. 'minus': 606,
  27847. 'Icircumflex': 389,
  27848. 'ncaron': 556,
  27849. 'tcommaaccent': 278,
  27850. 'logicalnot': 606,
  27851. 'odieresis': 500,
  27852. 'udieresis': 556,
  27853. 'notequal': 549,
  27854. 'gcommaaccent': 500,
  27855. 'eth': 500,
  27856. 'zcaron': 389,
  27857. 'ncommaaccent': 556,
  27858. 'onesuperior': 300,
  27859. 'imacron': 278,
  27860. 'Euro': 500
  27861. },
  27862. 'Times-Italic': {
  27863. 'space': 250,
  27864. 'exclam': 333,
  27865. 'quotedbl': 420,
  27866. 'numbersign': 500,
  27867. 'dollar': 500,
  27868. 'percent': 833,
  27869. 'ampersand': 778,
  27870. 'quoteright': 333,
  27871. 'parenleft': 333,
  27872. 'parenright': 333,
  27873. 'asterisk': 500,
  27874. 'plus': 675,
  27875. 'comma': 250,
  27876. 'hyphen': 333,
  27877. 'period': 250,
  27878. 'slash': 278,
  27879. 'zero': 500,
  27880. 'one': 500,
  27881. 'two': 500,
  27882. 'three': 500,
  27883. 'four': 500,
  27884. 'five': 500,
  27885. 'six': 500,
  27886. 'seven': 500,
  27887. 'eight': 500,
  27888. 'nine': 500,
  27889. 'colon': 333,
  27890. 'semicolon': 333,
  27891. 'less': 675,
  27892. 'equal': 675,
  27893. 'greater': 675,
  27894. 'question': 500,
  27895. 'at': 920,
  27896. 'A': 611,
  27897. 'B': 611,
  27898. 'C': 667,
  27899. 'D': 722,
  27900. 'E': 611,
  27901. 'F': 611,
  27902. 'G': 722,
  27903. 'H': 722,
  27904. 'I': 333,
  27905. 'J': 444,
  27906. 'K': 667,
  27907. 'L': 556,
  27908. 'M': 833,
  27909. 'N': 667,
  27910. 'O': 722,
  27911. 'P': 611,
  27912. 'Q': 722,
  27913. 'R': 611,
  27914. 'S': 500,
  27915. 'T': 556,
  27916. 'U': 722,
  27917. 'V': 611,
  27918. 'W': 833,
  27919. 'X': 611,
  27920. 'Y': 556,
  27921. 'Z': 556,
  27922. 'bracketleft': 389,
  27923. 'backslash': 278,
  27924. 'bracketright': 389,
  27925. 'asciicircum': 422,
  27926. 'underscore': 500,
  27927. 'quoteleft': 333,
  27928. 'a': 500,
  27929. 'b': 500,
  27930. 'c': 444,
  27931. 'd': 500,
  27932. 'e': 444,
  27933. 'f': 278,
  27934. 'g': 500,
  27935. 'h': 500,
  27936. 'i': 278,
  27937. 'j': 278,
  27938. 'k': 444,
  27939. 'l': 278,
  27940. 'm': 722,
  27941. 'n': 500,
  27942. 'o': 500,
  27943. 'p': 500,
  27944. 'q': 500,
  27945. 'r': 389,
  27946. 's': 389,
  27947. 't': 278,
  27948. 'u': 500,
  27949. 'v': 444,
  27950. 'w': 667,
  27951. 'x': 444,
  27952. 'y': 444,
  27953. 'z': 389,
  27954. 'braceleft': 400,
  27955. 'bar': 275,
  27956. 'braceright': 400,
  27957. 'asciitilde': 541,
  27958. 'exclamdown': 389,
  27959. 'cent': 500,
  27960. 'sterling': 500,
  27961. 'fraction': 167,
  27962. 'yen': 500,
  27963. 'florin': 500,
  27964. 'section': 500,
  27965. 'currency': 500,
  27966. 'quotesingle': 214,
  27967. 'quotedblleft': 556,
  27968. 'guillemotleft': 500,
  27969. 'guilsinglleft': 333,
  27970. 'guilsinglright': 333,
  27971. 'fi': 500,
  27972. 'fl': 500,
  27973. 'endash': 500,
  27974. 'dagger': 500,
  27975. 'daggerdbl': 500,
  27976. 'periodcentered': 250,
  27977. 'paragraph': 523,
  27978. 'bullet': 350,
  27979. 'quotesinglbase': 333,
  27980. 'quotedblbase': 556,
  27981. 'quotedblright': 556,
  27982. 'guillemotright': 500,
  27983. 'ellipsis': 889,
  27984. 'perthousand': 1000,
  27985. 'questiondown': 500,
  27986. 'grave': 333,
  27987. 'acute': 333,
  27988. 'circumflex': 333,
  27989. 'tilde': 333,
  27990. 'macron': 333,
  27991. 'breve': 333,
  27992. 'dotaccent': 333,
  27993. 'dieresis': 333,
  27994. 'ring': 333,
  27995. 'cedilla': 333,
  27996. 'hungarumlaut': 333,
  27997. 'ogonek': 333,
  27998. 'caron': 333,
  27999. 'emdash': 889,
  28000. 'AE': 889,
  28001. 'ordfeminine': 276,
  28002. 'Lslash': 556,
  28003. 'Oslash': 722,
  28004. 'OE': 944,
  28005. 'ordmasculine': 310,
  28006. 'ae': 667,
  28007. 'dotlessi': 278,
  28008. 'lslash': 278,
  28009. 'oslash': 500,
  28010. 'oe': 667,
  28011. 'germandbls': 500,
  28012. 'Idieresis': 333,
  28013. 'eacute': 444,
  28014. 'abreve': 500,
  28015. 'uhungarumlaut': 500,
  28016. 'ecaron': 444,
  28017. 'Ydieresis': 556,
  28018. 'divide': 675,
  28019. 'Yacute': 556,
  28020. 'Acircumflex': 611,
  28021. 'aacute': 500,
  28022. 'Ucircumflex': 722,
  28023. 'yacute': 444,
  28024. 'scommaaccent': 389,
  28025. 'ecircumflex': 444,
  28026. 'Uring': 722,
  28027. 'Udieresis': 722,
  28028. 'aogonek': 500,
  28029. 'Uacute': 722,
  28030. 'uogonek': 500,
  28031. 'Edieresis': 611,
  28032. 'Dcroat': 722,
  28033. 'commaaccent': 250,
  28034. 'copyright': 760,
  28035. 'Emacron': 611,
  28036. 'ccaron': 444,
  28037. 'aring': 500,
  28038. 'Ncommaaccent': 667,
  28039. 'lacute': 278,
  28040. 'agrave': 500,
  28041. 'Tcommaaccent': 556,
  28042. 'Cacute': 667,
  28043. 'atilde': 500,
  28044. 'Edotaccent': 611,
  28045. 'scaron': 389,
  28046. 'scedilla': 389,
  28047. 'iacute': 278,
  28048. 'lozenge': 471,
  28049. 'Rcaron': 611,
  28050. 'Gcommaaccent': 722,
  28051. 'ucircumflex': 500,
  28052. 'acircumflex': 500,
  28053. 'Amacron': 611,
  28054. 'rcaron': 389,
  28055. 'ccedilla': 444,
  28056. 'Zdotaccent': 556,
  28057. 'Thorn': 611,
  28058. 'Omacron': 722,
  28059. 'Racute': 611,
  28060. 'Sacute': 500,
  28061. 'dcaron': 544,
  28062. 'Umacron': 722,
  28063. 'uring': 500,
  28064. 'threesuperior': 300,
  28065. 'Ograve': 722,
  28066. 'Agrave': 611,
  28067. 'Abreve': 611,
  28068. 'multiply': 675,
  28069. 'uacute': 500,
  28070. 'Tcaron': 556,
  28071. 'partialdiff': 476,
  28072. 'ydieresis': 444,
  28073. 'Nacute': 667,
  28074. 'icircumflex': 278,
  28075. 'Ecircumflex': 611,
  28076. 'adieresis': 500,
  28077. 'edieresis': 444,
  28078. 'cacute': 444,
  28079. 'nacute': 500,
  28080. 'umacron': 500,
  28081. 'Ncaron': 667,
  28082. 'Iacute': 333,
  28083. 'plusminus': 675,
  28084. 'brokenbar': 275,
  28085. 'registered': 760,
  28086. 'Gbreve': 722,
  28087. 'Idotaccent': 333,
  28088. 'summation': 600,
  28089. 'Egrave': 611,
  28090. 'racute': 389,
  28091. 'omacron': 500,
  28092. 'Zacute': 556,
  28093. 'Zcaron': 556,
  28094. 'greaterequal': 549,
  28095. 'Eth': 722,
  28096. 'Ccedilla': 667,
  28097. 'lcommaaccent': 278,
  28098. 'tcaron': 300,
  28099. 'eogonek': 444,
  28100. 'Uogonek': 722,
  28101. 'Aacute': 611,
  28102. 'Adieresis': 611,
  28103. 'egrave': 444,
  28104. 'zacute': 389,
  28105. 'iogonek': 278,
  28106. 'Oacute': 722,
  28107. 'oacute': 500,
  28108. 'amacron': 500,
  28109. 'sacute': 389,
  28110. 'idieresis': 278,
  28111. 'Ocircumflex': 722,
  28112. 'Ugrave': 722,
  28113. 'Delta': 612,
  28114. 'thorn': 500,
  28115. 'twosuperior': 300,
  28116. 'Odieresis': 722,
  28117. 'mu': 500,
  28118. 'igrave': 278,
  28119. 'ohungarumlaut': 500,
  28120. 'Eogonek': 611,
  28121. 'dcroat': 500,
  28122. 'threequarters': 750,
  28123. 'Scedilla': 500,
  28124. 'lcaron': 300,
  28125. 'Kcommaaccent': 667,
  28126. 'Lacute': 556,
  28127. 'trademark': 980,
  28128. 'edotaccent': 444,
  28129. 'Igrave': 333,
  28130. 'Imacron': 333,
  28131. 'Lcaron': 611,
  28132. 'onehalf': 750,
  28133. 'lessequal': 549,
  28134. 'ocircumflex': 500,
  28135. 'ntilde': 500,
  28136. 'Uhungarumlaut': 722,
  28137. 'Eacute': 611,
  28138. 'emacron': 444,
  28139. 'gbreve': 500,
  28140. 'onequarter': 750,
  28141. 'Scaron': 500,
  28142. 'Scommaaccent': 500,
  28143. 'Ohungarumlaut': 722,
  28144. 'degree': 400,
  28145. 'ograve': 500,
  28146. 'Ccaron': 667,
  28147. 'ugrave': 500,
  28148. 'radical': 453,
  28149. 'Dcaron': 722,
  28150. 'rcommaaccent': 389,
  28151. 'Ntilde': 667,
  28152. 'otilde': 500,
  28153. 'Rcommaaccent': 611,
  28154. 'Lcommaaccent': 556,
  28155. 'Atilde': 611,
  28156. 'Aogonek': 611,
  28157. 'Aring': 611,
  28158. 'Otilde': 722,
  28159. 'zdotaccent': 389,
  28160. 'Ecaron': 611,
  28161. 'Iogonek': 333,
  28162. 'kcommaaccent': 444,
  28163. 'minus': 675,
  28164. 'Icircumflex': 333,
  28165. 'ncaron': 500,
  28166. 'tcommaaccent': 278,
  28167. 'logicalnot': 675,
  28168. 'odieresis': 500,
  28169. 'udieresis': 500,
  28170. 'notequal': 549,
  28171. 'gcommaaccent': 500,
  28172. 'eth': 500,
  28173. 'zcaron': 389,
  28174. 'ncommaaccent': 500,
  28175. 'onesuperior': 300,
  28176. 'imacron': 278,
  28177. 'Euro': 500
  28178. },
  28179. 'ZapfDingbats': {
  28180. 'space': 278,
  28181. 'a1': 974,
  28182. 'a2': 961,
  28183. 'a202': 974,
  28184. 'a3': 980,
  28185. 'a4': 719,
  28186. 'a5': 789,
  28187. 'a119': 790,
  28188. 'a118': 791,
  28189. 'a117': 690,
  28190. 'a11': 960,
  28191. 'a12': 939,
  28192. 'a13': 549,
  28193. 'a14': 855,
  28194. 'a15': 911,
  28195. 'a16': 933,
  28196. 'a105': 911,
  28197. 'a17': 945,
  28198. 'a18': 974,
  28199. 'a19': 755,
  28200. 'a20': 846,
  28201. 'a21': 762,
  28202. 'a22': 761,
  28203. 'a23': 571,
  28204. 'a24': 677,
  28205. 'a25': 763,
  28206. 'a26': 760,
  28207. 'a27': 759,
  28208. 'a28': 754,
  28209. 'a6': 494,
  28210. 'a7': 552,
  28211. 'a8': 537,
  28212. 'a9': 577,
  28213. 'a10': 692,
  28214. 'a29': 786,
  28215. 'a30': 788,
  28216. 'a31': 788,
  28217. 'a32': 790,
  28218. 'a33': 793,
  28219. 'a34': 794,
  28220. 'a35': 816,
  28221. 'a36': 823,
  28222. 'a37': 789,
  28223. 'a38': 841,
  28224. 'a39': 823,
  28225. 'a40': 833,
  28226. 'a41': 816,
  28227. 'a42': 831,
  28228. 'a43': 923,
  28229. 'a44': 744,
  28230. 'a45': 723,
  28231. 'a46': 749,
  28232. 'a47': 790,
  28233. 'a48': 792,
  28234. 'a49': 695,
  28235. 'a50': 776,
  28236. 'a51': 768,
  28237. 'a52': 792,
  28238. 'a53': 759,
  28239. 'a54': 707,
  28240. 'a55': 708,
  28241. 'a56': 682,
  28242. 'a57': 701,
  28243. 'a58': 826,
  28244. 'a59': 815,
  28245. 'a60': 789,
  28246. 'a61': 789,
  28247. 'a62': 707,
  28248. 'a63': 687,
  28249. 'a64': 696,
  28250. 'a65': 689,
  28251. 'a66': 786,
  28252. 'a67': 787,
  28253. 'a68': 713,
  28254. 'a69': 791,
  28255. 'a70': 785,
  28256. 'a71': 791,
  28257. 'a72': 873,
  28258. 'a73': 761,
  28259. 'a74': 762,
  28260. 'a203': 762,
  28261. 'a75': 759,
  28262. 'a204': 759,
  28263. 'a76': 892,
  28264. 'a77': 892,
  28265. 'a78': 788,
  28266. 'a79': 784,
  28267. 'a81': 438,
  28268. 'a82': 138,
  28269. 'a83': 277,
  28270. 'a84': 415,
  28271. 'a97': 392,
  28272. 'a98': 392,
  28273. 'a99': 668,
  28274. 'a100': 668,
  28275. 'a89': 390,
  28276. 'a90': 390,
  28277. 'a93': 317,
  28278. 'a94': 317,
  28279. 'a91': 276,
  28280. 'a92': 276,
  28281. 'a205': 509,
  28282. 'a85': 509,
  28283. 'a206': 410,
  28284. 'a86': 410,
  28285. 'a87': 234,
  28286. 'a88': 234,
  28287. 'a95': 334,
  28288. 'a96': 334,
  28289. 'a101': 732,
  28290. 'a102': 544,
  28291. 'a103': 544,
  28292. 'a104': 910,
  28293. 'a106': 667,
  28294. 'a107': 760,
  28295. 'a108': 760,
  28296. 'a112': 776,
  28297. 'a111': 595,
  28298. 'a110': 694,
  28299. 'a109': 626,
  28300. 'a120': 788,
  28301. 'a121': 788,
  28302. 'a122': 788,
  28303. 'a123': 788,
  28304. 'a124': 788,
  28305. 'a125': 788,
  28306. 'a126': 788,
  28307. 'a127': 788,
  28308. 'a128': 788,
  28309. 'a129': 788,
  28310. 'a130': 788,
  28311. 'a131': 788,
  28312. 'a132': 788,
  28313. 'a133': 788,
  28314. 'a134': 788,
  28315. 'a135': 788,
  28316. 'a136': 788,
  28317. 'a137': 788,
  28318. 'a138': 788,
  28319. 'a139': 788,
  28320. 'a140': 788,
  28321. 'a141': 788,
  28322. 'a142': 788,
  28323. 'a143': 788,
  28324. 'a144': 788,
  28325. 'a145': 788,
  28326. 'a146': 788,
  28327. 'a147': 788,
  28328. 'a148': 788,
  28329. 'a149': 788,
  28330. 'a150': 788,
  28331. 'a151': 788,
  28332. 'a152': 788,
  28333. 'a153': 788,
  28334. 'a154': 788,
  28335. 'a155': 788,
  28336. 'a156': 788,
  28337. 'a157': 788,
  28338. 'a158': 788,
  28339. 'a159': 788,
  28340. 'a160': 894,
  28341. 'a161': 838,
  28342. 'a163': 1016,
  28343. 'a164': 458,
  28344. 'a196': 748,
  28345. 'a165': 924,
  28346. 'a192': 748,
  28347. 'a166': 918,
  28348. 'a167': 927,
  28349. 'a168': 928,
  28350. 'a169': 928,
  28351. 'a170': 834,
  28352. 'a171': 873,
  28353. 'a172': 828,
  28354. 'a173': 924,
  28355. 'a162': 924,
  28356. 'a174': 917,
  28357. 'a175': 930,
  28358. 'a176': 931,
  28359. 'a177': 463,
  28360. 'a178': 883,
  28361. 'a179': 836,
  28362. 'a193': 836,
  28363. 'a180': 867,
  28364. 'a199': 867,
  28365. 'a181': 696,
  28366. 'a200': 696,
  28367. 'a182': 874,
  28368. 'a201': 874,
  28369. 'a183': 760,
  28370. 'a184': 946,
  28371. 'a197': 771,
  28372. 'a185': 865,
  28373. 'a194': 771,
  28374. 'a198': 888,
  28375. 'a186': 967,
  28376. 'a195': 888,
  28377. 'a187': 831,
  28378. 'a188': 873,
  28379. 'a189': 927,
  28380. 'a190': 970,
  28381. 'a191': 918
  28382. }
  28383. };
  28384. var EOF = {};
  28385. function isEOF(v) {
  28386. return (v === EOF);
  28387. }
  28388. var MAX_LENGTH_TO_CACHE = 1000;
  28389. var Parser = (function ParserClosure() {
  28390. function Parser(lexer, allowStreams, xref) {
  28391. this.lexer = lexer;
  28392. this.allowStreams = allowStreams;
  28393. this.xref = xref;
  28394. this.imageCache = {};
  28395. this.refill();
  28396. }
  28397. Parser.prototype = {
  28398. refill: function Parser_refill() {
  28399. this.buf1 = this.lexer.getObj();
  28400. this.buf2 = this.lexer.getObj();
  28401. },
  28402. shift: function Parser_shift() {
  28403. if (isCmd(this.buf2, 'ID')) {
  28404. this.buf1 = this.buf2;
  28405. this.buf2 = null;
  28406. } else {
  28407. this.buf1 = this.buf2;
  28408. this.buf2 = this.lexer.getObj();
  28409. }
  28410. },
  28411. getObj: function Parser_getObj(cipherTransform) {
  28412. var buf1 = this.buf1;
  28413. this.shift();
  28414. if (buf1 instanceof Cmd) {
  28415. switch (buf1.cmd) {
  28416. case 'BI': // inline image
  28417. return this.makeInlineImage(cipherTransform);
  28418. case '[': // array
  28419. var array = [];
  28420. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28421. array.push(this.getObj(cipherTransform));
  28422. }
  28423. if (isEOF(this.buf1)) {
  28424. error('End of file inside array');
  28425. }
  28426. this.shift();
  28427. return array;
  28428. case '<<': // dictionary or stream
  28429. var dict = new Dict(this.xref);
  28430. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28431. if (!isName(this.buf1)) {
  28432. info('Malformed dictionary: key must be a name object');
  28433. this.shift();
  28434. continue;
  28435. }
  28436. var key = this.buf1.name;
  28437. this.shift();
  28438. if (isEOF(this.buf1)) {
  28439. break;
  28440. }
  28441. dict.set(key, this.getObj(cipherTransform));
  28442. }
  28443. if (isEOF(this.buf1)) {
  28444. error('End of file inside dictionary');
  28445. }
  28446. // Stream objects are not allowed inside content streams or
  28447. // object streams.
  28448. if (isCmd(this.buf2, 'stream')) {
  28449. return (this.allowStreams ?
  28450. this.makeStream(dict, cipherTransform) : dict);
  28451. }
  28452. this.shift();
  28453. return dict;
  28454. default: // simple object
  28455. return buf1;
  28456. }
  28457. }
  28458. if (isInt(buf1)) { // indirect reference or integer
  28459. var num = buf1;
  28460. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28461. var ref = new Ref(num, this.buf1);
  28462. this.shift();
  28463. this.shift();
  28464. return ref;
  28465. }
  28466. return num;
  28467. }
  28468. if (isString(buf1)) { // string
  28469. var str = buf1;
  28470. if (cipherTransform) {
  28471. str = cipherTransform.decryptString(str);
  28472. }
  28473. return str;
  28474. }
  28475. // simple object
  28476. return buf1;
  28477. },
  28478. /**
  28479. * Find the end of the stream by searching for the /EI\s/.
  28480. * @returns {number} The inline stream length.
  28481. */
  28482. findDefaultInlineStreamEnd:
  28483. function Parser_findDefaultInlineStreamEnd(stream) {
  28484. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28485. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28486. while ((ch = stream.getByte()) !== -1) {
  28487. if (state === 0) {
  28488. state = (ch === E) ? 1 : 0;
  28489. } else if (state === 1) {
  28490. state = (ch === I) ? 2 : 0;
  28491. } else {
  28492. assert(state === 2);
  28493. if (ch === SPACE || ch === LF || ch === CR) {
  28494. // Let's check the next five bytes are ASCII... just be sure.
  28495. n = 5;
  28496. followingBytes = stream.peekBytes(n);
  28497. for (i = 0; i < n; i++) {
  28498. ch = followingBytes[i];
  28499. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28500. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28501. // it's binary stuff. Resetting the state.
  28502. state = 0;
  28503. break;
  28504. }
  28505. }
  28506. if (state === 2) {
  28507. break; // Finished!
  28508. }
  28509. } else {
  28510. state = 0;
  28511. }
  28512. }
  28513. }
  28514. return ((stream.pos - 4) - startPos);
  28515. },
  28516. /**
  28517. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28518. * @returns {number} The inline stream length.
  28519. */
  28520. findDCTDecodeInlineStreamEnd:
  28521. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28522. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28523. while ((b = stream.getByte()) !== -1) {
  28524. if (b !== 0xFF) { // Not a valid marker.
  28525. continue;
  28526. }
  28527. switch (stream.getByte()) {
  28528. case 0x00: // Byte stuffing.
  28529. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28530. break;
  28531. case 0xFF: // Fill byte.
  28532. // Avoid skipping a valid marker, resetting the stream position.
  28533. stream.skip(-1);
  28534. break;
  28535. case 0xD9: // EOI
  28536. foundEOI = true;
  28537. break;
  28538. case 0xC0: // SOF0
  28539. case 0xC1: // SOF1
  28540. case 0xC2: // SOF2
  28541. case 0xC3: // SOF3
  28542. case 0xC5: // SOF5
  28543. case 0xC6: // SOF6
  28544. case 0xC7: // SOF7
  28545. case 0xC9: // SOF9
  28546. case 0xCA: // SOF10
  28547. case 0xCB: // SOF11
  28548. case 0xCD: // SOF13
  28549. case 0xCE: // SOF14
  28550. case 0xCF: // SOF15
  28551. case 0xC4: // DHT
  28552. case 0xCC: // DAC
  28553. case 0xDA: // SOS
  28554. case 0xDB: // DQT
  28555. case 0xDC: // DNL
  28556. case 0xDD: // DRI
  28557. case 0xDE: // DHP
  28558. case 0xDF: // EXP
  28559. case 0xE0: // APP0
  28560. case 0xE1: // APP1
  28561. case 0xE2: // APP2
  28562. case 0xE3: // APP3
  28563. case 0xE4: // APP4
  28564. case 0xE5: // APP5
  28565. case 0xE6: // APP6
  28566. case 0xE7: // APP7
  28567. case 0xE8: // APP8
  28568. case 0xE9: // APP9
  28569. case 0xEA: // APP10
  28570. case 0xEB: // APP11
  28571. case 0xEC: // APP12
  28572. case 0xED: // APP13
  28573. case 0xEE: // APP14
  28574. case 0xEF: // APP15
  28575. case 0xFE: // COM
  28576. // The marker should be followed by the length of the segment.
  28577. markerLength = stream.getUint16();
  28578. if (markerLength > 2) {
  28579. // |markerLength| contains the byte length of the marker segment,
  28580. // including its own length (2 bytes) and excluding the marker.
  28581. stream.skip(markerLength - 2); // Jump to the next marker.
  28582. } else {
  28583. // The marker length is invalid, resetting the stream position.
  28584. stream.skip(-2);
  28585. }
  28586. break;
  28587. }
  28588. if (foundEOI) {
  28589. break;
  28590. }
  28591. }
  28592. length = stream.pos - startPos;
  28593. if (b === -1) {
  28594. warn('Inline DCTDecode image stream: ' +
  28595. 'EOI marker not found, searching for /EI/ instead.');
  28596. stream.skip(-length); // Reset the stream position.
  28597. return this.findDefaultInlineStreamEnd(stream);
  28598. }
  28599. this.inlineStreamSkipEI(stream);
  28600. return length;
  28601. },
  28602. /**
  28603. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28604. * @returns {number} The inline stream length.
  28605. */
  28606. findASCII85DecodeInlineStreamEnd:
  28607. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28608. var TILDE = 0x7E, GT = 0x3E;
  28609. var startPos = stream.pos, ch, length;
  28610. while ((ch = stream.getByte()) !== -1) {
  28611. if (ch === TILDE && stream.peekByte() === GT) {
  28612. stream.skip();
  28613. break;
  28614. }
  28615. }
  28616. length = stream.pos - startPos;
  28617. if (ch === -1) {
  28618. warn('Inline ASCII85Decode image stream: ' +
  28619. 'EOD marker not found, searching for /EI/ instead.');
  28620. stream.skip(-length); // Reset the stream position.
  28621. return this.findDefaultInlineStreamEnd(stream);
  28622. }
  28623. this.inlineStreamSkipEI(stream);
  28624. return length;
  28625. },
  28626. /**
  28627. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28628. * @returns {number} The inline stream length.
  28629. */
  28630. findASCIIHexDecodeInlineStreamEnd:
  28631. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28632. var GT = 0x3E;
  28633. var startPos = stream.pos, ch, length;
  28634. while ((ch = stream.getByte()) !== -1) {
  28635. if (ch === GT) {
  28636. break;
  28637. }
  28638. }
  28639. length = stream.pos - startPos;
  28640. if (ch === -1) {
  28641. warn('Inline ASCIIHexDecode image stream: ' +
  28642. 'EOD marker not found, searching for /EI/ instead.');
  28643. stream.skip(-length); // Reset the stream position.
  28644. return this.findDefaultInlineStreamEnd(stream);
  28645. }
  28646. this.inlineStreamSkipEI(stream);
  28647. return length;
  28648. },
  28649. /**
  28650. * Skip over the /EI/ for streams where we search for an EOD marker.
  28651. */
  28652. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28653. var E = 0x45, I = 0x49;
  28654. var state = 0, ch;
  28655. while ((ch = stream.getByte()) !== -1) {
  28656. if (state === 0) {
  28657. state = (ch === E) ? 1 : 0;
  28658. } else if (state === 1) {
  28659. state = (ch === I) ? 2 : 0;
  28660. } else if (state === 2) {
  28661. break;
  28662. }
  28663. }
  28664. },
  28665. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28666. var lexer = this.lexer;
  28667. var stream = lexer.stream;
  28668. // Parse dictionary.
  28669. var dict = new Dict(null);
  28670. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28671. if (!isName(this.buf1)) {
  28672. error('Dictionary key must be a name object');
  28673. }
  28674. var key = this.buf1.name;
  28675. this.shift();
  28676. if (isEOF(this.buf1)) {
  28677. break;
  28678. }
  28679. dict.set(key, this.getObj(cipherTransform));
  28680. }
  28681. // Extract the name of the first (i.e. the current) image filter.
  28682. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28683. if (isName(filter)) {
  28684. filterName = filter.name;
  28685. } else if (isArray(filter) && isName(filter[0])) {
  28686. filterName = filter[0].name;
  28687. }
  28688. // Parse image stream.
  28689. var startPos = stream.pos, length, i, ii;
  28690. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28691. length = this.findDCTDecodeInlineStreamEnd(stream);
  28692. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28693. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28694. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28695. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28696. } else {
  28697. length = this.findDefaultInlineStreamEnd(stream);
  28698. }
  28699. var imageStream = stream.makeSubStream(startPos, length, dict);
  28700. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28701. // adler32 checksum.
  28702. var adler32;
  28703. if (length < MAX_LENGTH_TO_CACHE) {
  28704. var imageBytes = imageStream.getBytes();
  28705. imageStream.reset();
  28706. var a = 1;
  28707. var b = 0;
  28708. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28709. // No modulo required in the loop if imageBytes.length < 5552.
  28710. a += imageBytes[i] & 0xff;
  28711. b += a;
  28712. }
  28713. adler32 = ((b % 65521) << 16) | (a % 65521);
  28714. if (this.imageCache.adler32 === adler32) {
  28715. this.buf2 = Cmd.get('EI');
  28716. this.shift();
  28717. this.imageCache[adler32].reset();
  28718. return this.imageCache[adler32];
  28719. }
  28720. }
  28721. if (cipherTransform) {
  28722. imageStream = cipherTransform.createStream(imageStream, length);
  28723. }
  28724. imageStream = this.filter(imageStream, dict, length);
  28725. imageStream.dict = dict;
  28726. if (adler32 !== undefined) {
  28727. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28728. this.imageCache[adler32] = imageStream;
  28729. }
  28730. this.buf2 = Cmd.get('EI');
  28731. this.shift();
  28732. return imageStream;
  28733. },
  28734. fetchIfRef: function Parser_fetchIfRef(obj) {
  28735. // not relying on the xref.fetchIfRef -- xref might not be set
  28736. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28737. },
  28738. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28739. var lexer = this.lexer;
  28740. var stream = lexer.stream;
  28741. // get stream start position
  28742. lexer.skipToNextLine();
  28743. var pos = stream.pos - 1;
  28744. // get length
  28745. var length = this.fetchIfRef(dict.get('Length'));
  28746. if (!isInt(length)) {
  28747. info('Bad ' + length + ' attribute in stream');
  28748. length = 0;
  28749. }
  28750. // skip over the stream data
  28751. stream.pos = pos + length;
  28752. lexer.nextChar();
  28753. this.shift(); // '>>'
  28754. this.shift(); // 'stream'
  28755. if (!isCmd(this.buf1, 'endstream')) {
  28756. // bad stream length, scanning for endstream
  28757. stream.pos = pos;
  28758. var SCAN_BLOCK_SIZE = 2048;
  28759. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28760. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28761. 0x61, 0x6D];
  28762. var skipped = 0, found = false, i, j;
  28763. while (stream.pos < stream.end) {
  28764. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28765. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28766. if (scanLength <= 0) {
  28767. break;
  28768. }
  28769. found = false;
  28770. for (i = 0, j = 0; i < scanLength; i++) {
  28771. var b = scanBytes[i];
  28772. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28773. i -= j;
  28774. j = 0;
  28775. } else {
  28776. j++;
  28777. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28778. i++;
  28779. found = true;
  28780. break;
  28781. }
  28782. }
  28783. }
  28784. if (found) {
  28785. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28786. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28787. break;
  28788. }
  28789. skipped += scanLength;
  28790. stream.pos += scanLength;
  28791. }
  28792. if (!found) {
  28793. error('Missing endstream');
  28794. }
  28795. length = skipped;
  28796. lexer.nextChar();
  28797. this.shift();
  28798. this.shift();
  28799. }
  28800. this.shift(); // 'endstream'
  28801. stream = stream.makeSubStream(pos, length, dict);
  28802. if (cipherTransform) {
  28803. stream = cipherTransform.createStream(stream, length);
  28804. }
  28805. stream = this.filter(stream, dict, length);
  28806. stream.dict = dict;
  28807. return stream;
  28808. },
  28809. filter: function Parser_filter(stream, dict, length) {
  28810. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28811. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28812. if (isName(filter)) {
  28813. return this.makeFilter(stream, filter.name, length, params);
  28814. }
  28815. var maybeLength = length;
  28816. if (isArray(filter)) {
  28817. var filterArray = filter;
  28818. var paramsArray = params;
  28819. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28820. filter = filterArray[i];
  28821. if (!isName(filter)) {
  28822. error('Bad filter name: ' + filter);
  28823. }
  28824. params = null;
  28825. if (isArray(paramsArray) && (i in paramsArray)) {
  28826. params = paramsArray[i];
  28827. }
  28828. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28829. // after the first stream the length variable is invalid
  28830. maybeLength = null;
  28831. }
  28832. }
  28833. return stream;
  28834. },
  28835. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28836. if (stream.dict.get('Length') === 0) {
  28837. return new NullStream(stream);
  28838. }
  28839. try {
  28840. if (params) {
  28841. params = this.fetchIfRef(params);
  28842. }
  28843. var xrefStreamStats = this.xref.stats.streamTypes;
  28844. if (name === 'FlateDecode' || name === 'Fl') {
  28845. xrefStreamStats[StreamType.FLATE] = true;
  28846. if (params) {
  28847. return new PredictorStream(new FlateStream(stream, maybeLength),
  28848. maybeLength, params);
  28849. }
  28850. return new FlateStream(stream, maybeLength);
  28851. }
  28852. if (name === 'LZWDecode' || name === 'LZW') {
  28853. xrefStreamStats[StreamType.LZW] = true;
  28854. var earlyChange = 1;
  28855. if (params) {
  28856. if (params.has('EarlyChange')) {
  28857. earlyChange = params.get('EarlyChange');
  28858. }
  28859. return new PredictorStream(
  28860. new LZWStream(stream, maybeLength, earlyChange),
  28861. maybeLength, params);
  28862. }
  28863. return new LZWStream(stream, maybeLength, earlyChange);
  28864. }
  28865. if (name === 'DCTDecode' || name === 'DCT') {
  28866. xrefStreamStats[StreamType.DCT] = true;
  28867. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28868. }
  28869. if (name === 'JPXDecode' || name === 'JPX') {
  28870. xrefStreamStats[StreamType.JPX] = true;
  28871. return new JpxStream(stream, maybeLength, stream.dict);
  28872. }
  28873. if (name === 'ASCII85Decode' || name === 'A85') {
  28874. xrefStreamStats[StreamType.A85] = true;
  28875. return new Ascii85Stream(stream, maybeLength);
  28876. }
  28877. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28878. xrefStreamStats[StreamType.AHX] = true;
  28879. return new AsciiHexStream(stream, maybeLength);
  28880. }
  28881. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28882. xrefStreamStats[StreamType.CCF] = true;
  28883. return new CCITTFaxStream(stream, maybeLength, params);
  28884. }
  28885. if (name === 'RunLengthDecode' || name === 'RL') {
  28886. xrefStreamStats[StreamType.RL] = true;
  28887. return new RunLengthStream(stream, maybeLength);
  28888. }
  28889. if (name === 'JBIG2Decode') {
  28890. xrefStreamStats[StreamType.JBIG] = true;
  28891. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28892. }
  28893. warn('filter "' + name + '" not supported yet');
  28894. return stream;
  28895. } catch (ex) {
  28896. if (ex instanceof MissingDataException) {
  28897. throw ex;
  28898. }
  28899. warn('Invalid stream: \"' + ex + '\"');
  28900. return new NullStream(stream);
  28901. }
  28902. }
  28903. };
  28904. return Parser;
  28905. })();
  28906. var Lexer = (function LexerClosure() {
  28907. function Lexer(stream, knownCommands) {
  28908. this.stream = stream;
  28909. this.nextChar();
  28910. // While lexing, we build up many strings one char at a time. Using += for
  28911. // this can result in lots of garbage strings. It's better to build an
  28912. // array of single-char strings and then join() them together at the end.
  28913. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28914. // purpose uses less memory than using a new array for each string.
  28915. this.strBuf = [];
  28916. // The PDFs might have "glued" commands with other commands, operands or
  28917. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28918. // commands and their prefixes. The prefixes are built the following way:
  28919. // if there a command that is a prefix of the other valid command or
  28920. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28921. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28922. // other commands or literals as a prefix. The knowCommands is optional.
  28923. this.knownCommands = knownCommands;
  28924. }
  28925. Lexer.isSpace = function Lexer_isSpace(ch) {
  28926. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28927. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28928. };
  28929. // A '1' in this array means the character is white space. A '1' or
  28930. // '2' means the character ends a name or command.
  28931. var specialChars = [
  28932. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28934. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28948. ];
  28949. function toHexDigit(ch) {
  28950. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28951. return ch & 0x0F;
  28952. }
  28953. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28954. // 'A'-'F', 'a'-'f'
  28955. return (ch & 0x0F) + 9;
  28956. }
  28957. return -1;
  28958. }
  28959. Lexer.prototype = {
  28960. nextChar: function Lexer_nextChar() {
  28961. return (this.currentChar = this.stream.getByte());
  28962. },
  28963. peekChar: function Lexer_peekChar() {
  28964. return this.stream.peekByte();
  28965. },
  28966. getNumber: function Lexer_getNumber() {
  28967. var ch = this.currentChar;
  28968. var eNotation = false;
  28969. var divideBy = 0; // different from 0 if it's a floating point value
  28970. var sign = 1;
  28971. if (ch === 0x2D) { // '-'
  28972. sign = -1;
  28973. ch = this.nextChar();
  28974. } else if (ch === 0x2B) { // '+'
  28975. ch = this.nextChar();
  28976. }
  28977. if (ch === 0x2E) { // '.'
  28978. divideBy = 10;
  28979. ch = this.nextChar();
  28980. }
  28981. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28982. error('Invalid number: ' + String.fromCharCode(ch));
  28983. return 0;
  28984. }
  28985. var baseValue = ch - 0x30; // '0'
  28986. var powerValue = 0;
  28987. var powerValueSign = 1;
  28988. while ((ch = this.nextChar()) >= 0) {
  28989. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28990. var currentDigit = ch - 0x30; // '0'
  28991. if (eNotation) { // We are after an 'e' or 'E'
  28992. powerValue = powerValue * 10 + currentDigit;
  28993. } else {
  28994. if (divideBy !== 0) { // We are after a point
  28995. divideBy *= 10;
  28996. }
  28997. baseValue = baseValue * 10 + currentDigit;
  28998. }
  28999. } else if (ch === 0x2E) { // '.'
  29000. if (divideBy === 0) {
  29001. divideBy = 1;
  29002. } else {
  29003. // A number can have only one '.'
  29004. break;
  29005. }
  29006. } else if (ch === 0x2D) { // '-'
  29007. // ignore minus signs in the middle of numbers to match
  29008. // Adobe's behavior
  29009. warn('Badly formated number');
  29010. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29011. // 'E' can be either a scientific notation or the beginning of a new
  29012. // operator
  29013. ch = this.peekChar();
  29014. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29015. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29016. this.nextChar(); // Consume the sign character
  29017. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29018. // The 'E' must be the beginning of a new operator
  29019. break;
  29020. }
  29021. eNotation = true;
  29022. } else {
  29023. // the last character doesn't belong to us
  29024. break;
  29025. }
  29026. }
  29027. if (divideBy !== 0) {
  29028. baseValue /= divideBy;
  29029. }
  29030. if (eNotation) {
  29031. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29032. }
  29033. return sign * baseValue;
  29034. },
  29035. getString: function Lexer_getString() {
  29036. var numParen = 1;
  29037. var done = false;
  29038. var strBuf = this.strBuf;
  29039. strBuf.length = 0;
  29040. var ch = this.nextChar();
  29041. while (true) {
  29042. var charBuffered = false;
  29043. switch (ch | 0) {
  29044. case -1:
  29045. warn('Unterminated string');
  29046. done = true;
  29047. break;
  29048. case 0x28: // '('
  29049. ++numParen;
  29050. strBuf.push('(');
  29051. break;
  29052. case 0x29: // ')'
  29053. if (--numParen === 0) {
  29054. this.nextChar(); // consume strings ')'
  29055. done = true;
  29056. } else {
  29057. strBuf.push(')');
  29058. }
  29059. break;
  29060. case 0x5C: // '\\'
  29061. ch = this.nextChar();
  29062. switch (ch) {
  29063. case -1:
  29064. warn('Unterminated string');
  29065. done = true;
  29066. break;
  29067. case 0x6E: // 'n'
  29068. strBuf.push('\n');
  29069. break;
  29070. case 0x72: // 'r'
  29071. strBuf.push('\r');
  29072. break;
  29073. case 0x74: // 't'
  29074. strBuf.push('\t');
  29075. break;
  29076. case 0x62: // 'b'
  29077. strBuf.push('\b');
  29078. break;
  29079. case 0x66: // 'f'
  29080. strBuf.push('\f');
  29081. break;
  29082. case 0x5C: // '\'
  29083. case 0x28: // '('
  29084. case 0x29: // ')'
  29085. strBuf.push(String.fromCharCode(ch));
  29086. break;
  29087. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29088. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29089. var x = ch & 0x0F;
  29090. ch = this.nextChar();
  29091. charBuffered = true;
  29092. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29093. x = (x << 3) + (ch & 0x0F);
  29094. ch = this.nextChar();
  29095. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29096. charBuffered = false;
  29097. x = (x << 3) + (ch & 0x0F);
  29098. }
  29099. }
  29100. strBuf.push(String.fromCharCode(x));
  29101. break;
  29102. case 0x0D: // CR
  29103. if (this.peekChar() === 0x0A) { // LF
  29104. this.nextChar();
  29105. }
  29106. break;
  29107. case 0x0A: // LF
  29108. break;
  29109. default:
  29110. strBuf.push(String.fromCharCode(ch));
  29111. break;
  29112. }
  29113. break;
  29114. default:
  29115. strBuf.push(String.fromCharCode(ch));
  29116. break;
  29117. }
  29118. if (done) {
  29119. break;
  29120. }
  29121. if (!charBuffered) {
  29122. ch = this.nextChar();
  29123. }
  29124. }
  29125. return strBuf.join('');
  29126. },
  29127. getName: function Lexer_getName() {
  29128. var ch;
  29129. var strBuf = this.strBuf;
  29130. strBuf.length = 0;
  29131. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29132. if (ch === 0x23) { // '#'
  29133. ch = this.nextChar();
  29134. var x = toHexDigit(ch);
  29135. if (x !== -1) {
  29136. var x2 = toHexDigit(this.nextChar());
  29137. if (x2 === -1) {
  29138. error('Illegal digit in hex char in name: ' + x2);
  29139. }
  29140. strBuf.push(String.fromCharCode((x << 4) | x2));
  29141. } else {
  29142. strBuf.push('#', String.fromCharCode(ch));
  29143. }
  29144. } else {
  29145. strBuf.push(String.fromCharCode(ch));
  29146. }
  29147. }
  29148. if (strBuf.length > 128) {
  29149. error('Warning: name token is longer than allowed by the spec: ' +
  29150. strBuf.length);
  29151. }
  29152. return Name.get(strBuf.join(''));
  29153. },
  29154. getHexString: function Lexer_getHexString() {
  29155. var strBuf = this.strBuf;
  29156. strBuf.length = 0;
  29157. var ch = this.currentChar;
  29158. var isFirstHex = true;
  29159. var firstDigit;
  29160. var secondDigit;
  29161. while (true) {
  29162. if (ch < 0) {
  29163. warn('Unterminated hex string');
  29164. break;
  29165. } else if (ch === 0x3E) { // '>'
  29166. this.nextChar();
  29167. break;
  29168. } else if (specialChars[ch] === 1) {
  29169. ch = this.nextChar();
  29170. continue;
  29171. } else {
  29172. if (isFirstHex) {
  29173. firstDigit = toHexDigit(ch);
  29174. if (firstDigit === -1) {
  29175. warn('Ignoring invalid character "' + ch + '" in hex string');
  29176. ch = this.nextChar();
  29177. continue;
  29178. }
  29179. } else {
  29180. secondDigit = toHexDigit(ch);
  29181. if (secondDigit === -1) {
  29182. warn('Ignoring invalid character "' + ch + '" in hex string');
  29183. ch = this.nextChar();
  29184. continue;
  29185. }
  29186. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29187. }
  29188. isFirstHex = !isFirstHex;
  29189. ch = this.nextChar();
  29190. }
  29191. }
  29192. return strBuf.join('');
  29193. },
  29194. getObj: function Lexer_getObj() {
  29195. // skip whitespace and comments
  29196. var comment = false;
  29197. var ch = this.currentChar;
  29198. while (true) {
  29199. if (ch < 0) {
  29200. return EOF;
  29201. }
  29202. if (comment) {
  29203. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29204. comment = false;
  29205. }
  29206. } else if (ch === 0x25) { // '%'
  29207. comment = true;
  29208. } else if (specialChars[ch] !== 1) {
  29209. break;
  29210. }
  29211. ch = this.nextChar();
  29212. }
  29213. // start reading token
  29214. switch (ch | 0) {
  29215. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29216. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29217. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29218. return this.getNumber();
  29219. case 0x28: // '('
  29220. return this.getString();
  29221. case 0x2F: // '/'
  29222. return this.getName();
  29223. // array punctuation
  29224. case 0x5B: // '['
  29225. this.nextChar();
  29226. return Cmd.get('[');
  29227. case 0x5D: // ']'
  29228. this.nextChar();
  29229. return Cmd.get(']');
  29230. // hex string or dict punctuation
  29231. case 0x3C: // '<'
  29232. ch = this.nextChar();
  29233. if (ch === 0x3C) {
  29234. // dict punctuation
  29235. this.nextChar();
  29236. return Cmd.get('<<');
  29237. }
  29238. return this.getHexString();
  29239. // dict punctuation
  29240. case 0x3E: // '>'
  29241. ch = this.nextChar();
  29242. if (ch === 0x3E) {
  29243. this.nextChar();
  29244. return Cmd.get('>>');
  29245. }
  29246. return Cmd.get('>');
  29247. case 0x7B: // '{'
  29248. this.nextChar();
  29249. return Cmd.get('{');
  29250. case 0x7D: // '}'
  29251. this.nextChar();
  29252. return Cmd.get('}');
  29253. case 0x29: // ')'
  29254. error('Illegal character: ' + ch);
  29255. break;
  29256. }
  29257. // command
  29258. var str = String.fromCharCode(ch);
  29259. var knownCommands = this.knownCommands;
  29260. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29261. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29262. // stop if known command is found and next character does not make
  29263. // the str a command
  29264. var possibleCommand = str + String.fromCharCode(ch);
  29265. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29266. break;
  29267. }
  29268. if (str.length === 128) {
  29269. error('Command token too long: ' + str.length);
  29270. }
  29271. str = possibleCommand;
  29272. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29273. }
  29274. if (str === 'true') {
  29275. return true;
  29276. }
  29277. if (str === 'false') {
  29278. return false;
  29279. }
  29280. if (str === 'null') {
  29281. return null;
  29282. }
  29283. return Cmd.get(str);
  29284. },
  29285. skipToNextLine: function Lexer_skipToNextLine() {
  29286. var ch = this.currentChar;
  29287. while (ch >= 0) {
  29288. if (ch === 0x0D) { // CR
  29289. ch = this.nextChar();
  29290. if (ch === 0x0A) { // LF
  29291. this.nextChar();
  29292. }
  29293. break;
  29294. } else if (ch === 0x0A) { // LF
  29295. this.nextChar();
  29296. break;
  29297. }
  29298. ch = this.nextChar();
  29299. }
  29300. }
  29301. };
  29302. return Lexer;
  29303. })();
  29304. var Linearization = {
  29305. create: function LinearizationCreate(stream) {
  29306. function getInt(name, allowZeroValue) {
  29307. var obj = linDict.get(name);
  29308. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29309. return obj;
  29310. }
  29311. throw new Error('The "' + name + '" parameter in the linearization ' +
  29312. 'dictionary is invalid.');
  29313. }
  29314. function getHints() {
  29315. var hints = linDict.get('H'), hintsLength, item;
  29316. if (isArray(hints) &&
  29317. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29318. for (var index = 0; index < hintsLength; index++) {
  29319. if (!(isInt(item = hints[index]) && item > 0)) {
  29320. throw new Error('Hint (' + index +
  29321. ') in the linearization dictionary is invalid.');
  29322. }
  29323. }
  29324. return hints;
  29325. }
  29326. throw new Error('Hint array in the linearization dictionary is invalid.');
  29327. }
  29328. var parser = new Parser(new Lexer(stream), false, null);
  29329. var obj1 = parser.getObj();
  29330. var obj2 = parser.getObj();
  29331. var obj3 = parser.getObj();
  29332. var linDict = parser.getObj();
  29333. var obj, length;
  29334. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29335. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29336. return null; // No valid linearization dictionary found.
  29337. } else if ((length = getInt('L')) !== stream.length) {
  29338. throw new Error('The "L" parameter in the linearization dictionary ' +
  29339. 'does not equal the stream length.');
  29340. }
  29341. return {
  29342. length: length,
  29343. hints: getHints(),
  29344. objectNumberFirst: getInt('O'),
  29345. endFirst: getInt('E'),
  29346. numPages: getInt('N'),
  29347. mainXRefEntriesOffset: getInt('T'),
  29348. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29349. };
  29350. }
  29351. };
  29352. var PostScriptParser = (function PostScriptParserClosure() {
  29353. function PostScriptParser(lexer) {
  29354. this.lexer = lexer;
  29355. this.operators = [];
  29356. this.token = null;
  29357. this.prev = null;
  29358. }
  29359. PostScriptParser.prototype = {
  29360. nextToken: function PostScriptParser_nextToken() {
  29361. this.prev = this.token;
  29362. this.token = this.lexer.getToken();
  29363. },
  29364. accept: function PostScriptParser_accept(type) {
  29365. if (this.token.type === type) {
  29366. this.nextToken();
  29367. return true;
  29368. }
  29369. return false;
  29370. },
  29371. expect: function PostScriptParser_expect(type) {
  29372. if (this.accept(type)) {
  29373. return true;
  29374. }
  29375. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29376. type + '.');
  29377. },
  29378. parse: function PostScriptParser_parse() {
  29379. this.nextToken();
  29380. this.expect(PostScriptTokenTypes.LBRACE);
  29381. this.parseBlock();
  29382. this.expect(PostScriptTokenTypes.RBRACE);
  29383. return this.operators;
  29384. },
  29385. parseBlock: function PostScriptParser_parseBlock() {
  29386. while (true) {
  29387. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29388. this.operators.push(this.prev.value);
  29389. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29390. this.operators.push(this.prev.value);
  29391. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29392. this.parseCondition();
  29393. } else {
  29394. return;
  29395. }
  29396. }
  29397. },
  29398. parseCondition: function PostScriptParser_parseCondition() {
  29399. // Add two place holders that will be updated later
  29400. var conditionLocation = this.operators.length;
  29401. this.operators.push(null, null);
  29402. this.parseBlock();
  29403. this.expect(PostScriptTokenTypes.RBRACE);
  29404. if (this.accept(PostScriptTokenTypes.IF)) {
  29405. // The true block is right after the 'if' so it just falls through on
  29406. // true else it jumps and skips the true block.
  29407. this.operators[conditionLocation] = this.operators.length;
  29408. this.operators[conditionLocation + 1] = 'jz';
  29409. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29410. var jumpLocation = this.operators.length;
  29411. this.operators.push(null, null);
  29412. var endOfTrue = this.operators.length;
  29413. this.parseBlock();
  29414. this.expect(PostScriptTokenTypes.RBRACE);
  29415. this.expect(PostScriptTokenTypes.IFELSE);
  29416. // The jump is added at the end of the true block to skip the false
  29417. // block.
  29418. this.operators[jumpLocation] = this.operators.length;
  29419. this.operators[jumpLocation + 1] = 'j';
  29420. this.operators[conditionLocation] = endOfTrue;
  29421. this.operators[conditionLocation + 1] = 'jz';
  29422. } else {
  29423. error('PS Function: error parsing conditional.');
  29424. }
  29425. }
  29426. };
  29427. return PostScriptParser;
  29428. })();
  29429. var PostScriptTokenTypes = {
  29430. LBRACE: 0,
  29431. RBRACE: 1,
  29432. NUMBER: 2,
  29433. OPERATOR: 3,
  29434. IF: 4,
  29435. IFELSE: 5
  29436. };
  29437. var PostScriptToken = (function PostScriptTokenClosure() {
  29438. function PostScriptToken(type, value) {
  29439. this.type = type;
  29440. this.value = value;
  29441. }
  29442. var opCache = {};
  29443. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29444. var opValue = opCache[op];
  29445. if (opValue) {
  29446. return opValue;
  29447. }
  29448. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29449. };
  29450. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29451. '{');
  29452. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29453. '}');
  29454. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29455. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29456. 'IFELSE');
  29457. return PostScriptToken;
  29458. })();
  29459. var PostScriptLexer = (function PostScriptLexerClosure() {
  29460. function PostScriptLexer(stream) {
  29461. this.stream = stream;
  29462. this.nextChar();
  29463. this.strBuf = [];
  29464. }
  29465. PostScriptLexer.prototype = {
  29466. nextChar: function PostScriptLexer_nextChar() {
  29467. return (this.currentChar = this.stream.getByte());
  29468. },
  29469. getToken: function PostScriptLexer_getToken() {
  29470. var comment = false;
  29471. var ch = this.currentChar;
  29472. // skip comments
  29473. while (true) {
  29474. if (ch < 0) {
  29475. return EOF;
  29476. }
  29477. if (comment) {
  29478. if (ch === 0x0A || ch === 0x0D) {
  29479. comment = false;
  29480. }
  29481. } else if (ch === 0x25) { // '%'
  29482. comment = true;
  29483. } else if (!Lexer.isSpace(ch)) {
  29484. break;
  29485. }
  29486. ch = this.nextChar();
  29487. }
  29488. switch (ch | 0) {
  29489. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29490. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29491. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29492. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29493. this.getNumber());
  29494. case 0x7B: // '{'
  29495. this.nextChar();
  29496. return PostScriptToken.LBRACE;
  29497. case 0x7D: // '}'
  29498. this.nextChar();
  29499. return PostScriptToken.RBRACE;
  29500. }
  29501. // operator
  29502. var strBuf = this.strBuf;
  29503. strBuf.length = 0;
  29504. strBuf[0] = String.fromCharCode(ch);
  29505. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29506. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29507. strBuf.push(String.fromCharCode(ch));
  29508. }
  29509. var str = strBuf.join('');
  29510. switch (str.toLowerCase()) {
  29511. case 'if':
  29512. return PostScriptToken.IF;
  29513. case 'ifelse':
  29514. return PostScriptToken.IFELSE;
  29515. default:
  29516. return PostScriptToken.getOperator(str);
  29517. }
  29518. },
  29519. getNumber: function PostScriptLexer_getNumber() {
  29520. var ch = this.currentChar;
  29521. var strBuf = this.strBuf;
  29522. strBuf.length = 0;
  29523. strBuf[0] = String.fromCharCode(ch);
  29524. while ((ch = this.nextChar()) >= 0) {
  29525. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29526. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29527. strBuf.push(String.fromCharCode(ch));
  29528. } else {
  29529. break;
  29530. }
  29531. }
  29532. var value = parseFloat(strBuf.join(''));
  29533. if (isNaN(value)) {
  29534. error('Invalid floating point number: ' + value);
  29535. }
  29536. return value;
  29537. }
  29538. };
  29539. return PostScriptLexer;
  29540. })();
  29541. var Stream = (function StreamClosure() {
  29542. function Stream(arrayBuffer, start, length, dict) {
  29543. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29544. arrayBuffer : new Uint8Array(arrayBuffer));
  29545. this.start = start || 0;
  29546. this.pos = this.start;
  29547. this.end = (start + length) || this.bytes.length;
  29548. this.dict = dict;
  29549. }
  29550. // required methods for a stream. if a particular stream does not
  29551. // implement these, an error should be thrown
  29552. Stream.prototype = {
  29553. get length() {
  29554. return this.end - this.start;
  29555. },
  29556. get isEmpty() {
  29557. return this.length === 0;
  29558. },
  29559. getByte: function Stream_getByte() {
  29560. if (this.pos >= this.end) {
  29561. return -1;
  29562. }
  29563. return this.bytes[this.pos++];
  29564. },
  29565. getUint16: function Stream_getUint16() {
  29566. var b0 = this.getByte();
  29567. var b1 = this.getByte();
  29568. if (b0 === -1 || b1 === -1) {
  29569. return -1;
  29570. }
  29571. return (b0 << 8) + b1;
  29572. },
  29573. getInt32: function Stream_getInt32() {
  29574. var b0 = this.getByte();
  29575. var b1 = this.getByte();
  29576. var b2 = this.getByte();
  29577. var b3 = this.getByte();
  29578. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29579. },
  29580. // returns subarray of original buffer
  29581. // should only be read
  29582. getBytes: function Stream_getBytes(length) {
  29583. var bytes = this.bytes;
  29584. var pos = this.pos;
  29585. var strEnd = this.end;
  29586. if (!length) {
  29587. return bytes.subarray(pos, strEnd);
  29588. }
  29589. var end = pos + length;
  29590. if (end > strEnd) {
  29591. end = strEnd;
  29592. }
  29593. this.pos = end;
  29594. return bytes.subarray(pos, end);
  29595. },
  29596. peekByte: function Stream_peekByte() {
  29597. var peekedByte = this.getByte();
  29598. this.pos--;
  29599. return peekedByte;
  29600. },
  29601. peekBytes: function Stream_peekBytes(length) {
  29602. var bytes = this.getBytes(length);
  29603. this.pos -= bytes.length;
  29604. return bytes;
  29605. },
  29606. skip: function Stream_skip(n) {
  29607. if (!n) {
  29608. n = 1;
  29609. }
  29610. this.pos += n;
  29611. },
  29612. reset: function Stream_reset() {
  29613. this.pos = this.start;
  29614. },
  29615. moveStart: function Stream_moveStart() {
  29616. this.start = this.pos;
  29617. },
  29618. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29619. return new Stream(this.bytes.buffer, start, length, dict);
  29620. },
  29621. isStream: true
  29622. };
  29623. return Stream;
  29624. })();
  29625. var StringStream = (function StringStreamClosure() {
  29626. function StringStream(str) {
  29627. var length = str.length;
  29628. var bytes = new Uint8Array(length);
  29629. for (var n = 0; n < length; ++n) {
  29630. bytes[n] = str.charCodeAt(n);
  29631. }
  29632. Stream.call(this, bytes);
  29633. }
  29634. StringStream.prototype = Stream.prototype;
  29635. return StringStream;
  29636. })();
  29637. // super class for the decoding streams
  29638. var DecodeStream = (function DecodeStreamClosure() {
  29639. // Lots of DecodeStreams are created whose buffers are never used. For these
  29640. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29641. // having special cases that would be required if we used |null| for an empty
  29642. // buffer.
  29643. var emptyBuffer = new Uint8Array(0);
  29644. function DecodeStream(maybeMinBufferLength) {
  29645. this.pos = 0;
  29646. this.bufferLength = 0;
  29647. this.eof = false;
  29648. this.buffer = emptyBuffer;
  29649. this.minBufferLength = 512;
  29650. if (maybeMinBufferLength) {
  29651. // Compute the first power of two that is as big as maybeMinBufferLength.
  29652. while (this.minBufferLength < maybeMinBufferLength) {
  29653. this.minBufferLength *= 2;
  29654. }
  29655. }
  29656. }
  29657. DecodeStream.prototype = {
  29658. get isEmpty() {
  29659. while (!this.eof && this.bufferLength === 0) {
  29660. this.readBlock();
  29661. }
  29662. return this.bufferLength === 0;
  29663. },
  29664. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29665. var buffer = this.buffer;
  29666. if (requested <= buffer.byteLength) {
  29667. return buffer;
  29668. }
  29669. var size = this.minBufferLength;
  29670. while (size < requested) {
  29671. size *= 2;
  29672. }
  29673. var buffer2 = new Uint8Array(size);
  29674. buffer2.set(buffer);
  29675. return (this.buffer = buffer2);
  29676. },
  29677. getByte: function DecodeStream_getByte() {
  29678. var pos = this.pos;
  29679. while (this.bufferLength <= pos) {
  29680. if (this.eof) {
  29681. return -1;
  29682. }
  29683. this.readBlock();
  29684. }
  29685. return this.buffer[this.pos++];
  29686. },
  29687. getUint16: function DecodeStream_getUint16() {
  29688. var b0 = this.getByte();
  29689. var b1 = this.getByte();
  29690. if (b0 === -1 || b1 === -1) {
  29691. return -1;
  29692. }
  29693. return (b0 << 8) + b1;
  29694. },
  29695. getInt32: function DecodeStream_getInt32() {
  29696. var b0 = this.getByte();
  29697. var b1 = this.getByte();
  29698. var b2 = this.getByte();
  29699. var b3 = this.getByte();
  29700. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29701. },
  29702. getBytes: function DecodeStream_getBytes(length) {
  29703. var end, pos = this.pos;
  29704. if (length) {
  29705. this.ensureBuffer(pos + length);
  29706. end = pos + length;
  29707. while (!this.eof && this.bufferLength < end) {
  29708. this.readBlock();
  29709. }
  29710. var bufEnd = this.bufferLength;
  29711. if (end > bufEnd) {
  29712. end = bufEnd;
  29713. }
  29714. } else {
  29715. while (!this.eof) {
  29716. this.readBlock();
  29717. }
  29718. end = this.bufferLength;
  29719. }
  29720. this.pos = end;
  29721. return this.buffer.subarray(pos, end);
  29722. },
  29723. peekByte: function DecodeStream_peekByte() {
  29724. var peekedByte = this.getByte();
  29725. this.pos--;
  29726. return peekedByte;
  29727. },
  29728. peekBytes: function DecodeStream_peekBytes(length) {
  29729. var bytes = this.getBytes(length);
  29730. this.pos -= bytes.length;
  29731. return bytes;
  29732. },
  29733. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29734. var end = start + length;
  29735. while (this.bufferLength <= end && !this.eof) {
  29736. this.readBlock();
  29737. }
  29738. return new Stream(this.buffer, start, length, dict);
  29739. },
  29740. skip: function DecodeStream_skip(n) {
  29741. if (!n) {
  29742. n = 1;
  29743. }
  29744. this.pos += n;
  29745. },
  29746. reset: function DecodeStream_reset() {
  29747. this.pos = 0;
  29748. },
  29749. getBaseStreams: function DecodeStream_getBaseStreams() {
  29750. if (this.str && this.str.getBaseStreams) {
  29751. return this.str.getBaseStreams();
  29752. }
  29753. return [];
  29754. }
  29755. };
  29756. return DecodeStream;
  29757. })();
  29758. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29759. function StreamsSequenceStream(streams) {
  29760. this.streams = streams;
  29761. DecodeStream.call(this, /* maybeLength = */ null);
  29762. }
  29763. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29764. StreamsSequenceStream.prototype.readBlock =
  29765. function streamSequenceStreamReadBlock() {
  29766. var streams = this.streams;
  29767. if (streams.length === 0) {
  29768. this.eof = true;
  29769. return;
  29770. }
  29771. var stream = streams.shift();
  29772. var chunk = stream.getBytes();
  29773. var bufferLength = this.bufferLength;
  29774. var newLength = bufferLength + chunk.length;
  29775. var buffer = this.ensureBuffer(newLength);
  29776. buffer.set(chunk, bufferLength);
  29777. this.bufferLength = newLength;
  29778. };
  29779. StreamsSequenceStream.prototype.getBaseStreams =
  29780. function StreamsSequenceStream_getBaseStreams() {
  29781. var baseStreams = [];
  29782. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29783. var stream = this.streams[i];
  29784. if (stream.getBaseStreams) {
  29785. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29786. }
  29787. }
  29788. return baseStreams;
  29789. };
  29790. return StreamsSequenceStream;
  29791. })();
  29792. var FlateStream = (function FlateStreamClosure() {
  29793. var codeLenCodeMap = new Int32Array([
  29794. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29795. ]);
  29796. var lengthDecode = new Int32Array([
  29797. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29798. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29799. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29800. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29801. ]);
  29802. var distDecode = new Int32Array([
  29803. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29804. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29805. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29806. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29807. ]);
  29808. var fixedLitCodeTab = [new Int32Array([
  29809. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29810. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29811. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29812. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29813. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29814. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29815. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29816. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29817. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29818. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29819. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29820. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29821. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29822. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29823. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29824. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29825. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29826. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29827. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29828. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29829. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29830. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29831. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29832. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29833. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29834. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29835. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29836. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29837. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29838. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29839. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29840. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29841. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29842. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29843. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29844. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29845. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29846. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29847. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29848. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29849. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29850. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29851. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29852. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29853. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29854. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29855. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29856. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29857. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29858. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29859. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29860. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29861. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29862. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29863. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29864. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29865. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29866. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29867. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29868. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29869. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29870. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29871. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29872. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29873. ]), 9];
  29874. var fixedDistCodeTab = [new Int32Array([
  29875. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29876. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29877. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29878. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29879. ]), 5];
  29880. function FlateStream(str, maybeLength) {
  29881. this.str = str;
  29882. this.dict = str.dict;
  29883. var cmf = str.getByte();
  29884. var flg = str.getByte();
  29885. if (cmf === -1 || flg === -1) {
  29886. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29887. }
  29888. if ((cmf & 0x0f) !== 0x08) {
  29889. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29890. }
  29891. if ((((cmf << 8) + flg) % 31) !== 0) {
  29892. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29893. }
  29894. if (flg & 0x20) {
  29895. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29896. }
  29897. this.codeSize = 0;
  29898. this.codeBuf = 0;
  29899. DecodeStream.call(this, maybeLength);
  29900. }
  29901. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29902. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29903. var str = this.str;
  29904. var codeSize = this.codeSize;
  29905. var codeBuf = this.codeBuf;
  29906. var b;
  29907. while (codeSize < bits) {
  29908. if ((b = str.getByte()) === -1) {
  29909. error('Bad encoding in flate stream');
  29910. }
  29911. codeBuf |= b << codeSize;
  29912. codeSize += 8;
  29913. }
  29914. b = codeBuf & ((1 << bits) - 1);
  29915. this.codeBuf = codeBuf >> bits;
  29916. this.codeSize = codeSize -= bits;
  29917. return b;
  29918. };
  29919. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29920. var str = this.str;
  29921. var codes = table[0];
  29922. var maxLen = table[1];
  29923. var codeSize = this.codeSize;
  29924. var codeBuf = this.codeBuf;
  29925. var b;
  29926. while (codeSize < maxLen) {
  29927. if ((b = str.getByte()) === -1) {
  29928. // premature end of stream. code might however still be valid.
  29929. // codeSize < codeLen check below guards against incomplete codeVal.
  29930. break;
  29931. }
  29932. codeBuf |= (b << codeSize);
  29933. codeSize += 8;
  29934. }
  29935. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29936. var codeLen = code >> 16;
  29937. var codeVal = code & 0xffff;
  29938. if (codeLen < 1 || codeSize < codeLen) {
  29939. error('Bad encoding in flate stream');
  29940. }
  29941. this.codeBuf = (codeBuf >> codeLen);
  29942. this.codeSize = (codeSize - codeLen);
  29943. return codeVal;
  29944. };
  29945. FlateStream.prototype.generateHuffmanTable =
  29946. function flateStreamGenerateHuffmanTable(lengths) {
  29947. var n = lengths.length;
  29948. // find max code length
  29949. var maxLen = 0;
  29950. var i;
  29951. for (i = 0; i < n; ++i) {
  29952. if (lengths[i] > maxLen) {
  29953. maxLen = lengths[i];
  29954. }
  29955. }
  29956. // build the table
  29957. var size = 1 << maxLen;
  29958. var codes = new Int32Array(size);
  29959. for (var len = 1, code = 0, skip = 2;
  29960. len <= maxLen;
  29961. ++len, code <<= 1, skip <<= 1) {
  29962. for (var val = 0; val < n; ++val) {
  29963. if (lengths[val] === len) {
  29964. // bit-reverse the code
  29965. var code2 = 0;
  29966. var t = code;
  29967. for (i = 0; i < len; ++i) {
  29968. code2 = (code2 << 1) | (t & 1);
  29969. t >>= 1;
  29970. }
  29971. // fill the table entries
  29972. for (i = code2; i < size; i += skip) {
  29973. codes[i] = (len << 16) | val;
  29974. }
  29975. ++code;
  29976. }
  29977. }
  29978. }
  29979. return [codes, maxLen];
  29980. };
  29981. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29982. var buffer, len;
  29983. var str = this.str;
  29984. // read block header
  29985. var hdr = this.getBits(3);
  29986. if (hdr & 1) {
  29987. this.eof = true;
  29988. }
  29989. hdr >>= 1;
  29990. if (hdr === 0) { // uncompressed block
  29991. var b;
  29992. if ((b = str.getByte()) === -1) {
  29993. error('Bad block header in flate stream');
  29994. }
  29995. var blockLen = b;
  29996. if ((b = str.getByte()) === -1) {
  29997. error('Bad block header in flate stream');
  29998. }
  29999. blockLen |= (b << 8);
  30000. if ((b = str.getByte()) === -1) {
  30001. error('Bad block header in flate stream');
  30002. }
  30003. var check = b;
  30004. if ((b = str.getByte()) === -1) {
  30005. error('Bad block header in flate stream');
  30006. }
  30007. check |= (b << 8);
  30008. if (check !== (~blockLen & 0xffff) &&
  30009. (blockLen !== 0 || check !== 0)) {
  30010. // Ignoring error for bad "empty" block (see issue 1277)
  30011. error('Bad uncompressed block length in flate stream');
  30012. }
  30013. this.codeBuf = 0;
  30014. this.codeSize = 0;
  30015. var bufferLength = this.bufferLength;
  30016. buffer = this.ensureBuffer(bufferLength + blockLen);
  30017. var end = bufferLength + blockLen;
  30018. this.bufferLength = end;
  30019. if (blockLen === 0) {
  30020. if (str.peekByte() === -1) {
  30021. this.eof = true;
  30022. }
  30023. } else {
  30024. for (var n = bufferLength; n < end; ++n) {
  30025. if ((b = str.getByte()) === -1) {
  30026. this.eof = true;
  30027. break;
  30028. }
  30029. buffer[n] = b;
  30030. }
  30031. }
  30032. return;
  30033. }
  30034. var litCodeTable;
  30035. var distCodeTable;
  30036. if (hdr === 1) { // compressed block, fixed codes
  30037. litCodeTable = fixedLitCodeTab;
  30038. distCodeTable = fixedDistCodeTab;
  30039. } else if (hdr === 2) { // compressed block, dynamic codes
  30040. var numLitCodes = this.getBits(5) + 257;
  30041. var numDistCodes = this.getBits(5) + 1;
  30042. var numCodeLenCodes = this.getBits(4) + 4;
  30043. // build the code lengths code table
  30044. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30045. var i;
  30046. for (i = 0; i < numCodeLenCodes; ++i) {
  30047. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30048. }
  30049. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30050. // build the literal and distance code tables
  30051. len = 0;
  30052. i = 0;
  30053. var codes = numLitCodes + numDistCodes;
  30054. var codeLengths = new Uint8Array(codes);
  30055. var bitsLength, bitsOffset, what;
  30056. while (i < codes) {
  30057. var code = this.getCode(codeLenCodeTab);
  30058. if (code === 16) {
  30059. bitsLength = 2; bitsOffset = 3; what = len;
  30060. } else if (code === 17) {
  30061. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30062. } else if (code === 18) {
  30063. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30064. } else {
  30065. codeLengths[i++] = len = code;
  30066. continue;
  30067. }
  30068. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30069. while (repeatLength-- > 0) {
  30070. codeLengths[i++] = what;
  30071. }
  30072. }
  30073. litCodeTable =
  30074. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30075. distCodeTable =
  30076. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30077. } else {
  30078. error('Unknown block type in flate stream');
  30079. }
  30080. buffer = this.buffer;
  30081. var limit = buffer ? buffer.length : 0;
  30082. var pos = this.bufferLength;
  30083. while (true) {
  30084. var code1 = this.getCode(litCodeTable);
  30085. if (code1 < 256) {
  30086. if (pos + 1 >= limit) {
  30087. buffer = this.ensureBuffer(pos + 1);
  30088. limit = buffer.length;
  30089. }
  30090. buffer[pos++] = code1;
  30091. continue;
  30092. }
  30093. if (code1 === 256) {
  30094. this.bufferLength = pos;
  30095. return;
  30096. }
  30097. code1 -= 257;
  30098. code1 = lengthDecode[code1];
  30099. var code2 = code1 >> 16;
  30100. if (code2 > 0) {
  30101. code2 = this.getBits(code2);
  30102. }
  30103. len = (code1 & 0xffff) + code2;
  30104. code1 = this.getCode(distCodeTable);
  30105. code1 = distDecode[code1];
  30106. code2 = code1 >> 16;
  30107. if (code2 > 0) {
  30108. code2 = this.getBits(code2);
  30109. }
  30110. var dist = (code1 & 0xffff) + code2;
  30111. if (pos + len >= limit) {
  30112. buffer = this.ensureBuffer(pos + len);
  30113. limit = buffer.length;
  30114. }
  30115. for (var k = 0; k < len; ++k, ++pos) {
  30116. buffer[pos] = buffer[pos - dist];
  30117. }
  30118. }
  30119. };
  30120. return FlateStream;
  30121. })();
  30122. var PredictorStream = (function PredictorStreamClosure() {
  30123. function PredictorStream(str, maybeLength, params) {
  30124. var predictor = this.predictor = params.get('Predictor') || 1;
  30125. if (predictor <= 1) {
  30126. return str; // no prediction
  30127. }
  30128. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30129. error('Unsupported predictor: ' + predictor);
  30130. }
  30131. if (predictor === 2) {
  30132. this.readBlock = this.readBlockTiff;
  30133. } else {
  30134. this.readBlock = this.readBlockPng;
  30135. }
  30136. this.str = str;
  30137. this.dict = str.dict;
  30138. var colors = this.colors = params.get('Colors') || 1;
  30139. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30140. var columns = this.columns = params.get('Columns') || 1;
  30141. this.pixBytes = (colors * bits + 7) >> 3;
  30142. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30143. DecodeStream.call(this, maybeLength);
  30144. return this;
  30145. }
  30146. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30147. PredictorStream.prototype.readBlockTiff =
  30148. function predictorStreamReadBlockTiff() {
  30149. var rowBytes = this.rowBytes;
  30150. var bufferLength = this.bufferLength;
  30151. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30152. var bits = this.bits;
  30153. var colors = this.colors;
  30154. var rawBytes = this.str.getBytes(rowBytes);
  30155. this.eof = !rawBytes.length;
  30156. if (this.eof) {
  30157. return;
  30158. }
  30159. var inbuf = 0, outbuf = 0;
  30160. var inbits = 0, outbits = 0;
  30161. var pos = bufferLength;
  30162. var i;
  30163. if (bits === 1) {
  30164. for (i = 0; i < rowBytes; ++i) {
  30165. var c = rawBytes[i];
  30166. inbuf = (inbuf << 8) | c;
  30167. // bitwise addition is exclusive or
  30168. // first shift inbuf and then add
  30169. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30170. // truncate inbuf (assumes colors < 16)
  30171. inbuf &= 0xFFFF;
  30172. }
  30173. } else if (bits === 8) {
  30174. for (i = 0; i < colors; ++i) {
  30175. buffer[pos++] = rawBytes[i];
  30176. }
  30177. for (; i < rowBytes; ++i) {
  30178. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30179. pos++;
  30180. }
  30181. } else {
  30182. var compArray = new Uint8Array(colors + 1);
  30183. var bitMask = (1 << bits) - 1;
  30184. var j = 0, k = bufferLength;
  30185. var columns = this.columns;
  30186. for (i = 0; i < columns; ++i) {
  30187. for (var kk = 0; kk < colors; ++kk) {
  30188. if (inbits < bits) {
  30189. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30190. inbits += 8;
  30191. }
  30192. compArray[kk] = (compArray[kk] +
  30193. (inbuf >> (inbits - bits))) & bitMask;
  30194. inbits -= bits;
  30195. outbuf = (outbuf << bits) | compArray[kk];
  30196. outbits += bits;
  30197. if (outbits >= 8) {
  30198. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30199. outbits -= 8;
  30200. }
  30201. }
  30202. }
  30203. if (outbits > 0) {
  30204. buffer[k++] = (outbuf << (8 - outbits)) +
  30205. (inbuf & ((1 << (8 - outbits)) - 1));
  30206. }
  30207. }
  30208. this.bufferLength += rowBytes;
  30209. };
  30210. PredictorStream.prototype.readBlockPng =
  30211. function predictorStreamReadBlockPng() {
  30212. var rowBytes = this.rowBytes;
  30213. var pixBytes = this.pixBytes;
  30214. var predictor = this.str.getByte();
  30215. var rawBytes = this.str.getBytes(rowBytes);
  30216. this.eof = !rawBytes.length;
  30217. if (this.eof) {
  30218. return;
  30219. }
  30220. var bufferLength = this.bufferLength;
  30221. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30222. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30223. if (prevRow.length === 0) {
  30224. prevRow = new Uint8Array(rowBytes);
  30225. }
  30226. var i, j = bufferLength, up, c;
  30227. switch (predictor) {
  30228. case 0:
  30229. for (i = 0; i < rowBytes; ++i) {
  30230. buffer[j++] = rawBytes[i];
  30231. }
  30232. break;
  30233. case 1:
  30234. for (i = 0; i < pixBytes; ++i) {
  30235. buffer[j++] = rawBytes[i];
  30236. }
  30237. for (; i < rowBytes; ++i) {
  30238. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30239. j++;
  30240. }
  30241. break;
  30242. case 2:
  30243. for (i = 0; i < rowBytes; ++i) {
  30244. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30245. }
  30246. break;
  30247. case 3:
  30248. for (i = 0; i < pixBytes; ++i) {
  30249. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30250. }
  30251. for (; i < rowBytes; ++i) {
  30252. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30253. rawBytes[i]) & 0xFF;
  30254. j++;
  30255. }
  30256. break;
  30257. case 4:
  30258. // we need to save the up left pixels values. the simplest way
  30259. // is to create a new buffer
  30260. for (i = 0; i < pixBytes; ++i) {
  30261. up = prevRow[i];
  30262. c = rawBytes[i];
  30263. buffer[j++] = up + c;
  30264. }
  30265. for (; i < rowBytes; ++i) {
  30266. up = prevRow[i];
  30267. var upLeft = prevRow[i - pixBytes];
  30268. var left = buffer[j - pixBytes];
  30269. var p = left + up - upLeft;
  30270. var pa = p - left;
  30271. if (pa < 0) {
  30272. pa = -pa;
  30273. }
  30274. var pb = p - up;
  30275. if (pb < 0) {
  30276. pb = -pb;
  30277. }
  30278. var pc = p - upLeft;
  30279. if (pc < 0) {
  30280. pc = -pc;
  30281. }
  30282. c = rawBytes[i];
  30283. if (pa <= pb && pa <= pc) {
  30284. buffer[j++] = left + c;
  30285. } else if (pb <= pc) {
  30286. buffer[j++] = up + c;
  30287. } else {
  30288. buffer[j++] = upLeft + c;
  30289. }
  30290. }
  30291. break;
  30292. default:
  30293. error('Unsupported predictor: ' + predictor);
  30294. }
  30295. this.bufferLength += rowBytes;
  30296. };
  30297. return PredictorStream;
  30298. })();
  30299. /**
  30300. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30301. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30302. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30303. * a library to decode these images and the stream behaves like all the other
  30304. * DecodeStreams.
  30305. */
  30306. var JpegStream = (function JpegStreamClosure() {
  30307. function JpegStream(stream, maybeLength, dict, xref) {
  30308. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30309. // Note: this seems to mainly affect inline images.
  30310. var ch;
  30311. while ((ch = stream.getByte()) !== -1) {
  30312. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30313. stream.skip(-1); // Reset the stream position to the SOI.
  30314. break;
  30315. }
  30316. }
  30317. this.stream = stream;
  30318. this.maybeLength = maybeLength;
  30319. this.dict = dict;
  30320. DecodeStream.call(this, maybeLength);
  30321. }
  30322. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30323. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30324. get: function JpegStream_bytes() {
  30325. // If this.maybeLength is null, we'll get the entire stream.
  30326. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30327. },
  30328. configurable: true
  30329. });
  30330. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30331. if (this.bufferLength) {
  30332. return;
  30333. }
  30334. try {
  30335. var jpegImage = new JpegImage();
  30336. // checking if values needs to be transformed before conversion
  30337. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30338. var decodeArr = this.dict.get('Decode');
  30339. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30340. var decodeArrLength = decodeArr.length;
  30341. var transform = new Int32Array(decodeArrLength);
  30342. var transformNeeded = false;
  30343. var maxValue = (1 << bitsPerComponent) - 1;
  30344. for (var i = 0; i < decodeArrLength; i += 2) {
  30345. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30346. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30347. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30348. transformNeeded = true;
  30349. }
  30350. }
  30351. if (transformNeeded) {
  30352. jpegImage.decodeTransform = transform;
  30353. }
  30354. }
  30355. jpegImage.parse(this.bytes);
  30356. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30357. this.forceRGB);
  30358. this.buffer = data;
  30359. this.bufferLength = data.length;
  30360. this.eof = true;
  30361. } catch (e) {
  30362. error('JPEG error: ' + e);
  30363. }
  30364. };
  30365. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30366. this.ensureBuffer();
  30367. return this.buffer;
  30368. };
  30369. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30370. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30371. };
  30372. /**
  30373. * Checks if the image can be decoded and displayed by the browser without any
  30374. * further processing such as color space conversions.
  30375. */
  30376. JpegStream.prototype.isNativelySupported =
  30377. function JpegStream_isNativelySupported(xref, res) {
  30378. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30379. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30380. };
  30381. /**
  30382. * Checks if the image can be decoded by the browser.
  30383. */
  30384. JpegStream.prototype.isNativelyDecodable =
  30385. function JpegStream_isNativelyDecodable(xref, res) {
  30386. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30387. var numComps = cs.numComps;
  30388. return numComps === 1 || numComps === 3;
  30389. };
  30390. return JpegStream;
  30391. })();
  30392. /**
  30393. * For JPEG 2000's we use a library to decode these images and
  30394. * the stream behaves like all the other DecodeStreams.
  30395. */
  30396. var JpxStream = (function JpxStreamClosure() {
  30397. function JpxStream(stream, maybeLength, dict) {
  30398. this.stream = stream;
  30399. this.maybeLength = maybeLength;
  30400. this.dict = dict;
  30401. DecodeStream.call(this, maybeLength);
  30402. }
  30403. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30404. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30405. get: function JpxStream_bytes() {
  30406. // If this.maybeLength is null, we'll get the entire stream.
  30407. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30408. },
  30409. configurable: true
  30410. });
  30411. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30412. if (this.bufferLength) {
  30413. return;
  30414. }
  30415. var jpxImage = new JpxImage();
  30416. jpxImage.parse(this.bytes);
  30417. var width = jpxImage.width;
  30418. var height = jpxImage.height;
  30419. var componentsCount = jpxImage.componentsCount;
  30420. var tileCount = jpxImage.tiles.length;
  30421. if (tileCount === 1) {
  30422. this.buffer = jpxImage.tiles[0].items;
  30423. } else {
  30424. var data = new Uint8Array(width * height * componentsCount);
  30425. for (var k = 0; k < tileCount; k++) {
  30426. var tileComponents = jpxImage.tiles[k];
  30427. var tileWidth = tileComponents.width;
  30428. var tileHeight = tileComponents.height;
  30429. var tileLeft = tileComponents.left;
  30430. var tileTop = tileComponents.top;
  30431. var src = tileComponents.items;
  30432. var srcPosition = 0;
  30433. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30434. var imgRowSize = width * componentsCount;
  30435. var tileRowSize = tileWidth * componentsCount;
  30436. for (var j = 0; j < tileHeight; j++) {
  30437. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30438. data.set(rowBytes, dataPosition);
  30439. srcPosition += tileRowSize;
  30440. dataPosition += imgRowSize;
  30441. }
  30442. }
  30443. this.buffer = data;
  30444. }
  30445. this.bufferLength = this.buffer.length;
  30446. this.eof = true;
  30447. };
  30448. return JpxStream;
  30449. })();
  30450. /**
  30451. * For JBIG2's we use a library to decode these images and
  30452. * the stream behaves like all the other DecodeStreams.
  30453. */
  30454. var Jbig2Stream = (function Jbig2StreamClosure() {
  30455. function Jbig2Stream(stream, maybeLength, dict) {
  30456. this.stream = stream;
  30457. this.maybeLength = maybeLength;
  30458. this.dict = dict;
  30459. DecodeStream.call(this, maybeLength);
  30460. }
  30461. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30462. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30463. get: function Jbig2Stream_bytes() {
  30464. // If this.maybeLength is null, we'll get the entire stream.
  30465. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30466. },
  30467. configurable: true
  30468. });
  30469. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30470. if (this.bufferLength) {
  30471. return;
  30472. }
  30473. var jbig2Image = new Jbig2Image();
  30474. var chunks = [], xref = this.dict.xref;
  30475. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30476. // According to the PDF specification, DecodeParms can be either
  30477. // a dictionary, or an array whose elements are dictionaries.
  30478. if (isArray(decodeParams)) {
  30479. if (decodeParams.length > 1) {
  30480. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30481. 'not supported.');
  30482. }
  30483. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30484. }
  30485. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30486. var globalsStream = decodeParams.get('JBIG2Globals');
  30487. var globals = globalsStream.getBytes();
  30488. chunks.push({data: globals, start: 0, end: globals.length});
  30489. }
  30490. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30491. var data = jbig2Image.parseChunks(chunks);
  30492. var dataLength = data.length;
  30493. // JBIG2 had black as 1 and white as 0, inverting the colors
  30494. for (var i = 0; i < dataLength; i++) {
  30495. data[i] ^= 0xFF;
  30496. }
  30497. this.buffer = data;
  30498. this.bufferLength = dataLength;
  30499. this.eof = true;
  30500. };
  30501. return Jbig2Stream;
  30502. })();
  30503. var DecryptStream = (function DecryptStreamClosure() {
  30504. function DecryptStream(str, maybeLength, decrypt) {
  30505. this.str = str;
  30506. this.dict = str.dict;
  30507. this.decrypt = decrypt;
  30508. this.nextChunk = null;
  30509. this.initialized = false;
  30510. DecodeStream.call(this, maybeLength);
  30511. }
  30512. var chunkSize = 512;
  30513. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30514. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30515. var chunk;
  30516. if (this.initialized) {
  30517. chunk = this.nextChunk;
  30518. } else {
  30519. chunk = this.str.getBytes(chunkSize);
  30520. this.initialized = true;
  30521. }
  30522. if (!chunk || chunk.length === 0) {
  30523. this.eof = true;
  30524. return;
  30525. }
  30526. this.nextChunk = this.str.getBytes(chunkSize);
  30527. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30528. var decrypt = this.decrypt;
  30529. chunk = decrypt(chunk, !hasMoreData);
  30530. var bufferLength = this.bufferLength;
  30531. var i, n = chunk.length;
  30532. var buffer = this.ensureBuffer(bufferLength + n);
  30533. for (i = 0; i < n; i++) {
  30534. buffer[bufferLength++] = chunk[i];
  30535. }
  30536. this.bufferLength = bufferLength;
  30537. };
  30538. return DecryptStream;
  30539. })();
  30540. var Ascii85Stream = (function Ascii85StreamClosure() {
  30541. function Ascii85Stream(str, maybeLength) {
  30542. this.str = str;
  30543. this.dict = str.dict;
  30544. this.input = new Uint8Array(5);
  30545. // Most streams increase in size when decoded, but Ascii85 streams
  30546. // typically shrink by ~20%.
  30547. if (maybeLength) {
  30548. maybeLength = 0.8 * maybeLength;
  30549. }
  30550. DecodeStream.call(this, maybeLength);
  30551. }
  30552. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30553. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30554. var TILDA_CHAR = 0x7E; // '~'
  30555. var Z_LOWER_CHAR = 0x7A; // 'z'
  30556. var EOF = -1;
  30557. var str = this.str;
  30558. var c = str.getByte();
  30559. while (Lexer.isSpace(c)) {
  30560. c = str.getByte();
  30561. }
  30562. if (c === EOF || c === TILDA_CHAR) {
  30563. this.eof = true;
  30564. return;
  30565. }
  30566. var bufferLength = this.bufferLength, buffer;
  30567. var i;
  30568. // special code for z
  30569. if (c === Z_LOWER_CHAR) {
  30570. buffer = this.ensureBuffer(bufferLength + 4);
  30571. for (i = 0; i < 4; ++i) {
  30572. buffer[bufferLength + i] = 0;
  30573. }
  30574. this.bufferLength += 4;
  30575. } else {
  30576. var input = this.input;
  30577. input[0] = c;
  30578. for (i = 1; i < 5; ++i) {
  30579. c = str.getByte();
  30580. while (Lexer.isSpace(c)) {
  30581. c = str.getByte();
  30582. }
  30583. input[i] = c;
  30584. if (c === EOF || c === TILDA_CHAR) {
  30585. break;
  30586. }
  30587. }
  30588. buffer = this.ensureBuffer(bufferLength + i - 1);
  30589. this.bufferLength += i - 1;
  30590. // partial ending;
  30591. if (i < 5) {
  30592. for (; i < 5; ++i) {
  30593. input[i] = 0x21 + 84;
  30594. }
  30595. this.eof = true;
  30596. }
  30597. var t = 0;
  30598. for (i = 0; i < 5; ++i) {
  30599. t = t * 85 + (input[i] - 0x21);
  30600. }
  30601. for (i = 3; i >= 0; --i) {
  30602. buffer[bufferLength + i] = t & 0xFF;
  30603. t >>= 8;
  30604. }
  30605. }
  30606. };
  30607. return Ascii85Stream;
  30608. })();
  30609. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30610. function AsciiHexStream(str, maybeLength) {
  30611. this.str = str;
  30612. this.dict = str.dict;
  30613. this.firstDigit = -1;
  30614. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30615. // by 50%.
  30616. if (maybeLength) {
  30617. maybeLength = 0.5 * maybeLength;
  30618. }
  30619. DecodeStream.call(this, maybeLength);
  30620. }
  30621. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30622. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30623. var UPSTREAM_BLOCK_SIZE = 8000;
  30624. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30625. if (!bytes.length) {
  30626. this.eof = true;
  30627. return;
  30628. }
  30629. var maxDecodeLength = (bytes.length + 1) >> 1;
  30630. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30631. var bufferLength = this.bufferLength;
  30632. var firstDigit = this.firstDigit;
  30633. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30634. var ch = bytes[i], digit;
  30635. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30636. digit = ch & 0x0F;
  30637. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30638. // 'A'-'Z', 'a'-'z'
  30639. digit = (ch & 0x0F) + 9;
  30640. } else if (ch === 0x3E) { // '>'
  30641. this.eof = true;
  30642. break;
  30643. } else { // probably whitespace
  30644. continue; // ignoring
  30645. }
  30646. if (firstDigit < 0) {
  30647. firstDigit = digit;
  30648. } else {
  30649. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30650. firstDigit = -1;
  30651. }
  30652. }
  30653. if (firstDigit >= 0 && this.eof) {
  30654. // incomplete byte
  30655. buffer[bufferLength++] = (firstDigit << 4);
  30656. firstDigit = -1;
  30657. }
  30658. this.firstDigit = firstDigit;
  30659. this.bufferLength = bufferLength;
  30660. };
  30661. return AsciiHexStream;
  30662. })();
  30663. var RunLengthStream = (function RunLengthStreamClosure() {
  30664. function RunLengthStream(str, maybeLength) {
  30665. this.str = str;
  30666. this.dict = str.dict;
  30667. DecodeStream.call(this, maybeLength);
  30668. }
  30669. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30670. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30671. // The repeatHeader has following format. The first byte defines type of run
  30672. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30673. // (in addition to the second byte from the header), n = 129 through 255 -
  30674. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30675. var repeatHeader = this.str.getBytes(2);
  30676. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30677. this.eof = true;
  30678. return;
  30679. }
  30680. var buffer;
  30681. var bufferLength = this.bufferLength;
  30682. var n = repeatHeader[0];
  30683. if (n < 128) {
  30684. // copy n bytes
  30685. buffer = this.ensureBuffer(bufferLength + n + 1);
  30686. buffer[bufferLength++] = repeatHeader[1];
  30687. if (n > 0) {
  30688. var source = this.str.getBytes(n);
  30689. buffer.set(source, bufferLength);
  30690. bufferLength += n;
  30691. }
  30692. } else {
  30693. n = 257 - n;
  30694. var b = repeatHeader[1];
  30695. buffer = this.ensureBuffer(bufferLength + n + 1);
  30696. for (var i = 0; i < n; i++) {
  30697. buffer[bufferLength++] = b;
  30698. }
  30699. }
  30700. this.bufferLength = bufferLength;
  30701. };
  30702. return RunLengthStream;
  30703. })();
  30704. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30705. var ccittEOL = -2;
  30706. var twoDimPass = 0;
  30707. var twoDimHoriz = 1;
  30708. var twoDimVert0 = 2;
  30709. var twoDimVertR1 = 3;
  30710. var twoDimVertL1 = 4;
  30711. var twoDimVertR2 = 5;
  30712. var twoDimVertL2 = 6;
  30713. var twoDimVertR3 = 7;
  30714. var twoDimVertL3 = 8;
  30715. var twoDimTable = [
  30716. [-1, -1], [-1, -1], // 000000x
  30717. [7, twoDimVertL3], // 0000010
  30718. [7, twoDimVertR3], // 0000011
  30719. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30720. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30721. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30722. [4, twoDimPass], [4, twoDimPass],
  30723. [4, twoDimPass], [4, twoDimPass],
  30724. [4, twoDimPass], [4, twoDimPass],
  30725. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30726. [3, twoDimHoriz], [3, twoDimHoriz],
  30727. [3, twoDimHoriz], [3, twoDimHoriz],
  30728. [3, twoDimHoriz], [3, twoDimHoriz],
  30729. [3, twoDimHoriz], [3, twoDimHoriz],
  30730. [3, twoDimHoriz], [3, twoDimHoriz],
  30731. [3, twoDimHoriz], [3, twoDimHoriz],
  30732. [3, twoDimHoriz], [3, twoDimHoriz],
  30733. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30734. [3, twoDimVertL1], [3, twoDimVertL1],
  30735. [3, twoDimVertL1], [3, twoDimVertL1],
  30736. [3, twoDimVertL1], [3, twoDimVertL1],
  30737. [3, twoDimVertL1], [3, twoDimVertL1],
  30738. [3, twoDimVertL1], [3, twoDimVertL1],
  30739. [3, twoDimVertL1], [3, twoDimVertL1],
  30740. [3, twoDimVertL1], [3, twoDimVertL1],
  30741. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30742. [3, twoDimVertR1], [3, twoDimVertR1],
  30743. [3, twoDimVertR1], [3, twoDimVertR1],
  30744. [3, twoDimVertR1], [3, twoDimVertR1],
  30745. [3, twoDimVertR1], [3, twoDimVertR1],
  30746. [3, twoDimVertR1], [3, twoDimVertR1],
  30747. [3, twoDimVertR1], [3, twoDimVertR1],
  30748. [3, twoDimVertR1], [3, twoDimVertR1],
  30749. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30750. [1, twoDimVert0], [1, twoDimVert0],
  30751. [1, twoDimVert0], [1, twoDimVert0],
  30752. [1, twoDimVert0], [1, twoDimVert0],
  30753. [1, twoDimVert0], [1, twoDimVert0],
  30754. [1, twoDimVert0], [1, twoDimVert0],
  30755. [1, twoDimVert0], [1, twoDimVert0],
  30756. [1, twoDimVert0], [1, twoDimVert0],
  30757. [1, twoDimVert0], [1, twoDimVert0],
  30758. [1, twoDimVert0], [1, twoDimVert0],
  30759. [1, twoDimVert0], [1, twoDimVert0],
  30760. [1, twoDimVert0], [1, twoDimVert0],
  30761. [1, twoDimVert0], [1, twoDimVert0],
  30762. [1, twoDimVert0], [1, twoDimVert0],
  30763. [1, twoDimVert0], [1, twoDimVert0],
  30764. [1, twoDimVert0], [1, twoDimVert0],
  30765. [1, twoDimVert0], [1, twoDimVert0],
  30766. [1, twoDimVert0], [1, twoDimVert0],
  30767. [1, twoDimVert0], [1, twoDimVert0],
  30768. [1, twoDimVert0], [1, twoDimVert0],
  30769. [1, twoDimVert0], [1, twoDimVert0],
  30770. [1, twoDimVert0], [1, twoDimVert0],
  30771. [1, twoDimVert0], [1, twoDimVert0],
  30772. [1, twoDimVert0], [1, twoDimVert0],
  30773. [1, twoDimVert0], [1, twoDimVert0],
  30774. [1, twoDimVert0], [1, twoDimVert0],
  30775. [1, twoDimVert0], [1, twoDimVert0],
  30776. [1, twoDimVert0], [1, twoDimVert0],
  30777. [1, twoDimVert0], [1, twoDimVert0],
  30778. [1, twoDimVert0], [1, twoDimVert0],
  30779. [1, twoDimVert0], [1, twoDimVert0],
  30780. [1, twoDimVert0], [1, twoDimVert0]
  30781. ];
  30782. var whiteTable1 = [
  30783. [-1, -1], // 00000
  30784. [12, ccittEOL], // 00001
  30785. [-1, -1], [-1, -1], // 0001x
  30786. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30787. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30788. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30789. [11, 1792], [11, 1792], // 1000x
  30790. [12, 1984], // 10010
  30791. [12, 2048], // 10011
  30792. [12, 2112], // 10100
  30793. [12, 2176], // 10101
  30794. [12, 2240], // 10110
  30795. [12, 2304], // 10111
  30796. [11, 1856], [11, 1856], // 1100x
  30797. [11, 1920], [11, 1920], // 1101x
  30798. [12, 2368], // 11100
  30799. [12, 2432], // 11101
  30800. [12, 2496], // 11110
  30801. [12, 2560] // 11111
  30802. ];
  30803. var whiteTable2 = [
  30804. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30805. [8, 29], [8, 29], // 00000010x
  30806. [8, 30], [8, 30], // 00000011x
  30807. [8, 45], [8, 45], // 00000100x
  30808. [8, 46], [8, 46], // 00000101x
  30809. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30810. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30811. [8, 47], [8, 47], // 00001010x
  30812. [8, 48], [8, 48], // 00001011x
  30813. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30814. [6, 13], [6, 13], [6, 13], [6, 13],
  30815. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30816. [8, 33], [8, 33], // 00010010x
  30817. [8, 34], [8, 34], // 00010011x
  30818. [8, 35], [8, 35], // 00010100x
  30819. [8, 36], [8, 36], // 00010101x
  30820. [8, 37], [8, 37], // 00010110x
  30821. [8, 38], [8, 38], // 00010111x
  30822. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30823. [8, 31], [8, 31], // 00011010x
  30824. [8, 32], [8, 32], // 00011011x
  30825. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30826. [6, 1], [6, 1], [6, 1], [6, 1],
  30827. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30828. [6, 12], [6, 12], [6, 12], [6, 12],
  30829. [8, 53], [8, 53], // 00100100x
  30830. [8, 54], [8, 54], // 00100101x
  30831. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30832. [8, 39], [8, 39], // 00101000x
  30833. [8, 40], [8, 40], // 00101001x
  30834. [8, 41], [8, 41], // 00101010x
  30835. [8, 42], [8, 42], // 00101011x
  30836. [8, 43], [8, 43], // 00101100x
  30837. [8, 44], [8, 44], // 00101101x
  30838. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30839. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30840. [8, 61], [8, 61], // 00110010x
  30841. [8, 62], [8, 62], // 00110011x
  30842. [8, 63], [8, 63], // 00110100x
  30843. [8, 0], [8, 0], // 00110101x
  30844. [8, 320], [8, 320], // 00110110x
  30845. [8, 384], [8, 384], // 00110111x
  30846. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30847. [5, 10], [5, 10], [5, 10], [5, 10],
  30848. [5, 10], [5, 10], [5, 10], [5, 10],
  30849. [5, 10], [5, 10], [5, 10], [5, 10],
  30850. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30851. [5, 11], [5, 11], [5, 11], [5, 11],
  30852. [5, 11], [5, 11], [5, 11], [5, 11],
  30853. [5, 11], [5, 11], [5, 11], [5, 11],
  30854. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30855. [8, 59], [8, 59], // 01001010x
  30856. [8, 60], [8, 60], // 01001011x
  30857. [9, 1472], // 010011000
  30858. [9, 1536], // 010011001
  30859. [9, 1600], // 010011010
  30860. [9, 1728], // 010011011
  30861. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30862. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30863. [8, 49], [8, 49], // 01010010x
  30864. [8, 50], [8, 50], // 01010011x
  30865. [8, 51], [8, 51], // 01010100x
  30866. [8, 52], [8, 52], // 01010101x
  30867. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30868. [8, 55], [8, 55], // 01011000x
  30869. [8, 56], [8, 56], // 01011001x
  30870. [8, 57], [8, 57], // 01011010x
  30871. [8, 58], [8, 58], // 01011011x
  30872. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30873. [6, 192], [6, 192], [6, 192], [6, 192],
  30874. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30875. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30876. [8, 448], [8, 448], // 01100100x
  30877. [8, 512], [8, 512], // 01100101x
  30878. [9, 704], // 011001100
  30879. [9, 768], // 011001101
  30880. [8, 640], [8, 640], // 01100111x
  30881. [8, 576], [8, 576], // 01101000x
  30882. [9, 832], // 011010010
  30883. [9, 896], // 011010011
  30884. [9, 960], // 011010100
  30885. [9, 1024], // 011010101
  30886. [9, 1088], // 011010110
  30887. [9, 1152], // 011010111
  30888. [9, 1216], // 011011000
  30889. [9, 1280], // 011011001
  30890. [9, 1344], // 011011010
  30891. [9, 1408], // 011011011
  30892. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30893. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30894. [4, 2], [4, 2], [4, 2], [4, 2],
  30895. [4, 2], [4, 2], [4, 2], [4, 2],
  30896. [4, 2], [4, 2], [4, 2], [4, 2],
  30897. [4, 2], [4, 2], [4, 2], [4, 2],
  30898. [4, 2], [4, 2], [4, 2], [4, 2],
  30899. [4, 2], [4, 2], [4, 2], [4, 2],
  30900. [4, 2], [4, 2], [4, 2], [4, 2],
  30901. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30902. [4, 3], [4, 3], [4, 3], [4, 3],
  30903. [4, 3], [4, 3], [4, 3], [4, 3],
  30904. [4, 3], [4, 3], [4, 3], [4, 3],
  30905. [4, 3], [4, 3], [4, 3], [4, 3],
  30906. [4, 3], [4, 3], [4, 3], [4, 3],
  30907. [4, 3], [4, 3], [4, 3], [4, 3],
  30908. [4, 3], [4, 3], [4, 3], [4, 3],
  30909. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30910. [5, 128], [5, 128], [5, 128], [5, 128],
  30911. [5, 128], [5, 128], [5, 128], [5, 128],
  30912. [5, 128], [5, 128], [5, 128], [5, 128],
  30913. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30914. [5, 8], [5, 8], [5, 8], [5, 8],
  30915. [5, 8], [5, 8], [5, 8], [5, 8],
  30916. [5, 8], [5, 8], [5, 8], [5, 8],
  30917. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30918. [5, 9], [5, 9], [5, 9], [5, 9],
  30919. [5, 9], [5, 9], [5, 9], [5, 9],
  30920. [5, 9], [5, 9], [5, 9], [5, 9],
  30921. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30922. [6, 16], [6, 16], [6, 16], [6, 16],
  30923. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30924. [6, 17], [6, 17], [6, 17], [6, 17],
  30925. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30926. [4, 4], [4, 4], [4, 4], [4, 4],
  30927. [4, 4], [4, 4], [4, 4], [4, 4],
  30928. [4, 4], [4, 4], [4, 4], [4, 4],
  30929. [4, 4], [4, 4], [4, 4], [4, 4],
  30930. [4, 4], [4, 4], [4, 4], [4, 4],
  30931. [4, 4], [4, 4], [4, 4], [4, 4],
  30932. [4, 4], [4, 4], [4, 4], [4, 4],
  30933. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30934. [4, 5], [4, 5], [4, 5], [4, 5],
  30935. [4, 5], [4, 5], [4, 5], [4, 5],
  30936. [4, 5], [4, 5], [4, 5], [4, 5],
  30937. [4, 5], [4, 5], [4, 5], [4, 5],
  30938. [4, 5], [4, 5], [4, 5], [4, 5],
  30939. [4, 5], [4, 5], [4, 5], [4, 5],
  30940. [4, 5], [4, 5], [4, 5], [4, 5],
  30941. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30942. [6, 14], [6, 14], [6, 14], [6, 14],
  30943. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30944. [6, 15], [6, 15], [6, 15], [6, 15],
  30945. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30946. [5, 64], [5, 64], [5, 64], [5, 64],
  30947. [5, 64], [5, 64], [5, 64], [5, 64],
  30948. [5, 64], [5, 64], [5, 64], [5, 64],
  30949. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30950. [4, 6], [4, 6], [4, 6], [4, 6],
  30951. [4, 6], [4, 6], [4, 6], [4, 6],
  30952. [4, 6], [4, 6], [4, 6], [4, 6],
  30953. [4, 6], [4, 6], [4, 6], [4, 6],
  30954. [4, 6], [4, 6], [4, 6], [4, 6],
  30955. [4, 6], [4, 6], [4, 6], [4, 6],
  30956. [4, 6], [4, 6], [4, 6], [4, 6],
  30957. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30958. [4, 7], [4, 7], [4, 7], [4, 7],
  30959. [4, 7], [4, 7], [4, 7], [4, 7],
  30960. [4, 7], [4, 7], [4, 7], [4, 7],
  30961. [4, 7], [4, 7], [4, 7], [4, 7],
  30962. [4, 7], [4, 7], [4, 7], [4, 7],
  30963. [4, 7], [4, 7], [4, 7], [4, 7],
  30964. [4, 7], [4, 7], [4, 7], [4, 7]
  30965. ];
  30966. var blackTable1 = [
  30967. [-1, -1], [-1, -1], // 000000000000x
  30968. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30969. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30970. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30971. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30972. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30973. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30974. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30975. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30976. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30977. [12, 1984], [12, 1984], // 000000010010x
  30978. [12, 2048], [12, 2048], // 000000010011x
  30979. [12, 2112], [12, 2112], // 000000010100x
  30980. [12, 2176], [12, 2176], // 000000010101x
  30981. [12, 2240], [12, 2240], // 000000010110x
  30982. [12, 2304], [12, 2304], // 000000010111x
  30983. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30984. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30985. [12, 2368], [12, 2368], // 000000011100x
  30986. [12, 2432], [12, 2432], // 000000011101x
  30987. [12, 2496], [12, 2496], // 000000011110x
  30988. [12, 2560], [12, 2560], // 000000011111x
  30989. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30990. [10, 18], [10, 18], [10, 18], [10, 18],
  30991. [12, 52], [12, 52], // 000000100100x
  30992. [13, 640], // 0000001001010
  30993. [13, 704], // 0000001001011
  30994. [13, 768], // 0000001001100
  30995. [13, 832], // 0000001001101
  30996. [12, 55], [12, 55], // 000000100111x
  30997. [12, 56], [12, 56], // 000000101000x
  30998. [13, 1280], // 0000001010010
  30999. [13, 1344], // 0000001010011
  31000. [13, 1408], // 0000001010100
  31001. [13, 1472], // 0000001010101
  31002. [12, 59], [12, 59], // 000000101011x
  31003. [12, 60], [12, 60], // 000000101100x
  31004. [13, 1536], // 0000001011010
  31005. [13, 1600], // 0000001011011
  31006. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31007. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31008. [13, 1664], // 0000001100100
  31009. [13, 1728], // 0000001100101
  31010. [12, 320], [12, 320], // 000000110011x
  31011. [12, 384], [12, 384], // 000000110100x
  31012. [12, 448], [12, 448], // 000000110101x
  31013. [13, 512], // 0000001101100
  31014. [13, 576], // 0000001101101
  31015. [12, 53], [12, 53], // 000000110111x
  31016. [12, 54], [12, 54], // 000000111000x
  31017. [13, 896], // 0000001110010
  31018. [13, 960], // 0000001110011
  31019. [13, 1024], // 0000001110100
  31020. [13, 1088], // 0000001110101
  31021. [13, 1152], // 0000001110110
  31022. [13, 1216], // 0000001110111
  31023. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31024. [10, 64], [10, 64], [10, 64], [10, 64]
  31025. ];
  31026. var blackTable2 = [
  31027. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31028. [8, 13], [8, 13], [8, 13], [8, 13],
  31029. [8, 13], [8, 13], [8, 13], [8, 13],
  31030. [8, 13], [8, 13], [8, 13], [8, 13],
  31031. [11, 23], [11, 23], // 00000101000x
  31032. [12, 50], // 000001010010
  31033. [12, 51], // 000001010011
  31034. [12, 44], // 000001010100
  31035. [12, 45], // 000001010101
  31036. [12, 46], // 000001010110
  31037. [12, 47], // 000001010111
  31038. [12, 57], // 000001011000
  31039. [12, 58], // 000001011001
  31040. [12, 61], // 000001011010
  31041. [12, 256], // 000001011011
  31042. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31043. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31044. [12, 48], // 000001100100
  31045. [12, 49], // 000001100101
  31046. [12, 62], // 000001100110
  31047. [12, 63], // 000001100111
  31048. [12, 30], // 000001101000
  31049. [12, 31], // 000001101001
  31050. [12, 32], // 000001101010
  31051. [12, 33], // 000001101011
  31052. [12, 40], // 000001101100
  31053. [12, 41], // 000001101101
  31054. [11, 22], [11, 22], // 00000110111x
  31055. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31056. [8, 14], [8, 14], [8, 14], [8, 14],
  31057. [8, 14], [8, 14], [8, 14], [8, 14],
  31058. [8, 14], [8, 14], [8, 14], [8, 14],
  31059. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31060. [7, 10], [7, 10], [7, 10], [7, 10],
  31061. [7, 10], [7, 10], [7, 10], [7, 10],
  31062. [7, 10], [7, 10], [7, 10], [7, 10],
  31063. [7, 10], [7, 10], [7, 10], [7, 10],
  31064. [7, 10], [7, 10], [7, 10], [7, 10],
  31065. [7, 10], [7, 10], [7, 10], [7, 10],
  31066. [7, 10], [7, 10], [7, 10], [7, 10],
  31067. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31068. [7, 11], [7, 11], [7, 11], [7, 11],
  31069. [7, 11], [7, 11], [7, 11], [7, 11],
  31070. [7, 11], [7, 11], [7, 11], [7, 11],
  31071. [7, 11], [7, 11], [7, 11], [7, 11],
  31072. [7, 11], [7, 11], [7, 11], [7, 11],
  31073. [7, 11], [7, 11], [7, 11], [7, 11],
  31074. [7, 11], [7, 11], [7, 11], [7, 11],
  31075. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31076. [9, 15], [9, 15], [9, 15], [9, 15],
  31077. [12, 128], // 000011001000
  31078. [12, 192], // 000011001001
  31079. [12, 26], // 000011001010
  31080. [12, 27], // 000011001011
  31081. [12, 28], // 000011001100
  31082. [12, 29], // 000011001101
  31083. [11, 19], [11, 19], // 00001100111x
  31084. [11, 20], [11, 20], // 00001101000x
  31085. [12, 34], // 000011010010
  31086. [12, 35], // 000011010011
  31087. [12, 36], // 000011010100
  31088. [12, 37], // 000011010101
  31089. [12, 38], // 000011010110
  31090. [12, 39], // 000011010111
  31091. [11, 21], [11, 21], // 00001101100x
  31092. [12, 42], // 000011011010
  31093. [12, 43], // 000011011011
  31094. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31095. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31096. [7, 12], [7, 12], [7, 12], [7, 12],
  31097. [7, 12], [7, 12], [7, 12], [7, 12],
  31098. [7, 12], [7, 12], [7, 12], [7, 12],
  31099. [7, 12], [7, 12], [7, 12], [7, 12],
  31100. [7, 12], [7, 12], [7, 12], [7, 12],
  31101. [7, 12], [7, 12], [7, 12], [7, 12],
  31102. [7, 12], [7, 12], [7, 12], [7, 12]
  31103. ];
  31104. var blackTable3 = [
  31105. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31106. [6, 9], // 000100
  31107. [6, 8], // 000101
  31108. [5, 7], [5, 7], // 00011x
  31109. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31110. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31111. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31112. [3, 1], [3, 1], [3, 1], [3, 1],
  31113. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31114. [3, 4], [3, 4], [3, 4], [3, 4],
  31115. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31116. [2, 3], [2, 3], [2, 3], [2, 3],
  31117. [2, 3], [2, 3], [2, 3], [2, 3],
  31118. [2, 3], [2, 3], [2, 3], [2, 3],
  31119. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31120. [2, 2], [2, 2], [2, 2], [2, 2],
  31121. [2, 2], [2, 2], [2, 2], [2, 2],
  31122. [2, 2], [2, 2], [2, 2], [2, 2]
  31123. ];
  31124. function CCITTFaxStream(str, maybeLength, params) {
  31125. this.str = str;
  31126. this.dict = str.dict;
  31127. params = params || Dict.empty;
  31128. this.encoding = params.get('K') || 0;
  31129. this.eoline = params.get('EndOfLine') || false;
  31130. this.byteAlign = params.get('EncodedByteAlign') || false;
  31131. this.columns = params.get('Columns') || 1728;
  31132. this.rows = params.get('Rows') || 0;
  31133. var eoblock = params.get('EndOfBlock');
  31134. if (eoblock === null || eoblock === undefined) {
  31135. eoblock = true;
  31136. }
  31137. this.eoblock = eoblock;
  31138. this.black = params.get('BlackIs1') || false;
  31139. this.codingLine = new Uint32Array(this.columns + 1);
  31140. this.refLine = new Uint32Array(this.columns + 2);
  31141. this.codingLine[0] = this.columns;
  31142. this.codingPos = 0;
  31143. this.row = 0;
  31144. this.nextLine2D = this.encoding < 0;
  31145. this.inputBits = 0;
  31146. this.inputBuf = 0;
  31147. this.outputBits = 0;
  31148. var code1;
  31149. while ((code1 = this.lookBits(12)) === 0) {
  31150. this.eatBits(1);
  31151. }
  31152. if (code1 === 1) {
  31153. this.eatBits(12);
  31154. }
  31155. if (this.encoding > 0) {
  31156. this.nextLine2D = !this.lookBits(1);
  31157. this.eatBits(1);
  31158. }
  31159. DecodeStream.call(this, maybeLength);
  31160. }
  31161. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31162. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31163. while (!this.eof) {
  31164. var c = this.lookChar();
  31165. this.ensureBuffer(this.bufferLength + 1);
  31166. this.buffer[this.bufferLength++] = c;
  31167. }
  31168. };
  31169. CCITTFaxStream.prototype.addPixels =
  31170. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31171. var codingLine = this.codingLine;
  31172. var codingPos = this.codingPos;
  31173. if (a1 > codingLine[codingPos]) {
  31174. if (a1 > this.columns) {
  31175. info('row is wrong length');
  31176. this.err = true;
  31177. a1 = this.columns;
  31178. }
  31179. if ((codingPos & 1) ^ blackPixels) {
  31180. ++codingPos;
  31181. }
  31182. codingLine[codingPos] = a1;
  31183. }
  31184. this.codingPos = codingPos;
  31185. };
  31186. CCITTFaxStream.prototype.addPixelsNeg =
  31187. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31188. var codingLine = this.codingLine;
  31189. var codingPos = this.codingPos;
  31190. if (a1 > codingLine[codingPos]) {
  31191. if (a1 > this.columns) {
  31192. info('row is wrong length');
  31193. this.err = true;
  31194. a1 = this.columns;
  31195. }
  31196. if ((codingPos & 1) ^ blackPixels) {
  31197. ++codingPos;
  31198. }
  31199. codingLine[codingPos] = a1;
  31200. } else if (a1 < codingLine[codingPos]) {
  31201. if (a1 < 0) {
  31202. info('invalid code');
  31203. this.err = true;
  31204. a1 = 0;
  31205. }
  31206. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31207. --codingPos;
  31208. }
  31209. codingLine[codingPos] = a1;
  31210. }
  31211. this.codingPos = codingPos;
  31212. };
  31213. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31214. var refLine = this.refLine;
  31215. var codingLine = this.codingLine;
  31216. var columns = this.columns;
  31217. var refPos, blackPixels, bits, i;
  31218. if (this.outputBits === 0) {
  31219. if (this.eof) {
  31220. return null;
  31221. }
  31222. this.err = false;
  31223. var code1, code2, code3;
  31224. if (this.nextLine2D) {
  31225. for (i = 0; codingLine[i] < columns; ++i) {
  31226. refLine[i] = codingLine[i];
  31227. }
  31228. refLine[i++] = columns;
  31229. refLine[i] = columns;
  31230. codingLine[0] = 0;
  31231. this.codingPos = 0;
  31232. refPos = 0;
  31233. blackPixels = 0;
  31234. while (codingLine[this.codingPos] < columns) {
  31235. code1 = this.getTwoDimCode();
  31236. switch (code1) {
  31237. case twoDimPass:
  31238. this.addPixels(refLine[refPos + 1], blackPixels);
  31239. if (refLine[refPos + 1] < columns) {
  31240. refPos += 2;
  31241. }
  31242. break;
  31243. case twoDimHoriz:
  31244. code1 = code2 = 0;
  31245. if (blackPixels) {
  31246. do {
  31247. code1 += (code3 = this.getBlackCode());
  31248. } while (code3 >= 64);
  31249. do {
  31250. code2 += (code3 = this.getWhiteCode());
  31251. } while (code3 >= 64);
  31252. } else {
  31253. do {
  31254. code1 += (code3 = this.getWhiteCode());
  31255. } while (code3 >= 64);
  31256. do {
  31257. code2 += (code3 = this.getBlackCode());
  31258. } while (code3 >= 64);
  31259. }
  31260. this.addPixels(codingLine[this.codingPos] +
  31261. code1, blackPixels);
  31262. if (codingLine[this.codingPos] < columns) {
  31263. this.addPixels(codingLine[this.codingPos] + code2,
  31264. blackPixels ^ 1);
  31265. }
  31266. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31267. refLine[refPos] < columns) {
  31268. refPos += 2;
  31269. }
  31270. break;
  31271. case twoDimVertR3:
  31272. this.addPixels(refLine[refPos] + 3, blackPixels);
  31273. blackPixels ^= 1;
  31274. if (codingLine[this.codingPos] < columns) {
  31275. ++refPos;
  31276. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31277. refLine[refPos] < columns) {
  31278. refPos += 2;
  31279. }
  31280. }
  31281. break;
  31282. case twoDimVertR2:
  31283. this.addPixels(refLine[refPos] + 2, blackPixels);
  31284. blackPixels ^= 1;
  31285. if (codingLine[this.codingPos] < columns) {
  31286. ++refPos;
  31287. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31288. refLine[refPos] < columns) {
  31289. refPos += 2;
  31290. }
  31291. }
  31292. break;
  31293. case twoDimVertR1:
  31294. this.addPixels(refLine[refPos] + 1, blackPixels);
  31295. blackPixels ^= 1;
  31296. if (codingLine[this.codingPos] < columns) {
  31297. ++refPos;
  31298. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31299. refLine[refPos] < columns) {
  31300. refPos += 2;
  31301. }
  31302. }
  31303. break;
  31304. case twoDimVert0:
  31305. this.addPixels(refLine[refPos], blackPixels);
  31306. blackPixels ^= 1;
  31307. if (codingLine[this.codingPos] < columns) {
  31308. ++refPos;
  31309. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31310. refLine[refPos] < columns) {
  31311. refPos += 2;
  31312. }
  31313. }
  31314. break;
  31315. case twoDimVertL3:
  31316. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31317. blackPixels ^= 1;
  31318. if (codingLine[this.codingPos] < columns) {
  31319. if (refPos > 0) {
  31320. --refPos;
  31321. } else {
  31322. ++refPos;
  31323. }
  31324. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31325. refLine[refPos] < columns) {
  31326. refPos += 2;
  31327. }
  31328. }
  31329. break;
  31330. case twoDimVertL2:
  31331. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31332. blackPixels ^= 1;
  31333. if (codingLine[this.codingPos] < columns) {
  31334. if (refPos > 0) {
  31335. --refPos;
  31336. } else {
  31337. ++refPos;
  31338. }
  31339. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31340. refLine[refPos] < columns) {
  31341. refPos += 2;
  31342. }
  31343. }
  31344. break;
  31345. case twoDimVertL1:
  31346. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31347. blackPixels ^= 1;
  31348. if (codingLine[this.codingPos] < columns) {
  31349. if (refPos > 0) {
  31350. --refPos;
  31351. } else {
  31352. ++refPos;
  31353. }
  31354. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31355. refLine[refPos] < columns) {
  31356. refPos += 2;
  31357. }
  31358. }
  31359. break;
  31360. case EOF:
  31361. this.addPixels(columns, 0);
  31362. this.eof = true;
  31363. break;
  31364. default:
  31365. info('bad 2d code');
  31366. this.addPixels(columns, 0);
  31367. this.err = true;
  31368. }
  31369. }
  31370. } else {
  31371. codingLine[0] = 0;
  31372. this.codingPos = 0;
  31373. blackPixels = 0;
  31374. while (codingLine[this.codingPos] < columns) {
  31375. code1 = 0;
  31376. if (blackPixels) {
  31377. do {
  31378. code1 += (code3 = this.getBlackCode());
  31379. } while (code3 >= 64);
  31380. } else {
  31381. do {
  31382. code1 += (code3 = this.getWhiteCode());
  31383. } while (code3 >= 64);
  31384. }
  31385. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31386. blackPixels ^= 1;
  31387. }
  31388. }
  31389. var gotEOL = false;
  31390. if (this.byteAlign) {
  31391. this.inputBits &= ~7;
  31392. }
  31393. if (!this.eoblock && this.row === this.rows - 1) {
  31394. this.eof = true;
  31395. } else {
  31396. code1 = this.lookBits(12);
  31397. if (this.eoline) {
  31398. while (code1 !== EOF && code1 !== 1) {
  31399. this.eatBits(1);
  31400. code1 = this.lookBits(12);
  31401. }
  31402. } else {
  31403. while (code1 === 0) {
  31404. this.eatBits(1);
  31405. code1 = this.lookBits(12);
  31406. }
  31407. }
  31408. if (code1 === 1) {
  31409. this.eatBits(12);
  31410. gotEOL = true;
  31411. } else if (code1 === EOF) {
  31412. this.eof = true;
  31413. }
  31414. }
  31415. if (!this.eof && this.encoding > 0) {
  31416. this.nextLine2D = !this.lookBits(1);
  31417. this.eatBits(1);
  31418. }
  31419. if (this.eoblock && gotEOL && this.byteAlign) {
  31420. code1 = this.lookBits(12);
  31421. if (code1 === 1) {
  31422. this.eatBits(12);
  31423. if (this.encoding > 0) {
  31424. this.lookBits(1);
  31425. this.eatBits(1);
  31426. }
  31427. if (this.encoding >= 0) {
  31428. for (i = 0; i < 4; ++i) {
  31429. code1 = this.lookBits(12);
  31430. if (code1 !== 1) {
  31431. info('bad rtc code: ' + code1);
  31432. }
  31433. this.eatBits(12);
  31434. if (this.encoding > 0) {
  31435. this.lookBits(1);
  31436. this.eatBits(1);
  31437. }
  31438. }
  31439. }
  31440. this.eof = true;
  31441. }
  31442. } else if (this.err && this.eoline) {
  31443. while (true) {
  31444. code1 = this.lookBits(13);
  31445. if (code1 === EOF) {
  31446. this.eof = true;
  31447. return null;
  31448. }
  31449. if ((code1 >> 1) === 1) {
  31450. break;
  31451. }
  31452. this.eatBits(1);
  31453. }
  31454. this.eatBits(12);
  31455. if (this.encoding > 0) {
  31456. this.eatBits(1);
  31457. this.nextLine2D = !(code1 & 1);
  31458. }
  31459. }
  31460. if (codingLine[0] > 0) {
  31461. this.outputBits = codingLine[this.codingPos = 0];
  31462. } else {
  31463. this.outputBits = codingLine[this.codingPos = 1];
  31464. }
  31465. this.row++;
  31466. }
  31467. var c;
  31468. if (this.outputBits >= 8) {
  31469. c = (this.codingPos & 1) ? 0 : 0xFF;
  31470. this.outputBits -= 8;
  31471. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31472. this.codingPos++;
  31473. this.outputBits = (codingLine[this.codingPos] -
  31474. codingLine[this.codingPos - 1]);
  31475. }
  31476. } else {
  31477. bits = 8;
  31478. c = 0;
  31479. do {
  31480. if (this.outputBits > bits) {
  31481. c <<= bits;
  31482. if (!(this.codingPos & 1)) {
  31483. c |= 0xFF >> (8 - bits);
  31484. }
  31485. this.outputBits -= bits;
  31486. bits = 0;
  31487. } else {
  31488. c <<= this.outputBits;
  31489. if (!(this.codingPos & 1)) {
  31490. c |= 0xFF >> (8 - this.outputBits);
  31491. }
  31492. bits -= this.outputBits;
  31493. this.outputBits = 0;
  31494. if (codingLine[this.codingPos] < columns) {
  31495. this.codingPos++;
  31496. this.outputBits = (codingLine[this.codingPos] -
  31497. codingLine[this.codingPos - 1]);
  31498. } else if (bits > 0) {
  31499. c <<= bits;
  31500. bits = 0;
  31501. }
  31502. }
  31503. } while (bits);
  31504. }
  31505. if (this.black) {
  31506. c ^= 0xFF;
  31507. }
  31508. return c;
  31509. };
  31510. // This functions returns the code found from the table.
  31511. // The start and end parameters set the boundaries for searching the table.
  31512. // The limit parameter is optional. Function returns an array with three
  31513. // values. The first array element indicates whether a valid code is being
  31514. // returned. The second array element is the actual code. The third array
  31515. // element indicates whether EOF was reached.
  31516. CCITTFaxStream.prototype.findTableCode =
  31517. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31518. var limitValue = limit || 0;
  31519. for (var i = start; i <= end; ++i) {
  31520. var code = this.lookBits(i);
  31521. if (code === EOF) {
  31522. return [true, 1, false];
  31523. }
  31524. if (i < end) {
  31525. code <<= end - i;
  31526. }
  31527. if (!limitValue || code >= limitValue) {
  31528. var p = table[code - limitValue];
  31529. if (p[0] === i) {
  31530. this.eatBits(i);
  31531. return [true, p[1], true];
  31532. }
  31533. }
  31534. }
  31535. return [false, 0, false];
  31536. };
  31537. CCITTFaxStream.prototype.getTwoDimCode =
  31538. function ccittFaxStreamGetTwoDimCode() {
  31539. var code = 0;
  31540. var p;
  31541. if (this.eoblock) {
  31542. code = this.lookBits(7);
  31543. p = twoDimTable[code];
  31544. if (p && p[0] > 0) {
  31545. this.eatBits(p[0]);
  31546. return p[1];
  31547. }
  31548. } else {
  31549. var result = this.findTableCode(1, 7, twoDimTable);
  31550. if (result[0] && result[2]) {
  31551. return result[1];
  31552. }
  31553. }
  31554. info('Bad two dim code');
  31555. return EOF;
  31556. };
  31557. CCITTFaxStream.prototype.getWhiteCode =
  31558. function ccittFaxStreamGetWhiteCode() {
  31559. var code = 0;
  31560. var p;
  31561. if (this.eoblock) {
  31562. code = this.lookBits(12);
  31563. if (code === EOF) {
  31564. return 1;
  31565. }
  31566. if ((code >> 5) === 0) {
  31567. p = whiteTable1[code];
  31568. } else {
  31569. p = whiteTable2[code >> 3];
  31570. }
  31571. if (p[0] > 0) {
  31572. this.eatBits(p[0]);
  31573. return p[1];
  31574. }
  31575. } else {
  31576. var result = this.findTableCode(1, 9, whiteTable2);
  31577. if (result[0]) {
  31578. return result[1];
  31579. }
  31580. result = this.findTableCode(11, 12, whiteTable1);
  31581. if (result[0]) {
  31582. return result[1];
  31583. }
  31584. }
  31585. info('bad white code');
  31586. this.eatBits(1);
  31587. return 1;
  31588. };
  31589. CCITTFaxStream.prototype.getBlackCode =
  31590. function ccittFaxStreamGetBlackCode() {
  31591. var code, p;
  31592. if (this.eoblock) {
  31593. code = this.lookBits(13);
  31594. if (code === EOF) {
  31595. return 1;
  31596. }
  31597. if ((code >> 7) === 0) {
  31598. p = blackTable1[code];
  31599. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31600. p = blackTable2[(code >> 1) - 64];
  31601. } else {
  31602. p = blackTable3[code >> 7];
  31603. }
  31604. if (p[0] > 0) {
  31605. this.eatBits(p[0]);
  31606. return p[1];
  31607. }
  31608. } else {
  31609. var result = this.findTableCode(2, 6, blackTable3);
  31610. if (result[0]) {
  31611. return result[1];
  31612. }
  31613. result = this.findTableCode(7, 12, blackTable2, 64);
  31614. if (result[0]) {
  31615. return result[1];
  31616. }
  31617. result = this.findTableCode(10, 13, blackTable1);
  31618. if (result[0]) {
  31619. return result[1];
  31620. }
  31621. }
  31622. info('bad black code');
  31623. this.eatBits(1);
  31624. return 1;
  31625. };
  31626. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31627. var c;
  31628. while (this.inputBits < n) {
  31629. if ((c = this.str.getByte()) === -1) {
  31630. if (this.inputBits === 0) {
  31631. return EOF;
  31632. }
  31633. return ((this.inputBuf << (n - this.inputBits)) &
  31634. (0xFFFF >> (16 - n)));
  31635. }
  31636. this.inputBuf = (this.inputBuf << 8) + c;
  31637. this.inputBits += 8;
  31638. }
  31639. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31640. };
  31641. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31642. if ((this.inputBits -= n) < 0) {
  31643. this.inputBits = 0;
  31644. }
  31645. };
  31646. return CCITTFaxStream;
  31647. })();
  31648. var LZWStream = (function LZWStreamClosure() {
  31649. function LZWStream(str, maybeLength, earlyChange) {
  31650. this.str = str;
  31651. this.dict = str.dict;
  31652. this.cachedData = 0;
  31653. this.bitsCached = 0;
  31654. var maxLzwDictionarySize = 4096;
  31655. var lzwState = {
  31656. earlyChange: earlyChange,
  31657. codeLength: 9,
  31658. nextCode: 258,
  31659. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31660. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31661. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31662. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31663. currentSequenceLength: 0
  31664. };
  31665. for (var i = 0; i < 256; ++i) {
  31666. lzwState.dictionaryValues[i] = i;
  31667. lzwState.dictionaryLengths[i] = 1;
  31668. }
  31669. this.lzwState = lzwState;
  31670. DecodeStream.call(this, maybeLength);
  31671. }
  31672. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31673. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31674. var bitsCached = this.bitsCached;
  31675. var cachedData = this.cachedData;
  31676. while (bitsCached < n) {
  31677. var c = this.str.getByte();
  31678. if (c === -1) {
  31679. this.eof = true;
  31680. return null;
  31681. }
  31682. cachedData = (cachedData << 8) | c;
  31683. bitsCached += 8;
  31684. }
  31685. this.bitsCached = (bitsCached -= n);
  31686. this.cachedData = cachedData;
  31687. this.lastCode = null;
  31688. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31689. };
  31690. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31691. var blockSize = 512;
  31692. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31693. var i, j, q;
  31694. var lzwState = this.lzwState;
  31695. if (!lzwState) {
  31696. return; // eof was found
  31697. }
  31698. var earlyChange = lzwState.earlyChange;
  31699. var nextCode = lzwState.nextCode;
  31700. var dictionaryValues = lzwState.dictionaryValues;
  31701. var dictionaryLengths = lzwState.dictionaryLengths;
  31702. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31703. var codeLength = lzwState.codeLength;
  31704. var prevCode = lzwState.prevCode;
  31705. var currentSequence = lzwState.currentSequence;
  31706. var currentSequenceLength = lzwState.currentSequenceLength;
  31707. var decodedLength = 0;
  31708. var currentBufferLength = this.bufferLength;
  31709. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31710. for (i = 0; i < blockSize; i++) {
  31711. var code = this.readBits(codeLength);
  31712. var hasPrev = currentSequenceLength > 0;
  31713. if (code < 256) {
  31714. currentSequence[0] = code;
  31715. currentSequenceLength = 1;
  31716. } else if (code >= 258) {
  31717. if (code < nextCode) {
  31718. currentSequenceLength = dictionaryLengths[code];
  31719. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31720. currentSequence[j] = dictionaryValues[q];
  31721. q = dictionaryPrevCodes[q];
  31722. }
  31723. } else {
  31724. currentSequence[currentSequenceLength++] = currentSequence[0];
  31725. }
  31726. } else if (code === 256) {
  31727. codeLength = 9;
  31728. nextCode = 258;
  31729. currentSequenceLength = 0;
  31730. continue;
  31731. } else {
  31732. this.eof = true;
  31733. delete this.lzwState;
  31734. break;
  31735. }
  31736. if (hasPrev) {
  31737. dictionaryPrevCodes[nextCode] = prevCode;
  31738. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31739. dictionaryValues[nextCode] = currentSequence[0];
  31740. nextCode++;
  31741. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31742. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31743. 0.6931471805599453 + 1, 12) | 0;
  31744. }
  31745. prevCode = code;
  31746. decodedLength += currentSequenceLength;
  31747. if (estimatedDecodedSize < decodedLength) {
  31748. do {
  31749. estimatedDecodedSize += decodedSizeDelta;
  31750. } while (estimatedDecodedSize < decodedLength);
  31751. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31752. }
  31753. for (j = 0; j < currentSequenceLength; j++) {
  31754. buffer[currentBufferLength++] = currentSequence[j];
  31755. }
  31756. }
  31757. lzwState.nextCode = nextCode;
  31758. lzwState.codeLength = codeLength;
  31759. lzwState.prevCode = prevCode;
  31760. lzwState.currentSequenceLength = currentSequenceLength;
  31761. this.bufferLength = currentBufferLength;
  31762. };
  31763. return LZWStream;
  31764. })();
  31765. var NullStream = (function NullStreamClosure() {
  31766. function NullStream() {
  31767. Stream.call(this, new Uint8Array(0));
  31768. }
  31769. NullStream.prototype = Stream.prototype;
  31770. return NullStream;
  31771. })();
  31772. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31773. setup: function wphSetup(handler) {
  31774. var pdfManager;
  31775. function loadDocument(recoveryMode) {
  31776. var loadDocumentCapability = createPromiseCapability();
  31777. var parseSuccess = function parseSuccess() {
  31778. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31779. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31780. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31781. Promise.all([numPagesPromise, fingerprintPromise,
  31782. encryptedPromise]).then(function onDocReady(results) {
  31783. var doc = {
  31784. numPages: results[0],
  31785. fingerprint: results[1],
  31786. encrypted: !!results[2],
  31787. };
  31788. loadDocumentCapability.resolve(doc);
  31789. },
  31790. parseFailure);
  31791. };
  31792. var parseFailure = function parseFailure(e) {
  31793. loadDocumentCapability.reject(e);
  31794. };
  31795. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31796. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31797. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31798. parseSuccess, parseFailure);
  31799. }, parseFailure);
  31800. }, parseFailure);
  31801. return loadDocumentCapability.promise;
  31802. }
  31803. function getPdfManager(data) {
  31804. var pdfManagerCapability = createPromiseCapability();
  31805. var source = data.source;
  31806. var disableRange = data.disableRange;
  31807. if (source.data) {
  31808. try {
  31809. pdfManager = new LocalPdfManager(source.data, source.password);
  31810. pdfManagerCapability.resolve();
  31811. } catch (ex) {
  31812. pdfManagerCapability.reject(ex);
  31813. }
  31814. return pdfManagerCapability.promise;
  31815. } else if (source.chunkedViewerLoading) {
  31816. try {
  31817. pdfManager = new NetworkPdfManager(source, handler);
  31818. pdfManagerCapability.resolve();
  31819. } catch (ex) {
  31820. pdfManagerCapability.reject(ex);
  31821. }
  31822. return pdfManagerCapability.promise;
  31823. }
  31824. var networkManager = new NetworkManager(source.url, {
  31825. httpHeaders: source.httpHeaders,
  31826. withCredentials: source.withCredentials
  31827. });
  31828. var cachedChunks = [];
  31829. var fullRequestXhrId = networkManager.requestFull({
  31830. onHeadersReceived: function onHeadersReceived() {
  31831. if (disableRange) {
  31832. return;
  31833. }
  31834. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31835. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31836. return;
  31837. }
  31838. var contentEncoding =
  31839. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31840. if (contentEncoding !== 'identity') {
  31841. return;
  31842. }
  31843. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31844. length = parseInt(length, 10);
  31845. if (!isInt(length)) {
  31846. return;
  31847. }
  31848. source.length = length;
  31849. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31850. // The file size is smaller than the size of two chunks, so it does
  31851. // not make any sense to abort the request and retry with a range
  31852. // request.
  31853. return;
  31854. }
  31855. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31856. // We can continue fetching when progressive loading is enabled,
  31857. // and we don't need the autoFetch feature.
  31858. source.disableAutoFetch = true;
  31859. } else {
  31860. // NOTE: by cancelling the full request, and then issuing range
  31861. // requests, there will be an issue for sites where you can only
  31862. // request the pdf once. However, if this is the case, then the
  31863. // server should not be returning that it can support range
  31864. // requests.
  31865. networkManager.abortRequest(fullRequestXhrId);
  31866. }
  31867. try {
  31868. pdfManager = new NetworkPdfManager(source, handler);
  31869. pdfManagerCapability.resolve(pdfManager);
  31870. } catch (ex) {
  31871. pdfManagerCapability.reject(ex);
  31872. }
  31873. },
  31874. onProgressiveData: source.disableStream ? null :
  31875. function onProgressiveData(chunk) {
  31876. if (!pdfManager) {
  31877. cachedChunks.push(chunk);
  31878. return;
  31879. }
  31880. pdfManager.sendProgressiveData(chunk);
  31881. },
  31882. onDone: function onDone(args) {
  31883. if (pdfManager) {
  31884. return; // already processed
  31885. }
  31886. var pdfFile;
  31887. if (args === null) {
  31888. // TODO add some streaming manager, e.g. for unknown length files.
  31889. // The data was returned in the onProgressiveData, combining...
  31890. var pdfFileLength = 0, pos = 0;
  31891. cachedChunks.forEach(function (chunk) {
  31892. pdfFileLength += chunk.byteLength;
  31893. });
  31894. if (source.length && pdfFileLength !== source.length) {
  31895. warn('reported HTTP length is different from actual');
  31896. }
  31897. var pdfFileArray = new Uint8Array(pdfFileLength);
  31898. cachedChunks.forEach(function (chunk) {
  31899. pdfFileArray.set(new Uint8Array(chunk), pos);
  31900. pos += chunk.byteLength;
  31901. });
  31902. pdfFile = pdfFileArray.buffer;
  31903. } else {
  31904. pdfFile = args.chunk;
  31905. }
  31906. // the data is array, instantiating directly from it
  31907. try {
  31908. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31909. pdfManagerCapability.resolve();
  31910. } catch (ex) {
  31911. pdfManagerCapability.reject(ex);
  31912. }
  31913. },
  31914. onError: function onError(status) {
  31915. var exception;
  31916. if (status === 404) {
  31917. exception = new MissingPDFException('Missing PDF "' +
  31918. source.url + '".');
  31919. handler.send('MissingPDF', exception);
  31920. } else {
  31921. exception = new UnexpectedResponseException(
  31922. 'Unexpected server response (' + status +
  31923. ') while retrieving PDF "' + source.url + '".', status);
  31924. handler.send('UnexpectedResponse', exception);
  31925. }
  31926. },
  31927. onProgress: function onProgress(evt) {
  31928. handler.send('DocProgress', {
  31929. loaded: evt.loaded,
  31930. total: evt.lengthComputable ? evt.total : source.length
  31931. });
  31932. }
  31933. });
  31934. return pdfManagerCapability.promise;
  31935. }
  31936. handler.on('test', function wphSetupTest(data) {
  31937. // check if Uint8Array can be sent to worker
  31938. if (!(data instanceof Uint8Array)) {
  31939. handler.send('test', false);
  31940. return;
  31941. }
  31942. // making sure postMessage transfers are working
  31943. var supportTransfers = data[0] === 255;
  31944. handler.postMessageTransfers = supportTransfers;
  31945. // check if the response property is supported by xhr
  31946. var xhr = new XMLHttpRequest();
  31947. var responseExists = 'response' in xhr;
  31948. // check if the property is actually implemented
  31949. try {
  31950. var dummy = xhr.responseType;
  31951. } catch (e) {
  31952. responseExists = false;
  31953. }
  31954. if (!responseExists) {
  31955. handler.send('test', false);
  31956. return;
  31957. }
  31958. handler.send('test', {
  31959. supportTypedArray: true,
  31960. supportTransfers: supportTransfers
  31961. });
  31962. });
  31963. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31964. var onSuccess = function(doc) {
  31965. handler.send('GetDoc', { pdfInfo: doc });
  31966. };
  31967. var onFailure = function(e) {
  31968. if (e instanceof PasswordException) {
  31969. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31970. handler.send('NeedPassword', e);
  31971. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31972. handler.send('IncorrectPassword', e);
  31973. }
  31974. } else if (e instanceof InvalidPDFException) {
  31975. handler.send('InvalidPDF', e);
  31976. } else if (e instanceof MissingPDFException) {
  31977. handler.send('MissingPDF', e);
  31978. } else if (e instanceof UnexpectedResponseException) {
  31979. handler.send('UnexpectedResponse', e);
  31980. } else {
  31981. handler.send('UnknownError',
  31982. new UnknownErrorException(e.message, e.toString()));
  31983. }
  31984. };
  31985. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31986. -1 : data.maxImageSize;
  31987. PDFJS.disableFontFace = data.disableFontFace;
  31988. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31989. PDFJS.verbosity = data.verbosity;
  31990. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31991. null : data.cMapUrl;
  31992. PDFJS.cMapPacked = data.cMapPacked === true;
  31993. getPdfManager(data).then(function () {
  31994. handler.send('PDFManagerReady', null);
  31995. pdfManager.onLoadedStream().then(function(stream) {
  31996. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31997. });
  31998. }).then(function pdfManagerReady() {
  31999. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32000. // Try again with recoveryMode == true
  32001. if (!(ex instanceof XRefParseException)) {
  32002. if (ex instanceof PasswordException) {
  32003. // after password exception prepare to receive a new password
  32004. // to repeat loading
  32005. pdfManager.passwordChanged().then(pdfManagerReady);
  32006. }
  32007. onFailure(ex);
  32008. return;
  32009. }
  32010. pdfManager.requestLoadedStream();
  32011. pdfManager.onLoadedStream().then(function() {
  32012. loadDocument(true).then(onSuccess, onFailure);
  32013. });
  32014. }, onFailure);
  32015. }, onFailure);
  32016. });
  32017. handler.on('GetPage', function wphSetupGetPage(data) {
  32018. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32019. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32020. var refPromise = pdfManager.ensure(page, 'ref');
  32021. var viewPromise = pdfManager.ensure(page, 'view');
  32022. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32023. function(results) {
  32024. return {
  32025. rotate: results[0],
  32026. ref: results[1],
  32027. view: results[2]
  32028. };
  32029. });
  32030. });
  32031. });
  32032. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32033. var ref = new Ref(data.ref.num, data.ref.gen);
  32034. var catalog = pdfManager.pdfDocument.catalog;
  32035. return catalog.getPageIndex(ref);
  32036. });
  32037. handler.on('GetDestinations',
  32038. function wphSetupGetDestinations(data) {
  32039. return pdfManager.ensureCatalog('destinations');
  32040. }
  32041. );
  32042. handler.on('GetDestination',
  32043. function wphSetupGetDestination(data) {
  32044. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32045. }
  32046. );
  32047. handler.on('GetAttachments',
  32048. function wphSetupGetAttachments(data) {
  32049. return pdfManager.ensureCatalog('attachments');
  32050. }
  32051. );
  32052. handler.on('GetJavaScript',
  32053. function wphSetupGetJavaScript(data) {
  32054. return pdfManager.ensureCatalog('javaScript');
  32055. }
  32056. );
  32057. handler.on('GetOutline',
  32058. function wphSetupGetOutline(data) {
  32059. return pdfManager.ensureCatalog('documentOutline');
  32060. }
  32061. );
  32062. handler.on('GetMetadata',
  32063. function wphSetupGetMetadata(data) {
  32064. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32065. pdfManager.ensureCatalog('metadata')]);
  32066. }
  32067. );
  32068. handler.on('GetData', function wphSetupGetData(data) {
  32069. pdfManager.requestLoadedStream();
  32070. return pdfManager.onLoadedStream().then(function(stream) {
  32071. return stream.bytes;
  32072. });
  32073. });
  32074. handler.on('GetStats',
  32075. function wphSetupGetStats(data) {
  32076. return pdfManager.pdfDocument.xref.stats;
  32077. }
  32078. );
  32079. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32080. pdfManager.updatePassword(data);
  32081. });
  32082. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32083. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32084. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32085. });
  32086. });
  32087. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32088. pdfManager.getPage(data.pageIndex).then(function(page) {
  32089. var pageNum = data.pageIndex + 1;
  32090. var start = Date.now();
  32091. // Pre compile the pdf page and fetch the fonts/images.
  32092. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  32093. info('page=' + pageNum + ' - getOperatorList: time=' +
  32094. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  32095. }, function(e) {
  32096. var minimumStackMessage =
  32097. 'worker.js: while trying to getPage() and getOperatorList()';
  32098. var wrappedException;
  32099. // Turn the error into an obj that can be serialized
  32100. if (typeof e === 'string') {
  32101. wrappedException = {
  32102. message: e,
  32103. stack: minimumStackMessage
  32104. };
  32105. } else if (typeof e === 'object') {
  32106. wrappedException = {
  32107. message: e.message || e.toString(),
  32108. stack: e.stack || minimumStackMessage
  32109. };
  32110. } else {
  32111. wrappedException = {
  32112. message: 'Unknown exception type: ' + (typeof e),
  32113. stack: minimumStackMessage
  32114. };
  32115. }
  32116. handler.send('PageError', {
  32117. pageNum: pageNum,
  32118. error: wrappedException,
  32119. intent: data.intent
  32120. });
  32121. });
  32122. });
  32123. }, this);
  32124. handler.on('GetTextContent', function wphExtractText(data) {
  32125. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32126. var pageNum = data.pageIndex + 1;
  32127. var start = Date.now();
  32128. return page.extractTextContent().then(function(textContent) {
  32129. info('text indexing: page=' + pageNum + ' - time=' +
  32130. (Date.now() - start) + 'ms');
  32131. return textContent;
  32132. });
  32133. });
  32134. });
  32135. handler.on('Cleanup', function wphCleanup(data) {
  32136. return pdfManager.cleanup();
  32137. });
  32138. handler.on('Terminate', function wphTerminate(data) {
  32139. pdfManager.terminate();
  32140. });
  32141. }
  32142. };
  32143. var consoleTimer = {};
  32144. var workerConsole = {
  32145. log: function log() {
  32146. var args = Array.prototype.slice.call(arguments);
  32147. globalScope.postMessage({
  32148. action: 'console_log',
  32149. data: args
  32150. });
  32151. },
  32152. error: function error() {
  32153. var args = Array.prototype.slice.call(arguments);
  32154. globalScope.postMessage({
  32155. action: 'console_error',
  32156. data: args
  32157. });
  32158. throw 'pdf.js execution error';
  32159. },
  32160. time: function time(name) {
  32161. consoleTimer[name] = Date.now();
  32162. },
  32163. timeEnd: function timeEnd(name) {
  32164. var time = consoleTimer[name];
  32165. if (!time) {
  32166. error('Unknown timer name ' + name);
  32167. }
  32168. this.log('Timer:', name, Date.now() - time);
  32169. }
  32170. };
  32171. // Worker thread?
  32172. if (typeof window === 'undefined') {
  32173. if (!('console' in globalScope)) {
  32174. globalScope.console = workerConsole;
  32175. }
  32176. // Listen for unsupported features so we can pass them on to the main thread.
  32177. PDFJS.UnsupportedManager.listen(function (msg) {
  32178. globalScope.postMessage({
  32179. action: '_unsupported_feature',
  32180. data: msg
  32181. });
  32182. });
  32183. var handler = new MessageHandler('worker_processor', this);
  32184. WorkerMessageHandler.setup(handler);
  32185. }
  32186. /* This class implements the QM Coder decoding as defined in
  32187. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32188. * Annex C.3 Arithmetic decoding procedure
  32189. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32190. *
  32191. * The arithmetic decoder is used in conjunction with context models to decode
  32192. * JPEG2000 and JBIG2 streams.
  32193. */
  32194. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32195. // Table C-2
  32196. var QeTable = [
  32197. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32198. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32199. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32200. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32201. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32202. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32203. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32204. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32205. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32206. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32207. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32208. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32209. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32210. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32211. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32212. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32213. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32214. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32215. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32216. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32217. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32218. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32219. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32220. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32221. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32222. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32223. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32224. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32225. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32226. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32227. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32228. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32229. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32230. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32231. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32232. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32233. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32234. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32235. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32236. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32237. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32238. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32239. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32240. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32241. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32242. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32243. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32244. ];
  32245. // C.3.5 Initialisation of the decoder (INITDEC)
  32246. function ArithmeticDecoder(data, start, end) {
  32247. this.data = data;
  32248. this.bp = start;
  32249. this.dataEnd = end;
  32250. this.chigh = data[start];
  32251. this.clow = 0;
  32252. this.byteIn();
  32253. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32254. this.clow = (this.clow << 7) & 0xFFFF;
  32255. this.ct -= 7;
  32256. this.a = 0x8000;
  32257. }
  32258. ArithmeticDecoder.prototype = {
  32259. // C.3.4 Compressed data input (BYTEIN)
  32260. byteIn: function ArithmeticDecoder_byteIn() {
  32261. var data = this.data;
  32262. var bp = this.bp;
  32263. if (data[bp] === 0xFF) {
  32264. var b1 = data[bp + 1];
  32265. if (b1 > 0x8F) {
  32266. this.clow += 0xFF00;
  32267. this.ct = 8;
  32268. } else {
  32269. bp++;
  32270. this.clow += (data[bp] << 9);
  32271. this.ct = 7;
  32272. this.bp = bp;
  32273. }
  32274. } else {
  32275. bp++;
  32276. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32277. this.ct = 8;
  32278. this.bp = bp;
  32279. }
  32280. if (this.clow > 0xFFFF) {
  32281. this.chigh += (this.clow >> 16);
  32282. this.clow &= 0xFFFF;
  32283. }
  32284. },
  32285. // C.3.2 Decoding a decision (DECODE)
  32286. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32287. // contexts are packed into 1 byte:
  32288. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32289. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32290. var qeTableIcx = QeTable[cx_index];
  32291. var qeIcx = qeTableIcx.qe;
  32292. var d;
  32293. var a = this.a - qeIcx;
  32294. if (this.chigh < qeIcx) {
  32295. // exchangeLps
  32296. if (a < qeIcx) {
  32297. a = qeIcx;
  32298. d = cx_mps;
  32299. cx_index = qeTableIcx.nmps;
  32300. } else {
  32301. a = qeIcx;
  32302. d = 1 ^ cx_mps;
  32303. if (qeTableIcx.switchFlag === 1) {
  32304. cx_mps = d;
  32305. }
  32306. cx_index = qeTableIcx.nlps;
  32307. }
  32308. } else {
  32309. this.chigh -= qeIcx;
  32310. if ((a & 0x8000) !== 0) {
  32311. this.a = a;
  32312. return cx_mps;
  32313. }
  32314. // exchangeMps
  32315. if (a < qeIcx) {
  32316. d = 1 ^ cx_mps;
  32317. if (qeTableIcx.switchFlag === 1) {
  32318. cx_mps = d;
  32319. }
  32320. cx_index = qeTableIcx.nlps;
  32321. } else {
  32322. d = cx_mps;
  32323. cx_index = qeTableIcx.nmps;
  32324. }
  32325. }
  32326. // C.3.3 renormD;
  32327. do {
  32328. if (this.ct === 0) {
  32329. this.byteIn();
  32330. }
  32331. a <<= 1;
  32332. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32333. this.clow = (this.clow << 1) & 0xFFFF;
  32334. this.ct--;
  32335. } while ((a & 0x8000) === 0);
  32336. this.a = a;
  32337. contexts[pos] = cx_index << 1 | cx_mps;
  32338. return d;
  32339. }
  32340. };
  32341. return ArithmeticDecoder;
  32342. })();
  32343. var JpegImage = (function jpegImage() {
  32344. var dctZigZag = new Uint8Array([
  32345. 0,
  32346. 1, 8,
  32347. 16, 9, 2,
  32348. 3, 10, 17, 24,
  32349. 32, 25, 18, 11, 4,
  32350. 5, 12, 19, 26, 33, 40,
  32351. 48, 41, 34, 27, 20, 13, 6,
  32352. 7, 14, 21, 28, 35, 42, 49, 56,
  32353. 57, 50, 43, 36, 29, 22, 15,
  32354. 23, 30, 37, 44, 51, 58,
  32355. 59, 52, 45, 38, 31,
  32356. 39, 46, 53, 60,
  32357. 61, 54, 47,
  32358. 55, 62,
  32359. 63
  32360. ]);
  32361. var dctCos1 = 4017; // cos(pi/16)
  32362. var dctSin1 = 799; // sin(pi/16)
  32363. var dctCos3 = 3406; // cos(3*pi/16)
  32364. var dctSin3 = 2276; // sin(3*pi/16)
  32365. var dctCos6 = 1567; // cos(6*pi/16)
  32366. var dctSin6 = 3784; // sin(6*pi/16)
  32367. var dctSqrt2 = 5793; // sqrt(2)
  32368. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32369. function constructor() {
  32370. }
  32371. function buildHuffmanTable(codeLengths, values) {
  32372. var k = 0, code = [], i, j, length = 16;
  32373. while (length > 0 && !codeLengths[length - 1]) {
  32374. length--;
  32375. }
  32376. code.push({children: [], index: 0});
  32377. var p = code[0], q;
  32378. for (i = 0; i < length; i++) {
  32379. for (j = 0; j < codeLengths[i]; j++) {
  32380. p = code.pop();
  32381. p.children[p.index] = values[k];
  32382. while (p.index > 0) {
  32383. p = code.pop();
  32384. }
  32385. p.index++;
  32386. code.push(p);
  32387. while (code.length <= i) {
  32388. code.push(q = {children: [], index: 0});
  32389. p.children[p.index] = q.children;
  32390. p = q;
  32391. }
  32392. k++;
  32393. }
  32394. if (i + 1 < length) {
  32395. // p here points to last code
  32396. code.push(q = {children: [], index: 0});
  32397. p.children[p.index] = q.children;
  32398. p = q;
  32399. }
  32400. }
  32401. return code[0].children;
  32402. }
  32403. function getBlockBufferOffset(component, row, col) {
  32404. return 64 * ((component.blocksPerLine + 1) * row + col);
  32405. }
  32406. function decodeScan(data, offset, frame, components, resetInterval,
  32407. spectralStart, spectralEnd, successivePrev, successive) {
  32408. var precision = frame.precision;
  32409. var samplesPerLine = frame.samplesPerLine;
  32410. var scanLines = frame.scanLines;
  32411. var mcusPerLine = frame.mcusPerLine;
  32412. var progressive = frame.progressive;
  32413. var maxH = frame.maxH, maxV = frame.maxV;
  32414. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32415. function readBit() {
  32416. if (bitsCount > 0) {
  32417. bitsCount--;
  32418. return (bitsData >> bitsCount) & 1;
  32419. }
  32420. bitsData = data[offset++];
  32421. if (bitsData === 0xFF) {
  32422. var nextByte = data[offset++];
  32423. if (nextByte) {
  32424. throw 'unexpected marker: ' +
  32425. ((bitsData << 8) | nextByte).toString(16);
  32426. }
  32427. // unstuff 0
  32428. }
  32429. bitsCount = 7;
  32430. return bitsData >>> 7;
  32431. }
  32432. function decodeHuffman(tree) {
  32433. var node = tree;
  32434. while (true) {
  32435. node = node[readBit()];
  32436. if (typeof node === 'number') {
  32437. return node;
  32438. }
  32439. if (typeof node !== 'object') {
  32440. throw 'invalid huffman sequence';
  32441. }
  32442. }
  32443. }
  32444. function receive(length) {
  32445. var n = 0;
  32446. while (length > 0) {
  32447. n = (n << 1) | readBit();
  32448. length--;
  32449. }
  32450. return n;
  32451. }
  32452. function receiveAndExtend(length) {
  32453. if (length === 1) {
  32454. return readBit() === 1 ? 1 : -1;
  32455. }
  32456. var n = receive(length);
  32457. if (n >= 1 << (length - 1)) {
  32458. return n;
  32459. }
  32460. return n + (-1 << length) + 1;
  32461. }
  32462. function decodeBaseline(component, offset) {
  32463. var t = decodeHuffman(component.huffmanTableDC);
  32464. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32465. component.blockData[offset] = (component.pred += diff);
  32466. var k = 1;
  32467. while (k < 64) {
  32468. var rs = decodeHuffman(component.huffmanTableAC);
  32469. var s = rs & 15, r = rs >> 4;
  32470. if (s === 0) {
  32471. if (r < 15) {
  32472. break;
  32473. }
  32474. k += 16;
  32475. continue;
  32476. }
  32477. k += r;
  32478. var z = dctZigZag[k];
  32479. component.blockData[offset + z] = receiveAndExtend(s);
  32480. k++;
  32481. }
  32482. }
  32483. function decodeDCFirst(component, offset) {
  32484. var t = decodeHuffman(component.huffmanTableDC);
  32485. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32486. component.blockData[offset] = (component.pred += diff);
  32487. }
  32488. function decodeDCSuccessive(component, offset) {
  32489. component.blockData[offset] |= readBit() << successive;
  32490. }
  32491. var eobrun = 0;
  32492. function decodeACFirst(component, offset) {
  32493. if (eobrun > 0) {
  32494. eobrun--;
  32495. return;
  32496. }
  32497. var k = spectralStart, e = spectralEnd;
  32498. while (k <= e) {
  32499. var rs = decodeHuffman(component.huffmanTableAC);
  32500. var s = rs & 15, r = rs >> 4;
  32501. if (s === 0) {
  32502. if (r < 15) {
  32503. eobrun = receive(r) + (1 << r) - 1;
  32504. break;
  32505. }
  32506. k += 16;
  32507. continue;
  32508. }
  32509. k += r;
  32510. var z = dctZigZag[k];
  32511. component.blockData[offset + z] =
  32512. receiveAndExtend(s) * (1 << successive);
  32513. k++;
  32514. }
  32515. }
  32516. var successiveACState = 0, successiveACNextValue;
  32517. function decodeACSuccessive(component, offset) {
  32518. var k = spectralStart;
  32519. var e = spectralEnd;
  32520. var r = 0;
  32521. var s;
  32522. var rs;
  32523. while (k <= e) {
  32524. var z = dctZigZag[k];
  32525. switch (successiveACState) {
  32526. case 0: // initial state
  32527. rs = decodeHuffman(component.huffmanTableAC);
  32528. s = rs & 15;
  32529. r = rs >> 4;
  32530. if (s === 0) {
  32531. if (r < 15) {
  32532. eobrun = receive(r) + (1 << r);
  32533. successiveACState = 4;
  32534. } else {
  32535. r = 16;
  32536. successiveACState = 1;
  32537. }
  32538. } else {
  32539. if (s !== 1) {
  32540. throw 'invalid ACn encoding';
  32541. }
  32542. successiveACNextValue = receiveAndExtend(s);
  32543. successiveACState = r ? 2 : 3;
  32544. }
  32545. continue;
  32546. case 1: // skipping r zero items
  32547. case 2:
  32548. if (component.blockData[offset + z]) {
  32549. component.blockData[offset + z] += (readBit() << successive);
  32550. } else {
  32551. r--;
  32552. if (r === 0) {
  32553. successiveACState = successiveACState === 2 ? 3 : 0;
  32554. }
  32555. }
  32556. break;
  32557. case 3: // set value for a zero item
  32558. if (component.blockData[offset + z]) {
  32559. component.blockData[offset + z] += (readBit() << successive);
  32560. } else {
  32561. component.blockData[offset + z] =
  32562. successiveACNextValue << successive;
  32563. successiveACState = 0;
  32564. }
  32565. break;
  32566. case 4: // eob
  32567. if (component.blockData[offset + z]) {
  32568. component.blockData[offset + z] += (readBit() << successive);
  32569. }
  32570. break;
  32571. }
  32572. k++;
  32573. }
  32574. if (successiveACState === 4) {
  32575. eobrun--;
  32576. if (eobrun === 0) {
  32577. successiveACState = 0;
  32578. }
  32579. }
  32580. }
  32581. function decodeMcu(component, decode, mcu, row, col) {
  32582. var mcuRow = (mcu / mcusPerLine) | 0;
  32583. var mcuCol = mcu % mcusPerLine;
  32584. var blockRow = mcuRow * component.v + row;
  32585. var blockCol = mcuCol * component.h + col;
  32586. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32587. decode(component, offset);
  32588. }
  32589. function decodeBlock(component, decode, mcu) {
  32590. var blockRow = (mcu / component.blocksPerLine) | 0;
  32591. var blockCol = mcu % component.blocksPerLine;
  32592. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32593. decode(component, offset);
  32594. }
  32595. var componentsLength = components.length;
  32596. var component, i, j, k, n;
  32597. var decodeFn;
  32598. if (progressive) {
  32599. if (spectralStart === 0) {
  32600. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32601. } else {
  32602. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32603. }
  32604. } else {
  32605. decodeFn = decodeBaseline;
  32606. }
  32607. var mcu = 0, marker;
  32608. var mcuExpected;
  32609. if (componentsLength === 1) {
  32610. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32611. } else {
  32612. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32613. }
  32614. if (!resetInterval) {
  32615. resetInterval = mcuExpected;
  32616. }
  32617. var h, v;
  32618. while (mcu < mcuExpected) {
  32619. // reset interval stuff
  32620. for (i = 0; i < componentsLength; i++) {
  32621. components[i].pred = 0;
  32622. }
  32623. eobrun = 0;
  32624. if (componentsLength === 1) {
  32625. component = components[0];
  32626. for (n = 0; n < resetInterval; n++) {
  32627. decodeBlock(component, decodeFn, mcu);
  32628. mcu++;
  32629. }
  32630. } else {
  32631. for (n = 0; n < resetInterval; n++) {
  32632. for (i = 0; i < componentsLength; i++) {
  32633. component = components[i];
  32634. h = component.h;
  32635. v = component.v;
  32636. for (j = 0; j < v; j++) {
  32637. for (k = 0; k < h; k++) {
  32638. decodeMcu(component, decodeFn, mcu, j, k);
  32639. }
  32640. }
  32641. }
  32642. mcu++;
  32643. }
  32644. }
  32645. // find marker
  32646. bitsCount = 0;
  32647. marker = (data[offset] << 8) | data[offset + 1];
  32648. if (marker <= 0xFF00) {
  32649. throw 'marker was not found';
  32650. }
  32651. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32652. offset += 2;
  32653. } else {
  32654. break;
  32655. }
  32656. }
  32657. return offset - startOffset;
  32658. }
  32659. // A port of poppler's IDCT method which in turn is taken from:
  32660. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32661. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32662. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32663. // 988-991.
  32664. function quantizeAndInverse(component, blockBufferOffset, p) {
  32665. var qt = component.quantizationTable, blockData = component.blockData;
  32666. var v0, v1, v2, v3, v4, v5, v6, v7;
  32667. var p0, p1, p2, p3, p4, p5, p6, p7;
  32668. var t;
  32669. // inverse DCT on rows
  32670. for (var row = 0; row < 64; row += 8) {
  32671. // gather block data
  32672. p0 = blockData[blockBufferOffset + row];
  32673. p1 = blockData[blockBufferOffset + row + 1];
  32674. p2 = blockData[blockBufferOffset + row + 2];
  32675. p3 = blockData[blockBufferOffset + row + 3];
  32676. p4 = blockData[blockBufferOffset + row + 4];
  32677. p5 = blockData[blockBufferOffset + row + 5];
  32678. p6 = blockData[blockBufferOffset + row + 6];
  32679. p7 = blockData[blockBufferOffset + row + 7];
  32680. // dequant p0
  32681. p0 *= qt[row];
  32682. // check for all-zero AC coefficients
  32683. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32684. t = (dctSqrt2 * p0 + 512) >> 10;
  32685. p[row] = t;
  32686. p[row + 1] = t;
  32687. p[row + 2] = t;
  32688. p[row + 3] = t;
  32689. p[row + 4] = t;
  32690. p[row + 5] = t;
  32691. p[row + 6] = t;
  32692. p[row + 7] = t;
  32693. continue;
  32694. }
  32695. // dequant p1 ... p7
  32696. p1 *= qt[row + 1];
  32697. p2 *= qt[row + 2];
  32698. p3 *= qt[row + 3];
  32699. p4 *= qt[row + 4];
  32700. p5 *= qt[row + 5];
  32701. p6 *= qt[row + 6];
  32702. p7 *= qt[row + 7];
  32703. // stage 4
  32704. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32705. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32706. v2 = p2;
  32707. v3 = p6;
  32708. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32709. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32710. v5 = p3 << 4;
  32711. v6 = p5 << 4;
  32712. // stage 3
  32713. v0 = (v0 + v1 + 1) >> 1;
  32714. v1 = v0 - v1;
  32715. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32716. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32717. v3 = t;
  32718. v4 = (v4 + v6 + 1) >> 1;
  32719. v6 = v4 - v6;
  32720. v7 = (v7 + v5 + 1) >> 1;
  32721. v5 = v7 - v5;
  32722. // stage 2
  32723. v0 = (v0 + v3 + 1) >> 1;
  32724. v3 = v0 - v3;
  32725. v1 = (v1 + v2 + 1) >> 1;
  32726. v2 = v1 - v2;
  32727. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32728. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32729. v7 = t;
  32730. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32731. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32732. v6 = t;
  32733. // stage 1
  32734. p[row] = v0 + v7;
  32735. p[row + 7] = v0 - v7;
  32736. p[row + 1] = v1 + v6;
  32737. p[row + 6] = v1 - v6;
  32738. p[row + 2] = v2 + v5;
  32739. p[row + 5] = v2 - v5;
  32740. p[row + 3] = v3 + v4;
  32741. p[row + 4] = v3 - v4;
  32742. }
  32743. // inverse DCT on columns
  32744. for (var col = 0; col < 8; ++col) {
  32745. p0 = p[col];
  32746. p1 = p[col + 8];
  32747. p2 = p[col + 16];
  32748. p3 = p[col + 24];
  32749. p4 = p[col + 32];
  32750. p5 = p[col + 40];
  32751. p6 = p[col + 48];
  32752. p7 = p[col + 56];
  32753. // check for all-zero AC coefficients
  32754. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32755. t = (dctSqrt2 * p0 + 8192) >> 14;
  32756. // convert to 8 bit
  32757. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32758. blockData[blockBufferOffset + col] = t;
  32759. blockData[blockBufferOffset + col + 8] = t;
  32760. blockData[blockBufferOffset + col + 16] = t;
  32761. blockData[blockBufferOffset + col + 24] = t;
  32762. blockData[blockBufferOffset + col + 32] = t;
  32763. blockData[blockBufferOffset + col + 40] = t;
  32764. blockData[blockBufferOffset + col + 48] = t;
  32765. blockData[blockBufferOffset + col + 56] = t;
  32766. continue;
  32767. }
  32768. // stage 4
  32769. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32770. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32771. v2 = p2;
  32772. v3 = p6;
  32773. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32774. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32775. v5 = p3;
  32776. v6 = p5;
  32777. // stage 3
  32778. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32779. // converting to UInt8 range later.
  32780. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32781. v1 = v0 - v1;
  32782. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32783. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32784. v3 = t;
  32785. v4 = (v4 + v6 + 1) >> 1;
  32786. v6 = v4 - v6;
  32787. v7 = (v7 + v5 + 1) >> 1;
  32788. v5 = v7 - v5;
  32789. // stage 2
  32790. v0 = (v0 + v3 + 1) >> 1;
  32791. v3 = v0 - v3;
  32792. v1 = (v1 + v2 + 1) >> 1;
  32793. v2 = v1 - v2;
  32794. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32795. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32796. v7 = t;
  32797. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32798. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32799. v6 = t;
  32800. // stage 1
  32801. p0 = v0 + v7;
  32802. p7 = v0 - v7;
  32803. p1 = v1 + v6;
  32804. p6 = v1 - v6;
  32805. p2 = v2 + v5;
  32806. p5 = v2 - v5;
  32807. p3 = v3 + v4;
  32808. p4 = v3 - v4;
  32809. // convert to 8-bit integers
  32810. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32811. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32812. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32813. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32814. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32815. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32816. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32817. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32818. // store block data
  32819. blockData[blockBufferOffset + col] = p0;
  32820. blockData[blockBufferOffset + col + 8] = p1;
  32821. blockData[blockBufferOffset + col + 16] = p2;
  32822. blockData[blockBufferOffset + col + 24] = p3;
  32823. blockData[blockBufferOffset + col + 32] = p4;
  32824. blockData[blockBufferOffset + col + 40] = p5;
  32825. blockData[blockBufferOffset + col + 48] = p6;
  32826. blockData[blockBufferOffset + col + 56] = p7;
  32827. }
  32828. }
  32829. function buildComponentData(frame, component) {
  32830. var blocksPerLine = component.blocksPerLine;
  32831. var blocksPerColumn = component.blocksPerColumn;
  32832. var computationBuffer = new Int16Array(64);
  32833. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32834. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32835. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32836. quantizeAndInverse(component, offset, computationBuffer);
  32837. }
  32838. }
  32839. return component.blockData;
  32840. }
  32841. function clamp0to255(a) {
  32842. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32843. }
  32844. constructor.prototype = {
  32845. parse: function parse(data) {
  32846. function readUint16() {
  32847. var value = (data[offset] << 8) | data[offset + 1];
  32848. offset += 2;
  32849. return value;
  32850. }
  32851. function readDataBlock() {
  32852. var length = readUint16();
  32853. var array = data.subarray(offset, offset + length - 2);
  32854. offset += array.length;
  32855. return array;
  32856. }
  32857. function prepareComponents(frame) {
  32858. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32859. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32860. for (var i = 0; i < frame.components.length; i++) {
  32861. component = frame.components[i];
  32862. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32863. component.h / frame.maxH);
  32864. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32865. component.v / frame.maxV);
  32866. var blocksPerLineForMcu = mcusPerLine * component.h;
  32867. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32868. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32869. (blocksPerLineForMcu + 1);
  32870. component.blockData = new Int16Array(blocksBufferSize);
  32871. component.blocksPerLine = blocksPerLine;
  32872. component.blocksPerColumn = blocksPerColumn;
  32873. }
  32874. frame.mcusPerLine = mcusPerLine;
  32875. frame.mcusPerColumn = mcusPerColumn;
  32876. }
  32877. var offset = 0, length = data.length;
  32878. var jfif = null;
  32879. var adobe = null;
  32880. var pixels = null;
  32881. var frame, resetInterval;
  32882. var quantizationTables = [];
  32883. var huffmanTablesAC = [], huffmanTablesDC = [];
  32884. var fileMarker = readUint16();
  32885. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32886. throw 'SOI not found';
  32887. }
  32888. fileMarker = readUint16();
  32889. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32890. var i, j, l;
  32891. switch(fileMarker) {
  32892. case 0xFFE0: // APP0 (Application Specific)
  32893. case 0xFFE1: // APP1
  32894. case 0xFFE2: // APP2
  32895. case 0xFFE3: // APP3
  32896. case 0xFFE4: // APP4
  32897. case 0xFFE5: // APP5
  32898. case 0xFFE6: // APP6
  32899. case 0xFFE7: // APP7
  32900. case 0xFFE8: // APP8
  32901. case 0xFFE9: // APP9
  32902. case 0xFFEA: // APP10
  32903. case 0xFFEB: // APP11
  32904. case 0xFFEC: // APP12
  32905. case 0xFFED: // APP13
  32906. case 0xFFEE: // APP14
  32907. case 0xFFEF: // APP15
  32908. case 0xFFFE: // COM (Comment)
  32909. var appData = readDataBlock();
  32910. if (fileMarker === 0xFFE0) {
  32911. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32912. appData[2] === 0x49 && appData[3] === 0x46 &&
  32913. appData[4] === 0) { // 'JFIF\x00'
  32914. jfif = {
  32915. version: { major: appData[5], minor: appData[6] },
  32916. densityUnits: appData[7],
  32917. xDensity: (appData[8] << 8) | appData[9],
  32918. yDensity: (appData[10] << 8) | appData[11],
  32919. thumbWidth: appData[12],
  32920. thumbHeight: appData[13],
  32921. thumbData: appData.subarray(14, 14 +
  32922. 3 * appData[12] * appData[13])
  32923. };
  32924. }
  32925. }
  32926. // TODO APP1 - Exif
  32927. if (fileMarker === 0xFFEE) {
  32928. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32929. appData[2] === 0x6F && appData[3] === 0x62 &&
  32930. appData[4] === 0x65) { // 'Adobe'
  32931. adobe = {
  32932. version: (appData[5] << 8) | appData[6],
  32933. flags0: (appData[7] << 8) | appData[8],
  32934. flags1: (appData[9] << 8) | appData[10],
  32935. transformCode: appData[11]
  32936. };
  32937. }
  32938. }
  32939. break;
  32940. case 0xFFDB: // DQT (Define Quantization Tables)
  32941. var quantizationTablesLength = readUint16();
  32942. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32943. var z;
  32944. while (offset < quantizationTablesEnd) {
  32945. var quantizationTableSpec = data[offset++];
  32946. var tableData = new Uint16Array(64);
  32947. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32948. for (j = 0; j < 64; j++) {
  32949. z = dctZigZag[j];
  32950. tableData[z] = data[offset++];
  32951. }
  32952. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32953. for (j = 0; j < 64; j++) {
  32954. z = dctZigZag[j];
  32955. tableData[z] = readUint16();
  32956. }
  32957. } else {
  32958. throw 'DQT: invalid table spec';
  32959. }
  32960. quantizationTables[quantizationTableSpec & 15] = tableData;
  32961. }
  32962. break;
  32963. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32964. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32965. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32966. if (frame) {
  32967. throw 'Only single frame JPEGs supported';
  32968. }
  32969. readUint16(); // skip data length
  32970. frame = {};
  32971. frame.extended = (fileMarker === 0xFFC1);
  32972. frame.progressive = (fileMarker === 0xFFC2);
  32973. frame.precision = data[offset++];
  32974. frame.scanLines = readUint16();
  32975. frame.samplesPerLine = readUint16();
  32976. frame.components = [];
  32977. frame.componentIds = {};
  32978. var componentsCount = data[offset++], componentId;
  32979. var maxH = 0, maxV = 0;
  32980. for (i = 0; i < componentsCount; i++) {
  32981. componentId = data[offset];
  32982. var h = data[offset + 1] >> 4;
  32983. var v = data[offset + 1] & 15;
  32984. if (maxH < h) {
  32985. maxH = h;
  32986. }
  32987. if (maxV < v) {
  32988. maxV = v;
  32989. }
  32990. var qId = data[offset + 2];
  32991. l = frame.components.push({
  32992. h: h,
  32993. v: v,
  32994. quantizationTable: quantizationTables[qId]
  32995. });
  32996. frame.componentIds[componentId] = l - 1;
  32997. offset += 3;
  32998. }
  32999. frame.maxH = maxH;
  33000. frame.maxV = maxV;
  33001. prepareComponents(frame);
  33002. break;
  33003. case 0xFFC4: // DHT (Define Huffman Tables)
  33004. var huffmanLength = readUint16();
  33005. for (i = 2; i < huffmanLength;) {
  33006. var huffmanTableSpec = data[offset++];
  33007. var codeLengths = new Uint8Array(16);
  33008. var codeLengthSum = 0;
  33009. for (j = 0; j < 16; j++, offset++) {
  33010. codeLengthSum += (codeLengths[j] = data[offset]);
  33011. }
  33012. var huffmanValues = new Uint8Array(codeLengthSum);
  33013. for (j = 0; j < codeLengthSum; j++, offset++) {
  33014. huffmanValues[j] = data[offset];
  33015. }
  33016. i += 17 + codeLengthSum;
  33017. ((huffmanTableSpec >> 4) === 0 ?
  33018. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33019. buildHuffmanTable(codeLengths, huffmanValues);
  33020. }
  33021. break;
  33022. case 0xFFDD: // DRI (Define Restart Interval)
  33023. readUint16(); // skip data length
  33024. resetInterval = readUint16();
  33025. break;
  33026. case 0xFFDA: // SOS (Start of Scan)
  33027. var scanLength = readUint16();
  33028. var selectorsCount = data[offset++];
  33029. var components = [], component;
  33030. for (i = 0; i < selectorsCount; i++) {
  33031. var componentIndex = frame.componentIds[data[offset++]];
  33032. component = frame.components[componentIndex];
  33033. var tableSpec = data[offset++];
  33034. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33035. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33036. components.push(component);
  33037. }
  33038. var spectralStart = data[offset++];
  33039. var spectralEnd = data[offset++];
  33040. var successiveApproximation = data[offset++];
  33041. var processed = decodeScan(data, offset,
  33042. frame, components, resetInterval,
  33043. spectralStart, spectralEnd,
  33044. successiveApproximation >> 4, successiveApproximation & 15);
  33045. offset += processed;
  33046. break;
  33047. case 0xFFFF: // Fill bytes
  33048. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33049. offset--;
  33050. }
  33051. break;
  33052. default:
  33053. if (data[offset - 3] === 0xFF &&
  33054. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33055. // could be incorrect encoding -- last 0xFF byte of the previous
  33056. // block was eaten by the encoder
  33057. offset -= 3;
  33058. break;
  33059. }
  33060. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33061. }
  33062. fileMarker = readUint16();
  33063. }
  33064. this.width = frame.samplesPerLine;
  33065. this.height = frame.scanLines;
  33066. this.jfif = jfif;
  33067. this.adobe = adobe;
  33068. this.components = [];
  33069. for (i = 0; i < frame.components.length; i++) {
  33070. component = frame.components[i];
  33071. this.components.push({
  33072. output: buildComponentData(frame, component),
  33073. scaleX: component.h / frame.maxH,
  33074. scaleY: component.v / frame.maxV,
  33075. blocksPerLine: component.blocksPerLine,
  33076. blocksPerColumn: component.blocksPerColumn
  33077. });
  33078. }
  33079. this.numComponents = this.components.length;
  33080. },
  33081. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33082. var scaleX = this.width / width, scaleY = this.height / height;
  33083. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33084. var x, y, i, j, k;
  33085. var index;
  33086. var offset = 0;
  33087. var output;
  33088. var numComponents = this.components.length;
  33089. var dataLength = width * height * numComponents;
  33090. var data = new Uint8Array(dataLength);
  33091. var xScaleBlockOffset = new Uint32Array(width);
  33092. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33093. for (i = 0; i < numComponents; i++) {
  33094. component = this.components[i];
  33095. componentScaleX = component.scaleX * scaleX;
  33096. componentScaleY = component.scaleY * scaleY;
  33097. offset = i;
  33098. output = component.output;
  33099. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33100. // precalculate the xScaleBlockOffset
  33101. for (x = 0; x < width; x++) {
  33102. j = 0 | (x * componentScaleX);
  33103. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33104. }
  33105. // linearize the blocks of the component
  33106. for (y = 0; y < height; y++) {
  33107. j = 0 | (y * componentScaleY);
  33108. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33109. for (x = 0; x < width; x++) {
  33110. data[offset] = output[index + xScaleBlockOffset[x]];
  33111. offset += numComponents;
  33112. }
  33113. }
  33114. }
  33115. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33116. var transform = this.decodeTransform;
  33117. if (transform) {
  33118. for (i = 0; i < dataLength;) {
  33119. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33120. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33121. }
  33122. }
  33123. }
  33124. return data;
  33125. },
  33126. _isColorConversionNeeded: function isColorConversionNeeded() {
  33127. if (this.adobe && this.adobe.transformCode) {
  33128. // The adobe transform marker overrides any previous setting
  33129. return true;
  33130. } else if (this.numComponents === 3) {
  33131. return true;
  33132. } else {
  33133. return false;
  33134. }
  33135. },
  33136. _convertYccToRgb: function convertYccToRgb(data) {
  33137. var Y, Cb, Cr;
  33138. for (var i = 0, length = data.length; i < length; i += 3) {
  33139. Y = data[i ];
  33140. Cb = data[i + 1];
  33141. Cr = data[i + 2];
  33142. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33143. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33144. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33145. }
  33146. return data;
  33147. },
  33148. _convertYcckToRgb: function convertYcckToRgb(data) {
  33149. var Y, Cb, Cr, k;
  33150. var offset = 0;
  33151. for (var i = 0, length = data.length; i < length; i += 4) {
  33152. Y = data[i];
  33153. Cb = data[i + 1];
  33154. Cr = data[i + 2];
  33155. k = data[i + 3];
  33156. var r = -122.67195406894 +
  33157. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33158. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33159. 0.154362151871126) +
  33160. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33161. 0.00477271405408747 * k + 1.53380253221734) +
  33162. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33163. 0.48357088451265) +
  33164. k * (-0.000336197177618394 * k + 0.484791561490776);
  33165. var g = 107.268039397724 +
  33166. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33167. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33168. 0.176491792462875) +
  33169. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33170. 0.000770482631801132 * k - 0.151051492775562) +
  33171. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33172. 0.25802910206845) +
  33173. k * (-0.000318913117588328 * k - 0.213742400323665);
  33174. var b = -20.810012546947 +
  33175. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33176. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33177. 0.814272968359295) +
  33178. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33179. 0.000560833691242812 * k - 0.195152027534049) +
  33180. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33181. 0.116935020465145) +
  33182. k * (-0.000343531996510555 * k + 0.24165260232407);
  33183. data[offset++] = clamp0to255(r);
  33184. data[offset++] = clamp0to255(g);
  33185. data[offset++] = clamp0to255(b);
  33186. }
  33187. return data;
  33188. },
  33189. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33190. var Y, Cb, Cr;
  33191. for (var i = 0, length = data.length; i < length; i += 4) {
  33192. Y = data[i];
  33193. Cb = data[i + 1];
  33194. Cr = data[i + 2];
  33195. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33196. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33197. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33198. // K in data[i + 3] is unchanged
  33199. }
  33200. return data;
  33201. },
  33202. _convertCmykToRgb: function convertCmykToRgb(data) {
  33203. var c, m, y, k;
  33204. var offset = 0;
  33205. var min = -255 * 255 * 255;
  33206. var scale = 1 / 255 / 255;
  33207. for (var i = 0, length = data.length; i < length; i += 4) {
  33208. c = data[i];
  33209. m = data[i + 1];
  33210. y = data[i + 2];
  33211. k = data[i + 3];
  33212. var r =
  33213. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33214. 18.82290502165302 * y + 212.25662451639585 * k -
  33215. 72734.4411664936) +
  33216. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33217. 17.873870861415444 * k - 1401.7366389350734) +
  33218. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33219. 4465.541406466231) -
  33220. k * (21.86122147463605 * k + 48317.86113160301);
  33221. var g =
  33222. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33223. 6.871425592049007 * y + 31.159100130055922 * k -
  33224. 20220.756542821975) +
  33225. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33226. 131.35250912493976 * k - 48691.05921601825) +
  33227. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33228. 6341.191035517494) -
  33229. k * (20.737325471181034 * k + 47890.15695978492);
  33230. var b =
  33231. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33232. 30.89978309703729 * y - 0.23883238689178934 * k -
  33233. 3616.812083916688) +
  33234. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33235. 50.606957656360734 * k - 28620.90484698408) +
  33236. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33237. 49363.43385999684) -
  33238. k * (22.33816807309886 * k + 45932.16563550634);
  33239. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33240. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33241. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33242. }
  33243. return data;
  33244. },
  33245. getData: function getData(width, height, forceRGBoutput) {
  33246. if (this.numComponents > 4) {
  33247. throw 'Unsupported color mode';
  33248. }
  33249. // type of data: Uint8Array(width * height * numComponents)
  33250. var data = this._getLinearizedBlockData(width, height);
  33251. if (this.numComponents === 3) {
  33252. return this._convertYccToRgb(data);
  33253. } else if (this.numComponents === 4) {
  33254. if (this._isColorConversionNeeded()) {
  33255. if (forceRGBoutput) {
  33256. return this._convertYcckToRgb(data);
  33257. } else {
  33258. return this._convertYcckToCmyk(data);
  33259. }
  33260. } else if (forceRGBoutput) {
  33261. return this._convertCmykToRgb(data);
  33262. }
  33263. }
  33264. return data;
  33265. }
  33266. };
  33267. return constructor;
  33268. })();
  33269. var JpxImage = (function JpxImageClosure() {
  33270. // Table E.1
  33271. var SubbandsGainLog2 = {
  33272. 'LL': 0,
  33273. 'LH': 1,
  33274. 'HL': 1,
  33275. 'HH': 2
  33276. };
  33277. function JpxImage() {
  33278. this.failOnCorruptedImage = false;
  33279. }
  33280. JpxImage.prototype = {
  33281. parse: function JpxImage_parse(data) {
  33282. var head = readUint16(data, 0);
  33283. // No box header, immediate start of codestream (SOC)
  33284. if (head === 0xFF4F) {
  33285. this.parseCodestream(data, 0, data.length);
  33286. return;
  33287. }
  33288. var position = 0, length = data.length;
  33289. while (position < length) {
  33290. var headerSize = 8;
  33291. var lbox = readUint32(data, position);
  33292. var tbox = readUint32(data, position + 4);
  33293. position += headerSize;
  33294. if (lbox === 1) {
  33295. // XLBox: read UInt64 according to spec.
  33296. // JavaScript's int precision of 53 bit should be sufficient here.
  33297. lbox = readUint32(data, position) * 4294967296 +
  33298. readUint32(data, position + 4);
  33299. position += 8;
  33300. headerSize += 8;
  33301. }
  33302. if (lbox === 0) {
  33303. lbox = length - position + headerSize;
  33304. }
  33305. if (lbox < headerSize) {
  33306. throw new Error('JPX Error: Invalid box field size');
  33307. }
  33308. var dataLength = lbox - headerSize;
  33309. var jumpDataLength = true;
  33310. switch (tbox) {
  33311. case 0x6A703268: // 'jp2h'
  33312. jumpDataLength = false; // parsing child boxes
  33313. break;
  33314. case 0x636F6C72: // 'colr'
  33315. // Colorspaces are not used, the CS from the PDF is used.
  33316. var method = data[position];
  33317. var precedence = data[position + 1];
  33318. var approximation = data[position + 2];
  33319. if (method === 1) {
  33320. // enumerated colorspace
  33321. var colorspace = readUint32(data, position + 3);
  33322. switch (colorspace) {
  33323. case 16: // this indicates a sRGB colorspace
  33324. case 17: // this indicates a grayscale colorspace
  33325. case 18: // this indicates a YUV colorspace
  33326. break;
  33327. default:
  33328. warn('Unknown colorspace ' + colorspace);
  33329. break;
  33330. }
  33331. } else if (method === 2) {
  33332. info('ICC profile not supported');
  33333. }
  33334. break;
  33335. case 0x6A703263: // 'jp2c'
  33336. this.parseCodestream(data, position, position + dataLength);
  33337. break;
  33338. case 0x6A502020: // 'jP\024\024'
  33339. if (0x0d0a870a !== readUint32(data, position)) {
  33340. warn('Invalid JP2 signature');
  33341. }
  33342. break;
  33343. // The following header types are valid but currently not used:
  33344. case 0x6A501A1A: // 'jP\032\032'
  33345. case 0x66747970: // 'ftyp'
  33346. case 0x72726571: // 'rreq'
  33347. case 0x72657320: // 'res '
  33348. case 0x69686472: // 'ihdr'
  33349. break;
  33350. default:
  33351. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33352. (tbox >> 16) & 0xFF,
  33353. (tbox >> 8) & 0xFF,
  33354. tbox & 0xFF);
  33355. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33356. break;
  33357. }
  33358. if (jumpDataLength) {
  33359. position += dataLength;
  33360. }
  33361. }
  33362. },
  33363. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33364. var newByte = stream.getByte();
  33365. while (newByte >= 0) {
  33366. var oldByte = newByte;
  33367. newByte = stream.getByte();
  33368. var code = (oldByte << 8) | newByte;
  33369. // Image and tile size (SIZ)
  33370. if (code === 0xFF51) {
  33371. stream.skip(4);
  33372. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33373. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33374. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33375. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33376. stream.skip(16);
  33377. var Csiz = stream.getUint16(); // Byte 36
  33378. this.width = Xsiz - XOsiz;
  33379. this.height = Ysiz - YOsiz;
  33380. this.componentsCount = Csiz;
  33381. // Results are always returned as Uint8Arrays
  33382. this.bitsPerComponent = 8;
  33383. return;
  33384. }
  33385. }
  33386. throw new Error('JPX Error: No size marker found in JPX stream');
  33387. },
  33388. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33389. var context = {};
  33390. try {
  33391. var doNotRecover = false;
  33392. var position = start;
  33393. while (position + 1 < end) {
  33394. var code = readUint16(data, position);
  33395. position += 2;
  33396. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33397. switch (code) {
  33398. case 0xFF4F: // Start of codestream (SOC)
  33399. context.mainHeader = true;
  33400. break;
  33401. case 0xFFD9: // End of codestream (EOC)
  33402. break;
  33403. case 0xFF51: // Image and tile size (SIZ)
  33404. length = readUint16(data, position);
  33405. var siz = {};
  33406. siz.Xsiz = readUint32(data, position + 4);
  33407. siz.Ysiz = readUint32(data, position + 8);
  33408. siz.XOsiz = readUint32(data, position + 12);
  33409. siz.YOsiz = readUint32(data, position + 16);
  33410. siz.XTsiz = readUint32(data, position + 20);
  33411. siz.YTsiz = readUint32(data, position + 24);
  33412. siz.XTOsiz = readUint32(data, position + 28);
  33413. siz.YTOsiz = readUint32(data, position + 32);
  33414. var componentsCount = readUint16(data, position + 36);
  33415. siz.Csiz = componentsCount;
  33416. var components = [];
  33417. j = position + 38;
  33418. for (var i = 0; i < componentsCount; i++) {
  33419. var component = {
  33420. precision: (data[j] & 0x7F) + 1,
  33421. isSigned: !!(data[j] & 0x80),
  33422. XRsiz: data[j + 1],
  33423. YRsiz: data[j + 1]
  33424. };
  33425. calculateComponentDimensions(component, siz);
  33426. components.push(component);
  33427. }
  33428. context.SIZ = siz;
  33429. context.components = components;
  33430. calculateTileGrids(context, components);
  33431. context.QCC = [];
  33432. context.COC = [];
  33433. break;
  33434. case 0xFF5C: // Quantization default (QCD)
  33435. length = readUint16(data, position);
  33436. var qcd = {};
  33437. j = position + 2;
  33438. sqcd = data[j++];
  33439. switch (sqcd & 0x1F) {
  33440. case 0:
  33441. spqcdSize = 8;
  33442. scalarExpounded = true;
  33443. break;
  33444. case 1:
  33445. spqcdSize = 16;
  33446. scalarExpounded = false;
  33447. break;
  33448. case 2:
  33449. spqcdSize = 16;
  33450. scalarExpounded = true;
  33451. break;
  33452. default:
  33453. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33454. }
  33455. qcd.noQuantization = (spqcdSize === 8);
  33456. qcd.scalarExpounded = scalarExpounded;
  33457. qcd.guardBits = sqcd >> 5;
  33458. spqcds = [];
  33459. while (j < length + position) {
  33460. var spqcd = {};
  33461. if (spqcdSize === 8) {
  33462. spqcd.epsilon = data[j++] >> 3;
  33463. spqcd.mu = 0;
  33464. } else {
  33465. spqcd.epsilon = data[j] >> 3;
  33466. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33467. j += 2;
  33468. }
  33469. spqcds.push(spqcd);
  33470. }
  33471. qcd.SPqcds = spqcds;
  33472. if (context.mainHeader) {
  33473. context.QCD = qcd;
  33474. } else {
  33475. context.currentTile.QCD = qcd;
  33476. context.currentTile.QCC = [];
  33477. }
  33478. break;
  33479. case 0xFF5D: // Quantization component (QCC)
  33480. length = readUint16(data, position);
  33481. var qcc = {};
  33482. j = position + 2;
  33483. var cqcc;
  33484. if (context.SIZ.Csiz < 257) {
  33485. cqcc = data[j++];
  33486. } else {
  33487. cqcc = readUint16(data, j);
  33488. j += 2;
  33489. }
  33490. sqcd = data[j++];
  33491. switch (sqcd & 0x1F) {
  33492. case 0:
  33493. spqcdSize = 8;
  33494. scalarExpounded = true;
  33495. break;
  33496. case 1:
  33497. spqcdSize = 16;
  33498. scalarExpounded = false;
  33499. break;
  33500. case 2:
  33501. spqcdSize = 16;
  33502. scalarExpounded = true;
  33503. break;
  33504. default:
  33505. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33506. }
  33507. qcc.noQuantization = (spqcdSize === 8);
  33508. qcc.scalarExpounded = scalarExpounded;
  33509. qcc.guardBits = sqcd >> 5;
  33510. spqcds = [];
  33511. while (j < (length + position)) {
  33512. spqcd = {};
  33513. if (spqcdSize === 8) {
  33514. spqcd.epsilon = data[j++] >> 3;
  33515. spqcd.mu = 0;
  33516. } else {
  33517. spqcd.epsilon = data[j] >> 3;
  33518. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33519. j += 2;
  33520. }
  33521. spqcds.push(spqcd);
  33522. }
  33523. qcc.SPqcds = spqcds;
  33524. if (context.mainHeader) {
  33525. context.QCC[cqcc] = qcc;
  33526. } else {
  33527. context.currentTile.QCC[cqcc] = qcc;
  33528. }
  33529. break;
  33530. case 0xFF52: // Coding style default (COD)
  33531. length = readUint16(data, position);
  33532. var cod = {};
  33533. j = position + 2;
  33534. var scod = data[j++];
  33535. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33536. cod.sopMarkerUsed = !!(scod & 2);
  33537. cod.ephMarkerUsed = !!(scod & 4);
  33538. cod.progressionOrder = data[j++];
  33539. cod.layersCount = readUint16(data, j);
  33540. j += 2;
  33541. cod.multipleComponentTransform = data[j++];
  33542. cod.decompositionLevelsCount = data[j++];
  33543. cod.xcb = (data[j++] & 0xF) + 2;
  33544. cod.ycb = (data[j++] & 0xF) + 2;
  33545. var blockStyle = data[j++];
  33546. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33547. cod.resetContextProbabilities = !!(blockStyle & 2);
  33548. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33549. cod.verticalyStripe = !!(blockStyle & 8);
  33550. cod.predictableTermination = !!(blockStyle & 16);
  33551. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33552. cod.reversibleTransformation = data[j++];
  33553. if (cod.entropyCoderWithCustomPrecincts) {
  33554. var precinctsSizes = [];
  33555. while (j < length + position) {
  33556. var precinctsSize = data[j++];
  33557. precinctsSizes.push({
  33558. PPx: precinctsSize & 0xF,
  33559. PPy: precinctsSize >> 4
  33560. });
  33561. }
  33562. cod.precinctsSizes = precinctsSizes;
  33563. }
  33564. var unsupported = [];
  33565. if (cod.selectiveArithmeticCodingBypass) {
  33566. unsupported.push('selectiveArithmeticCodingBypass');
  33567. }
  33568. if (cod.resetContextProbabilities) {
  33569. unsupported.push('resetContextProbabilities');
  33570. }
  33571. if (cod.terminationOnEachCodingPass) {
  33572. unsupported.push('terminationOnEachCodingPass');
  33573. }
  33574. if (cod.verticalyStripe) {
  33575. unsupported.push('verticalyStripe');
  33576. }
  33577. if (cod.predictableTermination) {
  33578. unsupported.push('predictableTermination');
  33579. }
  33580. if (unsupported.length > 0) {
  33581. doNotRecover = true;
  33582. throw new Error('JPX Error: Unsupported COD options (' +
  33583. unsupported.join(', ') + ')');
  33584. }
  33585. if (context.mainHeader) {
  33586. context.COD = cod;
  33587. } else {
  33588. context.currentTile.COD = cod;
  33589. context.currentTile.COC = [];
  33590. }
  33591. break;
  33592. case 0xFF90: // Start of tile-part (SOT)
  33593. length = readUint16(data, position);
  33594. tile = {};
  33595. tile.index = readUint16(data, position + 2);
  33596. tile.length = readUint32(data, position + 4);
  33597. tile.dataEnd = tile.length + position - 2;
  33598. tile.partIndex = data[position + 8];
  33599. tile.partsCount = data[position + 9];
  33600. context.mainHeader = false;
  33601. if (tile.partIndex === 0) {
  33602. // reset component specific settings
  33603. tile.COD = context.COD;
  33604. tile.COC = context.COC.slice(0); // clone of the global COC
  33605. tile.QCD = context.QCD;
  33606. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33607. }
  33608. context.currentTile = tile;
  33609. break;
  33610. case 0xFF93: // Start of data (SOD)
  33611. tile = context.currentTile;
  33612. if (tile.partIndex === 0) {
  33613. initializeTile(context, tile.index);
  33614. buildPackets(context);
  33615. }
  33616. // moving to the end of the data
  33617. length = tile.dataEnd - position;
  33618. parseTilePackets(context, data, position, length);
  33619. break;
  33620. case 0xFF55: // Tile-part lengths, main header (TLM)
  33621. case 0xFF57: // Packet length, main header (PLM)
  33622. case 0xFF58: // Packet length, tile-part header (PLT)
  33623. case 0xFF64: // Comment (COM)
  33624. length = readUint16(data, position);
  33625. // skipping content
  33626. break;
  33627. case 0xFF53: // Coding style component (COC)
  33628. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33629. 'not implemented');
  33630. default:
  33631. throw new Error('JPX Error: Unknown codestream code: ' +
  33632. code.toString(16));
  33633. }
  33634. position += length;
  33635. }
  33636. } catch (e) {
  33637. if (doNotRecover || this.failOnCorruptedImage) {
  33638. throw e;
  33639. } else {
  33640. warn('Trying to recover from ' + e.message);
  33641. }
  33642. }
  33643. this.tiles = transformComponents(context);
  33644. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33645. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33646. this.componentsCount = context.SIZ.Csiz;
  33647. }
  33648. };
  33649. function calculateComponentDimensions(component, siz) {
  33650. // Section B.2 Component mapping
  33651. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33652. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33653. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33654. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33655. component.width = component.x1 - component.x0;
  33656. component.height = component.y1 - component.y0;
  33657. }
  33658. function calculateTileGrids(context, components) {
  33659. var siz = context.SIZ;
  33660. // Section B.3 Division into tile and tile-components
  33661. var tile, tiles = [];
  33662. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33663. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33664. for (var q = 0; q < numYtiles; q++) {
  33665. for (var p = 0; p < numXtiles; p++) {
  33666. tile = {};
  33667. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33668. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33669. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33670. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33671. tile.width = tile.tx1 - tile.tx0;
  33672. tile.height = tile.ty1 - tile.ty0;
  33673. tile.components = [];
  33674. tiles.push(tile);
  33675. }
  33676. }
  33677. context.tiles = tiles;
  33678. var componentsCount = siz.Csiz;
  33679. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33680. var component = components[i];
  33681. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33682. var tileComponent = {};
  33683. tile = tiles[j];
  33684. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33685. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33686. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33687. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33688. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33689. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33690. tile.components[i] = tileComponent;
  33691. }
  33692. }
  33693. }
  33694. function getBlocksDimensions(context, component, r) {
  33695. var codOrCoc = component.codingStyleParameters;
  33696. var result = {};
  33697. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33698. result.PPx = 15;
  33699. result.PPy = 15;
  33700. } else {
  33701. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33702. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33703. }
  33704. // calculate codeblock size as described in section B.7
  33705. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33706. Math.min(codOrCoc.xcb, result.PPx));
  33707. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33708. Math.min(codOrCoc.ycb, result.PPy));
  33709. return result;
  33710. }
  33711. function buildPrecincts(context, resolution, dimensions) {
  33712. // Section B.6 Division resolution to precincts
  33713. var precinctWidth = 1 << dimensions.PPx;
  33714. var precinctHeight = 1 << dimensions.PPy;
  33715. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33716. // to precincts. Precinct partition divides a resolution according to width
  33717. // and height parameters. The subband that belongs to the resolution level
  33718. // has a different size than the level, unless it is the zero resolution.
  33719. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33720. // The precinct partitioning for a particular subband is derived from a
  33721. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33722. // resolution level)... The LL band associated with each resolution level is
  33723. // divided into precincts... Each of the resulting precinct regions is then
  33724. // mapped into its child subbands (if any) at the next lower resolution
  33725. // level. This is accomplished by using the coordinate transformation
  33726. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33727. // coordinates of a point in the LL band and child subband, respectively.
  33728. var isZeroRes = resolution.resLevel === 0;
  33729. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33730. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33731. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33732. Math.ceil(resolution.trx1 / precinctWidth) -
  33733. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33734. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33735. Math.ceil(resolution.try1 / precinctHeight) -
  33736. Math.floor(resolution.try0 / precinctHeight) : 0);
  33737. var numprecincts = numprecinctswide * numprecinctshigh;
  33738. resolution.precinctParameters = {
  33739. precinctWidth: precinctWidth,
  33740. precinctHeight: precinctHeight,
  33741. numprecinctswide: numprecinctswide,
  33742. numprecinctshigh: numprecinctshigh,
  33743. numprecincts: numprecincts,
  33744. precinctWidthInSubband: precinctWidthInSubband,
  33745. precinctHeightInSubband: precinctHeightInSubband
  33746. };
  33747. }
  33748. function buildCodeblocks(context, subband, dimensions) {
  33749. // Section B.7 Division sub-band into code-blocks
  33750. var xcb_ = dimensions.xcb_;
  33751. var ycb_ = dimensions.ycb_;
  33752. var codeblockWidth = 1 << xcb_;
  33753. var codeblockHeight = 1 << ycb_;
  33754. var cbx0 = subband.tbx0 >> xcb_;
  33755. var cby0 = subband.tby0 >> ycb_;
  33756. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33757. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33758. var precinctParameters = subband.resolution.precinctParameters;
  33759. var codeblocks = [];
  33760. var precincts = [];
  33761. var i, j, codeblock, precinctNumber;
  33762. for (j = cby0; j < cby1; j++) {
  33763. for (i = cbx0; i < cbx1; i++) {
  33764. codeblock = {
  33765. cbx: i,
  33766. cby: j,
  33767. tbx0: codeblockWidth * i,
  33768. tby0: codeblockHeight * j,
  33769. tbx1: codeblockWidth * (i + 1),
  33770. tby1: codeblockHeight * (j + 1)
  33771. };
  33772. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33773. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33774. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33775. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33776. // Calculate precinct number for this codeblock, codeblock position
  33777. // should be relative to its subband, use actual dimension and position
  33778. // See comment about codeblock group width and height
  33779. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33780. precinctParameters.precinctWidthInSubband);
  33781. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33782. precinctParameters.precinctHeightInSubband);
  33783. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33784. codeblock.precinctNumber = precinctNumber;
  33785. codeblock.subbandType = subband.type;
  33786. codeblock.Lblock = 3;
  33787. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33788. codeblock.tby1_ <= codeblock.tby0_) {
  33789. continue;
  33790. }
  33791. codeblocks.push(codeblock);
  33792. // building precinct for the sub-band
  33793. var precinct = precincts[precinctNumber];
  33794. if (precinct !== undefined) {
  33795. if (i < precinct.cbxMin) {
  33796. precinct.cbxMin = i;
  33797. } else if (i > precinct.cbxMax) {
  33798. precinct.cbxMax = i;
  33799. }
  33800. if (j < precinct.cbyMin) {
  33801. precinct.cbxMin = j;
  33802. } else if (j > precinct.cbyMax) {
  33803. precinct.cbyMax = j;
  33804. }
  33805. } else {
  33806. precincts[precinctNumber] = precinct = {
  33807. cbxMin: i,
  33808. cbyMin: j,
  33809. cbxMax: i,
  33810. cbyMax: j
  33811. };
  33812. }
  33813. codeblock.precinct = precinct;
  33814. }
  33815. }
  33816. subband.codeblockParameters = {
  33817. codeblockWidth: xcb_,
  33818. codeblockHeight: ycb_,
  33819. numcodeblockwide: cbx1 - cbx0 + 1,
  33820. numcodeblockhigh: cby1 - cby0 + 1
  33821. };
  33822. subband.codeblocks = codeblocks;
  33823. subband.precincts = precincts;
  33824. }
  33825. function createPacket(resolution, precinctNumber, layerNumber) {
  33826. var precinctCodeblocks = [];
  33827. // Section B.10.8 Order of info in packet
  33828. var subbands = resolution.subbands;
  33829. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33830. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33831. var subband = subbands[i];
  33832. var codeblocks = subband.codeblocks;
  33833. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33834. var codeblock = codeblocks[j];
  33835. if (codeblock.precinctNumber !== precinctNumber) {
  33836. continue;
  33837. }
  33838. precinctCodeblocks.push(codeblock);
  33839. }
  33840. }
  33841. return {
  33842. layerNumber: layerNumber,
  33843. codeblocks: precinctCodeblocks
  33844. };
  33845. }
  33846. function LayerResolutionComponentPositionIterator(context) {
  33847. var siz = context.SIZ;
  33848. var tileIndex = context.currentTile.index;
  33849. var tile = context.tiles[tileIndex];
  33850. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33851. var componentsCount = siz.Csiz;
  33852. var maxDecompositionLevelsCount = 0;
  33853. for (var q = 0; q < componentsCount; q++) {
  33854. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33855. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33856. }
  33857. var l = 0, r = 0, i = 0, k = 0;
  33858. this.nextPacket = function JpxImage_nextPacket() {
  33859. // Section B.12.1.1 Layer-resolution-component-position
  33860. for (; l < layersCount; l++) {
  33861. for (; r <= maxDecompositionLevelsCount; r++) {
  33862. for (; i < componentsCount; i++) {
  33863. var component = tile.components[i];
  33864. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33865. continue;
  33866. }
  33867. var resolution = component.resolutions[r];
  33868. var numprecincts = resolution.precinctParameters.numprecincts;
  33869. for (; k < numprecincts;) {
  33870. var packet = createPacket(resolution, k, l);
  33871. k++;
  33872. return packet;
  33873. }
  33874. k = 0;
  33875. }
  33876. i = 0;
  33877. }
  33878. r = 0;
  33879. }
  33880. throw new Error('JPX Error: Out of packets');
  33881. };
  33882. }
  33883. function ResolutionLayerComponentPositionIterator(context) {
  33884. var siz = context.SIZ;
  33885. var tileIndex = context.currentTile.index;
  33886. var tile = context.tiles[tileIndex];
  33887. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33888. var componentsCount = siz.Csiz;
  33889. var maxDecompositionLevelsCount = 0;
  33890. for (var q = 0; q < componentsCount; q++) {
  33891. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33892. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33893. }
  33894. var r = 0, l = 0, i = 0, k = 0;
  33895. this.nextPacket = function JpxImage_nextPacket() {
  33896. // Section B.12.1.2 Resolution-layer-component-position
  33897. for (; r <= maxDecompositionLevelsCount; r++) {
  33898. for (; l < layersCount; l++) {
  33899. for (; i < componentsCount; i++) {
  33900. var component = tile.components[i];
  33901. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33902. continue;
  33903. }
  33904. var resolution = component.resolutions[r];
  33905. var numprecincts = resolution.precinctParameters.numprecincts;
  33906. for (; k < numprecincts;) {
  33907. var packet = createPacket(resolution, k, l);
  33908. k++;
  33909. return packet;
  33910. }
  33911. k = 0;
  33912. }
  33913. i = 0;
  33914. }
  33915. l = 0;
  33916. }
  33917. throw new Error('JPX Error: Out of packets');
  33918. };
  33919. }
  33920. function ResolutionPositionComponentLayerIterator(context) {
  33921. var siz = context.SIZ;
  33922. var tileIndex = context.currentTile.index;
  33923. var tile = context.tiles[tileIndex];
  33924. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33925. var componentsCount = siz.Csiz;
  33926. var l, r, c, p;
  33927. var maxDecompositionLevelsCount = 0;
  33928. for (c = 0; c < componentsCount; c++) {
  33929. var component = tile.components[c];
  33930. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33931. component.codingStyleParameters.decompositionLevelsCount);
  33932. }
  33933. var maxNumPrecinctsInLevel = new Int32Array(
  33934. maxDecompositionLevelsCount + 1);
  33935. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33936. var maxNumPrecincts = 0;
  33937. for (c = 0; c < componentsCount; ++c) {
  33938. var resolutions = tile.components[c].resolutions;
  33939. if (r < resolutions.length) {
  33940. maxNumPrecincts = Math.max(maxNumPrecincts,
  33941. resolutions[r].precinctParameters.numprecincts);
  33942. }
  33943. }
  33944. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  33945. }
  33946. l = 0;
  33947. r = 0;
  33948. c = 0;
  33949. p = 0;
  33950. this.nextPacket = function JpxImage_nextPacket() {
  33951. // Section B.12.1.3 Resolution-position-component-layer
  33952. for (; r <= maxDecompositionLevelsCount; r++) {
  33953. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  33954. for (; c < componentsCount; c++) {
  33955. var component = tile.components[c];
  33956. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33957. continue;
  33958. }
  33959. var resolution = component.resolutions[r];
  33960. var numprecincts = resolution.precinctParameters.numprecincts;
  33961. if (p >= numprecincts) {
  33962. continue;
  33963. }
  33964. for (; l < layersCount;) {
  33965. var packet = createPacket(resolution, p, l);
  33966. l++;
  33967. return packet;
  33968. }
  33969. l = 0;
  33970. }
  33971. c = 0;
  33972. }
  33973. p = 0;
  33974. }
  33975. throw new Error('JPX Error: Out of packets');
  33976. };
  33977. }
  33978. function PositionComponentResolutionLayerIterator(context) {
  33979. var siz = context.SIZ;
  33980. var tileIndex = context.currentTile.index;
  33981. var tile = context.tiles[tileIndex];
  33982. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33983. var componentsCount = siz.Csiz;
  33984. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33985. var precinctsIterationSizes = precinctsSizes;
  33986. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33987. this.nextPacket = function JpxImage_nextPacket() {
  33988. // Section B.12.1.4 Position-component-resolution-layer
  33989. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33990. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33991. for (; c < componentsCount; c++) {
  33992. var component = tile.components[c];
  33993. var decompositionLevelsCount =
  33994. component.codingStyleParameters.decompositionLevelsCount;
  33995. for (; r <= decompositionLevelsCount; r++) {
  33996. var resolution = component.resolutions[r];
  33997. var sizeInImageScale =
  33998. precinctsSizes.components[c].resolutions[r];
  33999. var k = getPrecinctIndexIfExist(
  34000. px,
  34001. py,
  34002. sizeInImageScale,
  34003. precinctsIterationSizes,
  34004. resolution);
  34005. if (k === null) {
  34006. continue;
  34007. }
  34008. for (; l < layersCount;) {
  34009. var packet = createPacket(resolution, k, l);
  34010. l++;
  34011. return packet;
  34012. }
  34013. l = 0;
  34014. }
  34015. r = 0;
  34016. }
  34017. c = 0;
  34018. }
  34019. px = 0;
  34020. }
  34021. throw new Error('JPX Error: Out of packets');
  34022. };
  34023. }
  34024. function ComponentPositionResolutionLayerIterator(context) {
  34025. var siz = context.SIZ;
  34026. var tileIndex = context.currentTile.index;
  34027. var tile = context.tiles[tileIndex];
  34028. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34029. var componentsCount = siz.Csiz;
  34030. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34031. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34032. this.nextPacket = function JpxImage_nextPacket() {
  34033. // Section B.12.1.5 Component-position-resolution-layer
  34034. for (; c < componentsCount; ++c) {
  34035. var component = tile.components[c];
  34036. var precinctsIterationSizes = precinctsSizes.components[c];
  34037. var decompositionLevelsCount =
  34038. component.codingStyleParameters.decompositionLevelsCount;
  34039. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34040. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34041. for (; r <= decompositionLevelsCount; r++) {
  34042. var resolution = component.resolutions[r];
  34043. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34044. var k = getPrecinctIndexIfExist(
  34045. px,
  34046. py,
  34047. sizeInImageScale,
  34048. precinctsIterationSizes,
  34049. resolution);
  34050. if (k === null) {
  34051. continue;
  34052. }
  34053. for (; l < layersCount;) {
  34054. var packet = createPacket(resolution, k, l);
  34055. l++;
  34056. return packet;
  34057. }
  34058. l = 0;
  34059. }
  34060. r = 0;
  34061. }
  34062. px = 0;
  34063. }
  34064. py = 0;
  34065. }
  34066. throw new Error('JPX Error: Out of packets');
  34067. };
  34068. }
  34069. function getPrecinctIndexIfExist(
  34070. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34071. var posX = pxIndex * precinctIterationSizes.minWidth;
  34072. var posY = pyIndex * precinctIterationSizes.minHeight;
  34073. if (posX % sizeInImageScale.width !== 0 ||
  34074. posY % sizeInImageScale.height !== 0) {
  34075. return null;
  34076. }
  34077. var startPrecinctRowIndex =
  34078. (posY / sizeInImageScale.width) *
  34079. resolution.precinctParameters.numprecinctswide;
  34080. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34081. }
  34082. function getPrecinctSizesInImageScale(tile) {
  34083. var componentsCount = tile.components.length;
  34084. var minWidth = Number.MAX_VALUE;
  34085. var minHeight = Number.MAX_VALUE;
  34086. var maxNumWide = 0;
  34087. var maxNumHigh = 0;
  34088. var sizePerComponent = new Array(componentsCount);
  34089. for (var c = 0; c < componentsCount; c++) {
  34090. var component = tile.components[c];
  34091. var decompositionLevelsCount =
  34092. component.codingStyleParameters.decompositionLevelsCount;
  34093. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34094. var minWidthCurrentComponent = Number.MAX_VALUE;
  34095. var minHeightCurrentComponent = Number.MAX_VALUE;
  34096. var maxNumWideCurrentComponent = 0;
  34097. var maxNumHighCurrentComponent = 0;
  34098. var scale = 1;
  34099. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34100. var resolution = component.resolutions[r];
  34101. var widthCurrentResolution =
  34102. scale * resolution.precinctParameters.precinctWidth;
  34103. var heightCurrentResolution =
  34104. scale * resolution.precinctParameters.precinctHeight;
  34105. minWidthCurrentComponent = Math.min(
  34106. minWidthCurrentComponent,
  34107. widthCurrentResolution);
  34108. minHeightCurrentComponent = Math.min(
  34109. minHeightCurrentComponent,
  34110. heightCurrentResolution);
  34111. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34112. resolution.precinctParameters.numprecinctswide);
  34113. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34114. resolution.precinctParameters.numprecinctshigh);
  34115. sizePerResolution[r] = {
  34116. width: widthCurrentResolution,
  34117. height: heightCurrentResolution
  34118. };
  34119. scale <<= 1;
  34120. }
  34121. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34122. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34123. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34124. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34125. sizePerComponent[c] = {
  34126. resolutions: sizePerResolution,
  34127. minWidth: minWidthCurrentComponent,
  34128. minHeight: minHeightCurrentComponent,
  34129. maxNumWide: maxNumWideCurrentComponent,
  34130. maxNumHigh: maxNumHighCurrentComponent
  34131. };
  34132. }
  34133. return {
  34134. components: sizePerComponent,
  34135. minWidth: minWidth,
  34136. minHeight: minHeight,
  34137. maxNumWide: maxNumWide,
  34138. maxNumHigh: maxNumHigh
  34139. };
  34140. }
  34141. function buildPackets(context) {
  34142. var siz = context.SIZ;
  34143. var tileIndex = context.currentTile.index;
  34144. var tile = context.tiles[tileIndex];
  34145. var componentsCount = siz.Csiz;
  34146. // Creating resolutions and sub-bands for each component
  34147. for (var c = 0; c < componentsCount; c++) {
  34148. var component = tile.components[c];
  34149. var decompositionLevelsCount =
  34150. component.codingStyleParameters.decompositionLevelsCount;
  34151. // Section B.5 Resolution levels and sub-bands
  34152. var resolutions = [];
  34153. var subbands = [];
  34154. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34155. var blocksDimensions = getBlocksDimensions(context, component, r);
  34156. var resolution = {};
  34157. var scale = 1 << (decompositionLevelsCount - r);
  34158. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34159. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34160. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34161. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34162. resolution.resLevel = r;
  34163. buildPrecincts(context, resolution, blocksDimensions);
  34164. resolutions.push(resolution);
  34165. var subband;
  34166. if (r === 0) {
  34167. // one sub-band (LL) with last decomposition
  34168. subband = {};
  34169. subband.type = 'LL';
  34170. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34171. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34172. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34173. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34174. subband.resolution = resolution;
  34175. buildCodeblocks(context, subband, blocksDimensions);
  34176. subbands.push(subband);
  34177. resolution.subbands = [subband];
  34178. } else {
  34179. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34180. var resolutionSubbands = [];
  34181. // three sub-bands (HL, LH and HH) with rest of decompositions
  34182. subband = {};
  34183. subband.type = 'HL';
  34184. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34185. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34186. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34187. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34188. subband.resolution = resolution;
  34189. buildCodeblocks(context, subband, blocksDimensions);
  34190. subbands.push(subband);
  34191. resolutionSubbands.push(subband);
  34192. subband = {};
  34193. subband.type = 'LH';
  34194. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34195. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34196. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34197. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34198. subband.resolution = resolution;
  34199. buildCodeblocks(context, subband, blocksDimensions);
  34200. subbands.push(subband);
  34201. resolutionSubbands.push(subband);
  34202. subband = {};
  34203. subband.type = 'HH';
  34204. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34205. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34206. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34207. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34208. subband.resolution = resolution;
  34209. buildCodeblocks(context, subband, blocksDimensions);
  34210. subbands.push(subband);
  34211. resolutionSubbands.push(subband);
  34212. resolution.subbands = resolutionSubbands;
  34213. }
  34214. }
  34215. component.resolutions = resolutions;
  34216. component.subbands = subbands;
  34217. }
  34218. // Generate the packets sequence
  34219. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34220. switch (progressionOrder) {
  34221. case 0:
  34222. tile.packetsIterator =
  34223. new LayerResolutionComponentPositionIterator(context);
  34224. break;
  34225. case 1:
  34226. tile.packetsIterator =
  34227. new ResolutionLayerComponentPositionIterator(context);
  34228. break;
  34229. case 2:
  34230. tile.packetsIterator =
  34231. new ResolutionPositionComponentLayerIterator(context);
  34232. break;
  34233. case 3:
  34234. tile.packetsIterator =
  34235. new PositionComponentResolutionLayerIterator(context);
  34236. break;
  34237. case 4:
  34238. tile.packetsIterator =
  34239. new ComponentPositionResolutionLayerIterator(context);
  34240. break;
  34241. default:
  34242. throw new Error('JPX Error: Unsupported progression order ' +
  34243. progressionOrder);
  34244. }
  34245. }
  34246. function parseTilePackets(context, data, offset, dataLength) {
  34247. var position = 0;
  34248. var buffer, bufferSize = 0, skipNextBit = false;
  34249. function readBits(count) {
  34250. while (bufferSize < count) {
  34251. var b = data[offset + position];
  34252. position++;
  34253. if (skipNextBit) {
  34254. buffer = (buffer << 7) | b;
  34255. bufferSize += 7;
  34256. skipNextBit = false;
  34257. } else {
  34258. buffer = (buffer << 8) | b;
  34259. bufferSize += 8;
  34260. }
  34261. if (b === 0xFF) {
  34262. skipNextBit = true;
  34263. }
  34264. }
  34265. bufferSize -= count;
  34266. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34267. }
  34268. function skipMarkerIfEqual(value) {
  34269. if (data[offset + position - 1] === 0xFF &&
  34270. data[offset + position] === value) {
  34271. skipBytes(1);
  34272. return true;
  34273. } else if (data[offset + position] === 0xFF &&
  34274. data[offset + position + 1] === value) {
  34275. skipBytes(2);
  34276. return true;
  34277. }
  34278. return false;
  34279. }
  34280. function skipBytes(count) {
  34281. position += count;
  34282. }
  34283. function alignToByte() {
  34284. bufferSize = 0;
  34285. if (skipNextBit) {
  34286. position++;
  34287. skipNextBit = false;
  34288. }
  34289. }
  34290. function readCodingpasses() {
  34291. if (readBits(1) === 0) {
  34292. return 1;
  34293. }
  34294. if (readBits(1) === 0) {
  34295. return 2;
  34296. }
  34297. var value = readBits(2);
  34298. if (value < 3) {
  34299. return value + 3;
  34300. }
  34301. value = readBits(5);
  34302. if (value < 31) {
  34303. return value + 6;
  34304. }
  34305. value = readBits(7);
  34306. return value + 37;
  34307. }
  34308. var tileIndex = context.currentTile.index;
  34309. var tile = context.tiles[tileIndex];
  34310. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34311. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34312. var packetsIterator = tile.packetsIterator;
  34313. while (position < dataLength) {
  34314. alignToByte();
  34315. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34316. // Skip also marker segment length and packet sequence ID
  34317. skipBytes(4);
  34318. }
  34319. var packet = packetsIterator.nextPacket();
  34320. if (!readBits(1)) {
  34321. continue;
  34322. }
  34323. var layerNumber = packet.layerNumber;
  34324. var queue = [], codeblock;
  34325. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34326. codeblock = packet.codeblocks[i];
  34327. var precinct = codeblock.precinct;
  34328. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34329. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34330. var codeblockIncluded = false;
  34331. var firstTimeInclusion = false;
  34332. var valueReady;
  34333. if (codeblock['included'] !== undefined) {
  34334. codeblockIncluded = !!readBits(1);
  34335. } else {
  34336. // reading inclusion tree
  34337. precinct = codeblock.precinct;
  34338. var inclusionTree, zeroBitPlanesTree;
  34339. if (precinct['inclusionTree'] !== undefined) {
  34340. inclusionTree = precinct.inclusionTree;
  34341. } else {
  34342. // building inclusion and zero bit-planes trees
  34343. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34344. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34345. inclusionTree = new InclusionTree(width, height, layerNumber);
  34346. zeroBitPlanesTree = new TagTree(width, height);
  34347. precinct.inclusionTree = inclusionTree;
  34348. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34349. }
  34350. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34351. while (true) {
  34352. if (readBits(1)) {
  34353. valueReady = !inclusionTree.nextLevel();
  34354. if (valueReady) {
  34355. codeblock.included = true;
  34356. codeblockIncluded = firstTimeInclusion = true;
  34357. break;
  34358. }
  34359. } else {
  34360. inclusionTree.incrementValue(layerNumber);
  34361. break;
  34362. }
  34363. }
  34364. }
  34365. }
  34366. if (!codeblockIncluded) {
  34367. continue;
  34368. }
  34369. if (firstTimeInclusion) {
  34370. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34371. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34372. while (true) {
  34373. if (readBits(1)) {
  34374. valueReady = !zeroBitPlanesTree.nextLevel();
  34375. if (valueReady) {
  34376. break;
  34377. }
  34378. } else {
  34379. zeroBitPlanesTree.incrementValue();
  34380. }
  34381. }
  34382. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34383. }
  34384. var codingpasses = readCodingpasses();
  34385. while (readBits(1)) {
  34386. codeblock.Lblock++;
  34387. }
  34388. var codingpassesLog2 = log2(codingpasses);
  34389. // rounding down log2
  34390. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34391. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34392. var codedDataLength = readBits(bits);
  34393. queue.push({
  34394. codeblock: codeblock,
  34395. codingpasses: codingpasses,
  34396. dataLength: codedDataLength
  34397. });
  34398. }
  34399. alignToByte();
  34400. if (ephMarkerUsed) {
  34401. skipMarkerIfEqual(0x92);
  34402. }
  34403. while (queue.length > 0) {
  34404. var packetItem = queue.shift();
  34405. codeblock = packetItem.codeblock;
  34406. if (codeblock['data'] === undefined) {
  34407. codeblock.data = [];
  34408. }
  34409. codeblock.data.push({
  34410. data: data,
  34411. start: offset + position,
  34412. end: offset + position + packetItem.dataLength,
  34413. codingpasses: packetItem.codingpasses
  34414. });
  34415. position += packetItem.dataLength;
  34416. }
  34417. }
  34418. return position;
  34419. }
  34420. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34421. delta, mb, reversible, segmentationSymbolUsed) {
  34422. var x0 = subband.tbx0;
  34423. var y0 = subband.tby0;
  34424. var width = subband.tbx1 - subband.tbx0;
  34425. var codeblocks = subband.codeblocks;
  34426. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34427. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34428. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34429. var codeblock = codeblocks[i];
  34430. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34431. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34432. if (blockWidth === 0 || blockHeight === 0) {
  34433. continue;
  34434. }
  34435. if (codeblock['data'] === undefined) {
  34436. continue;
  34437. }
  34438. var bitModel, currentCodingpassType;
  34439. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34440. codeblock.zeroBitPlanes, mb);
  34441. currentCodingpassType = 2; // first bit plane starts from cleanup
  34442. // collect data
  34443. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34444. var j, jj, dataItem;
  34445. for (j = 0, jj = data.length; j < jj; j++) {
  34446. dataItem = data[j];
  34447. totalLength += dataItem.end - dataItem.start;
  34448. codingpasses += dataItem.codingpasses;
  34449. }
  34450. var encodedData = new Uint8Array(totalLength);
  34451. var position = 0;
  34452. for (j = 0, jj = data.length; j < jj; j++) {
  34453. dataItem = data[j];
  34454. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34455. encodedData.set(chunk, position);
  34456. position += chunk.length;
  34457. }
  34458. // decoding the item
  34459. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34460. bitModel.setDecoder(decoder);
  34461. for (j = 0; j < codingpasses; j++) {
  34462. switch (currentCodingpassType) {
  34463. case 0:
  34464. bitModel.runSignificancePropogationPass();
  34465. break;
  34466. case 1:
  34467. bitModel.runMagnitudeRefinementPass();
  34468. break;
  34469. case 2:
  34470. bitModel.runCleanupPass();
  34471. if (segmentationSymbolUsed) {
  34472. bitModel.checkSegmentationSymbol();
  34473. }
  34474. break;
  34475. }
  34476. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34477. }
  34478. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34479. var sign = bitModel.coefficentsSign;
  34480. var magnitude = bitModel.coefficentsMagnitude;
  34481. var bitsDecoded = bitModel.bitsDecoded;
  34482. var magnitudeCorrection = reversible ? 0 : 0.5;
  34483. var k, n, nb;
  34484. position = 0;
  34485. // Do the interleaving of Section F.3.3 here, so we do not need
  34486. // to copy later. LL level is not interleaved, just copied.
  34487. var interleave = (subband.type !== 'LL');
  34488. for (j = 0; j < blockHeight; j++) {
  34489. var row = (offset / width) | 0; // row in the non-interleaved subband
  34490. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34491. for (k = 0; k < blockWidth; k++) {
  34492. n = magnitude[position];
  34493. if (n !== 0) {
  34494. n = (n + magnitudeCorrection) * delta;
  34495. if (sign[position] !== 0) {
  34496. n = -n;
  34497. }
  34498. nb = bitsDecoded[position];
  34499. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34500. if (reversible && (nb >= mb)) {
  34501. coefficients[pos] = n;
  34502. } else {
  34503. coefficients[pos] = n * (1 << (mb - nb));
  34504. }
  34505. }
  34506. offset++;
  34507. position++;
  34508. }
  34509. offset += width - blockWidth;
  34510. }
  34511. }
  34512. }
  34513. function transformTile(context, tile, c) {
  34514. var component = tile.components[c];
  34515. var codingStyleParameters = component.codingStyleParameters;
  34516. var quantizationParameters = component.quantizationParameters;
  34517. var decompositionLevelsCount =
  34518. codingStyleParameters.decompositionLevelsCount;
  34519. var spqcds = quantizationParameters.SPqcds;
  34520. var scalarExpounded = quantizationParameters.scalarExpounded;
  34521. var guardBits = quantizationParameters.guardBits;
  34522. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34523. var precision = context.components[c].precision;
  34524. var reversible = codingStyleParameters.reversibleTransformation;
  34525. var transform = (reversible ? new ReversibleTransform() :
  34526. new IrreversibleTransform());
  34527. var subbandCoefficients = [];
  34528. var b = 0;
  34529. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34530. var resolution = component.resolutions[i];
  34531. var width = resolution.trx1 - resolution.trx0;
  34532. var height = resolution.try1 - resolution.try0;
  34533. // Allocate space for the whole sublevel.
  34534. var coefficients = new Float32Array(width * height);
  34535. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34536. var mu, epsilon;
  34537. if (!scalarExpounded) {
  34538. // formula E-5
  34539. mu = spqcds[0].mu;
  34540. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34541. } else {
  34542. mu = spqcds[b].mu;
  34543. epsilon = spqcds[b].epsilon;
  34544. b++;
  34545. }
  34546. var subband = resolution.subbands[j];
  34547. var gainLog2 = SubbandsGainLog2[subband.type];
  34548. // calulate quantization coefficient (Section E.1.1.1)
  34549. var delta = (reversible ? 1 :
  34550. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34551. var mb = (guardBits + epsilon - 1);
  34552. // In the first resolution level, copyCoefficients will fill the
  34553. // whole array with coefficients. In the succeding passes,
  34554. // copyCoefficients will consecutively fill in the values that belong
  34555. // to the interleaved positions of the HL, LH, and HH coefficients.
  34556. // The LL coefficients will then be interleaved in Transform.iterate().
  34557. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34558. reversible, segmentationSymbolUsed);
  34559. }
  34560. subbandCoefficients.push({
  34561. width: width,
  34562. height: height,
  34563. items: coefficients
  34564. });
  34565. }
  34566. var result = transform.calculate(subbandCoefficients,
  34567. component.tcx0, component.tcy0);
  34568. return {
  34569. left: component.tcx0,
  34570. top: component.tcy0,
  34571. width: result.width,
  34572. height: result.height,
  34573. items: result.items
  34574. };
  34575. }
  34576. function transformComponents(context) {
  34577. var siz = context.SIZ;
  34578. var components = context.components;
  34579. var componentsCount = siz.Csiz;
  34580. var resultImages = [];
  34581. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34582. var tile = context.tiles[i];
  34583. var transformedTiles = [];
  34584. var c;
  34585. for (c = 0; c < componentsCount; c++) {
  34586. transformedTiles[c] = transformTile(context, tile, c);
  34587. }
  34588. var tile0 = transformedTiles[0];
  34589. var out = new Uint8Array(tile0.items.length * componentsCount);
  34590. var result = {
  34591. left: tile0.left,
  34592. top: tile0.top,
  34593. width: tile0.width,
  34594. height: tile0.height,
  34595. items: out
  34596. };
  34597. // Section G.2.2 Inverse multi component transform
  34598. var shift, offset, max, min, maxK;
  34599. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34600. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34601. var fourComponents = componentsCount === 4;
  34602. var y0items = transformedTiles[0].items;
  34603. var y1items = transformedTiles[1].items;
  34604. var y2items = transformedTiles[2].items;
  34605. var y3items = fourComponents ? transformedTiles[3].items : null;
  34606. // HACK: The multiple component transform formulas below assume that
  34607. // all components have the same precision. With this in mind, we
  34608. // compute shift and offset only once.
  34609. shift = components[0].precision - 8;
  34610. offset = (128 << shift) + 0.5;
  34611. max = 255 * (1 << shift);
  34612. maxK = max * 0.5;
  34613. min = -maxK;
  34614. var component0 = tile.components[0];
  34615. var alpha01 = componentsCount - 3;
  34616. jj = y0items.length;
  34617. if (!component0.codingStyleParameters.reversibleTransformation) {
  34618. // inverse irreversible multiple component transform
  34619. for (j = 0; j < jj; j++, pos += alpha01) {
  34620. y0 = y0items[j] + offset;
  34621. y1 = y1items[j];
  34622. y2 = y2items[j];
  34623. r = y0 + 1.402 * y2;
  34624. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34625. b = y0 + 1.772 * y1;
  34626. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34627. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34628. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34629. }
  34630. } else {
  34631. // inverse reversible multiple component transform
  34632. for (j = 0; j < jj; j++, pos += alpha01) {
  34633. y0 = y0items[j] + offset;
  34634. y1 = y1items[j];
  34635. y2 = y2items[j];
  34636. g = y0 - ((y2 + y1) >> 2);
  34637. r = g + y2;
  34638. b = g + y1;
  34639. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34640. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34641. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34642. }
  34643. }
  34644. if (fourComponents) {
  34645. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34646. k = y3items[j];
  34647. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34648. }
  34649. }
  34650. } else { // no multi-component transform
  34651. for (c = 0; c < componentsCount; c++) {
  34652. var items = transformedTiles[c].items;
  34653. shift = components[c].precision - 8;
  34654. offset = (128 << shift) + 0.5;
  34655. max = (127.5 * (1 << shift));
  34656. min = -max;
  34657. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34658. val = items[j];
  34659. out[pos] = val <= min ? 0 :
  34660. val >= max ? 255 : (val + offset) >> shift;
  34661. pos += componentsCount;
  34662. }
  34663. }
  34664. }
  34665. resultImages.push(result);
  34666. }
  34667. return resultImages;
  34668. }
  34669. function initializeTile(context, tileIndex) {
  34670. var siz = context.SIZ;
  34671. var componentsCount = siz.Csiz;
  34672. var tile = context.tiles[tileIndex];
  34673. for (var c = 0; c < componentsCount; c++) {
  34674. var component = tile.components[c];
  34675. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34676. context.currentTile.QCC[c] : context.currentTile.QCD);
  34677. component.quantizationParameters = qcdOrQcc;
  34678. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34679. context.currentTile.COC[c] : context.currentTile.COD);
  34680. component.codingStyleParameters = codOrCoc;
  34681. }
  34682. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34683. }
  34684. // Section B.10.2 Tag trees
  34685. var TagTree = (function TagTreeClosure() {
  34686. function TagTree(width, height) {
  34687. var levelsLength = log2(Math.max(width, height)) + 1;
  34688. this.levels = [];
  34689. for (var i = 0; i < levelsLength; i++) {
  34690. var level = {
  34691. width: width,
  34692. height: height,
  34693. items: []
  34694. };
  34695. this.levels.push(level);
  34696. width = Math.ceil(width / 2);
  34697. height = Math.ceil(height / 2);
  34698. }
  34699. }
  34700. TagTree.prototype = {
  34701. reset: function TagTree_reset(i, j) {
  34702. var currentLevel = 0, value = 0, level;
  34703. while (currentLevel < this.levels.length) {
  34704. level = this.levels[currentLevel];
  34705. var index = i + j * level.width;
  34706. if (level.items[index] !== undefined) {
  34707. value = level.items[index];
  34708. break;
  34709. }
  34710. level.index = index;
  34711. i >>= 1;
  34712. j >>= 1;
  34713. currentLevel++;
  34714. }
  34715. currentLevel--;
  34716. level = this.levels[currentLevel];
  34717. level.items[level.index] = value;
  34718. this.currentLevel = currentLevel;
  34719. delete this.value;
  34720. },
  34721. incrementValue: function TagTree_incrementValue() {
  34722. var level = this.levels[this.currentLevel];
  34723. level.items[level.index]++;
  34724. },
  34725. nextLevel: function TagTree_nextLevel() {
  34726. var currentLevel = this.currentLevel;
  34727. var level = this.levels[currentLevel];
  34728. var value = level.items[level.index];
  34729. currentLevel--;
  34730. if (currentLevel < 0) {
  34731. this.value = value;
  34732. return false;
  34733. }
  34734. this.currentLevel = currentLevel;
  34735. level = this.levels[currentLevel];
  34736. level.items[level.index] = value;
  34737. return true;
  34738. }
  34739. };
  34740. return TagTree;
  34741. })();
  34742. var InclusionTree = (function InclusionTreeClosure() {
  34743. function InclusionTree(width, height, defaultValue) {
  34744. var levelsLength = log2(Math.max(width, height)) + 1;
  34745. this.levels = [];
  34746. for (var i = 0; i < levelsLength; i++) {
  34747. var items = new Uint8Array(width * height);
  34748. for (var j = 0, jj = items.length; j < jj; j++) {
  34749. items[j] = defaultValue;
  34750. }
  34751. var level = {
  34752. width: width,
  34753. height: height,
  34754. items: items
  34755. };
  34756. this.levels.push(level);
  34757. width = Math.ceil(width / 2);
  34758. height = Math.ceil(height / 2);
  34759. }
  34760. }
  34761. InclusionTree.prototype = {
  34762. reset: function InclusionTree_reset(i, j, stopValue) {
  34763. var currentLevel = 0;
  34764. while (currentLevel < this.levels.length) {
  34765. var level = this.levels[currentLevel];
  34766. var index = i + j * level.width;
  34767. level.index = index;
  34768. var value = level.items[index];
  34769. if (value === 0xFF) {
  34770. break;
  34771. }
  34772. if (value > stopValue) {
  34773. this.currentLevel = currentLevel;
  34774. // already know about this one, propagating the value to top levels
  34775. this.propagateValues();
  34776. return false;
  34777. }
  34778. i >>= 1;
  34779. j >>= 1;
  34780. currentLevel++;
  34781. }
  34782. this.currentLevel = currentLevel - 1;
  34783. return true;
  34784. },
  34785. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34786. var level = this.levels[this.currentLevel];
  34787. level.items[level.index] = stopValue + 1;
  34788. this.propagateValues();
  34789. },
  34790. propagateValues: function InclusionTree_propagateValues() {
  34791. var levelIndex = this.currentLevel;
  34792. var level = this.levels[levelIndex];
  34793. var currentValue = level.items[level.index];
  34794. while (--levelIndex >= 0) {
  34795. level = this.levels[levelIndex];
  34796. level.items[level.index] = currentValue;
  34797. }
  34798. },
  34799. nextLevel: function InclusionTree_nextLevel() {
  34800. var currentLevel = this.currentLevel;
  34801. var level = this.levels[currentLevel];
  34802. var value = level.items[level.index];
  34803. level.items[level.index] = 0xFF;
  34804. currentLevel--;
  34805. if (currentLevel < 0) {
  34806. return false;
  34807. }
  34808. this.currentLevel = currentLevel;
  34809. level = this.levels[currentLevel];
  34810. level.items[level.index] = value;
  34811. return true;
  34812. }
  34813. };
  34814. return InclusionTree;
  34815. })();
  34816. // Section D. Coefficient bit modeling
  34817. var BitModel = (function BitModelClosure() {
  34818. var UNIFORM_CONTEXT = 17;
  34819. var RUNLENGTH_CONTEXT = 18;
  34820. // Table D-1
  34821. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34822. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34823. var LLAndLHContextsLabel = new Uint8Array([
  34824. 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,
  34825. 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,
  34826. 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
  34827. ]);
  34828. var HLContextLabel = new Uint8Array([
  34829. 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,
  34830. 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,
  34831. 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
  34832. ]);
  34833. var HHContextLabel = new Uint8Array([
  34834. 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,
  34835. 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,
  34836. 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
  34837. ]);
  34838. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34839. this.width = width;
  34840. this.height = height;
  34841. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34842. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34843. var coefficientCount = width * height;
  34844. // coefficients outside the encoding region treated as insignificant
  34845. // add border state cells for significanceState
  34846. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34847. this.coefficentsSign = new Uint8Array(coefficientCount);
  34848. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34849. mb > 6 ? new Uint16Array(coefficientCount) :
  34850. new Uint8Array(coefficientCount);
  34851. this.processingFlags = new Uint8Array(coefficientCount);
  34852. var bitsDecoded = new Uint8Array(coefficientCount);
  34853. if (zeroBitPlanes !== 0) {
  34854. for (var i = 0; i < coefficientCount; i++) {
  34855. bitsDecoded[i] = zeroBitPlanes;
  34856. }
  34857. }
  34858. this.bitsDecoded = bitsDecoded;
  34859. this.reset();
  34860. }
  34861. BitModel.prototype = {
  34862. setDecoder: function BitModel_setDecoder(decoder) {
  34863. this.decoder = decoder;
  34864. },
  34865. reset: function BitModel_reset() {
  34866. // We have 17 contexts that are accessed via context labels,
  34867. // plus the uniform and runlength context.
  34868. this.contexts = new Int8Array(19);
  34869. // Contexts are packed into 1 byte:
  34870. // highest 7 bits carry the index, lowest bit carries mps
  34871. this.contexts[0] = (4 << 1) | 0;
  34872. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34873. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34874. },
  34875. setNeighborsSignificance:
  34876. function BitModel_setNeighborsSignificance(row, column, index) {
  34877. var neighborsSignificance = this.neighborsSignificance;
  34878. var width = this.width, height = this.height;
  34879. var left = (column > 0);
  34880. var right = (column + 1 < width);
  34881. var i;
  34882. if (row > 0) {
  34883. i = index - width;
  34884. if (left) {
  34885. neighborsSignificance[i - 1] += 0x10;
  34886. }
  34887. if (right) {
  34888. neighborsSignificance[i + 1] += 0x10;
  34889. }
  34890. neighborsSignificance[i] += 0x04;
  34891. }
  34892. if (row + 1 < height) {
  34893. i = index + width;
  34894. if (left) {
  34895. neighborsSignificance[i - 1] += 0x10;
  34896. }
  34897. if (right) {
  34898. neighborsSignificance[i + 1] += 0x10;
  34899. }
  34900. neighborsSignificance[i] += 0x04;
  34901. }
  34902. if (left) {
  34903. neighborsSignificance[index - 1] += 0x01;
  34904. }
  34905. if (right) {
  34906. neighborsSignificance[index + 1] += 0x01;
  34907. }
  34908. neighborsSignificance[index] |= 0x80;
  34909. },
  34910. runSignificancePropogationPass:
  34911. function BitModel_runSignificancePropogationPass() {
  34912. var decoder = this.decoder;
  34913. var width = this.width, height = this.height;
  34914. var coefficentsMagnitude = this.coefficentsMagnitude;
  34915. var coefficentsSign = this.coefficentsSign;
  34916. var neighborsSignificance = this.neighborsSignificance;
  34917. var processingFlags = this.processingFlags;
  34918. var contexts = this.contexts;
  34919. var labels = this.contextLabelTable;
  34920. var bitsDecoded = this.bitsDecoded;
  34921. var processedInverseMask = ~1;
  34922. var processedMask = 1;
  34923. var firstMagnitudeBitMask = 2;
  34924. for (var i0 = 0; i0 < height; i0 += 4) {
  34925. for (var j = 0; j < width; j++) {
  34926. var index = i0 * width + j;
  34927. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34928. var i = i0 + i1;
  34929. if (i >= height) {
  34930. break;
  34931. }
  34932. // clear processed flag first
  34933. processingFlags[index] &= processedInverseMask;
  34934. if (coefficentsMagnitude[index] ||
  34935. !neighborsSignificance[index]) {
  34936. continue;
  34937. }
  34938. var contextLabel = labels[neighborsSignificance[index]];
  34939. var decision = decoder.readBit(contexts, contextLabel);
  34940. if (decision) {
  34941. var sign = this.decodeSignBit(i, j, index);
  34942. coefficentsSign[index] = sign;
  34943. coefficentsMagnitude[index] = 1;
  34944. this.setNeighborsSignificance(i, j, index);
  34945. processingFlags[index] |= firstMagnitudeBitMask;
  34946. }
  34947. bitsDecoded[index]++;
  34948. processingFlags[index] |= processedMask;
  34949. }
  34950. }
  34951. }
  34952. },
  34953. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34954. var width = this.width, height = this.height;
  34955. var coefficentsMagnitude = this.coefficentsMagnitude;
  34956. var coefficentsSign = this.coefficentsSign;
  34957. var contribution, sign0, sign1, significance1;
  34958. var contextLabel, decoded;
  34959. // calculate horizontal contribution
  34960. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34961. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34962. sign1 = coefficentsSign[index + 1];
  34963. if (significance1) {
  34964. sign0 = coefficentsSign[index - 1];
  34965. contribution = 1 - sign1 - sign0;
  34966. } else {
  34967. contribution = 1 - sign1 - sign1;
  34968. }
  34969. } else if (significance1) {
  34970. sign0 = coefficentsSign[index - 1];
  34971. contribution = 1 - sign0 - sign0;
  34972. } else {
  34973. contribution = 0;
  34974. }
  34975. var horizontalContribution = 3 * contribution;
  34976. // calculate vertical contribution and combine with the horizontal
  34977. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34978. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34979. sign1 = coefficentsSign[index + width];
  34980. if (significance1) {
  34981. sign0 = coefficentsSign[index - width];
  34982. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34983. } else {
  34984. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34985. }
  34986. } else if (significance1) {
  34987. sign0 = coefficentsSign[index - width];
  34988. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34989. } else {
  34990. contribution = horizontalContribution;
  34991. }
  34992. if (contribution >= 0) {
  34993. contextLabel = 9 + contribution;
  34994. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34995. } else {
  34996. contextLabel = 9 - contribution;
  34997. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34998. }
  34999. return decoded;
  35000. },
  35001. runMagnitudeRefinementPass:
  35002. function BitModel_runMagnitudeRefinementPass() {
  35003. var decoder = this.decoder;
  35004. var width = this.width, height = this.height;
  35005. var coefficentsMagnitude = this.coefficentsMagnitude;
  35006. var neighborsSignificance = this.neighborsSignificance;
  35007. var contexts = this.contexts;
  35008. var bitsDecoded = this.bitsDecoded;
  35009. var processingFlags = this.processingFlags;
  35010. var processedMask = 1;
  35011. var firstMagnitudeBitMask = 2;
  35012. var length = width * height;
  35013. var width4 = width * 4;
  35014. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35015. indexNext = Math.min(length, index0 + width4);
  35016. for (var j = 0; j < width; j++) {
  35017. for (var index = index0 + j; index < indexNext; index += width) {
  35018. // significant but not those that have just become
  35019. if (!coefficentsMagnitude[index] ||
  35020. (processingFlags[index] & processedMask) !== 0) {
  35021. continue;
  35022. }
  35023. var contextLabel = 16;
  35024. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35025. processingFlags[index] ^= firstMagnitudeBitMask;
  35026. // first refinement
  35027. var significance = neighborsSignificance[index] & 127;
  35028. contextLabel = significance === 0 ? 15 : 14;
  35029. }
  35030. var bit = decoder.readBit(contexts, contextLabel);
  35031. coefficentsMagnitude[index] =
  35032. (coefficentsMagnitude[index] << 1) | bit;
  35033. bitsDecoded[index]++;
  35034. processingFlags[index] |= processedMask;
  35035. }
  35036. }
  35037. }
  35038. },
  35039. runCleanupPass: function BitModel_runCleanupPass() {
  35040. var decoder = this.decoder;
  35041. var width = this.width, height = this.height;
  35042. var neighborsSignificance = this.neighborsSignificance;
  35043. var coefficentsMagnitude = this.coefficentsMagnitude;
  35044. var coefficentsSign = this.coefficentsSign;
  35045. var contexts = this.contexts;
  35046. var labels = this.contextLabelTable;
  35047. var bitsDecoded = this.bitsDecoded;
  35048. var processingFlags = this.processingFlags;
  35049. var processedMask = 1;
  35050. var firstMagnitudeBitMask = 2;
  35051. var oneRowDown = width;
  35052. var twoRowsDown = width * 2;
  35053. var threeRowsDown = width * 3;
  35054. var iNext;
  35055. for (var i0 = 0; i0 < height; i0 = iNext) {
  35056. iNext = Math.min(i0 + 4, height);
  35057. var indexBase = i0 * width;
  35058. var checkAllEmpty = i0 + 3 < height;
  35059. for (var j = 0; j < width; j++) {
  35060. var index0 = indexBase + j;
  35061. // using the property: labels[neighborsSignificance[index]] === 0
  35062. // when neighborsSignificance[index] === 0
  35063. var allEmpty = (checkAllEmpty &&
  35064. processingFlags[index0] === 0 &&
  35065. processingFlags[index0 + oneRowDown] === 0 &&
  35066. processingFlags[index0 + twoRowsDown] === 0 &&
  35067. processingFlags[index0 + threeRowsDown] === 0 &&
  35068. neighborsSignificance[index0] === 0 &&
  35069. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35070. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35071. neighborsSignificance[index0 + threeRowsDown] === 0);
  35072. var i1 = 0, index = index0;
  35073. var i = i0, sign;
  35074. if (allEmpty) {
  35075. var hasSignificantCoefficent =
  35076. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35077. if (!hasSignificantCoefficent) {
  35078. bitsDecoded[index0]++;
  35079. bitsDecoded[index0 + oneRowDown]++;
  35080. bitsDecoded[index0 + twoRowsDown]++;
  35081. bitsDecoded[index0 + threeRowsDown]++;
  35082. continue; // next column
  35083. }
  35084. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35085. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35086. if (i1 !== 0) {
  35087. i = i0 + i1;
  35088. index += i1 * width;
  35089. }
  35090. sign = this.decodeSignBit(i, j, index);
  35091. coefficentsSign[index] = sign;
  35092. coefficentsMagnitude[index] = 1;
  35093. this.setNeighborsSignificance(i, j, index);
  35094. processingFlags[index] |= firstMagnitudeBitMask;
  35095. index = index0;
  35096. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35097. bitsDecoded[index]++;
  35098. }
  35099. i1++;
  35100. }
  35101. for (i = i0 + i1; i < iNext; i++, index += width) {
  35102. if (coefficentsMagnitude[index] ||
  35103. (processingFlags[index] & processedMask) !== 0) {
  35104. continue;
  35105. }
  35106. var contextLabel = labels[neighborsSignificance[index]];
  35107. var decision = decoder.readBit(contexts, contextLabel);
  35108. if (decision === 1) {
  35109. sign = this.decodeSignBit(i, j, index);
  35110. coefficentsSign[index] = sign;
  35111. coefficentsMagnitude[index] = 1;
  35112. this.setNeighborsSignificance(i, j, index);
  35113. processingFlags[index] |= firstMagnitudeBitMask;
  35114. }
  35115. bitsDecoded[index]++;
  35116. }
  35117. }
  35118. }
  35119. },
  35120. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35121. var decoder = this.decoder;
  35122. var contexts = this.contexts;
  35123. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35124. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35125. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35126. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35127. if (symbol !== 0xA) {
  35128. throw new Error('JPX Error: Invalid segmentation symbol');
  35129. }
  35130. }
  35131. };
  35132. return BitModel;
  35133. })();
  35134. // Section F, Discrete wavelet transformation
  35135. var Transform = (function TransformClosure() {
  35136. function Transform() {}
  35137. Transform.prototype.calculate =
  35138. function transformCalculate(subbands, u0, v0) {
  35139. var ll = subbands[0];
  35140. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35141. ll = this.iterate(ll, subbands[i], u0, v0);
  35142. }
  35143. return ll;
  35144. };
  35145. Transform.prototype.extend = function extend(buffer, offset, size) {
  35146. // Section F.3.7 extending... using max extension of 4
  35147. var i1 = offset - 1, j1 = offset + 1;
  35148. var i2 = offset + size - 2, j2 = offset + size;
  35149. buffer[i1--] = buffer[j1++];
  35150. buffer[j2++] = buffer[i2--];
  35151. buffer[i1--] = buffer[j1++];
  35152. buffer[j2++] = buffer[i2--];
  35153. buffer[i1--] = buffer[j1++];
  35154. buffer[j2++] = buffer[i2--];
  35155. buffer[i1] = buffer[j1];
  35156. buffer[j2] = buffer[i2];
  35157. };
  35158. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35159. u0, v0) {
  35160. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35161. var width = hl_lh_hh.width;
  35162. var height = hl_lh_hh.height;
  35163. var items = hl_lh_hh.items;
  35164. var i, j, k, l, u, v;
  35165. // Interleave LL according to Section F.3.3
  35166. for (k = 0, i = 0; i < llHeight; i++) {
  35167. l = i * 2 * width;
  35168. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35169. items[l] = llItems[k];
  35170. }
  35171. }
  35172. // The LL band is not needed anymore.
  35173. llItems = ll.items = null;
  35174. var bufferPadding = 4;
  35175. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35176. // Section F.3.4 HOR_SR
  35177. if (width === 1) {
  35178. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35179. if ((u0 & 1) !== 0) {
  35180. for (v = 0, k = 0; v < height; v++, k += width) {
  35181. items[k] *= 0.5;
  35182. }
  35183. }
  35184. } else {
  35185. for (v = 0, k = 0; v < height; v++, k += width) {
  35186. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35187. this.extend(rowBuffer, bufferPadding, width);
  35188. this.filter(rowBuffer, bufferPadding, width);
  35189. items.set(
  35190. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35191. k);
  35192. }
  35193. }
  35194. // Accesses to the items array can take long, because it may not fit into
  35195. // CPU cache and has to be fetched from main memory. Since subsequent
  35196. // accesses to the items array are not local when reading columns, we
  35197. // have a cache miss every time. To reduce cache misses, get up to
  35198. // 'numBuffers' items at a time and store them into the individual
  35199. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35200. var numBuffers = 16;
  35201. var colBuffers = [];
  35202. for (i = 0; i < numBuffers; i++) {
  35203. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35204. }
  35205. var b, currentBuffer = 0;
  35206. ll = bufferPadding + height;
  35207. // Section F.3.5 VER_SR
  35208. if (height === 1) {
  35209. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35210. if ((v0 & 1) !== 0) {
  35211. for (u = 0; u < width; u++) {
  35212. items[u] *= 0.5;
  35213. }
  35214. }
  35215. } else {
  35216. for (u = 0; u < width; u++) {
  35217. // if we ran out of buffers, copy several image columns at once
  35218. if (currentBuffer === 0) {
  35219. numBuffers = Math.min(width - u, numBuffers);
  35220. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35221. for (b = 0; b < numBuffers; b++) {
  35222. colBuffers[b][l] = items[k + b];
  35223. }
  35224. }
  35225. currentBuffer = numBuffers;
  35226. }
  35227. currentBuffer--;
  35228. var buffer = colBuffers[currentBuffer];
  35229. this.extend(buffer, bufferPadding, height);
  35230. this.filter(buffer, bufferPadding, height);
  35231. // If this is last buffer in this group of buffers, flush all buffers.
  35232. if (currentBuffer === 0) {
  35233. k = u - numBuffers + 1;
  35234. for (l = bufferPadding; l < ll; k += width, l++) {
  35235. for (b = 0; b < numBuffers; b++) {
  35236. items[k + b] = colBuffers[b][l];
  35237. }
  35238. }
  35239. }
  35240. }
  35241. }
  35242. return {
  35243. width: width,
  35244. height: height,
  35245. items: items
  35246. };
  35247. };
  35248. return Transform;
  35249. })();
  35250. // Section 3.8.2 Irreversible 9-7 filter
  35251. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35252. function IrreversibleTransform() {
  35253. Transform.call(this);
  35254. }
  35255. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35256. IrreversibleTransform.prototype.filter =
  35257. function irreversibleTransformFilter(x, offset, length) {
  35258. var len = length >> 1;
  35259. offset = offset | 0;
  35260. var j, n, current, next;
  35261. var alpha = -1.586134342059924;
  35262. var beta = -0.052980118572961;
  35263. var gamma = 0.882911075530934;
  35264. var delta = 0.443506852043971;
  35265. var K = 1.230174104914001;
  35266. var K_ = 1 / K;
  35267. // step 1 is combined with step 3
  35268. // step 2
  35269. j = offset - 3;
  35270. for (n = len + 4; n--; j += 2) {
  35271. x[j] *= K_;
  35272. }
  35273. // step 1 & 3
  35274. j = offset - 2;
  35275. current = delta * x[j -1];
  35276. for (n = len + 3; n--; j += 2) {
  35277. next = delta * x[j + 1];
  35278. x[j] = K * x[j] - current - next;
  35279. if (n--) {
  35280. j += 2;
  35281. current = delta * x[j + 1];
  35282. x[j] = K * x[j] - current - next;
  35283. } else {
  35284. break;
  35285. }
  35286. }
  35287. // step 4
  35288. j = offset - 1;
  35289. current = gamma * x[j - 1];
  35290. for (n = len + 2; n--; j += 2) {
  35291. next = gamma * x[j + 1];
  35292. x[j] -= current + next;
  35293. if (n--) {
  35294. j += 2;
  35295. current = gamma * x[j + 1];
  35296. x[j] -= current + next;
  35297. } else {
  35298. break;
  35299. }
  35300. }
  35301. // step 5
  35302. j = offset;
  35303. current = beta * x[j - 1];
  35304. for (n = len + 1; n--; j += 2) {
  35305. next = beta * x[j + 1];
  35306. x[j] -= current + next;
  35307. if (n--) {
  35308. j += 2;
  35309. current = beta * x[j + 1];
  35310. x[j] -= current + next;
  35311. } else {
  35312. break;
  35313. }
  35314. }
  35315. // step 6
  35316. if (len !== 0) {
  35317. j = offset + 1;
  35318. current = alpha * x[j - 1];
  35319. for (n = len; n--; j += 2) {
  35320. next = alpha * x[j + 1];
  35321. x[j] -= current + next;
  35322. if (n--) {
  35323. j += 2;
  35324. current = alpha * x[j + 1];
  35325. x[j] -= current + next;
  35326. } else {
  35327. break;
  35328. }
  35329. }
  35330. }
  35331. };
  35332. return IrreversibleTransform;
  35333. })();
  35334. // Section 3.8.1 Reversible 5-3 filter
  35335. var ReversibleTransform = (function ReversibleTransformClosure() {
  35336. function ReversibleTransform() {
  35337. Transform.call(this);
  35338. }
  35339. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35340. ReversibleTransform.prototype.filter =
  35341. function reversibleTransformFilter(x, offset, length) {
  35342. var len = length >> 1;
  35343. offset = offset | 0;
  35344. var j, n;
  35345. for (j = offset, n = len + 1; n--; j += 2) {
  35346. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35347. }
  35348. for (j = offset + 1, n = len; n--; j += 2) {
  35349. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35350. }
  35351. };
  35352. return ReversibleTransform;
  35353. })();
  35354. return JpxImage;
  35355. })();
  35356. var Jbig2Image = (function Jbig2ImageClosure() {
  35357. // Utility data structures
  35358. function ContextCache() {}
  35359. ContextCache.prototype = {
  35360. getContexts: function(id) {
  35361. if (id in this) {
  35362. return this[id];
  35363. }
  35364. return (this[id] = new Int8Array(1 << 16));
  35365. }
  35366. };
  35367. function DecodingContext(data, start, end) {
  35368. this.data = data;
  35369. this.start = start;
  35370. this.end = end;
  35371. }
  35372. DecodingContext.prototype = {
  35373. get decoder() {
  35374. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35375. return shadow(this, 'decoder', decoder);
  35376. },
  35377. get contextCache() {
  35378. var cache = new ContextCache();
  35379. return shadow(this, 'contextCache', cache);
  35380. }
  35381. };
  35382. // Annex A. Arithmetic Integer Decoding Procedure
  35383. // A.2 Procedure for decoding values
  35384. function decodeInteger(contextCache, procedure, decoder) {
  35385. var contexts = contextCache.getContexts(procedure);
  35386. var prev = 1;
  35387. function readBits(length) {
  35388. var v = 0;
  35389. for (var i = 0; i < length; i++) {
  35390. var bit = decoder.readBit(contexts, prev);
  35391. prev = (prev < 256 ? (prev << 1) | bit :
  35392. (((prev << 1) | bit) & 511) | 256);
  35393. v = (v << 1) | bit;
  35394. }
  35395. return v >>> 0;
  35396. }
  35397. var sign = readBits(1);
  35398. var value = readBits(1) ?
  35399. (readBits(1) ?
  35400. (readBits(1) ?
  35401. (readBits(1) ?
  35402. (readBits(1) ?
  35403. (readBits(32) + 4436) :
  35404. readBits(12) + 340) :
  35405. readBits(8) + 84) :
  35406. readBits(6) + 20) :
  35407. readBits(4) + 4) :
  35408. readBits(2);
  35409. return (sign === 0 ? value : (value > 0 ? -value : null));
  35410. }
  35411. // A.3 The IAID decoding procedure
  35412. function decodeIAID(contextCache, decoder, codeLength) {
  35413. var contexts = contextCache.getContexts('IAID');
  35414. var prev = 1;
  35415. for (var i = 0; i < codeLength; i++) {
  35416. var bit = decoder.readBit(contexts, prev);
  35417. prev = (prev << 1) | bit;
  35418. }
  35419. if (codeLength < 31) {
  35420. return prev & ((1 << codeLength) - 1);
  35421. }
  35422. return prev & 0x7FFFFFFF;
  35423. }
  35424. // 7.3 Segment types
  35425. var SegmentTypes = [
  35426. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35427. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35428. null, null, null, null, null, 'patternDictionary', null, null, null,
  35429. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35430. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35431. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35432. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35433. 'IntermediateGenericRefinementRegion', null,
  35434. 'ImmediateGenericRefinementRegion',
  35435. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35436. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35437. 'Tables', null, null, null, null, null, null, null, null,
  35438. 'Extension'
  35439. ];
  35440. var CodingTemplates = [
  35441. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35442. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35443. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35444. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35445. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35446. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35447. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35448. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35449. {x: -1, y: 0}],
  35450. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35451. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35452. ];
  35453. var RefinementTemplates = [
  35454. {
  35455. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35456. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35457. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35458. },
  35459. {
  35460. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35461. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35462. {x: 0, y: 1}, {x: 1, y: 1}]
  35463. }
  35464. ];
  35465. // See 6.2.5.7 Decoding the bitmap.
  35466. var ReusedContexts = [
  35467. 0x9B25, // 10011 0110010 0101
  35468. 0x0795, // 0011 110010 101
  35469. 0x00E5, // 001 11001 01
  35470. 0x0195 // 011001 0101
  35471. ];
  35472. var RefinementReusedContexts = [
  35473. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35474. 0x0008 // '0000' + '001000'
  35475. ];
  35476. function decodeBitmapTemplate0(width, height, decodingContext) {
  35477. var decoder = decodingContext.decoder;
  35478. var contexts = decodingContext.contextCache.getContexts('GB');
  35479. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35480. // ...ooooo....
  35481. // ..ooooooo... Context template for current pixel (X)
  35482. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35483. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35484. for (i = 0; i < height; i++) {
  35485. row = bitmap[i] = new Uint8Array(width);
  35486. row1 = (i < 1) ? row : bitmap[i - 1];
  35487. row2 = (i < 2) ? row : bitmap[i - 2];
  35488. // At the beginning of each row:
  35489. // Fill contextLabel with pixels that are above/right of (X)
  35490. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35491. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35492. (row1[3] << 4);
  35493. for (j = 0; j < width; j++) {
  35494. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35495. // At each pixel: Clear contextLabel pixels that are shifted
  35496. // out of the context, then add new ones.
  35497. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35498. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35499. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35500. }
  35501. }
  35502. return bitmap;
  35503. }
  35504. // 6.2 Generic Region Decoding Procedure
  35505. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35506. decodingContext) {
  35507. if (mmr) {
  35508. error('JBIG2 error: MMR encoding is not supported');
  35509. }
  35510. // Use optimized version for the most common case
  35511. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35512. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35513. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35514. return decodeBitmapTemplate0(width, height, decodingContext);
  35515. }
  35516. var useskip = !!skip;
  35517. var template = CodingTemplates[templateIndex].concat(at);
  35518. // Sorting is non-standard, and it is not required. But sorting increases
  35519. // the number of template bits that can be reused from the previous
  35520. // contextLabel in the main loop.
  35521. template.sort(function (a, b) {
  35522. return (a.y - b.y) || (a.x - b.x);
  35523. });
  35524. var templateLength = template.length;
  35525. var templateX = new Int8Array(templateLength);
  35526. var templateY = new Int8Array(templateLength);
  35527. var changingTemplateEntries = [];
  35528. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35529. var c, k;
  35530. for (k = 0; k < templateLength; k++) {
  35531. templateX[k] = template[k].x;
  35532. templateY[k] = template[k].y;
  35533. minX = Math.min(minX, template[k].x);
  35534. maxX = Math.max(maxX, template[k].x);
  35535. minY = Math.min(minY, template[k].y);
  35536. // Check if the template pixel appears in two consecutive context labels,
  35537. // so it can be reused. Otherwise, we add it to the list of changing
  35538. // template entries.
  35539. if (k < templateLength - 1 &&
  35540. template[k].y === template[k + 1].y &&
  35541. template[k].x === template[k + 1].x - 1) {
  35542. reuseMask |= 1 << (templateLength - 1 - k);
  35543. } else {
  35544. changingTemplateEntries.push(k);
  35545. }
  35546. }
  35547. var changingEntriesLength = changingTemplateEntries.length;
  35548. var changingTemplateX = new Int8Array(changingEntriesLength);
  35549. var changingTemplateY = new Int8Array(changingEntriesLength);
  35550. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35551. for (c = 0; c < changingEntriesLength; c++) {
  35552. k = changingTemplateEntries[c];
  35553. changingTemplateX[c] = template[k].x;
  35554. changingTemplateY[c] = template[k].y;
  35555. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35556. }
  35557. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35558. var sbb_left = -minX;
  35559. var sbb_top = -minY;
  35560. var sbb_right = width - maxX;
  35561. var pseudoPixelContext = ReusedContexts[templateIndex];
  35562. var row = new Uint8Array(width);
  35563. var bitmap = [];
  35564. var decoder = decodingContext.decoder;
  35565. var contexts = decodingContext.contextCache.getContexts('GB');
  35566. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35567. for (var i = 0; i < height; i++) {
  35568. if (prediction) {
  35569. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35570. ltp ^= sltp;
  35571. if (ltp) {
  35572. bitmap.push(row); // duplicate previous row
  35573. continue;
  35574. }
  35575. }
  35576. row = new Uint8Array(row);
  35577. bitmap.push(row);
  35578. for (j = 0; j < width; j++) {
  35579. if (useskip && skip[i][j]) {
  35580. row[j] = 0;
  35581. continue;
  35582. }
  35583. // Are we in the middle of a scanline, so we can reuse contextLabel
  35584. // bits?
  35585. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35586. // If yes, we can just shift the bits that are reusable and only
  35587. // fetch the remaining ones.
  35588. contextLabel = (contextLabel << 1) & reuseMask;
  35589. for (k = 0; k < changingEntriesLength; k++) {
  35590. i0 = i + changingTemplateY[k];
  35591. j0 = j + changingTemplateX[k];
  35592. bit = bitmap[i0][j0];
  35593. if (bit) {
  35594. bit = changingTemplateBit[k];
  35595. contextLabel |= bit;
  35596. }
  35597. }
  35598. } else {
  35599. // compute the contextLabel from scratch
  35600. contextLabel = 0;
  35601. shift = templateLength - 1;
  35602. for (k = 0; k < templateLength; k++, shift--) {
  35603. j0 = j + templateX[k];
  35604. if (j0 >= 0 && j0 < width) {
  35605. i0 = i + templateY[k];
  35606. if (i0 >= 0) {
  35607. bit = bitmap[i0][j0];
  35608. if (bit) {
  35609. contextLabel |= bit << shift;
  35610. }
  35611. }
  35612. }
  35613. }
  35614. }
  35615. var pixel = decoder.readBit(contexts, contextLabel);
  35616. row[j] = pixel;
  35617. }
  35618. }
  35619. return bitmap;
  35620. }
  35621. // 6.3.2 Generic Refinement Region Decoding Procedure
  35622. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35623. offsetX, offsetY, prediction, at,
  35624. decodingContext) {
  35625. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35626. if (templateIndex === 0) {
  35627. codingTemplate = codingTemplate.concat([at[0]]);
  35628. }
  35629. var codingTemplateLength = codingTemplate.length;
  35630. var codingTemplateX = new Int32Array(codingTemplateLength);
  35631. var codingTemplateY = new Int32Array(codingTemplateLength);
  35632. var k;
  35633. for (k = 0; k < codingTemplateLength; k++) {
  35634. codingTemplateX[k] = codingTemplate[k].x;
  35635. codingTemplateY[k] = codingTemplate[k].y;
  35636. }
  35637. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35638. if (templateIndex === 0) {
  35639. referenceTemplate = referenceTemplate.concat([at[1]]);
  35640. }
  35641. var referenceTemplateLength = referenceTemplate.length;
  35642. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35643. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35644. for (k = 0; k < referenceTemplateLength; k++) {
  35645. referenceTemplateX[k] = referenceTemplate[k].x;
  35646. referenceTemplateY[k] = referenceTemplate[k].y;
  35647. }
  35648. var referenceWidth = referenceBitmap[0].length;
  35649. var referenceHeight = referenceBitmap.length;
  35650. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35651. var bitmap = [];
  35652. var decoder = decodingContext.decoder;
  35653. var contexts = decodingContext.contextCache.getContexts('GR');
  35654. var ltp = 0;
  35655. for (var i = 0; i < height; i++) {
  35656. if (prediction) {
  35657. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35658. ltp ^= sltp;
  35659. if (ltp) {
  35660. error('JBIG2 error: prediction is not supported');
  35661. }
  35662. }
  35663. var row = new Uint8Array(width);
  35664. bitmap.push(row);
  35665. for (var j = 0; j < width; j++) {
  35666. var i0, j0;
  35667. var contextLabel = 0;
  35668. for (k = 0; k < codingTemplateLength; k++) {
  35669. i0 = i + codingTemplateY[k];
  35670. j0 = j + codingTemplateX[k];
  35671. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35672. contextLabel <<= 1; // out of bound pixel
  35673. } else {
  35674. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35675. }
  35676. }
  35677. for (k = 0; k < referenceTemplateLength; k++) {
  35678. i0 = i + referenceTemplateY[k] + offsetY;
  35679. j0 = j + referenceTemplateX[k] + offsetX;
  35680. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35681. j0 >= referenceWidth) {
  35682. contextLabel <<= 1; // out of bound pixel
  35683. } else {
  35684. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35685. }
  35686. }
  35687. var pixel = decoder.readBit(contexts, contextLabel);
  35688. row[j] = pixel;
  35689. }
  35690. }
  35691. return bitmap;
  35692. }
  35693. // 6.5.5 Decoding the symbol dictionary
  35694. function decodeSymbolDictionary(huffman, refinement, symbols,
  35695. numberOfNewSymbols, numberOfExportedSymbols,
  35696. huffmanTables, templateIndex, at,
  35697. refinementTemplateIndex, refinementAt,
  35698. decodingContext) {
  35699. if (huffman) {
  35700. error('JBIG2 error: huffman is not supported');
  35701. }
  35702. var newSymbols = [];
  35703. var currentHeight = 0;
  35704. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35705. var decoder = decodingContext.decoder;
  35706. var contextCache = decodingContext.contextCache;
  35707. while (newSymbols.length < numberOfNewSymbols) {
  35708. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35709. currentHeight += deltaHeight;
  35710. var currentWidth = 0;
  35711. var totalWidth = 0;
  35712. while (true) {
  35713. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35714. if (deltaWidth === null) {
  35715. break; // OOB
  35716. }
  35717. currentWidth += deltaWidth;
  35718. totalWidth += currentWidth;
  35719. var bitmap;
  35720. if (refinement) {
  35721. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35722. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35723. if (numberOfInstances > 1) {
  35724. bitmap = decodeTextRegion(huffman, refinement,
  35725. currentWidth, currentHeight, 0,
  35726. numberOfInstances, 1, //strip size
  35727. symbols.concat(newSymbols),
  35728. symbolCodeLength,
  35729. 0, //transposed
  35730. 0, //ds offset
  35731. 1, //top left 7.4.3.1.1
  35732. 0, //OR operator
  35733. huffmanTables,
  35734. refinementTemplateIndex, refinementAt,
  35735. decodingContext);
  35736. } else {
  35737. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35738. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35739. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35740. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35741. newSymbols[symbolId - symbols.length]);
  35742. bitmap = decodeRefinement(currentWidth, currentHeight,
  35743. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35744. decodingContext);
  35745. }
  35746. } else {
  35747. // 6.5.8.1 Direct-coded symbol bitmap
  35748. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35749. templateIndex, false, null, at, decodingContext);
  35750. }
  35751. newSymbols.push(bitmap);
  35752. }
  35753. }
  35754. // 6.5.10 Exported symbols
  35755. var exportedSymbols = [];
  35756. var flags = [], currentFlag = false;
  35757. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35758. while (flags.length < totalSymbolsLength) {
  35759. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35760. while (runLength--) {
  35761. flags.push(currentFlag);
  35762. }
  35763. currentFlag = !currentFlag;
  35764. }
  35765. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35766. if (flags[i]) {
  35767. exportedSymbols.push(symbols[i]);
  35768. }
  35769. }
  35770. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35771. if (flags[i]) {
  35772. exportedSymbols.push(newSymbols[j]);
  35773. }
  35774. }
  35775. return exportedSymbols;
  35776. }
  35777. function decodeTextRegion(huffman, refinement, width, height,
  35778. defaultPixelValue, numberOfSymbolInstances,
  35779. stripSize, inputSymbols, symbolCodeLength,
  35780. transposed, dsOffset, referenceCorner,
  35781. combinationOperator, huffmanTables,
  35782. refinementTemplateIndex, refinementAt,
  35783. decodingContext) {
  35784. if (huffman) {
  35785. error('JBIG2 error: huffman is not supported');
  35786. }
  35787. // Prepare bitmap
  35788. var bitmap = [];
  35789. var i, row;
  35790. for (i = 0; i < height; i++) {
  35791. row = new Uint8Array(width);
  35792. if (defaultPixelValue) {
  35793. for (var j = 0; j < width; j++) {
  35794. row[j] = defaultPixelValue;
  35795. }
  35796. }
  35797. bitmap.push(row);
  35798. }
  35799. var decoder = decodingContext.decoder;
  35800. var contextCache = decodingContext.contextCache;
  35801. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35802. var firstS = 0;
  35803. i = 0;
  35804. while (i < numberOfSymbolInstances) {
  35805. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35806. stripT += deltaT;
  35807. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35808. firstS += deltaFirstS;
  35809. var currentS = firstS;
  35810. do {
  35811. var currentT = (stripSize === 1 ? 0 :
  35812. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35813. var t = stripSize * stripT + currentT;
  35814. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35815. var applyRefinement = (refinement &&
  35816. decodeInteger(contextCache, 'IARI', decoder));
  35817. var symbolBitmap = inputSymbols[symbolId];
  35818. var symbolWidth = symbolBitmap[0].length;
  35819. var symbolHeight = symbolBitmap.length;
  35820. if (applyRefinement) {
  35821. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35822. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35823. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35824. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35825. symbolWidth += rdw;
  35826. symbolHeight += rdh;
  35827. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35828. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35829. (rdh >> 1) + rdy, false, refinementAt,
  35830. decodingContext);
  35831. }
  35832. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35833. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35834. var s2, t2, symbolRow;
  35835. if (transposed) {
  35836. // Place Symbol Bitmap from T1,S1
  35837. for (s2 = 0; s2 < symbolHeight; s2++) {
  35838. row = bitmap[offsetS + s2];
  35839. if (!row) {
  35840. continue;
  35841. }
  35842. symbolRow = symbolBitmap[s2];
  35843. // To ignore Parts of Symbol bitmap which goes
  35844. // outside bitmap region
  35845. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35846. switch (combinationOperator) {
  35847. case 0: // OR
  35848. for (t2 = 0; t2 < maxWidth; t2++) {
  35849. row[offsetT + t2] |= symbolRow[t2];
  35850. }
  35851. break;
  35852. case 2: // XOR
  35853. for (t2 = 0; t2 < maxWidth; t2++) {
  35854. row[offsetT + t2] ^= symbolRow[t2];
  35855. }
  35856. break;
  35857. default:
  35858. error('JBIG2 error: operator ' + combinationOperator +
  35859. ' is not supported');
  35860. }
  35861. }
  35862. currentS += symbolHeight - 1;
  35863. } else {
  35864. for (t2 = 0; t2 < symbolHeight; t2++) {
  35865. row = bitmap[offsetT + t2];
  35866. if (!row) {
  35867. continue;
  35868. }
  35869. symbolRow = symbolBitmap[t2];
  35870. switch (combinationOperator) {
  35871. case 0: // OR
  35872. for (s2 = 0; s2 < symbolWidth; s2++) {
  35873. row[offsetS + s2] |= symbolRow[s2];
  35874. }
  35875. break;
  35876. case 2: // XOR
  35877. for (s2 = 0; s2 < symbolWidth; s2++) {
  35878. row[offsetS + s2] ^= symbolRow[s2];
  35879. }
  35880. break;
  35881. default:
  35882. error('JBIG2 error: operator ' + combinationOperator +
  35883. ' is not supported');
  35884. }
  35885. }
  35886. currentS += symbolWidth - 1;
  35887. }
  35888. i++;
  35889. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35890. if (deltaS === null) {
  35891. break; // OOB
  35892. }
  35893. currentS += deltaS + dsOffset;
  35894. } while (true);
  35895. }
  35896. return bitmap;
  35897. }
  35898. function readSegmentHeader(data, start) {
  35899. var segmentHeader = {};
  35900. segmentHeader.number = readUint32(data, start);
  35901. var flags = data[start + 4];
  35902. var segmentType = flags & 0x3F;
  35903. if (!SegmentTypes[segmentType]) {
  35904. error('JBIG2 error: invalid segment type: ' + segmentType);
  35905. }
  35906. segmentHeader.type = segmentType;
  35907. segmentHeader.typeName = SegmentTypes[segmentType];
  35908. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35909. var pageAssociationFieldSize = !!(flags & 0x40);
  35910. var referredFlags = data[start + 5];
  35911. var referredToCount = (referredFlags >> 5) & 7;
  35912. var retainBits = [referredFlags & 31];
  35913. var position = start + 6;
  35914. if (referredFlags === 7) {
  35915. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35916. position += 3;
  35917. var bytes = (referredToCount + 7) >> 3;
  35918. retainBits[0] = data[position++];
  35919. while (--bytes > 0) {
  35920. retainBits.push(data[position++]);
  35921. }
  35922. } else if (referredFlags === 5 || referredFlags === 6) {
  35923. error('JBIG2 error: invalid referred-to flags');
  35924. }
  35925. segmentHeader.retainBits = retainBits;
  35926. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35927. (segmentHeader.number <= 65536 ? 2 : 4));
  35928. var referredTo = [];
  35929. var i, ii;
  35930. for (i = 0; i < referredToCount; i++) {
  35931. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35932. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35933. readUint32(data, position)));
  35934. referredTo.push(number);
  35935. position += referredToSegmentNumberSize;
  35936. }
  35937. segmentHeader.referredTo = referredTo;
  35938. if (!pageAssociationFieldSize) {
  35939. segmentHeader.pageAssociation = data[position++];
  35940. } else {
  35941. segmentHeader.pageAssociation = readUint32(data, position);
  35942. position += 4;
  35943. }
  35944. segmentHeader.length = readUint32(data, position);
  35945. position += 4;
  35946. if (segmentHeader.length === 0xFFFFFFFF) {
  35947. // 7.2.7 Segment data length, unknown segment length
  35948. if (segmentType === 38) { // ImmediateGenericRegion
  35949. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35950. var genericRegionSegmentFlags = data[position +
  35951. RegionSegmentInformationFieldLength];
  35952. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35953. // searching for the segment end
  35954. var searchPatternLength = 6;
  35955. var searchPattern = new Uint8Array(searchPatternLength);
  35956. if (!genericRegionMmr) {
  35957. searchPattern[0] = 0xFF;
  35958. searchPattern[1] = 0xAC;
  35959. }
  35960. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35961. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35962. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35963. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35964. for (i = position, ii = data.length; i < ii; i++) {
  35965. var j = 0;
  35966. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35967. j++;
  35968. }
  35969. if (j === searchPatternLength) {
  35970. segmentHeader.length = i + searchPatternLength;
  35971. break;
  35972. }
  35973. }
  35974. if (segmentHeader.length === 0xFFFFFFFF) {
  35975. error('JBIG2 error: segment end was not found');
  35976. }
  35977. } else {
  35978. error('JBIG2 error: invalid unknown segment length');
  35979. }
  35980. }
  35981. segmentHeader.headerEnd = position;
  35982. return segmentHeader;
  35983. }
  35984. function readSegments(header, data, start, end) {
  35985. var segments = [];
  35986. var position = start;
  35987. while (position < end) {
  35988. var segmentHeader = readSegmentHeader(data, position);
  35989. position = segmentHeader.headerEnd;
  35990. var segment = {
  35991. header: segmentHeader,
  35992. data: data
  35993. };
  35994. if (!header.randomAccess) {
  35995. segment.start = position;
  35996. position += segmentHeader.length;
  35997. segment.end = position;
  35998. }
  35999. segments.push(segment);
  36000. if (segmentHeader.type === 51) {
  36001. break; // end of file is found
  36002. }
  36003. }
  36004. if (header.randomAccess) {
  36005. for (var i = 0, ii = segments.length; i < ii; i++) {
  36006. segments[i].start = position;
  36007. position += segments[i].header.length;
  36008. segments[i].end = position;
  36009. }
  36010. }
  36011. return segments;
  36012. }
  36013. // 7.4.1 Region segment information field
  36014. function readRegionSegmentInformation(data, start) {
  36015. return {
  36016. width: readUint32(data, start),
  36017. height: readUint32(data, start + 4),
  36018. x: readUint32(data, start + 8),
  36019. y: readUint32(data, start + 12),
  36020. combinationOperator: data[start + 16] & 7
  36021. };
  36022. }
  36023. var RegionSegmentInformationFieldLength = 17;
  36024. function processSegment(segment, visitor) {
  36025. var header = segment.header;
  36026. var data = segment.data, position = segment.start, end = segment.end;
  36027. var args, at, i, atLength;
  36028. switch (header.type) {
  36029. case 0: // SymbolDictionary
  36030. // 7.4.2 Symbol dictionary segment syntax
  36031. var dictionary = {};
  36032. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36033. dictionary.huffman = !!(dictionaryFlags & 1);
  36034. dictionary.refinement = !!(dictionaryFlags & 2);
  36035. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36036. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36037. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36038. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36039. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36040. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36041. dictionary.template = (dictionaryFlags >> 10) & 3;
  36042. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36043. position += 2;
  36044. if (!dictionary.huffman) {
  36045. atLength = dictionary.template === 0 ? 4 : 1;
  36046. at = [];
  36047. for (i = 0; i < atLength; i++) {
  36048. at.push({
  36049. x: readInt8(data, position),
  36050. y: readInt8(data, position + 1)
  36051. });
  36052. position += 2;
  36053. }
  36054. dictionary.at = at;
  36055. }
  36056. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36057. at = [];
  36058. for (i = 0; i < 2; i++) {
  36059. at.push({
  36060. x: readInt8(data, position),
  36061. y: readInt8(data, position + 1)
  36062. });
  36063. position += 2;
  36064. }
  36065. dictionary.refinementAt = at;
  36066. }
  36067. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36068. position += 4;
  36069. dictionary.numberOfNewSymbols = readUint32(data, position);
  36070. position += 4;
  36071. args = [dictionary, header.number, header.referredTo,
  36072. data, position, end];
  36073. break;
  36074. case 6: // ImmediateTextRegion
  36075. case 7: // ImmediateLosslessTextRegion
  36076. var textRegion = {};
  36077. textRegion.info = readRegionSegmentInformation(data, position);
  36078. position += RegionSegmentInformationFieldLength;
  36079. var textRegionSegmentFlags = readUint16(data, position);
  36080. position += 2;
  36081. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36082. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36083. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36084. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36085. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36086. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36087. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36088. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36089. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36090. if (textRegion.huffman) {
  36091. var textRegionHuffmanFlags = readUint16(data, position);
  36092. position += 2;
  36093. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36094. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36095. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36096. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36097. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36098. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36099. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36100. textRegion.huffmanRefinementSizeSelector =
  36101. !!(textRegionHuffmanFlags & 14);
  36102. }
  36103. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36104. at = [];
  36105. for (i = 0; i < 2; i++) {
  36106. at.push({
  36107. x: readInt8(data, position),
  36108. y: readInt8(data, position + 1)
  36109. });
  36110. position += 2;
  36111. }
  36112. textRegion.refinementAt = at;
  36113. }
  36114. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36115. position += 4;
  36116. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36117. if (textRegion.huffman) {
  36118. error('JBIG2 error: huffman is not supported');
  36119. }
  36120. args = [textRegion, header.referredTo, data, position, end];
  36121. break;
  36122. case 38: // ImmediateGenericRegion
  36123. case 39: // ImmediateLosslessGenericRegion
  36124. var genericRegion = {};
  36125. genericRegion.info = readRegionSegmentInformation(data, position);
  36126. position += RegionSegmentInformationFieldLength;
  36127. var genericRegionSegmentFlags = data[position++];
  36128. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36129. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36130. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36131. if (!genericRegion.mmr) {
  36132. atLength = genericRegion.template === 0 ? 4 : 1;
  36133. at = [];
  36134. for (i = 0; i < atLength; i++) {
  36135. at.push({
  36136. x: readInt8(data, position),
  36137. y: readInt8(data, position + 1)
  36138. });
  36139. position += 2;
  36140. }
  36141. genericRegion.at = at;
  36142. }
  36143. args = [genericRegion, data, position, end];
  36144. break;
  36145. case 48: // PageInformation
  36146. var pageInfo = {
  36147. width: readUint32(data, position),
  36148. height: readUint32(data, position + 4),
  36149. resolutionX: readUint32(data, position + 8),
  36150. resolutionY: readUint32(data, position + 12)
  36151. };
  36152. if (pageInfo.height === 0xFFFFFFFF) {
  36153. delete pageInfo.height;
  36154. }
  36155. var pageSegmentFlags = data[position + 16];
  36156. var pageStripingInformatiom = readUint16(data, position + 17);
  36157. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36158. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36159. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36160. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36161. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36162. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36163. args = [pageInfo];
  36164. break;
  36165. case 49: // EndOfPage
  36166. break;
  36167. case 50: // EndOfStripe
  36168. break;
  36169. case 51: // EndOfFile
  36170. break;
  36171. case 62: // 7.4.15 defines 2 extension types which
  36172. // are comments and can be ignored.
  36173. break;
  36174. default:
  36175. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36176. header.type + ') is not implemented');
  36177. }
  36178. var callbackName = 'on' + header.typeName;
  36179. if (callbackName in visitor) {
  36180. visitor[callbackName].apply(visitor, args);
  36181. }
  36182. }
  36183. function processSegments(segments, visitor) {
  36184. for (var i = 0, ii = segments.length; i < ii; i++) {
  36185. processSegment(segments[i], visitor);
  36186. }
  36187. }
  36188. function parseJbig2(data, start, end) {
  36189. var position = start;
  36190. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36191. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36192. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36193. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36194. error('JBIG2 error: invalid header');
  36195. }
  36196. var header = {};
  36197. position += 8;
  36198. var flags = data[position++];
  36199. header.randomAccess = !(flags & 1);
  36200. if (!(flags & 2)) {
  36201. header.numberOfPages = readUint32(data, position);
  36202. position += 4;
  36203. }
  36204. var segments = readSegments(header, data, position, end);
  36205. error('Not implemented');
  36206. // processSegments(segments, new SimpleSegmentVisitor());
  36207. }
  36208. function parseJbig2Chunks(chunks) {
  36209. var visitor = new SimpleSegmentVisitor();
  36210. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36211. var chunk = chunks[i];
  36212. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36213. processSegments(segments, visitor);
  36214. }
  36215. return visitor.buffer;
  36216. }
  36217. function SimpleSegmentVisitor() {}
  36218. SimpleSegmentVisitor.prototype = {
  36219. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36220. this.currentPageInfo = info;
  36221. var rowSize = (info.width + 7) >> 3;
  36222. var buffer = new Uint8Array(rowSize * info.height);
  36223. // The contents of ArrayBuffers are initialized to 0.
  36224. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36225. if (info.defaultPixelValue) {
  36226. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36227. buffer[i] = 0xFF;
  36228. }
  36229. }
  36230. this.buffer = buffer;
  36231. },
  36232. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36233. var pageInfo = this.currentPageInfo;
  36234. var width = regionInfo.width, height = regionInfo.height;
  36235. var rowSize = (pageInfo.width + 7) >> 3;
  36236. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36237. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36238. var buffer = this.buffer;
  36239. var mask0 = 128 >> (regionInfo.x & 7);
  36240. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36241. var i, j, mask, offset;
  36242. switch (combinationOperator) {
  36243. case 0: // OR
  36244. for (i = 0; i < height; i++) {
  36245. mask = mask0;
  36246. offset = offset0;
  36247. for (j = 0; j < width; j++) {
  36248. if (bitmap[i][j]) {
  36249. buffer[offset] |= mask;
  36250. }
  36251. mask >>= 1;
  36252. if (!mask) {
  36253. mask = 128;
  36254. offset++;
  36255. }
  36256. }
  36257. offset0 += rowSize;
  36258. }
  36259. break;
  36260. case 2: // XOR
  36261. for (i = 0; i < height; i++) {
  36262. mask = mask0;
  36263. offset = offset0;
  36264. for (j = 0; j < width; j++) {
  36265. if (bitmap[i][j]) {
  36266. buffer[offset] ^= mask;
  36267. }
  36268. mask >>= 1;
  36269. if (!mask) {
  36270. mask = 128;
  36271. offset++;
  36272. }
  36273. }
  36274. offset0 += rowSize;
  36275. }
  36276. break;
  36277. default:
  36278. error('JBIG2 error: operator ' + combinationOperator +
  36279. ' is not supported');
  36280. }
  36281. },
  36282. onImmediateGenericRegion:
  36283. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36284. start, end) {
  36285. var regionInfo = region.info;
  36286. var decodingContext = new DecodingContext(data, start, end);
  36287. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36288. region.template, region.prediction, null,
  36289. region.at, decodingContext);
  36290. this.drawBitmap(regionInfo, bitmap);
  36291. },
  36292. onImmediateLosslessGenericRegion:
  36293. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36294. this.onImmediateGenericRegion.apply(this, arguments);
  36295. },
  36296. onSymbolDictionary:
  36297. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36298. currentSegment,
  36299. referredSegments,
  36300. data, start, end) {
  36301. var huffmanTables;
  36302. if (dictionary.huffman) {
  36303. error('JBIG2 error: huffman is not supported');
  36304. }
  36305. // Combines exported symbols from all referred segments
  36306. var symbols = this.symbols;
  36307. if (!symbols) {
  36308. this.symbols = symbols = {};
  36309. }
  36310. var inputSymbols = [];
  36311. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36312. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36313. }
  36314. var decodingContext = new DecodingContext(data, start, end);
  36315. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36316. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36317. dictionary.numberOfExportedSymbols, huffmanTables,
  36318. dictionary.template, dictionary.at,
  36319. dictionary.refinementTemplate, dictionary.refinementAt,
  36320. decodingContext);
  36321. },
  36322. onImmediateTextRegion:
  36323. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36324. referredSegments,
  36325. data, start, end) {
  36326. var regionInfo = region.info;
  36327. var huffmanTables;
  36328. // Combines exported symbols from all referred segments
  36329. var symbols = this.symbols;
  36330. var inputSymbols = [];
  36331. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36332. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36333. }
  36334. var symbolCodeLength = log2(inputSymbols.length);
  36335. var decodingContext = new DecodingContext(data, start, end);
  36336. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36337. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36338. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36339. symbolCodeLength, region.transposed, region.dsOffset,
  36340. region.referenceCorner, region.combinationOperator, huffmanTables,
  36341. region.refinementTemplate, region.refinementAt, decodingContext);
  36342. this.drawBitmap(regionInfo, bitmap);
  36343. },
  36344. onImmediateLosslessTextRegion:
  36345. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36346. this.onImmediateTextRegion.apply(this, arguments);
  36347. }
  36348. };
  36349. function Jbig2Image() {}
  36350. Jbig2Image.prototype = {
  36351. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36352. return parseJbig2Chunks(chunks);
  36353. }
  36354. };
  36355. return Jbig2Image;
  36356. })();
  36357. var bidi = PDFJS.bidi = (function bidiClosure() {
  36358. // Character types for symbols from 0000 to 00FF.
  36359. var baseTypes = [
  36360. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36361. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36362. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36363. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36364. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36365. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36366. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36367. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36368. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36369. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36370. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36371. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36372. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36373. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36374. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36375. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36376. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36377. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36378. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36379. ];
  36380. // Character types for symbols from 0600 to 06FF
  36381. var arabicTypes = [
  36382. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36383. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36384. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36385. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36386. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36387. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36388. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36389. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36390. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36391. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36392. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36393. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36394. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36395. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36396. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36397. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36398. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36399. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36400. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36401. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36402. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36403. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36404. ];
  36405. function isOdd(i) {
  36406. return (i & 1) !== 0;
  36407. }
  36408. function isEven(i) {
  36409. return (i & 1) === 0;
  36410. }
  36411. function findUnequal(arr, start, value) {
  36412. for (var j = start, jj = arr.length; j < jj; ++j) {
  36413. if (arr[j] !== value) {
  36414. return j;
  36415. }
  36416. }
  36417. return j;
  36418. }
  36419. function setValues(arr, start, end, value) {
  36420. for (var j = start; j < end; ++j) {
  36421. arr[j] = value;
  36422. }
  36423. }
  36424. function reverseValues(arr, start, end) {
  36425. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36426. var temp = arr[i];
  36427. arr[i] = arr[j];
  36428. arr[j] = temp;
  36429. }
  36430. }
  36431. function createBidiText(str, isLTR, vertical) {
  36432. return {
  36433. str: str,
  36434. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36435. };
  36436. }
  36437. // These are used in bidi(), which is called frequently. We re-use them on
  36438. // each call to avoid unnecessary allocations.
  36439. var chars = [];
  36440. var types = [];
  36441. function bidi(str, startLevel, vertical) {
  36442. var isLTR = true;
  36443. var strLength = str.length;
  36444. if (strLength === 0 || vertical) {
  36445. return createBidiText(str, isLTR, vertical);
  36446. }
  36447. // Get types and fill arrays
  36448. chars.length = strLength;
  36449. types.length = strLength;
  36450. var numBidi = 0;
  36451. var i, ii;
  36452. for (i = 0; i < strLength; ++i) {
  36453. chars[i] = str.charAt(i);
  36454. var charCode = str.charCodeAt(i);
  36455. var charType = 'L';
  36456. if (charCode <= 0x00ff) {
  36457. charType = baseTypes[charCode];
  36458. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36459. charType = 'R';
  36460. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36461. charType = arabicTypes[charCode & 0xff];
  36462. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36463. charType = 'AL';
  36464. }
  36465. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36466. numBidi++;
  36467. }
  36468. types[i] = charType;
  36469. }
  36470. // Detect the bidi method
  36471. // - If there are no rtl characters then no bidi needed
  36472. // - If less than 30% chars are rtl then string is primarily ltr
  36473. // - If more than 30% chars are rtl then string is primarily rtl
  36474. if (numBidi === 0) {
  36475. isLTR = true;
  36476. return createBidiText(str, isLTR);
  36477. }
  36478. if (startLevel === -1) {
  36479. if ((strLength / numBidi) < 0.3) {
  36480. isLTR = true;
  36481. startLevel = 0;
  36482. } else {
  36483. isLTR = false;
  36484. startLevel = 1;
  36485. }
  36486. }
  36487. var levels = [];
  36488. for (i = 0; i < strLength; ++i) {
  36489. levels[i] = startLevel;
  36490. }
  36491. /*
  36492. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36493. */
  36494. var e = (isOdd(startLevel) ? 'R' : 'L');
  36495. var sor = e;
  36496. var eor = sor;
  36497. /*
  36498. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36499. type of the NSM to the type of the previous character. If the NSM is at the
  36500. start of the level run, it will get the type of sor.
  36501. */
  36502. var lastType = sor;
  36503. for (i = 0; i < strLength; ++i) {
  36504. if (types[i] === 'NSM') {
  36505. types[i] = lastType;
  36506. } else {
  36507. lastType = types[i];
  36508. }
  36509. }
  36510. /*
  36511. W2. Search backwards from each instance of a European number until the
  36512. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36513. the type of the European number to Arabic number.
  36514. */
  36515. lastType = sor;
  36516. var t;
  36517. for (i = 0; i < strLength; ++i) {
  36518. t = types[i];
  36519. if (t === 'EN') {
  36520. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36521. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36522. lastType = t;
  36523. }
  36524. }
  36525. /*
  36526. W3. Change all ALs to R.
  36527. */
  36528. for (i = 0; i < strLength; ++i) {
  36529. t = types[i];
  36530. if (t === 'AL') {
  36531. types[i] = 'R';
  36532. }
  36533. }
  36534. /*
  36535. W4. A single European separator between two European numbers changes to a
  36536. European number. A single common separator between two numbers of the same
  36537. type changes to that type:
  36538. */
  36539. for (i = 1; i < strLength - 1; ++i) {
  36540. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36541. types[i] = 'EN';
  36542. }
  36543. if (types[i] === 'CS' &&
  36544. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36545. types[i + 1] === types[i - 1]) {
  36546. types[i] = types[i - 1];
  36547. }
  36548. }
  36549. /*
  36550. W5. A sequence of European terminators adjacent to European numbers changes
  36551. to all European numbers:
  36552. */
  36553. for (i = 0; i < strLength; ++i) {
  36554. if (types[i] === 'EN') {
  36555. // do before
  36556. var j;
  36557. for (j = i - 1; j >= 0; --j) {
  36558. if (types[j] !== 'ET') {
  36559. break;
  36560. }
  36561. types[j] = 'EN';
  36562. }
  36563. // do after
  36564. for (j = i + 1; j < strLength; --j) {
  36565. if (types[j] !== 'ET') {
  36566. break;
  36567. }
  36568. types[j] = 'EN';
  36569. }
  36570. }
  36571. }
  36572. /*
  36573. W6. Otherwise, separators and terminators change to Other Neutral:
  36574. */
  36575. for (i = 0; i < strLength; ++i) {
  36576. t = types[i];
  36577. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36578. types[i] = 'ON';
  36579. }
  36580. }
  36581. /*
  36582. W7. Search backwards from each instance of a European number until the
  36583. first strong type (R, L, or sor) is found. If an L is found, then change
  36584. the type of the European number to L.
  36585. */
  36586. lastType = sor;
  36587. for (i = 0; i < strLength; ++i) {
  36588. t = types[i];
  36589. if (t === 'EN') {
  36590. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36591. } else if (t === 'R' || t === 'L') {
  36592. lastType = t;
  36593. }
  36594. }
  36595. /*
  36596. N1. A sequence of neutrals takes the direction of the surrounding strong
  36597. text if the text on both sides has the same direction. European and Arabic
  36598. numbers are treated as though they were R. Start-of-level-run (sor) and
  36599. end-of-level-run (eor) are used at level run boundaries.
  36600. */
  36601. for (i = 0; i < strLength; ++i) {
  36602. if (types[i] === 'ON') {
  36603. var end = findUnequal(types, i + 1, 'ON');
  36604. var before = sor;
  36605. if (i > 0) {
  36606. before = types[i - 1];
  36607. }
  36608. var after = eor;
  36609. if (end + 1 < strLength) {
  36610. after = types[end + 1];
  36611. }
  36612. if (before !== 'L') {
  36613. before = 'R';
  36614. }
  36615. if (after !== 'L') {
  36616. after = 'R';
  36617. }
  36618. if (before === after) {
  36619. setValues(types, i, end, before);
  36620. }
  36621. i = end - 1; // reset to end (-1 so next iteration is ok)
  36622. }
  36623. }
  36624. /*
  36625. N2. Any remaining neutrals take the embedding direction.
  36626. */
  36627. for (i = 0; i < strLength; ++i) {
  36628. if (types[i] === 'ON') {
  36629. types[i] = e;
  36630. }
  36631. }
  36632. /*
  36633. I1. For all characters with an even (left-to-right) embedding direction,
  36634. those of type R go up one level and those of type AN or EN go up two
  36635. levels.
  36636. I2. For all characters with an odd (right-to-left) embedding direction,
  36637. those of type L, EN or AN go up one level.
  36638. */
  36639. for (i = 0; i < strLength; ++i) {
  36640. t = types[i];
  36641. if (isEven(levels[i])) {
  36642. if (t === 'R') {
  36643. levels[i] += 1;
  36644. } else if (t === 'AN' || t === 'EN') {
  36645. levels[i] += 2;
  36646. }
  36647. } else { // isOdd
  36648. if (t === 'L' || t === 'AN' || t === 'EN') {
  36649. levels[i] += 1;
  36650. }
  36651. }
  36652. }
  36653. /*
  36654. L1. On each line, reset the embedding level of the following characters to
  36655. the paragraph embedding level:
  36656. segment separators,
  36657. paragraph separators,
  36658. any sequence of whitespace characters preceding a segment separator or
  36659. paragraph separator, and any sequence of white space characters at the end
  36660. of the line.
  36661. */
  36662. // don't bother as text is only single line
  36663. /*
  36664. L2. From the highest level found in the text to the lowest odd level on
  36665. each line, reverse any contiguous sequence of characters that are at that
  36666. level or higher.
  36667. */
  36668. // find highest level & lowest odd level
  36669. var highestLevel = -1;
  36670. var lowestOddLevel = 99;
  36671. var level;
  36672. for (i = 0, ii = levels.length; i < ii; ++i) {
  36673. level = levels[i];
  36674. if (highestLevel < level) {
  36675. highestLevel = level;
  36676. }
  36677. if (lowestOddLevel > level && isOdd(level)) {
  36678. lowestOddLevel = level;
  36679. }
  36680. }
  36681. // now reverse between those limits
  36682. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36683. // find segments to reverse
  36684. var start = -1;
  36685. for (i = 0, ii = levels.length; i < ii; ++i) {
  36686. if (levels[i] < level) {
  36687. if (start >= 0) {
  36688. reverseValues(chars, start, i);
  36689. start = -1;
  36690. }
  36691. } else if (start < 0) {
  36692. start = i;
  36693. }
  36694. }
  36695. if (start >= 0) {
  36696. reverseValues(chars, start, levels.length);
  36697. }
  36698. }
  36699. /*
  36700. L3. Combining marks applied to a right-to-left base character will at this
  36701. point precede their base character. If the rendering engine expects them to
  36702. follow the base characters in the final display process, then the ordering
  36703. of the marks and the base character must be reversed.
  36704. */
  36705. // don't bother for now
  36706. /*
  36707. L4. A character that possesses the mirrored property as specified by
  36708. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36709. directionality of that character is R.
  36710. */
  36711. // don't mirror as characters are already mirrored in the pdf
  36712. // Finally, return string
  36713. var result = '';
  36714. for (i = 0, ii = chars.length; i < ii; ++i) {
  36715. var ch = chars[i];
  36716. if (ch !== '<' && ch !== '>') {
  36717. result += ch;
  36718. }
  36719. }
  36720. return createBidiText(result, isLTR);
  36721. }
  36722. return bidi;
  36723. })();
  36724. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36725. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36726. /* Copyright 2014 Opera Software ASA
  36727. *
  36728. * Licensed under the Apache License, Version 2.0 (the "License");
  36729. * you may not use this file except in compliance with the License.
  36730. * You may obtain a copy of the License at
  36731. *
  36732. * http://www.apache.org/licenses/LICENSE-2.0
  36733. *
  36734. * Unless required by applicable law or agreed to in writing, software
  36735. * distributed under the License is distributed on an "AS IS" BASIS,
  36736. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36737. * See the License for the specific language governing permissions and
  36738. * limitations under the License.
  36739. *
  36740. *
  36741. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36742. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36743. */
  36744. /* globals Uint32ArrayView */
  36745. 'use strict';
  36746. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36747. // Workaround for missing math precison in JS.
  36748. var MASK_HIGH = 0xffff0000;
  36749. var MASK_LOW = 0xffff;
  36750. function MurmurHash3_64 (seed) {
  36751. var SEED = 0xc3d2e1f0;
  36752. this.h1 = seed ? seed & 0xffffffff : SEED;
  36753. this.h2 = seed ? seed & 0xffffffff : SEED;
  36754. }
  36755. var alwaysUseUint32ArrayView = false;
  36756. // old webkits have issues with non-aligned arrays
  36757. try {
  36758. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36759. } catch (e) {
  36760. alwaysUseUint32ArrayView = true;
  36761. }
  36762. MurmurHash3_64.prototype = {
  36763. update: function MurmurHash3_64_update(input) {
  36764. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36765. var i;
  36766. if (typeof input === 'string') {
  36767. var data = new Uint8Array(input.length * 2);
  36768. var length = 0;
  36769. for (i = 0; i < input.length; i++) {
  36770. var code = input.charCodeAt(i);
  36771. if (code <= 0xff) {
  36772. data[length++] = code;
  36773. }
  36774. else {
  36775. data[length++] = code >>> 8;
  36776. data[length++] = code & 0xff;
  36777. }
  36778. }
  36779. } else if (input instanceof Uint8Array) {
  36780. data = input;
  36781. length = data.length;
  36782. } else if (typeof input === 'object' && ('length' in input)) {
  36783. // processing regular arrays as well, e.g. for IE9
  36784. data = input;
  36785. length = data.length;
  36786. useUint32ArrayView = true;
  36787. } else {
  36788. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36789. 'Input must be a string or array.');
  36790. }
  36791. var blockCounts = length >> 2;
  36792. var tailLength = length - blockCounts * 4;
  36793. // we don't care about endianness here
  36794. var dataUint32 = useUint32ArrayView ?
  36795. new Uint32ArrayView(data, blockCounts) :
  36796. new Uint32Array(data.buffer, 0, blockCounts);
  36797. var k1 = 0;
  36798. var k2 = 0;
  36799. var h1 = this.h1;
  36800. var h2 = this.h2;
  36801. var C1 = 0xcc9e2d51;
  36802. var C2 = 0x1b873593;
  36803. var C1_LOW = C1 & MASK_LOW;
  36804. var C2_LOW = C2 & MASK_LOW;
  36805. for (i = 0; i < blockCounts; i++) {
  36806. if (i & 1) {
  36807. k1 = dataUint32[i];
  36808. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36809. k1 = k1 << 15 | k1 >>> 17;
  36810. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36811. h1 ^= k1;
  36812. h1 = h1 << 13 | h1 >>> 19;
  36813. h1 = h1 * 5 + 0xe6546b64;
  36814. } else {
  36815. k2 = dataUint32[i];
  36816. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36817. k2 = k2 << 15 | k2 >>> 17;
  36818. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36819. h2 ^= k2;
  36820. h2 = h2 << 13 | h2 >>> 19;
  36821. h2 = h2 * 5 + 0xe6546b64;
  36822. }
  36823. }
  36824. k1 = 0;
  36825. switch (tailLength) {
  36826. case 3:
  36827. k1 ^= data[blockCounts * 4 + 2] << 16;
  36828. /* falls through */
  36829. case 2:
  36830. k1 ^= data[blockCounts * 4 + 1] << 8;
  36831. /* falls through */
  36832. case 1:
  36833. k1 ^= data[blockCounts * 4];
  36834. /* falls through */
  36835. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36836. k1 = k1 << 15 | k1 >>> 17;
  36837. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36838. if (blockCounts & 1) {
  36839. h1 ^= k1;
  36840. } else {
  36841. h2 ^= k1;
  36842. }
  36843. }
  36844. this.h1 = h1;
  36845. this.h2 = h2;
  36846. return this;
  36847. },
  36848. hexdigest: function MurmurHash3_64_hexdigest () {
  36849. var h1 = this.h1;
  36850. var h2 = this.h2;
  36851. h1 ^= h2 >>> 1;
  36852. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36853. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36854. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36855. h1 ^= h2 >>> 1;
  36856. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36857. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36858. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36859. h1 ^= h2 >>> 1;
  36860. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36861. var hex = (arr[i] >>> 0).toString(16);
  36862. while (hex.length < 8) {
  36863. hex = '0' + hex;
  36864. }
  36865. str += hex;
  36866. }
  36867. return str;
  36868. }
  36869. };
  36870. return MurmurHash3_64;
  36871. })();
  36872. }).call((typeof window === 'undefined') ? this : window);
  36873. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36874. // workerSrc is not set -- using last script url to define default location
  36875. PDFJS.workerSrc = (function () {
  36876. 'use strict';
  36877. var scriptTagContainer = document.body ||
  36878. document.getElementsByTagName('head')[0];
  36879. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36880. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36881. })();
  36882. }