pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408
  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.187';
  24. PDFJS.build = '8aa1c81';
  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 utf8StringToString(str) {
  868. return unescape(encodeURIComponent(str));
  869. }
  870. function isEmptyObj(obj) {
  871. for (var key in obj) {
  872. return false;
  873. }
  874. return true;
  875. }
  876. function isBool(v) {
  877. return typeof v === 'boolean';
  878. }
  879. function isInt(v) {
  880. return typeof v === 'number' && ((v | 0) === v);
  881. }
  882. function isNum(v) {
  883. return typeof v === 'number';
  884. }
  885. function isString(v) {
  886. return typeof v === 'string';
  887. }
  888. function isName(v) {
  889. return v instanceof Name;
  890. }
  891. function isCmd(v, cmd) {
  892. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  893. }
  894. function isDict(v, type) {
  895. if (!(v instanceof Dict)) {
  896. return false;
  897. }
  898. if (!type) {
  899. return true;
  900. }
  901. var dictType = v.get('Type');
  902. return isName(dictType) && dictType.name === type;
  903. }
  904. function isArray(v) {
  905. return v instanceof Array;
  906. }
  907. function isStream(v) {
  908. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  909. }
  910. function isArrayBuffer(v) {
  911. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  912. }
  913. function isRef(v) {
  914. return v instanceof Ref;
  915. }
  916. /**
  917. * Promise Capability object.
  918. *
  919. * @typedef {Object} PromiseCapability
  920. * @property {Promise} promise - A promise object.
  921. * @property {function} resolve - Fullfills the promise.
  922. * @property {function} reject - Rejects the promise.
  923. */
  924. /**
  925. * Creates a promise capability object.
  926. * @alias PDFJS.createPromiseCapability
  927. *
  928. * @return {PromiseCapability} A capability object contains:
  929. * - a Promise, resolve and reject methods.
  930. */
  931. function createPromiseCapability() {
  932. var capability = {};
  933. capability.promise = new Promise(function (resolve, reject) {
  934. capability.resolve = resolve;
  935. capability.reject = reject;
  936. });
  937. return capability;
  938. }
  939. PDFJS.createPromiseCapability = createPromiseCapability;
  940. /**
  941. * Polyfill for Promises:
  942. * The following promise implementation tries to generally implement the
  943. * Promise/A+ spec. Some notable differences from other promise libaries are:
  944. * - There currently isn't a seperate deferred and promise object.
  945. * - Unhandled rejections eventually show an error if they aren't handled.
  946. *
  947. * Based off of the work in:
  948. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  949. */
  950. (function PromiseClosure() {
  951. if (globalScope.Promise) {
  952. // Promises existing in the DOM/Worker, checking presence of all/resolve
  953. if (typeof globalScope.Promise.all !== 'function') {
  954. globalScope.Promise.all = function (iterable) {
  955. var count = 0, results = [], resolve, reject;
  956. var promise = new globalScope.Promise(function (resolve_, reject_) {
  957. resolve = resolve_;
  958. reject = reject_;
  959. });
  960. iterable.forEach(function (p, i) {
  961. count++;
  962. p.then(function (result) {
  963. results[i] = result;
  964. count--;
  965. if (count === 0) {
  966. resolve(results);
  967. }
  968. }, reject);
  969. });
  970. if (count === 0) {
  971. resolve(results);
  972. }
  973. return promise;
  974. };
  975. }
  976. if (typeof globalScope.Promise.resolve !== 'function') {
  977. globalScope.Promise.resolve = function (value) {
  978. return new globalScope.Promise(function (resolve) { resolve(value); });
  979. };
  980. }
  981. if (typeof globalScope.Promise.reject !== 'function') {
  982. globalScope.Promise.reject = function (reason) {
  983. return new globalScope.Promise(function (resolve, reject) {
  984. reject(reason);
  985. });
  986. };
  987. }
  988. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  989. globalScope.Promise.prototype.catch = function (onReject) {
  990. return globalScope.Promise.prototype.then(undefined, onReject);
  991. };
  992. }
  993. return;
  994. }
  995. var STATUS_PENDING = 0;
  996. var STATUS_RESOLVED = 1;
  997. var STATUS_REJECTED = 2;
  998. // In an attempt to avoid silent exceptions, unhandled rejections are
  999. // tracked and if they aren't handled in a certain amount of time an
  1000. // error is logged.
  1001. var REJECTION_TIMEOUT = 500;
  1002. var HandlerManager = {
  1003. handlers: [],
  1004. running: false,
  1005. unhandledRejections: [],
  1006. pendingRejectionCheck: false,
  1007. scheduleHandlers: function scheduleHandlers(promise) {
  1008. if (promise._status === STATUS_PENDING) {
  1009. return;
  1010. }
  1011. this.handlers = this.handlers.concat(promise._handlers);
  1012. promise._handlers = [];
  1013. if (this.running) {
  1014. return;
  1015. }
  1016. this.running = true;
  1017. setTimeout(this.runHandlers.bind(this), 0);
  1018. },
  1019. runHandlers: function runHandlers() {
  1020. var RUN_TIMEOUT = 1; // ms
  1021. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1022. while (this.handlers.length > 0) {
  1023. var handler = this.handlers.shift();
  1024. var nextStatus = handler.thisPromise._status;
  1025. var nextValue = handler.thisPromise._value;
  1026. try {
  1027. if (nextStatus === STATUS_RESOLVED) {
  1028. if (typeof handler.onResolve === 'function') {
  1029. nextValue = handler.onResolve(nextValue);
  1030. }
  1031. } else if (typeof handler.onReject === 'function') {
  1032. nextValue = handler.onReject(nextValue);
  1033. nextStatus = STATUS_RESOLVED;
  1034. if (handler.thisPromise._unhandledRejection) {
  1035. this.removeUnhandeledRejection(handler.thisPromise);
  1036. }
  1037. }
  1038. } catch (ex) {
  1039. nextStatus = STATUS_REJECTED;
  1040. nextValue = ex;
  1041. }
  1042. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1043. if (Date.now() >= timeoutAt) {
  1044. break;
  1045. }
  1046. }
  1047. if (this.handlers.length > 0) {
  1048. setTimeout(this.runHandlers.bind(this), 0);
  1049. return;
  1050. }
  1051. this.running = false;
  1052. },
  1053. addUnhandledRejection: function addUnhandledRejection(promise) {
  1054. this.unhandledRejections.push({
  1055. promise: promise,
  1056. time: Date.now()
  1057. });
  1058. this.scheduleRejectionCheck();
  1059. },
  1060. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1061. promise._unhandledRejection = false;
  1062. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1063. if (this.unhandledRejections[i].promise === promise) {
  1064. this.unhandledRejections.splice(i);
  1065. i--;
  1066. }
  1067. }
  1068. },
  1069. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1070. if (this.pendingRejectionCheck) {
  1071. return;
  1072. }
  1073. this.pendingRejectionCheck = true;
  1074. setTimeout(function rejectionCheck() {
  1075. this.pendingRejectionCheck = false;
  1076. var now = Date.now();
  1077. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1078. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1079. var unhandled = this.unhandledRejections[i].promise._value;
  1080. var msg = 'Unhandled rejection: ' + unhandled;
  1081. if (unhandled.stack) {
  1082. msg += '\n' + unhandled.stack;
  1083. }
  1084. warn(msg);
  1085. this.unhandledRejections.splice(i);
  1086. i--;
  1087. }
  1088. }
  1089. if (this.unhandledRejections.length) {
  1090. this.scheduleRejectionCheck();
  1091. }
  1092. }.bind(this), REJECTION_TIMEOUT);
  1093. }
  1094. };
  1095. function Promise(resolver) {
  1096. this._status = STATUS_PENDING;
  1097. this._handlers = [];
  1098. try {
  1099. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1100. } catch (e) {
  1101. this._reject(e);
  1102. }
  1103. }
  1104. /**
  1105. * Builds a promise that is resolved when all the passed in promises are
  1106. * resolved.
  1107. * @param {array} array of data and/or promises to wait for.
  1108. * @return {Promise} New dependant promise.
  1109. */
  1110. Promise.all = function Promise_all(promises) {
  1111. var resolveAll, rejectAll;
  1112. var deferred = new Promise(function (resolve, reject) {
  1113. resolveAll = resolve;
  1114. rejectAll = reject;
  1115. });
  1116. var unresolved = promises.length;
  1117. var results = [];
  1118. if (unresolved === 0) {
  1119. resolveAll(results);
  1120. return deferred;
  1121. }
  1122. function reject(reason) {
  1123. if (deferred._status === STATUS_REJECTED) {
  1124. return;
  1125. }
  1126. results = [];
  1127. rejectAll(reason);
  1128. }
  1129. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1130. var promise = promises[i];
  1131. var resolve = (function(i) {
  1132. return function(value) {
  1133. if (deferred._status === STATUS_REJECTED) {
  1134. return;
  1135. }
  1136. results[i] = value;
  1137. unresolved--;
  1138. if (unresolved === 0) {
  1139. resolveAll(results);
  1140. }
  1141. };
  1142. })(i);
  1143. if (Promise.isPromise(promise)) {
  1144. promise.then(resolve, reject);
  1145. } else {
  1146. resolve(promise);
  1147. }
  1148. }
  1149. return deferred;
  1150. };
  1151. /**
  1152. * Checks if the value is likely a promise (has a 'then' function).
  1153. * @return {boolean} true if value is thenable
  1154. */
  1155. Promise.isPromise = function Promise_isPromise(value) {
  1156. return value && typeof value.then === 'function';
  1157. };
  1158. /**
  1159. * Creates resolved promise
  1160. * @param value resolve value
  1161. * @returns {Promise}
  1162. */
  1163. Promise.resolve = function Promise_resolve(value) {
  1164. return new Promise(function (resolve) { resolve(value); });
  1165. };
  1166. /**
  1167. * Creates rejected promise
  1168. * @param reason rejection value
  1169. * @returns {Promise}
  1170. */
  1171. Promise.reject = function Promise_reject(reason) {
  1172. return new Promise(function (resolve, reject) { reject(reason); });
  1173. };
  1174. Promise.prototype = {
  1175. _status: null,
  1176. _value: null,
  1177. _handlers: null,
  1178. _unhandledRejection: null,
  1179. _updateStatus: function Promise__updateStatus(status, value) {
  1180. if (this._status === STATUS_RESOLVED ||
  1181. this._status === STATUS_REJECTED) {
  1182. return;
  1183. }
  1184. if (status === STATUS_RESOLVED &&
  1185. Promise.isPromise(value)) {
  1186. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1187. this._updateStatus.bind(this, STATUS_REJECTED));
  1188. return;
  1189. }
  1190. this._status = status;
  1191. this._value = value;
  1192. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1193. this._unhandledRejection = true;
  1194. HandlerManager.addUnhandledRejection(this);
  1195. }
  1196. HandlerManager.scheduleHandlers(this);
  1197. },
  1198. _resolve: function Promise_resolve(value) {
  1199. this._updateStatus(STATUS_RESOLVED, value);
  1200. },
  1201. _reject: function Promise_reject(reason) {
  1202. this._updateStatus(STATUS_REJECTED, reason);
  1203. },
  1204. then: function Promise_then(onResolve, onReject) {
  1205. var nextPromise = new Promise(function (resolve, reject) {
  1206. this.resolve = resolve;
  1207. this.reject = reject;
  1208. });
  1209. this._handlers.push({
  1210. thisPromise: this,
  1211. onResolve: onResolve,
  1212. onReject: onReject,
  1213. nextPromise: nextPromise
  1214. });
  1215. HandlerManager.scheduleHandlers(this);
  1216. return nextPromise;
  1217. },
  1218. catch: function Promise_catch(onReject) {
  1219. return this.then(undefined, onReject);
  1220. }
  1221. };
  1222. globalScope.Promise = Promise;
  1223. })();
  1224. var StatTimer = (function StatTimerClosure() {
  1225. function rpad(str, pad, length) {
  1226. while (str.length < length) {
  1227. str += pad;
  1228. }
  1229. return str;
  1230. }
  1231. function StatTimer() {
  1232. this.started = {};
  1233. this.times = [];
  1234. this.enabled = true;
  1235. }
  1236. StatTimer.prototype = {
  1237. time: function StatTimer_time(name) {
  1238. if (!this.enabled) {
  1239. return;
  1240. }
  1241. if (name in this.started) {
  1242. warn('Timer is already running for ' + name);
  1243. }
  1244. this.started[name] = Date.now();
  1245. },
  1246. timeEnd: function StatTimer_timeEnd(name) {
  1247. if (!this.enabled) {
  1248. return;
  1249. }
  1250. if (!(name in this.started)) {
  1251. warn('Timer has not been started for ' + name);
  1252. }
  1253. this.times.push({
  1254. 'name': name,
  1255. 'start': this.started[name],
  1256. 'end': Date.now()
  1257. });
  1258. // Remove timer from started so it can be called again.
  1259. delete this.started[name];
  1260. },
  1261. toString: function StatTimer_toString() {
  1262. var i, ii;
  1263. var times = this.times;
  1264. var out = '';
  1265. // Find the longest name for padding purposes.
  1266. var longest = 0;
  1267. for (i = 0, ii = times.length; i < ii; ++i) {
  1268. var name = times[i]['name'];
  1269. if (name.length > longest) {
  1270. longest = name.length;
  1271. }
  1272. }
  1273. for (i = 0, ii = times.length; i < ii; ++i) {
  1274. var span = times[i];
  1275. var duration = span.end - span.start;
  1276. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1277. }
  1278. return out;
  1279. }
  1280. };
  1281. return StatTimer;
  1282. })();
  1283. PDFJS.createBlob = function createBlob(data, contentType) {
  1284. if (typeof Blob !== 'undefined') {
  1285. return new Blob([data], { type: contentType });
  1286. }
  1287. // Blob builder is deprecated in FF14 and removed in FF18.
  1288. var bb = new MozBlobBuilder();
  1289. bb.append(data);
  1290. return bb.getBlob(contentType);
  1291. };
  1292. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1293. // Blob/createObjectURL is not available, falling back to data schema.
  1294. var digits =
  1295. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1296. return function createObjectURL(data, contentType) {
  1297. if (!PDFJS.disableCreateObjectURL &&
  1298. typeof URL !== 'undefined' && URL.createObjectURL) {
  1299. var blob = PDFJS.createBlob(data, contentType);
  1300. return URL.createObjectURL(blob);
  1301. }
  1302. var buffer = 'data:' + contentType + ';base64,';
  1303. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1304. var b1 = data[i] & 0xFF;
  1305. var b2 = data[i + 1] & 0xFF;
  1306. var b3 = data[i + 2] & 0xFF;
  1307. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1308. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1309. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1310. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1311. }
  1312. return buffer;
  1313. };
  1314. })();
  1315. function MessageHandler(name, comObj) {
  1316. this.name = name;
  1317. this.comObj = comObj;
  1318. this.callbackIndex = 1;
  1319. this.postMessageTransfers = true;
  1320. var callbacksCapabilities = this.callbacksCapabilities = {};
  1321. var ah = this.actionHandler = {};
  1322. ah['console_log'] = [function ahConsoleLog(data) {
  1323. console.log.apply(console, data);
  1324. }];
  1325. ah['console_error'] = [function ahConsoleError(data) {
  1326. console.error.apply(console, data);
  1327. }];
  1328. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1329. UnsupportedManager.notify(data);
  1330. }];
  1331. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1332. var data = event.data;
  1333. if (data.isReply) {
  1334. var callbackId = data.callbackId;
  1335. if (data.callbackId in callbacksCapabilities) {
  1336. var callback = callbacksCapabilities[callbackId];
  1337. delete callbacksCapabilities[callbackId];
  1338. if ('error' in data) {
  1339. callback.reject(data.error);
  1340. } else {
  1341. callback.resolve(data.data);
  1342. }
  1343. } else {
  1344. error('Cannot resolve callback ' + callbackId);
  1345. }
  1346. } else if (data.action in ah) {
  1347. var action = ah[data.action];
  1348. if (data.callbackId) {
  1349. Promise.resolve().then(function () {
  1350. return action[0].call(action[1], data.data);
  1351. }).then(function (result) {
  1352. comObj.postMessage({
  1353. isReply: true,
  1354. callbackId: data.callbackId,
  1355. data: result
  1356. });
  1357. }, function (reason) {
  1358. comObj.postMessage({
  1359. isReply: true,
  1360. callbackId: data.callbackId,
  1361. error: reason
  1362. });
  1363. });
  1364. } else {
  1365. action[0].call(action[1], data.data);
  1366. }
  1367. } else {
  1368. error('Unknown action from worker: ' + data.action);
  1369. }
  1370. };
  1371. }
  1372. MessageHandler.prototype = {
  1373. on: function messageHandlerOn(actionName, handler, scope) {
  1374. var ah = this.actionHandler;
  1375. if (ah[actionName]) {
  1376. error('There is already an actionName called "' + actionName + '"');
  1377. }
  1378. ah[actionName] = [handler, scope];
  1379. },
  1380. /**
  1381. * Sends a message to the comObj to invoke the action with the supplied data.
  1382. * @param {String} actionName Action to call.
  1383. * @param {JSON} data JSON data to send.
  1384. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1385. */
  1386. send: function messageHandlerSend(actionName, data, transfers) {
  1387. var message = {
  1388. action: actionName,
  1389. data: data
  1390. };
  1391. this.postMessage(message, transfers);
  1392. },
  1393. /**
  1394. * Sends a message to the comObj to invoke the action with the supplied data.
  1395. * Expects that other side will callback with the response.
  1396. * @param {String} actionName Action to call.
  1397. * @param {JSON} data JSON data to send.
  1398. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1399. * @returns {Promise} Promise to be resolved with response data.
  1400. */
  1401. sendWithPromise:
  1402. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1403. var callbackId = this.callbackIndex++;
  1404. var message = {
  1405. action: actionName,
  1406. data: data,
  1407. callbackId: callbackId
  1408. };
  1409. var capability = createPromiseCapability();
  1410. this.callbacksCapabilities[callbackId] = capability;
  1411. try {
  1412. this.postMessage(message, transfers);
  1413. } catch (e) {
  1414. capability.reject(e);
  1415. }
  1416. return capability.promise;
  1417. },
  1418. /**
  1419. * Sends raw message to the comObj.
  1420. * @private
  1421. * @param message {Object} Raw message.
  1422. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1423. */
  1424. postMessage: function (message, transfers) {
  1425. if (transfers && this.postMessageTransfers) {
  1426. this.comObj.postMessage(message, transfers);
  1427. } else {
  1428. this.comObj.postMessage(message);
  1429. }
  1430. }
  1431. };
  1432. function loadJpegStream(id, imageUrl, objs) {
  1433. var img = new Image();
  1434. img.onload = (function loadJpegStream_onloadClosure() {
  1435. objs.resolve(id, img);
  1436. });
  1437. img.onerror = (function loadJpegStream_onerrorClosure() {
  1438. objs.resolve(id, null);
  1439. warn('Error during JPEG image loading');
  1440. });
  1441. img.src = imageUrl;
  1442. }
  1443. var NetworkManager = (function NetworkManagerClosure() {
  1444. var OK_RESPONSE = 200;
  1445. var PARTIAL_CONTENT_RESPONSE = 206;
  1446. function NetworkManager(url, args) {
  1447. this.url = url;
  1448. args = args || {};
  1449. this.isHttp = /^https?:/i.test(url);
  1450. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1451. this.withCredentials = args.withCredentials || false;
  1452. this.getXhr = args.getXhr ||
  1453. function NetworkManager_getXhr() {
  1454. return new XMLHttpRequest();
  1455. };
  1456. this.currXhrId = 0;
  1457. this.pendingRequests = {};
  1458. this.loadedRequests = {};
  1459. }
  1460. function getArrayBuffer(xhr) {
  1461. var data = xhr.response;
  1462. if (typeof data !== 'string') {
  1463. return data;
  1464. }
  1465. var length = data.length;
  1466. var array = new Uint8Array(length);
  1467. for (var i = 0; i < length; i++) {
  1468. array[i] = data.charCodeAt(i) & 0xFF;
  1469. }
  1470. return array.buffer;
  1471. }
  1472. NetworkManager.prototype = {
  1473. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1474. var args = {
  1475. begin: begin,
  1476. end: end
  1477. };
  1478. for (var prop in listeners) {
  1479. args[prop] = listeners[prop];
  1480. }
  1481. return this.request(args);
  1482. },
  1483. requestFull: function NetworkManager_requestFull(listeners) {
  1484. return this.request(listeners);
  1485. },
  1486. request: function NetworkManager_request(args) {
  1487. var xhr = this.getXhr();
  1488. var xhrId = this.currXhrId++;
  1489. var pendingRequest = this.pendingRequests[xhrId] = {
  1490. xhr: xhr
  1491. };
  1492. xhr.open('GET', this.url);
  1493. xhr.withCredentials = this.withCredentials;
  1494. for (var property in this.httpHeaders) {
  1495. var value = this.httpHeaders[property];
  1496. if (typeof value === 'undefined') {
  1497. continue;
  1498. }
  1499. xhr.setRequestHeader(property, value);
  1500. }
  1501. if (this.isHttp && 'begin' in args && 'end' in args) {
  1502. var rangeStr = args.begin + '-' + (args.end - 1);
  1503. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1504. pendingRequest.expectedStatus = 206;
  1505. } else {
  1506. pendingRequest.expectedStatus = 200;
  1507. }
  1508. if (args.onProgressiveData) {
  1509. // Some legacy browsers might throw an exception.
  1510. try {
  1511. xhr.responseType = 'moz-chunked-arraybuffer';
  1512. } catch(e) {}
  1513. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1514. pendingRequest.onProgressiveData = args.onProgressiveData;
  1515. pendingRequest.mozChunked = true;
  1516. } else {
  1517. xhr.responseType = 'arraybuffer';
  1518. }
  1519. } else {
  1520. xhr.responseType = 'arraybuffer';
  1521. }
  1522. if (args.onError) {
  1523. xhr.onerror = function(evt) {
  1524. args.onError(xhr.status);
  1525. };
  1526. }
  1527. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1528. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1529. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1530. pendingRequest.onDone = args.onDone;
  1531. pendingRequest.onError = args.onError;
  1532. pendingRequest.onProgress = args.onProgress;
  1533. xhr.send(null);
  1534. return xhrId;
  1535. },
  1536. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1537. var pendingRequest = this.pendingRequests[xhrId];
  1538. if (!pendingRequest) {
  1539. // Maybe abortRequest was called...
  1540. return;
  1541. }
  1542. if (pendingRequest.mozChunked) {
  1543. var chunk = getArrayBuffer(pendingRequest.xhr);
  1544. pendingRequest.onProgressiveData(chunk);
  1545. }
  1546. var onProgress = pendingRequest.onProgress;
  1547. if (onProgress) {
  1548. onProgress(evt);
  1549. }
  1550. },
  1551. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1552. var pendingRequest = this.pendingRequests[xhrId];
  1553. if (!pendingRequest) {
  1554. // Maybe abortRequest was called...
  1555. return;
  1556. }
  1557. var xhr = pendingRequest.xhr;
  1558. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1559. pendingRequest.onHeadersReceived();
  1560. delete pendingRequest.onHeadersReceived;
  1561. }
  1562. if (xhr.readyState !== 4) {
  1563. return;
  1564. }
  1565. if (!(xhrId in this.pendingRequests)) {
  1566. // The XHR request might have been aborted in onHeadersReceived()
  1567. // callback, in which case we should abort request
  1568. return;
  1569. }
  1570. delete this.pendingRequests[xhrId];
  1571. // success status == 0 can be on ftp, file and other protocols
  1572. if (xhr.status === 0 && this.isHttp) {
  1573. if (pendingRequest.onError) {
  1574. pendingRequest.onError(xhr.status);
  1575. }
  1576. return;
  1577. }
  1578. var xhrStatus = xhr.status || OK_RESPONSE;
  1579. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1580. // "A server MAY ignore the Range header". This means it's possible to
  1581. // get a 200 rather than a 206 response from a range request.
  1582. var ok_response_on_range_request =
  1583. xhrStatus === OK_RESPONSE &&
  1584. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1585. if (!ok_response_on_range_request &&
  1586. xhrStatus !== pendingRequest.expectedStatus) {
  1587. if (pendingRequest.onError) {
  1588. pendingRequest.onError(xhr.status);
  1589. }
  1590. return;
  1591. }
  1592. this.loadedRequests[xhrId] = true;
  1593. var chunk = getArrayBuffer(xhr);
  1594. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1595. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1596. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1597. var begin = parseInt(matches[1], 10);
  1598. pendingRequest.onDone({
  1599. begin: begin,
  1600. chunk: chunk
  1601. });
  1602. } else if (pendingRequest.onProgressiveData) {
  1603. pendingRequest.onDone(null);
  1604. } else {
  1605. pendingRequest.onDone({
  1606. begin: 0,
  1607. chunk: chunk
  1608. });
  1609. }
  1610. },
  1611. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1612. for (var xhrId in this.pendingRequests) {
  1613. return true;
  1614. }
  1615. return false;
  1616. },
  1617. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1618. return this.pendingRequests[xhrId].xhr;
  1619. },
  1620. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1621. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1622. },
  1623. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1624. return xhrId in this.pendingRequests;
  1625. },
  1626. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1627. return xhrId in this.loadedRequests;
  1628. },
  1629. abortAllRequests: function NetworkManager_abortAllRequests() {
  1630. for (var xhrId in this.pendingRequests) {
  1631. this.abortRequest(xhrId | 0);
  1632. }
  1633. },
  1634. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1635. var xhr = this.pendingRequests[xhrId].xhr;
  1636. delete this.pendingRequests[xhrId];
  1637. xhr.abort();
  1638. }
  1639. };
  1640. return NetworkManager;
  1641. })();
  1642. var ChunkedStream = (function ChunkedStreamClosure() {
  1643. function ChunkedStream(length, chunkSize, manager) {
  1644. this.bytes = new Uint8Array(length);
  1645. this.start = 0;
  1646. this.pos = 0;
  1647. this.end = length;
  1648. this.chunkSize = chunkSize;
  1649. this.loadedChunks = [];
  1650. this.numChunksLoaded = 0;
  1651. this.numChunks = Math.ceil(length / chunkSize);
  1652. this.manager = manager;
  1653. this.progressiveDataLength = 0;
  1654. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1655. }
  1656. // required methods for a stream. if a particular stream does not
  1657. // implement these, an error should be thrown
  1658. ChunkedStream.prototype = {
  1659. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1660. var chunks = [];
  1661. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1662. if (!this.loadedChunks[chunk]) {
  1663. chunks.push(chunk);
  1664. }
  1665. }
  1666. return chunks;
  1667. },
  1668. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1669. return [this];
  1670. },
  1671. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1672. return this.numChunksLoaded === this.numChunks;
  1673. },
  1674. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1675. var end = begin + chunk.byteLength;
  1676. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1677. // Using this.length is inaccurate here since this.start can be moved
  1678. // See ChunkedStream.moveStart()
  1679. var length = this.bytes.length;
  1680. assert(end % this.chunkSize === 0 || end === length,
  1681. 'Bad end offset: ' + end);
  1682. this.bytes.set(new Uint8Array(chunk), begin);
  1683. var chunkSize = this.chunkSize;
  1684. var beginChunk = Math.floor(begin / chunkSize);
  1685. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1686. var curChunk;
  1687. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1688. if (!this.loadedChunks[curChunk]) {
  1689. this.loadedChunks[curChunk] = true;
  1690. ++this.numChunksLoaded;
  1691. }
  1692. }
  1693. },
  1694. onReceiveProgressiveData:
  1695. function ChunkedStream_onReceiveProgressiveData(data) {
  1696. var position = this.progressiveDataLength;
  1697. var beginChunk = Math.floor(position / this.chunkSize);
  1698. this.bytes.set(new Uint8Array(data), position);
  1699. position += data.byteLength;
  1700. this.progressiveDataLength = position;
  1701. var endChunk = position >= this.end ? this.numChunks :
  1702. Math.floor(position / this.chunkSize);
  1703. var curChunk;
  1704. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1705. if (!this.loadedChunks[curChunk]) {
  1706. this.loadedChunks[curChunk] = true;
  1707. ++this.numChunksLoaded;
  1708. }
  1709. }
  1710. },
  1711. ensureByte: function ChunkedStream_ensureByte(pos) {
  1712. var chunk = Math.floor(pos / this.chunkSize);
  1713. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1714. return;
  1715. }
  1716. if (!this.loadedChunks[chunk]) {
  1717. throw new MissingDataException(pos, pos + 1);
  1718. }
  1719. this.lastSuccessfulEnsureByteChunk = chunk;
  1720. },
  1721. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1722. if (begin >= end) {
  1723. return;
  1724. }
  1725. if (end <= this.progressiveDataLength) {
  1726. return;
  1727. }
  1728. var chunkSize = this.chunkSize;
  1729. var beginChunk = Math.floor(begin / chunkSize);
  1730. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1731. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1732. if (!this.loadedChunks[chunk]) {
  1733. throw new MissingDataException(begin, end);
  1734. }
  1735. }
  1736. },
  1737. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1738. var chunk, n;
  1739. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1740. if (!this.loadedChunks[chunk]) {
  1741. return chunk;
  1742. }
  1743. }
  1744. // Wrap around to beginning
  1745. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1746. if (!this.loadedChunks[chunk]) {
  1747. return chunk;
  1748. }
  1749. }
  1750. return null;
  1751. },
  1752. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1753. return !!this.loadedChunks[chunk];
  1754. },
  1755. get length() {
  1756. return this.end - this.start;
  1757. },
  1758. get isEmpty() {
  1759. return this.length === 0;
  1760. },
  1761. getByte: function ChunkedStream_getByte() {
  1762. var pos = this.pos;
  1763. if (pos >= this.end) {
  1764. return -1;
  1765. }
  1766. this.ensureByte(pos);
  1767. return this.bytes[this.pos++];
  1768. },
  1769. getUint16: function ChunkedStream_getUint16() {
  1770. var b0 = this.getByte();
  1771. var b1 = this.getByte();
  1772. if (b0 === -1 || b1 === -1) {
  1773. return -1;
  1774. }
  1775. return (b0 << 8) + b1;
  1776. },
  1777. getInt32: function ChunkedStream_getInt32() {
  1778. var b0 = this.getByte();
  1779. var b1 = this.getByte();
  1780. var b2 = this.getByte();
  1781. var b3 = this.getByte();
  1782. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1783. },
  1784. // returns subarray of original buffer
  1785. // should only be read
  1786. getBytes: function ChunkedStream_getBytes(length) {
  1787. var bytes = this.bytes;
  1788. var pos = this.pos;
  1789. var strEnd = this.end;
  1790. if (!length) {
  1791. this.ensureRange(pos, strEnd);
  1792. return bytes.subarray(pos, strEnd);
  1793. }
  1794. var end = pos + length;
  1795. if (end > strEnd) {
  1796. end = strEnd;
  1797. }
  1798. this.ensureRange(pos, end);
  1799. this.pos = end;
  1800. return bytes.subarray(pos, end);
  1801. },
  1802. peekByte: function ChunkedStream_peekByte() {
  1803. var peekedByte = this.getByte();
  1804. this.pos--;
  1805. return peekedByte;
  1806. },
  1807. peekBytes: function ChunkedStream_peekBytes(length) {
  1808. var bytes = this.getBytes(length);
  1809. this.pos -= bytes.length;
  1810. return bytes;
  1811. },
  1812. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1813. this.ensureRange(begin, end);
  1814. return this.bytes.subarray(begin, end);
  1815. },
  1816. skip: function ChunkedStream_skip(n) {
  1817. if (!n) {
  1818. n = 1;
  1819. }
  1820. this.pos += n;
  1821. },
  1822. reset: function ChunkedStream_reset() {
  1823. this.pos = this.start;
  1824. },
  1825. moveStart: function ChunkedStream_moveStart() {
  1826. this.start = this.pos;
  1827. },
  1828. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1829. this.ensureRange(start, start + length);
  1830. function ChunkedStreamSubstream() {}
  1831. ChunkedStreamSubstream.prototype = Object.create(this);
  1832. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1833. var chunkSize = this.chunkSize;
  1834. var beginChunk = Math.floor(this.start / chunkSize);
  1835. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1836. var missingChunks = [];
  1837. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1838. if (!this.loadedChunks[chunk]) {
  1839. missingChunks.push(chunk);
  1840. }
  1841. }
  1842. return missingChunks;
  1843. };
  1844. var subStream = new ChunkedStreamSubstream();
  1845. subStream.pos = subStream.start = start;
  1846. subStream.end = start + length || this.end;
  1847. subStream.dict = dict;
  1848. return subStream;
  1849. },
  1850. isStream: true
  1851. };
  1852. return ChunkedStream;
  1853. })();
  1854. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1855. function ChunkedStreamManager(length, chunkSize, url, args) {
  1856. this.stream = new ChunkedStream(length, chunkSize, this);
  1857. this.length = length;
  1858. this.chunkSize = chunkSize;
  1859. this.url = url;
  1860. this.disableAutoFetch = args.disableAutoFetch;
  1861. var msgHandler = this.msgHandler = args.msgHandler;
  1862. if (args.chunkedViewerLoading) {
  1863. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1864. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1865. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1866. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1867. };
  1868. } else {
  1869. var getXhr = function getXhr() {
  1870. return new XMLHttpRequest();
  1871. };
  1872. this.networkManager = new NetworkManager(this.url, {
  1873. getXhr: getXhr,
  1874. httpHeaders: args.httpHeaders,
  1875. withCredentials: args.withCredentials
  1876. });
  1877. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1878. this.networkManager.requestRange(begin, end, {
  1879. onDone: this.onReceiveData.bind(this),
  1880. onProgress: this.onProgress.bind(this)
  1881. });
  1882. };
  1883. }
  1884. this.currRequestId = 0;
  1885. this.chunksNeededByRequest = {};
  1886. this.requestsByChunk = {};
  1887. this.callbacksByRequest = {};
  1888. this.progressiveDataLength = 0;
  1889. this._loadedStreamCapability = createPromiseCapability();
  1890. if (args.initialData) {
  1891. this.onReceiveData({chunk: args.initialData});
  1892. }
  1893. }
  1894. ChunkedStreamManager.prototype = {
  1895. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1896. return this._loadedStreamCapability.promise;
  1897. },
  1898. // Get all the chunks that are not yet loaded and groups them into
  1899. // contiguous ranges to load in as few requests as possible
  1900. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1901. var missingChunks = this.stream.getMissingChunks();
  1902. this.requestChunks(missingChunks);
  1903. return this._loadedStreamCapability.promise;
  1904. },
  1905. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1906. callback) {
  1907. var requestId = this.currRequestId++;
  1908. var chunksNeeded;
  1909. var i, ii;
  1910. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1911. for (i = 0, ii = chunks.length; i < ii; i++) {
  1912. if (!this.stream.hasChunk(chunks[i])) {
  1913. chunksNeeded[chunks[i]] = true;
  1914. }
  1915. }
  1916. if (isEmptyObj(chunksNeeded)) {
  1917. if (callback) {
  1918. callback();
  1919. }
  1920. return;
  1921. }
  1922. this.callbacksByRequest[requestId] = callback;
  1923. var chunksToRequest = [];
  1924. for (var chunk in chunksNeeded) {
  1925. chunk = chunk | 0;
  1926. if (!(chunk in this.requestsByChunk)) {
  1927. this.requestsByChunk[chunk] = [];
  1928. chunksToRequest.push(chunk);
  1929. }
  1930. this.requestsByChunk[chunk].push(requestId);
  1931. }
  1932. if (!chunksToRequest.length) {
  1933. return;
  1934. }
  1935. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1936. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1937. var groupedChunk = groupedChunksToRequest[i];
  1938. var begin = groupedChunk.beginChunk * this.chunkSize;
  1939. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1940. this.sendRequest(begin, end);
  1941. }
  1942. },
  1943. getStream: function ChunkedStreamManager_getStream() {
  1944. return this.stream;
  1945. },
  1946. // Loads any chunks in the requested range that are not yet loaded
  1947. requestRange: function ChunkedStreamManager_requestRange(
  1948. begin, end, callback) {
  1949. end = Math.min(end, this.length);
  1950. var beginChunk = this.getBeginChunk(begin);
  1951. var endChunk = this.getEndChunk(end);
  1952. var chunks = [];
  1953. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1954. chunks.push(chunk);
  1955. }
  1956. this.requestChunks(chunks, callback);
  1957. },
  1958. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1959. callback) {
  1960. ranges = ranges || [];
  1961. var chunksToRequest = [];
  1962. for (var i = 0; i < ranges.length; i++) {
  1963. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1964. var endChunk = this.getEndChunk(ranges[i].end);
  1965. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1966. if (chunksToRequest.indexOf(chunk) < 0) {
  1967. chunksToRequest.push(chunk);
  1968. }
  1969. }
  1970. }
  1971. chunksToRequest.sort(function(a, b) { return a - b; });
  1972. this.requestChunks(chunksToRequest, callback);
  1973. },
  1974. // Groups a sorted array of chunks into as few continguous larger
  1975. // chunks as possible
  1976. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1977. var groupedChunks = [];
  1978. var beginChunk = -1;
  1979. var prevChunk = -1;
  1980. for (var i = 0; i < chunks.length; ++i) {
  1981. var chunk = chunks[i];
  1982. if (beginChunk < 0) {
  1983. beginChunk = chunk;
  1984. }
  1985. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1986. groupedChunks.push({ beginChunk: beginChunk,
  1987. endChunk: prevChunk + 1 });
  1988. beginChunk = chunk;
  1989. }
  1990. if (i + 1 === chunks.length) {
  1991. groupedChunks.push({ beginChunk: beginChunk,
  1992. endChunk: chunk + 1 });
  1993. }
  1994. prevChunk = chunk;
  1995. }
  1996. return groupedChunks;
  1997. },
  1998. onProgress: function ChunkedStreamManager_onProgress(args) {
  1999. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2000. args.loaded);
  2001. this.msgHandler.send('DocProgress', {
  2002. loaded: bytesLoaded,
  2003. total: this.length
  2004. });
  2005. },
  2006. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2007. var chunk = args.chunk;
  2008. var isProgressive = args.begin === undefined;
  2009. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2010. var end = begin + chunk.byteLength;
  2011. var beginChunk = Math.floor(begin / this.chunkSize);
  2012. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2013. Math.ceil(end / this.chunkSize);
  2014. if (isProgressive) {
  2015. this.stream.onReceiveProgressiveData(chunk);
  2016. this.progressiveDataLength = end;
  2017. } else {
  2018. this.stream.onReceiveData(begin, chunk);
  2019. }
  2020. if (this.stream.allChunksLoaded()) {
  2021. this._loadedStreamCapability.resolve(this.stream);
  2022. }
  2023. var loadedRequests = [];
  2024. var i, requestId;
  2025. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2026. // The server might return more chunks than requested
  2027. var requestIds = this.requestsByChunk[chunk] || [];
  2028. delete this.requestsByChunk[chunk];
  2029. for (i = 0; i < requestIds.length; ++i) {
  2030. requestId = requestIds[i];
  2031. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2032. if (chunk in chunksNeeded) {
  2033. delete chunksNeeded[chunk];
  2034. }
  2035. if (!isEmptyObj(chunksNeeded)) {
  2036. continue;
  2037. }
  2038. loadedRequests.push(requestId);
  2039. }
  2040. }
  2041. // If there are no pending requests, automatically fetch the next
  2042. // unfetched chunk of the PDF
  2043. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2044. var nextEmptyChunk;
  2045. if (this.stream.numChunksLoaded === 1) {
  2046. // This is a special optimization so that after fetching the first
  2047. // chunk, rather than fetching the second chunk, we fetch the last
  2048. // chunk.
  2049. var lastChunk = this.stream.numChunks - 1;
  2050. if (!this.stream.hasChunk(lastChunk)) {
  2051. nextEmptyChunk = lastChunk;
  2052. }
  2053. } else {
  2054. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2055. }
  2056. if (isInt(nextEmptyChunk)) {
  2057. this.requestChunks([nextEmptyChunk]);
  2058. }
  2059. }
  2060. for (i = 0; i < loadedRequests.length; ++i) {
  2061. requestId = loadedRequests[i];
  2062. var callback = this.callbacksByRequest[requestId];
  2063. delete this.callbacksByRequest[requestId];
  2064. if (callback) {
  2065. callback();
  2066. }
  2067. }
  2068. this.msgHandler.send('DocProgress', {
  2069. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2070. total: this.length
  2071. });
  2072. },
  2073. onError: function ChunkedStreamManager_onError(err) {
  2074. this._loadedStreamCapability.reject(err);
  2075. },
  2076. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2077. var chunk = Math.floor(begin / this.chunkSize);
  2078. return chunk;
  2079. },
  2080. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2081. if (end % this.chunkSize === 0) {
  2082. return end / this.chunkSize;
  2083. }
  2084. // 0 -> 0
  2085. // 1 -> 1
  2086. // 99 -> 1
  2087. // 100 -> 1
  2088. // 101 -> 2
  2089. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2090. return chunk;
  2091. }
  2092. };
  2093. return ChunkedStreamManager;
  2094. })();
  2095. // The maximum number of bytes fetched per range request
  2096. var RANGE_CHUNK_SIZE = 65536;
  2097. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2098. var BasePdfManager = (function BasePdfManagerClosure() {
  2099. function BasePdfManager() {
  2100. throw new Error('Cannot initialize BaseManagerManager');
  2101. }
  2102. BasePdfManager.prototype = {
  2103. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2104. throw new NotImplementedException();
  2105. },
  2106. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2107. return this.ensure(this.pdfDocument, prop, args);
  2108. },
  2109. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2110. return this.ensure(this.pdfDocument.xref, prop, args);
  2111. },
  2112. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2113. return this.ensure(this.pdfDocument.catalog, prop, args);
  2114. },
  2115. getPage: function BasePdfManager_pagePage(pageIndex) {
  2116. return this.pdfDocument.getPage(pageIndex);
  2117. },
  2118. cleanup: function BasePdfManager_cleanup() {
  2119. return this.pdfDocument.cleanup();
  2120. },
  2121. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2122. return new NotImplementedException();
  2123. },
  2124. requestRange: function BasePdfManager_ensure(begin, end) {
  2125. return new NotImplementedException();
  2126. },
  2127. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2128. return new NotImplementedException();
  2129. },
  2130. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2131. return new NotImplementedException();
  2132. },
  2133. updatePassword: function BasePdfManager_updatePassword(password) {
  2134. this.pdfDocument.xref.password = this.password = password;
  2135. if (this._passwordChangedCapability) {
  2136. this._passwordChangedCapability.resolve();
  2137. }
  2138. },
  2139. passwordChanged: function BasePdfManager_passwordChanged() {
  2140. this._passwordChangedCapability = createPromiseCapability();
  2141. return this._passwordChangedCapability.promise;
  2142. },
  2143. terminate: function BasePdfManager_terminate() {
  2144. return new NotImplementedException();
  2145. }
  2146. };
  2147. return BasePdfManager;
  2148. })();
  2149. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2150. function LocalPdfManager(data, password) {
  2151. var stream = new Stream(data);
  2152. this.pdfDocument = new PDFDocument(this, stream, password);
  2153. this._loadedStreamCapability = createPromiseCapability();
  2154. this._loadedStreamCapability.resolve(stream);
  2155. }
  2156. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2157. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2158. LocalPdfManager.prototype.ensure =
  2159. function LocalPdfManager_ensure(obj, prop, args) {
  2160. return new Promise(function (resolve, reject) {
  2161. try {
  2162. var value = obj[prop];
  2163. var result;
  2164. if (typeof value === 'function') {
  2165. result = value.apply(obj, args);
  2166. } else {
  2167. result = value;
  2168. }
  2169. resolve(result);
  2170. } catch (e) {
  2171. reject(e);
  2172. }
  2173. });
  2174. };
  2175. LocalPdfManager.prototype.requestRange =
  2176. function LocalPdfManager_requestRange(begin, end) {
  2177. return Promise.resolve();
  2178. };
  2179. LocalPdfManager.prototype.requestLoadedStream =
  2180. function LocalPdfManager_requestLoadedStream() {
  2181. };
  2182. LocalPdfManager.prototype.onLoadedStream =
  2183. function LocalPdfManager_getLoadedStream() {
  2184. return this._loadedStreamCapability.promise;
  2185. };
  2186. LocalPdfManager.prototype.terminate =
  2187. function LocalPdfManager_terminate() {
  2188. return;
  2189. };
  2190. return LocalPdfManager;
  2191. })();
  2192. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2193. function NetworkPdfManager(args, msgHandler) {
  2194. this.msgHandler = msgHandler;
  2195. var params = {
  2196. msgHandler: msgHandler,
  2197. httpHeaders: args.httpHeaders,
  2198. withCredentials: args.withCredentials,
  2199. chunkedViewerLoading: args.chunkedViewerLoading,
  2200. disableAutoFetch: args.disableAutoFetch,
  2201. initialData: args.initialData
  2202. };
  2203. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2204. args.url, params);
  2205. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2206. args.password);
  2207. }
  2208. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2209. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2210. NetworkPdfManager.prototype.ensure =
  2211. function NetworkPdfManager_ensure(obj, prop, args) {
  2212. var pdfManager = this;
  2213. return new Promise(function (resolve, reject) {
  2214. function ensureHelper() {
  2215. try {
  2216. var result;
  2217. var value = obj[prop];
  2218. if (typeof value === 'function') {
  2219. result = value.apply(obj, args);
  2220. } else {
  2221. result = value;
  2222. }
  2223. resolve(result);
  2224. } catch(e) {
  2225. if (!(e instanceof MissingDataException)) {
  2226. reject(e);
  2227. return;
  2228. }
  2229. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2230. }
  2231. }
  2232. ensureHelper();
  2233. });
  2234. };
  2235. NetworkPdfManager.prototype.requestRange =
  2236. function NetworkPdfManager_requestRange(begin, end) {
  2237. return new Promise(function (resolve) {
  2238. this.streamManager.requestRange(begin, end, function() {
  2239. resolve();
  2240. });
  2241. }.bind(this));
  2242. };
  2243. NetworkPdfManager.prototype.requestLoadedStream =
  2244. function NetworkPdfManager_requestLoadedStream() {
  2245. this.streamManager.requestAllChunks();
  2246. };
  2247. NetworkPdfManager.prototype.sendProgressiveData =
  2248. function NetworkPdfManager_sendProgressiveData(chunk) {
  2249. this.streamManager.onReceiveData({ chunk: chunk });
  2250. };
  2251. NetworkPdfManager.prototype.onLoadedStream =
  2252. function NetworkPdfManager_getLoadedStream() {
  2253. return this.streamManager.onLoadedStream();
  2254. };
  2255. NetworkPdfManager.prototype.terminate =
  2256. function NetworkPdfManager_terminate() {
  2257. this.streamManager.networkManager.abortAllRequests();
  2258. };
  2259. return NetworkPdfManager;
  2260. })();
  2261. var Page = (function PageClosure() {
  2262. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2263. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2264. this.pdfManager = pdfManager;
  2265. this.pageIndex = pageIndex;
  2266. this.pageDict = pageDict;
  2267. this.xref = xref;
  2268. this.ref = ref;
  2269. this.fontCache = fontCache;
  2270. this.idCounters = {
  2271. obj: 0
  2272. };
  2273. this.resourcesPromise = null;
  2274. }
  2275. Page.prototype = {
  2276. getPageProp: function Page_getPageProp(key) {
  2277. return this.pageDict.get(key);
  2278. },
  2279. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2280. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2281. var MAX_LOOP_COUNT = 100;
  2282. // Always walk up the entire parent chain, to be able to find
  2283. // e.g. \Resources placed on multiple levels of the tree.
  2284. while (dict) {
  2285. var value = dict.get(key);
  2286. if (value) {
  2287. if (!valueArray) {
  2288. valueArray = [];
  2289. }
  2290. valueArray.push(value);
  2291. }
  2292. if (++loopCount > MAX_LOOP_COUNT) {
  2293. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2294. break;
  2295. }
  2296. dict = dict.get('Parent');
  2297. }
  2298. if (!valueArray) {
  2299. return Dict.empty;
  2300. }
  2301. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2302. loopCount > MAX_LOOP_COUNT) {
  2303. return valueArray[0];
  2304. }
  2305. return Dict.merge(this.xref, valueArray);
  2306. },
  2307. get content() {
  2308. return this.getPageProp('Contents');
  2309. },
  2310. get resources() {
  2311. // For robustness: The spec states that a \Resources entry has to be
  2312. // present, but can be empty. Some document omit it still, in this case
  2313. // we return an empty dictionary.
  2314. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2315. },
  2316. get mediaBox() {
  2317. var obj = this.getInheritedPageProp('MediaBox');
  2318. // Reset invalid media box to letter size.
  2319. if (!isArray(obj) || obj.length !== 4) {
  2320. obj = LETTER_SIZE_MEDIABOX;
  2321. }
  2322. return shadow(this, 'mediaBox', obj);
  2323. },
  2324. get view() {
  2325. var mediaBox = this.mediaBox;
  2326. var cropBox = this.getInheritedPageProp('CropBox');
  2327. if (!isArray(cropBox) || cropBox.length !== 4) {
  2328. return shadow(this, 'view', mediaBox);
  2329. }
  2330. // From the spec, 6th ed., p.963:
  2331. // "The crop, bleed, trim, and art boxes should not ordinarily
  2332. // extend beyond the boundaries of the media box. If they do, they are
  2333. // effectively reduced to their intersection with the media box."
  2334. cropBox = Util.intersect(cropBox, mediaBox);
  2335. if (!cropBox) {
  2336. return shadow(this, 'view', mediaBox);
  2337. }
  2338. return shadow(this, 'view', cropBox);
  2339. },
  2340. get annotationRefs() {
  2341. return shadow(this, 'annotationRefs',
  2342. this.getInheritedPageProp('Annots'));
  2343. },
  2344. get rotate() {
  2345. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2346. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2347. if (rotate % 90 !== 0) {
  2348. rotate = 0;
  2349. } else if (rotate >= 360) {
  2350. rotate = rotate % 360;
  2351. } else if (rotate < 0) {
  2352. // The spec doesn't cover negatives, assume its counterclockwise
  2353. // rotation. The following is the other implementation of modulo.
  2354. rotate = ((rotate % 360) + 360) % 360;
  2355. }
  2356. return shadow(this, 'rotate', rotate);
  2357. },
  2358. getContentStream: function Page_getContentStream() {
  2359. var content = this.content;
  2360. var stream;
  2361. if (isArray(content)) {
  2362. // fetching items
  2363. var xref = this.xref;
  2364. var i, n = content.length;
  2365. var streams = [];
  2366. for (i = 0; i < n; ++i) {
  2367. streams.push(xref.fetchIfRef(content[i]));
  2368. }
  2369. stream = new StreamsSequenceStream(streams);
  2370. } else if (isStream(content)) {
  2371. stream = content;
  2372. } else {
  2373. // replacing non-existent page content with empty one
  2374. stream = new NullStream();
  2375. }
  2376. return stream;
  2377. },
  2378. loadResources: function Page_loadResources(keys) {
  2379. if (!this.resourcesPromise) {
  2380. // TODO: add async getInheritedPageProp and remove this.
  2381. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2382. }
  2383. return this.resourcesPromise.then(function resourceSuccess() {
  2384. var objectLoader = new ObjectLoader(this.resources.map,
  2385. keys,
  2386. this.xref);
  2387. return objectLoader.load();
  2388. }.bind(this));
  2389. },
  2390. getOperatorList: function Page_getOperatorList(handler, intent) {
  2391. var self = this;
  2392. var pdfManager = this.pdfManager;
  2393. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2394. []);
  2395. var resourcesPromise = this.loadResources([
  2396. 'ExtGState',
  2397. 'ColorSpace',
  2398. 'Pattern',
  2399. 'Shading',
  2400. 'XObject',
  2401. 'Font'
  2402. // ProcSet
  2403. // Properties
  2404. ]);
  2405. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2406. handler, this.pageIndex,
  2407. 'p' + this.pageIndex + '_',
  2408. this.idCounters,
  2409. this.fontCache);
  2410. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2411. var pageListPromise = dataPromises.then(function(data) {
  2412. var contentStream = data[0];
  2413. var opList = new OperatorList(intent, handler, self.pageIndex);
  2414. handler.send('StartRenderPage', {
  2415. transparency: partialEvaluator.hasBlendModes(self.resources),
  2416. pageIndex: self.pageIndex,
  2417. intent: intent
  2418. });
  2419. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2420. opList).then(function () {
  2421. return opList;
  2422. });
  2423. });
  2424. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2425. return Promise.all([pageListPromise, annotationsPromise]).then(
  2426. function(datas) {
  2427. var pageOpList = datas[0];
  2428. var annotations = datas[1];
  2429. if (annotations.length === 0) {
  2430. pageOpList.flush(true);
  2431. return pageOpList;
  2432. }
  2433. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2434. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2435. return annotationsReadyPromise.then(function () {
  2436. pageOpList.flush(true);
  2437. return pageOpList;
  2438. });
  2439. });
  2440. },
  2441. extractTextContent: function Page_extractTextContent() {
  2442. var handler = {
  2443. on: function nullHandlerOn() {},
  2444. send: function nullHandlerSend() {}
  2445. };
  2446. var self = this;
  2447. var pdfManager = this.pdfManager;
  2448. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2449. []);
  2450. var resourcesPromise = this.loadResources([
  2451. 'ExtGState',
  2452. 'XObject',
  2453. 'Font'
  2454. ]);
  2455. var dataPromises = Promise.all([contentStreamPromise,
  2456. resourcesPromise]);
  2457. return dataPromises.then(function(data) {
  2458. var contentStream = data[0];
  2459. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2460. handler, self.pageIndex,
  2461. 'p' + self.pageIndex + '_',
  2462. self.idCounters,
  2463. self.fontCache);
  2464. return partialEvaluator.getTextContent(contentStream,
  2465. self.resources);
  2466. });
  2467. },
  2468. getAnnotationsData: function Page_getAnnotationsData() {
  2469. var annotations = this.annotations;
  2470. var annotationsData = [];
  2471. for (var i = 0, n = annotations.length; i < n; ++i) {
  2472. annotationsData.push(annotations[i].getData());
  2473. }
  2474. return annotationsData;
  2475. },
  2476. get annotations() {
  2477. var annotations = [];
  2478. var annotationRefs = (this.annotationRefs || []);
  2479. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2480. var annotationRef = annotationRefs[i];
  2481. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2482. if (annotation) {
  2483. annotations.push(annotation);
  2484. }
  2485. }
  2486. return shadow(this, 'annotations', annotations);
  2487. }
  2488. };
  2489. return Page;
  2490. })();
  2491. /**
  2492. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2493. * `PDFDoc`, this one doesn't have any job management code.
  2494. * Right now there exists one PDFDocument on the main thread + one object
  2495. * for each worker. If there is no worker support enabled, there are two
  2496. * `PDFDocument` objects on the main thread created.
  2497. */
  2498. var PDFDocument = (function PDFDocumentClosure() {
  2499. var FINGERPRINT_FIRST_BYTES = 1024;
  2500. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2501. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2502. function PDFDocument(pdfManager, arg, password) {
  2503. if (isStream(arg)) {
  2504. init.call(this, pdfManager, arg, password);
  2505. } else if (isArrayBuffer(arg)) {
  2506. init.call(this, pdfManager, new Stream(arg), password);
  2507. } else {
  2508. error('PDFDocument: Unknown argument type');
  2509. }
  2510. }
  2511. function init(pdfManager, stream, password) {
  2512. assert(stream.length > 0, 'stream must have data');
  2513. this.pdfManager = pdfManager;
  2514. this.stream = stream;
  2515. var xref = new XRef(this.stream, password, pdfManager);
  2516. this.xref = xref;
  2517. }
  2518. function find(stream, needle, limit, backwards) {
  2519. var pos = stream.pos;
  2520. var end = stream.end;
  2521. var strBuf = [];
  2522. if (pos + limit > end) {
  2523. limit = end - pos;
  2524. }
  2525. for (var n = 0; n < limit; ++n) {
  2526. strBuf.push(String.fromCharCode(stream.getByte()));
  2527. }
  2528. var str = strBuf.join('');
  2529. stream.pos = pos;
  2530. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2531. if (index === -1) {
  2532. return false; /* not found */
  2533. }
  2534. stream.pos += index;
  2535. return true; /* found */
  2536. }
  2537. var DocumentInfoValidators = {
  2538. get entries() {
  2539. // Lazily build this since all the validation functions below are not
  2540. // defined until after this file loads.
  2541. return shadow(this, 'entries', {
  2542. Title: isString,
  2543. Author: isString,
  2544. Subject: isString,
  2545. Keywords: isString,
  2546. Creator: isString,
  2547. Producer: isString,
  2548. CreationDate: isString,
  2549. ModDate: isString,
  2550. Trapped: isName
  2551. });
  2552. }
  2553. };
  2554. PDFDocument.prototype = {
  2555. parse: function PDFDocument_parse(recoveryMode) {
  2556. this.setup(recoveryMode);
  2557. var version = this.catalog.catDict.get('Version');
  2558. if (isName(version)) {
  2559. this.pdfFormatVersion = version.name;
  2560. }
  2561. try {
  2562. // checking if AcroForm is present
  2563. this.acroForm = this.catalog.catDict.get('AcroForm');
  2564. if (this.acroForm) {
  2565. this.xfa = this.acroForm.get('XFA');
  2566. var fields = this.acroForm.get('Fields');
  2567. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2568. !this.xfa) {
  2569. // no fields and no XFA -- not a form (?)
  2570. this.acroForm = null;
  2571. }
  2572. }
  2573. } catch (ex) {
  2574. info('Something wrong with AcroForm entry');
  2575. this.acroForm = null;
  2576. }
  2577. },
  2578. get linearization() {
  2579. var linearization = null;
  2580. if (this.stream.length) {
  2581. try {
  2582. linearization = Linearization.create(this.stream);
  2583. } catch (err) {
  2584. if (err instanceof MissingDataException) {
  2585. throw err;
  2586. }
  2587. info(err);
  2588. }
  2589. }
  2590. // shadow the prototype getter with a data property
  2591. return shadow(this, 'linearization', linearization);
  2592. },
  2593. get startXRef() {
  2594. var stream = this.stream;
  2595. var startXRef = 0;
  2596. var linearization = this.linearization;
  2597. if (linearization) {
  2598. // Find end of first obj.
  2599. stream.reset();
  2600. if (find(stream, 'endobj', 1024)) {
  2601. startXRef = stream.pos + 6;
  2602. }
  2603. } else {
  2604. // Find startxref by jumping backward from the end of the file.
  2605. var step = 1024;
  2606. var found = false, pos = stream.end;
  2607. while (!found && pos > 0) {
  2608. pos -= step - 'startxref'.length;
  2609. if (pos < 0) {
  2610. pos = 0;
  2611. }
  2612. stream.pos = pos;
  2613. found = find(stream, 'startxref', step, true);
  2614. }
  2615. if (found) {
  2616. stream.skip(9);
  2617. var ch;
  2618. do {
  2619. ch = stream.getByte();
  2620. } while (Lexer.isSpace(ch));
  2621. var str = '';
  2622. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2623. str += String.fromCharCode(ch);
  2624. ch = stream.getByte();
  2625. }
  2626. startXRef = parseInt(str, 10);
  2627. if (isNaN(startXRef)) {
  2628. startXRef = 0;
  2629. }
  2630. }
  2631. }
  2632. // shadow the prototype getter with a data property
  2633. return shadow(this, 'startXRef', startXRef);
  2634. },
  2635. get mainXRefEntriesOffset() {
  2636. var mainXRefEntriesOffset = 0;
  2637. var linearization = this.linearization;
  2638. if (linearization) {
  2639. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2640. }
  2641. // shadow the prototype getter with a data property
  2642. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2643. },
  2644. // Find the header, remove leading garbage and setup the stream
  2645. // starting from the header.
  2646. checkHeader: function PDFDocument_checkHeader() {
  2647. var stream = this.stream;
  2648. stream.reset();
  2649. if (find(stream, '%PDF-', 1024)) {
  2650. // Found the header, trim off any garbage before it.
  2651. stream.moveStart();
  2652. // Reading file format version
  2653. var MAX_VERSION_LENGTH = 12;
  2654. var version = '', ch;
  2655. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2656. if (version.length >= MAX_VERSION_LENGTH) {
  2657. break;
  2658. }
  2659. version += String.fromCharCode(ch);
  2660. }
  2661. if (!this.pdfFormatVersion) {
  2662. // removing "%PDF-"-prefix
  2663. this.pdfFormatVersion = version.substring(5);
  2664. }
  2665. return;
  2666. }
  2667. // May not be a PDF file, continue anyway.
  2668. },
  2669. parseStartXRef: function PDFDocument_parseStartXRef() {
  2670. var startXRef = this.startXRef;
  2671. this.xref.setStartXRef(startXRef);
  2672. },
  2673. setup: function PDFDocument_setup(recoveryMode) {
  2674. this.xref.parse(recoveryMode);
  2675. this.catalog = new Catalog(this.pdfManager, this.xref);
  2676. },
  2677. get numPages() {
  2678. var linearization = this.linearization;
  2679. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2680. // shadow the prototype getter
  2681. return shadow(this, 'numPages', num);
  2682. },
  2683. get documentInfo() {
  2684. var docInfo = {
  2685. PDFFormatVersion: this.pdfFormatVersion,
  2686. IsAcroFormPresent: !!this.acroForm,
  2687. IsXFAPresent: !!this.xfa
  2688. };
  2689. var infoDict;
  2690. try {
  2691. infoDict = this.xref.trailer.get('Info');
  2692. } catch (err) {
  2693. info('The document information dictionary is invalid.');
  2694. }
  2695. if (infoDict) {
  2696. var validEntries = DocumentInfoValidators.entries;
  2697. // Only fill the document info with valid entries from the spec.
  2698. for (var key in validEntries) {
  2699. if (infoDict.has(key)) {
  2700. var value = infoDict.get(key);
  2701. // Make sure the value conforms to the spec.
  2702. if (validEntries[key](value)) {
  2703. docInfo[key] = (typeof value !== 'string' ?
  2704. value : stringToPDFString(value));
  2705. } else {
  2706. info('Bad value in document info for "' + key + '"');
  2707. }
  2708. }
  2709. }
  2710. }
  2711. return shadow(this, 'documentInfo', docInfo);
  2712. },
  2713. get fingerprint() {
  2714. var xref = this.xref, idArray, hash, fileID = '';
  2715. if (xref.trailer.has('ID')) {
  2716. idArray = xref.trailer.get('ID');
  2717. }
  2718. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2719. hash = stringToBytes(idArray[0]);
  2720. } else {
  2721. if (this.stream.ensureRange) {
  2722. this.stream.ensureRange(0,
  2723. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2724. }
  2725. hash = calculateMD5(this.stream.bytes.subarray(0,
  2726. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2727. }
  2728. for (var i = 0, n = hash.length; i < n; i++) {
  2729. var hex = hash[i].toString(16);
  2730. fileID += hex.length === 1 ? '0' + hex : hex;
  2731. }
  2732. return shadow(this, 'fingerprint', fileID);
  2733. },
  2734. getPage: function PDFDocument_getPage(pageIndex) {
  2735. return this.catalog.getPage(pageIndex);
  2736. },
  2737. cleanup: function PDFDocument_cleanup() {
  2738. return this.catalog.cleanup();
  2739. }
  2740. };
  2741. return PDFDocument;
  2742. })();
  2743. var Name = (function NameClosure() {
  2744. function Name(name) {
  2745. this.name = name;
  2746. }
  2747. Name.prototype = {};
  2748. var nameCache = {};
  2749. Name.get = function Name_get(name) {
  2750. var nameValue = nameCache[name];
  2751. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2752. };
  2753. return Name;
  2754. })();
  2755. var Cmd = (function CmdClosure() {
  2756. function Cmd(cmd) {
  2757. this.cmd = cmd;
  2758. }
  2759. Cmd.prototype = {};
  2760. var cmdCache = {};
  2761. Cmd.get = function Cmd_get(cmd) {
  2762. var cmdValue = cmdCache[cmd];
  2763. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2764. };
  2765. return Cmd;
  2766. })();
  2767. var Dict = (function DictClosure() {
  2768. var nonSerializable = function nonSerializableClosure() {
  2769. return nonSerializable; // creating closure on some variable
  2770. };
  2771. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2772. 'Background': true,
  2773. 'ExtGState': true,
  2774. 'Halftone': true,
  2775. 'Layout': true,
  2776. 'Mask': true,
  2777. 'Pagination': true,
  2778. 'Printing': true
  2779. };
  2780. function isRecursionAllowedFor(dict) {
  2781. if (!isName(dict.Type)) {
  2782. return true;
  2783. }
  2784. var dictType = dict.Type.name;
  2785. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2786. }
  2787. // xref is optional
  2788. function Dict(xref) {
  2789. // Map should only be used internally, use functions below to access.
  2790. this.map = Object.create(null);
  2791. this.xref = xref;
  2792. this.objId = null;
  2793. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2794. }
  2795. Dict.prototype = {
  2796. assignXref: function Dict_assignXref(newXref) {
  2797. this.xref = newXref;
  2798. },
  2799. // automatically dereferences Ref objects
  2800. get: function Dict_get(key1, key2, key3) {
  2801. var value;
  2802. var xref = this.xref;
  2803. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2804. typeof key2 === 'undefined') {
  2805. return xref ? xref.fetchIfRef(value) : value;
  2806. }
  2807. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2808. typeof key3 === 'undefined') {
  2809. return xref ? xref.fetchIfRef(value) : value;
  2810. }
  2811. value = this.map[key3] || null;
  2812. return xref ? xref.fetchIfRef(value) : value;
  2813. },
  2814. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2815. getAsync: function Dict_getAsync(key1, key2, key3) {
  2816. var value;
  2817. var xref = this.xref;
  2818. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2819. typeof key2 === 'undefined') {
  2820. if (xref) {
  2821. return xref.fetchIfRefAsync(value);
  2822. }
  2823. return Promise.resolve(value);
  2824. }
  2825. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2826. typeof key3 === 'undefined') {
  2827. if (xref) {
  2828. return xref.fetchIfRefAsync(value);
  2829. }
  2830. return Promise.resolve(value);
  2831. }
  2832. value = this.map[key3] || null;
  2833. if (xref) {
  2834. return xref.fetchIfRefAsync(value);
  2835. }
  2836. return Promise.resolve(value);
  2837. },
  2838. // no dereferencing
  2839. getRaw: function Dict_getRaw(key) {
  2840. return this.map[key];
  2841. },
  2842. // creates new map and dereferences all Refs
  2843. getAll: function Dict_getAll() {
  2844. var all = Object.create(null);
  2845. var queue = null;
  2846. var key, obj;
  2847. for (key in this.map) {
  2848. obj = this.get(key);
  2849. if (obj instanceof Dict) {
  2850. if (isRecursionAllowedFor(obj)) {
  2851. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2852. } else {
  2853. all[key] = this.getRaw(key);
  2854. }
  2855. } else {
  2856. all[key] = obj;
  2857. }
  2858. }
  2859. if (!queue) {
  2860. return all;
  2861. }
  2862. // trying to take cyclic references into the account
  2863. var processed = Object.create(null);
  2864. while (queue.length > 0) {
  2865. var item = queue.shift();
  2866. var itemObj = item.obj;
  2867. var objId = itemObj.objId;
  2868. if (objId && objId in processed) {
  2869. item.target[item.key] = processed[objId];
  2870. continue;
  2871. }
  2872. var dereferenced = Object.create(null);
  2873. for (key in itemObj.map) {
  2874. obj = itemObj.get(key);
  2875. if (obj instanceof Dict) {
  2876. if (isRecursionAllowedFor(obj)) {
  2877. queue.push({target: dereferenced, key: key, obj: obj});
  2878. } else {
  2879. dereferenced[key] = itemObj.getRaw(key);
  2880. }
  2881. } else {
  2882. dereferenced[key] = obj;
  2883. }
  2884. }
  2885. if (objId) {
  2886. processed[objId] = dereferenced;
  2887. }
  2888. item.target[item.key] = dereferenced;
  2889. }
  2890. return all;
  2891. },
  2892. getKeys: function Dict_getKeys() {
  2893. return Object.keys(this.map);
  2894. },
  2895. set: function Dict_set(key, value) {
  2896. this.map[key] = value;
  2897. },
  2898. has: function Dict_has(key) {
  2899. return key in this.map;
  2900. },
  2901. forEach: function Dict_forEach(callback) {
  2902. for (var key in this.map) {
  2903. callback(key, this.get(key));
  2904. }
  2905. }
  2906. };
  2907. Dict.empty = new Dict(null);
  2908. Dict.merge = function Dict_merge(xref, dictArray) {
  2909. var mergedDict = new Dict(xref);
  2910. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  2911. var dict = dictArray[i];
  2912. if (!isDict(dict)) {
  2913. continue;
  2914. }
  2915. for (var keyName in dict.map) {
  2916. if (mergedDict.map[keyName]) {
  2917. continue;
  2918. }
  2919. mergedDict.map[keyName] = dict.map[keyName];
  2920. }
  2921. }
  2922. return mergedDict;
  2923. };
  2924. return Dict;
  2925. })();
  2926. var Ref = (function RefClosure() {
  2927. function Ref(num, gen) {
  2928. this.num = num;
  2929. this.gen = gen;
  2930. }
  2931. Ref.prototype = {
  2932. toString: function Ref_toString() {
  2933. // This function is hot, so we make the string as compact as possible.
  2934. // |this.gen| is almost always zero, so we treat that case specially.
  2935. var str = this.num + 'R';
  2936. if (this.gen !== 0) {
  2937. str += this.gen;
  2938. }
  2939. return str;
  2940. }
  2941. };
  2942. return Ref;
  2943. })();
  2944. // The reference is identified by number and generation.
  2945. // This structure stores only one instance of the reference.
  2946. var RefSet = (function RefSetClosure() {
  2947. function RefSet() {
  2948. this.dict = {};
  2949. }
  2950. RefSet.prototype = {
  2951. has: function RefSet_has(ref) {
  2952. return ref.toString() in this.dict;
  2953. },
  2954. put: function RefSet_put(ref) {
  2955. this.dict[ref.toString()] = true;
  2956. },
  2957. remove: function RefSet_remove(ref) {
  2958. delete this.dict[ref.toString()];
  2959. }
  2960. };
  2961. return RefSet;
  2962. })();
  2963. var RefSetCache = (function RefSetCacheClosure() {
  2964. function RefSetCache() {
  2965. this.dict = Object.create(null);
  2966. }
  2967. RefSetCache.prototype = {
  2968. get: function RefSetCache_get(ref) {
  2969. return this.dict[ref.toString()];
  2970. },
  2971. has: function RefSetCache_has(ref) {
  2972. return ref.toString() in this.dict;
  2973. },
  2974. put: function RefSetCache_put(ref, obj) {
  2975. this.dict[ref.toString()] = obj;
  2976. },
  2977. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2978. this.dict[ref.toString()] = this.get(aliasRef);
  2979. },
  2980. forEach: function RefSetCache_forEach(fn, thisArg) {
  2981. for (var i in this.dict) {
  2982. fn.call(thisArg, this.dict[i]);
  2983. }
  2984. },
  2985. clear: function RefSetCache_clear() {
  2986. this.dict = Object.create(null);
  2987. }
  2988. };
  2989. return RefSetCache;
  2990. })();
  2991. var Catalog = (function CatalogClosure() {
  2992. function Catalog(pdfManager, xref) {
  2993. this.pdfManager = pdfManager;
  2994. this.xref = xref;
  2995. this.catDict = xref.getCatalogObj();
  2996. this.fontCache = new RefSetCache();
  2997. assert(isDict(this.catDict),
  2998. 'catalog object is not a dictionary');
  2999. this.pagePromises = [];
  3000. }
  3001. Catalog.prototype = {
  3002. get metadata() {
  3003. var streamRef = this.catDict.getRaw('Metadata');
  3004. if (!isRef(streamRef)) {
  3005. return shadow(this, 'metadata', null);
  3006. }
  3007. var encryptMetadata = (!this.xref.encrypt ? false :
  3008. this.xref.encrypt.encryptMetadata);
  3009. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3010. var metadata;
  3011. if (stream && isDict(stream.dict)) {
  3012. var type = stream.dict.get('Type');
  3013. var subtype = stream.dict.get('Subtype');
  3014. if (isName(type) && isName(subtype) &&
  3015. type.name === 'Metadata' && subtype.name === 'XML') {
  3016. // XXX: This should examine the charset the XML document defines,
  3017. // however since there are currently no real means to decode
  3018. // arbitrary charsets, let's just hope that the author of the PDF
  3019. // was reasonable enough to stick with the XML default charset,
  3020. // which is UTF-8.
  3021. try {
  3022. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3023. } catch (e) {
  3024. info('Skipping invalid metadata.');
  3025. }
  3026. }
  3027. }
  3028. return shadow(this, 'metadata', metadata);
  3029. },
  3030. get toplevelPagesDict() {
  3031. var pagesObj = this.catDict.get('Pages');
  3032. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3033. // shadow the prototype getter
  3034. return shadow(this, 'toplevelPagesDict', pagesObj);
  3035. },
  3036. get documentOutline() {
  3037. var obj = null;
  3038. try {
  3039. obj = this.readDocumentOutline();
  3040. } catch (ex) {
  3041. if (ex instanceof MissingDataException) {
  3042. throw ex;
  3043. }
  3044. warn('Unable to read document outline');
  3045. }
  3046. return shadow(this, 'documentOutline', obj);
  3047. },
  3048. readDocumentOutline: function Catalog_readDocumentOutline() {
  3049. var xref = this.xref;
  3050. var obj = this.catDict.get('Outlines');
  3051. var root = { items: [] };
  3052. if (isDict(obj)) {
  3053. obj = obj.getRaw('First');
  3054. var processed = new RefSet();
  3055. if (isRef(obj)) {
  3056. var queue = [{obj: obj, parent: root}];
  3057. // to avoid recursion keeping track of the items
  3058. // in the processed dictionary
  3059. processed.put(obj);
  3060. while (queue.length > 0) {
  3061. var i = queue.shift();
  3062. var outlineDict = xref.fetchIfRef(i.obj);
  3063. if (outlineDict === null) {
  3064. continue;
  3065. }
  3066. if (!outlineDict.has('Title')) {
  3067. error('Invalid outline item');
  3068. }
  3069. var dest = outlineDict.get('A');
  3070. if (dest) {
  3071. dest = dest.get('D');
  3072. } else if (outlineDict.has('Dest')) {
  3073. dest = outlineDict.getRaw('Dest');
  3074. if (isName(dest)) {
  3075. dest = dest.name;
  3076. }
  3077. }
  3078. var title = outlineDict.get('Title');
  3079. var outlineItem = {
  3080. dest: dest,
  3081. title: stringToPDFString(title),
  3082. color: outlineDict.get('C') || [0, 0, 0],
  3083. count: outlineDict.get('Count'),
  3084. bold: !!(outlineDict.get('F') & 2),
  3085. italic: !!(outlineDict.get('F') & 1),
  3086. items: []
  3087. };
  3088. i.parent.items.push(outlineItem);
  3089. obj = outlineDict.getRaw('First');
  3090. if (isRef(obj) && !processed.has(obj)) {
  3091. queue.push({obj: obj, parent: outlineItem});
  3092. processed.put(obj);
  3093. }
  3094. obj = outlineDict.getRaw('Next');
  3095. if (isRef(obj) && !processed.has(obj)) {
  3096. queue.push({obj: obj, parent: i.parent});
  3097. processed.put(obj);
  3098. }
  3099. }
  3100. }
  3101. }
  3102. return (root.items.length > 0 ? root.items : null);
  3103. },
  3104. get numPages() {
  3105. var obj = this.toplevelPagesDict.get('Count');
  3106. assert(
  3107. isInt(obj),
  3108. 'page count in top level pages object is not an integer'
  3109. );
  3110. // shadow the prototype getter
  3111. return shadow(this, 'num', obj);
  3112. },
  3113. get destinations() {
  3114. function fetchDestination(dest) {
  3115. return isDict(dest) ? dest.get('D') : dest;
  3116. }
  3117. var xref = this.xref;
  3118. var dests = {}, nameTreeRef, nameDictionaryRef;
  3119. var obj = this.catDict.get('Names');
  3120. if (obj && obj.has('Dests')) {
  3121. nameTreeRef = obj.getRaw('Dests');
  3122. } else if (this.catDict.has('Dests')) {
  3123. nameDictionaryRef = this.catDict.get('Dests');
  3124. }
  3125. if (nameDictionaryRef) {
  3126. // reading simple destination dictionary
  3127. obj = nameDictionaryRef;
  3128. obj.forEach(function catalogForEach(key, value) {
  3129. if (!value) {
  3130. return;
  3131. }
  3132. dests[key] = fetchDestination(value);
  3133. });
  3134. }
  3135. if (nameTreeRef) {
  3136. var nameTree = new NameTree(nameTreeRef, xref);
  3137. var names = nameTree.getAll();
  3138. for (var name in names) {
  3139. if (!names.hasOwnProperty(name)) {
  3140. continue;
  3141. }
  3142. dests[name] = fetchDestination(names[name]);
  3143. }
  3144. }
  3145. return shadow(this, 'destinations', dests);
  3146. },
  3147. getDestination: function Catalog_getDestination(destinationId) {
  3148. function fetchDestination(dest) {
  3149. return isDict(dest) ? dest.get('D') : dest;
  3150. }
  3151. var xref = this.xref;
  3152. var dest, nameTreeRef, nameDictionaryRef;
  3153. var obj = this.catDict.get('Names');
  3154. if (obj && obj.has('Dests')) {
  3155. nameTreeRef = obj.getRaw('Dests');
  3156. } else if (this.catDict.has('Dests')) {
  3157. nameDictionaryRef = this.catDict.get('Dests');
  3158. }
  3159. if (nameDictionaryRef) {
  3160. // reading simple destination dictionary
  3161. obj = nameDictionaryRef;
  3162. obj.forEach(function catalogForEach(key, value) {
  3163. if (!value) {
  3164. return;
  3165. }
  3166. if (key === destinationId) {
  3167. dest = fetchDestination(value);
  3168. }
  3169. });
  3170. }
  3171. if (nameTreeRef) {
  3172. var nameTree = new NameTree(nameTreeRef, xref);
  3173. dest = fetchDestination(nameTree.get(destinationId));
  3174. }
  3175. return dest;
  3176. },
  3177. get attachments() {
  3178. var xref = this.xref;
  3179. var attachments = null, nameTreeRef;
  3180. var obj = this.catDict.get('Names');
  3181. if (obj) {
  3182. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3183. }
  3184. if (nameTreeRef) {
  3185. var nameTree = new NameTree(nameTreeRef, xref);
  3186. var names = nameTree.getAll();
  3187. for (var name in names) {
  3188. if (!names.hasOwnProperty(name)) {
  3189. continue;
  3190. }
  3191. var fs = new FileSpec(names[name], xref);
  3192. if (!attachments) {
  3193. attachments = {};
  3194. }
  3195. attachments[stringToPDFString(name)] = fs.serializable;
  3196. }
  3197. }
  3198. return shadow(this, 'attachments', attachments);
  3199. },
  3200. get javaScript() {
  3201. var xref = this.xref;
  3202. var obj = this.catDict.get('Names');
  3203. var javaScript = [];
  3204. if (obj && obj.has('JavaScript')) {
  3205. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3206. var names = nameTree.getAll();
  3207. for (var name in names) {
  3208. if (!names.hasOwnProperty(name)) {
  3209. continue;
  3210. }
  3211. // We don't really use the JavaScript right now. This code is
  3212. // defensive so we don't cause errors on document load.
  3213. var jsDict = names[name];
  3214. if (!isDict(jsDict)) {
  3215. continue;
  3216. }
  3217. var type = jsDict.get('S');
  3218. if (!isName(type) || type.name !== 'JavaScript') {
  3219. continue;
  3220. }
  3221. var js = jsDict.get('JS');
  3222. if (!isString(js) && !isStream(js)) {
  3223. continue;
  3224. }
  3225. if (isStream(js)) {
  3226. js = bytesToString(js.getBytes());
  3227. }
  3228. javaScript.push(stringToPDFString(js));
  3229. }
  3230. }
  3231. // Append OpenAction actions to javaScript array
  3232. var openactionDict = this.catDict.get('OpenAction');
  3233. if (isDict(openactionDict)) {
  3234. var objType = openactionDict.get('Type');
  3235. var actionType = openactionDict.get('S');
  3236. var action = openactionDict.get('N');
  3237. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3238. isName(actionType) && actionType.name === 'Named' &&
  3239. isName(action) && action.name === 'Print');
  3240. if (isPrintAction) {
  3241. javaScript.push('print(true);');
  3242. }
  3243. }
  3244. return shadow(this, 'javaScript', javaScript);
  3245. },
  3246. cleanup: function Catalog_cleanup() {
  3247. var promises = [];
  3248. this.fontCache.forEach(function (promise) {
  3249. promises.push(promise);
  3250. });
  3251. return Promise.all(promises).then(function (translatedFonts) {
  3252. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3253. var font = translatedFonts[i].dict;
  3254. delete font.translated;
  3255. }
  3256. this.fontCache.clear();
  3257. }.bind(this));
  3258. },
  3259. getPage: function Catalog_getPage(pageIndex) {
  3260. if (!(pageIndex in this.pagePromises)) {
  3261. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3262. function (a) {
  3263. var dict = a[0];
  3264. var ref = a[1];
  3265. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3266. this.fontCache);
  3267. }.bind(this)
  3268. );
  3269. }
  3270. return this.pagePromises[pageIndex];
  3271. },
  3272. getPageDict: function Catalog_getPageDict(pageIndex) {
  3273. var capability = createPromiseCapability();
  3274. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3275. var currentPageIndex = 0;
  3276. var xref = this.xref;
  3277. var checkAllKids = false;
  3278. function next() {
  3279. while (nodesToVisit.length) {
  3280. var currentNode = nodesToVisit.pop();
  3281. if (isRef(currentNode)) {
  3282. xref.fetchAsync(currentNode).then(function (obj) {
  3283. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3284. if (pageIndex === currentPageIndex) {
  3285. capability.resolve([obj, currentNode]);
  3286. } else {
  3287. currentPageIndex++;
  3288. next();
  3289. }
  3290. return;
  3291. }
  3292. nodesToVisit.push(obj);
  3293. next();
  3294. }, capability.reject);
  3295. return;
  3296. }
  3297. // Must be a child page dictionary.
  3298. assert(
  3299. isDict(currentNode),
  3300. 'page dictionary kid reference points to wrong type of object'
  3301. );
  3302. var count = currentNode.get('Count');
  3303. // If the current node doesn't have any children, avoid getting stuck
  3304. // in an empty node further down in the tree (see issue5644.pdf).
  3305. if (count === 0) {
  3306. checkAllKids = true;
  3307. }
  3308. // Skip nodes where the page can't be.
  3309. if (currentPageIndex + count <= pageIndex) {
  3310. currentPageIndex += count;
  3311. continue;
  3312. }
  3313. var kids = currentNode.get('Kids');
  3314. assert(isArray(kids), 'page dictionary kids object is not an array');
  3315. if (!checkAllKids && count === kids.length) {
  3316. // Nodes that don't have the page have been skipped and this is the
  3317. // bottom of the tree which means the page requested must be a
  3318. // descendant of this pages node. Ideally we would just resolve the
  3319. // promise with the page ref here, but there is the case where more
  3320. // pages nodes could link to single a page (see issue 3666 pdf). To
  3321. // handle this push it back on the queue so if it is a pages node it
  3322. // will be descended into.
  3323. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3324. currentPageIndex = pageIndex;
  3325. continue;
  3326. } else {
  3327. for (var last = kids.length - 1; last >= 0; last--) {
  3328. nodesToVisit.push(kids[last]);
  3329. }
  3330. }
  3331. }
  3332. capability.reject('Page index ' + pageIndex + ' not found.');
  3333. }
  3334. next();
  3335. return capability.promise;
  3336. },
  3337. getPageIndex: function Catalog_getPageIndex(ref) {
  3338. // The page tree nodes have the count of all the leaves below them. To get
  3339. // how many pages are before we just have to walk up the tree and keep
  3340. // adding the count of siblings to the left of the node.
  3341. var xref = this.xref;
  3342. function pagesBeforeRef(kidRef) {
  3343. var total = 0;
  3344. var parentRef;
  3345. return xref.fetchAsync(kidRef).then(function (node) {
  3346. if (!node) {
  3347. return null;
  3348. }
  3349. parentRef = node.getRaw('Parent');
  3350. return node.getAsync('Parent');
  3351. }).then(function (parent) {
  3352. if (!parent) {
  3353. return null;
  3354. }
  3355. return parent.getAsync('Kids');
  3356. }).then(function (kids) {
  3357. if (!kids) {
  3358. return null;
  3359. }
  3360. var kidPromises = [];
  3361. var found = false;
  3362. for (var i = 0; i < kids.length; i++) {
  3363. var kid = kids[i];
  3364. assert(isRef(kid), 'kids must be a ref');
  3365. if (kid.num === kidRef.num) {
  3366. found = true;
  3367. break;
  3368. }
  3369. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3370. if (kid.has('Count')) {
  3371. var count = kid.get('Count');
  3372. total += count;
  3373. } else { // page leaf node
  3374. total++;
  3375. }
  3376. }));
  3377. }
  3378. if (!found) {
  3379. error('kid ref not found in parents kids');
  3380. }
  3381. return Promise.all(kidPromises).then(function () {
  3382. return [total, parentRef];
  3383. });
  3384. });
  3385. }
  3386. var total = 0;
  3387. function next(ref) {
  3388. return pagesBeforeRef(ref).then(function (args) {
  3389. if (!args) {
  3390. return total;
  3391. }
  3392. var count = args[0];
  3393. var parentRef = args[1];
  3394. total += count;
  3395. return next(parentRef);
  3396. });
  3397. }
  3398. return next(ref);
  3399. }
  3400. };
  3401. return Catalog;
  3402. })();
  3403. var XRef = (function XRefClosure() {
  3404. function XRef(stream, password) {
  3405. this.stream = stream;
  3406. this.entries = [];
  3407. this.xrefstms = {};
  3408. // prepare the XRef cache
  3409. this.cache = [];
  3410. this.password = password;
  3411. this.stats = {
  3412. streamTypes: [],
  3413. fontTypes: []
  3414. };
  3415. }
  3416. XRef.prototype = {
  3417. setStartXRef: function XRef_setStartXRef(startXRef) {
  3418. // Store the starting positions of xref tables as we process them
  3419. // so we can recover from missing data errors
  3420. this.startXRefQueue = [startXRef];
  3421. },
  3422. parse: function XRef_parse(recoveryMode) {
  3423. var trailerDict;
  3424. if (!recoveryMode) {
  3425. trailerDict = this.readXRef();
  3426. } else {
  3427. warn('Indexing all PDF objects');
  3428. trailerDict = this.indexObjects();
  3429. }
  3430. trailerDict.assignXref(this);
  3431. this.trailer = trailerDict;
  3432. var encrypt = trailerDict.get('Encrypt');
  3433. if (encrypt) {
  3434. var ids = trailerDict.get('ID');
  3435. var fileId = (ids && ids.length) ? ids[0] : '';
  3436. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3437. this.password);
  3438. }
  3439. // get the root dictionary (catalog) object
  3440. if (!(this.root = trailerDict.get('Root'))) {
  3441. error('Invalid root reference');
  3442. }
  3443. },
  3444. processXRefTable: function XRef_processXRefTable(parser) {
  3445. if (!('tableState' in this)) {
  3446. // Stores state of the table as we process it so we can resume
  3447. // from middle of table in case of missing data error
  3448. this.tableState = {
  3449. entryNum: 0,
  3450. streamPos: parser.lexer.stream.pos,
  3451. parserBuf1: parser.buf1,
  3452. parserBuf2: parser.buf2
  3453. };
  3454. }
  3455. var obj = this.readXRefTable(parser);
  3456. // Sanity check
  3457. if (!isCmd(obj, 'trailer')) {
  3458. error('Invalid XRef table: could not find trailer dictionary');
  3459. }
  3460. // Read trailer dictionary, e.g.
  3461. // trailer
  3462. // << /Size 22
  3463. // /Root 20R
  3464. // /Info 10R
  3465. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3466. // >>
  3467. // The parser goes through the entire stream << ... >> and provides
  3468. // a getter interface for the key-value table
  3469. var dict = parser.getObj();
  3470. // The pdflib PDF generator can generate a nested trailer dictionary
  3471. if (!isDict(dict) && dict.dict) {
  3472. dict = dict.dict;
  3473. }
  3474. if (!isDict(dict)) {
  3475. error('Invalid XRef table: could not parse trailer dictionary');
  3476. }
  3477. delete this.tableState;
  3478. return dict;
  3479. },
  3480. readXRefTable: function XRef_readXRefTable(parser) {
  3481. // Example of cross-reference table:
  3482. // xref
  3483. // 0 1 <-- subsection header (first obj #, obj count)
  3484. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3485. // 23 2 <-- subsection header ... and so on ...
  3486. // 0000025518 00002 n
  3487. // 0000025635 00000 n
  3488. // trailer
  3489. // ...
  3490. var stream = parser.lexer.stream;
  3491. var tableState = this.tableState;
  3492. stream.pos = tableState.streamPos;
  3493. parser.buf1 = tableState.parserBuf1;
  3494. parser.buf2 = tableState.parserBuf2;
  3495. // Outer loop is over subsection headers
  3496. var obj;
  3497. while (true) {
  3498. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3499. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3500. break;
  3501. }
  3502. tableState.firstEntryNum = obj;
  3503. tableState.entryCount = parser.getObj();
  3504. }
  3505. var first = tableState.firstEntryNum;
  3506. var count = tableState.entryCount;
  3507. if (!isInt(first) || !isInt(count)) {
  3508. error('Invalid XRef table: wrong types in subsection header');
  3509. }
  3510. // Inner loop is over objects themselves
  3511. for (var i = tableState.entryNum; i < count; i++) {
  3512. tableState.streamPos = stream.pos;
  3513. tableState.entryNum = i;
  3514. tableState.parserBuf1 = parser.buf1;
  3515. tableState.parserBuf2 = parser.buf2;
  3516. var entry = {};
  3517. entry.offset = parser.getObj();
  3518. entry.gen = parser.getObj();
  3519. var type = parser.getObj();
  3520. if (isCmd(type, 'f')) {
  3521. entry.free = true;
  3522. } else if (isCmd(type, 'n')) {
  3523. entry.uncompressed = true;
  3524. }
  3525. // Validate entry obj
  3526. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3527. !(entry.free || entry.uncompressed)) {
  3528. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3529. }
  3530. if (!this.entries[i + first]) {
  3531. this.entries[i + first] = entry;
  3532. }
  3533. }
  3534. tableState.entryNum = 0;
  3535. tableState.streamPos = stream.pos;
  3536. tableState.parserBuf1 = parser.buf1;
  3537. tableState.parserBuf2 = parser.buf2;
  3538. delete tableState.firstEntryNum;
  3539. delete tableState.entryCount;
  3540. }
  3541. // Per issue 3248: hp scanners generate bad XRef
  3542. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3543. // shifting the entries
  3544. this.entries.shift();
  3545. }
  3546. // Sanity check: as per spec, first object must be free
  3547. if (this.entries[0] && !this.entries[0].free) {
  3548. error('Invalid XRef table: unexpected first object');
  3549. }
  3550. return obj;
  3551. },
  3552. processXRefStream: function XRef_processXRefStream(stream) {
  3553. if (!('streamState' in this)) {
  3554. // Stores state of the stream as we process it so we can resume
  3555. // from middle of stream in case of missing data error
  3556. var streamParameters = stream.dict;
  3557. var byteWidths = streamParameters.get('W');
  3558. var range = streamParameters.get('Index');
  3559. if (!range) {
  3560. range = [0, streamParameters.get('Size')];
  3561. }
  3562. this.streamState = {
  3563. entryRanges: range,
  3564. byteWidths: byteWidths,
  3565. entryNum: 0,
  3566. streamPos: stream.pos
  3567. };
  3568. }
  3569. this.readXRefStream(stream);
  3570. delete this.streamState;
  3571. return stream.dict;
  3572. },
  3573. readXRefStream: function XRef_readXRefStream(stream) {
  3574. var i, j;
  3575. var streamState = this.streamState;
  3576. stream.pos = streamState.streamPos;
  3577. var byteWidths = streamState.byteWidths;
  3578. var typeFieldWidth = byteWidths[0];
  3579. var offsetFieldWidth = byteWidths[1];
  3580. var generationFieldWidth = byteWidths[2];
  3581. var entryRanges = streamState.entryRanges;
  3582. while (entryRanges.length > 0) {
  3583. var first = entryRanges[0];
  3584. var n = entryRanges[1];
  3585. if (!isInt(first) || !isInt(n)) {
  3586. error('Invalid XRef range fields: ' + first + ', ' + n);
  3587. }
  3588. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3589. !isInt(generationFieldWidth)) {
  3590. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3591. }
  3592. for (i = streamState.entryNum; i < n; ++i) {
  3593. streamState.entryNum = i;
  3594. streamState.streamPos = stream.pos;
  3595. var type = 0, offset = 0, generation = 0;
  3596. for (j = 0; j < typeFieldWidth; ++j) {
  3597. type = (type << 8) | stream.getByte();
  3598. }
  3599. // if type field is absent, its default value is 1
  3600. if (typeFieldWidth === 0) {
  3601. type = 1;
  3602. }
  3603. for (j = 0; j < offsetFieldWidth; ++j) {
  3604. offset = (offset << 8) | stream.getByte();
  3605. }
  3606. for (j = 0; j < generationFieldWidth; ++j) {
  3607. generation = (generation << 8) | stream.getByte();
  3608. }
  3609. var entry = {};
  3610. entry.offset = offset;
  3611. entry.gen = generation;
  3612. switch (type) {
  3613. case 0:
  3614. entry.free = true;
  3615. break;
  3616. case 1:
  3617. entry.uncompressed = true;
  3618. break;
  3619. case 2:
  3620. break;
  3621. default:
  3622. error('Invalid XRef entry type: ' + type);
  3623. }
  3624. if (!this.entries[first + i]) {
  3625. this.entries[first + i] = entry;
  3626. }
  3627. }
  3628. streamState.entryNum = 0;
  3629. streamState.streamPos = stream.pos;
  3630. entryRanges.splice(0, 2);
  3631. }
  3632. },
  3633. indexObjects: function XRef_indexObjects() {
  3634. // Simple scan through the PDF content to find objects,
  3635. // trailers and XRef streams.
  3636. function readToken(data, offset) {
  3637. var token = '', ch = data[offset];
  3638. while (ch !== 13 && ch !== 10) {
  3639. if (++offset >= data.length) {
  3640. break;
  3641. }
  3642. token += String.fromCharCode(ch);
  3643. ch = data[offset];
  3644. }
  3645. return token;
  3646. }
  3647. function skipUntil(data, offset, what) {
  3648. var length = what.length, dataLength = data.length;
  3649. var skipped = 0;
  3650. // finding byte sequence
  3651. while (offset < dataLength) {
  3652. var i = 0;
  3653. while (i < length && data[offset + i] === what[i]) {
  3654. ++i;
  3655. }
  3656. if (i >= length) {
  3657. break; // sequence found
  3658. }
  3659. offset++;
  3660. skipped++;
  3661. }
  3662. return skipped;
  3663. }
  3664. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3665. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3666. 101, 102]);
  3667. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3668. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3669. var stream = this.stream;
  3670. stream.pos = 0;
  3671. var buffer = stream.getBytes();
  3672. var position = stream.start, length = buffer.length;
  3673. var trailers = [], xrefStms = [];
  3674. while (position < length) {
  3675. var ch = buffer[position];
  3676. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3677. ++position;
  3678. continue;
  3679. }
  3680. if (ch === 37) { // %-comment
  3681. do {
  3682. ++position;
  3683. if (position >= length) {
  3684. break;
  3685. }
  3686. ch = buffer[position];
  3687. } while (ch !== 13 && ch !== 10);
  3688. continue;
  3689. }
  3690. var token = readToken(buffer, position);
  3691. var m;
  3692. if (token === 'xref') {
  3693. position += skipUntil(buffer, position, trailerBytes);
  3694. trailers.push(position);
  3695. position += skipUntil(buffer, position, startxrefBytes);
  3696. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3697. if (typeof this.entries[m[1]] === 'undefined') {
  3698. this.entries[m[1]] = {
  3699. offset: position,
  3700. gen: m[2] | 0,
  3701. uncompressed: true
  3702. };
  3703. }
  3704. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3705. var content = buffer.subarray(position, position + contentLength);
  3706. // checking XRef stream suspect
  3707. // (it shall have '/XRef' and next char is not a letter)
  3708. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3709. if (xrefTagOffset < contentLength &&
  3710. content[xrefTagOffset + 5] < 64) {
  3711. xrefStms.push(position);
  3712. this.xrefstms[position] = 1; // don't read it recursively
  3713. }
  3714. position += contentLength;
  3715. } else {
  3716. position += token.length + 1;
  3717. }
  3718. }
  3719. // reading XRef streams
  3720. var i, ii;
  3721. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3722. this.startXRefQueue.push(xrefStms[i]);
  3723. this.readXRef(/* recoveryMode */ true);
  3724. }
  3725. // finding main trailer
  3726. var dict;
  3727. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3728. stream.pos = trailers[i];
  3729. var parser = new Parser(new Lexer(stream), true, this);
  3730. var obj = parser.getObj();
  3731. if (!isCmd(obj, 'trailer')) {
  3732. continue;
  3733. }
  3734. // read the trailer dictionary
  3735. if (!isDict(dict = parser.getObj())) {
  3736. continue;
  3737. }
  3738. // taking the first one with 'ID'
  3739. if (dict.has('ID')) {
  3740. return dict;
  3741. }
  3742. }
  3743. // no tailer with 'ID', taking last one (if exists)
  3744. if (dict) {
  3745. return dict;
  3746. }
  3747. // nothing helps
  3748. // calling error() would reject worker with an UnknownErrorException.
  3749. throw new InvalidPDFException('Invalid PDF structure');
  3750. },
  3751. readXRef: function XRef_readXRef(recoveryMode) {
  3752. var stream = this.stream;
  3753. try {
  3754. while (this.startXRefQueue.length) {
  3755. var startXRef = this.startXRefQueue[0];
  3756. stream.pos = startXRef + stream.start;
  3757. var parser = new Parser(new Lexer(stream), true, this);
  3758. var obj = parser.getObj();
  3759. var dict;
  3760. // Get dictionary
  3761. if (isCmd(obj, 'xref')) {
  3762. // Parse end-of-file XRef
  3763. dict = this.processXRefTable(parser);
  3764. if (!this.topDict) {
  3765. this.topDict = dict;
  3766. }
  3767. // Recursively get other XRefs 'XRefStm', if any
  3768. obj = dict.get('XRefStm');
  3769. if (isInt(obj)) {
  3770. var pos = obj;
  3771. // ignore previously loaded xref streams
  3772. // (possible infinite recursion)
  3773. if (!(pos in this.xrefstms)) {
  3774. this.xrefstms[pos] = 1;
  3775. this.startXRefQueue.push(pos);
  3776. }
  3777. }
  3778. } else if (isInt(obj)) {
  3779. // Parse in-stream XRef
  3780. if (!isInt(parser.getObj()) ||
  3781. !isCmd(parser.getObj(), 'obj') ||
  3782. !isStream(obj = parser.getObj())) {
  3783. error('Invalid XRef stream');
  3784. }
  3785. dict = this.processXRefStream(obj);
  3786. if (!this.topDict) {
  3787. this.topDict = dict;
  3788. }
  3789. if (!dict) {
  3790. error('Failed to read XRef stream');
  3791. }
  3792. } else {
  3793. error('Invalid XRef stream header');
  3794. }
  3795. // Recursively get previous dictionary, if any
  3796. obj = dict.get('Prev');
  3797. if (isInt(obj)) {
  3798. this.startXRefQueue.push(obj);
  3799. } else if (isRef(obj)) {
  3800. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3801. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3802. this.startXRefQueue.push(obj.num);
  3803. }
  3804. this.startXRefQueue.shift();
  3805. }
  3806. return this.topDict;
  3807. } catch (e) {
  3808. if (e instanceof MissingDataException) {
  3809. throw e;
  3810. }
  3811. info('(while reading XRef): ' + e);
  3812. }
  3813. if (recoveryMode) {
  3814. return;
  3815. }
  3816. throw new XRefParseException();
  3817. },
  3818. getEntry: function XRef_getEntry(i) {
  3819. var xrefEntry = this.entries[i];
  3820. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3821. return xrefEntry;
  3822. }
  3823. return null;
  3824. },
  3825. fetchIfRef: function XRef_fetchIfRef(obj) {
  3826. if (!isRef(obj)) {
  3827. return obj;
  3828. }
  3829. return this.fetch(obj);
  3830. },
  3831. fetch: function XRef_fetch(ref, suppressEncryption) {
  3832. assert(isRef(ref), 'ref object is not a reference');
  3833. var num = ref.num;
  3834. if (num in this.cache) {
  3835. var cacheEntry = this.cache[num];
  3836. return cacheEntry;
  3837. }
  3838. var xrefEntry = this.getEntry(num);
  3839. // the referenced entry can be free
  3840. if (xrefEntry === null) {
  3841. return (this.cache[num] = null);
  3842. }
  3843. if (xrefEntry.uncompressed) {
  3844. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3845. } else {
  3846. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3847. }
  3848. if (isDict(xrefEntry)){
  3849. xrefEntry.objId = ref.toString();
  3850. } else if (isStream(xrefEntry)) {
  3851. xrefEntry.dict.objId = ref.toString();
  3852. }
  3853. return xrefEntry;
  3854. },
  3855. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3856. suppressEncryption) {
  3857. var gen = ref.gen;
  3858. var num = ref.num;
  3859. if (xrefEntry.gen !== gen) {
  3860. error('inconsistent generation in XRef');
  3861. }
  3862. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3863. this.stream.start);
  3864. var parser = new Parser(new Lexer(stream), true, this);
  3865. var obj1 = parser.getObj();
  3866. var obj2 = parser.getObj();
  3867. var obj3 = parser.getObj();
  3868. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3869. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3870. !isCmd(obj3)) {
  3871. error('bad XRef entry');
  3872. }
  3873. if (!isCmd(obj3, 'obj')) {
  3874. // some bad PDFs use "obj1234" and really mean 1234
  3875. if (obj3.cmd.indexOf('obj') === 0) {
  3876. num = parseInt(obj3.cmd.substring(3), 10);
  3877. if (!isNaN(num)) {
  3878. return num;
  3879. }
  3880. }
  3881. error('bad XRef entry');
  3882. }
  3883. if (this.encrypt && !suppressEncryption) {
  3884. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3885. } else {
  3886. xrefEntry = parser.getObj();
  3887. }
  3888. if (!isStream(xrefEntry)) {
  3889. this.cache[num] = xrefEntry;
  3890. }
  3891. return xrefEntry;
  3892. },
  3893. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3894. suppressEncryption) {
  3895. var tableOffset = xrefEntry.offset;
  3896. var stream = this.fetch(new Ref(tableOffset, 0));
  3897. if (!isStream(stream)) {
  3898. error('bad ObjStm stream');
  3899. }
  3900. var first = stream.dict.get('First');
  3901. var n = stream.dict.get('N');
  3902. if (!isInt(first) || !isInt(n)) {
  3903. error('invalid first and n parameters for ObjStm stream');
  3904. }
  3905. var parser = new Parser(new Lexer(stream), false, this);
  3906. parser.allowStreams = true;
  3907. var i, entries = [], num, nums = [];
  3908. // read the object numbers to populate cache
  3909. for (i = 0; i < n; ++i) {
  3910. num = parser.getObj();
  3911. if (!isInt(num)) {
  3912. error('invalid object number in the ObjStm stream: ' + num);
  3913. }
  3914. nums.push(num);
  3915. var offset = parser.getObj();
  3916. if (!isInt(offset)) {
  3917. error('invalid object offset in the ObjStm stream: ' + offset);
  3918. }
  3919. }
  3920. // read stream objects for cache
  3921. for (i = 0; i < n; ++i) {
  3922. entries.push(parser.getObj());
  3923. num = nums[i];
  3924. var entry = this.entries[num];
  3925. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3926. this.cache[num] = entries[i];
  3927. }
  3928. }
  3929. xrefEntry = entries[xrefEntry.gen];
  3930. if (xrefEntry === undefined) {
  3931. error('bad XRef entry for compressed object');
  3932. }
  3933. return xrefEntry;
  3934. },
  3935. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3936. if (!isRef(obj)) {
  3937. return Promise.resolve(obj);
  3938. }
  3939. return this.fetchAsync(obj);
  3940. },
  3941. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3942. var streamManager = this.stream.manager;
  3943. var xref = this;
  3944. return new Promise(function tryFetch(resolve, reject) {
  3945. try {
  3946. resolve(xref.fetch(ref, suppressEncryption));
  3947. } catch (e) {
  3948. if (e instanceof MissingDataException) {
  3949. streamManager.requestRange(e.begin, e.end, function () {
  3950. tryFetch(resolve, reject);
  3951. });
  3952. return;
  3953. }
  3954. reject(e);
  3955. }
  3956. });
  3957. },
  3958. getCatalogObj: function XRef_getCatalogObj() {
  3959. return this.root;
  3960. }
  3961. };
  3962. return XRef;
  3963. })();
  3964. /**
  3965. * A NameTree is like a Dict but has some advantageous properties, see the
  3966. * spec (7.9.6) for more details.
  3967. * TODO: implement all the Dict functions and make this more efficent.
  3968. */
  3969. var NameTree = (function NameTreeClosure() {
  3970. function NameTree(root, xref) {
  3971. this.root = root;
  3972. this.xref = xref;
  3973. }
  3974. NameTree.prototype = {
  3975. getAll: function NameTree_getAll() {
  3976. var dict = {};
  3977. if (!this.root) {
  3978. return dict;
  3979. }
  3980. var xref = this.xref;
  3981. // reading name tree
  3982. var processed = new RefSet();
  3983. processed.put(this.root);
  3984. var queue = [this.root];
  3985. while (queue.length > 0) {
  3986. var i, n;
  3987. var obj = xref.fetchIfRef(queue.shift());
  3988. if (!isDict(obj)) {
  3989. continue;
  3990. }
  3991. if (obj.has('Kids')) {
  3992. var kids = obj.get('Kids');
  3993. for (i = 0, n = kids.length; i < n; i++) {
  3994. var kid = kids[i];
  3995. if (processed.has(kid)) {
  3996. error('invalid destinations');
  3997. }
  3998. queue.push(kid);
  3999. processed.put(kid);
  4000. }
  4001. continue;
  4002. }
  4003. var names = obj.get('Names');
  4004. if (names) {
  4005. for (i = 0, n = names.length; i < n; i += 2) {
  4006. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  4007. }
  4008. }
  4009. }
  4010. return dict;
  4011. },
  4012. get: function NameTree_get(destinationId) {
  4013. if (!this.root) {
  4014. return null;
  4015. }
  4016. var xref = this.xref;
  4017. var kidsOrNames = xref.fetchIfRef(this.root);
  4018. var loopCount = 0;
  4019. var MAX_NAMES_LEVELS = 10;
  4020. var l, r, m;
  4021. // Perform a binary search to quickly find the entry that
  4022. // contains the named destination we are looking for.
  4023. while (kidsOrNames.has('Kids')) {
  4024. loopCount++;
  4025. if (loopCount > MAX_NAMES_LEVELS) {
  4026. warn('Search depth limit for named destionations has been reached.');
  4027. return null;
  4028. }
  4029. var kids = kidsOrNames.get('Kids');
  4030. if (!isArray(kids)) {
  4031. return null;
  4032. }
  4033. l = 0;
  4034. r = kids.length - 1;
  4035. while (l <= r) {
  4036. m = (l + r) >> 1;
  4037. var kid = xref.fetchIfRef(kids[m]);
  4038. var limits = kid.get('Limits');
  4039. if (destinationId < limits[0]) {
  4040. r = m - 1;
  4041. } else if (destinationId > limits[1]) {
  4042. l = m + 1;
  4043. } else {
  4044. kidsOrNames = xref.fetchIfRef(kids[m]);
  4045. break;
  4046. }
  4047. }
  4048. if (l > r) {
  4049. return null;
  4050. }
  4051. }
  4052. // If we get here, then we have found the right entry. Now
  4053. // go through the named destinations in the Named dictionary
  4054. // until we find the exact destination we're looking for.
  4055. var names = kidsOrNames.get('Names');
  4056. if (isArray(names)) {
  4057. // Perform a binary search to reduce the lookup time.
  4058. l = 0;
  4059. r = names.length - 2;
  4060. while (l <= r) {
  4061. // Check only even indices (0, 2, 4, ...) because the
  4062. // odd indices contain the actual D array.
  4063. m = (l + r) & ~1;
  4064. if (destinationId < names[m]) {
  4065. r = m - 2;
  4066. } else if (destinationId > names[m]) {
  4067. l = m + 2;
  4068. } else {
  4069. return xref.fetchIfRef(names[m + 1]);
  4070. }
  4071. }
  4072. }
  4073. return null;
  4074. }
  4075. };
  4076. return NameTree;
  4077. })();
  4078. /**
  4079. * "A PDF file can refer to the contents of another file by using a File
  4080. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4081. * NOTE: Only embedded files are supported (as part of the attachments support)
  4082. * TODO: support the 'URL' file system (with caching if !/V), portable
  4083. * collections attributes and related files (/RF)
  4084. */
  4085. var FileSpec = (function FileSpecClosure() {
  4086. function FileSpec(root, xref) {
  4087. if (!root || !isDict(root)) {
  4088. return;
  4089. }
  4090. this.xref = xref;
  4091. this.root = root;
  4092. if (root.has('FS')) {
  4093. this.fs = root.get('FS');
  4094. }
  4095. this.description = root.has('Desc') ?
  4096. stringToPDFString(root.get('Desc')) :
  4097. '';
  4098. if (root.has('RF')) {
  4099. warn('Related file specifications are not supported');
  4100. }
  4101. this.contentAvailable = true;
  4102. if (!root.has('EF')) {
  4103. this.contentAvailable = false;
  4104. warn('Non-embedded file specifications are not supported');
  4105. }
  4106. }
  4107. function pickPlatformItem(dict) {
  4108. // Look for the filename in this order:
  4109. // UF, F, Unix, Mac, DOS
  4110. if (dict.has('UF')) {
  4111. return dict.get('UF');
  4112. } else if (dict.has('F')) {
  4113. return dict.get('F');
  4114. } else if (dict.has('Unix')) {
  4115. return dict.get('Unix');
  4116. } else if (dict.has('Mac')) {
  4117. return dict.get('Mac');
  4118. } else if (dict.has('DOS')) {
  4119. return dict.get('DOS');
  4120. } else {
  4121. return null;
  4122. }
  4123. }
  4124. FileSpec.prototype = {
  4125. get filename() {
  4126. if (!this._filename && this.root) {
  4127. var filename = pickPlatformItem(this.root) || 'unnamed';
  4128. this._filename = stringToPDFString(filename).
  4129. replace(/\\\\/g, '\\').
  4130. replace(/\\\//g, '/').
  4131. replace(/\\/g, '/');
  4132. }
  4133. return this._filename;
  4134. },
  4135. get content() {
  4136. if (!this.contentAvailable) {
  4137. return null;
  4138. }
  4139. if (!this.contentRef && this.root) {
  4140. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4141. }
  4142. var content = null;
  4143. if (this.contentRef) {
  4144. var xref = this.xref;
  4145. var fileObj = xref.fetchIfRef(this.contentRef);
  4146. if (fileObj && isStream(fileObj)) {
  4147. content = fileObj.getBytes();
  4148. } else {
  4149. warn('Embedded file specification points to non-existing/invalid ' +
  4150. 'content');
  4151. }
  4152. } else {
  4153. warn('Embedded file specification does not have a content');
  4154. }
  4155. return content;
  4156. },
  4157. get serializable() {
  4158. return {
  4159. filename: this.filename,
  4160. content: this.content
  4161. };
  4162. }
  4163. };
  4164. return FileSpec;
  4165. })();
  4166. /**
  4167. * A helper for loading missing data in object graphs. It traverses the graph
  4168. * depth first and queues up any objects that have missing data. Once it has
  4169. * has traversed as many objects that are available it attempts to bundle the
  4170. * missing data requests and then resume from the nodes that weren't ready.
  4171. *
  4172. * NOTE: It provides protection from circular references by keeping track of
  4173. * of loaded references. However, you must be careful not to load any graphs
  4174. * that have references to the catalog or other pages since that will cause the
  4175. * entire PDF document object graph to be traversed.
  4176. */
  4177. var ObjectLoader = (function() {
  4178. function mayHaveChildren(value) {
  4179. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4180. }
  4181. function addChildren(node, nodesToVisit) {
  4182. var value;
  4183. if (isDict(node) || isStream(node)) {
  4184. var map;
  4185. if (isDict(node)) {
  4186. map = node.map;
  4187. } else {
  4188. map = node.dict.map;
  4189. }
  4190. for (var key in map) {
  4191. value = map[key];
  4192. if (mayHaveChildren(value)) {
  4193. nodesToVisit.push(value);
  4194. }
  4195. }
  4196. } else if (isArray(node)) {
  4197. for (var i = 0, ii = node.length; i < ii; i++) {
  4198. value = node[i];
  4199. if (mayHaveChildren(value)) {
  4200. nodesToVisit.push(value);
  4201. }
  4202. }
  4203. }
  4204. }
  4205. function ObjectLoader(obj, keys, xref) {
  4206. this.obj = obj;
  4207. this.keys = keys;
  4208. this.xref = xref;
  4209. this.refSet = null;
  4210. }
  4211. ObjectLoader.prototype = {
  4212. load: function ObjectLoader_load() {
  4213. var keys = this.keys;
  4214. this.capability = createPromiseCapability();
  4215. // Don't walk the graph if all the data is already loaded.
  4216. if (!(this.xref.stream instanceof ChunkedStream) ||
  4217. this.xref.stream.getMissingChunks().length === 0) {
  4218. this.capability.resolve();
  4219. return this.capability.promise;
  4220. }
  4221. this.refSet = new RefSet();
  4222. // Setup the initial nodes to visit.
  4223. var nodesToVisit = [];
  4224. for (var i = 0; i < keys.length; i++) {
  4225. nodesToVisit.push(this.obj[keys[i]]);
  4226. }
  4227. this.walk(nodesToVisit);
  4228. return this.capability.promise;
  4229. },
  4230. walk: function ObjectLoader_walk(nodesToVisit) {
  4231. var nodesToRevisit = [];
  4232. var pendingRequests = [];
  4233. // DFS walk of the object graph.
  4234. while (nodesToVisit.length) {
  4235. var currentNode = nodesToVisit.pop();
  4236. // Only references or chunked streams can cause missing data exceptions.
  4237. if (isRef(currentNode)) {
  4238. // Skip nodes that have already been visited.
  4239. if (this.refSet.has(currentNode)) {
  4240. continue;
  4241. }
  4242. try {
  4243. var ref = currentNode;
  4244. this.refSet.put(ref);
  4245. currentNode = this.xref.fetch(currentNode);
  4246. } catch (e) {
  4247. if (!(e instanceof MissingDataException)) {
  4248. throw e;
  4249. }
  4250. nodesToRevisit.push(currentNode);
  4251. pendingRequests.push({ begin: e.begin, end: e.end });
  4252. }
  4253. }
  4254. if (currentNode && currentNode.getBaseStreams) {
  4255. var baseStreams = currentNode.getBaseStreams();
  4256. var foundMissingData = false;
  4257. for (var i = 0; i < baseStreams.length; i++) {
  4258. var stream = baseStreams[i];
  4259. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4260. foundMissingData = true;
  4261. pendingRequests.push({
  4262. begin: stream.start,
  4263. end: stream.end
  4264. });
  4265. }
  4266. }
  4267. if (foundMissingData) {
  4268. nodesToRevisit.push(currentNode);
  4269. }
  4270. }
  4271. addChildren(currentNode, nodesToVisit);
  4272. }
  4273. if (pendingRequests.length) {
  4274. this.xref.stream.manager.requestRanges(pendingRequests,
  4275. function pendingRequestCallback() {
  4276. nodesToVisit = nodesToRevisit;
  4277. for (var i = 0; i < nodesToRevisit.length; i++) {
  4278. var node = nodesToRevisit[i];
  4279. // Remove any reference nodes from the currrent refset so they
  4280. // aren't skipped when we revist them.
  4281. if (isRef(node)) {
  4282. this.refSet.remove(node);
  4283. }
  4284. }
  4285. this.walk(nodesToVisit);
  4286. }.bind(this));
  4287. return;
  4288. }
  4289. // Everything is loaded.
  4290. this.refSet = null;
  4291. this.capability.resolve();
  4292. }
  4293. };
  4294. return ObjectLoader;
  4295. })();
  4296. var ISOAdobeCharset = [
  4297. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4298. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4299. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4300. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4301. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4302. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4303. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4304. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4305. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4306. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4307. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4308. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4309. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4310. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4311. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4312. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4313. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4314. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4315. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4316. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4317. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4318. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4319. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4320. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4321. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4322. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4323. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4324. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4325. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4326. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4327. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4328. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4329. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4330. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4331. ];
  4332. var ExpertCharset = [
  4333. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4334. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4335. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4336. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4337. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4338. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4339. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4340. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4341. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4342. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4343. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4344. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4345. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4346. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4347. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4348. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4349. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4350. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4351. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4352. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4353. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4354. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4355. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4356. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4357. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4358. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4359. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4360. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4361. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4362. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4363. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4364. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4365. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4366. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4367. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4368. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4369. 'Ydieresissmall'
  4370. ];
  4371. var ExpertSubsetCharset = [
  4372. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4373. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4374. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4375. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4376. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4377. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4378. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4379. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4380. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4381. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4382. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4383. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4384. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4385. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4386. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4387. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4388. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4389. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4390. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4391. 'periodinferior', 'commainferior'
  4392. ];
  4393. var DEFAULT_ICON_SIZE = 22; // px
  4394. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4395. var Annotation = (function AnnotationClosure() {
  4396. // 12.5.5: Algorithm: Appearance streams
  4397. function getTransformMatrix(rect, bbox, matrix) {
  4398. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4399. var minX = bounds[0];
  4400. var minY = bounds[1];
  4401. var maxX = bounds[2];
  4402. var maxY = bounds[3];
  4403. if (minX === maxX || minY === maxY) {
  4404. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4405. // just apply the transform for rect
  4406. return [1, 0, 0, 1, rect[0], rect[1]];
  4407. }
  4408. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4409. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4410. return [
  4411. xRatio,
  4412. 0,
  4413. 0,
  4414. yRatio,
  4415. rect[0] - minX * xRatio,
  4416. rect[1] - minY * yRatio
  4417. ];
  4418. }
  4419. function getDefaultAppearance(dict) {
  4420. var appearanceState = dict.get('AP');
  4421. if (!isDict(appearanceState)) {
  4422. return;
  4423. }
  4424. var appearance;
  4425. var appearances = appearanceState.get('N');
  4426. if (isDict(appearances)) {
  4427. var as = dict.get('AS');
  4428. if (as && appearances.has(as.name)) {
  4429. appearance = appearances.get(as.name);
  4430. }
  4431. } else {
  4432. appearance = appearances;
  4433. }
  4434. return appearance;
  4435. }
  4436. function Annotation(params) {
  4437. var dict = params.dict;
  4438. var data = this.data = {};
  4439. data.subtype = dict.get('Subtype').name;
  4440. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4441. data.rect = Util.normalizeRect(rect);
  4442. data.annotationFlags = dict.get('F');
  4443. var color = dict.get('C');
  4444. if (!color) {
  4445. // The PDF spec does not mention how a missing color array is interpreted.
  4446. // Adobe Reader seems to default to black in this case.
  4447. data.color = [0, 0, 0];
  4448. } else if (isArray(color)) {
  4449. switch (color.length) {
  4450. case 0:
  4451. // Empty array denotes transparent border.
  4452. data.color = null;
  4453. break;
  4454. case 1:
  4455. // TODO: implement DeviceGray
  4456. break;
  4457. case 3:
  4458. data.color = color;
  4459. break;
  4460. case 4:
  4461. // TODO: implement DeviceCMYK
  4462. break;
  4463. }
  4464. }
  4465. // Some types of annotations have border style dict which has more
  4466. // info than the border array
  4467. if (dict.has('BS')) {
  4468. var borderStyle = dict.get('BS');
  4469. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4470. } else {
  4471. var borderArray = dict.get('Border') || [0, 0, 1];
  4472. data.borderWidth = borderArray[2] || 0;
  4473. // TODO: implement proper support for annotations with line dash patterns.
  4474. var dashArray = borderArray[3];
  4475. if (data.borderWidth > 0 && dashArray) {
  4476. if (!isArray(dashArray)) {
  4477. // Ignore the border if dashArray is not actually an array,
  4478. // this is consistent with the behaviour in Adobe Reader.
  4479. data.borderWidth = 0;
  4480. } else {
  4481. var dashArrayLength = dashArray.length;
  4482. if (dashArrayLength > 0) {
  4483. // According to the PDF specification: the elements in a dashArray
  4484. // shall be numbers that are nonnegative and not all equal to zero.
  4485. var isInvalid = false;
  4486. var numPositive = 0;
  4487. for (var i = 0; i < dashArrayLength; i++) {
  4488. var validNumber = (+dashArray[i] >= 0);
  4489. if (!validNumber) {
  4490. isInvalid = true;
  4491. break;
  4492. } else if (dashArray[i] > 0) {
  4493. numPositive++;
  4494. }
  4495. }
  4496. if (isInvalid || numPositive === 0) {
  4497. data.borderWidth = 0;
  4498. }
  4499. }
  4500. }
  4501. }
  4502. }
  4503. this.appearance = getDefaultAppearance(dict);
  4504. data.hasAppearance = !!this.appearance;
  4505. data.id = params.ref.num;
  4506. }
  4507. Annotation.prototype = {
  4508. getData: function Annotation_getData() {
  4509. return this.data;
  4510. },
  4511. isInvisible: function Annotation_isInvisible() {
  4512. var data = this.data;
  4513. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4514. return false;
  4515. } else {
  4516. return !!(data &&
  4517. data.annotationFlags && // Default: not invisible
  4518. data.annotationFlags & 0x1); // Invisible
  4519. }
  4520. },
  4521. isViewable: function Annotation_isViewable() {
  4522. var data = this.data;
  4523. return !!(!this.isInvisible() &&
  4524. data &&
  4525. (!data.annotationFlags ||
  4526. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4527. data.rect); // rectangle is necessary
  4528. },
  4529. isPrintable: function Annotation_isPrintable() {
  4530. var data = this.data;
  4531. return !!(!this.isInvisible() &&
  4532. data &&
  4533. data.annotationFlags && // Default: not printable
  4534. data.annotationFlags & 0x4 && // Print
  4535. !(data.annotationFlags & 0x2) && // Hidden
  4536. data.rect); // rectangle is necessary
  4537. },
  4538. loadResources: function Annotation_loadResources(keys) {
  4539. return new Promise(function (resolve, reject) {
  4540. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4541. if (!resources) {
  4542. resolve();
  4543. return;
  4544. }
  4545. var objectLoader = new ObjectLoader(resources.map,
  4546. keys,
  4547. resources.xref);
  4548. objectLoader.load().then(function() {
  4549. resolve(resources);
  4550. }, reject);
  4551. }, reject);
  4552. }.bind(this));
  4553. },
  4554. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4555. if (!this.appearance) {
  4556. return Promise.resolve(new OperatorList());
  4557. }
  4558. var data = this.data;
  4559. var appearanceDict = this.appearance.dict;
  4560. var resourcesPromise = this.loadResources([
  4561. 'ExtGState',
  4562. 'ColorSpace',
  4563. 'Pattern',
  4564. 'Shading',
  4565. 'XObject',
  4566. 'Font'
  4567. // ProcSet
  4568. // Properties
  4569. ]);
  4570. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4571. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4572. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4573. var self = this;
  4574. return resourcesPromise.then(function(resources) {
  4575. var opList = new OperatorList();
  4576. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4577. return evaluator.getOperatorList(self.appearance, resources, opList).
  4578. then(function () {
  4579. opList.addOp(OPS.endAnnotation, []);
  4580. self.appearance.reset();
  4581. return opList;
  4582. });
  4583. });
  4584. }
  4585. };
  4586. Annotation.getConstructor =
  4587. function Annotation_getConstructor(subtype, fieldType) {
  4588. if (!subtype) {
  4589. return;
  4590. }
  4591. // TODO(mack): Implement FreeText annotations
  4592. if (subtype === 'Link') {
  4593. return LinkAnnotation;
  4594. } else if (subtype === 'Text') {
  4595. return TextAnnotation;
  4596. } else if (subtype === 'Widget') {
  4597. if (!fieldType) {
  4598. return;
  4599. }
  4600. if (fieldType === 'Tx') {
  4601. return TextWidgetAnnotation;
  4602. } else {
  4603. return WidgetAnnotation;
  4604. }
  4605. } else {
  4606. return Annotation;
  4607. }
  4608. };
  4609. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4610. var dict = xref.fetchIfRef(ref);
  4611. if (!isDict(dict)) {
  4612. return;
  4613. }
  4614. var subtype = dict.get('Subtype');
  4615. subtype = isName(subtype) ? subtype.name : '';
  4616. if (!subtype) {
  4617. return;
  4618. }
  4619. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4620. fieldType = isName(fieldType) ? fieldType.name : '';
  4621. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4622. if (!Constructor) {
  4623. return;
  4624. }
  4625. var params = {
  4626. dict: dict,
  4627. ref: ref,
  4628. };
  4629. var annotation = new Constructor(params);
  4630. if (annotation.isViewable() || annotation.isPrintable()) {
  4631. return annotation;
  4632. } else {
  4633. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4634. warn('unimplemented annotation type: ' + subtype);
  4635. }
  4636. }
  4637. };
  4638. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4639. annotations, opList, pdfManager, partialEvaluator, intent) {
  4640. function reject(e) {
  4641. annotationsReadyCapability.reject(e);
  4642. }
  4643. var annotationsReadyCapability = createPromiseCapability();
  4644. var annotationPromises = [];
  4645. for (var i = 0, n = annotations.length; i < n; ++i) {
  4646. if (intent === 'display' && annotations[i].isViewable() ||
  4647. intent === 'print' && annotations[i].isPrintable()) {
  4648. annotationPromises.push(
  4649. annotations[i].getOperatorList(partialEvaluator));
  4650. }
  4651. }
  4652. Promise.all(annotationPromises).then(function(datas) {
  4653. opList.addOp(OPS.beginAnnotations, []);
  4654. for (var i = 0, n = datas.length; i < n; ++i) {
  4655. var annotOpList = datas[i];
  4656. opList.addOpList(annotOpList);
  4657. }
  4658. opList.addOp(OPS.endAnnotations, []);
  4659. annotationsReadyCapability.resolve();
  4660. }, reject);
  4661. return annotationsReadyCapability.promise;
  4662. };
  4663. return Annotation;
  4664. })();
  4665. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4666. function WidgetAnnotation(params) {
  4667. Annotation.call(this, params);
  4668. var dict = params.dict;
  4669. var data = this.data;
  4670. data.fieldValue = stringToPDFString(
  4671. Util.getInheritableProperty(dict, 'V') || '');
  4672. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4673. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4674. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4675. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4676. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4677. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4678. // Building the full field name by collecting the field and
  4679. // its ancestors 'T' data and joining them using '.'.
  4680. var fieldName = [];
  4681. var namedItem = dict;
  4682. var ref = params.ref;
  4683. while (namedItem) {
  4684. var parent = namedItem.get('Parent');
  4685. var parentRef = namedItem.getRaw('Parent');
  4686. var name = namedItem.get('T');
  4687. if (name) {
  4688. fieldName.unshift(stringToPDFString(name));
  4689. } else if (parent && ref) {
  4690. // The field name is absent, that means more than one field
  4691. // with the same name may exist. Replacing the empty name
  4692. // with the '`' plus index in the parent's 'Kids' array.
  4693. // This is not in the PDF spec but necessary to id the
  4694. // the input controls.
  4695. var kids = parent.get('Kids');
  4696. var j, jj;
  4697. for (j = 0, jj = kids.length; j < jj; j++) {
  4698. var kidRef = kids[j];
  4699. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4700. break;
  4701. }
  4702. }
  4703. fieldName.unshift('`' + j);
  4704. }
  4705. namedItem = parent;
  4706. ref = parentRef;
  4707. }
  4708. data.fullName = fieldName.join('.');
  4709. }
  4710. var parent = Annotation.prototype;
  4711. Util.inherit(WidgetAnnotation, Annotation, {
  4712. isViewable: function WidgetAnnotation_isViewable() {
  4713. if (this.data.fieldType === 'Sig') {
  4714. warn('unimplemented annotation type: Widget signature');
  4715. return false;
  4716. }
  4717. return parent.isViewable.call(this);
  4718. }
  4719. });
  4720. return WidgetAnnotation;
  4721. })();
  4722. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4723. function TextWidgetAnnotation(params) {
  4724. WidgetAnnotation.call(this, params);
  4725. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4726. this.data.annotationType = AnnotationType.WIDGET;
  4727. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4728. }
  4729. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4730. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4731. if (this.appearance) {
  4732. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4733. }
  4734. var opList = new OperatorList();
  4735. var data = this.data;
  4736. // Even if there is an appearance stream, ignore it. This is the
  4737. // behaviour used by Adobe Reader.
  4738. if (!data.defaultAppearance) {
  4739. return Promise.resolve(opList);
  4740. }
  4741. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4742. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4743. then(function () {
  4744. return opList;
  4745. });
  4746. }
  4747. });
  4748. return TextWidgetAnnotation;
  4749. })();
  4750. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4751. function InteractiveAnnotation(params) {
  4752. Annotation.call(this, params);
  4753. this.data.hasHtml = true;
  4754. }
  4755. Util.inherit(InteractiveAnnotation, Annotation, { });
  4756. return InteractiveAnnotation;
  4757. })();
  4758. var TextAnnotation = (function TextAnnotationClosure() {
  4759. function TextAnnotation(params) {
  4760. InteractiveAnnotation.call(this, params);
  4761. var dict = params.dict;
  4762. var data = this.data;
  4763. var content = dict.get('Contents');
  4764. var title = dict.get('T');
  4765. data.annotationType = AnnotationType.TEXT;
  4766. data.content = stringToPDFString(content || '');
  4767. data.title = stringToPDFString(title || '');
  4768. if (data.hasAppearance) {
  4769. data.name = 'NoIcon';
  4770. } else {
  4771. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4772. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4773. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4774. }
  4775. if (dict.has('C')) {
  4776. data.hasBgColor = true;
  4777. }
  4778. }
  4779. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4780. return TextAnnotation;
  4781. })();
  4782. var LinkAnnotation = (function LinkAnnotationClosure() {
  4783. function LinkAnnotation(params) {
  4784. InteractiveAnnotation.call(this, params);
  4785. var dict = params.dict;
  4786. var data = this.data;
  4787. data.annotationType = AnnotationType.LINK;
  4788. var action = dict.get('A');
  4789. if (action && isDict(action)) {
  4790. var linkType = action.get('S').name;
  4791. if (linkType === 'URI') {
  4792. var url = action.get('URI');
  4793. if (isName(url)) {
  4794. // Some bad PDFs do not put parentheses around relative URLs.
  4795. url = '/' + url.name;
  4796. } else if (url) {
  4797. url = addDefaultProtocolToUrl(url);
  4798. }
  4799. // TODO: pdf spec mentions urls can be relative to a Base
  4800. // entry in the dictionary.
  4801. if (!isValidUrl(url, false)) {
  4802. url = '';
  4803. }
  4804. // According to ISO 32000-1:2008, section 12.6.4.7,
  4805. // URI should to be encoded in 7-bit ASCII.
  4806. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4807. try {
  4808. data.url = stringToUTF8String(url);
  4809. } catch (e) {
  4810. // Fall back to a simple copy.
  4811. data.url = url;
  4812. }
  4813. } else if (linkType === 'GoTo') {
  4814. data.dest = action.get('D');
  4815. } else if (linkType === 'GoToR') {
  4816. var urlDict = action.get('F');
  4817. if (isDict(urlDict)) {
  4818. // We assume that the 'url' is a Filspec dictionary
  4819. // and fetch the url without checking any further
  4820. url = urlDict.get('F') || '';
  4821. }
  4822. // TODO: pdf reference says that GoToR
  4823. // can also have 'NewWindow' attribute
  4824. if (!isValidUrl(url, false)) {
  4825. url = '';
  4826. }
  4827. data.url = url;
  4828. data.dest = action.get('D');
  4829. } else if (linkType === 'Named') {
  4830. data.action = action.get('N').name;
  4831. } else {
  4832. warn('unrecognized link type: ' + linkType);
  4833. }
  4834. } else if (dict.has('Dest')) {
  4835. // simple destination link
  4836. var dest = dict.get('Dest');
  4837. data.dest = isName(dest) ? dest.name : dest;
  4838. }
  4839. }
  4840. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4841. function addDefaultProtocolToUrl(url) {
  4842. if (url && url.indexOf('www.') === 0) {
  4843. return ('http://' + url);
  4844. }
  4845. return url;
  4846. }
  4847. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4848. return LinkAnnotation;
  4849. })();
  4850. var PDFFunction = (function PDFFunctionClosure() {
  4851. var CONSTRUCT_SAMPLED = 0;
  4852. var CONSTRUCT_INTERPOLATED = 2;
  4853. var CONSTRUCT_STICHED = 3;
  4854. var CONSTRUCT_POSTSCRIPT = 4;
  4855. return {
  4856. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4857. str) {
  4858. var i, ii;
  4859. var length = 1;
  4860. for (i = 0, ii = size.length; i < ii; i++) {
  4861. length *= size[i];
  4862. }
  4863. length *= outputSize;
  4864. var array = new Array(length);
  4865. var codeSize = 0;
  4866. var codeBuf = 0;
  4867. // 32 is a valid bps so shifting won't work
  4868. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4869. var strBytes = str.getBytes((length * bps + 7) / 8);
  4870. var strIdx = 0;
  4871. for (i = 0; i < length; i++) {
  4872. while (codeSize < bps) {
  4873. codeBuf <<= 8;
  4874. codeBuf |= strBytes[strIdx++];
  4875. codeSize += 8;
  4876. }
  4877. codeSize -= bps;
  4878. array[i] = (codeBuf >> codeSize) * sampleMul;
  4879. codeBuf &= (1 << codeSize) - 1;
  4880. }
  4881. return array;
  4882. },
  4883. getIR: function PDFFunction_getIR(xref, fn) {
  4884. var dict = fn.dict;
  4885. if (!dict) {
  4886. dict = fn;
  4887. }
  4888. var types = [this.constructSampled,
  4889. null,
  4890. this.constructInterpolated,
  4891. this.constructStiched,
  4892. this.constructPostScript];
  4893. var typeNum = dict.get('FunctionType');
  4894. var typeFn = types[typeNum];
  4895. if (!typeFn) {
  4896. error('Unknown type of function');
  4897. }
  4898. return typeFn.call(this, fn, dict, xref);
  4899. },
  4900. fromIR: function PDFFunction_fromIR(IR) {
  4901. var type = IR[0];
  4902. switch (type) {
  4903. case CONSTRUCT_SAMPLED:
  4904. return this.constructSampledFromIR(IR);
  4905. case CONSTRUCT_INTERPOLATED:
  4906. return this.constructInterpolatedFromIR(IR);
  4907. case CONSTRUCT_STICHED:
  4908. return this.constructStichedFromIR(IR);
  4909. //case CONSTRUCT_POSTSCRIPT:
  4910. default:
  4911. return this.constructPostScriptFromIR(IR);
  4912. }
  4913. },
  4914. parse: function PDFFunction_parse(xref, fn) {
  4915. var IR = this.getIR(xref, fn);
  4916. return this.fromIR(IR);
  4917. },
  4918. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4919. if (!isArray(fnObj)) {
  4920. // not an array -- parsing as regular function
  4921. return this.parse(xref, fnObj);
  4922. }
  4923. var fnArray = [];
  4924. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4925. var obj = xref.fetchIfRef(fnObj[j]);
  4926. fnArray.push(PDFFunction.parse(xref, obj));
  4927. }
  4928. return function (src, srcOffset, dest, destOffset) {
  4929. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4930. fnArray[i](src, srcOffset, dest, destOffset + i);
  4931. }
  4932. };
  4933. },
  4934. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4935. function toMultiArray(arr) {
  4936. var inputLength = arr.length;
  4937. var out = [];
  4938. var index = 0;
  4939. for (var i = 0; i < inputLength; i += 2) {
  4940. out[index] = [arr[i], arr[i + 1]];
  4941. ++index;
  4942. }
  4943. return out;
  4944. }
  4945. var domain = dict.get('Domain');
  4946. var range = dict.get('Range');
  4947. if (!domain || !range) {
  4948. error('No domain or range');
  4949. }
  4950. var inputSize = domain.length / 2;
  4951. var outputSize = range.length / 2;
  4952. domain = toMultiArray(domain);
  4953. range = toMultiArray(range);
  4954. var size = dict.get('Size');
  4955. var bps = dict.get('BitsPerSample');
  4956. var order = dict.get('Order') || 1;
  4957. if (order !== 1) {
  4958. // No description how cubic spline interpolation works in PDF32000:2008
  4959. // As in poppler, ignoring order, linear interpolation may work as good
  4960. info('No support for cubic spline interpolation: ' + order);
  4961. }
  4962. var encode = dict.get('Encode');
  4963. if (!encode) {
  4964. encode = [];
  4965. for (var i = 0; i < inputSize; ++i) {
  4966. encode.push(0);
  4967. encode.push(size[i] - 1);
  4968. }
  4969. }
  4970. encode = toMultiArray(encode);
  4971. var decode = dict.get('Decode');
  4972. if (!decode) {
  4973. decode = range;
  4974. } else {
  4975. decode = toMultiArray(decode);
  4976. }
  4977. var samples = this.getSampleArray(size, outputSize, bps, str);
  4978. return [
  4979. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4980. outputSize, Math.pow(2, bps) - 1, range
  4981. ];
  4982. },
  4983. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4984. // See chapter 3, page 109 of the PDF reference
  4985. function interpolate(x, xmin, xmax, ymin, ymax) {
  4986. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4987. }
  4988. return function constructSampledFromIRResult(src, srcOffset,
  4989. dest, destOffset) {
  4990. // See chapter 3, page 110 of the PDF reference.
  4991. var m = IR[1];
  4992. var domain = IR[2];
  4993. var encode = IR[3];
  4994. var decode = IR[4];
  4995. var samples = IR[5];
  4996. var size = IR[6];
  4997. var n = IR[7];
  4998. //var mask = IR[8];
  4999. var range = IR[9];
  5000. // Building the cube vertices: its part and sample index
  5001. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5002. var cubeVertices = 1 << m;
  5003. var cubeN = new Float64Array(cubeVertices);
  5004. var cubeVertex = new Uint32Array(cubeVertices);
  5005. var i, j;
  5006. for (j = 0; j < cubeVertices; j++) {
  5007. cubeN[j] = 1;
  5008. }
  5009. var k = n, pos = 1;
  5010. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5011. for (i = 0; i < m; ++i) {
  5012. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5013. var domain_2i = domain[i][0];
  5014. var domain_2i_1 = domain[i][1];
  5015. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5016. domain_2i_1);
  5017. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5018. // Encode_2i, Encode_2i+1)
  5019. var e = interpolate(xi, domain_2i, domain_2i_1,
  5020. encode[i][0], encode[i][1]);
  5021. // e_i' = min(max(e_i, 0), Size_i - 1)
  5022. var size_i = size[i];
  5023. e = Math.min(Math.max(e, 0), size_i - 1);
  5024. // Adjusting the cube: N and vertex sample index
  5025. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5026. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5027. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5028. var offset0 = e0 * k;
  5029. var offset1 = offset0 + k; // e1 * k
  5030. for (j = 0; j < cubeVertices; j++) {
  5031. if (j & pos) {
  5032. cubeN[j] *= n1;
  5033. cubeVertex[j] += offset1;
  5034. } else {
  5035. cubeN[j] *= n0;
  5036. cubeVertex[j] += offset0;
  5037. }
  5038. }
  5039. k *= size_i;
  5040. pos <<= 1;
  5041. }
  5042. for (j = 0; j < n; ++j) {
  5043. // Sum all cube vertices' samples portions
  5044. var rj = 0;
  5045. for (i = 0; i < cubeVertices; i++) {
  5046. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5047. }
  5048. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5049. // Decode_2j, Decode_2j+1)
  5050. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5051. // y_j = min(max(r_j, range_2j), range_2j+1)
  5052. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5053. range[j][1]);
  5054. }
  5055. };
  5056. },
  5057. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5058. dict) {
  5059. var c0 = dict.get('C0') || [0];
  5060. var c1 = dict.get('C1') || [1];
  5061. var n = dict.get('N');
  5062. if (!isArray(c0) || !isArray(c1)) {
  5063. error('Illegal dictionary for interpolated function');
  5064. }
  5065. var length = c0.length;
  5066. var diff = [];
  5067. for (var i = 0; i < length; ++i) {
  5068. diff.push(c1[i] - c0[i]);
  5069. }
  5070. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5071. },
  5072. constructInterpolatedFromIR:
  5073. function PDFFunction_constructInterpolatedFromIR(IR) {
  5074. var c0 = IR[1];
  5075. var diff = IR[2];
  5076. var n = IR[3];
  5077. var length = diff.length;
  5078. return function constructInterpolatedFromIRResult(src, srcOffset,
  5079. dest, destOffset) {
  5080. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5081. for (var j = 0; j < length; ++j) {
  5082. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5083. }
  5084. };
  5085. },
  5086. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5087. var domain = dict.get('Domain');
  5088. if (!domain) {
  5089. error('No domain');
  5090. }
  5091. var inputSize = domain.length / 2;
  5092. if (inputSize !== 1) {
  5093. error('Bad domain for stiched function');
  5094. }
  5095. var fnRefs = dict.get('Functions');
  5096. var fns = [];
  5097. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5098. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5099. }
  5100. var bounds = dict.get('Bounds');
  5101. var encode = dict.get('Encode');
  5102. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5103. },
  5104. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5105. var domain = IR[1];
  5106. var bounds = IR[2];
  5107. var encode = IR[3];
  5108. var fnsIR = IR[4];
  5109. var fns = [];
  5110. var tmpBuf = new Float32Array(1);
  5111. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5112. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5113. }
  5114. return function constructStichedFromIRResult(src, srcOffset,
  5115. dest, destOffset) {
  5116. var clip = function constructStichedFromIRClip(v, min, max) {
  5117. if (v > max) {
  5118. v = max;
  5119. } else if (v < min) {
  5120. v = min;
  5121. }
  5122. return v;
  5123. };
  5124. // clip to domain
  5125. var v = clip(src[srcOffset], domain[0], domain[1]);
  5126. // calulate which bound the value is in
  5127. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5128. if (v < bounds[i]) {
  5129. break;
  5130. }
  5131. }
  5132. // encode value into domain of function
  5133. var dmin = domain[0];
  5134. if (i > 0) {
  5135. dmin = bounds[i - 1];
  5136. }
  5137. var dmax = domain[1];
  5138. if (i < bounds.length) {
  5139. dmax = bounds[i];
  5140. }
  5141. var rmin = encode[2 * i];
  5142. var rmax = encode[2 * i + 1];
  5143. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5144. // call the appropriate function
  5145. fns[i](tmpBuf, 0, dest, destOffset);
  5146. };
  5147. },
  5148. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5149. xref) {
  5150. var domain = dict.get('Domain');
  5151. var range = dict.get('Range');
  5152. if (!domain) {
  5153. error('No domain.');
  5154. }
  5155. if (!range) {
  5156. error('No range.');
  5157. }
  5158. var lexer = new PostScriptLexer(fn);
  5159. var parser = new PostScriptParser(lexer);
  5160. var code = parser.parse();
  5161. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5162. },
  5163. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5164. IR) {
  5165. var domain = IR[1];
  5166. var range = IR[2];
  5167. var code = IR[3];
  5168. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5169. if (compiled) {
  5170. // Compiled function consists of simple expressions such as addition,
  5171. // subtraction, Math.max, and also contains 'var' and 'return'
  5172. // statements. See the generation in the PostScriptCompiler below.
  5173. /*jshint -W054 */
  5174. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5175. }
  5176. info('Unable to compile PS function');
  5177. var numOutputs = range.length >> 1;
  5178. var numInputs = domain.length >> 1;
  5179. var evaluator = new PostScriptEvaluator(code);
  5180. // Cache the values for a big speed up, the cache size is limited though
  5181. // since the number of possible values can be huge from a PS function.
  5182. var cache = {};
  5183. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5184. // seen in our tests.
  5185. var MAX_CACHE_SIZE = 2048 * 4;
  5186. var cache_available = MAX_CACHE_SIZE;
  5187. var tmpBuf = new Float32Array(numInputs);
  5188. return function constructPostScriptFromIRResult(src, srcOffset,
  5189. dest, destOffset) {
  5190. var i, value;
  5191. var key = '';
  5192. var input = tmpBuf;
  5193. for (i = 0; i < numInputs; i++) {
  5194. value = src[srcOffset + i];
  5195. input[i] = value;
  5196. key += value + '_';
  5197. }
  5198. var cachedValue = cache[key];
  5199. if (cachedValue !== undefined) {
  5200. dest.set(cachedValue, destOffset);
  5201. return;
  5202. }
  5203. var output = new Float32Array(numOutputs);
  5204. var stack = evaluator.execute(input);
  5205. var stackIndex = stack.length - numOutputs;
  5206. for (i = 0; i < numOutputs; i++) {
  5207. value = stack[stackIndex + i];
  5208. var bound = range[i * 2];
  5209. if (value < bound) {
  5210. value = bound;
  5211. } else {
  5212. bound = range[i * 2 +1];
  5213. if (value > bound) {
  5214. value = bound;
  5215. }
  5216. }
  5217. output[i] = value;
  5218. }
  5219. if (cache_available > 0) {
  5220. cache_available--;
  5221. cache[key] = output;
  5222. }
  5223. dest.set(output, destOffset);
  5224. };
  5225. }
  5226. };
  5227. })();
  5228. function isPDFFunction(v) {
  5229. var fnDict;
  5230. if (typeof v !== 'object') {
  5231. return false;
  5232. } else if (isDict(v)) {
  5233. fnDict = v;
  5234. } else if (isStream(v)) {
  5235. fnDict = v.dict;
  5236. } else {
  5237. return false;
  5238. }
  5239. return fnDict.has('FunctionType');
  5240. }
  5241. var PostScriptStack = (function PostScriptStackClosure() {
  5242. var MAX_STACK_SIZE = 100;
  5243. function PostScriptStack(initialStack) {
  5244. this.stack = !initialStack ? [] :
  5245. Array.prototype.slice.call(initialStack, 0);
  5246. }
  5247. PostScriptStack.prototype = {
  5248. push: function PostScriptStack_push(value) {
  5249. if (this.stack.length >= MAX_STACK_SIZE) {
  5250. error('PostScript function stack overflow.');
  5251. }
  5252. this.stack.push(value);
  5253. },
  5254. pop: function PostScriptStack_pop() {
  5255. if (this.stack.length <= 0) {
  5256. error('PostScript function stack underflow.');
  5257. }
  5258. return this.stack.pop();
  5259. },
  5260. copy: function PostScriptStack_copy(n) {
  5261. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5262. error('PostScript function stack overflow.');
  5263. }
  5264. var stack = this.stack;
  5265. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5266. stack.push(stack[i]);
  5267. }
  5268. },
  5269. index: function PostScriptStack_index(n) {
  5270. this.push(this.stack[this.stack.length - n - 1]);
  5271. },
  5272. // rotate the last n stack elements p times
  5273. roll: function PostScriptStack_roll(n, p) {
  5274. var stack = this.stack;
  5275. var l = stack.length - n;
  5276. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5277. for (i = l, j = r; i < j; i++, j--) {
  5278. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5279. }
  5280. for (i = l, j = c - 1; i < j; i++, j--) {
  5281. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5282. }
  5283. for (i = c, j = r; i < j; i++, j--) {
  5284. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5285. }
  5286. }
  5287. };
  5288. return PostScriptStack;
  5289. })();
  5290. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5291. function PostScriptEvaluator(operators) {
  5292. this.operators = operators;
  5293. }
  5294. PostScriptEvaluator.prototype = {
  5295. execute: function PostScriptEvaluator_execute(initialStack) {
  5296. var stack = new PostScriptStack(initialStack);
  5297. var counter = 0;
  5298. var operators = this.operators;
  5299. var length = operators.length;
  5300. var operator, a, b;
  5301. while (counter < length) {
  5302. operator = operators[counter++];
  5303. if (typeof operator === 'number') {
  5304. // Operator is really an operand and should be pushed to the stack.
  5305. stack.push(operator);
  5306. continue;
  5307. }
  5308. switch (operator) {
  5309. // non standard ps operators
  5310. case 'jz': // jump if false
  5311. b = stack.pop();
  5312. a = stack.pop();
  5313. if (!a) {
  5314. counter = b;
  5315. }
  5316. break;
  5317. case 'j': // jump
  5318. a = stack.pop();
  5319. counter = a;
  5320. break;
  5321. // all ps operators in alphabetical order (excluding if/ifelse)
  5322. case 'abs':
  5323. a = stack.pop();
  5324. stack.push(Math.abs(a));
  5325. break;
  5326. case 'add':
  5327. b = stack.pop();
  5328. a = stack.pop();
  5329. stack.push(a + b);
  5330. break;
  5331. case 'and':
  5332. b = stack.pop();
  5333. a = stack.pop();
  5334. if (isBool(a) && isBool(b)) {
  5335. stack.push(a && b);
  5336. } else {
  5337. stack.push(a & b);
  5338. }
  5339. break;
  5340. case 'atan':
  5341. a = stack.pop();
  5342. stack.push(Math.atan(a));
  5343. break;
  5344. case 'bitshift':
  5345. b = stack.pop();
  5346. a = stack.pop();
  5347. if (a > 0) {
  5348. stack.push(a << b);
  5349. } else {
  5350. stack.push(a >> b);
  5351. }
  5352. break;
  5353. case 'ceiling':
  5354. a = stack.pop();
  5355. stack.push(Math.ceil(a));
  5356. break;
  5357. case 'copy':
  5358. a = stack.pop();
  5359. stack.copy(a);
  5360. break;
  5361. case 'cos':
  5362. a = stack.pop();
  5363. stack.push(Math.cos(a));
  5364. break;
  5365. case 'cvi':
  5366. a = stack.pop() | 0;
  5367. stack.push(a);
  5368. break;
  5369. case 'cvr':
  5370. // noop
  5371. break;
  5372. case 'div':
  5373. b = stack.pop();
  5374. a = stack.pop();
  5375. stack.push(a / b);
  5376. break;
  5377. case 'dup':
  5378. stack.copy(1);
  5379. break;
  5380. case 'eq':
  5381. b = stack.pop();
  5382. a = stack.pop();
  5383. stack.push(a === b);
  5384. break;
  5385. case 'exch':
  5386. stack.roll(2, 1);
  5387. break;
  5388. case 'exp':
  5389. b = stack.pop();
  5390. a = stack.pop();
  5391. stack.push(Math.pow(a, b));
  5392. break;
  5393. case 'false':
  5394. stack.push(false);
  5395. break;
  5396. case 'floor':
  5397. a = stack.pop();
  5398. stack.push(Math.floor(a));
  5399. break;
  5400. case 'ge':
  5401. b = stack.pop();
  5402. a = stack.pop();
  5403. stack.push(a >= b);
  5404. break;
  5405. case 'gt':
  5406. b = stack.pop();
  5407. a = stack.pop();
  5408. stack.push(a > b);
  5409. break;
  5410. case 'idiv':
  5411. b = stack.pop();
  5412. a = stack.pop();
  5413. stack.push((a / b) | 0);
  5414. break;
  5415. case 'index':
  5416. a = stack.pop();
  5417. stack.index(a);
  5418. break;
  5419. case 'le':
  5420. b = stack.pop();
  5421. a = stack.pop();
  5422. stack.push(a <= b);
  5423. break;
  5424. case 'ln':
  5425. a = stack.pop();
  5426. stack.push(Math.log(a));
  5427. break;
  5428. case 'log':
  5429. a = stack.pop();
  5430. stack.push(Math.log(a) / Math.LN10);
  5431. break;
  5432. case 'lt':
  5433. b = stack.pop();
  5434. a = stack.pop();
  5435. stack.push(a < b);
  5436. break;
  5437. case 'mod':
  5438. b = stack.pop();
  5439. a = stack.pop();
  5440. stack.push(a % b);
  5441. break;
  5442. case 'mul':
  5443. b = stack.pop();
  5444. a = stack.pop();
  5445. stack.push(a * b);
  5446. break;
  5447. case 'ne':
  5448. b = stack.pop();
  5449. a = stack.pop();
  5450. stack.push(a !== b);
  5451. break;
  5452. case 'neg':
  5453. a = stack.pop();
  5454. stack.push(-a);
  5455. break;
  5456. case 'not':
  5457. a = stack.pop();
  5458. if (isBool(a)) {
  5459. stack.push(!a);
  5460. } else {
  5461. stack.push(~a);
  5462. }
  5463. break;
  5464. case 'or':
  5465. b = stack.pop();
  5466. a = stack.pop();
  5467. if (isBool(a) && isBool(b)) {
  5468. stack.push(a || b);
  5469. } else {
  5470. stack.push(a | b);
  5471. }
  5472. break;
  5473. case 'pop':
  5474. stack.pop();
  5475. break;
  5476. case 'roll':
  5477. b = stack.pop();
  5478. a = stack.pop();
  5479. stack.roll(a, b);
  5480. break;
  5481. case 'round':
  5482. a = stack.pop();
  5483. stack.push(Math.round(a));
  5484. break;
  5485. case 'sin':
  5486. a = stack.pop();
  5487. stack.push(Math.sin(a));
  5488. break;
  5489. case 'sqrt':
  5490. a = stack.pop();
  5491. stack.push(Math.sqrt(a));
  5492. break;
  5493. case 'sub':
  5494. b = stack.pop();
  5495. a = stack.pop();
  5496. stack.push(a - b);
  5497. break;
  5498. case 'true':
  5499. stack.push(true);
  5500. break;
  5501. case 'truncate':
  5502. a = stack.pop();
  5503. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5504. stack.push(a);
  5505. break;
  5506. case 'xor':
  5507. b = stack.pop();
  5508. a = stack.pop();
  5509. if (isBool(a) && isBool(b)) {
  5510. stack.push(a !== b);
  5511. } else {
  5512. stack.push(a ^ b);
  5513. }
  5514. break;
  5515. default:
  5516. error('Unknown operator ' + operator);
  5517. break;
  5518. }
  5519. }
  5520. return stack.stack;
  5521. }
  5522. };
  5523. return PostScriptEvaluator;
  5524. })();
  5525. // Most of the PDFs functions consist of simple operations such as:
  5526. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5527. //
  5528. // We can compile most of such programs, and at the same moment, we can
  5529. // optimize some expressions using basic math properties. Keeping track of
  5530. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5531. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5532. function AstNode(type) {
  5533. this.type = type;
  5534. }
  5535. AstNode.prototype.visit = function (visitor) {
  5536. throw new Error('abstract method');
  5537. };
  5538. function AstArgument(index, min, max) {
  5539. AstNode.call(this, 'args');
  5540. this.index = index;
  5541. this.min = min;
  5542. this.max = max;
  5543. }
  5544. AstArgument.prototype = Object.create(AstNode.prototype);
  5545. AstArgument.prototype.visit = function (visitor) {
  5546. visitor.visitArgument(this);
  5547. };
  5548. function AstLiteral(number) {
  5549. AstNode.call(this, 'literal');
  5550. this.number = number;
  5551. this.min = number;
  5552. this.max = number;
  5553. }
  5554. AstLiteral.prototype = Object.create(AstNode.prototype);
  5555. AstLiteral.prototype.visit = function (visitor) {
  5556. visitor.visitLiteral(this);
  5557. };
  5558. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5559. AstNode.call(this, 'binary');
  5560. this.op = op;
  5561. this.arg1 = arg1;
  5562. this.arg2 = arg2;
  5563. this.min = min;
  5564. this.max = max;
  5565. }
  5566. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5567. AstBinaryOperation.prototype.visit = function (visitor) {
  5568. visitor.visitBinaryOperation(this);
  5569. };
  5570. function AstMin(arg, max) {
  5571. AstNode.call(this, 'max');
  5572. this.arg = arg;
  5573. this.min = arg.min;
  5574. this.max = max;
  5575. }
  5576. AstMin.prototype = Object.create(AstNode.prototype);
  5577. AstMin.prototype.visit = function (visitor) {
  5578. visitor.visitMin(this);
  5579. };
  5580. function AstVariable(index, min, max) {
  5581. AstNode.call(this, 'var');
  5582. this.index = index;
  5583. this.min = min;
  5584. this.max = max;
  5585. }
  5586. AstVariable.prototype = Object.create(AstNode.prototype);
  5587. AstVariable.prototype.visit = function (visitor) {
  5588. visitor.visitVariable(this);
  5589. };
  5590. function AstVariableDefinition(variable, arg) {
  5591. AstNode.call(this, 'definition');
  5592. this.variable = variable;
  5593. this.arg = arg;
  5594. }
  5595. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5596. AstVariableDefinition.prototype.visit = function (visitor) {
  5597. visitor.visitVariableDefinition(this);
  5598. };
  5599. function ExpressionBuilderVisitor() {
  5600. this.parts = [];
  5601. }
  5602. ExpressionBuilderVisitor.prototype = {
  5603. visitArgument: function (arg) {
  5604. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5605. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5606. },
  5607. visitVariable: function (variable) {
  5608. this.parts.push('v', variable.index);
  5609. },
  5610. visitLiteral: function (literal) {
  5611. this.parts.push(literal.number);
  5612. },
  5613. visitBinaryOperation: function (operation) {
  5614. this.parts.push('(');
  5615. operation.arg1.visit(this);
  5616. this.parts.push(' ', operation.op, ' ');
  5617. operation.arg2.visit(this);
  5618. this.parts.push(')');
  5619. },
  5620. visitVariableDefinition: function (definition) {
  5621. this.parts.push('var ');
  5622. definition.variable.visit(this);
  5623. this.parts.push(' = ');
  5624. definition.arg.visit(this);
  5625. this.parts.push(';');
  5626. },
  5627. visitMin: function (max) {
  5628. this.parts.push('Math.min(');
  5629. max.arg.visit(this);
  5630. this.parts.push(', ', max.max, ')');
  5631. },
  5632. toString: function () {
  5633. return this.parts.join('');
  5634. }
  5635. };
  5636. function buildAddOperation(num1, num2) {
  5637. if (num2.type === 'literal' && num2.number === 0) {
  5638. // optimization: second operand is 0
  5639. return num1;
  5640. }
  5641. if (num1.type === 'literal' && num1.number === 0) {
  5642. // optimization: first operand is 0
  5643. return num2;
  5644. }
  5645. if (num2.type === 'literal' && num1.type === 'literal') {
  5646. // optimization: operands operand are literals
  5647. return new AstLiteral(num1.number + num2.number);
  5648. }
  5649. return new AstBinaryOperation('+', num1, num2,
  5650. num1.min + num2.min, num1.max + num2.max);
  5651. }
  5652. function buildMulOperation(num1, num2) {
  5653. if (num2.type === 'literal') {
  5654. // optimization: second operands is a literal...
  5655. if (num2.number === 0) {
  5656. return new AstLiteral(0); // and it's 0
  5657. } else if (num2.number === 1) {
  5658. return num1; // and it's 1
  5659. } else if (num1.type === 'literal') {
  5660. // ... and first operands is a literal too
  5661. return new AstLiteral(num1.number * num2.number);
  5662. }
  5663. }
  5664. if (num1.type === 'literal') {
  5665. // optimization: first operands is a literal...
  5666. if (num1.number === 0) {
  5667. return new AstLiteral(0); // and it's 0
  5668. } else if (num1.number === 1) {
  5669. return num2; // and it's 1
  5670. }
  5671. }
  5672. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5673. num1.max * num2.min, num1.max * num2.max);
  5674. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5675. num1.max * num2.min, num1.max * num2.max);
  5676. return new AstBinaryOperation('*', num1, num2, min, max);
  5677. }
  5678. function buildSubOperation(num1, num2) {
  5679. if (num2.type === 'literal') {
  5680. // optimization: second operands is a literal...
  5681. if (num2.number === 0) {
  5682. return num1; // ... and it's 0
  5683. } else if (num1.type === 'literal') {
  5684. // ... and first operands is a literal too
  5685. return new AstLiteral(num1.number - num2.number);
  5686. }
  5687. }
  5688. if (num2.type === 'binary' && num2.op === '-' &&
  5689. num1.type === 'literal' && num1.number === 1 &&
  5690. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5691. // optimization for case: 1 - (1 - x)
  5692. return num2.arg2;
  5693. }
  5694. return new AstBinaryOperation('-', num1, num2,
  5695. num1.min - num2.max, num1.max - num2.min);
  5696. }
  5697. function buildMinOperation(num1, max) {
  5698. if (num1.min >= max) {
  5699. // optimization: num1 min value is not less than required max
  5700. return new AstLiteral(max); // just returning max
  5701. } else if (num1.max <= max) {
  5702. // optimization: num1 max value is not greater than required max
  5703. return num1; // just returning an argument
  5704. }
  5705. return new AstMin(num1, max);
  5706. }
  5707. function PostScriptCompiler() {}
  5708. PostScriptCompiler.prototype = {
  5709. compile: function PostScriptCompiler_compile(code, domain, range) {
  5710. var stack = [];
  5711. var i, ii;
  5712. var instructions = [];
  5713. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5714. var lastRegister = 0;
  5715. var n, j, min, max;
  5716. var num1, num2, ast1, ast2, tmpVar, item;
  5717. for (i = 0; i < inputSize; i++) {
  5718. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5719. }
  5720. for (i = 0, ii = code.length; i < ii; i++) {
  5721. item = code[i];
  5722. if (typeof item === 'number') {
  5723. stack.push(new AstLiteral(item));
  5724. continue;
  5725. }
  5726. switch (item) {
  5727. case 'add':
  5728. if (stack.length < 2) {
  5729. return null;
  5730. }
  5731. num2 = stack.pop();
  5732. num1 = stack.pop();
  5733. stack.push(buildAddOperation(num1, num2));
  5734. break;
  5735. case 'cvr':
  5736. if (stack.length < 1) {
  5737. return null;
  5738. }
  5739. break;
  5740. case 'mul':
  5741. if (stack.length < 2) {
  5742. return null;
  5743. }
  5744. num2 = stack.pop();
  5745. num1 = stack.pop();
  5746. stack.push(buildMulOperation(num1, num2));
  5747. break;
  5748. case 'sub':
  5749. if (stack.length < 2) {
  5750. return null;
  5751. }
  5752. num2 = stack.pop();
  5753. num1 = stack.pop();
  5754. stack.push(buildSubOperation(num1, num2));
  5755. break;
  5756. case 'exch':
  5757. if (stack.length < 2) {
  5758. return null;
  5759. }
  5760. ast1 = stack.pop(); ast2 = stack.pop();
  5761. stack.push(ast1, ast2);
  5762. break;
  5763. case 'pop':
  5764. if (stack.length < 1) {
  5765. return null;
  5766. }
  5767. stack.pop();
  5768. break;
  5769. case 'index':
  5770. if (stack.length < 1) {
  5771. return null;
  5772. }
  5773. num1 = stack.pop();
  5774. if (num1.type !== 'literal') {
  5775. return null;
  5776. }
  5777. n = num1.number;
  5778. if (n < 0 || (n|0) !== n || stack.length < n) {
  5779. return null;
  5780. }
  5781. ast1 = stack[stack.length - n - 1];
  5782. if (ast1.type === 'literal' || ast1.type === 'var') {
  5783. stack.push(ast1);
  5784. break;
  5785. }
  5786. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5787. stack[stack.length - n - 1] = tmpVar;
  5788. stack.push(tmpVar);
  5789. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5790. break;
  5791. case 'dup':
  5792. if (stack.length < 1) {
  5793. return null;
  5794. }
  5795. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5796. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5797. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5798. // special case of the commands sequence for the min operation
  5799. num1 = stack.pop();
  5800. stack.push(buildMinOperation(num1, code[i + 1]));
  5801. i += 6;
  5802. break;
  5803. }
  5804. ast1 = stack[stack.length - 1];
  5805. if (ast1.type === 'literal' || ast1.type === 'var') {
  5806. // we don't have to save into intermediate variable a literal or
  5807. // variable.
  5808. stack.push(ast1);
  5809. break;
  5810. }
  5811. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5812. stack[stack.length - 1] = tmpVar;
  5813. stack.push(tmpVar);
  5814. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5815. break;
  5816. case 'roll':
  5817. if (stack.length < 2) {
  5818. return null;
  5819. }
  5820. num2 = stack.pop();
  5821. num1 = stack.pop();
  5822. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5823. // both roll operands must be numbers
  5824. return null;
  5825. }
  5826. j = num2.number;
  5827. n = num1.number;
  5828. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5829. // ... and integers
  5830. return null;
  5831. }
  5832. j = ((j % n) + n) % n;
  5833. if (j === 0) {
  5834. break; // just skipping -- there are nothing to rotate
  5835. }
  5836. Array.prototype.push.apply(stack,
  5837. stack.splice(stack.length - n, n - j));
  5838. break;
  5839. default:
  5840. return null; // unsupported operator
  5841. }
  5842. }
  5843. if (stack.length !== outputSize) {
  5844. return null;
  5845. }
  5846. var result = [];
  5847. instructions.forEach(function (instruction) {
  5848. var statementBuilder = new ExpressionBuilderVisitor();
  5849. instruction.visit(statementBuilder);
  5850. result.push(statementBuilder.toString());
  5851. });
  5852. stack.forEach(function (expr, i) {
  5853. var statementBuilder = new ExpressionBuilderVisitor();
  5854. expr.visit(statementBuilder);
  5855. var min = range[i * 2], max = range[i * 2 + 1];
  5856. var out = [statementBuilder.toString()];
  5857. if (min > expr.min) {
  5858. out.unshift('Math.max(', min, ', ');
  5859. out.push(')');
  5860. }
  5861. if (max < expr.max) {
  5862. out.unshift('Math.min(', max, ', ');
  5863. out.push(')');
  5864. }
  5865. out.unshift('dest[destOffset + ', i, '] = ');
  5866. out.push(';');
  5867. result.push(out.join(''));
  5868. });
  5869. return result.join('\n');
  5870. }
  5871. };
  5872. return PostScriptCompiler;
  5873. })();
  5874. var ColorSpace = (function ColorSpaceClosure() {
  5875. // Constructor should define this.numComps, this.defaultColor, this.name
  5876. function ColorSpace() {
  5877. error('should not call ColorSpace constructor');
  5878. }
  5879. ColorSpace.prototype = {
  5880. /**
  5881. * Converts the color value to the RGB color. The color components are
  5882. * located in the src array starting from the srcOffset. Returns the array
  5883. * of the rgb components, each value ranging from [0,255].
  5884. */
  5885. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5886. var rgb = new Uint8Array(3);
  5887. this.getRgbItem(src, srcOffset, rgb, 0);
  5888. return rgb;
  5889. },
  5890. /**
  5891. * Converts the color value to the RGB color, similar to the getRgb method.
  5892. * The result placed into the dest array starting from the destOffset.
  5893. */
  5894. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5895. dest, destOffset) {
  5896. error('Should not call ColorSpace.getRgbItem');
  5897. },
  5898. /**
  5899. * Converts the specified number of the color values to the RGB colors.
  5900. * The colors are located in the src array starting from the srcOffset.
  5901. * The result is placed into the dest array starting from the destOffset.
  5902. * The src array items shall be in [0,2^bits) range, the dest array items
  5903. * will be in [0,255] range. alpha01 indicates how many alpha components
  5904. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5905. * array).
  5906. */
  5907. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5908. dest, destOffset, bits,
  5909. alpha01) {
  5910. error('Should not call ColorSpace.getRgbBuffer');
  5911. },
  5912. /**
  5913. * Determines the number of bytes required to store the result of the
  5914. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5915. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5916. */
  5917. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5918. alpha01) {
  5919. error('Should not call ColorSpace.getOutputLength');
  5920. },
  5921. /**
  5922. * Returns true if source data will be equal the result/output data.
  5923. */
  5924. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5925. return false;
  5926. },
  5927. /**
  5928. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5929. * how many alpha components there are in the dest array; it will be either
  5930. * 0 (RGB array) or 1 (RGBA array).
  5931. */
  5932. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5933. originalHeight, width, height,
  5934. actualHeight, bpc, comps, alpha01) {
  5935. var count = originalWidth * originalHeight;
  5936. var rgbBuf = null;
  5937. var numComponentColors = 1 << bpc;
  5938. var needsResizing = originalHeight !== height || originalWidth !== width;
  5939. var i, ii;
  5940. if (this.isPassthrough(bpc)) {
  5941. rgbBuf = comps;
  5942. } else if (this.numComps === 1 && count > numComponentColors &&
  5943. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5944. // Optimization: create a color map when there is just one component and
  5945. // we are converting more colors than the size of the color map. We
  5946. // don't build the map if the colorspace is gray or rgb since those
  5947. // methods are faster than building a map. This mainly offers big speed
  5948. // ups for indexed and alternate colorspaces.
  5949. //
  5950. // TODO it may be worth while to cache the color map. While running
  5951. // testing I never hit a cache so I will leave that out for now (perhaps
  5952. // we are reparsing colorspaces too much?).
  5953. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5954. new Uint16Array(numComponentColors);
  5955. var key;
  5956. for (i = 0; i < numComponentColors; i++) {
  5957. allColors[i] = i;
  5958. }
  5959. var colorMap = new Uint8Array(numComponentColors * 3);
  5960. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5961. /* alpha01 = */ 0);
  5962. var destPos, rgbPos;
  5963. if (!needsResizing) {
  5964. // Fill in the RGB values directly into |dest|.
  5965. destPos = 0;
  5966. for (i = 0; i < count; ++i) {
  5967. key = comps[i] * 3;
  5968. dest[destPos++] = colorMap[key];
  5969. dest[destPos++] = colorMap[key + 1];
  5970. dest[destPos++] = colorMap[key + 2];
  5971. destPos += alpha01;
  5972. }
  5973. } else {
  5974. rgbBuf = new Uint8Array(count * 3);
  5975. rgbPos = 0;
  5976. for (i = 0; i < count; ++i) {
  5977. key = comps[i] * 3;
  5978. rgbBuf[rgbPos++] = colorMap[key];
  5979. rgbBuf[rgbPos++] = colorMap[key + 1];
  5980. rgbBuf[rgbPos++] = colorMap[key + 2];
  5981. }
  5982. }
  5983. } else {
  5984. if (!needsResizing) {
  5985. // Fill in the RGB values directly into |dest|.
  5986. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5987. alpha01);
  5988. } else {
  5989. rgbBuf = new Uint8Array(count * 3);
  5990. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5991. /* alpha01 = */ 0);
  5992. }
  5993. }
  5994. if (rgbBuf) {
  5995. if (needsResizing) {
  5996. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5997. height, dest, alpha01);
  5998. } else {
  5999. rgbPos = 0;
  6000. destPos = 0;
  6001. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6002. dest[destPos++] = rgbBuf[rgbPos++];
  6003. dest[destPos++] = rgbBuf[rgbPos++];
  6004. dest[destPos++] = rgbBuf[rgbPos++];
  6005. destPos += alpha01;
  6006. }
  6007. }
  6008. }
  6009. },
  6010. /**
  6011. * True if the colorspace has components in the default range of [0, 1].
  6012. * This should be true for all colorspaces except for lab color spaces
  6013. * which are [0,100], [-128, 127], [-128, 127].
  6014. */
  6015. usesZeroToOneRange: true
  6016. };
  6017. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6018. var IR = ColorSpace.parseToIR(cs, xref, res);
  6019. if (IR instanceof AlternateCS) {
  6020. return IR;
  6021. }
  6022. return ColorSpace.fromIR(IR);
  6023. };
  6024. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6025. var name = isArray(IR) ? IR[0] : IR;
  6026. var whitePoint, blackPoint, gamma;
  6027. switch (name) {
  6028. case 'DeviceGrayCS':
  6029. return this.singletons.gray;
  6030. case 'DeviceRgbCS':
  6031. return this.singletons.rgb;
  6032. case 'DeviceCmykCS':
  6033. return this.singletons.cmyk;
  6034. case 'CalGrayCS':
  6035. whitePoint = IR[1].WhitePoint;
  6036. blackPoint = IR[1].BlackPoint;
  6037. gamma = IR[1].Gamma;
  6038. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6039. case 'CalRGBCS':
  6040. whitePoint = IR[1].WhitePoint;
  6041. blackPoint = IR[1].BlackPoint;
  6042. gamma = IR[1].Gamma;
  6043. var matrix = IR[1].Matrix;
  6044. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6045. case 'PatternCS':
  6046. var basePatternCS = IR[1];
  6047. if (basePatternCS) {
  6048. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6049. }
  6050. return new PatternCS(basePatternCS);
  6051. case 'IndexedCS':
  6052. var baseIndexedCS = IR[1];
  6053. var hiVal = IR[2];
  6054. var lookup = IR[3];
  6055. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6056. case 'AlternateCS':
  6057. var numComps = IR[1];
  6058. var alt = IR[2];
  6059. var tintFnIR = IR[3];
  6060. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6061. PDFFunction.fromIR(tintFnIR));
  6062. case 'LabCS':
  6063. whitePoint = IR[1].WhitePoint;
  6064. blackPoint = IR[1].BlackPoint;
  6065. var range = IR[1].Range;
  6066. return new LabCS(whitePoint, blackPoint, range);
  6067. default:
  6068. error('Unknown name ' + name);
  6069. }
  6070. return null;
  6071. };
  6072. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6073. if (isName(cs)) {
  6074. var colorSpaces = res.get('ColorSpace');
  6075. if (isDict(colorSpaces)) {
  6076. var refcs = colorSpaces.get(cs.name);
  6077. if (refcs) {
  6078. cs = refcs;
  6079. }
  6080. }
  6081. }
  6082. cs = xref.fetchIfRef(cs);
  6083. var mode;
  6084. if (isName(cs)) {
  6085. mode = cs.name;
  6086. this.mode = mode;
  6087. switch (mode) {
  6088. case 'DeviceGray':
  6089. case 'G':
  6090. return 'DeviceGrayCS';
  6091. case 'DeviceRGB':
  6092. case 'RGB':
  6093. return 'DeviceRgbCS';
  6094. case 'DeviceCMYK':
  6095. case 'CMYK':
  6096. return 'DeviceCmykCS';
  6097. case 'Pattern':
  6098. return ['PatternCS', null];
  6099. default:
  6100. error('unrecognized colorspace ' + mode);
  6101. }
  6102. } else if (isArray(cs)) {
  6103. mode = xref.fetchIfRef(cs[0]).name;
  6104. this.mode = mode;
  6105. var numComps, params;
  6106. switch (mode) {
  6107. case 'DeviceGray':
  6108. case 'G':
  6109. return 'DeviceGrayCS';
  6110. case 'DeviceRGB':
  6111. case 'RGB':
  6112. return 'DeviceRgbCS';
  6113. case 'DeviceCMYK':
  6114. case 'CMYK':
  6115. return 'DeviceCmykCS';
  6116. case 'CalGray':
  6117. params = xref.fetchIfRef(cs[1]).getAll();
  6118. return ['CalGrayCS', params];
  6119. case 'CalRGB':
  6120. params = xref.fetchIfRef(cs[1]).getAll();
  6121. return ['CalRGBCS', params];
  6122. case 'ICCBased':
  6123. var stream = xref.fetchIfRef(cs[1]);
  6124. var dict = stream.dict;
  6125. numComps = dict.get('N');
  6126. if (numComps === 1) {
  6127. return 'DeviceGrayCS';
  6128. } else if (numComps === 3) {
  6129. return 'DeviceRgbCS';
  6130. } else if (numComps === 4) {
  6131. return 'DeviceCmykCS';
  6132. }
  6133. break;
  6134. case 'Pattern':
  6135. var basePatternCS = xref.fetchIfRef(cs[1]) || null;
  6136. if (basePatternCS) {
  6137. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6138. }
  6139. return ['PatternCS', basePatternCS];
  6140. case 'Indexed':
  6141. case 'I':
  6142. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6143. var hiVal = cs[2] + 1;
  6144. var lookup = xref.fetchIfRef(cs[3]);
  6145. if (isStream(lookup)) {
  6146. lookup = lookup.getBytes();
  6147. }
  6148. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6149. case 'Separation':
  6150. case 'DeviceN':
  6151. var name = cs[1];
  6152. numComps = 1;
  6153. if (isName(name)) {
  6154. numComps = 1;
  6155. } else if (isArray(name)) {
  6156. numComps = name.length;
  6157. }
  6158. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6159. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6160. return ['AlternateCS', numComps, alt, tintFnIR];
  6161. case 'Lab':
  6162. params = cs[1].getAll();
  6163. return ['LabCS', params];
  6164. default:
  6165. error('unimplemented color space object "' + mode + '"');
  6166. }
  6167. } else {
  6168. error('unrecognized color space object: "' + cs + '"');
  6169. }
  6170. return null;
  6171. };
  6172. /**
  6173. * Checks if a decode map matches the default decode map for a color space.
  6174. * This handles the general decode maps where there are two values per
  6175. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6176. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6177. * slightly different.
  6178. * @param {Array} decode Decode map (usually from an image).
  6179. * @param {Number} n Number of components the color space has.
  6180. */
  6181. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6182. if (!decode) {
  6183. return true;
  6184. }
  6185. if (n * 2 !== decode.length) {
  6186. warn('The decode map is not the correct length');
  6187. return true;
  6188. }
  6189. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6190. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6191. return false;
  6192. }
  6193. }
  6194. return true;
  6195. };
  6196. ColorSpace.singletons = {
  6197. get gray() {
  6198. return shadow(this, 'gray', new DeviceGrayCS());
  6199. },
  6200. get rgb() {
  6201. return shadow(this, 'rgb', new DeviceRgbCS());
  6202. },
  6203. get cmyk() {
  6204. return shadow(this, 'cmyk', new DeviceCmykCS());
  6205. }
  6206. };
  6207. return ColorSpace;
  6208. })();
  6209. /**
  6210. * Alternate color space handles both Separation and DeviceN color spaces. A
  6211. * Separation color space is actually just a DeviceN with one color component.
  6212. * Both color spaces use a tinting function to convert colors to a base color
  6213. * space.
  6214. */
  6215. var AlternateCS = (function AlternateCSClosure() {
  6216. function AlternateCS(numComps, base, tintFn) {
  6217. this.name = 'Alternate';
  6218. this.numComps = numComps;
  6219. this.defaultColor = new Float32Array(numComps);
  6220. for (var i = 0; i < numComps; ++i) {
  6221. this.defaultColor[i] = 1;
  6222. }
  6223. this.base = base;
  6224. this.tintFn = tintFn;
  6225. this.tmpBuf = new Float32Array(base.numComps);
  6226. }
  6227. AlternateCS.prototype = {
  6228. getRgb: ColorSpace.prototype.getRgb,
  6229. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6230. dest, destOffset) {
  6231. var tmpBuf = this.tmpBuf;
  6232. this.tintFn(src, srcOffset, tmpBuf, 0);
  6233. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6234. },
  6235. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6236. dest, destOffset, bits,
  6237. alpha01) {
  6238. var tintFn = this.tintFn;
  6239. var base = this.base;
  6240. var scale = 1 / ((1 << bits) - 1);
  6241. var baseNumComps = base.numComps;
  6242. var usesZeroToOneRange = base.usesZeroToOneRange;
  6243. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6244. alpha01 === 0;
  6245. var pos = isPassthrough ? destOffset : 0;
  6246. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6247. var numComps = this.numComps;
  6248. var scaled = new Float32Array(numComps);
  6249. var tinted = new Float32Array(baseNumComps);
  6250. var i, j;
  6251. if (usesZeroToOneRange) {
  6252. for (i = 0; i < count; i++) {
  6253. for (j = 0; j < numComps; j++) {
  6254. scaled[j] = src[srcOffset++] * scale;
  6255. }
  6256. tintFn(scaled, 0, tinted, 0);
  6257. for (j = 0; j < baseNumComps; j++) {
  6258. baseBuf[pos++] = tinted[j] * 255;
  6259. }
  6260. }
  6261. } else {
  6262. for (i = 0; i < count; i++) {
  6263. for (j = 0; j < numComps; j++) {
  6264. scaled[j] = src[srcOffset++] * scale;
  6265. }
  6266. tintFn(scaled, 0, tinted, 0);
  6267. base.getRgbItem(tinted, 0, baseBuf, pos);
  6268. pos += baseNumComps;
  6269. }
  6270. }
  6271. if (!isPassthrough) {
  6272. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6273. }
  6274. },
  6275. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6276. alpha01) {
  6277. return this.base.getOutputLength(inputLength *
  6278. this.base.numComps / this.numComps,
  6279. alpha01);
  6280. },
  6281. isPassthrough: ColorSpace.prototype.isPassthrough,
  6282. fillRgb: ColorSpace.prototype.fillRgb,
  6283. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6284. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6285. },
  6286. usesZeroToOneRange: true
  6287. };
  6288. return AlternateCS;
  6289. })();
  6290. var PatternCS = (function PatternCSClosure() {
  6291. function PatternCS(baseCS) {
  6292. this.name = 'Pattern';
  6293. this.base = baseCS;
  6294. }
  6295. PatternCS.prototype = {};
  6296. return PatternCS;
  6297. })();
  6298. var IndexedCS = (function IndexedCSClosure() {
  6299. function IndexedCS(base, highVal, lookup) {
  6300. this.name = 'Indexed';
  6301. this.numComps = 1;
  6302. this.defaultColor = new Uint8Array([0]);
  6303. this.base = base;
  6304. this.highVal = highVal;
  6305. var baseNumComps = base.numComps;
  6306. var length = baseNumComps * highVal;
  6307. var lookupArray;
  6308. if (isStream(lookup)) {
  6309. lookupArray = new Uint8Array(length);
  6310. var bytes = lookup.getBytes(length);
  6311. lookupArray.set(bytes);
  6312. } else if (isString(lookup)) {
  6313. lookupArray = new Uint8Array(length);
  6314. for (var i = 0; i < length; ++i) {
  6315. lookupArray[i] = lookup.charCodeAt(i);
  6316. }
  6317. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6318. lookupArray = lookup;
  6319. } else {
  6320. error('Unrecognized lookup table: ' + lookup);
  6321. }
  6322. this.lookup = lookupArray;
  6323. }
  6324. IndexedCS.prototype = {
  6325. getRgb: ColorSpace.prototype.getRgb,
  6326. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6327. dest, destOffset) {
  6328. var numComps = this.base.numComps;
  6329. var start = src[srcOffset] * numComps;
  6330. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6331. },
  6332. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6333. dest, destOffset, bits,
  6334. alpha01) {
  6335. var base = this.base;
  6336. var numComps = base.numComps;
  6337. var outputDelta = base.getOutputLength(numComps, alpha01);
  6338. var lookup = this.lookup;
  6339. for (var i = 0; i < count; ++i) {
  6340. var lookupPos = src[srcOffset++] * numComps;
  6341. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6342. destOffset += outputDelta;
  6343. }
  6344. },
  6345. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6346. return this.base.getOutputLength(inputLength * this.base.numComps,
  6347. alpha01);
  6348. },
  6349. isPassthrough: ColorSpace.prototype.isPassthrough,
  6350. fillRgb: ColorSpace.prototype.fillRgb,
  6351. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6352. // indexed color maps shouldn't be changed
  6353. return true;
  6354. },
  6355. usesZeroToOneRange: true
  6356. };
  6357. return IndexedCS;
  6358. })();
  6359. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6360. function DeviceGrayCS() {
  6361. this.name = 'DeviceGray';
  6362. this.numComps = 1;
  6363. this.defaultColor = new Float32Array([0]);
  6364. }
  6365. DeviceGrayCS.prototype = {
  6366. getRgb: ColorSpace.prototype.getRgb,
  6367. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6368. dest, destOffset) {
  6369. var c = (src[srcOffset] * 255) | 0;
  6370. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6371. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6372. },
  6373. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6374. dest, destOffset, bits,
  6375. alpha01) {
  6376. var scale = 255 / ((1 << bits) - 1);
  6377. var j = srcOffset, q = destOffset;
  6378. for (var i = 0; i < count; ++i) {
  6379. var c = (scale * src[j++]) | 0;
  6380. dest[q++] = c;
  6381. dest[q++] = c;
  6382. dest[q++] = c;
  6383. q += alpha01;
  6384. }
  6385. },
  6386. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6387. alpha01) {
  6388. return inputLength * (3 + alpha01);
  6389. },
  6390. isPassthrough: ColorSpace.prototype.isPassthrough,
  6391. fillRgb: ColorSpace.prototype.fillRgb,
  6392. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6393. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6394. },
  6395. usesZeroToOneRange: true
  6396. };
  6397. return DeviceGrayCS;
  6398. })();
  6399. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6400. function DeviceRgbCS() {
  6401. this.name = 'DeviceRGB';
  6402. this.numComps = 3;
  6403. this.defaultColor = new Float32Array([0, 0, 0]);
  6404. }
  6405. DeviceRgbCS.prototype = {
  6406. getRgb: ColorSpace.prototype.getRgb,
  6407. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6408. dest, destOffset) {
  6409. var r = (src[srcOffset] * 255) | 0;
  6410. var g = (src[srcOffset + 1] * 255) | 0;
  6411. var b = (src[srcOffset + 2] * 255) | 0;
  6412. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6413. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6414. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6415. },
  6416. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6417. dest, destOffset, bits,
  6418. alpha01) {
  6419. if (bits === 8 && alpha01 === 0) {
  6420. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6421. return;
  6422. }
  6423. var scale = 255 / ((1 << bits) - 1);
  6424. var j = srcOffset, q = destOffset;
  6425. for (var i = 0; i < count; ++i) {
  6426. dest[q++] = (scale * src[j++]) | 0;
  6427. dest[q++] = (scale * src[j++]) | 0;
  6428. dest[q++] = (scale * src[j++]) | 0;
  6429. q += alpha01;
  6430. }
  6431. },
  6432. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6433. alpha01) {
  6434. return (inputLength * (3 + alpha01) / 3) | 0;
  6435. },
  6436. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6437. return bits === 8;
  6438. },
  6439. fillRgb: ColorSpace.prototype.fillRgb,
  6440. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6441. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6442. },
  6443. usesZeroToOneRange: true
  6444. };
  6445. return DeviceRgbCS;
  6446. })();
  6447. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6448. // The coefficients below was found using numerical analysis: the method of
  6449. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6450. // where color_value is the tabular value from the table of sampled RGB colors
  6451. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6452. // CMYK color conversion using the estimation below:
  6453. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6454. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6455. var c = src[srcOffset + 0] * srcScale;
  6456. var m = src[srcOffset + 1] * srcScale;
  6457. var y = src[srcOffset + 2] * srcScale;
  6458. var k = src[srcOffset + 3] * srcScale;
  6459. var r =
  6460. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6461. 18.82290502165302 * y + 212.25662451639585 * k +
  6462. -285.2331026137004) +
  6463. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6464. -17.873870861415444 * k - 5.497006427196366) +
  6465. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6466. 17.5119270841813) +
  6467. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6468. var g =
  6469. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6470. 6.871425592049007 * y + 31.159100130055922 * k +
  6471. -79.2970844816548) +
  6472. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6473. 131.35250912493976 * k - 190.9453302588951) +
  6474. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6475. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6476. var b =
  6477. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6478. 30.89978309703729 * y - 0.23883238689178934 * k +
  6479. -14.183576799673286) +
  6480. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6481. 50.606957656360734 * k - 112.23884253719248) +
  6482. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6483. -193.58209356861505) +
  6484. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6485. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6486. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6487. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6488. }
  6489. function DeviceCmykCS() {
  6490. this.name = 'DeviceCMYK';
  6491. this.numComps = 4;
  6492. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6493. }
  6494. DeviceCmykCS.prototype = {
  6495. getRgb: ColorSpace.prototype.getRgb,
  6496. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6497. dest, destOffset) {
  6498. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6499. },
  6500. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6501. dest, destOffset, bits,
  6502. alpha01) {
  6503. var scale = 1 / ((1 << bits) - 1);
  6504. for (var i = 0; i < count; i++) {
  6505. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6506. srcOffset += 4;
  6507. destOffset += 3 + alpha01;
  6508. }
  6509. },
  6510. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6511. alpha01) {
  6512. return (inputLength / 4 * (3 + alpha01)) | 0;
  6513. },
  6514. isPassthrough: ColorSpace.prototype.isPassthrough,
  6515. fillRgb: ColorSpace.prototype.fillRgb,
  6516. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6517. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6518. },
  6519. usesZeroToOneRange: true
  6520. };
  6521. return DeviceCmykCS;
  6522. })();
  6523. //
  6524. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6525. //
  6526. var CalGrayCS = (function CalGrayCSClosure() {
  6527. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6528. this.name = 'CalGray';
  6529. this.numComps = 1;
  6530. this.defaultColor = new Float32Array([0]);
  6531. if (!whitePoint) {
  6532. error('WhitePoint missing - required for color space CalGray');
  6533. }
  6534. blackPoint = blackPoint || [0, 0, 0];
  6535. gamma = gamma || 1;
  6536. // Translate arguments to spec variables.
  6537. this.XW = whitePoint[0];
  6538. this.YW = whitePoint[1];
  6539. this.ZW = whitePoint[2];
  6540. this.XB = blackPoint[0];
  6541. this.YB = blackPoint[1];
  6542. this.ZB = blackPoint[2];
  6543. this.G = gamma;
  6544. // Validate variables as per spec.
  6545. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6546. error('Invalid WhitePoint components for ' + this.name +
  6547. ', no fallback available');
  6548. }
  6549. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6550. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6551. this.XB = this.YB = this.ZB = 0;
  6552. }
  6553. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6554. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6555. ', ZB: ' + this.ZB + ', only default values are supported.');
  6556. }
  6557. if (this.G < 1) {
  6558. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6559. ', falling back to default');
  6560. this.G = 1;
  6561. }
  6562. }
  6563. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6564. // A represents a gray component of a calibrated gray space.
  6565. // A <---> AG in the spec
  6566. var A = src[srcOffset] * scale;
  6567. var AG = Math.pow(A, cs.G);
  6568. // Computes L as per spec. ( = cs.YW * AG )
  6569. // Except if other than default BlackPoint values are used.
  6570. var L = cs.YW * AG;
  6571. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6572. // Convert values to rgb range [0, 255].
  6573. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6574. dest[destOffset] = val;
  6575. dest[destOffset + 1] = val;
  6576. dest[destOffset + 2] = val;
  6577. }
  6578. CalGrayCS.prototype = {
  6579. getRgb: ColorSpace.prototype.getRgb,
  6580. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6581. dest, destOffset) {
  6582. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6583. },
  6584. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6585. dest, destOffset, bits,
  6586. alpha01) {
  6587. var scale = 1 / ((1 << bits) - 1);
  6588. for (var i = 0; i < count; ++i) {
  6589. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6590. srcOffset += 1;
  6591. destOffset += 3 + alpha01;
  6592. }
  6593. },
  6594. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6595. return inputLength * (3 + alpha01);
  6596. },
  6597. isPassthrough: ColorSpace.prototype.isPassthrough,
  6598. fillRgb: ColorSpace.prototype.fillRgb,
  6599. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6600. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6601. },
  6602. usesZeroToOneRange: true
  6603. };
  6604. return CalGrayCS;
  6605. })();
  6606. //
  6607. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6608. //
  6609. var CalRGBCS = (function CalRGBCSClosure() {
  6610. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6611. // matrices.
  6612. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6613. 0.8951, 0.2664, -0.1614,
  6614. -0.7502, 1.7135, 0.0367,
  6615. 0.0389, -0.0685, 1.0296]);
  6616. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6617. 0.9869929, -0.1470543, 0.1599627,
  6618. 0.4323053, 0.5183603, 0.0492912,
  6619. -0.0085287, 0.0400428, 0.9684867]);
  6620. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6621. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6622. 3.2404542, -1.5371385, -0.4985314,
  6623. -0.9692660, 1.8760108, 0.0415560,
  6624. 0.0556434, -0.2040259, 1.0572252]);
  6625. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6626. var tempNormalizeMatrix = new Float32Array(3);
  6627. var tempConvertMatrix1 = new Float32Array(3);
  6628. var tempConvertMatrix2 = new Float32Array(3);
  6629. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6630. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6631. this.name = 'CalRGB';
  6632. this.numComps = 3;
  6633. this.defaultColor = new Float32Array(3);
  6634. if (!whitePoint) {
  6635. error('WhitePoint missing - required for color space CalRGB');
  6636. }
  6637. blackPoint = blackPoint || new Float32Array(3);
  6638. gamma = gamma || new Float32Array([1, 1, 1]);
  6639. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6640. // Translate arguments to spec variables.
  6641. var XW = whitePoint[0];
  6642. var YW = whitePoint[1];
  6643. var ZW = whitePoint[2];
  6644. this.whitePoint = whitePoint;
  6645. var XB = blackPoint[0];
  6646. var YB = blackPoint[1];
  6647. var ZB = blackPoint[2];
  6648. this.blackPoint = blackPoint;
  6649. this.GR = gamma[0];
  6650. this.GG = gamma[1];
  6651. this.GB = gamma[2];
  6652. this.MXA = matrix[0];
  6653. this.MYA = matrix[1];
  6654. this.MZA = matrix[2];
  6655. this.MXB = matrix[3];
  6656. this.MYB = matrix[4];
  6657. this.MZB = matrix[5];
  6658. this.MXC = matrix[6];
  6659. this.MYC = matrix[7];
  6660. this.MZC = matrix[8];
  6661. // Validate variables as per spec.
  6662. if (XW < 0 || ZW < 0 || YW !== 1) {
  6663. error('Invalid WhitePoint components for ' + this.name +
  6664. ', no fallback available');
  6665. }
  6666. if (XB < 0 || YB < 0 || ZB < 0) {
  6667. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6668. ', ' + ZB + '], falling back to default');
  6669. this.blackPoint = new Float32Array(3);
  6670. }
  6671. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6672. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6673. '] for ' + this.name + ', falling back to default');
  6674. this.GR = this.GG = this.GB = 1;
  6675. }
  6676. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6677. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6678. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6679. info('Invalid Matrix for ' + this.name + ' [' +
  6680. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6681. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6682. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6683. '], falling back to default');
  6684. this.MXA = this.MYB = this.MZC = 1;
  6685. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6686. }
  6687. }
  6688. function matrixProduct(a, b, result) {
  6689. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6690. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6691. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6692. }
  6693. function convertToFlat(sourceWhitePoint, LMS, result) {
  6694. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6695. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6696. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6697. }
  6698. function convertToD65(sourceWhitePoint, LMS, result) {
  6699. var D65X = 0.95047;
  6700. var D65Y = 1;
  6701. var D65Z = 1.08883;
  6702. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6703. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6704. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6705. }
  6706. function sRGBTransferFunction(color) {
  6707. // See http://en.wikipedia.org/wiki/SRGB.
  6708. if (color <= 0.0031308){
  6709. return adjustToRange(0, 1, 12.92 * color);
  6710. }
  6711. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6712. }
  6713. function adjustToRange(min, max, value) {
  6714. return Math.max(min, Math.min(max, value));
  6715. }
  6716. function decodeL(L) {
  6717. if (L < 0) {
  6718. return -decodeL(-L);
  6719. }
  6720. if (L > 8.0) {
  6721. return Math.pow(((L + 16) / 116), 3);
  6722. }
  6723. return L * DECODE_L_CONSTANT;
  6724. }
  6725. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6726. // In case the blackPoint is already the default blackPoint then there is
  6727. // no need to do compensation.
  6728. if (sourceBlackPoint[0] === 0 &&
  6729. sourceBlackPoint[1] === 0 &&
  6730. sourceBlackPoint[2] === 0) {
  6731. result[0] = XYZ_Flat[0];
  6732. result[1] = XYZ_Flat[1];
  6733. result[2] = XYZ_Flat[2];
  6734. return;
  6735. }
  6736. // For the blackPoint calculation details, please see
  6737. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6738. // AdobeBPC.pdf.
  6739. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6740. var zeroDecodeL = decodeL(0);
  6741. var X_DST = zeroDecodeL;
  6742. var X_SRC = decodeL(sourceBlackPoint[0]);
  6743. var Y_DST = zeroDecodeL;
  6744. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6745. var Z_DST = zeroDecodeL;
  6746. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6747. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6748. var X_Offset = 1 - X_Scale;
  6749. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6750. var Y_Offset = 1 - Y_Scale;
  6751. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6752. var Z_Offset = 1 - Z_Scale;
  6753. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6754. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6755. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6756. }
  6757. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6758. // In case the whitePoint is already flat then there is no need to do
  6759. // normalization.
  6760. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6761. result[0] = XYZ_In[0];
  6762. result[1] = XYZ_In[1];
  6763. result[2] = XYZ_In[2];
  6764. return;
  6765. }
  6766. var LMS = result;
  6767. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6768. var LMS_Flat = tempNormalizeMatrix;
  6769. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6770. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6771. }
  6772. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6773. var LMS = result;
  6774. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6775. var LMS_D65 = tempNormalizeMatrix;
  6776. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6777. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6778. }
  6779. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6780. // A, B and C represent a red, green and blue components of a calibrated
  6781. // rgb space.
  6782. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6783. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6784. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6785. // A <---> AGR in the spec
  6786. // B <---> BGG in the spec
  6787. // C <---> CGB in the spec
  6788. var AGR = Math.pow(A, cs.GR);
  6789. var BGG = Math.pow(B, cs.GG);
  6790. var CGB = Math.pow(C, cs.GB);
  6791. // Computes intermediate variables L, M, N as per spec.
  6792. // To decode X, Y, Z values map L, M, N directly to them.
  6793. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6794. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6795. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6796. // The following calculations are based on this document:
  6797. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6798. // AdobeBPC.pdf.
  6799. var XYZ = tempConvertMatrix1;
  6800. XYZ[0] = X;
  6801. XYZ[1] = Y;
  6802. XYZ[2] = Z;
  6803. var XYZ_Flat = tempConvertMatrix2;
  6804. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6805. var XYZ_Black = tempConvertMatrix1;
  6806. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6807. var XYZ_D65 = tempConvertMatrix2;
  6808. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6809. var SRGB = tempConvertMatrix1;
  6810. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6811. var sR = sRGBTransferFunction(SRGB[0]);
  6812. var sG = sRGBTransferFunction(SRGB[1]);
  6813. var sB = sRGBTransferFunction(SRGB[2]);
  6814. // Convert the values to rgb range [0, 255].
  6815. dest[destOffset] = Math.round(sR * 255);
  6816. dest[destOffset + 1] = Math.round(sG * 255);
  6817. dest[destOffset + 2] = Math.round(sB * 255);
  6818. }
  6819. CalRGBCS.prototype = {
  6820. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6821. var rgb = new Uint8Array(3);
  6822. this.getRgbItem(src, srcOffset, rgb, 0);
  6823. return rgb;
  6824. },
  6825. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6826. dest, destOffset) {
  6827. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6828. },
  6829. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6830. dest, destOffset, bits,
  6831. alpha01) {
  6832. var scale = 1 / ((1 << bits) - 1);
  6833. for (var i = 0; i < count; ++i) {
  6834. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6835. srcOffset += 3;
  6836. destOffset += 3 + alpha01;
  6837. }
  6838. },
  6839. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6840. return (inputLength * (3 + alpha01) / 3) | 0;
  6841. },
  6842. isPassthrough: ColorSpace.prototype.isPassthrough,
  6843. fillRgb: ColorSpace.prototype.fillRgb,
  6844. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6845. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6846. },
  6847. usesZeroToOneRange: true
  6848. };
  6849. return CalRGBCS;
  6850. })();
  6851. //
  6852. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6853. //
  6854. var LabCS = (function LabCSClosure() {
  6855. function LabCS(whitePoint, blackPoint, range) {
  6856. this.name = 'Lab';
  6857. this.numComps = 3;
  6858. this.defaultColor = new Float32Array([0, 0, 0]);
  6859. if (!whitePoint) {
  6860. error('WhitePoint missing - required for color space Lab');
  6861. }
  6862. blackPoint = blackPoint || [0, 0, 0];
  6863. range = range || [-100, 100, -100, 100];
  6864. // Translate args to spec variables
  6865. this.XW = whitePoint[0];
  6866. this.YW = whitePoint[1];
  6867. this.ZW = whitePoint[2];
  6868. this.amin = range[0];
  6869. this.amax = range[1];
  6870. this.bmin = range[2];
  6871. this.bmax = range[3];
  6872. // These are here just for completeness - the spec doesn't offer any
  6873. // formulas that use BlackPoint in Lab
  6874. this.XB = blackPoint[0];
  6875. this.YB = blackPoint[1];
  6876. this.ZB = blackPoint[2];
  6877. // Validate vars as per spec
  6878. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6879. error('Invalid WhitePoint components, no fallback available');
  6880. }
  6881. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6882. info('Invalid BlackPoint, falling back to default');
  6883. this.XB = this.YB = this.ZB = 0;
  6884. }
  6885. if (this.amin > this.amax || this.bmin > this.bmax) {
  6886. info('Invalid Range, falling back to defaults');
  6887. this.amin = -100;
  6888. this.amax = 100;
  6889. this.bmin = -100;
  6890. this.bmax = 100;
  6891. }
  6892. }
  6893. // Function g(x) from spec
  6894. function fn_g(x) {
  6895. if (x >= 6 / 29) {
  6896. return x * x * x;
  6897. } else {
  6898. return (108 / 841) * (x - 4 / 29);
  6899. }
  6900. }
  6901. function decode(value, high1, low2, high2) {
  6902. return low2 + (value) * (high2 - low2) / (high1);
  6903. }
  6904. // If decoding is needed maxVal should be 2^bits per component - 1.
  6905. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6906. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6907. // not the usual [0, 1]. If a command like setFillColor is used the src
  6908. // values will already be within the correct range. However, if we are
  6909. // converting an image we have to map the values to the correct range given
  6910. // above.
  6911. // Ls,as,bs <---> L*,a*,b* in the spec
  6912. var Ls = src[srcOffset];
  6913. var as = src[srcOffset + 1];
  6914. var bs = src[srcOffset + 2];
  6915. if (maxVal !== false) {
  6916. Ls = decode(Ls, maxVal, 0, 100);
  6917. as = decode(as, maxVal, cs.amin, cs.amax);
  6918. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6919. }
  6920. // Adjust limits of 'as' and 'bs'
  6921. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6922. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6923. // Computes intermediate variables X,Y,Z as per spec
  6924. var M = (Ls + 16) / 116;
  6925. var L = M + (as / 500);
  6926. var N = M - (bs / 200);
  6927. var X = cs.XW * fn_g(L);
  6928. var Y = cs.YW * fn_g(M);
  6929. var Z = cs.ZW * fn_g(N);
  6930. var r, g, b;
  6931. // Using different conversions for D50 and D65 white points,
  6932. // per http://www.color.org/srgb.pdf
  6933. if (cs.ZW < 1) {
  6934. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6935. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6936. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6937. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6938. } else {
  6939. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6940. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6941. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6942. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6943. }
  6944. // clamp color values to [0,1] range then convert to [0,255] range.
  6945. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6946. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6947. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6948. }
  6949. LabCS.prototype = {
  6950. getRgb: ColorSpace.prototype.getRgb,
  6951. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6952. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6953. },
  6954. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6955. dest, destOffset, bits,
  6956. alpha01) {
  6957. var maxVal = (1 << bits) - 1;
  6958. for (var i = 0; i < count; i++) {
  6959. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6960. srcOffset += 3;
  6961. destOffset += 3 + alpha01;
  6962. }
  6963. },
  6964. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6965. return (inputLength * (3 + alpha01) / 3) | 0;
  6966. },
  6967. isPassthrough: ColorSpace.prototype.isPassthrough,
  6968. fillRgb: ColorSpace.prototype.fillRgb,
  6969. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6970. // XXX: Decoding is handled with the lab conversion because of the strange
  6971. // ranges that are used.
  6972. return true;
  6973. },
  6974. usesZeroToOneRange: false
  6975. };
  6976. return LabCS;
  6977. })();
  6978. var ARCFourCipher = (function ARCFourCipherClosure() {
  6979. function ARCFourCipher(key) {
  6980. this.a = 0;
  6981. this.b = 0;
  6982. var s = new Uint8Array(256);
  6983. var i, j = 0, tmp, keyLength = key.length;
  6984. for (i = 0; i < 256; ++i) {
  6985. s[i] = i;
  6986. }
  6987. for (i = 0; i < 256; ++i) {
  6988. tmp = s[i];
  6989. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6990. s[i] = s[j];
  6991. s[j] = tmp;
  6992. }
  6993. this.s = s;
  6994. }
  6995. ARCFourCipher.prototype = {
  6996. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6997. var i, n = data.length, tmp, tmp2;
  6998. var a = this.a, b = this.b, s = this.s;
  6999. var output = new Uint8Array(n);
  7000. for (i = 0; i < n; ++i) {
  7001. a = (a + 1) & 0xFF;
  7002. tmp = s[a];
  7003. b = (b + tmp) & 0xFF;
  7004. tmp2 = s[b];
  7005. s[a] = tmp2;
  7006. s[b] = tmp;
  7007. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7008. }
  7009. this.a = a;
  7010. this.b = b;
  7011. return output;
  7012. }
  7013. };
  7014. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7015. return ARCFourCipher;
  7016. })();
  7017. var calculateMD5 = (function calculateMD5Closure() {
  7018. var r = new Uint8Array([
  7019. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7020. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7021. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7022. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7023. var k = new Int32Array([
  7024. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7025. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7026. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7027. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7028. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7029. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7030. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7031. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7032. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7033. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7034. -145523070, -1120210379, 718787259, -343485551]);
  7035. function hash(data, offset, length) {
  7036. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7037. // pre-processing
  7038. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7039. var padded = new Uint8Array(paddedLength);
  7040. var i, j, n;
  7041. for (i = 0; i < length; ++i) {
  7042. padded[i] = data[offset++];
  7043. }
  7044. padded[i++] = 0x80;
  7045. n = paddedLength - 8;
  7046. while (i < n) {
  7047. padded[i++] = 0;
  7048. }
  7049. padded[i++] = (length << 3) & 0xFF;
  7050. padded[i++] = (length >> 5) & 0xFF;
  7051. padded[i++] = (length >> 13) & 0xFF;
  7052. padded[i++] = (length >> 21) & 0xFF;
  7053. padded[i++] = (length >>> 29) & 0xFF;
  7054. padded[i++] = 0;
  7055. padded[i++] = 0;
  7056. padded[i++] = 0;
  7057. var w = new Int32Array(16);
  7058. for (i = 0; i < paddedLength;) {
  7059. for (j = 0; j < 16; ++j, i += 4) {
  7060. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7061. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7062. }
  7063. var a = h0, b = h1, c = h2, d = h3, f, g;
  7064. for (j = 0; j < 64; ++j) {
  7065. if (j < 16) {
  7066. f = (b & c) | ((~b) & d);
  7067. g = j;
  7068. } else if (j < 32) {
  7069. f = (d & b) | ((~d) & c);
  7070. g = (5 * j + 1) & 15;
  7071. } else if (j < 48) {
  7072. f = b ^ c ^ d;
  7073. g = (3 * j + 5) & 15;
  7074. } else {
  7075. f = c ^ (b | (~d));
  7076. g = (7 * j) & 15;
  7077. }
  7078. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7079. d = c;
  7080. c = b;
  7081. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7082. a = tmp;
  7083. }
  7084. h0 = (h0 + a) | 0;
  7085. h1 = (h1 + b) | 0;
  7086. h2 = (h2 + c) | 0;
  7087. h3 = (h3 + d) | 0;
  7088. }
  7089. return new Uint8Array([
  7090. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7091. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7092. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7093. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7094. ]);
  7095. }
  7096. return hash;
  7097. })();
  7098. var Word64 = (function Word64Closure() {
  7099. function Word64(highInteger, lowInteger) {
  7100. this.high = highInteger | 0;
  7101. this.low = lowInteger | 0;
  7102. }
  7103. Word64.prototype = {
  7104. and: function Word64_and(word) {
  7105. this.high &= word.high;
  7106. this.low &= word.low;
  7107. },
  7108. xor: function Word64_xor(word) {
  7109. this.high ^= word.high;
  7110. this.low ^= word.low;
  7111. },
  7112. or: function Word64_or(word) {
  7113. this.high |= word.high;
  7114. this.low |= word.low;
  7115. },
  7116. shiftRight: function Word64_shiftRight(places) {
  7117. if (places >= 32) {
  7118. this.low = (this.high >>> (places - 32)) | 0;
  7119. this.high = 0;
  7120. } else {
  7121. this.low = (this.low >>> places) | (this.high << (32 - places));
  7122. this.high = (this.high >>> places) | 0;
  7123. }
  7124. },
  7125. shiftLeft: function Word64_shiftLeft(places) {
  7126. if (places >= 32) {
  7127. this.high = this.low << (places - 32);
  7128. this.low = 0;
  7129. } else {
  7130. this.high = (this.high << places) | (this.low >>> (32 - places));
  7131. this.low = this.low << places;
  7132. }
  7133. },
  7134. rotateRight: function Word64_rotateRight(places) {
  7135. var low, high;
  7136. if (places & 32) {
  7137. high = this.low;
  7138. low = this.high;
  7139. } else {
  7140. low = this.low;
  7141. high = this.high;
  7142. }
  7143. places &= 31;
  7144. this.low = (low >>> places) | (high << (32 - places));
  7145. this.high = (high >>> places) | (low << (32 - places));
  7146. },
  7147. not: function Word64_not() {
  7148. this.high = ~this.high;
  7149. this.low = ~this.low;
  7150. },
  7151. add: function Word64_add(word) {
  7152. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7153. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7154. if (lowAdd > 0xFFFFFFFF) {
  7155. highAdd += 1;
  7156. }
  7157. this.low = lowAdd | 0;
  7158. this.high = highAdd | 0;
  7159. },
  7160. copyTo: function Word64_copyTo(bytes, offset) {
  7161. bytes[offset] = (this.high >>> 24) & 0xFF;
  7162. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7163. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7164. bytes[offset + 3] = this.high & 0xFF;
  7165. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7166. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7167. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7168. bytes[offset + 7] = this.low & 0xFF;
  7169. },
  7170. assign: function Word64_assign(word) {
  7171. this.high = word.high;
  7172. this.low = word.low;
  7173. }
  7174. };
  7175. return Word64;
  7176. })();
  7177. var calculateSHA256 = (function calculateSHA256Closure() {
  7178. function rotr(x, n) {
  7179. return (x >>> n) | (x << 32 - n);
  7180. }
  7181. function ch(x, y, z) {
  7182. return (x & y) ^ (~x & z);
  7183. }
  7184. function maj(x, y, z) {
  7185. return (x & y) ^ (x & z) ^ (y & z);
  7186. }
  7187. function sigma(x) {
  7188. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7189. }
  7190. function sigmaPrime(x) {
  7191. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7192. }
  7193. function littleSigma(x) {
  7194. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7195. }
  7196. function littleSigmaPrime(x) {
  7197. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7198. }
  7199. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7200. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7201. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7202. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7203. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7204. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7205. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7206. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7207. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7208. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7209. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7210. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7211. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7212. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7213. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7214. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7215. function hash(data, offset, length) {
  7216. // initial hash values
  7217. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7218. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7219. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7220. // pre-processing
  7221. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7222. var padded = new Uint8Array(paddedLength);
  7223. var i, j, n;
  7224. for (i = 0; i < length; ++i) {
  7225. padded[i] = data[offset++];
  7226. }
  7227. padded[i++] = 0x80;
  7228. n = paddedLength - 8;
  7229. while (i < n) {
  7230. padded[i++] = 0;
  7231. }
  7232. padded[i++] = 0;
  7233. padded[i++] = 0;
  7234. padded[i++] = 0;
  7235. padded[i++] = (length >>> 29) & 0xFF;
  7236. padded[i++] = (length >> 21) & 0xFF;
  7237. padded[i++] = (length >> 13) & 0xFF;
  7238. padded[i++] = (length >> 5) & 0xFF;
  7239. padded[i++] = (length << 3) & 0xFF;
  7240. var w = new Uint32Array(64);
  7241. // for each 512 bit block
  7242. for (i = 0; i < paddedLength;) {
  7243. for (j = 0; j < 16; ++j) {
  7244. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7245. (padded[i + 2] << 8) | (padded[i + 3]));
  7246. i += 4;
  7247. }
  7248. for (j = 16; j < 64; ++j) {
  7249. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7250. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7251. }
  7252. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7253. f = h5, g = h6, h = h7, t1, t2;
  7254. for (j = 0; j < 64; ++j) {
  7255. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7256. t2 = sigma(a) + maj(a, b, c);
  7257. h = g;
  7258. g = f;
  7259. f = e;
  7260. e = (d + t1) | 0;
  7261. d = c;
  7262. c = b;
  7263. b = a;
  7264. a = (t1 + t2) | 0;
  7265. }
  7266. h0 = (h0 + a) | 0;
  7267. h1 = (h1 + b) | 0;
  7268. h2 = (h2 + c) | 0;
  7269. h3 = (h3 + d) | 0;
  7270. h4 = (h4 + e) | 0;
  7271. h5 = (h5 + f) | 0;
  7272. h6 = (h6 + g) | 0;
  7273. h7 = (h7 + h) | 0;
  7274. }
  7275. return new Uint8Array([
  7276. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7277. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7278. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7279. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7280. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7281. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7282. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7283. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7284. ]);
  7285. }
  7286. return hash;
  7287. })();
  7288. var calculateSHA512 = (function calculateSHA512Closure() {
  7289. function ch(result, x, y, z, tmp) {
  7290. result.assign(x);
  7291. result.and(y);
  7292. tmp.assign(x);
  7293. tmp.not();
  7294. tmp.and(z);
  7295. result.xor(tmp);
  7296. }
  7297. function maj(result, x, y, z, tmp) {
  7298. result.assign(x);
  7299. result.and(y);
  7300. tmp.assign(x);
  7301. tmp.and(z);
  7302. result.xor(tmp);
  7303. tmp.assign(y);
  7304. tmp.and(z);
  7305. result.xor(tmp);
  7306. }
  7307. function sigma(result, x, tmp) {
  7308. result.assign(x);
  7309. result.rotateRight(28);
  7310. tmp.assign(x);
  7311. tmp.rotateRight(34);
  7312. result.xor(tmp);
  7313. tmp.assign(x);
  7314. tmp.rotateRight(39);
  7315. result.xor(tmp);
  7316. }
  7317. function sigmaPrime(result, x, tmp) {
  7318. result.assign(x);
  7319. result.rotateRight(14);
  7320. tmp.assign(x);
  7321. tmp.rotateRight(18);
  7322. result.xor(tmp);
  7323. tmp.assign(x);
  7324. tmp.rotateRight(41);
  7325. result.xor(tmp);
  7326. }
  7327. function littleSigma(result, x, tmp) {
  7328. result.assign(x);
  7329. result.rotateRight(1);
  7330. tmp.assign(x);
  7331. tmp.rotateRight(8);
  7332. result.xor(tmp);
  7333. tmp.assign(x);
  7334. tmp.shiftRight(7);
  7335. result.xor(tmp);
  7336. }
  7337. function littleSigmaPrime(result, x, tmp) {
  7338. result.assign(x);
  7339. result.rotateRight(19);
  7340. tmp.assign(x);
  7341. tmp.rotateRight(61);
  7342. result.xor(tmp);
  7343. tmp.assign(x);
  7344. tmp.shiftRight(6);
  7345. result.xor(tmp);
  7346. }
  7347. var k = [
  7348. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7349. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7350. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7351. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7352. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7353. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7354. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7355. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7356. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7357. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7358. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7359. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7360. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7361. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7362. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7363. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7364. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7365. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7366. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7367. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7368. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7369. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7370. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7371. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7372. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7373. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7374. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7375. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7376. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7377. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7378. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7379. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7380. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7381. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7382. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7383. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7384. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7385. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7386. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7387. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7388. function hash(data, offset, length, mode384) {
  7389. mode384 = !!mode384;
  7390. // initial hash values
  7391. var h0, h1, h2, h3, h4, h5, h6, h7;
  7392. if (!mode384) {
  7393. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7394. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7395. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7396. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7397. h4 = new Word64(0x510e527f, 0xade682d1);
  7398. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7399. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7400. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7401. }
  7402. else {
  7403. // SHA384 is exactly the same
  7404. // except with different starting values and a trimmed result
  7405. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7406. h1 = new Word64(0x629a292a, 0x367cd507);
  7407. h2 = new Word64(0x9159015a, 0x3070dd17);
  7408. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7409. h4 = new Word64(0x67332667, 0xffc00b31);
  7410. h5 = new Word64(0x8eb44a87, 0x68581511);
  7411. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7412. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7413. }
  7414. // pre-processing
  7415. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7416. var padded = new Uint8Array(paddedLength);
  7417. var i, j, n;
  7418. for (i = 0; i < length; ++i) {
  7419. padded[i] = data[offset++];
  7420. }
  7421. padded[i++] = 0x80;
  7422. n = paddedLength - 16;
  7423. while (i < n) {
  7424. padded[i++] = 0;
  7425. }
  7426. padded[i++] = 0;
  7427. padded[i++] = 0;
  7428. padded[i++] = 0;
  7429. padded[i++] = 0;
  7430. padded[i++] = 0;
  7431. padded[i++] = 0;
  7432. padded[i++] = 0;
  7433. padded[i++] = 0;
  7434. padded[i++] = 0;
  7435. padded[i++] = 0;
  7436. padded[i++] = 0;
  7437. padded[i++] = (length >>> 29) & 0xFF;
  7438. padded[i++] = (length >> 21) & 0xFF;
  7439. padded[i++] = (length >> 13) & 0xFF;
  7440. padded[i++] = (length >> 5) & 0xFF;
  7441. padded[i++] = (length << 3) & 0xFF;
  7442. var w = new Array(80);
  7443. for (i = 0; i < 80; i++) {
  7444. w[i] = new Word64(0, 0);
  7445. }
  7446. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7447. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7448. var g = new Word64(0, 0), h = new Word64(0, 0);
  7449. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7450. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7451. // for each 1024 bit block
  7452. for (i = 0; i < paddedLength;) {
  7453. for (j = 0; j < 16; ++j) {
  7454. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7455. (padded[i + 2] << 8) | (padded[i + 3]);
  7456. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7457. (padded[i + 6]) << 8 | (padded[i + 7]);
  7458. i += 8;
  7459. }
  7460. for (j = 16; j < 80; ++j) {
  7461. tmp3 = w[j];
  7462. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7463. tmp3.add(w[j - 7]);
  7464. littleSigma(tmp1, w[j - 15], tmp2);
  7465. tmp3.add(tmp1);
  7466. tmp3.add(w[j - 16]);
  7467. }
  7468. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7469. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7470. for (j = 0; j < 80; ++j) {
  7471. t1.assign(h);
  7472. sigmaPrime(tmp1, e, tmp2);
  7473. t1.add(tmp1);
  7474. ch(tmp1, e, f, g, tmp2);
  7475. t1.add(tmp1);
  7476. t1.add(k[j]);
  7477. t1.add(w[j]);
  7478. sigma(t2, a, tmp2);
  7479. maj(tmp1, a, b, c, tmp2);
  7480. t2.add(tmp1);
  7481. tmp3 = h;
  7482. h = g;
  7483. g = f;
  7484. f = e;
  7485. d.add(t1);
  7486. e = d;
  7487. d = c;
  7488. c = b;
  7489. b = a;
  7490. tmp3.assign(t1);
  7491. tmp3.add(t2);
  7492. a = tmp3;
  7493. }
  7494. h0.add(a);
  7495. h1.add(b);
  7496. h2.add(c);
  7497. h3.add(d);
  7498. h4.add(e);
  7499. h5.add(f);
  7500. h6.add(g);
  7501. h7.add(h);
  7502. }
  7503. var result;
  7504. if (!mode384) {
  7505. result = new Uint8Array(64);
  7506. h0.copyTo(result,0);
  7507. h1.copyTo(result,8);
  7508. h2.copyTo(result,16);
  7509. h3.copyTo(result,24);
  7510. h4.copyTo(result,32);
  7511. h5.copyTo(result,40);
  7512. h6.copyTo(result,48);
  7513. h7.copyTo(result,56);
  7514. }
  7515. else {
  7516. result = new Uint8Array(48);
  7517. h0.copyTo(result,0);
  7518. h1.copyTo(result,8);
  7519. h2.copyTo(result,16);
  7520. h3.copyTo(result,24);
  7521. h4.copyTo(result,32);
  7522. h5.copyTo(result,40);
  7523. }
  7524. return result;
  7525. }
  7526. return hash;
  7527. })();
  7528. var calculateSHA384 = (function calculateSHA384Closure() {
  7529. function hash(data, offset, length) {
  7530. return calculateSHA512(data, offset, length, true);
  7531. }
  7532. return hash;
  7533. })();
  7534. var NullCipher = (function NullCipherClosure() {
  7535. function NullCipher() {
  7536. }
  7537. NullCipher.prototype = {
  7538. decryptBlock: function NullCipher_decryptBlock(data) {
  7539. return data;
  7540. }
  7541. };
  7542. return NullCipher;
  7543. })();
  7544. var AES128Cipher = (function AES128CipherClosure() {
  7545. var rcon = new Uint8Array([
  7546. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7547. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7548. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7549. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7550. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7551. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7552. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7553. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7554. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7555. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7556. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7557. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7558. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7559. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7560. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7561. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7562. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7563. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7564. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7565. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7566. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7567. 0x74, 0xe8, 0xcb, 0x8d]);
  7568. var s = new Uint8Array([
  7569. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7570. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7571. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7572. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7573. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7574. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7575. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7576. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7577. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7578. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7579. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7580. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7581. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7582. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7583. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7584. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7585. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7586. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7587. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7588. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7589. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7590. 0xb0, 0x54, 0xbb, 0x16]);
  7591. var inv_s = new Uint8Array([
  7592. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7593. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7594. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7595. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7596. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7597. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7598. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7599. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7600. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7601. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7602. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7603. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7604. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7605. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7606. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7607. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7608. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7609. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7610. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7611. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7612. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7613. 0x55, 0x21, 0x0c, 0x7d]);
  7614. var mixCol = new Uint8Array(256);
  7615. for (var i = 0; i < 256; i++) {
  7616. if (i < 128) {
  7617. mixCol[i] = i << 1;
  7618. } else {
  7619. mixCol[i] = (i << 1) ^ 0x1b;
  7620. }
  7621. }
  7622. var mix = new Uint32Array([
  7623. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7624. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7625. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7626. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7627. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7628. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7629. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7630. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7631. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7632. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7633. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7634. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7635. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7636. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7637. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7638. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7639. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7640. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7641. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7642. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7643. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7644. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7645. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7646. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7647. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7648. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7649. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7650. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7651. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7652. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7653. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7654. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7655. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7656. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7657. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7658. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7659. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7660. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7661. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7662. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7663. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7664. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7665. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7666. function expandKey128(cipherKey) {
  7667. var b = 176, result = new Uint8Array(b);
  7668. result.set(cipherKey);
  7669. for (var j = 16, i = 1; j < b; ++i) {
  7670. // RotWord
  7671. var t1 = result[j - 3], t2 = result[j - 2],
  7672. t3 = result[j - 1], t4 = result[j - 4];
  7673. // SubWord
  7674. t1 = s[t1];
  7675. t2 = s[t2];
  7676. t3 = s[t3];
  7677. t4 = s[t4];
  7678. // Rcon
  7679. t1 = t1 ^ rcon[i];
  7680. for (var n = 0; n < 4; ++n) {
  7681. result[j] = (t1 ^= result[j - 16]);
  7682. j++;
  7683. result[j] = (t2 ^= result[j - 16]);
  7684. j++;
  7685. result[j] = (t3 ^= result[j - 16]);
  7686. j++;
  7687. result[j] = (t4 ^= result[j - 16]);
  7688. j++;
  7689. }
  7690. }
  7691. return result;
  7692. }
  7693. function decrypt128(input, key) {
  7694. var state = new Uint8Array(16);
  7695. state.set(input);
  7696. var i, j, k;
  7697. var t, u, v;
  7698. // AddRoundKey
  7699. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7700. state[j] ^= key[k];
  7701. }
  7702. for (i = 9; i >= 1; --i) {
  7703. // InvShiftRows
  7704. t = state[13];
  7705. state[13] = state[9];
  7706. state[9] = state[5];
  7707. state[5] = state[1];
  7708. state[1] = t;
  7709. t = state[14];
  7710. u = state[10];
  7711. state[14] = state[6];
  7712. state[10] = state[2];
  7713. state[6] = t;
  7714. state[2] = u;
  7715. t = state[15];
  7716. u = state[11];
  7717. v = state[7];
  7718. state[15] = state[3];
  7719. state[11] = t;
  7720. state[7] = u;
  7721. state[3] = v;
  7722. // InvSubBytes
  7723. for (j = 0; j < 16; ++j) {
  7724. state[j] = inv_s[state[j]];
  7725. }
  7726. // AddRoundKey
  7727. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7728. state[j] ^= key[k];
  7729. }
  7730. // InvMixColumns
  7731. for (j = 0; j < 16; j += 4) {
  7732. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7733. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7734. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7735. (s3 >>> 24) ^ (s3 << 8));
  7736. state[j] = (t >>> 24) & 0xFF;
  7737. state[j + 1] = (t >> 16) & 0xFF;
  7738. state[j + 2] = (t >> 8) & 0xFF;
  7739. state[j + 3] = t & 0xFF;
  7740. }
  7741. }
  7742. // InvShiftRows
  7743. t = state[13];
  7744. state[13] = state[9];
  7745. state[9] = state[5];
  7746. state[5] = state[1];
  7747. state[1] = t;
  7748. t = state[14];
  7749. u = state[10];
  7750. state[14] = state[6];
  7751. state[10] = state[2];
  7752. state[6] = t;
  7753. state[2] = u;
  7754. t = state[15];
  7755. u = state[11];
  7756. v = state[7];
  7757. state[15] = state[3];
  7758. state[11] = t;
  7759. state[7] = u;
  7760. state[3] = v;
  7761. for (j = 0; j < 16; ++j) {
  7762. // InvSubBytes
  7763. state[j] = inv_s[state[j]];
  7764. // AddRoundKey
  7765. state[j] ^= key[j];
  7766. }
  7767. return state;
  7768. }
  7769. function encrypt128(input, key) {
  7770. var t, u, v, k;
  7771. var state = new Uint8Array(16);
  7772. state.set(input);
  7773. for (j = 0; j < 16; ++j) {
  7774. // AddRoundKey
  7775. state[j] ^= key[j];
  7776. }
  7777. for (i = 1; i < 10; i++) {
  7778. //SubBytes
  7779. for (j = 0; j < 16; ++j) {
  7780. state[j] = s[state[j]];
  7781. }
  7782. //ShiftRows
  7783. v = state[1];
  7784. state[1] = state[5];
  7785. state[5] = state[9];
  7786. state[9] = state[13];
  7787. state[13] = v;
  7788. v = state[2];
  7789. u = state[6];
  7790. state[2] = state[10];
  7791. state[6] = state[14];
  7792. state[10] = v;
  7793. state[14] = u;
  7794. v = state[3];
  7795. u = state[7];
  7796. t = state[11];
  7797. state[3] = state[15];
  7798. state[7] = v;
  7799. state[11] = u;
  7800. state[15] = t;
  7801. //MixColumns
  7802. for (var j = 0; j < 16; j += 4) {
  7803. var s0 = state[j + 0], s1 = state[j + 1];
  7804. var s2 = state[j + 2], s3 = state[j + 3];
  7805. t = s0 ^ s1 ^ s2 ^ s3;
  7806. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7807. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7808. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7809. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7810. }
  7811. //AddRoundKey
  7812. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7813. state[j] ^= key[k];
  7814. }
  7815. }
  7816. //SubBytes
  7817. for (j = 0; j < 16; ++j) {
  7818. state[j] = s[state[j]];
  7819. }
  7820. //ShiftRows
  7821. v = state[1];
  7822. state[1] = state[5];
  7823. state[5] = state[9];
  7824. state[9] = state[13];
  7825. state[13] = v;
  7826. v = state[2];
  7827. u = state[6];
  7828. state[2] = state[10];
  7829. state[6] = state[14];
  7830. state[10] = v;
  7831. state[14] = u;
  7832. v = state[3];
  7833. u = state[7];
  7834. t = state[11];
  7835. state[3] = state[15];
  7836. state[7] = v;
  7837. state[11] = u;
  7838. state[15] = t;
  7839. //AddRoundKey
  7840. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7841. state[j] ^= key[k];
  7842. }
  7843. return state;
  7844. }
  7845. function AES128Cipher(key) {
  7846. this.key = expandKey128(key);
  7847. this.buffer = new Uint8Array(16);
  7848. this.bufferPosition = 0;
  7849. }
  7850. function decryptBlock2(data, finalize) {
  7851. var i, j, ii, sourceLength = data.length,
  7852. buffer = this.buffer, bufferLength = this.bufferPosition,
  7853. result = [], iv = this.iv;
  7854. for (i = 0; i < sourceLength; ++i) {
  7855. buffer[bufferLength] = data[i];
  7856. ++bufferLength;
  7857. if (bufferLength < 16) {
  7858. continue;
  7859. }
  7860. // buffer is full, decrypting
  7861. var plain = decrypt128(buffer, this.key);
  7862. // xor-ing the IV vector to get plain text
  7863. for (j = 0; j < 16; ++j) {
  7864. plain[j] ^= iv[j];
  7865. }
  7866. iv = buffer;
  7867. result.push(plain);
  7868. buffer = new Uint8Array(16);
  7869. bufferLength = 0;
  7870. }
  7871. // saving incomplete buffer
  7872. this.buffer = buffer;
  7873. this.bufferLength = bufferLength;
  7874. this.iv = iv;
  7875. if (result.length === 0) {
  7876. return new Uint8Array([]);
  7877. }
  7878. // combining plain text blocks into one
  7879. var outputLength = 16 * result.length;
  7880. if (finalize) {
  7881. // undo a padding that is described in RFC 2898
  7882. var lastBlock = result[result.length - 1];
  7883. var psLen = lastBlock[15];
  7884. if (psLen <= 16) {
  7885. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7886. if (lastBlock[i] !== psLen) {
  7887. // Invalid padding, assume that the block has no padding.
  7888. psLen = 0;
  7889. break;
  7890. }
  7891. }
  7892. outputLength -= psLen;
  7893. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7894. }
  7895. }
  7896. var output = new Uint8Array(outputLength);
  7897. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7898. output.set(result[i], j);
  7899. }
  7900. return output;
  7901. }
  7902. AES128Cipher.prototype = {
  7903. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7904. var i, sourceLength = data.length;
  7905. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7906. // waiting for IV values -- they are at the start of the stream
  7907. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7908. buffer[bufferLength] = data[i];
  7909. }
  7910. if (bufferLength < 16) {
  7911. // need more data
  7912. this.bufferLength = bufferLength;
  7913. return new Uint8Array([]);
  7914. }
  7915. this.iv = buffer;
  7916. this.buffer = new Uint8Array(16);
  7917. this.bufferLength = 0;
  7918. // starting decryption
  7919. this.decryptBlock = decryptBlock2;
  7920. return this.decryptBlock(data.subarray(16), finalize);
  7921. },
  7922. encrypt: function AES128Cipher_encrypt(data, iv) {
  7923. var i, j, ii, sourceLength = data.length,
  7924. buffer = this.buffer, bufferLength = this.bufferPosition,
  7925. result = [];
  7926. if (!iv) {
  7927. iv = new Uint8Array(16);
  7928. }
  7929. for (i = 0; i < sourceLength; ++i) {
  7930. buffer[bufferLength] = data[i];
  7931. ++bufferLength;
  7932. if (bufferLength < 16) {
  7933. continue;
  7934. }
  7935. for (j = 0; j < 16; ++j) {
  7936. buffer[j] ^= iv[j];
  7937. }
  7938. // buffer is full, encrypting
  7939. var cipher = encrypt128(buffer, this.key);
  7940. iv = cipher;
  7941. result.push(cipher);
  7942. buffer = new Uint8Array(16);
  7943. bufferLength = 0;
  7944. }
  7945. // saving incomplete buffer
  7946. this.buffer = buffer;
  7947. this.bufferLength = bufferLength;
  7948. this.iv = iv;
  7949. if (result.length === 0) {
  7950. return new Uint8Array([]);
  7951. }
  7952. // combining plain text blocks into one
  7953. var outputLength = 16 * result.length;
  7954. var output = new Uint8Array(outputLength);
  7955. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7956. output.set(result[i], j);
  7957. }
  7958. return output;
  7959. }
  7960. };
  7961. return AES128Cipher;
  7962. })();
  7963. var AES256Cipher = (function AES256CipherClosure() {
  7964. var rcon = new Uint8Array([
  7965. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7966. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7967. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7968. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7969. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7970. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7971. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7972. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7973. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7974. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7975. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7976. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7977. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7978. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7979. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7980. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7981. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7982. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7983. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7984. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7985. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7986. 0x74, 0xe8, 0xcb, 0x8d]);
  7987. var s = new Uint8Array([
  7988. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7989. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7990. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7991. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7992. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7993. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7994. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7995. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7996. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7997. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7998. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7999. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8000. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8001. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8002. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8003. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8004. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8005. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8006. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8007. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8008. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8009. 0xb0, 0x54, 0xbb, 0x16]);
  8010. var inv_s = new Uint8Array([
  8011. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8012. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8013. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8014. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8015. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8016. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8017. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8018. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8019. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8020. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8021. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8022. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8023. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8024. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8025. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8026. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8027. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8028. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8029. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8030. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8031. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8032. 0x55, 0x21, 0x0c, 0x7d]);
  8033. var mixCol = new Uint8Array(256);
  8034. for (var i = 0; i < 256; i++) {
  8035. if (i < 128) {
  8036. mixCol[i] = i << 1;
  8037. } else {
  8038. mixCol[i] = (i << 1) ^ 0x1b;
  8039. }
  8040. }
  8041. var mix = new Uint32Array([
  8042. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8043. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8044. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8045. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8046. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8047. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8048. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8049. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8050. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8051. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8052. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8053. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8054. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8055. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8056. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8057. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8058. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8059. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8060. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8061. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8062. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8063. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8064. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8065. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8066. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8067. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8068. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8069. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8070. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8071. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8072. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8073. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8074. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8075. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8076. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8077. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8078. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8079. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8080. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8081. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8082. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8083. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8084. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8085. function expandKey256(cipherKey) {
  8086. var b = 240, result = new Uint8Array(b);
  8087. var r = 1;
  8088. result.set(cipherKey);
  8089. for (var j = 32, i = 1; j < b; ++i) {
  8090. if (j % 32 === 16) {
  8091. t1 = s[t1];
  8092. t2 = s[t2];
  8093. t3 = s[t3];
  8094. t4 = s[t4];
  8095. } else if (j % 32 === 0) {
  8096. // RotWord
  8097. var t1 = result[j - 3], t2 = result[j - 2],
  8098. t3 = result[j - 1], t4 = result[j - 4];
  8099. // SubWord
  8100. t1 = s[t1];
  8101. t2 = s[t2];
  8102. t3 = s[t3];
  8103. t4 = s[t4];
  8104. // Rcon
  8105. t1 = t1 ^ r;
  8106. if ((r <<= 1) >= 256) {
  8107. r = (r ^ 0x1b) & 0xFF;
  8108. }
  8109. }
  8110. for (var n = 0; n < 4; ++n) {
  8111. result[j] = (t1 ^= result[j - 32]);
  8112. j++;
  8113. result[j] = (t2 ^= result[j - 32]);
  8114. j++;
  8115. result[j] = (t3 ^= result[j - 32]);
  8116. j++;
  8117. result[j] = (t4 ^= result[j - 32]);
  8118. j++;
  8119. }
  8120. }
  8121. return result;
  8122. }
  8123. function decrypt256(input, key) {
  8124. var state = new Uint8Array(16);
  8125. state.set(input);
  8126. var i, j, k;
  8127. var t, u, v;
  8128. // AddRoundKey
  8129. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8130. state[j] ^= key[k];
  8131. }
  8132. for (i = 13; i >= 1; --i) {
  8133. // InvShiftRows
  8134. t = state[13];
  8135. state[13] = state[9];
  8136. state[9] = state[5];
  8137. state[5] = state[1];
  8138. state[1] = t;
  8139. t = state[14];
  8140. u = state[10];
  8141. state[14] = state[6];
  8142. state[10] = state[2];
  8143. state[6] = t;
  8144. state[2] = u;
  8145. t = state[15];
  8146. u = state[11];
  8147. v = state[7];
  8148. state[15] = state[3];
  8149. state[11] = t;
  8150. state[7] = u;
  8151. state[3] = v;
  8152. // InvSubBytes
  8153. for (j = 0; j < 16; ++j) {
  8154. state[j] = inv_s[state[j]];
  8155. }
  8156. // AddRoundKey
  8157. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8158. state[j] ^= key[k];
  8159. }
  8160. // InvMixColumns
  8161. for (j = 0; j < 16; j += 4) {
  8162. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8163. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8164. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8165. (s3 >>> 24) ^ (s3 << 8));
  8166. state[j] = (t >>> 24) & 0xFF;
  8167. state[j + 1] = (t >> 16) & 0xFF;
  8168. state[j + 2] = (t >> 8) & 0xFF;
  8169. state[j + 3] = t & 0xFF;
  8170. }
  8171. }
  8172. // InvShiftRows
  8173. t = state[13];
  8174. state[13] = state[9];
  8175. state[9] = state[5];
  8176. state[5] = state[1];
  8177. state[1] = t;
  8178. t = state[14];
  8179. u = state[10];
  8180. state[14] = state[6];
  8181. state[10] = state[2];
  8182. state[6] = t;
  8183. state[2] = u;
  8184. t = state[15];
  8185. u = state[11];
  8186. v = state[7];
  8187. state[15] = state[3];
  8188. state[11] = t;
  8189. state[7] = u;
  8190. state[3] = v;
  8191. for (j = 0; j < 16; ++j) {
  8192. // InvSubBytes
  8193. state[j] = inv_s[state[j]];
  8194. // AddRoundKey
  8195. state[j] ^= key[j];
  8196. }
  8197. return state;
  8198. }
  8199. function encrypt256(input, key) {
  8200. var t, u, v, k;
  8201. var state = new Uint8Array(16);
  8202. state.set(input);
  8203. for (j = 0; j < 16; ++j) {
  8204. // AddRoundKey
  8205. state[j] ^= key[j];
  8206. }
  8207. for (i = 1; i < 14; i++) {
  8208. //SubBytes
  8209. for (j = 0; j < 16; ++j) {
  8210. state[j] = s[state[j]];
  8211. }
  8212. //ShiftRows
  8213. v = state[1];
  8214. state[1] = state[5];
  8215. state[5] = state[9];
  8216. state[9] = state[13];
  8217. state[13] = v;
  8218. v = state[2];
  8219. u = state[6];
  8220. state[2] = state[10];
  8221. state[6] = state[14];
  8222. state[10] = v;
  8223. state[14] = u;
  8224. v = state[3];
  8225. u = state[7];
  8226. t = state[11];
  8227. state[3] = state[15];
  8228. state[7] = v;
  8229. state[11] = u;
  8230. state[15] = t;
  8231. //MixColumns
  8232. for (var j = 0; j < 16; j += 4) {
  8233. var s0 = state[j + 0], s1 = state[j + 1];
  8234. var s2 = state[j + 2], s3 = state[j + 3];
  8235. t = s0 ^ s1 ^ s2 ^ s3;
  8236. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8237. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8238. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8239. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8240. }
  8241. //AddRoundKey
  8242. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8243. state[j] ^= key[k];
  8244. }
  8245. }
  8246. //SubBytes
  8247. for (j = 0; j < 16; ++j) {
  8248. state[j] = s[state[j]];
  8249. }
  8250. //ShiftRows
  8251. v = state[1];
  8252. state[1] = state[5];
  8253. state[5] = state[9];
  8254. state[9] = state[13];
  8255. state[13] = v;
  8256. v = state[2];
  8257. u = state[6];
  8258. state[2] = state[10];
  8259. state[6] = state[14];
  8260. state[10] = v;
  8261. state[14] = u;
  8262. v = state[3];
  8263. u = state[7];
  8264. t = state[11];
  8265. state[3] = state[15];
  8266. state[7] = v;
  8267. state[11] = u;
  8268. state[15] = t;
  8269. //AddRoundKey
  8270. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8271. state[j] ^= key[k];
  8272. }
  8273. return state;
  8274. }
  8275. function AES256Cipher(key) {
  8276. this.key = expandKey256(key);
  8277. this.buffer = new Uint8Array(16);
  8278. this.bufferPosition = 0;
  8279. }
  8280. function decryptBlock2(data, finalize) {
  8281. var i, j, ii, sourceLength = data.length,
  8282. buffer = this.buffer, bufferLength = this.bufferPosition,
  8283. result = [], iv = this.iv;
  8284. for (i = 0; i < sourceLength; ++i) {
  8285. buffer[bufferLength] = data[i];
  8286. ++bufferLength;
  8287. if (bufferLength < 16) {
  8288. continue;
  8289. }
  8290. // buffer is full, decrypting
  8291. var plain = decrypt256(buffer, this.key);
  8292. // xor-ing the IV vector to get plain text
  8293. for (j = 0; j < 16; ++j) {
  8294. plain[j] ^= iv[j];
  8295. }
  8296. iv = buffer;
  8297. result.push(plain);
  8298. buffer = new Uint8Array(16);
  8299. bufferLength = 0;
  8300. }
  8301. // saving incomplete buffer
  8302. this.buffer = buffer;
  8303. this.bufferLength = bufferLength;
  8304. this.iv = iv;
  8305. if (result.length === 0) {
  8306. return new Uint8Array([]);
  8307. }
  8308. // combining plain text blocks into one
  8309. var outputLength = 16 * result.length;
  8310. if (finalize) {
  8311. // undo a padding that is described in RFC 2898
  8312. var lastBlock = result[result.length - 1];
  8313. var psLen = lastBlock[15];
  8314. if (psLen <= 16) {
  8315. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8316. if (lastBlock[i] !== psLen) {
  8317. // Invalid padding, assume that the block has no padding.
  8318. psLen = 0;
  8319. break;
  8320. }
  8321. }
  8322. outputLength -= psLen;
  8323. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8324. }
  8325. }
  8326. var output = new Uint8Array(outputLength);
  8327. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8328. output.set(result[i], j);
  8329. }
  8330. return output;
  8331. }
  8332. AES256Cipher.prototype = {
  8333. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8334. var i, sourceLength = data.length;
  8335. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8336. // if not supplied an IV wait for IV values
  8337. // they are at the start of the stream
  8338. if (iv) {
  8339. this.iv = iv;
  8340. } else {
  8341. for (i = 0; bufferLength < 16 &&
  8342. i < sourceLength; ++i, ++bufferLength) {
  8343. buffer[bufferLength] = data[i];
  8344. }
  8345. if (bufferLength < 16) {
  8346. //need more data
  8347. this.bufferLength = bufferLength;
  8348. return new Uint8Array([]);
  8349. }
  8350. this.iv = buffer;
  8351. data = data.subarray(16);
  8352. }
  8353. this.buffer = new Uint8Array(16);
  8354. this.bufferLength = 0;
  8355. // starting decryption
  8356. this.decryptBlock = decryptBlock2;
  8357. return this.decryptBlock(data, finalize);
  8358. },
  8359. encrypt: function AES256Cipher_encrypt(data, iv) {
  8360. var i, j, ii, sourceLength = data.length,
  8361. buffer = this.buffer, bufferLength = this.bufferPosition,
  8362. result = [];
  8363. if (!iv) {
  8364. iv = new Uint8Array(16);
  8365. }
  8366. for (i = 0; i < sourceLength; ++i) {
  8367. buffer[bufferLength] = data[i];
  8368. ++bufferLength;
  8369. if (bufferLength < 16) {
  8370. continue;
  8371. }
  8372. for (j = 0; j < 16; ++j) {
  8373. buffer[j] ^= iv[j];
  8374. }
  8375. // buffer is full, encrypting
  8376. var cipher = encrypt256(buffer, this.key);
  8377. this.iv = cipher;
  8378. result.push(cipher);
  8379. buffer = new Uint8Array(16);
  8380. bufferLength = 0;
  8381. }
  8382. // saving incomplete buffer
  8383. this.buffer = buffer;
  8384. this.bufferLength = bufferLength;
  8385. this.iv = iv;
  8386. if (result.length === 0) {
  8387. return new Uint8Array([]);
  8388. }
  8389. // combining plain text blocks into one
  8390. var outputLength = 16 * result.length;
  8391. var output = new Uint8Array(outputLength);
  8392. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8393. output.set(result[i], j);
  8394. }
  8395. return output;
  8396. }
  8397. };
  8398. return AES256Cipher;
  8399. })();
  8400. var PDF17 = (function PDF17Closure() {
  8401. function compareByteArrays(array1, array2) {
  8402. if (array1.length !== array2.length) {
  8403. return false;
  8404. }
  8405. for (var i = 0; i < array1.length; i++) {
  8406. if (array1[i] !== array2[i]) {
  8407. return false;
  8408. }
  8409. }
  8410. return true;
  8411. }
  8412. function PDF17() {
  8413. }
  8414. PDF17.prototype = {
  8415. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8416. ownerValidationSalt,
  8417. userBytes,
  8418. ownerPassword) {
  8419. var hashData = new Uint8Array(password.length + 56);
  8420. hashData.set(password, 0);
  8421. hashData.set(ownerValidationSalt, password.length);
  8422. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8423. var result = calculateSHA256(hashData, 0, hashData.length);
  8424. return compareByteArrays(result, ownerPassword);
  8425. },
  8426. checkUserPassword: function PDF17_checkUserPassword(password,
  8427. userValidationSalt,
  8428. userPassword) {
  8429. var hashData = new Uint8Array(password.length + 8);
  8430. hashData.set(password, 0);
  8431. hashData.set(userValidationSalt, password.length);
  8432. var result = calculateSHA256(hashData, 0, hashData.length);
  8433. return compareByteArrays(result, userPassword);
  8434. },
  8435. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8436. ownerEncryption) {
  8437. var hashData = new Uint8Array(password.length + 56);
  8438. hashData.set(password, 0);
  8439. hashData.set(ownerKeySalt, password.length);
  8440. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8441. var key = calculateSHA256(hashData, 0, hashData.length);
  8442. var cipher = new AES256Cipher(key);
  8443. return cipher.decryptBlock(ownerEncryption,
  8444. false,
  8445. new Uint8Array(16));
  8446. },
  8447. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8448. userEncryption) {
  8449. var hashData = new Uint8Array(password.length + 8);
  8450. hashData.set(password, 0);
  8451. hashData.set(userKeySalt, password.length);
  8452. //key is the decryption key for the UE string
  8453. var key = calculateSHA256(hashData, 0, hashData.length);
  8454. var cipher = new AES256Cipher(key);
  8455. return cipher.decryptBlock(userEncryption,
  8456. false,
  8457. new Uint8Array(16));
  8458. }
  8459. };
  8460. return PDF17;
  8461. })();
  8462. var PDF20 = (function PDF20Closure() {
  8463. function concatArrays(array1, array2) {
  8464. var t = new Uint8Array(array1.length + array2.length);
  8465. t.set(array1, 0);
  8466. t.set(array2, array1.length);
  8467. return t;
  8468. }
  8469. function calculatePDF20Hash(password, input, userBytes) {
  8470. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8471. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8472. var e = [0];
  8473. var i = 0;
  8474. while (i < 64 || e[e.length - 1] > i - 32) {
  8475. var arrayLength = password.length + k.length + userBytes.length;
  8476. var k1 = new Uint8Array(arrayLength * 64);
  8477. var array = concatArrays(password, k);
  8478. array = concatArrays(array, userBytes);
  8479. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8480. k1.set(array, pos);
  8481. }
  8482. //AES128 CBC NO PADDING with
  8483. //first 16 bytes of k as the key and the second 16 as the iv.
  8484. var cipher = new AES128Cipher(k.subarray(0, 16));
  8485. e = cipher.encrypt(k1, k.subarray(16, 32));
  8486. //Now we have to take the first 16 bytes of an unsigned
  8487. //big endian integer... and compute the remainder
  8488. //modulo 3.... That is a fairly large number and
  8489. //JavaScript isn't going to handle that well...
  8490. //So we're using a trick that allows us to perform
  8491. //modulo math byte by byte
  8492. var remainder = 0;
  8493. for (var z = 0; z < 16; z++) {
  8494. remainder *= (256 % 3);
  8495. remainder %= 3;
  8496. remainder += ((e[z] >>> 0) % 3);
  8497. remainder %= 3;
  8498. }
  8499. if (remainder === 0) {
  8500. k = calculateSHA256(e, 0, e.length);
  8501. }
  8502. else if (remainder === 1) {
  8503. k = calculateSHA384(e, 0, e.length);
  8504. }
  8505. else if (remainder === 2) {
  8506. k = calculateSHA512(e, 0, e.length);
  8507. }
  8508. i++;
  8509. }
  8510. return k.subarray(0, 32);
  8511. }
  8512. function PDF20() {
  8513. }
  8514. function compareByteArrays(array1, array2) {
  8515. if (array1.length !== array2.length) {
  8516. return false;
  8517. }
  8518. for (var i = 0; i < array1.length; i++) {
  8519. if (array1[i] !== array2[i]) {
  8520. return false;
  8521. }
  8522. }
  8523. return true;
  8524. }
  8525. PDF20.prototype = {
  8526. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8527. return calculatePDF20Hash(password, concatBytes, userBytes);
  8528. },
  8529. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8530. ownerValidationSalt,
  8531. userBytes,
  8532. ownerPassword) {
  8533. var hashData = new Uint8Array(password.length + 56);
  8534. hashData.set(password, 0);
  8535. hashData.set(ownerValidationSalt, password.length);
  8536. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8537. var result = calculatePDF20Hash(password, hashData, userBytes);
  8538. return compareByteArrays(result, ownerPassword);
  8539. },
  8540. checkUserPassword: function PDF20_checkUserPassword(password,
  8541. userValidationSalt,
  8542. userPassword) {
  8543. var hashData = new Uint8Array(password.length + 8);
  8544. hashData.set(password, 0);
  8545. hashData.set(userValidationSalt, password.length);
  8546. var result = calculatePDF20Hash(password, hashData, []);
  8547. return compareByteArrays(result, userPassword);
  8548. },
  8549. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8550. ownerEncryption) {
  8551. var hashData = new Uint8Array(password.length + 56);
  8552. hashData.set(password, 0);
  8553. hashData.set(ownerKeySalt, password.length);
  8554. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8555. var key = calculatePDF20Hash(password, hashData, userBytes);
  8556. var cipher = new AES256Cipher(key);
  8557. return cipher.decryptBlock(ownerEncryption,
  8558. false,
  8559. new Uint8Array(16));
  8560. },
  8561. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8562. userEncryption) {
  8563. var hashData = new Uint8Array(password.length + 8);
  8564. hashData.set(password, 0);
  8565. hashData.set(userKeySalt, password.length);
  8566. //key is the decryption key for the UE string
  8567. var key = calculatePDF20Hash(password, hashData, []);
  8568. var cipher = new AES256Cipher(key);
  8569. return cipher.decryptBlock(userEncryption,
  8570. false,
  8571. new Uint8Array(16));
  8572. }
  8573. };
  8574. return PDF20;
  8575. })();
  8576. var CipherTransform = (function CipherTransformClosure() {
  8577. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8578. this.stringCipherConstructor = stringCipherConstructor;
  8579. this.streamCipherConstructor = streamCipherConstructor;
  8580. }
  8581. CipherTransform.prototype = {
  8582. createStream: function CipherTransform_createStream(stream, length) {
  8583. var cipher = new this.streamCipherConstructor();
  8584. return new DecryptStream(stream, length,
  8585. function cipherTransformDecryptStream(data, finalize) {
  8586. return cipher.decryptBlock(data, finalize);
  8587. }
  8588. );
  8589. },
  8590. decryptString: function CipherTransform_decryptString(s) {
  8591. var cipher = new this.stringCipherConstructor();
  8592. var data = stringToBytes(s);
  8593. data = cipher.decryptBlock(data, true);
  8594. return bytesToString(data);
  8595. }
  8596. };
  8597. return CipherTransform;
  8598. })();
  8599. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8600. var defaultPasswordBytes = new Uint8Array([
  8601. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8602. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8603. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8604. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8605. function createEncryptionKey20(revision, password, ownerPassword,
  8606. ownerValidationSalt, ownerKeySalt, uBytes,
  8607. userPassword, userValidationSalt, userKeySalt,
  8608. ownerEncryption, userEncryption, perms) {
  8609. if (password) {
  8610. var passwordLength = Math.min(127, password.length);
  8611. password = password.subarray(0, passwordLength);
  8612. } else {
  8613. password = [];
  8614. }
  8615. var pdfAlgorithm;
  8616. if (revision === 6) {
  8617. pdfAlgorithm = new PDF20();
  8618. } else {
  8619. pdfAlgorithm = new PDF17();
  8620. }
  8621. if (pdfAlgorithm) {
  8622. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8623. userPassword)) {
  8624. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8625. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8626. uBytes,
  8627. ownerPassword)) {
  8628. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8629. ownerEncryption);
  8630. }
  8631. }
  8632. return null;
  8633. }
  8634. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8635. flags, revision, keyLength, encryptMetadata) {
  8636. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8637. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8638. if (password) {
  8639. n = Math.min(32, password.length);
  8640. for (; i < n; ++i) {
  8641. hashData[i] = password[i];
  8642. }
  8643. }
  8644. j = 0;
  8645. while (i < 32) {
  8646. hashData[i++] = defaultPasswordBytes[j++];
  8647. }
  8648. // as now the padded password in the hashData[0..i]
  8649. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8650. hashData[i++] = ownerPassword[j];
  8651. }
  8652. hashData[i++] = flags & 0xFF;
  8653. hashData[i++] = (flags >> 8) & 0xFF;
  8654. hashData[i++] = (flags >> 16) & 0xFF;
  8655. hashData[i++] = (flags >>> 24) & 0xFF;
  8656. for (j = 0, n = fileId.length; j < n; ++j) {
  8657. hashData[i++] = fileId[j];
  8658. }
  8659. if (revision >= 4 && !encryptMetadata) {
  8660. hashData[i++] = 0xFF;
  8661. hashData[i++] = 0xFF;
  8662. hashData[i++] = 0xFF;
  8663. hashData[i++] = 0xFF;
  8664. }
  8665. var hash = calculateMD5(hashData, 0, i);
  8666. var keyLengthInBytes = keyLength >> 3;
  8667. if (revision >= 3) {
  8668. for (j = 0; j < 50; ++j) {
  8669. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8670. }
  8671. }
  8672. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8673. var cipher, checkData;
  8674. if (revision >= 3) {
  8675. for (i = 0; i < 32; ++i) {
  8676. hashData[i] = defaultPasswordBytes[i];
  8677. }
  8678. for (j = 0, n = fileId.length; j < n; ++j) {
  8679. hashData[i++] = fileId[j];
  8680. }
  8681. cipher = new ARCFourCipher(encryptionKey);
  8682. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8683. n = encryptionKey.length;
  8684. var derivedKey = new Uint8Array(n), k;
  8685. for (j = 1; j <= 19; ++j) {
  8686. for (k = 0; k < n; ++k) {
  8687. derivedKey[k] = encryptionKey[k] ^ j;
  8688. }
  8689. cipher = new ARCFourCipher(derivedKey);
  8690. checkData = cipher.encryptBlock(checkData);
  8691. }
  8692. for (j = 0, n = checkData.length; j < n; ++j) {
  8693. if (userPassword[j] !== checkData[j]) {
  8694. return null;
  8695. }
  8696. }
  8697. } else {
  8698. cipher = new ARCFourCipher(encryptionKey);
  8699. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8700. for (j = 0, n = checkData.length; j < n; ++j) {
  8701. if (userPassword[j] !== checkData[j]) {
  8702. return null;
  8703. }
  8704. }
  8705. }
  8706. return encryptionKey;
  8707. }
  8708. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8709. var hashData = new Uint8Array(32), i = 0, j, n;
  8710. n = Math.min(32, password.length);
  8711. for (; i < n; ++i) {
  8712. hashData[i] = password[i];
  8713. }
  8714. j = 0;
  8715. while (i < 32) {
  8716. hashData[i++] = defaultPasswordBytes[j++];
  8717. }
  8718. var hash = calculateMD5(hashData, 0, i);
  8719. var keyLengthInBytes = keyLength >> 3;
  8720. if (revision >= 3) {
  8721. for (j = 0; j < 50; ++j) {
  8722. hash = calculateMD5(hash, 0, hash.length);
  8723. }
  8724. }
  8725. var cipher, userPassword;
  8726. if (revision >= 3) {
  8727. userPassword = ownerPassword;
  8728. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8729. for (j = 19; j >= 0; j--) {
  8730. for (k = 0; k < keyLengthInBytes; ++k) {
  8731. derivedKey[k] = hash[k] ^ j;
  8732. }
  8733. cipher = new ARCFourCipher(derivedKey);
  8734. userPassword = cipher.encryptBlock(userPassword);
  8735. }
  8736. } else {
  8737. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8738. userPassword = cipher.encryptBlock(ownerPassword);
  8739. }
  8740. return userPassword;
  8741. }
  8742. var identityName = Name.get('Identity');
  8743. function CipherTransformFactory(dict, fileId, password) {
  8744. var filter = dict.get('Filter');
  8745. if (!isName(filter) || filter.name !== 'Standard') {
  8746. error('unknown encryption method');
  8747. }
  8748. this.dict = dict;
  8749. var algorithm = dict.get('V');
  8750. if (!isInt(algorithm) ||
  8751. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8752. algorithm !== 5)) {
  8753. error('unsupported encryption algorithm');
  8754. }
  8755. this.algorithm = algorithm;
  8756. var keyLength = dict.get('Length') || 40;
  8757. if (!isInt(keyLength) ||
  8758. keyLength < 40 || (keyLength % 8) !== 0) {
  8759. error('invalid key length');
  8760. }
  8761. // prepare keys
  8762. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8763. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8764. var flags = dict.get('P');
  8765. var revision = dict.get('R');
  8766. // meaningful when V is 4 or 5
  8767. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8768. dict.get('EncryptMetadata') !== false);
  8769. this.encryptMetadata = encryptMetadata;
  8770. var fileIdBytes = stringToBytes(fileId);
  8771. var passwordBytes;
  8772. if (password) {
  8773. if (revision === 6) {
  8774. try {
  8775. password = utf8StringToString(password);
  8776. } catch (ex) {
  8777. warn('CipherTransformFactory: ' +
  8778. 'Unable to convert UTF8 encoded password.');
  8779. }
  8780. }
  8781. passwordBytes = stringToBytes(password);
  8782. }
  8783. var encryptionKey;
  8784. if (algorithm !== 5) {
  8785. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8786. ownerPassword, userPassword, flags,
  8787. revision, keyLength, encryptMetadata);
  8788. }
  8789. else {
  8790. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8791. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8792. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8793. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8794. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8795. var ownerEncryption = stringToBytes(dict.get('OE'));
  8796. var userEncryption = stringToBytes(dict.get('UE'));
  8797. var perms = stringToBytes(dict.get('Perms'));
  8798. encryptionKey =
  8799. createEncryptionKey20(revision, passwordBytes,
  8800. ownerPassword, ownerValidationSalt,
  8801. ownerKeySalt, uBytes,
  8802. userPassword, userValidationSalt,
  8803. userKeySalt, ownerEncryption,
  8804. userEncryption, perms);
  8805. }
  8806. if (!encryptionKey && !password) {
  8807. throw new PasswordException('No password given',
  8808. PasswordResponses.NEED_PASSWORD);
  8809. } else if (!encryptionKey && password) {
  8810. // Attempting use the password as an owner password
  8811. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8812. revision, keyLength);
  8813. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8814. ownerPassword, userPassword, flags,
  8815. revision, keyLength, encryptMetadata);
  8816. }
  8817. if (!encryptionKey) {
  8818. throw new PasswordException('Incorrect Password',
  8819. PasswordResponses.INCORRECT_PASSWORD);
  8820. }
  8821. this.encryptionKey = encryptionKey;
  8822. if (algorithm >= 4) {
  8823. this.cf = dict.get('CF');
  8824. this.stmf = dict.get('StmF') || identityName;
  8825. this.strf = dict.get('StrF') || identityName;
  8826. this.eff = dict.get('EFF') || this.stmf;
  8827. }
  8828. }
  8829. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8830. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8831. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8832. key[i] = encryptionKey[i];
  8833. }
  8834. key[i++] = num & 0xFF;
  8835. key[i++] = (num >> 8) & 0xFF;
  8836. key[i++] = (num >> 16) & 0xFF;
  8837. key[i++] = gen & 0xFF;
  8838. key[i++] = (gen >> 8) & 0xFF;
  8839. if (isAes) {
  8840. key[i++] = 0x73;
  8841. key[i++] = 0x41;
  8842. key[i++] = 0x6C;
  8843. key[i++] = 0x54;
  8844. }
  8845. var hash = calculateMD5(key, 0, i);
  8846. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8847. }
  8848. function buildCipherConstructor(cf, name, num, gen, key) {
  8849. var cryptFilter = cf.get(name.name);
  8850. var cfm;
  8851. if (cryptFilter !== null && cryptFilter !== undefined) {
  8852. cfm = cryptFilter.get('CFM');
  8853. }
  8854. if (!cfm || cfm.name === 'None') {
  8855. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8856. return new NullCipher();
  8857. };
  8858. }
  8859. if ('V2' === cfm.name) {
  8860. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8861. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8862. };
  8863. }
  8864. if ('AESV2' === cfm.name) {
  8865. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8866. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8867. };
  8868. }
  8869. if ('AESV3' === cfm.name) {
  8870. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8871. return new AES256Cipher(key);
  8872. };
  8873. }
  8874. error('Unknown crypto method');
  8875. }
  8876. CipherTransformFactory.prototype = {
  8877. createCipherTransform:
  8878. function CipherTransformFactory_createCipherTransform(num, gen) {
  8879. if (this.algorithm === 4 || this.algorithm === 5) {
  8880. return new CipherTransform(
  8881. buildCipherConstructor(this.cf, this.stmf,
  8882. num, gen, this.encryptionKey),
  8883. buildCipherConstructor(this.cf, this.strf,
  8884. num, gen, this.encryptionKey));
  8885. }
  8886. // algorithms 1 and 2
  8887. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8888. var cipherConstructor = function buildCipherCipherConstructor() {
  8889. return new ARCFourCipher(key);
  8890. };
  8891. return new CipherTransform(cipherConstructor, cipherConstructor);
  8892. }
  8893. };
  8894. return CipherTransformFactory;
  8895. })();
  8896. var PatternType = {
  8897. FUNCTION_BASED: 1,
  8898. AXIAL: 2,
  8899. RADIAL: 3,
  8900. FREE_FORM_MESH: 4,
  8901. LATTICE_FORM_MESH: 5,
  8902. COONS_PATCH_MESH: 6,
  8903. TENSOR_PATCH_MESH: 7
  8904. };
  8905. var Pattern = (function PatternClosure() {
  8906. // Constructor should define this.getPattern
  8907. function Pattern() {
  8908. error('should not call Pattern constructor');
  8909. }
  8910. Pattern.prototype = {
  8911. // Input: current Canvas context
  8912. // Output: the appropriate fillStyle or strokeStyle
  8913. getPattern: function Pattern_getPattern(ctx) {
  8914. error('Should not call Pattern.getStyle: ' + ctx);
  8915. }
  8916. };
  8917. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8918. res) {
  8919. var dict = isStream(shading) ? shading.dict : shading;
  8920. var type = dict.get('ShadingType');
  8921. try {
  8922. switch (type) {
  8923. case PatternType.AXIAL:
  8924. case PatternType.RADIAL:
  8925. // Both radial and axial shadings are handled by RadialAxial shading.
  8926. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8927. case PatternType.FREE_FORM_MESH:
  8928. case PatternType.LATTICE_FORM_MESH:
  8929. case PatternType.COONS_PATCH_MESH:
  8930. case PatternType.TENSOR_PATCH_MESH:
  8931. return new Shadings.Mesh(shading, matrix, xref, res);
  8932. default:
  8933. throw new Error('Unknown PatternType: ' + type);
  8934. }
  8935. } catch (ex) {
  8936. if (ex instanceof MissingDataException) {
  8937. throw ex;
  8938. }
  8939. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8940. warn(ex);
  8941. return new Shadings.Dummy();
  8942. }
  8943. };
  8944. return Pattern;
  8945. })();
  8946. var Shadings = {};
  8947. // A small number to offset the first/last color stops so we can insert ones to
  8948. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8949. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8950. // internally so we have to go bigger.
  8951. Shadings.SMALL_NUMBER = 1e-2;
  8952. // Radial and axial shading have very similar implementations
  8953. // If needed, the implementations can be broken into two classes
  8954. Shadings.RadialAxial = (function RadialAxialClosure() {
  8955. function RadialAxial(dict, matrix, xref, res) {
  8956. this.matrix = matrix;
  8957. this.coordsArr = dict.get('Coords');
  8958. this.shadingType = dict.get('ShadingType');
  8959. this.type = 'Pattern';
  8960. var cs = dict.get('ColorSpace', 'CS');
  8961. cs = ColorSpace.parse(cs, xref, res);
  8962. this.cs = cs;
  8963. var t0 = 0.0, t1 = 1.0;
  8964. if (dict.has('Domain')) {
  8965. var domainArr = dict.get('Domain');
  8966. t0 = domainArr[0];
  8967. t1 = domainArr[1];
  8968. }
  8969. var extendStart = false, extendEnd = false;
  8970. if (dict.has('Extend')) {
  8971. var extendArr = dict.get('Extend');
  8972. extendStart = extendArr[0];
  8973. extendEnd = extendArr[1];
  8974. }
  8975. if (this.shadingType === PatternType.RADIAL &&
  8976. (!extendStart || !extendEnd)) {
  8977. // Radial gradient only currently works if either circle is fully within
  8978. // the other circle.
  8979. var x1 = this.coordsArr[0];
  8980. var y1 = this.coordsArr[1];
  8981. var r1 = this.coordsArr[2];
  8982. var x2 = this.coordsArr[3];
  8983. var y2 = this.coordsArr[4];
  8984. var r2 = this.coordsArr[5];
  8985. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8986. if (r1 <= r2 + distance &&
  8987. r2 <= r1 + distance) {
  8988. warn('Unsupported radial gradient.');
  8989. }
  8990. }
  8991. this.extendStart = extendStart;
  8992. this.extendEnd = extendEnd;
  8993. var fnObj = dict.get('Function');
  8994. var fn = PDFFunction.parseArray(xref, fnObj);
  8995. // 10 samples seems good enough for now, but probably won't work
  8996. // if there are sharp color changes. Ideally, we would implement
  8997. // the spec faithfully and add lossless optimizations.
  8998. var diff = t1 - t0;
  8999. var step = diff / 10;
  9000. var colorStops = this.colorStops = [];
  9001. // Protect against bad domains so we don't end up in an infinte loop below.
  9002. if (t0 >= t1 || step <= 0) {
  9003. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9004. // now.
  9005. info('Bad shading domain.');
  9006. return;
  9007. }
  9008. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9009. var rgbColor;
  9010. for (var i = t0; i <= t1; i += step) {
  9011. ratio[0] = i;
  9012. fn(ratio, 0, color, 0);
  9013. rgbColor = cs.getRgb(color, 0);
  9014. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9015. colorStops.push([(i - t0) / diff, cssColor]);
  9016. }
  9017. var background = 'transparent';
  9018. if (dict.has('Background')) {
  9019. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9020. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9021. }
  9022. if (!extendStart) {
  9023. // Insert a color stop at the front and offset the first real color stop
  9024. // so it doesn't conflict with the one we insert.
  9025. colorStops.unshift([0, background]);
  9026. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9027. }
  9028. if (!extendEnd) {
  9029. // Same idea as above in extendStart but for the end.
  9030. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9031. colorStops.push([1, background]);
  9032. }
  9033. this.colorStops = colorStops;
  9034. }
  9035. RadialAxial.prototype = {
  9036. getIR: function RadialAxial_getIR() {
  9037. var coordsArr = this.coordsArr;
  9038. var shadingType = this.shadingType;
  9039. var type, p0, p1, r0, r1;
  9040. if (shadingType === PatternType.AXIAL) {
  9041. p0 = [coordsArr[0], coordsArr[1]];
  9042. p1 = [coordsArr[2], coordsArr[3]];
  9043. r0 = null;
  9044. r1 = null;
  9045. type = 'axial';
  9046. } else if (shadingType === PatternType.RADIAL) {
  9047. p0 = [coordsArr[0], coordsArr[1]];
  9048. p1 = [coordsArr[3], coordsArr[4]];
  9049. r0 = coordsArr[2];
  9050. r1 = coordsArr[5];
  9051. type = 'radial';
  9052. } else {
  9053. error('getPattern type unknown: ' + shadingType);
  9054. }
  9055. var matrix = this.matrix;
  9056. if (matrix) {
  9057. p0 = Util.applyTransform(p0, matrix);
  9058. p1 = Util.applyTransform(p1, matrix);
  9059. }
  9060. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9061. }
  9062. };
  9063. return RadialAxial;
  9064. })();
  9065. // All mesh shading. For now, they will be presented as set of the triangles
  9066. // to be drawn on the canvas and rgb color for each vertex.
  9067. Shadings.Mesh = (function MeshClosure() {
  9068. function MeshStreamReader(stream, context) {
  9069. this.stream = stream;
  9070. this.context = context;
  9071. this.buffer = 0;
  9072. this.bufferLength = 0;
  9073. var numComps = context.numComps;
  9074. this.tmpCompsBuf = new Float32Array(numComps);
  9075. var csNumComps = context.colorSpace;
  9076. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9077. this.tmpCompsBuf;
  9078. }
  9079. MeshStreamReader.prototype = {
  9080. get hasData() {
  9081. if (this.stream.end) {
  9082. return this.stream.pos < this.stream.end;
  9083. }
  9084. if (this.bufferLength > 0) {
  9085. return true;
  9086. }
  9087. var nextByte = this.stream.getByte();
  9088. if (nextByte < 0) {
  9089. return false;
  9090. }
  9091. this.buffer = nextByte;
  9092. this.bufferLength = 8;
  9093. return true;
  9094. },
  9095. readBits: function MeshStreamReader_readBits(n) {
  9096. var buffer = this.buffer;
  9097. var bufferLength = this.bufferLength;
  9098. if (n === 32) {
  9099. if (bufferLength === 0) {
  9100. return ((this.stream.getByte() << 24) |
  9101. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9102. this.stream.getByte()) >>> 0;
  9103. }
  9104. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9105. (this.stream.getByte() << 8) | this.stream.getByte();
  9106. var nextByte = this.stream.getByte();
  9107. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9108. return ((buffer << (8 - bufferLength)) |
  9109. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9110. }
  9111. if (n === 8 && bufferLength === 0) {
  9112. return this.stream.getByte();
  9113. }
  9114. while (bufferLength < n) {
  9115. buffer = (buffer << 8) | this.stream.getByte();
  9116. bufferLength += 8;
  9117. }
  9118. bufferLength -= n;
  9119. this.bufferLength = bufferLength;
  9120. this.buffer = buffer & ((1 << bufferLength) - 1);
  9121. return buffer >> bufferLength;
  9122. },
  9123. align: function MeshStreamReader_align() {
  9124. this.buffer = 0;
  9125. this.bufferLength = 0;
  9126. },
  9127. readFlag: function MeshStreamReader_readFlag() {
  9128. return this.readBits(this.context.bitsPerFlag);
  9129. },
  9130. readCoordinate: function MeshStreamReader_readCoordinate() {
  9131. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9132. var xi = this.readBits(bitsPerCoordinate);
  9133. var yi = this.readBits(bitsPerCoordinate);
  9134. var decode = this.context.decode;
  9135. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9136. 2.3283064365386963e-10; // 2 ^ -32
  9137. return [
  9138. xi * scale * (decode[1] - decode[0]) + decode[0],
  9139. yi * scale * (decode[3] - decode[2]) + decode[2]
  9140. ];
  9141. },
  9142. readComponents: function MeshStreamReader_readComponents() {
  9143. var numComps = this.context.numComps;
  9144. var bitsPerComponent = this.context.bitsPerComponent;
  9145. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9146. 2.3283064365386963e-10; // 2 ^ -32
  9147. var decode = this.context.decode;
  9148. var components = this.tmpCompsBuf;
  9149. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9150. var ci = this.readBits(bitsPerComponent);
  9151. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9152. }
  9153. var color = this.tmpCsCompsBuf;
  9154. if (this.context.colorFn) {
  9155. this.context.colorFn(components, 0, color, 0);
  9156. }
  9157. return this.context.colorSpace.getRgb(color, 0);
  9158. }
  9159. };
  9160. function decodeType4Shading(mesh, reader) {
  9161. var coords = mesh.coords;
  9162. var colors = mesh.colors;
  9163. var operators = [];
  9164. var ps = []; // not maintaining cs since that will match ps
  9165. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9166. while (reader.hasData) {
  9167. var f = reader.readFlag();
  9168. var coord = reader.readCoordinate();
  9169. var color = reader.readComponents();
  9170. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9171. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9172. switch (f) {
  9173. case 0:
  9174. verticesLeft = 3;
  9175. break;
  9176. case 1:
  9177. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9178. verticesLeft = 1;
  9179. break;
  9180. case 2:
  9181. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9182. verticesLeft = 1;
  9183. break;
  9184. }
  9185. operators.push(f);
  9186. }
  9187. ps.push(coords.length);
  9188. coords.push(coord);
  9189. colors.push(color);
  9190. verticesLeft--;
  9191. reader.align();
  9192. }
  9193. var psPacked = new Int32Array(ps);
  9194. mesh.figures.push({
  9195. type: 'triangles',
  9196. coords: psPacked,
  9197. colors: psPacked
  9198. });
  9199. }
  9200. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9201. var coords = mesh.coords;
  9202. var colors = mesh.colors;
  9203. var ps = []; // not maintaining cs since that will match ps
  9204. while (reader.hasData) {
  9205. var coord = reader.readCoordinate();
  9206. var color = reader.readComponents();
  9207. ps.push(coords.length);
  9208. coords.push(coord);
  9209. colors.push(color);
  9210. }
  9211. var psPacked = new Int32Array(ps);
  9212. mesh.figures.push({
  9213. type: 'lattice',
  9214. coords: psPacked,
  9215. colors: psPacked,
  9216. verticesPerRow: verticesPerRow
  9217. });
  9218. }
  9219. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9220. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9221. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9222. var getB = (function getBClosure() {
  9223. function buildB(count) {
  9224. var lut = [];
  9225. for (var i = 0; i <= count; i++) {
  9226. var t = i / count, t_ = 1 - t;
  9227. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9228. 3 * t * t * t_, t * t * t]));
  9229. }
  9230. return lut;
  9231. }
  9232. var cache = [];
  9233. return function getB(count) {
  9234. if (!cache[count]) {
  9235. cache[count] = buildB(count);
  9236. }
  9237. return cache[count];
  9238. };
  9239. })();
  9240. function buildFigureFromPatch(mesh, index) {
  9241. var figure = mesh.figures[index];
  9242. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9243. var coords = mesh.coords, colors = mesh.colors;
  9244. var pi = figure.coords;
  9245. var ci = figure.colors;
  9246. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9247. coords[pi[12]][0], coords[pi[15]][0]);
  9248. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9249. coords[pi[12]][1], coords[pi[15]][1]);
  9250. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9251. coords[pi[12]][0], coords[pi[15]][0]);
  9252. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9253. coords[pi[12]][1], coords[pi[15]][1]);
  9254. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9255. (mesh.bounds[2] - mesh.bounds[0]));
  9256. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9257. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9258. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9259. (mesh.bounds[3] - mesh.bounds[1]));
  9260. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9261. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9262. var verticesPerRow = splitXBy + 1;
  9263. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9264. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9265. var k = 0;
  9266. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9267. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9268. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9269. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9270. for (var row = 0; row <= splitYBy; row++) {
  9271. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9272. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9273. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9274. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9275. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9276. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9277. for (var col = 0; col <= splitXBy; col++, k++) {
  9278. if ((row === 0 || row === splitYBy) &&
  9279. (col === 0 || col === splitXBy)) {
  9280. continue;
  9281. }
  9282. var x = 0, y = 0;
  9283. var q = 0;
  9284. for (var i = 0; i <= 3; i++) {
  9285. for (var j = 0; j <= 3; j++, q++) {
  9286. var m = bRow[row][i] * bCol[col][j];
  9287. x += coords[pi[q]][0] * m;
  9288. y += coords[pi[q]][1] * m;
  9289. }
  9290. }
  9291. figureCoords[k] = coords.length;
  9292. coords.push([x, y]);
  9293. figureColors[k] = colors.length;
  9294. var newColor = new Uint8Array(3);
  9295. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9296. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9297. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9298. colors.push(newColor);
  9299. }
  9300. }
  9301. figureCoords[0] = pi[0];
  9302. figureColors[0] = ci[0];
  9303. figureCoords[splitXBy] = pi[3];
  9304. figureColors[splitXBy] = ci[1];
  9305. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9306. figureColors[verticesPerRow * splitYBy] = ci[2];
  9307. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9308. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9309. mesh.figures[index] = {
  9310. type: 'lattice',
  9311. coords: figureCoords,
  9312. colors: figureColors,
  9313. verticesPerRow: verticesPerRow
  9314. };
  9315. }
  9316. function decodeType6Shading(mesh, reader) {
  9317. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9318. var coords = mesh.coords;
  9319. var colors = mesh.colors;
  9320. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9321. var cs = new Int32Array(4); // c00, c30, c03, c33
  9322. while (reader.hasData) {
  9323. var f = reader.readFlag();
  9324. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9325. var i, ii;
  9326. var pi = coords.length;
  9327. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9328. coords.push(reader.readCoordinate());
  9329. }
  9330. var ci = colors.length;
  9331. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9332. colors.push(reader.readComponents());
  9333. }
  9334. var tmp1, tmp2, tmp3, tmp4;
  9335. switch (f) {
  9336. case 0:
  9337. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9338. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9339. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9340. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9341. cs[2] = ci + 1; cs[3] = ci + 2;
  9342. cs[0] = ci; cs[1] = ci + 3;
  9343. break;
  9344. case 1:
  9345. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9346. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9347. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9348. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9349. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9350. tmp1 = cs[2]; tmp2 = cs[3];
  9351. cs[2] = ci + 1; cs[3] = ci;
  9352. cs[0] = tmp1; cs[1] = tmp2;
  9353. break;
  9354. case 2:
  9355. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9356. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9357. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9358. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9359. cs[2] = cs[3]; cs[3] = ci + 1;
  9360. cs[0] = cs[1]; cs[1] = ci;
  9361. break;
  9362. case 3:
  9363. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9364. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9365. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9366. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9367. cs[2] = cs[0]; cs[3] = cs[1];
  9368. cs[0] = ci; cs[1] = ci + 1;
  9369. break;
  9370. }
  9371. // set p11, p12, p21, p22
  9372. ps[5] = coords.length;
  9373. coords.push([
  9374. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9375. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9376. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9377. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9378. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9379. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9380. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9381. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9382. ]);
  9383. ps[6] = coords.length;
  9384. coords.push([
  9385. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9386. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9387. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9388. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9389. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9390. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9391. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9392. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9393. ]);
  9394. ps[9] = coords.length;
  9395. coords.push([
  9396. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9397. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9398. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9399. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9400. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9401. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9402. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9403. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9404. ]);
  9405. ps[10] = coords.length;
  9406. coords.push([
  9407. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9408. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9409. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9410. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9411. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9412. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9413. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9414. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9415. ]);
  9416. mesh.figures.push({
  9417. type: 'patch',
  9418. coords: new Int32Array(ps), // making copies of ps and cs
  9419. colors: new Int32Array(cs)
  9420. });
  9421. }
  9422. }
  9423. function decodeType7Shading(mesh, reader) {
  9424. var coords = mesh.coords;
  9425. var colors = mesh.colors;
  9426. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9427. var cs = new Int32Array(4); // c00, c30, c03, c33
  9428. while (reader.hasData) {
  9429. var f = reader.readFlag();
  9430. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9431. var i, ii;
  9432. var pi = coords.length;
  9433. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9434. coords.push(reader.readCoordinate());
  9435. }
  9436. var ci = colors.length;
  9437. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9438. colors.push(reader.readComponents());
  9439. }
  9440. var tmp1, tmp2, tmp3, tmp4;
  9441. switch (f) {
  9442. case 0:
  9443. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9444. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9445. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9446. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9447. cs[2] = ci + 1; cs[3] = ci + 2;
  9448. cs[0] = ci; cs[1] = ci + 3;
  9449. break;
  9450. case 1:
  9451. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9452. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9453. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9454. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9455. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9456. tmp1 = cs[2]; tmp2 = cs[3];
  9457. cs[2] = ci + 1; cs[3] = ci;
  9458. cs[0] = tmp1; cs[1] = tmp2;
  9459. break;
  9460. case 2:
  9461. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9462. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9463. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9464. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9465. cs[2] = cs[3]; cs[3] = ci + 1;
  9466. cs[0] = cs[1]; cs[1] = ci;
  9467. break;
  9468. case 3:
  9469. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9470. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9471. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9472. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9473. cs[2] = cs[0]; cs[3] = cs[1];
  9474. cs[0] = ci; cs[1] = ci + 1;
  9475. break;
  9476. }
  9477. mesh.figures.push({
  9478. type: 'patch',
  9479. coords: new Int32Array(ps), // making copies of ps and cs
  9480. colors: new Int32Array(cs)
  9481. });
  9482. }
  9483. }
  9484. function updateBounds(mesh) {
  9485. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9486. maxX = minX, maxY = minY;
  9487. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9488. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9489. minX = minX > x ? x : minX;
  9490. minY = minY > y ? y : minY;
  9491. maxX = maxX < x ? x : maxX;
  9492. maxY = maxY < y ? y : maxY;
  9493. }
  9494. mesh.bounds = [minX, minY, maxX, maxY];
  9495. }
  9496. function packData(mesh) {
  9497. var i, ii, j, jj;
  9498. var coords = mesh.coords;
  9499. var coordsPacked = new Float32Array(coords.length * 2);
  9500. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9501. var xy = coords[i];
  9502. coordsPacked[j++] = xy[0];
  9503. coordsPacked[j++] = xy[1];
  9504. }
  9505. mesh.coords = coordsPacked;
  9506. var colors = mesh.colors;
  9507. var colorsPacked = new Uint8Array(colors.length * 3);
  9508. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9509. var c = colors[i];
  9510. colorsPacked[j++] = c[0];
  9511. colorsPacked[j++] = c[1];
  9512. colorsPacked[j++] = c[2];
  9513. }
  9514. mesh.colors = colorsPacked;
  9515. var figures = mesh.figures;
  9516. for (i = 0, ii = figures.length; i < ii; i++) {
  9517. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9518. for (j = 0, jj = ps.length; j < jj; j++) {
  9519. ps[j] *= 2;
  9520. cs[j] *= 3;
  9521. }
  9522. }
  9523. }
  9524. function Mesh(stream, matrix, xref, res) {
  9525. assert(isStream(stream), 'Mesh data is not a stream');
  9526. var dict = stream.dict;
  9527. this.matrix = matrix;
  9528. this.shadingType = dict.get('ShadingType');
  9529. this.type = 'Pattern';
  9530. this.bbox = dict.get('BBox');
  9531. var cs = dict.get('ColorSpace', 'CS');
  9532. cs = ColorSpace.parse(cs, xref, res);
  9533. this.cs = cs;
  9534. this.background = dict.has('Background') ?
  9535. cs.getRgb(dict.get('Background'), 0) : null;
  9536. var fnObj = dict.get('Function');
  9537. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9538. this.coords = [];
  9539. this.colors = [];
  9540. this.figures = [];
  9541. var decodeContext = {
  9542. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9543. bitsPerComponent: dict.get('BitsPerComponent'),
  9544. bitsPerFlag: dict.get('BitsPerFlag'),
  9545. decode: dict.get('Decode'),
  9546. colorFn: fn,
  9547. colorSpace: cs,
  9548. numComps: fn ? 1 : cs.numComps
  9549. };
  9550. var reader = new MeshStreamReader(stream, decodeContext);
  9551. var patchMesh = false;
  9552. switch (this.shadingType) {
  9553. case PatternType.FREE_FORM_MESH:
  9554. decodeType4Shading(this, reader);
  9555. break;
  9556. case PatternType.LATTICE_FORM_MESH:
  9557. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9558. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9559. decodeType5Shading(this, reader, verticesPerRow);
  9560. break;
  9561. case PatternType.COONS_PATCH_MESH:
  9562. decodeType6Shading(this, reader);
  9563. patchMesh = true;
  9564. break;
  9565. case PatternType.TENSOR_PATCH_MESH:
  9566. decodeType7Shading(this, reader);
  9567. patchMesh = true;
  9568. break;
  9569. default:
  9570. error('Unsupported mesh type.');
  9571. break;
  9572. }
  9573. if (patchMesh) {
  9574. // dirty bounds calculation for determining, how dense shall be triangles
  9575. updateBounds(this);
  9576. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9577. buildFigureFromPatch(this, i);
  9578. }
  9579. }
  9580. // calculate bounds
  9581. updateBounds(this);
  9582. packData(this);
  9583. }
  9584. Mesh.prototype = {
  9585. getIR: function Mesh_getIR() {
  9586. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9587. this.bounds, this.matrix, this.bbox, this.background];
  9588. }
  9589. };
  9590. return Mesh;
  9591. })();
  9592. Shadings.Dummy = (function DummyClosure() {
  9593. function Dummy() {
  9594. this.type = 'Pattern';
  9595. }
  9596. Dummy.prototype = {
  9597. getIR: function Dummy_getIR() {
  9598. return ['Dummy'];
  9599. }
  9600. };
  9601. return Dummy;
  9602. })();
  9603. function getTilingPatternIR(operatorList, dict, args) {
  9604. var matrix = dict.get('Matrix');
  9605. var bbox = dict.get('BBox');
  9606. var xstep = dict.get('XStep');
  9607. var ystep = dict.get('YStep');
  9608. var paintType = dict.get('PaintType');
  9609. var tilingType = dict.get('TilingType');
  9610. return [
  9611. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9612. paintType, tilingType
  9613. ];
  9614. }
  9615. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9616. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9617. uniquePrefix, idCounters, fontCache) {
  9618. this.pdfManager = pdfManager;
  9619. this.xref = xref;
  9620. this.handler = handler;
  9621. this.pageIndex = pageIndex;
  9622. this.uniquePrefix = uniquePrefix;
  9623. this.idCounters = idCounters;
  9624. this.fontCache = fontCache;
  9625. }
  9626. // Trying to minimize Date.now() usage and check every 100 time
  9627. var TIME_SLOT_DURATION_MS = 20;
  9628. var CHECK_TIME_EVERY = 100;
  9629. function TimeSlotManager() {
  9630. this.reset();
  9631. }
  9632. TimeSlotManager.prototype = {
  9633. check: function TimeSlotManager_check() {
  9634. if (++this.checked < CHECK_TIME_EVERY) {
  9635. return false;
  9636. }
  9637. this.checked = 0;
  9638. return this.endTime <= Date.now();
  9639. },
  9640. reset: function TimeSlotManager_reset() {
  9641. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9642. this.checked = 0;
  9643. }
  9644. };
  9645. var deferred = Promise.resolve();
  9646. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9647. PartialEvaluator.prototype = {
  9648. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9649. if (!isDict(resources)) {
  9650. return false;
  9651. }
  9652. var processed = Object.create(null);
  9653. if (resources.objId) {
  9654. processed[resources.objId] = true;
  9655. }
  9656. var nodes = [resources];
  9657. while (nodes.length) {
  9658. var key;
  9659. var node = nodes.shift();
  9660. // First check the current resources for blend modes.
  9661. var graphicStates = node.get('ExtGState');
  9662. if (isDict(graphicStates)) {
  9663. graphicStates = graphicStates.getAll();
  9664. for (key in graphicStates) {
  9665. var graphicState = graphicStates[key];
  9666. var bm = graphicState['BM'];
  9667. if (isName(bm) && bm.name !== 'Normal') {
  9668. return true;
  9669. }
  9670. }
  9671. }
  9672. // Descend into the XObjects to look for more resources and blend modes.
  9673. var xObjects = node.get('XObject');
  9674. if (!isDict(xObjects)) {
  9675. continue;
  9676. }
  9677. xObjects = xObjects.getAll();
  9678. for (key in xObjects) {
  9679. var xObject = xObjects[key];
  9680. if (!isStream(xObject)) {
  9681. continue;
  9682. }
  9683. if (xObject.dict.objId) {
  9684. if (processed[xObject.dict.objId]) {
  9685. // stream has objId and is processed already
  9686. continue;
  9687. }
  9688. processed[xObject.dict.objId] = true;
  9689. }
  9690. var xResources = xObject.dict.get('Resources');
  9691. // Checking objId to detect an infinite loop.
  9692. if (isDict(xResources) &&
  9693. (!xResources.objId || !processed[xResources.objId])) {
  9694. nodes.push(xResources);
  9695. if (xResources.objId) {
  9696. processed[xResources.objId] = true;
  9697. }
  9698. }
  9699. }
  9700. }
  9701. return false;
  9702. },
  9703. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9704. xobj, smask,
  9705. operatorList,
  9706. initialState) {
  9707. var matrix = xobj.dict.get('Matrix');
  9708. var bbox = xobj.dict.get('BBox');
  9709. var group = xobj.dict.get('Group');
  9710. if (group) {
  9711. var groupOptions = {
  9712. matrix: matrix,
  9713. bbox: bbox,
  9714. smask: smask,
  9715. isolated: false,
  9716. knockout: false
  9717. };
  9718. var groupSubtype = group.get('S');
  9719. var colorSpace;
  9720. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9721. groupOptions.isolated = (group.get('I') || false);
  9722. groupOptions.knockout = (group.get('K') || false);
  9723. colorSpace = (group.has('CS') ?
  9724. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9725. }
  9726. if (smask && smask.backdrop) {
  9727. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9728. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9729. }
  9730. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9731. }
  9732. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9733. return this.getOperatorList(xobj,
  9734. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9735. then(function () {
  9736. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9737. if (group) {
  9738. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9739. }
  9740. });
  9741. },
  9742. buildPaintImageXObject:
  9743. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9744. inline, operatorList,
  9745. cacheKey, imageCache) {
  9746. var self = this;
  9747. var dict = image.dict;
  9748. var w = dict.get('Width', 'W');
  9749. var h = dict.get('Height', 'H');
  9750. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9751. warn('Image dimensions are missing, or not numbers.');
  9752. return;
  9753. }
  9754. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9755. warn('Image exceeded maximum allowed size and was removed.');
  9756. return;
  9757. }
  9758. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9759. var imgData, args;
  9760. if (imageMask) {
  9761. // This depends on a tmpCanvas being filled with the
  9762. // current fillStyle, such that processing the pixel
  9763. // data can't be done here. Instead of creating a
  9764. // complete PDFImage, only read the information needed
  9765. // for later.
  9766. var width = dict.get('Width', 'W');
  9767. var height = dict.get('Height', 'H');
  9768. var bitStrideLength = (width + 7) >> 3;
  9769. var imgArray = image.getBytes(bitStrideLength * height);
  9770. var decode = dict.get('Decode', 'D');
  9771. var inverseDecode = (!!decode && decode[0] > 0);
  9772. imgData = PDFImage.createMask(imgArray, width, height,
  9773. image instanceof DecodeStream,
  9774. inverseDecode);
  9775. imgData.cached = true;
  9776. args = [imgData];
  9777. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9778. if (cacheKey) {
  9779. imageCache[cacheKey] = {
  9780. fn: OPS.paintImageMaskXObject,
  9781. args: args
  9782. };
  9783. }
  9784. return;
  9785. }
  9786. var softMask = (dict.get('SMask', 'SM') || false);
  9787. var mask = (dict.get('Mask') || false);
  9788. var SMALL_IMAGE_DIMENSIONS = 200;
  9789. // Inlining small images into the queue as RGB data
  9790. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9791. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9792. var imageObj = new PDFImage(this.xref, resources, image,
  9793. inline, null, null);
  9794. // We force the use of RGBA_32BPP images here, because we can't handle
  9795. // any other kind.
  9796. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9797. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9798. return;
  9799. }
  9800. // If there is no imageMask, create the PDFImage and a lot
  9801. // of image processing can be done here.
  9802. var uniquePrefix = (this.uniquePrefix || '');
  9803. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9804. operatorList.addDependency(objId);
  9805. args = [objId, w, h];
  9806. if (!softMask && !mask && image instanceof JpegStream &&
  9807. image.isNativelySupported(this.xref, resources)) {
  9808. // These JPEGs don't need any more processing so we can just send it.
  9809. operatorList.addOp(OPS.paintJpegXObject, args);
  9810. this.handler.send('obj',
  9811. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9812. return;
  9813. }
  9814. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9815. then(function(imageObj) {
  9816. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9817. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9818. [imgData.data.buffer]);
  9819. }).then(undefined, function (reason) {
  9820. warn('Unable to decode image: ' + reason);
  9821. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9822. });
  9823. operatorList.addOp(OPS.paintImageXObject, args);
  9824. if (cacheKey) {
  9825. imageCache[cacheKey] = {
  9826. fn: OPS.paintImageXObject,
  9827. args: args
  9828. };
  9829. }
  9830. },
  9831. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9832. operatorList,
  9833. stateManager) {
  9834. var smaskContent = smask.get('G');
  9835. var smaskOptions = {
  9836. subtype: smask.get('S').name,
  9837. backdrop: smask.get('BC')
  9838. };
  9839. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9840. operatorList, stateManager.state.clone());
  9841. },
  9842. handleTilingType:
  9843. function PartialEvaluator_handleTilingType(fn, args, resources,
  9844. pattern, patternDict,
  9845. operatorList) {
  9846. // Create an IR of the pattern code.
  9847. var tilingOpList = new OperatorList();
  9848. return this.getOperatorList(pattern,
  9849. (patternDict.get('Resources') || resources), tilingOpList).
  9850. then(function () {
  9851. // Add the dependencies to the parent operator list so they are
  9852. // resolved before sub operator list is executed synchronously.
  9853. operatorList.addDependencies(tilingOpList.dependencies);
  9854. operatorList.addOp(fn, getTilingPatternIR({
  9855. fnArray: tilingOpList.fnArray,
  9856. argsArray: tilingOpList.argsArray
  9857. }, patternDict, args));
  9858. });
  9859. },
  9860. handleSetFont:
  9861. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9862. operatorList, state) {
  9863. // TODO(mack): Not needed?
  9864. var fontName;
  9865. if (fontArgs) {
  9866. fontArgs = fontArgs.slice();
  9867. fontName = fontArgs[0].name;
  9868. }
  9869. var self = this;
  9870. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9871. function (translated) {
  9872. if (!translated.font.isType3Font) {
  9873. return translated;
  9874. }
  9875. return translated.loadType3Data(self, resources, operatorList).then(
  9876. function () {
  9877. return translated;
  9878. });
  9879. }).then(function (translated) {
  9880. state.font = translated.font;
  9881. translated.send(self.handler);
  9882. return translated.loadedName;
  9883. });
  9884. },
  9885. handleText: function PartialEvaluator_handleText(chars, state) {
  9886. var font = state.font;
  9887. var glyphs = font.charsToGlyphs(chars);
  9888. var isAddToPathSet = !!(state.textRenderingMode &
  9889. TextRenderingMode.ADD_TO_PATH_FLAG);
  9890. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9891. var buildPath = function (fontChar) {
  9892. if (!font.renderer.hasBuiltPath(fontChar)) {
  9893. var path = font.renderer.getPathJs(fontChar);
  9894. this.handler.send('commonobj', [
  9895. font.loadedName + '_path_' + fontChar,
  9896. 'FontPath',
  9897. path
  9898. ]);
  9899. }
  9900. }.bind(this);
  9901. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9902. var glyph = glyphs[i];
  9903. if (glyph === null) {
  9904. continue;
  9905. }
  9906. buildPath(glyph.fontChar);
  9907. // If the glyph has an accent we need to build a path for its
  9908. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9909. var accent = glyph.accent;
  9910. if (accent && accent.fontChar) {
  9911. buildPath(accent.fontChar);
  9912. }
  9913. }
  9914. }
  9915. return glyphs;
  9916. },
  9917. setGState: function PartialEvaluator_setGState(resources, gState,
  9918. operatorList, xref,
  9919. stateManager) {
  9920. // This array holds the converted/processed state data.
  9921. var gStateObj = [];
  9922. var gStateMap = gState.map;
  9923. var self = this;
  9924. var promise = Promise.resolve();
  9925. for (var key in gStateMap) {
  9926. var value = gStateMap[key];
  9927. switch (key) {
  9928. case 'Type':
  9929. break;
  9930. case 'LW':
  9931. case 'LC':
  9932. case 'LJ':
  9933. case 'ML':
  9934. case 'D':
  9935. case 'RI':
  9936. case 'FL':
  9937. case 'CA':
  9938. case 'ca':
  9939. gStateObj.push([key, value]);
  9940. break;
  9941. case 'Font':
  9942. promise = promise.then(function () {
  9943. return self.handleSetFont(resources, null, value[0],
  9944. operatorList, stateManager.state).
  9945. then(function (loadedName) {
  9946. operatorList.addDependency(loadedName);
  9947. gStateObj.push([key, [loadedName, value[1]]]);
  9948. });
  9949. });
  9950. break;
  9951. case 'BM':
  9952. gStateObj.push([key, value]);
  9953. break;
  9954. case 'SMask':
  9955. if (isName(value) && value.name === 'None') {
  9956. gStateObj.push([key, false]);
  9957. break;
  9958. }
  9959. var dict = xref.fetchIfRef(value);
  9960. if (isDict(dict)) {
  9961. promise = promise.then(function () {
  9962. return self.handleSMask(dict, resources, operatorList,
  9963. stateManager);
  9964. });
  9965. gStateObj.push([key, true]);
  9966. } else {
  9967. warn('Unsupported SMask type');
  9968. }
  9969. break;
  9970. // Only generate info log messages for the following since
  9971. // they are unlikely to have a big impact on the rendering.
  9972. case 'OP':
  9973. case 'op':
  9974. case 'OPM':
  9975. case 'BG':
  9976. case 'BG2':
  9977. case 'UCR':
  9978. case 'UCR2':
  9979. case 'TR':
  9980. case 'TR2':
  9981. case 'HT':
  9982. case 'SM':
  9983. case 'SA':
  9984. case 'AIS':
  9985. case 'TK':
  9986. // TODO implement these operators.
  9987. info('graphic state operator ' + key);
  9988. break;
  9989. default:
  9990. info('Unknown graphic state operator ' + key);
  9991. break;
  9992. }
  9993. }
  9994. return promise.then(function () {
  9995. if (gStateObj.length >= 0) {
  9996. operatorList.addOp(OPS.setGState, [gStateObj]);
  9997. }
  9998. });
  9999. },
  10000. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10001. resources) {
  10002. function errorFont() {
  10003. return Promise.resolve(new TranslatedFont('g_font_error',
  10004. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10005. }
  10006. var fontRef;
  10007. if (font) { // Loading by ref.
  10008. assert(isRef(font));
  10009. fontRef = font;
  10010. } else { // Loading by name.
  10011. var fontRes = resources.get('Font');
  10012. if (fontRes) {
  10013. fontRef = fontRes.getRaw(fontName);
  10014. } else {
  10015. warn('fontRes not available');
  10016. return errorFont();
  10017. }
  10018. }
  10019. if (!fontRef) {
  10020. warn('fontRef not available');
  10021. return errorFont();
  10022. }
  10023. if (this.fontCache.has(fontRef)) {
  10024. return this.fontCache.get(fontRef);
  10025. }
  10026. font = xref.fetchIfRef(fontRef);
  10027. if (!isDict(font)) {
  10028. return errorFont();
  10029. }
  10030. // We are holding font.translated references just for fontRef that are not
  10031. // dictionaries (Dict). See explanation below.
  10032. if (font.translated) {
  10033. return font.translated;
  10034. }
  10035. var fontCapability = createPromiseCapability();
  10036. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10037. var descriptor = preEvaluatedFont.descriptor;
  10038. var fontID = fontRef.num + '_' + fontRef.gen;
  10039. if (isDict(descriptor)) {
  10040. if (!descriptor.fontAliases) {
  10041. descriptor.fontAliases = Object.create(null);
  10042. }
  10043. var fontAliases = descriptor.fontAliases;
  10044. var hash = preEvaluatedFont.hash;
  10045. if (fontAliases[hash]) {
  10046. var aliasFontRef = fontAliases[hash].aliasRef;
  10047. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10048. this.fontCache.putAlias(fontRef, aliasFontRef);
  10049. return this.fontCache.get(fontRef);
  10050. }
  10051. }
  10052. if (!fontAliases[hash]) {
  10053. fontAliases[hash] = {
  10054. fontID: Font.getFontID()
  10055. };
  10056. }
  10057. fontAliases[hash].aliasRef = fontRef;
  10058. fontID = fontAliases[hash].fontID;
  10059. }
  10060. // Workaround for bad PDF generators that don't reference fonts
  10061. // properly, i.e. by not using an object identifier.
  10062. // Check if the fontRef is a Dict (as opposed to a standard object),
  10063. // in which case we don't cache the font and instead reference it by
  10064. // fontName in font.loadedName below.
  10065. var fontRefIsDict = isDict(fontRef);
  10066. if (!fontRefIsDict) {
  10067. this.fontCache.put(fontRef, fontCapability.promise);
  10068. }
  10069. // Keep track of each font we translated so the caller can
  10070. // load them asynchronously before calling display on a page.
  10071. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10072. fontName.replace(/\W/g, '') : fontID);
  10073. font.translated = fontCapability.promise;
  10074. // TODO move promises into translate font
  10075. var translatedPromise;
  10076. try {
  10077. translatedPromise = Promise.resolve(
  10078. this.translateFont(preEvaluatedFont, xref));
  10079. } catch (e) {
  10080. translatedPromise = Promise.reject(e);
  10081. }
  10082. translatedPromise.then(function (translatedFont) {
  10083. if (translatedFont.fontType !== undefined) {
  10084. var xrefFontStats = xref.stats.fontTypes;
  10085. xrefFontStats[translatedFont.fontType] = true;
  10086. }
  10087. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10088. translatedFont, font));
  10089. }, function (reason) {
  10090. // TODO fontCapability.reject?
  10091. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10092. try {
  10093. // error, but it's still nice to have font type reported
  10094. var descriptor = preEvaluatedFont.descriptor;
  10095. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10096. var subtype = fontFile3 && fontFile3.get('Subtype');
  10097. var fontType = getFontType(preEvaluatedFont.type,
  10098. subtype && subtype.name);
  10099. var xrefFontStats = xref.stats.fontTypes;
  10100. xrefFontStats[fontType] = true;
  10101. } catch (ex) { }
  10102. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10103. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10104. font));
  10105. });
  10106. return fontCapability.promise;
  10107. },
  10108. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10109. var lastIndex = operatorList.length - 1;
  10110. if (!args) {
  10111. args = [];
  10112. }
  10113. if (lastIndex < 0 ||
  10114. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10115. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10116. } else {
  10117. var opArgs = operatorList.argsArray[lastIndex];
  10118. opArgs[0].push(fn);
  10119. Array.prototype.push.apply(opArgs[1], args);
  10120. }
  10121. },
  10122. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10123. cs, patterns, resources, xref) {
  10124. // compile tiling patterns
  10125. var patternName = args[args.length - 1];
  10126. // SCN/scn applies patterns along with normal colors
  10127. var pattern;
  10128. if (isName(patternName) &&
  10129. (pattern = patterns.get(patternName.name))) {
  10130. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10131. var typeNum = dict.get('PatternType');
  10132. if (typeNum === TILING_PATTERN) {
  10133. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10134. return this.handleTilingType(fn, color, resources, pattern,
  10135. dict, operatorList);
  10136. } else if (typeNum === SHADING_PATTERN) {
  10137. var shading = dict.get('Shading');
  10138. var matrix = dict.get('Matrix');
  10139. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10140. operatorList.addOp(fn, pattern.getIR());
  10141. return Promise.resolve();
  10142. } else {
  10143. return Promise.reject('Unknown PatternType: ' + typeNum);
  10144. }
  10145. }
  10146. // TODO shall we fail here?
  10147. operatorList.addOp(fn, args);
  10148. return Promise.resolve();
  10149. },
  10150. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10151. resources,
  10152. operatorList,
  10153. initialState) {
  10154. var self = this;
  10155. var xref = this.xref;
  10156. var imageCache = {};
  10157. assert(operatorList);
  10158. resources = (resources || Dict.empty);
  10159. var xobjs = (resources.get('XObject') || Dict.empty);
  10160. var patterns = (resources.get('Pattern') || Dict.empty);
  10161. var stateManager = new StateManager(initialState || new EvalState());
  10162. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10163. var timeSlotManager = new TimeSlotManager();
  10164. return new Promise(function next(resolve, reject) {
  10165. timeSlotManager.reset();
  10166. var stop, operation = {}, i, ii, cs;
  10167. while (!(stop = timeSlotManager.check())) {
  10168. // The arguments parsed by read() are used beyond this loop, so we
  10169. // cannot reuse the same array on each iteration. Therefore we pass
  10170. // in |null| as the initial value (see the comment on
  10171. // EvaluatorPreprocessor_read() for why).
  10172. operation.args = null;
  10173. if (!(preprocessor.read(operation))) {
  10174. break;
  10175. }
  10176. var args = operation.args;
  10177. var fn = operation.fn;
  10178. switch (fn | 0) {
  10179. case OPS.paintXObject:
  10180. if (args[0].code) {
  10181. break;
  10182. }
  10183. // eagerly compile XForm objects
  10184. var name = args[0].name;
  10185. if (imageCache[name] !== undefined) {
  10186. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10187. args = null;
  10188. continue;
  10189. }
  10190. var xobj = xobjs.get(name);
  10191. if (xobj) {
  10192. assert(isStream(xobj), 'XObject should be a stream');
  10193. var type = xobj.dict.get('Subtype');
  10194. assert(isName(type),
  10195. 'XObject should have a Name subtype');
  10196. if (type.name === 'Form') {
  10197. stateManager.save();
  10198. return self.buildFormXObject(resources, xobj, null,
  10199. operatorList,
  10200. stateManager.state.clone()).
  10201. then(function () {
  10202. stateManager.restore();
  10203. next(resolve, reject);
  10204. }, reject);
  10205. } else if (type.name === 'Image') {
  10206. self.buildPaintImageXObject(resources, xobj, false,
  10207. operatorList, name, imageCache);
  10208. args = null;
  10209. continue;
  10210. } else if (type.name === 'PS') {
  10211. // PostScript XObjects are unused when viewing documents.
  10212. // See section 4.7.1 of Adobe's PDF reference.
  10213. info('Ignored XObject subtype PS');
  10214. continue;
  10215. } else {
  10216. error('Unhandled XObject subtype ' + type.name);
  10217. }
  10218. }
  10219. break;
  10220. case OPS.setFont:
  10221. var fontSize = args[1];
  10222. // eagerly collect all fonts
  10223. return self.handleSetFont(resources, args, null,
  10224. operatorList, stateManager.state).
  10225. then(function (loadedName) {
  10226. operatorList.addDependency(loadedName);
  10227. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10228. next(resolve, reject);
  10229. }, reject);
  10230. case OPS.endInlineImage:
  10231. var cacheKey = args[0].cacheKey;
  10232. if (cacheKey) {
  10233. var cacheEntry = imageCache[cacheKey];
  10234. if (cacheEntry !== undefined) {
  10235. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10236. args = null;
  10237. continue;
  10238. }
  10239. }
  10240. self.buildPaintImageXObject(resources, args[0], true,
  10241. operatorList, cacheKey, imageCache);
  10242. args = null;
  10243. continue;
  10244. case OPS.showText:
  10245. args[0] = self.handleText(args[0], stateManager.state);
  10246. break;
  10247. case OPS.showSpacedText:
  10248. var arr = args[0];
  10249. var combinedGlyphs = [];
  10250. var arrLength = arr.length;
  10251. for (i = 0; i < arrLength; ++i) {
  10252. var arrItem = arr[i];
  10253. if (isString(arrItem)) {
  10254. Array.prototype.push.apply(combinedGlyphs,
  10255. self.handleText(arrItem, stateManager.state));
  10256. } else if (isNum(arrItem)) {
  10257. combinedGlyphs.push(arrItem);
  10258. }
  10259. }
  10260. args[0] = combinedGlyphs;
  10261. fn = OPS.showText;
  10262. break;
  10263. case OPS.nextLineShowText:
  10264. operatorList.addOp(OPS.nextLine);
  10265. args[0] = self.handleText(args[0], stateManager.state);
  10266. fn = OPS.showText;
  10267. break;
  10268. case OPS.nextLineSetSpacingShowText:
  10269. operatorList.addOp(OPS.nextLine);
  10270. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10271. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10272. args[0] = self.handleText(args[0], stateManager.state);
  10273. fn = OPS.showText;
  10274. break;
  10275. case OPS.setTextRenderingMode:
  10276. stateManager.state.textRenderingMode = args[0];
  10277. break;
  10278. case OPS.setFillColorSpace:
  10279. stateManager.state.fillColorSpace =
  10280. ColorSpace.parse(args[0], xref, resources);
  10281. continue;
  10282. case OPS.setStrokeColorSpace:
  10283. stateManager.state.strokeColorSpace =
  10284. ColorSpace.parse(args[0], xref, resources);
  10285. continue;
  10286. case OPS.setFillColor:
  10287. cs = stateManager.state.fillColorSpace;
  10288. args = cs.getRgb(args, 0);
  10289. fn = OPS.setFillRGBColor;
  10290. break;
  10291. case OPS.setStrokeColor:
  10292. cs = stateManager.state.strokeColorSpace;
  10293. args = cs.getRgb(args, 0);
  10294. fn = OPS.setStrokeRGBColor;
  10295. break;
  10296. case OPS.setFillGray:
  10297. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10298. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10299. fn = OPS.setFillRGBColor;
  10300. break;
  10301. case OPS.setStrokeGray:
  10302. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10303. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10304. fn = OPS.setStrokeRGBColor;
  10305. break;
  10306. case OPS.setFillCMYKColor:
  10307. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10308. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10309. fn = OPS.setFillRGBColor;
  10310. break;
  10311. case OPS.setStrokeCMYKColor:
  10312. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10313. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10314. fn = OPS.setStrokeRGBColor;
  10315. break;
  10316. case OPS.setFillRGBColor:
  10317. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10318. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10319. break;
  10320. case OPS.setStrokeRGBColor:
  10321. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10322. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10323. break;
  10324. case OPS.setFillColorN:
  10325. cs = stateManager.state.fillColorSpace;
  10326. if (cs.name === 'Pattern') {
  10327. return self.handleColorN(operatorList, OPS.setFillColorN,
  10328. args, cs, patterns, resources, xref).then(function() {
  10329. next(resolve, reject);
  10330. }, reject);
  10331. }
  10332. args = cs.getRgb(args, 0);
  10333. fn = OPS.setFillRGBColor;
  10334. break;
  10335. case OPS.setStrokeColorN:
  10336. cs = stateManager.state.strokeColorSpace;
  10337. if (cs.name === 'Pattern') {
  10338. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10339. args, cs, patterns, resources, xref).then(function() {
  10340. next(resolve, reject);
  10341. }, reject);
  10342. }
  10343. args = cs.getRgb(args, 0);
  10344. fn = OPS.setStrokeRGBColor;
  10345. break;
  10346. case OPS.shadingFill:
  10347. var shadingRes = resources.get('Shading');
  10348. if (!shadingRes) {
  10349. error('No shading resource found');
  10350. }
  10351. var shading = shadingRes.get(args[0].name);
  10352. if (!shading) {
  10353. error('No shading object found');
  10354. }
  10355. var shadingFill = Pattern.parseShading(shading, null, xref,
  10356. resources);
  10357. var patternIR = shadingFill.getIR();
  10358. args = [patternIR];
  10359. fn = OPS.shadingFill;
  10360. break;
  10361. case OPS.setGState:
  10362. var dictName = args[0];
  10363. var extGState = resources.get('ExtGState');
  10364. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10365. break;
  10366. }
  10367. var gState = extGState.get(dictName.name);
  10368. return self.setGState(resources, gState, operatorList, xref,
  10369. stateManager).then(function() {
  10370. next(resolve, reject);
  10371. }, reject);
  10372. case OPS.moveTo:
  10373. case OPS.lineTo:
  10374. case OPS.curveTo:
  10375. case OPS.curveTo2:
  10376. case OPS.curveTo3:
  10377. case OPS.closePath:
  10378. self.buildPath(operatorList, fn, args);
  10379. continue;
  10380. case OPS.rectangle:
  10381. self.buildPath(operatorList, fn, args);
  10382. continue;
  10383. }
  10384. operatorList.addOp(fn, args);
  10385. }
  10386. if (stop) {
  10387. deferred.then(function () {
  10388. next(resolve, reject);
  10389. });
  10390. return;
  10391. }
  10392. // Some PDFs don't close all restores inside object/form.
  10393. // Closing those for them.
  10394. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10395. operatorList.addOp(OPS.restore, []);
  10396. }
  10397. resolve();
  10398. });
  10399. },
  10400. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10401. stateManager) {
  10402. stateManager = (stateManager || new StateManager(new TextState()));
  10403. var textContent = {
  10404. items: [],
  10405. styles: Object.create(null)
  10406. };
  10407. var bidiTexts = textContent.items;
  10408. var SPACE_FACTOR = 0.3;
  10409. var MULTI_SPACE_FACTOR = 1.5;
  10410. var self = this;
  10411. var xref = this.xref;
  10412. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10413. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10414. var xobjs = null;
  10415. var xobjsCache = {};
  10416. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10417. var textState;
  10418. function newTextChunk() {
  10419. var font = textState.font;
  10420. if (!(font.loadedName in textContent.styles)) {
  10421. textContent.styles[font.loadedName] = {
  10422. fontFamily: font.fallbackName,
  10423. ascent: font.ascent,
  10424. descent: font.descent,
  10425. vertical: font.vertical
  10426. };
  10427. }
  10428. return {
  10429. // |str| is initially an array which we push individual chars to, and
  10430. // then runBidi() overwrites it with the final string.
  10431. str: [],
  10432. dir: null,
  10433. width: 0,
  10434. height: 0,
  10435. transform: null,
  10436. fontName: font.loadedName
  10437. };
  10438. }
  10439. function runBidi(textChunk) {
  10440. var str = textChunk.str.join('');
  10441. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10442. textChunk.str = bidiResult.str;
  10443. textChunk.dir = bidiResult.dir;
  10444. return textChunk;
  10445. }
  10446. function handleSetFont(fontName, fontRef) {
  10447. return self.loadFont(fontName, fontRef, xref, resources).
  10448. then(function (translated) {
  10449. textState.font = translated.font;
  10450. textState.fontMatrix = translated.font.fontMatrix ||
  10451. FONT_IDENTITY_MATRIX;
  10452. });
  10453. }
  10454. function buildTextGeometry(chars, textChunk) {
  10455. var font = textState.font;
  10456. textChunk = textChunk || newTextChunk();
  10457. if (!textChunk.transform) {
  10458. // 9.4.4 Text Space Details
  10459. var tsm = [textState.fontSize * textState.textHScale, 0,
  10460. 0, textState.fontSize,
  10461. 0, textState.textRise];
  10462. if (font.isType3Font &&
  10463. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10464. textState.fontSize === 1) {
  10465. var glyphHeight = font.bbox[3] - font.bbox[1];
  10466. if (glyphHeight > 0) {
  10467. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10468. tsm[3] *= glyphHeight;
  10469. }
  10470. }
  10471. var trm = textChunk.transform = Util.transform(textState.ctm,
  10472. Util.transform(textState.textMatrix, tsm));
  10473. if (!font.vertical) {
  10474. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10475. } else {
  10476. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10477. }
  10478. }
  10479. var width = 0;
  10480. var height = 0;
  10481. var glyphs = font.charsToGlyphs(chars);
  10482. var defaultVMetrics = font.defaultVMetrics;
  10483. for (var i = 0; i < glyphs.length; i++) {
  10484. var glyph = glyphs[i];
  10485. if (!glyph) { // Previous glyph was a space.
  10486. width += textState.wordSpacing * textState.textHScale;
  10487. continue;
  10488. }
  10489. var vMetricX = null;
  10490. var vMetricY = null;
  10491. var glyphWidth = null;
  10492. if (font.vertical) {
  10493. if (glyph.vmetric) {
  10494. glyphWidth = glyph.vmetric[0];
  10495. vMetricX = glyph.vmetric[1];
  10496. vMetricY = glyph.vmetric[2];
  10497. } else {
  10498. glyphWidth = glyph.width;
  10499. vMetricX = glyph.width * 0.5;
  10500. vMetricY = defaultVMetrics[2];
  10501. }
  10502. } else {
  10503. glyphWidth = glyph.width;
  10504. }
  10505. var glyphUnicode = glyph.unicode;
  10506. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10507. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10508. }
  10509. glyphUnicode = reverseIfRtl(glyphUnicode);
  10510. // The following will calculate the x and y of the individual glyphs.
  10511. // if (font.vertical) {
  10512. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10513. // textState.fontMatrix[0];
  10514. // tsm[5] -= vMetricY * textState.fontSize *
  10515. // textState.fontMatrix[0];
  10516. // }
  10517. // var trm = Util.transform(textState.textMatrix, tsm);
  10518. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10519. // var x = pt[0];
  10520. // var y = pt[1];
  10521. var charSpacing = 0;
  10522. if (textChunk.str.length > 0) {
  10523. // Apply char spacing only when there are chars.
  10524. // As a result there is only spacing between glyphs.
  10525. charSpacing = textState.charSpacing;
  10526. }
  10527. var tx = 0;
  10528. var ty = 0;
  10529. if (!font.vertical) {
  10530. var w0 = glyphWidth * textState.fontMatrix[0];
  10531. tx = (w0 * textState.fontSize + charSpacing) *
  10532. textState.textHScale;
  10533. width += tx;
  10534. } else {
  10535. var w1 = glyphWidth * textState.fontMatrix[0];
  10536. ty = w1 * textState.fontSize + charSpacing;
  10537. height += ty;
  10538. }
  10539. textState.translateTextMatrix(tx, ty);
  10540. textChunk.str.push(glyphUnicode);
  10541. }
  10542. var a = textState.textLineMatrix[0];
  10543. var b = textState.textLineMatrix[1];
  10544. var scaleLineX = Math.sqrt(a * a + b * b);
  10545. a = textState.ctm[0];
  10546. b = textState.ctm[1];
  10547. var scaleCtmX = Math.sqrt(a * a + b * b);
  10548. if (!font.vertical) {
  10549. textChunk.width += width * scaleCtmX * scaleLineX;
  10550. } else {
  10551. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10552. }
  10553. return textChunk;
  10554. }
  10555. var timeSlotManager = new TimeSlotManager();
  10556. return new Promise(function next(resolve, reject) {
  10557. timeSlotManager.reset();
  10558. var stop, operation = {}, args = [];
  10559. while (!(stop = timeSlotManager.check())) {
  10560. // The arguments parsed by read() are not used beyond this loop, so
  10561. // we can reuse the same array on every iteration, thus avoiding
  10562. // unnecessary allocations.
  10563. args.length = 0;
  10564. operation.args = args;
  10565. if (!(preprocessor.read(operation))) {
  10566. break;
  10567. }
  10568. textState = stateManager.state;
  10569. var fn = operation.fn;
  10570. args = operation.args;
  10571. switch (fn | 0) {
  10572. case OPS.setFont:
  10573. textState.fontSize = args[1];
  10574. return handleSetFont(args[0].name).then(function() {
  10575. next(resolve, reject);
  10576. }, reject);
  10577. case OPS.setTextRise:
  10578. textState.textRise = args[0];
  10579. break;
  10580. case OPS.setHScale:
  10581. textState.textHScale = args[0] / 100;
  10582. break;
  10583. case OPS.setLeading:
  10584. textState.leading = args[0];
  10585. break;
  10586. case OPS.moveText:
  10587. textState.translateTextLineMatrix(args[0], args[1]);
  10588. textState.textMatrix = textState.textLineMatrix.slice();
  10589. break;
  10590. case OPS.setLeadingMoveText:
  10591. textState.leading = -args[1];
  10592. textState.translateTextLineMatrix(args[0], args[1]);
  10593. textState.textMatrix = textState.textLineMatrix.slice();
  10594. break;
  10595. case OPS.nextLine:
  10596. textState.carriageReturn();
  10597. break;
  10598. case OPS.setTextMatrix:
  10599. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10600. args[4], args[5]);
  10601. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10602. args[4], args[5]);
  10603. break;
  10604. case OPS.setCharSpacing:
  10605. textState.charSpacing = args[0];
  10606. break;
  10607. case OPS.setWordSpacing:
  10608. textState.wordSpacing = args[0];
  10609. break;
  10610. case OPS.beginText:
  10611. textState.textMatrix = IDENTITY_MATRIX.slice();
  10612. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10613. break;
  10614. case OPS.showSpacedText:
  10615. var items = args[0];
  10616. var textChunk = newTextChunk();
  10617. var offset;
  10618. for (var j = 0, jj = items.length; j < jj; j++) {
  10619. if (typeof items[j] === 'string') {
  10620. buildTextGeometry(items[j], textChunk);
  10621. } else {
  10622. var val = items[j] / 1000;
  10623. if (!textState.font.vertical) {
  10624. offset = -val * textState.fontSize * textState.textHScale *
  10625. textState.textMatrix[0];
  10626. textState.translateTextMatrix(offset, 0);
  10627. textChunk.width += offset;
  10628. } else {
  10629. offset = -val * textState.fontSize *
  10630. textState.textMatrix[3];
  10631. textState.translateTextMatrix(0, offset);
  10632. textChunk.height += offset;
  10633. }
  10634. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10635. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10636. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10637. fakeSpaces = Math.round(fakeSpaces);
  10638. while (fakeSpaces--) {
  10639. textChunk.str.push(' ');
  10640. }
  10641. } else if (fakeSpaces > SPACE_FACTOR) {
  10642. textChunk.str.push(' ');
  10643. }
  10644. }
  10645. }
  10646. }
  10647. bidiTexts.push(runBidi(textChunk));
  10648. break;
  10649. case OPS.showText:
  10650. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10651. break;
  10652. case OPS.nextLineShowText:
  10653. textState.carriageReturn();
  10654. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10655. break;
  10656. case OPS.nextLineSetSpacingShowText:
  10657. textState.wordSpacing = args[0];
  10658. textState.charSpacing = args[1];
  10659. textState.carriageReturn();
  10660. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10661. break;
  10662. case OPS.paintXObject:
  10663. if (args[0].code) {
  10664. break;
  10665. }
  10666. if (!xobjs) {
  10667. xobjs = (resources.get('XObject') || Dict.empty);
  10668. }
  10669. var name = args[0].name;
  10670. if (xobjsCache.key === name) {
  10671. if (xobjsCache.texts) {
  10672. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10673. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10674. }
  10675. break;
  10676. }
  10677. var xobj = xobjs.get(name);
  10678. if (!xobj) {
  10679. break;
  10680. }
  10681. assert(isStream(xobj), 'XObject should be a stream');
  10682. var type = xobj.dict.get('Subtype');
  10683. assert(isName(type),
  10684. 'XObject should have a Name subtype');
  10685. if ('Form' !== type.name) {
  10686. xobjsCache.key = name;
  10687. xobjsCache.texts = null;
  10688. break;
  10689. }
  10690. stateManager.save();
  10691. var matrix = xobj.dict.get('Matrix');
  10692. if (isArray(matrix) && matrix.length === 6) {
  10693. stateManager.transform(matrix);
  10694. }
  10695. return self.getTextContent(xobj,
  10696. xobj.dict.get('Resources') || resources, stateManager).
  10697. then(function (formTextContent) {
  10698. Util.appendToArray(bidiTexts, formTextContent.items);
  10699. Util.extendObj(textContent.styles, formTextContent.styles);
  10700. stateManager.restore();
  10701. xobjsCache.key = name;
  10702. xobjsCache.texts = formTextContent;
  10703. next(resolve, reject);
  10704. }, reject);
  10705. case OPS.setGState:
  10706. var dictName = args[0];
  10707. var extGState = resources.get('ExtGState');
  10708. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10709. break;
  10710. }
  10711. var gsStateMap = extGState.get(dictName.name);
  10712. var gsStateFont = null;
  10713. for (var key in gsStateMap) {
  10714. if (key === 'Font') {
  10715. assert(!gsStateFont);
  10716. gsStateFont = gsStateMap[key];
  10717. }
  10718. }
  10719. if (gsStateFont) {
  10720. textState.fontSize = gsStateFont[1];
  10721. return handleSetFont(gsStateFont[0]).then(function() {
  10722. next(resolve, reject);
  10723. }, reject);
  10724. }
  10725. break;
  10726. } // switch
  10727. } // while
  10728. if (stop) {
  10729. deferred.then(function () {
  10730. next(resolve, reject);
  10731. });
  10732. return;
  10733. }
  10734. resolve(textContent);
  10735. });
  10736. },
  10737. extractDataStructures: function
  10738. partialEvaluatorExtractDataStructures(dict, baseDict,
  10739. xref, properties) {
  10740. // 9.10.2
  10741. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10742. if (toUnicode) {
  10743. properties.toUnicode = this.readToUnicode(toUnicode);
  10744. }
  10745. if (properties.composite) {
  10746. // CIDSystemInfo helps to match CID to glyphs
  10747. var cidSystemInfo = dict.get('CIDSystemInfo');
  10748. if (isDict(cidSystemInfo)) {
  10749. properties.cidSystemInfo = {
  10750. registry: cidSystemInfo.get('Registry'),
  10751. ordering: cidSystemInfo.get('Ordering'),
  10752. supplement: cidSystemInfo.get('Supplement')
  10753. };
  10754. }
  10755. var cidToGidMap = dict.get('CIDToGIDMap');
  10756. if (isStream(cidToGidMap)) {
  10757. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10758. }
  10759. }
  10760. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10761. // and depends on the font type. The base encoding and differences are
  10762. // read here, but the encoding that is actually used is chosen during
  10763. // glyph mapping in the font.
  10764. // TODO: Loading the built in encoding in the font would allow the
  10765. // differences to be merged in here not require us to hold on to it.
  10766. var differences = [];
  10767. var baseEncodingName = null;
  10768. var encoding;
  10769. if (dict.has('Encoding')) {
  10770. encoding = dict.get('Encoding');
  10771. if (isDict(encoding)) {
  10772. baseEncodingName = encoding.get('BaseEncoding');
  10773. baseEncodingName = (isName(baseEncodingName) ?
  10774. baseEncodingName.name : null);
  10775. // Load the differences between the base and original
  10776. if (encoding.has('Differences')) {
  10777. var diffEncoding = encoding.get('Differences');
  10778. var index = 0;
  10779. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10780. var data = diffEncoding[j];
  10781. if (isNum(data)) {
  10782. index = data;
  10783. } else if (isName(data)) {
  10784. differences[index++] = data.name;
  10785. } else if (isRef(data)) {
  10786. diffEncoding[j--] = xref.fetch(data);
  10787. continue;
  10788. } else {
  10789. error('Invalid entry in \'Differences\' array: ' + data);
  10790. }
  10791. }
  10792. }
  10793. } else if (isName(encoding)) {
  10794. baseEncodingName = encoding.name;
  10795. } else {
  10796. error('Encoding is not a Name nor a Dict');
  10797. }
  10798. // According to table 114 if the encoding is a named encoding it must be
  10799. // one of these predefined encodings.
  10800. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10801. baseEncodingName !== 'MacExpertEncoding' &&
  10802. baseEncodingName !== 'WinAnsiEncoding')) {
  10803. baseEncodingName = null;
  10804. }
  10805. }
  10806. if (baseEncodingName) {
  10807. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10808. } else {
  10809. encoding = (properties.type === 'TrueType' ?
  10810. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10811. // The Symbolic attribute can be misused for regular fonts
  10812. // Heuristic: we have to check if the font is a standard one also
  10813. if (!!(properties.flags & FontFlags.Symbolic)) {
  10814. encoding = Encodings.MacRomanEncoding;
  10815. if (!properties.file) {
  10816. if (/Symbol/i.test(properties.name)) {
  10817. encoding = Encodings.SymbolSetEncoding;
  10818. } else if (/Dingbats/i.test(properties.name)) {
  10819. encoding = Encodings.ZapfDingbatsEncoding;
  10820. }
  10821. }
  10822. }
  10823. properties.defaultEncoding = encoding;
  10824. }
  10825. properties.differences = differences;
  10826. properties.baseEncodingName = baseEncodingName;
  10827. properties.dict = dict;
  10828. },
  10829. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10830. var cmap, cmapObj = toUnicode;
  10831. if (isName(cmapObj)) {
  10832. cmap = CMapFactory.create(cmapObj,
  10833. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10834. if (cmap instanceof IdentityCMap) {
  10835. return new IdentityToUnicodeMap(0, 0xFFFF);
  10836. }
  10837. return new ToUnicodeMap(cmap.getMap());
  10838. } else if (isStream(cmapObj)) {
  10839. cmap = CMapFactory.create(cmapObj,
  10840. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10841. if (cmap instanceof IdentityCMap) {
  10842. return new IdentityToUnicodeMap(0, 0xFFFF);
  10843. }
  10844. cmap = cmap.getMap();
  10845. // Convert UTF-16BE
  10846. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10847. // to iterate over all keys.
  10848. cmap.forEach(function(token, i) {
  10849. var str = [];
  10850. for (var k = 0; k < token.length; k += 2) {
  10851. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10852. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10853. str.push(w1);
  10854. continue;
  10855. }
  10856. k += 2;
  10857. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10858. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10859. }
  10860. cmap[i] = String.fromCharCode.apply(String, str);
  10861. });
  10862. return new ToUnicodeMap(cmap);
  10863. }
  10864. return null;
  10865. },
  10866. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10867. // Extract the encoding from the CIDToGIDMap
  10868. var glyphsData = cidToGidStream.getBytes();
  10869. // Set encoding 0 to later verify the font has an encoding
  10870. var result = [];
  10871. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10872. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10873. if (glyphID === 0) {
  10874. continue;
  10875. }
  10876. var code = j >> 1;
  10877. result[code] = glyphID;
  10878. }
  10879. return result;
  10880. },
  10881. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10882. descriptor,
  10883. properties) {
  10884. var glyphsWidths = [];
  10885. var defaultWidth = 0;
  10886. var glyphsVMetrics = [];
  10887. var defaultVMetrics;
  10888. var i, ii, j, jj, start, code, widths;
  10889. if (properties.composite) {
  10890. defaultWidth = dict.get('DW') || 1000;
  10891. widths = dict.get('W');
  10892. if (widths) {
  10893. for (i = 0, ii = widths.length; i < ii; i++) {
  10894. start = widths[i++];
  10895. code = xref.fetchIfRef(widths[i]);
  10896. if (isArray(code)) {
  10897. for (j = 0, jj = code.length; j < jj; j++) {
  10898. glyphsWidths[start++] = code[j];
  10899. }
  10900. } else {
  10901. var width = widths[++i];
  10902. for (j = start; j <= code; j++) {
  10903. glyphsWidths[j] = width;
  10904. }
  10905. }
  10906. }
  10907. }
  10908. if (properties.vertical) {
  10909. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10910. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10911. vmetrics = dict.get('W2');
  10912. if (vmetrics) {
  10913. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10914. start = vmetrics[i++];
  10915. code = xref.fetchIfRef(vmetrics[i]);
  10916. if (isArray(code)) {
  10917. for (j = 0, jj = code.length; j < jj; j++) {
  10918. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10919. }
  10920. } else {
  10921. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10922. for (j = start; j <= code; j++) {
  10923. glyphsVMetrics[j] = vmetric;
  10924. }
  10925. }
  10926. }
  10927. }
  10928. }
  10929. } else {
  10930. var firstChar = properties.firstChar;
  10931. widths = dict.get('Widths');
  10932. if (widths) {
  10933. j = firstChar;
  10934. for (i = 0, ii = widths.length; i < ii; i++) {
  10935. glyphsWidths[j++] = widths[i];
  10936. }
  10937. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10938. } else {
  10939. // Trying get the BaseFont metrics (see comment above).
  10940. var baseFontName = dict.get('BaseFont');
  10941. if (isName(baseFontName)) {
  10942. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10943. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10944. properties);
  10945. defaultWidth = metrics.defaultWidth;
  10946. }
  10947. }
  10948. }
  10949. // Heuristic: detection of monospace font by checking all non-zero widths
  10950. var isMonospace = true;
  10951. var firstWidth = defaultWidth;
  10952. for (var glyph in glyphsWidths) {
  10953. var glyphWidth = glyphsWidths[glyph];
  10954. if (!glyphWidth) {
  10955. continue;
  10956. }
  10957. if (!firstWidth) {
  10958. firstWidth = glyphWidth;
  10959. continue;
  10960. }
  10961. if (firstWidth !== glyphWidth) {
  10962. isMonospace = false;
  10963. break;
  10964. }
  10965. }
  10966. if (isMonospace) {
  10967. properties.flags |= FontFlags.FixedPitch;
  10968. }
  10969. properties.defaultWidth = defaultWidth;
  10970. properties.widths = glyphsWidths;
  10971. properties.defaultVMetrics = defaultVMetrics;
  10972. properties.vmetrics = glyphsVMetrics;
  10973. },
  10974. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10975. // Simulating descriptor flags attribute
  10976. var fontNameWoStyle = baseFontName.split('-')[0];
  10977. return (fontNameWoStyle in serifFonts) ||
  10978. (fontNameWoStyle.search(/serif/gi) !== -1);
  10979. },
  10980. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10981. var defaultWidth = 0;
  10982. var widths = [];
  10983. var monospace = false;
  10984. var lookupName = (stdFontMap[name] || name);
  10985. if (!(lookupName in Metrics)) {
  10986. // Use default fonts for looking up font metrics if the passed
  10987. // font is not a base font
  10988. if (this.isSerifFont(name)) {
  10989. lookupName = 'Times-Roman';
  10990. } else {
  10991. lookupName = 'Helvetica';
  10992. }
  10993. }
  10994. var glyphWidths = Metrics[lookupName];
  10995. if (isNum(glyphWidths)) {
  10996. defaultWidth = glyphWidths;
  10997. monospace = true;
  10998. } else {
  10999. widths = glyphWidths;
  11000. }
  11001. return {
  11002. defaultWidth: defaultWidth,
  11003. monospace: monospace,
  11004. widths: widths
  11005. };
  11006. },
  11007. buildCharCodeToWidth:
  11008. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11009. properties) {
  11010. var widths = Object.create(null);
  11011. var differences = properties.differences;
  11012. var encoding = properties.defaultEncoding;
  11013. for (var charCode = 0; charCode < 256; charCode++) {
  11014. if (charCode in differences &&
  11015. widthsByGlyphName[differences[charCode]]) {
  11016. widths[charCode] = widthsByGlyphName[differences[charCode]];
  11017. continue;
  11018. }
  11019. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  11020. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  11021. continue;
  11022. }
  11023. }
  11024. return widths;
  11025. },
  11026. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  11027. var baseDict = dict;
  11028. var type = dict.get('Subtype');
  11029. assert(isName(type), 'invalid font Subtype');
  11030. var composite = false;
  11031. var uint8array;
  11032. if (type.name === 'Type0') {
  11033. // If font is a composite
  11034. // - get the descendant font
  11035. // - set the type according to the descendant font
  11036. // - get the FontDescriptor from the descendant font
  11037. var df = dict.get('DescendantFonts');
  11038. if (!df) {
  11039. error('Descendant fonts are not specified');
  11040. }
  11041. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  11042. type = dict.get('Subtype');
  11043. assert(isName(type), 'invalid font Subtype');
  11044. composite = true;
  11045. }
  11046. var descriptor = dict.get('FontDescriptor');
  11047. if (descriptor) {
  11048. var hash = new MurmurHash3_64();
  11049. var encoding = baseDict.getRaw('Encoding');
  11050. if (isName(encoding)) {
  11051. hash.update(encoding.name);
  11052. } else if (isRef(encoding)) {
  11053. hash.update(encoding.num + '_' + encoding.gen);
  11054. } else if (isDict(encoding)) {
  11055. var keys = encoding.getKeys();
  11056. for (var i = 0, ii = keys.length; i < ii; i++) {
  11057. var entry = encoding.getRaw(keys[i]);
  11058. if (isName(entry)) {
  11059. hash.update(entry.name);
  11060. } else if (isRef(entry)) {
  11061. hash.update(entry.num + '_' + entry.gen);
  11062. } else if (isArray(entry)) { // 'Differences' entry.
  11063. // Ideally we should check the contents of the array, but to avoid
  11064. // parsing it here and then again in |extractDataStructures|,
  11065. // we only use the array length for now (fixes bug1157493.pdf).
  11066. hash.update(entry.length.toString());
  11067. }
  11068. }
  11069. }
  11070. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11071. if (isStream(toUnicode)) {
  11072. var stream = toUnicode.str || toUnicode;
  11073. uint8array = stream.buffer ?
  11074. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11075. new Uint8Array(stream.bytes.buffer,
  11076. stream.start, stream.end - stream.start);
  11077. hash.update(uint8array);
  11078. } else if (isName(toUnicode)) {
  11079. hash.update(toUnicode.name);
  11080. }
  11081. var widths = dict.get('Widths') || baseDict.get('Widths');
  11082. if (widths) {
  11083. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11084. hash.update(uint8array);
  11085. }
  11086. }
  11087. return {
  11088. descriptor: descriptor,
  11089. dict: dict,
  11090. baseDict: baseDict,
  11091. composite: composite,
  11092. type: type.name,
  11093. hash: hash ? hash.hexdigest() : ''
  11094. };
  11095. },
  11096. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11097. xref) {
  11098. var baseDict = preEvaluatedFont.baseDict;
  11099. var dict = preEvaluatedFont.dict;
  11100. var composite = preEvaluatedFont.composite;
  11101. var descriptor = preEvaluatedFont.descriptor;
  11102. var type = preEvaluatedFont.type;
  11103. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11104. var properties;
  11105. if (!descriptor) {
  11106. if (type === 'Type3') {
  11107. // FontDescriptor is only required for Type3 fonts when the document
  11108. // is a tagged pdf. Create a barbebones one to get by.
  11109. descriptor = new Dict(null);
  11110. descriptor.set('FontName', Name.get(type));
  11111. descriptor.set('FontBBox', dict.get('FontBBox'));
  11112. } else {
  11113. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11114. // FontDescriptor was not required.
  11115. // This case is here for compatibility.
  11116. var baseFontName = dict.get('BaseFont');
  11117. if (!isName(baseFontName)) {
  11118. error('Base font is not specified');
  11119. }
  11120. // Using base font name as a font name.
  11121. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11122. var metrics = this.getBaseFontMetrics(baseFontName);
  11123. // Simulating descriptor flags attribute
  11124. var fontNameWoStyle = baseFontName.split('-')[0];
  11125. var flags =
  11126. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11127. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11128. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11129. FontFlags.Nonsymbolic);
  11130. properties = {
  11131. type: type,
  11132. name: baseFontName,
  11133. widths: metrics.widths,
  11134. defaultWidth: metrics.defaultWidth,
  11135. flags: flags,
  11136. firstChar: 0,
  11137. lastChar: maxCharIndex
  11138. };
  11139. this.extractDataStructures(dict, dict, xref, properties);
  11140. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11141. properties);
  11142. return new Font(baseFontName, null, properties);
  11143. }
  11144. }
  11145. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11146. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11147. // to ignore this rule when a variant of a standart font is used.
  11148. // TODO Fill the width array depending on which of the base font this is
  11149. // a variant.
  11150. var firstChar = (dict.get('FirstChar') || 0);
  11151. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11152. var fontName = descriptor.get('FontName');
  11153. var baseFont = dict.get('BaseFont');
  11154. // Some bad PDFs have a string as the font name.
  11155. if (isString(fontName)) {
  11156. fontName = Name.get(fontName);
  11157. }
  11158. if (isString(baseFont)) {
  11159. baseFont = Name.get(baseFont);
  11160. }
  11161. if (type !== 'Type3') {
  11162. var fontNameStr = fontName && fontName.name;
  11163. var baseFontStr = baseFont && baseFont.name;
  11164. if (fontNameStr !== baseFontStr) {
  11165. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11166. '" but should be the same as the Font\'s BaseFont "' +
  11167. baseFontStr + '"');
  11168. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11169. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11170. if (fontNameStr && baseFontStr &&
  11171. baseFontStr.indexOf(fontNameStr) === 0) {
  11172. fontName = baseFont;
  11173. }
  11174. }
  11175. }
  11176. fontName = (fontName || baseFont);
  11177. assert(isName(fontName), 'invalid font name');
  11178. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11179. if (fontFile) {
  11180. if (fontFile.dict) {
  11181. var subtype = fontFile.dict.get('Subtype');
  11182. if (subtype) {
  11183. subtype = subtype.name;
  11184. }
  11185. var length1 = fontFile.dict.get('Length1');
  11186. var length2 = fontFile.dict.get('Length2');
  11187. }
  11188. }
  11189. properties = {
  11190. type: type,
  11191. name: fontName.name,
  11192. subtype: subtype,
  11193. file: fontFile,
  11194. length1: length1,
  11195. length2: length2,
  11196. loadedName: baseDict.loadedName,
  11197. composite: composite,
  11198. wideChars: composite,
  11199. fixedPitch: false,
  11200. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11201. firstChar: firstChar || 0,
  11202. lastChar: (lastChar || maxCharIndex),
  11203. bbox: descriptor.get('FontBBox'),
  11204. ascent: descriptor.get('Ascent'),
  11205. descent: descriptor.get('Descent'),
  11206. xHeight: descriptor.get('XHeight'),
  11207. capHeight: descriptor.get('CapHeight'),
  11208. flags: descriptor.get('Flags'),
  11209. italicAngle: descriptor.get('ItalicAngle'),
  11210. coded: false
  11211. };
  11212. if (composite) {
  11213. var cidEncoding = baseDict.get('Encoding');
  11214. if (isName(cidEncoding)) {
  11215. properties.cidEncoding = cidEncoding.name;
  11216. }
  11217. properties.cMap = CMapFactory.create(cidEncoding,
  11218. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11219. properties.vertical = properties.cMap.vertical;
  11220. }
  11221. this.extractDataStructures(dict, baseDict, xref, properties);
  11222. this.extractWidths(dict, xref, descriptor, properties);
  11223. if (type === 'Type3') {
  11224. properties.isType3Font = true;
  11225. }
  11226. return new Font(fontName.name, fontFile, properties);
  11227. }
  11228. };
  11229. return PartialEvaluator;
  11230. })();
  11231. var TranslatedFont = (function TranslatedFontClosure() {
  11232. function TranslatedFont(loadedName, font, dict) {
  11233. this.loadedName = loadedName;
  11234. this.font = font;
  11235. this.dict = dict;
  11236. this.type3Loaded = null;
  11237. this.sent = false;
  11238. }
  11239. TranslatedFont.prototype = {
  11240. send: function (handler) {
  11241. if (this.sent) {
  11242. return;
  11243. }
  11244. var fontData = this.font.exportData();
  11245. handler.send('commonobj', [
  11246. this.loadedName,
  11247. 'Font',
  11248. fontData
  11249. ]);
  11250. this.sent = true;
  11251. },
  11252. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11253. assert(this.font.isType3Font);
  11254. if (this.type3Loaded) {
  11255. return this.type3Loaded;
  11256. }
  11257. var translatedFont = this.font;
  11258. var loadCharProcsPromise = Promise.resolve();
  11259. var charProcs = this.dict.get('CharProcs').getAll();
  11260. var fontResources = this.dict.get('Resources') || resources;
  11261. var charProcKeys = Object.keys(charProcs);
  11262. var charProcOperatorList = {};
  11263. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11264. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11265. var glyphStream = charProcs[key];
  11266. var operatorList = new OperatorList();
  11267. return evaluator.getOperatorList(glyphStream, fontResources,
  11268. operatorList).then(function () {
  11269. charProcOperatorList[key] = operatorList.getIR();
  11270. // Add the dependencies to the parent operator list so they are
  11271. // resolved before sub operator list is executed synchronously.
  11272. parentOperatorList.addDependencies(operatorList.dependencies);
  11273. }, function (reason) {
  11274. warn('Type3 font resource \"' + key + '\" is not available');
  11275. var operatorList = new OperatorList();
  11276. charProcOperatorList[key] = operatorList.getIR();
  11277. });
  11278. }.bind(this, charProcKeys[i]));
  11279. }
  11280. this.type3Loaded = loadCharProcsPromise.then(function () {
  11281. translatedFont.charProcOperatorList = charProcOperatorList;
  11282. });
  11283. return this.type3Loaded;
  11284. }
  11285. };
  11286. return TranslatedFont;
  11287. })();
  11288. var OperatorList = (function OperatorListClosure() {
  11289. var CHUNK_SIZE = 1000;
  11290. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11291. function getTransfers(queue) {
  11292. var transfers = [];
  11293. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11294. for (var i = 0, ii = queue.length; i < ii; i++) {
  11295. switch (fnArray[i]) {
  11296. case OPS.paintInlineImageXObject:
  11297. case OPS.paintInlineImageXObjectGroup:
  11298. case OPS.paintImageMaskXObject:
  11299. var arg = argsArray[i][0]; // first param in imgData
  11300. if (!arg.cached) {
  11301. transfers.push(arg.data.buffer);
  11302. }
  11303. break;
  11304. }
  11305. }
  11306. return transfers;
  11307. }
  11308. function OperatorList(intent, messageHandler, pageIndex) {
  11309. this.messageHandler = messageHandler;
  11310. this.fnArray = [];
  11311. this.argsArray = [];
  11312. this.dependencies = {};
  11313. this.pageIndex = pageIndex;
  11314. this.intent = intent;
  11315. }
  11316. OperatorList.prototype = {
  11317. get length() {
  11318. return this.argsArray.length;
  11319. },
  11320. addOp: function(fn, args) {
  11321. this.fnArray.push(fn);
  11322. this.argsArray.push(args);
  11323. if (this.messageHandler) {
  11324. if (this.fnArray.length >= CHUNK_SIZE) {
  11325. this.flush();
  11326. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11327. (fn === OPS.restore || fn === OPS.endText)) {
  11328. // heuristic to flush on boundary of restore or endText
  11329. this.flush();
  11330. }
  11331. }
  11332. },
  11333. addDependency: function(dependency) {
  11334. if (dependency in this.dependencies) {
  11335. return;
  11336. }
  11337. this.dependencies[dependency] = true;
  11338. this.addOp(OPS.dependency, [dependency]);
  11339. },
  11340. addDependencies: function(dependencies) {
  11341. for (var key in dependencies) {
  11342. this.addDependency(key);
  11343. }
  11344. },
  11345. addOpList: function(opList) {
  11346. Util.extendObj(this.dependencies, opList.dependencies);
  11347. for (var i = 0, ii = opList.length; i < ii; i++) {
  11348. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11349. }
  11350. },
  11351. getIR: function() {
  11352. return {
  11353. fnArray: this.fnArray,
  11354. argsArray: this.argsArray,
  11355. length: this.length
  11356. };
  11357. },
  11358. flush: function(lastChunk) {
  11359. if (this.intent !== 'oplist') {
  11360. new QueueOptimizer().optimize(this);
  11361. }
  11362. var transfers = getTransfers(this);
  11363. this.messageHandler.send('RenderPageChunk', {
  11364. operatorList: {
  11365. fnArray: this.fnArray,
  11366. argsArray: this.argsArray,
  11367. lastChunk: lastChunk,
  11368. length: this.length
  11369. },
  11370. pageIndex: this.pageIndex,
  11371. intent: this.intent
  11372. }, transfers);
  11373. this.dependencies = {};
  11374. this.fnArray.length = 0;
  11375. this.argsArray.length = 0;
  11376. }
  11377. };
  11378. return OperatorList;
  11379. })();
  11380. var StateManager = (function StateManagerClosure() {
  11381. function StateManager(initialState) {
  11382. this.state = initialState;
  11383. this.stateStack = [];
  11384. }
  11385. StateManager.prototype = {
  11386. save: function () {
  11387. var old = this.state;
  11388. this.stateStack.push(this.state);
  11389. this.state = old.clone();
  11390. },
  11391. restore: function () {
  11392. var prev = this.stateStack.pop();
  11393. if (prev) {
  11394. this.state = prev;
  11395. }
  11396. },
  11397. transform: function (args) {
  11398. this.state.ctm = Util.transform(this.state.ctm, args);
  11399. }
  11400. };
  11401. return StateManager;
  11402. })();
  11403. var TextState = (function TextStateClosure() {
  11404. function TextState() {
  11405. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11406. this.fontSize = 0;
  11407. this.font = null;
  11408. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11409. this.textMatrix = IDENTITY_MATRIX.slice();
  11410. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11411. this.charSpacing = 0;
  11412. this.wordSpacing = 0;
  11413. this.leading = 0;
  11414. this.textHScale = 1;
  11415. this.textRise = 0;
  11416. }
  11417. TextState.prototype = {
  11418. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11419. var m = this.textMatrix;
  11420. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11421. },
  11422. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11423. var m = this.textLineMatrix;
  11424. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11425. },
  11426. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11427. var m = this.textMatrix;
  11428. m[4] = m[0] * x + m[2] * y + m[4];
  11429. m[5] = m[1] * x + m[3] * y + m[5];
  11430. },
  11431. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11432. var m = this.textLineMatrix;
  11433. m[4] = m[0] * x + m[2] * y + m[4];
  11434. m[5] = m[1] * x + m[3] * y + m[5];
  11435. },
  11436. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11437. // 9.4.4 Text Space Details
  11438. var tsm = [this.fontSize * this.textHScale, 0,
  11439. 0, this.fontSize,
  11440. 0, this.textRise];
  11441. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11442. },
  11443. carriageReturn: function TextState_carriageReturn() {
  11444. this.translateTextLineMatrix(0, -this.leading);
  11445. this.textMatrix = this.textLineMatrix.slice();
  11446. },
  11447. clone: function TextState_clone() {
  11448. var clone = Object.create(this);
  11449. clone.textMatrix = this.textMatrix.slice();
  11450. clone.textLineMatrix = this.textLineMatrix.slice();
  11451. clone.fontMatrix = this.fontMatrix.slice();
  11452. return clone;
  11453. }
  11454. };
  11455. return TextState;
  11456. })();
  11457. var EvalState = (function EvalStateClosure() {
  11458. function EvalState() {
  11459. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11460. this.font = null;
  11461. this.textRenderingMode = TextRenderingMode.FILL;
  11462. this.fillColorSpace = ColorSpace.singletons.gray;
  11463. this.strokeColorSpace = ColorSpace.singletons.gray;
  11464. }
  11465. EvalState.prototype = {
  11466. clone: function CanvasExtraState_clone() {
  11467. return Object.create(this);
  11468. },
  11469. };
  11470. return EvalState;
  11471. })();
  11472. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11473. // Specifies properties for each command
  11474. //
  11475. // If variableArgs === true: [0, `numArgs`] expected
  11476. // If variableArgs === false: exactly `numArgs` expected
  11477. var OP_MAP = {
  11478. // Graphic state
  11479. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11480. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11481. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11482. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11483. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11484. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11485. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11486. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11487. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11488. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11489. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11490. // Path
  11491. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11492. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11493. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11494. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11495. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11496. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11497. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11498. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11499. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11500. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11501. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11502. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11503. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11504. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11505. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11506. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11507. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11508. // Clipping
  11509. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11510. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11511. // Text
  11512. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11513. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11514. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11515. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11516. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11517. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11518. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11519. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11520. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11521. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11522. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11523. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11524. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11525. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11526. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11527. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11528. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11529. variableArgs: false },
  11530. // Type3 fonts
  11531. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11532. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11533. // Color
  11534. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11535. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11536. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11537. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11538. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11539. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11540. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11541. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11542. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11543. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11544. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11545. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11546. // Shading
  11547. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11548. // Images
  11549. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11550. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11551. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11552. // XObjects
  11553. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11554. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11555. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11556. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11557. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11558. variableArgs: false },
  11559. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11560. // Compatibility
  11561. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11562. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11563. // (reserved partial commands for the lexer)
  11564. BM: null,
  11565. BD: null,
  11566. 'true': null,
  11567. fa: null,
  11568. fal: null,
  11569. fals: null,
  11570. 'false': null,
  11571. nu: null,
  11572. nul: null,
  11573. 'null': null
  11574. };
  11575. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11576. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11577. // dictionary
  11578. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11579. this.stateManager = stateManager;
  11580. this.nonProcessedArgs = [];
  11581. }
  11582. EvaluatorPreprocessor.prototype = {
  11583. get savedStatesDepth() {
  11584. return this.stateManager.stateStack.length;
  11585. },
  11586. // |operation| is an object with two fields:
  11587. //
  11588. // - |fn| is an out param.
  11589. //
  11590. // - |args| is an inout param. On entry, it should have one of two values.
  11591. //
  11592. // - An empty array. This indicates that the caller is providing the
  11593. // array in which the args will be stored in. The caller should use
  11594. // this value if it can reuse a single array for each call to read().
  11595. //
  11596. // - |null|. This indicates that the caller needs this function to create
  11597. // the array in which any args are stored in. If there are zero args,
  11598. // this function will leave |operation.args| as |null| (thus avoiding
  11599. // allocations that would occur if we used an empty array to represent
  11600. // zero arguments). Otherwise, it will replace |null| with a new array
  11601. // containing the arguments. The caller should use this value if it
  11602. // cannot reuse an array for each call to read().
  11603. //
  11604. // These two modes are present because this function is very hot and so
  11605. // avoiding allocations where possible is worthwhile.
  11606. //
  11607. read: function EvaluatorPreprocessor_read(operation) {
  11608. var args = operation.args;
  11609. while (true) {
  11610. var obj = this.parser.getObj();
  11611. if (isCmd(obj)) {
  11612. var cmd = obj.cmd;
  11613. // Check that the command is valid
  11614. var opSpec = OP_MAP[cmd];
  11615. if (!opSpec) {
  11616. warn('Unknown command "' + cmd + '"');
  11617. continue;
  11618. }
  11619. var fn = opSpec.id;
  11620. var numArgs = opSpec.numArgs;
  11621. var argsLength = args !== null ? args.length : 0;
  11622. if (!opSpec.variableArgs) {
  11623. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11624. if (argsLength !== numArgs) {
  11625. var nonProcessedArgs = this.nonProcessedArgs;
  11626. while (argsLength > numArgs) {
  11627. nonProcessedArgs.push(args.shift());
  11628. argsLength--;
  11629. }
  11630. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11631. if (!args) {
  11632. args = [];
  11633. }
  11634. args.unshift(nonProcessedArgs.pop());
  11635. argsLength++;
  11636. }
  11637. }
  11638. if (argsLength < numArgs) {
  11639. // If we receive too few args, it's not possible to possible
  11640. // to execute the command, so skip the command
  11641. info('Command ' + fn + ': because expected ' +
  11642. numArgs + ' args, but received ' + argsLength +
  11643. ' args; skipping');
  11644. args = null;
  11645. continue;
  11646. }
  11647. } else if (argsLength > numArgs) {
  11648. info('Command ' + fn + ': expected [0,' + numArgs +
  11649. '] args, but received ' + argsLength + ' args');
  11650. }
  11651. // TODO figure out how to type-check vararg functions
  11652. this.preprocessCommand(fn, args);
  11653. operation.fn = fn;
  11654. operation.args = args;
  11655. return true;
  11656. } else {
  11657. if (isEOF(obj)) {
  11658. return false; // no more commands
  11659. }
  11660. // argument
  11661. if (obj !== null) {
  11662. if (!args) {
  11663. args = [];
  11664. }
  11665. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11666. assert(args.length <= 33, 'Too many arguments');
  11667. }
  11668. }
  11669. }
  11670. },
  11671. preprocessCommand:
  11672. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11673. switch (fn | 0) {
  11674. case OPS.save:
  11675. this.stateManager.save();
  11676. break;
  11677. case OPS.restore:
  11678. this.stateManager.restore();
  11679. break;
  11680. case OPS.transform:
  11681. this.stateManager.transform(args);
  11682. break;
  11683. }
  11684. }
  11685. };
  11686. return EvaluatorPreprocessor;
  11687. })();
  11688. var QueueOptimizer = (function QueueOptimizerClosure() {
  11689. function addState(parentState, pattern, fn) {
  11690. var state = parentState;
  11691. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11692. var item = pattern[i];
  11693. state = (state[item] || (state[item] = []));
  11694. }
  11695. state[pattern[pattern.length - 1]] = fn;
  11696. }
  11697. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11698. argsArray) {
  11699. // Handles special case of mainly LaTeX documents which use image masks to
  11700. // draw lines with the current fill style.
  11701. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11702. // have been found at iFirstSave.
  11703. var iFirstPIMXO = iFirstSave + 2;
  11704. for (var i = 0; i < count; i++) {
  11705. var arg = argsArray[iFirstPIMXO + 4 * i];
  11706. var imageMask = arg.length === 1 && arg[0];
  11707. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11708. (!imageMask.data.length ||
  11709. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11710. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11711. continue;
  11712. }
  11713. break;
  11714. }
  11715. return count - i;
  11716. }
  11717. var InitialState = [];
  11718. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11719. // sequences with one |paintInlineImageXObjectGroup| operation.
  11720. addState(InitialState,
  11721. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11722. function foundInlineImageGroup(context) {
  11723. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11724. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11725. var MAX_WIDTH = 1000;
  11726. var IMAGE_PADDING = 1;
  11727. var fnArray = context.fnArray, argsArray = context.argsArray;
  11728. var curr = context.iCurr;
  11729. var iFirstSave = curr - 3;
  11730. var iFirstTransform = curr - 2;
  11731. var iFirstPIIXO = curr - 1;
  11732. // Look for the quartets.
  11733. var i = iFirstSave + 4;
  11734. var ii = fnArray.length;
  11735. while (i + 3 < ii) {
  11736. if (fnArray[i] !== OPS.save ||
  11737. fnArray[i + 1] !== OPS.transform ||
  11738. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11739. fnArray[i + 3] !== OPS.restore) {
  11740. break; // ops don't match
  11741. }
  11742. i += 4;
  11743. }
  11744. // At this point, i is the index of the first op past the last valid
  11745. // quartet.
  11746. var count = Math.min((i - iFirstSave) / 4,
  11747. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11748. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11749. return i;
  11750. }
  11751. // assuming that heights of those image is too small (~1 pixel)
  11752. // packing as much as possible by lines
  11753. var maxX = 0;
  11754. var map = [], maxLineHeight = 0;
  11755. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11756. var q;
  11757. for (q = 0; q < count; q++) {
  11758. var transform = argsArray[iFirstTransform + (q << 2)];
  11759. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11760. if (currentX + img.width > MAX_WIDTH) {
  11761. // starting new line
  11762. maxX = Math.max(maxX, currentX);
  11763. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11764. currentX = 0;
  11765. maxLineHeight = 0;
  11766. }
  11767. map.push({
  11768. transform: transform,
  11769. x: currentX, y: currentY,
  11770. w: img.width, h: img.height
  11771. });
  11772. currentX += img.width + 2 * IMAGE_PADDING;
  11773. maxLineHeight = Math.max(maxLineHeight, img.height);
  11774. }
  11775. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11776. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11777. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11778. var imgRowSize = imgWidth << 2;
  11779. for (q = 0; q < count; q++) {
  11780. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11781. // Copy image by lines and extends pixels into padding.
  11782. var rowSize = map[q].w << 2;
  11783. var dataOffset = 0;
  11784. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11785. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11786. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11787. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11788. dataOffset += rowSize;
  11789. offset += imgRowSize;
  11790. }
  11791. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11792. while (offset >= 0) {
  11793. data[offset - 4] = data[offset];
  11794. data[offset - 3] = data[offset + 1];
  11795. data[offset - 2] = data[offset + 2];
  11796. data[offset - 1] = data[offset + 3];
  11797. data[offset + rowSize] = data[offset + rowSize - 4];
  11798. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11799. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11800. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11801. offset -= imgRowSize;
  11802. }
  11803. }
  11804. // Replace queue items.
  11805. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11806. argsArray.splice(iFirstSave, count * 4,
  11807. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11808. data: imgData }, map]);
  11809. return iFirstSave + 1;
  11810. });
  11811. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11812. // sequences with one |paintImageMaskXObjectGroup| or one
  11813. // |paintImageMaskXObjectRepeat| operation.
  11814. addState(InitialState,
  11815. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11816. function foundImageMaskGroup(context) {
  11817. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11818. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11819. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11820. var fnArray = context.fnArray, argsArray = context.argsArray;
  11821. var curr = context.iCurr;
  11822. var iFirstSave = curr - 3;
  11823. var iFirstTransform = curr - 2;
  11824. var iFirstPIMXO = curr - 1;
  11825. // Look for the quartets.
  11826. var i = iFirstSave + 4;
  11827. var ii = fnArray.length;
  11828. while (i + 3 < ii) {
  11829. if (fnArray[i] !== OPS.save ||
  11830. fnArray[i + 1] !== OPS.transform ||
  11831. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11832. fnArray[i + 3] !== OPS.restore) {
  11833. break; // ops don't match
  11834. }
  11835. i += 4;
  11836. }
  11837. // At this point, i is the index of the first op past the last valid
  11838. // quartet.
  11839. var count = (i - iFirstSave) / 4;
  11840. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11841. argsArray);
  11842. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11843. return i;
  11844. }
  11845. var q;
  11846. var isSameImage = false;
  11847. var iTransform, transformArgs;
  11848. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11849. if (argsArray[iFirstTransform][1] === 0 &&
  11850. argsArray[iFirstTransform][2] === 0) {
  11851. isSameImage = true;
  11852. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11853. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11854. iTransform = iFirstTransform + 4;
  11855. var iPIMXO = iFirstPIMXO + 4;
  11856. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11857. transformArgs = argsArray[iTransform];
  11858. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11859. transformArgs[0] !== firstTransformArg0 ||
  11860. transformArgs[1] !== 0 ||
  11861. transformArgs[2] !== 0 ||
  11862. transformArgs[3] !== firstTransformArg3) {
  11863. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11864. isSameImage = false;
  11865. } else {
  11866. count = q;
  11867. }
  11868. break; // different image or transform
  11869. }
  11870. }
  11871. }
  11872. if (isSameImage) {
  11873. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11874. var positions = new Float32Array(count * 2);
  11875. iTransform = iFirstTransform;
  11876. for (q = 0; q < count; q++, iTransform += 4) {
  11877. transformArgs = argsArray[iTransform];
  11878. positions[(q << 1)] = transformArgs[4];
  11879. positions[(q << 1) + 1] = transformArgs[5];
  11880. }
  11881. // Replace queue items.
  11882. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11883. argsArray.splice(iFirstSave, count * 4,
  11884. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11885. } else {
  11886. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11887. var images = [];
  11888. for (q = 0; q < count; q++) {
  11889. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11890. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11891. images.push({ data: maskParams.data, width: maskParams.width,
  11892. height: maskParams.height,
  11893. transform: transformArgs });
  11894. }
  11895. // Replace queue items.
  11896. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11897. argsArray.splice(iFirstSave, count * 4, [images]);
  11898. }
  11899. return iFirstSave + 1;
  11900. });
  11901. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11902. // with one paintImageXObjectRepeat operation, if the |transform| and
  11903. // |paintImageXObjectRepeat| ops are appropriate.
  11904. addState(InitialState,
  11905. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11906. function (context) {
  11907. var MIN_IMAGES_IN_BLOCK = 3;
  11908. var MAX_IMAGES_IN_BLOCK = 1000;
  11909. var fnArray = context.fnArray, argsArray = context.argsArray;
  11910. var curr = context.iCurr;
  11911. var iFirstSave = curr - 3;
  11912. var iFirstTransform = curr - 2;
  11913. var iFirstPIXO = curr - 1;
  11914. var iFirstRestore = curr;
  11915. if (argsArray[iFirstTransform][1] !== 0 ||
  11916. argsArray[iFirstTransform][2] !== 0) {
  11917. return iFirstRestore + 1; // transform has the wrong form
  11918. }
  11919. // Look for the quartets.
  11920. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11921. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11922. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11923. var i = iFirstSave + 4;
  11924. var ii = fnArray.length;
  11925. while (i + 3 < ii) {
  11926. if (fnArray[i] !== OPS.save ||
  11927. fnArray[i + 1] !== OPS.transform ||
  11928. fnArray[i + 2] !== OPS.paintImageXObject ||
  11929. fnArray[i + 3] !== OPS.restore) {
  11930. break; // ops don't match
  11931. }
  11932. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11933. argsArray[i + 1][1] !== 0 ||
  11934. argsArray[i + 1][2] !== 0 ||
  11935. argsArray[i + 1][3] !== firstTransformArg3) {
  11936. break; // transforms don't match
  11937. }
  11938. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11939. break; // images don't match
  11940. }
  11941. i += 4;
  11942. }
  11943. // At this point, i is the index of the first op past the last valid
  11944. // quartet.
  11945. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11946. if (count < MIN_IMAGES_IN_BLOCK) {
  11947. return i;
  11948. }
  11949. // Extract the (x,y) positions from all of the matching transforms.
  11950. var positions = new Float32Array(count * 2);
  11951. var iTransform = iFirstTransform;
  11952. for (var q = 0; q < count; q++, iTransform += 4) {
  11953. var transformArgs = argsArray[iTransform];
  11954. positions[(q << 1)] = transformArgs[4];
  11955. positions[(q << 1) + 1] = transformArgs[5];
  11956. }
  11957. // Replace queue items.
  11958. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11959. positions];
  11960. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11961. argsArray.splice(iFirstSave, count * 4, args);
  11962. return iFirstSave + 1;
  11963. });
  11964. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11965. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11966. // sequences, if the font for each one is the same.
  11967. addState(InitialState,
  11968. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11969. function (context) {
  11970. var MIN_CHARS_IN_BLOCK = 3;
  11971. var MAX_CHARS_IN_BLOCK = 1000;
  11972. var fnArray = context.fnArray, argsArray = context.argsArray;
  11973. var curr = context.iCurr;
  11974. var iFirstBeginText = curr - 4;
  11975. var iFirstSetFont = curr - 3;
  11976. var iFirstSetTextMatrix = curr - 2;
  11977. var iFirstShowText = curr - 1;
  11978. var iFirstEndText = curr;
  11979. // Look for the quintets.
  11980. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11981. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11982. var i = iFirstBeginText + 5;
  11983. var ii = fnArray.length;
  11984. while (i + 4 < ii) {
  11985. if (fnArray[i] !== OPS.beginText ||
  11986. fnArray[i + 1] !== OPS.setFont ||
  11987. fnArray[i + 2] !== OPS.setTextMatrix ||
  11988. fnArray[i + 3] !== OPS.showText ||
  11989. fnArray[i + 4] !== OPS.endText) {
  11990. break; // ops don't match
  11991. }
  11992. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11993. argsArray[i + 1][1] !== firstSetFontArg1) {
  11994. break; // fonts don't match
  11995. }
  11996. i += 5;
  11997. }
  11998. // At this point, i is the index of the first op past the last valid
  11999. // quintet.
  12000. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12001. if (count < MIN_CHARS_IN_BLOCK) {
  12002. return i;
  12003. }
  12004. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  12005. // showText, endText), include that as well. (E.g. <something> might be
  12006. // |dependency|.)
  12007. var iFirst = iFirstBeginText;
  12008. if (iFirstBeginText >= 4 &&
  12009. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  12010. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  12011. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  12012. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  12013. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  12014. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  12015. count++;
  12016. iFirst -= 5;
  12017. }
  12018. // Remove (endText, beginText, setFont) trios.
  12019. var iEndText = iFirst + 4;
  12020. for (var q = 1; q < count; q++) {
  12021. fnArray.splice(iEndText, 3);
  12022. argsArray.splice(iEndText, 3);
  12023. iEndText += 2;
  12024. }
  12025. return iEndText + 1;
  12026. });
  12027. function QueueOptimizer() {}
  12028. QueueOptimizer.prototype = {
  12029. optimize: function QueueOptimizer_optimize(queue) {
  12030. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12031. var context = {
  12032. iCurr: 0,
  12033. fnArray: fnArray,
  12034. argsArray: argsArray
  12035. };
  12036. var state;
  12037. var i = 0, ii = fnArray.length;
  12038. while (i < ii) {
  12039. state = (state || InitialState)[fnArray[i]];
  12040. if (typeof state === 'function') { // we found some handler
  12041. context.iCurr = i;
  12042. // state() returns the index of the first non-matching op (if we
  12043. // didn't match) or the first op past the modified ops (if we did
  12044. // match and replace).
  12045. i = state(context);
  12046. state = undefined; // reset the state machine
  12047. ii = context.fnArray.length;
  12048. } else {
  12049. i++;
  12050. }
  12051. }
  12052. }
  12053. };
  12054. return QueueOptimizer;
  12055. })();
  12056. var BUILT_IN_CMAPS = [
  12057. // << Start unicode maps.
  12058. 'Adobe-GB1-UCS2',
  12059. 'Adobe-CNS1-UCS2',
  12060. 'Adobe-Japan1-UCS2',
  12061. 'Adobe-Korea1-UCS2',
  12062. // >> End unicode maps.
  12063. '78-EUC-H',
  12064. '78-EUC-V',
  12065. '78-H',
  12066. '78-RKSJ-H',
  12067. '78-RKSJ-V',
  12068. '78-V',
  12069. '78ms-RKSJ-H',
  12070. '78ms-RKSJ-V',
  12071. '83pv-RKSJ-H',
  12072. '90ms-RKSJ-H',
  12073. '90ms-RKSJ-V',
  12074. '90msp-RKSJ-H',
  12075. '90msp-RKSJ-V',
  12076. '90pv-RKSJ-H',
  12077. '90pv-RKSJ-V',
  12078. 'Add-H',
  12079. 'Add-RKSJ-H',
  12080. 'Add-RKSJ-V',
  12081. 'Add-V',
  12082. 'Adobe-CNS1-0',
  12083. 'Adobe-CNS1-1',
  12084. 'Adobe-CNS1-2',
  12085. 'Adobe-CNS1-3',
  12086. 'Adobe-CNS1-4',
  12087. 'Adobe-CNS1-5',
  12088. 'Adobe-CNS1-6',
  12089. 'Adobe-GB1-0',
  12090. 'Adobe-GB1-1',
  12091. 'Adobe-GB1-2',
  12092. 'Adobe-GB1-3',
  12093. 'Adobe-GB1-4',
  12094. 'Adobe-GB1-5',
  12095. 'Adobe-Japan1-0',
  12096. 'Adobe-Japan1-1',
  12097. 'Adobe-Japan1-2',
  12098. 'Adobe-Japan1-3',
  12099. 'Adobe-Japan1-4',
  12100. 'Adobe-Japan1-5',
  12101. 'Adobe-Japan1-6',
  12102. 'Adobe-Korea1-0',
  12103. 'Adobe-Korea1-1',
  12104. 'Adobe-Korea1-2',
  12105. 'B5-H',
  12106. 'B5-V',
  12107. 'B5pc-H',
  12108. 'B5pc-V',
  12109. 'CNS-EUC-H',
  12110. 'CNS-EUC-V',
  12111. 'CNS1-H',
  12112. 'CNS1-V',
  12113. 'CNS2-H',
  12114. 'CNS2-V',
  12115. 'ETHK-B5-H',
  12116. 'ETHK-B5-V',
  12117. 'ETen-B5-H',
  12118. 'ETen-B5-V',
  12119. 'ETenms-B5-H',
  12120. 'ETenms-B5-V',
  12121. 'EUC-H',
  12122. 'EUC-V',
  12123. 'Ext-H',
  12124. 'Ext-RKSJ-H',
  12125. 'Ext-RKSJ-V',
  12126. 'Ext-V',
  12127. 'GB-EUC-H',
  12128. 'GB-EUC-V',
  12129. 'GB-H',
  12130. 'GB-V',
  12131. 'GBK-EUC-H',
  12132. 'GBK-EUC-V',
  12133. 'GBK2K-H',
  12134. 'GBK2K-V',
  12135. 'GBKp-EUC-H',
  12136. 'GBKp-EUC-V',
  12137. 'GBT-EUC-H',
  12138. 'GBT-EUC-V',
  12139. 'GBT-H',
  12140. 'GBT-V',
  12141. 'GBTpc-EUC-H',
  12142. 'GBTpc-EUC-V',
  12143. 'GBpc-EUC-H',
  12144. 'GBpc-EUC-V',
  12145. 'H',
  12146. 'HKdla-B5-H',
  12147. 'HKdla-B5-V',
  12148. 'HKdlb-B5-H',
  12149. 'HKdlb-B5-V',
  12150. 'HKgccs-B5-H',
  12151. 'HKgccs-B5-V',
  12152. 'HKm314-B5-H',
  12153. 'HKm314-B5-V',
  12154. 'HKm471-B5-H',
  12155. 'HKm471-B5-V',
  12156. 'HKscs-B5-H',
  12157. 'HKscs-B5-V',
  12158. 'Hankaku',
  12159. 'Hiragana',
  12160. 'KSC-EUC-H',
  12161. 'KSC-EUC-V',
  12162. 'KSC-H',
  12163. 'KSC-Johab-H',
  12164. 'KSC-Johab-V',
  12165. 'KSC-V',
  12166. 'KSCms-UHC-H',
  12167. 'KSCms-UHC-HW-H',
  12168. 'KSCms-UHC-HW-V',
  12169. 'KSCms-UHC-V',
  12170. 'KSCpc-EUC-H',
  12171. 'KSCpc-EUC-V',
  12172. 'Katakana',
  12173. 'NWP-H',
  12174. 'NWP-V',
  12175. 'RKSJ-H',
  12176. 'RKSJ-V',
  12177. 'Roman',
  12178. 'UniCNS-UCS2-H',
  12179. 'UniCNS-UCS2-V',
  12180. 'UniCNS-UTF16-H',
  12181. 'UniCNS-UTF16-V',
  12182. 'UniCNS-UTF32-H',
  12183. 'UniCNS-UTF32-V',
  12184. 'UniCNS-UTF8-H',
  12185. 'UniCNS-UTF8-V',
  12186. 'UniGB-UCS2-H',
  12187. 'UniGB-UCS2-V',
  12188. 'UniGB-UTF16-H',
  12189. 'UniGB-UTF16-V',
  12190. 'UniGB-UTF32-H',
  12191. 'UniGB-UTF32-V',
  12192. 'UniGB-UTF8-H',
  12193. 'UniGB-UTF8-V',
  12194. 'UniJIS-UCS2-H',
  12195. 'UniJIS-UCS2-HW-H',
  12196. 'UniJIS-UCS2-HW-V',
  12197. 'UniJIS-UCS2-V',
  12198. 'UniJIS-UTF16-H',
  12199. 'UniJIS-UTF16-V',
  12200. 'UniJIS-UTF32-H',
  12201. 'UniJIS-UTF32-V',
  12202. 'UniJIS-UTF8-H',
  12203. 'UniJIS-UTF8-V',
  12204. 'UniJIS2004-UTF16-H',
  12205. 'UniJIS2004-UTF16-V',
  12206. 'UniJIS2004-UTF32-H',
  12207. 'UniJIS2004-UTF32-V',
  12208. 'UniJIS2004-UTF8-H',
  12209. 'UniJIS2004-UTF8-V',
  12210. 'UniJISPro-UCS2-HW-V',
  12211. 'UniJISPro-UCS2-V',
  12212. 'UniJISPro-UTF8-V',
  12213. 'UniJISX0213-UTF32-H',
  12214. 'UniJISX0213-UTF32-V',
  12215. 'UniJISX02132004-UTF32-H',
  12216. 'UniJISX02132004-UTF32-V',
  12217. 'UniKS-UCS2-H',
  12218. 'UniKS-UCS2-V',
  12219. 'UniKS-UTF16-H',
  12220. 'UniKS-UTF16-V',
  12221. 'UniKS-UTF32-H',
  12222. 'UniKS-UTF32-V',
  12223. 'UniKS-UTF8-H',
  12224. 'UniKS-UTF8-V',
  12225. 'V',
  12226. 'WP-Symbol'];
  12227. // CMap, not to be confused with TrueType's cmap.
  12228. var CMap = (function CMapClosure() {
  12229. function CMap(builtInCMap) {
  12230. // Codespace ranges are stored as follows:
  12231. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12232. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12233. this.codespaceRanges = [[], [], [], []];
  12234. this.numCodespaceRanges = 0;
  12235. // Map entries have one of two forms.
  12236. // - cid chars are 16-bit unsigned integers, stored as integers.
  12237. // - bf chars are variable-length byte sequences, stored as strings, with
  12238. // one byte per character.
  12239. this._map = [];
  12240. this.name = '';
  12241. this.vertical = false;
  12242. this.useCMap = null;
  12243. this.builtInCMap = builtInCMap;
  12244. }
  12245. CMap.prototype = {
  12246. addCodespaceRange: function(n, low, high) {
  12247. this.codespaceRanges[n - 1].push(low, high);
  12248. this.numCodespaceRanges++;
  12249. },
  12250. mapCidRange: function(low, high, dstLow) {
  12251. while (low <= high) {
  12252. this._map[low++] = dstLow++;
  12253. }
  12254. },
  12255. mapBfRange: function(low, high, dstLow) {
  12256. var lastByte = dstLow.length - 1;
  12257. while (low <= high) {
  12258. this._map[low++] = dstLow;
  12259. // Only the last byte has to be incremented.
  12260. dstLow = dstLow.substr(0, lastByte) +
  12261. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12262. }
  12263. },
  12264. mapBfRangeToArray: function(low, high, array) {
  12265. var i = 0, ii = array.length;
  12266. while (low <= high && i < ii) {
  12267. this._map[low] = array[i++];
  12268. ++low;
  12269. }
  12270. },
  12271. // This is used for both bf and cid chars.
  12272. mapOne: function(src, dst) {
  12273. this._map[src] = dst;
  12274. },
  12275. lookup: function(code) {
  12276. return this._map[code];
  12277. },
  12278. contains: function(code) {
  12279. return this._map[code] !== undefined;
  12280. },
  12281. forEach: function(callback) {
  12282. // Most maps have fewer than 65536 entries, and for those we use normal
  12283. // array iteration. But really sparse tables are possible -- e.g. with
  12284. // indices in the *billions*. For such tables we use for..in, which isn't
  12285. // ideal because it stringifies the indices for all present elements, but
  12286. // it does avoid iterating over every undefined entry.
  12287. var map = this._map;
  12288. var length = map.length;
  12289. var i;
  12290. if (length <= 0x10000) {
  12291. for (i = 0; i < length; i++) {
  12292. if (map[i] !== undefined) {
  12293. callback(i, map[i]);
  12294. }
  12295. }
  12296. } else {
  12297. for (i in this._map) {
  12298. callback(i, map[i]);
  12299. }
  12300. }
  12301. },
  12302. charCodeOf: function(value) {
  12303. return this._map.indexOf(value);
  12304. },
  12305. getMap: function() {
  12306. return this._map;
  12307. },
  12308. readCharCode: function(str, offset, out) {
  12309. var c = 0;
  12310. var codespaceRanges = this.codespaceRanges;
  12311. var codespaceRangesLen = this.codespaceRanges.length;
  12312. // 9.7.6.2 CMap Mapping
  12313. // The code length is at most 4.
  12314. for (var n = 0; n < codespaceRangesLen; n++) {
  12315. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12316. // Check each codespace range to see if it falls within.
  12317. var codespaceRange = codespaceRanges[n];
  12318. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12319. var low = codespaceRange[k++];
  12320. var high = codespaceRange[k++];
  12321. if (c >= low && c <= high) {
  12322. out.charcode = c;
  12323. out.length = n + 1;
  12324. return;
  12325. }
  12326. }
  12327. }
  12328. out.charcode = 0;
  12329. out.length = 1;
  12330. },
  12331. get isIdentityCMap() {
  12332. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12333. return false;
  12334. }
  12335. if (this._map.length !== 0x10000) {
  12336. return false;
  12337. }
  12338. for (var i = 0; i < 0x10000; i++) {
  12339. if (this._map[i] !== i) {
  12340. return false;
  12341. }
  12342. }
  12343. return true;
  12344. }
  12345. };
  12346. return CMap;
  12347. })();
  12348. // A special case of CMap, where the _map array implicitly has a length of
  12349. // 65536 and each element is equal to its index.
  12350. var IdentityCMap = (function IdentityCMapClosure() {
  12351. function IdentityCMap(vertical, n) {
  12352. CMap.call(this);
  12353. this.vertical = vertical;
  12354. this.addCodespaceRange(n, 0, 0xffff);
  12355. }
  12356. Util.inherit(IdentityCMap, CMap, {});
  12357. IdentityCMap.prototype = {
  12358. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12359. mapCidRange: function(low, high, dstLow) {
  12360. error('should not call mapCidRange');
  12361. },
  12362. mapBfRange: function(low, high, dstLow) {
  12363. error('should not call mapBfRange');
  12364. },
  12365. mapBfRangeToArray: function(low, high, array) {
  12366. error('should not call mapBfRangeToArray');
  12367. },
  12368. mapOne: function(src, dst) {
  12369. error('should not call mapCidOne');
  12370. },
  12371. lookup: function(code) {
  12372. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12373. },
  12374. contains: function(code) {
  12375. return isInt(code) && code <= 0xffff;
  12376. },
  12377. forEach: function(callback) {
  12378. for (var i = 0; i <= 0xffff; i++) {
  12379. callback(i, i);
  12380. }
  12381. },
  12382. charCodeOf: function(value) {
  12383. return (isInt(value) && value <= 0xffff) ? value : -1;
  12384. },
  12385. getMap: function() {
  12386. // Sometimes identity maps must be instantiated, but it's rare.
  12387. var map = new Array(0x10000);
  12388. for (var i = 0; i <= 0xffff; i++) {
  12389. map[i] = i;
  12390. }
  12391. return map;
  12392. },
  12393. readCharCode: CMap.prototype.readCharCode,
  12394. get isIdentityCMap() {
  12395. error('should not access .isIdentityCMap');
  12396. }
  12397. };
  12398. return IdentityCMap;
  12399. })();
  12400. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12401. function fetchBinaryData(url) {
  12402. var nonBinaryRequest = PDFJS.disableWorker;
  12403. var request = new XMLHttpRequest();
  12404. request.open('GET', url, false);
  12405. if (!nonBinaryRequest) {
  12406. try {
  12407. request.responseType = 'arraybuffer';
  12408. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12409. } catch (e) {
  12410. nonBinaryRequest = true;
  12411. }
  12412. }
  12413. if (nonBinaryRequest && request.overrideMimeType) {
  12414. request.overrideMimeType('text/plain; charset=x-user-defined');
  12415. }
  12416. request.send(null);
  12417. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12418. error('Unable to get binary cMap at: ' + url);
  12419. }
  12420. if (nonBinaryRequest) {
  12421. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12422. return ch.charCodeAt(0) & 255;
  12423. });
  12424. return new Uint8Array(data);
  12425. }
  12426. return new Uint8Array(request.response);
  12427. }
  12428. function hexToInt(a, size) {
  12429. var n = 0;
  12430. for (var i = 0; i <= size; i++) {
  12431. n = (n << 8) | a[i];
  12432. }
  12433. return n >>> 0;
  12434. }
  12435. function hexToStr(a, size) {
  12436. // This code is hot. Special-case some common values to avoid creating an
  12437. // object with subarray().
  12438. if (size === 1) {
  12439. return String.fromCharCode(a[0], a[1]);
  12440. }
  12441. if (size === 3) {
  12442. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12443. }
  12444. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12445. }
  12446. function addHex(a, b, size) {
  12447. var c = 0;
  12448. for (var i = size; i >= 0; i--) {
  12449. c += a[i] + b[i];
  12450. a[i] = c & 255;
  12451. c >>= 8;
  12452. }
  12453. }
  12454. function incHex(a, size) {
  12455. var c = 1;
  12456. for (var i = size; i >= 0 && c > 0; i--) {
  12457. c += a[i];
  12458. a[i] = c & 255;
  12459. c >>= 8;
  12460. }
  12461. }
  12462. var MAX_NUM_SIZE = 16;
  12463. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12464. function BinaryCMapStream(data) {
  12465. this.buffer = data;
  12466. this.pos = 0;
  12467. this.end = data.length;
  12468. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12469. }
  12470. BinaryCMapStream.prototype = {
  12471. readByte: function () {
  12472. if (this.pos >= this.end) {
  12473. return -1;
  12474. }
  12475. return this.buffer[this.pos++];
  12476. },
  12477. readNumber: function () {
  12478. var n = 0;
  12479. var last;
  12480. do {
  12481. var b = this.readByte();
  12482. if (b < 0) {
  12483. error('unexpected EOF in bcmap');
  12484. }
  12485. last = !(b & 0x80);
  12486. n = (n << 7) | (b & 0x7F);
  12487. } while (!last);
  12488. return n;
  12489. },
  12490. readSigned: function () {
  12491. var n = this.readNumber();
  12492. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12493. },
  12494. readHex: function (num, size) {
  12495. num.set(this.buffer.subarray(this.pos,
  12496. this.pos + size + 1));
  12497. this.pos += size + 1;
  12498. },
  12499. readHexNumber: function (num, size) {
  12500. var last;
  12501. var stack = this.tmpBuf, sp = 0;
  12502. do {
  12503. var b = this.readByte();
  12504. if (b < 0) {
  12505. error('unexpected EOF in bcmap');
  12506. }
  12507. last = !(b & 0x80);
  12508. stack[sp++] = b & 0x7F;
  12509. } while (!last);
  12510. var i = size, buffer = 0, bufferSize = 0;
  12511. while (i >= 0) {
  12512. while (bufferSize < 8 && stack.length > 0) {
  12513. buffer = (stack[--sp] << bufferSize) | buffer;
  12514. bufferSize += 7;
  12515. }
  12516. num[i] = buffer & 255;
  12517. i--;
  12518. buffer >>= 8;
  12519. bufferSize -= 8;
  12520. }
  12521. },
  12522. readHexSigned: function (num, size) {
  12523. this.readHexNumber(num, size);
  12524. var sign = num[size] & 1 ? 255 : 0;
  12525. var c = 0;
  12526. for (var i = 0; i <= size; i++) {
  12527. c = ((c & 1) << 8) | num[i];
  12528. num[i] = (c >> 1) ^ sign;
  12529. }
  12530. },
  12531. readString: function () {
  12532. var len = this.readNumber();
  12533. var s = '';
  12534. for (var i = 0; i < len; i++) {
  12535. s += String.fromCharCode(this.readNumber());
  12536. }
  12537. return s;
  12538. }
  12539. };
  12540. function processBinaryCMap(url, cMap, extend) {
  12541. var data = fetchBinaryData(url);
  12542. var stream = new BinaryCMapStream(data);
  12543. var header = stream.readByte();
  12544. cMap.vertical = !!(header & 1);
  12545. var useCMap = null;
  12546. var start = new Uint8Array(MAX_NUM_SIZE);
  12547. var end = new Uint8Array(MAX_NUM_SIZE);
  12548. var char = new Uint8Array(MAX_NUM_SIZE);
  12549. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12550. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12551. var code;
  12552. var b;
  12553. while ((b = stream.readByte()) >= 0) {
  12554. var type = b >> 5;
  12555. if (type === 7) { // metadata, e.g. comment or usecmap
  12556. switch (b & 0x1F) {
  12557. case 0:
  12558. stream.readString(); // skipping comment
  12559. break;
  12560. case 1:
  12561. useCMap = stream.readString();
  12562. break;
  12563. }
  12564. continue;
  12565. }
  12566. var sequence = !!(b & 0x10);
  12567. var dataSize = b & 15;
  12568. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12569. var ucs2DataSize = 1;
  12570. var subitemsCount = stream.readNumber();
  12571. var i;
  12572. switch (type) {
  12573. case 0: // codespacerange
  12574. stream.readHex(start, dataSize);
  12575. stream.readHexNumber(end, dataSize);
  12576. addHex(end, start, dataSize);
  12577. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12578. hexToInt(end, dataSize));
  12579. for (i = 1; i < subitemsCount; i++) {
  12580. incHex(end, dataSize);
  12581. stream.readHexNumber(start, dataSize);
  12582. addHex(start, end, dataSize);
  12583. stream.readHexNumber(end, dataSize);
  12584. addHex(end, start, dataSize);
  12585. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12586. hexToInt(end, dataSize));
  12587. }
  12588. break;
  12589. case 1: // notdefrange
  12590. stream.readHex(start, dataSize);
  12591. stream.readHexNumber(end, dataSize);
  12592. addHex(end, start, dataSize);
  12593. code = stream.readNumber();
  12594. // undefined range, skipping
  12595. for (i = 1; i < subitemsCount; i++) {
  12596. incHex(end, dataSize);
  12597. stream.readHexNumber(start, dataSize);
  12598. addHex(start, end, dataSize);
  12599. stream.readHexNumber(end, dataSize);
  12600. addHex(end, start, dataSize);
  12601. code = stream.readNumber();
  12602. // nop
  12603. }
  12604. break;
  12605. case 2: // cidchar
  12606. stream.readHex(char, dataSize);
  12607. code = stream.readNumber();
  12608. cMap.mapOne(hexToInt(char, dataSize), code);
  12609. for (i = 1; i < subitemsCount; i++) {
  12610. incHex(char, dataSize);
  12611. if (!sequence) {
  12612. stream.readHexNumber(tmp, dataSize);
  12613. addHex(char, tmp, dataSize);
  12614. }
  12615. code = stream.readSigned() + (code + 1);
  12616. cMap.mapOne(hexToInt(char, dataSize), code);
  12617. }
  12618. break;
  12619. case 3: // cidrange
  12620. stream.readHex(start, dataSize);
  12621. stream.readHexNumber(end, dataSize);
  12622. addHex(end, start, dataSize);
  12623. code = stream.readNumber();
  12624. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12625. code);
  12626. for (i = 1; i < subitemsCount; i++) {
  12627. incHex(end, dataSize);
  12628. if (!sequence) {
  12629. stream.readHexNumber(start, dataSize);
  12630. addHex(start, end, dataSize);
  12631. } else {
  12632. start.set(end);
  12633. }
  12634. stream.readHexNumber(end, dataSize);
  12635. addHex(end, start, dataSize);
  12636. code = stream.readNumber();
  12637. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12638. code);
  12639. }
  12640. break;
  12641. case 4: // bfchar
  12642. stream.readHex(char, ucs2DataSize);
  12643. stream.readHex(charCode, dataSize);
  12644. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12645. hexToStr(charCode, dataSize));
  12646. for (i = 1; i < subitemsCount; i++) {
  12647. incHex(char, ucs2DataSize);
  12648. if (!sequence) {
  12649. stream.readHexNumber(tmp, ucs2DataSize);
  12650. addHex(char, tmp, ucs2DataSize);
  12651. }
  12652. incHex(charCode, dataSize);
  12653. stream.readHexSigned(tmp, dataSize);
  12654. addHex(charCode, tmp, dataSize);
  12655. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12656. hexToStr(charCode, dataSize));
  12657. }
  12658. break;
  12659. case 5: // bfrange
  12660. stream.readHex(start, ucs2DataSize);
  12661. stream.readHexNumber(end, ucs2DataSize);
  12662. addHex(end, start, ucs2DataSize);
  12663. stream.readHex(charCode, dataSize);
  12664. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12665. hexToInt(end, ucs2DataSize),
  12666. hexToStr(charCode, dataSize));
  12667. for (i = 1; i < subitemsCount; i++) {
  12668. incHex(end, ucs2DataSize);
  12669. if (!sequence) {
  12670. stream.readHexNumber(start, ucs2DataSize);
  12671. addHex(start, end, ucs2DataSize);
  12672. } else {
  12673. start.set(end);
  12674. }
  12675. stream.readHexNumber(end, ucs2DataSize);
  12676. addHex(end, start, ucs2DataSize);
  12677. stream.readHex(charCode, dataSize);
  12678. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12679. hexToInt(end, ucs2DataSize),
  12680. hexToStr(charCode, dataSize));
  12681. }
  12682. break;
  12683. default:
  12684. error('Unknown type: ' + type);
  12685. break;
  12686. }
  12687. }
  12688. if (useCMap) {
  12689. extend(useCMap);
  12690. }
  12691. return cMap;
  12692. }
  12693. function BinaryCMapReader() {}
  12694. BinaryCMapReader.prototype = {
  12695. read: processBinaryCMap
  12696. };
  12697. return BinaryCMapReader;
  12698. })();
  12699. var CMapFactory = (function CMapFactoryClosure() {
  12700. function strToInt(str) {
  12701. var a = 0;
  12702. for (var i = 0; i < str.length; i++) {
  12703. a = (a << 8) | str.charCodeAt(i);
  12704. }
  12705. return a >>> 0;
  12706. }
  12707. function expectString(obj) {
  12708. if (!isString(obj)) {
  12709. error('Malformed CMap: expected string.');
  12710. }
  12711. }
  12712. function expectInt(obj) {
  12713. if (!isInt(obj)) {
  12714. error('Malformed CMap: expected int.');
  12715. }
  12716. }
  12717. function parseBfChar(cMap, lexer) {
  12718. while (true) {
  12719. var obj = lexer.getObj();
  12720. if (isEOF(obj)) {
  12721. break;
  12722. }
  12723. if (isCmd(obj, 'endbfchar')) {
  12724. return;
  12725. }
  12726. expectString(obj);
  12727. var src = strToInt(obj);
  12728. obj = lexer.getObj();
  12729. // TODO are /dstName used?
  12730. expectString(obj);
  12731. var dst = obj;
  12732. cMap.mapOne(src, dst);
  12733. }
  12734. }
  12735. function parseBfRange(cMap, lexer) {
  12736. while (true) {
  12737. var obj = lexer.getObj();
  12738. if (isEOF(obj)) {
  12739. break;
  12740. }
  12741. if (isCmd(obj, 'endbfrange')) {
  12742. return;
  12743. }
  12744. expectString(obj);
  12745. var low = strToInt(obj);
  12746. obj = lexer.getObj();
  12747. expectString(obj);
  12748. var high = strToInt(obj);
  12749. obj = lexer.getObj();
  12750. if (isInt(obj) || isString(obj)) {
  12751. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12752. cMap.mapBfRange(low, high, dstLow);
  12753. } else if (isCmd(obj, '[')) {
  12754. obj = lexer.getObj();
  12755. var array = [];
  12756. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12757. array.push(obj);
  12758. obj = lexer.getObj();
  12759. }
  12760. cMap.mapBfRangeToArray(low, high, array);
  12761. } else {
  12762. break;
  12763. }
  12764. }
  12765. error('Invalid bf range.');
  12766. }
  12767. function parseCidChar(cMap, lexer) {
  12768. while (true) {
  12769. var obj = lexer.getObj();
  12770. if (isEOF(obj)) {
  12771. break;
  12772. }
  12773. if (isCmd(obj, 'endcidchar')) {
  12774. return;
  12775. }
  12776. expectString(obj);
  12777. var src = strToInt(obj);
  12778. obj = lexer.getObj();
  12779. expectInt(obj);
  12780. var dst = obj;
  12781. cMap.mapOne(src, dst);
  12782. }
  12783. }
  12784. function parseCidRange(cMap, lexer) {
  12785. while (true) {
  12786. var obj = lexer.getObj();
  12787. if (isEOF(obj)) {
  12788. break;
  12789. }
  12790. if (isCmd(obj, 'endcidrange')) {
  12791. return;
  12792. }
  12793. expectString(obj);
  12794. var low = strToInt(obj);
  12795. obj = lexer.getObj();
  12796. expectString(obj);
  12797. var high = strToInt(obj);
  12798. obj = lexer.getObj();
  12799. expectInt(obj);
  12800. var dstLow = obj;
  12801. cMap.mapCidRange(low, high, dstLow);
  12802. }
  12803. }
  12804. function parseCodespaceRange(cMap, lexer) {
  12805. while (true) {
  12806. var obj = lexer.getObj();
  12807. if (isEOF(obj)) {
  12808. break;
  12809. }
  12810. if (isCmd(obj, 'endcodespacerange')) {
  12811. return;
  12812. }
  12813. if (!isString(obj)) {
  12814. break;
  12815. }
  12816. var low = strToInt(obj);
  12817. obj = lexer.getObj();
  12818. if (!isString(obj)) {
  12819. break;
  12820. }
  12821. var high = strToInt(obj);
  12822. cMap.addCodespaceRange(obj.length, low, high);
  12823. }
  12824. error('Invalid codespace range.');
  12825. }
  12826. function parseWMode(cMap, lexer) {
  12827. var obj = lexer.getObj();
  12828. if (isInt(obj)) {
  12829. cMap.vertical = !!obj;
  12830. }
  12831. }
  12832. function parseCMapName(cMap, lexer) {
  12833. var obj = lexer.getObj();
  12834. if (isName(obj) && isString(obj.name)) {
  12835. cMap.name = obj.name;
  12836. }
  12837. }
  12838. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12839. var previous;
  12840. var embededUseCMap;
  12841. objLoop: while (true) {
  12842. var obj = lexer.getObj();
  12843. if (isEOF(obj)) {
  12844. break;
  12845. } else if (isName(obj)) {
  12846. if (obj.name === 'WMode') {
  12847. parseWMode(cMap, lexer);
  12848. } else if (obj.name === 'CMapName') {
  12849. parseCMapName(cMap, lexer);
  12850. }
  12851. previous = obj;
  12852. } else if (isCmd(obj)) {
  12853. switch (obj.cmd) {
  12854. case 'endcmap':
  12855. break objLoop;
  12856. case 'usecmap':
  12857. if (isName(previous)) {
  12858. embededUseCMap = previous.name;
  12859. }
  12860. break;
  12861. case 'begincodespacerange':
  12862. parseCodespaceRange(cMap, lexer);
  12863. break;
  12864. case 'beginbfchar':
  12865. parseBfChar(cMap, lexer);
  12866. break;
  12867. case 'begincidchar':
  12868. parseCidChar(cMap, lexer);
  12869. break;
  12870. case 'beginbfrange':
  12871. parseBfRange(cMap, lexer);
  12872. break;
  12873. case 'begincidrange':
  12874. parseCidRange(cMap, lexer);
  12875. break;
  12876. }
  12877. }
  12878. }
  12879. if (!useCMap && embededUseCMap) {
  12880. // Load the usecmap definition from the file only if there wasn't one
  12881. // specified.
  12882. useCMap = embededUseCMap;
  12883. }
  12884. if (useCMap) {
  12885. extendCMap(cMap, builtInCMapParams, useCMap);
  12886. }
  12887. }
  12888. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12889. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12890. // If there aren't any code space ranges defined clone all the parent ones
  12891. // into this cMap.
  12892. if (cMap.numCodespaceRanges === 0) {
  12893. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12894. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12895. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12896. }
  12897. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12898. }
  12899. // Merge the map into the current one, making sure not to override
  12900. // any previously defined entries.
  12901. cMap.useCMap.forEach(function(key, value) {
  12902. if (!cMap.contains(key)) {
  12903. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12904. }
  12905. });
  12906. }
  12907. function parseBinaryCMap(name, builtInCMapParams) {
  12908. var url = builtInCMapParams.url + name + '.bcmap';
  12909. var cMap = new CMap(true);
  12910. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12911. extendCMap(cMap, builtInCMapParams, useCMap);
  12912. });
  12913. return cMap;
  12914. }
  12915. function createBuiltInCMap(name, builtInCMapParams) {
  12916. if (name === 'Identity-H') {
  12917. return new IdentityCMap(false, 2);
  12918. } else if (name === 'Identity-V') {
  12919. return new IdentityCMap(true, 2);
  12920. }
  12921. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12922. error('Unknown cMap name: ' + name);
  12923. }
  12924. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12925. if (builtInCMapParams.packed) {
  12926. return parseBinaryCMap(name, builtInCMapParams);
  12927. }
  12928. var request = new XMLHttpRequest();
  12929. var url = builtInCMapParams.url + name;
  12930. request.open('GET', url, false);
  12931. request.send(null);
  12932. if (!request.responseText) {
  12933. error('Unable to get cMap at: ' + url);
  12934. }
  12935. var cMap = new CMap(true);
  12936. var lexer = new Lexer(new StringStream(request.responseText));
  12937. parseCMap(cMap, lexer, builtInCMapParams, null);
  12938. return cMap;
  12939. }
  12940. return {
  12941. create: function (encoding, builtInCMapParams, useCMap) {
  12942. if (isName(encoding)) {
  12943. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12944. } else if (isStream(encoding)) {
  12945. var cMap = new CMap();
  12946. var lexer = new Lexer(encoding);
  12947. try {
  12948. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12949. } catch (e) {
  12950. warn('Invalid CMap data. ' + e);
  12951. }
  12952. if (cMap.isIdentityCMap) {
  12953. return createBuiltInCMap(cMap.name, builtInCMapParams);
  12954. }
  12955. return cMap;
  12956. }
  12957. error('Encoding required.');
  12958. }
  12959. };
  12960. })();
  12961. // Unicode Private Use Area
  12962. var PRIVATE_USE_OFFSET_START = 0xE000;
  12963. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12964. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12965. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12966. // except for Type 3 fonts
  12967. var PDF_GLYPH_SPACE_UNITS = 1000;
  12968. // Hinting is currently disabled due to unknown problems on windows
  12969. // in tracemonkey and various other pdfs with type1 fonts.
  12970. var HINTING_ENABLED = false;
  12971. // Accented charactars are not displayed properly on windows, using this flag
  12972. // to control analysis of seac charstrings.
  12973. var SEAC_ANALYSIS_ENABLED = false;
  12974. var FontFlags = {
  12975. FixedPitch: 1,
  12976. Serif: 2,
  12977. Symbolic: 4,
  12978. Script: 8,
  12979. Nonsymbolic: 32,
  12980. Italic: 64,
  12981. AllCap: 65536,
  12982. SmallCap: 131072,
  12983. ForceBold: 262144
  12984. };
  12985. var Encodings = {
  12986. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12987. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12988. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12989. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12990. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12991. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12992. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12993. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12994. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12995. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12996. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12997. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12998. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12999. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  13000. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  13001. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  13002. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  13003. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  13004. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  13005. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13006. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  13007. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  13008. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  13009. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  13010. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  13011. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  13012. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  13013. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  13014. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  13015. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  13016. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  13017. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  13018. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  13019. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  13020. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  13021. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  13022. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  13023. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  13024. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  13025. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  13026. 'Ydieresissmall'],
  13027. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13028. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13029. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  13030. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  13031. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  13032. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  13033. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  13034. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  13035. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  13036. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  13037. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  13038. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  13039. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  13040. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  13041. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  13042. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  13043. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  13044. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  13045. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  13046. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  13047. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  13048. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  13049. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  13050. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13051. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13052. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13053. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13054. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13055. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13056. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13057. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13058. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13059. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13060. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13061. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13062. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13063. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13064. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13065. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13066. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13067. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13068. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13069. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13070. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13071. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13072. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13073. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13074. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13075. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13076. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13077. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13078. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13079. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13080. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13081. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13082. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13083. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13084. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13085. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13086. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13087. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13088. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13089. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13090. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13091. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13092. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13093. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13094. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13095. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13096. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13097. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13098. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13099. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13100. 'ogonek', 'caron'],
  13101. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13102. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13103. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13104. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13105. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13106. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13107. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13108. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13109. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13110. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13111. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13112. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13113. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13114. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13115. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13116. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13117. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13118. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13119. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13120. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13121. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13122. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13123. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13124. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13125. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13126. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13127. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13128. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13129. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13130. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13131. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13132. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13133. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13134. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13135. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13136. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13137. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13138. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13139. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13140. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13141. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13142. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13143. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13144. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13145. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13146. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13147. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13148. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13149. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13150. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13151. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13152. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13153. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13154. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13155. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13156. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13157. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13158. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13159. 'ydieresis'],
  13160. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13161. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13162. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13163. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13164. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13165. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13166. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13167. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13168. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13169. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13170. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13171. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13172. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13173. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13174. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13175. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13176. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13177. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13178. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13179. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13180. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13181. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13182. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13183. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13184. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13185. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13186. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13187. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13188. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13189. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13190. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13191. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13192. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13193. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13194. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13195. 'bracerightbt'],
  13196. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13197. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13198. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13199. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13200. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13201. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13202. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13203. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13204. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13205. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13206. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13207. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13208. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13209. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13210. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13211. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13212. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13213. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13214. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13215. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13216. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13217. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13218. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13219. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13220. };
  13221. /**
  13222. * Hold a map of decoded fonts and of the standard fourteen Type1
  13223. * fonts and their acronyms.
  13224. */
  13225. var stdFontMap = {
  13226. 'ArialNarrow': 'Helvetica',
  13227. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13228. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13229. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13230. 'ArialBlack': 'Helvetica',
  13231. 'ArialBlack-Bold': 'Helvetica-Bold',
  13232. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13233. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13234. 'Arial': 'Helvetica',
  13235. 'Arial-Bold': 'Helvetica-Bold',
  13236. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13237. 'Arial-Italic': 'Helvetica-Oblique',
  13238. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13239. 'Arial-BoldMT': 'Helvetica-Bold',
  13240. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13241. 'ArialMT': 'Helvetica',
  13242. 'Courier-Bold': 'Courier-Bold',
  13243. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13244. 'Courier-Italic': 'Courier-Oblique',
  13245. 'CourierNew': 'Courier',
  13246. 'CourierNew-Bold': 'Courier-Bold',
  13247. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13248. 'CourierNew-Italic': 'Courier-Oblique',
  13249. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13250. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13251. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13252. 'CourierNewPSMT': 'Courier',
  13253. 'Helvetica': 'Helvetica',
  13254. 'Helvetica-Bold': 'Helvetica-Bold',
  13255. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13256. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13257. 'Helvetica-Italic': 'Helvetica-Oblique',
  13258. 'Helvetica-Oblique':'Helvetica-Oblique',
  13259. 'Symbol-Bold': 'Symbol',
  13260. 'Symbol-BoldItalic': 'Symbol',
  13261. 'Symbol-Italic': 'Symbol',
  13262. 'TimesNewRoman': 'Times-Roman',
  13263. 'TimesNewRoman-Bold': 'Times-Bold',
  13264. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13265. 'TimesNewRoman-Italic': 'Times-Italic',
  13266. 'TimesNewRomanPS': 'Times-Roman',
  13267. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13268. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13269. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13270. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13271. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13272. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13273. 'TimesNewRomanPSMT': 'Times-Roman',
  13274. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13275. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13276. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13277. };
  13278. /**
  13279. * Holds the map of the non-standard fonts that might be included as a standard
  13280. * fonts without glyph data.
  13281. */
  13282. var nonStdFontMap = {
  13283. 'CenturyGothic': 'Helvetica',
  13284. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13285. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13286. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13287. 'ComicSansMS': 'Comic Sans MS',
  13288. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13289. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13290. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13291. 'LucidaConsole': 'Courier',
  13292. 'LucidaConsole-Bold': 'Courier-Bold',
  13293. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13294. 'LucidaConsole-Italic': 'Courier-Oblique',
  13295. 'MS-Gothic': 'MS Gothic',
  13296. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13297. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13298. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13299. 'MS-Mincho': 'MS Mincho',
  13300. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13301. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13302. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13303. 'MS-PGothic': 'MS PGothic',
  13304. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13305. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13306. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13307. 'MS-PMincho': 'MS PMincho',
  13308. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13309. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13310. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13311. 'Wingdings': 'ZapfDingbats'
  13312. };
  13313. var serifFonts = {
  13314. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13315. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13316. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13317. 'Arno': true, 'Aster': true, 'Aurora': true,
  13318. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13319. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13320. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13321. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13322. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13323. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13324. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13325. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13326. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13327. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13328. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13329. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13330. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13331. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13332. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13333. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13334. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13335. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13336. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13337. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13338. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13339. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13340. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13341. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13342. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13343. 'Miller': true, 'Minion': true, 'Modern': true,
  13344. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13345. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13346. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13347. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13348. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13349. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13350. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13351. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13352. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13353. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13354. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13355. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13356. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13357. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13358. };
  13359. var symbolsFonts = {
  13360. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13361. };
  13362. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13363. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13364. // glyphs, but common for some set of the standard fonts.
  13365. var GlyphMapForStandardFonts = {
  13366. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13367. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13368. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13369. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13370. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13371. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13372. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13373. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13374. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13375. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13376. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13377. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13378. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13379. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13380. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13381. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13382. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13383. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13384. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13385. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13386. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13387. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13388. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13389. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13390. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13391. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13392. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13393. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13394. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13395. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13396. '298': 380, '305': 963,
  13397. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13398. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13399. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13400. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13401. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13402. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13403. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13404. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13405. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13406. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13407. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13408. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13409. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13410. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13411. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13412. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13413. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13414. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13415. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13416. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13417. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13418. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13419. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13420. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13421. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13422. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13423. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13424. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13425. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13426. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13427. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13428. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13429. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13430. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13431. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13432. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13433. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13434. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13435. };
  13436. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13437. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13438. // to the similar equivalents in the normal characters range.
  13439. var SpecialPUASymbols = {
  13440. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13441. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13442. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13443. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13444. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13445. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13446. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13447. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13448. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13449. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13450. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13451. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13452. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13453. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13454. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13455. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13456. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13457. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13458. '63723': 0x239B, // parenlefttp (0xF8EB)
  13459. '63724': 0x239C, // parenleftex (0xF8EC)
  13460. '63725': 0x239D, // parenleftbt (0xF8ED)
  13461. '63734': 0x239E, // parenrighttp (0xF8F6)
  13462. '63735': 0x239F, // parenrightex (0xF8F7)
  13463. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13464. };
  13465. function mapSpecialUnicodeValues(code) {
  13466. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13467. return 0;
  13468. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13469. return (SpecialPUASymbols[code] || code);
  13470. }
  13471. return code;
  13472. }
  13473. var UnicodeRanges = [
  13474. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13475. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13476. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13477. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13478. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13479. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13480. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13481. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13482. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13483. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13484. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13485. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13486. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13487. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13488. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13489. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13490. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13491. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13492. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13493. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13494. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13495. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13496. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13497. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13498. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13499. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13500. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13501. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13502. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13503. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13504. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13505. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13506. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13507. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13508. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13509. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13510. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13511. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13512. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13513. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13514. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13515. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13516. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13517. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13518. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13519. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13520. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13521. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13522. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13523. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13524. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13525. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13526. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13527. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13528. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13529. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13530. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13531. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13532. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13533. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13534. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13535. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13536. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13537. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13538. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13539. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13540. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13541. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13542. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13543. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13544. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13545. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13546. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13547. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13548. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13549. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13550. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13551. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13552. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13553. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13554. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13555. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13556. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13557. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13558. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13559. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13560. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13561. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13562. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13563. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13564. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13565. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13566. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13567. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13568. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13569. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13570. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13571. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13572. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13573. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13574. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13575. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13576. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13577. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13578. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13579. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13580. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13581. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13582. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13583. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13584. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13585. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13586. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13587. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13588. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13589. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13590. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13591. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13592. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13593. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13594. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13595. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13596. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13597. ];
  13598. var MacStandardGlyphOrdering = [
  13599. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13600. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13601. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13602. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13603. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13604. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13605. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13606. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13607. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13608. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13609. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13610. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13611. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13612. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13613. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13614. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13615. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13616. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13617. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13618. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13619. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13620. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13621. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13622. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13623. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13624. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13625. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13626. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13627. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13628. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13629. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13630. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13631. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13632. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13633. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13634. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13635. function getUnicodeRangeFor(value) {
  13636. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13637. var range = UnicodeRanges[i];
  13638. if (value >= range.begin && value < range.end) {
  13639. return i;
  13640. }
  13641. }
  13642. return -1;
  13643. }
  13644. function isRTLRangeFor(value) {
  13645. var range = UnicodeRanges[13];
  13646. if (value >= range.begin && value < range.end) {
  13647. return true;
  13648. }
  13649. range = UnicodeRanges[11];
  13650. if (value >= range.begin && value < range.end) {
  13651. return true;
  13652. }
  13653. return false;
  13654. }
  13655. // The normalization table is obtained by filtering the Unicode characters
  13656. // database with <compat> entries.
  13657. var NormalizedUnicodes = {
  13658. '\u00A8': '\u0020\u0308',
  13659. '\u00AF': '\u0020\u0304',
  13660. '\u00B4': '\u0020\u0301',
  13661. '\u00B5': '\u03BC',
  13662. '\u00B8': '\u0020\u0327',
  13663. '\u0132': '\u0049\u004A',
  13664. '\u0133': '\u0069\u006A',
  13665. '\u013F': '\u004C\u00B7',
  13666. '\u0140': '\u006C\u00B7',
  13667. '\u0149': '\u02BC\u006E',
  13668. '\u017F': '\u0073',
  13669. '\u01C4': '\u0044\u017D',
  13670. '\u01C5': '\u0044\u017E',
  13671. '\u01C6': '\u0064\u017E',
  13672. '\u01C7': '\u004C\u004A',
  13673. '\u01C8': '\u004C\u006A',
  13674. '\u01C9': '\u006C\u006A',
  13675. '\u01CA': '\u004E\u004A',
  13676. '\u01CB': '\u004E\u006A',
  13677. '\u01CC': '\u006E\u006A',
  13678. '\u01F1': '\u0044\u005A',
  13679. '\u01F2': '\u0044\u007A',
  13680. '\u01F3': '\u0064\u007A',
  13681. '\u02D8': '\u0020\u0306',
  13682. '\u02D9': '\u0020\u0307',
  13683. '\u02DA': '\u0020\u030A',
  13684. '\u02DB': '\u0020\u0328',
  13685. '\u02DC': '\u0020\u0303',
  13686. '\u02DD': '\u0020\u030B',
  13687. '\u037A': '\u0020\u0345',
  13688. '\u0384': '\u0020\u0301',
  13689. '\u03D0': '\u03B2',
  13690. '\u03D1': '\u03B8',
  13691. '\u03D2': '\u03A5',
  13692. '\u03D5': '\u03C6',
  13693. '\u03D6': '\u03C0',
  13694. '\u03F0': '\u03BA',
  13695. '\u03F1': '\u03C1',
  13696. '\u03F2': '\u03C2',
  13697. '\u03F4': '\u0398',
  13698. '\u03F5': '\u03B5',
  13699. '\u03F9': '\u03A3',
  13700. '\u0587': '\u0565\u0582',
  13701. '\u0675': '\u0627\u0674',
  13702. '\u0676': '\u0648\u0674',
  13703. '\u0677': '\u06C7\u0674',
  13704. '\u0678': '\u064A\u0674',
  13705. '\u0E33': '\u0E4D\u0E32',
  13706. '\u0EB3': '\u0ECD\u0EB2',
  13707. '\u0EDC': '\u0EAB\u0E99',
  13708. '\u0EDD': '\u0EAB\u0EA1',
  13709. '\u0F77': '\u0FB2\u0F81',
  13710. '\u0F79': '\u0FB3\u0F81',
  13711. '\u1E9A': '\u0061\u02BE',
  13712. '\u1FBD': '\u0020\u0313',
  13713. '\u1FBF': '\u0020\u0313',
  13714. '\u1FC0': '\u0020\u0342',
  13715. '\u1FFE': '\u0020\u0314',
  13716. '\u2002': '\u0020',
  13717. '\u2003': '\u0020',
  13718. '\u2004': '\u0020',
  13719. '\u2005': '\u0020',
  13720. '\u2006': '\u0020',
  13721. '\u2008': '\u0020',
  13722. '\u2009': '\u0020',
  13723. '\u200A': '\u0020',
  13724. '\u2017': '\u0020\u0333',
  13725. '\u2024': '\u002E',
  13726. '\u2025': '\u002E\u002E',
  13727. '\u2026': '\u002E\u002E\u002E',
  13728. '\u2033': '\u2032\u2032',
  13729. '\u2034': '\u2032\u2032\u2032',
  13730. '\u2036': '\u2035\u2035',
  13731. '\u2037': '\u2035\u2035\u2035',
  13732. '\u203C': '\u0021\u0021',
  13733. '\u203E': '\u0020\u0305',
  13734. '\u2047': '\u003F\u003F',
  13735. '\u2048': '\u003F\u0021',
  13736. '\u2049': '\u0021\u003F',
  13737. '\u2057': '\u2032\u2032\u2032\u2032',
  13738. '\u205F': '\u0020',
  13739. '\u20A8': '\u0052\u0073',
  13740. '\u2100': '\u0061\u002F\u0063',
  13741. '\u2101': '\u0061\u002F\u0073',
  13742. '\u2103': '\u00B0\u0043',
  13743. '\u2105': '\u0063\u002F\u006F',
  13744. '\u2106': '\u0063\u002F\u0075',
  13745. '\u2107': '\u0190',
  13746. '\u2109': '\u00B0\u0046',
  13747. '\u2116': '\u004E\u006F',
  13748. '\u2121': '\u0054\u0045\u004C',
  13749. '\u2135': '\u05D0',
  13750. '\u2136': '\u05D1',
  13751. '\u2137': '\u05D2',
  13752. '\u2138': '\u05D3',
  13753. '\u213B': '\u0046\u0041\u0058',
  13754. '\u2160': '\u0049',
  13755. '\u2161': '\u0049\u0049',
  13756. '\u2162': '\u0049\u0049\u0049',
  13757. '\u2163': '\u0049\u0056',
  13758. '\u2164': '\u0056',
  13759. '\u2165': '\u0056\u0049',
  13760. '\u2166': '\u0056\u0049\u0049',
  13761. '\u2167': '\u0056\u0049\u0049\u0049',
  13762. '\u2168': '\u0049\u0058',
  13763. '\u2169': '\u0058',
  13764. '\u216A': '\u0058\u0049',
  13765. '\u216B': '\u0058\u0049\u0049',
  13766. '\u216C': '\u004C',
  13767. '\u216D': '\u0043',
  13768. '\u216E': '\u0044',
  13769. '\u216F': '\u004D',
  13770. '\u2170': '\u0069',
  13771. '\u2171': '\u0069\u0069',
  13772. '\u2172': '\u0069\u0069\u0069',
  13773. '\u2173': '\u0069\u0076',
  13774. '\u2174': '\u0076',
  13775. '\u2175': '\u0076\u0069',
  13776. '\u2176': '\u0076\u0069\u0069',
  13777. '\u2177': '\u0076\u0069\u0069\u0069',
  13778. '\u2178': '\u0069\u0078',
  13779. '\u2179': '\u0078',
  13780. '\u217A': '\u0078\u0069',
  13781. '\u217B': '\u0078\u0069\u0069',
  13782. '\u217C': '\u006C',
  13783. '\u217D': '\u0063',
  13784. '\u217E': '\u0064',
  13785. '\u217F': '\u006D',
  13786. '\u222C': '\u222B\u222B',
  13787. '\u222D': '\u222B\u222B\u222B',
  13788. '\u222F': '\u222E\u222E',
  13789. '\u2230': '\u222E\u222E\u222E',
  13790. '\u2474': '\u0028\u0031\u0029',
  13791. '\u2475': '\u0028\u0032\u0029',
  13792. '\u2476': '\u0028\u0033\u0029',
  13793. '\u2477': '\u0028\u0034\u0029',
  13794. '\u2478': '\u0028\u0035\u0029',
  13795. '\u2479': '\u0028\u0036\u0029',
  13796. '\u247A': '\u0028\u0037\u0029',
  13797. '\u247B': '\u0028\u0038\u0029',
  13798. '\u247C': '\u0028\u0039\u0029',
  13799. '\u247D': '\u0028\u0031\u0030\u0029',
  13800. '\u247E': '\u0028\u0031\u0031\u0029',
  13801. '\u247F': '\u0028\u0031\u0032\u0029',
  13802. '\u2480': '\u0028\u0031\u0033\u0029',
  13803. '\u2481': '\u0028\u0031\u0034\u0029',
  13804. '\u2482': '\u0028\u0031\u0035\u0029',
  13805. '\u2483': '\u0028\u0031\u0036\u0029',
  13806. '\u2484': '\u0028\u0031\u0037\u0029',
  13807. '\u2485': '\u0028\u0031\u0038\u0029',
  13808. '\u2486': '\u0028\u0031\u0039\u0029',
  13809. '\u2487': '\u0028\u0032\u0030\u0029',
  13810. '\u2488': '\u0031\u002E',
  13811. '\u2489': '\u0032\u002E',
  13812. '\u248A': '\u0033\u002E',
  13813. '\u248B': '\u0034\u002E',
  13814. '\u248C': '\u0035\u002E',
  13815. '\u248D': '\u0036\u002E',
  13816. '\u248E': '\u0037\u002E',
  13817. '\u248F': '\u0038\u002E',
  13818. '\u2490': '\u0039\u002E',
  13819. '\u2491': '\u0031\u0030\u002E',
  13820. '\u2492': '\u0031\u0031\u002E',
  13821. '\u2493': '\u0031\u0032\u002E',
  13822. '\u2494': '\u0031\u0033\u002E',
  13823. '\u2495': '\u0031\u0034\u002E',
  13824. '\u2496': '\u0031\u0035\u002E',
  13825. '\u2497': '\u0031\u0036\u002E',
  13826. '\u2498': '\u0031\u0037\u002E',
  13827. '\u2499': '\u0031\u0038\u002E',
  13828. '\u249A': '\u0031\u0039\u002E',
  13829. '\u249B': '\u0032\u0030\u002E',
  13830. '\u249C': '\u0028\u0061\u0029',
  13831. '\u249D': '\u0028\u0062\u0029',
  13832. '\u249E': '\u0028\u0063\u0029',
  13833. '\u249F': '\u0028\u0064\u0029',
  13834. '\u24A0': '\u0028\u0065\u0029',
  13835. '\u24A1': '\u0028\u0066\u0029',
  13836. '\u24A2': '\u0028\u0067\u0029',
  13837. '\u24A3': '\u0028\u0068\u0029',
  13838. '\u24A4': '\u0028\u0069\u0029',
  13839. '\u24A5': '\u0028\u006A\u0029',
  13840. '\u24A6': '\u0028\u006B\u0029',
  13841. '\u24A7': '\u0028\u006C\u0029',
  13842. '\u24A8': '\u0028\u006D\u0029',
  13843. '\u24A9': '\u0028\u006E\u0029',
  13844. '\u24AA': '\u0028\u006F\u0029',
  13845. '\u24AB': '\u0028\u0070\u0029',
  13846. '\u24AC': '\u0028\u0071\u0029',
  13847. '\u24AD': '\u0028\u0072\u0029',
  13848. '\u24AE': '\u0028\u0073\u0029',
  13849. '\u24AF': '\u0028\u0074\u0029',
  13850. '\u24B0': '\u0028\u0075\u0029',
  13851. '\u24B1': '\u0028\u0076\u0029',
  13852. '\u24B2': '\u0028\u0077\u0029',
  13853. '\u24B3': '\u0028\u0078\u0029',
  13854. '\u24B4': '\u0028\u0079\u0029',
  13855. '\u24B5': '\u0028\u007A\u0029',
  13856. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13857. '\u2A74': '\u003A\u003A\u003D',
  13858. '\u2A75': '\u003D\u003D',
  13859. '\u2A76': '\u003D\u003D\u003D',
  13860. '\u2E9F': '\u6BCD',
  13861. '\u2EF3': '\u9F9F',
  13862. '\u2F00': '\u4E00',
  13863. '\u2F01': '\u4E28',
  13864. '\u2F02': '\u4E36',
  13865. '\u2F03': '\u4E3F',
  13866. '\u2F04': '\u4E59',
  13867. '\u2F05': '\u4E85',
  13868. '\u2F06': '\u4E8C',
  13869. '\u2F07': '\u4EA0',
  13870. '\u2F08': '\u4EBA',
  13871. '\u2F09': '\u513F',
  13872. '\u2F0A': '\u5165',
  13873. '\u2F0B': '\u516B',
  13874. '\u2F0C': '\u5182',
  13875. '\u2F0D': '\u5196',
  13876. '\u2F0E': '\u51AB',
  13877. '\u2F0F': '\u51E0',
  13878. '\u2F10': '\u51F5',
  13879. '\u2F11': '\u5200',
  13880. '\u2F12': '\u529B',
  13881. '\u2F13': '\u52F9',
  13882. '\u2F14': '\u5315',
  13883. '\u2F15': '\u531A',
  13884. '\u2F16': '\u5338',
  13885. '\u2F17': '\u5341',
  13886. '\u2F18': '\u535C',
  13887. '\u2F19': '\u5369',
  13888. '\u2F1A': '\u5382',
  13889. '\u2F1B': '\u53B6',
  13890. '\u2F1C': '\u53C8',
  13891. '\u2F1D': '\u53E3',
  13892. '\u2F1E': '\u56D7',
  13893. '\u2F1F': '\u571F',
  13894. '\u2F20': '\u58EB',
  13895. '\u2F21': '\u5902',
  13896. '\u2F22': '\u590A',
  13897. '\u2F23': '\u5915',
  13898. '\u2F24': '\u5927',
  13899. '\u2F25': '\u5973',
  13900. '\u2F26': '\u5B50',
  13901. '\u2F27': '\u5B80',
  13902. '\u2F28': '\u5BF8',
  13903. '\u2F29': '\u5C0F',
  13904. '\u2F2A': '\u5C22',
  13905. '\u2F2B': '\u5C38',
  13906. '\u2F2C': '\u5C6E',
  13907. '\u2F2D': '\u5C71',
  13908. '\u2F2E': '\u5DDB',
  13909. '\u2F2F': '\u5DE5',
  13910. '\u2F30': '\u5DF1',
  13911. '\u2F31': '\u5DFE',
  13912. '\u2F32': '\u5E72',
  13913. '\u2F33': '\u5E7A',
  13914. '\u2F34': '\u5E7F',
  13915. '\u2F35': '\u5EF4',
  13916. '\u2F36': '\u5EFE',
  13917. '\u2F37': '\u5F0B',
  13918. '\u2F38': '\u5F13',
  13919. '\u2F39': '\u5F50',
  13920. '\u2F3A': '\u5F61',
  13921. '\u2F3B': '\u5F73',
  13922. '\u2F3C': '\u5FC3',
  13923. '\u2F3D': '\u6208',
  13924. '\u2F3E': '\u6236',
  13925. '\u2F3F': '\u624B',
  13926. '\u2F40': '\u652F',
  13927. '\u2F41': '\u6534',
  13928. '\u2F42': '\u6587',
  13929. '\u2F43': '\u6597',
  13930. '\u2F44': '\u65A4',
  13931. '\u2F45': '\u65B9',
  13932. '\u2F46': '\u65E0',
  13933. '\u2F47': '\u65E5',
  13934. '\u2F48': '\u66F0',
  13935. '\u2F49': '\u6708',
  13936. '\u2F4A': '\u6728',
  13937. '\u2F4B': '\u6B20',
  13938. '\u2F4C': '\u6B62',
  13939. '\u2F4D': '\u6B79',
  13940. '\u2F4E': '\u6BB3',
  13941. '\u2F4F': '\u6BCB',
  13942. '\u2F50': '\u6BD4',
  13943. '\u2F51': '\u6BDB',
  13944. '\u2F52': '\u6C0F',
  13945. '\u2F53': '\u6C14',
  13946. '\u2F54': '\u6C34',
  13947. '\u2F55': '\u706B',
  13948. '\u2F56': '\u722A',
  13949. '\u2F57': '\u7236',
  13950. '\u2F58': '\u723B',
  13951. '\u2F59': '\u723F',
  13952. '\u2F5A': '\u7247',
  13953. '\u2F5B': '\u7259',
  13954. '\u2F5C': '\u725B',
  13955. '\u2F5D': '\u72AC',
  13956. '\u2F5E': '\u7384',
  13957. '\u2F5F': '\u7389',
  13958. '\u2F60': '\u74DC',
  13959. '\u2F61': '\u74E6',
  13960. '\u2F62': '\u7518',
  13961. '\u2F63': '\u751F',
  13962. '\u2F64': '\u7528',
  13963. '\u2F65': '\u7530',
  13964. '\u2F66': '\u758B',
  13965. '\u2F67': '\u7592',
  13966. '\u2F68': '\u7676',
  13967. '\u2F69': '\u767D',
  13968. '\u2F6A': '\u76AE',
  13969. '\u2F6B': '\u76BF',
  13970. '\u2F6C': '\u76EE',
  13971. '\u2F6D': '\u77DB',
  13972. '\u2F6E': '\u77E2',
  13973. '\u2F6F': '\u77F3',
  13974. '\u2F70': '\u793A',
  13975. '\u2F71': '\u79B8',
  13976. '\u2F72': '\u79BE',
  13977. '\u2F73': '\u7A74',
  13978. '\u2F74': '\u7ACB',
  13979. '\u2F75': '\u7AF9',
  13980. '\u2F76': '\u7C73',
  13981. '\u2F77': '\u7CF8',
  13982. '\u2F78': '\u7F36',
  13983. '\u2F79': '\u7F51',
  13984. '\u2F7A': '\u7F8A',
  13985. '\u2F7B': '\u7FBD',
  13986. '\u2F7C': '\u8001',
  13987. '\u2F7D': '\u800C',
  13988. '\u2F7E': '\u8012',
  13989. '\u2F7F': '\u8033',
  13990. '\u2F80': '\u807F',
  13991. '\u2F81': '\u8089',
  13992. '\u2F82': '\u81E3',
  13993. '\u2F83': '\u81EA',
  13994. '\u2F84': '\u81F3',
  13995. '\u2F85': '\u81FC',
  13996. '\u2F86': '\u820C',
  13997. '\u2F87': '\u821B',
  13998. '\u2F88': '\u821F',
  13999. '\u2F89': '\u826E',
  14000. '\u2F8A': '\u8272',
  14001. '\u2F8B': '\u8278',
  14002. '\u2F8C': '\u864D',
  14003. '\u2F8D': '\u866B',
  14004. '\u2F8E': '\u8840',
  14005. '\u2F8F': '\u884C',
  14006. '\u2F90': '\u8863',
  14007. '\u2F91': '\u897E',
  14008. '\u2F92': '\u898B',
  14009. '\u2F93': '\u89D2',
  14010. '\u2F94': '\u8A00',
  14011. '\u2F95': '\u8C37',
  14012. '\u2F96': '\u8C46',
  14013. '\u2F97': '\u8C55',
  14014. '\u2F98': '\u8C78',
  14015. '\u2F99': '\u8C9D',
  14016. '\u2F9A': '\u8D64',
  14017. '\u2F9B': '\u8D70',
  14018. '\u2F9C': '\u8DB3',
  14019. '\u2F9D': '\u8EAB',
  14020. '\u2F9E': '\u8ECA',
  14021. '\u2F9F': '\u8F9B',
  14022. '\u2FA0': '\u8FB0',
  14023. '\u2FA1': '\u8FB5',
  14024. '\u2FA2': '\u9091',
  14025. '\u2FA3': '\u9149',
  14026. '\u2FA4': '\u91C6',
  14027. '\u2FA5': '\u91CC',
  14028. '\u2FA6': '\u91D1',
  14029. '\u2FA7': '\u9577',
  14030. '\u2FA8': '\u9580',
  14031. '\u2FA9': '\u961C',
  14032. '\u2FAA': '\u96B6',
  14033. '\u2FAB': '\u96B9',
  14034. '\u2FAC': '\u96E8',
  14035. '\u2FAD': '\u9751',
  14036. '\u2FAE': '\u975E',
  14037. '\u2FAF': '\u9762',
  14038. '\u2FB0': '\u9769',
  14039. '\u2FB1': '\u97CB',
  14040. '\u2FB2': '\u97ED',
  14041. '\u2FB3': '\u97F3',
  14042. '\u2FB4': '\u9801',
  14043. '\u2FB5': '\u98A8',
  14044. '\u2FB6': '\u98DB',
  14045. '\u2FB7': '\u98DF',
  14046. '\u2FB8': '\u9996',
  14047. '\u2FB9': '\u9999',
  14048. '\u2FBA': '\u99AC',
  14049. '\u2FBB': '\u9AA8',
  14050. '\u2FBC': '\u9AD8',
  14051. '\u2FBD': '\u9ADF',
  14052. '\u2FBE': '\u9B25',
  14053. '\u2FBF': '\u9B2F',
  14054. '\u2FC0': '\u9B32',
  14055. '\u2FC1': '\u9B3C',
  14056. '\u2FC2': '\u9B5A',
  14057. '\u2FC3': '\u9CE5',
  14058. '\u2FC4': '\u9E75',
  14059. '\u2FC5': '\u9E7F',
  14060. '\u2FC6': '\u9EA5',
  14061. '\u2FC7': '\u9EBB',
  14062. '\u2FC8': '\u9EC3',
  14063. '\u2FC9': '\u9ECD',
  14064. '\u2FCA': '\u9ED1',
  14065. '\u2FCB': '\u9EF9',
  14066. '\u2FCC': '\u9EFD',
  14067. '\u2FCD': '\u9F0E',
  14068. '\u2FCE': '\u9F13',
  14069. '\u2FCF': '\u9F20',
  14070. '\u2FD0': '\u9F3B',
  14071. '\u2FD1': '\u9F4A',
  14072. '\u2FD2': '\u9F52',
  14073. '\u2FD3': '\u9F8D',
  14074. '\u2FD4': '\u9F9C',
  14075. '\u2FD5': '\u9FA0',
  14076. '\u3036': '\u3012',
  14077. '\u3038': '\u5341',
  14078. '\u3039': '\u5344',
  14079. '\u303A': '\u5345',
  14080. '\u309B': '\u0020\u3099',
  14081. '\u309C': '\u0020\u309A',
  14082. '\u3131': '\u1100',
  14083. '\u3132': '\u1101',
  14084. '\u3133': '\u11AA',
  14085. '\u3134': '\u1102',
  14086. '\u3135': '\u11AC',
  14087. '\u3136': '\u11AD',
  14088. '\u3137': '\u1103',
  14089. '\u3138': '\u1104',
  14090. '\u3139': '\u1105',
  14091. '\u313A': '\u11B0',
  14092. '\u313B': '\u11B1',
  14093. '\u313C': '\u11B2',
  14094. '\u313D': '\u11B3',
  14095. '\u313E': '\u11B4',
  14096. '\u313F': '\u11B5',
  14097. '\u3140': '\u111A',
  14098. '\u3141': '\u1106',
  14099. '\u3142': '\u1107',
  14100. '\u3143': '\u1108',
  14101. '\u3144': '\u1121',
  14102. '\u3145': '\u1109',
  14103. '\u3146': '\u110A',
  14104. '\u3147': '\u110B',
  14105. '\u3148': '\u110C',
  14106. '\u3149': '\u110D',
  14107. '\u314A': '\u110E',
  14108. '\u314B': '\u110F',
  14109. '\u314C': '\u1110',
  14110. '\u314D': '\u1111',
  14111. '\u314E': '\u1112',
  14112. '\u314F': '\u1161',
  14113. '\u3150': '\u1162',
  14114. '\u3151': '\u1163',
  14115. '\u3152': '\u1164',
  14116. '\u3153': '\u1165',
  14117. '\u3154': '\u1166',
  14118. '\u3155': '\u1167',
  14119. '\u3156': '\u1168',
  14120. '\u3157': '\u1169',
  14121. '\u3158': '\u116A',
  14122. '\u3159': '\u116B',
  14123. '\u315A': '\u116C',
  14124. '\u315B': '\u116D',
  14125. '\u315C': '\u116E',
  14126. '\u315D': '\u116F',
  14127. '\u315E': '\u1170',
  14128. '\u315F': '\u1171',
  14129. '\u3160': '\u1172',
  14130. '\u3161': '\u1173',
  14131. '\u3162': '\u1174',
  14132. '\u3163': '\u1175',
  14133. '\u3164': '\u1160',
  14134. '\u3165': '\u1114',
  14135. '\u3166': '\u1115',
  14136. '\u3167': '\u11C7',
  14137. '\u3168': '\u11C8',
  14138. '\u3169': '\u11CC',
  14139. '\u316A': '\u11CE',
  14140. '\u316B': '\u11D3',
  14141. '\u316C': '\u11D7',
  14142. '\u316D': '\u11D9',
  14143. '\u316E': '\u111C',
  14144. '\u316F': '\u11DD',
  14145. '\u3170': '\u11DF',
  14146. '\u3171': '\u111D',
  14147. '\u3172': '\u111E',
  14148. '\u3173': '\u1120',
  14149. '\u3174': '\u1122',
  14150. '\u3175': '\u1123',
  14151. '\u3176': '\u1127',
  14152. '\u3177': '\u1129',
  14153. '\u3178': '\u112B',
  14154. '\u3179': '\u112C',
  14155. '\u317A': '\u112D',
  14156. '\u317B': '\u112E',
  14157. '\u317C': '\u112F',
  14158. '\u317D': '\u1132',
  14159. '\u317E': '\u1136',
  14160. '\u317F': '\u1140',
  14161. '\u3180': '\u1147',
  14162. '\u3181': '\u114C',
  14163. '\u3182': '\u11F1',
  14164. '\u3183': '\u11F2',
  14165. '\u3184': '\u1157',
  14166. '\u3185': '\u1158',
  14167. '\u3186': '\u1159',
  14168. '\u3187': '\u1184',
  14169. '\u3188': '\u1185',
  14170. '\u3189': '\u1188',
  14171. '\u318A': '\u1191',
  14172. '\u318B': '\u1192',
  14173. '\u318C': '\u1194',
  14174. '\u318D': '\u119E',
  14175. '\u318E': '\u11A1',
  14176. '\u3200': '\u0028\u1100\u0029',
  14177. '\u3201': '\u0028\u1102\u0029',
  14178. '\u3202': '\u0028\u1103\u0029',
  14179. '\u3203': '\u0028\u1105\u0029',
  14180. '\u3204': '\u0028\u1106\u0029',
  14181. '\u3205': '\u0028\u1107\u0029',
  14182. '\u3206': '\u0028\u1109\u0029',
  14183. '\u3207': '\u0028\u110B\u0029',
  14184. '\u3208': '\u0028\u110C\u0029',
  14185. '\u3209': '\u0028\u110E\u0029',
  14186. '\u320A': '\u0028\u110F\u0029',
  14187. '\u320B': '\u0028\u1110\u0029',
  14188. '\u320C': '\u0028\u1111\u0029',
  14189. '\u320D': '\u0028\u1112\u0029',
  14190. '\u320E': '\u0028\u1100\u1161\u0029',
  14191. '\u320F': '\u0028\u1102\u1161\u0029',
  14192. '\u3210': '\u0028\u1103\u1161\u0029',
  14193. '\u3211': '\u0028\u1105\u1161\u0029',
  14194. '\u3212': '\u0028\u1106\u1161\u0029',
  14195. '\u3213': '\u0028\u1107\u1161\u0029',
  14196. '\u3214': '\u0028\u1109\u1161\u0029',
  14197. '\u3215': '\u0028\u110B\u1161\u0029',
  14198. '\u3216': '\u0028\u110C\u1161\u0029',
  14199. '\u3217': '\u0028\u110E\u1161\u0029',
  14200. '\u3218': '\u0028\u110F\u1161\u0029',
  14201. '\u3219': '\u0028\u1110\u1161\u0029',
  14202. '\u321A': '\u0028\u1111\u1161\u0029',
  14203. '\u321B': '\u0028\u1112\u1161\u0029',
  14204. '\u321C': '\u0028\u110C\u116E\u0029',
  14205. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14206. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14207. '\u3220': '\u0028\u4E00\u0029',
  14208. '\u3221': '\u0028\u4E8C\u0029',
  14209. '\u3222': '\u0028\u4E09\u0029',
  14210. '\u3223': '\u0028\u56DB\u0029',
  14211. '\u3224': '\u0028\u4E94\u0029',
  14212. '\u3225': '\u0028\u516D\u0029',
  14213. '\u3226': '\u0028\u4E03\u0029',
  14214. '\u3227': '\u0028\u516B\u0029',
  14215. '\u3228': '\u0028\u4E5D\u0029',
  14216. '\u3229': '\u0028\u5341\u0029',
  14217. '\u322A': '\u0028\u6708\u0029',
  14218. '\u322B': '\u0028\u706B\u0029',
  14219. '\u322C': '\u0028\u6C34\u0029',
  14220. '\u322D': '\u0028\u6728\u0029',
  14221. '\u322E': '\u0028\u91D1\u0029',
  14222. '\u322F': '\u0028\u571F\u0029',
  14223. '\u3230': '\u0028\u65E5\u0029',
  14224. '\u3231': '\u0028\u682A\u0029',
  14225. '\u3232': '\u0028\u6709\u0029',
  14226. '\u3233': '\u0028\u793E\u0029',
  14227. '\u3234': '\u0028\u540D\u0029',
  14228. '\u3235': '\u0028\u7279\u0029',
  14229. '\u3236': '\u0028\u8CA1\u0029',
  14230. '\u3237': '\u0028\u795D\u0029',
  14231. '\u3238': '\u0028\u52B4\u0029',
  14232. '\u3239': '\u0028\u4EE3\u0029',
  14233. '\u323A': '\u0028\u547C\u0029',
  14234. '\u323B': '\u0028\u5B66\u0029',
  14235. '\u323C': '\u0028\u76E3\u0029',
  14236. '\u323D': '\u0028\u4F01\u0029',
  14237. '\u323E': '\u0028\u8CC7\u0029',
  14238. '\u323F': '\u0028\u5354\u0029',
  14239. '\u3240': '\u0028\u796D\u0029',
  14240. '\u3241': '\u0028\u4F11\u0029',
  14241. '\u3242': '\u0028\u81EA\u0029',
  14242. '\u3243': '\u0028\u81F3\u0029',
  14243. '\u32C0': '\u0031\u6708',
  14244. '\u32C1': '\u0032\u6708',
  14245. '\u32C2': '\u0033\u6708',
  14246. '\u32C3': '\u0034\u6708',
  14247. '\u32C4': '\u0035\u6708',
  14248. '\u32C5': '\u0036\u6708',
  14249. '\u32C6': '\u0037\u6708',
  14250. '\u32C7': '\u0038\u6708',
  14251. '\u32C8': '\u0039\u6708',
  14252. '\u32C9': '\u0031\u0030\u6708',
  14253. '\u32CA': '\u0031\u0031\u6708',
  14254. '\u32CB': '\u0031\u0032\u6708',
  14255. '\u3358': '\u0030\u70B9',
  14256. '\u3359': '\u0031\u70B9',
  14257. '\u335A': '\u0032\u70B9',
  14258. '\u335B': '\u0033\u70B9',
  14259. '\u335C': '\u0034\u70B9',
  14260. '\u335D': '\u0035\u70B9',
  14261. '\u335E': '\u0036\u70B9',
  14262. '\u335F': '\u0037\u70B9',
  14263. '\u3360': '\u0038\u70B9',
  14264. '\u3361': '\u0039\u70B9',
  14265. '\u3362': '\u0031\u0030\u70B9',
  14266. '\u3363': '\u0031\u0031\u70B9',
  14267. '\u3364': '\u0031\u0032\u70B9',
  14268. '\u3365': '\u0031\u0033\u70B9',
  14269. '\u3366': '\u0031\u0034\u70B9',
  14270. '\u3367': '\u0031\u0035\u70B9',
  14271. '\u3368': '\u0031\u0036\u70B9',
  14272. '\u3369': '\u0031\u0037\u70B9',
  14273. '\u336A': '\u0031\u0038\u70B9',
  14274. '\u336B': '\u0031\u0039\u70B9',
  14275. '\u336C': '\u0032\u0030\u70B9',
  14276. '\u336D': '\u0032\u0031\u70B9',
  14277. '\u336E': '\u0032\u0032\u70B9',
  14278. '\u336F': '\u0032\u0033\u70B9',
  14279. '\u3370': '\u0032\u0034\u70B9',
  14280. '\u33E0': '\u0031\u65E5',
  14281. '\u33E1': '\u0032\u65E5',
  14282. '\u33E2': '\u0033\u65E5',
  14283. '\u33E3': '\u0034\u65E5',
  14284. '\u33E4': '\u0035\u65E5',
  14285. '\u33E5': '\u0036\u65E5',
  14286. '\u33E6': '\u0037\u65E5',
  14287. '\u33E7': '\u0038\u65E5',
  14288. '\u33E8': '\u0039\u65E5',
  14289. '\u33E9': '\u0031\u0030\u65E5',
  14290. '\u33EA': '\u0031\u0031\u65E5',
  14291. '\u33EB': '\u0031\u0032\u65E5',
  14292. '\u33EC': '\u0031\u0033\u65E5',
  14293. '\u33ED': '\u0031\u0034\u65E5',
  14294. '\u33EE': '\u0031\u0035\u65E5',
  14295. '\u33EF': '\u0031\u0036\u65E5',
  14296. '\u33F0': '\u0031\u0037\u65E5',
  14297. '\u33F1': '\u0031\u0038\u65E5',
  14298. '\u33F2': '\u0031\u0039\u65E5',
  14299. '\u33F3': '\u0032\u0030\u65E5',
  14300. '\u33F4': '\u0032\u0031\u65E5',
  14301. '\u33F5': '\u0032\u0032\u65E5',
  14302. '\u33F6': '\u0032\u0033\u65E5',
  14303. '\u33F7': '\u0032\u0034\u65E5',
  14304. '\u33F8': '\u0032\u0035\u65E5',
  14305. '\u33F9': '\u0032\u0036\u65E5',
  14306. '\u33FA': '\u0032\u0037\u65E5',
  14307. '\u33FB': '\u0032\u0038\u65E5',
  14308. '\u33FC': '\u0032\u0039\u65E5',
  14309. '\u33FD': '\u0033\u0030\u65E5',
  14310. '\u33FE': '\u0033\u0031\u65E5',
  14311. '\uFB00': '\u0066\u0066',
  14312. '\uFB01': '\u0066\u0069',
  14313. '\uFB02': '\u0066\u006C',
  14314. '\uFB03': '\u0066\u0066\u0069',
  14315. '\uFB04': '\u0066\u0066\u006C',
  14316. '\uFB05': '\u017F\u0074',
  14317. '\uFB06': '\u0073\u0074',
  14318. '\uFB13': '\u0574\u0576',
  14319. '\uFB14': '\u0574\u0565',
  14320. '\uFB15': '\u0574\u056B',
  14321. '\uFB16': '\u057E\u0576',
  14322. '\uFB17': '\u0574\u056D',
  14323. '\uFB4F': '\u05D0\u05DC',
  14324. '\uFB50': '\u0671',
  14325. '\uFB51': '\u0671',
  14326. '\uFB52': '\u067B',
  14327. '\uFB53': '\u067B',
  14328. '\uFB54': '\u067B',
  14329. '\uFB55': '\u067B',
  14330. '\uFB56': '\u067E',
  14331. '\uFB57': '\u067E',
  14332. '\uFB58': '\u067E',
  14333. '\uFB59': '\u067E',
  14334. '\uFB5A': '\u0680',
  14335. '\uFB5B': '\u0680',
  14336. '\uFB5C': '\u0680',
  14337. '\uFB5D': '\u0680',
  14338. '\uFB5E': '\u067A',
  14339. '\uFB5F': '\u067A',
  14340. '\uFB60': '\u067A',
  14341. '\uFB61': '\u067A',
  14342. '\uFB62': '\u067F',
  14343. '\uFB63': '\u067F',
  14344. '\uFB64': '\u067F',
  14345. '\uFB65': '\u067F',
  14346. '\uFB66': '\u0679',
  14347. '\uFB67': '\u0679',
  14348. '\uFB68': '\u0679',
  14349. '\uFB69': '\u0679',
  14350. '\uFB6A': '\u06A4',
  14351. '\uFB6B': '\u06A4',
  14352. '\uFB6C': '\u06A4',
  14353. '\uFB6D': '\u06A4',
  14354. '\uFB6E': '\u06A6',
  14355. '\uFB6F': '\u06A6',
  14356. '\uFB70': '\u06A6',
  14357. '\uFB71': '\u06A6',
  14358. '\uFB72': '\u0684',
  14359. '\uFB73': '\u0684',
  14360. '\uFB74': '\u0684',
  14361. '\uFB75': '\u0684',
  14362. '\uFB76': '\u0683',
  14363. '\uFB77': '\u0683',
  14364. '\uFB78': '\u0683',
  14365. '\uFB79': '\u0683',
  14366. '\uFB7A': '\u0686',
  14367. '\uFB7B': '\u0686',
  14368. '\uFB7C': '\u0686',
  14369. '\uFB7D': '\u0686',
  14370. '\uFB7E': '\u0687',
  14371. '\uFB7F': '\u0687',
  14372. '\uFB80': '\u0687',
  14373. '\uFB81': '\u0687',
  14374. '\uFB82': '\u068D',
  14375. '\uFB83': '\u068D',
  14376. '\uFB84': '\u068C',
  14377. '\uFB85': '\u068C',
  14378. '\uFB86': '\u068E',
  14379. '\uFB87': '\u068E',
  14380. '\uFB88': '\u0688',
  14381. '\uFB89': '\u0688',
  14382. '\uFB8A': '\u0698',
  14383. '\uFB8B': '\u0698',
  14384. '\uFB8C': '\u0691',
  14385. '\uFB8D': '\u0691',
  14386. '\uFB8E': '\u06A9',
  14387. '\uFB8F': '\u06A9',
  14388. '\uFB90': '\u06A9',
  14389. '\uFB91': '\u06A9',
  14390. '\uFB92': '\u06AF',
  14391. '\uFB93': '\u06AF',
  14392. '\uFB94': '\u06AF',
  14393. '\uFB95': '\u06AF',
  14394. '\uFB96': '\u06B3',
  14395. '\uFB97': '\u06B3',
  14396. '\uFB98': '\u06B3',
  14397. '\uFB99': '\u06B3',
  14398. '\uFB9A': '\u06B1',
  14399. '\uFB9B': '\u06B1',
  14400. '\uFB9C': '\u06B1',
  14401. '\uFB9D': '\u06B1',
  14402. '\uFB9E': '\u06BA',
  14403. '\uFB9F': '\u06BA',
  14404. '\uFBA0': '\u06BB',
  14405. '\uFBA1': '\u06BB',
  14406. '\uFBA2': '\u06BB',
  14407. '\uFBA3': '\u06BB',
  14408. '\uFBA4': '\u06C0',
  14409. '\uFBA5': '\u06C0',
  14410. '\uFBA6': '\u06C1',
  14411. '\uFBA7': '\u06C1',
  14412. '\uFBA8': '\u06C1',
  14413. '\uFBA9': '\u06C1',
  14414. '\uFBAA': '\u06BE',
  14415. '\uFBAB': '\u06BE',
  14416. '\uFBAC': '\u06BE',
  14417. '\uFBAD': '\u06BE',
  14418. '\uFBAE': '\u06D2',
  14419. '\uFBAF': '\u06D2',
  14420. '\uFBB0': '\u06D3',
  14421. '\uFBB1': '\u06D3',
  14422. '\uFBD3': '\u06AD',
  14423. '\uFBD4': '\u06AD',
  14424. '\uFBD5': '\u06AD',
  14425. '\uFBD6': '\u06AD',
  14426. '\uFBD7': '\u06C7',
  14427. '\uFBD8': '\u06C7',
  14428. '\uFBD9': '\u06C6',
  14429. '\uFBDA': '\u06C6',
  14430. '\uFBDB': '\u06C8',
  14431. '\uFBDC': '\u06C8',
  14432. '\uFBDD': '\u0677',
  14433. '\uFBDE': '\u06CB',
  14434. '\uFBDF': '\u06CB',
  14435. '\uFBE0': '\u06C5',
  14436. '\uFBE1': '\u06C5',
  14437. '\uFBE2': '\u06C9',
  14438. '\uFBE3': '\u06C9',
  14439. '\uFBE4': '\u06D0',
  14440. '\uFBE5': '\u06D0',
  14441. '\uFBE6': '\u06D0',
  14442. '\uFBE7': '\u06D0',
  14443. '\uFBE8': '\u0649',
  14444. '\uFBE9': '\u0649',
  14445. '\uFBEA': '\u0626\u0627',
  14446. '\uFBEB': '\u0626\u0627',
  14447. '\uFBEC': '\u0626\u06D5',
  14448. '\uFBED': '\u0626\u06D5',
  14449. '\uFBEE': '\u0626\u0648',
  14450. '\uFBEF': '\u0626\u0648',
  14451. '\uFBF0': '\u0626\u06C7',
  14452. '\uFBF1': '\u0626\u06C7',
  14453. '\uFBF2': '\u0626\u06C6',
  14454. '\uFBF3': '\u0626\u06C6',
  14455. '\uFBF4': '\u0626\u06C8',
  14456. '\uFBF5': '\u0626\u06C8',
  14457. '\uFBF6': '\u0626\u06D0',
  14458. '\uFBF7': '\u0626\u06D0',
  14459. '\uFBF8': '\u0626\u06D0',
  14460. '\uFBF9': '\u0626\u0649',
  14461. '\uFBFA': '\u0626\u0649',
  14462. '\uFBFB': '\u0626\u0649',
  14463. '\uFBFC': '\u06CC',
  14464. '\uFBFD': '\u06CC',
  14465. '\uFBFE': '\u06CC',
  14466. '\uFBFF': '\u06CC',
  14467. '\uFC00': '\u0626\u062C',
  14468. '\uFC01': '\u0626\u062D',
  14469. '\uFC02': '\u0626\u0645',
  14470. '\uFC03': '\u0626\u0649',
  14471. '\uFC04': '\u0626\u064A',
  14472. '\uFC05': '\u0628\u062C',
  14473. '\uFC06': '\u0628\u062D',
  14474. '\uFC07': '\u0628\u062E',
  14475. '\uFC08': '\u0628\u0645',
  14476. '\uFC09': '\u0628\u0649',
  14477. '\uFC0A': '\u0628\u064A',
  14478. '\uFC0B': '\u062A\u062C',
  14479. '\uFC0C': '\u062A\u062D',
  14480. '\uFC0D': '\u062A\u062E',
  14481. '\uFC0E': '\u062A\u0645',
  14482. '\uFC0F': '\u062A\u0649',
  14483. '\uFC10': '\u062A\u064A',
  14484. '\uFC11': '\u062B\u062C',
  14485. '\uFC12': '\u062B\u0645',
  14486. '\uFC13': '\u062B\u0649',
  14487. '\uFC14': '\u062B\u064A',
  14488. '\uFC15': '\u062C\u062D',
  14489. '\uFC16': '\u062C\u0645',
  14490. '\uFC17': '\u062D\u062C',
  14491. '\uFC18': '\u062D\u0645',
  14492. '\uFC19': '\u062E\u062C',
  14493. '\uFC1A': '\u062E\u062D',
  14494. '\uFC1B': '\u062E\u0645',
  14495. '\uFC1C': '\u0633\u062C',
  14496. '\uFC1D': '\u0633\u062D',
  14497. '\uFC1E': '\u0633\u062E',
  14498. '\uFC1F': '\u0633\u0645',
  14499. '\uFC20': '\u0635\u062D',
  14500. '\uFC21': '\u0635\u0645',
  14501. '\uFC22': '\u0636\u062C',
  14502. '\uFC23': '\u0636\u062D',
  14503. '\uFC24': '\u0636\u062E',
  14504. '\uFC25': '\u0636\u0645',
  14505. '\uFC26': '\u0637\u062D',
  14506. '\uFC27': '\u0637\u0645',
  14507. '\uFC28': '\u0638\u0645',
  14508. '\uFC29': '\u0639\u062C',
  14509. '\uFC2A': '\u0639\u0645',
  14510. '\uFC2B': '\u063A\u062C',
  14511. '\uFC2C': '\u063A\u0645',
  14512. '\uFC2D': '\u0641\u062C',
  14513. '\uFC2E': '\u0641\u062D',
  14514. '\uFC2F': '\u0641\u062E',
  14515. '\uFC30': '\u0641\u0645',
  14516. '\uFC31': '\u0641\u0649',
  14517. '\uFC32': '\u0641\u064A',
  14518. '\uFC33': '\u0642\u062D',
  14519. '\uFC34': '\u0642\u0645',
  14520. '\uFC35': '\u0642\u0649',
  14521. '\uFC36': '\u0642\u064A',
  14522. '\uFC37': '\u0643\u0627',
  14523. '\uFC38': '\u0643\u062C',
  14524. '\uFC39': '\u0643\u062D',
  14525. '\uFC3A': '\u0643\u062E',
  14526. '\uFC3B': '\u0643\u0644',
  14527. '\uFC3C': '\u0643\u0645',
  14528. '\uFC3D': '\u0643\u0649',
  14529. '\uFC3E': '\u0643\u064A',
  14530. '\uFC3F': '\u0644\u062C',
  14531. '\uFC40': '\u0644\u062D',
  14532. '\uFC41': '\u0644\u062E',
  14533. '\uFC42': '\u0644\u0645',
  14534. '\uFC43': '\u0644\u0649',
  14535. '\uFC44': '\u0644\u064A',
  14536. '\uFC45': '\u0645\u062C',
  14537. '\uFC46': '\u0645\u062D',
  14538. '\uFC47': '\u0645\u062E',
  14539. '\uFC48': '\u0645\u0645',
  14540. '\uFC49': '\u0645\u0649',
  14541. '\uFC4A': '\u0645\u064A',
  14542. '\uFC4B': '\u0646\u062C',
  14543. '\uFC4C': '\u0646\u062D',
  14544. '\uFC4D': '\u0646\u062E',
  14545. '\uFC4E': '\u0646\u0645',
  14546. '\uFC4F': '\u0646\u0649',
  14547. '\uFC50': '\u0646\u064A',
  14548. '\uFC51': '\u0647\u062C',
  14549. '\uFC52': '\u0647\u0645',
  14550. '\uFC53': '\u0647\u0649',
  14551. '\uFC54': '\u0647\u064A',
  14552. '\uFC55': '\u064A\u062C',
  14553. '\uFC56': '\u064A\u062D',
  14554. '\uFC57': '\u064A\u062E',
  14555. '\uFC58': '\u064A\u0645',
  14556. '\uFC59': '\u064A\u0649',
  14557. '\uFC5A': '\u064A\u064A',
  14558. '\uFC5B': '\u0630\u0670',
  14559. '\uFC5C': '\u0631\u0670',
  14560. '\uFC5D': '\u0649\u0670',
  14561. '\uFC5E': '\u0020\u064C\u0651',
  14562. '\uFC5F': '\u0020\u064D\u0651',
  14563. '\uFC60': '\u0020\u064E\u0651',
  14564. '\uFC61': '\u0020\u064F\u0651',
  14565. '\uFC62': '\u0020\u0650\u0651',
  14566. '\uFC63': '\u0020\u0651\u0670',
  14567. '\uFC64': '\u0626\u0631',
  14568. '\uFC65': '\u0626\u0632',
  14569. '\uFC66': '\u0626\u0645',
  14570. '\uFC67': '\u0626\u0646',
  14571. '\uFC68': '\u0626\u0649',
  14572. '\uFC69': '\u0626\u064A',
  14573. '\uFC6A': '\u0628\u0631',
  14574. '\uFC6B': '\u0628\u0632',
  14575. '\uFC6C': '\u0628\u0645',
  14576. '\uFC6D': '\u0628\u0646',
  14577. '\uFC6E': '\u0628\u0649',
  14578. '\uFC6F': '\u0628\u064A',
  14579. '\uFC70': '\u062A\u0631',
  14580. '\uFC71': '\u062A\u0632',
  14581. '\uFC72': '\u062A\u0645',
  14582. '\uFC73': '\u062A\u0646',
  14583. '\uFC74': '\u062A\u0649',
  14584. '\uFC75': '\u062A\u064A',
  14585. '\uFC76': '\u062B\u0631',
  14586. '\uFC77': '\u062B\u0632',
  14587. '\uFC78': '\u062B\u0645',
  14588. '\uFC79': '\u062B\u0646',
  14589. '\uFC7A': '\u062B\u0649',
  14590. '\uFC7B': '\u062B\u064A',
  14591. '\uFC7C': '\u0641\u0649',
  14592. '\uFC7D': '\u0641\u064A',
  14593. '\uFC7E': '\u0642\u0649',
  14594. '\uFC7F': '\u0642\u064A',
  14595. '\uFC80': '\u0643\u0627',
  14596. '\uFC81': '\u0643\u0644',
  14597. '\uFC82': '\u0643\u0645',
  14598. '\uFC83': '\u0643\u0649',
  14599. '\uFC84': '\u0643\u064A',
  14600. '\uFC85': '\u0644\u0645',
  14601. '\uFC86': '\u0644\u0649',
  14602. '\uFC87': '\u0644\u064A',
  14603. '\uFC88': '\u0645\u0627',
  14604. '\uFC89': '\u0645\u0645',
  14605. '\uFC8A': '\u0646\u0631',
  14606. '\uFC8B': '\u0646\u0632',
  14607. '\uFC8C': '\u0646\u0645',
  14608. '\uFC8D': '\u0646\u0646',
  14609. '\uFC8E': '\u0646\u0649',
  14610. '\uFC8F': '\u0646\u064A',
  14611. '\uFC90': '\u0649\u0670',
  14612. '\uFC91': '\u064A\u0631',
  14613. '\uFC92': '\u064A\u0632',
  14614. '\uFC93': '\u064A\u0645',
  14615. '\uFC94': '\u064A\u0646',
  14616. '\uFC95': '\u064A\u0649',
  14617. '\uFC96': '\u064A\u064A',
  14618. '\uFC97': '\u0626\u062C',
  14619. '\uFC98': '\u0626\u062D',
  14620. '\uFC99': '\u0626\u062E',
  14621. '\uFC9A': '\u0626\u0645',
  14622. '\uFC9B': '\u0626\u0647',
  14623. '\uFC9C': '\u0628\u062C',
  14624. '\uFC9D': '\u0628\u062D',
  14625. '\uFC9E': '\u0628\u062E',
  14626. '\uFC9F': '\u0628\u0645',
  14627. '\uFCA0': '\u0628\u0647',
  14628. '\uFCA1': '\u062A\u062C',
  14629. '\uFCA2': '\u062A\u062D',
  14630. '\uFCA3': '\u062A\u062E',
  14631. '\uFCA4': '\u062A\u0645',
  14632. '\uFCA5': '\u062A\u0647',
  14633. '\uFCA6': '\u062B\u0645',
  14634. '\uFCA7': '\u062C\u062D',
  14635. '\uFCA8': '\u062C\u0645',
  14636. '\uFCA9': '\u062D\u062C',
  14637. '\uFCAA': '\u062D\u0645',
  14638. '\uFCAB': '\u062E\u062C',
  14639. '\uFCAC': '\u062E\u0645',
  14640. '\uFCAD': '\u0633\u062C',
  14641. '\uFCAE': '\u0633\u062D',
  14642. '\uFCAF': '\u0633\u062E',
  14643. '\uFCB0': '\u0633\u0645',
  14644. '\uFCB1': '\u0635\u062D',
  14645. '\uFCB2': '\u0635\u062E',
  14646. '\uFCB3': '\u0635\u0645',
  14647. '\uFCB4': '\u0636\u062C',
  14648. '\uFCB5': '\u0636\u062D',
  14649. '\uFCB6': '\u0636\u062E',
  14650. '\uFCB7': '\u0636\u0645',
  14651. '\uFCB8': '\u0637\u062D',
  14652. '\uFCB9': '\u0638\u0645',
  14653. '\uFCBA': '\u0639\u062C',
  14654. '\uFCBB': '\u0639\u0645',
  14655. '\uFCBC': '\u063A\u062C',
  14656. '\uFCBD': '\u063A\u0645',
  14657. '\uFCBE': '\u0641\u062C',
  14658. '\uFCBF': '\u0641\u062D',
  14659. '\uFCC0': '\u0641\u062E',
  14660. '\uFCC1': '\u0641\u0645',
  14661. '\uFCC2': '\u0642\u062D',
  14662. '\uFCC3': '\u0642\u0645',
  14663. '\uFCC4': '\u0643\u062C',
  14664. '\uFCC5': '\u0643\u062D',
  14665. '\uFCC6': '\u0643\u062E',
  14666. '\uFCC7': '\u0643\u0644',
  14667. '\uFCC8': '\u0643\u0645',
  14668. '\uFCC9': '\u0644\u062C',
  14669. '\uFCCA': '\u0644\u062D',
  14670. '\uFCCB': '\u0644\u062E',
  14671. '\uFCCC': '\u0644\u0645',
  14672. '\uFCCD': '\u0644\u0647',
  14673. '\uFCCE': '\u0645\u062C',
  14674. '\uFCCF': '\u0645\u062D',
  14675. '\uFCD0': '\u0645\u062E',
  14676. '\uFCD1': '\u0645\u0645',
  14677. '\uFCD2': '\u0646\u062C',
  14678. '\uFCD3': '\u0646\u062D',
  14679. '\uFCD4': '\u0646\u062E',
  14680. '\uFCD5': '\u0646\u0645',
  14681. '\uFCD6': '\u0646\u0647',
  14682. '\uFCD7': '\u0647\u062C',
  14683. '\uFCD8': '\u0647\u0645',
  14684. '\uFCD9': '\u0647\u0670',
  14685. '\uFCDA': '\u064A\u062C',
  14686. '\uFCDB': '\u064A\u062D',
  14687. '\uFCDC': '\u064A\u062E',
  14688. '\uFCDD': '\u064A\u0645',
  14689. '\uFCDE': '\u064A\u0647',
  14690. '\uFCDF': '\u0626\u0645',
  14691. '\uFCE0': '\u0626\u0647',
  14692. '\uFCE1': '\u0628\u0645',
  14693. '\uFCE2': '\u0628\u0647',
  14694. '\uFCE3': '\u062A\u0645',
  14695. '\uFCE4': '\u062A\u0647',
  14696. '\uFCE5': '\u062B\u0645',
  14697. '\uFCE6': '\u062B\u0647',
  14698. '\uFCE7': '\u0633\u0645',
  14699. '\uFCE8': '\u0633\u0647',
  14700. '\uFCE9': '\u0634\u0645',
  14701. '\uFCEA': '\u0634\u0647',
  14702. '\uFCEB': '\u0643\u0644',
  14703. '\uFCEC': '\u0643\u0645',
  14704. '\uFCED': '\u0644\u0645',
  14705. '\uFCEE': '\u0646\u0645',
  14706. '\uFCEF': '\u0646\u0647',
  14707. '\uFCF0': '\u064A\u0645',
  14708. '\uFCF1': '\u064A\u0647',
  14709. '\uFCF2': '\u0640\u064E\u0651',
  14710. '\uFCF3': '\u0640\u064F\u0651',
  14711. '\uFCF4': '\u0640\u0650\u0651',
  14712. '\uFCF5': '\u0637\u0649',
  14713. '\uFCF6': '\u0637\u064A',
  14714. '\uFCF7': '\u0639\u0649',
  14715. '\uFCF8': '\u0639\u064A',
  14716. '\uFCF9': '\u063A\u0649',
  14717. '\uFCFA': '\u063A\u064A',
  14718. '\uFCFB': '\u0633\u0649',
  14719. '\uFCFC': '\u0633\u064A',
  14720. '\uFCFD': '\u0634\u0649',
  14721. '\uFCFE': '\u0634\u064A',
  14722. '\uFCFF': '\u062D\u0649',
  14723. '\uFD00': '\u062D\u064A',
  14724. '\uFD01': '\u062C\u0649',
  14725. '\uFD02': '\u062C\u064A',
  14726. '\uFD03': '\u062E\u0649',
  14727. '\uFD04': '\u062E\u064A',
  14728. '\uFD05': '\u0635\u0649',
  14729. '\uFD06': '\u0635\u064A',
  14730. '\uFD07': '\u0636\u0649',
  14731. '\uFD08': '\u0636\u064A',
  14732. '\uFD09': '\u0634\u062C',
  14733. '\uFD0A': '\u0634\u062D',
  14734. '\uFD0B': '\u0634\u062E',
  14735. '\uFD0C': '\u0634\u0645',
  14736. '\uFD0D': '\u0634\u0631',
  14737. '\uFD0E': '\u0633\u0631',
  14738. '\uFD0F': '\u0635\u0631',
  14739. '\uFD10': '\u0636\u0631',
  14740. '\uFD11': '\u0637\u0649',
  14741. '\uFD12': '\u0637\u064A',
  14742. '\uFD13': '\u0639\u0649',
  14743. '\uFD14': '\u0639\u064A',
  14744. '\uFD15': '\u063A\u0649',
  14745. '\uFD16': '\u063A\u064A',
  14746. '\uFD17': '\u0633\u0649',
  14747. '\uFD18': '\u0633\u064A',
  14748. '\uFD19': '\u0634\u0649',
  14749. '\uFD1A': '\u0634\u064A',
  14750. '\uFD1B': '\u062D\u0649',
  14751. '\uFD1C': '\u062D\u064A',
  14752. '\uFD1D': '\u062C\u0649',
  14753. '\uFD1E': '\u062C\u064A',
  14754. '\uFD1F': '\u062E\u0649',
  14755. '\uFD20': '\u062E\u064A',
  14756. '\uFD21': '\u0635\u0649',
  14757. '\uFD22': '\u0635\u064A',
  14758. '\uFD23': '\u0636\u0649',
  14759. '\uFD24': '\u0636\u064A',
  14760. '\uFD25': '\u0634\u062C',
  14761. '\uFD26': '\u0634\u062D',
  14762. '\uFD27': '\u0634\u062E',
  14763. '\uFD28': '\u0634\u0645',
  14764. '\uFD29': '\u0634\u0631',
  14765. '\uFD2A': '\u0633\u0631',
  14766. '\uFD2B': '\u0635\u0631',
  14767. '\uFD2C': '\u0636\u0631',
  14768. '\uFD2D': '\u0634\u062C',
  14769. '\uFD2E': '\u0634\u062D',
  14770. '\uFD2F': '\u0634\u062E',
  14771. '\uFD30': '\u0634\u0645',
  14772. '\uFD31': '\u0633\u0647',
  14773. '\uFD32': '\u0634\u0647',
  14774. '\uFD33': '\u0637\u0645',
  14775. '\uFD34': '\u0633\u062C',
  14776. '\uFD35': '\u0633\u062D',
  14777. '\uFD36': '\u0633\u062E',
  14778. '\uFD37': '\u0634\u062C',
  14779. '\uFD38': '\u0634\u062D',
  14780. '\uFD39': '\u0634\u062E',
  14781. '\uFD3A': '\u0637\u0645',
  14782. '\uFD3B': '\u0638\u0645',
  14783. '\uFD3C': '\u0627\u064B',
  14784. '\uFD3D': '\u0627\u064B',
  14785. '\uFD50': '\u062A\u062C\u0645',
  14786. '\uFD51': '\u062A\u062D\u062C',
  14787. '\uFD52': '\u062A\u062D\u062C',
  14788. '\uFD53': '\u062A\u062D\u0645',
  14789. '\uFD54': '\u062A\u062E\u0645',
  14790. '\uFD55': '\u062A\u0645\u062C',
  14791. '\uFD56': '\u062A\u0645\u062D',
  14792. '\uFD57': '\u062A\u0645\u062E',
  14793. '\uFD58': '\u062C\u0645\u062D',
  14794. '\uFD59': '\u062C\u0645\u062D',
  14795. '\uFD5A': '\u062D\u0645\u064A',
  14796. '\uFD5B': '\u062D\u0645\u0649',
  14797. '\uFD5C': '\u0633\u062D\u062C',
  14798. '\uFD5D': '\u0633\u062C\u062D',
  14799. '\uFD5E': '\u0633\u062C\u0649',
  14800. '\uFD5F': '\u0633\u0645\u062D',
  14801. '\uFD60': '\u0633\u0645\u062D',
  14802. '\uFD61': '\u0633\u0645\u062C',
  14803. '\uFD62': '\u0633\u0645\u0645',
  14804. '\uFD63': '\u0633\u0645\u0645',
  14805. '\uFD64': '\u0635\u062D\u062D',
  14806. '\uFD65': '\u0635\u062D\u062D',
  14807. '\uFD66': '\u0635\u0645\u0645',
  14808. '\uFD67': '\u0634\u062D\u0645',
  14809. '\uFD68': '\u0634\u062D\u0645',
  14810. '\uFD69': '\u0634\u062C\u064A',
  14811. '\uFD6A': '\u0634\u0645\u062E',
  14812. '\uFD6B': '\u0634\u0645\u062E',
  14813. '\uFD6C': '\u0634\u0645\u0645',
  14814. '\uFD6D': '\u0634\u0645\u0645',
  14815. '\uFD6E': '\u0636\u062D\u0649',
  14816. '\uFD6F': '\u0636\u062E\u0645',
  14817. '\uFD70': '\u0636\u062E\u0645',
  14818. '\uFD71': '\u0637\u0645\u062D',
  14819. '\uFD72': '\u0637\u0645\u062D',
  14820. '\uFD73': '\u0637\u0645\u0645',
  14821. '\uFD74': '\u0637\u0645\u064A',
  14822. '\uFD75': '\u0639\u062C\u0645',
  14823. '\uFD76': '\u0639\u0645\u0645',
  14824. '\uFD77': '\u0639\u0645\u0645',
  14825. '\uFD78': '\u0639\u0645\u0649',
  14826. '\uFD79': '\u063A\u0645\u0645',
  14827. '\uFD7A': '\u063A\u0645\u064A',
  14828. '\uFD7B': '\u063A\u0645\u0649',
  14829. '\uFD7C': '\u0641\u062E\u0645',
  14830. '\uFD7D': '\u0641\u062E\u0645',
  14831. '\uFD7E': '\u0642\u0645\u062D',
  14832. '\uFD7F': '\u0642\u0645\u0645',
  14833. '\uFD80': '\u0644\u062D\u0645',
  14834. '\uFD81': '\u0644\u062D\u064A',
  14835. '\uFD82': '\u0644\u062D\u0649',
  14836. '\uFD83': '\u0644\u062C\u062C',
  14837. '\uFD84': '\u0644\u062C\u062C',
  14838. '\uFD85': '\u0644\u062E\u0645',
  14839. '\uFD86': '\u0644\u062E\u0645',
  14840. '\uFD87': '\u0644\u0645\u062D',
  14841. '\uFD88': '\u0644\u0645\u062D',
  14842. '\uFD89': '\u0645\u062D\u062C',
  14843. '\uFD8A': '\u0645\u062D\u0645',
  14844. '\uFD8B': '\u0645\u062D\u064A',
  14845. '\uFD8C': '\u0645\u062C\u062D',
  14846. '\uFD8D': '\u0645\u062C\u0645',
  14847. '\uFD8E': '\u0645\u062E\u062C',
  14848. '\uFD8F': '\u0645\u062E\u0645',
  14849. '\uFD92': '\u0645\u062C\u062E',
  14850. '\uFD93': '\u0647\u0645\u062C',
  14851. '\uFD94': '\u0647\u0645\u0645',
  14852. '\uFD95': '\u0646\u062D\u0645',
  14853. '\uFD96': '\u0646\u062D\u0649',
  14854. '\uFD97': '\u0646\u062C\u0645',
  14855. '\uFD98': '\u0646\u062C\u0645',
  14856. '\uFD99': '\u0646\u062C\u0649',
  14857. '\uFD9A': '\u0646\u0645\u064A',
  14858. '\uFD9B': '\u0646\u0645\u0649',
  14859. '\uFD9C': '\u064A\u0645\u0645',
  14860. '\uFD9D': '\u064A\u0645\u0645',
  14861. '\uFD9E': '\u0628\u062E\u064A',
  14862. '\uFD9F': '\u062A\u062C\u064A',
  14863. '\uFDA0': '\u062A\u062C\u0649',
  14864. '\uFDA1': '\u062A\u062E\u064A',
  14865. '\uFDA2': '\u062A\u062E\u0649',
  14866. '\uFDA3': '\u062A\u0645\u064A',
  14867. '\uFDA4': '\u062A\u0645\u0649',
  14868. '\uFDA5': '\u062C\u0645\u064A',
  14869. '\uFDA6': '\u062C\u062D\u0649',
  14870. '\uFDA7': '\u062C\u0645\u0649',
  14871. '\uFDA8': '\u0633\u062E\u0649',
  14872. '\uFDA9': '\u0635\u062D\u064A',
  14873. '\uFDAA': '\u0634\u062D\u064A',
  14874. '\uFDAB': '\u0636\u062D\u064A',
  14875. '\uFDAC': '\u0644\u062C\u064A',
  14876. '\uFDAD': '\u0644\u0645\u064A',
  14877. '\uFDAE': '\u064A\u062D\u064A',
  14878. '\uFDAF': '\u064A\u062C\u064A',
  14879. '\uFDB0': '\u064A\u0645\u064A',
  14880. '\uFDB1': '\u0645\u0645\u064A',
  14881. '\uFDB2': '\u0642\u0645\u064A',
  14882. '\uFDB3': '\u0646\u062D\u064A',
  14883. '\uFDB4': '\u0642\u0645\u062D',
  14884. '\uFDB5': '\u0644\u062D\u0645',
  14885. '\uFDB6': '\u0639\u0645\u064A',
  14886. '\uFDB7': '\u0643\u0645\u064A',
  14887. '\uFDB8': '\u0646\u062C\u062D',
  14888. '\uFDB9': '\u0645\u062E\u064A',
  14889. '\uFDBA': '\u0644\u062C\u0645',
  14890. '\uFDBB': '\u0643\u0645\u0645',
  14891. '\uFDBC': '\u0644\u062C\u0645',
  14892. '\uFDBD': '\u0646\u062C\u062D',
  14893. '\uFDBE': '\u062C\u062D\u064A',
  14894. '\uFDBF': '\u062D\u062C\u064A',
  14895. '\uFDC0': '\u0645\u062C\u064A',
  14896. '\uFDC1': '\u0641\u0645\u064A',
  14897. '\uFDC2': '\u0628\u062D\u064A',
  14898. '\uFDC3': '\u0643\u0645\u0645',
  14899. '\uFDC4': '\u0639\u062C\u0645',
  14900. '\uFDC5': '\u0635\u0645\u0645',
  14901. '\uFDC6': '\u0633\u062E\u064A',
  14902. '\uFDC7': '\u0646\u062C\u064A',
  14903. '\uFE49': '\u203E',
  14904. '\uFE4A': '\u203E',
  14905. '\uFE4B': '\u203E',
  14906. '\uFE4C': '\u203E',
  14907. '\uFE4D': '\u005F',
  14908. '\uFE4E': '\u005F',
  14909. '\uFE4F': '\u005F',
  14910. '\uFE80': '\u0621',
  14911. '\uFE81': '\u0622',
  14912. '\uFE82': '\u0622',
  14913. '\uFE83': '\u0623',
  14914. '\uFE84': '\u0623',
  14915. '\uFE85': '\u0624',
  14916. '\uFE86': '\u0624',
  14917. '\uFE87': '\u0625',
  14918. '\uFE88': '\u0625',
  14919. '\uFE89': '\u0626',
  14920. '\uFE8A': '\u0626',
  14921. '\uFE8B': '\u0626',
  14922. '\uFE8C': '\u0626',
  14923. '\uFE8D': '\u0627',
  14924. '\uFE8E': '\u0627',
  14925. '\uFE8F': '\u0628',
  14926. '\uFE90': '\u0628',
  14927. '\uFE91': '\u0628',
  14928. '\uFE92': '\u0628',
  14929. '\uFE93': '\u0629',
  14930. '\uFE94': '\u0629',
  14931. '\uFE95': '\u062A',
  14932. '\uFE96': '\u062A',
  14933. '\uFE97': '\u062A',
  14934. '\uFE98': '\u062A',
  14935. '\uFE99': '\u062B',
  14936. '\uFE9A': '\u062B',
  14937. '\uFE9B': '\u062B',
  14938. '\uFE9C': '\u062B',
  14939. '\uFE9D': '\u062C',
  14940. '\uFE9E': '\u062C',
  14941. '\uFE9F': '\u062C',
  14942. '\uFEA0': '\u062C',
  14943. '\uFEA1': '\u062D',
  14944. '\uFEA2': '\u062D',
  14945. '\uFEA3': '\u062D',
  14946. '\uFEA4': '\u062D',
  14947. '\uFEA5': '\u062E',
  14948. '\uFEA6': '\u062E',
  14949. '\uFEA7': '\u062E',
  14950. '\uFEA8': '\u062E',
  14951. '\uFEA9': '\u062F',
  14952. '\uFEAA': '\u062F',
  14953. '\uFEAB': '\u0630',
  14954. '\uFEAC': '\u0630',
  14955. '\uFEAD': '\u0631',
  14956. '\uFEAE': '\u0631',
  14957. '\uFEAF': '\u0632',
  14958. '\uFEB0': '\u0632',
  14959. '\uFEB1': '\u0633',
  14960. '\uFEB2': '\u0633',
  14961. '\uFEB3': '\u0633',
  14962. '\uFEB4': '\u0633',
  14963. '\uFEB5': '\u0634',
  14964. '\uFEB6': '\u0634',
  14965. '\uFEB7': '\u0634',
  14966. '\uFEB8': '\u0634',
  14967. '\uFEB9': '\u0635',
  14968. '\uFEBA': '\u0635',
  14969. '\uFEBB': '\u0635',
  14970. '\uFEBC': '\u0635',
  14971. '\uFEBD': '\u0636',
  14972. '\uFEBE': '\u0636',
  14973. '\uFEBF': '\u0636',
  14974. '\uFEC0': '\u0636',
  14975. '\uFEC1': '\u0637',
  14976. '\uFEC2': '\u0637',
  14977. '\uFEC3': '\u0637',
  14978. '\uFEC4': '\u0637',
  14979. '\uFEC5': '\u0638',
  14980. '\uFEC6': '\u0638',
  14981. '\uFEC7': '\u0638',
  14982. '\uFEC8': '\u0638',
  14983. '\uFEC9': '\u0639',
  14984. '\uFECA': '\u0639',
  14985. '\uFECB': '\u0639',
  14986. '\uFECC': '\u0639',
  14987. '\uFECD': '\u063A',
  14988. '\uFECE': '\u063A',
  14989. '\uFECF': '\u063A',
  14990. '\uFED0': '\u063A',
  14991. '\uFED1': '\u0641',
  14992. '\uFED2': '\u0641',
  14993. '\uFED3': '\u0641',
  14994. '\uFED4': '\u0641',
  14995. '\uFED5': '\u0642',
  14996. '\uFED6': '\u0642',
  14997. '\uFED7': '\u0642',
  14998. '\uFED8': '\u0642',
  14999. '\uFED9': '\u0643',
  15000. '\uFEDA': '\u0643',
  15001. '\uFEDB': '\u0643',
  15002. '\uFEDC': '\u0643',
  15003. '\uFEDD': '\u0644',
  15004. '\uFEDE': '\u0644',
  15005. '\uFEDF': '\u0644',
  15006. '\uFEE0': '\u0644',
  15007. '\uFEE1': '\u0645',
  15008. '\uFEE2': '\u0645',
  15009. '\uFEE3': '\u0645',
  15010. '\uFEE4': '\u0645',
  15011. '\uFEE5': '\u0646',
  15012. '\uFEE6': '\u0646',
  15013. '\uFEE7': '\u0646',
  15014. '\uFEE8': '\u0646',
  15015. '\uFEE9': '\u0647',
  15016. '\uFEEA': '\u0647',
  15017. '\uFEEB': '\u0647',
  15018. '\uFEEC': '\u0647',
  15019. '\uFEED': '\u0648',
  15020. '\uFEEE': '\u0648',
  15021. '\uFEEF': '\u0649',
  15022. '\uFEF0': '\u0649',
  15023. '\uFEF1': '\u064A',
  15024. '\uFEF2': '\u064A',
  15025. '\uFEF3': '\u064A',
  15026. '\uFEF4': '\u064A',
  15027. '\uFEF5': '\u0644\u0622',
  15028. '\uFEF6': '\u0644\u0622',
  15029. '\uFEF7': '\u0644\u0623',
  15030. '\uFEF8': '\u0644\u0623',
  15031. '\uFEF9': '\u0644\u0625',
  15032. '\uFEFA': '\u0644\u0625',
  15033. '\uFEFB': '\u0644\u0627',
  15034. '\uFEFC': '\u0644\u0627'
  15035. };
  15036. function reverseIfRtl(chars) {
  15037. var charsLength = chars.length;
  15038. //reverse an arabic ligature
  15039. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  15040. return chars;
  15041. }
  15042. var s = '';
  15043. for (var ii = charsLength - 1; ii >= 0; ii--) {
  15044. s += chars[ii];
  15045. }
  15046. return s;
  15047. }
  15048. function adjustWidths(properties) {
  15049. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  15050. return;
  15051. }
  15052. // adjusting width to fontMatrix scale
  15053. var scale = 0.001 / properties.fontMatrix[0];
  15054. var glyphsWidths = properties.widths;
  15055. for (var glyph in glyphsWidths) {
  15056. glyphsWidths[glyph] *= scale;
  15057. }
  15058. properties.defaultWidth *= scale;
  15059. }
  15060. function getFontType(type, subtype) {
  15061. switch (type) {
  15062. case 'Type1':
  15063. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15064. case 'CIDFontType0':
  15065. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15066. FontType.CIDFONTTYPE0;
  15067. case 'OpenType':
  15068. return FontType.OPENTYPE;
  15069. case 'TrueType':
  15070. return FontType.TRUETYPE;
  15071. case 'CIDFontType2':
  15072. return FontType.CIDFONTTYPE2;
  15073. case 'MMType1':
  15074. return FontType.MMTYPE1;
  15075. case 'Type0':
  15076. return FontType.TYPE0;
  15077. default:
  15078. return FontType.UNKNOWN;
  15079. }
  15080. }
  15081. var Glyph = (function GlyphClosure() {
  15082. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15083. this.fontChar = fontChar;
  15084. this.unicode = unicode;
  15085. this.accent = accent;
  15086. this.width = width;
  15087. this.vmetric = vmetric;
  15088. this.operatorListId = operatorListId;
  15089. }
  15090. Glyph.prototype.matchesForCache =
  15091. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15092. return this.fontChar === fontChar &&
  15093. this.unicode === unicode &&
  15094. this.accent === accent &&
  15095. this.width === width &&
  15096. this.vmetric === vmetric &&
  15097. this.operatorListId === operatorListId;
  15098. };
  15099. return Glyph;
  15100. })();
  15101. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15102. function ToUnicodeMap(cmap) {
  15103. // The elements of this._map can be integers or strings, depending on how
  15104. // |cmap| was created.
  15105. this._map = cmap;
  15106. }
  15107. ToUnicodeMap.prototype = {
  15108. get length() {
  15109. return this._map.length;
  15110. },
  15111. forEach: function(callback) {
  15112. for (var charCode in this._map) {
  15113. callback(charCode, this._map[charCode].charCodeAt(0));
  15114. }
  15115. },
  15116. has: function(i) {
  15117. return this._map[i] !== undefined;
  15118. },
  15119. get: function(i) {
  15120. return this._map[i];
  15121. },
  15122. charCodeOf: function(v) {
  15123. return this._map.indexOf(v);
  15124. }
  15125. };
  15126. return ToUnicodeMap;
  15127. })();
  15128. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15129. function IdentityToUnicodeMap(firstChar, lastChar) {
  15130. this.firstChar = firstChar;
  15131. this.lastChar = lastChar;
  15132. }
  15133. IdentityToUnicodeMap.prototype = {
  15134. get length() {
  15135. return (this.lastChar + 1) - this.firstChar;
  15136. },
  15137. forEach: function (callback) {
  15138. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15139. callback(i, i);
  15140. }
  15141. },
  15142. has: function (i) {
  15143. return this.firstChar <= i && i <= this.lastChar;
  15144. },
  15145. get: function (i) {
  15146. if (this.firstChar <= i && i <= this.lastChar) {
  15147. return String.fromCharCode(i);
  15148. }
  15149. return undefined;
  15150. },
  15151. charCodeOf: function (v) {
  15152. error('should not call .charCodeOf');
  15153. }
  15154. };
  15155. return IdentityToUnicodeMap;
  15156. })();
  15157. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15158. function writeInt16(dest, offset, num) {
  15159. dest[offset] = (num >> 8) & 0xFF;
  15160. dest[offset + 1] = num & 0xFF;
  15161. }
  15162. function writeInt32(dest, offset, num) {
  15163. dest[offset] = (num >> 24) & 0xFF;
  15164. dest[offset + 1] = (num >> 16) & 0xFF;
  15165. dest[offset + 2] = (num >> 8) & 0xFF;
  15166. dest[offset + 3] = num & 0xFF;
  15167. }
  15168. function writeData(dest, offset, data) {
  15169. var i, ii;
  15170. if (data instanceof Uint8Array) {
  15171. dest.set(data, offset);
  15172. } else if (typeof data === 'string') {
  15173. for (i = 0, ii = data.length; i < ii; i++) {
  15174. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15175. }
  15176. } else {
  15177. // treating everything else as array
  15178. for (i = 0, ii = data.length; i < ii; i++) {
  15179. dest[offset++] = data[i] & 0xFF;
  15180. }
  15181. }
  15182. }
  15183. function OpenTypeFileBuilder(sfnt) {
  15184. this.sfnt = sfnt;
  15185. this.tables = Object.create(null);
  15186. }
  15187. OpenTypeFileBuilder.getSearchParams =
  15188. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15189. var maxPower2 = 1, log2 = 0;
  15190. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15191. maxPower2 <<= 1;
  15192. log2++;
  15193. }
  15194. var searchRange = maxPower2 * entrySize;
  15195. return {
  15196. range: searchRange,
  15197. entry: log2,
  15198. rangeShift: entrySize * entriesCount - searchRange
  15199. };
  15200. };
  15201. var OTF_HEADER_SIZE = 12;
  15202. var OTF_TABLE_ENTRY_SIZE = 16;
  15203. OpenTypeFileBuilder.prototype = {
  15204. toArray: function OpenTypeFileBuilder_toArray() {
  15205. var sfnt = this.sfnt;
  15206. // Tables needs to be written by ascendant alphabetic order
  15207. var tables = this.tables;
  15208. var tablesNames = Object.keys(tables);
  15209. tablesNames.sort();
  15210. var numTables = tablesNames.length;
  15211. var i, j, jj, table, tableName;
  15212. // layout the tables data
  15213. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15214. var tableOffsets = [offset];
  15215. for (i = 0; i < numTables; i++) {
  15216. table = tables[tablesNames[i]];
  15217. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15218. offset += paddedLength;
  15219. tableOffsets.push(offset);
  15220. }
  15221. var file = new Uint8Array(offset);
  15222. // write the table data first (mostly for checksum)
  15223. for (i = 0; i < numTables; i++) {
  15224. table = tables[tablesNames[i]];
  15225. writeData(file, tableOffsets[i], table);
  15226. }
  15227. // sfnt version (4 bytes)
  15228. if (sfnt === 'true') {
  15229. // Windows hates the Mac TrueType sfnt version number
  15230. sfnt = string32(0x00010000);
  15231. }
  15232. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15233. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15234. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15235. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15236. // numTables (2 bytes)
  15237. writeInt16(file, 4, numTables);
  15238. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15239. // searchRange (2 bytes)
  15240. writeInt16(file, 6, searchParams.range);
  15241. // entrySelector (2 bytes)
  15242. writeInt16(file, 8, searchParams.entry);
  15243. // rangeShift (2 bytes)
  15244. writeInt16(file, 10, searchParams.rangeShift);
  15245. offset = OTF_HEADER_SIZE;
  15246. // writing table entries
  15247. for (i = 0; i < numTables; i++) {
  15248. tableName = tablesNames[i];
  15249. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15250. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15251. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15252. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15253. // checksum
  15254. var checksum = 0;
  15255. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15256. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15257. (file[j + 2] << 8) + file[j + 3];
  15258. checksum = (checksum + quad) | 0;
  15259. }
  15260. writeInt32(file, offset + 4, checksum);
  15261. // offset
  15262. writeInt32(file, offset + 8, tableOffsets[i]);
  15263. // length
  15264. writeInt32(file, offset + 12, tables[tableName].length);
  15265. offset += OTF_TABLE_ENTRY_SIZE;
  15266. }
  15267. return file;
  15268. },
  15269. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15270. if (tag in this.tables) {
  15271. throw new Error('Table ' + tag + ' already exists');
  15272. }
  15273. this.tables[tag] = data;
  15274. }
  15275. };
  15276. return OpenTypeFileBuilder;
  15277. })();
  15278. /**
  15279. * 'Font' is the class the outside world should use, it encapsulate all the font
  15280. * decoding logics whatever type it is (assuming the font type is supported).
  15281. *
  15282. * For example to read a Type1 font and to attach it to the document:
  15283. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15284. * type1Font.bind();
  15285. */
  15286. var Font = (function FontClosure() {
  15287. function Font(name, file, properties) {
  15288. var charCode, glyphName, fontChar;
  15289. this.name = name;
  15290. this.loadedName = properties.loadedName;
  15291. this.isType3Font = properties.isType3Font;
  15292. this.sizes = [];
  15293. this.glyphCache = {};
  15294. var names = name.split('+');
  15295. names = names.length > 1 ? names[1] : names[0];
  15296. names = names.split(/[-,_]/g)[0];
  15297. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15298. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15299. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15300. var type = properties.type;
  15301. var subtype = properties.subtype;
  15302. this.type = type;
  15303. this.fallbackName = (this.isMonospace ? 'monospace' :
  15304. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15305. this.differences = properties.differences;
  15306. this.widths = properties.widths;
  15307. this.defaultWidth = properties.defaultWidth;
  15308. this.composite = properties.composite;
  15309. this.wideChars = properties.wideChars;
  15310. this.cMap = properties.cMap;
  15311. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15312. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15313. this.fontMatrix = properties.fontMatrix;
  15314. this.bbox = properties.bbox;
  15315. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15316. this.toFontChar = [];
  15317. if (properties.type === 'Type3') {
  15318. for (charCode = 0; charCode < 256; charCode++) {
  15319. this.toFontChar[charCode] = (this.differences[charCode] ||
  15320. properties.defaultEncoding[charCode]);
  15321. }
  15322. this.fontType = FontType.TYPE3;
  15323. return;
  15324. }
  15325. this.cidEncoding = properties.cidEncoding;
  15326. this.vertical = properties.vertical;
  15327. if (this.vertical) {
  15328. this.vmetrics = properties.vmetrics;
  15329. this.defaultVMetrics = properties.defaultVMetrics;
  15330. }
  15331. if (!file || file.isEmpty) {
  15332. if (file) {
  15333. // Some bad PDF generators will include empty font files,
  15334. // attempting to recover by assuming that no file exists.
  15335. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15336. }
  15337. this.missingFile = true;
  15338. // The file data is not specified. Trying to fix the font name
  15339. // to be used with the canvas.font.
  15340. var fontName = name.replace(/[,_]/g, '-');
  15341. var isStandardFont = !!stdFontMap[fontName] ||
  15342. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15343. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15344. this.bold = (fontName.search(/bold/gi) !== -1);
  15345. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15346. (fontName.search(/italic/gi) !== -1));
  15347. // Use 'name' instead of 'fontName' here because the original
  15348. // name ArialBlack for example will be replaced by Helvetica.
  15349. this.black = (name.search(/Black/g) !== -1);
  15350. // if at least one width is present, remeasure all chars when exists
  15351. this.remeasure = Object.keys(this.widths).length > 0;
  15352. if (isStandardFont && type === 'CIDFontType2' &&
  15353. properties.cidEncoding.indexOf('Identity-') === 0) {
  15354. // Standard fonts might be embedded as CID font without glyph mapping.
  15355. // Building one based on GlyphMapForStandardFonts.
  15356. var map = [];
  15357. for (var code in GlyphMapForStandardFonts) {
  15358. map[+code] = GlyphMapForStandardFonts[code];
  15359. }
  15360. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15361. if (!isIdentityUnicode) {
  15362. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15363. map[+charCode] = unicodeCharCode;
  15364. });
  15365. }
  15366. this.toFontChar = map;
  15367. this.toUnicode = new ToUnicodeMap(map);
  15368. } else if (/Symbol/i.test(fontName)) {
  15369. var symbols = Encodings.SymbolSetEncoding;
  15370. for (charCode in symbols) {
  15371. fontChar = GlyphsUnicode[symbols[charCode]];
  15372. if (!fontChar) {
  15373. continue;
  15374. }
  15375. this.toFontChar[charCode] = fontChar;
  15376. }
  15377. for (charCode in properties.differences) {
  15378. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15379. if (!fontChar) {
  15380. continue;
  15381. }
  15382. this.toFontChar[charCode] = fontChar;
  15383. }
  15384. } else if (/Dingbats/i.test(fontName)) {
  15385. if (/Wingdings/i.test(name)) {
  15386. warn('Wingdings font without embedded font file, ' +
  15387. 'falling back to the ZapfDingbats encoding.');
  15388. }
  15389. var dingbats = Encodings.ZapfDingbatsEncoding;
  15390. for (charCode in dingbats) {
  15391. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15392. if (!fontChar) {
  15393. continue;
  15394. }
  15395. this.toFontChar[charCode] = fontChar;
  15396. }
  15397. for (charCode in properties.differences) {
  15398. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15399. if (!fontChar) {
  15400. continue;
  15401. }
  15402. this.toFontChar[charCode] = fontChar;
  15403. }
  15404. } else if (isStandardFont) {
  15405. this.toFontChar = [];
  15406. for (charCode in properties.defaultEncoding) {
  15407. glyphName = (properties.differences[charCode] ||
  15408. properties.defaultEncoding[charCode]);
  15409. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15410. }
  15411. } else {
  15412. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15413. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15414. if (notCidFont) {
  15415. glyphName = (properties.differences[charCode] ||
  15416. properties.defaultEncoding[charCode]);
  15417. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15418. }
  15419. this.toFontChar[charCode] = unicodeCharCode;
  15420. }.bind(this));
  15421. }
  15422. this.loadedName = fontName.split('-')[0];
  15423. this.loading = false;
  15424. this.fontType = getFontType(type, subtype);
  15425. return;
  15426. }
  15427. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15428. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15429. // Some TrueType fonts by mistake claim Type1C
  15430. if (isTrueTypeFile(file)) {
  15431. subtype = 'TrueType';
  15432. } else {
  15433. type = 'Type1';
  15434. }
  15435. }
  15436. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15437. type = 'CIDFontType0';
  15438. }
  15439. if (subtype === 'OpenType') {
  15440. type = 'OpenType';
  15441. }
  15442. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15443. if (type === 'CIDFontType0') {
  15444. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15445. }
  15446. var data;
  15447. switch (type) {
  15448. case 'MMType1':
  15449. info('MMType1 font (' + name + '), falling back to Type1.');
  15450. /* falls through */
  15451. case 'Type1':
  15452. case 'CIDFontType0':
  15453. this.mimetype = 'font/opentype';
  15454. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15455. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15456. adjustWidths(properties);
  15457. // Wrap the CFF data inside an OTF font file
  15458. data = this.convert(name, cff, properties);
  15459. break;
  15460. case 'OpenType':
  15461. case 'TrueType':
  15462. case 'CIDFontType2':
  15463. this.mimetype = 'font/opentype';
  15464. // Repair the TrueType file. It is can be damaged in the point of
  15465. // view of the sanitizer
  15466. data = this.checkAndRepair(name, file, properties);
  15467. if (this.isOpenType) {
  15468. type = 'OpenType';
  15469. }
  15470. break;
  15471. default:
  15472. error('Font ' + type + ' is not supported');
  15473. break;
  15474. }
  15475. this.data = data;
  15476. this.fontType = getFontType(type, subtype);
  15477. // Transfer some properties again that could change during font conversion
  15478. this.fontMatrix = properties.fontMatrix;
  15479. this.widths = properties.widths;
  15480. this.defaultWidth = properties.defaultWidth;
  15481. this.encoding = properties.baseEncoding;
  15482. this.seacMap = properties.seacMap;
  15483. this.loading = true;
  15484. }
  15485. Font.getFontID = (function () {
  15486. var ID = 1;
  15487. return function Font_getFontID() {
  15488. return String(ID++);
  15489. };
  15490. })();
  15491. function int16(b0, b1) {
  15492. return (b0 << 8) + b1;
  15493. }
  15494. function int32(b0, b1, b2, b3) {
  15495. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15496. }
  15497. function string16(value) {
  15498. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15499. }
  15500. function safeString16(value) {
  15501. // clamp value to the 16-bit int range
  15502. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15503. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15504. }
  15505. function isTrueTypeFile(file) {
  15506. var header = file.peekBytes(4);
  15507. return readUint32(header, 0) === 0x00010000;
  15508. }
  15509. function isType1File(file) {
  15510. var header = file.peekBytes(2);
  15511. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15512. if (header[0] === 0x25 && header[1] === 0x21) {
  15513. return true;
  15514. }
  15515. // ... obviously some fonts violate that part of the specification,
  15516. // please refer to the comment in |Type1Font| below.
  15517. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15518. return true;
  15519. }
  15520. return false;
  15521. }
  15522. /**
  15523. * Helper function for |adjustMapping|.
  15524. * @return {boolean}
  15525. */
  15526. function isProblematicUnicodeLocation(code) {
  15527. if (code <= 0x1F) { // Control chars
  15528. return true;
  15529. }
  15530. if (code >= 0x80 && code <= 0x9F) { // Control chars
  15531. return true;
  15532. }
  15533. if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
  15534. (code >= 0x2028 && code <= 0x202F) ||
  15535. (code >= 0x2060 && code <= 0x206F)) {
  15536. return true;
  15537. }
  15538. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
  15539. return true;
  15540. }
  15541. switch (code) {
  15542. case 0x7F: // Control char
  15543. case 0xA0: // Non breaking space
  15544. case 0xAD: // Soft hyphen
  15545. case 0x0E33: // Thai character SARA AM
  15546. case 0x2011: // Non breaking hyphen
  15547. case 0x205F: // Medium mathematical space
  15548. case 0x25CC: // Dotted circle (combining mark)
  15549. return true;
  15550. }
  15551. return false;
  15552. }
  15553. /**
  15554. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15555. * with their unicode value. It also moves char codes that are in known
  15556. * problematic locations.
  15557. * @return {Object} Two properties:
  15558. * 'toFontChar' - maps original char codes(the value that will be read
  15559. * from commands such as show text) to the char codes that will be used in the
  15560. * font that we build
  15561. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15562. */
  15563. function adjustMapping(charCodeToGlyphId, properties) {
  15564. var toUnicode = properties.toUnicode;
  15565. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15566. var isIdentityUnicode =
  15567. properties.toUnicode instanceof IdentityToUnicodeMap;
  15568. var newMap = Object.create(null);
  15569. var toFontChar = [];
  15570. var usedFontCharCodes = [];
  15571. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15572. for (var originalCharCode in charCodeToGlyphId) {
  15573. originalCharCode |= 0;
  15574. var glyphId = charCodeToGlyphId[originalCharCode];
  15575. var fontCharCode = originalCharCode;
  15576. // First try to map the value to a unicode position if a non identity map
  15577. // was created.
  15578. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15579. var unicode = toUnicode.get(fontCharCode);
  15580. // TODO: Try to map ligatures to the correct spot.
  15581. if (unicode.length === 1) {
  15582. fontCharCode = unicode.charCodeAt(0);
  15583. }
  15584. }
  15585. // Try to move control characters, special characters and already mapped
  15586. // characters to the private use area since they will not be drawn by
  15587. // canvas if left in their current position. Also, move characters if the
  15588. // font was symbolic and there is only an identity unicode map since the
  15589. // characters probably aren't in the correct position (fixes an issue
  15590. // with firefox and thuluthfont).
  15591. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15592. isProblematicUnicodeLocation(fontCharCode) ||
  15593. (isSymbolic && isIdentityUnicode)) &&
  15594. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15595. // Loop to try and find a free spot in the private use area.
  15596. do {
  15597. fontCharCode = nextAvailableFontCharCode++;
  15598. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15599. fontCharCode = 0xF020;
  15600. nextAvailableFontCharCode = fontCharCode + 1;
  15601. }
  15602. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15603. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15604. }
  15605. newMap[fontCharCode] = glyphId;
  15606. toFontChar[originalCharCode] = fontCharCode;
  15607. usedFontCharCodes[fontCharCode] = true;
  15608. }
  15609. return {
  15610. toFontChar: toFontChar,
  15611. charCodeToGlyphId: newMap,
  15612. nextAvailableFontCharCode: nextAvailableFontCharCode
  15613. };
  15614. }
  15615. function getRanges(glyphs) {
  15616. // Array.sort() sorts by characters, not numerically, so convert to an
  15617. // array of characters.
  15618. var codes = [];
  15619. for (var charCode in glyphs) {
  15620. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15621. }
  15622. codes.sort(function fontGetRangesSort(a, b) {
  15623. return a.fontCharCode - b.fontCharCode;
  15624. });
  15625. // Split the sorted codes into ranges.
  15626. var ranges = [];
  15627. var length = codes.length;
  15628. for (var n = 0; n < length; ) {
  15629. var start = codes[n].fontCharCode;
  15630. var codeIndices = [codes[n].glyphId];
  15631. ++n;
  15632. var end = start;
  15633. while (n < length && end + 1 === codes[n].fontCharCode) {
  15634. codeIndices.push(codes[n].glyphId);
  15635. ++end;
  15636. ++n;
  15637. if (end === 0xFFFF) {
  15638. break;
  15639. }
  15640. }
  15641. ranges.push([start, end, codeIndices]);
  15642. }
  15643. return ranges;
  15644. }
  15645. function createCmapTable(glyphs) {
  15646. var ranges = getRanges(glyphs);
  15647. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15648. var cmap = '\x00\x00' + // version
  15649. string16(numTables) + // numTables
  15650. '\x00\x03' + // platformID
  15651. '\x00\x01' + // encodingID
  15652. string32(4 + numTables * 8); // start of the table record
  15653. var i, ii, j, jj;
  15654. for (i = ranges.length - 1; i >= 0; --i) {
  15655. if (ranges[i][0] <= 0xFFFF) { break; }
  15656. }
  15657. var bmpLength = i + 1;
  15658. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15659. ranges[i][1] = 0xFFFE;
  15660. }
  15661. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15662. var segCount = bmpLength + trailingRangesCount;
  15663. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15664. // Fill up the 4 parallel arrays describing the segments.
  15665. var startCount = '';
  15666. var endCount = '';
  15667. var idDeltas = '';
  15668. var idRangeOffsets = '';
  15669. var glyphsIds = '';
  15670. var bias = 0;
  15671. var range, start, end, codes;
  15672. for (i = 0, ii = bmpLength; i < ii; i++) {
  15673. range = ranges[i];
  15674. start = range[0];
  15675. end = range[1];
  15676. startCount += string16(start);
  15677. endCount += string16(end);
  15678. codes = range[2];
  15679. var contiguous = true;
  15680. for (j = 1, jj = codes.length; j < jj; ++j) {
  15681. if (codes[j] !== codes[j - 1] + 1) {
  15682. contiguous = false;
  15683. break;
  15684. }
  15685. }
  15686. if (!contiguous) {
  15687. var offset = (segCount - i) * 2 + bias * 2;
  15688. bias += (end - start + 1);
  15689. idDeltas += string16(0);
  15690. idRangeOffsets += string16(offset);
  15691. for (j = 0, jj = codes.length; j < jj; ++j) {
  15692. glyphsIds += string16(codes[j]);
  15693. }
  15694. } else {
  15695. var startCode = codes[0];
  15696. idDeltas += string16((startCode - start) & 0xFFFF);
  15697. idRangeOffsets += string16(0);
  15698. }
  15699. }
  15700. if (trailingRangesCount > 0) {
  15701. endCount += '\xFF\xFF';
  15702. startCount += '\xFF\xFF';
  15703. idDeltas += '\x00\x01';
  15704. idRangeOffsets += '\x00\x00';
  15705. }
  15706. var format314 = '\x00\x00' + // language
  15707. string16(2 * segCount) +
  15708. string16(searchParams.range) +
  15709. string16(searchParams.entry) +
  15710. string16(searchParams.rangeShift) +
  15711. endCount + '\x00\x00' + startCount +
  15712. idDeltas + idRangeOffsets + glyphsIds;
  15713. var format31012 = '';
  15714. var header31012 = '';
  15715. if (numTables > 1) {
  15716. cmap += '\x00\x03' + // platformID
  15717. '\x00\x0A' + // encodingID
  15718. string32(4 + numTables * 8 +
  15719. 4 + format314.length); // start of the table record
  15720. format31012 = '';
  15721. for (i = 0, ii = ranges.length; i < ii; i++) {
  15722. range = ranges[i];
  15723. start = range[0];
  15724. codes = range[2];
  15725. var code = codes[0];
  15726. for (j = 1, jj = codes.length; j < jj; ++j) {
  15727. if (codes[j] !== codes[j - 1] + 1) {
  15728. end = range[0] + j - 1;
  15729. format31012 += string32(start) + // startCharCode
  15730. string32(end) + // endCharCode
  15731. string32(code); // startGlyphID
  15732. start = end + 1;
  15733. code = codes[j];
  15734. }
  15735. }
  15736. format31012 += string32(start) + // startCharCode
  15737. string32(range[1]) + // endCharCode
  15738. string32(code); // startGlyphID
  15739. }
  15740. header31012 = '\x00\x0C' + // format
  15741. '\x00\x00' + // reserved
  15742. string32(format31012.length + 16) + // length
  15743. '\x00\x00\x00\x00' + // language
  15744. string32(format31012.length / 12); // nGroups
  15745. }
  15746. return cmap + '\x00\x04' + // format
  15747. string16(format314.length + 4) + // length
  15748. format314 + header31012 + format31012;
  15749. }
  15750. function validateOS2Table(os2) {
  15751. var stream = new Stream(os2.data);
  15752. var version = stream.getUint16();
  15753. // TODO verify all OS/2 tables fields, but currently we validate only those
  15754. // that give us issues
  15755. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15756. var selection = stream.getUint16();
  15757. if (version < 4 && (selection & 0x0300)) {
  15758. return false;
  15759. }
  15760. var firstChar = stream.getUint16();
  15761. var lastChar = stream.getUint16();
  15762. if (firstChar > lastChar) {
  15763. return false;
  15764. }
  15765. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15766. var usWinAscent = stream.getUint16();
  15767. if (usWinAscent === 0) { // makes font unreadable by windows
  15768. return false;
  15769. }
  15770. // OS/2 appears to be valid, resetting some fields
  15771. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15772. return true;
  15773. }
  15774. function createOS2Table(properties, charstrings, override) {
  15775. override = override || {
  15776. unitsPerEm: 0,
  15777. yMax: 0,
  15778. yMin: 0,
  15779. ascent: 0,
  15780. descent: 0
  15781. };
  15782. var ulUnicodeRange1 = 0;
  15783. var ulUnicodeRange2 = 0;
  15784. var ulUnicodeRange3 = 0;
  15785. var ulUnicodeRange4 = 0;
  15786. var firstCharIndex = null;
  15787. var lastCharIndex = 0;
  15788. if (charstrings) {
  15789. for (var code in charstrings) {
  15790. code |= 0;
  15791. if (firstCharIndex > code || !firstCharIndex) {
  15792. firstCharIndex = code;
  15793. }
  15794. if (lastCharIndex < code) {
  15795. lastCharIndex = code;
  15796. }
  15797. var position = getUnicodeRangeFor(code);
  15798. if (position < 32) {
  15799. ulUnicodeRange1 |= 1 << position;
  15800. } else if (position < 64) {
  15801. ulUnicodeRange2 |= 1 << position - 32;
  15802. } else if (position < 96) {
  15803. ulUnicodeRange3 |= 1 << position - 64;
  15804. } else if (position < 123) {
  15805. ulUnicodeRange4 |= 1 << position - 96;
  15806. } else {
  15807. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15808. }
  15809. }
  15810. } else {
  15811. // TODO
  15812. firstCharIndex = 0;
  15813. lastCharIndex = 255;
  15814. }
  15815. var bbox = properties.bbox || [0, 0, 0, 0];
  15816. var unitsPerEm = (override.unitsPerEm ||
  15817. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15818. // if the font units differ to the PDF glyph space units
  15819. // then scale up the values
  15820. var scale = (properties.ascentScaled ? 1.0 :
  15821. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15822. var typoAscent = (override.ascent ||
  15823. Math.round(scale * (properties.ascent || bbox[3])));
  15824. var typoDescent = (override.descent ||
  15825. Math.round(scale * (properties.descent || bbox[1])));
  15826. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15827. typoDescent = -typoDescent; // fixing incorrect descent
  15828. }
  15829. var winAscent = override.yMax || typoAscent;
  15830. var winDescent = -override.yMin || -typoDescent;
  15831. return '\x00\x03' + // version
  15832. '\x02\x24' + // xAvgCharWidth
  15833. '\x01\xF4' + // usWeightClass
  15834. '\x00\x05' + // usWidthClass
  15835. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15836. '\x02\x8A' + // ySubscriptXSize
  15837. '\x02\xBB' + // ySubscriptYSize
  15838. '\x00\x00' + // ySubscriptXOffset
  15839. '\x00\x8C' + // ySubscriptYOffset
  15840. '\x02\x8A' + // ySuperScriptXSize
  15841. '\x02\xBB' + // ySuperScriptYSize
  15842. '\x00\x00' + // ySuperScriptXOffset
  15843. '\x01\xDF' + // ySuperScriptYOffset
  15844. '\x00\x31' + // yStrikeOutSize
  15845. '\x01\x02' + // yStrikeOutPosition
  15846. '\x00\x00' + // sFamilyClass
  15847. '\x00\x00\x06' +
  15848. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15849. '\x00\x00\x00\x00\x00\x00' + // Panose
  15850. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15851. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15852. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15853. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15854. '\x2A\x32\x31\x2A' + // achVendID
  15855. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15856. string16(firstCharIndex ||
  15857. properties.firstChar) + // usFirstCharIndex
  15858. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15859. string16(typoAscent) + // sTypoAscender
  15860. string16(typoDescent) + // sTypoDescender
  15861. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15862. string16(winAscent) + // usWinAscent
  15863. string16(winDescent) + // usWinDescent
  15864. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15865. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15866. string16(properties.xHeight) + // sxHeight
  15867. string16(properties.capHeight) + // sCapHeight
  15868. string16(0) + // usDefaultChar
  15869. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15870. '\x00\x03'; // usMaxContext
  15871. }
  15872. function createPostTable(properties) {
  15873. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15874. return ('\x00\x03\x00\x00' + // Version number
  15875. string32(angle) + // italicAngle
  15876. '\x00\x00' + // underlinePosition
  15877. '\x00\x00' + // underlineThickness
  15878. string32(properties.fixedPitch) + // isFixedPitch
  15879. '\x00\x00\x00\x00' + // minMemType42
  15880. '\x00\x00\x00\x00' + // maxMemType42
  15881. '\x00\x00\x00\x00' + // minMemType1
  15882. '\x00\x00\x00\x00'); // maxMemType1
  15883. }
  15884. function createNameTable(name, proto) {
  15885. if (!proto) {
  15886. proto = [[], []]; // no strings and unicode strings
  15887. }
  15888. var strings = [
  15889. proto[0][0] || 'Original licence', // 0.Copyright
  15890. proto[0][1] || name, // 1.Font family
  15891. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15892. proto[0][3] || 'uniqueID', // 3.Unique ID
  15893. proto[0][4] || name, // 4.Full font name
  15894. proto[0][5] || 'Version 0.11', // 5.Version
  15895. proto[0][6] || '', // 6.Postscript name
  15896. proto[0][7] || 'Unknown', // 7.Trademark
  15897. proto[0][8] || 'Unknown', // 8.Manufacturer
  15898. proto[0][9] || 'Unknown' // 9.Designer
  15899. ];
  15900. // Mac want 1-byte per character strings while Windows want
  15901. // 2-bytes per character, so duplicate the names table
  15902. var stringsUnicode = [];
  15903. var i, ii, j, jj, str;
  15904. for (i = 0, ii = strings.length; i < ii; i++) {
  15905. str = proto[1][i] || strings[i];
  15906. var strBufUnicode = [];
  15907. for (j = 0, jj = str.length; j < jj; j++) {
  15908. strBufUnicode.push(string16(str.charCodeAt(j)));
  15909. }
  15910. stringsUnicode.push(strBufUnicode.join(''));
  15911. }
  15912. var names = [strings, stringsUnicode];
  15913. var platforms = ['\x00\x01', '\x00\x03'];
  15914. var encodings = ['\x00\x00', '\x00\x01'];
  15915. var languages = ['\x00\x00', '\x04\x09'];
  15916. var namesRecordCount = strings.length * platforms.length;
  15917. var nameTable =
  15918. '\x00\x00' + // format
  15919. string16(namesRecordCount) + // Number of names Record
  15920. string16(namesRecordCount * 12 + 6); // Storage
  15921. // Build the name records field
  15922. var strOffset = 0;
  15923. for (i = 0, ii = platforms.length; i < ii; i++) {
  15924. var strs = names[i];
  15925. for (j = 0, jj = strs.length; j < jj; j++) {
  15926. str = strs[j];
  15927. var nameRecord =
  15928. platforms[i] + // platform ID
  15929. encodings[i] + // encoding ID
  15930. languages[i] + // language ID
  15931. string16(j) + // name ID
  15932. string16(str.length) +
  15933. string16(strOffset);
  15934. nameTable += nameRecord;
  15935. strOffset += str.length;
  15936. }
  15937. }
  15938. nameTable += strings.join('') + stringsUnicode.join('');
  15939. return nameTable;
  15940. }
  15941. Font.prototype = {
  15942. name: null,
  15943. font: null,
  15944. mimetype: null,
  15945. encoding: null,
  15946. get renderer() {
  15947. var renderer = FontRendererFactory.create(this);
  15948. return shadow(this, 'renderer', renderer);
  15949. },
  15950. exportData: function Font_exportData() {
  15951. var data = {};
  15952. for (var i in this) {
  15953. if (this.hasOwnProperty(i)) {
  15954. data[i] = this[i];
  15955. }
  15956. }
  15957. return data;
  15958. },
  15959. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15960. function readTableEntry(file) {
  15961. var tag = bytesToString(file.getBytes(4));
  15962. var checksum = file.getInt32();
  15963. var offset = file.getInt32() >>> 0;
  15964. var length = file.getInt32() >>> 0;
  15965. // Read the table associated data
  15966. var previousPosition = file.pos;
  15967. file.pos = file.start ? file.start : 0;
  15968. file.skip(offset);
  15969. var data = file.getBytes(length);
  15970. file.pos = previousPosition;
  15971. if (tag === 'head') {
  15972. // clearing checksum adjustment
  15973. data[8] = data[9] = data[10] = data[11] = 0;
  15974. data[17] |= 0x20; //Set font optimized for cleartype flag
  15975. }
  15976. return {
  15977. tag: tag,
  15978. checksum: checksum,
  15979. length: length,
  15980. offset: offset,
  15981. data: data
  15982. };
  15983. }
  15984. function readOpenTypeHeader(ttf) {
  15985. return {
  15986. version: bytesToString(ttf.getBytes(4)),
  15987. numTables: ttf.getUint16(),
  15988. searchRange: ttf.getUint16(),
  15989. entrySelector: ttf.getUint16(),
  15990. rangeShift: ttf.getUint16()
  15991. };
  15992. }
  15993. /**
  15994. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15995. * PDF spec
  15996. */
  15997. function readCmapTable(cmap, font, isSymbolicFont) {
  15998. var segment;
  15999. var start = (font.start ? font.start : 0) + cmap.offset;
  16000. font.pos = start;
  16001. var version = font.getUint16();
  16002. var numTables = font.getUint16();
  16003. var potentialTable;
  16004. var canBreak = false;
  16005. // There's an order of preference in terms of which cmap subtable to
  16006. // use:
  16007. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  16008. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  16009. // The following takes advantage of the fact that the tables are sorted
  16010. // to work.
  16011. for (var i = 0; i < numTables; i++) {
  16012. var platformId = font.getUint16();
  16013. var encodingId = font.getUint16();
  16014. var offset = font.getInt32() >>> 0;
  16015. var useTable = false;
  16016. if (platformId === 0 && encodingId === 0) {
  16017. useTable = true;
  16018. // Continue the loop since there still may be a higher priority
  16019. // table.
  16020. } else if (platformId === 1 && encodingId === 0) {
  16021. useTable = true;
  16022. // Continue the loop since there still may be a higher priority
  16023. // table.
  16024. } else if (platformId === 3 && encodingId === 1 &&
  16025. (!isSymbolicFont || !potentialTable)) {
  16026. useTable = true;
  16027. if (!isSymbolicFont) {
  16028. canBreak = true;
  16029. }
  16030. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  16031. useTable = true;
  16032. canBreak = true;
  16033. }
  16034. if (useTable) {
  16035. potentialTable = {
  16036. platformId: platformId,
  16037. encodingId: encodingId,
  16038. offset: offset
  16039. };
  16040. }
  16041. if (canBreak) {
  16042. break;
  16043. }
  16044. }
  16045. if (potentialTable) {
  16046. font.pos = start + potentialTable.offset;
  16047. }
  16048. if (!potentialTable || font.peekByte() === -1) {
  16049. warn('Could not find a preferred cmap table.');
  16050. return {
  16051. platformId: -1,
  16052. encodingId: -1,
  16053. mappings: [],
  16054. hasShortCmap: false
  16055. };
  16056. }
  16057. var format = font.getUint16();
  16058. var length = font.getUint16();
  16059. var language = font.getUint16();
  16060. var hasShortCmap = false;
  16061. var mappings = [];
  16062. var j, glyphId;
  16063. // TODO(mack): refactor this cmap subtable reading logic out
  16064. if (format === 0) {
  16065. for (j = 0; j < 256; j++) {
  16066. var index = font.getByte();
  16067. if (!index) {
  16068. continue;
  16069. }
  16070. mappings.push({
  16071. charCode: j,
  16072. glyphId: index
  16073. });
  16074. }
  16075. hasShortCmap = true;
  16076. } else if (format === 4) {
  16077. // re-creating the table in format 4 since the encoding
  16078. // might be changed
  16079. var segCount = (font.getUint16() >> 1);
  16080. font.getBytes(6); // skipping range fields
  16081. var segIndex, segments = [];
  16082. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16083. segments.push({ end: font.getUint16() });
  16084. }
  16085. font.getUint16();
  16086. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16087. segments[segIndex].start = font.getUint16();
  16088. }
  16089. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16090. segments[segIndex].delta = font.getUint16();
  16091. }
  16092. var offsetsCount = 0;
  16093. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16094. segment = segments[segIndex];
  16095. var rangeOffset = font.getUint16();
  16096. if (!rangeOffset) {
  16097. segment.offsetIndex = -1;
  16098. continue;
  16099. }
  16100. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16101. segment.offsetIndex = offsetIndex;
  16102. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16103. segment.end - segment.start + 1);
  16104. }
  16105. var offsets = [];
  16106. for (j = 0; j < offsetsCount; j++) {
  16107. offsets.push(font.getUint16());
  16108. }
  16109. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16110. segment = segments[segIndex];
  16111. start = segment.start;
  16112. var end = segment.end;
  16113. var delta = segment.delta;
  16114. offsetIndex = segment.offsetIndex;
  16115. for (j = start; j <= end; j++) {
  16116. if (j === 0xFFFF) {
  16117. continue;
  16118. }
  16119. glyphId = (offsetIndex < 0 ?
  16120. j : offsets[offsetIndex + j - start]);
  16121. glyphId = (glyphId + delta) & 0xFFFF;
  16122. if (glyphId === 0) {
  16123. continue;
  16124. }
  16125. mappings.push({
  16126. charCode: j,
  16127. glyphId: glyphId
  16128. });
  16129. }
  16130. }
  16131. } else if (format === 6) {
  16132. // Format 6 is a 2-bytes dense mapping, which means the font data
  16133. // lives glue together even if they are pretty far in the unicode
  16134. // table. (This looks weird, so I can have missed something), this
  16135. // works on Linux but seems to fails on Mac so let's rewrite the
  16136. // cmap table to a 3-1-4 style
  16137. var firstCode = font.getUint16();
  16138. var entryCount = font.getUint16();
  16139. for (j = 0; j < entryCount; j++) {
  16140. glyphId = font.getUint16();
  16141. var charCode = firstCode + j;
  16142. mappings.push({
  16143. charCode: charCode,
  16144. glyphId: glyphId
  16145. });
  16146. }
  16147. } else {
  16148. error('cmap table has unsupported format: ' + format);
  16149. }
  16150. // removing duplicate entries
  16151. mappings.sort(function (a, b) {
  16152. return a.charCode - b.charCode;
  16153. });
  16154. for (i = 1; i < mappings.length; i++) {
  16155. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16156. mappings.splice(i, 1);
  16157. i--;
  16158. }
  16159. }
  16160. return {
  16161. platformId: potentialTable.platformId,
  16162. encodingId: potentialTable.encodingId,
  16163. mappings: mappings,
  16164. hasShortCmap: hasShortCmap
  16165. };
  16166. }
  16167. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16168. if (!header) {
  16169. if (metrics) {
  16170. metrics.data = null;
  16171. }
  16172. return;
  16173. }
  16174. font.pos = (font.start ? font.start : 0) + header.offset;
  16175. font.pos += header.length - 2;
  16176. var numOfMetrics = font.getUint16();
  16177. if (numOfMetrics > numGlyphs) {
  16178. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16179. 'greater than the numGlyphs (' + numGlyphs + ')');
  16180. // Reduce numOfMetrics if it is greater than numGlyphs
  16181. numOfMetrics = numGlyphs;
  16182. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16183. header.data[35] = numOfMetrics & 0x00ff;
  16184. }
  16185. var numOfSidebearings = numGlyphs - numOfMetrics;
  16186. var numMissing = numOfSidebearings -
  16187. ((metrics.length - numOfMetrics * 4) >> 1);
  16188. if (numMissing > 0) {
  16189. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16190. // Since we need to add two properties for each glyph, this explains
  16191. // the use of |numMissing * 2| when initializing the typed array.
  16192. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16193. entries.set(metrics.data);
  16194. metrics.data = entries;
  16195. }
  16196. }
  16197. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16198. hintsValid) {
  16199. if (sourceEnd - sourceStart <= 12) {
  16200. // glyph with data less than 12 is invalid one
  16201. return 0;
  16202. }
  16203. var glyf = source.subarray(sourceStart, sourceEnd);
  16204. var contoursCount = (glyf[0] << 8) | glyf[1];
  16205. if (contoursCount & 0x8000) {
  16206. // complex glyph, writing as is
  16207. dest.set(glyf, destStart);
  16208. return glyf.length;
  16209. }
  16210. var i, j = 10, flagsCount = 0;
  16211. for (i = 0; i < contoursCount; i++) {
  16212. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16213. flagsCount = endPoint + 1;
  16214. j += 2;
  16215. }
  16216. // skipping instructions
  16217. var instructionsStart = j;
  16218. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16219. j += 2 + instructionsLength;
  16220. var instructionsEnd = j;
  16221. // validating flags
  16222. var coordinatesLength = 0;
  16223. for (i = 0; i < flagsCount; i++) {
  16224. var flag = glyf[j++];
  16225. if (flag & 0xC0) {
  16226. // reserved flags must be zero, cleaning up
  16227. glyf[j - 1] = flag & 0x3F;
  16228. }
  16229. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16230. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16231. coordinatesLength += xyLength;
  16232. if (flag & 8) {
  16233. var repeat = glyf[j++];
  16234. i += repeat;
  16235. coordinatesLength += repeat * xyLength;
  16236. }
  16237. }
  16238. // glyph without coordinates will be rejected
  16239. if (coordinatesLength === 0) {
  16240. return 0;
  16241. }
  16242. var glyphDataLength = j + coordinatesLength;
  16243. if (glyphDataLength > glyf.length) {
  16244. // not enough data for coordinates
  16245. return 0;
  16246. }
  16247. if (!hintsValid && instructionsLength > 0) {
  16248. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16249. dest.set([0, 0], destStart + instructionsStart);
  16250. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16251. destStart + instructionsStart + 2);
  16252. glyphDataLength -= instructionsLength;
  16253. if (glyf.length - glyphDataLength > 3) {
  16254. glyphDataLength = (glyphDataLength + 3) & ~3;
  16255. }
  16256. return glyphDataLength;
  16257. }
  16258. if (glyf.length - glyphDataLength > 3) {
  16259. // truncating and aligning to 4 bytes the long glyph data
  16260. glyphDataLength = (glyphDataLength + 3) & ~3;
  16261. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16262. return glyphDataLength;
  16263. }
  16264. // glyph data is fine
  16265. dest.set(glyf, destStart);
  16266. return glyf.length;
  16267. }
  16268. function sanitizeHead(head, numGlyphs, locaLength) {
  16269. var data = head.data;
  16270. // Validate version:
  16271. // Should always be 0x00010000
  16272. var version = int32(data[0], data[1], data[2], data[3]);
  16273. if (version >> 16 !== 1) {
  16274. info('Attempting to fix invalid version in head table: ' + version);
  16275. data[0] = 0;
  16276. data[1] = 1;
  16277. data[2] = 0;
  16278. data[3] = 0;
  16279. }
  16280. var indexToLocFormat = int16(data[50], data[51]);
  16281. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16282. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16283. indexToLocFormat);
  16284. // The value of indexToLocFormat should be 0 if the loca table
  16285. // consists of short offsets, and should be 1 if the loca table
  16286. // consists of long offsets.
  16287. //
  16288. // The number of entries in the loca table should be numGlyphs + 1.
  16289. //
  16290. // Using this information, we can work backwards to deduce if the
  16291. // size of each offset in the loca table, and thus figure out the
  16292. // appropriate value for indexToLocFormat.
  16293. var numGlyphsPlusOne = numGlyphs + 1;
  16294. if (locaLength === numGlyphsPlusOne << 1) {
  16295. // 0x0000 indicates the loca table consists of short offsets
  16296. data[50] = 0;
  16297. data[51] = 0;
  16298. } else if (locaLength === numGlyphsPlusOne << 2) {
  16299. // 0x0001 indicates the loca table consists of long offsets
  16300. data[50] = 0;
  16301. data[51] = 1;
  16302. } else {
  16303. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16304. }
  16305. }
  16306. }
  16307. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16308. isGlyphLocationsLong, hintsValid,
  16309. dupFirstEntry) {
  16310. var itemSize, itemDecode, itemEncode;
  16311. if (isGlyphLocationsLong) {
  16312. itemSize = 4;
  16313. itemDecode = function fontItemDecodeLong(data, offset) {
  16314. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16315. (data[offset + 2] << 8) | data[offset + 3];
  16316. };
  16317. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16318. data[offset] = (value >>> 24) & 0xFF;
  16319. data[offset + 1] = (value >> 16) & 0xFF;
  16320. data[offset + 2] = (value >> 8) & 0xFF;
  16321. data[offset + 3] = value & 0xFF;
  16322. };
  16323. } else {
  16324. itemSize = 2;
  16325. itemDecode = function fontItemDecode(data, offset) {
  16326. return (data[offset] << 9) | (data[offset + 1] << 1);
  16327. };
  16328. itemEncode = function fontItemEncode(data, offset, value) {
  16329. data[offset] = (value >> 9) & 0xFF;
  16330. data[offset + 1] = (value >> 1) & 0xFF;
  16331. };
  16332. }
  16333. var locaData = loca.data;
  16334. var locaDataSize = itemSize * (1 + numGlyphs);
  16335. // is loca.data too short or long?
  16336. if (locaData.length !== locaDataSize) {
  16337. locaData = new Uint8Array(locaDataSize);
  16338. locaData.set(loca.data.subarray(0, locaDataSize));
  16339. loca.data = locaData;
  16340. }
  16341. // removing the invalid glyphs
  16342. var oldGlyfData = glyf.data;
  16343. var oldGlyfDataLength = oldGlyfData.length;
  16344. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16345. var startOffset = itemDecode(locaData, 0);
  16346. var writeOffset = 0;
  16347. var missingGlyphData = {};
  16348. itemEncode(locaData, 0, writeOffset);
  16349. var i, j;
  16350. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16351. var endOffset = itemDecode(locaData, j);
  16352. if (endOffset > oldGlyfDataLength &&
  16353. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16354. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16355. // the glyf table size, which makes last glyph out of range.
  16356. endOffset = oldGlyfDataLength;
  16357. }
  16358. if (endOffset > oldGlyfDataLength) {
  16359. // glyph end offset points outside glyf data, rejecting the glyph
  16360. itemEncode(locaData, j, writeOffset);
  16361. startOffset = endOffset;
  16362. continue;
  16363. }
  16364. if (startOffset === endOffset) {
  16365. missingGlyphData[i] = true;
  16366. }
  16367. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16368. newGlyfData, writeOffset, hintsValid);
  16369. writeOffset += newLength;
  16370. itemEncode(locaData, j, writeOffset);
  16371. startOffset = endOffset;
  16372. }
  16373. if (writeOffset === 0) {
  16374. // glyf table cannot be empty -- redoing the glyf and loca tables
  16375. // to have single glyph with one point
  16376. var simpleGlyph = new Uint8Array(
  16377. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16378. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16379. itemEncode(locaData, j, simpleGlyph.length);
  16380. }
  16381. glyf.data = simpleGlyph;
  16382. return missingGlyphData;
  16383. }
  16384. if (dupFirstEntry) {
  16385. var firstEntryLength = itemDecode(locaData, itemSize);
  16386. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16387. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16388. } else {
  16389. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16390. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16391. }
  16392. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16393. itemEncode(loca.data, locaData.length - itemSize,
  16394. writeOffset + firstEntryLength);
  16395. } else {
  16396. glyf.data = newGlyfData.subarray(0, writeOffset);
  16397. }
  16398. return missingGlyphData;
  16399. }
  16400. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16401. var start = (font.start ? font.start : 0) + post.offset;
  16402. font.pos = start;
  16403. var length = post.length, end = start + length;
  16404. var version = font.getInt32();
  16405. // skip rest to the tables
  16406. font.getBytes(28);
  16407. var glyphNames;
  16408. var valid = true;
  16409. var i;
  16410. switch (version) {
  16411. case 0x00010000:
  16412. glyphNames = MacStandardGlyphOrdering;
  16413. break;
  16414. case 0x00020000:
  16415. var numGlyphs = font.getUint16();
  16416. if (numGlyphs !== maxpNumGlyphs) {
  16417. valid = false;
  16418. break;
  16419. }
  16420. var glyphNameIndexes = [];
  16421. for (i = 0; i < numGlyphs; ++i) {
  16422. var index = font.getUint16();
  16423. if (index >= 32768) {
  16424. valid = false;
  16425. break;
  16426. }
  16427. glyphNameIndexes.push(index);
  16428. }
  16429. if (!valid) {
  16430. break;
  16431. }
  16432. var customNames = [];
  16433. var strBuf = [];
  16434. while (font.pos < end) {
  16435. var stringLength = font.getByte();
  16436. strBuf.length = stringLength;
  16437. for (i = 0; i < stringLength; ++i) {
  16438. strBuf[i] = String.fromCharCode(font.getByte());
  16439. }
  16440. customNames.push(strBuf.join(''));
  16441. }
  16442. glyphNames = [];
  16443. for (i = 0; i < numGlyphs; ++i) {
  16444. var j = glyphNameIndexes[i];
  16445. if (j < 258) {
  16446. glyphNames.push(MacStandardGlyphOrdering[j]);
  16447. continue;
  16448. }
  16449. glyphNames.push(customNames[j - 258]);
  16450. }
  16451. break;
  16452. case 0x00030000:
  16453. break;
  16454. default:
  16455. warn('Unknown/unsupported post table version ' + version);
  16456. valid = false;
  16457. if (properties.defaultEncoding) {
  16458. glyphNames = properties.defaultEncoding;
  16459. }
  16460. break;
  16461. }
  16462. properties.glyphNames = glyphNames;
  16463. return valid;
  16464. }
  16465. function readNameTable(nameTable) {
  16466. var start = (font.start ? font.start : 0) + nameTable.offset;
  16467. font.pos = start;
  16468. var names = [[], []];
  16469. var length = nameTable.length, end = start + length;
  16470. var format = font.getUint16();
  16471. var FORMAT_0_HEADER_LENGTH = 6;
  16472. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16473. // unsupported name table format or table "too" small
  16474. return names;
  16475. }
  16476. var numRecords = font.getUint16();
  16477. var stringsStart = font.getUint16();
  16478. var records = [];
  16479. var NAME_RECORD_LENGTH = 12;
  16480. var i, ii;
  16481. for (i = 0; i < numRecords &&
  16482. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16483. var r = {
  16484. platform: font.getUint16(),
  16485. encoding: font.getUint16(),
  16486. language: font.getUint16(),
  16487. name: font.getUint16(),
  16488. length: font.getUint16(),
  16489. offset: font.getUint16()
  16490. };
  16491. // using only Macintosh and Windows platform/encoding names
  16492. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16493. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16494. records.push(r);
  16495. }
  16496. }
  16497. for (i = 0, ii = records.length; i < ii; i++) {
  16498. var record = records[i];
  16499. var pos = start + stringsStart + record.offset;
  16500. if (pos + record.length > end) {
  16501. continue; // outside of name table, ignoring
  16502. }
  16503. font.pos = pos;
  16504. var nameIndex = record.name;
  16505. if (record.encoding) {
  16506. // unicode
  16507. var str = '';
  16508. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16509. str += String.fromCharCode(font.getUint16());
  16510. }
  16511. names[1][nameIndex] = str;
  16512. } else {
  16513. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16514. }
  16515. }
  16516. return names;
  16517. }
  16518. var TTOpsStackDeltas = [
  16519. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16520. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16521. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16522. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16523. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16524. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16525. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16526. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16527. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16528. // 0xC0-DF == -1 and 0xE0-FF == -2
  16529. function sanitizeTTProgram(table, ttContext) {
  16530. var data = table.data;
  16531. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16532. var stack = [];
  16533. var callstack = [];
  16534. var functionsCalled = [];
  16535. var tooComplexToFollowFunctions =
  16536. ttContext.tooComplexToFollowFunctions;
  16537. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16538. for (var ii = data.length; i < ii;) {
  16539. var op = data[i++];
  16540. // The TrueType instruction set docs can be found at
  16541. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16542. if (op === 0x40) { // NPUSHB - pushes n bytes
  16543. n = data[i++];
  16544. if (inFDEF || inELSE) {
  16545. i += n;
  16546. } else {
  16547. for (j = 0; j < n; j++) {
  16548. stack.push(data[i++]);
  16549. }
  16550. }
  16551. } else if (op === 0x41) { // NPUSHW - pushes n words
  16552. n = data[i++];
  16553. if (inFDEF || inELSE) {
  16554. i += n * 2;
  16555. } else {
  16556. for (j = 0; j < n; j++) {
  16557. b = data[i++];
  16558. stack.push((b << 8) | data[i++]);
  16559. }
  16560. }
  16561. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16562. n = op - 0xB0 + 1;
  16563. if (inFDEF || inELSE) {
  16564. i += n;
  16565. } else {
  16566. for (j = 0; j < n; j++) {
  16567. stack.push(data[i++]);
  16568. }
  16569. }
  16570. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16571. n = op - 0xB8 + 1;
  16572. if (inFDEF || inELSE) {
  16573. i += n * 2;
  16574. } else {
  16575. for (j = 0; j < n; j++) {
  16576. b = data[i++];
  16577. stack.push((b << 8) | data[i++]);
  16578. }
  16579. }
  16580. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16581. if (!inFDEF && !inELSE) {
  16582. // collecting inforamtion about which functions are used
  16583. funcId = stack[stack.length - 1];
  16584. ttContext.functionsUsed[funcId] = true;
  16585. if (funcId in ttContext.functionsStackDeltas) {
  16586. stack.length += ttContext.functionsStackDeltas[funcId];
  16587. } else if (funcId in ttContext.functionsDefined &&
  16588. functionsCalled.indexOf(funcId) < 0) {
  16589. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16590. functionsCalled.push(funcId);
  16591. pc = ttContext.functionsDefined[funcId];
  16592. if (!pc) {
  16593. warn('TT: CALL non-existent function');
  16594. ttContext.hintsValid = false;
  16595. return;
  16596. }
  16597. data = pc.data;
  16598. i = pc.i;
  16599. }
  16600. }
  16601. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16602. if (inFDEF || inELSE) {
  16603. warn('TT: nested FDEFs not allowed');
  16604. tooComplexToFollowFunctions = true;
  16605. }
  16606. inFDEF = true;
  16607. // collecting inforamtion about which functions are defined
  16608. lastDeff = i;
  16609. funcId = stack.pop();
  16610. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16611. } else if (op === 0x2D) { // ENDF - end of function
  16612. if (inFDEF) {
  16613. inFDEF = false;
  16614. lastEndf = i;
  16615. } else {
  16616. pc = callstack.pop();
  16617. if (!pc) {
  16618. warn('TT: ENDF bad stack');
  16619. ttContext.hintsValid = false;
  16620. return;
  16621. }
  16622. funcId = functionsCalled.pop();
  16623. data = pc.data;
  16624. i = pc.i;
  16625. ttContext.functionsStackDeltas[funcId] =
  16626. stack.length - pc.stackTop;
  16627. }
  16628. } else if (op === 0x89) { // IDEF - instruction definition
  16629. if (inFDEF || inELSE) {
  16630. warn('TT: nested IDEFs not allowed');
  16631. tooComplexToFollowFunctions = true;
  16632. }
  16633. inFDEF = true;
  16634. // recording it as a function to track ENDF
  16635. lastDeff = i;
  16636. } else if (op === 0x58) { // IF
  16637. ++ifLevel;
  16638. } else if (op === 0x1B) { // ELSE
  16639. inELSE = ifLevel;
  16640. } else if (op === 0x59) { // EIF
  16641. if (inELSE === ifLevel) {
  16642. inELSE = 0;
  16643. }
  16644. --ifLevel;
  16645. } else if (op === 0x1C) { // JMPR
  16646. if (!inFDEF && !inELSE) {
  16647. var offset = stack[stack.length - 1];
  16648. // only jumping forward to prevent infinite loop
  16649. if (offset > 0) {
  16650. i += offset - 1;
  16651. }
  16652. }
  16653. }
  16654. // Adjusting stack not extactly, but just enough to get function id
  16655. if (!inFDEF && !inELSE) {
  16656. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16657. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16658. if (op >= 0x71 && op <= 0x75) {
  16659. n = stack.pop();
  16660. if (n === n) {
  16661. stackDelta = -n * 2;
  16662. }
  16663. }
  16664. while (stackDelta < 0 && stack.length > 0) {
  16665. stack.pop();
  16666. stackDelta++;
  16667. }
  16668. while (stackDelta > 0) {
  16669. stack.push(NaN); // pushing any number into stack
  16670. stackDelta--;
  16671. }
  16672. }
  16673. }
  16674. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16675. var content = [data];
  16676. if (i > data.length) {
  16677. content.push(new Uint8Array(i - data.length));
  16678. }
  16679. if (lastDeff > lastEndf) {
  16680. warn('TT: complementing a missing function tail');
  16681. // new function definition started, but not finished
  16682. // complete function by [CLEAR, ENDF]
  16683. content.push(new Uint8Array([0x22, 0x2D]));
  16684. }
  16685. foldTTTable(table, content);
  16686. }
  16687. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16688. if (ttContext.tooComplexToFollowFunctions) {
  16689. return;
  16690. }
  16691. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16692. warn('TT: more functions defined than expected');
  16693. ttContext.hintsValid = false;
  16694. return;
  16695. }
  16696. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16697. if (j > maxFunctionDefs) {
  16698. warn('TT: invalid function id: ' + j);
  16699. ttContext.hintsValid = false;
  16700. return;
  16701. }
  16702. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16703. warn('TT: undefined function: ' + j);
  16704. ttContext.hintsValid = false;
  16705. return;
  16706. }
  16707. }
  16708. }
  16709. function foldTTTable(table, content) {
  16710. if (content.length > 1) {
  16711. // concatenating the content items
  16712. var newLength = 0;
  16713. var j, jj;
  16714. for (j = 0, jj = content.length; j < jj; j++) {
  16715. newLength += content[j].length;
  16716. }
  16717. newLength = (newLength + 3) & ~3;
  16718. var result = new Uint8Array(newLength);
  16719. var pos = 0;
  16720. for (j = 0, jj = content.length; j < jj; j++) {
  16721. result.set(content[j], pos);
  16722. pos += content[j].length;
  16723. }
  16724. table.data = result;
  16725. table.length = newLength;
  16726. }
  16727. }
  16728. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16729. var ttContext = {
  16730. functionsDefined: [],
  16731. functionsUsed: [],
  16732. functionsStackDeltas: [],
  16733. tooComplexToFollowFunctions: false,
  16734. hintsValid: true
  16735. };
  16736. if (fpgm) {
  16737. sanitizeTTProgram(fpgm, ttContext);
  16738. }
  16739. if (prep) {
  16740. sanitizeTTProgram(prep, ttContext);
  16741. }
  16742. if (fpgm) {
  16743. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16744. }
  16745. if (cvt && (cvt.length & 1)) {
  16746. var cvtData = new Uint8Array(cvt.length + 1);
  16747. cvtData.set(cvt.data);
  16748. cvt.data = cvtData;
  16749. }
  16750. return ttContext.hintsValid;
  16751. }
  16752. // The following steps modify the original font data, making copy
  16753. font = new Stream(new Uint8Array(font.getBytes()));
  16754. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16755. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16756. var header = readOpenTypeHeader(font);
  16757. var numTables = header.numTables;
  16758. var cff, cffFile;
  16759. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16760. hmtx: null, maxp: null, name: null, post: null };
  16761. var table;
  16762. for (var i = 0; i < numTables; i++) {
  16763. table = readTableEntry(font);
  16764. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16765. continue; // skipping table if it's not a required or optional table
  16766. }
  16767. if (table.length === 0) {
  16768. continue; // skipping empty tables
  16769. }
  16770. tables[table.tag] = table;
  16771. }
  16772. var isTrueType = !tables['CFF '];
  16773. if (!isTrueType) {
  16774. // OpenType font
  16775. if (header.version === 'OTTO' ||
  16776. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16777. // no major tables: throwing everything at CFFFont
  16778. cffFile = new Stream(tables['CFF '].data);
  16779. cff = new CFFFont(cffFile, properties);
  16780. return this.convert(name, cff, properties);
  16781. }
  16782. delete tables.glyf;
  16783. delete tables.loca;
  16784. delete tables.fpgm;
  16785. delete tables.prep;
  16786. delete tables['cvt '];
  16787. this.isOpenType = true;
  16788. } else {
  16789. if (!tables.glyf || !tables.loca) {
  16790. error('Required "glyf" or "loca" tables are not found');
  16791. }
  16792. this.isOpenType = false;
  16793. }
  16794. if (!tables.maxp) {
  16795. error('Required "maxp" table is not found');
  16796. }
  16797. font.pos = (font.start || 0) + tables.maxp.offset;
  16798. var version = font.getInt32();
  16799. var numGlyphs = font.getUint16();
  16800. var maxFunctionDefs = 0;
  16801. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16802. // maxZones can be invalid
  16803. font.pos += 8;
  16804. var maxZones = font.getUint16();
  16805. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16806. tables.maxp.data[14] = 0;
  16807. tables.maxp.data[15] = 2;
  16808. }
  16809. font.pos += 4;
  16810. maxFunctionDefs = font.getUint16();
  16811. }
  16812. var dupFirstEntry = false;
  16813. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16814. properties.toUnicode.get(0) > '\u0000') {
  16815. // oracle's defect (see 3427), duplicating first entry
  16816. dupFirstEntry = true;
  16817. numGlyphs++;
  16818. tables.maxp.data[4] = numGlyphs >> 8;
  16819. tables.maxp.data[5] = numGlyphs & 255;
  16820. }
  16821. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16822. tables['cvt '], maxFunctionDefs);
  16823. if (!hintsValid) {
  16824. delete tables.fpgm;
  16825. delete tables.prep;
  16826. delete tables['cvt '];
  16827. }
  16828. // Ensure the hmtx table contains the advance width and
  16829. // sidebearings information for numGlyphs in the maxp table
  16830. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16831. if (!tables.head) {
  16832. error('Required "head" table is not found');
  16833. }
  16834. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16835. var missingGlyphs = {};
  16836. if (isTrueType) {
  16837. var isGlyphLocationsLong = int16(tables.head.data[50],
  16838. tables.head.data[51]);
  16839. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  16840. numGlyphs, isGlyphLocationsLong,
  16841. hintsValid, dupFirstEntry);
  16842. }
  16843. if (!tables.hhea) {
  16844. error('Required "hhea" table is not found');
  16845. }
  16846. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16847. // Sometimes it's 0. That needs to be fixed
  16848. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16849. tables.hhea.data[10] = 0xFF;
  16850. tables.hhea.data[11] = 0xFF;
  16851. }
  16852. // The 'post' table has glyphs names.
  16853. if (tables.post) {
  16854. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16855. if (!valid) {
  16856. tables.post = null;
  16857. }
  16858. }
  16859. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  16860. function hasGlyph(glyphId, charCode) {
  16861. if (!missingGlyphs[glyphId]) {
  16862. return true;
  16863. }
  16864. if (charCode >= 0 && toUnicode.has(charCode)) {
  16865. return true;
  16866. }
  16867. return false;
  16868. }
  16869. if (properties.type === 'CIDFontType2') {
  16870. var cidToGidMap = properties.cidToGidMap || [];
  16871. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  16872. properties.cMap.forEach(function(charCode, cid) {
  16873. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16874. var glyphId = -1;
  16875. if (isCidToGidMapEmpty) {
  16876. glyphId = charCode;
  16877. } else if (cidToGidMap[cid] !== undefined) {
  16878. glyphId = cidToGidMap[cid];
  16879. }
  16880. if (glyphId >= 0 && glyphId < numGlyphs &&
  16881. hasGlyph(glyphId, charCode)) {
  16882. charCodeToGlyphId[charCode] = glyphId;
  16883. }
  16884. });
  16885. if (dupFirstEntry) {
  16886. charCodeToGlyphId[0] = numGlyphs - 1;
  16887. }
  16888. } else {
  16889. // Most of the following logic in this code branch is based on the
  16890. // 9.6.6.4 of the PDF spec.
  16891. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16892. var cmapPlatformId = cmapTable.platformId;
  16893. var cmapEncodingId = cmapTable.encodingId;
  16894. var cmapMappings = cmapTable.mappings;
  16895. var cmapMappingsLength = cmapMappings.length;
  16896. var hasEncoding = properties.differences.length ||
  16897. !!properties.baseEncodingName;
  16898. // The spec seems to imply that if the font is symbolic the encoding
  16899. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16900. // where the the font is symbolic and it has an encoding.
  16901. if (hasEncoding &&
  16902. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16903. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16904. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16905. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16906. // When no preferred cmap table was found and |baseEncodingName| is
  16907. // one of the predefined encodings, we seem to obtain a better
  16908. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16909. // TODO: Note that this is a hack which should be removed as soon as
  16910. // we have proper support for more exotic cmap tables.
  16911. var baseEncoding = [];
  16912. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16913. properties.baseEncodingName === 'WinAnsiEncoding') {
  16914. baseEncoding = Encodings[properties.baseEncodingName];
  16915. }
  16916. for (charCode = 0; charCode < 256; charCode++) {
  16917. var glyphName;
  16918. if (this.differences && charCode in this.differences) {
  16919. glyphName = this.differences[charCode];
  16920. } else if (charCode in baseEncoding &&
  16921. baseEncoding[charCode] !== '') {
  16922. glyphName = baseEncoding[charCode];
  16923. } else {
  16924. glyphName = Encodings.StandardEncoding[charCode];
  16925. }
  16926. if (!glyphName) {
  16927. continue;
  16928. }
  16929. var unicodeOrCharCode;
  16930. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16931. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16932. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16933. // TODO: the encoding needs to be updated with mac os table.
  16934. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16935. }
  16936. var found = false;
  16937. for (i = 0; i < cmapMappingsLength; ++i) {
  16938. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  16939. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  16940. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16941. found = true;
  16942. break;
  16943. }
  16944. }
  16945. if (!found && properties.glyphNames) {
  16946. // Try to map using the post table. There are currently no known
  16947. // pdfs that this fixes.
  16948. var glyphId = properties.glyphNames.indexOf(glyphName);
  16949. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  16950. charCodeToGlyphId[charCode] = glyphId;
  16951. }
  16952. }
  16953. }
  16954. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  16955. // Default Unicode semantics, use the charcodes as is.
  16956. for (i = 0; i < cmapMappingsLength; ++i) {
  16957. charCodeToGlyphId[cmapMappings[i].charCode] =
  16958. cmapMappings[i].glyphId;
  16959. }
  16960. } else {
  16961. // For (3, 0) cmap tables:
  16962. // The charcode key being stored in charCodeToGlyphId is the lower
  16963. // byte of the two-byte charcodes of the cmap table since according to
  16964. // the spec: 'each byte from the string shall be prepended with the
  16965. // high byte of the range [of charcodes in the cmap table], to form
  16966. // a two-byte character, which shall be used to select the
  16967. // associated glyph description from the subtable'.
  16968. //
  16969. // For (1, 0) cmap tables:
  16970. // 'single bytes from the string shall be used to look up the
  16971. // associated glyph descriptions from the subtable'. This means
  16972. // charcodes in the cmap will be single bytes, so no-op since
  16973. // glyph.charCode & 0xFF === glyph.charCode
  16974. for (i = 0; i < cmapMappingsLength; ++i) {
  16975. charCode = cmapMappings[i].charCode & 0xFF;
  16976. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16977. }
  16978. }
  16979. }
  16980. if (charCodeToGlyphId.length === 0) {
  16981. // defines at least one glyph
  16982. charCodeToGlyphId[0] = 0;
  16983. }
  16984. // Converting glyphs and ids into font's cmap table
  16985. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16986. this.toFontChar = newMapping.toFontChar;
  16987. tables.cmap = {
  16988. tag: 'cmap',
  16989. data: createCmapTable(newMapping.charCodeToGlyphId)
  16990. };
  16991. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16992. // extract some more font properties from the OpenType head and
  16993. // hhea tables; yMin and descent value are always negative
  16994. var override = {
  16995. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16996. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16997. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16998. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16999. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17000. };
  17001. tables['OS/2'] = {
  17002. tag: 'OS/2',
  17003. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  17004. override)
  17005. };
  17006. }
  17007. // Rewrite the 'post' table if needed
  17008. if (!tables.post) {
  17009. tables.post = {
  17010. tag: 'post',
  17011. data: createPostTable(properties)
  17012. };
  17013. }
  17014. if (!isTrueType) {
  17015. try {
  17016. // Trying to repair CFF file
  17017. cffFile = new Stream(tables['CFF '].data);
  17018. var parser = new CFFParser(cffFile, properties);
  17019. cff = parser.parse();
  17020. var compiler = new CFFCompiler(cff);
  17021. tables['CFF '].data = compiler.compile();
  17022. } catch (e) {
  17023. warn('Failed to compile font ' + properties.loadedName);
  17024. }
  17025. }
  17026. // Re-creating 'name' table
  17027. if (!tables.name) {
  17028. tables.name = {
  17029. tag: 'name',
  17030. data: createNameTable(this.name)
  17031. };
  17032. } else {
  17033. // ... using existing 'name' table as prototype
  17034. var namePrototype = readNameTable(tables.name);
  17035. tables.name.data = createNameTable(name, namePrototype);
  17036. }
  17037. var builder = new OpenTypeFileBuilder(header.version);
  17038. for (var tableTag in tables) {
  17039. builder.addTable(tableTag, tables[tableTag].data);
  17040. }
  17041. return builder.toArray();
  17042. },
  17043. convert: function Font_convert(fontName, font, properties) {
  17044. // TODO: Check the charstring widths to determine this.
  17045. properties.fixedPitch = false;
  17046. var mapping = font.getGlyphMapping(properties);
  17047. var newMapping = adjustMapping(mapping, properties);
  17048. this.toFontChar = newMapping.toFontChar;
  17049. var numGlyphs = font.numGlyphs;
  17050. function getCharCodes(charCodeToGlyphId, glyphId) {
  17051. var charCodes = null;
  17052. for (var charCode in charCodeToGlyphId) {
  17053. if (glyphId === charCodeToGlyphId[charCode]) {
  17054. if (!charCodes) {
  17055. charCodes = [];
  17056. }
  17057. charCodes.push(charCode | 0);
  17058. }
  17059. }
  17060. return charCodes;
  17061. }
  17062. function createCharCode(charCodeToGlyphId, glyphId) {
  17063. for (var charCode in charCodeToGlyphId) {
  17064. if (glyphId === charCodeToGlyphId[charCode]) {
  17065. return charCode | 0;
  17066. }
  17067. }
  17068. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17069. glyphId;
  17070. return newMapping.nextAvailableFontCharCode++;
  17071. }
  17072. var seacs = font.seacs;
  17073. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17074. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17075. var charset = font.getCharset();
  17076. var seacMap = Object.create(null);
  17077. for (var glyphId in seacs) {
  17078. glyphId |= 0;
  17079. var seac = seacs[glyphId];
  17080. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17081. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17082. var baseGlyphId = charset.indexOf(baseGlyphName);
  17083. var accentGlyphId = charset.indexOf(accentGlyphName);
  17084. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17085. continue;
  17086. }
  17087. var accentOffset = {
  17088. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17089. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17090. };
  17091. var charCodes = getCharCodes(mapping, glyphId);
  17092. if (!charCodes) {
  17093. // There's no point in mapping it if the char code was never mapped
  17094. // to begin with.
  17095. continue;
  17096. }
  17097. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17098. var charCode = charCodes[i];
  17099. // Find a fontCharCode that maps to the base and accent glyphs.
  17100. // If one doesn't exists, create it.
  17101. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17102. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17103. baseGlyphId);
  17104. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17105. accentGlyphId);
  17106. seacMap[charCode] = {
  17107. baseFontCharCode: baseFontCharCode,
  17108. accentFontCharCode: accentFontCharCode,
  17109. accentOffset: accentOffset
  17110. };
  17111. }
  17112. }
  17113. properties.seacMap = seacMap;
  17114. }
  17115. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17116. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17117. // PostScript Font Program
  17118. builder.addTable('CFF ', font.data);
  17119. // OS/2 and Windows Specific metrics
  17120. builder.addTable('OS/2', createOS2Table(properties,
  17121. newMapping.charCodeToGlyphId));
  17122. // Character to glyphs mapping
  17123. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17124. // Font header
  17125. builder.addTable('head',
  17126. '\x00\x01\x00\x00' + // Version number
  17127. '\x00\x00\x10\x00' + // fontRevision
  17128. '\x00\x00\x00\x00' + // checksumAdjustement
  17129. '\x5F\x0F\x3C\xF5' + // magicNumber
  17130. '\x00\x00' + // Flags
  17131. safeString16(unitsPerEm) + // unitsPerEM
  17132. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17133. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17134. '\x00\x00' + // xMin
  17135. safeString16(properties.descent) + // yMin
  17136. '\x0F\xFF' + // xMax
  17137. safeString16(properties.ascent) + // yMax
  17138. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17139. '\x00\x11' + // lowestRecPPEM
  17140. '\x00\x00' + // fontDirectionHint
  17141. '\x00\x00' + // indexToLocFormat
  17142. '\x00\x00'); // glyphDataFormat
  17143. // Horizontal header
  17144. builder.addTable('hhea',
  17145. '\x00\x01\x00\x00' + // Version number
  17146. safeString16(properties.ascent) + // Typographic Ascent
  17147. safeString16(properties.descent) + // Typographic Descent
  17148. '\x00\x00' + // Line Gap
  17149. '\xFF\xFF' + // advanceWidthMax
  17150. '\x00\x00' + // minLeftSidebearing
  17151. '\x00\x00' + // minRightSidebearing
  17152. '\x00\x00' + // xMaxExtent
  17153. safeString16(properties.capHeight) + // caretSlopeRise
  17154. safeString16(Math.tan(properties.italicAngle) *
  17155. properties.xHeight) + // caretSlopeRun
  17156. '\x00\x00' + // caretOffset
  17157. '\x00\x00' + // -reserved-
  17158. '\x00\x00' + // -reserved-
  17159. '\x00\x00' + // -reserved-
  17160. '\x00\x00' + // -reserved-
  17161. '\x00\x00' + // metricDataFormat
  17162. string16(numGlyphs)); // Number of HMetrics
  17163. // Horizontal metrics
  17164. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17165. var charstrings = font.charstrings;
  17166. var cffWidths = font.cff ? font.cff.widths : null;
  17167. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17168. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17169. var width = 0;
  17170. if (charstrings) {
  17171. var charstring = charstrings[i - 1];
  17172. width = 'width' in charstring ? charstring.width : 0;
  17173. } else if (cffWidths) {
  17174. width = Math.ceil(cffWidths[i] || 0);
  17175. }
  17176. hmtx += string16(width) + string16(0);
  17177. }
  17178. return hmtx;
  17179. })());
  17180. // Maximum profile
  17181. builder.addTable('maxp',
  17182. '\x00\x00\x50\x00' + // Version number
  17183. string16(numGlyphs)); // Num of glyphs
  17184. // Naming tables
  17185. builder.addTable('name', createNameTable(fontName));
  17186. // PostScript informations
  17187. builder.addTable('post', createPostTable(properties));
  17188. return builder.toArray();
  17189. },
  17190. /**
  17191. * Builds a char code to unicode map based on section 9.10 of the spec.
  17192. * @param {Object} properties Font properties object.
  17193. * @return {Object} A ToUnicodeMap object.
  17194. */
  17195. buildToUnicode: function Font_buildToUnicode(properties) {
  17196. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17197. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17198. return properties.toUnicode;
  17199. }
  17200. // According to the spec if the font is a simple font we should only map
  17201. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17202. // the differences array only contains adobe standard or symbol set names,
  17203. // in pratice it seems better to always try to create a toUnicode
  17204. // map based of the default encoding.
  17205. var toUnicode, charcode;
  17206. if (!properties.composite /* is simple font */) {
  17207. toUnicode = [];
  17208. var encoding = properties.defaultEncoding.slice();
  17209. var baseEncodingName = properties.baseEncodingName;
  17210. // Merge in the differences array.
  17211. var differences = properties.differences;
  17212. for (charcode in differences) {
  17213. encoding[charcode] = differences[charcode];
  17214. }
  17215. for (charcode in encoding) {
  17216. // a) Map the character code to a character name.
  17217. var glyphName = encoding[charcode];
  17218. // b) Look up the character name in the Adobe Glyph List (see the
  17219. // Bibliography) to obtain the corresponding Unicode value.
  17220. if (glyphName === '') {
  17221. continue;
  17222. } else if (GlyphsUnicode[glyphName] === undefined) {
  17223. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17224. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17225. var code = 0;
  17226. switch (glyphName[0]) {
  17227. case 'G': // Gxx glyph
  17228. if (glyphName.length === 3) {
  17229. code = parseInt(glyphName.substr(1), 16);
  17230. }
  17231. break;
  17232. case 'g': // g00xx glyph
  17233. if (glyphName.length === 5) {
  17234. code = parseInt(glyphName.substr(1), 16);
  17235. }
  17236. break;
  17237. case 'C': // Cddd glyph
  17238. case 'c': // cddd glyph
  17239. if (glyphName.length >= 3) {
  17240. code = +glyphName.substr(1);
  17241. }
  17242. break;
  17243. }
  17244. if (code) {
  17245. // If |baseEncodingName| is one the predefined encodings,
  17246. // and |code| equals |charcode|, using the glyph defined in the
  17247. // baseEncoding seems to yield a better |toUnicode| mapping
  17248. // (fixes issue 5070).
  17249. if (baseEncodingName && code === +charcode) {
  17250. var baseEncoding = Encodings[baseEncodingName];
  17251. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17252. toUnicode[charcode] =
  17253. String.fromCharCode(GlyphsUnicode[glyphName]);
  17254. continue;
  17255. }
  17256. }
  17257. toUnicode[charcode] = String.fromCharCode(code);
  17258. }
  17259. continue;
  17260. }
  17261. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17262. }
  17263. return new ToUnicodeMap(toUnicode);
  17264. }
  17265. // If the font is a composite font that uses one of the predefined CMaps
  17266. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17267. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17268. // Adobe-Korea1 character collection:
  17269. if (properties.composite && (
  17270. (properties.cMap.builtInCMap &&
  17271. !(properties.cMap instanceof IdentityCMap)) ||
  17272. (properties.cidSystemInfo.registry === 'Adobe' &&
  17273. (properties.cidSystemInfo.ordering === 'GB1' ||
  17274. properties.cidSystemInfo.ordering === 'CNS1' ||
  17275. properties.cidSystemInfo.ordering === 'Japan1' ||
  17276. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17277. // Then:
  17278. // a) Map the character code to a character identifier (CID) according
  17279. // to the font’s CMap.
  17280. // b) Obtain the registry and ordering of the character collection used
  17281. // by the font’s CMap (for example, Adobe and Japan1) from its
  17282. // CIDSystemInfo dictionary.
  17283. var registry = properties.cidSystemInfo.registry;
  17284. var ordering = properties.cidSystemInfo.ordering;
  17285. // c) Construct a second CMap name by concatenating the registry and
  17286. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17287. // (for example, Adobe–Japan1–UCS2).
  17288. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17289. // d) Obtain the CMap with the name constructed in step (c) (available
  17290. // from the ASN Web site; see the Bibliography).
  17291. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17292. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17293. var cMap = properties.cMap;
  17294. toUnicode = [];
  17295. cMap.forEach(function(charcode, cid) {
  17296. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17297. // e) Map the CID obtained in step (a) according to the CMap obtained
  17298. // in step (d), producing a Unicode value.
  17299. var ucs2 = ucs2CMap.lookup(cid);
  17300. if (ucs2) {
  17301. toUnicode[charcode] =
  17302. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17303. ucs2.charCodeAt(1));
  17304. }
  17305. });
  17306. return new ToUnicodeMap(toUnicode);
  17307. }
  17308. // The viewer's choice, just use an identity map.
  17309. return new IdentityToUnicodeMap(properties.firstChar,
  17310. properties.lastChar);
  17311. },
  17312. get spaceWidth() {
  17313. if ('_shadowWidth' in this) {
  17314. return this._shadowWidth;
  17315. }
  17316. // trying to estimate space character width
  17317. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17318. var width;
  17319. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17320. var glyphName = possibleSpaceReplacements[i];
  17321. // if possible, getting width by glyph name
  17322. if (glyphName in this.widths) {
  17323. width = this.widths[glyphName];
  17324. break;
  17325. }
  17326. var glyphUnicode = GlyphsUnicode[glyphName];
  17327. // finding the charcode via unicodeToCID map
  17328. var charcode = 0;
  17329. if (this.composite) {
  17330. if (this.cMap.contains(glyphUnicode)) {
  17331. charcode = this.cMap.lookup(glyphUnicode);
  17332. }
  17333. }
  17334. // ... via toUnicode map
  17335. if (!charcode && 'toUnicode' in this) {
  17336. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17337. }
  17338. // setting it to unicode if negative or undefined
  17339. if (charcode <= 0) {
  17340. charcode = glyphUnicode;
  17341. }
  17342. // trying to get width via charcode
  17343. width = this.widths[charcode];
  17344. if (width) {
  17345. break; // the non-zero width found
  17346. }
  17347. }
  17348. width = width || this.defaultWidth;
  17349. // Do not shadow the property here. See discussion:
  17350. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17351. this._shadowWidth = width;
  17352. return width;
  17353. },
  17354. charToGlyph: function Font_charToGlyph(charcode) {
  17355. var fontCharCode, width, operatorListId;
  17356. var widthCode = charcode;
  17357. if (this.cMap && this.cMap.contains(charcode)) {
  17358. widthCode = this.cMap.lookup(charcode);
  17359. }
  17360. width = this.widths[widthCode];
  17361. width = isNum(width) ? width : this.defaultWidth;
  17362. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17363. var unicode = this.toUnicode.get(charcode) || charcode;
  17364. if (typeof unicode === 'number') {
  17365. unicode = String.fromCharCode(unicode);
  17366. }
  17367. // First try the toFontChar map, if it's not there then try falling
  17368. // back to the char code.
  17369. fontCharCode = this.toFontChar[charcode] || charcode;
  17370. if (this.missingFile) {
  17371. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17372. }
  17373. if (this.isType3Font) {
  17374. // Font char code in this case is actually a glyph name.
  17375. operatorListId = fontCharCode;
  17376. }
  17377. var accent = null;
  17378. if (this.seacMap && this.seacMap[charcode]) {
  17379. var seac = this.seacMap[charcode];
  17380. fontCharCode = seac.baseFontCharCode;
  17381. accent = {
  17382. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17383. offset: seac.accentOffset
  17384. };
  17385. }
  17386. var fontChar = String.fromCharCode(fontCharCode);
  17387. var glyph = this.glyphCache[charcode];
  17388. if (!glyph ||
  17389. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17390. operatorListId)) {
  17391. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17392. operatorListId);
  17393. this.glyphCache[charcode] = glyph;
  17394. }
  17395. return glyph;
  17396. },
  17397. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17398. var charsCache = this.charsCache;
  17399. var glyphs, glyph, charcode;
  17400. // if we translated this string before, just grab it from the cache
  17401. if (charsCache) {
  17402. glyphs = charsCache[chars];
  17403. if (glyphs) {
  17404. return glyphs;
  17405. }
  17406. }
  17407. // lazily create the translation cache
  17408. if (!charsCache) {
  17409. charsCache = this.charsCache = Object.create(null);
  17410. }
  17411. glyphs = [];
  17412. var charsCacheKey = chars;
  17413. var i = 0, ii;
  17414. if (this.cMap) {
  17415. // composite fonts have multi-byte strings convert the string from
  17416. // single-byte to multi-byte
  17417. var c = {};
  17418. while (i < chars.length) {
  17419. this.cMap.readCharCode(chars, i, c);
  17420. charcode = c.charcode;
  17421. var length = c.length;
  17422. i += length;
  17423. glyph = this.charToGlyph(charcode);
  17424. glyphs.push(glyph);
  17425. // placing null after each word break charcode (ASCII SPACE)
  17426. // Ignore occurences of 0x20 in multiple-byte codes.
  17427. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17428. glyphs.push(null);
  17429. }
  17430. }
  17431. } else {
  17432. for (i = 0, ii = chars.length; i < ii; ++i) {
  17433. charcode = chars.charCodeAt(i);
  17434. glyph = this.charToGlyph(charcode);
  17435. glyphs.push(glyph);
  17436. if (charcode === 0x20) {
  17437. glyphs.push(null);
  17438. }
  17439. }
  17440. }
  17441. // Enter the translated string into the cache
  17442. return (charsCache[charsCacheKey] = glyphs);
  17443. }
  17444. };
  17445. return Font;
  17446. })();
  17447. var ErrorFont = (function ErrorFontClosure() {
  17448. function ErrorFont(error) {
  17449. this.error = error;
  17450. this.loadedName = 'g_font_error';
  17451. this.loading = false;
  17452. }
  17453. ErrorFont.prototype = {
  17454. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17455. return [];
  17456. },
  17457. exportData: function ErrorFont_exportData() {
  17458. return {error: this.error};
  17459. }
  17460. };
  17461. return ErrorFont;
  17462. })();
  17463. /**
  17464. * Shared logic for building a char code to glyph id mapping for Type1 and
  17465. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17466. * @param {Object} properties Font properties object.
  17467. * @param {Object} builtInEncoding The encoding contained within the actual font
  17468. * data.
  17469. * @param {Array} Array of glyph names where the index is the glyph ID.
  17470. * @returns {Object} A char code to glyph ID map.
  17471. */
  17472. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17473. var charCodeToGlyphId = Object.create(null);
  17474. var glyphId, charCode, baseEncoding;
  17475. if (properties.baseEncodingName) {
  17476. // If a valid base encoding name was used, the mapping is initialized with
  17477. // that.
  17478. baseEncoding = Encodings[properties.baseEncodingName];
  17479. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17480. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17481. if (glyphId >= 0) {
  17482. charCodeToGlyphId[charCode] = glyphId;
  17483. } else {
  17484. charCodeToGlyphId[charCode] = 0; // notdef
  17485. }
  17486. }
  17487. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17488. // For a symbolic font the encoding should be the fonts built-in
  17489. // encoding.
  17490. for (charCode in builtInEncoding) {
  17491. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17492. }
  17493. } else {
  17494. // For non-symbolic fonts that don't have a base encoding the standard
  17495. // encoding should be used.
  17496. baseEncoding = Encodings.StandardEncoding;
  17497. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17498. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17499. if (glyphId >= 0) {
  17500. charCodeToGlyphId[charCode] = glyphId;
  17501. } else {
  17502. charCodeToGlyphId[charCode] = 0; // notdef
  17503. }
  17504. }
  17505. }
  17506. // Lastly, merge in the differences.
  17507. var differences = properties.differences;
  17508. if (differences) {
  17509. for (charCode in differences) {
  17510. var glyphName = differences[charCode];
  17511. glyphId = glyphNames.indexOf(glyphName);
  17512. if (glyphId >= 0) {
  17513. charCodeToGlyphId[charCode] = glyphId;
  17514. } else {
  17515. charCodeToGlyphId[charCode] = 0; // notdef
  17516. }
  17517. }
  17518. }
  17519. return charCodeToGlyphId;
  17520. }
  17521. /*
  17522. * CharStrings are encoded following the the CharString Encoding sequence
  17523. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17524. * The value in a byte indicates a command, a number, or subsequent bytes
  17525. * that are to be interpreted in a special way.
  17526. *
  17527. * CharString Number Encoding:
  17528. * A CharString byte containing the values from 32 through 255 inclusive
  17529. * indicate an integer. These values are decoded in four ranges.
  17530. *
  17531. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17532. * indicate the integer v - 139. Thus, the integer values from -107 through
  17533. * 107 inclusive may be encoded in single byte.
  17534. *
  17535. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17536. * indicates an integer involving the next byte, w, according to the formula:
  17537. * [(v - 247) x 256] + w + 108
  17538. *
  17539. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17540. * indicates an integer involving the next byte, w, according to the formula:
  17541. * -[(v - 251) * 256] - w - 108
  17542. *
  17543. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17544. * are a two complement signed integer. The first of these bytes contains the
  17545. * highest order bits, the second byte contains the next higher order bits
  17546. * and the fourth byte contain the lowest order bits.
  17547. *
  17548. *
  17549. * CharString Command Encoding:
  17550. * CharStrings commands are encoded in 1 or 2 bytes.
  17551. *
  17552. * Single byte commands are encoded in 1 byte that contains a value between
  17553. * 0 and 31 inclusive.
  17554. * If a command byte contains the value 12, then the value in the next byte
  17555. * indicates a command. This "escape" mechanism allows many extra commands
  17556. * to be encoded and this encoding technique helps to minimize the length of
  17557. * the charStrings.
  17558. */
  17559. var Type1CharString = (function Type1CharStringClosure() {
  17560. var COMMAND_MAP = {
  17561. 'hstem': [1],
  17562. 'vstem': [3],
  17563. 'vmoveto': [4],
  17564. 'rlineto': [5],
  17565. 'hlineto': [6],
  17566. 'vlineto': [7],
  17567. 'rrcurveto': [8],
  17568. 'callsubr': [10],
  17569. 'flex': [12, 35],
  17570. 'drop' : [12, 18],
  17571. 'endchar': [14],
  17572. 'rmoveto': [21],
  17573. 'hmoveto': [22],
  17574. 'vhcurveto': [30],
  17575. 'hvcurveto': [31]
  17576. };
  17577. function Type1CharString() {
  17578. this.width = 0;
  17579. this.lsb = 0;
  17580. this.flexing = false;
  17581. this.output = [];
  17582. this.stack = [];
  17583. }
  17584. Type1CharString.prototype = {
  17585. convert: function Type1CharString_convert(encoded, subrs) {
  17586. var count = encoded.length;
  17587. var error = false;
  17588. var wx, sbx, subrNumber;
  17589. for (var i = 0; i < count; i++) {
  17590. var value = encoded[i];
  17591. if (value < 32) {
  17592. if (value === 12) {
  17593. value = (value << 8) + encoded[++i];
  17594. }
  17595. switch (value) {
  17596. case 1: // hstem
  17597. if (!HINTING_ENABLED) {
  17598. this.stack = [];
  17599. break;
  17600. }
  17601. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17602. break;
  17603. case 3: // vstem
  17604. if (!HINTING_ENABLED) {
  17605. this.stack = [];
  17606. break;
  17607. }
  17608. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17609. break;
  17610. case 4: // vmoveto
  17611. if (this.flexing) {
  17612. if (this.stack.length < 1) {
  17613. error = true;
  17614. break;
  17615. }
  17616. // Add the dx for flex and but also swap the values so they are
  17617. // the right order.
  17618. var dy = this.stack.pop();
  17619. this.stack.push(0, dy);
  17620. break;
  17621. }
  17622. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17623. break;
  17624. case 5: // rlineto
  17625. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17626. break;
  17627. case 6: // hlineto
  17628. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17629. break;
  17630. case 7: // vlineto
  17631. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17632. break;
  17633. case 8: // rrcurveto
  17634. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17635. break;
  17636. case 9: // closepath
  17637. // closepath is a Type1 command that does not take argument and is
  17638. // useless in Type2 and it can simply be ignored.
  17639. this.stack = [];
  17640. break;
  17641. case 10: // callsubr
  17642. if (this.stack.length < 1) {
  17643. error = true;
  17644. break;
  17645. }
  17646. subrNumber = this.stack.pop();
  17647. error = this.convert(subrs[subrNumber], subrs);
  17648. break;
  17649. case 11: // return
  17650. return error;
  17651. case 13: // hsbw
  17652. if (this.stack.length < 2) {
  17653. error = true;
  17654. break;
  17655. }
  17656. // To convert to type2 we have to move the width value to the
  17657. // first part of the charstring and then use hmoveto with lsb.
  17658. wx = this.stack.pop();
  17659. sbx = this.stack.pop();
  17660. this.lsb = sbx;
  17661. this.width = wx;
  17662. this.stack.push(wx, sbx);
  17663. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17664. break;
  17665. case 14: // endchar
  17666. this.output.push(COMMAND_MAP.endchar[0]);
  17667. break;
  17668. case 21: // rmoveto
  17669. if (this.flexing) {
  17670. break;
  17671. }
  17672. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17673. break;
  17674. case 22: // hmoveto
  17675. if (this.flexing) {
  17676. // Add the dy for flex.
  17677. this.stack.push(0);
  17678. break;
  17679. }
  17680. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17681. break;
  17682. case 30: // vhcurveto
  17683. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17684. break;
  17685. case 31: // hvcurveto
  17686. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17687. break;
  17688. case (12 << 8) + 0: // dotsection
  17689. // dotsection is a Type1 command to specify some hinting feature
  17690. // for dots that do not take a parameter and it can safely be
  17691. // ignored for Type2.
  17692. this.stack = [];
  17693. break;
  17694. case (12 << 8) + 1: // vstem3
  17695. if (!HINTING_ENABLED) {
  17696. this.stack = [];
  17697. break;
  17698. }
  17699. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17700. // multiple parameters, so instead of returning [vh]stem3 take a
  17701. // shortcut and return [vhstem] instead.
  17702. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17703. break;
  17704. case (12 << 8) + 2: // hstem3
  17705. if (!HINTING_ENABLED) {
  17706. this.stack = [];
  17707. break;
  17708. }
  17709. // See vstem3.
  17710. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17711. break;
  17712. case (12 << 8) + 6: // seac
  17713. // seac is like type 2's special endchar but it doesn't use the
  17714. // first argument asb, so remove it.
  17715. if (SEAC_ANALYSIS_ENABLED) {
  17716. this.seac = this.stack.splice(-4, 4);
  17717. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17718. } else {
  17719. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17720. }
  17721. break;
  17722. case (12 << 8) + 7: // sbw
  17723. if (this.stack.length < 4) {
  17724. error = true;
  17725. break;
  17726. }
  17727. // To convert to type2 we have to move the width value to the
  17728. // first part of the charstring and then use rmoveto with
  17729. // (dx, dy). The height argument will not be used for vmtx and
  17730. // vhea tables reconstruction -- ignoring it.
  17731. var wy = this.stack.pop();
  17732. wx = this.stack.pop();
  17733. var sby = this.stack.pop();
  17734. sbx = this.stack.pop();
  17735. this.lsb = sbx;
  17736. this.width = wx;
  17737. this.stack.push(wx, sbx, sby);
  17738. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17739. break;
  17740. case (12 << 8) + 12: // div
  17741. if (this.stack.length < 2) {
  17742. error = true;
  17743. break;
  17744. }
  17745. var num2 = this.stack.pop();
  17746. var num1 = this.stack.pop();
  17747. this.stack.push(num1 / num2);
  17748. break;
  17749. case (12 << 8) + 16: // callothersubr
  17750. if (this.stack.length < 2) {
  17751. error = true;
  17752. break;
  17753. }
  17754. subrNumber = this.stack.pop();
  17755. var numArgs = this.stack.pop();
  17756. if (subrNumber === 0 && numArgs === 3) {
  17757. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17758. this.stack.push(
  17759. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17760. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17761. flexArgs[4], // bcp2x
  17762. flexArgs[5], // bcp2y
  17763. flexArgs[6], // p2x
  17764. flexArgs[7], // p2y
  17765. flexArgs[8], // bcp3x
  17766. flexArgs[9], // bcp3y
  17767. flexArgs[10], // bcp4x
  17768. flexArgs[11], // bcp4y
  17769. flexArgs[12], // p3x
  17770. flexArgs[13], // p3y
  17771. flexArgs[14] // flexDepth
  17772. // 15 = finalx unused by flex
  17773. // 16 = finaly unused by flex
  17774. );
  17775. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17776. this.flexing = false;
  17777. this.stack.push(flexArgs[15], flexArgs[16]);
  17778. } else if (subrNumber === 1 && numArgs === 0) {
  17779. this.flexing = true;
  17780. }
  17781. break;
  17782. case (12 << 8) + 17: // pop
  17783. // Ignore this since it is only used with othersubr.
  17784. break;
  17785. case (12 << 8) + 33: // setcurrentpoint
  17786. // Ignore for now.
  17787. this.stack = [];
  17788. break;
  17789. default:
  17790. warn('Unknown type 1 charstring command of "' + value + '"');
  17791. break;
  17792. }
  17793. if (error) {
  17794. break;
  17795. }
  17796. continue;
  17797. } else if (value <= 246) {
  17798. value = value - 139;
  17799. } else if (value <= 250) {
  17800. value = ((value - 247) * 256) + encoded[++i] + 108;
  17801. } else if (value <= 254) {
  17802. value = -((value - 251) * 256) - encoded[++i] - 108;
  17803. } else {
  17804. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17805. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17806. }
  17807. this.stack.push(value);
  17808. }
  17809. return error;
  17810. },
  17811. executeCommand: function(howManyArgs, command, keepStack) {
  17812. var stackLength = this.stack.length;
  17813. if (howManyArgs > stackLength) {
  17814. return true;
  17815. }
  17816. var start = stackLength - howManyArgs;
  17817. for (var i = start; i < stackLength; i++) {
  17818. var value = this.stack[i];
  17819. if (value === (value | 0)) { // int
  17820. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17821. } else { // fixed point
  17822. value = (65536 * value) | 0;
  17823. this.output.push(255,
  17824. (value >> 24) & 0xFF,
  17825. (value >> 16) & 0xFF,
  17826. (value >> 8) & 0xFF,
  17827. value & 0xFF);
  17828. }
  17829. }
  17830. this.output.push.apply(this.output, command);
  17831. if (keepStack) {
  17832. this.stack.splice(start, howManyArgs);
  17833. } else {
  17834. this.stack.length = 0;
  17835. }
  17836. return false;
  17837. }
  17838. };
  17839. return Type1CharString;
  17840. })();
  17841. /*
  17842. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17843. * program. Some of its logic depends on the Type2 charstrings
  17844. * structure.
  17845. * Note: this doesn't really parse the font since that would require evaluation
  17846. * of PostScript, but it is possible in most cases to extract what we need
  17847. * without a full parse.
  17848. */
  17849. var Type1Parser = (function Type1ParserClosure() {
  17850. /*
  17851. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17852. * of Plaintext Bytes. The function took a key as a parameter which can be
  17853. * for decrypting the eexec block of for decoding charStrings.
  17854. */
  17855. var EEXEC_ENCRYPT_KEY = 55665;
  17856. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17857. function isHexDigit(code) {
  17858. return code >= 48 && code <= 57 || // '0'-'9'
  17859. code >= 65 && code <= 70 || // 'A'-'F'
  17860. code >= 97 && code <= 102; // 'a'-'f'
  17861. }
  17862. function decrypt(data, key, discardNumber) {
  17863. var r = key | 0, c1 = 52845, c2 = 22719;
  17864. var count = data.length;
  17865. var decrypted = new Uint8Array(count);
  17866. for (var i = 0; i < count; i++) {
  17867. var value = data[i];
  17868. decrypted[i] = value ^ (r >> 8);
  17869. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17870. }
  17871. return Array.prototype.slice.call(decrypted, discardNumber);
  17872. }
  17873. function decryptAscii(data, key, discardNumber) {
  17874. var r = key | 0, c1 = 52845, c2 = 22719;
  17875. var count = data.length, maybeLength = count >>> 1;
  17876. var decrypted = new Uint8Array(maybeLength);
  17877. var i, j;
  17878. for (i = 0, j = 0; i < count; i++) {
  17879. var digit1 = data[i];
  17880. if (!isHexDigit(digit1)) {
  17881. continue;
  17882. }
  17883. i++;
  17884. var digit2;
  17885. while (i < count && !isHexDigit(digit2 = data[i])) {
  17886. i++;
  17887. }
  17888. if (i < count) {
  17889. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17890. decrypted[j++] = value ^ (r >> 8);
  17891. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17892. }
  17893. }
  17894. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17895. }
  17896. function isSpecial(c) {
  17897. return c === 0x2F || // '/'
  17898. c === 0x5B || c === 0x5D || // '[', ']'
  17899. c === 0x7B || c === 0x7D || // '{', '}'
  17900. c === 0x28 || c === 0x29; // '(', ')'
  17901. }
  17902. function Type1Parser(stream, encrypted) {
  17903. if (encrypted) {
  17904. var data = stream.getBytes();
  17905. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17906. isHexDigit(data[2]) && isHexDigit(data[3]));
  17907. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17908. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17909. }
  17910. this.stream = stream;
  17911. this.nextChar();
  17912. }
  17913. Type1Parser.prototype = {
  17914. readNumberArray: function Type1Parser_readNumberArray() {
  17915. this.getToken(); // read '[' or '{' (arrays can start with either)
  17916. var array = [];
  17917. while (true) {
  17918. var token = this.getToken();
  17919. if (token === null || token === ']' || token === '}') {
  17920. break;
  17921. }
  17922. array.push(parseFloat(token || 0));
  17923. }
  17924. return array;
  17925. },
  17926. readNumber: function Type1Parser_readNumber() {
  17927. var token = this.getToken();
  17928. return parseFloat(token || 0);
  17929. },
  17930. readInt: function Type1Parser_readInt() {
  17931. // Use '| 0' to prevent setting a double into length such as the double
  17932. // does not flow into the loop variable.
  17933. var token = this.getToken();
  17934. return parseInt(token || 0, 10) | 0;
  17935. },
  17936. readBoolean: function Type1Parser_readBoolean() {
  17937. var token = this.getToken();
  17938. // Use 1 and 0 since that's what type2 charstrings use.
  17939. return token === 'true' ? 1 : 0;
  17940. },
  17941. nextChar : function Type1_nextChar() {
  17942. return (this.currentChar = this.stream.getByte());
  17943. },
  17944. getToken: function Type1Parser_getToken() {
  17945. // Eat whitespace and comments.
  17946. var comment = false;
  17947. var ch = this.currentChar;
  17948. while (true) {
  17949. if (ch === -1) {
  17950. return null;
  17951. }
  17952. if (comment) {
  17953. if (ch === 0x0A || ch === 0x0D) {
  17954. comment = false;
  17955. }
  17956. } else if (ch === 0x25) { // '%'
  17957. comment = true;
  17958. } else if (!Lexer.isSpace(ch)) {
  17959. break;
  17960. }
  17961. ch = this.nextChar();
  17962. }
  17963. if (isSpecial(ch)) {
  17964. this.nextChar();
  17965. return String.fromCharCode(ch);
  17966. }
  17967. var token = '';
  17968. do {
  17969. token += String.fromCharCode(ch);
  17970. ch = this.nextChar();
  17971. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17972. return token;
  17973. },
  17974. /*
  17975. * Returns an object containing a Subrs array and a CharStrings
  17976. * array extracted from and eexec encrypted block of data
  17977. */
  17978. extractFontProgram: function Type1Parser_extractFontProgram() {
  17979. var stream = this.stream;
  17980. var subrs = [], charstrings = [];
  17981. var program = {
  17982. subrs: [],
  17983. charstrings: [],
  17984. properties: {
  17985. 'privateData': {
  17986. 'lenIV': 4
  17987. }
  17988. }
  17989. };
  17990. var token, length, data, lenIV, encoded;
  17991. while ((token = this.getToken()) !== null) {
  17992. if (token !== '/') {
  17993. continue;
  17994. }
  17995. token = this.getToken();
  17996. switch (token) {
  17997. case 'CharStrings':
  17998. // The number immediately following CharStrings must be greater or
  17999. // equal to the number of CharStrings.
  18000. this.getToken();
  18001. this.getToken(); // read in 'dict'
  18002. this.getToken(); // read in 'dup'
  18003. this.getToken(); // read in 'begin'
  18004. while(true) {
  18005. token = this.getToken();
  18006. if (token === null || token === 'end') {
  18007. break;
  18008. }
  18009. if (token !== '/') {
  18010. continue;
  18011. }
  18012. var glyph = this.getToken();
  18013. length = this.readInt();
  18014. this.getToken(); // read in 'RD' or '-|'
  18015. data = stream.makeSubStream(stream.pos, length);
  18016. lenIV = program.properties.privateData['lenIV'];
  18017. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18018. // Skip past the required space and binary data.
  18019. stream.skip(length);
  18020. this.nextChar();
  18021. token = this.getToken(); // read in 'ND' or '|-'
  18022. if (token === 'noaccess') {
  18023. this.getToken(); // read in 'def'
  18024. }
  18025. charstrings.push({
  18026. glyph: glyph,
  18027. encoded: encoded
  18028. });
  18029. }
  18030. break;
  18031. case 'Subrs':
  18032. var num = this.readInt();
  18033. this.getToken(); // read in 'array'
  18034. while ((token = this.getToken()) === 'dup') {
  18035. var index = this.readInt();
  18036. length = this.readInt();
  18037. this.getToken(); // read in 'RD' or '-|'
  18038. data = stream.makeSubStream(stream.pos, length);
  18039. lenIV = program.properties.privateData['lenIV'];
  18040. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18041. // Skip past the required space and binary data.
  18042. stream.skip(length);
  18043. this.nextChar();
  18044. token = this.getToken(); // read in 'NP' or '|'
  18045. if (token === 'noaccess') {
  18046. this.getToken(); // read in 'put'
  18047. }
  18048. subrs[index] = encoded;
  18049. }
  18050. break;
  18051. case 'BlueValues':
  18052. case 'OtherBlues':
  18053. case 'FamilyBlues':
  18054. case 'FamilyOtherBlues':
  18055. var blueArray = this.readNumberArray();
  18056. // *Blue* values may contain invalid data: disables reading of
  18057. // those values when hinting is disabled.
  18058. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18059. HINTING_ENABLED) {
  18060. program.properties.privateData[token] = blueArray;
  18061. }
  18062. break;
  18063. case 'StemSnapH':
  18064. case 'StemSnapV':
  18065. program.properties.privateData[token] = this.readNumberArray();
  18066. break;
  18067. case 'StdHW':
  18068. case 'StdVW':
  18069. program.properties.privateData[token] =
  18070. this.readNumberArray()[0];
  18071. break;
  18072. case 'BlueShift':
  18073. case 'lenIV':
  18074. case 'BlueFuzz':
  18075. case 'BlueScale':
  18076. case 'LanguageGroup':
  18077. case 'ExpansionFactor':
  18078. program.properties.privateData[token] = this.readNumber();
  18079. break;
  18080. case 'ForceBold':
  18081. program.properties.privateData[token] = this.readBoolean();
  18082. break;
  18083. }
  18084. }
  18085. for (var i = 0; i < charstrings.length; i++) {
  18086. glyph = charstrings[i].glyph;
  18087. encoded = charstrings[i].encoded;
  18088. var charString = new Type1CharString();
  18089. var error = charString.convert(encoded, subrs);
  18090. var output = charString.output;
  18091. if (error) {
  18092. // It seems when FreeType encounters an error while evaluating a glyph
  18093. // that it completely ignores the glyph so we'll mimic that behaviour
  18094. // here and put an endchar to make the validator happy.
  18095. output = [14];
  18096. }
  18097. program.charstrings.push({
  18098. glyphName: glyph,
  18099. charstring: output,
  18100. width: charString.width,
  18101. lsb: charString.lsb,
  18102. seac: charString.seac
  18103. });
  18104. }
  18105. return program;
  18106. },
  18107. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18108. var token;
  18109. while ((token = this.getToken()) !== null) {
  18110. if (token !== '/') {
  18111. continue;
  18112. }
  18113. token = this.getToken();
  18114. switch (token) {
  18115. case 'FontMatrix':
  18116. var matrix = this.readNumberArray();
  18117. properties.fontMatrix = matrix;
  18118. break;
  18119. case 'Encoding':
  18120. var encodingArg = this.getToken();
  18121. var encoding;
  18122. if (!/^\d+$/.test(encodingArg)) {
  18123. // encoding name is specified
  18124. encoding = Encodings[encodingArg];
  18125. } else {
  18126. encoding = [];
  18127. var size = parseInt(encodingArg, 10) | 0;
  18128. this.getToken(); // read in 'array'
  18129. for (var j = 0; j < size; j++) {
  18130. token = this.getToken();
  18131. // skipping till first dup or def (e.g. ignoring for statement)
  18132. while (token !== 'dup' && token !== 'def') {
  18133. token = this.getToken();
  18134. if (token === null) {
  18135. return; // invalid header
  18136. }
  18137. }
  18138. if (token === 'def') {
  18139. break; // read all array data
  18140. }
  18141. var index = this.readInt();
  18142. this.getToken(); // read in '/'
  18143. var glyph = this.getToken();
  18144. encoding[index] = glyph;
  18145. this.getToken(); // read the in 'put'
  18146. }
  18147. }
  18148. properties.builtInEncoding = encoding;
  18149. break;
  18150. case 'FontBBox':
  18151. var fontBBox = this.readNumberArray();
  18152. // adjusting ascent/descent
  18153. properties.ascent = fontBBox[3];
  18154. properties.descent = fontBBox[1];
  18155. properties.ascentScaled = true;
  18156. break;
  18157. }
  18158. }
  18159. }
  18160. };
  18161. return Type1Parser;
  18162. })();
  18163. /**
  18164. * The CFF class takes a Type1 file and wrap it into a
  18165. * 'Compact Font Format' which itself embed Type2 charstrings.
  18166. */
  18167. var CFFStandardStrings = [
  18168. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18169. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18170. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18171. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18172. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18173. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18174. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18175. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18176. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18177. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18178. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18179. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18180. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18181. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18182. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18183. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18184. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18185. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18186. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18187. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18188. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18189. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18190. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18191. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18192. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18193. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18194. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18195. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18196. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18197. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18198. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18199. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18200. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18201. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18202. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18203. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18204. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18205. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18206. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18207. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18208. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18209. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18210. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18211. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18212. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18213. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18214. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18215. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18216. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18217. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18218. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18219. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18220. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18221. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18222. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18223. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18224. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18225. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18226. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18227. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18228. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18229. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18230. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18231. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18232. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18233. ];
  18234. // Type1Font is also a CIDFontType0.
  18235. var Type1Font = function Type1Font(name, file, properties) {
  18236. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18237. // Also, length1 and length2 might be off by 6 bytes as well.
  18238. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18239. var PFB_HEADER_SIZE = 6;
  18240. var headerBlockLength = properties.length1;
  18241. var eexecBlockLength = properties.length2;
  18242. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18243. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18244. if (pfbHeaderPresent) {
  18245. file.skip(PFB_HEADER_SIZE);
  18246. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18247. (pfbHeader[3] << 8) | pfbHeader[2];
  18248. }
  18249. // Get the data block containing glyphs and subrs informations
  18250. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18251. var headerBlockParser = new Type1Parser(headerBlock);
  18252. headerBlockParser.extractFontHeader(properties);
  18253. if (pfbHeaderPresent) {
  18254. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18255. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18256. (pfbHeader[3] << 8) | pfbHeader[2];
  18257. }
  18258. // Decrypt the data blocks and retrieve it's content
  18259. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18260. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18261. var data = eexecBlockParser.extractFontProgram();
  18262. for (var info in data.properties) {
  18263. properties[info] = data.properties[info];
  18264. }
  18265. var charstrings = data.charstrings;
  18266. var type2Charstrings = this.getType2Charstrings(charstrings);
  18267. var subrs = this.getType2Subrs(data.subrs);
  18268. this.charstrings = charstrings;
  18269. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18270. subrs, properties);
  18271. this.seacs = this.getSeacs(data.charstrings);
  18272. };
  18273. Type1Font.prototype = {
  18274. get numGlyphs() {
  18275. return this.charstrings.length + 1;
  18276. },
  18277. getCharset: function Type1Font_getCharset() {
  18278. var charset = ['.notdef'];
  18279. var charstrings = this.charstrings;
  18280. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18281. charset.push(charstrings[glyphId].glyphName);
  18282. }
  18283. return charset;
  18284. },
  18285. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18286. var charstrings = this.charstrings;
  18287. var glyphNames = ['.notdef'], glyphId;
  18288. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18289. glyphNames.push(charstrings[glyphId].glyphName);
  18290. }
  18291. var encoding = properties.builtInEncoding;
  18292. if (encoding) {
  18293. var builtInEncoding = {};
  18294. for (var charCode in encoding) {
  18295. glyphId = glyphNames.indexOf(encoding[charCode]);
  18296. if (glyphId >= 0) {
  18297. builtInEncoding[charCode] = glyphId;
  18298. }
  18299. }
  18300. }
  18301. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18302. },
  18303. getSeacs: function Type1Font_getSeacs(charstrings) {
  18304. var i, ii;
  18305. var seacMap = [];
  18306. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18307. var charstring = charstrings[i];
  18308. if (charstring.seac) {
  18309. // Offset by 1 for .notdef
  18310. seacMap[i + 1] = charstring.seac;
  18311. }
  18312. }
  18313. return seacMap;
  18314. },
  18315. getType2Charstrings: function Type1Font_getType2Charstrings(
  18316. type1Charstrings) {
  18317. var type2Charstrings = [];
  18318. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18319. type2Charstrings.push(type1Charstrings[i].charstring);
  18320. }
  18321. return type2Charstrings;
  18322. },
  18323. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18324. var bias = 0;
  18325. var count = type1Subrs.length;
  18326. if (count < 1133) {
  18327. bias = 107;
  18328. } else if (count < 33769) {
  18329. bias = 1131;
  18330. } else {
  18331. bias = 32768;
  18332. }
  18333. // Add a bunch of empty subrs to deal with the Type2 bias
  18334. var type2Subrs = [];
  18335. var i;
  18336. for (i = 0; i < bias; i++) {
  18337. type2Subrs.push([0x0B]);
  18338. }
  18339. for (i = 0; i < count; i++) {
  18340. type2Subrs.push(type1Subrs[i]);
  18341. }
  18342. return type2Subrs;
  18343. },
  18344. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18345. var cff = new CFF();
  18346. cff.header = new CFFHeader(1, 0, 4, 4);
  18347. cff.names = [name];
  18348. var topDict = new CFFTopDict();
  18349. // CFF strings IDs 0...390 are predefined names, so refering
  18350. // to entries in our own String INDEX starts at SID 391.
  18351. topDict.setByName('version', 391);
  18352. topDict.setByName('Notice', 392);
  18353. topDict.setByName('FullName', 393);
  18354. topDict.setByName('FamilyName', 394);
  18355. topDict.setByName('Weight', 395);
  18356. topDict.setByName('Encoding', null); // placeholder
  18357. topDict.setByName('FontMatrix', properties.fontMatrix);
  18358. topDict.setByName('FontBBox', properties.bbox);
  18359. topDict.setByName('charset', null); // placeholder
  18360. topDict.setByName('CharStrings', null); // placeholder
  18361. topDict.setByName('Private', null); // placeholder
  18362. cff.topDict = topDict;
  18363. var strings = new CFFStrings();
  18364. strings.add('Version 0.11'); // Version
  18365. strings.add('See original notice'); // Notice
  18366. strings.add(name); // FullName
  18367. strings.add(name); // FamilyName
  18368. strings.add('Medium'); // Weight
  18369. cff.strings = strings;
  18370. cff.globalSubrIndex = new CFFIndex();
  18371. var count = glyphs.length;
  18372. var charsetArray = [0];
  18373. var i, ii;
  18374. for (i = 0; i < count; i++) {
  18375. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18376. // TODO: Insert the string and correctly map it. Previously it was
  18377. // thought mapping names that aren't in the standard strings to .notdef
  18378. // was fine, however in issue818 when mapping them all to .notdef the
  18379. // adieresis glyph no longer worked.
  18380. if (index === -1) {
  18381. index = 0;
  18382. }
  18383. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18384. }
  18385. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18386. var charStringsIndex = new CFFIndex();
  18387. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18388. for (i = 0; i < count; i++) {
  18389. charStringsIndex.add(glyphs[i]);
  18390. }
  18391. cff.charStrings = charStringsIndex;
  18392. var privateDict = new CFFPrivateDict();
  18393. privateDict.setByName('Subrs', null); // placeholder
  18394. var fields = [
  18395. 'BlueValues',
  18396. 'OtherBlues',
  18397. 'FamilyBlues',
  18398. 'FamilyOtherBlues',
  18399. 'StemSnapH',
  18400. 'StemSnapV',
  18401. 'BlueShift',
  18402. 'BlueFuzz',
  18403. 'BlueScale',
  18404. 'LanguageGroup',
  18405. 'ExpansionFactor',
  18406. 'ForceBold',
  18407. 'StdHW',
  18408. 'StdVW'
  18409. ];
  18410. for (i = 0, ii = fields.length; i < ii; i++) {
  18411. var field = fields[i];
  18412. if (!properties.privateData.hasOwnProperty(field)) {
  18413. continue;
  18414. }
  18415. var value = properties.privateData[field];
  18416. if (isArray(value)) {
  18417. // All of the private dictionary array data in CFF must be stored as
  18418. // "delta-encoded" numbers.
  18419. for (var j = value.length - 1; j > 0; j--) {
  18420. value[j] -= value[j - 1]; // ... difference from previous value
  18421. }
  18422. }
  18423. privateDict.setByName(field, value);
  18424. }
  18425. cff.topDict.privateDict = privateDict;
  18426. var subrIndex = new CFFIndex();
  18427. for (i = 0, ii = subrs.length; i < ii; i++) {
  18428. subrIndex.add(subrs[i]);
  18429. }
  18430. privateDict.subrsIndex = subrIndex;
  18431. var compiler = new CFFCompiler(cff);
  18432. return compiler.compile();
  18433. }
  18434. };
  18435. var CFFFont = (function CFFFontClosure() {
  18436. function CFFFont(file, properties) {
  18437. this.properties = properties;
  18438. var parser = new CFFParser(file, properties);
  18439. this.cff = parser.parse();
  18440. var compiler = new CFFCompiler(this.cff);
  18441. this.seacs = this.cff.seacs;
  18442. try {
  18443. this.data = compiler.compile();
  18444. } catch (e) {
  18445. warn('Failed to compile font ' + properties.loadedName);
  18446. // There may have just been an issue with the compiler, set the data
  18447. // anyway and hope the font loaded.
  18448. this.data = file;
  18449. }
  18450. }
  18451. CFFFont.prototype = {
  18452. get numGlyphs() {
  18453. return this.cff.charStrings.count;
  18454. },
  18455. getCharset: function CFFFont_getCharset() {
  18456. return this.cff.charset.charset;
  18457. },
  18458. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18459. var cff = this.cff;
  18460. var properties = this.properties;
  18461. var charsets = cff.charset.charset;
  18462. var charCodeToGlyphId;
  18463. var glyphId;
  18464. if (properties.composite) {
  18465. charCodeToGlyphId = Object.create(null);
  18466. if (cff.isCIDFont) {
  18467. // If the font is actually a CID font then we should use the charset
  18468. // to map CIDs to GIDs.
  18469. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18470. var cid = charsets[glyphId];
  18471. var charCode = properties.cMap.charCodeOf(cid);
  18472. charCodeToGlyphId[charCode] = glyphId;
  18473. }
  18474. } else {
  18475. // If it is NOT actually a CID font then CIDs should be mapped
  18476. // directly to GIDs.
  18477. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18478. charCodeToGlyphId[glyphId] = glyphId;
  18479. }
  18480. }
  18481. return charCodeToGlyphId;
  18482. }
  18483. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18484. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18485. return charCodeToGlyphId;
  18486. }
  18487. };
  18488. return CFFFont;
  18489. })();
  18490. var CFFParser = (function CFFParserClosure() {
  18491. var CharstringValidationData = [
  18492. null,
  18493. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18494. null,
  18495. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18496. { id: 'vmoveto', min: 1, stackClearing: true },
  18497. { id: 'rlineto', min: 2, resetStack: true },
  18498. { id: 'hlineto', min: 1, resetStack: true },
  18499. { id: 'vlineto', min: 1, resetStack: true },
  18500. { id: 'rrcurveto', min: 6, resetStack: true },
  18501. null,
  18502. { id: 'callsubr', min: 1, undefStack: true },
  18503. { id: 'return', min: 0, undefStack: true },
  18504. null, // 12
  18505. null,
  18506. { id: 'endchar', min: 0, stackClearing: true },
  18507. null,
  18508. null,
  18509. null,
  18510. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18511. { id: 'hintmask', min: 0, stackClearing: true },
  18512. { id: 'cntrmask', min: 0, stackClearing: true },
  18513. { id: 'rmoveto', min: 2, stackClearing: true },
  18514. { id: 'hmoveto', min: 1, stackClearing: true },
  18515. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18516. { id: 'rcurveline', min: 8, resetStack: true },
  18517. { id: 'rlinecurve', min: 8, resetStack: true },
  18518. { id: 'vvcurveto', min: 4, resetStack: true },
  18519. { id: 'hhcurveto', min: 4, resetStack: true },
  18520. null, // shortint
  18521. { id: 'callgsubr', min: 1, undefStack: true },
  18522. { id: 'vhcurveto', min: 4, resetStack: true },
  18523. { id: 'hvcurveto', min: 4, resetStack: true }
  18524. ];
  18525. var CharstringValidationData12 = [
  18526. null,
  18527. null,
  18528. null,
  18529. { id: 'and', min: 2, stackDelta: -1 },
  18530. { id: 'or', min: 2, stackDelta: -1 },
  18531. { id: 'not', min: 1, stackDelta: 0 },
  18532. null,
  18533. null,
  18534. null,
  18535. { id: 'abs', min: 1, stackDelta: 0 },
  18536. { id: 'add', min: 2, stackDelta: -1,
  18537. stackFn: function stack_div(stack, index) {
  18538. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18539. }
  18540. },
  18541. { id: 'sub', min: 2, stackDelta: -1,
  18542. stackFn: function stack_div(stack, index) {
  18543. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18544. }
  18545. },
  18546. { id: 'div', min: 2, stackDelta: -1,
  18547. stackFn: function stack_div(stack, index) {
  18548. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18549. }
  18550. },
  18551. null,
  18552. { id: 'neg', min: 1, stackDelta: 0,
  18553. stackFn: function stack_div(stack, index) {
  18554. stack[index - 1] = -stack[index - 1];
  18555. }
  18556. },
  18557. { id: 'eq', min: 2, stackDelta: -1 },
  18558. null,
  18559. null,
  18560. { id: 'drop', min: 1, stackDelta: -1 },
  18561. null,
  18562. { id: 'put', min: 2, stackDelta: -2 },
  18563. { id: 'get', min: 1, stackDelta: 0 },
  18564. { id: 'ifelse', min: 4, stackDelta: -3 },
  18565. { id: 'random', min: 0, stackDelta: 1 },
  18566. { id: 'mul', min: 2, stackDelta: -1,
  18567. stackFn: function stack_div(stack, index) {
  18568. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18569. }
  18570. },
  18571. null,
  18572. { id: 'sqrt', min: 1, stackDelta: 0 },
  18573. { id: 'dup', min: 1, stackDelta: 1 },
  18574. { id: 'exch', min: 2, stackDelta: 0 },
  18575. { id: 'index', min: 2, stackDelta: 0 },
  18576. { id: 'roll', min: 3, stackDelta: -2 },
  18577. null,
  18578. null,
  18579. null,
  18580. { id: 'hflex', min: 7, resetStack: true },
  18581. { id: 'flex', min: 13, resetStack: true },
  18582. { id: 'hflex1', min: 9, resetStack: true },
  18583. { id: 'flex1', min: 11, resetStack: true }
  18584. ];
  18585. function CFFParser(file, properties) {
  18586. this.bytes = file.getBytes();
  18587. this.properties = properties;
  18588. }
  18589. CFFParser.prototype = {
  18590. parse: function CFFParser_parse() {
  18591. var properties = this.properties;
  18592. var cff = new CFF();
  18593. this.cff = cff;
  18594. // The first five sections must be in order, all the others are reached
  18595. // via offsets contained in one of the below.
  18596. var header = this.parseHeader();
  18597. var nameIndex = this.parseIndex(header.endPos);
  18598. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18599. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18600. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18601. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18602. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18603. cff.header = header.obj;
  18604. cff.names = this.parseNameIndex(nameIndex.obj);
  18605. cff.strings = this.parseStringIndex(stringIndex.obj);
  18606. cff.topDict = topDict;
  18607. cff.globalSubrIndex = globalSubrIndex.obj;
  18608. this.parsePrivateDict(cff.topDict);
  18609. cff.isCIDFont = topDict.hasName('ROS');
  18610. var charStringOffset = topDict.getByName('CharStrings');
  18611. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18612. cff.charStrings = charStringsAndSeacs.charStrings;
  18613. cff.seacs = charStringsAndSeacs.seacs;
  18614. cff.widths = charStringsAndSeacs.widths;
  18615. var fontMatrix = topDict.getByName('FontMatrix');
  18616. if (fontMatrix) {
  18617. properties.fontMatrix = fontMatrix;
  18618. }
  18619. var fontBBox = topDict.getByName('FontBBox');
  18620. if (fontBBox) {
  18621. // adjusting ascent/descent
  18622. properties.ascent = fontBBox[3];
  18623. properties.descent = fontBBox[1];
  18624. properties.ascentScaled = true;
  18625. }
  18626. var charset, encoding;
  18627. if (cff.isCIDFont) {
  18628. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18629. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18630. var dictRaw = fdArrayIndex.get(i);
  18631. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18632. cff.strings);
  18633. this.parsePrivateDict(fontDict);
  18634. cff.fdArray.push(fontDict);
  18635. }
  18636. // cid fonts don't have an encoding
  18637. encoding = null;
  18638. charset = this.parseCharsets(topDict.getByName('charset'),
  18639. cff.charStrings.count, cff.strings, true);
  18640. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18641. cff.charStrings.count);
  18642. } else {
  18643. charset = this.parseCharsets(topDict.getByName('charset'),
  18644. cff.charStrings.count, cff.strings, false);
  18645. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18646. properties,
  18647. cff.strings, charset.charset);
  18648. }
  18649. cff.charset = charset;
  18650. cff.encoding = encoding;
  18651. return cff;
  18652. },
  18653. parseHeader: function CFFParser_parseHeader() {
  18654. var bytes = this.bytes;
  18655. var bytesLength = bytes.length;
  18656. var offset = 0;
  18657. // Prevent an infinite loop, by checking that the offset is within the
  18658. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18659. while (offset < bytesLength && bytes[offset] !== 1) {
  18660. ++offset;
  18661. }
  18662. if (offset >= bytesLength) {
  18663. error('Invalid CFF header');
  18664. } else if (offset !== 0) {
  18665. info('cff data is shifted');
  18666. bytes = bytes.subarray(offset);
  18667. this.bytes = bytes;
  18668. }
  18669. var major = bytes[0];
  18670. var minor = bytes[1];
  18671. var hdrSize = bytes[2];
  18672. var offSize = bytes[3];
  18673. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18674. return { obj: header, endPos: hdrSize };
  18675. },
  18676. parseDict: function CFFParser_parseDict(dict) {
  18677. var pos = 0;
  18678. function parseOperand() {
  18679. var value = dict[pos++];
  18680. if (value === 30) {
  18681. return parseFloatOperand(pos);
  18682. } else if (value === 28) {
  18683. value = dict[pos++];
  18684. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18685. return value;
  18686. } else if (value === 29) {
  18687. value = dict[pos++];
  18688. value = (value << 8) | dict[pos++];
  18689. value = (value << 8) | dict[pos++];
  18690. value = (value << 8) | dict[pos++];
  18691. return value;
  18692. } else if (value >= 32 && value <= 246) {
  18693. return value - 139;
  18694. } else if (value >= 247 && value <= 250) {
  18695. return ((value - 247) * 256) + dict[pos++] + 108;
  18696. } else if (value >= 251 && value <= 254) {
  18697. return -((value - 251) * 256) - dict[pos++] - 108;
  18698. } else {
  18699. error('255 is not a valid DICT command');
  18700. }
  18701. return -1;
  18702. }
  18703. function parseFloatOperand() {
  18704. var str = '';
  18705. var eof = 15;
  18706. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18707. '9', '.', 'E', 'E-', null, '-'];
  18708. var length = dict.length;
  18709. while (pos < length) {
  18710. var b = dict[pos++];
  18711. var b1 = b >> 4;
  18712. var b2 = b & 15;
  18713. if (b1 === eof) {
  18714. break;
  18715. }
  18716. str += lookup[b1];
  18717. if (b2 === eof) {
  18718. break;
  18719. }
  18720. str += lookup[b2];
  18721. }
  18722. return parseFloat(str);
  18723. }
  18724. var operands = [];
  18725. var entries = [];
  18726. pos = 0;
  18727. var end = dict.length;
  18728. while (pos < end) {
  18729. var b = dict[pos];
  18730. if (b <= 21) {
  18731. if (b === 12) {
  18732. b = (b << 8) | dict[++pos];
  18733. }
  18734. entries.push([b, operands]);
  18735. operands = [];
  18736. ++pos;
  18737. } else {
  18738. operands.push(parseOperand());
  18739. }
  18740. }
  18741. return entries;
  18742. },
  18743. parseIndex: function CFFParser_parseIndex(pos) {
  18744. var cffIndex = new CFFIndex();
  18745. var bytes = this.bytes;
  18746. var count = (bytes[pos++] << 8) | bytes[pos++];
  18747. var offsets = [];
  18748. var end = pos;
  18749. var i, ii;
  18750. if (count !== 0) {
  18751. var offsetSize = bytes[pos++];
  18752. // add 1 for offset to determine size of last object
  18753. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18754. for (i = 0, ii = count + 1; i < ii; ++i) {
  18755. var offset = 0;
  18756. for (var j = 0; j < offsetSize; ++j) {
  18757. offset <<= 8;
  18758. offset += bytes[pos++];
  18759. }
  18760. offsets.push(startPos + offset);
  18761. }
  18762. end = offsets[count];
  18763. }
  18764. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18765. var offsetStart = offsets[i];
  18766. var offsetEnd = offsets[i + 1];
  18767. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18768. }
  18769. return {obj: cffIndex, endPos: end};
  18770. },
  18771. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18772. var names = [];
  18773. for (var i = 0, ii = index.count; i < ii; ++i) {
  18774. var name = index.get(i);
  18775. // OTS doesn't allow names to be over 127 characters.
  18776. var length = Math.min(name.length, 127);
  18777. var data = [];
  18778. // OTS also only permits certain characters in the name.
  18779. for (var j = 0; j < length; ++j) {
  18780. var c = name[j];
  18781. if (j === 0 && c === 0) {
  18782. data[j] = c;
  18783. continue;
  18784. }
  18785. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18786. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18787. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18788. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18789. data[j] = 95;
  18790. continue;
  18791. }
  18792. data[j] = c;
  18793. }
  18794. names.push(bytesToString(data));
  18795. }
  18796. return names;
  18797. },
  18798. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18799. var strings = new CFFStrings();
  18800. for (var i = 0, ii = index.count; i < ii; ++i) {
  18801. var data = index.get(i);
  18802. strings.add(bytesToString(data));
  18803. }
  18804. return strings;
  18805. },
  18806. createDict: function CFFParser_createDict(Type, dict, strings) {
  18807. var cffDict = new Type(strings);
  18808. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18809. var pair = dict[i];
  18810. var key = pair[0];
  18811. var value = pair[1];
  18812. cffDict.setByKey(key, value);
  18813. }
  18814. return cffDict;
  18815. },
  18816. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18817. var charStrings = this.parseIndex(charStringOffset).obj;
  18818. var seacs = [];
  18819. var widths = [];
  18820. var count = charStrings.count;
  18821. for (var i = 0; i < count; i++) {
  18822. var charstring = charStrings.get(i);
  18823. var stackSize = 0;
  18824. var stack = [];
  18825. var undefStack = true;
  18826. var hints = 0;
  18827. var valid = true;
  18828. var data = charstring;
  18829. var length = data.length;
  18830. var firstStackClearing = true;
  18831. for (var j = 0; j < length;) {
  18832. var value = data[j++];
  18833. var validationCommand = null;
  18834. if (value === 12) {
  18835. var q = data[j++];
  18836. if (q === 0) {
  18837. // The CFF specification state that the 'dotsection' command
  18838. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18839. // charstrings processors should support them. Unfortunately
  18840. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18841. // is replaced by a useless (0, hmoveto).
  18842. data[j - 2] = 139;
  18843. data[j - 1] = 22;
  18844. stackSize = 0;
  18845. } else {
  18846. validationCommand = CharstringValidationData12[q];
  18847. }
  18848. } else if (value === 28) { // number (16 bit)
  18849. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18850. j += 2;
  18851. stackSize++;
  18852. } else if (value === 14) {
  18853. if (stackSize >= 4) {
  18854. stackSize -= 4;
  18855. if (SEAC_ANALYSIS_ENABLED) {
  18856. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18857. valid = false;
  18858. }
  18859. }
  18860. validationCommand = CharstringValidationData[value];
  18861. } else if (value >= 32 && value <= 246) { // number
  18862. stack[stackSize] = value - 139;
  18863. stackSize++;
  18864. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18865. stack[stackSize] = (value < 251 ?
  18866. ((value - 247) << 8) + data[j] + 108 :
  18867. -((value - 251) << 8) - data[j] - 108);
  18868. j++;
  18869. stackSize++;
  18870. } else if (value === 255) { // number (32 bit)
  18871. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18872. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18873. j += 4;
  18874. stackSize++;
  18875. } else if (value === 19 || value === 20) {
  18876. hints += stackSize >> 1;
  18877. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18878. stackSize %= 2;
  18879. validationCommand = CharstringValidationData[value];
  18880. } else {
  18881. validationCommand = CharstringValidationData[value];
  18882. }
  18883. if (validationCommand) {
  18884. if (validationCommand.stem) {
  18885. hints += stackSize >> 1;
  18886. }
  18887. if ('min' in validationCommand) {
  18888. if (!undefStack && stackSize < validationCommand.min) {
  18889. warn('Not enough parameters for ' + validationCommand.id +
  18890. '; actual: ' + stackSize +
  18891. ', expected: ' + validationCommand.min);
  18892. valid = false;
  18893. break;
  18894. }
  18895. }
  18896. if (firstStackClearing && validationCommand.stackClearing) {
  18897. firstStackClearing = false;
  18898. // the optional character width can be found before the first
  18899. // stack-clearing command arguments
  18900. stackSize -= validationCommand.min;
  18901. if (stackSize >= 2 && validationCommand.stem) {
  18902. // there are even amount of arguments for stem commands
  18903. stackSize %= 2;
  18904. } else if (stackSize > 1) {
  18905. warn('Found too many parameters for stack-clearing command');
  18906. }
  18907. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18908. widths[i] = stack[stackSize - 1];
  18909. }
  18910. }
  18911. if ('stackDelta' in validationCommand) {
  18912. if ('stackFn' in validationCommand) {
  18913. validationCommand.stackFn(stack, stackSize);
  18914. }
  18915. stackSize += validationCommand.stackDelta;
  18916. } else if (validationCommand.stackClearing) {
  18917. stackSize = 0;
  18918. } else if (validationCommand.resetStack) {
  18919. stackSize = 0;
  18920. undefStack = false;
  18921. } else if (validationCommand.undefStack) {
  18922. stackSize = 0;
  18923. undefStack = true;
  18924. firstStackClearing = false;
  18925. }
  18926. }
  18927. }
  18928. if (!valid) {
  18929. // resetting invalid charstring to single 'endchar'
  18930. charStrings.set(i, new Uint8Array([14]));
  18931. }
  18932. }
  18933. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18934. },
  18935. emptyPrivateDictionary:
  18936. function CFFParser_emptyPrivateDictionary(parentDict) {
  18937. var privateDict = this.createDict(CFFPrivateDict, [],
  18938. parentDict.strings);
  18939. parentDict.setByKey(18, [0, 0]);
  18940. parentDict.privateDict = privateDict;
  18941. },
  18942. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18943. // no private dict, do nothing
  18944. if (!parentDict.hasName('Private')) {
  18945. this.emptyPrivateDictionary(parentDict);
  18946. return;
  18947. }
  18948. var privateOffset = parentDict.getByName('Private');
  18949. // make sure the params are formatted correctly
  18950. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18951. parentDict.removeByName('Private');
  18952. return;
  18953. }
  18954. var size = privateOffset[0];
  18955. var offset = privateOffset[1];
  18956. // remove empty dicts or ones that refer to invalid location
  18957. if (size === 0 || offset >= this.bytes.length) {
  18958. this.emptyPrivateDictionary(parentDict);
  18959. return;
  18960. }
  18961. var privateDictEnd = offset + size;
  18962. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18963. var dict = this.parseDict(dictData);
  18964. var privateDict = this.createDict(CFFPrivateDict, dict,
  18965. parentDict.strings);
  18966. parentDict.privateDict = privateDict;
  18967. // Parse the Subrs index also since it's relative to the private dict.
  18968. if (!privateDict.getByName('Subrs')) {
  18969. return;
  18970. }
  18971. var subrsOffset = privateDict.getByName('Subrs');
  18972. var relativeOffset = offset + subrsOffset;
  18973. // Validate the offset.
  18974. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18975. this.emptyPrivateDictionary(parentDict);
  18976. return;
  18977. }
  18978. var subrsIndex = this.parseIndex(relativeOffset);
  18979. privateDict.subrsIndex = subrsIndex.obj;
  18980. },
  18981. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18982. if (pos === 0) {
  18983. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18984. ISOAdobeCharset);
  18985. } else if (pos === 1) {
  18986. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18987. ExpertCharset);
  18988. } else if (pos === 2) {
  18989. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18990. ExpertSubsetCharset);
  18991. }
  18992. var bytes = this.bytes;
  18993. var start = pos;
  18994. var format = bytes[pos++];
  18995. var charset = ['.notdef'];
  18996. var id, count, i;
  18997. // subtract 1 for the .notdef glyph
  18998. length -= 1;
  18999. switch (format) {
  19000. case 0:
  19001. for (i = 0; i < length; i++) {
  19002. id = (bytes[pos++] << 8) | bytes[pos++];
  19003. charset.push(cid ? id : strings.get(id));
  19004. }
  19005. break;
  19006. case 1:
  19007. while (charset.length <= length) {
  19008. id = (bytes[pos++] << 8) | bytes[pos++];
  19009. count = bytes[pos++];
  19010. for (i = 0; i <= count; i++) {
  19011. charset.push(cid ? id++ : strings.get(id++));
  19012. }
  19013. }
  19014. break;
  19015. case 2:
  19016. while (charset.length <= length) {
  19017. id = (bytes[pos++] << 8) | bytes[pos++];
  19018. count = (bytes[pos++] << 8) | bytes[pos++];
  19019. for (i = 0; i <= count; i++) {
  19020. charset.push(cid ? id++ : strings.get(id++));
  19021. }
  19022. }
  19023. break;
  19024. default:
  19025. error('Unknown charset format');
  19026. }
  19027. // Raw won't be needed if we actually compile the charset.
  19028. var end = pos;
  19029. var raw = bytes.subarray(start, end);
  19030. return new CFFCharset(false, format, charset, raw);
  19031. },
  19032. parseEncoding: function CFFParser_parseEncoding(pos,
  19033. properties,
  19034. strings,
  19035. charset) {
  19036. var encoding = {};
  19037. var bytes = this.bytes;
  19038. var predefined = false;
  19039. var hasSupplement = false;
  19040. var format, i, ii;
  19041. var raw = null;
  19042. function readSupplement() {
  19043. var supplementsCount = bytes[pos++];
  19044. for (i = 0; i < supplementsCount; i++) {
  19045. var code = bytes[pos++];
  19046. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  19047. encoding[code] = charset.indexOf(strings.get(sid));
  19048. }
  19049. }
  19050. if (pos === 0 || pos === 1) {
  19051. predefined = true;
  19052. format = pos;
  19053. var baseEncoding = pos ? Encodings.ExpertEncoding :
  19054. Encodings.StandardEncoding;
  19055. for (i = 0, ii = charset.length; i < ii; i++) {
  19056. var index = baseEncoding.indexOf(charset[i]);
  19057. if (index !== -1) {
  19058. encoding[index] = i;
  19059. }
  19060. }
  19061. } else {
  19062. var dataStart = pos;
  19063. format = bytes[pos++];
  19064. switch (format & 0x7f) {
  19065. case 0:
  19066. var glyphsCount = bytes[pos++];
  19067. for (i = 1; i <= glyphsCount; i++) {
  19068. encoding[bytes[pos++]] = i;
  19069. }
  19070. break;
  19071. case 1:
  19072. var rangesCount = bytes[pos++];
  19073. var gid = 1;
  19074. for (i = 0; i < rangesCount; i++) {
  19075. var start = bytes[pos++];
  19076. var left = bytes[pos++];
  19077. for (var j = start; j <= start + left; j++) {
  19078. encoding[j] = gid++;
  19079. }
  19080. }
  19081. break;
  19082. default:
  19083. error('Unknow encoding format: ' + format + ' in CFF');
  19084. break;
  19085. }
  19086. var dataEnd = pos;
  19087. if (format & 0x80) {
  19088. // The font sanitizer does not support CFF encoding with a
  19089. // supplement, since the encoding is not really used to map
  19090. // between gid to glyph, let's overwrite what is declared in
  19091. // the top dictionary to let the sanitizer think the font use
  19092. // StandardEncoding, that's a lie but that's ok.
  19093. bytes[dataStart] &= 0x7f;
  19094. readSupplement();
  19095. hasSupplement = true;
  19096. }
  19097. raw = bytes.subarray(dataStart, dataEnd);
  19098. }
  19099. format = format & 0x7f;
  19100. return new CFFEncoding(predefined, format, encoding, raw);
  19101. },
  19102. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19103. var start = pos;
  19104. var bytes = this.bytes;
  19105. var format = bytes[pos++];
  19106. var fdSelect = [];
  19107. var i;
  19108. switch (format) {
  19109. case 0:
  19110. for (i = 0; i < length; ++i) {
  19111. var id = bytes[pos++];
  19112. fdSelect.push(id);
  19113. }
  19114. break;
  19115. case 3:
  19116. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19117. for (i = 0; i < rangesCount; ++i) {
  19118. var first = (bytes[pos++] << 8) | bytes[pos++];
  19119. var fdIndex = bytes[pos++];
  19120. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19121. for (var j = first; j < next; ++j) {
  19122. fdSelect.push(fdIndex);
  19123. }
  19124. }
  19125. // Advance past the sentinel(next).
  19126. pos += 2;
  19127. break;
  19128. default:
  19129. error('Unknown fdselect format ' + format);
  19130. break;
  19131. }
  19132. var end = pos;
  19133. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19134. }
  19135. };
  19136. return CFFParser;
  19137. })();
  19138. // Compact Font Format
  19139. var CFF = (function CFFClosure() {
  19140. function CFF() {
  19141. this.header = null;
  19142. this.names = [];
  19143. this.topDict = null;
  19144. this.strings = new CFFStrings();
  19145. this.globalSubrIndex = null;
  19146. // The following could really be per font, but since we only have one font
  19147. // store them here.
  19148. this.encoding = null;
  19149. this.charset = null;
  19150. this.charStrings = null;
  19151. this.fdArray = [];
  19152. this.fdSelect = null;
  19153. this.isCIDFont = false;
  19154. }
  19155. return CFF;
  19156. })();
  19157. var CFFHeader = (function CFFHeaderClosure() {
  19158. function CFFHeader(major, minor, hdrSize, offSize) {
  19159. this.major = major;
  19160. this.minor = minor;
  19161. this.hdrSize = hdrSize;
  19162. this.offSize = offSize;
  19163. }
  19164. return CFFHeader;
  19165. })();
  19166. var CFFStrings = (function CFFStringsClosure() {
  19167. function CFFStrings() {
  19168. this.strings = [];
  19169. }
  19170. CFFStrings.prototype = {
  19171. get: function CFFStrings_get(index) {
  19172. if (index >= 0 && index <= 390) {
  19173. return CFFStandardStrings[index];
  19174. }
  19175. if (index - 391 <= this.strings.length) {
  19176. return this.strings[index - 391];
  19177. }
  19178. return CFFStandardStrings[0];
  19179. },
  19180. add: function CFFStrings_add(value) {
  19181. this.strings.push(value);
  19182. },
  19183. get count() {
  19184. return this.strings.length;
  19185. }
  19186. };
  19187. return CFFStrings;
  19188. })();
  19189. var CFFIndex = (function CFFIndexClosure() {
  19190. function CFFIndex() {
  19191. this.objects = [];
  19192. this.length = 0;
  19193. }
  19194. CFFIndex.prototype = {
  19195. add: function CFFIndex_add(data) {
  19196. this.length += data.length;
  19197. this.objects.push(data);
  19198. },
  19199. set: function CFFIndex_set(index, data) {
  19200. this.length += data.length - this.objects[index].length;
  19201. this.objects[index] = data;
  19202. },
  19203. get: function CFFIndex_get(index) {
  19204. return this.objects[index];
  19205. },
  19206. get count() {
  19207. return this.objects.length;
  19208. }
  19209. };
  19210. return CFFIndex;
  19211. })();
  19212. var CFFDict = (function CFFDictClosure() {
  19213. function CFFDict(tables, strings) {
  19214. this.keyToNameMap = tables.keyToNameMap;
  19215. this.nameToKeyMap = tables.nameToKeyMap;
  19216. this.defaults = tables.defaults;
  19217. this.types = tables.types;
  19218. this.opcodes = tables.opcodes;
  19219. this.order = tables.order;
  19220. this.strings = strings;
  19221. this.values = {};
  19222. }
  19223. CFFDict.prototype = {
  19224. // value should always be an array
  19225. setByKey: function CFFDict_setByKey(key, value) {
  19226. if (!(key in this.keyToNameMap)) {
  19227. return false;
  19228. }
  19229. // ignore empty values
  19230. if (value.length === 0) {
  19231. return true;
  19232. }
  19233. var type = this.types[key];
  19234. // remove the array wrapping these types of values
  19235. if (type === 'num' || type === 'sid' || type === 'offset') {
  19236. value = value[0];
  19237. }
  19238. this.values[key] = value;
  19239. return true;
  19240. },
  19241. setByName: function CFFDict_setByName(name, value) {
  19242. if (!(name in this.nameToKeyMap)) {
  19243. error('Invalid dictionary name "' + name + '"');
  19244. }
  19245. this.values[this.nameToKeyMap[name]] = value;
  19246. },
  19247. hasName: function CFFDict_hasName(name) {
  19248. return this.nameToKeyMap[name] in this.values;
  19249. },
  19250. getByName: function CFFDict_getByName(name) {
  19251. if (!(name in this.nameToKeyMap)) {
  19252. error('Invalid dictionary name "' + name + '"');
  19253. }
  19254. var key = this.nameToKeyMap[name];
  19255. if (!(key in this.values)) {
  19256. return this.defaults[key];
  19257. }
  19258. return this.values[key];
  19259. },
  19260. removeByName: function CFFDict_removeByName(name) {
  19261. delete this.values[this.nameToKeyMap[name]];
  19262. }
  19263. };
  19264. CFFDict.createTables = function CFFDict_createTables(layout) {
  19265. var tables = {
  19266. keyToNameMap: {},
  19267. nameToKeyMap: {},
  19268. defaults: {},
  19269. types: {},
  19270. opcodes: {},
  19271. order: []
  19272. };
  19273. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19274. var entry = layout[i];
  19275. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19276. tables.keyToNameMap[key] = entry[1];
  19277. tables.nameToKeyMap[entry[1]] = key;
  19278. tables.types[key] = entry[2];
  19279. tables.defaults[key] = entry[3];
  19280. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19281. tables.order.push(key);
  19282. }
  19283. return tables;
  19284. };
  19285. return CFFDict;
  19286. })();
  19287. var CFFTopDict = (function CFFTopDictClosure() {
  19288. var layout = [
  19289. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19290. [[12, 20], 'SyntheticBase', 'num', null],
  19291. [0, 'version', 'sid', null],
  19292. [1, 'Notice', 'sid', null],
  19293. [[12, 0], 'Copyright', 'sid', null],
  19294. [2, 'FullName', 'sid', null],
  19295. [3, 'FamilyName', 'sid', null],
  19296. [4, 'Weight', 'sid', null],
  19297. [[12, 1], 'isFixedPitch', 'num', 0],
  19298. [[12, 2], 'ItalicAngle', 'num', 0],
  19299. [[12, 3], 'UnderlinePosition', 'num', -100],
  19300. [[12, 4], 'UnderlineThickness', 'num', 50],
  19301. [[12, 5], 'PaintType', 'num', 0],
  19302. [[12, 6], 'CharstringType', 'num', 2],
  19303. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19304. [0.001, 0, 0, 0.001, 0, 0]],
  19305. [13, 'UniqueID', 'num', null],
  19306. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19307. [[12, 8], 'StrokeWidth', 'num', 0],
  19308. [14, 'XUID', 'array', null],
  19309. [15, 'charset', 'offset', 0],
  19310. [16, 'Encoding', 'offset', 0],
  19311. [17, 'CharStrings', 'offset', 0],
  19312. [18, 'Private', ['offset', 'offset'], null],
  19313. [[12, 21], 'PostScript', 'sid', null],
  19314. [[12, 22], 'BaseFontName', 'sid', null],
  19315. [[12, 23], 'BaseFontBlend', 'delta', null],
  19316. [[12, 31], 'CIDFontVersion', 'num', 0],
  19317. [[12, 32], 'CIDFontRevision', 'num', 0],
  19318. [[12, 33], 'CIDFontType', 'num', 0],
  19319. [[12, 34], 'CIDCount', 'num', 8720],
  19320. [[12, 35], 'UIDBase', 'num', null],
  19321. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19322. // before FDArray.
  19323. [[12, 37], 'FDSelect', 'offset', null],
  19324. [[12, 36], 'FDArray', 'offset', null],
  19325. [[12, 38], 'FontName', 'sid', null]
  19326. ];
  19327. var tables = null;
  19328. function CFFTopDict(strings) {
  19329. if (tables === null) {
  19330. tables = CFFDict.createTables(layout);
  19331. }
  19332. CFFDict.call(this, tables, strings);
  19333. this.privateDict = null;
  19334. }
  19335. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19336. return CFFTopDict;
  19337. })();
  19338. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19339. var layout = [
  19340. [6, 'BlueValues', 'delta', null],
  19341. [7, 'OtherBlues', 'delta', null],
  19342. [8, 'FamilyBlues', 'delta', null],
  19343. [9, 'FamilyOtherBlues', 'delta', null],
  19344. [[12, 9], 'BlueScale', 'num', 0.039625],
  19345. [[12, 10], 'BlueShift', 'num', 7],
  19346. [[12, 11], 'BlueFuzz', 'num', 1],
  19347. [10, 'StdHW', 'num', null],
  19348. [11, 'StdVW', 'num', null],
  19349. [[12, 12], 'StemSnapH', 'delta', null],
  19350. [[12, 13], 'StemSnapV', 'delta', null],
  19351. [[12, 14], 'ForceBold', 'num', 0],
  19352. [[12, 17], 'LanguageGroup', 'num', 0],
  19353. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19354. [[12, 19], 'initialRandomSeed', 'num', 0],
  19355. [20, 'defaultWidthX', 'num', 0],
  19356. [21, 'nominalWidthX', 'num', 0],
  19357. [19, 'Subrs', 'offset', null]
  19358. ];
  19359. var tables = null;
  19360. function CFFPrivateDict(strings) {
  19361. if (tables === null) {
  19362. tables = CFFDict.createTables(layout);
  19363. }
  19364. CFFDict.call(this, tables, strings);
  19365. this.subrsIndex = null;
  19366. }
  19367. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19368. return CFFPrivateDict;
  19369. })();
  19370. var CFFCharsetPredefinedTypes = {
  19371. ISO_ADOBE: 0,
  19372. EXPERT: 1,
  19373. EXPERT_SUBSET: 2
  19374. };
  19375. var CFFCharset = (function CFFCharsetClosure() {
  19376. function CFFCharset(predefined, format, charset, raw) {
  19377. this.predefined = predefined;
  19378. this.format = format;
  19379. this.charset = charset;
  19380. this.raw = raw;
  19381. }
  19382. return CFFCharset;
  19383. })();
  19384. var CFFEncoding = (function CFFEncodingClosure() {
  19385. function CFFEncoding(predefined, format, encoding, raw) {
  19386. this.predefined = predefined;
  19387. this.format = format;
  19388. this.encoding = encoding;
  19389. this.raw = raw;
  19390. }
  19391. return CFFEncoding;
  19392. })();
  19393. var CFFFDSelect = (function CFFFDSelectClosure() {
  19394. function CFFFDSelect(fdSelect, raw) {
  19395. this.fdSelect = fdSelect;
  19396. this.raw = raw;
  19397. }
  19398. return CFFFDSelect;
  19399. })();
  19400. // Helper class to keep track of where an offset is within the data and helps
  19401. // filling in that offset once it's known.
  19402. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19403. function CFFOffsetTracker() {
  19404. this.offsets = {};
  19405. }
  19406. CFFOffsetTracker.prototype = {
  19407. isTracking: function CFFOffsetTracker_isTracking(key) {
  19408. return key in this.offsets;
  19409. },
  19410. track: function CFFOffsetTracker_track(key, location) {
  19411. if (key in this.offsets) {
  19412. error('Already tracking location of ' + key);
  19413. }
  19414. this.offsets[key] = location;
  19415. },
  19416. offset: function CFFOffsetTracker_offset(value) {
  19417. for (var key in this.offsets) {
  19418. this.offsets[key] += value;
  19419. }
  19420. },
  19421. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19422. values,
  19423. output) {
  19424. if (!(key in this.offsets)) {
  19425. error('Not tracking location of ' + key);
  19426. }
  19427. var data = output.data;
  19428. var dataOffset = this.offsets[key];
  19429. var size = 5;
  19430. for (var i = 0, ii = values.length; i < ii; ++i) {
  19431. var offset0 = i * size + dataOffset;
  19432. var offset1 = offset0 + 1;
  19433. var offset2 = offset0 + 2;
  19434. var offset3 = offset0 + 3;
  19435. var offset4 = offset0 + 4;
  19436. // It's easy to screw up offsets so perform this sanity check.
  19437. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19438. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19439. error('writing to an offset that is not empty');
  19440. }
  19441. var value = values[i];
  19442. data[offset0] = 0x1d;
  19443. data[offset1] = (value >> 24) & 0xFF;
  19444. data[offset2] = (value >> 16) & 0xFF;
  19445. data[offset3] = (value >> 8) & 0xFF;
  19446. data[offset4] = value & 0xFF;
  19447. }
  19448. }
  19449. };
  19450. return CFFOffsetTracker;
  19451. })();
  19452. // Takes a CFF and converts it to the binary representation.
  19453. var CFFCompiler = (function CFFCompilerClosure() {
  19454. function CFFCompiler(cff) {
  19455. this.cff = cff;
  19456. }
  19457. CFFCompiler.prototype = {
  19458. compile: function CFFCompiler_compile() {
  19459. var cff = this.cff;
  19460. var output = {
  19461. data: [],
  19462. length: 0,
  19463. add: function CFFCompiler_add(data) {
  19464. this.data = this.data.concat(data);
  19465. this.length = this.data.length;
  19466. }
  19467. };
  19468. // Compile the five entries that must be in order.
  19469. var header = this.compileHeader(cff.header);
  19470. output.add(header);
  19471. var nameIndex = this.compileNameIndex(cff.names);
  19472. output.add(nameIndex);
  19473. if (cff.isCIDFont) {
  19474. // The spec is unclear on how font matrices should relate to each other
  19475. // when there is one in the main top dict and the sub top dicts.
  19476. // Windows handles this differently than linux and osx so we have to
  19477. // normalize to work on all.
  19478. // Rules based off of some mailing list discussions:
  19479. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19480. // - If no main font matrix and there is a subfont matrix, use the
  19481. // subfont matrix.
  19482. // - If both have matrices, concat together.
  19483. // - If neither have matrices, use default.
  19484. // To make this work on all platforms we move the top matrix into each
  19485. // sub top dict and concat if necessary.
  19486. if (cff.topDict.hasName('FontMatrix')) {
  19487. var base = cff.topDict.getByName('FontMatrix');
  19488. cff.topDict.removeByName('FontMatrix');
  19489. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19490. var subDict = cff.fdArray[i];
  19491. var matrix = base.slice(0);
  19492. if (subDict.hasName('FontMatrix')) {
  19493. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19494. }
  19495. subDict.setByName('FontMatrix', matrix);
  19496. }
  19497. }
  19498. }
  19499. var compiled = this.compileTopDicts([cff.topDict],
  19500. output.length,
  19501. cff.isCIDFont);
  19502. output.add(compiled.output);
  19503. var topDictTracker = compiled.trackers[0];
  19504. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19505. output.add(stringIndex);
  19506. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19507. output.add(globalSubrIndex);
  19508. // Now start on the other entries that have no specfic order.
  19509. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19510. if (cff.encoding.predefined) {
  19511. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19512. output);
  19513. } else {
  19514. var encoding = this.compileEncoding(cff.encoding);
  19515. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19516. output.add(encoding);
  19517. }
  19518. }
  19519. if (cff.charset && cff.topDict.hasName('charset')) {
  19520. if (cff.charset.predefined) {
  19521. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19522. output);
  19523. } else {
  19524. var charset = this.compileCharset(cff.charset);
  19525. topDictTracker.setEntryLocation('charset', [output.length], output);
  19526. output.add(charset);
  19527. }
  19528. }
  19529. var charStrings = this.compileCharStrings(cff.charStrings);
  19530. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19531. output.add(charStrings);
  19532. if (cff.isCIDFont) {
  19533. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19534. // and linux don't seem to care.
  19535. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19536. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19537. output.add(fdSelect);
  19538. // It is unclear if the sub font dictionary can have CID related
  19539. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19540. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19541. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19542. output.add(compiled.output);
  19543. var fontDictTrackers = compiled.trackers;
  19544. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19545. }
  19546. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19547. // If the font data ends with INDEX whose object data is zero-length,
  19548. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19549. output.add([0]);
  19550. return output.data;
  19551. },
  19552. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19553. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19554. return this.encodeInteger(value);
  19555. } else {
  19556. return this.encodeFloat(value);
  19557. }
  19558. },
  19559. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19560. var value = num.toString();
  19561. // rounding inaccurate doubles
  19562. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19563. if (m) {
  19564. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19565. value = (Math.round(num * epsilon) / epsilon).toString();
  19566. }
  19567. var nibbles = '';
  19568. var i, ii;
  19569. for (i = 0, ii = value.length; i < ii; ++i) {
  19570. var a = value[i];
  19571. if (a === 'e') {
  19572. nibbles += value[++i] === '-' ? 'c' : 'b';
  19573. } else if (a === '.') {
  19574. nibbles += 'a';
  19575. } else if (a === '-') {
  19576. nibbles += 'e';
  19577. } else {
  19578. nibbles += a;
  19579. }
  19580. }
  19581. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19582. var out = [30];
  19583. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19584. out.push(parseInt(nibbles.substr(i, 2), 16));
  19585. }
  19586. return out;
  19587. },
  19588. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19589. var code;
  19590. if (value >= -107 && value <= 107) {
  19591. code = [value + 139];
  19592. } else if (value >= 108 && value <= 1131) {
  19593. value = [value - 108];
  19594. code = [(value >> 8) + 247, value & 0xFF];
  19595. } else if (value >= -1131 && value <= -108) {
  19596. value = -value - 108;
  19597. code = [(value >> 8) + 251, value & 0xFF];
  19598. } else if (value >= -32768 && value <= 32767) {
  19599. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19600. } else {
  19601. code = [0x1d,
  19602. (value >> 24) & 0xFF,
  19603. (value >> 16) & 0xFF,
  19604. (value >> 8) & 0xFF,
  19605. value & 0xFF];
  19606. }
  19607. return code;
  19608. },
  19609. compileHeader: function CFFCompiler_compileHeader(header) {
  19610. return [
  19611. header.major,
  19612. header.minor,
  19613. header.hdrSize,
  19614. header.offSize
  19615. ];
  19616. },
  19617. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19618. var nameIndex = new CFFIndex();
  19619. for (var i = 0, ii = names.length; i < ii; ++i) {
  19620. nameIndex.add(stringToBytes(names[i]));
  19621. }
  19622. return this.compileIndex(nameIndex);
  19623. },
  19624. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19625. length,
  19626. removeCidKeys) {
  19627. var fontDictTrackers = [];
  19628. var fdArrayIndex = new CFFIndex();
  19629. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19630. var fontDict = dicts[i];
  19631. if (removeCidKeys) {
  19632. fontDict.removeByName('CIDFontVersion');
  19633. fontDict.removeByName('CIDFontRevision');
  19634. fontDict.removeByName('CIDFontType');
  19635. fontDict.removeByName('CIDCount');
  19636. fontDict.removeByName('UIDBase');
  19637. }
  19638. var fontDictTracker = new CFFOffsetTracker();
  19639. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19640. fontDictTrackers.push(fontDictTracker);
  19641. fdArrayIndex.add(fontDictData);
  19642. fontDictTracker.offset(length);
  19643. }
  19644. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19645. return {
  19646. trackers: fontDictTrackers,
  19647. output: fdArrayIndex
  19648. };
  19649. },
  19650. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19651. trackers,
  19652. output) {
  19653. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19654. var fontDict = dicts[i];
  19655. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19656. 'There must be an private dictionary.');
  19657. var privateDict = fontDict.privateDict;
  19658. var privateDictTracker = new CFFOffsetTracker();
  19659. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19660. var outputLength = output.length;
  19661. privateDictTracker.offset(outputLength);
  19662. if (!privateDictData.length) {
  19663. // The private dictionary was empty, set the output length to zero to
  19664. // ensure the offset length isn't out of bounds in the eyes of the
  19665. // sanitizer.
  19666. outputLength = 0;
  19667. }
  19668. trackers[i].setEntryLocation('Private',
  19669. [privateDictData.length, outputLength],
  19670. output);
  19671. output.add(privateDictData);
  19672. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19673. var subrs = this.compileIndex(privateDict.subrsIndex);
  19674. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19675. output);
  19676. output.add(subrs);
  19677. }
  19678. }
  19679. },
  19680. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19681. var out = [];
  19682. // The dictionary keys must be in a certain order.
  19683. var order = dict.order;
  19684. for (var i = 0; i < order.length; ++i) {
  19685. var key = order[i];
  19686. if (!(key in dict.values)) {
  19687. continue;
  19688. }
  19689. var values = dict.values[key];
  19690. var types = dict.types[key];
  19691. if (!isArray(types)) {
  19692. types = [types];
  19693. }
  19694. if (!isArray(values)) {
  19695. values = [values];
  19696. }
  19697. // Remove any empty dict values.
  19698. if (values.length === 0) {
  19699. continue;
  19700. }
  19701. for (var j = 0, jj = types.length; j < jj; ++j) {
  19702. var type = types[j];
  19703. var value = values[j];
  19704. switch (type) {
  19705. case 'num':
  19706. case 'sid':
  19707. out = out.concat(this.encodeNumber(value));
  19708. break;
  19709. case 'offset':
  19710. // For offsets we just insert a 32bit integer so we don't have to
  19711. // deal with figuring out the length of the offset when it gets
  19712. // replaced later on by the compiler.
  19713. var name = dict.keyToNameMap[key];
  19714. // Some offsets have the offset and the length, so just record the
  19715. // position of the first one.
  19716. if (!offsetTracker.isTracking(name)) {
  19717. offsetTracker.track(name, out.length);
  19718. }
  19719. out = out.concat([0x1d, 0, 0, 0, 0]);
  19720. break;
  19721. case 'array':
  19722. case 'delta':
  19723. out = out.concat(this.encodeNumber(value));
  19724. for (var k = 1, kk = values.length; k < kk; ++k) {
  19725. out = out.concat(this.encodeNumber(values[k]));
  19726. }
  19727. break;
  19728. default:
  19729. error('Unknown data type of ' + type);
  19730. break;
  19731. }
  19732. }
  19733. out = out.concat(dict.opcodes[key]);
  19734. }
  19735. return out;
  19736. },
  19737. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19738. var stringIndex = new CFFIndex();
  19739. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19740. stringIndex.add(stringToBytes(strings[i]));
  19741. }
  19742. return this.compileIndex(stringIndex);
  19743. },
  19744. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19745. var globalSubrIndex = this.cff.globalSubrIndex;
  19746. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19747. },
  19748. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19749. return this.compileIndex(charStrings);
  19750. },
  19751. compileCharset: function CFFCompiler_compileCharset(charset) {
  19752. return this.compileTypedArray(charset.raw);
  19753. },
  19754. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19755. return this.compileTypedArray(encoding.raw);
  19756. },
  19757. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19758. return this.compileTypedArray(fdSelect);
  19759. },
  19760. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19761. var out = [];
  19762. for (var i = 0, ii = data.length; i < ii; ++i) {
  19763. out[i] = data[i];
  19764. }
  19765. return out;
  19766. },
  19767. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19768. trackers = trackers || [];
  19769. var objects = index.objects;
  19770. // First 2 bytes contains the number of objects contained into this index
  19771. var count = objects.length;
  19772. // If there is no object, just create an index. This technically
  19773. // should just be [0, 0] but OTS has an issue with that.
  19774. if (count === 0) {
  19775. return [0, 0, 0];
  19776. }
  19777. var data = [(count >> 8) & 0xFF, count & 0xff];
  19778. var lastOffset = 1, i;
  19779. for (i = 0; i < count; ++i) {
  19780. lastOffset += objects[i].length;
  19781. }
  19782. var offsetSize;
  19783. if (lastOffset < 0x100) {
  19784. offsetSize = 1;
  19785. } else if (lastOffset < 0x10000) {
  19786. offsetSize = 2;
  19787. } else if (lastOffset < 0x1000000) {
  19788. offsetSize = 3;
  19789. } else {
  19790. offsetSize = 4;
  19791. }
  19792. // Next byte contains the offset size use to reference object in the file
  19793. data.push(offsetSize);
  19794. // Add another offset after this one because we need a new offset
  19795. var relativeOffset = 1;
  19796. for (i = 0; i < count + 1; i++) {
  19797. if (offsetSize === 1) {
  19798. data.push(relativeOffset & 0xFF);
  19799. } else if (offsetSize === 2) {
  19800. data.push((relativeOffset >> 8) & 0xFF,
  19801. relativeOffset & 0xFF);
  19802. } else if (offsetSize === 3) {
  19803. data.push((relativeOffset >> 16) & 0xFF,
  19804. (relativeOffset >> 8) & 0xFF,
  19805. relativeOffset & 0xFF);
  19806. } else {
  19807. data.push((relativeOffset >>> 24) & 0xFF,
  19808. (relativeOffset >> 16) & 0xFF,
  19809. (relativeOffset >> 8) & 0xFF,
  19810. relativeOffset & 0xFF);
  19811. }
  19812. if (objects[i]) {
  19813. relativeOffset += objects[i].length;
  19814. }
  19815. }
  19816. for (i = 0; i < count; i++) {
  19817. // Notify the tracker where the object will be offset in the data.
  19818. if (trackers[i]) {
  19819. trackers[i].offset(data.length);
  19820. }
  19821. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19822. data.push(objects[i][j]);
  19823. }
  19824. }
  19825. return data;
  19826. }
  19827. };
  19828. return CFFCompiler;
  19829. })();
  19830. // Workaround for seac on Windows.
  19831. (function checkSeacSupport() {
  19832. if (/Windows/.test(navigator.userAgent)) {
  19833. SEAC_ANALYSIS_ENABLED = true;
  19834. }
  19835. })();
  19836. // Workaround for Private Use Area characters in Chrome on Windows
  19837. // http://code.google.com/p/chromium/issues/detail?id=122465
  19838. // https://github.com/mozilla/pdf.js/issues/1689
  19839. (function checkChromeWindows() {
  19840. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19841. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19842. }
  19843. })();
  19844. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19845. function getLong(data, offset) {
  19846. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19847. (data[offset + 2] << 8) | data[offset + 3];
  19848. }
  19849. function getUshort(data, offset) {
  19850. return (data[offset] << 8) | data[offset + 1];
  19851. }
  19852. function parseCmap(data, start, end) {
  19853. var offset = (getUshort(data, start + 2) === 1 ?
  19854. getLong(data, start + 8) : getLong(data, start + 16));
  19855. var format = getUshort(data, start + offset);
  19856. var length, ranges, p, i;
  19857. if (format === 4) {
  19858. length = getUshort(data, start + offset + 2);
  19859. var segCount = getUshort(data, start + offset + 6) >> 1;
  19860. p = start + offset + 14;
  19861. ranges = [];
  19862. for (i = 0; i < segCount; i++, p += 2) {
  19863. ranges[i] = {end: getUshort(data, p)};
  19864. }
  19865. p += 2;
  19866. for (i = 0; i < segCount; i++, p += 2) {
  19867. ranges[i].start = getUshort(data, p);
  19868. }
  19869. for (i = 0; i < segCount; i++, p += 2) {
  19870. ranges[i].idDelta = getUshort(data, p);
  19871. }
  19872. for (i = 0; i < segCount; i++, p += 2) {
  19873. var idOffset = getUshort(data, p);
  19874. if (idOffset === 0) {
  19875. continue;
  19876. }
  19877. ranges[i].ids = [];
  19878. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19879. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19880. idOffset += 2;
  19881. }
  19882. }
  19883. return ranges;
  19884. } else if (format === 12) {
  19885. length = getLong(data, start + offset + 4);
  19886. var groups = getLong(data, start + offset + 12);
  19887. p = start + offset + 16;
  19888. ranges = [];
  19889. for (i = 0; i < groups; i++) {
  19890. ranges.push({
  19891. start: getLong(data, p),
  19892. end: getLong(data, p + 4),
  19893. idDelta: getLong(data, p + 8) - getLong(data, p)
  19894. });
  19895. p += 12;
  19896. }
  19897. return ranges;
  19898. }
  19899. error('not supported cmap: ' + format);
  19900. }
  19901. function parseCff(data, start, end) {
  19902. var properties = {};
  19903. var parser = new CFFParser(new Stream(data, start, end - start),
  19904. properties);
  19905. var cff = parser.parse();
  19906. return {
  19907. glyphs: cff.charStrings.objects,
  19908. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19909. cff.topDict.privateDict.subrsIndex.objects),
  19910. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19911. };
  19912. }
  19913. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19914. var itemSize, itemDecode;
  19915. if (isGlyphLocationsLong) {
  19916. itemSize = 4;
  19917. itemDecode = function fontItemDecodeLong(data, offset) {
  19918. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19919. (data[offset + 2] << 8) | data[offset + 3];
  19920. };
  19921. } else {
  19922. itemSize = 2;
  19923. itemDecode = function fontItemDecode(data, offset) {
  19924. return (data[offset] << 9) | (data[offset + 1] << 1);
  19925. };
  19926. }
  19927. var glyphs = [];
  19928. var startOffset = itemDecode(loca, 0);
  19929. for (var j = itemSize; j < loca.length; j += itemSize) {
  19930. var endOffset = itemDecode(loca, j);
  19931. glyphs.push(glyf.subarray(startOffset, endOffset));
  19932. startOffset = endOffset;
  19933. }
  19934. return glyphs;
  19935. }
  19936. function lookupCmap(ranges, unicode) {
  19937. var code = unicode.charCodeAt(0);
  19938. var l = 0, r = ranges.length - 1;
  19939. while (l < r) {
  19940. var c = (l + r + 1) >> 1;
  19941. if (code < ranges[c].start) {
  19942. r = c - 1;
  19943. } else {
  19944. l = c;
  19945. }
  19946. }
  19947. if (ranges[l].start <= code && code <= ranges[l].end) {
  19948. return (ranges[l].idDelta + (ranges[l].ids ?
  19949. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19950. }
  19951. return 0;
  19952. }
  19953. function compileGlyf(code, js, font) {
  19954. function moveTo(x, y) {
  19955. js.push('c.moveTo(' + x + ',' + y + ');');
  19956. }
  19957. function lineTo(x, y) {
  19958. js.push('c.lineTo(' + x + ',' + y + ');');
  19959. }
  19960. function quadraticCurveTo(xa, ya, x, y) {
  19961. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19962. x + ',' + y + ');');
  19963. }
  19964. var i = 0;
  19965. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19966. var flags;
  19967. var x = 0, y = 0;
  19968. i += 10;
  19969. if (numberOfContours < 0) {
  19970. // composite glyph
  19971. do {
  19972. flags = (code[i] << 8) | code[i + 1];
  19973. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19974. i += 4;
  19975. var arg1, arg2;
  19976. if ((flags & 0x01)) {
  19977. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19978. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19979. i += 4;
  19980. } else {
  19981. arg1 = code[i++]; arg2 = code[i++];
  19982. }
  19983. if ((flags & 0x02)) {
  19984. x = arg1;
  19985. y = arg2;
  19986. } else {
  19987. x = 0; y = 0; // TODO "they are points" ?
  19988. }
  19989. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19990. if ((flags & 0x08)) {
  19991. scaleX =
  19992. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19993. i += 2;
  19994. } else if ((flags & 0x40)) {
  19995. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19996. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19997. i += 4;
  19998. } else if ((flags & 0x80)) {
  19999. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20000. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20001. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  20002. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  20003. i += 8;
  20004. }
  20005. var subglyph = font.glyphs[glyphIndex];
  20006. if (subglyph) {
  20007. js.push('c.save();');
  20008. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  20009. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  20010. compileGlyf(subglyph, js, font);
  20011. js.push('c.restore();');
  20012. }
  20013. } while ((flags & 0x20));
  20014. } else {
  20015. // simple glyph
  20016. var endPtsOfContours = [];
  20017. var j, jj;
  20018. for (j = 0; j < numberOfContours; j++) {
  20019. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  20020. i += 2;
  20021. }
  20022. var instructionLength = (code[i] << 8) | code[i + 1];
  20023. i += 2 + instructionLength; // skipping the instructions
  20024. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  20025. var points = [];
  20026. while (points.length < numberOfPoints) {
  20027. flags = code[i++];
  20028. var repeat = 1;
  20029. if ((flags & 0x08)) {
  20030. repeat += code[i++];
  20031. }
  20032. while (repeat-- > 0) {
  20033. points.push({flags: flags});
  20034. }
  20035. }
  20036. for (j = 0; j < numberOfPoints; j++) {
  20037. switch (points[j].flags & 0x12) {
  20038. case 0x00:
  20039. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20040. i += 2;
  20041. break;
  20042. case 0x02:
  20043. x -= code[i++];
  20044. break;
  20045. case 0x12:
  20046. x += code[i++];
  20047. break;
  20048. }
  20049. points[j].x = x;
  20050. }
  20051. for (j = 0; j < numberOfPoints; j++) {
  20052. switch (points[j].flags & 0x24) {
  20053. case 0x00:
  20054. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20055. i += 2;
  20056. break;
  20057. case 0x04:
  20058. y -= code[i++];
  20059. break;
  20060. case 0x24:
  20061. y += code[i++];
  20062. break;
  20063. }
  20064. points[j].y = y;
  20065. }
  20066. var startPoint = 0;
  20067. for (i = 0; i < numberOfContours; i++) {
  20068. var endPoint = endPtsOfContours[i];
  20069. // contours might have implicit points, which is located in the middle
  20070. // between two neighboring off-curve points
  20071. var contour = points.slice(startPoint, endPoint + 1);
  20072. if ((contour[0].flags & 1)) {
  20073. contour.push(contour[0]); // using start point at the contour end
  20074. } else if ((contour[contour.length - 1].flags & 1)) {
  20075. // first is off-curve point, trying to use one from the end
  20076. contour.unshift(contour[contour.length - 1]);
  20077. } else {
  20078. // start and end are off-curve points, creating implicit one
  20079. var p = {
  20080. flags: 1,
  20081. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20082. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20083. };
  20084. contour.unshift(p);
  20085. contour.push(p);
  20086. }
  20087. moveTo(contour[0].x, contour[0].y);
  20088. for (j = 1, jj = contour.length; j < jj; j++) {
  20089. if ((contour[j].flags & 1)) {
  20090. lineTo(contour[j].x, contour[j].y);
  20091. } else if ((contour[j + 1].flags & 1)){
  20092. quadraticCurveTo(contour[j].x, contour[j].y,
  20093. contour[j + 1].x, contour[j + 1].y);
  20094. j++;
  20095. } else {
  20096. quadraticCurveTo(contour[j].x, contour[j].y,
  20097. (contour[j].x + contour[j + 1].x) / 2,
  20098. (contour[j].y + contour[j + 1].y) / 2);
  20099. }
  20100. }
  20101. startPoint = endPoint + 1;
  20102. }
  20103. }
  20104. }
  20105. function compileCharString(code, js, font) {
  20106. var stack = [];
  20107. var x = 0, y = 0;
  20108. var stems = 0;
  20109. function moveTo(x, y) {
  20110. js.push('c.moveTo(' + x + ',' + y + ');');
  20111. }
  20112. function lineTo(x, y) {
  20113. js.push('c.lineTo(' + x + ',' + y + ');');
  20114. }
  20115. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20116. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  20117. x + ',' + y + ');');
  20118. }
  20119. function parse(code) {
  20120. var i = 0;
  20121. while (i < code.length) {
  20122. var stackClean = false;
  20123. var v = code[i++];
  20124. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20125. switch (v) {
  20126. case 1: // hstem
  20127. stems += stack.length >> 1;
  20128. stackClean = true;
  20129. break;
  20130. case 3: // vstem
  20131. stems += stack.length >> 1;
  20132. stackClean = true;
  20133. break;
  20134. case 4: // vmoveto
  20135. y += stack.pop();
  20136. moveTo(x, y);
  20137. stackClean = true;
  20138. break;
  20139. case 5: // rlineto
  20140. while (stack.length > 0) {
  20141. x += stack.shift();
  20142. y += stack.shift();
  20143. lineTo(x, y);
  20144. }
  20145. break;
  20146. case 6: // hlineto
  20147. while (stack.length > 0) {
  20148. x += stack.shift();
  20149. lineTo(x, y);
  20150. if (stack.length === 0) {
  20151. break;
  20152. }
  20153. y += stack.shift();
  20154. lineTo(x, y);
  20155. }
  20156. break;
  20157. case 7: // vlineto
  20158. while (stack.length > 0) {
  20159. y += stack.shift();
  20160. lineTo(x, y);
  20161. if (stack.length === 0) {
  20162. break;
  20163. }
  20164. x += stack.shift();
  20165. lineTo(x, y);
  20166. }
  20167. break;
  20168. case 8: // rrcurveto
  20169. while (stack.length > 0) {
  20170. xa = x + stack.shift(); ya = y + stack.shift();
  20171. xb = xa + stack.shift(); yb = ya + stack.shift();
  20172. x = xb + stack.shift(); y = yb + stack.shift();
  20173. bezierCurveTo(xa, ya, xb, yb, x, y);
  20174. }
  20175. break;
  20176. case 10: // callsubr
  20177. n = stack.pop() + font.subrsBias;
  20178. subrCode = font.subrs[n];
  20179. if (subrCode) {
  20180. parse(subrCode);
  20181. }
  20182. break;
  20183. case 11: // return
  20184. return;
  20185. case 12:
  20186. v = code[i++];
  20187. switch (v) {
  20188. case 34: // flex
  20189. xa = x + stack.shift();
  20190. xb = xa + stack.shift(); y1 = y + stack.shift();
  20191. x = xb + stack.shift();
  20192. bezierCurveTo(xa, y, xb, y1, x, y1);
  20193. xa = x + stack.shift();
  20194. xb = xa + stack.shift();
  20195. x = xb + stack.shift();
  20196. bezierCurveTo(xa, y1, xb, y, x, y);
  20197. break;
  20198. case 35: // flex
  20199. xa = x + stack.shift(); ya = y + stack.shift();
  20200. xb = xa + stack.shift(); yb = ya + stack.shift();
  20201. x = xb + stack.shift(); y = yb + stack.shift();
  20202. bezierCurveTo(xa, ya, xb, yb, x, y);
  20203. xa = x + stack.shift(); ya = y + stack.shift();
  20204. xb = xa + stack.shift(); yb = ya + stack.shift();
  20205. x = xb + stack.shift(); y = yb + stack.shift();
  20206. bezierCurveTo(xa, ya, xb, yb, x, y);
  20207. stack.pop(); // fd
  20208. break;
  20209. case 36: // hflex1
  20210. xa = x + stack.shift(); y1 = y + stack.shift();
  20211. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20212. x = xb + stack.shift();
  20213. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20214. xa = x + stack.shift();
  20215. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20216. x = xb + stack.shift();
  20217. bezierCurveTo(xa, y2, xb, y3, x, y);
  20218. break;
  20219. case 37: // flex1
  20220. var x0 = x, y0 = y;
  20221. xa = x + stack.shift(); ya = y + stack.shift();
  20222. xb = xa + stack.shift(); yb = ya + stack.shift();
  20223. x = xb + stack.shift(); y = yb + stack.shift();
  20224. bezierCurveTo(xa, ya, xb, yb, x, y);
  20225. xa = x + stack.shift(); ya = y + stack.shift();
  20226. xb = xa + stack.shift(); yb = ya + stack.shift();
  20227. x = xb; y = yb;
  20228. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20229. x += stack.shift();
  20230. } else {
  20231. y += stack.shift();
  20232. }
  20233. bezierCurveTo(xa, ya, xb, yb, x, y);
  20234. break;
  20235. default:
  20236. error('unknown operator: 12 ' + v);
  20237. }
  20238. break;
  20239. case 14: // endchar
  20240. if (stack.length >= 4) {
  20241. var achar = stack.pop();
  20242. var bchar = stack.pop();
  20243. y = stack.pop();
  20244. x = stack.pop();
  20245. js.push('c.save();');
  20246. js.push('c.translate('+ x + ',' + y + ');');
  20247. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20248. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20249. compileCharString(font.glyphs[gid], js, font);
  20250. js.push('c.restore();');
  20251. gid = lookupCmap(font.cmap, String.fromCharCode(
  20252. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20253. compileCharString(font.glyphs[gid], js, font);
  20254. }
  20255. return;
  20256. case 18: // hstemhm
  20257. stems += stack.length >> 1;
  20258. stackClean = true;
  20259. break;
  20260. case 19: // hintmask
  20261. stems += stack.length >> 1;
  20262. i += (stems + 7) >> 3;
  20263. stackClean = true;
  20264. break;
  20265. case 20: // cntrmask
  20266. stems += stack.length >> 1;
  20267. i += (stems + 7) >> 3;
  20268. stackClean = true;
  20269. break;
  20270. case 21: // rmoveto
  20271. y += stack.pop();
  20272. x += stack.pop();
  20273. moveTo(x, y);
  20274. stackClean = true;
  20275. break;
  20276. case 22: // hmoveto
  20277. x += stack.pop();
  20278. moveTo(x, y);
  20279. stackClean = true;
  20280. break;
  20281. case 23: // vstemhm
  20282. stems += stack.length >> 1;
  20283. stackClean = true;
  20284. break;
  20285. case 24: // rcurveline
  20286. while (stack.length > 2) {
  20287. xa = x + stack.shift(); ya = y + stack.shift();
  20288. xb = xa + stack.shift(); yb = ya + stack.shift();
  20289. x = xb + stack.shift(); y = yb + stack.shift();
  20290. bezierCurveTo(xa, ya, xb, yb, x, y);
  20291. }
  20292. x += stack.shift();
  20293. y += stack.shift();
  20294. lineTo(x, y);
  20295. break;
  20296. case 25: // rlinecurve
  20297. while (stack.length > 6) {
  20298. x += stack.shift();
  20299. y += stack.shift();
  20300. lineTo(x, y);
  20301. }
  20302. xa = x + stack.shift(); ya = y + stack.shift();
  20303. xb = xa + stack.shift(); yb = ya + stack.shift();
  20304. x = xb + stack.shift(); y = yb + stack.shift();
  20305. bezierCurveTo(xa, ya, xb, yb, x, y);
  20306. break;
  20307. case 26: // vvcurveto
  20308. if (stack.length % 2) {
  20309. x += stack.shift();
  20310. }
  20311. while (stack.length > 0) {
  20312. xa = x; ya = y + stack.shift();
  20313. xb = xa + stack.shift(); yb = ya + stack.shift();
  20314. x = xb; y = yb + stack.shift();
  20315. bezierCurveTo(xa, ya, xb, yb, x, y);
  20316. }
  20317. break;
  20318. case 27: // hhcurveto
  20319. if (stack.length % 2) {
  20320. y += stack.shift();
  20321. }
  20322. while (stack.length > 0) {
  20323. xa = x + stack.shift(); ya = y;
  20324. xb = xa + stack.shift(); yb = ya + stack.shift();
  20325. x = xb + stack.shift(); y = yb;
  20326. bezierCurveTo(xa, ya, xb, yb, x, y);
  20327. }
  20328. break;
  20329. case 28:
  20330. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20331. i += 2;
  20332. break;
  20333. case 29: // callgsubr
  20334. n = stack.pop() + font.gsubrsBias;
  20335. subrCode = font.gsubrs[n];
  20336. if (subrCode) {
  20337. parse(subrCode);
  20338. }
  20339. break;
  20340. case 30: // vhcurveto
  20341. while (stack.length > 0) {
  20342. xa = x; ya = y + stack.shift();
  20343. xb = xa + stack.shift(); yb = ya + stack.shift();
  20344. x = xb + stack.shift();
  20345. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20346. bezierCurveTo(xa, ya, xb, yb, x, y);
  20347. if (stack.length === 0) {
  20348. break;
  20349. }
  20350. xa = x + stack.shift(); ya = y;
  20351. xb = xa + stack.shift(); yb = ya + stack.shift();
  20352. y = yb + stack.shift();
  20353. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20354. bezierCurveTo(xa, ya, xb, yb, x, y);
  20355. }
  20356. break;
  20357. case 31: // hvcurveto
  20358. while (stack.length > 0) {
  20359. xa = x + stack.shift(); ya = y;
  20360. xb = xa + stack.shift(); yb = ya + stack.shift();
  20361. y = yb + stack.shift();
  20362. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20363. bezierCurveTo(xa, ya, xb, yb, x, y);
  20364. if (stack.length === 0) {
  20365. break;
  20366. }
  20367. xa = x; ya = y + stack.shift();
  20368. xb = xa + stack.shift(); yb = ya + stack.shift();
  20369. x = xb + stack.shift();
  20370. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20371. bezierCurveTo(xa, ya, xb, yb, x, y);
  20372. }
  20373. break;
  20374. default:
  20375. if (v < 32) {
  20376. error('unknown operator: ' + v);
  20377. }
  20378. if (v < 247) {
  20379. stack.push(v - 139);
  20380. } else if (v < 251) {
  20381. stack.push((v - 247) * 256 + code[i++] + 108);
  20382. } else if (v < 255) {
  20383. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20384. } else {
  20385. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20386. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20387. i += 4;
  20388. }
  20389. break;
  20390. }
  20391. if (stackClean) {
  20392. stack.length = 0;
  20393. }
  20394. }
  20395. }
  20396. parse(code);
  20397. }
  20398. var noop = '';
  20399. function CompiledFont(fontMatrix) {
  20400. this.compiledGlyphs = {};
  20401. this.fontMatrix = fontMatrix;
  20402. }
  20403. CompiledFont.prototype = {
  20404. getPathJs: function (unicode) {
  20405. var gid = lookupCmap(this.cmap, unicode);
  20406. var fn = this.compiledGlyphs[gid];
  20407. if (!fn) {
  20408. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20409. }
  20410. return fn;
  20411. },
  20412. compileGlyph: function (code) {
  20413. if (!code || code.length === 0 || code[0] === 14) {
  20414. return noop;
  20415. }
  20416. var js = [];
  20417. js.push('c.save();');
  20418. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20419. js.push('c.scale(size, -size);');
  20420. this.compileGlyphImpl(code, js);
  20421. js.push('c.restore();');
  20422. return js.join('\n');
  20423. },
  20424. compileGlyphImpl: function () {
  20425. error('Children classes should implement this.');
  20426. },
  20427. hasBuiltPath: function (unicode) {
  20428. var gid = lookupCmap(this.cmap, unicode);
  20429. return gid in this.compiledGlyphs;
  20430. }
  20431. };
  20432. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20433. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20434. CompiledFont.call(this, fontMatrix);
  20435. this.glyphs = glyphs;
  20436. this.cmap = cmap;
  20437. this.compiledGlyphs = [];
  20438. }
  20439. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20440. compileGlyphImpl: function (code, js) {
  20441. compileGlyf(code, js, this);
  20442. }
  20443. });
  20444. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20445. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20446. CompiledFont.call(this, fontMatrix);
  20447. this.glyphs = cffInfo.glyphs;
  20448. this.gsubrs = cffInfo.gsubrs || [];
  20449. this.subrs = cffInfo.subrs || [];
  20450. this.cmap = cmap;
  20451. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20452. this.compiledGlyphs = [];
  20453. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20454. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20455. this.subrsBias = (this.subrs.length < 1240 ?
  20456. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20457. }
  20458. Util.inherit(Type2Compiled, CompiledFont, {
  20459. compileGlyphImpl: function (code, js) {
  20460. compileCharString(code, js, this);
  20461. }
  20462. });
  20463. return {
  20464. create: function FontRendererFactory_create(font) {
  20465. var data = new Uint8Array(font.data);
  20466. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20467. var numTables = getUshort(data, 4);
  20468. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20469. var tag = bytesToString(data.subarray(p, p + 4));
  20470. var offset = getLong(data, p + 8);
  20471. var length = getLong(data, p + 12);
  20472. switch (tag) {
  20473. case 'cmap':
  20474. cmap = parseCmap(data, offset, offset + length);
  20475. break;
  20476. case 'glyf':
  20477. glyf = data.subarray(offset, offset + length);
  20478. break;
  20479. case 'loca':
  20480. loca = data.subarray(offset, offset + length);
  20481. break;
  20482. case 'head':
  20483. unitsPerEm = getUshort(data, offset + 18);
  20484. indexToLocFormat = getUshort(data, offset + 50);
  20485. break;
  20486. case 'CFF ':
  20487. cff = parseCff(data, offset, offset + length);
  20488. break;
  20489. }
  20490. }
  20491. if (glyf) {
  20492. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20493. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20494. return new TrueTypeCompiled(
  20495. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20496. } else {
  20497. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20498. }
  20499. }
  20500. };
  20501. })();
  20502. var GlyphsUnicode = {
  20503. A: 0x0041,
  20504. AE: 0x00C6,
  20505. AEacute: 0x01FC,
  20506. AEmacron: 0x01E2,
  20507. AEsmall: 0xF7E6,
  20508. Aacute: 0x00C1,
  20509. Aacutesmall: 0xF7E1,
  20510. Abreve: 0x0102,
  20511. Abreveacute: 0x1EAE,
  20512. Abrevecyrillic: 0x04D0,
  20513. Abrevedotbelow: 0x1EB6,
  20514. Abrevegrave: 0x1EB0,
  20515. Abrevehookabove: 0x1EB2,
  20516. Abrevetilde: 0x1EB4,
  20517. Acaron: 0x01CD,
  20518. Acircle: 0x24B6,
  20519. Acircumflex: 0x00C2,
  20520. Acircumflexacute: 0x1EA4,
  20521. Acircumflexdotbelow: 0x1EAC,
  20522. Acircumflexgrave: 0x1EA6,
  20523. Acircumflexhookabove: 0x1EA8,
  20524. Acircumflexsmall: 0xF7E2,
  20525. Acircumflextilde: 0x1EAA,
  20526. Acute: 0xF6C9,
  20527. Acutesmall: 0xF7B4,
  20528. Acyrillic: 0x0410,
  20529. Adblgrave: 0x0200,
  20530. Adieresis: 0x00C4,
  20531. Adieresiscyrillic: 0x04D2,
  20532. Adieresismacron: 0x01DE,
  20533. Adieresissmall: 0xF7E4,
  20534. Adotbelow: 0x1EA0,
  20535. Adotmacron: 0x01E0,
  20536. Agrave: 0x00C0,
  20537. Agravesmall: 0xF7E0,
  20538. Ahookabove: 0x1EA2,
  20539. Aiecyrillic: 0x04D4,
  20540. Ainvertedbreve: 0x0202,
  20541. Alpha: 0x0391,
  20542. Alphatonos: 0x0386,
  20543. Amacron: 0x0100,
  20544. Amonospace: 0xFF21,
  20545. Aogonek: 0x0104,
  20546. Aring: 0x00C5,
  20547. Aringacute: 0x01FA,
  20548. Aringbelow: 0x1E00,
  20549. Aringsmall: 0xF7E5,
  20550. Asmall: 0xF761,
  20551. Atilde: 0x00C3,
  20552. Atildesmall: 0xF7E3,
  20553. Aybarmenian: 0x0531,
  20554. B: 0x0042,
  20555. Bcircle: 0x24B7,
  20556. Bdotaccent: 0x1E02,
  20557. Bdotbelow: 0x1E04,
  20558. Becyrillic: 0x0411,
  20559. Benarmenian: 0x0532,
  20560. Beta: 0x0392,
  20561. Bhook: 0x0181,
  20562. Blinebelow: 0x1E06,
  20563. Bmonospace: 0xFF22,
  20564. Brevesmall: 0xF6F4,
  20565. Bsmall: 0xF762,
  20566. Btopbar: 0x0182,
  20567. C: 0x0043,
  20568. Caarmenian: 0x053E,
  20569. Cacute: 0x0106,
  20570. Caron: 0xF6CA,
  20571. Caronsmall: 0xF6F5,
  20572. Ccaron: 0x010C,
  20573. Ccedilla: 0x00C7,
  20574. Ccedillaacute: 0x1E08,
  20575. Ccedillasmall: 0xF7E7,
  20576. Ccircle: 0x24B8,
  20577. Ccircumflex: 0x0108,
  20578. Cdot: 0x010A,
  20579. Cdotaccent: 0x010A,
  20580. Cedillasmall: 0xF7B8,
  20581. Chaarmenian: 0x0549,
  20582. Cheabkhasiancyrillic: 0x04BC,
  20583. Checyrillic: 0x0427,
  20584. Chedescenderabkhasiancyrillic: 0x04BE,
  20585. Chedescendercyrillic: 0x04B6,
  20586. Chedieresiscyrillic: 0x04F4,
  20587. Cheharmenian: 0x0543,
  20588. Chekhakassiancyrillic: 0x04CB,
  20589. Cheverticalstrokecyrillic: 0x04B8,
  20590. Chi: 0x03A7,
  20591. Chook: 0x0187,
  20592. Circumflexsmall: 0xF6F6,
  20593. Cmonospace: 0xFF23,
  20594. Coarmenian: 0x0551,
  20595. Csmall: 0xF763,
  20596. D: 0x0044,
  20597. DZ: 0x01F1,
  20598. DZcaron: 0x01C4,
  20599. Daarmenian: 0x0534,
  20600. Dafrican: 0x0189,
  20601. Dcaron: 0x010E,
  20602. Dcedilla: 0x1E10,
  20603. Dcircle: 0x24B9,
  20604. Dcircumflexbelow: 0x1E12,
  20605. Dcroat: 0x0110,
  20606. Ddotaccent: 0x1E0A,
  20607. Ddotbelow: 0x1E0C,
  20608. Decyrillic: 0x0414,
  20609. Deicoptic: 0x03EE,
  20610. Delta: 0x2206,
  20611. Deltagreek: 0x0394,
  20612. Dhook: 0x018A,
  20613. Dieresis: 0xF6CB,
  20614. DieresisAcute: 0xF6CC,
  20615. DieresisGrave: 0xF6CD,
  20616. Dieresissmall: 0xF7A8,
  20617. Digammagreek: 0x03DC,
  20618. Djecyrillic: 0x0402,
  20619. Dlinebelow: 0x1E0E,
  20620. Dmonospace: 0xFF24,
  20621. Dotaccentsmall: 0xF6F7,
  20622. Dslash: 0x0110,
  20623. Dsmall: 0xF764,
  20624. Dtopbar: 0x018B,
  20625. Dz: 0x01F2,
  20626. Dzcaron: 0x01C5,
  20627. Dzeabkhasiancyrillic: 0x04E0,
  20628. Dzecyrillic: 0x0405,
  20629. Dzhecyrillic: 0x040F,
  20630. E: 0x0045,
  20631. Eacute: 0x00C9,
  20632. Eacutesmall: 0xF7E9,
  20633. Ebreve: 0x0114,
  20634. Ecaron: 0x011A,
  20635. Ecedillabreve: 0x1E1C,
  20636. Echarmenian: 0x0535,
  20637. Ecircle: 0x24BA,
  20638. Ecircumflex: 0x00CA,
  20639. Ecircumflexacute: 0x1EBE,
  20640. Ecircumflexbelow: 0x1E18,
  20641. Ecircumflexdotbelow: 0x1EC6,
  20642. Ecircumflexgrave: 0x1EC0,
  20643. Ecircumflexhookabove: 0x1EC2,
  20644. Ecircumflexsmall: 0xF7EA,
  20645. Ecircumflextilde: 0x1EC4,
  20646. Ecyrillic: 0x0404,
  20647. Edblgrave: 0x0204,
  20648. Edieresis: 0x00CB,
  20649. Edieresissmall: 0xF7EB,
  20650. Edot: 0x0116,
  20651. Edotaccent: 0x0116,
  20652. Edotbelow: 0x1EB8,
  20653. Efcyrillic: 0x0424,
  20654. Egrave: 0x00C8,
  20655. Egravesmall: 0xF7E8,
  20656. Eharmenian: 0x0537,
  20657. Ehookabove: 0x1EBA,
  20658. Eightroman: 0x2167,
  20659. Einvertedbreve: 0x0206,
  20660. Eiotifiedcyrillic: 0x0464,
  20661. Elcyrillic: 0x041B,
  20662. Elevenroman: 0x216A,
  20663. Emacron: 0x0112,
  20664. Emacronacute: 0x1E16,
  20665. Emacrongrave: 0x1E14,
  20666. Emcyrillic: 0x041C,
  20667. Emonospace: 0xFF25,
  20668. Encyrillic: 0x041D,
  20669. Endescendercyrillic: 0x04A2,
  20670. Eng: 0x014A,
  20671. Enghecyrillic: 0x04A4,
  20672. Enhookcyrillic: 0x04C7,
  20673. Eogonek: 0x0118,
  20674. Eopen: 0x0190,
  20675. Epsilon: 0x0395,
  20676. Epsilontonos: 0x0388,
  20677. Ercyrillic: 0x0420,
  20678. Ereversed: 0x018E,
  20679. Ereversedcyrillic: 0x042D,
  20680. Escyrillic: 0x0421,
  20681. Esdescendercyrillic: 0x04AA,
  20682. Esh: 0x01A9,
  20683. Esmall: 0xF765,
  20684. Eta: 0x0397,
  20685. Etarmenian: 0x0538,
  20686. Etatonos: 0x0389,
  20687. Eth: 0x00D0,
  20688. Ethsmall: 0xF7F0,
  20689. Etilde: 0x1EBC,
  20690. Etildebelow: 0x1E1A,
  20691. Euro: 0x20AC,
  20692. Ezh: 0x01B7,
  20693. Ezhcaron: 0x01EE,
  20694. Ezhreversed: 0x01B8,
  20695. F: 0x0046,
  20696. Fcircle: 0x24BB,
  20697. Fdotaccent: 0x1E1E,
  20698. Feharmenian: 0x0556,
  20699. Feicoptic: 0x03E4,
  20700. Fhook: 0x0191,
  20701. Fitacyrillic: 0x0472,
  20702. Fiveroman: 0x2164,
  20703. Fmonospace: 0xFF26,
  20704. Fourroman: 0x2163,
  20705. Fsmall: 0xF766,
  20706. G: 0x0047,
  20707. GBsquare: 0x3387,
  20708. Gacute: 0x01F4,
  20709. Gamma: 0x0393,
  20710. Gammaafrican: 0x0194,
  20711. Gangiacoptic: 0x03EA,
  20712. Gbreve: 0x011E,
  20713. Gcaron: 0x01E6,
  20714. Gcedilla: 0x0122,
  20715. Gcircle: 0x24BC,
  20716. Gcircumflex: 0x011C,
  20717. Gcommaaccent: 0x0122,
  20718. Gdot: 0x0120,
  20719. Gdotaccent: 0x0120,
  20720. Gecyrillic: 0x0413,
  20721. Ghadarmenian: 0x0542,
  20722. Ghemiddlehookcyrillic: 0x0494,
  20723. Ghestrokecyrillic: 0x0492,
  20724. Gheupturncyrillic: 0x0490,
  20725. Ghook: 0x0193,
  20726. Gimarmenian: 0x0533,
  20727. Gjecyrillic: 0x0403,
  20728. Gmacron: 0x1E20,
  20729. Gmonospace: 0xFF27,
  20730. Grave: 0xF6CE,
  20731. Gravesmall: 0xF760,
  20732. Gsmall: 0xF767,
  20733. Gsmallhook: 0x029B,
  20734. Gstroke: 0x01E4,
  20735. H: 0x0048,
  20736. H18533: 0x25CF,
  20737. H18543: 0x25AA,
  20738. H18551: 0x25AB,
  20739. H22073: 0x25A1,
  20740. HPsquare: 0x33CB,
  20741. Haabkhasiancyrillic: 0x04A8,
  20742. Hadescendercyrillic: 0x04B2,
  20743. Hardsigncyrillic: 0x042A,
  20744. Hbar: 0x0126,
  20745. Hbrevebelow: 0x1E2A,
  20746. Hcedilla: 0x1E28,
  20747. Hcircle: 0x24BD,
  20748. Hcircumflex: 0x0124,
  20749. Hdieresis: 0x1E26,
  20750. Hdotaccent: 0x1E22,
  20751. Hdotbelow: 0x1E24,
  20752. Hmonospace: 0xFF28,
  20753. Hoarmenian: 0x0540,
  20754. Horicoptic: 0x03E8,
  20755. Hsmall: 0xF768,
  20756. Hungarumlaut: 0xF6CF,
  20757. Hungarumlautsmall: 0xF6F8,
  20758. Hzsquare: 0x3390,
  20759. I: 0x0049,
  20760. IAcyrillic: 0x042F,
  20761. IJ: 0x0132,
  20762. IUcyrillic: 0x042E,
  20763. Iacute: 0x00CD,
  20764. Iacutesmall: 0xF7ED,
  20765. Ibreve: 0x012C,
  20766. Icaron: 0x01CF,
  20767. Icircle: 0x24BE,
  20768. Icircumflex: 0x00CE,
  20769. Icircumflexsmall: 0xF7EE,
  20770. Icyrillic: 0x0406,
  20771. Idblgrave: 0x0208,
  20772. Idieresis: 0x00CF,
  20773. Idieresisacute: 0x1E2E,
  20774. Idieresiscyrillic: 0x04E4,
  20775. Idieresissmall: 0xF7EF,
  20776. Idot: 0x0130,
  20777. Idotaccent: 0x0130,
  20778. Idotbelow: 0x1ECA,
  20779. Iebrevecyrillic: 0x04D6,
  20780. Iecyrillic: 0x0415,
  20781. Ifraktur: 0x2111,
  20782. Igrave: 0x00CC,
  20783. Igravesmall: 0xF7EC,
  20784. Ihookabove: 0x1EC8,
  20785. Iicyrillic: 0x0418,
  20786. Iinvertedbreve: 0x020A,
  20787. Iishortcyrillic: 0x0419,
  20788. Imacron: 0x012A,
  20789. Imacroncyrillic: 0x04E2,
  20790. Imonospace: 0xFF29,
  20791. Iniarmenian: 0x053B,
  20792. Iocyrillic: 0x0401,
  20793. Iogonek: 0x012E,
  20794. Iota: 0x0399,
  20795. Iotaafrican: 0x0196,
  20796. Iotadieresis: 0x03AA,
  20797. Iotatonos: 0x038A,
  20798. Ismall: 0xF769,
  20799. Istroke: 0x0197,
  20800. Itilde: 0x0128,
  20801. Itildebelow: 0x1E2C,
  20802. Izhitsacyrillic: 0x0474,
  20803. Izhitsadblgravecyrillic: 0x0476,
  20804. J: 0x004A,
  20805. Jaarmenian: 0x0541,
  20806. Jcircle: 0x24BF,
  20807. Jcircumflex: 0x0134,
  20808. Jecyrillic: 0x0408,
  20809. Jheharmenian: 0x054B,
  20810. Jmonospace: 0xFF2A,
  20811. Jsmall: 0xF76A,
  20812. K: 0x004B,
  20813. KBsquare: 0x3385,
  20814. KKsquare: 0x33CD,
  20815. Kabashkircyrillic: 0x04A0,
  20816. Kacute: 0x1E30,
  20817. Kacyrillic: 0x041A,
  20818. Kadescendercyrillic: 0x049A,
  20819. Kahookcyrillic: 0x04C3,
  20820. Kappa: 0x039A,
  20821. Kastrokecyrillic: 0x049E,
  20822. Kaverticalstrokecyrillic: 0x049C,
  20823. Kcaron: 0x01E8,
  20824. Kcedilla: 0x0136,
  20825. Kcircle: 0x24C0,
  20826. Kcommaaccent: 0x0136,
  20827. Kdotbelow: 0x1E32,
  20828. Keharmenian: 0x0554,
  20829. Kenarmenian: 0x053F,
  20830. Khacyrillic: 0x0425,
  20831. Kheicoptic: 0x03E6,
  20832. Khook: 0x0198,
  20833. Kjecyrillic: 0x040C,
  20834. Klinebelow: 0x1E34,
  20835. Kmonospace: 0xFF2B,
  20836. Koppacyrillic: 0x0480,
  20837. Koppagreek: 0x03DE,
  20838. Ksicyrillic: 0x046E,
  20839. Ksmall: 0xF76B,
  20840. L: 0x004C,
  20841. LJ: 0x01C7,
  20842. LL: 0xF6BF,
  20843. Lacute: 0x0139,
  20844. Lambda: 0x039B,
  20845. Lcaron: 0x013D,
  20846. Lcedilla: 0x013B,
  20847. Lcircle: 0x24C1,
  20848. Lcircumflexbelow: 0x1E3C,
  20849. Lcommaaccent: 0x013B,
  20850. Ldot: 0x013F,
  20851. Ldotaccent: 0x013F,
  20852. Ldotbelow: 0x1E36,
  20853. Ldotbelowmacron: 0x1E38,
  20854. Liwnarmenian: 0x053C,
  20855. Lj: 0x01C8,
  20856. Ljecyrillic: 0x0409,
  20857. Llinebelow: 0x1E3A,
  20858. Lmonospace: 0xFF2C,
  20859. Lslash: 0x0141,
  20860. Lslashsmall: 0xF6F9,
  20861. Lsmall: 0xF76C,
  20862. M: 0x004D,
  20863. MBsquare: 0x3386,
  20864. Macron: 0xF6D0,
  20865. Macronsmall: 0xF7AF,
  20866. Macute: 0x1E3E,
  20867. Mcircle: 0x24C2,
  20868. Mdotaccent: 0x1E40,
  20869. Mdotbelow: 0x1E42,
  20870. Menarmenian: 0x0544,
  20871. Mmonospace: 0xFF2D,
  20872. Msmall: 0xF76D,
  20873. Mturned: 0x019C,
  20874. Mu: 0x039C,
  20875. N: 0x004E,
  20876. NJ: 0x01CA,
  20877. Nacute: 0x0143,
  20878. Ncaron: 0x0147,
  20879. Ncedilla: 0x0145,
  20880. Ncircle: 0x24C3,
  20881. Ncircumflexbelow: 0x1E4A,
  20882. Ncommaaccent: 0x0145,
  20883. Ndotaccent: 0x1E44,
  20884. Ndotbelow: 0x1E46,
  20885. Nhookleft: 0x019D,
  20886. Nineroman: 0x2168,
  20887. Nj: 0x01CB,
  20888. Njecyrillic: 0x040A,
  20889. Nlinebelow: 0x1E48,
  20890. Nmonospace: 0xFF2E,
  20891. Nowarmenian: 0x0546,
  20892. Nsmall: 0xF76E,
  20893. Ntilde: 0x00D1,
  20894. Ntildesmall: 0xF7F1,
  20895. Nu: 0x039D,
  20896. O: 0x004F,
  20897. OE: 0x0152,
  20898. OEsmall: 0xF6FA,
  20899. Oacute: 0x00D3,
  20900. Oacutesmall: 0xF7F3,
  20901. Obarredcyrillic: 0x04E8,
  20902. Obarreddieresiscyrillic: 0x04EA,
  20903. Obreve: 0x014E,
  20904. Ocaron: 0x01D1,
  20905. Ocenteredtilde: 0x019F,
  20906. Ocircle: 0x24C4,
  20907. Ocircumflex: 0x00D4,
  20908. Ocircumflexacute: 0x1ED0,
  20909. Ocircumflexdotbelow: 0x1ED8,
  20910. Ocircumflexgrave: 0x1ED2,
  20911. Ocircumflexhookabove: 0x1ED4,
  20912. Ocircumflexsmall: 0xF7F4,
  20913. Ocircumflextilde: 0x1ED6,
  20914. Ocyrillic: 0x041E,
  20915. Odblacute: 0x0150,
  20916. Odblgrave: 0x020C,
  20917. Odieresis: 0x00D6,
  20918. Odieresiscyrillic: 0x04E6,
  20919. Odieresissmall: 0xF7F6,
  20920. Odotbelow: 0x1ECC,
  20921. Ogoneksmall: 0xF6FB,
  20922. Ograve: 0x00D2,
  20923. Ogravesmall: 0xF7F2,
  20924. Oharmenian: 0x0555,
  20925. Ohm: 0x2126,
  20926. Ohookabove: 0x1ECE,
  20927. Ohorn: 0x01A0,
  20928. Ohornacute: 0x1EDA,
  20929. Ohorndotbelow: 0x1EE2,
  20930. Ohorngrave: 0x1EDC,
  20931. Ohornhookabove: 0x1EDE,
  20932. Ohorntilde: 0x1EE0,
  20933. Ohungarumlaut: 0x0150,
  20934. Oi: 0x01A2,
  20935. Oinvertedbreve: 0x020E,
  20936. Omacron: 0x014C,
  20937. Omacronacute: 0x1E52,
  20938. Omacrongrave: 0x1E50,
  20939. Omega: 0x2126,
  20940. Omegacyrillic: 0x0460,
  20941. Omegagreek: 0x03A9,
  20942. Omegaroundcyrillic: 0x047A,
  20943. Omegatitlocyrillic: 0x047C,
  20944. Omegatonos: 0x038F,
  20945. Omicron: 0x039F,
  20946. Omicrontonos: 0x038C,
  20947. Omonospace: 0xFF2F,
  20948. Oneroman: 0x2160,
  20949. Oogonek: 0x01EA,
  20950. Oogonekmacron: 0x01EC,
  20951. Oopen: 0x0186,
  20952. Oslash: 0x00D8,
  20953. Oslashacute: 0x01FE,
  20954. Oslashsmall: 0xF7F8,
  20955. Osmall: 0xF76F,
  20956. Ostrokeacute: 0x01FE,
  20957. Otcyrillic: 0x047E,
  20958. Otilde: 0x00D5,
  20959. Otildeacute: 0x1E4C,
  20960. Otildedieresis: 0x1E4E,
  20961. Otildesmall: 0xF7F5,
  20962. P: 0x0050,
  20963. Pacute: 0x1E54,
  20964. Pcircle: 0x24C5,
  20965. Pdotaccent: 0x1E56,
  20966. Pecyrillic: 0x041F,
  20967. Peharmenian: 0x054A,
  20968. Pemiddlehookcyrillic: 0x04A6,
  20969. Phi: 0x03A6,
  20970. Phook: 0x01A4,
  20971. Pi: 0x03A0,
  20972. Piwrarmenian: 0x0553,
  20973. Pmonospace: 0xFF30,
  20974. Psi: 0x03A8,
  20975. Psicyrillic: 0x0470,
  20976. Psmall: 0xF770,
  20977. Q: 0x0051,
  20978. Qcircle: 0x24C6,
  20979. Qmonospace: 0xFF31,
  20980. Qsmall: 0xF771,
  20981. R: 0x0052,
  20982. Raarmenian: 0x054C,
  20983. Racute: 0x0154,
  20984. Rcaron: 0x0158,
  20985. Rcedilla: 0x0156,
  20986. Rcircle: 0x24C7,
  20987. Rcommaaccent: 0x0156,
  20988. Rdblgrave: 0x0210,
  20989. Rdotaccent: 0x1E58,
  20990. Rdotbelow: 0x1E5A,
  20991. Rdotbelowmacron: 0x1E5C,
  20992. Reharmenian: 0x0550,
  20993. Rfraktur: 0x211C,
  20994. Rho: 0x03A1,
  20995. Ringsmall: 0xF6FC,
  20996. Rinvertedbreve: 0x0212,
  20997. Rlinebelow: 0x1E5E,
  20998. Rmonospace: 0xFF32,
  20999. Rsmall: 0xF772,
  21000. Rsmallinverted: 0x0281,
  21001. Rsmallinvertedsuperior: 0x02B6,
  21002. S: 0x0053,
  21003. SF010000: 0x250C,
  21004. SF020000: 0x2514,
  21005. SF030000: 0x2510,
  21006. SF040000: 0x2518,
  21007. SF050000: 0x253C,
  21008. SF060000: 0x252C,
  21009. SF070000: 0x2534,
  21010. SF080000: 0x251C,
  21011. SF090000: 0x2524,
  21012. SF100000: 0x2500,
  21013. SF110000: 0x2502,
  21014. SF190000: 0x2561,
  21015. SF200000: 0x2562,
  21016. SF210000: 0x2556,
  21017. SF220000: 0x2555,
  21018. SF230000: 0x2563,
  21019. SF240000: 0x2551,
  21020. SF250000: 0x2557,
  21021. SF260000: 0x255D,
  21022. SF270000: 0x255C,
  21023. SF280000: 0x255B,
  21024. SF360000: 0x255E,
  21025. SF370000: 0x255F,
  21026. SF380000: 0x255A,
  21027. SF390000: 0x2554,
  21028. SF400000: 0x2569,
  21029. SF410000: 0x2566,
  21030. SF420000: 0x2560,
  21031. SF430000: 0x2550,
  21032. SF440000: 0x256C,
  21033. SF450000: 0x2567,
  21034. SF460000: 0x2568,
  21035. SF470000: 0x2564,
  21036. SF480000: 0x2565,
  21037. SF490000: 0x2559,
  21038. SF500000: 0x2558,
  21039. SF510000: 0x2552,
  21040. SF520000: 0x2553,
  21041. SF530000: 0x256B,
  21042. SF540000: 0x256A,
  21043. Sacute: 0x015A,
  21044. Sacutedotaccent: 0x1E64,
  21045. Sampigreek: 0x03E0,
  21046. Scaron: 0x0160,
  21047. Scarondotaccent: 0x1E66,
  21048. Scaronsmall: 0xF6FD,
  21049. Scedilla: 0x015E,
  21050. Schwa: 0x018F,
  21051. Schwacyrillic: 0x04D8,
  21052. Schwadieresiscyrillic: 0x04DA,
  21053. Scircle: 0x24C8,
  21054. Scircumflex: 0x015C,
  21055. Scommaaccent: 0x0218,
  21056. Sdotaccent: 0x1E60,
  21057. Sdotbelow: 0x1E62,
  21058. Sdotbelowdotaccent: 0x1E68,
  21059. Seharmenian: 0x054D,
  21060. Sevenroman: 0x2166,
  21061. Shaarmenian: 0x0547,
  21062. Shacyrillic: 0x0428,
  21063. Shchacyrillic: 0x0429,
  21064. Sheicoptic: 0x03E2,
  21065. Shhacyrillic: 0x04BA,
  21066. Shimacoptic: 0x03EC,
  21067. Sigma: 0x03A3,
  21068. Sixroman: 0x2165,
  21069. Smonospace: 0xFF33,
  21070. Softsigncyrillic: 0x042C,
  21071. Ssmall: 0xF773,
  21072. Stigmagreek: 0x03DA,
  21073. T: 0x0054,
  21074. Tau: 0x03A4,
  21075. Tbar: 0x0166,
  21076. Tcaron: 0x0164,
  21077. Tcedilla: 0x0162,
  21078. Tcircle: 0x24C9,
  21079. Tcircumflexbelow: 0x1E70,
  21080. Tcommaaccent: 0x0162,
  21081. Tdotaccent: 0x1E6A,
  21082. Tdotbelow: 0x1E6C,
  21083. Tecyrillic: 0x0422,
  21084. Tedescendercyrillic: 0x04AC,
  21085. Tenroman: 0x2169,
  21086. Tetsecyrillic: 0x04B4,
  21087. Theta: 0x0398,
  21088. Thook: 0x01AC,
  21089. Thorn: 0x00DE,
  21090. Thornsmall: 0xF7FE,
  21091. Threeroman: 0x2162,
  21092. Tildesmall: 0xF6FE,
  21093. Tiwnarmenian: 0x054F,
  21094. Tlinebelow: 0x1E6E,
  21095. Tmonospace: 0xFF34,
  21096. Toarmenian: 0x0539,
  21097. Tonefive: 0x01BC,
  21098. Tonesix: 0x0184,
  21099. Tonetwo: 0x01A7,
  21100. Tretroflexhook: 0x01AE,
  21101. Tsecyrillic: 0x0426,
  21102. Tshecyrillic: 0x040B,
  21103. Tsmall: 0xF774,
  21104. Twelveroman: 0x216B,
  21105. Tworoman: 0x2161,
  21106. U: 0x0055,
  21107. Uacute: 0x00DA,
  21108. Uacutesmall: 0xF7FA,
  21109. Ubreve: 0x016C,
  21110. Ucaron: 0x01D3,
  21111. Ucircle: 0x24CA,
  21112. Ucircumflex: 0x00DB,
  21113. Ucircumflexbelow: 0x1E76,
  21114. Ucircumflexsmall: 0xF7FB,
  21115. Ucyrillic: 0x0423,
  21116. Udblacute: 0x0170,
  21117. Udblgrave: 0x0214,
  21118. Udieresis: 0x00DC,
  21119. Udieresisacute: 0x01D7,
  21120. Udieresisbelow: 0x1E72,
  21121. Udieresiscaron: 0x01D9,
  21122. Udieresiscyrillic: 0x04F0,
  21123. Udieresisgrave: 0x01DB,
  21124. Udieresismacron: 0x01D5,
  21125. Udieresissmall: 0xF7FC,
  21126. Udotbelow: 0x1EE4,
  21127. Ugrave: 0x00D9,
  21128. Ugravesmall: 0xF7F9,
  21129. Uhookabove: 0x1EE6,
  21130. Uhorn: 0x01AF,
  21131. Uhornacute: 0x1EE8,
  21132. Uhorndotbelow: 0x1EF0,
  21133. Uhorngrave: 0x1EEA,
  21134. Uhornhookabove: 0x1EEC,
  21135. Uhorntilde: 0x1EEE,
  21136. Uhungarumlaut: 0x0170,
  21137. Uhungarumlautcyrillic: 0x04F2,
  21138. Uinvertedbreve: 0x0216,
  21139. Ukcyrillic: 0x0478,
  21140. Umacron: 0x016A,
  21141. Umacroncyrillic: 0x04EE,
  21142. Umacrondieresis: 0x1E7A,
  21143. Umonospace: 0xFF35,
  21144. Uogonek: 0x0172,
  21145. Upsilon: 0x03A5,
  21146. Upsilon1: 0x03D2,
  21147. Upsilonacutehooksymbolgreek: 0x03D3,
  21148. Upsilonafrican: 0x01B1,
  21149. Upsilondieresis: 0x03AB,
  21150. Upsilondieresishooksymbolgreek: 0x03D4,
  21151. Upsilonhooksymbol: 0x03D2,
  21152. Upsilontonos: 0x038E,
  21153. Uring: 0x016E,
  21154. Ushortcyrillic: 0x040E,
  21155. Usmall: 0xF775,
  21156. Ustraightcyrillic: 0x04AE,
  21157. Ustraightstrokecyrillic: 0x04B0,
  21158. Utilde: 0x0168,
  21159. Utildeacute: 0x1E78,
  21160. Utildebelow: 0x1E74,
  21161. V: 0x0056,
  21162. Vcircle: 0x24CB,
  21163. Vdotbelow: 0x1E7E,
  21164. Vecyrillic: 0x0412,
  21165. Vewarmenian: 0x054E,
  21166. Vhook: 0x01B2,
  21167. Vmonospace: 0xFF36,
  21168. Voarmenian: 0x0548,
  21169. Vsmall: 0xF776,
  21170. Vtilde: 0x1E7C,
  21171. W: 0x0057,
  21172. Wacute: 0x1E82,
  21173. Wcircle: 0x24CC,
  21174. Wcircumflex: 0x0174,
  21175. Wdieresis: 0x1E84,
  21176. Wdotaccent: 0x1E86,
  21177. Wdotbelow: 0x1E88,
  21178. Wgrave: 0x1E80,
  21179. Wmonospace: 0xFF37,
  21180. Wsmall: 0xF777,
  21181. X: 0x0058,
  21182. Xcircle: 0x24CD,
  21183. Xdieresis: 0x1E8C,
  21184. Xdotaccent: 0x1E8A,
  21185. Xeharmenian: 0x053D,
  21186. Xi: 0x039E,
  21187. Xmonospace: 0xFF38,
  21188. Xsmall: 0xF778,
  21189. Y: 0x0059,
  21190. Yacute: 0x00DD,
  21191. Yacutesmall: 0xF7FD,
  21192. Yatcyrillic: 0x0462,
  21193. Ycircle: 0x24CE,
  21194. Ycircumflex: 0x0176,
  21195. Ydieresis: 0x0178,
  21196. Ydieresissmall: 0xF7FF,
  21197. Ydotaccent: 0x1E8E,
  21198. Ydotbelow: 0x1EF4,
  21199. Yericyrillic: 0x042B,
  21200. Yerudieresiscyrillic: 0x04F8,
  21201. Ygrave: 0x1EF2,
  21202. Yhook: 0x01B3,
  21203. Yhookabove: 0x1EF6,
  21204. Yiarmenian: 0x0545,
  21205. Yicyrillic: 0x0407,
  21206. Yiwnarmenian: 0x0552,
  21207. Ymonospace: 0xFF39,
  21208. Ysmall: 0xF779,
  21209. Ytilde: 0x1EF8,
  21210. Yusbigcyrillic: 0x046A,
  21211. Yusbigiotifiedcyrillic: 0x046C,
  21212. Yuslittlecyrillic: 0x0466,
  21213. Yuslittleiotifiedcyrillic: 0x0468,
  21214. Z: 0x005A,
  21215. Zaarmenian: 0x0536,
  21216. Zacute: 0x0179,
  21217. Zcaron: 0x017D,
  21218. Zcaronsmall: 0xF6FF,
  21219. Zcircle: 0x24CF,
  21220. Zcircumflex: 0x1E90,
  21221. Zdot: 0x017B,
  21222. Zdotaccent: 0x017B,
  21223. Zdotbelow: 0x1E92,
  21224. Zecyrillic: 0x0417,
  21225. Zedescendercyrillic: 0x0498,
  21226. Zedieresiscyrillic: 0x04DE,
  21227. Zeta: 0x0396,
  21228. Zhearmenian: 0x053A,
  21229. Zhebrevecyrillic: 0x04C1,
  21230. Zhecyrillic: 0x0416,
  21231. Zhedescendercyrillic: 0x0496,
  21232. Zhedieresiscyrillic: 0x04DC,
  21233. Zlinebelow: 0x1E94,
  21234. Zmonospace: 0xFF3A,
  21235. Zsmall: 0xF77A,
  21236. Zstroke: 0x01B5,
  21237. a: 0x0061,
  21238. aabengali: 0x0986,
  21239. aacute: 0x00E1,
  21240. aadeva: 0x0906,
  21241. aagujarati: 0x0A86,
  21242. aagurmukhi: 0x0A06,
  21243. aamatragurmukhi: 0x0A3E,
  21244. aarusquare: 0x3303,
  21245. aavowelsignbengali: 0x09BE,
  21246. aavowelsigndeva: 0x093E,
  21247. aavowelsigngujarati: 0x0ABE,
  21248. abbreviationmarkarmenian: 0x055F,
  21249. abbreviationsigndeva: 0x0970,
  21250. abengali: 0x0985,
  21251. abopomofo: 0x311A,
  21252. abreve: 0x0103,
  21253. abreveacute: 0x1EAF,
  21254. abrevecyrillic: 0x04D1,
  21255. abrevedotbelow: 0x1EB7,
  21256. abrevegrave: 0x1EB1,
  21257. abrevehookabove: 0x1EB3,
  21258. abrevetilde: 0x1EB5,
  21259. acaron: 0x01CE,
  21260. acircle: 0x24D0,
  21261. acircumflex: 0x00E2,
  21262. acircumflexacute: 0x1EA5,
  21263. acircumflexdotbelow: 0x1EAD,
  21264. acircumflexgrave: 0x1EA7,
  21265. acircumflexhookabove: 0x1EA9,
  21266. acircumflextilde: 0x1EAB,
  21267. acute: 0x00B4,
  21268. acutebelowcmb: 0x0317,
  21269. acutecmb: 0x0301,
  21270. acutecomb: 0x0301,
  21271. acutedeva: 0x0954,
  21272. acutelowmod: 0x02CF,
  21273. acutetonecmb: 0x0341,
  21274. acyrillic: 0x0430,
  21275. adblgrave: 0x0201,
  21276. addakgurmukhi: 0x0A71,
  21277. adeva: 0x0905,
  21278. adieresis: 0x00E4,
  21279. adieresiscyrillic: 0x04D3,
  21280. adieresismacron: 0x01DF,
  21281. adotbelow: 0x1EA1,
  21282. adotmacron: 0x01E1,
  21283. ae: 0x00E6,
  21284. aeacute: 0x01FD,
  21285. aekorean: 0x3150,
  21286. aemacron: 0x01E3,
  21287. afii00208: 0x2015,
  21288. afii08941: 0x20A4,
  21289. afii10017: 0x0410,
  21290. afii10018: 0x0411,
  21291. afii10019: 0x0412,
  21292. afii10020: 0x0413,
  21293. afii10021: 0x0414,
  21294. afii10022: 0x0415,
  21295. afii10023: 0x0401,
  21296. afii10024: 0x0416,
  21297. afii10025: 0x0417,
  21298. afii10026: 0x0418,
  21299. afii10027: 0x0419,
  21300. afii10028: 0x041A,
  21301. afii10029: 0x041B,
  21302. afii10030: 0x041C,
  21303. afii10031: 0x041D,
  21304. afii10032: 0x041E,
  21305. afii10033: 0x041F,
  21306. afii10034: 0x0420,
  21307. afii10035: 0x0421,
  21308. afii10036: 0x0422,
  21309. afii10037: 0x0423,
  21310. afii10038: 0x0424,
  21311. afii10039: 0x0425,
  21312. afii10040: 0x0426,
  21313. afii10041: 0x0427,
  21314. afii10042: 0x0428,
  21315. afii10043: 0x0429,
  21316. afii10044: 0x042A,
  21317. afii10045: 0x042B,
  21318. afii10046: 0x042C,
  21319. afii10047: 0x042D,
  21320. afii10048: 0x042E,
  21321. afii10049: 0x042F,
  21322. afii10050: 0x0490,
  21323. afii10051: 0x0402,
  21324. afii10052: 0x0403,
  21325. afii10053: 0x0404,
  21326. afii10054: 0x0405,
  21327. afii10055: 0x0406,
  21328. afii10056: 0x0407,
  21329. afii10057: 0x0408,
  21330. afii10058: 0x0409,
  21331. afii10059: 0x040A,
  21332. afii10060: 0x040B,
  21333. afii10061: 0x040C,
  21334. afii10062: 0x040E,
  21335. afii10063: 0xF6C4,
  21336. afii10064: 0xF6C5,
  21337. afii10065: 0x0430,
  21338. afii10066: 0x0431,
  21339. afii10067: 0x0432,
  21340. afii10068: 0x0433,
  21341. afii10069: 0x0434,
  21342. afii10070: 0x0435,
  21343. afii10071: 0x0451,
  21344. afii10072: 0x0436,
  21345. afii10073: 0x0437,
  21346. afii10074: 0x0438,
  21347. afii10075: 0x0439,
  21348. afii10076: 0x043A,
  21349. afii10077: 0x043B,
  21350. afii10078: 0x043C,
  21351. afii10079: 0x043D,
  21352. afii10080: 0x043E,
  21353. afii10081: 0x043F,
  21354. afii10082: 0x0440,
  21355. afii10083: 0x0441,
  21356. afii10084: 0x0442,
  21357. afii10085: 0x0443,
  21358. afii10086: 0x0444,
  21359. afii10087: 0x0445,
  21360. afii10088: 0x0446,
  21361. afii10089: 0x0447,
  21362. afii10090: 0x0448,
  21363. afii10091: 0x0449,
  21364. afii10092: 0x044A,
  21365. afii10093: 0x044B,
  21366. afii10094: 0x044C,
  21367. afii10095: 0x044D,
  21368. afii10096: 0x044E,
  21369. afii10097: 0x044F,
  21370. afii10098: 0x0491,
  21371. afii10099: 0x0452,
  21372. afii10100: 0x0453,
  21373. afii10101: 0x0454,
  21374. afii10102: 0x0455,
  21375. afii10103: 0x0456,
  21376. afii10104: 0x0457,
  21377. afii10105: 0x0458,
  21378. afii10106: 0x0459,
  21379. afii10107: 0x045A,
  21380. afii10108: 0x045B,
  21381. afii10109: 0x045C,
  21382. afii10110: 0x045E,
  21383. afii10145: 0x040F,
  21384. afii10146: 0x0462,
  21385. afii10147: 0x0472,
  21386. afii10148: 0x0474,
  21387. afii10192: 0xF6C6,
  21388. afii10193: 0x045F,
  21389. afii10194: 0x0463,
  21390. afii10195: 0x0473,
  21391. afii10196: 0x0475,
  21392. afii10831: 0xF6C7,
  21393. afii10832: 0xF6C8,
  21394. afii10846: 0x04D9,
  21395. afii299: 0x200E,
  21396. afii300: 0x200F,
  21397. afii301: 0x200D,
  21398. afii57381: 0x066A,
  21399. afii57388: 0x060C,
  21400. afii57392: 0x0660,
  21401. afii57393: 0x0661,
  21402. afii57394: 0x0662,
  21403. afii57395: 0x0663,
  21404. afii57396: 0x0664,
  21405. afii57397: 0x0665,
  21406. afii57398: 0x0666,
  21407. afii57399: 0x0667,
  21408. afii57400: 0x0668,
  21409. afii57401: 0x0669,
  21410. afii57403: 0x061B,
  21411. afii57407: 0x061F,
  21412. afii57409: 0x0621,
  21413. afii57410: 0x0622,
  21414. afii57411: 0x0623,
  21415. afii57412: 0x0624,
  21416. afii57413: 0x0625,
  21417. afii57414: 0x0626,
  21418. afii57415: 0x0627,
  21419. afii57416: 0x0628,
  21420. afii57417: 0x0629,
  21421. afii57418: 0x062A,
  21422. afii57419: 0x062B,
  21423. afii57420: 0x062C,
  21424. afii57421: 0x062D,
  21425. afii57422: 0x062E,
  21426. afii57423: 0x062F,
  21427. afii57424: 0x0630,
  21428. afii57425: 0x0631,
  21429. afii57426: 0x0632,
  21430. afii57427: 0x0633,
  21431. afii57428: 0x0634,
  21432. afii57429: 0x0635,
  21433. afii57430: 0x0636,
  21434. afii57431: 0x0637,
  21435. afii57432: 0x0638,
  21436. afii57433: 0x0639,
  21437. afii57434: 0x063A,
  21438. afii57440: 0x0640,
  21439. afii57441: 0x0641,
  21440. afii57442: 0x0642,
  21441. afii57443: 0x0643,
  21442. afii57444: 0x0644,
  21443. afii57445: 0x0645,
  21444. afii57446: 0x0646,
  21445. afii57448: 0x0648,
  21446. afii57449: 0x0649,
  21447. afii57450: 0x064A,
  21448. afii57451: 0x064B,
  21449. afii57452: 0x064C,
  21450. afii57453: 0x064D,
  21451. afii57454: 0x064E,
  21452. afii57455: 0x064F,
  21453. afii57456: 0x0650,
  21454. afii57457: 0x0651,
  21455. afii57458: 0x0652,
  21456. afii57470: 0x0647,
  21457. afii57505: 0x06A4,
  21458. afii57506: 0x067E,
  21459. afii57507: 0x0686,
  21460. afii57508: 0x0698,
  21461. afii57509: 0x06AF,
  21462. afii57511: 0x0679,
  21463. afii57512: 0x0688,
  21464. afii57513: 0x0691,
  21465. afii57514: 0x06BA,
  21466. afii57519: 0x06D2,
  21467. afii57534: 0x06D5,
  21468. afii57636: 0x20AA,
  21469. afii57645: 0x05BE,
  21470. afii57658: 0x05C3,
  21471. afii57664: 0x05D0,
  21472. afii57665: 0x05D1,
  21473. afii57666: 0x05D2,
  21474. afii57667: 0x05D3,
  21475. afii57668: 0x05D4,
  21476. afii57669: 0x05D5,
  21477. afii57670: 0x05D6,
  21478. afii57671: 0x05D7,
  21479. afii57672: 0x05D8,
  21480. afii57673: 0x05D9,
  21481. afii57674: 0x05DA,
  21482. afii57675: 0x05DB,
  21483. afii57676: 0x05DC,
  21484. afii57677: 0x05DD,
  21485. afii57678: 0x05DE,
  21486. afii57679: 0x05DF,
  21487. afii57680: 0x05E0,
  21488. afii57681: 0x05E1,
  21489. afii57682: 0x05E2,
  21490. afii57683: 0x05E3,
  21491. afii57684: 0x05E4,
  21492. afii57685: 0x05E5,
  21493. afii57686: 0x05E6,
  21494. afii57687: 0x05E7,
  21495. afii57688: 0x05E8,
  21496. afii57689: 0x05E9,
  21497. afii57690: 0x05EA,
  21498. afii57694: 0xFB2A,
  21499. afii57695: 0xFB2B,
  21500. afii57700: 0xFB4B,
  21501. afii57705: 0xFB1F,
  21502. afii57716: 0x05F0,
  21503. afii57717: 0x05F1,
  21504. afii57718: 0x05F2,
  21505. afii57723: 0xFB35,
  21506. afii57793: 0x05B4,
  21507. afii57794: 0x05B5,
  21508. afii57795: 0x05B6,
  21509. afii57796: 0x05BB,
  21510. afii57797: 0x05B8,
  21511. afii57798: 0x05B7,
  21512. afii57799: 0x05B0,
  21513. afii57800: 0x05B2,
  21514. afii57801: 0x05B1,
  21515. afii57802: 0x05B3,
  21516. afii57803: 0x05C2,
  21517. afii57804: 0x05C1,
  21518. afii57806: 0x05B9,
  21519. afii57807: 0x05BC,
  21520. afii57839: 0x05BD,
  21521. afii57841: 0x05BF,
  21522. afii57842: 0x05C0,
  21523. afii57929: 0x02BC,
  21524. afii61248: 0x2105,
  21525. afii61289: 0x2113,
  21526. afii61352: 0x2116,
  21527. afii61573: 0x202C,
  21528. afii61574: 0x202D,
  21529. afii61575: 0x202E,
  21530. afii61664: 0x200C,
  21531. afii63167: 0x066D,
  21532. afii64937: 0x02BD,
  21533. agrave: 0x00E0,
  21534. agujarati: 0x0A85,
  21535. agurmukhi: 0x0A05,
  21536. ahiragana: 0x3042,
  21537. ahookabove: 0x1EA3,
  21538. aibengali: 0x0990,
  21539. aibopomofo: 0x311E,
  21540. aideva: 0x0910,
  21541. aiecyrillic: 0x04D5,
  21542. aigujarati: 0x0A90,
  21543. aigurmukhi: 0x0A10,
  21544. aimatragurmukhi: 0x0A48,
  21545. ainarabic: 0x0639,
  21546. ainfinalarabic: 0xFECA,
  21547. aininitialarabic: 0xFECB,
  21548. ainmedialarabic: 0xFECC,
  21549. ainvertedbreve: 0x0203,
  21550. aivowelsignbengali: 0x09C8,
  21551. aivowelsigndeva: 0x0948,
  21552. aivowelsigngujarati: 0x0AC8,
  21553. akatakana: 0x30A2,
  21554. akatakanahalfwidth: 0xFF71,
  21555. akorean: 0x314F,
  21556. alef: 0x05D0,
  21557. alefarabic: 0x0627,
  21558. alefdageshhebrew: 0xFB30,
  21559. aleffinalarabic: 0xFE8E,
  21560. alefhamzaabovearabic: 0x0623,
  21561. alefhamzaabovefinalarabic: 0xFE84,
  21562. alefhamzabelowarabic: 0x0625,
  21563. alefhamzabelowfinalarabic: 0xFE88,
  21564. alefhebrew: 0x05D0,
  21565. aleflamedhebrew: 0xFB4F,
  21566. alefmaddaabovearabic: 0x0622,
  21567. alefmaddaabovefinalarabic: 0xFE82,
  21568. alefmaksuraarabic: 0x0649,
  21569. alefmaksurafinalarabic: 0xFEF0,
  21570. alefmaksurainitialarabic: 0xFEF3,
  21571. alefmaksuramedialarabic: 0xFEF4,
  21572. alefpatahhebrew: 0xFB2E,
  21573. alefqamatshebrew: 0xFB2F,
  21574. aleph: 0x2135,
  21575. allequal: 0x224C,
  21576. alpha: 0x03B1,
  21577. alphatonos: 0x03AC,
  21578. amacron: 0x0101,
  21579. amonospace: 0xFF41,
  21580. ampersand: 0x0026,
  21581. ampersandmonospace: 0xFF06,
  21582. ampersandsmall: 0xF726,
  21583. amsquare: 0x33C2,
  21584. anbopomofo: 0x3122,
  21585. angbopomofo: 0x3124,
  21586. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21587. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21588. angkhankhuthai: 0x0E5A,
  21589. angle: 0x2220,
  21590. anglebracketleft: 0x3008,
  21591. anglebracketleftvertical: 0xFE3F,
  21592. anglebracketright: 0x3009,
  21593. anglebracketrightvertical: 0xFE40,
  21594. angleleft: 0x2329,
  21595. angleright: 0x232A,
  21596. angstrom: 0x212B,
  21597. anoteleia: 0x0387,
  21598. anudattadeva: 0x0952,
  21599. anusvarabengali: 0x0982,
  21600. anusvaradeva: 0x0902,
  21601. anusvaragujarati: 0x0A82,
  21602. aogonek: 0x0105,
  21603. apaatosquare: 0x3300,
  21604. aparen: 0x249C,
  21605. apostrophearmenian: 0x055A,
  21606. apostrophemod: 0x02BC,
  21607. apple: 0xF8FF,
  21608. approaches: 0x2250,
  21609. approxequal: 0x2248,
  21610. approxequalorimage: 0x2252,
  21611. approximatelyequal: 0x2245,
  21612. araeaekorean: 0x318E,
  21613. araeakorean: 0x318D,
  21614. arc: 0x2312,
  21615. arighthalfring: 0x1E9A,
  21616. aring: 0x00E5,
  21617. aringacute: 0x01FB,
  21618. aringbelow: 0x1E01,
  21619. arrowboth: 0x2194,
  21620. arrowdashdown: 0x21E3,
  21621. arrowdashleft: 0x21E0,
  21622. arrowdashright: 0x21E2,
  21623. arrowdashup: 0x21E1,
  21624. arrowdblboth: 0x21D4,
  21625. arrowdbldown: 0x21D3,
  21626. arrowdblleft: 0x21D0,
  21627. arrowdblright: 0x21D2,
  21628. arrowdblup: 0x21D1,
  21629. arrowdown: 0x2193,
  21630. arrowdownleft: 0x2199,
  21631. arrowdownright: 0x2198,
  21632. arrowdownwhite: 0x21E9,
  21633. arrowheaddownmod: 0x02C5,
  21634. arrowheadleftmod: 0x02C2,
  21635. arrowheadrightmod: 0x02C3,
  21636. arrowheadupmod: 0x02C4,
  21637. arrowhorizex: 0xF8E7,
  21638. arrowleft: 0x2190,
  21639. arrowleftdbl: 0x21D0,
  21640. arrowleftdblstroke: 0x21CD,
  21641. arrowleftoverright: 0x21C6,
  21642. arrowleftwhite: 0x21E6,
  21643. arrowright: 0x2192,
  21644. arrowrightdblstroke: 0x21CF,
  21645. arrowrightheavy: 0x279E,
  21646. arrowrightoverleft: 0x21C4,
  21647. arrowrightwhite: 0x21E8,
  21648. arrowtableft: 0x21E4,
  21649. arrowtabright: 0x21E5,
  21650. arrowup: 0x2191,
  21651. arrowupdn: 0x2195,
  21652. arrowupdnbse: 0x21A8,
  21653. arrowupdownbase: 0x21A8,
  21654. arrowupleft: 0x2196,
  21655. arrowupleftofdown: 0x21C5,
  21656. arrowupright: 0x2197,
  21657. arrowupwhite: 0x21E7,
  21658. arrowvertex: 0xF8E6,
  21659. asciicircum: 0x005E,
  21660. asciicircummonospace: 0xFF3E,
  21661. asciitilde: 0x007E,
  21662. asciitildemonospace: 0xFF5E,
  21663. ascript: 0x0251,
  21664. ascriptturned: 0x0252,
  21665. asmallhiragana: 0x3041,
  21666. asmallkatakana: 0x30A1,
  21667. asmallkatakanahalfwidth: 0xFF67,
  21668. asterisk: 0x002A,
  21669. asteriskaltonearabic: 0x066D,
  21670. asteriskarabic: 0x066D,
  21671. asteriskmath: 0x2217,
  21672. asteriskmonospace: 0xFF0A,
  21673. asterisksmall: 0xFE61,
  21674. asterism: 0x2042,
  21675. asuperior: 0xF6E9,
  21676. asymptoticallyequal: 0x2243,
  21677. at: 0x0040,
  21678. atilde: 0x00E3,
  21679. atmonospace: 0xFF20,
  21680. atsmall: 0xFE6B,
  21681. aturned: 0x0250,
  21682. aubengali: 0x0994,
  21683. aubopomofo: 0x3120,
  21684. audeva: 0x0914,
  21685. augujarati: 0x0A94,
  21686. augurmukhi: 0x0A14,
  21687. aulengthmarkbengali: 0x09D7,
  21688. aumatragurmukhi: 0x0A4C,
  21689. auvowelsignbengali: 0x09CC,
  21690. auvowelsigndeva: 0x094C,
  21691. auvowelsigngujarati: 0x0ACC,
  21692. avagrahadeva: 0x093D,
  21693. aybarmenian: 0x0561,
  21694. ayin: 0x05E2,
  21695. ayinaltonehebrew: 0xFB20,
  21696. ayinhebrew: 0x05E2,
  21697. b: 0x0062,
  21698. babengali: 0x09AC,
  21699. backslash: 0x005C,
  21700. backslashmonospace: 0xFF3C,
  21701. badeva: 0x092C,
  21702. bagujarati: 0x0AAC,
  21703. bagurmukhi: 0x0A2C,
  21704. bahiragana: 0x3070,
  21705. bahtthai: 0x0E3F,
  21706. bakatakana: 0x30D0,
  21707. bar: 0x007C,
  21708. barmonospace: 0xFF5C,
  21709. bbopomofo: 0x3105,
  21710. bcircle: 0x24D1,
  21711. bdotaccent: 0x1E03,
  21712. bdotbelow: 0x1E05,
  21713. beamedsixteenthnotes: 0x266C,
  21714. because: 0x2235,
  21715. becyrillic: 0x0431,
  21716. beharabic: 0x0628,
  21717. behfinalarabic: 0xFE90,
  21718. behinitialarabic: 0xFE91,
  21719. behiragana: 0x3079,
  21720. behmedialarabic: 0xFE92,
  21721. behmeeminitialarabic: 0xFC9F,
  21722. behmeemisolatedarabic: 0xFC08,
  21723. behnoonfinalarabic: 0xFC6D,
  21724. bekatakana: 0x30D9,
  21725. benarmenian: 0x0562,
  21726. bet: 0x05D1,
  21727. beta: 0x03B2,
  21728. betasymbolgreek: 0x03D0,
  21729. betdagesh: 0xFB31,
  21730. betdageshhebrew: 0xFB31,
  21731. bethebrew: 0x05D1,
  21732. betrafehebrew: 0xFB4C,
  21733. bhabengali: 0x09AD,
  21734. bhadeva: 0x092D,
  21735. bhagujarati: 0x0AAD,
  21736. bhagurmukhi: 0x0A2D,
  21737. bhook: 0x0253,
  21738. bihiragana: 0x3073,
  21739. bikatakana: 0x30D3,
  21740. bilabialclick: 0x0298,
  21741. bindigurmukhi: 0x0A02,
  21742. birusquare: 0x3331,
  21743. blackcircle: 0x25CF,
  21744. blackdiamond: 0x25C6,
  21745. blackdownpointingtriangle: 0x25BC,
  21746. blackleftpointingpointer: 0x25C4,
  21747. blackleftpointingtriangle: 0x25C0,
  21748. blacklenticularbracketleft: 0x3010,
  21749. blacklenticularbracketleftvertical: 0xFE3B,
  21750. blacklenticularbracketright: 0x3011,
  21751. blacklenticularbracketrightvertical: 0xFE3C,
  21752. blacklowerlefttriangle: 0x25E3,
  21753. blacklowerrighttriangle: 0x25E2,
  21754. blackrectangle: 0x25AC,
  21755. blackrightpointingpointer: 0x25BA,
  21756. blackrightpointingtriangle: 0x25B6,
  21757. blacksmallsquare: 0x25AA,
  21758. blacksmilingface: 0x263B,
  21759. blacksquare: 0x25A0,
  21760. blackstar: 0x2605,
  21761. blackupperlefttriangle: 0x25E4,
  21762. blackupperrighttriangle: 0x25E5,
  21763. blackuppointingsmalltriangle: 0x25B4,
  21764. blackuppointingtriangle: 0x25B2,
  21765. blank: 0x2423,
  21766. blinebelow: 0x1E07,
  21767. block: 0x2588,
  21768. bmonospace: 0xFF42,
  21769. bobaimaithai: 0x0E1A,
  21770. bohiragana: 0x307C,
  21771. bokatakana: 0x30DC,
  21772. bparen: 0x249D,
  21773. bqsquare: 0x33C3,
  21774. braceex: 0xF8F4,
  21775. braceleft: 0x007B,
  21776. braceleftbt: 0xF8F3,
  21777. braceleftmid: 0xF8F2,
  21778. braceleftmonospace: 0xFF5B,
  21779. braceleftsmall: 0xFE5B,
  21780. bracelefttp: 0xF8F1,
  21781. braceleftvertical: 0xFE37,
  21782. braceright: 0x007D,
  21783. bracerightbt: 0xF8FE,
  21784. bracerightmid: 0xF8FD,
  21785. bracerightmonospace: 0xFF5D,
  21786. bracerightsmall: 0xFE5C,
  21787. bracerighttp: 0xF8FC,
  21788. bracerightvertical: 0xFE38,
  21789. bracketleft: 0x005B,
  21790. bracketleftbt: 0xF8F0,
  21791. bracketleftex: 0xF8EF,
  21792. bracketleftmonospace: 0xFF3B,
  21793. bracketlefttp: 0xF8EE,
  21794. bracketright: 0x005D,
  21795. bracketrightbt: 0xF8FB,
  21796. bracketrightex: 0xF8FA,
  21797. bracketrightmonospace: 0xFF3D,
  21798. bracketrighttp: 0xF8F9,
  21799. breve: 0x02D8,
  21800. brevebelowcmb: 0x032E,
  21801. brevecmb: 0x0306,
  21802. breveinvertedbelowcmb: 0x032F,
  21803. breveinvertedcmb: 0x0311,
  21804. breveinverteddoublecmb: 0x0361,
  21805. bridgebelowcmb: 0x032A,
  21806. bridgeinvertedbelowcmb: 0x033A,
  21807. brokenbar: 0x00A6,
  21808. bstroke: 0x0180,
  21809. bsuperior: 0xF6EA,
  21810. btopbar: 0x0183,
  21811. buhiragana: 0x3076,
  21812. bukatakana: 0x30D6,
  21813. bullet: 0x2022,
  21814. bulletinverse: 0x25D8,
  21815. bulletoperator: 0x2219,
  21816. bullseye: 0x25CE,
  21817. c: 0x0063,
  21818. caarmenian: 0x056E,
  21819. cabengali: 0x099A,
  21820. cacute: 0x0107,
  21821. cadeva: 0x091A,
  21822. cagujarati: 0x0A9A,
  21823. cagurmukhi: 0x0A1A,
  21824. calsquare: 0x3388,
  21825. candrabindubengali: 0x0981,
  21826. candrabinducmb: 0x0310,
  21827. candrabindudeva: 0x0901,
  21828. candrabindugujarati: 0x0A81,
  21829. capslock: 0x21EA,
  21830. careof: 0x2105,
  21831. caron: 0x02C7,
  21832. caronbelowcmb: 0x032C,
  21833. caroncmb: 0x030C,
  21834. carriagereturn: 0x21B5,
  21835. cbopomofo: 0x3118,
  21836. ccaron: 0x010D,
  21837. ccedilla: 0x00E7,
  21838. ccedillaacute: 0x1E09,
  21839. ccircle: 0x24D2,
  21840. ccircumflex: 0x0109,
  21841. ccurl: 0x0255,
  21842. cdot: 0x010B,
  21843. cdotaccent: 0x010B,
  21844. cdsquare: 0x33C5,
  21845. cedilla: 0x00B8,
  21846. cedillacmb: 0x0327,
  21847. cent: 0x00A2,
  21848. centigrade: 0x2103,
  21849. centinferior: 0xF6DF,
  21850. centmonospace: 0xFFE0,
  21851. centoldstyle: 0xF7A2,
  21852. centsuperior: 0xF6E0,
  21853. chaarmenian: 0x0579,
  21854. chabengali: 0x099B,
  21855. chadeva: 0x091B,
  21856. chagujarati: 0x0A9B,
  21857. chagurmukhi: 0x0A1B,
  21858. chbopomofo: 0x3114,
  21859. cheabkhasiancyrillic: 0x04BD,
  21860. checkmark: 0x2713,
  21861. checyrillic: 0x0447,
  21862. chedescenderabkhasiancyrillic: 0x04BF,
  21863. chedescendercyrillic: 0x04B7,
  21864. chedieresiscyrillic: 0x04F5,
  21865. cheharmenian: 0x0573,
  21866. chekhakassiancyrillic: 0x04CC,
  21867. cheverticalstrokecyrillic: 0x04B9,
  21868. chi: 0x03C7,
  21869. chieuchacirclekorean: 0x3277,
  21870. chieuchaparenkorean: 0x3217,
  21871. chieuchcirclekorean: 0x3269,
  21872. chieuchkorean: 0x314A,
  21873. chieuchparenkorean: 0x3209,
  21874. chochangthai: 0x0E0A,
  21875. chochanthai: 0x0E08,
  21876. chochingthai: 0x0E09,
  21877. chochoethai: 0x0E0C,
  21878. chook: 0x0188,
  21879. cieucacirclekorean: 0x3276,
  21880. cieucaparenkorean: 0x3216,
  21881. cieuccirclekorean: 0x3268,
  21882. cieuckorean: 0x3148,
  21883. cieucparenkorean: 0x3208,
  21884. cieucuparenkorean: 0x321C,
  21885. circle: 0x25CB,
  21886. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21887. circlemultiply: 0x2297,
  21888. circleot: 0x2299,
  21889. circleplus: 0x2295,
  21890. circlepostalmark: 0x3036,
  21891. circlewithlefthalfblack: 0x25D0,
  21892. circlewithrighthalfblack: 0x25D1,
  21893. circumflex: 0x02C6,
  21894. circumflexbelowcmb: 0x032D,
  21895. circumflexcmb: 0x0302,
  21896. clear: 0x2327,
  21897. clickalveolar: 0x01C2,
  21898. clickdental: 0x01C0,
  21899. clicklateral: 0x01C1,
  21900. clickretroflex: 0x01C3,
  21901. club: 0x2663,
  21902. clubsuitblack: 0x2663,
  21903. clubsuitwhite: 0x2667,
  21904. cmcubedsquare: 0x33A4,
  21905. cmonospace: 0xFF43,
  21906. cmsquaredsquare: 0x33A0,
  21907. coarmenian: 0x0581,
  21908. colon: 0x003A,
  21909. colonmonetary: 0x20A1,
  21910. colonmonospace: 0xFF1A,
  21911. colonsign: 0x20A1,
  21912. colonsmall: 0xFE55,
  21913. colontriangularhalfmod: 0x02D1,
  21914. colontriangularmod: 0x02D0,
  21915. comma: 0x002C,
  21916. commaabovecmb: 0x0313,
  21917. commaaboverightcmb: 0x0315,
  21918. commaaccent: 0xF6C3,
  21919. commaarabic: 0x060C,
  21920. commaarmenian: 0x055D,
  21921. commainferior: 0xF6E1,
  21922. commamonospace: 0xFF0C,
  21923. commareversedabovecmb: 0x0314,
  21924. commareversedmod: 0x02BD,
  21925. commasmall: 0xFE50,
  21926. commasuperior: 0xF6E2,
  21927. commaturnedabovecmb: 0x0312,
  21928. commaturnedmod: 0x02BB,
  21929. compass: 0x263C,
  21930. congruent: 0x2245,
  21931. contourintegral: 0x222E,
  21932. control: 0x2303,
  21933. controlACK: 0x0006,
  21934. controlBEL: 0x0007,
  21935. controlBS: 0x0008,
  21936. controlCAN: 0x0018,
  21937. controlCR: 0x000D,
  21938. controlDC1: 0x0011,
  21939. controlDC2: 0x0012,
  21940. controlDC3: 0x0013,
  21941. controlDC4: 0x0014,
  21942. controlDEL: 0x007F,
  21943. controlDLE: 0x0010,
  21944. controlEM: 0x0019,
  21945. controlENQ: 0x0005,
  21946. controlEOT: 0x0004,
  21947. controlESC: 0x001B,
  21948. controlETB: 0x0017,
  21949. controlETX: 0x0003,
  21950. controlFF: 0x000C,
  21951. controlFS: 0x001C,
  21952. controlGS: 0x001D,
  21953. controlHT: 0x0009,
  21954. controlLF: 0x000A,
  21955. controlNAK: 0x0015,
  21956. controlRS: 0x001E,
  21957. controlSI: 0x000F,
  21958. controlSO: 0x000E,
  21959. controlSOT: 0x0002,
  21960. controlSTX: 0x0001,
  21961. controlSUB: 0x001A,
  21962. controlSYN: 0x0016,
  21963. controlUS: 0x001F,
  21964. controlVT: 0x000B,
  21965. copyright: 0x00A9,
  21966. copyrightsans: 0xF8E9,
  21967. copyrightserif: 0xF6D9,
  21968. cornerbracketleft: 0x300C,
  21969. cornerbracketlefthalfwidth: 0xFF62,
  21970. cornerbracketleftvertical: 0xFE41,
  21971. cornerbracketright: 0x300D,
  21972. cornerbracketrighthalfwidth: 0xFF63,
  21973. cornerbracketrightvertical: 0xFE42,
  21974. corporationsquare: 0x337F,
  21975. cosquare: 0x33C7,
  21976. coverkgsquare: 0x33C6,
  21977. cparen: 0x249E,
  21978. cruzeiro: 0x20A2,
  21979. cstretched: 0x0297,
  21980. curlyand: 0x22CF,
  21981. curlyor: 0x22CE,
  21982. currency: 0x00A4,
  21983. cyrBreve: 0xF6D1,
  21984. cyrFlex: 0xF6D2,
  21985. cyrbreve: 0xF6D4,
  21986. cyrflex: 0xF6D5,
  21987. d: 0x0064,
  21988. daarmenian: 0x0564,
  21989. dabengali: 0x09A6,
  21990. dadarabic: 0x0636,
  21991. dadeva: 0x0926,
  21992. dadfinalarabic: 0xFEBE,
  21993. dadinitialarabic: 0xFEBF,
  21994. dadmedialarabic: 0xFEC0,
  21995. dagesh: 0x05BC,
  21996. dageshhebrew: 0x05BC,
  21997. dagger: 0x2020,
  21998. daggerdbl: 0x2021,
  21999. dagujarati: 0x0AA6,
  22000. dagurmukhi: 0x0A26,
  22001. dahiragana: 0x3060,
  22002. dakatakana: 0x30C0,
  22003. dalarabic: 0x062F,
  22004. dalet: 0x05D3,
  22005. daletdagesh: 0xFB33,
  22006. daletdageshhebrew: 0xFB33,
  22007. dalethebrew: 0x05D3,
  22008. dalfinalarabic: 0xFEAA,
  22009. dammaarabic: 0x064F,
  22010. dammalowarabic: 0x064F,
  22011. dammatanaltonearabic: 0x064C,
  22012. dammatanarabic: 0x064C,
  22013. danda: 0x0964,
  22014. dargahebrew: 0x05A7,
  22015. dargalefthebrew: 0x05A7,
  22016. dasiapneumatacyrilliccmb: 0x0485,
  22017. dblGrave: 0xF6D3,
  22018. dblanglebracketleft: 0x300A,
  22019. dblanglebracketleftvertical: 0xFE3D,
  22020. dblanglebracketright: 0x300B,
  22021. dblanglebracketrightvertical: 0xFE3E,
  22022. dblarchinvertedbelowcmb: 0x032B,
  22023. dblarrowleft: 0x21D4,
  22024. dblarrowright: 0x21D2,
  22025. dbldanda: 0x0965,
  22026. dblgrave: 0xF6D6,
  22027. dblgravecmb: 0x030F,
  22028. dblintegral: 0x222C,
  22029. dbllowline: 0x2017,
  22030. dbllowlinecmb: 0x0333,
  22031. dbloverlinecmb: 0x033F,
  22032. dblprimemod: 0x02BA,
  22033. dblverticalbar: 0x2016,
  22034. dblverticallineabovecmb: 0x030E,
  22035. dbopomofo: 0x3109,
  22036. dbsquare: 0x33C8,
  22037. dcaron: 0x010F,
  22038. dcedilla: 0x1E11,
  22039. dcircle: 0x24D3,
  22040. dcircumflexbelow: 0x1E13,
  22041. dcroat: 0x0111,
  22042. ddabengali: 0x09A1,
  22043. ddadeva: 0x0921,
  22044. ddagujarati: 0x0AA1,
  22045. ddagurmukhi: 0x0A21,
  22046. ddalarabic: 0x0688,
  22047. ddalfinalarabic: 0xFB89,
  22048. dddhadeva: 0x095C,
  22049. ddhabengali: 0x09A2,
  22050. ddhadeva: 0x0922,
  22051. ddhagujarati: 0x0AA2,
  22052. ddhagurmukhi: 0x0A22,
  22053. ddotaccent: 0x1E0B,
  22054. ddotbelow: 0x1E0D,
  22055. decimalseparatorarabic: 0x066B,
  22056. decimalseparatorpersian: 0x066B,
  22057. decyrillic: 0x0434,
  22058. degree: 0x00B0,
  22059. dehihebrew: 0x05AD,
  22060. dehiragana: 0x3067,
  22061. deicoptic: 0x03EF,
  22062. dekatakana: 0x30C7,
  22063. deleteleft: 0x232B,
  22064. deleteright: 0x2326,
  22065. delta: 0x03B4,
  22066. deltaturned: 0x018D,
  22067. denominatorminusonenumeratorbengali: 0x09F8,
  22068. dezh: 0x02A4,
  22069. dhabengali: 0x09A7,
  22070. dhadeva: 0x0927,
  22071. dhagujarati: 0x0AA7,
  22072. dhagurmukhi: 0x0A27,
  22073. dhook: 0x0257,
  22074. dialytikatonos: 0x0385,
  22075. dialytikatonoscmb: 0x0344,
  22076. diamond: 0x2666,
  22077. diamondsuitwhite: 0x2662,
  22078. dieresis: 0x00A8,
  22079. dieresisacute: 0xF6D7,
  22080. dieresisbelowcmb: 0x0324,
  22081. dieresiscmb: 0x0308,
  22082. dieresisgrave: 0xF6D8,
  22083. dieresistonos: 0x0385,
  22084. dihiragana: 0x3062,
  22085. dikatakana: 0x30C2,
  22086. dittomark: 0x3003,
  22087. divide: 0x00F7,
  22088. divides: 0x2223,
  22089. divisionslash: 0x2215,
  22090. djecyrillic: 0x0452,
  22091. dkshade: 0x2593,
  22092. dlinebelow: 0x1E0F,
  22093. dlsquare: 0x3397,
  22094. dmacron: 0x0111,
  22095. dmonospace: 0xFF44,
  22096. dnblock: 0x2584,
  22097. dochadathai: 0x0E0E,
  22098. dodekthai: 0x0E14,
  22099. dohiragana: 0x3069,
  22100. dokatakana: 0x30C9,
  22101. dollar: 0x0024,
  22102. dollarinferior: 0xF6E3,
  22103. dollarmonospace: 0xFF04,
  22104. dollaroldstyle: 0xF724,
  22105. dollarsmall: 0xFE69,
  22106. dollarsuperior: 0xF6E4,
  22107. dong: 0x20AB,
  22108. dorusquare: 0x3326,
  22109. dotaccent: 0x02D9,
  22110. dotaccentcmb: 0x0307,
  22111. dotbelowcmb: 0x0323,
  22112. dotbelowcomb: 0x0323,
  22113. dotkatakana: 0x30FB,
  22114. dotlessi: 0x0131,
  22115. dotlessj: 0xF6BE,
  22116. dotlessjstrokehook: 0x0284,
  22117. dotmath: 0x22C5,
  22118. dottedcircle: 0x25CC,
  22119. doubleyodpatah: 0xFB1F,
  22120. doubleyodpatahhebrew: 0xFB1F,
  22121. downtackbelowcmb: 0x031E,
  22122. downtackmod: 0x02D5,
  22123. dparen: 0x249F,
  22124. dsuperior: 0xF6EB,
  22125. dtail: 0x0256,
  22126. dtopbar: 0x018C,
  22127. duhiragana: 0x3065,
  22128. dukatakana: 0x30C5,
  22129. dz: 0x01F3,
  22130. dzaltone: 0x02A3,
  22131. dzcaron: 0x01C6,
  22132. dzcurl: 0x02A5,
  22133. dzeabkhasiancyrillic: 0x04E1,
  22134. dzecyrillic: 0x0455,
  22135. dzhecyrillic: 0x045F,
  22136. e: 0x0065,
  22137. eacute: 0x00E9,
  22138. earth: 0x2641,
  22139. ebengali: 0x098F,
  22140. ebopomofo: 0x311C,
  22141. ebreve: 0x0115,
  22142. ecandradeva: 0x090D,
  22143. ecandragujarati: 0x0A8D,
  22144. ecandravowelsigndeva: 0x0945,
  22145. ecandravowelsigngujarati: 0x0AC5,
  22146. ecaron: 0x011B,
  22147. ecedillabreve: 0x1E1D,
  22148. echarmenian: 0x0565,
  22149. echyiwnarmenian: 0x0587,
  22150. ecircle: 0x24D4,
  22151. ecircumflex: 0x00EA,
  22152. ecircumflexacute: 0x1EBF,
  22153. ecircumflexbelow: 0x1E19,
  22154. ecircumflexdotbelow: 0x1EC7,
  22155. ecircumflexgrave: 0x1EC1,
  22156. ecircumflexhookabove: 0x1EC3,
  22157. ecircumflextilde: 0x1EC5,
  22158. ecyrillic: 0x0454,
  22159. edblgrave: 0x0205,
  22160. edeva: 0x090F,
  22161. edieresis: 0x00EB,
  22162. edot: 0x0117,
  22163. edotaccent: 0x0117,
  22164. edotbelow: 0x1EB9,
  22165. eegurmukhi: 0x0A0F,
  22166. eematragurmukhi: 0x0A47,
  22167. efcyrillic: 0x0444,
  22168. egrave: 0x00E8,
  22169. egujarati: 0x0A8F,
  22170. eharmenian: 0x0567,
  22171. ehbopomofo: 0x311D,
  22172. ehiragana: 0x3048,
  22173. ehookabove: 0x1EBB,
  22174. eibopomofo: 0x311F,
  22175. eight: 0x0038,
  22176. eightarabic: 0x0668,
  22177. eightbengali: 0x09EE,
  22178. eightcircle: 0x2467,
  22179. eightcircleinversesansserif: 0x2791,
  22180. eightdeva: 0x096E,
  22181. eighteencircle: 0x2471,
  22182. eighteenparen: 0x2485,
  22183. eighteenperiod: 0x2499,
  22184. eightgujarati: 0x0AEE,
  22185. eightgurmukhi: 0x0A6E,
  22186. eighthackarabic: 0x0668,
  22187. eighthangzhou: 0x3028,
  22188. eighthnotebeamed: 0x266B,
  22189. eightideographicparen: 0x3227,
  22190. eightinferior: 0x2088,
  22191. eightmonospace: 0xFF18,
  22192. eightoldstyle: 0xF738,
  22193. eightparen: 0x247B,
  22194. eightperiod: 0x248F,
  22195. eightpersian: 0x06F8,
  22196. eightroman: 0x2177,
  22197. eightsuperior: 0x2078,
  22198. eightthai: 0x0E58,
  22199. einvertedbreve: 0x0207,
  22200. eiotifiedcyrillic: 0x0465,
  22201. ekatakana: 0x30A8,
  22202. ekatakanahalfwidth: 0xFF74,
  22203. ekonkargurmukhi: 0x0A74,
  22204. ekorean: 0x3154,
  22205. elcyrillic: 0x043B,
  22206. element: 0x2208,
  22207. elevencircle: 0x246A,
  22208. elevenparen: 0x247E,
  22209. elevenperiod: 0x2492,
  22210. elevenroman: 0x217A,
  22211. ellipsis: 0x2026,
  22212. ellipsisvertical: 0x22EE,
  22213. emacron: 0x0113,
  22214. emacronacute: 0x1E17,
  22215. emacrongrave: 0x1E15,
  22216. emcyrillic: 0x043C,
  22217. emdash: 0x2014,
  22218. emdashvertical: 0xFE31,
  22219. emonospace: 0xFF45,
  22220. emphasismarkarmenian: 0x055B,
  22221. emptyset: 0x2205,
  22222. enbopomofo: 0x3123,
  22223. encyrillic: 0x043D,
  22224. endash: 0x2013,
  22225. endashvertical: 0xFE32,
  22226. endescendercyrillic: 0x04A3,
  22227. eng: 0x014B,
  22228. engbopomofo: 0x3125,
  22229. enghecyrillic: 0x04A5,
  22230. enhookcyrillic: 0x04C8,
  22231. enspace: 0x2002,
  22232. eogonek: 0x0119,
  22233. eokorean: 0x3153,
  22234. eopen: 0x025B,
  22235. eopenclosed: 0x029A,
  22236. eopenreversed: 0x025C,
  22237. eopenreversedclosed: 0x025E,
  22238. eopenreversedhook: 0x025D,
  22239. eparen: 0x24A0,
  22240. epsilon: 0x03B5,
  22241. epsilontonos: 0x03AD,
  22242. equal: 0x003D,
  22243. equalmonospace: 0xFF1D,
  22244. equalsmall: 0xFE66,
  22245. equalsuperior: 0x207C,
  22246. equivalence: 0x2261,
  22247. erbopomofo: 0x3126,
  22248. ercyrillic: 0x0440,
  22249. ereversed: 0x0258,
  22250. ereversedcyrillic: 0x044D,
  22251. escyrillic: 0x0441,
  22252. esdescendercyrillic: 0x04AB,
  22253. esh: 0x0283,
  22254. eshcurl: 0x0286,
  22255. eshortdeva: 0x090E,
  22256. eshortvowelsigndeva: 0x0946,
  22257. eshreversedloop: 0x01AA,
  22258. eshsquatreversed: 0x0285,
  22259. esmallhiragana: 0x3047,
  22260. esmallkatakana: 0x30A7,
  22261. esmallkatakanahalfwidth: 0xFF6A,
  22262. estimated: 0x212E,
  22263. esuperior: 0xF6EC,
  22264. eta: 0x03B7,
  22265. etarmenian: 0x0568,
  22266. etatonos: 0x03AE,
  22267. eth: 0x00F0,
  22268. etilde: 0x1EBD,
  22269. etildebelow: 0x1E1B,
  22270. etnahtafoukhhebrew: 0x0591,
  22271. etnahtafoukhlefthebrew: 0x0591,
  22272. etnahtahebrew: 0x0591,
  22273. etnahtalefthebrew: 0x0591,
  22274. eturned: 0x01DD,
  22275. eukorean: 0x3161,
  22276. euro: 0x20AC,
  22277. evowelsignbengali: 0x09C7,
  22278. evowelsigndeva: 0x0947,
  22279. evowelsigngujarati: 0x0AC7,
  22280. exclam: 0x0021,
  22281. exclamarmenian: 0x055C,
  22282. exclamdbl: 0x203C,
  22283. exclamdown: 0x00A1,
  22284. exclamdownsmall: 0xF7A1,
  22285. exclammonospace: 0xFF01,
  22286. exclamsmall: 0xF721,
  22287. existential: 0x2203,
  22288. ezh: 0x0292,
  22289. ezhcaron: 0x01EF,
  22290. ezhcurl: 0x0293,
  22291. ezhreversed: 0x01B9,
  22292. ezhtail: 0x01BA,
  22293. f: 0x0066,
  22294. fadeva: 0x095E,
  22295. fagurmukhi: 0x0A5E,
  22296. fahrenheit: 0x2109,
  22297. fathaarabic: 0x064E,
  22298. fathalowarabic: 0x064E,
  22299. fathatanarabic: 0x064B,
  22300. fbopomofo: 0x3108,
  22301. fcircle: 0x24D5,
  22302. fdotaccent: 0x1E1F,
  22303. feharabic: 0x0641,
  22304. feharmenian: 0x0586,
  22305. fehfinalarabic: 0xFED2,
  22306. fehinitialarabic: 0xFED3,
  22307. fehmedialarabic: 0xFED4,
  22308. feicoptic: 0x03E5,
  22309. female: 0x2640,
  22310. ff: 0xFB00,
  22311. ffi: 0xFB03,
  22312. ffl: 0xFB04,
  22313. fi: 0xFB01,
  22314. fifteencircle: 0x246E,
  22315. fifteenparen: 0x2482,
  22316. fifteenperiod: 0x2496,
  22317. figuredash: 0x2012,
  22318. filledbox: 0x25A0,
  22319. filledrect: 0x25AC,
  22320. finalkaf: 0x05DA,
  22321. finalkafdagesh: 0xFB3A,
  22322. finalkafdageshhebrew: 0xFB3A,
  22323. finalkafhebrew: 0x05DA,
  22324. finalmem: 0x05DD,
  22325. finalmemhebrew: 0x05DD,
  22326. finalnun: 0x05DF,
  22327. finalnunhebrew: 0x05DF,
  22328. finalpe: 0x05E3,
  22329. finalpehebrew: 0x05E3,
  22330. finaltsadi: 0x05E5,
  22331. finaltsadihebrew: 0x05E5,
  22332. firsttonechinese: 0x02C9,
  22333. fisheye: 0x25C9,
  22334. fitacyrillic: 0x0473,
  22335. five: 0x0035,
  22336. fivearabic: 0x0665,
  22337. fivebengali: 0x09EB,
  22338. fivecircle: 0x2464,
  22339. fivecircleinversesansserif: 0x278E,
  22340. fivedeva: 0x096B,
  22341. fiveeighths: 0x215D,
  22342. fivegujarati: 0x0AEB,
  22343. fivegurmukhi: 0x0A6B,
  22344. fivehackarabic: 0x0665,
  22345. fivehangzhou: 0x3025,
  22346. fiveideographicparen: 0x3224,
  22347. fiveinferior: 0x2085,
  22348. fivemonospace: 0xFF15,
  22349. fiveoldstyle: 0xF735,
  22350. fiveparen: 0x2478,
  22351. fiveperiod: 0x248C,
  22352. fivepersian: 0x06F5,
  22353. fiveroman: 0x2174,
  22354. fivesuperior: 0x2075,
  22355. fivethai: 0x0E55,
  22356. fl: 0xFB02,
  22357. florin: 0x0192,
  22358. fmonospace: 0xFF46,
  22359. fmsquare: 0x3399,
  22360. fofanthai: 0x0E1F,
  22361. fofathai: 0x0E1D,
  22362. fongmanthai: 0x0E4F,
  22363. forall: 0x2200,
  22364. four: 0x0034,
  22365. fourarabic: 0x0664,
  22366. fourbengali: 0x09EA,
  22367. fourcircle: 0x2463,
  22368. fourcircleinversesansserif: 0x278D,
  22369. fourdeva: 0x096A,
  22370. fourgujarati: 0x0AEA,
  22371. fourgurmukhi: 0x0A6A,
  22372. fourhackarabic: 0x0664,
  22373. fourhangzhou: 0x3024,
  22374. fourideographicparen: 0x3223,
  22375. fourinferior: 0x2084,
  22376. fourmonospace: 0xFF14,
  22377. fournumeratorbengali: 0x09F7,
  22378. fouroldstyle: 0xF734,
  22379. fourparen: 0x2477,
  22380. fourperiod: 0x248B,
  22381. fourpersian: 0x06F4,
  22382. fourroman: 0x2173,
  22383. foursuperior: 0x2074,
  22384. fourteencircle: 0x246D,
  22385. fourteenparen: 0x2481,
  22386. fourteenperiod: 0x2495,
  22387. fourthai: 0x0E54,
  22388. fourthtonechinese: 0x02CB,
  22389. fparen: 0x24A1,
  22390. fraction: 0x2044,
  22391. franc: 0x20A3,
  22392. g: 0x0067,
  22393. gabengali: 0x0997,
  22394. gacute: 0x01F5,
  22395. gadeva: 0x0917,
  22396. gafarabic: 0x06AF,
  22397. gaffinalarabic: 0xFB93,
  22398. gafinitialarabic: 0xFB94,
  22399. gafmedialarabic: 0xFB95,
  22400. gagujarati: 0x0A97,
  22401. gagurmukhi: 0x0A17,
  22402. gahiragana: 0x304C,
  22403. gakatakana: 0x30AC,
  22404. gamma: 0x03B3,
  22405. gammalatinsmall: 0x0263,
  22406. gammasuperior: 0x02E0,
  22407. gangiacoptic: 0x03EB,
  22408. gbopomofo: 0x310D,
  22409. gbreve: 0x011F,
  22410. gcaron: 0x01E7,
  22411. gcedilla: 0x0123,
  22412. gcircle: 0x24D6,
  22413. gcircumflex: 0x011D,
  22414. gcommaaccent: 0x0123,
  22415. gdot: 0x0121,
  22416. gdotaccent: 0x0121,
  22417. gecyrillic: 0x0433,
  22418. gehiragana: 0x3052,
  22419. gekatakana: 0x30B2,
  22420. geometricallyequal: 0x2251,
  22421. gereshaccenthebrew: 0x059C,
  22422. gereshhebrew: 0x05F3,
  22423. gereshmuqdamhebrew: 0x059D,
  22424. germandbls: 0x00DF,
  22425. gershayimaccenthebrew: 0x059E,
  22426. gershayimhebrew: 0x05F4,
  22427. getamark: 0x3013,
  22428. ghabengali: 0x0998,
  22429. ghadarmenian: 0x0572,
  22430. ghadeva: 0x0918,
  22431. ghagujarati: 0x0A98,
  22432. ghagurmukhi: 0x0A18,
  22433. ghainarabic: 0x063A,
  22434. ghainfinalarabic: 0xFECE,
  22435. ghaininitialarabic: 0xFECF,
  22436. ghainmedialarabic: 0xFED0,
  22437. ghemiddlehookcyrillic: 0x0495,
  22438. ghestrokecyrillic: 0x0493,
  22439. gheupturncyrillic: 0x0491,
  22440. ghhadeva: 0x095A,
  22441. ghhagurmukhi: 0x0A5A,
  22442. ghook: 0x0260,
  22443. ghzsquare: 0x3393,
  22444. gihiragana: 0x304E,
  22445. gikatakana: 0x30AE,
  22446. gimarmenian: 0x0563,
  22447. gimel: 0x05D2,
  22448. gimeldagesh: 0xFB32,
  22449. gimeldageshhebrew: 0xFB32,
  22450. gimelhebrew: 0x05D2,
  22451. gjecyrillic: 0x0453,
  22452. glottalinvertedstroke: 0x01BE,
  22453. glottalstop: 0x0294,
  22454. glottalstopinverted: 0x0296,
  22455. glottalstopmod: 0x02C0,
  22456. glottalstopreversed: 0x0295,
  22457. glottalstopreversedmod: 0x02C1,
  22458. glottalstopreversedsuperior: 0x02E4,
  22459. glottalstopstroke: 0x02A1,
  22460. glottalstopstrokereversed: 0x02A2,
  22461. gmacron: 0x1E21,
  22462. gmonospace: 0xFF47,
  22463. gohiragana: 0x3054,
  22464. gokatakana: 0x30B4,
  22465. gparen: 0x24A2,
  22466. gpasquare: 0x33AC,
  22467. gradient: 0x2207,
  22468. grave: 0x0060,
  22469. gravebelowcmb: 0x0316,
  22470. gravecmb: 0x0300,
  22471. gravecomb: 0x0300,
  22472. gravedeva: 0x0953,
  22473. gravelowmod: 0x02CE,
  22474. gravemonospace: 0xFF40,
  22475. gravetonecmb: 0x0340,
  22476. greater: 0x003E,
  22477. greaterequal: 0x2265,
  22478. greaterequalorless: 0x22DB,
  22479. greatermonospace: 0xFF1E,
  22480. greaterorequivalent: 0x2273,
  22481. greaterorless: 0x2277,
  22482. greateroverequal: 0x2267,
  22483. greatersmall: 0xFE65,
  22484. gscript: 0x0261,
  22485. gstroke: 0x01E5,
  22486. guhiragana: 0x3050,
  22487. guillemotleft: 0x00AB,
  22488. guillemotright: 0x00BB,
  22489. guilsinglleft: 0x2039,
  22490. guilsinglright: 0x203A,
  22491. gukatakana: 0x30B0,
  22492. guramusquare: 0x3318,
  22493. gysquare: 0x33C9,
  22494. h: 0x0068,
  22495. haabkhasiancyrillic: 0x04A9,
  22496. haaltonearabic: 0x06C1,
  22497. habengali: 0x09B9,
  22498. hadescendercyrillic: 0x04B3,
  22499. hadeva: 0x0939,
  22500. hagujarati: 0x0AB9,
  22501. hagurmukhi: 0x0A39,
  22502. haharabic: 0x062D,
  22503. hahfinalarabic: 0xFEA2,
  22504. hahinitialarabic: 0xFEA3,
  22505. hahiragana: 0x306F,
  22506. hahmedialarabic: 0xFEA4,
  22507. haitusquare: 0x332A,
  22508. hakatakana: 0x30CF,
  22509. hakatakanahalfwidth: 0xFF8A,
  22510. halantgurmukhi: 0x0A4D,
  22511. hamzaarabic: 0x0621,
  22512. hamzalowarabic: 0x0621,
  22513. hangulfiller: 0x3164,
  22514. hardsigncyrillic: 0x044A,
  22515. harpoonleftbarbup: 0x21BC,
  22516. harpoonrightbarbup: 0x21C0,
  22517. hasquare: 0x33CA,
  22518. hatafpatah: 0x05B2,
  22519. hatafpatah16: 0x05B2,
  22520. hatafpatah23: 0x05B2,
  22521. hatafpatah2f: 0x05B2,
  22522. hatafpatahhebrew: 0x05B2,
  22523. hatafpatahnarrowhebrew: 0x05B2,
  22524. hatafpatahquarterhebrew: 0x05B2,
  22525. hatafpatahwidehebrew: 0x05B2,
  22526. hatafqamats: 0x05B3,
  22527. hatafqamats1b: 0x05B3,
  22528. hatafqamats28: 0x05B3,
  22529. hatafqamats34: 0x05B3,
  22530. hatafqamatshebrew: 0x05B3,
  22531. hatafqamatsnarrowhebrew: 0x05B3,
  22532. hatafqamatsquarterhebrew: 0x05B3,
  22533. hatafqamatswidehebrew: 0x05B3,
  22534. hatafsegol: 0x05B1,
  22535. hatafsegol17: 0x05B1,
  22536. hatafsegol24: 0x05B1,
  22537. hatafsegol30: 0x05B1,
  22538. hatafsegolhebrew: 0x05B1,
  22539. hatafsegolnarrowhebrew: 0x05B1,
  22540. hatafsegolquarterhebrew: 0x05B1,
  22541. hatafsegolwidehebrew: 0x05B1,
  22542. hbar: 0x0127,
  22543. hbopomofo: 0x310F,
  22544. hbrevebelow: 0x1E2B,
  22545. hcedilla: 0x1E29,
  22546. hcircle: 0x24D7,
  22547. hcircumflex: 0x0125,
  22548. hdieresis: 0x1E27,
  22549. hdotaccent: 0x1E23,
  22550. hdotbelow: 0x1E25,
  22551. he: 0x05D4,
  22552. heart: 0x2665,
  22553. heartsuitblack: 0x2665,
  22554. heartsuitwhite: 0x2661,
  22555. hedagesh: 0xFB34,
  22556. hedageshhebrew: 0xFB34,
  22557. hehaltonearabic: 0x06C1,
  22558. heharabic: 0x0647,
  22559. hehebrew: 0x05D4,
  22560. hehfinalaltonearabic: 0xFBA7,
  22561. hehfinalalttwoarabic: 0xFEEA,
  22562. hehfinalarabic: 0xFEEA,
  22563. hehhamzaabovefinalarabic: 0xFBA5,
  22564. hehhamzaaboveisolatedarabic: 0xFBA4,
  22565. hehinitialaltonearabic: 0xFBA8,
  22566. hehinitialarabic: 0xFEEB,
  22567. hehiragana: 0x3078,
  22568. hehmedialaltonearabic: 0xFBA9,
  22569. hehmedialarabic: 0xFEEC,
  22570. heiseierasquare: 0x337B,
  22571. hekatakana: 0x30D8,
  22572. hekatakanahalfwidth: 0xFF8D,
  22573. hekutaarusquare: 0x3336,
  22574. henghook: 0x0267,
  22575. herutusquare: 0x3339,
  22576. het: 0x05D7,
  22577. hethebrew: 0x05D7,
  22578. hhook: 0x0266,
  22579. hhooksuperior: 0x02B1,
  22580. hieuhacirclekorean: 0x327B,
  22581. hieuhaparenkorean: 0x321B,
  22582. hieuhcirclekorean: 0x326D,
  22583. hieuhkorean: 0x314E,
  22584. hieuhparenkorean: 0x320D,
  22585. hihiragana: 0x3072,
  22586. hikatakana: 0x30D2,
  22587. hikatakanahalfwidth: 0xFF8B,
  22588. hiriq: 0x05B4,
  22589. hiriq14: 0x05B4,
  22590. hiriq21: 0x05B4,
  22591. hiriq2d: 0x05B4,
  22592. hiriqhebrew: 0x05B4,
  22593. hiriqnarrowhebrew: 0x05B4,
  22594. hiriqquarterhebrew: 0x05B4,
  22595. hiriqwidehebrew: 0x05B4,
  22596. hlinebelow: 0x1E96,
  22597. hmonospace: 0xFF48,
  22598. hoarmenian: 0x0570,
  22599. hohipthai: 0x0E2B,
  22600. hohiragana: 0x307B,
  22601. hokatakana: 0x30DB,
  22602. hokatakanahalfwidth: 0xFF8E,
  22603. holam: 0x05B9,
  22604. holam19: 0x05B9,
  22605. holam26: 0x05B9,
  22606. holam32: 0x05B9,
  22607. holamhebrew: 0x05B9,
  22608. holamnarrowhebrew: 0x05B9,
  22609. holamquarterhebrew: 0x05B9,
  22610. holamwidehebrew: 0x05B9,
  22611. honokhukthai: 0x0E2E,
  22612. hookabovecomb: 0x0309,
  22613. hookcmb: 0x0309,
  22614. hookpalatalizedbelowcmb: 0x0321,
  22615. hookretroflexbelowcmb: 0x0322,
  22616. hoonsquare: 0x3342,
  22617. horicoptic: 0x03E9,
  22618. horizontalbar: 0x2015,
  22619. horncmb: 0x031B,
  22620. hotsprings: 0x2668,
  22621. house: 0x2302,
  22622. hparen: 0x24A3,
  22623. hsuperior: 0x02B0,
  22624. hturned: 0x0265,
  22625. huhiragana: 0x3075,
  22626. huiitosquare: 0x3333,
  22627. hukatakana: 0x30D5,
  22628. hukatakanahalfwidth: 0xFF8C,
  22629. hungarumlaut: 0x02DD,
  22630. hungarumlautcmb: 0x030B,
  22631. hv: 0x0195,
  22632. hyphen: 0x002D,
  22633. hypheninferior: 0xF6E5,
  22634. hyphenmonospace: 0xFF0D,
  22635. hyphensmall: 0xFE63,
  22636. hyphensuperior: 0xF6E6,
  22637. hyphentwo: 0x2010,
  22638. i: 0x0069,
  22639. iacute: 0x00ED,
  22640. iacyrillic: 0x044F,
  22641. ibengali: 0x0987,
  22642. ibopomofo: 0x3127,
  22643. ibreve: 0x012D,
  22644. icaron: 0x01D0,
  22645. icircle: 0x24D8,
  22646. icircumflex: 0x00EE,
  22647. icyrillic: 0x0456,
  22648. idblgrave: 0x0209,
  22649. ideographearthcircle: 0x328F,
  22650. ideographfirecircle: 0x328B,
  22651. ideographicallianceparen: 0x323F,
  22652. ideographiccallparen: 0x323A,
  22653. ideographiccentrecircle: 0x32A5,
  22654. ideographicclose: 0x3006,
  22655. ideographiccomma: 0x3001,
  22656. ideographiccommaleft: 0xFF64,
  22657. ideographiccongratulationparen: 0x3237,
  22658. ideographiccorrectcircle: 0x32A3,
  22659. ideographicearthparen: 0x322F,
  22660. ideographicenterpriseparen: 0x323D,
  22661. ideographicexcellentcircle: 0x329D,
  22662. ideographicfestivalparen: 0x3240,
  22663. ideographicfinancialcircle: 0x3296,
  22664. ideographicfinancialparen: 0x3236,
  22665. ideographicfireparen: 0x322B,
  22666. ideographichaveparen: 0x3232,
  22667. ideographichighcircle: 0x32A4,
  22668. ideographiciterationmark: 0x3005,
  22669. ideographiclaborcircle: 0x3298,
  22670. ideographiclaborparen: 0x3238,
  22671. ideographicleftcircle: 0x32A7,
  22672. ideographiclowcircle: 0x32A6,
  22673. ideographicmedicinecircle: 0x32A9,
  22674. ideographicmetalparen: 0x322E,
  22675. ideographicmoonparen: 0x322A,
  22676. ideographicnameparen: 0x3234,
  22677. ideographicperiod: 0x3002,
  22678. ideographicprintcircle: 0x329E,
  22679. ideographicreachparen: 0x3243,
  22680. ideographicrepresentparen: 0x3239,
  22681. ideographicresourceparen: 0x323E,
  22682. ideographicrightcircle: 0x32A8,
  22683. ideographicsecretcircle: 0x3299,
  22684. ideographicselfparen: 0x3242,
  22685. ideographicsocietyparen: 0x3233,
  22686. ideographicspace: 0x3000,
  22687. ideographicspecialparen: 0x3235,
  22688. ideographicstockparen: 0x3231,
  22689. ideographicstudyparen: 0x323B,
  22690. ideographicsunparen: 0x3230,
  22691. ideographicsuperviseparen: 0x323C,
  22692. ideographicwaterparen: 0x322C,
  22693. ideographicwoodparen: 0x322D,
  22694. ideographiczero: 0x3007,
  22695. ideographmetalcircle: 0x328E,
  22696. ideographmooncircle: 0x328A,
  22697. ideographnamecircle: 0x3294,
  22698. ideographsuncircle: 0x3290,
  22699. ideographwatercircle: 0x328C,
  22700. ideographwoodcircle: 0x328D,
  22701. ideva: 0x0907,
  22702. idieresis: 0x00EF,
  22703. idieresisacute: 0x1E2F,
  22704. idieresiscyrillic: 0x04E5,
  22705. idotbelow: 0x1ECB,
  22706. iebrevecyrillic: 0x04D7,
  22707. iecyrillic: 0x0435,
  22708. ieungacirclekorean: 0x3275,
  22709. ieungaparenkorean: 0x3215,
  22710. ieungcirclekorean: 0x3267,
  22711. ieungkorean: 0x3147,
  22712. ieungparenkorean: 0x3207,
  22713. igrave: 0x00EC,
  22714. igujarati: 0x0A87,
  22715. igurmukhi: 0x0A07,
  22716. ihiragana: 0x3044,
  22717. ihookabove: 0x1EC9,
  22718. iibengali: 0x0988,
  22719. iicyrillic: 0x0438,
  22720. iideva: 0x0908,
  22721. iigujarati: 0x0A88,
  22722. iigurmukhi: 0x0A08,
  22723. iimatragurmukhi: 0x0A40,
  22724. iinvertedbreve: 0x020B,
  22725. iishortcyrillic: 0x0439,
  22726. iivowelsignbengali: 0x09C0,
  22727. iivowelsigndeva: 0x0940,
  22728. iivowelsigngujarati: 0x0AC0,
  22729. ij: 0x0133,
  22730. ikatakana: 0x30A4,
  22731. ikatakanahalfwidth: 0xFF72,
  22732. ikorean: 0x3163,
  22733. ilde: 0x02DC,
  22734. iluyhebrew: 0x05AC,
  22735. imacron: 0x012B,
  22736. imacroncyrillic: 0x04E3,
  22737. imageorapproximatelyequal: 0x2253,
  22738. imatragurmukhi: 0x0A3F,
  22739. imonospace: 0xFF49,
  22740. increment: 0x2206,
  22741. infinity: 0x221E,
  22742. iniarmenian: 0x056B,
  22743. integral: 0x222B,
  22744. integralbottom: 0x2321,
  22745. integralbt: 0x2321,
  22746. integralex: 0xF8F5,
  22747. integraltop: 0x2320,
  22748. integraltp: 0x2320,
  22749. intersection: 0x2229,
  22750. intisquare: 0x3305,
  22751. invbullet: 0x25D8,
  22752. invcircle: 0x25D9,
  22753. invsmileface: 0x263B,
  22754. iocyrillic: 0x0451,
  22755. iogonek: 0x012F,
  22756. iota: 0x03B9,
  22757. iotadieresis: 0x03CA,
  22758. iotadieresistonos: 0x0390,
  22759. iotalatin: 0x0269,
  22760. iotatonos: 0x03AF,
  22761. iparen: 0x24A4,
  22762. irigurmukhi: 0x0A72,
  22763. ismallhiragana: 0x3043,
  22764. ismallkatakana: 0x30A3,
  22765. ismallkatakanahalfwidth: 0xFF68,
  22766. issharbengali: 0x09FA,
  22767. istroke: 0x0268,
  22768. isuperior: 0xF6ED,
  22769. iterationhiragana: 0x309D,
  22770. iterationkatakana: 0x30FD,
  22771. itilde: 0x0129,
  22772. itildebelow: 0x1E2D,
  22773. iubopomofo: 0x3129,
  22774. iucyrillic: 0x044E,
  22775. ivowelsignbengali: 0x09BF,
  22776. ivowelsigndeva: 0x093F,
  22777. ivowelsigngujarati: 0x0ABF,
  22778. izhitsacyrillic: 0x0475,
  22779. izhitsadblgravecyrillic: 0x0477,
  22780. j: 0x006A,
  22781. jaarmenian: 0x0571,
  22782. jabengali: 0x099C,
  22783. jadeva: 0x091C,
  22784. jagujarati: 0x0A9C,
  22785. jagurmukhi: 0x0A1C,
  22786. jbopomofo: 0x3110,
  22787. jcaron: 0x01F0,
  22788. jcircle: 0x24D9,
  22789. jcircumflex: 0x0135,
  22790. jcrossedtail: 0x029D,
  22791. jdotlessstroke: 0x025F,
  22792. jecyrillic: 0x0458,
  22793. jeemarabic: 0x062C,
  22794. jeemfinalarabic: 0xFE9E,
  22795. jeeminitialarabic: 0xFE9F,
  22796. jeemmedialarabic: 0xFEA0,
  22797. jeharabic: 0x0698,
  22798. jehfinalarabic: 0xFB8B,
  22799. jhabengali: 0x099D,
  22800. jhadeva: 0x091D,
  22801. jhagujarati: 0x0A9D,
  22802. jhagurmukhi: 0x0A1D,
  22803. jheharmenian: 0x057B,
  22804. jis: 0x3004,
  22805. jmonospace: 0xFF4A,
  22806. jparen: 0x24A5,
  22807. jsuperior: 0x02B2,
  22808. k: 0x006B,
  22809. kabashkircyrillic: 0x04A1,
  22810. kabengali: 0x0995,
  22811. kacute: 0x1E31,
  22812. kacyrillic: 0x043A,
  22813. kadescendercyrillic: 0x049B,
  22814. kadeva: 0x0915,
  22815. kaf: 0x05DB,
  22816. kafarabic: 0x0643,
  22817. kafdagesh: 0xFB3B,
  22818. kafdageshhebrew: 0xFB3B,
  22819. kaffinalarabic: 0xFEDA,
  22820. kafhebrew: 0x05DB,
  22821. kafinitialarabic: 0xFEDB,
  22822. kafmedialarabic: 0xFEDC,
  22823. kafrafehebrew: 0xFB4D,
  22824. kagujarati: 0x0A95,
  22825. kagurmukhi: 0x0A15,
  22826. kahiragana: 0x304B,
  22827. kahookcyrillic: 0x04C4,
  22828. kakatakana: 0x30AB,
  22829. kakatakanahalfwidth: 0xFF76,
  22830. kappa: 0x03BA,
  22831. kappasymbolgreek: 0x03F0,
  22832. kapyeounmieumkorean: 0x3171,
  22833. kapyeounphieuphkorean: 0x3184,
  22834. kapyeounpieupkorean: 0x3178,
  22835. kapyeounssangpieupkorean: 0x3179,
  22836. karoriisquare: 0x330D,
  22837. kashidaautoarabic: 0x0640,
  22838. kashidaautonosidebearingarabic: 0x0640,
  22839. kasmallkatakana: 0x30F5,
  22840. kasquare: 0x3384,
  22841. kasraarabic: 0x0650,
  22842. kasratanarabic: 0x064D,
  22843. kastrokecyrillic: 0x049F,
  22844. katahiraprolongmarkhalfwidth: 0xFF70,
  22845. kaverticalstrokecyrillic: 0x049D,
  22846. kbopomofo: 0x310E,
  22847. kcalsquare: 0x3389,
  22848. kcaron: 0x01E9,
  22849. kcedilla: 0x0137,
  22850. kcircle: 0x24DA,
  22851. kcommaaccent: 0x0137,
  22852. kdotbelow: 0x1E33,
  22853. keharmenian: 0x0584,
  22854. kehiragana: 0x3051,
  22855. kekatakana: 0x30B1,
  22856. kekatakanahalfwidth: 0xFF79,
  22857. kenarmenian: 0x056F,
  22858. kesmallkatakana: 0x30F6,
  22859. kgreenlandic: 0x0138,
  22860. khabengali: 0x0996,
  22861. khacyrillic: 0x0445,
  22862. khadeva: 0x0916,
  22863. khagujarati: 0x0A96,
  22864. khagurmukhi: 0x0A16,
  22865. khaharabic: 0x062E,
  22866. khahfinalarabic: 0xFEA6,
  22867. khahinitialarabic: 0xFEA7,
  22868. khahmedialarabic: 0xFEA8,
  22869. kheicoptic: 0x03E7,
  22870. khhadeva: 0x0959,
  22871. khhagurmukhi: 0x0A59,
  22872. khieukhacirclekorean: 0x3278,
  22873. khieukhaparenkorean: 0x3218,
  22874. khieukhcirclekorean: 0x326A,
  22875. khieukhkorean: 0x314B,
  22876. khieukhparenkorean: 0x320A,
  22877. khokhaithai: 0x0E02,
  22878. khokhonthai: 0x0E05,
  22879. khokhuatthai: 0x0E03,
  22880. khokhwaithai: 0x0E04,
  22881. khomutthai: 0x0E5B,
  22882. khook: 0x0199,
  22883. khorakhangthai: 0x0E06,
  22884. khzsquare: 0x3391,
  22885. kihiragana: 0x304D,
  22886. kikatakana: 0x30AD,
  22887. kikatakanahalfwidth: 0xFF77,
  22888. kiroguramusquare: 0x3315,
  22889. kiromeetorusquare: 0x3316,
  22890. kirosquare: 0x3314,
  22891. kiyeokacirclekorean: 0x326E,
  22892. kiyeokaparenkorean: 0x320E,
  22893. kiyeokcirclekorean: 0x3260,
  22894. kiyeokkorean: 0x3131,
  22895. kiyeokparenkorean: 0x3200,
  22896. kiyeoksioskorean: 0x3133,
  22897. kjecyrillic: 0x045C,
  22898. klinebelow: 0x1E35,
  22899. klsquare: 0x3398,
  22900. kmcubedsquare: 0x33A6,
  22901. kmonospace: 0xFF4B,
  22902. kmsquaredsquare: 0x33A2,
  22903. kohiragana: 0x3053,
  22904. kohmsquare: 0x33C0,
  22905. kokaithai: 0x0E01,
  22906. kokatakana: 0x30B3,
  22907. kokatakanahalfwidth: 0xFF7A,
  22908. kooposquare: 0x331E,
  22909. koppacyrillic: 0x0481,
  22910. koreanstandardsymbol: 0x327F,
  22911. koroniscmb: 0x0343,
  22912. kparen: 0x24A6,
  22913. kpasquare: 0x33AA,
  22914. ksicyrillic: 0x046F,
  22915. ktsquare: 0x33CF,
  22916. kturned: 0x029E,
  22917. kuhiragana: 0x304F,
  22918. kukatakana: 0x30AF,
  22919. kukatakanahalfwidth: 0xFF78,
  22920. kvsquare: 0x33B8,
  22921. kwsquare: 0x33BE,
  22922. l: 0x006C,
  22923. labengali: 0x09B2,
  22924. lacute: 0x013A,
  22925. ladeva: 0x0932,
  22926. lagujarati: 0x0AB2,
  22927. lagurmukhi: 0x0A32,
  22928. lakkhangyaothai: 0x0E45,
  22929. lamaleffinalarabic: 0xFEFC,
  22930. lamalefhamzaabovefinalarabic: 0xFEF8,
  22931. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22932. lamalefhamzabelowfinalarabic: 0xFEFA,
  22933. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22934. lamalefisolatedarabic: 0xFEFB,
  22935. lamalefmaddaabovefinalarabic: 0xFEF6,
  22936. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22937. lamarabic: 0x0644,
  22938. lambda: 0x03BB,
  22939. lambdastroke: 0x019B,
  22940. lamed: 0x05DC,
  22941. lameddagesh: 0xFB3C,
  22942. lameddageshhebrew: 0xFB3C,
  22943. lamedhebrew: 0x05DC,
  22944. lamfinalarabic: 0xFEDE,
  22945. lamhahinitialarabic: 0xFCCA,
  22946. laminitialarabic: 0xFEDF,
  22947. lamjeeminitialarabic: 0xFCC9,
  22948. lamkhahinitialarabic: 0xFCCB,
  22949. lamlamhehisolatedarabic: 0xFDF2,
  22950. lammedialarabic: 0xFEE0,
  22951. lammeemhahinitialarabic: 0xFD88,
  22952. lammeeminitialarabic: 0xFCCC,
  22953. largecircle: 0x25EF,
  22954. lbar: 0x019A,
  22955. lbelt: 0x026C,
  22956. lbopomofo: 0x310C,
  22957. lcaron: 0x013E,
  22958. lcedilla: 0x013C,
  22959. lcircle: 0x24DB,
  22960. lcircumflexbelow: 0x1E3D,
  22961. lcommaaccent: 0x013C,
  22962. ldot: 0x0140,
  22963. ldotaccent: 0x0140,
  22964. ldotbelow: 0x1E37,
  22965. ldotbelowmacron: 0x1E39,
  22966. leftangleabovecmb: 0x031A,
  22967. lefttackbelowcmb: 0x0318,
  22968. less: 0x003C,
  22969. lessequal: 0x2264,
  22970. lessequalorgreater: 0x22DA,
  22971. lessmonospace: 0xFF1C,
  22972. lessorequivalent: 0x2272,
  22973. lessorgreater: 0x2276,
  22974. lessoverequal: 0x2266,
  22975. lesssmall: 0xFE64,
  22976. lezh: 0x026E,
  22977. lfblock: 0x258C,
  22978. lhookretroflex: 0x026D,
  22979. lira: 0x20A4,
  22980. liwnarmenian: 0x056C,
  22981. lj: 0x01C9,
  22982. ljecyrillic: 0x0459,
  22983. ll: 0xF6C0,
  22984. lladeva: 0x0933,
  22985. llagujarati: 0x0AB3,
  22986. llinebelow: 0x1E3B,
  22987. llladeva: 0x0934,
  22988. llvocalicbengali: 0x09E1,
  22989. llvocalicdeva: 0x0961,
  22990. llvocalicvowelsignbengali: 0x09E3,
  22991. llvocalicvowelsigndeva: 0x0963,
  22992. lmiddletilde: 0x026B,
  22993. lmonospace: 0xFF4C,
  22994. lmsquare: 0x33D0,
  22995. lochulathai: 0x0E2C,
  22996. logicaland: 0x2227,
  22997. logicalnot: 0x00AC,
  22998. logicalnotreversed: 0x2310,
  22999. logicalor: 0x2228,
  23000. lolingthai: 0x0E25,
  23001. longs: 0x017F,
  23002. lowlinecenterline: 0xFE4E,
  23003. lowlinecmb: 0x0332,
  23004. lowlinedashed: 0xFE4D,
  23005. lozenge: 0x25CA,
  23006. lparen: 0x24A7,
  23007. lslash: 0x0142,
  23008. lsquare: 0x2113,
  23009. lsuperior: 0xF6EE,
  23010. ltshade: 0x2591,
  23011. luthai: 0x0E26,
  23012. lvocalicbengali: 0x098C,
  23013. lvocalicdeva: 0x090C,
  23014. lvocalicvowelsignbengali: 0x09E2,
  23015. lvocalicvowelsigndeva: 0x0962,
  23016. lxsquare: 0x33D3,
  23017. m: 0x006D,
  23018. mabengali: 0x09AE,
  23019. macron: 0x00AF,
  23020. macronbelowcmb: 0x0331,
  23021. macroncmb: 0x0304,
  23022. macronlowmod: 0x02CD,
  23023. macronmonospace: 0xFFE3,
  23024. macute: 0x1E3F,
  23025. madeva: 0x092E,
  23026. magujarati: 0x0AAE,
  23027. magurmukhi: 0x0A2E,
  23028. mahapakhhebrew: 0x05A4,
  23029. mahapakhlefthebrew: 0x05A4,
  23030. mahiragana: 0x307E,
  23031. maichattawalowleftthai: 0xF895,
  23032. maichattawalowrightthai: 0xF894,
  23033. maichattawathai: 0x0E4B,
  23034. maichattawaupperleftthai: 0xF893,
  23035. maieklowleftthai: 0xF88C,
  23036. maieklowrightthai: 0xF88B,
  23037. maiekthai: 0x0E48,
  23038. maiekupperleftthai: 0xF88A,
  23039. maihanakatleftthai: 0xF884,
  23040. maihanakatthai: 0x0E31,
  23041. maitaikhuleftthai: 0xF889,
  23042. maitaikhuthai: 0x0E47,
  23043. maitholowleftthai: 0xF88F,
  23044. maitholowrightthai: 0xF88E,
  23045. maithothai: 0x0E49,
  23046. maithoupperleftthai: 0xF88D,
  23047. maitrilowleftthai: 0xF892,
  23048. maitrilowrightthai: 0xF891,
  23049. maitrithai: 0x0E4A,
  23050. maitriupperleftthai: 0xF890,
  23051. maiyamokthai: 0x0E46,
  23052. makatakana: 0x30DE,
  23053. makatakanahalfwidth: 0xFF8F,
  23054. male: 0x2642,
  23055. mansyonsquare: 0x3347,
  23056. maqafhebrew: 0x05BE,
  23057. mars: 0x2642,
  23058. masoracirclehebrew: 0x05AF,
  23059. masquare: 0x3383,
  23060. mbopomofo: 0x3107,
  23061. mbsquare: 0x33D4,
  23062. mcircle: 0x24DC,
  23063. mcubedsquare: 0x33A5,
  23064. mdotaccent: 0x1E41,
  23065. mdotbelow: 0x1E43,
  23066. meemarabic: 0x0645,
  23067. meemfinalarabic: 0xFEE2,
  23068. meeminitialarabic: 0xFEE3,
  23069. meemmedialarabic: 0xFEE4,
  23070. meemmeeminitialarabic: 0xFCD1,
  23071. meemmeemisolatedarabic: 0xFC48,
  23072. meetorusquare: 0x334D,
  23073. mehiragana: 0x3081,
  23074. meizierasquare: 0x337E,
  23075. mekatakana: 0x30E1,
  23076. mekatakanahalfwidth: 0xFF92,
  23077. mem: 0x05DE,
  23078. memdagesh: 0xFB3E,
  23079. memdageshhebrew: 0xFB3E,
  23080. memhebrew: 0x05DE,
  23081. menarmenian: 0x0574,
  23082. merkhahebrew: 0x05A5,
  23083. merkhakefulahebrew: 0x05A6,
  23084. merkhakefulalefthebrew: 0x05A6,
  23085. merkhalefthebrew: 0x05A5,
  23086. mhook: 0x0271,
  23087. mhzsquare: 0x3392,
  23088. middledotkatakanahalfwidth: 0xFF65,
  23089. middot: 0x00B7,
  23090. mieumacirclekorean: 0x3272,
  23091. mieumaparenkorean: 0x3212,
  23092. mieumcirclekorean: 0x3264,
  23093. mieumkorean: 0x3141,
  23094. mieumpansioskorean: 0x3170,
  23095. mieumparenkorean: 0x3204,
  23096. mieumpieupkorean: 0x316E,
  23097. mieumsioskorean: 0x316F,
  23098. mihiragana: 0x307F,
  23099. mikatakana: 0x30DF,
  23100. mikatakanahalfwidth: 0xFF90,
  23101. minus: 0x2212,
  23102. minusbelowcmb: 0x0320,
  23103. minuscircle: 0x2296,
  23104. minusmod: 0x02D7,
  23105. minusplus: 0x2213,
  23106. minute: 0x2032,
  23107. miribaarusquare: 0x334A,
  23108. mirisquare: 0x3349,
  23109. mlonglegturned: 0x0270,
  23110. mlsquare: 0x3396,
  23111. mmcubedsquare: 0x33A3,
  23112. mmonospace: 0xFF4D,
  23113. mmsquaredsquare: 0x339F,
  23114. mohiragana: 0x3082,
  23115. mohmsquare: 0x33C1,
  23116. mokatakana: 0x30E2,
  23117. mokatakanahalfwidth: 0xFF93,
  23118. molsquare: 0x33D6,
  23119. momathai: 0x0E21,
  23120. moverssquare: 0x33A7,
  23121. moverssquaredsquare: 0x33A8,
  23122. mparen: 0x24A8,
  23123. mpasquare: 0x33AB,
  23124. mssquare: 0x33B3,
  23125. msuperior: 0xF6EF,
  23126. mturned: 0x026F,
  23127. mu: 0x00B5,
  23128. mu1: 0x00B5,
  23129. muasquare: 0x3382,
  23130. muchgreater: 0x226B,
  23131. muchless: 0x226A,
  23132. mufsquare: 0x338C,
  23133. mugreek: 0x03BC,
  23134. mugsquare: 0x338D,
  23135. muhiragana: 0x3080,
  23136. mukatakana: 0x30E0,
  23137. mukatakanahalfwidth: 0xFF91,
  23138. mulsquare: 0x3395,
  23139. multiply: 0x00D7,
  23140. mumsquare: 0x339B,
  23141. munahhebrew: 0x05A3,
  23142. munahlefthebrew: 0x05A3,
  23143. musicalnote: 0x266A,
  23144. musicalnotedbl: 0x266B,
  23145. musicflatsign: 0x266D,
  23146. musicsharpsign: 0x266F,
  23147. mussquare: 0x33B2,
  23148. muvsquare: 0x33B6,
  23149. muwsquare: 0x33BC,
  23150. mvmegasquare: 0x33B9,
  23151. mvsquare: 0x33B7,
  23152. mwmegasquare: 0x33BF,
  23153. mwsquare: 0x33BD,
  23154. n: 0x006E,
  23155. nabengali: 0x09A8,
  23156. nabla: 0x2207,
  23157. nacute: 0x0144,
  23158. nadeva: 0x0928,
  23159. nagujarati: 0x0AA8,
  23160. nagurmukhi: 0x0A28,
  23161. nahiragana: 0x306A,
  23162. nakatakana: 0x30CA,
  23163. nakatakanahalfwidth: 0xFF85,
  23164. napostrophe: 0x0149,
  23165. nasquare: 0x3381,
  23166. nbopomofo: 0x310B,
  23167. nbspace: 0x00A0,
  23168. ncaron: 0x0148,
  23169. ncedilla: 0x0146,
  23170. ncircle: 0x24DD,
  23171. ncircumflexbelow: 0x1E4B,
  23172. ncommaaccent: 0x0146,
  23173. ndotaccent: 0x1E45,
  23174. ndotbelow: 0x1E47,
  23175. nehiragana: 0x306D,
  23176. nekatakana: 0x30CD,
  23177. nekatakanahalfwidth: 0xFF88,
  23178. newsheqelsign: 0x20AA,
  23179. nfsquare: 0x338B,
  23180. ngabengali: 0x0999,
  23181. ngadeva: 0x0919,
  23182. ngagujarati: 0x0A99,
  23183. ngagurmukhi: 0x0A19,
  23184. ngonguthai: 0x0E07,
  23185. nhiragana: 0x3093,
  23186. nhookleft: 0x0272,
  23187. nhookretroflex: 0x0273,
  23188. nieunacirclekorean: 0x326F,
  23189. nieunaparenkorean: 0x320F,
  23190. nieuncieuckorean: 0x3135,
  23191. nieuncirclekorean: 0x3261,
  23192. nieunhieuhkorean: 0x3136,
  23193. nieunkorean: 0x3134,
  23194. nieunpansioskorean: 0x3168,
  23195. nieunparenkorean: 0x3201,
  23196. nieunsioskorean: 0x3167,
  23197. nieuntikeutkorean: 0x3166,
  23198. nihiragana: 0x306B,
  23199. nikatakana: 0x30CB,
  23200. nikatakanahalfwidth: 0xFF86,
  23201. nikhahitleftthai: 0xF899,
  23202. nikhahitthai: 0x0E4D,
  23203. nine: 0x0039,
  23204. ninearabic: 0x0669,
  23205. ninebengali: 0x09EF,
  23206. ninecircle: 0x2468,
  23207. ninecircleinversesansserif: 0x2792,
  23208. ninedeva: 0x096F,
  23209. ninegujarati: 0x0AEF,
  23210. ninegurmukhi: 0x0A6F,
  23211. ninehackarabic: 0x0669,
  23212. ninehangzhou: 0x3029,
  23213. nineideographicparen: 0x3228,
  23214. nineinferior: 0x2089,
  23215. ninemonospace: 0xFF19,
  23216. nineoldstyle: 0xF739,
  23217. nineparen: 0x247C,
  23218. nineperiod: 0x2490,
  23219. ninepersian: 0x06F9,
  23220. nineroman: 0x2178,
  23221. ninesuperior: 0x2079,
  23222. nineteencircle: 0x2472,
  23223. nineteenparen: 0x2486,
  23224. nineteenperiod: 0x249A,
  23225. ninethai: 0x0E59,
  23226. nj: 0x01CC,
  23227. njecyrillic: 0x045A,
  23228. nkatakana: 0x30F3,
  23229. nkatakanahalfwidth: 0xFF9D,
  23230. nlegrightlong: 0x019E,
  23231. nlinebelow: 0x1E49,
  23232. nmonospace: 0xFF4E,
  23233. nmsquare: 0x339A,
  23234. nnabengali: 0x09A3,
  23235. nnadeva: 0x0923,
  23236. nnagujarati: 0x0AA3,
  23237. nnagurmukhi: 0x0A23,
  23238. nnnadeva: 0x0929,
  23239. nohiragana: 0x306E,
  23240. nokatakana: 0x30CE,
  23241. nokatakanahalfwidth: 0xFF89,
  23242. nonbreakingspace: 0x00A0,
  23243. nonenthai: 0x0E13,
  23244. nonuthai: 0x0E19,
  23245. noonarabic: 0x0646,
  23246. noonfinalarabic: 0xFEE6,
  23247. noonghunnaarabic: 0x06BA,
  23248. noonghunnafinalarabic: 0xFB9F,
  23249. nooninitialarabic: 0xFEE7,
  23250. noonjeeminitialarabic: 0xFCD2,
  23251. noonjeemisolatedarabic: 0xFC4B,
  23252. noonmedialarabic: 0xFEE8,
  23253. noonmeeminitialarabic: 0xFCD5,
  23254. noonmeemisolatedarabic: 0xFC4E,
  23255. noonnoonfinalarabic: 0xFC8D,
  23256. notcontains: 0x220C,
  23257. notelement: 0x2209,
  23258. notelementof: 0x2209,
  23259. notequal: 0x2260,
  23260. notgreater: 0x226F,
  23261. notgreaternorequal: 0x2271,
  23262. notgreaternorless: 0x2279,
  23263. notidentical: 0x2262,
  23264. notless: 0x226E,
  23265. notlessnorequal: 0x2270,
  23266. notparallel: 0x2226,
  23267. notprecedes: 0x2280,
  23268. notsubset: 0x2284,
  23269. notsucceeds: 0x2281,
  23270. notsuperset: 0x2285,
  23271. nowarmenian: 0x0576,
  23272. nparen: 0x24A9,
  23273. nssquare: 0x33B1,
  23274. nsuperior: 0x207F,
  23275. ntilde: 0x00F1,
  23276. nu: 0x03BD,
  23277. nuhiragana: 0x306C,
  23278. nukatakana: 0x30CC,
  23279. nukatakanahalfwidth: 0xFF87,
  23280. nuktabengali: 0x09BC,
  23281. nuktadeva: 0x093C,
  23282. nuktagujarati: 0x0ABC,
  23283. nuktagurmukhi: 0x0A3C,
  23284. numbersign: 0x0023,
  23285. numbersignmonospace: 0xFF03,
  23286. numbersignsmall: 0xFE5F,
  23287. numeralsigngreek: 0x0374,
  23288. numeralsignlowergreek: 0x0375,
  23289. numero: 0x2116,
  23290. nun: 0x05E0,
  23291. nundagesh: 0xFB40,
  23292. nundageshhebrew: 0xFB40,
  23293. nunhebrew: 0x05E0,
  23294. nvsquare: 0x33B5,
  23295. nwsquare: 0x33BB,
  23296. nyabengali: 0x099E,
  23297. nyadeva: 0x091E,
  23298. nyagujarati: 0x0A9E,
  23299. nyagurmukhi: 0x0A1E,
  23300. o: 0x006F,
  23301. oacute: 0x00F3,
  23302. oangthai: 0x0E2D,
  23303. obarred: 0x0275,
  23304. obarredcyrillic: 0x04E9,
  23305. obarreddieresiscyrillic: 0x04EB,
  23306. obengali: 0x0993,
  23307. obopomofo: 0x311B,
  23308. obreve: 0x014F,
  23309. ocandradeva: 0x0911,
  23310. ocandragujarati: 0x0A91,
  23311. ocandravowelsigndeva: 0x0949,
  23312. ocandravowelsigngujarati: 0x0AC9,
  23313. ocaron: 0x01D2,
  23314. ocircle: 0x24DE,
  23315. ocircumflex: 0x00F4,
  23316. ocircumflexacute: 0x1ED1,
  23317. ocircumflexdotbelow: 0x1ED9,
  23318. ocircumflexgrave: 0x1ED3,
  23319. ocircumflexhookabove: 0x1ED5,
  23320. ocircumflextilde: 0x1ED7,
  23321. ocyrillic: 0x043E,
  23322. odblacute: 0x0151,
  23323. odblgrave: 0x020D,
  23324. odeva: 0x0913,
  23325. odieresis: 0x00F6,
  23326. odieresiscyrillic: 0x04E7,
  23327. odotbelow: 0x1ECD,
  23328. oe: 0x0153,
  23329. oekorean: 0x315A,
  23330. ogonek: 0x02DB,
  23331. ogonekcmb: 0x0328,
  23332. ograve: 0x00F2,
  23333. ogujarati: 0x0A93,
  23334. oharmenian: 0x0585,
  23335. ohiragana: 0x304A,
  23336. ohookabove: 0x1ECF,
  23337. ohorn: 0x01A1,
  23338. ohornacute: 0x1EDB,
  23339. ohorndotbelow: 0x1EE3,
  23340. ohorngrave: 0x1EDD,
  23341. ohornhookabove: 0x1EDF,
  23342. ohorntilde: 0x1EE1,
  23343. ohungarumlaut: 0x0151,
  23344. oi: 0x01A3,
  23345. oinvertedbreve: 0x020F,
  23346. okatakana: 0x30AA,
  23347. okatakanahalfwidth: 0xFF75,
  23348. okorean: 0x3157,
  23349. olehebrew: 0x05AB,
  23350. omacron: 0x014D,
  23351. omacronacute: 0x1E53,
  23352. omacrongrave: 0x1E51,
  23353. omdeva: 0x0950,
  23354. omega: 0x03C9,
  23355. omega1: 0x03D6,
  23356. omegacyrillic: 0x0461,
  23357. omegalatinclosed: 0x0277,
  23358. omegaroundcyrillic: 0x047B,
  23359. omegatitlocyrillic: 0x047D,
  23360. omegatonos: 0x03CE,
  23361. omgujarati: 0x0AD0,
  23362. omicron: 0x03BF,
  23363. omicrontonos: 0x03CC,
  23364. omonospace: 0xFF4F,
  23365. one: 0x0031,
  23366. onearabic: 0x0661,
  23367. onebengali: 0x09E7,
  23368. onecircle: 0x2460,
  23369. onecircleinversesansserif: 0x278A,
  23370. onedeva: 0x0967,
  23371. onedotenleader: 0x2024,
  23372. oneeighth: 0x215B,
  23373. onefitted: 0xF6DC,
  23374. onegujarati: 0x0AE7,
  23375. onegurmukhi: 0x0A67,
  23376. onehackarabic: 0x0661,
  23377. onehalf: 0x00BD,
  23378. onehangzhou: 0x3021,
  23379. oneideographicparen: 0x3220,
  23380. oneinferior: 0x2081,
  23381. onemonospace: 0xFF11,
  23382. onenumeratorbengali: 0x09F4,
  23383. oneoldstyle: 0xF731,
  23384. oneparen: 0x2474,
  23385. oneperiod: 0x2488,
  23386. onepersian: 0x06F1,
  23387. onequarter: 0x00BC,
  23388. oneroman: 0x2170,
  23389. onesuperior: 0x00B9,
  23390. onethai: 0x0E51,
  23391. onethird: 0x2153,
  23392. oogonek: 0x01EB,
  23393. oogonekmacron: 0x01ED,
  23394. oogurmukhi: 0x0A13,
  23395. oomatragurmukhi: 0x0A4B,
  23396. oopen: 0x0254,
  23397. oparen: 0x24AA,
  23398. openbullet: 0x25E6,
  23399. option: 0x2325,
  23400. ordfeminine: 0x00AA,
  23401. ordmasculine: 0x00BA,
  23402. orthogonal: 0x221F,
  23403. oshortdeva: 0x0912,
  23404. oshortvowelsigndeva: 0x094A,
  23405. oslash: 0x00F8,
  23406. oslashacute: 0x01FF,
  23407. osmallhiragana: 0x3049,
  23408. osmallkatakana: 0x30A9,
  23409. osmallkatakanahalfwidth: 0xFF6B,
  23410. ostrokeacute: 0x01FF,
  23411. osuperior: 0xF6F0,
  23412. otcyrillic: 0x047F,
  23413. otilde: 0x00F5,
  23414. otildeacute: 0x1E4D,
  23415. otildedieresis: 0x1E4F,
  23416. oubopomofo: 0x3121,
  23417. overline: 0x203E,
  23418. overlinecenterline: 0xFE4A,
  23419. overlinecmb: 0x0305,
  23420. overlinedashed: 0xFE49,
  23421. overlinedblwavy: 0xFE4C,
  23422. overlinewavy: 0xFE4B,
  23423. overscore: 0x00AF,
  23424. ovowelsignbengali: 0x09CB,
  23425. ovowelsigndeva: 0x094B,
  23426. ovowelsigngujarati: 0x0ACB,
  23427. p: 0x0070,
  23428. paampssquare: 0x3380,
  23429. paasentosquare: 0x332B,
  23430. pabengali: 0x09AA,
  23431. pacute: 0x1E55,
  23432. padeva: 0x092A,
  23433. pagedown: 0x21DF,
  23434. pageup: 0x21DE,
  23435. pagujarati: 0x0AAA,
  23436. pagurmukhi: 0x0A2A,
  23437. pahiragana: 0x3071,
  23438. paiyannoithai: 0x0E2F,
  23439. pakatakana: 0x30D1,
  23440. palatalizationcyrilliccmb: 0x0484,
  23441. palochkacyrillic: 0x04C0,
  23442. pansioskorean: 0x317F,
  23443. paragraph: 0x00B6,
  23444. parallel: 0x2225,
  23445. parenleft: 0x0028,
  23446. parenleftaltonearabic: 0xFD3E,
  23447. parenleftbt: 0xF8ED,
  23448. parenleftex: 0xF8EC,
  23449. parenleftinferior: 0x208D,
  23450. parenleftmonospace: 0xFF08,
  23451. parenleftsmall: 0xFE59,
  23452. parenleftsuperior: 0x207D,
  23453. parenlefttp: 0xF8EB,
  23454. parenleftvertical: 0xFE35,
  23455. parenright: 0x0029,
  23456. parenrightaltonearabic: 0xFD3F,
  23457. parenrightbt: 0xF8F8,
  23458. parenrightex: 0xF8F7,
  23459. parenrightinferior: 0x208E,
  23460. parenrightmonospace: 0xFF09,
  23461. parenrightsmall: 0xFE5A,
  23462. parenrightsuperior: 0x207E,
  23463. parenrighttp: 0xF8F6,
  23464. parenrightvertical: 0xFE36,
  23465. partialdiff: 0x2202,
  23466. paseqhebrew: 0x05C0,
  23467. pashtahebrew: 0x0599,
  23468. pasquare: 0x33A9,
  23469. patah: 0x05B7,
  23470. patah11: 0x05B7,
  23471. patah1d: 0x05B7,
  23472. patah2a: 0x05B7,
  23473. patahhebrew: 0x05B7,
  23474. patahnarrowhebrew: 0x05B7,
  23475. patahquarterhebrew: 0x05B7,
  23476. patahwidehebrew: 0x05B7,
  23477. pazerhebrew: 0x05A1,
  23478. pbopomofo: 0x3106,
  23479. pcircle: 0x24DF,
  23480. pdotaccent: 0x1E57,
  23481. pe: 0x05E4,
  23482. pecyrillic: 0x043F,
  23483. pedagesh: 0xFB44,
  23484. pedageshhebrew: 0xFB44,
  23485. peezisquare: 0x333B,
  23486. pefinaldageshhebrew: 0xFB43,
  23487. peharabic: 0x067E,
  23488. peharmenian: 0x057A,
  23489. pehebrew: 0x05E4,
  23490. pehfinalarabic: 0xFB57,
  23491. pehinitialarabic: 0xFB58,
  23492. pehiragana: 0x307A,
  23493. pehmedialarabic: 0xFB59,
  23494. pekatakana: 0x30DA,
  23495. pemiddlehookcyrillic: 0x04A7,
  23496. perafehebrew: 0xFB4E,
  23497. percent: 0x0025,
  23498. percentarabic: 0x066A,
  23499. percentmonospace: 0xFF05,
  23500. percentsmall: 0xFE6A,
  23501. period: 0x002E,
  23502. periodarmenian: 0x0589,
  23503. periodcentered: 0x00B7,
  23504. periodhalfwidth: 0xFF61,
  23505. periodinferior: 0xF6E7,
  23506. periodmonospace: 0xFF0E,
  23507. periodsmall: 0xFE52,
  23508. periodsuperior: 0xF6E8,
  23509. perispomenigreekcmb: 0x0342,
  23510. perpendicular: 0x22A5,
  23511. perthousand: 0x2030,
  23512. peseta: 0x20A7,
  23513. pfsquare: 0x338A,
  23514. phabengali: 0x09AB,
  23515. phadeva: 0x092B,
  23516. phagujarati: 0x0AAB,
  23517. phagurmukhi: 0x0A2B,
  23518. phi: 0x03C6,
  23519. phi1: 0x03D5,
  23520. phieuphacirclekorean: 0x327A,
  23521. phieuphaparenkorean: 0x321A,
  23522. phieuphcirclekorean: 0x326C,
  23523. phieuphkorean: 0x314D,
  23524. phieuphparenkorean: 0x320C,
  23525. philatin: 0x0278,
  23526. phinthuthai: 0x0E3A,
  23527. phisymbolgreek: 0x03D5,
  23528. phook: 0x01A5,
  23529. phophanthai: 0x0E1E,
  23530. phophungthai: 0x0E1C,
  23531. phosamphaothai: 0x0E20,
  23532. pi: 0x03C0,
  23533. pieupacirclekorean: 0x3273,
  23534. pieupaparenkorean: 0x3213,
  23535. pieupcieuckorean: 0x3176,
  23536. pieupcirclekorean: 0x3265,
  23537. pieupkiyeokkorean: 0x3172,
  23538. pieupkorean: 0x3142,
  23539. pieupparenkorean: 0x3205,
  23540. pieupsioskiyeokkorean: 0x3174,
  23541. pieupsioskorean: 0x3144,
  23542. pieupsiostikeutkorean: 0x3175,
  23543. pieupthieuthkorean: 0x3177,
  23544. pieuptikeutkorean: 0x3173,
  23545. pihiragana: 0x3074,
  23546. pikatakana: 0x30D4,
  23547. pisymbolgreek: 0x03D6,
  23548. piwrarmenian: 0x0583,
  23549. plus: 0x002B,
  23550. plusbelowcmb: 0x031F,
  23551. pluscircle: 0x2295,
  23552. plusminus: 0x00B1,
  23553. plusmod: 0x02D6,
  23554. plusmonospace: 0xFF0B,
  23555. plussmall: 0xFE62,
  23556. plussuperior: 0x207A,
  23557. pmonospace: 0xFF50,
  23558. pmsquare: 0x33D8,
  23559. pohiragana: 0x307D,
  23560. pointingindexdownwhite: 0x261F,
  23561. pointingindexleftwhite: 0x261C,
  23562. pointingindexrightwhite: 0x261E,
  23563. pointingindexupwhite: 0x261D,
  23564. pokatakana: 0x30DD,
  23565. poplathai: 0x0E1B,
  23566. postalmark: 0x3012,
  23567. postalmarkface: 0x3020,
  23568. pparen: 0x24AB,
  23569. precedes: 0x227A,
  23570. prescription: 0x211E,
  23571. primemod: 0x02B9,
  23572. primereversed: 0x2035,
  23573. product: 0x220F,
  23574. projective: 0x2305,
  23575. prolongedkana: 0x30FC,
  23576. propellor: 0x2318,
  23577. propersubset: 0x2282,
  23578. propersuperset: 0x2283,
  23579. proportion: 0x2237,
  23580. proportional: 0x221D,
  23581. psi: 0x03C8,
  23582. psicyrillic: 0x0471,
  23583. psilipneumatacyrilliccmb: 0x0486,
  23584. pssquare: 0x33B0,
  23585. puhiragana: 0x3077,
  23586. pukatakana: 0x30D7,
  23587. pvsquare: 0x33B4,
  23588. pwsquare: 0x33BA,
  23589. q: 0x0071,
  23590. qadeva: 0x0958,
  23591. qadmahebrew: 0x05A8,
  23592. qafarabic: 0x0642,
  23593. qaffinalarabic: 0xFED6,
  23594. qafinitialarabic: 0xFED7,
  23595. qafmedialarabic: 0xFED8,
  23596. qamats: 0x05B8,
  23597. qamats10: 0x05B8,
  23598. qamats1a: 0x05B8,
  23599. qamats1c: 0x05B8,
  23600. qamats27: 0x05B8,
  23601. qamats29: 0x05B8,
  23602. qamats33: 0x05B8,
  23603. qamatsde: 0x05B8,
  23604. qamatshebrew: 0x05B8,
  23605. qamatsnarrowhebrew: 0x05B8,
  23606. qamatsqatanhebrew: 0x05B8,
  23607. qamatsqatannarrowhebrew: 0x05B8,
  23608. qamatsqatanquarterhebrew: 0x05B8,
  23609. qamatsqatanwidehebrew: 0x05B8,
  23610. qamatsquarterhebrew: 0x05B8,
  23611. qamatswidehebrew: 0x05B8,
  23612. qarneyparahebrew: 0x059F,
  23613. qbopomofo: 0x3111,
  23614. qcircle: 0x24E0,
  23615. qhook: 0x02A0,
  23616. qmonospace: 0xFF51,
  23617. qof: 0x05E7,
  23618. qofdagesh: 0xFB47,
  23619. qofdageshhebrew: 0xFB47,
  23620. qofhebrew: 0x05E7,
  23621. qparen: 0x24AC,
  23622. quarternote: 0x2669,
  23623. qubuts: 0x05BB,
  23624. qubuts18: 0x05BB,
  23625. qubuts25: 0x05BB,
  23626. qubuts31: 0x05BB,
  23627. qubutshebrew: 0x05BB,
  23628. qubutsnarrowhebrew: 0x05BB,
  23629. qubutsquarterhebrew: 0x05BB,
  23630. qubutswidehebrew: 0x05BB,
  23631. question: 0x003F,
  23632. questionarabic: 0x061F,
  23633. questionarmenian: 0x055E,
  23634. questiondown: 0x00BF,
  23635. questiondownsmall: 0xF7BF,
  23636. questiongreek: 0x037E,
  23637. questionmonospace: 0xFF1F,
  23638. questionsmall: 0xF73F,
  23639. quotedbl: 0x0022,
  23640. quotedblbase: 0x201E,
  23641. quotedblleft: 0x201C,
  23642. quotedblmonospace: 0xFF02,
  23643. quotedblprime: 0x301E,
  23644. quotedblprimereversed: 0x301D,
  23645. quotedblright: 0x201D,
  23646. quoteleft: 0x2018,
  23647. quoteleftreversed: 0x201B,
  23648. quotereversed: 0x201B,
  23649. quoteright: 0x2019,
  23650. quoterightn: 0x0149,
  23651. quotesinglbase: 0x201A,
  23652. quotesingle: 0x0027,
  23653. quotesinglemonospace: 0xFF07,
  23654. r: 0x0072,
  23655. raarmenian: 0x057C,
  23656. rabengali: 0x09B0,
  23657. racute: 0x0155,
  23658. radeva: 0x0930,
  23659. radical: 0x221A,
  23660. radicalex: 0xF8E5,
  23661. radoverssquare: 0x33AE,
  23662. radoverssquaredsquare: 0x33AF,
  23663. radsquare: 0x33AD,
  23664. rafe: 0x05BF,
  23665. rafehebrew: 0x05BF,
  23666. ragujarati: 0x0AB0,
  23667. ragurmukhi: 0x0A30,
  23668. rahiragana: 0x3089,
  23669. rakatakana: 0x30E9,
  23670. rakatakanahalfwidth: 0xFF97,
  23671. ralowerdiagonalbengali: 0x09F1,
  23672. ramiddlediagonalbengali: 0x09F0,
  23673. ramshorn: 0x0264,
  23674. ratio: 0x2236,
  23675. rbopomofo: 0x3116,
  23676. rcaron: 0x0159,
  23677. rcedilla: 0x0157,
  23678. rcircle: 0x24E1,
  23679. rcommaaccent: 0x0157,
  23680. rdblgrave: 0x0211,
  23681. rdotaccent: 0x1E59,
  23682. rdotbelow: 0x1E5B,
  23683. rdotbelowmacron: 0x1E5D,
  23684. referencemark: 0x203B,
  23685. reflexsubset: 0x2286,
  23686. reflexsuperset: 0x2287,
  23687. registered: 0x00AE,
  23688. registersans: 0xF8E8,
  23689. registerserif: 0xF6DA,
  23690. reharabic: 0x0631,
  23691. reharmenian: 0x0580,
  23692. rehfinalarabic: 0xFEAE,
  23693. rehiragana: 0x308C,
  23694. rekatakana: 0x30EC,
  23695. rekatakanahalfwidth: 0xFF9A,
  23696. resh: 0x05E8,
  23697. reshdageshhebrew: 0xFB48,
  23698. reshhebrew: 0x05E8,
  23699. reversedtilde: 0x223D,
  23700. reviahebrew: 0x0597,
  23701. reviamugrashhebrew: 0x0597,
  23702. revlogicalnot: 0x2310,
  23703. rfishhook: 0x027E,
  23704. rfishhookreversed: 0x027F,
  23705. rhabengali: 0x09DD,
  23706. rhadeva: 0x095D,
  23707. rho: 0x03C1,
  23708. rhook: 0x027D,
  23709. rhookturned: 0x027B,
  23710. rhookturnedsuperior: 0x02B5,
  23711. rhosymbolgreek: 0x03F1,
  23712. rhotichookmod: 0x02DE,
  23713. rieulacirclekorean: 0x3271,
  23714. rieulaparenkorean: 0x3211,
  23715. rieulcirclekorean: 0x3263,
  23716. rieulhieuhkorean: 0x3140,
  23717. rieulkiyeokkorean: 0x313A,
  23718. rieulkiyeoksioskorean: 0x3169,
  23719. rieulkorean: 0x3139,
  23720. rieulmieumkorean: 0x313B,
  23721. rieulpansioskorean: 0x316C,
  23722. rieulparenkorean: 0x3203,
  23723. rieulphieuphkorean: 0x313F,
  23724. rieulpieupkorean: 0x313C,
  23725. rieulpieupsioskorean: 0x316B,
  23726. rieulsioskorean: 0x313D,
  23727. rieulthieuthkorean: 0x313E,
  23728. rieultikeutkorean: 0x316A,
  23729. rieulyeorinhieuhkorean: 0x316D,
  23730. rightangle: 0x221F,
  23731. righttackbelowcmb: 0x0319,
  23732. righttriangle: 0x22BF,
  23733. rihiragana: 0x308A,
  23734. rikatakana: 0x30EA,
  23735. rikatakanahalfwidth: 0xFF98,
  23736. ring: 0x02DA,
  23737. ringbelowcmb: 0x0325,
  23738. ringcmb: 0x030A,
  23739. ringhalfleft: 0x02BF,
  23740. ringhalfleftarmenian: 0x0559,
  23741. ringhalfleftbelowcmb: 0x031C,
  23742. ringhalfleftcentered: 0x02D3,
  23743. ringhalfright: 0x02BE,
  23744. ringhalfrightbelowcmb: 0x0339,
  23745. ringhalfrightcentered: 0x02D2,
  23746. rinvertedbreve: 0x0213,
  23747. rittorusquare: 0x3351,
  23748. rlinebelow: 0x1E5F,
  23749. rlongleg: 0x027C,
  23750. rlonglegturned: 0x027A,
  23751. rmonospace: 0xFF52,
  23752. rohiragana: 0x308D,
  23753. rokatakana: 0x30ED,
  23754. rokatakanahalfwidth: 0xFF9B,
  23755. roruathai: 0x0E23,
  23756. rparen: 0x24AD,
  23757. rrabengali: 0x09DC,
  23758. rradeva: 0x0931,
  23759. rragurmukhi: 0x0A5C,
  23760. rreharabic: 0x0691,
  23761. rrehfinalarabic: 0xFB8D,
  23762. rrvocalicbengali: 0x09E0,
  23763. rrvocalicdeva: 0x0960,
  23764. rrvocalicgujarati: 0x0AE0,
  23765. rrvocalicvowelsignbengali: 0x09C4,
  23766. rrvocalicvowelsigndeva: 0x0944,
  23767. rrvocalicvowelsigngujarati: 0x0AC4,
  23768. rsuperior: 0xF6F1,
  23769. rtblock: 0x2590,
  23770. rturned: 0x0279,
  23771. rturnedsuperior: 0x02B4,
  23772. ruhiragana: 0x308B,
  23773. rukatakana: 0x30EB,
  23774. rukatakanahalfwidth: 0xFF99,
  23775. rupeemarkbengali: 0x09F2,
  23776. rupeesignbengali: 0x09F3,
  23777. rupiah: 0xF6DD,
  23778. ruthai: 0x0E24,
  23779. rvocalicbengali: 0x098B,
  23780. rvocalicdeva: 0x090B,
  23781. rvocalicgujarati: 0x0A8B,
  23782. rvocalicvowelsignbengali: 0x09C3,
  23783. rvocalicvowelsigndeva: 0x0943,
  23784. rvocalicvowelsigngujarati: 0x0AC3,
  23785. s: 0x0073,
  23786. sabengali: 0x09B8,
  23787. sacute: 0x015B,
  23788. sacutedotaccent: 0x1E65,
  23789. sadarabic: 0x0635,
  23790. sadeva: 0x0938,
  23791. sadfinalarabic: 0xFEBA,
  23792. sadinitialarabic: 0xFEBB,
  23793. sadmedialarabic: 0xFEBC,
  23794. sagujarati: 0x0AB8,
  23795. sagurmukhi: 0x0A38,
  23796. sahiragana: 0x3055,
  23797. sakatakana: 0x30B5,
  23798. sakatakanahalfwidth: 0xFF7B,
  23799. sallallahoualayhewasallamarabic: 0xFDFA,
  23800. samekh: 0x05E1,
  23801. samekhdagesh: 0xFB41,
  23802. samekhdageshhebrew: 0xFB41,
  23803. samekhhebrew: 0x05E1,
  23804. saraaathai: 0x0E32,
  23805. saraaethai: 0x0E41,
  23806. saraaimaimalaithai: 0x0E44,
  23807. saraaimaimuanthai: 0x0E43,
  23808. saraamthai: 0x0E33,
  23809. saraathai: 0x0E30,
  23810. saraethai: 0x0E40,
  23811. saraiileftthai: 0xF886,
  23812. saraiithai: 0x0E35,
  23813. saraileftthai: 0xF885,
  23814. saraithai: 0x0E34,
  23815. saraothai: 0x0E42,
  23816. saraueeleftthai: 0xF888,
  23817. saraueethai: 0x0E37,
  23818. saraueleftthai: 0xF887,
  23819. sarauethai: 0x0E36,
  23820. sarauthai: 0x0E38,
  23821. sarauuthai: 0x0E39,
  23822. sbopomofo: 0x3119,
  23823. scaron: 0x0161,
  23824. scarondotaccent: 0x1E67,
  23825. scedilla: 0x015F,
  23826. schwa: 0x0259,
  23827. schwacyrillic: 0x04D9,
  23828. schwadieresiscyrillic: 0x04DB,
  23829. schwahook: 0x025A,
  23830. scircle: 0x24E2,
  23831. scircumflex: 0x015D,
  23832. scommaaccent: 0x0219,
  23833. sdotaccent: 0x1E61,
  23834. sdotbelow: 0x1E63,
  23835. sdotbelowdotaccent: 0x1E69,
  23836. seagullbelowcmb: 0x033C,
  23837. second: 0x2033,
  23838. secondtonechinese: 0x02CA,
  23839. section: 0x00A7,
  23840. seenarabic: 0x0633,
  23841. seenfinalarabic: 0xFEB2,
  23842. seeninitialarabic: 0xFEB3,
  23843. seenmedialarabic: 0xFEB4,
  23844. segol: 0x05B6,
  23845. segol13: 0x05B6,
  23846. segol1f: 0x05B6,
  23847. segol2c: 0x05B6,
  23848. segolhebrew: 0x05B6,
  23849. segolnarrowhebrew: 0x05B6,
  23850. segolquarterhebrew: 0x05B6,
  23851. segoltahebrew: 0x0592,
  23852. segolwidehebrew: 0x05B6,
  23853. seharmenian: 0x057D,
  23854. sehiragana: 0x305B,
  23855. sekatakana: 0x30BB,
  23856. sekatakanahalfwidth: 0xFF7E,
  23857. semicolon: 0x003B,
  23858. semicolonarabic: 0x061B,
  23859. semicolonmonospace: 0xFF1B,
  23860. semicolonsmall: 0xFE54,
  23861. semivoicedmarkkana: 0x309C,
  23862. semivoicedmarkkanahalfwidth: 0xFF9F,
  23863. sentisquare: 0x3322,
  23864. sentosquare: 0x3323,
  23865. seven: 0x0037,
  23866. sevenarabic: 0x0667,
  23867. sevenbengali: 0x09ED,
  23868. sevencircle: 0x2466,
  23869. sevencircleinversesansserif: 0x2790,
  23870. sevendeva: 0x096D,
  23871. seveneighths: 0x215E,
  23872. sevengujarati: 0x0AED,
  23873. sevengurmukhi: 0x0A6D,
  23874. sevenhackarabic: 0x0667,
  23875. sevenhangzhou: 0x3027,
  23876. sevenideographicparen: 0x3226,
  23877. seveninferior: 0x2087,
  23878. sevenmonospace: 0xFF17,
  23879. sevenoldstyle: 0xF737,
  23880. sevenparen: 0x247A,
  23881. sevenperiod: 0x248E,
  23882. sevenpersian: 0x06F7,
  23883. sevenroman: 0x2176,
  23884. sevensuperior: 0x2077,
  23885. seventeencircle: 0x2470,
  23886. seventeenparen: 0x2484,
  23887. seventeenperiod: 0x2498,
  23888. seventhai: 0x0E57,
  23889. sfthyphen: 0x00AD,
  23890. shaarmenian: 0x0577,
  23891. shabengali: 0x09B6,
  23892. shacyrillic: 0x0448,
  23893. shaddaarabic: 0x0651,
  23894. shaddadammaarabic: 0xFC61,
  23895. shaddadammatanarabic: 0xFC5E,
  23896. shaddafathaarabic: 0xFC60,
  23897. shaddakasraarabic: 0xFC62,
  23898. shaddakasratanarabic: 0xFC5F,
  23899. shade: 0x2592,
  23900. shadedark: 0x2593,
  23901. shadelight: 0x2591,
  23902. shademedium: 0x2592,
  23903. shadeva: 0x0936,
  23904. shagujarati: 0x0AB6,
  23905. shagurmukhi: 0x0A36,
  23906. shalshelethebrew: 0x0593,
  23907. shbopomofo: 0x3115,
  23908. shchacyrillic: 0x0449,
  23909. sheenarabic: 0x0634,
  23910. sheenfinalarabic: 0xFEB6,
  23911. sheeninitialarabic: 0xFEB7,
  23912. sheenmedialarabic: 0xFEB8,
  23913. sheicoptic: 0x03E3,
  23914. sheqel: 0x20AA,
  23915. sheqelhebrew: 0x20AA,
  23916. sheva: 0x05B0,
  23917. sheva115: 0x05B0,
  23918. sheva15: 0x05B0,
  23919. sheva22: 0x05B0,
  23920. sheva2e: 0x05B0,
  23921. shevahebrew: 0x05B0,
  23922. shevanarrowhebrew: 0x05B0,
  23923. shevaquarterhebrew: 0x05B0,
  23924. shevawidehebrew: 0x05B0,
  23925. shhacyrillic: 0x04BB,
  23926. shimacoptic: 0x03ED,
  23927. shin: 0x05E9,
  23928. shindagesh: 0xFB49,
  23929. shindageshhebrew: 0xFB49,
  23930. shindageshshindot: 0xFB2C,
  23931. shindageshshindothebrew: 0xFB2C,
  23932. shindageshsindot: 0xFB2D,
  23933. shindageshsindothebrew: 0xFB2D,
  23934. shindothebrew: 0x05C1,
  23935. shinhebrew: 0x05E9,
  23936. shinshindot: 0xFB2A,
  23937. shinshindothebrew: 0xFB2A,
  23938. shinsindot: 0xFB2B,
  23939. shinsindothebrew: 0xFB2B,
  23940. shook: 0x0282,
  23941. sigma: 0x03C3,
  23942. sigma1: 0x03C2,
  23943. sigmafinal: 0x03C2,
  23944. sigmalunatesymbolgreek: 0x03F2,
  23945. sihiragana: 0x3057,
  23946. sikatakana: 0x30B7,
  23947. sikatakanahalfwidth: 0xFF7C,
  23948. siluqhebrew: 0x05BD,
  23949. siluqlefthebrew: 0x05BD,
  23950. similar: 0x223C,
  23951. sindothebrew: 0x05C2,
  23952. siosacirclekorean: 0x3274,
  23953. siosaparenkorean: 0x3214,
  23954. sioscieuckorean: 0x317E,
  23955. sioscirclekorean: 0x3266,
  23956. sioskiyeokkorean: 0x317A,
  23957. sioskorean: 0x3145,
  23958. siosnieunkorean: 0x317B,
  23959. siosparenkorean: 0x3206,
  23960. siospieupkorean: 0x317D,
  23961. siostikeutkorean: 0x317C,
  23962. six: 0x0036,
  23963. sixarabic: 0x0666,
  23964. sixbengali: 0x09EC,
  23965. sixcircle: 0x2465,
  23966. sixcircleinversesansserif: 0x278F,
  23967. sixdeva: 0x096C,
  23968. sixgujarati: 0x0AEC,
  23969. sixgurmukhi: 0x0A6C,
  23970. sixhackarabic: 0x0666,
  23971. sixhangzhou: 0x3026,
  23972. sixideographicparen: 0x3225,
  23973. sixinferior: 0x2086,
  23974. sixmonospace: 0xFF16,
  23975. sixoldstyle: 0xF736,
  23976. sixparen: 0x2479,
  23977. sixperiod: 0x248D,
  23978. sixpersian: 0x06F6,
  23979. sixroman: 0x2175,
  23980. sixsuperior: 0x2076,
  23981. sixteencircle: 0x246F,
  23982. sixteencurrencydenominatorbengali: 0x09F9,
  23983. sixteenparen: 0x2483,
  23984. sixteenperiod: 0x2497,
  23985. sixthai: 0x0E56,
  23986. slash: 0x002F,
  23987. slashmonospace: 0xFF0F,
  23988. slong: 0x017F,
  23989. slongdotaccent: 0x1E9B,
  23990. smileface: 0x263A,
  23991. smonospace: 0xFF53,
  23992. sofpasuqhebrew: 0x05C3,
  23993. softhyphen: 0x00AD,
  23994. softsigncyrillic: 0x044C,
  23995. sohiragana: 0x305D,
  23996. sokatakana: 0x30BD,
  23997. sokatakanahalfwidth: 0xFF7F,
  23998. soliduslongoverlaycmb: 0x0338,
  23999. solidusshortoverlaycmb: 0x0337,
  24000. sorusithai: 0x0E29,
  24001. sosalathai: 0x0E28,
  24002. sosothai: 0x0E0B,
  24003. sosuathai: 0x0E2A,
  24004. space: 0x0020,
  24005. spacehackarabic: 0x0020,
  24006. spade: 0x2660,
  24007. spadesuitblack: 0x2660,
  24008. spadesuitwhite: 0x2664,
  24009. sparen: 0x24AE,
  24010. squarebelowcmb: 0x033B,
  24011. squarecc: 0x33C4,
  24012. squarecm: 0x339D,
  24013. squarediagonalcrosshatchfill: 0x25A9,
  24014. squarehorizontalfill: 0x25A4,
  24015. squarekg: 0x338F,
  24016. squarekm: 0x339E,
  24017. squarekmcapital: 0x33CE,
  24018. squareln: 0x33D1,
  24019. squarelog: 0x33D2,
  24020. squaremg: 0x338E,
  24021. squaremil: 0x33D5,
  24022. squaremm: 0x339C,
  24023. squaremsquared: 0x33A1,
  24024. squareorthogonalcrosshatchfill: 0x25A6,
  24025. squareupperlefttolowerrightfill: 0x25A7,
  24026. squareupperrighttolowerleftfill: 0x25A8,
  24027. squareverticalfill: 0x25A5,
  24028. squarewhitewithsmallblack: 0x25A3,
  24029. srsquare: 0x33DB,
  24030. ssabengali: 0x09B7,
  24031. ssadeva: 0x0937,
  24032. ssagujarati: 0x0AB7,
  24033. ssangcieuckorean: 0x3149,
  24034. ssanghieuhkorean: 0x3185,
  24035. ssangieungkorean: 0x3180,
  24036. ssangkiyeokkorean: 0x3132,
  24037. ssangnieunkorean: 0x3165,
  24038. ssangpieupkorean: 0x3143,
  24039. ssangsioskorean: 0x3146,
  24040. ssangtikeutkorean: 0x3138,
  24041. ssuperior: 0xF6F2,
  24042. sterling: 0x00A3,
  24043. sterlingmonospace: 0xFFE1,
  24044. strokelongoverlaycmb: 0x0336,
  24045. strokeshortoverlaycmb: 0x0335,
  24046. subset: 0x2282,
  24047. subsetnotequal: 0x228A,
  24048. subsetorequal: 0x2286,
  24049. succeeds: 0x227B,
  24050. suchthat: 0x220B,
  24051. suhiragana: 0x3059,
  24052. sukatakana: 0x30B9,
  24053. sukatakanahalfwidth: 0xFF7D,
  24054. sukunarabic: 0x0652,
  24055. summation: 0x2211,
  24056. sun: 0x263C,
  24057. superset: 0x2283,
  24058. supersetnotequal: 0x228B,
  24059. supersetorequal: 0x2287,
  24060. svsquare: 0x33DC,
  24061. syouwaerasquare: 0x337C,
  24062. t: 0x0074,
  24063. tabengali: 0x09A4,
  24064. tackdown: 0x22A4,
  24065. tackleft: 0x22A3,
  24066. tadeva: 0x0924,
  24067. tagujarati: 0x0AA4,
  24068. tagurmukhi: 0x0A24,
  24069. taharabic: 0x0637,
  24070. tahfinalarabic: 0xFEC2,
  24071. tahinitialarabic: 0xFEC3,
  24072. tahiragana: 0x305F,
  24073. tahmedialarabic: 0xFEC4,
  24074. taisyouerasquare: 0x337D,
  24075. takatakana: 0x30BF,
  24076. takatakanahalfwidth: 0xFF80,
  24077. tatweelarabic: 0x0640,
  24078. tau: 0x03C4,
  24079. tav: 0x05EA,
  24080. tavdages: 0xFB4A,
  24081. tavdagesh: 0xFB4A,
  24082. tavdageshhebrew: 0xFB4A,
  24083. tavhebrew: 0x05EA,
  24084. tbar: 0x0167,
  24085. tbopomofo: 0x310A,
  24086. tcaron: 0x0165,
  24087. tccurl: 0x02A8,
  24088. tcedilla: 0x0163,
  24089. tcheharabic: 0x0686,
  24090. tchehfinalarabic: 0xFB7B,
  24091. tchehinitialarabic: 0xFB7C,
  24092. tchehmedialarabic: 0xFB7D,
  24093. tcircle: 0x24E3,
  24094. tcircumflexbelow: 0x1E71,
  24095. tcommaaccent: 0x0163,
  24096. tdieresis: 0x1E97,
  24097. tdotaccent: 0x1E6B,
  24098. tdotbelow: 0x1E6D,
  24099. tecyrillic: 0x0442,
  24100. tedescendercyrillic: 0x04AD,
  24101. teharabic: 0x062A,
  24102. tehfinalarabic: 0xFE96,
  24103. tehhahinitialarabic: 0xFCA2,
  24104. tehhahisolatedarabic: 0xFC0C,
  24105. tehinitialarabic: 0xFE97,
  24106. tehiragana: 0x3066,
  24107. tehjeeminitialarabic: 0xFCA1,
  24108. tehjeemisolatedarabic: 0xFC0B,
  24109. tehmarbutaarabic: 0x0629,
  24110. tehmarbutafinalarabic: 0xFE94,
  24111. tehmedialarabic: 0xFE98,
  24112. tehmeeminitialarabic: 0xFCA4,
  24113. tehmeemisolatedarabic: 0xFC0E,
  24114. tehnoonfinalarabic: 0xFC73,
  24115. tekatakana: 0x30C6,
  24116. tekatakanahalfwidth: 0xFF83,
  24117. telephone: 0x2121,
  24118. telephoneblack: 0x260E,
  24119. telishagedolahebrew: 0x05A0,
  24120. telishaqetanahebrew: 0x05A9,
  24121. tencircle: 0x2469,
  24122. tenideographicparen: 0x3229,
  24123. tenparen: 0x247D,
  24124. tenperiod: 0x2491,
  24125. tenroman: 0x2179,
  24126. tesh: 0x02A7,
  24127. tet: 0x05D8,
  24128. tetdagesh: 0xFB38,
  24129. tetdageshhebrew: 0xFB38,
  24130. tethebrew: 0x05D8,
  24131. tetsecyrillic: 0x04B5,
  24132. tevirhebrew: 0x059B,
  24133. tevirlefthebrew: 0x059B,
  24134. thabengali: 0x09A5,
  24135. thadeva: 0x0925,
  24136. thagujarati: 0x0AA5,
  24137. thagurmukhi: 0x0A25,
  24138. thalarabic: 0x0630,
  24139. thalfinalarabic: 0xFEAC,
  24140. thanthakhatlowleftthai: 0xF898,
  24141. thanthakhatlowrightthai: 0xF897,
  24142. thanthakhatthai: 0x0E4C,
  24143. thanthakhatupperleftthai: 0xF896,
  24144. theharabic: 0x062B,
  24145. thehfinalarabic: 0xFE9A,
  24146. thehinitialarabic: 0xFE9B,
  24147. thehmedialarabic: 0xFE9C,
  24148. thereexists: 0x2203,
  24149. therefore: 0x2234,
  24150. theta: 0x03B8,
  24151. theta1: 0x03D1,
  24152. thetasymbolgreek: 0x03D1,
  24153. thieuthacirclekorean: 0x3279,
  24154. thieuthaparenkorean: 0x3219,
  24155. thieuthcirclekorean: 0x326B,
  24156. thieuthkorean: 0x314C,
  24157. thieuthparenkorean: 0x320B,
  24158. thirteencircle: 0x246C,
  24159. thirteenparen: 0x2480,
  24160. thirteenperiod: 0x2494,
  24161. thonangmonthothai: 0x0E11,
  24162. thook: 0x01AD,
  24163. thophuthaothai: 0x0E12,
  24164. thorn: 0x00FE,
  24165. thothahanthai: 0x0E17,
  24166. thothanthai: 0x0E10,
  24167. thothongthai: 0x0E18,
  24168. thothungthai: 0x0E16,
  24169. thousandcyrillic: 0x0482,
  24170. thousandsseparatorarabic: 0x066C,
  24171. thousandsseparatorpersian: 0x066C,
  24172. three: 0x0033,
  24173. threearabic: 0x0663,
  24174. threebengali: 0x09E9,
  24175. threecircle: 0x2462,
  24176. threecircleinversesansserif: 0x278C,
  24177. threedeva: 0x0969,
  24178. threeeighths: 0x215C,
  24179. threegujarati: 0x0AE9,
  24180. threegurmukhi: 0x0A69,
  24181. threehackarabic: 0x0663,
  24182. threehangzhou: 0x3023,
  24183. threeideographicparen: 0x3222,
  24184. threeinferior: 0x2083,
  24185. threemonospace: 0xFF13,
  24186. threenumeratorbengali: 0x09F6,
  24187. threeoldstyle: 0xF733,
  24188. threeparen: 0x2476,
  24189. threeperiod: 0x248A,
  24190. threepersian: 0x06F3,
  24191. threequarters: 0x00BE,
  24192. threequartersemdash: 0xF6DE,
  24193. threeroman: 0x2172,
  24194. threesuperior: 0x00B3,
  24195. threethai: 0x0E53,
  24196. thzsquare: 0x3394,
  24197. tihiragana: 0x3061,
  24198. tikatakana: 0x30C1,
  24199. tikatakanahalfwidth: 0xFF81,
  24200. tikeutacirclekorean: 0x3270,
  24201. tikeutaparenkorean: 0x3210,
  24202. tikeutcirclekorean: 0x3262,
  24203. tikeutkorean: 0x3137,
  24204. tikeutparenkorean: 0x3202,
  24205. tilde: 0x02DC,
  24206. tildebelowcmb: 0x0330,
  24207. tildecmb: 0x0303,
  24208. tildecomb: 0x0303,
  24209. tildedoublecmb: 0x0360,
  24210. tildeoperator: 0x223C,
  24211. tildeoverlaycmb: 0x0334,
  24212. tildeverticalcmb: 0x033E,
  24213. timescircle: 0x2297,
  24214. tipehahebrew: 0x0596,
  24215. tipehalefthebrew: 0x0596,
  24216. tippigurmukhi: 0x0A70,
  24217. titlocyrilliccmb: 0x0483,
  24218. tiwnarmenian: 0x057F,
  24219. tlinebelow: 0x1E6F,
  24220. tmonospace: 0xFF54,
  24221. toarmenian: 0x0569,
  24222. tohiragana: 0x3068,
  24223. tokatakana: 0x30C8,
  24224. tokatakanahalfwidth: 0xFF84,
  24225. tonebarextrahighmod: 0x02E5,
  24226. tonebarextralowmod: 0x02E9,
  24227. tonebarhighmod: 0x02E6,
  24228. tonebarlowmod: 0x02E8,
  24229. tonebarmidmod: 0x02E7,
  24230. tonefive: 0x01BD,
  24231. tonesix: 0x0185,
  24232. tonetwo: 0x01A8,
  24233. tonos: 0x0384,
  24234. tonsquare: 0x3327,
  24235. topatakthai: 0x0E0F,
  24236. tortoiseshellbracketleft: 0x3014,
  24237. tortoiseshellbracketleftsmall: 0xFE5D,
  24238. tortoiseshellbracketleftvertical: 0xFE39,
  24239. tortoiseshellbracketright: 0x3015,
  24240. tortoiseshellbracketrightsmall: 0xFE5E,
  24241. tortoiseshellbracketrightvertical: 0xFE3A,
  24242. totaothai: 0x0E15,
  24243. tpalatalhook: 0x01AB,
  24244. tparen: 0x24AF,
  24245. trademark: 0x2122,
  24246. trademarksans: 0xF8EA,
  24247. trademarkserif: 0xF6DB,
  24248. tretroflexhook: 0x0288,
  24249. triagdn: 0x25BC,
  24250. triaglf: 0x25C4,
  24251. triagrt: 0x25BA,
  24252. triagup: 0x25B2,
  24253. ts: 0x02A6,
  24254. tsadi: 0x05E6,
  24255. tsadidagesh: 0xFB46,
  24256. tsadidageshhebrew: 0xFB46,
  24257. tsadihebrew: 0x05E6,
  24258. tsecyrillic: 0x0446,
  24259. tsere: 0x05B5,
  24260. tsere12: 0x05B5,
  24261. tsere1e: 0x05B5,
  24262. tsere2b: 0x05B5,
  24263. tserehebrew: 0x05B5,
  24264. tserenarrowhebrew: 0x05B5,
  24265. tserequarterhebrew: 0x05B5,
  24266. tserewidehebrew: 0x05B5,
  24267. tshecyrillic: 0x045B,
  24268. tsuperior: 0xF6F3,
  24269. ttabengali: 0x099F,
  24270. ttadeva: 0x091F,
  24271. ttagujarati: 0x0A9F,
  24272. ttagurmukhi: 0x0A1F,
  24273. tteharabic: 0x0679,
  24274. ttehfinalarabic: 0xFB67,
  24275. ttehinitialarabic: 0xFB68,
  24276. ttehmedialarabic: 0xFB69,
  24277. tthabengali: 0x09A0,
  24278. tthadeva: 0x0920,
  24279. tthagujarati: 0x0AA0,
  24280. tthagurmukhi: 0x0A20,
  24281. tturned: 0x0287,
  24282. tuhiragana: 0x3064,
  24283. tukatakana: 0x30C4,
  24284. tukatakanahalfwidth: 0xFF82,
  24285. tusmallhiragana: 0x3063,
  24286. tusmallkatakana: 0x30C3,
  24287. tusmallkatakanahalfwidth: 0xFF6F,
  24288. twelvecircle: 0x246B,
  24289. twelveparen: 0x247F,
  24290. twelveperiod: 0x2493,
  24291. twelveroman: 0x217B,
  24292. twentycircle: 0x2473,
  24293. twentyhangzhou: 0x5344,
  24294. twentyparen: 0x2487,
  24295. twentyperiod: 0x249B,
  24296. two: 0x0032,
  24297. twoarabic: 0x0662,
  24298. twobengali: 0x09E8,
  24299. twocircle: 0x2461,
  24300. twocircleinversesansserif: 0x278B,
  24301. twodeva: 0x0968,
  24302. twodotenleader: 0x2025,
  24303. twodotleader: 0x2025,
  24304. twodotleadervertical: 0xFE30,
  24305. twogujarati: 0x0AE8,
  24306. twogurmukhi: 0x0A68,
  24307. twohackarabic: 0x0662,
  24308. twohangzhou: 0x3022,
  24309. twoideographicparen: 0x3221,
  24310. twoinferior: 0x2082,
  24311. twomonospace: 0xFF12,
  24312. twonumeratorbengali: 0x09F5,
  24313. twooldstyle: 0xF732,
  24314. twoparen: 0x2475,
  24315. twoperiod: 0x2489,
  24316. twopersian: 0x06F2,
  24317. tworoman: 0x2171,
  24318. twostroke: 0x01BB,
  24319. twosuperior: 0x00B2,
  24320. twothai: 0x0E52,
  24321. twothirds: 0x2154,
  24322. u: 0x0075,
  24323. uacute: 0x00FA,
  24324. ubar: 0x0289,
  24325. ubengali: 0x0989,
  24326. ubopomofo: 0x3128,
  24327. ubreve: 0x016D,
  24328. ucaron: 0x01D4,
  24329. ucircle: 0x24E4,
  24330. ucircumflex: 0x00FB,
  24331. ucircumflexbelow: 0x1E77,
  24332. ucyrillic: 0x0443,
  24333. udattadeva: 0x0951,
  24334. udblacute: 0x0171,
  24335. udblgrave: 0x0215,
  24336. udeva: 0x0909,
  24337. udieresis: 0x00FC,
  24338. udieresisacute: 0x01D8,
  24339. udieresisbelow: 0x1E73,
  24340. udieresiscaron: 0x01DA,
  24341. udieresiscyrillic: 0x04F1,
  24342. udieresisgrave: 0x01DC,
  24343. udieresismacron: 0x01D6,
  24344. udotbelow: 0x1EE5,
  24345. ugrave: 0x00F9,
  24346. ugujarati: 0x0A89,
  24347. ugurmukhi: 0x0A09,
  24348. uhiragana: 0x3046,
  24349. uhookabove: 0x1EE7,
  24350. uhorn: 0x01B0,
  24351. uhornacute: 0x1EE9,
  24352. uhorndotbelow: 0x1EF1,
  24353. uhorngrave: 0x1EEB,
  24354. uhornhookabove: 0x1EED,
  24355. uhorntilde: 0x1EEF,
  24356. uhungarumlaut: 0x0171,
  24357. uhungarumlautcyrillic: 0x04F3,
  24358. uinvertedbreve: 0x0217,
  24359. ukatakana: 0x30A6,
  24360. ukatakanahalfwidth: 0xFF73,
  24361. ukcyrillic: 0x0479,
  24362. ukorean: 0x315C,
  24363. umacron: 0x016B,
  24364. umacroncyrillic: 0x04EF,
  24365. umacrondieresis: 0x1E7B,
  24366. umatragurmukhi: 0x0A41,
  24367. umonospace: 0xFF55,
  24368. underscore: 0x005F,
  24369. underscoredbl: 0x2017,
  24370. underscoremonospace: 0xFF3F,
  24371. underscorevertical: 0xFE33,
  24372. underscorewavy: 0xFE4F,
  24373. union: 0x222A,
  24374. universal: 0x2200,
  24375. uogonek: 0x0173,
  24376. uparen: 0x24B0,
  24377. upblock: 0x2580,
  24378. upperdothebrew: 0x05C4,
  24379. upsilon: 0x03C5,
  24380. upsilondieresis: 0x03CB,
  24381. upsilondieresistonos: 0x03B0,
  24382. upsilonlatin: 0x028A,
  24383. upsilontonos: 0x03CD,
  24384. uptackbelowcmb: 0x031D,
  24385. uptackmod: 0x02D4,
  24386. uragurmukhi: 0x0A73,
  24387. uring: 0x016F,
  24388. ushortcyrillic: 0x045E,
  24389. usmallhiragana: 0x3045,
  24390. usmallkatakana: 0x30A5,
  24391. usmallkatakanahalfwidth: 0xFF69,
  24392. ustraightcyrillic: 0x04AF,
  24393. ustraightstrokecyrillic: 0x04B1,
  24394. utilde: 0x0169,
  24395. utildeacute: 0x1E79,
  24396. utildebelow: 0x1E75,
  24397. uubengali: 0x098A,
  24398. uudeva: 0x090A,
  24399. uugujarati: 0x0A8A,
  24400. uugurmukhi: 0x0A0A,
  24401. uumatragurmukhi: 0x0A42,
  24402. uuvowelsignbengali: 0x09C2,
  24403. uuvowelsigndeva: 0x0942,
  24404. uuvowelsigngujarati: 0x0AC2,
  24405. uvowelsignbengali: 0x09C1,
  24406. uvowelsigndeva: 0x0941,
  24407. uvowelsigngujarati: 0x0AC1,
  24408. v: 0x0076,
  24409. vadeva: 0x0935,
  24410. vagujarati: 0x0AB5,
  24411. vagurmukhi: 0x0A35,
  24412. vakatakana: 0x30F7,
  24413. vav: 0x05D5,
  24414. vavdagesh: 0xFB35,
  24415. vavdagesh65: 0xFB35,
  24416. vavdageshhebrew: 0xFB35,
  24417. vavhebrew: 0x05D5,
  24418. vavholam: 0xFB4B,
  24419. vavholamhebrew: 0xFB4B,
  24420. vavvavhebrew: 0x05F0,
  24421. vavyodhebrew: 0x05F1,
  24422. vcircle: 0x24E5,
  24423. vdotbelow: 0x1E7F,
  24424. vecyrillic: 0x0432,
  24425. veharabic: 0x06A4,
  24426. vehfinalarabic: 0xFB6B,
  24427. vehinitialarabic: 0xFB6C,
  24428. vehmedialarabic: 0xFB6D,
  24429. vekatakana: 0x30F9,
  24430. venus: 0x2640,
  24431. verticalbar: 0x007C,
  24432. verticallineabovecmb: 0x030D,
  24433. verticallinebelowcmb: 0x0329,
  24434. verticallinelowmod: 0x02CC,
  24435. verticallinemod: 0x02C8,
  24436. vewarmenian: 0x057E,
  24437. vhook: 0x028B,
  24438. vikatakana: 0x30F8,
  24439. viramabengali: 0x09CD,
  24440. viramadeva: 0x094D,
  24441. viramagujarati: 0x0ACD,
  24442. visargabengali: 0x0983,
  24443. visargadeva: 0x0903,
  24444. visargagujarati: 0x0A83,
  24445. vmonospace: 0xFF56,
  24446. voarmenian: 0x0578,
  24447. voicediterationhiragana: 0x309E,
  24448. voicediterationkatakana: 0x30FE,
  24449. voicedmarkkana: 0x309B,
  24450. voicedmarkkanahalfwidth: 0xFF9E,
  24451. vokatakana: 0x30FA,
  24452. vparen: 0x24B1,
  24453. vtilde: 0x1E7D,
  24454. vturned: 0x028C,
  24455. vuhiragana: 0x3094,
  24456. vukatakana: 0x30F4,
  24457. w: 0x0077,
  24458. wacute: 0x1E83,
  24459. waekorean: 0x3159,
  24460. wahiragana: 0x308F,
  24461. wakatakana: 0x30EF,
  24462. wakatakanahalfwidth: 0xFF9C,
  24463. wakorean: 0x3158,
  24464. wasmallhiragana: 0x308E,
  24465. wasmallkatakana: 0x30EE,
  24466. wattosquare: 0x3357,
  24467. wavedash: 0x301C,
  24468. wavyunderscorevertical: 0xFE34,
  24469. wawarabic: 0x0648,
  24470. wawfinalarabic: 0xFEEE,
  24471. wawhamzaabovearabic: 0x0624,
  24472. wawhamzaabovefinalarabic: 0xFE86,
  24473. wbsquare: 0x33DD,
  24474. wcircle: 0x24E6,
  24475. wcircumflex: 0x0175,
  24476. wdieresis: 0x1E85,
  24477. wdotaccent: 0x1E87,
  24478. wdotbelow: 0x1E89,
  24479. wehiragana: 0x3091,
  24480. weierstrass: 0x2118,
  24481. wekatakana: 0x30F1,
  24482. wekorean: 0x315E,
  24483. weokorean: 0x315D,
  24484. wgrave: 0x1E81,
  24485. whitebullet: 0x25E6,
  24486. whitecircle: 0x25CB,
  24487. whitecircleinverse: 0x25D9,
  24488. whitecornerbracketleft: 0x300E,
  24489. whitecornerbracketleftvertical: 0xFE43,
  24490. whitecornerbracketright: 0x300F,
  24491. whitecornerbracketrightvertical: 0xFE44,
  24492. whitediamond: 0x25C7,
  24493. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24494. whitedownpointingsmalltriangle: 0x25BF,
  24495. whitedownpointingtriangle: 0x25BD,
  24496. whiteleftpointingsmalltriangle: 0x25C3,
  24497. whiteleftpointingtriangle: 0x25C1,
  24498. whitelenticularbracketleft: 0x3016,
  24499. whitelenticularbracketright: 0x3017,
  24500. whiterightpointingsmalltriangle: 0x25B9,
  24501. whiterightpointingtriangle: 0x25B7,
  24502. whitesmallsquare: 0x25AB,
  24503. whitesmilingface: 0x263A,
  24504. whitesquare: 0x25A1,
  24505. whitestar: 0x2606,
  24506. whitetelephone: 0x260F,
  24507. whitetortoiseshellbracketleft: 0x3018,
  24508. whitetortoiseshellbracketright: 0x3019,
  24509. whiteuppointingsmalltriangle: 0x25B5,
  24510. whiteuppointingtriangle: 0x25B3,
  24511. wihiragana: 0x3090,
  24512. wikatakana: 0x30F0,
  24513. wikorean: 0x315F,
  24514. wmonospace: 0xFF57,
  24515. wohiragana: 0x3092,
  24516. wokatakana: 0x30F2,
  24517. wokatakanahalfwidth: 0xFF66,
  24518. won: 0x20A9,
  24519. wonmonospace: 0xFFE6,
  24520. wowaenthai: 0x0E27,
  24521. wparen: 0x24B2,
  24522. wring: 0x1E98,
  24523. wsuperior: 0x02B7,
  24524. wturned: 0x028D,
  24525. wynn: 0x01BF,
  24526. x: 0x0078,
  24527. xabovecmb: 0x033D,
  24528. xbopomofo: 0x3112,
  24529. xcircle: 0x24E7,
  24530. xdieresis: 0x1E8D,
  24531. xdotaccent: 0x1E8B,
  24532. xeharmenian: 0x056D,
  24533. xi: 0x03BE,
  24534. xmonospace: 0xFF58,
  24535. xparen: 0x24B3,
  24536. xsuperior: 0x02E3,
  24537. y: 0x0079,
  24538. yaadosquare: 0x334E,
  24539. yabengali: 0x09AF,
  24540. yacute: 0x00FD,
  24541. yadeva: 0x092F,
  24542. yaekorean: 0x3152,
  24543. yagujarati: 0x0AAF,
  24544. yagurmukhi: 0x0A2F,
  24545. yahiragana: 0x3084,
  24546. yakatakana: 0x30E4,
  24547. yakatakanahalfwidth: 0xFF94,
  24548. yakorean: 0x3151,
  24549. yamakkanthai: 0x0E4E,
  24550. yasmallhiragana: 0x3083,
  24551. yasmallkatakana: 0x30E3,
  24552. yasmallkatakanahalfwidth: 0xFF6C,
  24553. yatcyrillic: 0x0463,
  24554. ycircle: 0x24E8,
  24555. ycircumflex: 0x0177,
  24556. ydieresis: 0x00FF,
  24557. ydotaccent: 0x1E8F,
  24558. ydotbelow: 0x1EF5,
  24559. yeharabic: 0x064A,
  24560. yehbarreearabic: 0x06D2,
  24561. yehbarreefinalarabic: 0xFBAF,
  24562. yehfinalarabic: 0xFEF2,
  24563. yehhamzaabovearabic: 0x0626,
  24564. yehhamzaabovefinalarabic: 0xFE8A,
  24565. yehhamzaaboveinitialarabic: 0xFE8B,
  24566. yehhamzaabovemedialarabic: 0xFE8C,
  24567. yehinitialarabic: 0xFEF3,
  24568. yehmedialarabic: 0xFEF4,
  24569. yehmeeminitialarabic: 0xFCDD,
  24570. yehmeemisolatedarabic: 0xFC58,
  24571. yehnoonfinalarabic: 0xFC94,
  24572. yehthreedotsbelowarabic: 0x06D1,
  24573. yekorean: 0x3156,
  24574. yen: 0x00A5,
  24575. yenmonospace: 0xFFE5,
  24576. yeokorean: 0x3155,
  24577. yeorinhieuhkorean: 0x3186,
  24578. yerahbenyomohebrew: 0x05AA,
  24579. yerahbenyomolefthebrew: 0x05AA,
  24580. yericyrillic: 0x044B,
  24581. yerudieresiscyrillic: 0x04F9,
  24582. yesieungkorean: 0x3181,
  24583. yesieungpansioskorean: 0x3183,
  24584. yesieungsioskorean: 0x3182,
  24585. yetivhebrew: 0x059A,
  24586. ygrave: 0x1EF3,
  24587. yhook: 0x01B4,
  24588. yhookabove: 0x1EF7,
  24589. yiarmenian: 0x0575,
  24590. yicyrillic: 0x0457,
  24591. yikorean: 0x3162,
  24592. yinyang: 0x262F,
  24593. yiwnarmenian: 0x0582,
  24594. ymonospace: 0xFF59,
  24595. yod: 0x05D9,
  24596. yoddagesh: 0xFB39,
  24597. yoddageshhebrew: 0xFB39,
  24598. yodhebrew: 0x05D9,
  24599. yodyodhebrew: 0x05F2,
  24600. yodyodpatahhebrew: 0xFB1F,
  24601. yohiragana: 0x3088,
  24602. yoikorean: 0x3189,
  24603. yokatakana: 0x30E8,
  24604. yokatakanahalfwidth: 0xFF96,
  24605. yokorean: 0x315B,
  24606. yosmallhiragana: 0x3087,
  24607. yosmallkatakana: 0x30E7,
  24608. yosmallkatakanahalfwidth: 0xFF6E,
  24609. yotgreek: 0x03F3,
  24610. yoyaekorean: 0x3188,
  24611. yoyakorean: 0x3187,
  24612. yoyakthai: 0x0E22,
  24613. yoyingthai: 0x0E0D,
  24614. yparen: 0x24B4,
  24615. ypogegrammeni: 0x037A,
  24616. ypogegrammenigreekcmb: 0x0345,
  24617. yr: 0x01A6,
  24618. yring: 0x1E99,
  24619. ysuperior: 0x02B8,
  24620. ytilde: 0x1EF9,
  24621. yturned: 0x028E,
  24622. yuhiragana: 0x3086,
  24623. yuikorean: 0x318C,
  24624. yukatakana: 0x30E6,
  24625. yukatakanahalfwidth: 0xFF95,
  24626. yukorean: 0x3160,
  24627. yusbigcyrillic: 0x046B,
  24628. yusbigiotifiedcyrillic: 0x046D,
  24629. yuslittlecyrillic: 0x0467,
  24630. yuslittleiotifiedcyrillic: 0x0469,
  24631. yusmallhiragana: 0x3085,
  24632. yusmallkatakana: 0x30E5,
  24633. yusmallkatakanahalfwidth: 0xFF6D,
  24634. yuyekorean: 0x318B,
  24635. yuyeokorean: 0x318A,
  24636. yyabengali: 0x09DF,
  24637. yyadeva: 0x095F,
  24638. z: 0x007A,
  24639. zaarmenian: 0x0566,
  24640. zacute: 0x017A,
  24641. zadeva: 0x095B,
  24642. zagurmukhi: 0x0A5B,
  24643. zaharabic: 0x0638,
  24644. zahfinalarabic: 0xFEC6,
  24645. zahinitialarabic: 0xFEC7,
  24646. zahiragana: 0x3056,
  24647. zahmedialarabic: 0xFEC8,
  24648. zainarabic: 0x0632,
  24649. zainfinalarabic: 0xFEB0,
  24650. zakatakana: 0x30B6,
  24651. zaqefgadolhebrew: 0x0595,
  24652. zaqefqatanhebrew: 0x0594,
  24653. zarqahebrew: 0x0598,
  24654. zayin: 0x05D6,
  24655. zayindagesh: 0xFB36,
  24656. zayindageshhebrew: 0xFB36,
  24657. zayinhebrew: 0x05D6,
  24658. zbopomofo: 0x3117,
  24659. zcaron: 0x017E,
  24660. zcircle: 0x24E9,
  24661. zcircumflex: 0x1E91,
  24662. zcurl: 0x0291,
  24663. zdot: 0x017C,
  24664. zdotaccent: 0x017C,
  24665. zdotbelow: 0x1E93,
  24666. zecyrillic: 0x0437,
  24667. zedescendercyrillic: 0x0499,
  24668. zedieresiscyrillic: 0x04DF,
  24669. zehiragana: 0x305C,
  24670. zekatakana: 0x30BC,
  24671. zero: 0x0030,
  24672. zeroarabic: 0x0660,
  24673. zerobengali: 0x09E6,
  24674. zerodeva: 0x0966,
  24675. zerogujarati: 0x0AE6,
  24676. zerogurmukhi: 0x0A66,
  24677. zerohackarabic: 0x0660,
  24678. zeroinferior: 0x2080,
  24679. zeromonospace: 0xFF10,
  24680. zerooldstyle: 0xF730,
  24681. zeropersian: 0x06F0,
  24682. zerosuperior: 0x2070,
  24683. zerothai: 0x0E50,
  24684. zerowidthjoiner: 0xFEFF,
  24685. zerowidthnonjoiner: 0x200C,
  24686. zerowidthspace: 0x200B,
  24687. zeta: 0x03B6,
  24688. zhbopomofo: 0x3113,
  24689. zhearmenian: 0x056A,
  24690. zhebrevecyrillic: 0x04C2,
  24691. zhecyrillic: 0x0436,
  24692. zhedescendercyrillic: 0x0497,
  24693. zhedieresiscyrillic: 0x04DD,
  24694. zihiragana: 0x3058,
  24695. zikatakana: 0x30B8,
  24696. zinorhebrew: 0x05AE,
  24697. zlinebelow: 0x1E95,
  24698. zmonospace: 0xFF5A,
  24699. zohiragana: 0x305E,
  24700. zokatakana: 0x30BE,
  24701. zparen: 0x24B5,
  24702. zretroflexhook: 0x0290,
  24703. zstroke: 0x01B6,
  24704. zuhiragana: 0x305A,
  24705. zukatakana: 0x30BA,
  24706. '.notdef': 0x0000
  24707. };
  24708. var DingbatsGlyphsUnicode = {
  24709. space: 0x0020,
  24710. a1: 0x2701,
  24711. a2: 0x2702,
  24712. a202: 0x2703,
  24713. a3: 0x2704,
  24714. a4: 0x260E,
  24715. a5: 0x2706,
  24716. a119: 0x2707,
  24717. a118: 0x2708,
  24718. a117: 0x2709,
  24719. a11: 0x261B,
  24720. a12: 0x261E,
  24721. a13: 0x270C,
  24722. a14: 0x270D,
  24723. a15: 0x270E,
  24724. a16: 0x270F,
  24725. a105: 0x2710,
  24726. a17: 0x2711,
  24727. a18: 0x2712,
  24728. a19: 0x2713,
  24729. a20: 0x2714,
  24730. a21: 0x2715,
  24731. a22: 0x2716,
  24732. a23: 0x2717,
  24733. a24: 0x2718,
  24734. a25: 0x2719,
  24735. a26: 0x271A,
  24736. a27: 0x271B,
  24737. a28: 0x271C,
  24738. a6: 0x271D,
  24739. a7: 0x271E,
  24740. a8: 0x271F,
  24741. a9: 0x2720,
  24742. a10: 0x2721,
  24743. a29: 0x2722,
  24744. a30: 0x2723,
  24745. a31: 0x2724,
  24746. a32: 0x2725,
  24747. a33: 0x2726,
  24748. a34: 0x2727,
  24749. a35: 0x2605,
  24750. a36: 0x2729,
  24751. a37: 0x272A,
  24752. a38: 0x272B,
  24753. a39: 0x272C,
  24754. a40: 0x272D,
  24755. a41: 0x272E,
  24756. a42: 0x272F,
  24757. a43: 0x2730,
  24758. a44: 0x2731,
  24759. a45: 0x2732,
  24760. a46: 0x2733,
  24761. a47: 0x2734,
  24762. a48: 0x2735,
  24763. a49: 0x2736,
  24764. a50: 0x2737,
  24765. a51: 0x2738,
  24766. a52: 0x2739,
  24767. a53: 0x273A,
  24768. a54: 0x273B,
  24769. a55: 0x273C,
  24770. a56: 0x273D,
  24771. a57: 0x273E,
  24772. a58: 0x273F,
  24773. a59: 0x2740,
  24774. a60: 0x2741,
  24775. a61: 0x2742,
  24776. a62: 0x2743,
  24777. a63: 0x2744,
  24778. a64: 0x2745,
  24779. a65: 0x2746,
  24780. a66: 0x2747,
  24781. a67: 0x2748,
  24782. a68: 0x2749,
  24783. a69: 0x274A,
  24784. a70: 0x274B,
  24785. a71: 0x25CF,
  24786. a72: 0x274D,
  24787. a73: 0x25A0,
  24788. a74: 0x274F,
  24789. a203: 0x2750,
  24790. a75: 0x2751,
  24791. a204: 0x2752,
  24792. a76: 0x25B2,
  24793. a77: 0x25BC,
  24794. a78: 0x25C6,
  24795. a79: 0x2756,
  24796. a81: 0x25D7,
  24797. a82: 0x2758,
  24798. a83: 0x2759,
  24799. a84: 0x275A,
  24800. a97: 0x275B,
  24801. a98: 0x275C,
  24802. a99: 0x275D,
  24803. a100: 0x275E,
  24804. a101: 0x2761,
  24805. a102: 0x2762,
  24806. a103: 0x2763,
  24807. a104: 0x2764,
  24808. a106: 0x2765,
  24809. a107: 0x2766,
  24810. a108: 0x2767,
  24811. a112: 0x2663,
  24812. a111: 0x2666,
  24813. a110: 0x2665,
  24814. a109: 0x2660,
  24815. a120: 0x2460,
  24816. a121: 0x2461,
  24817. a122: 0x2462,
  24818. a123: 0x2463,
  24819. a124: 0x2464,
  24820. a125: 0x2465,
  24821. a126: 0x2466,
  24822. a127: 0x2467,
  24823. a128: 0x2468,
  24824. a129: 0x2469,
  24825. a130: 0x2776,
  24826. a131: 0x2777,
  24827. a132: 0x2778,
  24828. a133: 0x2779,
  24829. a134: 0x277A,
  24830. a135: 0x277B,
  24831. a136: 0x277C,
  24832. a137: 0x277D,
  24833. a138: 0x277E,
  24834. a139: 0x277F,
  24835. a140: 0x2780,
  24836. a141: 0x2781,
  24837. a142: 0x2782,
  24838. a143: 0x2783,
  24839. a144: 0x2784,
  24840. a145: 0x2785,
  24841. a146: 0x2786,
  24842. a147: 0x2787,
  24843. a148: 0x2788,
  24844. a149: 0x2789,
  24845. a150: 0x278A,
  24846. a151: 0x278B,
  24847. a152: 0x278C,
  24848. a153: 0x278D,
  24849. a154: 0x278E,
  24850. a155: 0x278F,
  24851. a156: 0x2790,
  24852. a157: 0x2791,
  24853. a158: 0x2792,
  24854. a159: 0x2793,
  24855. a160: 0x2794,
  24856. a161: 0x2192,
  24857. a163: 0x2194,
  24858. a164: 0x2195,
  24859. a196: 0x2798,
  24860. a165: 0x2799,
  24861. a192: 0x279A,
  24862. a166: 0x279B,
  24863. a167: 0x279C,
  24864. a168: 0x279D,
  24865. a169: 0x279E,
  24866. a170: 0x279F,
  24867. a171: 0x27A0,
  24868. a172: 0x27A1,
  24869. a173: 0x27A2,
  24870. a162: 0x27A3,
  24871. a174: 0x27A4,
  24872. a175: 0x27A5,
  24873. a176: 0x27A6,
  24874. a177: 0x27A7,
  24875. a178: 0x27A8,
  24876. a179: 0x27A9,
  24877. a193: 0x27AA,
  24878. a180: 0x27AB,
  24879. a199: 0x27AC,
  24880. a181: 0x27AD,
  24881. a200: 0x27AE,
  24882. a182: 0x27AF,
  24883. a201: 0x27B1,
  24884. a183: 0x27B2,
  24885. a184: 0x27B3,
  24886. a197: 0x27B4,
  24887. a185: 0x27B5,
  24888. a194: 0x27B6,
  24889. a198: 0x27B7,
  24890. a186: 0x27B8,
  24891. a195: 0x27B9,
  24892. a187: 0x27BA,
  24893. a188: 0x27BB,
  24894. a189: 0x27BC,
  24895. a190: 0x27BD,
  24896. a191: 0x27BE,
  24897. a89: 0x2768, // 0xF8D7
  24898. a90: 0x2769, // 0xF8D8
  24899. a93: 0x276A, // 0xF8D9
  24900. a94: 0x276B, // 0xF8DA
  24901. a91: 0x276C, // 0xF8DB
  24902. a92: 0x276D, // 0xF8DC
  24903. a205: 0x276E, // 0xF8DD
  24904. a85: 0x276F, // 0xF8DE
  24905. a206: 0x2770, // 0xF8DF
  24906. a86: 0x2771, // 0xF8E0
  24907. a87: 0x2772, // 0xF8E1
  24908. a88: 0x2773, // 0xF8E2
  24909. a95: 0x2774, // 0xF8E3
  24910. a96: 0x2775, // 0xF8E4
  24911. '.notdef': 0x0000
  24912. };
  24913. var PDFImage = (function PDFImageClosure() {
  24914. /**
  24915. * Decode the image in the main thread if it supported. Resovles the promise
  24916. * when the image data is ready.
  24917. */
  24918. function handleImageData(handler, xref, res, image) {
  24919. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24920. // For natively supported jpegs send them to the main thread for decoding.
  24921. var dict = image.dict;
  24922. var colorSpace = dict.get('ColorSpace', 'CS');
  24923. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24924. var numComps = colorSpace.numComps;
  24925. var decodePromise = handler.sendWithPromise('JpegDecode',
  24926. [image.getIR(), numComps]);
  24927. return decodePromise.then(function (message) {
  24928. var data = message.data;
  24929. return new Stream(data, 0, data.length, image.dict);
  24930. });
  24931. } else {
  24932. return Promise.resolve(image);
  24933. }
  24934. }
  24935. /**
  24936. * Decode and clamp a value. The formula is different from the spec because we
  24937. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24938. */
  24939. function decodeAndClamp(value, addend, coefficient, max) {
  24940. value = addend + value * coefficient;
  24941. // Clamp the value to the range
  24942. return (value < 0 ? 0 : (value > max ? max : value));
  24943. }
  24944. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24945. this.image = image;
  24946. var dict = image.dict;
  24947. if (dict.has('Filter')) {
  24948. var filter = dict.get('Filter').name;
  24949. if (filter === 'JPXDecode') {
  24950. var jpxImage = new JpxImage();
  24951. jpxImage.parseImageProperties(image.stream);
  24952. image.stream.reset();
  24953. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24954. image.numComps = jpxImage.componentsCount;
  24955. } else if (filter === 'JBIG2Decode') {
  24956. image.bitsPerComponent = 1;
  24957. image.numComps = 1;
  24958. }
  24959. }
  24960. // TODO cache rendered images?
  24961. this.width = dict.get('Width', 'W');
  24962. this.height = dict.get('Height', 'H');
  24963. if (this.width < 1 || this.height < 1) {
  24964. error('Invalid image width: ' + this.width + ' or height: ' +
  24965. this.height);
  24966. }
  24967. this.interpolate = dict.get('Interpolate', 'I') || false;
  24968. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24969. this.matte = dict.get('Matte') || false;
  24970. var bitsPerComponent = image.bitsPerComponent;
  24971. if (!bitsPerComponent) {
  24972. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24973. if (!bitsPerComponent) {
  24974. if (this.imageMask) {
  24975. bitsPerComponent = 1;
  24976. } else {
  24977. error('Bits per component missing in image: ' + this.imageMask);
  24978. }
  24979. }
  24980. }
  24981. this.bpc = bitsPerComponent;
  24982. if (!this.imageMask) {
  24983. var colorSpace = dict.get('ColorSpace', 'CS');
  24984. if (!colorSpace) {
  24985. info('JPX images (which do not require color spaces)');
  24986. switch (image.numComps) {
  24987. case 1:
  24988. colorSpace = Name.get('DeviceGray');
  24989. break;
  24990. case 3:
  24991. colorSpace = Name.get('DeviceRGB');
  24992. break;
  24993. case 4:
  24994. colorSpace = Name.get('DeviceCMYK');
  24995. break;
  24996. default:
  24997. error('JPX images with ' + this.numComps +
  24998. ' color components not supported.');
  24999. }
  25000. }
  25001. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25002. this.numComps = this.colorSpace.numComps;
  25003. }
  25004. this.decode = dict.get('Decode', 'D');
  25005. this.needsDecode = false;
  25006. if (this.decode &&
  25007. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  25008. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  25009. this.needsDecode = true;
  25010. // Do some preprocessing to avoid more math.
  25011. var max = (1 << bitsPerComponent) - 1;
  25012. this.decodeCoefficients = [];
  25013. this.decodeAddends = [];
  25014. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  25015. var dmin = this.decode[i];
  25016. var dmax = this.decode[i + 1];
  25017. this.decodeCoefficients[j] = dmax - dmin;
  25018. this.decodeAddends[j] = max * dmin;
  25019. }
  25020. }
  25021. if (smask) {
  25022. this.smask = new PDFImage(xref, res, smask, false);
  25023. } else if (mask) {
  25024. if (isStream(mask)) {
  25025. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  25026. } else {
  25027. // Color key mask (just an array).
  25028. this.mask = mask;
  25029. }
  25030. }
  25031. }
  25032. /**
  25033. * Handles processing of image data and returns the Promise that is resolved
  25034. * with a PDFImage when the image is ready to be used.
  25035. */
  25036. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  25037. res, image, inline) {
  25038. var imagePromise = handleImageData(handler, xref, res, image);
  25039. var smaskPromise;
  25040. var maskPromise;
  25041. var smask = image.dict.get('SMask');
  25042. var mask = image.dict.get('Mask');
  25043. if (smask) {
  25044. smaskPromise = handleImageData(handler, xref, res, smask);
  25045. maskPromise = Promise.resolve(null);
  25046. } else {
  25047. smaskPromise = Promise.resolve(null);
  25048. if (mask) {
  25049. if (isStream(mask)) {
  25050. maskPromise = handleImageData(handler, xref, res, mask);
  25051. } else if (isArray(mask)) {
  25052. maskPromise = Promise.resolve(mask);
  25053. } else {
  25054. warn('Unsupported mask format.');
  25055. maskPromise = Promise.resolve(null);
  25056. }
  25057. } else {
  25058. maskPromise = Promise.resolve(null);
  25059. }
  25060. }
  25061. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25062. function(results) {
  25063. var imageData = results[0];
  25064. var smaskData = results[1];
  25065. var maskData = results[2];
  25066. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25067. });
  25068. };
  25069. /**
  25070. * Resize an image using the nearest neighbor algorithm. Currently only
  25071. * supports one and three component images.
  25072. * @param {TypedArray} pixels The original image with one component.
  25073. * @param {Number} bpc Number of bits per component.
  25074. * @param {Number} components Number of color components, 1 or 3 is supported.
  25075. * @param {Number} w1 Original width.
  25076. * @param {Number} h1 Original height.
  25077. * @param {Number} w2 New width.
  25078. * @param {Number} h2 New height.
  25079. * @param {TypedArray} dest (Optional) The destination buffer.
  25080. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25081. * @return {TypedArray} Resized image data.
  25082. */
  25083. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25084. w1, h1, w2, h2, dest, alpha01) {
  25085. if (components !== 1 && components !== 3) {
  25086. error('Unsupported component count for resizing.');
  25087. }
  25088. var length = w2 * h2 * components;
  25089. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25090. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25091. var xRatio = w1 / w2;
  25092. var yRatio = h1 / h2;
  25093. var i, j, py, newIndex = 0, oldIndex;
  25094. var xScaled = new Uint16Array(w2);
  25095. var w1Scanline = w1 * components;
  25096. if (alpha01 !== 1) {
  25097. alpha01 = 0;
  25098. }
  25099. for (j = 0; j < w2; j++) {
  25100. xScaled[j] = Math.floor(j * xRatio) * components;
  25101. }
  25102. if (components === 1) {
  25103. for (i = 0; i < h2; i++) {
  25104. py = Math.floor(i * yRatio) * w1Scanline;
  25105. for (j = 0; j < w2; j++) {
  25106. oldIndex = py + xScaled[j];
  25107. temp[newIndex++] = pixels[oldIndex];
  25108. }
  25109. }
  25110. } else if (components === 3) {
  25111. for (i = 0; i < h2; i++) {
  25112. py = Math.floor(i * yRatio) * w1Scanline;
  25113. for (j = 0; j < w2; j++) {
  25114. oldIndex = py + xScaled[j];
  25115. temp[newIndex++] = pixels[oldIndex++];
  25116. temp[newIndex++] = pixels[oldIndex++];
  25117. temp[newIndex++] = pixels[oldIndex++];
  25118. newIndex += alpha01;
  25119. }
  25120. }
  25121. }
  25122. return temp;
  25123. };
  25124. PDFImage.createMask =
  25125. function PDFImage_createMask(imgArray, width, height,
  25126. imageIsFromDecodeStream, inverseDecode) {
  25127. // |imgArray| might not contain full data for every pixel of the mask, so
  25128. // we need to distinguish between |computedLength| and |actualLength|.
  25129. // In particular, if inverseDecode is true, then the array we return must
  25130. // have a length of |computedLength|.
  25131. var computedLength = ((width + 7) >> 3) * height;
  25132. var actualLength = imgArray.byteLength;
  25133. var haveFullData = computedLength === actualLength;
  25134. var data, i;
  25135. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25136. // imgArray came from a DecodeStream and its data is in an appropriate
  25137. // form, so we can just transfer it.
  25138. data = imgArray;
  25139. } else if (!inverseDecode) {
  25140. data = new Uint8Array(actualLength);
  25141. data.set(imgArray);
  25142. } else {
  25143. data = new Uint8Array(computedLength);
  25144. data.set(imgArray);
  25145. for (i = actualLength; i < computedLength; i++) {
  25146. data[i] = 0xff;
  25147. }
  25148. }
  25149. // If necessary, invert the original mask data (but not any extra we might
  25150. // have added above). It's safe to modify the array -- whether it's the
  25151. // original or a copy, we're about to transfer it anyway, so nothing else
  25152. // in this thread can be relying on its contents.
  25153. if (inverseDecode) {
  25154. for (i = 0; i < actualLength; i++) {
  25155. data[i] = ~data[i];
  25156. }
  25157. }
  25158. return {data: data, width: width, height: height};
  25159. };
  25160. PDFImage.prototype = {
  25161. get drawWidth() {
  25162. return Math.max(this.width,
  25163. this.smask && this.smask.width || 0,
  25164. this.mask && this.mask.width || 0);
  25165. },
  25166. get drawHeight() {
  25167. return Math.max(this.height,
  25168. this.smask && this.smask.height || 0,
  25169. this.mask && this.mask.height || 0);
  25170. },
  25171. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25172. var bpc = this.bpc;
  25173. var numComps = this.numComps;
  25174. var decodeAddends = this.decodeAddends;
  25175. var decodeCoefficients = this.decodeCoefficients;
  25176. var max = (1 << bpc) - 1;
  25177. var i, ii;
  25178. if (bpc === 1) {
  25179. // If the buffer needed decode that means it just needs to be inverted.
  25180. for (i = 0, ii = buffer.length; i < ii; i++) {
  25181. buffer[i] = +!(buffer[i]);
  25182. }
  25183. return;
  25184. }
  25185. var index = 0;
  25186. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25187. for (var j = 0; j < numComps; j++) {
  25188. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25189. decodeCoefficients[j], max);
  25190. index++;
  25191. }
  25192. }
  25193. },
  25194. getComponents: function PDFImage_getComponents(buffer) {
  25195. var bpc = this.bpc;
  25196. // This image doesn't require any extra work.
  25197. if (bpc === 8) {
  25198. return buffer;
  25199. }
  25200. var width = this.width;
  25201. var height = this.height;
  25202. var numComps = this.numComps;
  25203. var length = width * height * numComps;
  25204. var bufferPos = 0;
  25205. var output = (bpc <= 8 ? new Uint8Array(length) :
  25206. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25207. var rowComps = width * numComps;
  25208. var max = (1 << bpc) - 1;
  25209. var i = 0, ii, buf;
  25210. if (bpc === 1) {
  25211. // Optimization for reading 1 bpc images.
  25212. var mask, loop1End, loop2End;
  25213. for (var j = 0; j < height; j++) {
  25214. loop1End = i + (rowComps & ~7);
  25215. loop2End = i + rowComps;
  25216. // unroll loop for all full bytes
  25217. while (i < loop1End) {
  25218. buf = buffer[bufferPos++];
  25219. output[i] = (buf >> 7) & 1;
  25220. output[i + 1] = (buf >> 6) & 1;
  25221. output[i + 2] = (buf >> 5) & 1;
  25222. output[i + 3] = (buf >> 4) & 1;
  25223. output[i + 4] = (buf >> 3) & 1;
  25224. output[i + 5] = (buf >> 2) & 1;
  25225. output[i + 6] = (buf >> 1) & 1;
  25226. output[i + 7] = buf & 1;
  25227. i += 8;
  25228. }
  25229. // handle remaing bits
  25230. if (i < loop2End) {
  25231. buf = buffer[bufferPos++];
  25232. mask = 128;
  25233. while (i < loop2End) {
  25234. output[i++] = +!!(buf & mask);
  25235. mask >>= 1;
  25236. }
  25237. }
  25238. }
  25239. } else {
  25240. // The general case that handles all other bpc values.
  25241. var bits = 0;
  25242. buf = 0;
  25243. for (i = 0, ii = length; i < ii; ++i) {
  25244. if (i % rowComps === 0) {
  25245. buf = 0;
  25246. bits = 0;
  25247. }
  25248. while (bits < bpc) {
  25249. buf = (buf << 8) | buffer[bufferPos++];
  25250. bits += 8;
  25251. }
  25252. var remainingBits = bits - bpc;
  25253. var value = buf >> remainingBits;
  25254. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25255. buf = buf & ((1 << remainingBits) - 1);
  25256. bits = remainingBits;
  25257. }
  25258. }
  25259. return output;
  25260. },
  25261. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25262. actualHeight, image) {
  25263. var smask = this.smask;
  25264. var mask = this.mask;
  25265. var alphaBuf, sw, sh, i, ii, j;
  25266. if (smask) {
  25267. sw = smask.width;
  25268. sh = smask.height;
  25269. alphaBuf = new Uint8Array(sw * sh);
  25270. smask.fillGrayBuffer(alphaBuf);
  25271. if (sw !== width || sh !== height) {
  25272. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25273. height);
  25274. }
  25275. } else if (mask) {
  25276. if (mask instanceof PDFImage) {
  25277. sw = mask.width;
  25278. sh = mask.height;
  25279. alphaBuf = new Uint8Array(sw * sh);
  25280. mask.numComps = 1;
  25281. mask.fillGrayBuffer(alphaBuf);
  25282. // Need to invert values in rgbaBuf
  25283. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25284. alphaBuf[i] = 255 - alphaBuf[i];
  25285. }
  25286. if (sw !== width || sh !== height) {
  25287. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25288. height);
  25289. }
  25290. } else if (isArray(mask)) {
  25291. // Color key mask: if any of the compontents are outside the range
  25292. // then they should be painted.
  25293. alphaBuf = new Uint8Array(width * height);
  25294. var numComps = this.numComps;
  25295. for (i = 0, ii = width * height; i < ii; ++i) {
  25296. var opacity = 0;
  25297. var imageOffset = i * numComps;
  25298. for (j = 0; j < numComps; ++j) {
  25299. var color = image[imageOffset + j];
  25300. var maskOffset = j * 2;
  25301. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25302. opacity = 255;
  25303. break;
  25304. }
  25305. }
  25306. alphaBuf[i] = opacity;
  25307. }
  25308. } else {
  25309. error('Unknown mask format.');
  25310. }
  25311. }
  25312. if (alphaBuf) {
  25313. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25314. rgbaBuf[j] = alphaBuf[i];
  25315. }
  25316. } else {
  25317. // No mask.
  25318. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25319. rgbaBuf[j] = 255;
  25320. }
  25321. }
  25322. },
  25323. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25324. var matte = this.smask && this.smask.matte;
  25325. if (!matte) {
  25326. return;
  25327. }
  25328. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25329. var matteR = matteRgb[0];
  25330. var matteG = matteRgb[1];
  25331. var matteB = matteRgb[2];
  25332. var length = width * height * 4;
  25333. var r, g, b;
  25334. for (var i = 0; i < length; i += 4) {
  25335. var alpha = buffer[i + 3];
  25336. if (alpha === 0) {
  25337. // according formula we have to get Infinity in all components
  25338. // making it white (typical paper color) should be okay
  25339. buffer[i] = 255;
  25340. buffer[i + 1] = 255;
  25341. buffer[i + 2] = 255;
  25342. continue;
  25343. }
  25344. var k = 255 / alpha;
  25345. r = (buffer[i] - matteR) * k + matteR;
  25346. g = (buffer[i + 1] - matteG) * k + matteG;
  25347. b = (buffer[i + 2] - matteB) * k + matteB;
  25348. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25349. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25350. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25351. }
  25352. },
  25353. createImageData: function PDFImage_createImageData(forceRGBA) {
  25354. var drawWidth = this.drawWidth;
  25355. var drawHeight = this.drawHeight;
  25356. var imgData = { // other fields are filled in below
  25357. width: drawWidth,
  25358. height: drawHeight
  25359. };
  25360. var numComps = this.numComps;
  25361. var originalWidth = this.width;
  25362. var originalHeight = this.height;
  25363. var bpc = this.bpc;
  25364. // Rows start at byte boundary.
  25365. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25366. var imgArray;
  25367. if (!forceRGBA) {
  25368. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25369. // without any complications, we pass a same-sized copy to the main
  25370. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25371. // of memory for many scanned documents. It's also much faster.
  25372. //
  25373. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25374. // complications, we avoid expanding by 1.333x to RGBA form.
  25375. var kind;
  25376. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25377. kind = ImageKind.GRAYSCALE_1BPP;
  25378. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25379. !this.needsDecode) {
  25380. kind = ImageKind.RGB_24BPP;
  25381. }
  25382. if (kind && !this.smask && !this.mask &&
  25383. drawWidth === originalWidth && drawHeight === originalHeight) {
  25384. imgData.kind = kind;
  25385. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25386. // If imgArray came from a DecodeStream, we're safe to transfer it
  25387. // (and thus neuter it) because it will constitute the entire
  25388. // DecodeStream's data. But if it came from a Stream, we need to
  25389. // copy it because it'll only be a portion of the Stream's data, and
  25390. // the rest will be read later on.
  25391. if (this.image instanceof DecodeStream) {
  25392. imgData.data = imgArray;
  25393. } else {
  25394. var newArray = new Uint8Array(imgArray.length);
  25395. newArray.set(imgArray);
  25396. imgData.data = newArray;
  25397. }
  25398. if (this.needsDecode) {
  25399. // Invert the buffer (which must be grayscale if we reached here).
  25400. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25401. var buffer = imgData.data;
  25402. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25403. buffer[i] ^= 0xff;
  25404. }
  25405. }
  25406. return imgData;
  25407. }
  25408. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25409. imgData.kind = ImageKind.RGB_24BPP;
  25410. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25411. drawWidth, drawHeight, true);
  25412. return imgData;
  25413. }
  25414. }
  25415. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25416. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25417. var actualHeight = 0 | (imgArray.length / rowBytes *
  25418. drawHeight / originalHeight);
  25419. var comps = this.getComponents(imgArray);
  25420. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25421. // more compact RGB_24BPP form if allowable.
  25422. var alpha01, maybeUndoPreblend;
  25423. if (!forceRGBA && !this.smask && !this.mask) {
  25424. imgData.kind = ImageKind.RGB_24BPP;
  25425. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25426. alpha01 = 0;
  25427. maybeUndoPreblend = false;
  25428. } else {
  25429. imgData.kind = ImageKind.RGBA_32BPP;
  25430. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25431. alpha01 = 1;
  25432. maybeUndoPreblend = true;
  25433. // Color key masking (opacity) must be performed before decoding.
  25434. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25435. comps);
  25436. }
  25437. if (this.needsDecode) {
  25438. this.decodeBuffer(comps);
  25439. }
  25440. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25441. drawWidth, drawHeight, actualHeight, bpc, comps,
  25442. alpha01);
  25443. if (maybeUndoPreblend) {
  25444. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25445. }
  25446. return imgData;
  25447. },
  25448. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25449. var numComps = this.numComps;
  25450. if (numComps !== 1) {
  25451. error('Reading gray scale from a color image: ' + numComps);
  25452. }
  25453. var width = this.width;
  25454. var height = this.height;
  25455. var bpc = this.bpc;
  25456. // rows start at byte boundary
  25457. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25458. var imgArray = this.getImageBytes(height * rowBytes);
  25459. var comps = this.getComponents(imgArray);
  25460. var i, length;
  25461. if (bpc === 1) {
  25462. // inline decoding (= inversion) for 1 bpc images
  25463. length = width * height;
  25464. if (this.needsDecode) {
  25465. // invert and scale to {0, 255}
  25466. for (i = 0; i < length; ++i) {
  25467. buffer[i] = (comps[i] - 1) & 255;
  25468. }
  25469. } else {
  25470. // scale to {0, 255}
  25471. for (i = 0; i < length; ++i) {
  25472. buffer[i] = (-comps[i]) & 255;
  25473. }
  25474. }
  25475. return;
  25476. }
  25477. if (this.needsDecode) {
  25478. this.decodeBuffer(comps);
  25479. }
  25480. length = width * height;
  25481. // we aren't using a colorspace so we need to scale the value
  25482. var scale = 255 / ((1 << bpc) - 1);
  25483. for (i = 0; i < length; ++i) {
  25484. buffer[i] = (scale * comps[i]) | 0;
  25485. }
  25486. },
  25487. getImageBytes: function PDFImage_getImageBytes(length,
  25488. drawWidth, drawHeight,
  25489. forceRGB) {
  25490. this.image.reset();
  25491. this.image.drawWidth = drawWidth || this.width;
  25492. this.image.drawHeight = drawHeight || this.height;
  25493. this.image.forceRGB = !!forceRGB;
  25494. return this.image.getBytes(length);
  25495. }
  25496. };
  25497. return PDFImage;
  25498. })();
  25499. // The Metrics object contains glyph widths (in glyph space units).
  25500. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25501. // space unit corresponds to 1/1000th of text space unit.
  25502. var Metrics = {
  25503. 'Courier': 600,
  25504. 'Courier-Bold': 600,
  25505. 'Courier-BoldOblique': 600,
  25506. 'Courier-Oblique': 600,
  25507. 'Helvetica' : {
  25508. 'space': 278,
  25509. 'exclam': 278,
  25510. 'quotedbl': 355,
  25511. 'numbersign': 556,
  25512. 'dollar': 556,
  25513. 'percent': 889,
  25514. 'ampersand': 667,
  25515. 'quoteright': 222,
  25516. 'parenleft': 333,
  25517. 'parenright': 333,
  25518. 'asterisk': 389,
  25519. 'plus': 584,
  25520. 'comma': 278,
  25521. 'hyphen': 333,
  25522. 'period': 278,
  25523. 'slash': 278,
  25524. 'zero': 556,
  25525. 'one': 556,
  25526. 'two': 556,
  25527. 'three': 556,
  25528. 'four': 556,
  25529. 'five': 556,
  25530. 'six': 556,
  25531. 'seven': 556,
  25532. 'eight': 556,
  25533. 'nine': 556,
  25534. 'colon': 278,
  25535. 'semicolon': 278,
  25536. 'less': 584,
  25537. 'equal': 584,
  25538. 'greater': 584,
  25539. 'question': 556,
  25540. 'at': 1015,
  25541. 'A': 667,
  25542. 'B': 667,
  25543. 'C': 722,
  25544. 'D': 722,
  25545. 'E': 667,
  25546. 'F': 611,
  25547. 'G': 778,
  25548. 'H': 722,
  25549. 'I': 278,
  25550. 'J': 500,
  25551. 'K': 667,
  25552. 'L': 556,
  25553. 'M': 833,
  25554. 'N': 722,
  25555. 'O': 778,
  25556. 'P': 667,
  25557. 'Q': 778,
  25558. 'R': 722,
  25559. 'S': 667,
  25560. 'T': 611,
  25561. 'U': 722,
  25562. 'V': 667,
  25563. 'W': 944,
  25564. 'X': 667,
  25565. 'Y': 667,
  25566. 'Z': 611,
  25567. 'bracketleft': 278,
  25568. 'backslash': 278,
  25569. 'bracketright': 278,
  25570. 'asciicircum': 469,
  25571. 'underscore': 556,
  25572. 'quoteleft': 222,
  25573. 'a': 556,
  25574. 'b': 556,
  25575. 'c': 500,
  25576. 'd': 556,
  25577. 'e': 556,
  25578. 'f': 278,
  25579. 'g': 556,
  25580. 'h': 556,
  25581. 'i': 222,
  25582. 'j': 222,
  25583. 'k': 500,
  25584. 'l': 222,
  25585. 'm': 833,
  25586. 'n': 556,
  25587. 'o': 556,
  25588. 'p': 556,
  25589. 'q': 556,
  25590. 'r': 333,
  25591. 's': 500,
  25592. 't': 278,
  25593. 'u': 556,
  25594. 'v': 500,
  25595. 'w': 722,
  25596. 'x': 500,
  25597. 'y': 500,
  25598. 'z': 500,
  25599. 'braceleft': 334,
  25600. 'bar': 260,
  25601. 'braceright': 334,
  25602. 'asciitilde': 584,
  25603. 'exclamdown': 333,
  25604. 'cent': 556,
  25605. 'sterling': 556,
  25606. 'fraction': 167,
  25607. 'yen': 556,
  25608. 'florin': 556,
  25609. 'section': 556,
  25610. 'currency': 556,
  25611. 'quotesingle': 191,
  25612. 'quotedblleft': 333,
  25613. 'guillemotleft': 556,
  25614. 'guilsinglleft': 333,
  25615. 'guilsinglright': 333,
  25616. 'fi': 500,
  25617. 'fl': 500,
  25618. 'endash': 556,
  25619. 'dagger': 556,
  25620. 'daggerdbl': 556,
  25621. 'periodcentered': 278,
  25622. 'paragraph': 537,
  25623. 'bullet': 350,
  25624. 'quotesinglbase': 222,
  25625. 'quotedblbase': 333,
  25626. 'quotedblright': 333,
  25627. 'guillemotright': 556,
  25628. 'ellipsis': 1000,
  25629. 'perthousand': 1000,
  25630. 'questiondown': 611,
  25631. 'grave': 333,
  25632. 'acute': 333,
  25633. 'circumflex': 333,
  25634. 'tilde': 333,
  25635. 'macron': 333,
  25636. 'breve': 333,
  25637. 'dotaccent': 333,
  25638. 'dieresis': 333,
  25639. 'ring': 333,
  25640. 'cedilla': 333,
  25641. 'hungarumlaut': 333,
  25642. 'ogonek': 333,
  25643. 'caron': 333,
  25644. 'emdash': 1000,
  25645. 'AE': 1000,
  25646. 'ordfeminine': 370,
  25647. 'Lslash': 556,
  25648. 'Oslash': 778,
  25649. 'OE': 1000,
  25650. 'ordmasculine': 365,
  25651. 'ae': 889,
  25652. 'dotlessi': 278,
  25653. 'lslash': 222,
  25654. 'oslash': 611,
  25655. 'oe': 944,
  25656. 'germandbls': 611,
  25657. 'Idieresis': 278,
  25658. 'eacute': 556,
  25659. 'abreve': 556,
  25660. 'uhungarumlaut': 556,
  25661. 'ecaron': 556,
  25662. 'Ydieresis': 667,
  25663. 'divide': 584,
  25664. 'Yacute': 667,
  25665. 'Acircumflex': 667,
  25666. 'aacute': 556,
  25667. 'Ucircumflex': 722,
  25668. 'yacute': 500,
  25669. 'scommaaccent': 500,
  25670. 'ecircumflex': 556,
  25671. 'Uring': 722,
  25672. 'Udieresis': 722,
  25673. 'aogonek': 556,
  25674. 'Uacute': 722,
  25675. 'uogonek': 556,
  25676. 'Edieresis': 667,
  25677. 'Dcroat': 722,
  25678. 'commaaccent': 250,
  25679. 'copyright': 737,
  25680. 'Emacron': 667,
  25681. 'ccaron': 500,
  25682. 'aring': 556,
  25683. 'Ncommaaccent': 722,
  25684. 'lacute': 222,
  25685. 'agrave': 556,
  25686. 'Tcommaaccent': 611,
  25687. 'Cacute': 722,
  25688. 'atilde': 556,
  25689. 'Edotaccent': 667,
  25690. 'scaron': 500,
  25691. 'scedilla': 500,
  25692. 'iacute': 278,
  25693. 'lozenge': 471,
  25694. 'Rcaron': 722,
  25695. 'Gcommaaccent': 778,
  25696. 'ucircumflex': 556,
  25697. 'acircumflex': 556,
  25698. 'Amacron': 667,
  25699. 'rcaron': 333,
  25700. 'ccedilla': 500,
  25701. 'Zdotaccent': 611,
  25702. 'Thorn': 667,
  25703. 'Omacron': 778,
  25704. 'Racute': 722,
  25705. 'Sacute': 667,
  25706. 'dcaron': 643,
  25707. 'Umacron': 722,
  25708. 'uring': 556,
  25709. 'threesuperior': 333,
  25710. 'Ograve': 778,
  25711. 'Agrave': 667,
  25712. 'Abreve': 667,
  25713. 'multiply': 584,
  25714. 'uacute': 556,
  25715. 'Tcaron': 611,
  25716. 'partialdiff': 476,
  25717. 'ydieresis': 500,
  25718. 'Nacute': 722,
  25719. 'icircumflex': 278,
  25720. 'Ecircumflex': 667,
  25721. 'adieresis': 556,
  25722. 'edieresis': 556,
  25723. 'cacute': 500,
  25724. 'nacute': 556,
  25725. 'umacron': 556,
  25726. 'Ncaron': 722,
  25727. 'Iacute': 278,
  25728. 'plusminus': 584,
  25729. 'brokenbar': 260,
  25730. 'registered': 737,
  25731. 'Gbreve': 778,
  25732. 'Idotaccent': 278,
  25733. 'summation': 600,
  25734. 'Egrave': 667,
  25735. 'racute': 333,
  25736. 'omacron': 556,
  25737. 'Zacute': 611,
  25738. 'Zcaron': 611,
  25739. 'greaterequal': 549,
  25740. 'Eth': 722,
  25741. 'Ccedilla': 722,
  25742. 'lcommaaccent': 222,
  25743. 'tcaron': 317,
  25744. 'eogonek': 556,
  25745. 'Uogonek': 722,
  25746. 'Aacute': 667,
  25747. 'Adieresis': 667,
  25748. 'egrave': 556,
  25749. 'zacute': 500,
  25750. 'iogonek': 222,
  25751. 'Oacute': 778,
  25752. 'oacute': 556,
  25753. 'amacron': 556,
  25754. 'sacute': 500,
  25755. 'idieresis': 278,
  25756. 'Ocircumflex': 778,
  25757. 'Ugrave': 722,
  25758. 'Delta': 612,
  25759. 'thorn': 556,
  25760. 'twosuperior': 333,
  25761. 'Odieresis': 778,
  25762. 'mu': 556,
  25763. 'igrave': 278,
  25764. 'ohungarumlaut': 556,
  25765. 'Eogonek': 667,
  25766. 'dcroat': 556,
  25767. 'threequarters': 834,
  25768. 'Scedilla': 667,
  25769. 'lcaron': 299,
  25770. 'Kcommaaccent': 667,
  25771. 'Lacute': 556,
  25772. 'trademark': 1000,
  25773. 'edotaccent': 556,
  25774. 'Igrave': 278,
  25775. 'Imacron': 278,
  25776. 'Lcaron': 556,
  25777. 'onehalf': 834,
  25778. 'lessequal': 549,
  25779. 'ocircumflex': 556,
  25780. 'ntilde': 556,
  25781. 'Uhungarumlaut': 722,
  25782. 'Eacute': 667,
  25783. 'emacron': 556,
  25784. 'gbreve': 556,
  25785. 'onequarter': 834,
  25786. 'Scaron': 667,
  25787. 'Scommaaccent': 667,
  25788. 'Ohungarumlaut': 778,
  25789. 'degree': 400,
  25790. 'ograve': 556,
  25791. 'Ccaron': 722,
  25792. 'ugrave': 556,
  25793. 'radical': 453,
  25794. 'Dcaron': 722,
  25795. 'rcommaaccent': 333,
  25796. 'Ntilde': 722,
  25797. 'otilde': 556,
  25798. 'Rcommaaccent': 722,
  25799. 'Lcommaaccent': 556,
  25800. 'Atilde': 667,
  25801. 'Aogonek': 667,
  25802. 'Aring': 667,
  25803. 'Otilde': 778,
  25804. 'zdotaccent': 500,
  25805. 'Ecaron': 667,
  25806. 'Iogonek': 278,
  25807. 'kcommaaccent': 500,
  25808. 'minus': 584,
  25809. 'Icircumflex': 278,
  25810. 'ncaron': 556,
  25811. 'tcommaaccent': 278,
  25812. 'logicalnot': 584,
  25813. 'odieresis': 556,
  25814. 'udieresis': 556,
  25815. 'notequal': 549,
  25816. 'gcommaaccent': 556,
  25817. 'eth': 556,
  25818. 'zcaron': 500,
  25819. 'ncommaaccent': 556,
  25820. 'onesuperior': 333,
  25821. 'imacron': 278,
  25822. 'Euro': 556
  25823. },
  25824. 'Helvetica-Bold': {
  25825. 'space': 278,
  25826. 'exclam': 333,
  25827. 'quotedbl': 474,
  25828. 'numbersign': 556,
  25829. 'dollar': 556,
  25830. 'percent': 889,
  25831. 'ampersand': 722,
  25832. 'quoteright': 278,
  25833. 'parenleft': 333,
  25834. 'parenright': 333,
  25835. 'asterisk': 389,
  25836. 'plus': 584,
  25837. 'comma': 278,
  25838. 'hyphen': 333,
  25839. 'period': 278,
  25840. 'slash': 278,
  25841. 'zero': 556,
  25842. 'one': 556,
  25843. 'two': 556,
  25844. 'three': 556,
  25845. 'four': 556,
  25846. 'five': 556,
  25847. 'six': 556,
  25848. 'seven': 556,
  25849. 'eight': 556,
  25850. 'nine': 556,
  25851. 'colon': 333,
  25852. 'semicolon': 333,
  25853. 'less': 584,
  25854. 'equal': 584,
  25855. 'greater': 584,
  25856. 'question': 611,
  25857. 'at': 975,
  25858. 'A': 722,
  25859. 'B': 722,
  25860. 'C': 722,
  25861. 'D': 722,
  25862. 'E': 667,
  25863. 'F': 611,
  25864. 'G': 778,
  25865. 'H': 722,
  25866. 'I': 278,
  25867. 'J': 556,
  25868. 'K': 722,
  25869. 'L': 611,
  25870. 'M': 833,
  25871. 'N': 722,
  25872. 'O': 778,
  25873. 'P': 667,
  25874. 'Q': 778,
  25875. 'R': 722,
  25876. 'S': 667,
  25877. 'T': 611,
  25878. 'U': 722,
  25879. 'V': 667,
  25880. 'W': 944,
  25881. 'X': 667,
  25882. 'Y': 667,
  25883. 'Z': 611,
  25884. 'bracketleft': 333,
  25885. 'backslash': 278,
  25886. 'bracketright': 333,
  25887. 'asciicircum': 584,
  25888. 'underscore': 556,
  25889. 'quoteleft': 278,
  25890. 'a': 556,
  25891. 'b': 611,
  25892. 'c': 556,
  25893. 'd': 611,
  25894. 'e': 556,
  25895. 'f': 333,
  25896. 'g': 611,
  25897. 'h': 611,
  25898. 'i': 278,
  25899. 'j': 278,
  25900. 'k': 556,
  25901. 'l': 278,
  25902. 'm': 889,
  25903. 'n': 611,
  25904. 'o': 611,
  25905. 'p': 611,
  25906. 'q': 611,
  25907. 'r': 389,
  25908. 's': 556,
  25909. 't': 333,
  25910. 'u': 611,
  25911. 'v': 556,
  25912. 'w': 778,
  25913. 'x': 556,
  25914. 'y': 556,
  25915. 'z': 500,
  25916. 'braceleft': 389,
  25917. 'bar': 280,
  25918. 'braceright': 389,
  25919. 'asciitilde': 584,
  25920. 'exclamdown': 333,
  25921. 'cent': 556,
  25922. 'sterling': 556,
  25923. 'fraction': 167,
  25924. 'yen': 556,
  25925. 'florin': 556,
  25926. 'section': 556,
  25927. 'currency': 556,
  25928. 'quotesingle': 238,
  25929. 'quotedblleft': 500,
  25930. 'guillemotleft': 556,
  25931. 'guilsinglleft': 333,
  25932. 'guilsinglright': 333,
  25933. 'fi': 611,
  25934. 'fl': 611,
  25935. 'endash': 556,
  25936. 'dagger': 556,
  25937. 'daggerdbl': 556,
  25938. 'periodcentered': 278,
  25939. 'paragraph': 556,
  25940. 'bullet': 350,
  25941. 'quotesinglbase': 278,
  25942. 'quotedblbase': 500,
  25943. 'quotedblright': 500,
  25944. 'guillemotright': 556,
  25945. 'ellipsis': 1000,
  25946. 'perthousand': 1000,
  25947. 'questiondown': 611,
  25948. 'grave': 333,
  25949. 'acute': 333,
  25950. 'circumflex': 333,
  25951. 'tilde': 333,
  25952. 'macron': 333,
  25953. 'breve': 333,
  25954. 'dotaccent': 333,
  25955. 'dieresis': 333,
  25956. 'ring': 333,
  25957. 'cedilla': 333,
  25958. 'hungarumlaut': 333,
  25959. 'ogonek': 333,
  25960. 'caron': 333,
  25961. 'emdash': 1000,
  25962. 'AE': 1000,
  25963. 'ordfeminine': 370,
  25964. 'Lslash': 611,
  25965. 'Oslash': 778,
  25966. 'OE': 1000,
  25967. 'ordmasculine': 365,
  25968. 'ae': 889,
  25969. 'dotlessi': 278,
  25970. 'lslash': 278,
  25971. 'oslash': 611,
  25972. 'oe': 944,
  25973. 'germandbls': 611,
  25974. 'Idieresis': 278,
  25975. 'eacute': 556,
  25976. 'abreve': 556,
  25977. 'uhungarumlaut': 611,
  25978. 'ecaron': 556,
  25979. 'Ydieresis': 667,
  25980. 'divide': 584,
  25981. 'Yacute': 667,
  25982. 'Acircumflex': 722,
  25983. 'aacute': 556,
  25984. 'Ucircumflex': 722,
  25985. 'yacute': 556,
  25986. 'scommaaccent': 556,
  25987. 'ecircumflex': 556,
  25988. 'Uring': 722,
  25989. 'Udieresis': 722,
  25990. 'aogonek': 556,
  25991. 'Uacute': 722,
  25992. 'uogonek': 611,
  25993. 'Edieresis': 667,
  25994. 'Dcroat': 722,
  25995. 'commaaccent': 250,
  25996. 'copyright': 737,
  25997. 'Emacron': 667,
  25998. 'ccaron': 556,
  25999. 'aring': 556,
  26000. 'Ncommaaccent': 722,
  26001. 'lacute': 278,
  26002. 'agrave': 556,
  26003. 'Tcommaaccent': 611,
  26004. 'Cacute': 722,
  26005. 'atilde': 556,
  26006. 'Edotaccent': 667,
  26007. 'scaron': 556,
  26008. 'scedilla': 556,
  26009. 'iacute': 278,
  26010. 'lozenge': 494,
  26011. 'Rcaron': 722,
  26012. 'Gcommaaccent': 778,
  26013. 'ucircumflex': 611,
  26014. 'acircumflex': 556,
  26015. 'Amacron': 722,
  26016. 'rcaron': 389,
  26017. 'ccedilla': 556,
  26018. 'Zdotaccent': 611,
  26019. 'Thorn': 667,
  26020. 'Omacron': 778,
  26021. 'Racute': 722,
  26022. 'Sacute': 667,
  26023. 'dcaron': 743,
  26024. 'Umacron': 722,
  26025. 'uring': 611,
  26026. 'threesuperior': 333,
  26027. 'Ograve': 778,
  26028. 'Agrave': 722,
  26029. 'Abreve': 722,
  26030. 'multiply': 584,
  26031. 'uacute': 611,
  26032. 'Tcaron': 611,
  26033. 'partialdiff': 494,
  26034. 'ydieresis': 556,
  26035. 'Nacute': 722,
  26036. 'icircumflex': 278,
  26037. 'Ecircumflex': 667,
  26038. 'adieresis': 556,
  26039. 'edieresis': 556,
  26040. 'cacute': 556,
  26041. 'nacute': 611,
  26042. 'umacron': 611,
  26043. 'Ncaron': 722,
  26044. 'Iacute': 278,
  26045. 'plusminus': 584,
  26046. 'brokenbar': 280,
  26047. 'registered': 737,
  26048. 'Gbreve': 778,
  26049. 'Idotaccent': 278,
  26050. 'summation': 600,
  26051. 'Egrave': 667,
  26052. 'racute': 389,
  26053. 'omacron': 611,
  26054. 'Zacute': 611,
  26055. 'Zcaron': 611,
  26056. 'greaterequal': 549,
  26057. 'Eth': 722,
  26058. 'Ccedilla': 722,
  26059. 'lcommaaccent': 278,
  26060. 'tcaron': 389,
  26061. 'eogonek': 556,
  26062. 'Uogonek': 722,
  26063. 'Aacute': 722,
  26064. 'Adieresis': 722,
  26065. 'egrave': 556,
  26066. 'zacute': 500,
  26067. 'iogonek': 278,
  26068. 'Oacute': 778,
  26069. 'oacute': 611,
  26070. 'amacron': 556,
  26071. 'sacute': 556,
  26072. 'idieresis': 278,
  26073. 'Ocircumflex': 778,
  26074. 'Ugrave': 722,
  26075. 'Delta': 612,
  26076. 'thorn': 611,
  26077. 'twosuperior': 333,
  26078. 'Odieresis': 778,
  26079. 'mu': 611,
  26080. 'igrave': 278,
  26081. 'ohungarumlaut': 611,
  26082. 'Eogonek': 667,
  26083. 'dcroat': 611,
  26084. 'threequarters': 834,
  26085. 'Scedilla': 667,
  26086. 'lcaron': 400,
  26087. 'Kcommaaccent': 722,
  26088. 'Lacute': 611,
  26089. 'trademark': 1000,
  26090. 'edotaccent': 556,
  26091. 'Igrave': 278,
  26092. 'Imacron': 278,
  26093. 'Lcaron': 611,
  26094. 'onehalf': 834,
  26095. 'lessequal': 549,
  26096. 'ocircumflex': 611,
  26097. 'ntilde': 611,
  26098. 'Uhungarumlaut': 722,
  26099. 'Eacute': 667,
  26100. 'emacron': 556,
  26101. 'gbreve': 611,
  26102. 'onequarter': 834,
  26103. 'Scaron': 667,
  26104. 'Scommaaccent': 667,
  26105. 'Ohungarumlaut': 778,
  26106. 'degree': 400,
  26107. 'ograve': 611,
  26108. 'Ccaron': 722,
  26109. 'ugrave': 611,
  26110. 'radical': 549,
  26111. 'Dcaron': 722,
  26112. 'rcommaaccent': 389,
  26113. 'Ntilde': 722,
  26114. 'otilde': 611,
  26115. 'Rcommaaccent': 722,
  26116. 'Lcommaaccent': 611,
  26117. 'Atilde': 722,
  26118. 'Aogonek': 722,
  26119. 'Aring': 722,
  26120. 'Otilde': 778,
  26121. 'zdotaccent': 500,
  26122. 'Ecaron': 667,
  26123. 'Iogonek': 278,
  26124. 'kcommaaccent': 556,
  26125. 'minus': 584,
  26126. 'Icircumflex': 278,
  26127. 'ncaron': 611,
  26128. 'tcommaaccent': 333,
  26129. 'logicalnot': 584,
  26130. 'odieresis': 611,
  26131. 'udieresis': 611,
  26132. 'notequal': 549,
  26133. 'gcommaaccent': 611,
  26134. 'eth': 611,
  26135. 'zcaron': 500,
  26136. 'ncommaaccent': 611,
  26137. 'onesuperior': 333,
  26138. 'imacron': 278,
  26139. 'Euro': 556
  26140. },
  26141. 'Helvetica-BoldOblique': {
  26142. 'space': 278,
  26143. 'exclam': 333,
  26144. 'quotedbl': 474,
  26145. 'numbersign': 556,
  26146. 'dollar': 556,
  26147. 'percent': 889,
  26148. 'ampersand': 722,
  26149. 'quoteright': 278,
  26150. 'parenleft': 333,
  26151. 'parenright': 333,
  26152. 'asterisk': 389,
  26153. 'plus': 584,
  26154. 'comma': 278,
  26155. 'hyphen': 333,
  26156. 'period': 278,
  26157. 'slash': 278,
  26158. 'zero': 556,
  26159. 'one': 556,
  26160. 'two': 556,
  26161. 'three': 556,
  26162. 'four': 556,
  26163. 'five': 556,
  26164. 'six': 556,
  26165. 'seven': 556,
  26166. 'eight': 556,
  26167. 'nine': 556,
  26168. 'colon': 333,
  26169. 'semicolon': 333,
  26170. 'less': 584,
  26171. 'equal': 584,
  26172. 'greater': 584,
  26173. 'question': 611,
  26174. 'at': 975,
  26175. 'A': 722,
  26176. 'B': 722,
  26177. 'C': 722,
  26178. 'D': 722,
  26179. 'E': 667,
  26180. 'F': 611,
  26181. 'G': 778,
  26182. 'H': 722,
  26183. 'I': 278,
  26184. 'J': 556,
  26185. 'K': 722,
  26186. 'L': 611,
  26187. 'M': 833,
  26188. 'N': 722,
  26189. 'O': 778,
  26190. 'P': 667,
  26191. 'Q': 778,
  26192. 'R': 722,
  26193. 'S': 667,
  26194. 'T': 611,
  26195. 'U': 722,
  26196. 'V': 667,
  26197. 'W': 944,
  26198. 'X': 667,
  26199. 'Y': 667,
  26200. 'Z': 611,
  26201. 'bracketleft': 333,
  26202. 'backslash': 278,
  26203. 'bracketright': 333,
  26204. 'asciicircum': 584,
  26205. 'underscore': 556,
  26206. 'quoteleft': 278,
  26207. 'a': 556,
  26208. 'b': 611,
  26209. 'c': 556,
  26210. 'd': 611,
  26211. 'e': 556,
  26212. 'f': 333,
  26213. 'g': 611,
  26214. 'h': 611,
  26215. 'i': 278,
  26216. 'j': 278,
  26217. 'k': 556,
  26218. 'l': 278,
  26219. 'm': 889,
  26220. 'n': 611,
  26221. 'o': 611,
  26222. 'p': 611,
  26223. 'q': 611,
  26224. 'r': 389,
  26225. 's': 556,
  26226. 't': 333,
  26227. 'u': 611,
  26228. 'v': 556,
  26229. 'w': 778,
  26230. 'x': 556,
  26231. 'y': 556,
  26232. 'z': 500,
  26233. 'braceleft': 389,
  26234. 'bar': 280,
  26235. 'braceright': 389,
  26236. 'asciitilde': 584,
  26237. 'exclamdown': 333,
  26238. 'cent': 556,
  26239. 'sterling': 556,
  26240. 'fraction': 167,
  26241. 'yen': 556,
  26242. 'florin': 556,
  26243. 'section': 556,
  26244. 'currency': 556,
  26245. 'quotesingle': 238,
  26246. 'quotedblleft': 500,
  26247. 'guillemotleft': 556,
  26248. 'guilsinglleft': 333,
  26249. 'guilsinglright': 333,
  26250. 'fi': 611,
  26251. 'fl': 611,
  26252. 'endash': 556,
  26253. 'dagger': 556,
  26254. 'daggerdbl': 556,
  26255. 'periodcentered': 278,
  26256. 'paragraph': 556,
  26257. 'bullet': 350,
  26258. 'quotesinglbase': 278,
  26259. 'quotedblbase': 500,
  26260. 'quotedblright': 500,
  26261. 'guillemotright': 556,
  26262. 'ellipsis': 1000,
  26263. 'perthousand': 1000,
  26264. 'questiondown': 611,
  26265. 'grave': 333,
  26266. 'acute': 333,
  26267. 'circumflex': 333,
  26268. 'tilde': 333,
  26269. 'macron': 333,
  26270. 'breve': 333,
  26271. 'dotaccent': 333,
  26272. 'dieresis': 333,
  26273. 'ring': 333,
  26274. 'cedilla': 333,
  26275. 'hungarumlaut': 333,
  26276. 'ogonek': 333,
  26277. 'caron': 333,
  26278. 'emdash': 1000,
  26279. 'AE': 1000,
  26280. 'ordfeminine': 370,
  26281. 'Lslash': 611,
  26282. 'Oslash': 778,
  26283. 'OE': 1000,
  26284. 'ordmasculine': 365,
  26285. 'ae': 889,
  26286. 'dotlessi': 278,
  26287. 'lslash': 278,
  26288. 'oslash': 611,
  26289. 'oe': 944,
  26290. 'germandbls': 611,
  26291. 'Idieresis': 278,
  26292. 'eacute': 556,
  26293. 'abreve': 556,
  26294. 'uhungarumlaut': 611,
  26295. 'ecaron': 556,
  26296. 'Ydieresis': 667,
  26297. 'divide': 584,
  26298. 'Yacute': 667,
  26299. 'Acircumflex': 722,
  26300. 'aacute': 556,
  26301. 'Ucircumflex': 722,
  26302. 'yacute': 556,
  26303. 'scommaaccent': 556,
  26304. 'ecircumflex': 556,
  26305. 'Uring': 722,
  26306. 'Udieresis': 722,
  26307. 'aogonek': 556,
  26308. 'Uacute': 722,
  26309. 'uogonek': 611,
  26310. 'Edieresis': 667,
  26311. 'Dcroat': 722,
  26312. 'commaaccent': 250,
  26313. 'copyright': 737,
  26314. 'Emacron': 667,
  26315. 'ccaron': 556,
  26316. 'aring': 556,
  26317. 'Ncommaaccent': 722,
  26318. 'lacute': 278,
  26319. 'agrave': 556,
  26320. 'Tcommaaccent': 611,
  26321. 'Cacute': 722,
  26322. 'atilde': 556,
  26323. 'Edotaccent': 667,
  26324. 'scaron': 556,
  26325. 'scedilla': 556,
  26326. 'iacute': 278,
  26327. 'lozenge': 494,
  26328. 'Rcaron': 722,
  26329. 'Gcommaaccent': 778,
  26330. 'ucircumflex': 611,
  26331. 'acircumflex': 556,
  26332. 'Amacron': 722,
  26333. 'rcaron': 389,
  26334. 'ccedilla': 556,
  26335. 'Zdotaccent': 611,
  26336. 'Thorn': 667,
  26337. 'Omacron': 778,
  26338. 'Racute': 722,
  26339. 'Sacute': 667,
  26340. 'dcaron': 743,
  26341. 'Umacron': 722,
  26342. 'uring': 611,
  26343. 'threesuperior': 333,
  26344. 'Ograve': 778,
  26345. 'Agrave': 722,
  26346. 'Abreve': 722,
  26347. 'multiply': 584,
  26348. 'uacute': 611,
  26349. 'Tcaron': 611,
  26350. 'partialdiff': 494,
  26351. 'ydieresis': 556,
  26352. 'Nacute': 722,
  26353. 'icircumflex': 278,
  26354. 'Ecircumflex': 667,
  26355. 'adieresis': 556,
  26356. 'edieresis': 556,
  26357. 'cacute': 556,
  26358. 'nacute': 611,
  26359. 'umacron': 611,
  26360. 'Ncaron': 722,
  26361. 'Iacute': 278,
  26362. 'plusminus': 584,
  26363. 'brokenbar': 280,
  26364. 'registered': 737,
  26365. 'Gbreve': 778,
  26366. 'Idotaccent': 278,
  26367. 'summation': 600,
  26368. 'Egrave': 667,
  26369. 'racute': 389,
  26370. 'omacron': 611,
  26371. 'Zacute': 611,
  26372. 'Zcaron': 611,
  26373. 'greaterequal': 549,
  26374. 'Eth': 722,
  26375. 'Ccedilla': 722,
  26376. 'lcommaaccent': 278,
  26377. 'tcaron': 389,
  26378. 'eogonek': 556,
  26379. 'Uogonek': 722,
  26380. 'Aacute': 722,
  26381. 'Adieresis': 722,
  26382. 'egrave': 556,
  26383. 'zacute': 500,
  26384. 'iogonek': 278,
  26385. 'Oacute': 778,
  26386. 'oacute': 611,
  26387. 'amacron': 556,
  26388. 'sacute': 556,
  26389. 'idieresis': 278,
  26390. 'Ocircumflex': 778,
  26391. 'Ugrave': 722,
  26392. 'Delta': 612,
  26393. 'thorn': 611,
  26394. 'twosuperior': 333,
  26395. 'Odieresis': 778,
  26396. 'mu': 611,
  26397. 'igrave': 278,
  26398. 'ohungarumlaut': 611,
  26399. 'Eogonek': 667,
  26400. 'dcroat': 611,
  26401. 'threequarters': 834,
  26402. 'Scedilla': 667,
  26403. 'lcaron': 400,
  26404. 'Kcommaaccent': 722,
  26405. 'Lacute': 611,
  26406. 'trademark': 1000,
  26407. 'edotaccent': 556,
  26408. 'Igrave': 278,
  26409. 'Imacron': 278,
  26410. 'Lcaron': 611,
  26411. 'onehalf': 834,
  26412. 'lessequal': 549,
  26413. 'ocircumflex': 611,
  26414. 'ntilde': 611,
  26415. 'Uhungarumlaut': 722,
  26416. 'Eacute': 667,
  26417. 'emacron': 556,
  26418. 'gbreve': 611,
  26419. 'onequarter': 834,
  26420. 'Scaron': 667,
  26421. 'Scommaaccent': 667,
  26422. 'Ohungarumlaut': 778,
  26423. 'degree': 400,
  26424. 'ograve': 611,
  26425. 'Ccaron': 722,
  26426. 'ugrave': 611,
  26427. 'radical': 549,
  26428. 'Dcaron': 722,
  26429. 'rcommaaccent': 389,
  26430. 'Ntilde': 722,
  26431. 'otilde': 611,
  26432. 'Rcommaaccent': 722,
  26433. 'Lcommaaccent': 611,
  26434. 'Atilde': 722,
  26435. 'Aogonek': 722,
  26436. 'Aring': 722,
  26437. 'Otilde': 778,
  26438. 'zdotaccent': 500,
  26439. 'Ecaron': 667,
  26440. 'Iogonek': 278,
  26441. 'kcommaaccent': 556,
  26442. 'minus': 584,
  26443. 'Icircumflex': 278,
  26444. 'ncaron': 611,
  26445. 'tcommaaccent': 333,
  26446. 'logicalnot': 584,
  26447. 'odieresis': 611,
  26448. 'udieresis': 611,
  26449. 'notequal': 549,
  26450. 'gcommaaccent': 611,
  26451. 'eth': 611,
  26452. 'zcaron': 500,
  26453. 'ncommaaccent': 611,
  26454. 'onesuperior': 333,
  26455. 'imacron': 278,
  26456. 'Euro': 556
  26457. },
  26458. 'Helvetica-Oblique' : {
  26459. 'space': 278,
  26460. 'exclam': 278,
  26461. 'quotedbl': 355,
  26462. 'numbersign': 556,
  26463. 'dollar': 556,
  26464. 'percent': 889,
  26465. 'ampersand': 667,
  26466. 'quoteright': 222,
  26467. 'parenleft': 333,
  26468. 'parenright': 333,
  26469. 'asterisk': 389,
  26470. 'plus': 584,
  26471. 'comma': 278,
  26472. 'hyphen': 333,
  26473. 'period': 278,
  26474. 'slash': 278,
  26475. 'zero': 556,
  26476. 'one': 556,
  26477. 'two': 556,
  26478. 'three': 556,
  26479. 'four': 556,
  26480. 'five': 556,
  26481. 'six': 556,
  26482. 'seven': 556,
  26483. 'eight': 556,
  26484. 'nine': 556,
  26485. 'colon': 278,
  26486. 'semicolon': 278,
  26487. 'less': 584,
  26488. 'equal': 584,
  26489. 'greater': 584,
  26490. 'question': 556,
  26491. 'at': 1015,
  26492. 'A': 667,
  26493. 'B': 667,
  26494. 'C': 722,
  26495. 'D': 722,
  26496. 'E': 667,
  26497. 'F': 611,
  26498. 'G': 778,
  26499. 'H': 722,
  26500. 'I': 278,
  26501. 'J': 500,
  26502. 'K': 667,
  26503. 'L': 556,
  26504. 'M': 833,
  26505. 'N': 722,
  26506. 'O': 778,
  26507. 'P': 667,
  26508. 'Q': 778,
  26509. 'R': 722,
  26510. 'S': 667,
  26511. 'T': 611,
  26512. 'U': 722,
  26513. 'V': 667,
  26514. 'W': 944,
  26515. 'X': 667,
  26516. 'Y': 667,
  26517. 'Z': 611,
  26518. 'bracketleft': 278,
  26519. 'backslash': 278,
  26520. 'bracketright': 278,
  26521. 'asciicircum': 469,
  26522. 'underscore': 556,
  26523. 'quoteleft': 222,
  26524. 'a': 556,
  26525. 'b': 556,
  26526. 'c': 500,
  26527. 'd': 556,
  26528. 'e': 556,
  26529. 'f': 278,
  26530. 'g': 556,
  26531. 'h': 556,
  26532. 'i': 222,
  26533. 'j': 222,
  26534. 'k': 500,
  26535. 'l': 222,
  26536. 'm': 833,
  26537. 'n': 556,
  26538. 'o': 556,
  26539. 'p': 556,
  26540. 'q': 556,
  26541. 'r': 333,
  26542. 's': 500,
  26543. 't': 278,
  26544. 'u': 556,
  26545. 'v': 500,
  26546. 'w': 722,
  26547. 'x': 500,
  26548. 'y': 500,
  26549. 'z': 500,
  26550. 'braceleft': 334,
  26551. 'bar': 260,
  26552. 'braceright': 334,
  26553. 'asciitilde': 584,
  26554. 'exclamdown': 333,
  26555. 'cent': 556,
  26556. 'sterling': 556,
  26557. 'fraction': 167,
  26558. 'yen': 556,
  26559. 'florin': 556,
  26560. 'section': 556,
  26561. 'currency': 556,
  26562. 'quotesingle': 191,
  26563. 'quotedblleft': 333,
  26564. 'guillemotleft': 556,
  26565. 'guilsinglleft': 333,
  26566. 'guilsinglright': 333,
  26567. 'fi': 500,
  26568. 'fl': 500,
  26569. 'endash': 556,
  26570. 'dagger': 556,
  26571. 'daggerdbl': 556,
  26572. 'periodcentered': 278,
  26573. 'paragraph': 537,
  26574. 'bullet': 350,
  26575. 'quotesinglbase': 222,
  26576. 'quotedblbase': 333,
  26577. 'quotedblright': 333,
  26578. 'guillemotright': 556,
  26579. 'ellipsis': 1000,
  26580. 'perthousand': 1000,
  26581. 'questiondown': 611,
  26582. 'grave': 333,
  26583. 'acute': 333,
  26584. 'circumflex': 333,
  26585. 'tilde': 333,
  26586. 'macron': 333,
  26587. 'breve': 333,
  26588. 'dotaccent': 333,
  26589. 'dieresis': 333,
  26590. 'ring': 333,
  26591. 'cedilla': 333,
  26592. 'hungarumlaut': 333,
  26593. 'ogonek': 333,
  26594. 'caron': 333,
  26595. 'emdash': 1000,
  26596. 'AE': 1000,
  26597. 'ordfeminine': 370,
  26598. 'Lslash': 556,
  26599. 'Oslash': 778,
  26600. 'OE': 1000,
  26601. 'ordmasculine': 365,
  26602. 'ae': 889,
  26603. 'dotlessi': 278,
  26604. 'lslash': 222,
  26605. 'oslash': 611,
  26606. 'oe': 944,
  26607. 'germandbls': 611,
  26608. 'Idieresis': 278,
  26609. 'eacute': 556,
  26610. 'abreve': 556,
  26611. 'uhungarumlaut': 556,
  26612. 'ecaron': 556,
  26613. 'Ydieresis': 667,
  26614. 'divide': 584,
  26615. 'Yacute': 667,
  26616. 'Acircumflex': 667,
  26617. 'aacute': 556,
  26618. 'Ucircumflex': 722,
  26619. 'yacute': 500,
  26620. 'scommaaccent': 500,
  26621. 'ecircumflex': 556,
  26622. 'Uring': 722,
  26623. 'Udieresis': 722,
  26624. 'aogonek': 556,
  26625. 'Uacute': 722,
  26626. 'uogonek': 556,
  26627. 'Edieresis': 667,
  26628. 'Dcroat': 722,
  26629. 'commaaccent': 250,
  26630. 'copyright': 737,
  26631. 'Emacron': 667,
  26632. 'ccaron': 500,
  26633. 'aring': 556,
  26634. 'Ncommaaccent': 722,
  26635. 'lacute': 222,
  26636. 'agrave': 556,
  26637. 'Tcommaaccent': 611,
  26638. 'Cacute': 722,
  26639. 'atilde': 556,
  26640. 'Edotaccent': 667,
  26641. 'scaron': 500,
  26642. 'scedilla': 500,
  26643. 'iacute': 278,
  26644. 'lozenge': 471,
  26645. 'Rcaron': 722,
  26646. 'Gcommaaccent': 778,
  26647. 'ucircumflex': 556,
  26648. 'acircumflex': 556,
  26649. 'Amacron': 667,
  26650. 'rcaron': 333,
  26651. 'ccedilla': 500,
  26652. 'Zdotaccent': 611,
  26653. 'Thorn': 667,
  26654. 'Omacron': 778,
  26655. 'Racute': 722,
  26656. 'Sacute': 667,
  26657. 'dcaron': 643,
  26658. 'Umacron': 722,
  26659. 'uring': 556,
  26660. 'threesuperior': 333,
  26661. 'Ograve': 778,
  26662. 'Agrave': 667,
  26663. 'Abreve': 667,
  26664. 'multiply': 584,
  26665. 'uacute': 556,
  26666. 'Tcaron': 611,
  26667. 'partialdiff': 476,
  26668. 'ydieresis': 500,
  26669. 'Nacute': 722,
  26670. 'icircumflex': 278,
  26671. 'Ecircumflex': 667,
  26672. 'adieresis': 556,
  26673. 'edieresis': 556,
  26674. 'cacute': 500,
  26675. 'nacute': 556,
  26676. 'umacron': 556,
  26677. 'Ncaron': 722,
  26678. 'Iacute': 278,
  26679. 'plusminus': 584,
  26680. 'brokenbar': 260,
  26681. 'registered': 737,
  26682. 'Gbreve': 778,
  26683. 'Idotaccent': 278,
  26684. 'summation': 600,
  26685. 'Egrave': 667,
  26686. 'racute': 333,
  26687. 'omacron': 556,
  26688. 'Zacute': 611,
  26689. 'Zcaron': 611,
  26690. 'greaterequal': 549,
  26691. 'Eth': 722,
  26692. 'Ccedilla': 722,
  26693. 'lcommaaccent': 222,
  26694. 'tcaron': 317,
  26695. 'eogonek': 556,
  26696. 'Uogonek': 722,
  26697. 'Aacute': 667,
  26698. 'Adieresis': 667,
  26699. 'egrave': 556,
  26700. 'zacute': 500,
  26701. 'iogonek': 222,
  26702. 'Oacute': 778,
  26703. 'oacute': 556,
  26704. 'amacron': 556,
  26705. 'sacute': 500,
  26706. 'idieresis': 278,
  26707. 'Ocircumflex': 778,
  26708. 'Ugrave': 722,
  26709. 'Delta': 612,
  26710. 'thorn': 556,
  26711. 'twosuperior': 333,
  26712. 'Odieresis': 778,
  26713. 'mu': 556,
  26714. 'igrave': 278,
  26715. 'ohungarumlaut': 556,
  26716. 'Eogonek': 667,
  26717. 'dcroat': 556,
  26718. 'threequarters': 834,
  26719. 'Scedilla': 667,
  26720. 'lcaron': 299,
  26721. 'Kcommaaccent': 667,
  26722. 'Lacute': 556,
  26723. 'trademark': 1000,
  26724. 'edotaccent': 556,
  26725. 'Igrave': 278,
  26726. 'Imacron': 278,
  26727. 'Lcaron': 556,
  26728. 'onehalf': 834,
  26729. 'lessequal': 549,
  26730. 'ocircumflex': 556,
  26731. 'ntilde': 556,
  26732. 'Uhungarumlaut': 722,
  26733. 'Eacute': 667,
  26734. 'emacron': 556,
  26735. 'gbreve': 556,
  26736. 'onequarter': 834,
  26737. 'Scaron': 667,
  26738. 'Scommaaccent': 667,
  26739. 'Ohungarumlaut': 778,
  26740. 'degree': 400,
  26741. 'ograve': 556,
  26742. 'Ccaron': 722,
  26743. 'ugrave': 556,
  26744. 'radical': 453,
  26745. 'Dcaron': 722,
  26746. 'rcommaaccent': 333,
  26747. 'Ntilde': 722,
  26748. 'otilde': 556,
  26749. 'Rcommaaccent': 722,
  26750. 'Lcommaaccent': 556,
  26751. 'Atilde': 667,
  26752. 'Aogonek': 667,
  26753. 'Aring': 667,
  26754. 'Otilde': 778,
  26755. 'zdotaccent': 500,
  26756. 'Ecaron': 667,
  26757. 'Iogonek': 278,
  26758. 'kcommaaccent': 500,
  26759. 'minus': 584,
  26760. 'Icircumflex': 278,
  26761. 'ncaron': 556,
  26762. 'tcommaaccent': 278,
  26763. 'logicalnot': 584,
  26764. 'odieresis': 556,
  26765. 'udieresis': 556,
  26766. 'notequal': 549,
  26767. 'gcommaaccent': 556,
  26768. 'eth': 556,
  26769. 'zcaron': 500,
  26770. 'ncommaaccent': 556,
  26771. 'onesuperior': 333,
  26772. 'imacron': 278,
  26773. 'Euro': 556
  26774. },
  26775. 'Symbol': {
  26776. 'space': 250,
  26777. 'exclam': 333,
  26778. 'universal': 713,
  26779. 'numbersign': 500,
  26780. 'existential': 549,
  26781. 'percent': 833,
  26782. 'ampersand': 778,
  26783. 'suchthat': 439,
  26784. 'parenleft': 333,
  26785. 'parenright': 333,
  26786. 'asteriskmath': 500,
  26787. 'plus': 549,
  26788. 'comma': 250,
  26789. 'minus': 549,
  26790. 'period': 250,
  26791. 'slash': 278,
  26792. 'zero': 500,
  26793. 'one': 500,
  26794. 'two': 500,
  26795. 'three': 500,
  26796. 'four': 500,
  26797. 'five': 500,
  26798. 'six': 500,
  26799. 'seven': 500,
  26800. 'eight': 500,
  26801. 'nine': 500,
  26802. 'colon': 278,
  26803. 'semicolon': 278,
  26804. 'less': 549,
  26805. 'equal': 549,
  26806. 'greater': 549,
  26807. 'question': 444,
  26808. 'congruent': 549,
  26809. 'Alpha': 722,
  26810. 'Beta': 667,
  26811. 'Chi': 722,
  26812. 'Delta': 612,
  26813. 'Epsilon': 611,
  26814. 'Phi': 763,
  26815. 'Gamma': 603,
  26816. 'Eta': 722,
  26817. 'Iota': 333,
  26818. 'theta1': 631,
  26819. 'Kappa': 722,
  26820. 'Lambda': 686,
  26821. 'Mu': 889,
  26822. 'Nu': 722,
  26823. 'Omicron': 722,
  26824. 'Pi': 768,
  26825. 'Theta': 741,
  26826. 'Rho': 556,
  26827. 'Sigma': 592,
  26828. 'Tau': 611,
  26829. 'Upsilon': 690,
  26830. 'sigma1': 439,
  26831. 'Omega': 768,
  26832. 'Xi': 645,
  26833. 'Psi': 795,
  26834. 'Zeta': 611,
  26835. 'bracketleft': 333,
  26836. 'therefore': 863,
  26837. 'bracketright': 333,
  26838. 'perpendicular': 658,
  26839. 'underscore': 500,
  26840. 'radicalex': 500,
  26841. 'alpha': 631,
  26842. 'beta': 549,
  26843. 'chi': 549,
  26844. 'delta': 494,
  26845. 'epsilon': 439,
  26846. 'phi': 521,
  26847. 'gamma': 411,
  26848. 'eta': 603,
  26849. 'iota': 329,
  26850. 'phi1': 603,
  26851. 'kappa': 549,
  26852. 'lambda': 549,
  26853. 'mu': 576,
  26854. 'nu': 521,
  26855. 'omicron': 549,
  26856. 'pi': 549,
  26857. 'theta': 521,
  26858. 'rho': 549,
  26859. 'sigma': 603,
  26860. 'tau': 439,
  26861. 'upsilon': 576,
  26862. 'omega1': 713,
  26863. 'omega': 686,
  26864. 'xi': 493,
  26865. 'psi': 686,
  26866. 'zeta': 494,
  26867. 'braceleft': 480,
  26868. 'bar': 200,
  26869. 'braceright': 480,
  26870. 'similar': 549,
  26871. 'Euro': 750,
  26872. 'Upsilon1': 620,
  26873. 'minute': 247,
  26874. 'lessequal': 549,
  26875. 'fraction': 167,
  26876. 'infinity': 713,
  26877. 'florin': 500,
  26878. 'club': 753,
  26879. 'diamond': 753,
  26880. 'heart': 753,
  26881. 'spade': 753,
  26882. 'arrowboth': 1042,
  26883. 'arrowleft': 987,
  26884. 'arrowup': 603,
  26885. 'arrowright': 987,
  26886. 'arrowdown': 603,
  26887. 'degree': 400,
  26888. 'plusminus': 549,
  26889. 'second': 411,
  26890. 'greaterequal': 549,
  26891. 'multiply': 549,
  26892. 'proportional': 713,
  26893. 'partialdiff': 494,
  26894. 'bullet': 460,
  26895. 'divide': 549,
  26896. 'notequal': 549,
  26897. 'equivalence': 549,
  26898. 'approxequal': 549,
  26899. 'ellipsis': 1000,
  26900. 'arrowvertex': 603,
  26901. 'arrowhorizex': 1000,
  26902. 'carriagereturn': 658,
  26903. 'aleph': 823,
  26904. 'Ifraktur': 686,
  26905. 'Rfraktur': 795,
  26906. 'weierstrass': 987,
  26907. 'circlemultiply': 768,
  26908. 'circleplus': 768,
  26909. 'emptyset': 823,
  26910. 'intersection': 768,
  26911. 'union': 768,
  26912. 'propersuperset': 713,
  26913. 'reflexsuperset': 713,
  26914. 'notsubset': 713,
  26915. 'propersubset': 713,
  26916. 'reflexsubset': 713,
  26917. 'element': 713,
  26918. 'notelement': 713,
  26919. 'angle': 768,
  26920. 'gradient': 713,
  26921. 'registerserif': 790,
  26922. 'copyrightserif': 790,
  26923. 'trademarkserif': 890,
  26924. 'product': 823,
  26925. 'radical': 549,
  26926. 'dotmath': 250,
  26927. 'logicalnot': 713,
  26928. 'logicaland': 603,
  26929. 'logicalor': 603,
  26930. 'arrowdblboth': 1042,
  26931. 'arrowdblleft': 987,
  26932. 'arrowdblup': 603,
  26933. 'arrowdblright': 987,
  26934. 'arrowdbldown': 603,
  26935. 'lozenge': 494,
  26936. 'angleleft': 329,
  26937. 'registersans': 790,
  26938. 'copyrightsans': 790,
  26939. 'trademarksans': 786,
  26940. 'summation': 713,
  26941. 'parenlefttp': 384,
  26942. 'parenleftex': 384,
  26943. 'parenleftbt': 384,
  26944. 'bracketlefttp': 384,
  26945. 'bracketleftex': 384,
  26946. 'bracketleftbt': 384,
  26947. 'bracelefttp': 494,
  26948. 'braceleftmid': 494,
  26949. 'braceleftbt': 494,
  26950. 'braceex': 494,
  26951. 'angleright': 329,
  26952. 'integral': 274,
  26953. 'integraltp': 686,
  26954. 'integralex': 686,
  26955. 'integralbt': 686,
  26956. 'parenrighttp': 384,
  26957. 'parenrightex': 384,
  26958. 'parenrightbt': 384,
  26959. 'bracketrighttp': 384,
  26960. 'bracketrightex': 384,
  26961. 'bracketrightbt': 384,
  26962. 'bracerighttp': 494,
  26963. 'bracerightmid': 494,
  26964. 'bracerightbt': 494,
  26965. 'apple': 790
  26966. },
  26967. 'Times-Roman': {
  26968. 'space': 250,
  26969. 'exclam': 333,
  26970. 'quotedbl': 408,
  26971. 'numbersign': 500,
  26972. 'dollar': 500,
  26973. 'percent': 833,
  26974. 'ampersand': 778,
  26975. 'quoteright': 333,
  26976. 'parenleft': 333,
  26977. 'parenright': 333,
  26978. 'asterisk': 500,
  26979. 'plus': 564,
  26980. 'comma': 250,
  26981. 'hyphen': 333,
  26982. 'period': 250,
  26983. 'slash': 278,
  26984. 'zero': 500,
  26985. 'one': 500,
  26986. 'two': 500,
  26987. 'three': 500,
  26988. 'four': 500,
  26989. 'five': 500,
  26990. 'six': 500,
  26991. 'seven': 500,
  26992. 'eight': 500,
  26993. 'nine': 500,
  26994. 'colon': 278,
  26995. 'semicolon': 278,
  26996. 'less': 564,
  26997. 'equal': 564,
  26998. 'greater': 564,
  26999. 'question': 444,
  27000. 'at': 921,
  27001. 'A': 722,
  27002. 'B': 667,
  27003. 'C': 667,
  27004. 'D': 722,
  27005. 'E': 611,
  27006. 'F': 556,
  27007. 'G': 722,
  27008. 'H': 722,
  27009. 'I': 333,
  27010. 'J': 389,
  27011. 'K': 722,
  27012. 'L': 611,
  27013. 'M': 889,
  27014. 'N': 722,
  27015. 'O': 722,
  27016. 'P': 556,
  27017. 'Q': 722,
  27018. 'R': 667,
  27019. 'S': 556,
  27020. 'T': 611,
  27021. 'U': 722,
  27022. 'V': 722,
  27023. 'W': 944,
  27024. 'X': 722,
  27025. 'Y': 722,
  27026. 'Z': 611,
  27027. 'bracketleft': 333,
  27028. 'backslash': 278,
  27029. 'bracketright': 333,
  27030. 'asciicircum': 469,
  27031. 'underscore': 500,
  27032. 'quoteleft': 333,
  27033. 'a': 444,
  27034. 'b': 500,
  27035. 'c': 444,
  27036. 'd': 500,
  27037. 'e': 444,
  27038. 'f': 333,
  27039. 'g': 500,
  27040. 'h': 500,
  27041. 'i': 278,
  27042. 'j': 278,
  27043. 'k': 500,
  27044. 'l': 278,
  27045. 'm': 778,
  27046. 'n': 500,
  27047. 'o': 500,
  27048. 'p': 500,
  27049. 'q': 500,
  27050. 'r': 333,
  27051. 's': 389,
  27052. 't': 278,
  27053. 'u': 500,
  27054. 'v': 500,
  27055. 'w': 722,
  27056. 'x': 500,
  27057. 'y': 500,
  27058. 'z': 444,
  27059. 'braceleft': 480,
  27060. 'bar': 200,
  27061. 'braceright': 480,
  27062. 'asciitilde': 541,
  27063. 'exclamdown': 333,
  27064. 'cent': 500,
  27065. 'sterling': 500,
  27066. 'fraction': 167,
  27067. 'yen': 500,
  27068. 'florin': 500,
  27069. 'section': 500,
  27070. 'currency': 500,
  27071. 'quotesingle': 180,
  27072. 'quotedblleft': 444,
  27073. 'guillemotleft': 500,
  27074. 'guilsinglleft': 333,
  27075. 'guilsinglright': 333,
  27076. 'fi': 556,
  27077. 'fl': 556,
  27078. 'endash': 500,
  27079. 'dagger': 500,
  27080. 'daggerdbl': 500,
  27081. 'periodcentered': 250,
  27082. 'paragraph': 453,
  27083. 'bullet': 350,
  27084. 'quotesinglbase': 333,
  27085. 'quotedblbase': 444,
  27086. 'quotedblright': 444,
  27087. 'guillemotright': 500,
  27088. 'ellipsis': 1000,
  27089. 'perthousand': 1000,
  27090. 'questiondown': 444,
  27091. 'grave': 333,
  27092. 'acute': 333,
  27093. 'circumflex': 333,
  27094. 'tilde': 333,
  27095. 'macron': 333,
  27096. 'breve': 333,
  27097. 'dotaccent': 333,
  27098. 'dieresis': 333,
  27099. 'ring': 333,
  27100. 'cedilla': 333,
  27101. 'hungarumlaut': 333,
  27102. 'ogonek': 333,
  27103. 'caron': 333,
  27104. 'emdash': 1000,
  27105. 'AE': 889,
  27106. 'ordfeminine': 276,
  27107. 'Lslash': 611,
  27108. 'Oslash': 722,
  27109. 'OE': 889,
  27110. 'ordmasculine': 310,
  27111. 'ae': 667,
  27112. 'dotlessi': 278,
  27113. 'lslash': 278,
  27114. 'oslash': 500,
  27115. 'oe': 722,
  27116. 'germandbls': 500,
  27117. 'Idieresis': 333,
  27118. 'eacute': 444,
  27119. 'abreve': 444,
  27120. 'uhungarumlaut': 500,
  27121. 'ecaron': 444,
  27122. 'Ydieresis': 722,
  27123. 'divide': 564,
  27124. 'Yacute': 722,
  27125. 'Acircumflex': 722,
  27126. 'aacute': 444,
  27127. 'Ucircumflex': 722,
  27128. 'yacute': 500,
  27129. 'scommaaccent': 389,
  27130. 'ecircumflex': 444,
  27131. 'Uring': 722,
  27132. 'Udieresis': 722,
  27133. 'aogonek': 444,
  27134. 'Uacute': 722,
  27135. 'uogonek': 500,
  27136. 'Edieresis': 611,
  27137. 'Dcroat': 722,
  27138. 'commaaccent': 250,
  27139. 'copyright': 760,
  27140. 'Emacron': 611,
  27141. 'ccaron': 444,
  27142. 'aring': 444,
  27143. 'Ncommaaccent': 722,
  27144. 'lacute': 278,
  27145. 'agrave': 444,
  27146. 'Tcommaaccent': 611,
  27147. 'Cacute': 667,
  27148. 'atilde': 444,
  27149. 'Edotaccent': 611,
  27150. 'scaron': 389,
  27151. 'scedilla': 389,
  27152. 'iacute': 278,
  27153. 'lozenge': 471,
  27154. 'Rcaron': 667,
  27155. 'Gcommaaccent': 722,
  27156. 'ucircumflex': 500,
  27157. 'acircumflex': 444,
  27158. 'Amacron': 722,
  27159. 'rcaron': 333,
  27160. 'ccedilla': 444,
  27161. 'Zdotaccent': 611,
  27162. 'Thorn': 556,
  27163. 'Omacron': 722,
  27164. 'Racute': 667,
  27165. 'Sacute': 556,
  27166. 'dcaron': 588,
  27167. 'Umacron': 722,
  27168. 'uring': 500,
  27169. 'threesuperior': 300,
  27170. 'Ograve': 722,
  27171. 'Agrave': 722,
  27172. 'Abreve': 722,
  27173. 'multiply': 564,
  27174. 'uacute': 500,
  27175. 'Tcaron': 611,
  27176. 'partialdiff': 476,
  27177. 'ydieresis': 500,
  27178. 'Nacute': 722,
  27179. 'icircumflex': 278,
  27180. 'Ecircumflex': 611,
  27181. 'adieresis': 444,
  27182. 'edieresis': 444,
  27183. 'cacute': 444,
  27184. 'nacute': 500,
  27185. 'umacron': 500,
  27186. 'Ncaron': 722,
  27187. 'Iacute': 333,
  27188. 'plusminus': 564,
  27189. 'brokenbar': 200,
  27190. 'registered': 760,
  27191. 'Gbreve': 722,
  27192. 'Idotaccent': 333,
  27193. 'summation': 600,
  27194. 'Egrave': 611,
  27195. 'racute': 333,
  27196. 'omacron': 500,
  27197. 'Zacute': 611,
  27198. 'Zcaron': 611,
  27199. 'greaterequal': 549,
  27200. 'Eth': 722,
  27201. 'Ccedilla': 667,
  27202. 'lcommaaccent': 278,
  27203. 'tcaron': 326,
  27204. 'eogonek': 444,
  27205. 'Uogonek': 722,
  27206. 'Aacute': 722,
  27207. 'Adieresis': 722,
  27208. 'egrave': 444,
  27209. 'zacute': 444,
  27210. 'iogonek': 278,
  27211. 'Oacute': 722,
  27212. 'oacute': 500,
  27213. 'amacron': 444,
  27214. 'sacute': 389,
  27215. 'idieresis': 278,
  27216. 'Ocircumflex': 722,
  27217. 'Ugrave': 722,
  27218. 'Delta': 612,
  27219. 'thorn': 500,
  27220. 'twosuperior': 300,
  27221. 'Odieresis': 722,
  27222. 'mu': 500,
  27223. 'igrave': 278,
  27224. 'ohungarumlaut': 500,
  27225. 'Eogonek': 611,
  27226. 'dcroat': 500,
  27227. 'threequarters': 750,
  27228. 'Scedilla': 556,
  27229. 'lcaron': 344,
  27230. 'Kcommaaccent': 722,
  27231. 'Lacute': 611,
  27232. 'trademark': 980,
  27233. 'edotaccent': 444,
  27234. 'Igrave': 333,
  27235. 'Imacron': 333,
  27236. 'Lcaron': 611,
  27237. 'onehalf': 750,
  27238. 'lessequal': 549,
  27239. 'ocircumflex': 500,
  27240. 'ntilde': 500,
  27241. 'Uhungarumlaut': 722,
  27242. 'Eacute': 611,
  27243. 'emacron': 444,
  27244. 'gbreve': 500,
  27245. 'onequarter': 750,
  27246. 'Scaron': 556,
  27247. 'Scommaaccent': 556,
  27248. 'Ohungarumlaut': 722,
  27249. 'degree': 400,
  27250. 'ograve': 500,
  27251. 'Ccaron': 667,
  27252. 'ugrave': 500,
  27253. 'radical': 453,
  27254. 'Dcaron': 722,
  27255. 'rcommaaccent': 333,
  27256. 'Ntilde': 722,
  27257. 'otilde': 500,
  27258. 'Rcommaaccent': 667,
  27259. 'Lcommaaccent': 611,
  27260. 'Atilde': 722,
  27261. 'Aogonek': 722,
  27262. 'Aring': 722,
  27263. 'Otilde': 722,
  27264. 'zdotaccent': 444,
  27265. 'Ecaron': 611,
  27266. 'Iogonek': 333,
  27267. 'kcommaaccent': 500,
  27268. 'minus': 564,
  27269. 'Icircumflex': 333,
  27270. 'ncaron': 500,
  27271. 'tcommaaccent': 278,
  27272. 'logicalnot': 564,
  27273. 'odieresis': 500,
  27274. 'udieresis': 500,
  27275. 'notequal': 549,
  27276. 'gcommaaccent': 500,
  27277. 'eth': 500,
  27278. 'zcaron': 444,
  27279. 'ncommaaccent': 500,
  27280. 'onesuperior': 300,
  27281. 'imacron': 278,
  27282. 'Euro': 500
  27283. },
  27284. 'Times-Bold': {
  27285. 'space': 250,
  27286. 'exclam': 333,
  27287. 'quotedbl': 555,
  27288. 'numbersign': 500,
  27289. 'dollar': 500,
  27290. 'percent': 1000,
  27291. 'ampersand': 833,
  27292. 'quoteright': 333,
  27293. 'parenleft': 333,
  27294. 'parenright': 333,
  27295. 'asterisk': 500,
  27296. 'plus': 570,
  27297. 'comma': 250,
  27298. 'hyphen': 333,
  27299. 'period': 250,
  27300. 'slash': 278,
  27301. 'zero': 500,
  27302. 'one': 500,
  27303. 'two': 500,
  27304. 'three': 500,
  27305. 'four': 500,
  27306. 'five': 500,
  27307. 'six': 500,
  27308. 'seven': 500,
  27309. 'eight': 500,
  27310. 'nine': 500,
  27311. 'colon': 333,
  27312. 'semicolon': 333,
  27313. 'less': 570,
  27314. 'equal': 570,
  27315. 'greater': 570,
  27316. 'question': 500,
  27317. 'at': 930,
  27318. 'A': 722,
  27319. 'B': 667,
  27320. 'C': 722,
  27321. 'D': 722,
  27322. 'E': 667,
  27323. 'F': 611,
  27324. 'G': 778,
  27325. 'H': 778,
  27326. 'I': 389,
  27327. 'J': 500,
  27328. 'K': 778,
  27329. 'L': 667,
  27330. 'M': 944,
  27331. 'N': 722,
  27332. 'O': 778,
  27333. 'P': 611,
  27334. 'Q': 778,
  27335. 'R': 722,
  27336. 'S': 556,
  27337. 'T': 667,
  27338. 'U': 722,
  27339. 'V': 722,
  27340. 'W': 1000,
  27341. 'X': 722,
  27342. 'Y': 722,
  27343. 'Z': 667,
  27344. 'bracketleft': 333,
  27345. 'backslash': 278,
  27346. 'bracketright': 333,
  27347. 'asciicircum': 581,
  27348. 'underscore': 500,
  27349. 'quoteleft': 333,
  27350. 'a': 500,
  27351. 'b': 556,
  27352. 'c': 444,
  27353. 'd': 556,
  27354. 'e': 444,
  27355. 'f': 333,
  27356. 'g': 500,
  27357. 'h': 556,
  27358. 'i': 278,
  27359. 'j': 333,
  27360. 'k': 556,
  27361. 'l': 278,
  27362. 'm': 833,
  27363. 'n': 556,
  27364. 'o': 500,
  27365. 'p': 556,
  27366. 'q': 556,
  27367. 'r': 444,
  27368. 's': 389,
  27369. 't': 333,
  27370. 'u': 556,
  27371. 'v': 500,
  27372. 'w': 722,
  27373. 'x': 500,
  27374. 'y': 500,
  27375. 'z': 444,
  27376. 'braceleft': 394,
  27377. 'bar': 220,
  27378. 'braceright': 394,
  27379. 'asciitilde': 520,
  27380. 'exclamdown': 333,
  27381. 'cent': 500,
  27382. 'sterling': 500,
  27383. 'fraction': 167,
  27384. 'yen': 500,
  27385. 'florin': 500,
  27386. 'section': 500,
  27387. 'currency': 500,
  27388. 'quotesingle': 278,
  27389. 'quotedblleft': 500,
  27390. 'guillemotleft': 500,
  27391. 'guilsinglleft': 333,
  27392. 'guilsinglright': 333,
  27393. 'fi': 556,
  27394. 'fl': 556,
  27395. 'endash': 500,
  27396. 'dagger': 500,
  27397. 'daggerdbl': 500,
  27398. 'periodcentered': 250,
  27399. 'paragraph': 540,
  27400. 'bullet': 350,
  27401. 'quotesinglbase': 333,
  27402. 'quotedblbase': 500,
  27403. 'quotedblright': 500,
  27404. 'guillemotright': 500,
  27405. 'ellipsis': 1000,
  27406. 'perthousand': 1000,
  27407. 'questiondown': 500,
  27408. 'grave': 333,
  27409. 'acute': 333,
  27410. 'circumflex': 333,
  27411. 'tilde': 333,
  27412. 'macron': 333,
  27413. 'breve': 333,
  27414. 'dotaccent': 333,
  27415. 'dieresis': 333,
  27416. 'ring': 333,
  27417. 'cedilla': 333,
  27418. 'hungarumlaut': 333,
  27419. 'ogonek': 333,
  27420. 'caron': 333,
  27421. 'emdash': 1000,
  27422. 'AE': 1000,
  27423. 'ordfeminine': 300,
  27424. 'Lslash': 667,
  27425. 'Oslash': 778,
  27426. 'OE': 1000,
  27427. 'ordmasculine': 330,
  27428. 'ae': 722,
  27429. 'dotlessi': 278,
  27430. 'lslash': 278,
  27431. 'oslash': 500,
  27432. 'oe': 722,
  27433. 'germandbls': 556,
  27434. 'Idieresis': 389,
  27435. 'eacute': 444,
  27436. 'abreve': 500,
  27437. 'uhungarumlaut': 556,
  27438. 'ecaron': 444,
  27439. 'Ydieresis': 722,
  27440. 'divide': 570,
  27441. 'Yacute': 722,
  27442. 'Acircumflex': 722,
  27443. 'aacute': 500,
  27444. 'Ucircumflex': 722,
  27445. 'yacute': 500,
  27446. 'scommaaccent': 389,
  27447. 'ecircumflex': 444,
  27448. 'Uring': 722,
  27449. 'Udieresis': 722,
  27450. 'aogonek': 500,
  27451. 'Uacute': 722,
  27452. 'uogonek': 556,
  27453. 'Edieresis': 667,
  27454. 'Dcroat': 722,
  27455. 'commaaccent': 250,
  27456. 'copyright': 747,
  27457. 'Emacron': 667,
  27458. 'ccaron': 444,
  27459. 'aring': 500,
  27460. 'Ncommaaccent': 722,
  27461. 'lacute': 278,
  27462. 'agrave': 500,
  27463. 'Tcommaaccent': 667,
  27464. 'Cacute': 722,
  27465. 'atilde': 500,
  27466. 'Edotaccent': 667,
  27467. 'scaron': 389,
  27468. 'scedilla': 389,
  27469. 'iacute': 278,
  27470. 'lozenge': 494,
  27471. 'Rcaron': 722,
  27472. 'Gcommaaccent': 778,
  27473. 'ucircumflex': 556,
  27474. 'acircumflex': 500,
  27475. 'Amacron': 722,
  27476. 'rcaron': 444,
  27477. 'ccedilla': 444,
  27478. 'Zdotaccent': 667,
  27479. 'Thorn': 611,
  27480. 'Omacron': 778,
  27481. 'Racute': 722,
  27482. 'Sacute': 556,
  27483. 'dcaron': 672,
  27484. 'Umacron': 722,
  27485. 'uring': 556,
  27486. 'threesuperior': 300,
  27487. 'Ograve': 778,
  27488. 'Agrave': 722,
  27489. 'Abreve': 722,
  27490. 'multiply': 570,
  27491. 'uacute': 556,
  27492. 'Tcaron': 667,
  27493. 'partialdiff': 494,
  27494. 'ydieresis': 500,
  27495. 'Nacute': 722,
  27496. 'icircumflex': 278,
  27497. 'Ecircumflex': 667,
  27498. 'adieresis': 500,
  27499. 'edieresis': 444,
  27500. 'cacute': 444,
  27501. 'nacute': 556,
  27502. 'umacron': 556,
  27503. 'Ncaron': 722,
  27504. 'Iacute': 389,
  27505. 'plusminus': 570,
  27506. 'brokenbar': 220,
  27507. 'registered': 747,
  27508. 'Gbreve': 778,
  27509. 'Idotaccent': 389,
  27510. 'summation': 600,
  27511. 'Egrave': 667,
  27512. 'racute': 444,
  27513. 'omacron': 500,
  27514. 'Zacute': 667,
  27515. 'Zcaron': 667,
  27516. 'greaterequal': 549,
  27517. 'Eth': 722,
  27518. 'Ccedilla': 722,
  27519. 'lcommaaccent': 278,
  27520. 'tcaron': 416,
  27521. 'eogonek': 444,
  27522. 'Uogonek': 722,
  27523. 'Aacute': 722,
  27524. 'Adieresis': 722,
  27525. 'egrave': 444,
  27526. 'zacute': 444,
  27527. 'iogonek': 278,
  27528. 'Oacute': 778,
  27529. 'oacute': 500,
  27530. 'amacron': 500,
  27531. 'sacute': 389,
  27532. 'idieresis': 278,
  27533. 'Ocircumflex': 778,
  27534. 'Ugrave': 722,
  27535. 'Delta': 612,
  27536. 'thorn': 556,
  27537. 'twosuperior': 300,
  27538. 'Odieresis': 778,
  27539. 'mu': 556,
  27540. 'igrave': 278,
  27541. 'ohungarumlaut': 500,
  27542. 'Eogonek': 667,
  27543. 'dcroat': 556,
  27544. 'threequarters': 750,
  27545. 'Scedilla': 556,
  27546. 'lcaron': 394,
  27547. 'Kcommaaccent': 778,
  27548. 'Lacute': 667,
  27549. 'trademark': 1000,
  27550. 'edotaccent': 444,
  27551. 'Igrave': 389,
  27552. 'Imacron': 389,
  27553. 'Lcaron': 667,
  27554. 'onehalf': 750,
  27555. 'lessequal': 549,
  27556. 'ocircumflex': 500,
  27557. 'ntilde': 556,
  27558. 'Uhungarumlaut': 722,
  27559. 'Eacute': 667,
  27560. 'emacron': 444,
  27561. 'gbreve': 500,
  27562. 'onequarter': 750,
  27563. 'Scaron': 556,
  27564. 'Scommaaccent': 556,
  27565. 'Ohungarumlaut': 778,
  27566. 'degree': 400,
  27567. 'ograve': 500,
  27568. 'Ccaron': 722,
  27569. 'ugrave': 556,
  27570. 'radical': 549,
  27571. 'Dcaron': 722,
  27572. 'rcommaaccent': 444,
  27573. 'Ntilde': 722,
  27574. 'otilde': 500,
  27575. 'Rcommaaccent': 722,
  27576. 'Lcommaaccent': 667,
  27577. 'Atilde': 722,
  27578. 'Aogonek': 722,
  27579. 'Aring': 722,
  27580. 'Otilde': 778,
  27581. 'zdotaccent': 444,
  27582. 'Ecaron': 667,
  27583. 'Iogonek': 389,
  27584. 'kcommaaccent': 556,
  27585. 'minus': 570,
  27586. 'Icircumflex': 389,
  27587. 'ncaron': 556,
  27588. 'tcommaaccent': 333,
  27589. 'logicalnot': 570,
  27590. 'odieresis': 500,
  27591. 'udieresis': 556,
  27592. 'notequal': 549,
  27593. 'gcommaaccent': 500,
  27594. 'eth': 500,
  27595. 'zcaron': 444,
  27596. 'ncommaaccent': 556,
  27597. 'onesuperior': 300,
  27598. 'imacron': 278,
  27599. 'Euro': 500
  27600. },
  27601. 'Times-BoldItalic': {
  27602. 'space': 250,
  27603. 'exclam': 389,
  27604. 'quotedbl': 555,
  27605. 'numbersign': 500,
  27606. 'dollar': 500,
  27607. 'percent': 833,
  27608. 'ampersand': 778,
  27609. 'quoteright': 333,
  27610. 'parenleft': 333,
  27611. 'parenright': 333,
  27612. 'asterisk': 500,
  27613. 'plus': 570,
  27614. 'comma': 250,
  27615. 'hyphen': 333,
  27616. 'period': 250,
  27617. 'slash': 278,
  27618. 'zero': 500,
  27619. 'one': 500,
  27620. 'two': 500,
  27621. 'three': 500,
  27622. 'four': 500,
  27623. 'five': 500,
  27624. 'six': 500,
  27625. 'seven': 500,
  27626. 'eight': 500,
  27627. 'nine': 500,
  27628. 'colon': 333,
  27629. 'semicolon': 333,
  27630. 'less': 570,
  27631. 'equal': 570,
  27632. 'greater': 570,
  27633. 'question': 500,
  27634. 'at': 832,
  27635. 'A': 667,
  27636. 'B': 667,
  27637. 'C': 667,
  27638. 'D': 722,
  27639. 'E': 667,
  27640. 'F': 667,
  27641. 'G': 722,
  27642. 'H': 778,
  27643. 'I': 389,
  27644. 'J': 500,
  27645. 'K': 667,
  27646. 'L': 611,
  27647. 'M': 889,
  27648. 'N': 722,
  27649. 'O': 722,
  27650. 'P': 611,
  27651. 'Q': 722,
  27652. 'R': 667,
  27653. 'S': 556,
  27654. 'T': 611,
  27655. 'U': 722,
  27656. 'V': 667,
  27657. 'W': 889,
  27658. 'X': 667,
  27659. 'Y': 611,
  27660. 'Z': 611,
  27661. 'bracketleft': 333,
  27662. 'backslash': 278,
  27663. 'bracketright': 333,
  27664. 'asciicircum': 570,
  27665. 'underscore': 500,
  27666. 'quoteleft': 333,
  27667. 'a': 500,
  27668. 'b': 500,
  27669. 'c': 444,
  27670. 'd': 500,
  27671. 'e': 444,
  27672. 'f': 333,
  27673. 'g': 500,
  27674. 'h': 556,
  27675. 'i': 278,
  27676. 'j': 278,
  27677. 'k': 500,
  27678. 'l': 278,
  27679. 'm': 778,
  27680. 'n': 556,
  27681. 'o': 500,
  27682. 'p': 500,
  27683. 'q': 500,
  27684. 'r': 389,
  27685. 's': 389,
  27686. 't': 278,
  27687. 'u': 556,
  27688. 'v': 444,
  27689. 'w': 667,
  27690. 'x': 500,
  27691. 'y': 444,
  27692. 'z': 389,
  27693. 'braceleft': 348,
  27694. 'bar': 220,
  27695. 'braceright': 348,
  27696. 'asciitilde': 570,
  27697. 'exclamdown': 389,
  27698. 'cent': 500,
  27699. 'sterling': 500,
  27700. 'fraction': 167,
  27701. 'yen': 500,
  27702. 'florin': 500,
  27703. 'section': 500,
  27704. 'currency': 500,
  27705. 'quotesingle': 278,
  27706. 'quotedblleft': 500,
  27707. 'guillemotleft': 500,
  27708. 'guilsinglleft': 333,
  27709. 'guilsinglright': 333,
  27710. 'fi': 556,
  27711. 'fl': 556,
  27712. 'endash': 500,
  27713. 'dagger': 500,
  27714. 'daggerdbl': 500,
  27715. 'periodcentered': 250,
  27716. 'paragraph': 500,
  27717. 'bullet': 350,
  27718. 'quotesinglbase': 333,
  27719. 'quotedblbase': 500,
  27720. 'quotedblright': 500,
  27721. 'guillemotright': 500,
  27722. 'ellipsis': 1000,
  27723. 'perthousand': 1000,
  27724. 'questiondown': 500,
  27725. 'grave': 333,
  27726. 'acute': 333,
  27727. 'circumflex': 333,
  27728. 'tilde': 333,
  27729. 'macron': 333,
  27730. 'breve': 333,
  27731. 'dotaccent': 333,
  27732. 'dieresis': 333,
  27733. 'ring': 333,
  27734. 'cedilla': 333,
  27735. 'hungarumlaut': 333,
  27736. 'ogonek': 333,
  27737. 'caron': 333,
  27738. 'emdash': 1000,
  27739. 'AE': 944,
  27740. 'ordfeminine': 266,
  27741. 'Lslash': 611,
  27742. 'Oslash': 722,
  27743. 'OE': 944,
  27744. 'ordmasculine': 300,
  27745. 'ae': 722,
  27746. 'dotlessi': 278,
  27747. 'lslash': 278,
  27748. 'oslash': 500,
  27749. 'oe': 722,
  27750. 'germandbls': 500,
  27751. 'Idieresis': 389,
  27752. 'eacute': 444,
  27753. 'abreve': 500,
  27754. 'uhungarumlaut': 556,
  27755. 'ecaron': 444,
  27756. 'Ydieresis': 611,
  27757. 'divide': 570,
  27758. 'Yacute': 611,
  27759. 'Acircumflex': 667,
  27760. 'aacute': 500,
  27761. 'Ucircumflex': 722,
  27762. 'yacute': 444,
  27763. 'scommaaccent': 389,
  27764. 'ecircumflex': 444,
  27765. 'Uring': 722,
  27766. 'Udieresis': 722,
  27767. 'aogonek': 500,
  27768. 'Uacute': 722,
  27769. 'uogonek': 556,
  27770. 'Edieresis': 667,
  27771. 'Dcroat': 722,
  27772. 'commaaccent': 250,
  27773. 'copyright': 747,
  27774. 'Emacron': 667,
  27775. 'ccaron': 444,
  27776. 'aring': 500,
  27777. 'Ncommaaccent': 722,
  27778. 'lacute': 278,
  27779. 'agrave': 500,
  27780. 'Tcommaaccent': 611,
  27781. 'Cacute': 667,
  27782. 'atilde': 500,
  27783. 'Edotaccent': 667,
  27784. 'scaron': 389,
  27785. 'scedilla': 389,
  27786. 'iacute': 278,
  27787. 'lozenge': 494,
  27788. 'Rcaron': 667,
  27789. 'Gcommaaccent': 722,
  27790. 'ucircumflex': 556,
  27791. 'acircumflex': 500,
  27792. 'Amacron': 667,
  27793. 'rcaron': 389,
  27794. 'ccedilla': 444,
  27795. 'Zdotaccent': 611,
  27796. 'Thorn': 611,
  27797. 'Omacron': 722,
  27798. 'Racute': 667,
  27799. 'Sacute': 556,
  27800. 'dcaron': 608,
  27801. 'Umacron': 722,
  27802. 'uring': 556,
  27803. 'threesuperior': 300,
  27804. 'Ograve': 722,
  27805. 'Agrave': 667,
  27806. 'Abreve': 667,
  27807. 'multiply': 570,
  27808. 'uacute': 556,
  27809. 'Tcaron': 611,
  27810. 'partialdiff': 494,
  27811. 'ydieresis': 444,
  27812. 'Nacute': 722,
  27813. 'icircumflex': 278,
  27814. 'Ecircumflex': 667,
  27815. 'adieresis': 500,
  27816. 'edieresis': 444,
  27817. 'cacute': 444,
  27818. 'nacute': 556,
  27819. 'umacron': 556,
  27820. 'Ncaron': 722,
  27821. 'Iacute': 389,
  27822. 'plusminus': 570,
  27823. 'brokenbar': 220,
  27824. 'registered': 747,
  27825. 'Gbreve': 722,
  27826. 'Idotaccent': 389,
  27827. 'summation': 600,
  27828. 'Egrave': 667,
  27829. 'racute': 389,
  27830. 'omacron': 500,
  27831. 'Zacute': 611,
  27832. 'Zcaron': 611,
  27833. 'greaterequal': 549,
  27834. 'Eth': 722,
  27835. 'Ccedilla': 667,
  27836. 'lcommaaccent': 278,
  27837. 'tcaron': 366,
  27838. 'eogonek': 444,
  27839. 'Uogonek': 722,
  27840. 'Aacute': 667,
  27841. 'Adieresis': 667,
  27842. 'egrave': 444,
  27843. 'zacute': 389,
  27844. 'iogonek': 278,
  27845. 'Oacute': 722,
  27846. 'oacute': 500,
  27847. 'amacron': 500,
  27848. 'sacute': 389,
  27849. 'idieresis': 278,
  27850. 'Ocircumflex': 722,
  27851. 'Ugrave': 722,
  27852. 'Delta': 612,
  27853. 'thorn': 500,
  27854. 'twosuperior': 300,
  27855. 'Odieresis': 722,
  27856. 'mu': 576,
  27857. 'igrave': 278,
  27858. 'ohungarumlaut': 500,
  27859. 'Eogonek': 667,
  27860. 'dcroat': 500,
  27861. 'threequarters': 750,
  27862. 'Scedilla': 556,
  27863. 'lcaron': 382,
  27864. 'Kcommaaccent': 667,
  27865. 'Lacute': 611,
  27866. 'trademark': 1000,
  27867. 'edotaccent': 444,
  27868. 'Igrave': 389,
  27869. 'Imacron': 389,
  27870. 'Lcaron': 611,
  27871. 'onehalf': 750,
  27872. 'lessequal': 549,
  27873. 'ocircumflex': 500,
  27874. 'ntilde': 556,
  27875. 'Uhungarumlaut': 722,
  27876. 'Eacute': 667,
  27877. 'emacron': 444,
  27878. 'gbreve': 500,
  27879. 'onequarter': 750,
  27880. 'Scaron': 556,
  27881. 'Scommaaccent': 556,
  27882. 'Ohungarumlaut': 722,
  27883. 'degree': 400,
  27884. 'ograve': 500,
  27885. 'Ccaron': 667,
  27886. 'ugrave': 556,
  27887. 'radical': 549,
  27888. 'Dcaron': 722,
  27889. 'rcommaaccent': 389,
  27890. 'Ntilde': 722,
  27891. 'otilde': 500,
  27892. 'Rcommaaccent': 667,
  27893. 'Lcommaaccent': 611,
  27894. 'Atilde': 667,
  27895. 'Aogonek': 667,
  27896. 'Aring': 667,
  27897. 'Otilde': 722,
  27898. 'zdotaccent': 389,
  27899. 'Ecaron': 667,
  27900. 'Iogonek': 389,
  27901. 'kcommaaccent': 500,
  27902. 'minus': 606,
  27903. 'Icircumflex': 389,
  27904. 'ncaron': 556,
  27905. 'tcommaaccent': 278,
  27906. 'logicalnot': 606,
  27907. 'odieresis': 500,
  27908. 'udieresis': 556,
  27909. 'notequal': 549,
  27910. 'gcommaaccent': 500,
  27911. 'eth': 500,
  27912. 'zcaron': 389,
  27913. 'ncommaaccent': 556,
  27914. 'onesuperior': 300,
  27915. 'imacron': 278,
  27916. 'Euro': 500
  27917. },
  27918. 'Times-Italic': {
  27919. 'space': 250,
  27920. 'exclam': 333,
  27921. 'quotedbl': 420,
  27922. 'numbersign': 500,
  27923. 'dollar': 500,
  27924. 'percent': 833,
  27925. 'ampersand': 778,
  27926. 'quoteright': 333,
  27927. 'parenleft': 333,
  27928. 'parenright': 333,
  27929. 'asterisk': 500,
  27930. 'plus': 675,
  27931. 'comma': 250,
  27932. 'hyphen': 333,
  27933. 'period': 250,
  27934. 'slash': 278,
  27935. 'zero': 500,
  27936. 'one': 500,
  27937. 'two': 500,
  27938. 'three': 500,
  27939. 'four': 500,
  27940. 'five': 500,
  27941. 'six': 500,
  27942. 'seven': 500,
  27943. 'eight': 500,
  27944. 'nine': 500,
  27945. 'colon': 333,
  27946. 'semicolon': 333,
  27947. 'less': 675,
  27948. 'equal': 675,
  27949. 'greater': 675,
  27950. 'question': 500,
  27951. 'at': 920,
  27952. 'A': 611,
  27953. 'B': 611,
  27954. 'C': 667,
  27955. 'D': 722,
  27956. 'E': 611,
  27957. 'F': 611,
  27958. 'G': 722,
  27959. 'H': 722,
  27960. 'I': 333,
  27961. 'J': 444,
  27962. 'K': 667,
  27963. 'L': 556,
  27964. 'M': 833,
  27965. 'N': 667,
  27966. 'O': 722,
  27967. 'P': 611,
  27968. 'Q': 722,
  27969. 'R': 611,
  27970. 'S': 500,
  27971. 'T': 556,
  27972. 'U': 722,
  27973. 'V': 611,
  27974. 'W': 833,
  27975. 'X': 611,
  27976. 'Y': 556,
  27977. 'Z': 556,
  27978. 'bracketleft': 389,
  27979. 'backslash': 278,
  27980. 'bracketright': 389,
  27981. 'asciicircum': 422,
  27982. 'underscore': 500,
  27983. 'quoteleft': 333,
  27984. 'a': 500,
  27985. 'b': 500,
  27986. 'c': 444,
  27987. 'd': 500,
  27988. 'e': 444,
  27989. 'f': 278,
  27990. 'g': 500,
  27991. 'h': 500,
  27992. 'i': 278,
  27993. 'j': 278,
  27994. 'k': 444,
  27995. 'l': 278,
  27996. 'm': 722,
  27997. 'n': 500,
  27998. 'o': 500,
  27999. 'p': 500,
  28000. 'q': 500,
  28001. 'r': 389,
  28002. 's': 389,
  28003. 't': 278,
  28004. 'u': 500,
  28005. 'v': 444,
  28006. 'w': 667,
  28007. 'x': 444,
  28008. 'y': 444,
  28009. 'z': 389,
  28010. 'braceleft': 400,
  28011. 'bar': 275,
  28012. 'braceright': 400,
  28013. 'asciitilde': 541,
  28014. 'exclamdown': 389,
  28015. 'cent': 500,
  28016. 'sterling': 500,
  28017. 'fraction': 167,
  28018. 'yen': 500,
  28019. 'florin': 500,
  28020. 'section': 500,
  28021. 'currency': 500,
  28022. 'quotesingle': 214,
  28023. 'quotedblleft': 556,
  28024. 'guillemotleft': 500,
  28025. 'guilsinglleft': 333,
  28026. 'guilsinglright': 333,
  28027. 'fi': 500,
  28028. 'fl': 500,
  28029. 'endash': 500,
  28030. 'dagger': 500,
  28031. 'daggerdbl': 500,
  28032. 'periodcentered': 250,
  28033. 'paragraph': 523,
  28034. 'bullet': 350,
  28035. 'quotesinglbase': 333,
  28036. 'quotedblbase': 556,
  28037. 'quotedblright': 556,
  28038. 'guillemotright': 500,
  28039. 'ellipsis': 889,
  28040. 'perthousand': 1000,
  28041. 'questiondown': 500,
  28042. 'grave': 333,
  28043. 'acute': 333,
  28044. 'circumflex': 333,
  28045. 'tilde': 333,
  28046. 'macron': 333,
  28047. 'breve': 333,
  28048. 'dotaccent': 333,
  28049. 'dieresis': 333,
  28050. 'ring': 333,
  28051. 'cedilla': 333,
  28052. 'hungarumlaut': 333,
  28053. 'ogonek': 333,
  28054. 'caron': 333,
  28055. 'emdash': 889,
  28056. 'AE': 889,
  28057. 'ordfeminine': 276,
  28058. 'Lslash': 556,
  28059. 'Oslash': 722,
  28060. 'OE': 944,
  28061. 'ordmasculine': 310,
  28062. 'ae': 667,
  28063. 'dotlessi': 278,
  28064. 'lslash': 278,
  28065. 'oslash': 500,
  28066. 'oe': 667,
  28067. 'germandbls': 500,
  28068. 'Idieresis': 333,
  28069. 'eacute': 444,
  28070. 'abreve': 500,
  28071. 'uhungarumlaut': 500,
  28072. 'ecaron': 444,
  28073. 'Ydieresis': 556,
  28074. 'divide': 675,
  28075. 'Yacute': 556,
  28076. 'Acircumflex': 611,
  28077. 'aacute': 500,
  28078. 'Ucircumflex': 722,
  28079. 'yacute': 444,
  28080. 'scommaaccent': 389,
  28081. 'ecircumflex': 444,
  28082. 'Uring': 722,
  28083. 'Udieresis': 722,
  28084. 'aogonek': 500,
  28085. 'Uacute': 722,
  28086. 'uogonek': 500,
  28087. 'Edieresis': 611,
  28088. 'Dcroat': 722,
  28089. 'commaaccent': 250,
  28090. 'copyright': 760,
  28091. 'Emacron': 611,
  28092. 'ccaron': 444,
  28093. 'aring': 500,
  28094. 'Ncommaaccent': 667,
  28095. 'lacute': 278,
  28096. 'agrave': 500,
  28097. 'Tcommaaccent': 556,
  28098. 'Cacute': 667,
  28099. 'atilde': 500,
  28100. 'Edotaccent': 611,
  28101. 'scaron': 389,
  28102. 'scedilla': 389,
  28103. 'iacute': 278,
  28104. 'lozenge': 471,
  28105. 'Rcaron': 611,
  28106. 'Gcommaaccent': 722,
  28107. 'ucircumflex': 500,
  28108. 'acircumflex': 500,
  28109. 'Amacron': 611,
  28110. 'rcaron': 389,
  28111. 'ccedilla': 444,
  28112. 'Zdotaccent': 556,
  28113. 'Thorn': 611,
  28114. 'Omacron': 722,
  28115. 'Racute': 611,
  28116. 'Sacute': 500,
  28117. 'dcaron': 544,
  28118. 'Umacron': 722,
  28119. 'uring': 500,
  28120. 'threesuperior': 300,
  28121. 'Ograve': 722,
  28122. 'Agrave': 611,
  28123. 'Abreve': 611,
  28124. 'multiply': 675,
  28125. 'uacute': 500,
  28126. 'Tcaron': 556,
  28127. 'partialdiff': 476,
  28128. 'ydieresis': 444,
  28129. 'Nacute': 667,
  28130. 'icircumflex': 278,
  28131. 'Ecircumflex': 611,
  28132. 'adieresis': 500,
  28133. 'edieresis': 444,
  28134. 'cacute': 444,
  28135. 'nacute': 500,
  28136. 'umacron': 500,
  28137. 'Ncaron': 667,
  28138. 'Iacute': 333,
  28139. 'plusminus': 675,
  28140. 'brokenbar': 275,
  28141. 'registered': 760,
  28142. 'Gbreve': 722,
  28143. 'Idotaccent': 333,
  28144. 'summation': 600,
  28145. 'Egrave': 611,
  28146. 'racute': 389,
  28147. 'omacron': 500,
  28148. 'Zacute': 556,
  28149. 'Zcaron': 556,
  28150. 'greaterequal': 549,
  28151. 'Eth': 722,
  28152. 'Ccedilla': 667,
  28153. 'lcommaaccent': 278,
  28154. 'tcaron': 300,
  28155. 'eogonek': 444,
  28156. 'Uogonek': 722,
  28157. 'Aacute': 611,
  28158. 'Adieresis': 611,
  28159. 'egrave': 444,
  28160. 'zacute': 389,
  28161. 'iogonek': 278,
  28162. 'Oacute': 722,
  28163. 'oacute': 500,
  28164. 'amacron': 500,
  28165. 'sacute': 389,
  28166. 'idieresis': 278,
  28167. 'Ocircumflex': 722,
  28168. 'Ugrave': 722,
  28169. 'Delta': 612,
  28170. 'thorn': 500,
  28171. 'twosuperior': 300,
  28172. 'Odieresis': 722,
  28173. 'mu': 500,
  28174. 'igrave': 278,
  28175. 'ohungarumlaut': 500,
  28176. 'Eogonek': 611,
  28177. 'dcroat': 500,
  28178. 'threequarters': 750,
  28179. 'Scedilla': 500,
  28180. 'lcaron': 300,
  28181. 'Kcommaaccent': 667,
  28182. 'Lacute': 556,
  28183. 'trademark': 980,
  28184. 'edotaccent': 444,
  28185. 'Igrave': 333,
  28186. 'Imacron': 333,
  28187. 'Lcaron': 611,
  28188. 'onehalf': 750,
  28189. 'lessequal': 549,
  28190. 'ocircumflex': 500,
  28191. 'ntilde': 500,
  28192. 'Uhungarumlaut': 722,
  28193. 'Eacute': 611,
  28194. 'emacron': 444,
  28195. 'gbreve': 500,
  28196. 'onequarter': 750,
  28197. 'Scaron': 500,
  28198. 'Scommaaccent': 500,
  28199. 'Ohungarumlaut': 722,
  28200. 'degree': 400,
  28201. 'ograve': 500,
  28202. 'Ccaron': 667,
  28203. 'ugrave': 500,
  28204. 'radical': 453,
  28205. 'Dcaron': 722,
  28206. 'rcommaaccent': 389,
  28207. 'Ntilde': 667,
  28208. 'otilde': 500,
  28209. 'Rcommaaccent': 611,
  28210. 'Lcommaaccent': 556,
  28211. 'Atilde': 611,
  28212. 'Aogonek': 611,
  28213. 'Aring': 611,
  28214. 'Otilde': 722,
  28215. 'zdotaccent': 389,
  28216. 'Ecaron': 611,
  28217. 'Iogonek': 333,
  28218. 'kcommaaccent': 444,
  28219. 'minus': 675,
  28220. 'Icircumflex': 333,
  28221. 'ncaron': 500,
  28222. 'tcommaaccent': 278,
  28223. 'logicalnot': 675,
  28224. 'odieresis': 500,
  28225. 'udieresis': 500,
  28226. 'notequal': 549,
  28227. 'gcommaaccent': 500,
  28228. 'eth': 500,
  28229. 'zcaron': 389,
  28230. 'ncommaaccent': 500,
  28231. 'onesuperior': 300,
  28232. 'imacron': 278,
  28233. 'Euro': 500
  28234. },
  28235. 'ZapfDingbats': {
  28236. 'space': 278,
  28237. 'a1': 974,
  28238. 'a2': 961,
  28239. 'a202': 974,
  28240. 'a3': 980,
  28241. 'a4': 719,
  28242. 'a5': 789,
  28243. 'a119': 790,
  28244. 'a118': 791,
  28245. 'a117': 690,
  28246. 'a11': 960,
  28247. 'a12': 939,
  28248. 'a13': 549,
  28249. 'a14': 855,
  28250. 'a15': 911,
  28251. 'a16': 933,
  28252. 'a105': 911,
  28253. 'a17': 945,
  28254. 'a18': 974,
  28255. 'a19': 755,
  28256. 'a20': 846,
  28257. 'a21': 762,
  28258. 'a22': 761,
  28259. 'a23': 571,
  28260. 'a24': 677,
  28261. 'a25': 763,
  28262. 'a26': 760,
  28263. 'a27': 759,
  28264. 'a28': 754,
  28265. 'a6': 494,
  28266. 'a7': 552,
  28267. 'a8': 537,
  28268. 'a9': 577,
  28269. 'a10': 692,
  28270. 'a29': 786,
  28271. 'a30': 788,
  28272. 'a31': 788,
  28273. 'a32': 790,
  28274. 'a33': 793,
  28275. 'a34': 794,
  28276. 'a35': 816,
  28277. 'a36': 823,
  28278. 'a37': 789,
  28279. 'a38': 841,
  28280. 'a39': 823,
  28281. 'a40': 833,
  28282. 'a41': 816,
  28283. 'a42': 831,
  28284. 'a43': 923,
  28285. 'a44': 744,
  28286. 'a45': 723,
  28287. 'a46': 749,
  28288. 'a47': 790,
  28289. 'a48': 792,
  28290. 'a49': 695,
  28291. 'a50': 776,
  28292. 'a51': 768,
  28293. 'a52': 792,
  28294. 'a53': 759,
  28295. 'a54': 707,
  28296. 'a55': 708,
  28297. 'a56': 682,
  28298. 'a57': 701,
  28299. 'a58': 826,
  28300. 'a59': 815,
  28301. 'a60': 789,
  28302. 'a61': 789,
  28303. 'a62': 707,
  28304. 'a63': 687,
  28305. 'a64': 696,
  28306. 'a65': 689,
  28307. 'a66': 786,
  28308. 'a67': 787,
  28309. 'a68': 713,
  28310. 'a69': 791,
  28311. 'a70': 785,
  28312. 'a71': 791,
  28313. 'a72': 873,
  28314. 'a73': 761,
  28315. 'a74': 762,
  28316. 'a203': 762,
  28317. 'a75': 759,
  28318. 'a204': 759,
  28319. 'a76': 892,
  28320. 'a77': 892,
  28321. 'a78': 788,
  28322. 'a79': 784,
  28323. 'a81': 438,
  28324. 'a82': 138,
  28325. 'a83': 277,
  28326. 'a84': 415,
  28327. 'a97': 392,
  28328. 'a98': 392,
  28329. 'a99': 668,
  28330. 'a100': 668,
  28331. 'a89': 390,
  28332. 'a90': 390,
  28333. 'a93': 317,
  28334. 'a94': 317,
  28335. 'a91': 276,
  28336. 'a92': 276,
  28337. 'a205': 509,
  28338. 'a85': 509,
  28339. 'a206': 410,
  28340. 'a86': 410,
  28341. 'a87': 234,
  28342. 'a88': 234,
  28343. 'a95': 334,
  28344. 'a96': 334,
  28345. 'a101': 732,
  28346. 'a102': 544,
  28347. 'a103': 544,
  28348. 'a104': 910,
  28349. 'a106': 667,
  28350. 'a107': 760,
  28351. 'a108': 760,
  28352. 'a112': 776,
  28353. 'a111': 595,
  28354. 'a110': 694,
  28355. 'a109': 626,
  28356. 'a120': 788,
  28357. 'a121': 788,
  28358. 'a122': 788,
  28359. 'a123': 788,
  28360. 'a124': 788,
  28361. 'a125': 788,
  28362. 'a126': 788,
  28363. 'a127': 788,
  28364. 'a128': 788,
  28365. 'a129': 788,
  28366. 'a130': 788,
  28367. 'a131': 788,
  28368. 'a132': 788,
  28369. 'a133': 788,
  28370. 'a134': 788,
  28371. 'a135': 788,
  28372. 'a136': 788,
  28373. 'a137': 788,
  28374. 'a138': 788,
  28375. 'a139': 788,
  28376. 'a140': 788,
  28377. 'a141': 788,
  28378. 'a142': 788,
  28379. 'a143': 788,
  28380. 'a144': 788,
  28381. 'a145': 788,
  28382. 'a146': 788,
  28383. 'a147': 788,
  28384. 'a148': 788,
  28385. 'a149': 788,
  28386. 'a150': 788,
  28387. 'a151': 788,
  28388. 'a152': 788,
  28389. 'a153': 788,
  28390. 'a154': 788,
  28391. 'a155': 788,
  28392. 'a156': 788,
  28393. 'a157': 788,
  28394. 'a158': 788,
  28395. 'a159': 788,
  28396. 'a160': 894,
  28397. 'a161': 838,
  28398. 'a163': 1016,
  28399. 'a164': 458,
  28400. 'a196': 748,
  28401. 'a165': 924,
  28402. 'a192': 748,
  28403. 'a166': 918,
  28404. 'a167': 927,
  28405. 'a168': 928,
  28406. 'a169': 928,
  28407. 'a170': 834,
  28408. 'a171': 873,
  28409. 'a172': 828,
  28410. 'a173': 924,
  28411. 'a162': 924,
  28412. 'a174': 917,
  28413. 'a175': 930,
  28414. 'a176': 931,
  28415. 'a177': 463,
  28416. 'a178': 883,
  28417. 'a179': 836,
  28418. 'a193': 836,
  28419. 'a180': 867,
  28420. 'a199': 867,
  28421. 'a181': 696,
  28422. 'a200': 696,
  28423. 'a182': 874,
  28424. 'a201': 874,
  28425. 'a183': 760,
  28426. 'a184': 946,
  28427. 'a197': 771,
  28428. 'a185': 865,
  28429. 'a194': 771,
  28430. 'a198': 888,
  28431. 'a186': 967,
  28432. 'a195': 888,
  28433. 'a187': 831,
  28434. 'a188': 873,
  28435. 'a189': 927,
  28436. 'a190': 970,
  28437. 'a191': 918
  28438. }
  28439. };
  28440. var EOF = {};
  28441. function isEOF(v) {
  28442. return (v === EOF);
  28443. }
  28444. var MAX_LENGTH_TO_CACHE = 1000;
  28445. var Parser = (function ParserClosure() {
  28446. function Parser(lexer, allowStreams, xref) {
  28447. this.lexer = lexer;
  28448. this.allowStreams = allowStreams;
  28449. this.xref = xref;
  28450. this.imageCache = {};
  28451. this.refill();
  28452. }
  28453. Parser.prototype = {
  28454. refill: function Parser_refill() {
  28455. this.buf1 = this.lexer.getObj();
  28456. this.buf2 = this.lexer.getObj();
  28457. },
  28458. shift: function Parser_shift() {
  28459. if (isCmd(this.buf2, 'ID')) {
  28460. this.buf1 = this.buf2;
  28461. this.buf2 = null;
  28462. } else {
  28463. this.buf1 = this.buf2;
  28464. this.buf2 = this.lexer.getObj();
  28465. }
  28466. },
  28467. getObj: function Parser_getObj(cipherTransform) {
  28468. var buf1 = this.buf1;
  28469. this.shift();
  28470. if (buf1 instanceof Cmd) {
  28471. switch (buf1.cmd) {
  28472. case 'BI': // inline image
  28473. return this.makeInlineImage(cipherTransform);
  28474. case '[': // array
  28475. var array = [];
  28476. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28477. array.push(this.getObj(cipherTransform));
  28478. }
  28479. if (isEOF(this.buf1)) {
  28480. error('End of file inside array');
  28481. }
  28482. this.shift();
  28483. return array;
  28484. case '<<': // dictionary or stream
  28485. var dict = new Dict(this.xref);
  28486. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28487. if (!isName(this.buf1)) {
  28488. info('Malformed dictionary: key must be a name object');
  28489. this.shift();
  28490. continue;
  28491. }
  28492. var key = this.buf1.name;
  28493. this.shift();
  28494. if (isEOF(this.buf1)) {
  28495. break;
  28496. }
  28497. dict.set(key, this.getObj(cipherTransform));
  28498. }
  28499. if (isEOF(this.buf1)) {
  28500. error('End of file inside dictionary');
  28501. }
  28502. // Stream objects are not allowed inside content streams or
  28503. // object streams.
  28504. if (isCmd(this.buf2, 'stream')) {
  28505. return (this.allowStreams ?
  28506. this.makeStream(dict, cipherTransform) : dict);
  28507. }
  28508. this.shift();
  28509. return dict;
  28510. default: // simple object
  28511. return buf1;
  28512. }
  28513. }
  28514. if (isInt(buf1)) { // indirect reference or integer
  28515. var num = buf1;
  28516. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28517. var ref = new Ref(num, this.buf1);
  28518. this.shift();
  28519. this.shift();
  28520. return ref;
  28521. }
  28522. return num;
  28523. }
  28524. if (isString(buf1)) { // string
  28525. var str = buf1;
  28526. if (cipherTransform) {
  28527. str = cipherTransform.decryptString(str);
  28528. }
  28529. return str;
  28530. }
  28531. // simple object
  28532. return buf1;
  28533. },
  28534. /**
  28535. * Find the end of the stream by searching for the /EI\s/.
  28536. * @returns {number} The inline stream length.
  28537. */
  28538. findDefaultInlineStreamEnd:
  28539. function Parser_findDefaultInlineStreamEnd(stream) {
  28540. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28541. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28542. while ((ch = stream.getByte()) !== -1) {
  28543. if (state === 0) {
  28544. state = (ch === E) ? 1 : 0;
  28545. } else if (state === 1) {
  28546. state = (ch === I) ? 2 : 0;
  28547. } else {
  28548. assert(state === 2);
  28549. if (ch === SPACE || ch === LF || ch === CR) {
  28550. // Let's check the next five bytes are ASCII... just be sure.
  28551. n = 5;
  28552. followingBytes = stream.peekBytes(n);
  28553. for (i = 0; i < n; i++) {
  28554. ch = followingBytes[i];
  28555. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28556. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28557. // it's binary stuff. Resetting the state.
  28558. state = 0;
  28559. break;
  28560. }
  28561. }
  28562. if (state === 2) {
  28563. break; // Finished!
  28564. }
  28565. } else {
  28566. state = 0;
  28567. }
  28568. }
  28569. }
  28570. return ((stream.pos - 4) - startPos);
  28571. },
  28572. /**
  28573. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28574. * @returns {number} The inline stream length.
  28575. */
  28576. findDCTDecodeInlineStreamEnd:
  28577. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28578. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28579. while ((b = stream.getByte()) !== -1) {
  28580. if (b !== 0xFF) { // Not a valid marker.
  28581. continue;
  28582. }
  28583. switch (stream.getByte()) {
  28584. case 0x00: // Byte stuffing.
  28585. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28586. break;
  28587. case 0xFF: // Fill byte.
  28588. // Avoid skipping a valid marker, resetting the stream position.
  28589. stream.skip(-1);
  28590. break;
  28591. case 0xD9: // EOI
  28592. foundEOI = true;
  28593. break;
  28594. case 0xC0: // SOF0
  28595. case 0xC1: // SOF1
  28596. case 0xC2: // SOF2
  28597. case 0xC3: // SOF3
  28598. case 0xC5: // SOF5
  28599. case 0xC6: // SOF6
  28600. case 0xC7: // SOF7
  28601. case 0xC9: // SOF9
  28602. case 0xCA: // SOF10
  28603. case 0xCB: // SOF11
  28604. case 0xCD: // SOF13
  28605. case 0xCE: // SOF14
  28606. case 0xCF: // SOF15
  28607. case 0xC4: // DHT
  28608. case 0xCC: // DAC
  28609. case 0xDA: // SOS
  28610. case 0xDB: // DQT
  28611. case 0xDC: // DNL
  28612. case 0xDD: // DRI
  28613. case 0xDE: // DHP
  28614. case 0xDF: // EXP
  28615. case 0xE0: // APP0
  28616. case 0xE1: // APP1
  28617. case 0xE2: // APP2
  28618. case 0xE3: // APP3
  28619. case 0xE4: // APP4
  28620. case 0xE5: // APP5
  28621. case 0xE6: // APP6
  28622. case 0xE7: // APP7
  28623. case 0xE8: // APP8
  28624. case 0xE9: // APP9
  28625. case 0xEA: // APP10
  28626. case 0xEB: // APP11
  28627. case 0xEC: // APP12
  28628. case 0xED: // APP13
  28629. case 0xEE: // APP14
  28630. case 0xEF: // APP15
  28631. case 0xFE: // COM
  28632. // The marker should be followed by the length of the segment.
  28633. markerLength = stream.getUint16();
  28634. if (markerLength > 2) {
  28635. // |markerLength| contains the byte length of the marker segment,
  28636. // including its own length (2 bytes) and excluding the marker.
  28637. stream.skip(markerLength - 2); // Jump to the next marker.
  28638. } else {
  28639. // The marker length is invalid, resetting the stream position.
  28640. stream.skip(-2);
  28641. }
  28642. break;
  28643. }
  28644. if (foundEOI) {
  28645. break;
  28646. }
  28647. }
  28648. length = stream.pos - startPos;
  28649. if (b === -1) {
  28650. warn('Inline DCTDecode image stream: ' +
  28651. 'EOI marker not found, searching for /EI/ instead.');
  28652. stream.skip(-length); // Reset the stream position.
  28653. return this.findDefaultInlineStreamEnd(stream);
  28654. }
  28655. this.inlineStreamSkipEI(stream);
  28656. return length;
  28657. },
  28658. /**
  28659. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28660. * @returns {number} The inline stream length.
  28661. */
  28662. findASCII85DecodeInlineStreamEnd:
  28663. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28664. var TILDE = 0x7E, GT = 0x3E;
  28665. var startPos = stream.pos, ch, length;
  28666. while ((ch = stream.getByte()) !== -1) {
  28667. if (ch === TILDE && stream.peekByte() === GT) {
  28668. stream.skip();
  28669. break;
  28670. }
  28671. }
  28672. length = stream.pos - startPos;
  28673. if (ch === -1) {
  28674. warn('Inline ASCII85Decode image stream: ' +
  28675. 'EOD marker not found, searching for /EI/ instead.');
  28676. stream.skip(-length); // Reset the stream position.
  28677. return this.findDefaultInlineStreamEnd(stream);
  28678. }
  28679. this.inlineStreamSkipEI(stream);
  28680. return length;
  28681. },
  28682. /**
  28683. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28684. * @returns {number} The inline stream length.
  28685. */
  28686. findASCIIHexDecodeInlineStreamEnd:
  28687. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28688. var GT = 0x3E;
  28689. var startPos = stream.pos, ch, length;
  28690. while ((ch = stream.getByte()) !== -1) {
  28691. if (ch === GT) {
  28692. break;
  28693. }
  28694. }
  28695. length = stream.pos - startPos;
  28696. if (ch === -1) {
  28697. warn('Inline ASCIIHexDecode image stream: ' +
  28698. 'EOD marker not found, searching for /EI/ instead.');
  28699. stream.skip(-length); // Reset the stream position.
  28700. return this.findDefaultInlineStreamEnd(stream);
  28701. }
  28702. this.inlineStreamSkipEI(stream);
  28703. return length;
  28704. },
  28705. /**
  28706. * Skip over the /EI/ for streams where we search for an EOD marker.
  28707. */
  28708. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28709. var E = 0x45, I = 0x49;
  28710. var state = 0, ch;
  28711. while ((ch = stream.getByte()) !== -1) {
  28712. if (state === 0) {
  28713. state = (ch === E) ? 1 : 0;
  28714. } else if (state === 1) {
  28715. state = (ch === I) ? 2 : 0;
  28716. } else if (state === 2) {
  28717. break;
  28718. }
  28719. }
  28720. },
  28721. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28722. var lexer = this.lexer;
  28723. var stream = lexer.stream;
  28724. // Parse dictionary.
  28725. var dict = new Dict(null);
  28726. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28727. if (!isName(this.buf1)) {
  28728. error('Dictionary key must be a name object');
  28729. }
  28730. var key = this.buf1.name;
  28731. this.shift();
  28732. if (isEOF(this.buf1)) {
  28733. break;
  28734. }
  28735. dict.set(key, this.getObj(cipherTransform));
  28736. }
  28737. // Extract the name of the first (i.e. the current) image filter.
  28738. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28739. if (isName(filter)) {
  28740. filterName = filter.name;
  28741. } else if (isArray(filter) && isName(filter[0])) {
  28742. filterName = filter[0].name;
  28743. }
  28744. // Parse image stream.
  28745. var startPos = stream.pos, length, i, ii;
  28746. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28747. length = this.findDCTDecodeInlineStreamEnd(stream);
  28748. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28749. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28750. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28751. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28752. } else {
  28753. length = this.findDefaultInlineStreamEnd(stream);
  28754. }
  28755. var imageStream = stream.makeSubStream(startPos, length, dict);
  28756. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28757. // adler32 checksum.
  28758. var adler32;
  28759. if (length < MAX_LENGTH_TO_CACHE) {
  28760. var imageBytes = imageStream.getBytes();
  28761. imageStream.reset();
  28762. var a = 1;
  28763. var b = 0;
  28764. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28765. // No modulo required in the loop if imageBytes.length < 5552.
  28766. a += imageBytes[i] & 0xff;
  28767. b += a;
  28768. }
  28769. adler32 = ((b % 65521) << 16) | (a % 65521);
  28770. if (this.imageCache.adler32 === adler32) {
  28771. this.buf2 = Cmd.get('EI');
  28772. this.shift();
  28773. this.imageCache[adler32].reset();
  28774. return this.imageCache[adler32];
  28775. }
  28776. }
  28777. if (cipherTransform) {
  28778. imageStream = cipherTransform.createStream(imageStream, length);
  28779. }
  28780. imageStream = this.filter(imageStream, dict, length);
  28781. imageStream.dict = dict;
  28782. if (adler32 !== undefined) {
  28783. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28784. this.imageCache[adler32] = imageStream;
  28785. }
  28786. this.buf2 = Cmd.get('EI');
  28787. this.shift();
  28788. return imageStream;
  28789. },
  28790. fetchIfRef: function Parser_fetchIfRef(obj) {
  28791. // not relying on the xref.fetchIfRef -- xref might not be set
  28792. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28793. },
  28794. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28795. var lexer = this.lexer;
  28796. var stream = lexer.stream;
  28797. // get stream start position
  28798. lexer.skipToNextLine();
  28799. var pos = stream.pos - 1;
  28800. // get length
  28801. var length = this.fetchIfRef(dict.get('Length'));
  28802. if (!isInt(length)) {
  28803. info('Bad ' + length + ' attribute in stream');
  28804. length = 0;
  28805. }
  28806. // skip over the stream data
  28807. stream.pos = pos + length;
  28808. lexer.nextChar();
  28809. this.shift(); // '>>'
  28810. this.shift(); // 'stream'
  28811. if (!isCmd(this.buf1, 'endstream')) {
  28812. // bad stream length, scanning for endstream
  28813. stream.pos = pos;
  28814. var SCAN_BLOCK_SIZE = 2048;
  28815. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28816. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28817. 0x61, 0x6D];
  28818. var skipped = 0, found = false, i, j;
  28819. while (stream.pos < stream.end) {
  28820. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28821. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28822. if (scanLength <= 0) {
  28823. break;
  28824. }
  28825. found = false;
  28826. for (i = 0, j = 0; i < scanLength; i++) {
  28827. var b = scanBytes[i];
  28828. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28829. i -= j;
  28830. j = 0;
  28831. } else {
  28832. j++;
  28833. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28834. i++;
  28835. found = true;
  28836. break;
  28837. }
  28838. }
  28839. }
  28840. if (found) {
  28841. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28842. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28843. break;
  28844. }
  28845. skipped += scanLength;
  28846. stream.pos += scanLength;
  28847. }
  28848. if (!found) {
  28849. error('Missing endstream');
  28850. }
  28851. length = skipped;
  28852. lexer.nextChar();
  28853. this.shift();
  28854. this.shift();
  28855. }
  28856. this.shift(); // 'endstream'
  28857. stream = stream.makeSubStream(pos, length, dict);
  28858. if (cipherTransform) {
  28859. stream = cipherTransform.createStream(stream, length);
  28860. }
  28861. stream = this.filter(stream, dict, length);
  28862. stream.dict = dict;
  28863. return stream;
  28864. },
  28865. filter: function Parser_filter(stream, dict, length) {
  28866. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28867. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28868. if (isName(filter)) {
  28869. return this.makeFilter(stream, filter.name, length, params);
  28870. }
  28871. var maybeLength = length;
  28872. if (isArray(filter)) {
  28873. var filterArray = filter;
  28874. var paramsArray = params;
  28875. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28876. filter = filterArray[i];
  28877. if (!isName(filter)) {
  28878. error('Bad filter name: ' + filter);
  28879. }
  28880. params = null;
  28881. if (isArray(paramsArray) && (i in paramsArray)) {
  28882. params = paramsArray[i];
  28883. }
  28884. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28885. // after the first stream the length variable is invalid
  28886. maybeLength = null;
  28887. }
  28888. }
  28889. return stream;
  28890. },
  28891. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28892. if (stream.dict.get('Length') === 0) {
  28893. return new NullStream(stream);
  28894. }
  28895. try {
  28896. if (params) {
  28897. params = this.fetchIfRef(params);
  28898. }
  28899. var xrefStreamStats = this.xref.stats.streamTypes;
  28900. if (name === 'FlateDecode' || name === 'Fl') {
  28901. xrefStreamStats[StreamType.FLATE] = true;
  28902. if (params) {
  28903. return new PredictorStream(new FlateStream(stream, maybeLength),
  28904. maybeLength, params);
  28905. }
  28906. return new FlateStream(stream, maybeLength);
  28907. }
  28908. if (name === 'LZWDecode' || name === 'LZW') {
  28909. xrefStreamStats[StreamType.LZW] = true;
  28910. var earlyChange = 1;
  28911. if (params) {
  28912. if (params.has('EarlyChange')) {
  28913. earlyChange = params.get('EarlyChange');
  28914. }
  28915. return new PredictorStream(
  28916. new LZWStream(stream, maybeLength, earlyChange),
  28917. maybeLength, params);
  28918. }
  28919. return new LZWStream(stream, maybeLength, earlyChange);
  28920. }
  28921. if (name === 'DCTDecode' || name === 'DCT') {
  28922. xrefStreamStats[StreamType.DCT] = true;
  28923. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28924. }
  28925. if (name === 'JPXDecode' || name === 'JPX') {
  28926. xrefStreamStats[StreamType.JPX] = true;
  28927. return new JpxStream(stream, maybeLength, stream.dict);
  28928. }
  28929. if (name === 'ASCII85Decode' || name === 'A85') {
  28930. xrefStreamStats[StreamType.A85] = true;
  28931. return new Ascii85Stream(stream, maybeLength);
  28932. }
  28933. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28934. xrefStreamStats[StreamType.AHX] = true;
  28935. return new AsciiHexStream(stream, maybeLength);
  28936. }
  28937. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28938. xrefStreamStats[StreamType.CCF] = true;
  28939. return new CCITTFaxStream(stream, maybeLength, params);
  28940. }
  28941. if (name === 'RunLengthDecode' || name === 'RL') {
  28942. xrefStreamStats[StreamType.RL] = true;
  28943. return new RunLengthStream(stream, maybeLength);
  28944. }
  28945. if (name === 'JBIG2Decode') {
  28946. xrefStreamStats[StreamType.JBIG] = true;
  28947. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28948. }
  28949. warn('filter "' + name + '" not supported yet');
  28950. return stream;
  28951. } catch (ex) {
  28952. if (ex instanceof MissingDataException) {
  28953. throw ex;
  28954. }
  28955. warn('Invalid stream: \"' + ex + '\"');
  28956. return new NullStream(stream);
  28957. }
  28958. }
  28959. };
  28960. return Parser;
  28961. })();
  28962. var Lexer = (function LexerClosure() {
  28963. function Lexer(stream, knownCommands) {
  28964. this.stream = stream;
  28965. this.nextChar();
  28966. // While lexing, we build up many strings one char at a time. Using += for
  28967. // this can result in lots of garbage strings. It's better to build an
  28968. // array of single-char strings and then join() them together at the end.
  28969. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28970. // purpose uses less memory than using a new array for each string.
  28971. this.strBuf = [];
  28972. // The PDFs might have "glued" commands with other commands, operands or
  28973. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28974. // commands and their prefixes. The prefixes are built the following way:
  28975. // if there a command that is a prefix of the other valid command or
  28976. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28977. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28978. // other commands or literals as a prefix. The knowCommands is optional.
  28979. this.knownCommands = knownCommands;
  28980. }
  28981. Lexer.isSpace = function Lexer_isSpace(ch) {
  28982. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28983. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28984. };
  28985. // A '1' in this array means the character is white space. A '1' or
  28986. // '2' means the character ends a name or command.
  28987. var specialChars = [
  28988. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28990. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  29000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  29001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  29002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  29003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  29004. ];
  29005. function toHexDigit(ch) {
  29006. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29007. return ch & 0x0F;
  29008. }
  29009. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29010. // 'A'-'F', 'a'-'f'
  29011. return (ch & 0x0F) + 9;
  29012. }
  29013. return -1;
  29014. }
  29015. Lexer.prototype = {
  29016. nextChar: function Lexer_nextChar() {
  29017. return (this.currentChar = this.stream.getByte());
  29018. },
  29019. peekChar: function Lexer_peekChar() {
  29020. return this.stream.peekByte();
  29021. },
  29022. getNumber: function Lexer_getNumber() {
  29023. var ch = this.currentChar;
  29024. var eNotation = false;
  29025. var divideBy = 0; // different from 0 if it's a floating point value
  29026. var sign = 1;
  29027. if (ch === 0x2D) { // '-'
  29028. sign = -1;
  29029. ch = this.nextChar();
  29030. } else if (ch === 0x2B) { // '+'
  29031. ch = this.nextChar();
  29032. }
  29033. if (ch === 0x2E) { // '.'
  29034. divideBy = 10;
  29035. ch = this.nextChar();
  29036. }
  29037. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29038. error('Invalid number: ' + String.fromCharCode(ch));
  29039. return 0;
  29040. }
  29041. var baseValue = ch - 0x30; // '0'
  29042. var powerValue = 0;
  29043. var powerValueSign = 1;
  29044. while ((ch = this.nextChar()) >= 0) {
  29045. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  29046. var currentDigit = ch - 0x30; // '0'
  29047. if (eNotation) { // We are after an 'e' or 'E'
  29048. powerValue = powerValue * 10 + currentDigit;
  29049. } else {
  29050. if (divideBy !== 0) { // We are after a point
  29051. divideBy *= 10;
  29052. }
  29053. baseValue = baseValue * 10 + currentDigit;
  29054. }
  29055. } else if (ch === 0x2E) { // '.'
  29056. if (divideBy === 0) {
  29057. divideBy = 1;
  29058. } else {
  29059. // A number can have only one '.'
  29060. break;
  29061. }
  29062. } else if (ch === 0x2D) { // '-'
  29063. // ignore minus signs in the middle of numbers to match
  29064. // Adobe's behavior
  29065. warn('Badly formated number');
  29066. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29067. // 'E' can be either a scientific notation or the beginning of a new
  29068. // operator
  29069. ch = this.peekChar();
  29070. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29071. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29072. this.nextChar(); // Consume the sign character
  29073. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29074. // The 'E' must be the beginning of a new operator
  29075. break;
  29076. }
  29077. eNotation = true;
  29078. } else {
  29079. // the last character doesn't belong to us
  29080. break;
  29081. }
  29082. }
  29083. if (divideBy !== 0) {
  29084. baseValue /= divideBy;
  29085. }
  29086. if (eNotation) {
  29087. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29088. }
  29089. return sign * baseValue;
  29090. },
  29091. getString: function Lexer_getString() {
  29092. var numParen = 1;
  29093. var done = false;
  29094. var strBuf = this.strBuf;
  29095. strBuf.length = 0;
  29096. var ch = this.nextChar();
  29097. while (true) {
  29098. var charBuffered = false;
  29099. switch (ch | 0) {
  29100. case -1:
  29101. warn('Unterminated string');
  29102. done = true;
  29103. break;
  29104. case 0x28: // '('
  29105. ++numParen;
  29106. strBuf.push('(');
  29107. break;
  29108. case 0x29: // ')'
  29109. if (--numParen === 0) {
  29110. this.nextChar(); // consume strings ')'
  29111. done = true;
  29112. } else {
  29113. strBuf.push(')');
  29114. }
  29115. break;
  29116. case 0x5C: // '\\'
  29117. ch = this.nextChar();
  29118. switch (ch) {
  29119. case -1:
  29120. warn('Unterminated string');
  29121. done = true;
  29122. break;
  29123. case 0x6E: // 'n'
  29124. strBuf.push('\n');
  29125. break;
  29126. case 0x72: // 'r'
  29127. strBuf.push('\r');
  29128. break;
  29129. case 0x74: // 't'
  29130. strBuf.push('\t');
  29131. break;
  29132. case 0x62: // 'b'
  29133. strBuf.push('\b');
  29134. break;
  29135. case 0x66: // 'f'
  29136. strBuf.push('\f');
  29137. break;
  29138. case 0x5C: // '\'
  29139. case 0x28: // '('
  29140. case 0x29: // ')'
  29141. strBuf.push(String.fromCharCode(ch));
  29142. break;
  29143. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29144. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29145. var x = ch & 0x0F;
  29146. ch = this.nextChar();
  29147. charBuffered = true;
  29148. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29149. x = (x << 3) + (ch & 0x0F);
  29150. ch = this.nextChar();
  29151. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29152. charBuffered = false;
  29153. x = (x << 3) + (ch & 0x0F);
  29154. }
  29155. }
  29156. strBuf.push(String.fromCharCode(x));
  29157. break;
  29158. case 0x0D: // CR
  29159. if (this.peekChar() === 0x0A) { // LF
  29160. this.nextChar();
  29161. }
  29162. break;
  29163. case 0x0A: // LF
  29164. break;
  29165. default:
  29166. strBuf.push(String.fromCharCode(ch));
  29167. break;
  29168. }
  29169. break;
  29170. default:
  29171. strBuf.push(String.fromCharCode(ch));
  29172. break;
  29173. }
  29174. if (done) {
  29175. break;
  29176. }
  29177. if (!charBuffered) {
  29178. ch = this.nextChar();
  29179. }
  29180. }
  29181. return strBuf.join('');
  29182. },
  29183. getName: function Lexer_getName() {
  29184. var ch;
  29185. var strBuf = this.strBuf;
  29186. strBuf.length = 0;
  29187. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29188. if (ch === 0x23) { // '#'
  29189. ch = this.nextChar();
  29190. var x = toHexDigit(ch);
  29191. if (x !== -1) {
  29192. var x2 = toHexDigit(this.nextChar());
  29193. if (x2 === -1) {
  29194. error('Illegal digit in hex char in name: ' + x2);
  29195. }
  29196. strBuf.push(String.fromCharCode((x << 4) | x2));
  29197. } else {
  29198. strBuf.push('#', String.fromCharCode(ch));
  29199. }
  29200. } else {
  29201. strBuf.push(String.fromCharCode(ch));
  29202. }
  29203. }
  29204. if (strBuf.length > 128) {
  29205. error('Warning: name token is longer than allowed by the spec: ' +
  29206. strBuf.length);
  29207. }
  29208. return Name.get(strBuf.join(''));
  29209. },
  29210. getHexString: function Lexer_getHexString() {
  29211. var strBuf = this.strBuf;
  29212. strBuf.length = 0;
  29213. var ch = this.currentChar;
  29214. var isFirstHex = true;
  29215. var firstDigit;
  29216. var secondDigit;
  29217. while (true) {
  29218. if (ch < 0) {
  29219. warn('Unterminated hex string');
  29220. break;
  29221. } else if (ch === 0x3E) { // '>'
  29222. this.nextChar();
  29223. break;
  29224. } else if (specialChars[ch] === 1) {
  29225. ch = this.nextChar();
  29226. continue;
  29227. } else {
  29228. if (isFirstHex) {
  29229. firstDigit = toHexDigit(ch);
  29230. if (firstDigit === -1) {
  29231. warn('Ignoring invalid character "' + ch + '" in hex string');
  29232. ch = this.nextChar();
  29233. continue;
  29234. }
  29235. } else {
  29236. secondDigit = toHexDigit(ch);
  29237. if (secondDigit === -1) {
  29238. warn('Ignoring invalid character "' + ch + '" in hex string');
  29239. ch = this.nextChar();
  29240. continue;
  29241. }
  29242. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29243. }
  29244. isFirstHex = !isFirstHex;
  29245. ch = this.nextChar();
  29246. }
  29247. }
  29248. return strBuf.join('');
  29249. },
  29250. getObj: function Lexer_getObj() {
  29251. // skip whitespace and comments
  29252. var comment = false;
  29253. var ch = this.currentChar;
  29254. while (true) {
  29255. if (ch < 0) {
  29256. return EOF;
  29257. }
  29258. if (comment) {
  29259. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29260. comment = false;
  29261. }
  29262. } else if (ch === 0x25) { // '%'
  29263. comment = true;
  29264. } else if (specialChars[ch] !== 1) {
  29265. break;
  29266. }
  29267. ch = this.nextChar();
  29268. }
  29269. // start reading token
  29270. switch (ch | 0) {
  29271. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29272. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29273. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29274. return this.getNumber();
  29275. case 0x28: // '('
  29276. return this.getString();
  29277. case 0x2F: // '/'
  29278. return this.getName();
  29279. // array punctuation
  29280. case 0x5B: // '['
  29281. this.nextChar();
  29282. return Cmd.get('[');
  29283. case 0x5D: // ']'
  29284. this.nextChar();
  29285. return Cmd.get(']');
  29286. // hex string or dict punctuation
  29287. case 0x3C: // '<'
  29288. ch = this.nextChar();
  29289. if (ch === 0x3C) {
  29290. // dict punctuation
  29291. this.nextChar();
  29292. return Cmd.get('<<');
  29293. }
  29294. return this.getHexString();
  29295. // dict punctuation
  29296. case 0x3E: // '>'
  29297. ch = this.nextChar();
  29298. if (ch === 0x3E) {
  29299. this.nextChar();
  29300. return Cmd.get('>>');
  29301. }
  29302. return Cmd.get('>');
  29303. case 0x7B: // '{'
  29304. this.nextChar();
  29305. return Cmd.get('{');
  29306. case 0x7D: // '}'
  29307. this.nextChar();
  29308. return Cmd.get('}');
  29309. case 0x29: // ')'
  29310. error('Illegal character: ' + ch);
  29311. break;
  29312. }
  29313. // command
  29314. var str = String.fromCharCode(ch);
  29315. var knownCommands = this.knownCommands;
  29316. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29317. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29318. // stop if known command is found and next character does not make
  29319. // the str a command
  29320. var possibleCommand = str + String.fromCharCode(ch);
  29321. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29322. break;
  29323. }
  29324. if (str.length === 128) {
  29325. error('Command token too long: ' + str.length);
  29326. }
  29327. str = possibleCommand;
  29328. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29329. }
  29330. if (str === 'true') {
  29331. return true;
  29332. }
  29333. if (str === 'false') {
  29334. return false;
  29335. }
  29336. if (str === 'null') {
  29337. return null;
  29338. }
  29339. return Cmd.get(str);
  29340. },
  29341. skipToNextLine: function Lexer_skipToNextLine() {
  29342. var ch = this.currentChar;
  29343. while (ch >= 0) {
  29344. if (ch === 0x0D) { // CR
  29345. ch = this.nextChar();
  29346. if (ch === 0x0A) { // LF
  29347. this.nextChar();
  29348. }
  29349. break;
  29350. } else if (ch === 0x0A) { // LF
  29351. this.nextChar();
  29352. break;
  29353. }
  29354. ch = this.nextChar();
  29355. }
  29356. }
  29357. };
  29358. return Lexer;
  29359. })();
  29360. var Linearization = {
  29361. create: function LinearizationCreate(stream) {
  29362. function getInt(name, allowZeroValue) {
  29363. var obj = linDict.get(name);
  29364. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29365. return obj;
  29366. }
  29367. throw new Error('The "' + name + '" parameter in the linearization ' +
  29368. 'dictionary is invalid.');
  29369. }
  29370. function getHints() {
  29371. var hints = linDict.get('H'), hintsLength, item;
  29372. if (isArray(hints) &&
  29373. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29374. for (var index = 0; index < hintsLength; index++) {
  29375. if (!(isInt(item = hints[index]) && item > 0)) {
  29376. throw new Error('Hint (' + index +
  29377. ') in the linearization dictionary is invalid.');
  29378. }
  29379. }
  29380. return hints;
  29381. }
  29382. throw new Error('Hint array in the linearization dictionary is invalid.');
  29383. }
  29384. var parser = new Parser(new Lexer(stream), false, null);
  29385. var obj1 = parser.getObj();
  29386. var obj2 = parser.getObj();
  29387. var obj3 = parser.getObj();
  29388. var linDict = parser.getObj();
  29389. var obj, length;
  29390. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29391. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29392. return null; // No valid linearization dictionary found.
  29393. } else if ((length = getInt('L')) !== stream.length) {
  29394. throw new Error('The "L" parameter in the linearization dictionary ' +
  29395. 'does not equal the stream length.');
  29396. }
  29397. return {
  29398. length: length,
  29399. hints: getHints(),
  29400. objectNumberFirst: getInt('O'),
  29401. endFirst: getInt('E'),
  29402. numPages: getInt('N'),
  29403. mainXRefEntriesOffset: getInt('T'),
  29404. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29405. };
  29406. }
  29407. };
  29408. var PostScriptParser = (function PostScriptParserClosure() {
  29409. function PostScriptParser(lexer) {
  29410. this.lexer = lexer;
  29411. this.operators = [];
  29412. this.token = null;
  29413. this.prev = null;
  29414. }
  29415. PostScriptParser.prototype = {
  29416. nextToken: function PostScriptParser_nextToken() {
  29417. this.prev = this.token;
  29418. this.token = this.lexer.getToken();
  29419. },
  29420. accept: function PostScriptParser_accept(type) {
  29421. if (this.token.type === type) {
  29422. this.nextToken();
  29423. return true;
  29424. }
  29425. return false;
  29426. },
  29427. expect: function PostScriptParser_expect(type) {
  29428. if (this.accept(type)) {
  29429. return true;
  29430. }
  29431. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29432. type + '.');
  29433. },
  29434. parse: function PostScriptParser_parse() {
  29435. this.nextToken();
  29436. this.expect(PostScriptTokenTypes.LBRACE);
  29437. this.parseBlock();
  29438. this.expect(PostScriptTokenTypes.RBRACE);
  29439. return this.operators;
  29440. },
  29441. parseBlock: function PostScriptParser_parseBlock() {
  29442. while (true) {
  29443. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29444. this.operators.push(this.prev.value);
  29445. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29446. this.operators.push(this.prev.value);
  29447. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29448. this.parseCondition();
  29449. } else {
  29450. return;
  29451. }
  29452. }
  29453. },
  29454. parseCondition: function PostScriptParser_parseCondition() {
  29455. // Add two place holders that will be updated later
  29456. var conditionLocation = this.operators.length;
  29457. this.operators.push(null, null);
  29458. this.parseBlock();
  29459. this.expect(PostScriptTokenTypes.RBRACE);
  29460. if (this.accept(PostScriptTokenTypes.IF)) {
  29461. // The true block is right after the 'if' so it just falls through on
  29462. // true else it jumps and skips the true block.
  29463. this.operators[conditionLocation] = this.operators.length;
  29464. this.operators[conditionLocation + 1] = 'jz';
  29465. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29466. var jumpLocation = this.operators.length;
  29467. this.operators.push(null, null);
  29468. var endOfTrue = this.operators.length;
  29469. this.parseBlock();
  29470. this.expect(PostScriptTokenTypes.RBRACE);
  29471. this.expect(PostScriptTokenTypes.IFELSE);
  29472. // The jump is added at the end of the true block to skip the false
  29473. // block.
  29474. this.operators[jumpLocation] = this.operators.length;
  29475. this.operators[jumpLocation + 1] = 'j';
  29476. this.operators[conditionLocation] = endOfTrue;
  29477. this.operators[conditionLocation + 1] = 'jz';
  29478. } else {
  29479. error('PS Function: error parsing conditional.');
  29480. }
  29481. }
  29482. };
  29483. return PostScriptParser;
  29484. })();
  29485. var PostScriptTokenTypes = {
  29486. LBRACE: 0,
  29487. RBRACE: 1,
  29488. NUMBER: 2,
  29489. OPERATOR: 3,
  29490. IF: 4,
  29491. IFELSE: 5
  29492. };
  29493. var PostScriptToken = (function PostScriptTokenClosure() {
  29494. function PostScriptToken(type, value) {
  29495. this.type = type;
  29496. this.value = value;
  29497. }
  29498. var opCache = {};
  29499. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29500. var opValue = opCache[op];
  29501. if (opValue) {
  29502. return opValue;
  29503. }
  29504. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29505. };
  29506. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29507. '{');
  29508. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29509. '}');
  29510. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29511. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29512. 'IFELSE');
  29513. return PostScriptToken;
  29514. })();
  29515. var PostScriptLexer = (function PostScriptLexerClosure() {
  29516. function PostScriptLexer(stream) {
  29517. this.stream = stream;
  29518. this.nextChar();
  29519. this.strBuf = [];
  29520. }
  29521. PostScriptLexer.prototype = {
  29522. nextChar: function PostScriptLexer_nextChar() {
  29523. return (this.currentChar = this.stream.getByte());
  29524. },
  29525. getToken: function PostScriptLexer_getToken() {
  29526. var comment = false;
  29527. var ch = this.currentChar;
  29528. // skip comments
  29529. while (true) {
  29530. if (ch < 0) {
  29531. return EOF;
  29532. }
  29533. if (comment) {
  29534. if (ch === 0x0A || ch === 0x0D) {
  29535. comment = false;
  29536. }
  29537. } else if (ch === 0x25) { // '%'
  29538. comment = true;
  29539. } else if (!Lexer.isSpace(ch)) {
  29540. break;
  29541. }
  29542. ch = this.nextChar();
  29543. }
  29544. switch (ch | 0) {
  29545. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29546. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29547. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29548. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29549. this.getNumber());
  29550. case 0x7B: // '{'
  29551. this.nextChar();
  29552. return PostScriptToken.LBRACE;
  29553. case 0x7D: // '}'
  29554. this.nextChar();
  29555. return PostScriptToken.RBRACE;
  29556. }
  29557. // operator
  29558. var strBuf = this.strBuf;
  29559. strBuf.length = 0;
  29560. strBuf[0] = String.fromCharCode(ch);
  29561. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29562. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29563. strBuf.push(String.fromCharCode(ch));
  29564. }
  29565. var str = strBuf.join('');
  29566. switch (str.toLowerCase()) {
  29567. case 'if':
  29568. return PostScriptToken.IF;
  29569. case 'ifelse':
  29570. return PostScriptToken.IFELSE;
  29571. default:
  29572. return PostScriptToken.getOperator(str);
  29573. }
  29574. },
  29575. getNumber: function PostScriptLexer_getNumber() {
  29576. var ch = this.currentChar;
  29577. var strBuf = this.strBuf;
  29578. strBuf.length = 0;
  29579. strBuf[0] = String.fromCharCode(ch);
  29580. while ((ch = this.nextChar()) >= 0) {
  29581. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29582. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29583. strBuf.push(String.fromCharCode(ch));
  29584. } else {
  29585. break;
  29586. }
  29587. }
  29588. var value = parseFloat(strBuf.join(''));
  29589. if (isNaN(value)) {
  29590. error('Invalid floating point number: ' + value);
  29591. }
  29592. return value;
  29593. }
  29594. };
  29595. return PostScriptLexer;
  29596. })();
  29597. var Stream = (function StreamClosure() {
  29598. function Stream(arrayBuffer, start, length, dict) {
  29599. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29600. arrayBuffer : new Uint8Array(arrayBuffer));
  29601. this.start = start || 0;
  29602. this.pos = this.start;
  29603. this.end = (start + length) || this.bytes.length;
  29604. this.dict = dict;
  29605. }
  29606. // required methods for a stream. if a particular stream does not
  29607. // implement these, an error should be thrown
  29608. Stream.prototype = {
  29609. get length() {
  29610. return this.end - this.start;
  29611. },
  29612. get isEmpty() {
  29613. return this.length === 0;
  29614. },
  29615. getByte: function Stream_getByte() {
  29616. if (this.pos >= this.end) {
  29617. return -1;
  29618. }
  29619. return this.bytes[this.pos++];
  29620. },
  29621. getUint16: function Stream_getUint16() {
  29622. var b0 = this.getByte();
  29623. var b1 = this.getByte();
  29624. if (b0 === -1 || b1 === -1) {
  29625. return -1;
  29626. }
  29627. return (b0 << 8) + b1;
  29628. },
  29629. getInt32: function Stream_getInt32() {
  29630. var b0 = this.getByte();
  29631. var b1 = this.getByte();
  29632. var b2 = this.getByte();
  29633. var b3 = this.getByte();
  29634. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29635. },
  29636. // returns subarray of original buffer
  29637. // should only be read
  29638. getBytes: function Stream_getBytes(length) {
  29639. var bytes = this.bytes;
  29640. var pos = this.pos;
  29641. var strEnd = this.end;
  29642. if (!length) {
  29643. return bytes.subarray(pos, strEnd);
  29644. }
  29645. var end = pos + length;
  29646. if (end > strEnd) {
  29647. end = strEnd;
  29648. }
  29649. this.pos = end;
  29650. return bytes.subarray(pos, end);
  29651. },
  29652. peekByte: function Stream_peekByte() {
  29653. var peekedByte = this.getByte();
  29654. this.pos--;
  29655. return peekedByte;
  29656. },
  29657. peekBytes: function Stream_peekBytes(length) {
  29658. var bytes = this.getBytes(length);
  29659. this.pos -= bytes.length;
  29660. return bytes;
  29661. },
  29662. skip: function Stream_skip(n) {
  29663. if (!n) {
  29664. n = 1;
  29665. }
  29666. this.pos += n;
  29667. },
  29668. reset: function Stream_reset() {
  29669. this.pos = this.start;
  29670. },
  29671. moveStart: function Stream_moveStart() {
  29672. this.start = this.pos;
  29673. },
  29674. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29675. return new Stream(this.bytes.buffer, start, length, dict);
  29676. },
  29677. isStream: true
  29678. };
  29679. return Stream;
  29680. })();
  29681. var StringStream = (function StringStreamClosure() {
  29682. function StringStream(str) {
  29683. var length = str.length;
  29684. var bytes = new Uint8Array(length);
  29685. for (var n = 0; n < length; ++n) {
  29686. bytes[n] = str.charCodeAt(n);
  29687. }
  29688. Stream.call(this, bytes);
  29689. }
  29690. StringStream.prototype = Stream.prototype;
  29691. return StringStream;
  29692. })();
  29693. // super class for the decoding streams
  29694. var DecodeStream = (function DecodeStreamClosure() {
  29695. // Lots of DecodeStreams are created whose buffers are never used. For these
  29696. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29697. // having special cases that would be required if we used |null| for an empty
  29698. // buffer.
  29699. var emptyBuffer = new Uint8Array(0);
  29700. function DecodeStream(maybeMinBufferLength) {
  29701. this.pos = 0;
  29702. this.bufferLength = 0;
  29703. this.eof = false;
  29704. this.buffer = emptyBuffer;
  29705. this.minBufferLength = 512;
  29706. if (maybeMinBufferLength) {
  29707. // Compute the first power of two that is as big as maybeMinBufferLength.
  29708. while (this.minBufferLength < maybeMinBufferLength) {
  29709. this.minBufferLength *= 2;
  29710. }
  29711. }
  29712. }
  29713. DecodeStream.prototype = {
  29714. get isEmpty() {
  29715. while (!this.eof && this.bufferLength === 0) {
  29716. this.readBlock();
  29717. }
  29718. return this.bufferLength === 0;
  29719. },
  29720. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29721. var buffer = this.buffer;
  29722. if (requested <= buffer.byteLength) {
  29723. return buffer;
  29724. }
  29725. var size = this.minBufferLength;
  29726. while (size < requested) {
  29727. size *= 2;
  29728. }
  29729. var buffer2 = new Uint8Array(size);
  29730. buffer2.set(buffer);
  29731. return (this.buffer = buffer2);
  29732. },
  29733. getByte: function DecodeStream_getByte() {
  29734. var pos = this.pos;
  29735. while (this.bufferLength <= pos) {
  29736. if (this.eof) {
  29737. return -1;
  29738. }
  29739. this.readBlock();
  29740. }
  29741. return this.buffer[this.pos++];
  29742. },
  29743. getUint16: function DecodeStream_getUint16() {
  29744. var b0 = this.getByte();
  29745. var b1 = this.getByte();
  29746. if (b0 === -1 || b1 === -1) {
  29747. return -1;
  29748. }
  29749. return (b0 << 8) + b1;
  29750. },
  29751. getInt32: function DecodeStream_getInt32() {
  29752. var b0 = this.getByte();
  29753. var b1 = this.getByte();
  29754. var b2 = this.getByte();
  29755. var b3 = this.getByte();
  29756. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29757. },
  29758. getBytes: function DecodeStream_getBytes(length) {
  29759. var end, pos = this.pos;
  29760. if (length) {
  29761. this.ensureBuffer(pos + length);
  29762. end = pos + length;
  29763. while (!this.eof && this.bufferLength < end) {
  29764. this.readBlock();
  29765. }
  29766. var bufEnd = this.bufferLength;
  29767. if (end > bufEnd) {
  29768. end = bufEnd;
  29769. }
  29770. } else {
  29771. while (!this.eof) {
  29772. this.readBlock();
  29773. }
  29774. end = this.bufferLength;
  29775. }
  29776. this.pos = end;
  29777. return this.buffer.subarray(pos, end);
  29778. },
  29779. peekByte: function DecodeStream_peekByte() {
  29780. var peekedByte = this.getByte();
  29781. this.pos--;
  29782. return peekedByte;
  29783. },
  29784. peekBytes: function DecodeStream_peekBytes(length) {
  29785. var bytes = this.getBytes(length);
  29786. this.pos -= bytes.length;
  29787. return bytes;
  29788. },
  29789. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29790. var end = start + length;
  29791. while (this.bufferLength <= end && !this.eof) {
  29792. this.readBlock();
  29793. }
  29794. return new Stream(this.buffer, start, length, dict);
  29795. },
  29796. skip: function DecodeStream_skip(n) {
  29797. if (!n) {
  29798. n = 1;
  29799. }
  29800. this.pos += n;
  29801. },
  29802. reset: function DecodeStream_reset() {
  29803. this.pos = 0;
  29804. },
  29805. getBaseStreams: function DecodeStream_getBaseStreams() {
  29806. if (this.str && this.str.getBaseStreams) {
  29807. return this.str.getBaseStreams();
  29808. }
  29809. return [];
  29810. }
  29811. };
  29812. return DecodeStream;
  29813. })();
  29814. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29815. function StreamsSequenceStream(streams) {
  29816. this.streams = streams;
  29817. DecodeStream.call(this, /* maybeLength = */ null);
  29818. }
  29819. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29820. StreamsSequenceStream.prototype.readBlock =
  29821. function streamSequenceStreamReadBlock() {
  29822. var streams = this.streams;
  29823. if (streams.length === 0) {
  29824. this.eof = true;
  29825. return;
  29826. }
  29827. var stream = streams.shift();
  29828. var chunk = stream.getBytes();
  29829. var bufferLength = this.bufferLength;
  29830. var newLength = bufferLength + chunk.length;
  29831. var buffer = this.ensureBuffer(newLength);
  29832. buffer.set(chunk, bufferLength);
  29833. this.bufferLength = newLength;
  29834. };
  29835. StreamsSequenceStream.prototype.getBaseStreams =
  29836. function StreamsSequenceStream_getBaseStreams() {
  29837. var baseStreams = [];
  29838. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29839. var stream = this.streams[i];
  29840. if (stream.getBaseStreams) {
  29841. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29842. }
  29843. }
  29844. return baseStreams;
  29845. };
  29846. return StreamsSequenceStream;
  29847. })();
  29848. var FlateStream = (function FlateStreamClosure() {
  29849. var codeLenCodeMap = new Int32Array([
  29850. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29851. ]);
  29852. var lengthDecode = new Int32Array([
  29853. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29854. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29855. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29856. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29857. ]);
  29858. var distDecode = new Int32Array([
  29859. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29860. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29861. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29862. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29863. ]);
  29864. var fixedLitCodeTab = [new Int32Array([
  29865. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29866. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29867. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29868. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29869. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29870. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29871. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29872. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29873. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29874. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29875. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29876. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29877. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29878. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29879. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29880. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29881. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29882. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29883. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29884. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29885. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29886. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29887. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29888. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29889. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29890. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29891. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29892. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29893. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29894. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29895. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29896. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29897. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29898. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29899. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29900. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29901. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29902. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29903. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29904. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29905. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29906. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29907. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29908. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29909. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29910. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29911. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29912. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29913. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29914. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29915. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29916. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29917. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29918. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29919. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29920. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29921. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29922. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29923. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29924. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29925. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29926. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29927. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29928. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29929. ]), 9];
  29930. var fixedDistCodeTab = [new Int32Array([
  29931. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29932. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29933. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29934. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29935. ]), 5];
  29936. function FlateStream(str, maybeLength) {
  29937. this.str = str;
  29938. this.dict = str.dict;
  29939. var cmf = str.getByte();
  29940. var flg = str.getByte();
  29941. if (cmf === -1 || flg === -1) {
  29942. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29943. }
  29944. if ((cmf & 0x0f) !== 0x08) {
  29945. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29946. }
  29947. if ((((cmf << 8) + flg) % 31) !== 0) {
  29948. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29949. }
  29950. if (flg & 0x20) {
  29951. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29952. }
  29953. this.codeSize = 0;
  29954. this.codeBuf = 0;
  29955. DecodeStream.call(this, maybeLength);
  29956. }
  29957. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29958. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29959. var str = this.str;
  29960. var codeSize = this.codeSize;
  29961. var codeBuf = this.codeBuf;
  29962. var b;
  29963. while (codeSize < bits) {
  29964. if ((b = str.getByte()) === -1) {
  29965. error('Bad encoding in flate stream');
  29966. }
  29967. codeBuf |= b << codeSize;
  29968. codeSize += 8;
  29969. }
  29970. b = codeBuf & ((1 << bits) - 1);
  29971. this.codeBuf = codeBuf >> bits;
  29972. this.codeSize = codeSize -= bits;
  29973. return b;
  29974. };
  29975. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29976. var str = this.str;
  29977. var codes = table[0];
  29978. var maxLen = table[1];
  29979. var codeSize = this.codeSize;
  29980. var codeBuf = this.codeBuf;
  29981. var b;
  29982. while (codeSize < maxLen) {
  29983. if ((b = str.getByte()) === -1) {
  29984. // premature end of stream. code might however still be valid.
  29985. // codeSize < codeLen check below guards against incomplete codeVal.
  29986. break;
  29987. }
  29988. codeBuf |= (b << codeSize);
  29989. codeSize += 8;
  29990. }
  29991. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29992. var codeLen = code >> 16;
  29993. var codeVal = code & 0xffff;
  29994. if (codeLen < 1 || codeSize < codeLen) {
  29995. error('Bad encoding in flate stream');
  29996. }
  29997. this.codeBuf = (codeBuf >> codeLen);
  29998. this.codeSize = (codeSize - codeLen);
  29999. return codeVal;
  30000. };
  30001. FlateStream.prototype.generateHuffmanTable =
  30002. function flateStreamGenerateHuffmanTable(lengths) {
  30003. var n = lengths.length;
  30004. // find max code length
  30005. var maxLen = 0;
  30006. var i;
  30007. for (i = 0; i < n; ++i) {
  30008. if (lengths[i] > maxLen) {
  30009. maxLen = lengths[i];
  30010. }
  30011. }
  30012. // build the table
  30013. var size = 1 << maxLen;
  30014. var codes = new Int32Array(size);
  30015. for (var len = 1, code = 0, skip = 2;
  30016. len <= maxLen;
  30017. ++len, code <<= 1, skip <<= 1) {
  30018. for (var val = 0; val < n; ++val) {
  30019. if (lengths[val] === len) {
  30020. // bit-reverse the code
  30021. var code2 = 0;
  30022. var t = code;
  30023. for (i = 0; i < len; ++i) {
  30024. code2 = (code2 << 1) | (t & 1);
  30025. t >>= 1;
  30026. }
  30027. // fill the table entries
  30028. for (i = code2; i < size; i += skip) {
  30029. codes[i] = (len << 16) | val;
  30030. }
  30031. ++code;
  30032. }
  30033. }
  30034. }
  30035. return [codes, maxLen];
  30036. };
  30037. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  30038. var buffer, len;
  30039. var str = this.str;
  30040. // read block header
  30041. var hdr = this.getBits(3);
  30042. if (hdr & 1) {
  30043. this.eof = true;
  30044. }
  30045. hdr >>= 1;
  30046. if (hdr === 0) { // uncompressed block
  30047. var b;
  30048. if ((b = str.getByte()) === -1) {
  30049. error('Bad block header in flate stream');
  30050. }
  30051. var blockLen = b;
  30052. if ((b = str.getByte()) === -1) {
  30053. error('Bad block header in flate stream');
  30054. }
  30055. blockLen |= (b << 8);
  30056. if ((b = str.getByte()) === -1) {
  30057. error('Bad block header in flate stream');
  30058. }
  30059. var check = b;
  30060. if ((b = str.getByte()) === -1) {
  30061. error('Bad block header in flate stream');
  30062. }
  30063. check |= (b << 8);
  30064. if (check !== (~blockLen & 0xffff) &&
  30065. (blockLen !== 0 || check !== 0)) {
  30066. // Ignoring error for bad "empty" block (see issue 1277)
  30067. error('Bad uncompressed block length in flate stream');
  30068. }
  30069. this.codeBuf = 0;
  30070. this.codeSize = 0;
  30071. var bufferLength = this.bufferLength;
  30072. buffer = this.ensureBuffer(bufferLength + blockLen);
  30073. var end = bufferLength + blockLen;
  30074. this.bufferLength = end;
  30075. if (blockLen === 0) {
  30076. if (str.peekByte() === -1) {
  30077. this.eof = true;
  30078. }
  30079. } else {
  30080. for (var n = bufferLength; n < end; ++n) {
  30081. if ((b = str.getByte()) === -1) {
  30082. this.eof = true;
  30083. break;
  30084. }
  30085. buffer[n] = b;
  30086. }
  30087. }
  30088. return;
  30089. }
  30090. var litCodeTable;
  30091. var distCodeTable;
  30092. if (hdr === 1) { // compressed block, fixed codes
  30093. litCodeTable = fixedLitCodeTab;
  30094. distCodeTable = fixedDistCodeTab;
  30095. } else if (hdr === 2) { // compressed block, dynamic codes
  30096. var numLitCodes = this.getBits(5) + 257;
  30097. var numDistCodes = this.getBits(5) + 1;
  30098. var numCodeLenCodes = this.getBits(4) + 4;
  30099. // build the code lengths code table
  30100. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30101. var i;
  30102. for (i = 0; i < numCodeLenCodes; ++i) {
  30103. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30104. }
  30105. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30106. // build the literal and distance code tables
  30107. len = 0;
  30108. i = 0;
  30109. var codes = numLitCodes + numDistCodes;
  30110. var codeLengths = new Uint8Array(codes);
  30111. var bitsLength, bitsOffset, what;
  30112. while (i < codes) {
  30113. var code = this.getCode(codeLenCodeTab);
  30114. if (code === 16) {
  30115. bitsLength = 2; bitsOffset = 3; what = len;
  30116. } else if (code === 17) {
  30117. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30118. } else if (code === 18) {
  30119. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30120. } else {
  30121. codeLengths[i++] = len = code;
  30122. continue;
  30123. }
  30124. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30125. while (repeatLength-- > 0) {
  30126. codeLengths[i++] = what;
  30127. }
  30128. }
  30129. litCodeTable =
  30130. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30131. distCodeTable =
  30132. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30133. } else {
  30134. error('Unknown block type in flate stream');
  30135. }
  30136. buffer = this.buffer;
  30137. var limit = buffer ? buffer.length : 0;
  30138. var pos = this.bufferLength;
  30139. while (true) {
  30140. var code1 = this.getCode(litCodeTable);
  30141. if (code1 < 256) {
  30142. if (pos + 1 >= limit) {
  30143. buffer = this.ensureBuffer(pos + 1);
  30144. limit = buffer.length;
  30145. }
  30146. buffer[pos++] = code1;
  30147. continue;
  30148. }
  30149. if (code1 === 256) {
  30150. this.bufferLength = pos;
  30151. return;
  30152. }
  30153. code1 -= 257;
  30154. code1 = lengthDecode[code1];
  30155. var code2 = code1 >> 16;
  30156. if (code2 > 0) {
  30157. code2 = this.getBits(code2);
  30158. }
  30159. len = (code1 & 0xffff) + code2;
  30160. code1 = this.getCode(distCodeTable);
  30161. code1 = distDecode[code1];
  30162. code2 = code1 >> 16;
  30163. if (code2 > 0) {
  30164. code2 = this.getBits(code2);
  30165. }
  30166. var dist = (code1 & 0xffff) + code2;
  30167. if (pos + len >= limit) {
  30168. buffer = this.ensureBuffer(pos + len);
  30169. limit = buffer.length;
  30170. }
  30171. for (var k = 0; k < len; ++k, ++pos) {
  30172. buffer[pos] = buffer[pos - dist];
  30173. }
  30174. }
  30175. };
  30176. return FlateStream;
  30177. })();
  30178. var PredictorStream = (function PredictorStreamClosure() {
  30179. function PredictorStream(str, maybeLength, params) {
  30180. var predictor = this.predictor = params.get('Predictor') || 1;
  30181. if (predictor <= 1) {
  30182. return str; // no prediction
  30183. }
  30184. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30185. error('Unsupported predictor: ' + predictor);
  30186. }
  30187. if (predictor === 2) {
  30188. this.readBlock = this.readBlockTiff;
  30189. } else {
  30190. this.readBlock = this.readBlockPng;
  30191. }
  30192. this.str = str;
  30193. this.dict = str.dict;
  30194. var colors = this.colors = params.get('Colors') || 1;
  30195. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30196. var columns = this.columns = params.get('Columns') || 1;
  30197. this.pixBytes = (colors * bits + 7) >> 3;
  30198. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30199. DecodeStream.call(this, maybeLength);
  30200. return this;
  30201. }
  30202. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30203. PredictorStream.prototype.readBlockTiff =
  30204. function predictorStreamReadBlockTiff() {
  30205. var rowBytes = this.rowBytes;
  30206. var bufferLength = this.bufferLength;
  30207. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30208. var bits = this.bits;
  30209. var colors = this.colors;
  30210. var rawBytes = this.str.getBytes(rowBytes);
  30211. this.eof = !rawBytes.length;
  30212. if (this.eof) {
  30213. return;
  30214. }
  30215. var inbuf = 0, outbuf = 0;
  30216. var inbits = 0, outbits = 0;
  30217. var pos = bufferLength;
  30218. var i;
  30219. if (bits === 1) {
  30220. for (i = 0; i < rowBytes; ++i) {
  30221. var c = rawBytes[i];
  30222. inbuf = (inbuf << 8) | c;
  30223. // bitwise addition is exclusive or
  30224. // first shift inbuf and then add
  30225. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30226. // truncate inbuf (assumes colors < 16)
  30227. inbuf &= 0xFFFF;
  30228. }
  30229. } else if (bits === 8) {
  30230. for (i = 0; i < colors; ++i) {
  30231. buffer[pos++] = rawBytes[i];
  30232. }
  30233. for (; i < rowBytes; ++i) {
  30234. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30235. pos++;
  30236. }
  30237. } else {
  30238. var compArray = new Uint8Array(colors + 1);
  30239. var bitMask = (1 << bits) - 1;
  30240. var j = 0, k = bufferLength;
  30241. var columns = this.columns;
  30242. for (i = 0; i < columns; ++i) {
  30243. for (var kk = 0; kk < colors; ++kk) {
  30244. if (inbits < bits) {
  30245. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30246. inbits += 8;
  30247. }
  30248. compArray[kk] = (compArray[kk] +
  30249. (inbuf >> (inbits - bits))) & bitMask;
  30250. inbits -= bits;
  30251. outbuf = (outbuf << bits) | compArray[kk];
  30252. outbits += bits;
  30253. if (outbits >= 8) {
  30254. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30255. outbits -= 8;
  30256. }
  30257. }
  30258. }
  30259. if (outbits > 0) {
  30260. buffer[k++] = (outbuf << (8 - outbits)) +
  30261. (inbuf & ((1 << (8 - outbits)) - 1));
  30262. }
  30263. }
  30264. this.bufferLength += rowBytes;
  30265. };
  30266. PredictorStream.prototype.readBlockPng =
  30267. function predictorStreamReadBlockPng() {
  30268. var rowBytes = this.rowBytes;
  30269. var pixBytes = this.pixBytes;
  30270. var predictor = this.str.getByte();
  30271. var rawBytes = this.str.getBytes(rowBytes);
  30272. this.eof = !rawBytes.length;
  30273. if (this.eof) {
  30274. return;
  30275. }
  30276. var bufferLength = this.bufferLength;
  30277. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30278. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30279. if (prevRow.length === 0) {
  30280. prevRow = new Uint8Array(rowBytes);
  30281. }
  30282. var i, j = bufferLength, up, c;
  30283. switch (predictor) {
  30284. case 0:
  30285. for (i = 0; i < rowBytes; ++i) {
  30286. buffer[j++] = rawBytes[i];
  30287. }
  30288. break;
  30289. case 1:
  30290. for (i = 0; i < pixBytes; ++i) {
  30291. buffer[j++] = rawBytes[i];
  30292. }
  30293. for (; i < rowBytes; ++i) {
  30294. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30295. j++;
  30296. }
  30297. break;
  30298. case 2:
  30299. for (i = 0; i < rowBytes; ++i) {
  30300. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30301. }
  30302. break;
  30303. case 3:
  30304. for (i = 0; i < pixBytes; ++i) {
  30305. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30306. }
  30307. for (; i < rowBytes; ++i) {
  30308. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30309. rawBytes[i]) & 0xFF;
  30310. j++;
  30311. }
  30312. break;
  30313. case 4:
  30314. // we need to save the up left pixels values. the simplest way
  30315. // is to create a new buffer
  30316. for (i = 0; i < pixBytes; ++i) {
  30317. up = prevRow[i];
  30318. c = rawBytes[i];
  30319. buffer[j++] = up + c;
  30320. }
  30321. for (; i < rowBytes; ++i) {
  30322. up = prevRow[i];
  30323. var upLeft = prevRow[i - pixBytes];
  30324. var left = buffer[j - pixBytes];
  30325. var p = left + up - upLeft;
  30326. var pa = p - left;
  30327. if (pa < 0) {
  30328. pa = -pa;
  30329. }
  30330. var pb = p - up;
  30331. if (pb < 0) {
  30332. pb = -pb;
  30333. }
  30334. var pc = p - upLeft;
  30335. if (pc < 0) {
  30336. pc = -pc;
  30337. }
  30338. c = rawBytes[i];
  30339. if (pa <= pb && pa <= pc) {
  30340. buffer[j++] = left + c;
  30341. } else if (pb <= pc) {
  30342. buffer[j++] = up + c;
  30343. } else {
  30344. buffer[j++] = upLeft + c;
  30345. }
  30346. }
  30347. break;
  30348. default:
  30349. error('Unsupported predictor: ' + predictor);
  30350. }
  30351. this.bufferLength += rowBytes;
  30352. };
  30353. return PredictorStream;
  30354. })();
  30355. /**
  30356. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30357. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30358. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30359. * a library to decode these images and the stream behaves like all the other
  30360. * DecodeStreams.
  30361. */
  30362. var JpegStream = (function JpegStreamClosure() {
  30363. function JpegStream(stream, maybeLength, dict, xref) {
  30364. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30365. // Note: this seems to mainly affect inline images.
  30366. var ch;
  30367. while ((ch = stream.getByte()) !== -1) {
  30368. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30369. stream.skip(-1); // Reset the stream position to the SOI.
  30370. break;
  30371. }
  30372. }
  30373. this.stream = stream;
  30374. this.maybeLength = maybeLength;
  30375. this.dict = dict;
  30376. DecodeStream.call(this, maybeLength);
  30377. }
  30378. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30379. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30380. get: function JpegStream_bytes() {
  30381. // If this.maybeLength is null, we'll get the entire stream.
  30382. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30383. },
  30384. configurable: true
  30385. });
  30386. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30387. if (this.bufferLength) {
  30388. return;
  30389. }
  30390. try {
  30391. var jpegImage = new JpegImage();
  30392. // checking if values needs to be transformed before conversion
  30393. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30394. var decodeArr = this.dict.get('Decode');
  30395. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30396. var decodeArrLength = decodeArr.length;
  30397. var transform = new Int32Array(decodeArrLength);
  30398. var transformNeeded = false;
  30399. var maxValue = (1 << bitsPerComponent) - 1;
  30400. for (var i = 0; i < decodeArrLength; i += 2) {
  30401. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30402. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30403. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30404. transformNeeded = true;
  30405. }
  30406. }
  30407. if (transformNeeded) {
  30408. jpegImage.decodeTransform = transform;
  30409. }
  30410. }
  30411. jpegImage.parse(this.bytes);
  30412. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30413. this.forceRGB);
  30414. this.buffer = data;
  30415. this.bufferLength = data.length;
  30416. this.eof = true;
  30417. } catch (e) {
  30418. error('JPEG error: ' + e);
  30419. }
  30420. };
  30421. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30422. this.ensureBuffer();
  30423. return this.buffer;
  30424. };
  30425. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30426. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30427. };
  30428. /**
  30429. * Checks if the image can be decoded and displayed by the browser without any
  30430. * further processing such as color space conversions.
  30431. */
  30432. JpegStream.prototype.isNativelySupported =
  30433. function JpegStream_isNativelySupported(xref, res) {
  30434. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30435. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30436. };
  30437. /**
  30438. * Checks if the image can be decoded by the browser.
  30439. */
  30440. JpegStream.prototype.isNativelyDecodable =
  30441. function JpegStream_isNativelyDecodable(xref, res) {
  30442. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30443. var numComps = cs.numComps;
  30444. return numComps === 1 || numComps === 3;
  30445. };
  30446. return JpegStream;
  30447. })();
  30448. /**
  30449. * For JPEG 2000's we use a library to decode these images and
  30450. * the stream behaves like all the other DecodeStreams.
  30451. */
  30452. var JpxStream = (function JpxStreamClosure() {
  30453. function JpxStream(stream, maybeLength, dict) {
  30454. this.stream = stream;
  30455. this.maybeLength = maybeLength;
  30456. this.dict = dict;
  30457. DecodeStream.call(this, maybeLength);
  30458. }
  30459. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30460. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30461. get: function JpxStream_bytes() {
  30462. // If this.maybeLength is null, we'll get the entire stream.
  30463. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30464. },
  30465. configurable: true
  30466. });
  30467. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30468. if (this.bufferLength) {
  30469. return;
  30470. }
  30471. var jpxImage = new JpxImage();
  30472. jpxImage.parse(this.bytes);
  30473. var width = jpxImage.width;
  30474. var height = jpxImage.height;
  30475. var componentsCount = jpxImage.componentsCount;
  30476. var tileCount = jpxImage.tiles.length;
  30477. if (tileCount === 1) {
  30478. this.buffer = jpxImage.tiles[0].items;
  30479. } else {
  30480. var data = new Uint8Array(width * height * componentsCount);
  30481. for (var k = 0; k < tileCount; k++) {
  30482. var tileComponents = jpxImage.tiles[k];
  30483. var tileWidth = tileComponents.width;
  30484. var tileHeight = tileComponents.height;
  30485. var tileLeft = tileComponents.left;
  30486. var tileTop = tileComponents.top;
  30487. var src = tileComponents.items;
  30488. var srcPosition = 0;
  30489. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30490. var imgRowSize = width * componentsCount;
  30491. var tileRowSize = tileWidth * componentsCount;
  30492. for (var j = 0; j < tileHeight; j++) {
  30493. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30494. data.set(rowBytes, dataPosition);
  30495. srcPosition += tileRowSize;
  30496. dataPosition += imgRowSize;
  30497. }
  30498. }
  30499. this.buffer = data;
  30500. }
  30501. this.bufferLength = this.buffer.length;
  30502. this.eof = true;
  30503. };
  30504. return JpxStream;
  30505. })();
  30506. /**
  30507. * For JBIG2's we use a library to decode these images and
  30508. * the stream behaves like all the other DecodeStreams.
  30509. */
  30510. var Jbig2Stream = (function Jbig2StreamClosure() {
  30511. function Jbig2Stream(stream, maybeLength, dict) {
  30512. this.stream = stream;
  30513. this.maybeLength = maybeLength;
  30514. this.dict = dict;
  30515. DecodeStream.call(this, maybeLength);
  30516. }
  30517. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30518. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30519. get: function Jbig2Stream_bytes() {
  30520. // If this.maybeLength is null, we'll get the entire stream.
  30521. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30522. },
  30523. configurable: true
  30524. });
  30525. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30526. if (this.bufferLength) {
  30527. return;
  30528. }
  30529. var jbig2Image = new Jbig2Image();
  30530. var chunks = [], xref = this.dict.xref;
  30531. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30532. // According to the PDF specification, DecodeParms can be either
  30533. // a dictionary, or an array whose elements are dictionaries.
  30534. if (isArray(decodeParams)) {
  30535. if (decodeParams.length > 1) {
  30536. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30537. 'not supported.');
  30538. }
  30539. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30540. }
  30541. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30542. var globalsStream = decodeParams.get('JBIG2Globals');
  30543. var globals = globalsStream.getBytes();
  30544. chunks.push({data: globals, start: 0, end: globals.length});
  30545. }
  30546. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30547. var data = jbig2Image.parseChunks(chunks);
  30548. var dataLength = data.length;
  30549. // JBIG2 had black as 1 and white as 0, inverting the colors
  30550. for (var i = 0; i < dataLength; i++) {
  30551. data[i] ^= 0xFF;
  30552. }
  30553. this.buffer = data;
  30554. this.bufferLength = dataLength;
  30555. this.eof = true;
  30556. };
  30557. return Jbig2Stream;
  30558. })();
  30559. var DecryptStream = (function DecryptStreamClosure() {
  30560. function DecryptStream(str, maybeLength, decrypt) {
  30561. this.str = str;
  30562. this.dict = str.dict;
  30563. this.decrypt = decrypt;
  30564. this.nextChunk = null;
  30565. this.initialized = false;
  30566. DecodeStream.call(this, maybeLength);
  30567. }
  30568. var chunkSize = 512;
  30569. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30570. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30571. var chunk;
  30572. if (this.initialized) {
  30573. chunk = this.nextChunk;
  30574. } else {
  30575. chunk = this.str.getBytes(chunkSize);
  30576. this.initialized = true;
  30577. }
  30578. if (!chunk || chunk.length === 0) {
  30579. this.eof = true;
  30580. return;
  30581. }
  30582. this.nextChunk = this.str.getBytes(chunkSize);
  30583. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30584. var decrypt = this.decrypt;
  30585. chunk = decrypt(chunk, !hasMoreData);
  30586. var bufferLength = this.bufferLength;
  30587. var i, n = chunk.length;
  30588. var buffer = this.ensureBuffer(bufferLength + n);
  30589. for (i = 0; i < n; i++) {
  30590. buffer[bufferLength++] = chunk[i];
  30591. }
  30592. this.bufferLength = bufferLength;
  30593. };
  30594. return DecryptStream;
  30595. })();
  30596. var Ascii85Stream = (function Ascii85StreamClosure() {
  30597. function Ascii85Stream(str, maybeLength) {
  30598. this.str = str;
  30599. this.dict = str.dict;
  30600. this.input = new Uint8Array(5);
  30601. // Most streams increase in size when decoded, but Ascii85 streams
  30602. // typically shrink by ~20%.
  30603. if (maybeLength) {
  30604. maybeLength = 0.8 * maybeLength;
  30605. }
  30606. DecodeStream.call(this, maybeLength);
  30607. }
  30608. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30609. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30610. var TILDA_CHAR = 0x7E; // '~'
  30611. var Z_LOWER_CHAR = 0x7A; // 'z'
  30612. var EOF = -1;
  30613. var str = this.str;
  30614. var c = str.getByte();
  30615. while (Lexer.isSpace(c)) {
  30616. c = str.getByte();
  30617. }
  30618. if (c === EOF || c === TILDA_CHAR) {
  30619. this.eof = true;
  30620. return;
  30621. }
  30622. var bufferLength = this.bufferLength, buffer;
  30623. var i;
  30624. // special code for z
  30625. if (c === Z_LOWER_CHAR) {
  30626. buffer = this.ensureBuffer(bufferLength + 4);
  30627. for (i = 0; i < 4; ++i) {
  30628. buffer[bufferLength + i] = 0;
  30629. }
  30630. this.bufferLength += 4;
  30631. } else {
  30632. var input = this.input;
  30633. input[0] = c;
  30634. for (i = 1; i < 5; ++i) {
  30635. c = str.getByte();
  30636. while (Lexer.isSpace(c)) {
  30637. c = str.getByte();
  30638. }
  30639. input[i] = c;
  30640. if (c === EOF || c === TILDA_CHAR) {
  30641. break;
  30642. }
  30643. }
  30644. buffer = this.ensureBuffer(bufferLength + i - 1);
  30645. this.bufferLength += i - 1;
  30646. // partial ending;
  30647. if (i < 5) {
  30648. for (; i < 5; ++i) {
  30649. input[i] = 0x21 + 84;
  30650. }
  30651. this.eof = true;
  30652. }
  30653. var t = 0;
  30654. for (i = 0; i < 5; ++i) {
  30655. t = t * 85 + (input[i] - 0x21);
  30656. }
  30657. for (i = 3; i >= 0; --i) {
  30658. buffer[bufferLength + i] = t & 0xFF;
  30659. t >>= 8;
  30660. }
  30661. }
  30662. };
  30663. return Ascii85Stream;
  30664. })();
  30665. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30666. function AsciiHexStream(str, maybeLength) {
  30667. this.str = str;
  30668. this.dict = str.dict;
  30669. this.firstDigit = -1;
  30670. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30671. // by 50%.
  30672. if (maybeLength) {
  30673. maybeLength = 0.5 * maybeLength;
  30674. }
  30675. DecodeStream.call(this, maybeLength);
  30676. }
  30677. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30678. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30679. var UPSTREAM_BLOCK_SIZE = 8000;
  30680. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30681. if (!bytes.length) {
  30682. this.eof = true;
  30683. return;
  30684. }
  30685. var maxDecodeLength = (bytes.length + 1) >> 1;
  30686. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30687. var bufferLength = this.bufferLength;
  30688. var firstDigit = this.firstDigit;
  30689. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30690. var ch = bytes[i], digit;
  30691. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30692. digit = ch & 0x0F;
  30693. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30694. // 'A'-'Z', 'a'-'z'
  30695. digit = (ch & 0x0F) + 9;
  30696. } else if (ch === 0x3E) { // '>'
  30697. this.eof = true;
  30698. break;
  30699. } else { // probably whitespace
  30700. continue; // ignoring
  30701. }
  30702. if (firstDigit < 0) {
  30703. firstDigit = digit;
  30704. } else {
  30705. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30706. firstDigit = -1;
  30707. }
  30708. }
  30709. if (firstDigit >= 0 && this.eof) {
  30710. // incomplete byte
  30711. buffer[bufferLength++] = (firstDigit << 4);
  30712. firstDigit = -1;
  30713. }
  30714. this.firstDigit = firstDigit;
  30715. this.bufferLength = bufferLength;
  30716. };
  30717. return AsciiHexStream;
  30718. })();
  30719. var RunLengthStream = (function RunLengthStreamClosure() {
  30720. function RunLengthStream(str, maybeLength) {
  30721. this.str = str;
  30722. this.dict = str.dict;
  30723. DecodeStream.call(this, maybeLength);
  30724. }
  30725. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30726. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30727. // The repeatHeader has following format. The first byte defines type of run
  30728. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30729. // (in addition to the second byte from the header), n = 129 through 255 -
  30730. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30731. var repeatHeader = this.str.getBytes(2);
  30732. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30733. this.eof = true;
  30734. return;
  30735. }
  30736. var buffer;
  30737. var bufferLength = this.bufferLength;
  30738. var n = repeatHeader[0];
  30739. if (n < 128) {
  30740. // copy n bytes
  30741. buffer = this.ensureBuffer(bufferLength + n + 1);
  30742. buffer[bufferLength++] = repeatHeader[1];
  30743. if (n > 0) {
  30744. var source = this.str.getBytes(n);
  30745. buffer.set(source, bufferLength);
  30746. bufferLength += n;
  30747. }
  30748. } else {
  30749. n = 257 - n;
  30750. var b = repeatHeader[1];
  30751. buffer = this.ensureBuffer(bufferLength + n + 1);
  30752. for (var i = 0; i < n; i++) {
  30753. buffer[bufferLength++] = b;
  30754. }
  30755. }
  30756. this.bufferLength = bufferLength;
  30757. };
  30758. return RunLengthStream;
  30759. })();
  30760. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30761. var ccittEOL = -2;
  30762. var twoDimPass = 0;
  30763. var twoDimHoriz = 1;
  30764. var twoDimVert0 = 2;
  30765. var twoDimVertR1 = 3;
  30766. var twoDimVertL1 = 4;
  30767. var twoDimVertR2 = 5;
  30768. var twoDimVertL2 = 6;
  30769. var twoDimVertR3 = 7;
  30770. var twoDimVertL3 = 8;
  30771. var twoDimTable = [
  30772. [-1, -1], [-1, -1], // 000000x
  30773. [7, twoDimVertL3], // 0000010
  30774. [7, twoDimVertR3], // 0000011
  30775. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30776. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30777. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30778. [4, twoDimPass], [4, twoDimPass],
  30779. [4, twoDimPass], [4, twoDimPass],
  30780. [4, twoDimPass], [4, twoDimPass],
  30781. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30782. [3, twoDimHoriz], [3, twoDimHoriz],
  30783. [3, twoDimHoriz], [3, twoDimHoriz],
  30784. [3, twoDimHoriz], [3, twoDimHoriz],
  30785. [3, twoDimHoriz], [3, twoDimHoriz],
  30786. [3, twoDimHoriz], [3, twoDimHoriz],
  30787. [3, twoDimHoriz], [3, twoDimHoriz],
  30788. [3, twoDimHoriz], [3, twoDimHoriz],
  30789. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30790. [3, twoDimVertL1], [3, twoDimVertL1],
  30791. [3, twoDimVertL1], [3, twoDimVertL1],
  30792. [3, twoDimVertL1], [3, twoDimVertL1],
  30793. [3, twoDimVertL1], [3, twoDimVertL1],
  30794. [3, twoDimVertL1], [3, twoDimVertL1],
  30795. [3, twoDimVertL1], [3, twoDimVertL1],
  30796. [3, twoDimVertL1], [3, twoDimVertL1],
  30797. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30798. [3, twoDimVertR1], [3, twoDimVertR1],
  30799. [3, twoDimVertR1], [3, twoDimVertR1],
  30800. [3, twoDimVertR1], [3, twoDimVertR1],
  30801. [3, twoDimVertR1], [3, twoDimVertR1],
  30802. [3, twoDimVertR1], [3, twoDimVertR1],
  30803. [3, twoDimVertR1], [3, twoDimVertR1],
  30804. [3, twoDimVertR1], [3, twoDimVertR1],
  30805. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30806. [1, twoDimVert0], [1, twoDimVert0],
  30807. [1, twoDimVert0], [1, twoDimVert0],
  30808. [1, twoDimVert0], [1, twoDimVert0],
  30809. [1, twoDimVert0], [1, twoDimVert0],
  30810. [1, twoDimVert0], [1, twoDimVert0],
  30811. [1, twoDimVert0], [1, twoDimVert0],
  30812. [1, twoDimVert0], [1, twoDimVert0],
  30813. [1, twoDimVert0], [1, twoDimVert0],
  30814. [1, twoDimVert0], [1, twoDimVert0],
  30815. [1, twoDimVert0], [1, twoDimVert0],
  30816. [1, twoDimVert0], [1, twoDimVert0],
  30817. [1, twoDimVert0], [1, twoDimVert0],
  30818. [1, twoDimVert0], [1, twoDimVert0],
  30819. [1, twoDimVert0], [1, twoDimVert0],
  30820. [1, twoDimVert0], [1, twoDimVert0],
  30821. [1, twoDimVert0], [1, twoDimVert0],
  30822. [1, twoDimVert0], [1, twoDimVert0],
  30823. [1, twoDimVert0], [1, twoDimVert0],
  30824. [1, twoDimVert0], [1, twoDimVert0],
  30825. [1, twoDimVert0], [1, twoDimVert0],
  30826. [1, twoDimVert0], [1, twoDimVert0],
  30827. [1, twoDimVert0], [1, twoDimVert0],
  30828. [1, twoDimVert0], [1, twoDimVert0],
  30829. [1, twoDimVert0], [1, twoDimVert0],
  30830. [1, twoDimVert0], [1, twoDimVert0],
  30831. [1, twoDimVert0], [1, twoDimVert0],
  30832. [1, twoDimVert0], [1, twoDimVert0],
  30833. [1, twoDimVert0], [1, twoDimVert0],
  30834. [1, twoDimVert0], [1, twoDimVert0],
  30835. [1, twoDimVert0], [1, twoDimVert0],
  30836. [1, twoDimVert0], [1, twoDimVert0]
  30837. ];
  30838. var whiteTable1 = [
  30839. [-1, -1], // 00000
  30840. [12, ccittEOL], // 00001
  30841. [-1, -1], [-1, -1], // 0001x
  30842. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30843. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30844. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30845. [11, 1792], [11, 1792], // 1000x
  30846. [12, 1984], // 10010
  30847. [12, 2048], // 10011
  30848. [12, 2112], // 10100
  30849. [12, 2176], // 10101
  30850. [12, 2240], // 10110
  30851. [12, 2304], // 10111
  30852. [11, 1856], [11, 1856], // 1100x
  30853. [11, 1920], [11, 1920], // 1101x
  30854. [12, 2368], // 11100
  30855. [12, 2432], // 11101
  30856. [12, 2496], // 11110
  30857. [12, 2560] // 11111
  30858. ];
  30859. var whiteTable2 = [
  30860. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30861. [8, 29], [8, 29], // 00000010x
  30862. [8, 30], [8, 30], // 00000011x
  30863. [8, 45], [8, 45], // 00000100x
  30864. [8, 46], [8, 46], // 00000101x
  30865. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30866. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30867. [8, 47], [8, 47], // 00001010x
  30868. [8, 48], [8, 48], // 00001011x
  30869. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30870. [6, 13], [6, 13], [6, 13], [6, 13],
  30871. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30872. [8, 33], [8, 33], // 00010010x
  30873. [8, 34], [8, 34], // 00010011x
  30874. [8, 35], [8, 35], // 00010100x
  30875. [8, 36], [8, 36], // 00010101x
  30876. [8, 37], [8, 37], // 00010110x
  30877. [8, 38], [8, 38], // 00010111x
  30878. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30879. [8, 31], [8, 31], // 00011010x
  30880. [8, 32], [8, 32], // 00011011x
  30881. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30882. [6, 1], [6, 1], [6, 1], [6, 1],
  30883. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30884. [6, 12], [6, 12], [6, 12], [6, 12],
  30885. [8, 53], [8, 53], // 00100100x
  30886. [8, 54], [8, 54], // 00100101x
  30887. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30888. [8, 39], [8, 39], // 00101000x
  30889. [8, 40], [8, 40], // 00101001x
  30890. [8, 41], [8, 41], // 00101010x
  30891. [8, 42], [8, 42], // 00101011x
  30892. [8, 43], [8, 43], // 00101100x
  30893. [8, 44], [8, 44], // 00101101x
  30894. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30895. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30896. [8, 61], [8, 61], // 00110010x
  30897. [8, 62], [8, 62], // 00110011x
  30898. [8, 63], [8, 63], // 00110100x
  30899. [8, 0], [8, 0], // 00110101x
  30900. [8, 320], [8, 320], // 00110110x
  30901. [8, 384], [8, 384], // 00110111x
  30902. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30903. [5, 10], [5, 10], [5, 10], [5, 10],
  30904. [5, 10], [5, 10], [5, 10], [5, 10],
  30905. [5, 10], [5, 10], [5, 10], [5, 10],
  30906. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30907. [5, 11], [5, 11], [5, 11], [5, 11],
  30908. [5, 11], [5, 11], [5, 11], [5, 11],
  30909. [5, 11], [5, 11], [5, 11], [5, 11],
  30910. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30911. [8, 59], [8, 59], // 01001010x
  30912. [8, 60], [8, 60], // 01001011x
  30913. [9, 1472], // 010011000
  30914. [9, 1536], // 010011001
  30915. [9, 1600], // 010011010
  30916. [9, 1728], // 010011011
  30917. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30918. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30919. [8, 49], [8, 49], // 01010010x
  30920. [8, 50], [8, 50], // 01010011x
  30921. [8, 51], [8, 51], // 01010100x
  30922. [8, 52], [8, 52], // 01010101x
  30923. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30924. [8, 55], [8, 55], // 01011000x
  30925. [8, 56], [8, 56], // 01011001x
  30926. [8, 57], [8, 57], // 01011010x
  30927. [8, 58], [8, 58], // 01011011x
  30928. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30929. [6, 192], [6, 192], [6, 192], [6, 192],
  30930. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30931. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30932. [8, 448], [8, 448], // 01100100x
  30933. [8, 512], [8, 512], // 01100101x
  30934. [9, 704], // 011001100
  30935. [9, 768], // 011001101
  30936. [8, 640], [8, 640], // 01100111x
  30937. [8, 576], [8, 576], // 01101000x
  30938. [9, 832], // 011010010
  30939. [9, 896], // 011010011
  30940. [9, 960], // 011010100
  30941. [9, 1024], // 011010101
  30942. [9, 1088], // 011010110
  30943. [9, 1152], // 011010111
  30944. [9, 1216], // 011011000
  30945. [9, 1280], // 011011001
  30946. [9, 1344], // 011011010
  30947. [9, 1408], // 011011011
  30948. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30949. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30950. [4, 2], [4, 2], [4, 2], [4, 2],
  30951. [4, 2], [4, 2], [4, 2], [4, 2],
  30952. [4, 2], [4, 2], [4, 2], [4, 2],
  30953. [4, 2], [4, 2], [4, 2], [4, 2],
  30954. [4, 2], [4, 2], [4, 2], [4, 2],
  30955. [4, 2], [4, 2], [4, 2], [4, 2],
  30956. [4, 2], [4, 2], [4, 2], [4, 2],
  30957. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30958. [4, 3], [4, 3], [4, 3], [4, 3],
  30959. [4, 3], [4, 3], [4, 3], [4, 3],
  30960. [4, 3], [4, 3], [4, 3], [4, 3],
  30961. [4, 3], [4, 3], [4, 3], [4, 3],
  30962. [4, 3], [4, 3], [4, 3], [4, 3],
  30963. [4, 3], [4, 3], [4, 3], [4, 3],
  30964. [4, 3], [4, 3], [4, 3], [4, 3],
  30965. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30966. [5, 128], [5, 128], [5, 128], [5, 128],
  30967. [5, 128], [5, 128], [5, 128], [5, 128],
  30968. [5, 128], [5, 128], [5, 128], [5, 128],
  30969. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30970. [5, 8], [5, 8], [5, 8], [5, 8],
  30971. [5, 8], [5, 8], [5, 8], [5, 8],
  30972. [5, 8], [5, 8], [5, 8], [5, 8],
  30973. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30974. [5, 9], [5, 9], [5, 9], [5, 9],
  30975. [5, 9], [5, 9], [5, 9], [5, 9],
  30976. [5, 9], [5, 9], [5, 9], [5, 9],
  30977. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30978. [6, 16], [6, 16], [6, 16], [6, 16],
  30979. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30980. [6, 17], [6, 17], [6, 17], [6, 17],
  30981. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30982. [4, 4], [4, 4], [4, 4], [4, 4],
  30983. [4, 4], [4, 4], [4, 4], [4, 4],
  30984. [4, 4], [4, 4], [4, 4], [4, 4],
  30985. [4, 4], [4, 4], [4, 4], [4, 4],
  30986. [4, 4], [4, 4], [4, 4], [4, 4],
  30987. [4, 4], [4, 4], [4, 4], [4, 4],
  30988. [4, 4], [4, 4], [4, 4], [4, 4],
  30989. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30990. [4, 5], [4, 5], [4, 5], [4, 5],
  30991. [4, 5], [4, 5], [4, 5], [4, 5],
  30992. [4, 5], [4, 5], [4, 5], [4, 5],
  30993. [4, 5], [4, 5], [4, 5], [4, 5],
  30994. [4, 5], [4, 5], [4, 5], [4, 5],
  30995. [4, 5], [4, 5], [4, 5], [4, 5],
  30996. [4, 5], [4, 5], [4, 5], [4, 5],
  30997. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30998. [6, 14], [6, 14], [6, 14], [6, 14],
  30999. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  31000. [6, 15], [6, 15], [6, 15], [6, 15],
  31001. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  31002. [5, 64], [5, 64], [5, 64], [5, 64],
  31003. [5, 64], [5, 64], [5, 64], [5, 64],
  31004. [5, 64], [5, 64], [5, 64], [5, 64],
  31005. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  31006. [4, 6], [4, 6], [4, 6], [4, 6],
  31007. [4, 6], [4, 6], [4, 6], [4, 6],
  31008. [4, 6], [4, 6], [4, 6], [4, 6],
  31009. [4, 6], [4, 6], [4, 6], [4, 6],
  31010. [4, 6], [4, 6], [4, 6], [4, 6],
  31011. [4, 6], [4, 6], [4, 6], [4, 6],
  31012. [4, 6], [4, 6], [4, 6], [4, 6],
  31013. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  31014. [4, 7], [4, 7], [4, 7], [4, 7],
  31015. [4, 7], [4, 7], [4, 7], [4, 7],
  31016. [4, 7], [4, 7], [4, 7], [4, 7],
  31017. [4, 7], [4, 7], [4, 7], [4, 7],
  31018. [4, 7], [4, 7], [4, 7], [4, 7],
  31019. [4, 7], [4, 7], [4, 7], [4, 7],
  31020. [4, 7], [4, 7], [4, 7], [4, 7]
  31021. ];
  31022. var blackTable1 = [
  31023. [-1, -1], [-1, -1], // 000000000000x
  31024. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  31025. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  31026. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  31027. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  31028. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  31029. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  31030. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  31031. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  31032. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  31033. [12, 1984], [12, 1984], // 000000010010x
  31034. [12, 2048], [12, 2048], // 000000010011x
  31035. [12, 2112], [12, 2112], // 000000010100x
  31036. [12, 2176], [12, 2176], // 000000010101x
  31037. [12, 2240], [12, 2240], // 000000010110x
  31038. [12, 2304], [12, 2304], // 000000010111x
  31039. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  31040. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  31041. [12, 2368], [12, 2368], // 000000011100x
  31042. [12, 2432], [12, 2432], // 000000011101x
  31043. [12, 2496], [12, 2496], // 000000011110x
  31044. [12, 2560], [12, 2560], // 000000011111x
  31045. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  31046. [10, 18], [10, 18], [10, 18], [10, 18],
  31047. [12, 52], [12, 52], // 000000100100x
  31048. [13, 640], // 0000001001010
  31049. [13, 704], // 0000001001011
  31050. [13, 768], // 0000001001100
  31051. [13, 832], // 0000001001101
  31052. [12, 55], [12, 55], // 000000100111x
  31053. [12, 56], [12, 56], // 000000101000x
  31054. [13, 1280], // 0000001010010
  31055. [13, 1344], // 0000001010011
  31056. [13, 1408], // 0000001010100
  31057. [13, 1472], // 0000001010101
  31058. [12, 59], [12, 59], // 000000101011x
  31059. [12, 60], [12, 60], // 000000101100x
  31060. [13, 1536], // 0000001011010
  31061. [13, 1600], // 0000001011011
  31062. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31063. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31064. [13, 1664], // 0000001100100
  31065. [13, 1728], // 0000001100101
  31066. [12, 320], [12, 320], // 000000110011x
  31067. [12, 384], [12, 384], // 000000110100x
  31068. [12, 448], [12, 448], // 000000110101x
  31069. [13, 512], // 0000001101100
  31070. [13, 576], // 0000001101101
  31071. [12, 53], [12, 53], // 000000110111x
  31072. [12, 54], [12, 54], // 000000111000x
  31073. [13, 896], // 0000001110010
  31074. [13, 960], // 0000001110011
  31075. [13, 1024], // 0000001110100
  31076. [13, 1088], // 0000001110101
  31077. [13, 1152], // 0000001110110
  31078. [13, 1216], // 0000001110111
  31079. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31080. [10, 64], [10, 64], [10, 64], [10, 64]
  31081. ];
  31082. var blackTable2 = [
  31083. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31084. [8, 13], [8, 13], [8, 13], [8, 13],
  31085. [8, 13], [8, 13], [8, 13], [8, 13],
  31086. [8, 13], [8, 13], [8, 13], [8, 13],
  31087. [11, 23], [11, 23], // 00000101000x
  31088. [12, 50], // 000001010010
  31089. [12, 51], // 000001010011
  31090. [12, 44], // 000001010100
  31091. [12, 45], // 000001010101
  31092. [12, 46], // 000001010110
  31093. [12, 47], // 000001010111
  31094. [12, 57], // 000001011000
  31095. [12, 58], // 000001011001
  31096. [12, 61], // 000001011010
  31097. [12, 256], // 000001011011
  31098. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31099. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31100. [12, 48], // 000001100100
  31101. [12, 49], // 000001100101
  31102. [12, 62], // 000001100110
  31103. [12, 63], // 000001100111
  31104. [12, 30], // 000001101000
  31105. [12, 31], // 000001101001
  31106. [12, 32], // 000001101010
  31107. [12, 33], // 000001101011
  31108. [12, 40], // 000001101100
  31109. [12, 41], // 000001101101
  31110. [11, 22], [11, 22], // 00000110111x
  31111. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31112. [8, 14], [8, 14], [8, 14], [8, 14],
  31113. [8, 14], [8, 14], [8, 14], [8, 14],
  31114. [8, 14], [8, 14], [8, 14], [8, 14],
  31115. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31116. [7, 10], [7, 10], [7, 10], [7, 10],
  31117. [7, 10], [7, 10], [7, 10], [7, 10],
  31118. [7, 10], [7, 10], [7, 10], [7, 10],
  31119. [7, 10], [7, 10], [7, 10], [7, 10],
  31120. [7, 10], [7, 10], [7, 10], [7, 10],
  31121. [7, 10], [7, 10], [7, 10], [7, 10],
  31122. [7, 10], [7, 10], [7, 10], [7, 10],
  31123. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31124. [7, 11], [7, 11], [7, 11], [7, 11],
  31125. [7, 11], [7, 11], [7, 11], [7, 11],
  31126. [7, 11], [7, 11], [7, 11], [7, 11],
  31127. [7, 11], [7, 11], [7, 11], [7, 11],
  31128. [7, 11], [7, 11], [7, 11], [7, 11],
  31129. [7, 11], [7, 11], [7, 11], [7, 11],
  31130. [7, 11], [7, 11], [7, 11], [7, 11],
  31131. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31132. [9, 15], [9, 15], [9, 15], [9, 15],
  31133. [12, 128], // 000011001000
  31134. [12, 192], // 000011001001
  31135. [12, 26], // 000011001010
  31136. [12, 27], // 000011001011
  31137. [12, 28], // 000011001100
  31138. [12, 29], // 000011001101
  31139. [11, 19], [11, 19], // 00001100111x
  31140. [11, 20], [11, 20], // 00001101000x
  31141. [12, 34], // 000011010010
  31142. [12, 35], // 000011010011
  31143. [12, 36], // 000011010100
  31144. [12, 37], // 000011010101
  31145. [12, 38], // 000011010110
  31146. [12, 39], // 000011010111
  31147. [11, 21], [11, 21], // 00001101100x
  31148. [12, 42], // 000011011010
  31149. [12, 43], // 000011011011
  31150. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31151. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31152. [7, 12], [7, 12], [7, 12], [7, 12],
  31153. [7, 12], [7, 12], [7, 12], [7, 12],
  31154. [7, 12], [7, 12], [7, 12], [7, 12],
  31155. [7, 12], [7, 12], [7, 12], [7, 12],
  31156. [7, 12], [7, 12], [7, 12], [7, 12],
  31157. [7, 12], [7, 12], [7, 12], [7, 12],
  31158. [7, 12], [7, 12], [7, 12], [7, 12]
  31159. ];
  31160. var blackTable3 = [
  31161. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31162. [6, 9], // 000100
  31163. [6, 8], // 000101
  31164. [5, 7], [5, 7], // 00011x
  31165. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31166. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31167. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31168. [3, 1], [3, 1], [3, 1], [3, 1],
  31169. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31170. [3, 4], [3, 4], [3, 4], [3, 4],
  31171. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31172. [2, 3], [2, 3], [2, 3], [2, 3],
  31173. [2, 3], [2, 3], [2, 3], [2, 3],
  31174. [2, 3], [2, 3], [2, 3], [2, 3],
  31175. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31176. [2, 2], [2, 2], [2, 2], [2, 2],
  31177. [2, 2], [2, 2], [2, 2], [2, 2],
  31178. [2, 2], [2, 2], [2, 2], [2, 2]
  31179. ];
  31180. function CCITTFaxStream(str, maybeLength, params) {
  31181. this.str = str;
  31182. this.dict = str.dict;
  31183. params = params || Dict.empty;
  31184. this.encoding = params.get('K') || 0;
  31185. this.eoline = params.get('EndOfLine') || false;
  31186. this.byteAlign = params.get('EncodedByteAlign') || false;
  31187. this.columns = params.get('Columns') || 1728;
  31188. this.rows = params.get('Rows') || 0;
  31189. var eoblock = params.get('EndOfBlock');
  31190. if (eoblock === null || eoblock === undefined) {
  31191. eoblock = true;
  31192. }
  31193. this.eoblock = eoblock;
  31194. this.black = params.get('BlackIs1') || false;
  31195. this.codingLine = new Uint32Array(this.columns + 1);
  31196. this.refLine = new Uint32Array(this.columns + 2);
  31197. this.codingLine[0] = this.columns;
  31198. this.codingPos = 0;
  31199. this.row = 0;
  31200. this.nextLine2D = this.encoding < 0;
  31201. this.inputBits = 0;
  31202. this.inputBuf = 0;
  31203. this.outputBits = 0;
  31204. var code1;
  31205. while ((code1 = this.lookBits(12)) === 0) {
  31206. this.eatBits(1);
  31207. }
  31208. if (code1 === 1) {
  31209. this.eatBits(12);
  31210. }
  31211. if (this.encoding > 0) {
  31212. this.nextLine2D = !this.lookBits(1);
  31213. this.eatBits(1);
  31214. }
  31215. DecodeStream.call(this, maybeLength);
  31216. }
  31217. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31218. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31219. while (!this.eof) {
  31220. var c = this.lookChar();
  31221. this.ensureBuffer(this.bufferLength + 1);
  31222. this.buffer[this.bufferLength++] = c;
  31223. }
  31224. };
  31225. CCITTFaxStream.prototype.addPixels =
  31226. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31227. var codingLine = this.codingLine;
  31228. var codingPos = this.codingPos;
  31229. if (a1 > codingLine[codingPos]) {
  31230. if (a1 > this.columns) {
  31231. info('row is wrong length');
  31232. this.err = true;
  31233. a1 = this.columns;
  31234. }
  31235. if ((codingPos & 1) ^ blackPixels) {
  31236. ++codingPos;
  31237. }
  31238. codingLine[codingPos] = a1;
  31239. }
  31240. this.codingPos = codingPos;
  31241. };
  31242. CCITTFaxStream.prototype.addPixelsNeg =
  31243. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31244. var codingLine = this.codingLine;
  31245. var codingPos = this.codingPos;
  31246. if (a1 > codingLine[codingPos]) {
  31247. if (a1 > this.columns) {
  31248. info('row is wrong length');
  31249. this.err = true;
  31250. a1 = this.columns;
  31251. }
  31252. if ((codingPos & 1) ^ blackPixels) {
  31253. ++codingPos;
  31254. }
  31255. codingLine[codingPos] = a1;
  31256. } else if (a1 < codingLine[codingPos]) {
  31257. if (a1 < 0) {
  31258. info('invalid code');
  31259. this.err = true;
  31260. a1 = 0;
  31261. }
  31262. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31263. --codingPos;
  31264. }
  31265. codingLine[codingPos] = a1;
  31266. }
  31267. this.codingPos = codingPos;
  31268. };
  31269. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31270. var refLine = this.refLine;
  31271. var codingLine = this.codingLine;
  31272. var columns = this.columns;
  31273. var refPos, blackPixels, bits, i;
  31274. if (this.outputBits === 0) {
  31275. if (this.eof) {
  31276. return null;
  31277. }
  31278. this.err = false;
  31279. var code1, code2, code3;
  31280. if (this.nextLine2D) {
  31281. for (i = 0; codingLine[i] < columns; ++i) {
  31282. refLine[i] = codingLine[i];
  31283. }
  31284. refLine[i++] = columns;
  31285. refLine[i] = columns;
  31286. codingLine[0] = 0;
  31287. this.codingPos = 0;
  31288. refPos = 0;
  31289. blackPixels = 0;
  31290. while (codingLine[this.codingPos] < columns) {
  31291. code1 = this.getTwoDimCode();
  31292. switch (code1) {
  31293. case twoDimPass:
  31294. this.addPixels(refLine[refPos + 1], blackPixels);
  31295. if (refLine[refPos + 1] < columns) {
  31296. refPos += 2;
  31297. }
  31298. break;
  31299. case twoDimHoriz:
  31300. code1 = code2 = 0;
  31301. if (blackPixels) {
  31302. do {
  31303. code1 += (code3 = this.getBlackCode());
  31304. } while (code3 >= 64);
  31305. do {
  31306. code2 += (code3 = this.getWhiteCode());
  31307. } while (code3 >= 64);
  31308. } else {
  31309. do {
  31310. code1 += (code3 = this.getWhiteCode());
  31311. } while (code3 >= 64);
  31312. do {
  31313. code2 += (code3 = this.getBlackCode());
  31314. } while (code3 >= 64);
  31315. }
  31316. this.addPixels(codingLine[this.codingPos] +
  31317. code1, blackPixels);
  31318. if (codingLine[this.codingPos] < columns) {
  31319. this.addPixels(codingLine[this.codingPos] + code2,
  31320. blackPixels ^ 1);
  31321. }
  31322. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31323. refLine[refPos] < columns) {
  31324. refPos += 2;
  31325. }
  31326. break;
  31327. case twoDimVertR3:
  31328. this.addPixels(refLine[refPos] + 3, blackPixels);
  31329. blackPixels ^= 1;
  31330. if (codingLine[this.codingPos] < columns) {
  31331. ++refPos;
  31332. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31333. refLine[refPos] < columns) {
  31334. refPos += 2;
  31335. }
  31336. }
  31337. break;
  31338. case twoDimVertR2:
  31339. this.addPixels(refLine[refPos] + 2, blackPixels);
  31340. blackPixels ^= 1;
  31341. if (codingLine[this.codingPos] < columns) {
  31342. ++refPos;
  31343. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31344. refLine[refPos] < columns) {
  31345. refPos += 2;
  31346. }
  31347. }
  31348. break;
  31349. case twoDimVertR1:
  31350. this.addPixels(refLine[refPos] + 1, blackPixels);
  31351. blackPixels ^= 1;
  31352. if (codingLine[this.codingPos] < columns) {
  31353. ++refPos;
  31354. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31355. refLine[refPos] < columns) {
  31356. refPos += 2;
  31357. }
  31358. }
  31359. break;
  31360. case twoDimVert0:
  31361. this.addPixels(refLine[refPos], blackPixels);
  31362. blackPixels ^= 1;
  31363. if (codingLine[this.codingPos] < columns) {
  31364. ++refPos;
  31365. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31366. refLine[refPos] < columns) {
  31367. refPos += 2;
  31368. }
  31369. }
  31370. break;
  31371. case twoDimVertL3:
  31372. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31373. blackPixels ^= 1;
  31374. if (codingLine[this.codingPos] < columns) {
  31375. if (refPos > 0) {
  31376. --refPos;
  31377. } else {
  31378. ++refPos;
  31379. }
  31380. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31381. refLine[refPos] < columns) {
  31382. refPos += 2;
  31383. }
  31384. }
  31385. break;
  31386. case twoDimVertL2:
  31387. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31388. blackPixels ^= 1;
  31389. if (codingLine[this.codingPos] < columns) {
  31390. if (refPos > 0) {
  31391. --refPos;
  31392. } else {
  31393. ++refPos;
  31394. }
  31395. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31396. refLine[refPos] < columns) {
  31397. refPos += 2;
  31398. }
  31399. }
  31400. break;
  31401. case twoDimVertL1:
  31402. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31403. blackPixels ^= 1;
  31404. if (codingLine[this.codingPos] < columns) {
  31405. if (refPos > 0) {
  31406. --refPos;
  31407. } else {
  31408. ++refPos;
  31409. }
  31410. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31411. refLine[refPos] < columns) {
  31412. refPos += 2;
  31413. }
  31414. }
  31415. break;
  31416. case EOF:
  31417. this.addPixels(columns, 0);
  31418. this.eof = true;
  31419. break;
  31420. default:
  31421. info('bad 2d code');
  31422. this.addPixels(columns, 0);
  31423. this.err = true;
  31424. }
  31425. }
  31426. } else {
  31427. codingLine[0] = 0;
  31428. this.codingPos = 0;
  31429. blackPixels = 0;
  31430. while (codingLine[this.codingPos] < columns) {
  31431. code1 = 0;
  31432. if (blackPixels) {
  31433. do {
  31434. code1 += (code3 = this.getBlackCode());
  31435. } while (code3 >= 64);
  31436. } else {
  31437. do {
  31438. code1 += (code3 = this.getWhiteCode());
  31439. } while (code3 >= 64);
  31440. }
  31441. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31442. blackPixels ^= 1;
  31443. }
  31444. }
  31445. var gotEOL = false;
  31446. if (this.byteAlign) {
  31447. this.inputBits &= ~7;
  31448. }
  31449. if (!this.eoblock && this.row === this.rows - 1) {
  31450. this.eof = true;
  31451. } else {
  31452. code1 = this.lookBits(12);
  31453. if (this.eoline) {
  31454. while (code1 !== EOF && code1 !== 1) {
  31455. this.eatBits(1);
  31456. code1 = this.lookBits(12);
  31457. }
  31458. } else {
  31459. while (code1 === 0) {
  31460. this.eatBits(1);
  31461. code1 = this.lookBits(12);
  31462. }
  31463. }
  31464. if (code1 === 1) {
  31465. this.eatBits(12);
  31466. gotEOL = true;
  31467. } else if (code1 === EOF) {
  31468. this.eof = true;
  31469. }
  31470. }
  31471. if (!this.eof && this.encoding > 0) {
  31472. this.nextLine2D = !this.lookBits(1);
  31473. this.eatBits(1);
  31474. }
  31475. if (this.eoblock && gotEOL && this.byteAlign) {
  31476. code1 = this.lookBits(12);
  31477. if (code1 === 1) {
  31478. this.eatBits(12);
  31479. if (this.encoding > 0) {
  31480. this.lookBits(1);
  31481. this.eatBits(1);
  31482. }
  31483. if (this.encoding >= 0) {
  31484. for (i = 0; i < 4; ++i) {
  31485. code1 = this.lookBits(12);
  31486. if (code1 !== 1) {
  31487. info('bad rtc code: ' + code1);
  31488. }
  31489. this.eatBits(12);
  31490. if (this.encoding > 0) {
  31491. this.lookBits(1);
  31492. this.eatBits(1);
  31493. }
  31494. }
  31495. }
  31496. this.eof = true;
  31497. }
  31498. } else if (this.err && this.eoline) {
  31499. while (true) {
  31500. code1 = this.lookBits(13);
  31501. if (code1 === EOF) {
  31502. this.eof = true;
  31503. return null;
  31504. }
  31505. if ((code1 >> 1) === 1) {
  31506. break;
  31507. }
  31508. this.eatBits(1);
  31509. }
  31510. this.eatBits(12);
  31511. if (this.encoding > 0) {
  31512. this.eatBits(1);
  31513. this.nextLine2D = !(code1 & 1);
  31514. }
  31515. }
  31516. if (codingLine[0] > 0) {
  31517. this.outputBits = codingLine[this.codingPos = 0];
  31518. } else {
  31519. this.outputBits = codingLine[this.codingPos = 1];
  31520. }
  31521. this.row++;
  31522. }
  31523. var c;
  31524. if (this.outputBits >= 8) {
  31525. c = (this.codingPos & 1) ? 0 : 0xFF;
  31526. this.outputBits -= 8;
  31527. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31528. this.codingPos++;
  31529. this.outputBits = (codingLine[this.codingPos] -
  31530. codingLine[this.codingPos - 1]);
  31531. }
  31532. } else {
  31533. bits = 8;
  31534. c = 0;
  31535. do {
  31536. if (this.outputBits > bits) {
  31537. c <<= bits;
  31538. if (!(this.codingPos & 1)) {
  31539. c |= 0xFF >> (8 - bits);
  31540. }
  31541. this.outputBits -= bits;
  31542. bits = 0;
  31543. } else {
  31544. c <<= this.outputBits;
  31545. if (!(this.codingPos & 1)) {
  31546. c |= 0xFF >> (8 - this.outputBits);
  31547. }
  31548. bits -= this.outputBits;
  31549. this.outputBits = 0;
  31550. if (codingLine[this.codingPos] < columns) {
  31551. this.codingPos++;
  31552. this.outputBits = (codingLine[this.codingPos] -
  31553. codingLine[this.codingPos - 1]);
  31554. } else if (bits > 0) {
  31555. c <<= bits;
  31556. bits = 0;
  31557. }
  31558. }
  31559. } while (bits);
  31560. }
  31561. if (this.black) {
  31562. c ^= 0xFF;
  31563. }
  31564. return c;
  31565. };
  31566. // This functions returns the code found from the table.
  31567. // The start and end parameters set the boundaries for searching the table.
  31568. // The limit parameter is optional. Function returns an array with three
  31569. // values. The first array element indicates whether a valid code is being
  31570. // returned. The second array element is the actual code. The third array
  31571. // element indicates whether EOF was reached.
  31572. CCITTFaxStream.prototype.findTableCode =
  31573. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31574. var limitValue = limit || 0;
  31575. for (var i = start; i <= end; ++i) {
  31576. var code = this.lookBits(i);
  31577. if (code === EOF) {
  31578. return [true, 1, false];
  31579. }
  31580. if (i < end) {
  31581. code <<= end - i;
  31582. }
  31583. if (!limitValue || code >= limitValue) {
  31584. var p = table[code - limitValue];
  31585. if (p[0] === i) {
  31586. this.eatBits(i);
  31587. return [true, p[1], true];
  31588. }
  31589. }
  31590. }
  31591. return [false, 0, false];
  31592. };
  31593. CCITTFaxStream.prototype.getTwoDimCode =
  31594. function ccittFaxStreamGetTwoDimCode() {
  31595. var code = 0;
  31596. var p;
  31597. if (this.eoblock) {
  31598. code = this.lookBits(7);
  31599. p = twoDimTable[code];
  31600. if (p && p[0] > 0) {
  31601. this.eatBits(p[0]);
  31602. return p[1];
  31603. }
  31604. } else {
  31605. var result = this.findTableCode(1, 7, twoDimTable);
  31606. if (result[0] && result[2]) {
  31607. return result[1];
  31608. }
  31609. }
  31610. info('Bad two dim code');
  31611. return EOF;
  31612. };
  31613. CCITTFaxStream.prototype.getWhiteCode =
  31614. function ccittFaxStreamGetWhiteCode() {
  31615. var code = 0;
  31616. var p;
  31617. if (this.eoblock) {
  31618. code = this.lookBits(12);
  31619. if (code === EOF) {
  31620. return 1;
  31621. }
  31622. if ((code >> 5) === 0) {
  31623. p = whiteTable1[code];
  31624. } else {
  31625. p = whiteTable2[code >> 3];
  31626. }
  31627. if (p[0] > 0) {
  31628. this.eatBits(p[0]);
  31629. return p[1];
  31630. }
  31631. } else {
  31632. var result = this.findTableCode(1, 9, whiteTable2);
  31633. if (result[0]) {
  31634. return result[1];
  31635. }
  31636. result = this.findTableCode(11, 12, whiteTable1);
  31637. if (result[0]) {
  31638. return result[1];
  31639. }
  31640. }
  31641. info('bad white code');
  31642. this.eatBits(1);
  31643. return 1;
  31644. };
  31645. CCITTFaxStream.prototype.getBlackCode =
  31646. function ccittFaxStreamGetBlackCode() {
  31647. var code, p;
  31648. if (this.eoblock) {
  31649. code = this.lookBits(13);
  31650. if (code === EOF) {
  31651. return 1;
  31652. }
  31653. if ((code >> 7) === 0) {
  31654. p = blackTable1[code];
  31655. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31656. p = blackTable2[(code >> 1) - 64];
  31657. } else {
  31658. p = blackTable3[code >> 7];
  31659. }
  31660. if (p[0] > 0) {
  31661. this.eatBits(p[0]);
  31662. return p[1];
  31663. }
  31664. } else {
  31665. var result = this.findTableCode(2, 6, blackTable3);
  31666. if (result[0]) {
  31667. return result[1];
  31668. }
  31669. result = this.findTableCode(7, 12, blackTable2, 64);
  31670. if (result[0]) {
  31671. return result[1];
  31672. }
  31673. result = this.findTableCode(10, 13, blackTable1);
  31674. if (result[0]) {
  31675. return result[1];
  31676. }
  31677. }
  31678. info('bad black code');
  31679. this.eatBits(1);
  31680. return 1;
  31681. };
  31682. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31683. var c;
  31684. while (this.inputBits < n) {
  31685. if ((c = this.str.getByte()) === -1) {
  31686. if (this.inputBits === 0) {
  31687. return EOF;
  31688. }
  31689. return ((this.inputBuf << (n - this.inputBits)) &
  31690. (0xFFFF >> (16 - n)));
  31691. }
  31692. this.inputBuf = (this.inputBuf << 8) + c;
  31693. this.inputBits += 8;
  31694. }
  31695. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31696. };
  31697. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31698. if ((this.inputBits -= n) < 0) {
  31699. this.inputBits = 0;
  31700. }
  31701. };
  31702. return CCITTFaxStream;
  31703. })();
  31704. var LZWStream = (function LZWStreamClosure() {
  31705. function LZWStream(str, maybeLength, earlyChange) {
  31706. this.str = str;
  31707. this.dict = str.dict;
  31708. this.cachedData = 0;
  31709. this.bitsCached = 0;
  31710. var maxLzwDictionarySize = 4096;
  31711. var lzwState = {
  31712. earlyChange: earlyChange,
  31713. codeLength: 9,
  31714. nextCode: 258,
  31715. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31716. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31717. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31718. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31719. currentSequenceLength: 0
  31720. };
  31721. for (var i = 0; i < 256; ++i) {
  31722. lzwState.dictionaryValues[i] = i;
  31723. lzwState.dictionaryLengths[i] = 1;
  31724. }
  31725. this.lzwState = lzwState;
  31726. DecodeStream.call(this, maybeLength);
  31727. }
  31728. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31729. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31730. var bitsCached = this.bitsCached;
  31731. var cachedData = this.cachedData;
  31732. while (bitsCached < n) {
  31733. var c = this.str.getByte();
  31734. if (c === -1) {
  31735. this.eof = true;
  31736. return null;
  31737. }
  31738. cachedData = (cachedData << 8) | c;
  31739. bitsCached += 8;
  31740. }
  31741. this.bitsCached = (bitsCached -= n);
  31742. this.cachedData = cachedData;
  31743. this.lastCode = null;
  31744. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31745. };
  31746. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31747. var blockSize = 512;
  31748. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31749. var i, j, q;
  31750. var lzwState = this.lzwState;
  31751. if (!lzwState) {
  31752. return; // eof was found
  31753. }
  31754. var earlyChange = lzwState.earlyChange;
  31755. var nextCode = lzwState.nextCode;
  31756. var dictionaryValues = lzwState.dictionaryValues;
  31757. var dictionaryLengths = lzwState.dictionaryLengths;
  31758. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31759. var codeLength = lzwState.codeLength;
  31760. var prevCode = lzwState.prevCode;
  31761. var currentSequence = lzwState.currentSequence;
  31762. var currentSequenceLength = lzwState.currentSequenceLength;
  31763. var decodedLength = 0;
  31764. var currentBufferLength = this.bufferLength;
  31765. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31766. for (i = 0; i < blockSize; i++) {
  31767. var code = this.readBits(codeLength);
  31768. var hasPrev = currentSequenceLength > 0;
  31769. if (code < 256) {
  31770. currentSequence[0] = code;
  31771. currentSequenceLength = 1;
  31772. } else if (code >= 258) {
  31773. if (code < nextCode) {
  31774. currentSequenceLength = dictionaryLengths[code];
  31775. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31776. currentSequence[j] = dictionaryValues[q];
  31777. q = dictionaryPrevCodes[q];
  31778. }
  31779. } else {
  31780. currentSequence[currentSequenceLength++] = currentSequence[0];
  31781. }
  31782. } else if (code === 256) {
  31783. codeLength = 9;
  31784. nextCode = 258;
  31785. currentSequenceLength = 0;
  31786. continue;
  31787. } else {
  31788. this.eof = true;
  31789. delete this.lzwState;
  31790. break;
  31791. }
  31792. if (hasPrev) {
  31793. dictionaryPrevCodes[nextCode] = prevCode;
  31794. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31795. dictionaryValues[nextCode] = currentSequence[0];
  31796. nextCode++;
  31797. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31798. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31799. 0.6931471805599453 + 1, 12) | 0;
  31800. }
  31801. prevCode = code;
  31802. decodedLength += currentSequenceLength;
  31803. if (estimatedDecodedSize < decodedLength) {
  31804. do {
  31805. estimatedDecodedSize += decodedSizeDelta;
  31806. } while (estimatedDecodedSize < decodedLength);
  31807. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31808. }
  31809. for (j = 0; j < currentSequenceLength; j++) {
  31810. buffer[currentBufferLength++] = currentSequence[j];
  31811. }
  31812. }
  31813. lzwState.nextCode = nextCode;
  31814. lzwState.codeLength = codeLength;
  31815. lzwState.prevCode = prevCode;
  31816. lzwState.currentSequenceLength = currentSequenceLength;
  31817. this.bufferLength = currentBufferLength;
  31818. };
  31819. return LZWStream;
  31820. })();
  31821. var NullStream = (function NullStreamClosure() {
  31822. function NullStream() {
  31823. Stream.call(this, new Uint8Array(0));
  31824. }
  31825. NullStream.prototype = Stream.prototype;
  31826. return NullStream;
  31827. })();
  31828. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31829. setup: function wphSetup(handler) {
  31830. var pdfManager;
  31831. function loadDocument(recoveryMode) {
  31832. var loadDocumentCapability = createPromiseCapability();
  31833. var parseSuccess = function parseSuccess() {
  31834. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31835. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31836. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31837. Promise.all([numPagesPromise, fingerprintPromise,
  31838. encryptedPromise]).then(function onDocReady(results) {
  31839. var doc = {
  31840. numPages: results[0],
  31841. fingerprint: results[1],
  31842. encrypted: !!results[2],
  31843. };
  31844. loadDocumentCapability.resolve(doc);
  31845. },
  31846. parseFailure);
  31847. };
  31848. var parseFailure = function parseFailure(e) {
  31849. loadDocumentCapability.reject(e);
  31850. };
  31851. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31852. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31853. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31854. parseSuccess, parseFailure);
  31855. }, parseFailure);
  31856. }, parseFailure);
  31857. return loadDocumentCapability.promise;
  31858. }
  31859. function getPdfManager(data) {
  31860. var pdfManagerCapability = createPromiseCapability();
  31861. var source = data.source;
  31862. var disableRange = data.disableRange;
  31863. if (source.data) {
  31864. try {
  31865. pdfManager = new LocalPdfManager(source.data, source.password);
  31866. pdfManagerCapability.resolve();
  31867. } catch (ex) {
  31868. pdfManagerCapability.reject(ex);
  31869. }
  31870. return pdfManagerCapability.promise;
  31871. } else if (source.chunkedViewerLoading) {
  31872. try {
  31873. pdfManager = new NetworkPdfManager(source, handler);
  31874. pdfManagerCapability.resolve();
  31875. } catch (ex) {
  31876. pdfManagerCapability.reject(ex);
  31877. }
  31878. return pdfManagerCapability.promise;
  31879. }
  31880. var networkManager = new NetworkManager(source.url, {
  31881. httpHeaders: source.httpHeaders,
  31882. withCredentials: source.withCredentials
  31883. });
  31884. var cachedChunks = [];
  31885. var fullRequestXhrId = networkManager.requestFull({
  31886. onHeadersReceived: function onHeadersReceived() {
  31887. if (disableRange) {
  31888. return;
  31889. }
  31890. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31891. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31892. return;
  31893. }
  31894. var contentEncoding =
  31895. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31896. if (contentEncoding !== 'identity') {
  31897. return;
  31898. }
  31899. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31900. length = parseInt(length, 10);
  31901. if (!isInt(length)) {
  31902. return;
  31903. }
  31904. source.length = length;
  31905. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31906. // The file size is smaller than the size of two chunks, so it does
  31907. // not make any sense to abort the request and retry with a range
  31908. // request.
  31909. return;
  31910. }
  31911. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31912. // We can continue fetching when progressive loading is enabled,
  31913. // and we don't need the autoFetch feature.
  31914. source.disableAutoFetch = true;
  31915. } else {
  31916. // NOTE: by cancelling the full request, and then issuing range
  31917. // requests, there will be an issue for sites where you can only
  31918. // request the pdf once. However, if this is the case, then the
  31919. // server should not be returning that it can support range
  31920. // requests.
  31921. networkManager.abortRequest(fullRequestXhrId);
  31922. }
  31923. try {
  31924. pdfManager = new NetworkPdfManager(source, handler);
  31925. pdfManagerCapability.resolve(pdfManager);
  31926. } catch (ex) {
  31927. pdfManagerCapability.reject(ex);
  31928. }
  31929. },
  31930. onProgressiveData: source.disableStream ? null :
  31931. function onProgressiveData(chunk) {
  31932. if (!pdfManager) {
  31933. cachedChunks.push(chunk);
  31934. return;
  31935. }
  31936. pdfManager.sendProgressiveData(chunk);
  31937. },
  31938. onDone: function onDone(args) {
  31939. if (pdfManager) {
  31940. return; // already processed
  31941. }
  31942. var pdfFile;
  31943. if (args === null) {
  31944. // TODO add some streaming manager, e.g. for unknown length files.
  31945. // The data was returned in the onProgressiveData, combining...
  31946. var pdfFileLength = 0, pos = 0;
  31947. cachedChunks.forEach(function (chunk) {
  31948. pdfFileLength += chunk.byteLength;
  31949. });
  31950. if (source.length && pdfFileLength !== source.length) {
  31951. warn('reported HTTP length is different from actual');
  31952. }
  31953. var pdfFileArray = new Uint8Array(pdfFileLength);
  31954. cachedChunks.forEach(function (chunk) {
  31955. pdfFileArray.set(new Uint8Array(chunk), pos);
  31956. pos += chunk.byteLength;
  31957. });
  31958. pdfFile = pdfFileArray.buffer;
  31959. } else {
  31960. pdfFile = args.chunk;
  31961. }
  31962. // the data is array, instantiating directly from it
  31963. try {
  31964. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31965. pdfManagerCapability.resolve();
  31966. } catch (ex) {
  31967. pdfManagerCapability.reject(ex);
  31968. }
  31969. },
  31970. onError: function onError(status) {
  31971. var exception;
  31972. if (status === 404) {
  31973. exception = new MissingPDFException('Missing PDF "' +
  31974. source.url + '".');
  31975. handler.send('MissingPDF', exception);
  31976. } else {
  31977. exception = new UnexpectedResponseException(
  31978. 'Unexpected server response (' + status +
  31979. ') while retrieving PDF "' + source.url + '".', status);
  31980. handler.send('UnexpectedResponse', exception);
  31981. }
  31982. },
  31983. onProgress: function onProgress(evt) {
  31984. handler.send('DocProgress', {
  31985. loaded: evt.loaded,
  31986. total: evt.lengthComputable ? evt.total : source.length
  31987. });
  31988. }
  31989. });
  31990. return pdfManagerCapability.promise;
  31991. }
  31992. handler.on('test', function wphSetupTest(data) {
  31993. // check if Uint8Array can be sent to worker
  31994. if (!(data instanceof Uint8Array)) {
  31995. handler.send('test', false);
  31996. return;
  31997. }
  31998. // making sure postMessage transfers are working
  31999. var supportTransfers = data[0] === 255;
  32000. handler.postMessageTransfers = supportTransfers;
  32001. // check if the response property is supported by xhr
  32002. var xhr = new XMLHttpRequest();
  32003. var responseExists = 'response' in xhr;
  32004. // check if the property is actually implemented
  32005. try {
  32006. var dummy = xhr.responseType;
  32007. } catch (e) {
  32008. responseExists = false;
  32009. }
  32010. if (!responseExists) {
  32011. handler.send('test', false);
  32012. return;
  32013. }
  32014. handler.send('test', {
  32015. supportTypedArray: true,
  32016. supportTransfers: supportTransfers
  32017. });
  32018. });
  32019. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32020. var onSuccess = function(doc) {
  32021. handler.send('GetDoc', { pdfInfo: doc });
  32022. };
  32023. var onFailure = function(e) {
  32024. if (e instanceof PasswordException) {
  32025. if (e.code === PasswordResponses.NEED_PASSWORD) {
  32026. handler.send('NeedPassword', e);
  32027. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  32028. handler.send('IncorrectPassword', e);
  32029. }
  32030. } else if (e instanceof InvalidPDFException) {
  32031. handler.send('InvalidPDF', e);
  32032. } else if (e instanceof MissingPDFException) {
  32033. handler.send('MissingPDF', e);
  32034. } else if (e instanceof UnexpectedResponseException) {
  32035. handler.send('UnexpectedResponse', e);
  32036. } else {
  32037. handler.send('UnknownError',
  32038. new UnknownErrorException(e.message, e.toString()));
  32039. }
  32040. };
  32041. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  32042. -1 : data.maxImageSize;
  32043. PDFJS.disableFontFace = data.disableFontFace;
  32044. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  32045. PDFJS.verbosity = data.verbosity;
  32046. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  32047. null : data.cMapUrl;
  32048. PDFJS.cMapPacked = data.cMapPacked === true;
  32049. getPdfManager(data).then(function () {
  32050. handler.send('PDFManagerReady', null);
  32051. pdfManager.onLoadedStream().then(function(stream) {
  32052. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  32053. });
  32054. }).then(function pdfManagerReady() {
  32055. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32056. // Try again with recoveryMode == true
  32057. if (!(ex instanceof XRefParseException)) {
  32058. if (ex instanceof PasswordException) {
  32059. // after password exception prepare to receive a new password
  32060. // to repeat loading
  32061. pdfManager.passwordChanged().then(pdfManagerReady);
  32062. }
  32063. onFailure(ex);
  32064. return;
  32065. }
  32066. pdfManager.requestLoadedStream();
  32067. pdfManager.onLoadedStream().then(function() {
  32068. loadDocument(true).then(onSuccess, onFailure);
  32069. });
  32070. }, onFailure);
  32071. }, onFailure);
  32072. });
  32073. handler.on('GetPage', function wphSetupGetPage(data) {
  32074. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32075. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32076. var refPromise = pdfManager.ensure(page, 'ref');
  32077. var viewPromise = pdfManager.ensure(page, 'view');
  32078. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32079. function(results) {
  32080. return {
  32081. rotate: results[0],
  32082. ref: results[1],
  32083. view: results[2]
  32084. };
  32085. });
  32086. });
  32087. });
  32088. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32089. var ref = new Ref(data.ref.num, data.ref.gen);
  32090. var catalog = pdfManager.pdfDocument.catalog;
  32091. return catalog.getPageIndex(ref);
  32092. });
  32093. handler.on('GetDestinations',
  32094. function wphSetupGetDestinations(data) {
  32095. return pdfManager.ensureCatalog('destinations');
  32096. }
  32097. );
  32098. handler.on('GetDestination',
  32099. function wphSetupGetDestination(data) {
  32100. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32101. }
  32102. );
  32103. handler.on('GetAttachments',
  32104. function wphSetupGetAttachments(data) {
  32105. return pdfManager.ensureCatalog('attachments');
  32106. }
  32107. );
  32108. handler.on('GetJavaScript',
  32109. function wphSetupGetJavaScript(data) {
  32110. return pdfManager.ensureCatalog('javaScript');
  32111. }
  32112. );
  32113. handler.on('GetOutline',
  32114. function wphSetupGetOutline(data) {
  32115. return pdfManager.ensureCatalog('documentOutline');
  32116. }
  32117. );
  32118. handler.on('GetMetadata',
  32119. function wphSetupGetMetadata(data) {
  32120. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32121. pdfManager.ensureCatalog('metadata')]);
  32122. }
  32123. );
  32124. handler.on('GetData', function wphSetupGetData(data) {
  32125. pdfManager.requestLoadedStream();
  32126. return pdfManager.onLoadedStream().then(function(stream) {
  32127. return stream.bytes;
  32128. });
  32129. });
  32130. handler.on('GetStats',
  32131. function wphSetupGetStats(data) {
  32132. return pdfManager.pdfDocument.xref.stats;
  32133. }
  32134. );
  32135. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32136. pdfManager.updatePassword(data);
  32137. });
  32138. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32139. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32140. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32141. });
  32142. });
  32143. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32144. pdfManager.getPage(data.pageIndex).then(function(page) {
  32145. var pageNum = data.pageIndex + 1;
  32146. var start = Date.now();
  32147. // Pre compile the pdf page and fetch the fonts/images.
  32148. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  32149. info('page=' + pageNum + ' - getOperatorList: time=' +
  32150. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  32151. }, function(e) {
  32152. var minimumStackMessage =
  32153. 'worker.js: while trying to getPage() and getOperatorList()';
  32154. var wrappedException;
  32155. // Turn the error into an obj that can be serialized
  32156. if (typeof e === 'string') {
  32157. wrappedException = {
  32158. message: e,
  32159. stack: minimumStackMessage
  32160. };
  32161. } else if (typeof e === 'object') {
  32162. wrappedException = {
  32163. message: e.message || e.toString(),
  32164. stack: e.stack || minimumStackMessage
  32165. };
  32166. } else {
  32167. wrappedException = {
  32168. message: 'Unknown exception type: ' + (typeof e),
  32169. stack: minimumStackMessage
  32170. };
  32171. }
  32172. handler.send('PageError', {
  32173. pageNum: pageNum,
  32174. error: wrappedException,
  32175. intent: data.intent
  32176. });
  32177. });
  32178. });
  32179. }, this);
  32180. handler.on('GetTextContent', function wphExtractText(data) {
  32181. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32182. var pageNum = data.pageIndex + 1;
  32183. var start = Date.now();
  32184. return page.extractTextContent().then(function(textContent) {
  32185. info('text indexing: page=' + pageNum + ' - time=' +
  32186. (Date.now() - start) + 'ms');
  32187. return textContent;
  32188. });
  32189. });
  32190. });
  32191. handler.on('Cleanup', function wphCleanup(data) {
  32192. return pdfManager.cleanup();
  32193. });
  32194. handler.on('Terminate', function wphTerminate(data) {
  32195. pdfManager.terminate();
  32196. });
  32197. }
  32198. };
  32199. var consoleTimer = {};
  32200. var workerConsole = {
  32201. log: function log() {
  32202. var args = Array.prototype.slice.call(arguments);
  32203. globalScope.postMessage({
  32204. action: 'console_log',
  32205. data: args
  32206. });
  32207. },
  32208. error: function error() {
  32209. var args = Array.prototype.slice.call(arguments);
  32210. globalScope.postMessage({
  32211. action: 'console_error',
  32212. data: args
  32213. });
  32214. throw 'pdf.js execution error';
  32215. },
  32216. time: function time(name) {
  32217. consoleTimer[name] = Date.now();
  32218. },
  32219. timeEnd: function timeEnd(name) {
  32220. var time = consoleTimer[name];
  32221. if (!time) {
  32222. error('Unknown timer name ' + name);
  32223. }
  32224. this.log('Timer:', name, Date.now() - time);
  32225. }
  32226. };
  32227. // Worker thread?
  32228. if (typeof window === 'undefined') {
  32229. if (!('console' in globalScope)) {
  32230. globalScope.console = workerConsole;
  32231. }
  32232. // Listen for unsupported features so we can pass them on to the main thread.
  32233. PDFJS.UnsupportedManager.listen(function (msg) {
  32234. globalScope.postMessage({
  32235. action: '_unsupported_feature',
  32236. data: msg
  32237. });
  32238. });
  32239. var handler = new MessageHandler('worker_processor', this);
  32240. WorkerMessageHandler.setup(handler);
  32241. }
  32242. /* This class implements the QM Coder decoding as defined in
  32243. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32244. * Annex C.3 Arithmetic decoding procedure
  32245. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32246. *
  32247. * The arithmetic decoder is used in conjunction with context models to decode
  32248. * JPEG2000 and JBIG2 streams.
  32249. */
  32250. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32251. // Table C-2
  32252. var QeTable = [
  32253. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32254. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32255. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32256. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32257. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32258. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32259. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32260. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32261. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32262. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32263. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32264. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32265. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32266. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32267. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32268. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32269. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32270. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32271. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32272. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32273. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32274. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32275. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32276. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32277. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32278. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32279. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32280. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32281. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32282. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32283. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32284. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32285. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32286. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32287. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32288. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32289. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32290. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32291. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32292. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32293. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32294. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32295. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32296. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32297. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32298. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32299. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32300. ];
  32301. // C.3.5 Initialisation of the decoder (INITDEC)
  32302. function ArithmeticDecoder(data, start, end) {
  32303. this.data = data;
  32304. this.bp = start;
  32305. this.dataEnd = end;
  32306. this.chigh = data[start];
  32307. this.clow = 0;
  32308. this.byteIn();
  32309. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32310. this.clow = (this.clow << 7) & 0xFFFF;
  32311. this.ct -= 7;
  32312. this.a = 0x8000;
  32313. }
  32314. ArithmeticDecoder.prototype = {
  32315. // C.3.4 Compressed data input (BYTEIN)
  32316. byteIn: function ArithmeticDecoder_byteIn() {
  32317. var data = this.data;
  32318. var bp = this.bp;
  32319. if (data[bp] === 0xFF) {
  32320. var b1 = data[bp + 1];
  32321. if (b1 > 0x8F) {
  32322. this.clow += 0xFF00;
  32323. this.ct = 8;
  32324. } else {
  32325. bp++;
  32326. this.clow += (data[bp] << 9);
  32327. this.ct = 7;
  32328. this.bp = bp;
  32329. }
  32330. } else {
  32331. bp++;
  32332. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32333. this.ct = 8;
  32334. this.bp = bp;
  32335. }
  32336. if (this.clow > 0xFFFF) {
  32337. this.chigh += (this.clow >> 16);
  32338. this.clow &= 0xFFFF;
  32339. }
  32340. },
  32341. // C.3.2 Decoding a decision (DECODE)
  32342. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32343. // contexts are packed into 1 byte:
  32344. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32345. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32346. var qeTableIcx = QeTable[cx_index];
  32347. var qeIcx = qeTableIcx.qe;
  32348. var d;
  32349. var a = this.a - qeIcx;
  32350. if (this.chigh < qeIcx) {
  32351. // exchangeLps
  32352. if (a < qeIcx) {
  32353. a = qeIcx;
  32354. d = cx_mps;
  32355. cx_index = qeTableIcx.nmps;
  32356. } else {
  32357. a = qeIcx;
  32358. d = 1 ^ cx_mps;
  32359. if (qeTableIcx.switchFlag === 1) {
  32360. cx_mps = d;
  32361. }
  32362. cx_index = qeTableIcx.nlps;
  32363. }
  32364. } else {
  32365. this.chigh -= qeIcx;
  32366. if ((a & 0x8000) !== 0) {
  32367. this.a = a;
  32368. return cx_mps;
  32369. }
  32370. // exchangeMps
  32371. if (a < qeIcx) {
  32372. d = 1 ^ cx_mps;
  32373. if (qeTableIcx.switchFlag === 1) {
  32374. cx_mps = d;
  32375. }
  32376. cx_index = qeTableIcx.nlps;
  32377. } else {
  32378. d = cx_mps;
  32379. cx_index = qeTableIcx.nmps;
  32380. }
  32381. }
  32382. // C.3.3 renormD;
  32383. do {
  32384. if (this.ct === 0) {
  32385. this.byteIn();
  32386. }
  32387. a <<= 1;
  32388. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32389. this.clow = (this.clow << 1) & 0xFFFF;
  32390. this.ct--;
  32391. } while ((a & 0x8000) === 0);
  32392. this.a = a;
  32393. contexts[pos] = cx_index << 1 | cx_mps;
  32394. return d;
  32395. }
  32396. };
  32397. return ArithmeticDecoder;
  32398. })();
  32399. var JpegImage = (function jpegImage() {
  32400. var dctZigZag = new Uint8Array([
  32401. 0,
  32402. 1, 8,
  32403. 16, 9, 2,
  32404. 3, 10, 17, 24,
  32405. 32, 25, 18, 11, 4,
  32406. 5, 12, 19, 26, 33, 40,
  32407. 48, 41, 34, 27, 20, 13, 6,
  32408. 7, 14, 21, 28, 35, 42, 49, 56,
  32409. 57, 50, 43, 36, 29, 22, 15,
  32410. 23, 30, 37, 44, 51, 58,
  32411. 59, 52, 45, 38, 31,
  32412. 39, 46, 53, 60,
  32413. 61, 54, 47,
  32414. 55, 62,
  32415. 63
  32416. ]);
  32417. var dctCos1 = 4017; // cos(pi/16)
  32418. var dctSin1 = 799; // sin(pi/16)
  32419. var dctCos3 = 3406; // cos(3*pi/16)
  32420. var dctSin3 = 2276; // sin(3*pi/16)
  32421. var dctCos6 = 1567; // cos(6*pi/16)
  32422. var dctSin6 = 3784; // sin(6*pi/16)
  32423. var dctSqrt2 = 5793; // sqrt(2)
  32424. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32425. function constructor() {
  32426. }
  32427. function buildHuffmanTable(codeLengths, values) {
  32428. var k = 0, code = [], i, j, length = 16;
  32429. while (length > 0 && !codeLengths[length - 1]) {
  32430. length--;
  32431. }
  32432. code.push({children: [], index: 0});
  32433. var p = code[0], q;
  32434. for (i = 0; i < length; i++) {
  32435. for (j = 0; j < codeLengths[i]; j++) {
  32436. p = code.pop();
  32437. p.children[p.index] = values[k];
  32438. while (p.index > 0) {
  32439. p = code.pop();
  32440. }
  32441. p.index++;
  32442. code.push(p);
  32443. while (code.length <= i) {
  32444. code.push(q = {children: [], index: 0});
  32445. p.children[p.index] = q.children;
  32446. p = q;
  32447. }
  32448. k++;
  32449. }
  32450. if (i + 1 < length) {
  32451. // p here points to last code
  32452. code.push(q = {children: [], index: 0});
  32453. p.children[p.index] = q.children;
  32454. p = q;
  32455. }
  32456. }
  32457. return code[0].children;
  32458. }
  32459. function getBlockBufferOffset(component, row, col) {
  32460. return 64 * ((component.blocksPerLine + 1) * row + col);
  32461. }
  32462. function decodeScan(data, offset, frame, components, resetInterval,
  32463. spectralStart, spectralEnd, successivePrev, successive) {
  32464. var precision = frame.precision;
  32465. var samplesPerLine = frame.samplesPerLine;
  32466. var scanLines = frame.scanLines;
  32467. var mcusPerLine = frame.mcusPerLine;
  32468. var progressive = frame.progressive;
  32469. var maxH = frame.maxH, maxV = frame.maxV;
  32470. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32471. function readBit() {
  32472. if (bitsCount > 0) {
  32473. bitsCount--;
  32474. return (bitsData >> bitsCount) & 1;
  32475. }
  32476. bitsData = data[offset++];
  32477. if (bitsData === 0xFF) {
  32478. var nextByte = data[offset++];
  32479. if (nextByte) {
  32480. throw 'unexpected marker: ' +
  32481. ((bitsData << 8) | nextByte).toString(16);
  32482. }
  32483. // unstuff 0
  32484. }
  32485. bitsCount = 7;
  32486. return bitsData >>> 7;
  32487. }
  32488. function decodeHuffman(tree) {
  32489. var node = tree;
  32490. while (true) {
  32491. node = node[readBit()];
  32492. if (typeof node === 'number') {
  32493. return node;
  32494. }
  32495. if (typeof node !== 'object') {
  32496. throw 'invalid huffman sequence';
  32497. }
  32498. }
  32499. }
  32500. function receive(length) {
  32501. var n = 0;
  32502. while (length > 0) {
  32503. n = (n << 1) | readBit();
  32504. length--;
  32505. }
  32506. return n;
  32507. }
  32508. function receiveAndExtend(length) {
  32509. if (length === 1) {
  32510. return readBit() === 1 ? 1 : -1;
  32511. }
  32512. var n = receive(length);
  32513. if (n >= 1 << (length - 1)) {
  32514. return n;
  32515. }
  32516. return n + (-1 << length) + 1;
  32517. }
  32518. function decodeBaseline(component, offset) {
  32519. var t = decodeHuffman(component.huffmanTableDC);
  32520. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32521. component.blockData[offset] = (component.pred += diff);
  32522. var k = 1;
  32523. while (k < 64) {
  32524. var rs = decodeHuffman(component.huffmanTableAC);
  32525. var s = rs & 15, r = rs >> 4;
  32526. if (s === 0) {
  32527. if (r < 15) {
  32528. break;
  32529. }
  32530. k += 16;
  32531. continue;
  32532. }
  32533. k += r;
  32534. var z = dctZigZag[k];
  32535. component.blockData[offset + z] = receiveAndExtend(s);
  32536. k++;
  32537. }
  32538. }
  32539. function decodeDCFirst(component, offset) {
  32540. var t = decodeHuffman(component.huffmanTableDC);
  32541. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32542. component.blockData[offset] = (component.pred += diff);
  32543. }
  32544. function decodeDCSuccessive(component, offset) {
  32545. component.blockData[offset] |= readBit() << successive;
  32546. }
  32547. var eobrun = 0;
  32548. function decodeACFirst(component, offset) {
  32549. if (eobrun > 0) {
  32550. eobrun--;
  32551. return;
  32552. }
  32553. var k = spectralStart, e = spectralEnd;
  32554. while (k <= e) {
  32555. var rs = decodeHuffman(component.huffmanTableAC);
  32556. var s = rs & 15, r = rs >> 4;
  32557. if (s === 0) {
  32558. if (r < 15) {
  32559. eobrun = receive(r) + (1 << r) - 1;
  32560. break;
  32561. }
  32562. k += 16;
  32563. continue;
  32564. }
  32565. k += r;
  32566. var z = dctZigZag[k];
  32567. component.blockData[offset + z] =
  32568. receiveAndExtend(s) * (1 << successive);
  32569. k++;
  32570. }
  32571. }
  32572. var successiveACState = 0, successiveACNextValue;
  32573. function decodeACSuccessive(component, offset) {
  32574. var k = spectralStart;
  32575. var e = spectralEnd;
  32576. var r = 0;
  32577. var s;
  32578. var rs;
  32579. while (k <= e) {
  32580. var z = dctZigZag[k];
  32581. switch (successiveACState) {
  32582. case 0: // initial state
  32583. rs = decodeHuffman(component.huffmanTableAC);
  32584. s = rs & 15;
  32585. r = rs >> 4;
  32586. if (s === 0) {
  32587. if (r < 15) {
  32588. eobrun = receive(r) + (1 << r);
  32589. successiveACState = 4;
  32590. } else {
  32591. r = 16;
  32592. successiveACState = 1;
  32593. }
  32594. } else {
  32595. if (s !== 1) {
  32596. throw 'invalid ACn encoding';
  32597. }
  32598. successiveACNextValue = receiveAndExtend(s);
  32599. successiveACState = r ? 2 : 3;
  32600. }
  32601. continue;
  32602. case 1: // skipping r zero items
  32603. case 2:
  32604. if (component.blockData[offset + z]) {
  32605. component.blockData[offset + z] += (readBit() << successive);
  32606. } else {
  32607. r--;
  32608. if (r === 0) {
  32609. successiveACState = successiveACState === 2 ? 3 : 0;
  32610. }
  32611. }
  32612. break;
  32613. case 3: // set value for a zero item
  32614. if (component.blockData[offset + z]) {
  32615. component.blockData[offset + z] += (readBit() << successive);
  32616. } else {
  32617. component.blockData[offset + z] =
  32618. successiveACNextValue << successive;
  32619. successiveACState = 0;
  32620. }
  32621. break;
  32622. case 4: // eob
  32623. if (component.blockData[offset + z]) {
  32624. component.blockData[offset + z] += (readBit() << successive);
  32625. }
  32626. break;
  32627. }
  32628. k++;
  32629. }
  32630. if (successiveACState === 4) {
  32631. eobrun--;
  32632. if (eobrun === 0) {
  32633. successiveACState = 0;
  32634. }
  32635. }
  32636. }
  32637. function decodeMcu(component, decode, mcu, row, col) {
  32638. var mcuRow = (mcu / mcusPerLine) | 0;
  32639. var mcuCol = mcu % mcusPerLine;
  32640. var blockRow = mcuRow * component.v + row;
  32641. var blockCol = mcuCol * component.h + col;
  32642. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32643. decode(component, offset);
  32644. }
  32645. function decodeBlock(component, decode, mcu) {
  32646. var blockRow = (mcu / component.blocksPerLine) | 0;
  32647. var blockCol = mcu % component.blocksPerLine;
  32648. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32649. decode(component, offset);
  32650. }
  32651. var componentsLength = components.length;
  32652. var component, i, j, k, n;
  32653. var decodeFn;
  32654. if (progressive) {
  32655. if (spectralStart === 0) {
  32656. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32657. } else {
  32658. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32659. }
  32660. } else {
  32661. decodeFn = decodeBaseline;
  32662. }
  32663. var mcu = 0, marker;
  32664. var mcuExpected;
  32665. if (componentsLength === 1) {
  32666. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32667. } else {
  32668. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32669. }
  32670. if (!resetInterval) {
  32671. resetInterval = mcuExpected;
  32672. }
  32673. var h, v;
  32674. while (mcu < mcuExpected) {
  32675. // reset interval stuff
  32676. for (i = 0; i < componentsLength; i++) {
  32677. components[i].pred = 0;
  32678. }
  32679. eobrun = 0;
  32680. if (componentsLength === 1) {
  32681. component = components[0];
  32682. for (n = 0; n < resetInterval; n++) {
  32683. decodeBlock(component, decodeFn, mcu);
  32684. mcu++;
  32685. }
  32686. } else {
  32687. for (n = 0; n < resetInterval; n++) {
  32688. for (i = 0; i < componentsLength; i++) {
  32689. component = components[i];
  32690. h = component.h;
  32691. v = component.v;
  32692. for (j = 0; j < v; j++) {
  32693. for (k = 0; k < h; k++) {
  32694. decodeMcu(component, decodeFn, mcu, j, k);
  32695. }
  32696. }
  32697. }
  32698. mcu++;
  32699. }
  32700. }
  32701. // find marker
  32702. bitsCount = 0;
  32703. marker = (data[offset] << 8) | data[offset + 1];
  32704. if (marker <= 0xFF00) {
  32705. throw 'marker was not found';
  32706. }
  32707. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32708. offset += 2;
  32709. } else {
  32710. break;
  32711. }
  32712. }
  32713. return offset - startOffset;
  32714. }
  32715. // A port of poppler's IDCT method which in turn is taken from:
  32716. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32717. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32718. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32719. // 988-991.
  32720. function quantizeAndInverse(component, blockBufferOffset, p) {
  32721. var qt = component.quantizationTable, blockData = component.blockData;
  32722. var v0, v1, v2, v3, v4, v5, v6, v7;
  32723. var p0, p1, p2, p3, p4, p5, p6, p7;
  32724. var t;
  32725. // inverse DCT on rows
  32726. for (var row = 0; row < 64; row += 8) {
  32727. // gather block data
  32728. p0 = blockData[blockBufferOffset + row];
  32729. p1 = blockData[blockBufferOffset + row + 1];
  32730. p2 = blockData[blockBufferOffset + row + 2];
  32731. p3 = blockData[blockBufferOffset + row + 3];
  32732. p4 = blockData[blockBufferOffset + row + 4];
  32733. p5 = blockData[blockBufferOffset + row + 5];
  32734. p6 = blockData[blockBufferOffset + row + 6];
  32735. p7 = blockData[blockBufferOffset + row + 7];
  32736. // dequant p0
  32737. p0 *= qt[row];
  32738. // check for all-zero AC coefficients
  32739. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32740. t = (dctSqrt2 * p0 + 512) >> 10;
  32741. p[row] = t;
  32742. p[row + 1] = t;
  32743. p[row + 2] = t;
  32744. p[row + 3] = t;
  32745. p[row + 4] = t;
  32746. p[row + 5] = t;
  32747. p[row + 6] = t;
  32748. p[row + 7] = t;
  32749. continue;
  32750. }
  32751. // dequant p1 ... p7
  32752. p1 *= qt[row + 1];
  32753. p2 *= qt[row + 2];
  32754. p3 *= qt[row + 3];
  32755. p4 *= qt[row + 4];
  32756. p5 *= qt[row + 5];
  32757. p6 *= qt[row + 6];
  32758. p7 *= qt[row + 7];
  32759. // stage 4
  32760. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32761. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32762. v2 = p2;
  32763. v3 = p6;
  32764. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32765. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32766. v5 = p3 << 4;
  32767. v6 = p5 << 4;
  32768. // stage 3
  32769. v0 = (v0 + v1 + 1) >> 1;
  32770. v1 = v0 - v1;
  32771. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32772. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32773. v3 = t;
  32774. v4 = (v4 + v6 + 1) >> 1;
  32775. v6 = v4 - v6;
  32776. v7 = (v7 + v5 + 1) >> 1;
  32777. v5 = v7 - v5;
  32778. // stage 2
  32779. v0 = (v0 + v3 + 1) >> 1;
  32780. v3 = v0 - v3;
  32781. v1 = (v1 + v2 + 1) >> 1;
  32782. v2 = v1 - v2;
  32783. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32784. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32785. v7 = t;
  32786. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32787. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32788. v6 = t;
  32789. // stage 1
  32790. p[row] = v0 + v7;
  32791. p[row + 7] = v0 - v7;
  32792. p[row + 1] = v1 + v6;
  32793. p[row + 6] = v1 - v6;
  32794. p[row + 2] = v2 + v5;
  32795. p[row + 5] = v2 - v5;
  32796. p[row + 3] = v3 + v4;
  32797. p[row + 4] = v3 - v4;
  32798. }
  32799. // inverse DCT on columns
  32800. for (var col = 0; col < 8; ++col) {
  32801. p0 = p[col];
  32802. p1 = p[col + 8];
  32803. p2 = p[col + 16];
  32804. p3 = p[col + 24];
  32805. p4 = p[col + 32];
  32806. p5 = p[col + 40];
  32807. p6 = p[col + 48];
  32808. p7 = p[col + 56];
  32809. // check for all-zero AC coefficients
  32810. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32811. t = (dctSqrt2 * p0 + 8192) >> 14;
  32812. // convert to 8 bit
  32813. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32814. blockData[blockBufferOffset + col] = t;
  32815. blockData[blockBufferOffset + col + 8] = t;
  32816. blockData[blockBufferOffset + col + 16] = t;
  32817. blockData[blockBufferOffset + col + 24] = t;
  32818. blockData[blockBufferOffset + col + 32] = t;
  32819. blockData[blockBufferOffset + col + 40] = t;
  32820. blockData[blockBufferOffset + col + 48] = t;
  32821. blockData[blockBufferOffset + col + 56] = t;
  32822. continue;
  32823. }
  32824. // stage 4
  32825. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32826. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32827. v2 = p2;
  32828. v3 = p6;
  32829. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32830. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32831. v5 = p3;
  32832. v6 = p5;
  32833. // stage 3
  32834. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32835. // converting to UInt8 range later.
  32836. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32837. v1 = v0 - v1;
  32838. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32839. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32840. v3 = t;
  32841. v4 = (v4 + v6 + 1) >> 1;
  32842. v6 = v4 - v6;
  32843. v7 = (v7 + v5 + 1) >> 1;
  32844. v5 = v7 - v5;
  32845. // stage 2
  32846. v0 = (v0 + v3 + 1) >> 1;
  32847. v3 = v0 - v3;
  32848. v1 = (v1 + v2 + 1) >> 1;
  32849. v2 = v1 - v2;
  32850. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32851. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32852. v7 = t;
  32853. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32854. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32855. v6 = t;
  32856. // stage 1
  32857. p0 = v0 + v7;
  32858. p7 = v0 - v7;
  32859. p1 = v1 + v6;
  32860. p6 = v1 - v6;
  32861. p2 = v2 + v5;
  32862. p5 = v2 - v5;
  32863. p3 = v3 + v4;
  32864. p4 = v3 - v4;
  32865. // convert to 8-bit integers
  32866. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32867. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32868. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32869. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32870. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32871. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32872. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32873. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32874. // store block data
  32875. blockData[blockBufferOffset + col] = p0;
  32876. blockData[blockBufferOffset + col + 8] = p1;
  32877. blockData[blockBufferOffset + col + 16] = p2;
  32878. blockData[blockBufferOffset + col + 24] = p3;
  32879. blockData[blockBufferOffset + col + 32] = p4;
  32880. blockData[blockBufferOffset + col + 40] = p5;
  32881. blockData[blockBufferOffset + col + 48] = p6;
  32882. blockData[blockBufferOffset + col + 56] = p7;
  32883. }
  32884. }
  32885. function buildComponentData(frame, component) {
  32886. var blocksPerLine = component.blocksPerLine;
  32887. var blocksPerColumn = component.blocksPerColumn;
  32888. var computationBuffer = new Int16Array(64);
  32889. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32890. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32891. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32892. quantizeAndInverse(component, offset, computationBuffer);
  32893. }
  32894. }
  32895. return component.blockData;
  32896. }
  32897. function clamp0to255(a) {
  32898. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32899. }
  32900. constructor.prototype = {
  32901. parse: function parse(data) {
  32902. function readUint16() {
  32903. var value = (data[offset] << 8) | data[offset + 1];
  32904. offset += 2;
  32905. return value;
  32906. }
  32907. function readDataBlock() {
  32908. var length = readUint16();
  32909. var array = data.subarray(offset, offset + length - 2);
  32910. offset += array.length;
  32911. return array;
  32912. }
  32913. function prepareComponents(frame) {
  32914. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32915. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32916. for (var i = 0; i < frame.components.length; i++) {
  32917. component = frame.components[i];
  32918. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32919. component.h / frame.maxH);
  32920. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32921. component.v / frame.maxV);
  32922. var blocksPerLineForMcu = mcusPerLine * component.h;
  32923. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32924. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32925. (blocksPerLineForMcu + 1);
  32926. component.blockData = new Int16Array(blocksBufferSize);
  32927. component.blocksPerLine = blocksPerLine;
  32928. component.blocksPerColumn = blocksPerColumn;
  32929. }
  32930. frame.mcusPerLine = mcusPerLine;
  32931. frame.mcusPerColumn = mcusPerColumn;
  32932. }
  32933. var offset = 0, length = data.length;
  32934. var jfif = null;
  32935. var adobe = null;
  32936. var pixels = null;
  32937. var frame, resetInterval;
  32938. var quantizationTables = [];
  32939. var huffmanTablesAC = [], huffmanTablesDC = [];
  32940. var fileMarker = readUint16();
  32941. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32942. throw 'SOI not found';
  32943. }
  32944. fileMarker = readUint16();
  32945. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32946. var i, j, l;
  32947. switch(fileMarker) {
  32948. case 0xFFE0: // APP0 (Application Specific)
  32949. case 0xFFE1: // APP1
  32950. case 0xFFE2: // APP2
  32951. case 0xFFE3: // APP3
  32952. case 0xFFE4: // APP4
  32953. case 0xFFE5: // APP5
  32954. case 0xFFE6: // APP6
  32955. case 0xFFE7: // APP7
  32956. case 0xFFE8: // APP8
  32957. case 0xFFE9: // APP9
  32958. case 0xFFEA: // APP10
  32959. case 0xFFEB: // APP11
  32960. case 0xFFEC: // APP12
  32961. case 0xFFED: // APP13
  32962. case 0xFFEE: // APP14
  32963. case 0xFFEF: // APP15
  32964. case 0xFFFE: // COM (Comment)
  32965. var appData = readDataBlock();
  32966. if (fileMarker === 0xFFE0) {
  32967. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32968. appData[2] === 0x49 && appData[3] === 0x46 &&
  32969. appData[4] === 0) { // 'JFIF\x00'
  32970. jfif = {
  32971. version: { major: appData[5], minor: appData[6] },
  32972. densityUnits: appData[7],
  32973. xDensity: (appData[8] << 8) | appData[9],
  32974. yDensity: (appData[10] << 8) | appData[11],
  32975. thumbWidth: appData[12],
  32976. thumbHeight: appData[13],
  32977. thumbData: appData.subarray(14, 14 +
  32978. 3 * appData[12] * appData[13])
  32979. };
  32980. }
  32981. }
  32982. // TODO APP1 - Exif
  32983. if (fileMarker === 0xFFEE) {
  32984. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32985. appData[2] === 0x6F && appData[3] === 0x62 &&
  32986. appData[4] === 0x65) { // 'Adobe'
  32987. adobe = {
  32988. version: (appData[5] << 8) | appData[6],
  32989. flags0: (appData[7] << 8) | appData[8],
  32990. flags1: (appData[9] << 8) | appData[10],
  32991. transformCode: appData[11]
  32992. };
  32993. }
  32994. }
  32995. break;
  32996. case 0xFFDB: // DQT (Define Quantization Tables)
  32997. var quantizationTablesLength = readUint16();
  32998. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32999. var z;
  33000. while (offset < quantizationTablesEnd) {
  33001. var quantizationTableSpec = data[offset++];
  33002. var tableData = new Uint16Array(64);
  33003. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  33004. for (j = 0; j < 64; j++) {
  33005. z = dctZigZag[j];
  33006. tableData[z] = data[offset++];
  33007. }
  33008. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  33009. for (j = 0; j < 64; j++) {
  33010. z = dctZigZag[j];
  33011. tableData[z] = readUint16();
  33012. }
  33013. } else {
  33014. throw 'DQT: invalid table spec';
  33015. }
  33016. quantizationTables[quantizationTableSpec & 15] = tableData;
  33017. }
  33018. break;
  33019. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  33020. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  33021. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  33022. if (frame) {
  33023. throw 'Only single frame JPEGs supported';
  33024. }
  33025. readUint16(); // skip data length
  33026. frame = {};
  33027. frame.extended = (fileMarker === 0xFFC1);
  33028. frame.progressive = (fileMarker === 0xFFC2);
  33029. frame.precision = data[offset++];
  33030. frame.scanLines = readUint16();
  33031. frame.samplesPerLine = readUint16();
  33032. frame.components = [];
  33033. frame.componentIds = {};
  33034. var componentsCount = data[offset++], componentId;
  33035. var maxH = 0, maxV = 0;
  33036. for (i = 0; i < componentsCount; i++) {
  33037. componentId = data[offset];
  33038. var h = data[offset + 1] >> 4;
  33039. var v = data[offset + 1] & 15;
  33040. if (maxH < h) {
  33041. maxH = h;
  33042. }
  33043. if (maxV < v) {
  33044. maxV = v;
  33045. }
  33046. var qId = data[offset + 2];
  33047. l = frame.components.push({
  33048. h: h,
  33049. v: v,
  33050. quantizationTable: quantizationTables[qId]
  33051. });
  33052. frame.componentIds[componentId] = l - 1;
  33053. offset += 3;
  33054. }
  33055. frame.maxH = maxH;
  33056. frame.maxV = maxV;
  33057. prepareComponents(frame);
  33058. break;
  33059. case 0xFFC4: // DHT (Define Huffman Tables)
  33060. var huffmanLength = readUint16();
  33061. for (i = 2; i < huffmanLength;) {
  33062. var huffmanTableSpec = data[offset++];
  33063. var codeLengths = new Uint8Array(16);
  33064. var codeLengthSum = 0;
  33065. for (j = 0; j < 16; j++, offset++) {
  33066. codeLengthSum += (codeLengths[j] = data[offset]);
  33067. }
  33068. var huffmanValues = new Uint8Array(codeLengthSum);
  33069. for (j = 0; j < codeLengthSum; j++, offset++) {
  33070. huffmanValues[j] = data[offset];
  33071. }
  33072. i += 17 + codeLengthSum;
  33073. ((huffmanTableSpec >> 4) === 0 ?
  33074. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33075. buildHuffmanTable(codeLengths, huffmanValues);
  33076. }
  33077. break;
  33078. case 0xFFDD: // DRI (Define Restart Interval)
  33079. readUint16(); // skip data length
  33080. resetInterval = readUint16();
  33081. break;
  33082. case 0xFFDA: // SOS (Start of Scan)
  33083. var scanLength = readUint16();
  33084. var selectorsCount = data[offset++];
  33085. var components = [], component;
  33086. for (i = 0; i < selectorsCount; i++) {
  33087. var componentIndex = frame.componentIds[data[offset++]];
  33088. component = frame.components[componentIndex];
  33089. var tableSpec = data[offset++];
  33090. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33091. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33092. components.push(component);
  33093. }
  33094. var spectralStart = data[offset++];
  33095. var spectralEnd = data[offset++];
  33096. var successiveApproximation = data[offset++];
  33097. var processed = decodeScan(data, offset,
  33098. frame, components, resetInterval,
  33099. spectralStart, spectralEnd,
  33100. successiveApproximation >> 4, successiveApproximation & 15);
  33101. offset += processed;
  33102. break;
  33103. case 0xFFFF: // Fill bytes
  33104. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33105. offset--;
  33106. }
  33107. break;
  33108. default:
  33109. if (data[offset - 3] === 0xFF &&
  33110. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33111. // could be incorrect encoding -- last 0xFF byte of the previous
  33112. // block was eaten by the encoder
  33113. offset -= 3;
  33114. break;
  33115. }
  33116. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33117. }
  33118. fileMarker = readUint16();
  33119. }
  33120. this.width = frame.samplesPerLine;
  33121. this.height = frame.scanLines;
  33122. this.jfif = jfif;
  33123. this.adobe = adobe;
  33124. this.components = [];
  33125. for (i = 0; i < frame.components.length; i++) {
  33126. component = frame.components[i];
  33127. this.components.push({
  33128. output: buildComponentData(frame, component),
  33129. scaleX: component.h / frame.maxH,
  33130. scaleY: component.v / frame.maxV,
  33131. blocksPerLine: component.blocksPerLine,
  33132. blocksPerColumn: component.blocksPerColumn
  33133. });
  33134. }
  33135. this.numComponents = this.components.length;
  33136. },
  33137. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33138. var scaleX = this.width / width, scaleY = this.height / height;
  33139. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33140. var x, y, i, j, k;
  33141. var index;
  33142. var offset = 0;
  33143. var output;
  33144. var numComponents = this.components.length;
  33145. var dataLength = width * height * numComponents;
  33146. var data = new Uint8Array(dataLength);
  33147. var xScaleBlockOffset = new Uint32Array(width);
  33148. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33149. for (i = 0; i < numComponents; i++) {
  33150. component = this.components[i];
  33151. componentScaleX = component.scaleX * scaleX;
  33152. componentScaleY = component.scaleY * scaleY;
  33153. offset = i;
  33154. output = component.output;
  33155. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33156. // precalculate the xScaleBlockOffset
  33157. for (x = 0; x < width; x++) {
  33158. j = 0 | (x * componentScaleX);
  33159. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33160. }
  33161. // linearize the blocks of the component
  33162. for (y = 0; y < height; y++) {
  33163. j = 0 | (y * componentScaleY);
  33164. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33165. for (x = 0; x < width; x++) {
  33166. data[offset] = output[index + xScaleBlockOffset[x]];
  33167. offset += numComponents;
  33168. }
  33169. }
  33170. }
  33171. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33172. var transform = this.decodeTransform;
  33173. if (transform) {
  33174. for (i = 0; i < dataLength;) {
  33175. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33176. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33177. }
  33178. }
  33179. }
  33180. return data;
  33181. },
  33182. _isColorConversionNeeded: function isColorConversionNeeded() {
  33183. if (this.adobe && this.adobe.transformCode) {
  33184. // The adobe transform marker overrides any previous setting
  33185. return true;
  33186. } else if (this.numComponents === 3) {
  33187. return true;
  33188. } else {
  33189. return false;
  33190. }
  33191. },
  33192. _convertYccToRgb: function convertYccToRgb(data) {
  33193. var Y, Cb, Cr;
  33194. for (var i = 0, length = data.length; i < length; i += 3) {
  33195. Y = data[i ];
  33196. Cb = data[i + 1];
  33197. Cr = data[i + 2];
  33198. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33199. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33200. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33201. }
  33202. return data;
  33203. },
  33204. _convertYcckToRgb: function convertYcckToRgb(data) {
  33205. var Y, Cb, Cr, k;
  33206. var offset = 0;
  33207. for (var i = 0, length = data.length; i < length; i += 4) {
  33208. Y = data[i];
  33209. Cb = data[i + 1];
  33210. Cr = data[i + 2];
  33211. k = data[i + 3];
  33212. var r = -122.67195406894 +
  33213. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33214. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33215. 0.154362151871126) +
  33216. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33217. 0.00477271405408747 * k + 1.53380253221734) +
  33218. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33219. 0.48357088451265) +
  33220. k * (-0.000336197177618394 * k + 0.484791561490776);
  33221. var g = 107.268039397724 +
  33222. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33223. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33224. 0.176491792462875) +
  33225. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33226. 0.000770482631801132 * k - 0.151051492775562) +
  33227. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33228. 0.25802910206845) +
  33229. k * (-0.000318913117588328 * k - 0.213742400323665);
  33230. var b = -20.810012546947 +
  33231. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33232. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33233. 0.814272968359295) +
  33234. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33235. 0.000560833691242812 * k - 0.195152027534049) +
  33236. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33237. 0.116935020465145) +
  33238. k * (-0.000343531996510555 * k + 0.24165260232407);
  33239. data[offset++] = clamp0to255(r);
  33240. data[offset++] = clamp0to255(g);
  33241. data[offset++] = clamp0to255(b);
  33242. }
  33243. return data;
  33244. },
  33245. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33246. var Y, Cb, Cr;
  33247. for (var i = 0, length = data.length; i < length; i += 4) {
  33248. Y = data[i];
  33249. Cb = data[i + 1];
  33250. Cr = data[i + 2];
  33251. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33252. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33253. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33254. // K in data[i + 3] is unchanged
  33255. }
  33256. return data;
  33257. },
  33258. _convertCmykToRgb: function convertCmykToRgb(data) {
  33259. var c, m, y, k;
  33260. var offset = 0;
  33261. var min = -255 * 255 * 255;
  33262. var scale = 1 / 255 / 255;
  33263. for (var i = 0, length = data.length; i < length; i += 4) {
  33264. c = data[i];
  33265. m = data[i + 1];
  33266. y = data[i + 2];
  33267. k = data[i + 3];
  33268. var r =
  33269. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33270. 18.82290502165302 * y + 212.25662451639585 * k -
  33271. 72734.4411664936) +
  33272. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33273. 17.873870861415444 * k - 1401.7366389350734) +
  33274. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33275. 4465.541406466231) -
  33276. k * (21.86122147463605 * k + 48317.86113160301);
  33277. var g =
  33278. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33279. 6.871425592049007 * y + 31.159100130055922 * k -
  33280. 20220.756542821975) +
  33281. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33282. 131.35250912493976 * k - 48691.05921601825) +
  33283. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33284. 6341.191035517494) -
  33285. k * (20.737325471181034 * k + 47890.15695978492);
  33286. var b =
  33287. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33288. 30.89978309703729 * y - 0.23883238689178934 * k -
  33289. 3616.812083916688) +
  33290. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33291. 50.606957656360734 * k - 28620.90484698408) +
  33292. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33293. 49363.43385999684) -
  33294. k * (22.33816807309886 * k + 45932.16563550634);
  33295. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33296. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33297. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33298. }
  33299. return data;
  33300. },
  33301. getData: function getData(width, height, forceRGBoutput) {
  33302. if (this.numComponents > 4) {
  33303. throw 'Unsupported color mode';
  33304. }
  33305. // type of data: Uint8Array(width * height * numComponents)
  33306. var data = this._getLinearizedBlockData(width, height);
  33307. if (this.numComponents === 3) {
  33308. return this._convertYccToRgb(data);
  33309. } else if (this.numComponents === 4) {
  33310. if (this._isColorConversionNeeded()) {
  33311. if (forceRGBoutput) {
  33312. return this._convertYcckToRgb(data);
  33313. } else {
  33314. return this._convertYcckToCmyk(data);
  33315. }
  33316. } else if (forceRGBoutput) {
  33317. return this._convertCmykToRgb(data);
  33318. }
  33319. }
  33320. return data;
  33321. }
  33322. };
  33323. return constructor;
  33324. })();
  33325. var JpxImage = (function JpxImageClosure() {
  33326. // Table E.1
  33327. var SubbandsGainLog2 = {
  33328. 'LL': 0,
  33329. 'LH': 1,
  33330. 'HL': 1,
  33331. 'HH': 2
  33332. };
  33333. function JpxImage() {
  33334. this.failOnCorruptedImage = false;
  33335. }
  33336. JpxImage.prototype = {
  33337. parse: function JpxImage_parse(data) {
  33338. var head = readUint16(data, 0);
  33339. // No box header, immediate start of codestream (SOC)
  33340. if (head === 0xFF4F) {
  33341. this.parseCodestream(data, 0, data.length);
  33342. return;
  33343. }
  33344. var position = 0, length = data.length;
  33345. while (position < length) {
  33346. var headerSize = 8;
  33347. var lbox = readUint32(data, position);
  33348. var tbox = readUint32(data, position + 4);
  33349. position += headerSize;
  33350. if (lbox === 1) {
  33351. // XLBox: read UInt64 according to spec.
  33352. // JavaScript's int precision of 53 bit should be sufficient here.
  33353. lbox = readUint32(data, position) * 4294967296 +
  33354. readUint32(data, position + 4);
  33355. position += 8;
  33356. headerSize += 8;
  33357. }
  33358. if (lbox === 0) {
  33359. lbox = length - position + headerSize;
  33360. }
  33361. if (lbox < headerSize) {
  33362. throw new Error('JPX Error: Invalid box field size');
  33363. }
  33364. var dataLength = lbox - headerSize;
  33365. var jumpDataLength = true;
  33366. switch (tbox) {
  33367. case 0x6A703268: // 'jp2h'
  33368. jumpDataLength = false; // parsing child boxes
  33369. break;
  33370. case 0x636F6C72: // 'colr'
  33371. // Colorspaces are not used, the CS from the PDF is used.
  33372. var method = data[position];
  33373. var precedence = data[position + 1];
  33374. var approximation = data[position + 2];
  33375. if (method === 1) {
  33376. // enumerated colorspace
  33377. var colorspace = readUint32(data, position + 3);
  33378. switch (colorspace) {
  33379. case 16: // this indicates a sRGB colorspace
  33380. case 17: // this indicates a grayscale colorspace
  33381. case 18: // this indicates a YUV colorspace
  33382. break;
  33383. default:
  33384. warn('Unknown colorspace ' + colorspace);
  33385. break;
  33386. }
  33387. } else if (method === 2) {
  33388. info('ICC profile not supported');
  33389. }
  33390. break;
  33391. case 0x6A703263: // 'jp2c'
  33392. this.parseCodestream(data, position, position + dataLength);
  33393. break;
  33394. case 0x6A502020: // 'jP\024\024'
  33395. if (0x0d0a870a !== readUint32(data, position)) {
  33396. warn('Invalid JP2 signature');
  33397. }
  33398. break;
  33399. // The following header types are valid but currently not used:
  33400. case 0x6A501A1A: // 'jP\032\032'
  33401. case 0x66747970: // 'ftyp'
  33402. case 0x72726571: // 'rreq'
  33403. case 0x72657320: // 'res '
  33404. case 0x69686472: // 'ihdr'
  33405. break;
  33406. default:
  33407. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33408. (tbox >> 16) & 0xFF,
  33409. (tbox >> 8) & 0xFF,
  33410. tbox & 0xFF);
  33411. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33412. break;
  33413. }
  33414. if (jumpDataLength) {
  33415. position += dataLength;
  33416. }
  33417. }
  33418. },
  33419. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33420. var newByte = stream.getByte();
  33421. while (newByte >= 0) {
  33422. var oldByte = newByte;
  33423. newByte = stream.getByte();
  33424. var code = (oldByte << 8) | newByte;
  33425. // Image and tile size (SIZ)
  33426. if (code === 0xFF51) {
  33427. stream.skip(4);
  33428. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33429. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33430. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33431. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33432. stream.skip(16);
  33433. var Csiz = stream.getUint16(); // Byte 36
  33434. this.width = Xsiz - XOsiz;
  33435. this.height = Ysiz - YOsiz;
  33436. this.componentsCount = Csiz;
  33437. // Results are always returned as Uint8Arrays
  33438. this.bitsPerComponent = 8;
  33439. return;
  33440. }
  33441. }
  33442. throw new Error('JPX Error: No size marker found in JPX stream');
  33443. },
  33444. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33445. var context = {};
  33446. try {
  33447. var doNotRecover = false;
  33448. var position = start;
  33449. while (position + 1 < end) {
  33450. var code = readUint16(data, position);
  33451. position += 2;
  33452. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33453. switch (code) {
  33454. case 0xFF4F: // Start of codestream (SOC)
  33455. context.mainHeader = true;
  33456. break;
  33457. case 0xFFD9: // End of codestream (EOC)
  33458. break;
  33459. case 0xFF51: // Image and tile size (SIZ)
  33460. length = readUint16(data, position);
  33461. var siz = {};
  33462. siz.Xsiz = readUint32(data, position + 4);
  33463. siz.Ysiz = readUint32(data, position + 8);
  33464. siz.XOsiz = readUint32(data, position + 12);
  33465. siz.YOsiz = readUint32(data, position + 16);
  33466. siz.XTsiz = readUint32(data, position + 20);
  33467. siz.YTsiz = readUint32(data, position + 24);
  33468. siz.XTOsiz = readUint32(data, position + 28);
  33469. siz.YTOsiz = readUint32(data, position + 32);
  33470. var componentsCount = readUint16(data, position + 36);
  33471. siz.Csiz = componentsCount;
  33472. var components = [];
  33473. j = position + 38;
  33474. for (var i = 0; i < componentsCount; i++) {
  33475. var component = {
  33476. precision: (data[j] & 0x7F) + 1,
  33477. isSigned: !!(data[j] & 0x80),
  33478. XRsiz: data[j + 1],
  33479. YRsiz: data[j + 1]
  33480. };
  33481. calculateComponentDimensions(component, siz);
  33482. components.push(component);
  33483. }
  33484. context.SIZ = siz;
  33485. context.components = components;
  33486. calculateTileGrids(context, components);
  33487. context.QCC = [];
  33488. context.COC = [];
  33489. break;
  33490. case 0xFF5C: // Quantization default (QCD)
  33491. length = readUint16(data, position);
  33492. var qcd = {};
  33493. j = position + 2;
  33494. sqcd = data[j++];
  33495. switch (sqcd & 0x1F) {
  33496. case 0:
  33497. spqcdSize = 8;
  33498. scalarExpounded = true;
  33499. break;
  33500. case 1:
  33501. spqcdSize = 16;
  33502. scalarExpounded = false;
  33503. break;
  33504. case 2:
  33505. spqcdSize = 16;
  33506. scalarExpounded = true;
  33507. break;
  33508. default:
  33509. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33510. }
  33511. qcd.noQuantization = (spqcdSize === 8);
  33512. qcd.scalarExpounded = scalarExpounded;
  33513. qcd.guardBits = sqcd >> 5;
  33514. spqcds = [];
  33515. while (j < length + position) {
  33516. var spqcd = {};
  33517. if (spqcdSize === 8) {
  33518. spqcd.epsilon = data[j++] >> 3;
  33519. spqcd.mu = 0;
  33520. } else {
  33521. spqcd.epsilon = data[j] >> 3;
  33522. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33523. j += 2;
  33524. }
  33525. spqcds.push(spqcd);
  33526. }
  33527. qcd.SPqcds = spqcds;
  33528. if (context.mainHeader) {
  33529. context.QCD = qcd;
  33530. } else {
  33531. context.currentTile.QCD = qcd;
  33532. context.currentTile.QCC = [];
  33533. }
  33534. break;
  33535. case 0xFF5D: // Quantization component (QCC)
  33536. length = readUint16(data, position);
  33537. var qcc = {};
  33538. j = position + 2;
  33539. var cqcc;
  33540. if (context.SIZ.Csiz < 257) {
  33541. cqcc = data[j++];
  33542. } else {
  33543. cqcc = readUint16(data, j);
  33544. j += 2;
  33545. }
  33546. sqcd = data[j++];
  33547. switch (sqcd & 0x1F) {
  33548. case 0:
  33549. spqcdSize = 8;
  33550. scalarExpounded = true;
  33551. break;
  33552. case 1:
  33553. spqcdSize = 16;
  33554. scalarExpounded = false;
  33555. break;
  33556. case 2:
  33557. spqcdSize = 16;
  33558. scalarExpounded = true;
  33559. break;
  33560. default:
  33561. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33562. }
  33563. qcc.noQuantization = (spqcdSize === 8);
  33564. qcc.scalarExpounded = scalarExpounded;
  33565. qcc.guardBits = sqcd >> 5;
  33566. spqcds = [];
  33567. while (j < (length + position)) {
  33568. spqcd = {};
  33569. if (spqcdSize === 8) {
  33570. spqcd.epsilon = data[j++] >> 3;
  33571. spqcd.mu = 0;
  33572. } else {
  33573. spqcd.epsilon = data[j] >> 3;
  33574. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33575. j += 2;
  33576. }
  33577. spqcds.push(spqcd);
  33578. }
  33579. qcc.SPqcds = spqcds;
  33580. if (context.mainHeader) {
  33581. context.QCC[cqcc] = qcc;
  33582. } else {
  33583. context.currentTile.QCC[cqcc] = qcc;
  33584. }
  33585. break;
  33586. case 0xFF52: // Coding style default (COD)
  33587. length = readUint16(data, position);
  33588. var cod = {};
  33589. j = position + 2;
  33590. var scod = data[j++];
  33591. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33592. cod.sopMarkerUsed = !!(scod & 2);
  33593. cod.ephMarkerUsed = !!(scod & 4);
  33594. cod.progressionOrder = data[j++];
  33595. cod.layersCount = readUint16(data, j);
  33596. j += 2;
  33597. cod.multipleComponentTransform = data[j++];
  33598. cod.decompositionLevelsCount = data[j++];
  33599. cod.xcb = (data[j++] & 0xF) + 2;
  33600. cod.ycb = (data[j++] & 0xF) + 2;
  33601. var blockStyle = data[j++];
  33602. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33603. cod.resetContextProbabilities = !!(blockStyle & 2);
  33604. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33605. cod.verticalyStripe = !!(blockStyle & 8);
  33606. cod.predictableTermination = !!(blockStyle & 16);
  33607. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33608. cod.reversibleTransformation = data[j++];
  33609. if (cod.entropyCoderWithCustomPrecincts) {
  33610. var precinctsSizes = [];
  33611. while (j < length + position) {
  33612. var precinctsSize = data[j++];
  33613. precinctsSizes.push({
  33614. PPx: precinctsSize & 0xF,
  33615. PPy: precinctsSize >> 4
  33616. });
  33617. }
  33618. cod.precinctsSizes = precinctsSizes;
  33619. }
  33620. var unsupported = [];
  33621. if (cod.selectiveArithmeticCodingBypass) {
  33622. unsupported.push('selectiveArithmeticCodingBypass');
  33623. }
  33624. if (cod.resetContextProbabilities) {
  33625. unsupported.push('resetContextProbabilities');
  33626. }
  33627. if (cod.terminationOnEachCodingPass) {
  33628. unsupported.push('terminationOnEachCodingPass');
  33629. }
  33630. if (cod.verticalyStripe) {
  33631. unsupported.push('verticalyStripe');
  33632. }
  33633. if (cod.predictableTermination) {
  33634. unsupported.push('predictableTermination');
  33635. }
  33636. if (unsupported.length > 0) {
  33637. doNotRecover = true;
  33638. throw new Error('JPX Error: Unsupported COD options (' +
  33639. unsupported.join(', ') + ')');
  33640. }
  33641. if (context.mainHeader) {
  33642. context.COD = cod;
  33643. } else {
  33644. context.currentTile.COD = cod;
  33645. context.currentTile.COC = [];
  33646. }
  33647. break;
  33648. case 0xFF90: // Start of tile-part (SOT)
  33649. length = readUint16(data, position);
  33650. tile = {};
  33651. tile.index = readUint16(data, position + 2);
  33652. tile.length = readUint32(data, position + 4);
  33653. tile.dataEnd = tile.length + position - 2;
  33654. tile.partIndex = data[position + 8];
  33655. tile.partsCount = data[position + 9];
  33656. context.mainHeader = false;
  33657. if (tile.partIndex === 0) {
  33658. // reset component specific settings
  33659. tile.COD = context.COD;
  33660. tile.COC = context.COC.slice(0); // clone of the global COC
  33661. tile.QCD = context.QCD;
  33662. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33663. }
  33664. context.currentTile = tile;
  33665. break;
  33666. case 0xFF93: // Start of data (SOD)
  33667. tile = context.currentTile;
  33668. if (tile.partIndex === 0) {
  33669. initializeTile(context, tile.index);
  33670. buildPackets(context);
  33671. }
  33672. // moving to the end of the data
  33673. length = tile.dataEnd - position;
  33674. parseTilePackets(context, data, position, length);
  33675. break;
  33676. case 0xFF55: // Tile-part lengths, main header (TLM)
  33677. case 0xFF57: // Packet length, main header (PLM)
  33678. case 0xFF58: // Packet length, tile-part header (PLT)
  33679. case 0xFF64: // Comment (COM)
  33680. length = readUint16(data, position);
  33681. // skipping content
  33682. break;
  33683. case 0xFF53: // Coding style component (COC)
  33684. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33685. 'not implemented');
  33686. default:
  33687. throw new Error('JPX Error: Unknown codestream code: ' +
  33688. code.toString(16));
  33689. }
  33690. position += length;
  33691. }
  33692. } catch (e) {
  33693. if (doNotRecover || this.failOnCorruptedImage) {
  33694. throw e;
  33695. } else {
  33696. warn('Trying to recover from ' + e.message);
  33697. }
  33698. }
  33699. this.tiles = transformComponents(context);
  33700. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33701. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33702. this.componentsCount = context.SIZ.Csiz;
  33703. }
  33704. };
  33705. function calculateComponentDimensions(component, siz) {
  33706. // Section B.2 Component mapping
  33707. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33708. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33709. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33710. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33711. component.width = component.x1 - component.x0;
  33712. component.height = component.y1 - component.y0;
  33713. }
  33714. function calculateTileGrids(context, components) {
  33715. var siz = context.SIZ;
  33716. // Section B.3 Division into tile and tile-components
  33717. var tile, tiles = [];
  33718. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33719. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33720. for (var q = 0; q < numYtiles; q++) {
  33721. for (var p = 0; p < numXtiles; p++) {
  33722. tile = {};
  33723. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33724. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33725. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33726. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33727. tile.width = tile.tx1 - tile.tx0;
  33728. tile.height = tile.ty1 - tile.ty0;
  33729. tile.components = [];
  33730. tiles.push(tile);
  33731. }
  33732. }
  33733. context.tiles = tiles;
  33734. var componentsCount = siz.Csiz;
  33735. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33736. var component = components[i];
  33737. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33738. var tileComponent = {};
  33739. tile = tiles[j];
  33740. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33741. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33742. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33743. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33744. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33745. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33746. tile.components[i] = tileComponent;
  33747. }
  33748. }
  33749. }
  33750. function getBlocksDimensions(context, component, r) {
  33751. var codOrCoc = component.codingStyleParameters;
  33752. var result = {};
  33753. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33754. result.PPx = 15;
  33755. result.PPy = 15;
  33756. } else {
  33757. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33758. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33759. }
  33760. // calculate codeblock size as described in section B.7
  33761. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33762. Math.min(codOrCoc.xcb, result.PPx));
  33763. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33764. Math.min(codOrCoc.ycb, result.PPy));
  33765. return result;
  33766. }
  33767. function buildPrecincts(context, resolution, dimensions) {
  33768. // Section B.6 Division resolution to precincts
  33769. var precinctWidth = 1 << dimensions.PPx;
  33770. var precinctHeight = 1 << dimensions.PPy;
  33771. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33772. // to precincts. Precinct partition divides a resolution according to width
  33773. // and height parameters. The subband that belongs to the resolution level
  33774. // has a different size than the level, unless it is the zero resolution.
  33775. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33776. // The precinct partitioning for a particular subband is derived from a
  33777. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33778. // resolution level)... The LL band associated with each resolution level is
  33779. // divided into precincts... Each of the resulting precinct regions is then
  33780. // mapped into its child subbands (if any) at the next lower resolution
  33781. // level. This is accomplished by using the coordinate transformation
  33782. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33783. // coordinates of a point in the LL band and child subband, respectively.
  33784. var isZeroRes = resolution.resLevel === 0;
  33785. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33786. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33787. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33788. Math.ceil(resolution.trx1 / precinctWidth) -
  33789. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33790. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33791. Math.ceil(resolution.try1 / precinctHeight) -
  33792. Math.floor(resolution.try0 / precinctHeight) : 0);
  33793. var numprecincts = numprecinctswide * numprecinctshigh;
  33794. resolution.precinctParameters = {
  33795. precinctWidth: precinctWidth,
  33796. precinctHeight: precinctHeight,
  33797. numprecinctswide: numprecinctswide,
  33798. numprecinctshigh: numprecinctshigh,
  33799. numprecincts: numprecincts,
  33800. precinctWidthInSubband: precinctWidthInSubband,
  33801. precinctHeightInSubband: precinctHeightInSubband
  33802. };
  33803. }
  33804. function buildCodeblocks(context, subband, dimensions) {
  33805. // Section B.7 Division sub-band into code-blocks
  33806. var xcb_ = dimensions.xcb_;
  33807. var ycb_ = dimensions.ycb_;
  33808. var codeblockWidth = 1 << xcb_;
  33809. var codeblockHeight = 1 << ycb_;
  33810. var cbx0 = subband.tbx0 >> xcb_;
  33811. var cby0 = subband.tby0 >> ycb_;
  33812. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33813. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33814. var precinctParameters = subband.resolution.precinctParameters;
  33815. var codeblocks = [];
  33816. var precincts = [];
  33817. var i, j, codeblock, precinctNumber;
  33818. for (j = cby0; j < cby1; j++) {
  33819. for (i = cbx0; i < cbx1; i++) {
  33820. codeblock = {
  33821. cbx: i,
  33822. cby: j,
  33823. tbx0: codeblockWidth * i,
  33824. tby0: codeblockHeight * j,
  33825. tbx1: codeblockWidth * (i + 1),
  33826. tby1: codeblockHeight * (j + 1)
  33827. };
  33828. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33829. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33830. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33831. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33832. // Calculate precinct number for this codeblock, codeblock position
  33833. // should be relative to its subband, use actual dimension and position
  33834. // See comment about codeblock group width and height
  33835. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33836. precinctParameters.precinctWidthInSubband);
  33837. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33838. precinctParameters.precinctHeightInSubband);
  33839. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33840. codeblock.precinctNumber = precinctNumber;
  33841. codeblock.subbandType = subband.type;
  33842. codeblock.Lblock = 3;
  33843. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33844. codeblock.tby1_ <= codeblock.tby0_) {
  33845. continue;
  33846. }
  33847. codeblocks.push(codeblock);
  33848. // building precinct for the sub-band
  33849. var precinct = precincts[precinctNumber];
  33850. if (precinct !== undefined) {
  33851. if (i < precinct.cbxMin) {
  33852. precinct.cbxMin = i;
  33853. } else if (i > precinct.cbxMax) {
  33854. precinct.cbxMax = i;
  33855. }
  33856. if (j < precinct.cbyMin) {
  33857. precinct.cbxMin = j;
  33858. } else if (j > precinct.cbyMax) {
  33859. precinct.cbyMax = j;
  33860. }
  33861. } else {
  33862. precincts[precinctNumber] = precinct = {
  33863. cbxMin: i,
  33864. cbyMin: j,
  33865. cbxMax: i,
  33866. cbyMax: j
  33867. };
  33868. }
  33869. codeblock.precinct = precinct;
  33870. }
  33871. }
  33872. subband.codeblockParameters = {
  33873. codeblockWidth: xcb_,
  33874. codeblockHeight: ycb_,
  33875. numcodeblockwide: cbx1 - cbx0 + 1,
  33876. numcodeblockhigh: cby1 - cby0 + 1
  33877. };
  33878. subband.codeblocks = codeblocks;
  33879. subband.precincts = precincts;
  33880. }
  33881. function createPacket(resolution, precinctNumber, layerNumber) {
  33882. var precinctCodeblocks = [];
  33883. // Section B.10.8 Order of info in packet
  33884. var subbands = resolution.subbands;
  33885. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33886. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33887. var subband = subbands[i];
  33888. var codeblocks = subband.codeblocks;
  33889. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33890. var codeblock = codeblocks[j];
  33891. if (codeblock.precinctNumber !== precinctNumber) {
  33892. continue;
  33893. }
  33894. precinctCodeblocks.push(codeblock);
  33895. }
  33896. }
  33897. return {
  33898. layerNumber: layerNumber,
  33899. codeblocks: precinctCodeblocks
  33900. };
  33901. }
  33902. function LayerResolutionComponentPositionIterator(context) {
  33903. var siz = context.SIZ;
  33904. var tileIndex = context.currentTile.index;
  33905. var tile = context.tiles[tileIndex];
  33906. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33907. var componentsCount = siz.Csiz;
  33908. var maxDecompositionLevelsCount = 0;
  33909. for (var q = 0; q < componentsCount; q++) {
  33910. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33911. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33912. }
  33913. var l = 0, r = 0, i = 0, k = 0;
  33914. this.nextPacket = function JpxImage_nextPacket() {
  33915. // Section B.12.1.1 Layer-resolution-component-position
  33916. for (; l < layersCount; l++) {
  33917. for (; r <= maxDecompositionLevelsCount; r++) {
  33918. for (; i < componentsCount; i++) {
  33919. var component = tile.components[i];
  33920. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33921. continue;
  33922. }
  33923. var resolution = component.resolutions[r];
  33924. var numprecincts = resolution.precinctParameters.numprecincts;
  33925. for (; k < numprecincts;) {
  33926. var packet = createPacket(resolution, k, l);
  33927. k++;
  33928. return packet;
  33929. }
  33930. k = 0;
  33931. }
  33932. i = 0;
  33933. }
  33934. r = 0;
  33935. }
  33936. throw new Error('JPX Error: Out of packets');
  33937. };
  33938. }
  33939. function ResolutionLayerComponentPositionIterator(context) {
  33940. var siz = context.SIZ;
  33941. var tileIndex = context.currentTile.index;
  33942. var tile = context.tiles[tileIndex];
  33943. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33944. var componentsCount = siz.Csiz;
  33945. var maxDecompositionLevelsCount = 0;
  33946. for (var q = 0; q < componentsCount; q++) {
  33947. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33948. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33949. }
  33950. var r = 0, l = 0, i = 0, k = 0;
  33951. this.nextPacket = function JpxImage_nextPacket() {
  33952. // Section B.12.1.2 Resolution-layer-component-position
  33953. for (; r <= maxDecompositionLevelsCount; r++) {
  33954. for (; l < layersCount; l++) {
  33955. for (; i < componentsCount; i++) {
  33956. var component = tile.components[i];
  33957. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33958. continue;
  33959. }
  33960. var resolution = component.resolutions[r];
  33961. var numprecincts = resolution.precinctParameters.numprecincts;
  33962. for (; k < numprecincts;) {
  33963. var packet = createPacket(resolution, k, l);
  33964. k++;
  33965. return packet;
  33966. }
  33967. k = 0;
  33968. }
  33969. i = 0;
  33970. }
  33971. l = 0;
  33972. }
  33973. throw new Error('JPX Error: Out of packets');
  33974. };
  33975. }
  33976. function ResolutionPositionComponentLayerIterator(context) {
  33977. var siz = context.SIZ;
  33978. var tileIndex = context.currentTile.index;
  33979. var tile = context.tiles[tileIndex];
  33980. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33981. var componentsCount = siz.Csiz;
  33982. var l, r, c, p;
  33983. var maxDecompositionLevelsCount = 0;
  33984. for (c = 0; c < componentsCount; c++) {
  33985. var component = tile.components[c];
  33986. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33987. component.codingStyleParameters.decompositionLevelsCount);
  33988. }
  33989. var maxNumPrecinctsInLevel = new Int32Array(
  33990. maxDecompositionLevelsCount + 1);
  33991. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33992. var maxNumPrecincts = 0;
  33993. for (c = 0; c < componentsCount; ++c) {
  33994. var resolutions = tile.components[c].resolutions;
  33995. if (r < resolutions.length) {
  33996. maxNumPrecincts = Math.max(maxNumPrecincts,
  33997. resolutions[r].precinctParameters.numprecincts);
  33998. }
  33999. }
  34000. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  34001. }
  34002. l = 0;
  34003. r = 0;
  34004. c = 0;
  34005. p = 0;
  34006. this.nextPacket = function JpxImage_nextPacket() {
  34007. // Section B.12.1.3 Resolution-position-component-layer
  34008. for (; r <= maxDecompositionLevelsCount; r++) {
  34009. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  34010. for (; c < componentsCount; c++) {
  34011. var component = tile.components[c];
  34012. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34013. continue;
  34014. }
  34015. var resolution = component.resolutions[r];
  34016. var numprecincts = resolution.precinctParameters.numprecincts;
  34017. if (p >= numprecincts) {
  34018. continue;
  34019. }
  34020. for (; l < layersCount;) {
  34021. var packet = createPacket(resolution, p, l);
  34022. l++;
  34023. return packet;
  34024. }
  34025. l = 0;
  34026. }
  34027. c = 0;
  34028. }
  34029. p = 0;
  34030. }
  34031. throw new Error('JPX Error: Out of packets');
  34032. };
  34033. }
  34034. function PositionComponentResolutionLayerIterator(context) {
  34035. var siz = context.SIZ;
  34036. var tileIndex = context.currentTile.index;
  34037. var tile = context.tiles[tileIndex];
  34038. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34039. var componentsCount = siz.Csiz;
  34040. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34041. var precinctsIterationSizes = precinctsSizes;
  34042. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34043. this.nextPacket = function JpxImage_nextPacket() {
  34044. // Section B.12.1.4 Position-component-resolution-layer
  34045. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34046. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34047. for (; c < componentsCount; c++) {
  34048. var component = tile.components[c];
  34049. var decompositionLevelsCount =
  34050. component.codingStyleParameters.decompositionLevelsCount;
  34051. for (; r <= decompositionLevelsCount; r++) {
  34052. var resolution = component.resolutions[r];
  34053. var sizeInImageScale =
  34054. precinctsSizes.components[c].resolutions[r];
  34055. var k = getPrecinctIndexIfExist(
  34056. px,
  34057. py,
  34058. sizeInImageScale,
  34059. precinctsIterationSizes,
  34060. resolution);
  34061. if (k === null) {
  34062. continue;
  34063. }
  34064. for (; l < layersCount;) {
  34065. var packet = createPacket(resolution, k, l);
  34066. l++;
  34067. return packet;
  34068. }
  34069. l = 0;
  34070. }
  34071. r = 0;
  34072. }
  34073. c = 0;
  34074. }
  34075. px = 0;
  34076. }
  34077. throw new Error('JPX Error: Out of packets');
  34078. };
  34079. }
  34080. function ComponentPositionResolutionLayerIterator(context) {
  34081. var siz = context.SIZ;
  34082. var tileIndex = context.currentTile.index;
  34083. var tile = context.tiles[tileIndex];
  34084. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34085. var componentsCount = siz.Csiz;
  34086. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34087. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34088. this.nextPacket = function JpxImage_nextPacket() {
  34089. // Section B.12.1.5 Component-position-resolution-layer
  34090. for (; c < componentsCount; ++c) {
  34091. var component = tile.components[c];
  34092. var precinctsIterationSizes = precinctsSizes.components[c];
  34093. var decompositionLevelsCount =
  34094. component.codingStyleParameters.decompositionLevelsCount;
  34095. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34096. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34097. for (; r <= decompositionLevelsCount; r++) {
  34098. var resolution = component.resolutions[r];
  34099. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34100. var k = getPrecinctIndexIfExist(
  34101. px,
  34102. py,
  34103. sizeInImageScale,
  34104. precinctsIterationSizes,
  34105. resolution);
  34106. if (k === null) {
  34107. continue;
  34108. }
  34109. for (; l < layersCount;) {
  34110. var packet = createPacket(resolution, k, l);
  34111. l++;
  34112. return packet;
  34113. }
  34114. l = 0;
  34115. }
  34116. r = 0;
  34117. }
  34118. px = 0;
  34119. }
  34120. py = 0;
  34121. }
  34122. throw new Error('JPX Error: Out of packets');
  34123. };
  34124. }
  34125. function getPrecinctIndexIfExist(
  34126. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34127. var posX = pxIndex * precinctIterationSizes.minWidth;
  34128. var posY = pyIndex * precinctIterationSizes.minHeight;
  34129. if (posX % sizeInImageScale.width !== 0 ||
  34130. posY % sizeInImageScale.height !== 0) {
  34131. return null;
  34132. }
  34133. var startPrecinctRowIndex =
  34134. (posY / sizeInImageScale.width) *
  34135. resolution.precinctParameters.numprecinctswide;
  34136. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34137. }
  34138. function getPrecinctSizesInImageScale(tile) {
  34139. var componentsCount = tile.components.length;
  34140. var minWidth = Number.MAX_VALUE;
  34141. var minHeight = Number.MAX_VALUE;
  34142. var maxNumWide = 0;
  34143. var maxNumHigh = 0;
  34144. var sizePerComponent = new Array(componentsCount);
  34145. for (var c = 0; c < componentsCount; c++) {
  34146. var component = tile.components[c];
  34147. var decompositionLevelsCount =
  34148. component.codingStyleParameters.decompositionLevelsCount;
  34149. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34150. var minWidthCurrentComponent = Number.MAX_VALUE;
  34151. var minHeightCurrentComponent = Number.MAX_VALUE;
  34152. var maxNumWideCurrentComponent = 0;
  34153. var maxNumHighCurrentComponent = 0;
  34154. var scale = 1;
  34155. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34156. var resolution = component.resolutions[r];
  34157. var widthCurrentResolution =
  34158. scale * resolution.precinctParameters.precinctWidth;
  34159. var heightCurrentResolution =
  34160. scale * resolution.precinctParameters.precinctHeight;
  34161. minWidthCurrentComponent = Math.min(
  34162. minWidthCurrentComponent,
  34163. widthCurrentResolution);
  34164. minHeightCurrentComponent = Math.min(
  34165. minHeightCurrentComponent,
  34166. heightCurrentResolution);
  34167. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34168. resolution.precinctParameters.numprecinctswide);
  34169. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34170. resolution.precinctParameters.numprecinctshigh);
  34171. sizePerResolution[r] = {
  34172. width: widthCurrentResolution,
  34173. height: heightCurrentResolution
  34174. };
  34175. scale <<= 1;
  34176. }
  34177. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34178. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34179. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34180. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34181. sizePerComponent[c] = {
  34182. resolutions: sizePerResolution,
  34183. minWidth: minWidthCurrentComponent,
  34184. minHeight: minHeightCurrentComponent,
  34185. maxNumWide: maxNumWideCurrentComponent,
  34186. maxNumHigh: maxNumHighCurrentComponent
  34187. };
  34188. }
  34189. return {
  34190. components: sizePerComponent,
  34191. minWidth: minWidth,
  34192. minHeight: minHeight,
  34193. maxNumWide: maxNumWide,
  34194. maxNumHigh: maxNumHigh
  34195. };
  34196. }
  34197. function buildPackets(context) {
  34198. var siz = context.SIZ;
  34199. var tileIndex = context.currentTile.index;
  34200. var tile = context.tiles[tileIndex];
  34201. var componentsCount = siz.Csiz;
  34202. // Creating resolutions and sub-bands for each component
  34203. for (var c = 0; c < componentsCount; c++) {
  34204. var component = tile.components[c];
  34205. var decompositionLevelsCount =
  34206. component.codingStyleParameters.decompositionLevelsCount;
  34207. // Section B.5 Resolution levels and sub-bands
  34208. var resolutions = [];
  34209. var subbands = [];
  34210. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34211. var blocksDimensions = getBlocksDimensions(context, component, r);
  34212. var resolution = {};
  34213. var scale = 1 << (decompositionLevelsCount - r);
  34214. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34215. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34216. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34217. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34218. resolution.resLevel = r;
  34219. buildPrecincts(context, resolution, blocksDimensions);
  34220. resolutions.push(resolution);
  34221. var subband;
  34222. if (r === 0) {
  34223. // one sub-band (LL) with last decomposition
  34224. subband = {};
  34225. subband.type = 'LL';
  34226. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34227. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34228. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34229. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34230. subband.resolution = resolution;
  34231. buildCodeblocks(context, subband, blocksDimensions);
  34232. subbands.push(subband);
  34233. resolution.subbands = [subband];
  34234. } else {
  34235. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34236. var resolutionSubbands = [];
  34237. // three sub-bands (HL, LH and HH) with rest of decompositions
  34238. subband = {};
  34239. subband.type = 'HL';
  34240. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34241. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34242. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34243. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34244. subband.resolution = resolution;
  34245. buildCodeblocks(context, subband, blocksDimensions);
  34246. subbands.push(subband);
  34247. resolutionSubbands.push(subband);
  34248. subband = {};
  34249. subband.type = 'LH';
  34250. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34251. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34252. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34253. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34254. subband.resolution = resolution;
  34255. buildCodeblocks(context, subband, blocksDimensions);
  34256. subbands.push(subband);
  34257. resolutionSubbands.push(subband);
  34258. subband = {};
  34259. subband.type = 'HH';
  34260. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34261. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34262. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34263. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34264. subband.resolution = resolution;
  34265. buildCodeblocks(context, subband, blocksDimensions);
  34266. subbands.push(subband);
  34267. resolutionSubbands.push(subband);
  34268. resolution.subbands = resolutionSubbands;
  34269. }
  34270. }
  34271. component.resolutions = resolutions;
  34272. component.subbands = subbands;
  34273. }
  34274. // Generate the packets sequence
  34275. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34276. switch (progressionOrder) {
  34277. case 0:
  34278. tile.packetsIterator =
  34279. new LayerResolutionComponentPositionIterator(context);
  34280. break;
  34281. case 1:
  34282. tile.packetsIterator =
  34283. new ResolutionLayerComponentPositionIterator(context);
  34284. break;
  34285. case 2:
  34286. tile.packetsIterator =
  34287. new ResolutionPositionComponentLayerIterator(context);
  34288. break;
  34289. case 3:
  34290. tile.packetsIterator =
  34291. new PositionComponentResolutionLayerIterator(context);
  34292. break;
  34293. case 4:
  34294. tile.packetsIterator =
  34295. new ComponentPositionResolutionLayerIterator(context);
  34296. break;
  34297. default:
  34298. throw new Error('JPX Error: Unsupported progression order ' +
  34299. progressionOrder);
  34300. }
  34301. }
  34302. function parseTilePackets(context, data, offset, dataLength) {
  34303. var position = 0;
  34304. var buffer, bufferSize = 0, skipNextBit = false;
  34305. function readBits(count) {
  34306. while (bufferSize < count) {
  34307. var b = data[offset + position];
  34308. position++;
  34309. if (skipNextBit) {
  34310. buffer = (buffer << 7) | b;
  34311. bufferSize += 7;
  34312. skipNextBit = false;
  34313. } else {
  34314. buffer = (buffer << 8) | b;
  34315. bufferSize += 8;
  34316. }
  34317. if (b === 0xFF) {
  34318. skipNextBit = true;
  34319. }
  34320. }
  34321. bufferSize -= count;
  34322. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34323. }
  34324. function skipMarkerIfEqual(value) {
  34325. if (data[offset + position - 1] === 0xFF &&
  34326. data[offset + position] === value) {
  34327. skipBytes(1);
  34328. return true;
  34329. } else if (data[offset + position] === 0xFF &&
  34330. data[offset + position + 1] === value) {
  34331. skipBytes(2);
  34332. return true;
  34333. }
  34334. return false;
  34335. }
  34336. function skipBytes(count) {
  34337. position += count;
  34338. }
  34339. function alignToByte() {
  34340. bufferSize = 0;
  34341. if (skipNextBit) {
  34342. position++;
  34343. skipNextBit = false;
  34344. }
  34345. }
  34346. function readCodingpasses() {
  34347. if (readBits(1) === 0) {
  34348. return 1;
  34349. }
  34350. if (readBits(1) === 0) {
  34351. return 2;
  34352. }
  34353. var value = readBits(2);
  34354. if (value < 3) {
  34355. return value + 3;
  34356. }
  34357. value = readBits(5);
  34358. if (value < 31) {
  34359. return value + 6;
  34360. }
  34361. value = readBits(7);
  34362. return value + 37;
  34363. }
  34364. var tileIndex = context.currentTile.index;
  34365. var tile = context.tiles[tileIndex];
  34366. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34367. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34368. var packetsIterator = tile.packetsIterator;
  34369. while (position < dataLength) {
  34370. alignToByte();
  34371. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34372. // Skip also marker segment length and packet sequence ID
  34373. skipBytes(4);
  34374. }
  34375. var packet = packetsIterator.nextPacket();
  34376. if (!readBits(1)) {
  34377. continue;
  34378. }
  34379. var layerNumber = packet.layerNumber;
  34380. var queue = [], codeblock;
  34381. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34382. codeblock = packet.codeblocks[i];
  34383. var precinct = codeblock.precinct;
  34384. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34385. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34386. var codeblockIncluded = false;
  34387. var firstTimeInclusion = false;
  34388. var valueReady;
  34389. if (codeblock['included'] !== undefined) {
  34390. codeblockIncluded = !!readBits(1);
  34391. } else {
  34392. // reading inclusion tree
  34393. precinct = codeblock.precinct;
  34394. var inclusionTree, zeroBitPlanesTree;
  34395. if (precinct['inclusionTree'] !== undefined) {
  34396. inclusionTree = precinct.inclusionTree;
  34397. } else {
  34398. // building inclusion and zero bit-planes trees
  34399. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34400. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34401. inclusionTree = new InclusionTree(width, height, layerNumber);
  34402. zeroBitPlanesTree = new TagTree(width, height);
  34403. precinct.inclusionTree = inclusionTree;
  34404. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34405. }
  34406. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34407. while (true) {
  34408. if (readBits(1)) {
  34409. valueReady = !inclusionTree.nextLevel();
  34410. if (valueReady) {
  34411. codeblock.included = true;
  34412. codeblockIncluded = firstTimeInclusion = true;
  34413. break;
  34414. }
  34415. } else {
  34416. inclusionTree.incrementValue(layerNumber);
  34417. break;
  34418. }
  34419. }
  34420. }
  34421. }
  34422. if (!codeblockIncluded) {
  34423. continue;
  34424. }
  34425. if (firstTimeInclusion) {
  34426. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34427. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34428. while (true) {
  34429. if (readBits(1)) {
  34430. valueReady = !zeroBitPlanesTree.nextLevel();
  34431. if (valueReady) {
  34432. break;
  34433. }
  34434. } else {
  34435. zeroBitPlanesTree.incrementValue();
  34436. }
  34437. }
  34438. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34439. }
  34440. var codingpasses = readCodingpasses();
  34441. while (readBits(1)) {
  34442. codeblock.Lblock++;
  34443. }
  34444. var codingpassesLog2 = log2(codingpasses);
  34445. // rounding down log2
  34446. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34447. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34448. var codedDataLength = readBits(bits);
  34449. queue.push({
  34450. codeblock: codeblock,
  34451. codingpasses: codingpasses,
  34452. dataLength: codedDataLength
  34453. });
  34454. }
  34455. alignToByte();
  34456. if (ephMarkerUsed) {
  34457. skipMarkerIfEqual(0x92);
  34458. }
  34459. while (queue.length > 0) {
  34460. var packetItem = queue.shift();
  34461. codeblock = packetItem.codeblock;
  34462. if (codeblock['data'] === undefined) {
  34463. codeblock.data = [];
  34464. }
  34465. codeblock.data.push({
  34466. data: data,
  34467. start: offset + position,
  34468. end: offset + position + packetItem.dataLength,
  34469. codingpasses: packetItem.codingpasses
  34470. });
  34471. position += packetItem.dataLength;
  34472. }
  34473. }
  34474. return position;
  34475. }
  34476. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34477. delta, mb, reversible, segmentationSymbolUsed) {
  34478. var x0 = subband.tbx0;
  34479. var y0 = subband.tby0;
  34480. var width = subband.tbx1 - subband.tbx0;
  34481. var codeblocks = subband.codeblocks;
  34482. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34483. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34484. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34485. var codeblock = codeblocks[i];
  34486. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34487. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34488. if (blockWidth === 0 || blockHeight === 0) {
  34489. continue;
  34490. }
  34491. if (codeblock['data'] === undefined) {
  34492. continue;
  34493. }
  34494. var bitModel, currentCodingpassType;
  34495. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34496. codeblock.zeroBitPlanes, mb);
  34497. currentCodingpassType = 2; // first bit plane starts from cleanup
  34498. // collect data
  34499. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34500. var j, jj, dataItem;
  34501. for (j = 0, jj = data.length; j < jj; j++) {
  34502. dataItem = data[j];
  34503. totalLength += dataItem.end - dataItem.start;
  34504. codingpasses += dataItem.codingpasses;
  34505. }
  34506. var encodedData = new Uint8Array(totalLength);
  34507. var position = 0;
  34508. for (j = 0, jj = data.length; j < jj; j++) {
  34509. dataItem = data[j];
  34510. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34511. encodedData.set(chunk, position);
  34512. position += chunk.length;
  34513. }
  34514. // decoding the item
  34515. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34516. bitModel.setDecoder(decoder);
  34517. for (j = 0; j < codingpasses; j++) {
  34518. switch (currentCodingpassType) {
  34519. case 0:
  34520. bitModel.runSignificancePropogationPass();
  34521. break;
  34522. case 1:
  34523. bitModel.runMagnitudeRefinementPass();
  34524. break;
  34525. case 2:
  34526. bitModel.runCleanupPass();
  34527. if (segmentationSymbolUsed) {
  34528. bitModel.checkSegmentationSymbol();
  34529. }
  34530. break;
  34531. }
  34532. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34533. }
  34534. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34535. var sign = bitModel.coefficentsSign;
  34536. var magnitude = bitModel.coefficentsMagnitude;
  34537. var bitsDecoded = bitModel.bitsDecoded;
  34538. var magnitudeCorrection = reversible ? 0 : 0.5;
  34539. var k, n, nb;
  34540. position = 0;
  34541. // Do the interleaving of Section F.3.3 here, so we do not need
  34542. // to copy later. LL level is not interleaved, just copied.
  34543. var interleave = (subband.type !== 'LL');
  34544. for (j = 0; j < blockHeight; j++) {
  34545. var row = (offset / width) | 0; // row in the non-interleaved subband
  34546. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34547. for (k = 0; k < blockWidth; k++) {
  34548. n = magnitude[position];
  34549. if (n !== 0) {
  34550. n = (n + magnitudeCorrection) * delta;
  34551. if (sign[position] !== 0) {
  34552. n = -n;
  34553. }
  34554. nb = bitsDecoded[position];
  34555. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34556. if (reversible && (nb >= mb)) {
  34557. coefficients[pos] = n;
  34558. } else {
  34559. coefficients[pos] = n * (1 << (mb - nb));
  34560. }
  34561. }
  34562. offset++;
  34563. position++;
  34564. }
  34565. offset += width - blockWidth;
  34566. }
  34567. }
  34568. }
  34569. function transformTile(context, tile, c) {
  34570. var component = tile.components[c];
  34571. var codingStyleParameters = component.codingStyleParameters;
  34572. var quantizationParameters = component.quantizationParameters;
  34573. var decompositionLevelsCount =
  34574. codingStyleParameters.decompositionLevelsCount;
  34575. var spqcds = quantizationParameters.SPqcds;
  34576. var scalarExpounded = quantizationParameters.scalarExpounded;
  34577. var guardBits = quantizationParameters.guardBits;
  34578. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34579. var precision = context.components[c].precision;
  34580. var reversible = codingStyleParameters.reversibleTransformation;
  34581. var transform = (reversible ? new ReversibleTransform() :
  34582. new IrreversibleTransform());
  34583. var subbandCoefficients = [];
  34584. var b = 0;
  34585. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34586. var resolution = component.resolutions[i];
  34587. var width = resolution.trx1 - resolution.trx0;
  34588. var height = resolution.try1 - resolution.try0;
  34589. // Allocate space for the whole sublevel.
  34590. var coefficients = new Float32Array(width * height);
  34591. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34592. var mu, epsilon;
  34593. if (!scalarExpounded) {
  34594. // formula E-5
  34595. mu = spqcds[0].mu;
  34596. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34597. } else {
  34598. mu = spqcds[b].mu;
  34599. epsilon = spqcds[b].epsilon;
  34600. b++;
  34601. }
  34602. var subband = resolution.subbands[j];
  34603. var gainLog2 = SubbandsGainLog2[subband.type];
  34604. // calulate quantization coefficient (Section E.1.1.1)
  34605. var delta = (reversible ? 1 :
  34606. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34607. var mb = (guardBits + epsilon - 1);
  34608. // In the first resolution level, copyCoefficients will fill the
  34609. // whole array with coefficients. In the succeding passes,
  34610. // copyCoefficients will consecutively fill in the values that belong
  34611. // to the interleaved positions of the HL, LH, and HH coefficients.
  34612. // The LL coefficients will then be interleaved in Transform.iterate().
  34613. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34614. reversible, segmentationSymbolUsed);
  34615. }
  34616. subbandCoefficients.push({
  34617. width: width,
  34618. height: height,
  34619. items: coefficients
  34620. });
  34621. }
  34622. var result = transform.calculate(subbandCoefficients,
  34623. component.tcx0, component.tcy0);
  34624. return {
  34625. left: component.tcx0,
  34626. top: component.tcy0,
  34627. width: result.width,
  34628. height: result.height,
  34629. items: result.items
  34630. };
  34631. }
  34632. function transformComponents(context) {
  34633. var siz = context.SIZ;
  34634. var components = context.components;
  34635. var componentsCount = siz.Csiz;
  34636. var resultImages = [];
  34637. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34638. var tile = context.tiles[i];
  34639. var transformedTiles = [];
  34640. var c;
  34641. for (c = 0; c < componentsCount; c++) {
  34642. transformedTiles[c] = transformTile(context, tile, c);
  34643. }
  34644. var tile0 = transformedTiles[0];
  34645. var out = new Uint8Array(tile0.items.length * componentsCount);
  34646. var result = {
  34647. left: tile0.left,
  34648. top: tile0.top,
  34649. width: tile0.width,
  34650. height: tile0.height,
  34651. items: out
  34652. };
  34653. // Section G.2.2 Inverse multi component transform
  34654. var shift, offset, max, min, maxK;
  34655. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34656. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34657. var fourComponents = componentsCount === 4;
  34658. var y0items = transformedTiles[0].items;
  34659. var y1items = transformedTiles[1].items;
  34660. var y2items = transformedTiles[2].items;
  34661. var y3items = fourComponents ? transformedTiles[3].items : null;
  34662. // HACK: The multiple component transform formulas below assume that
  34663. // all components have the same precision. With this in mind, we
  34664. // compute shift and offset only once.
  34665. shift = components[0].precision - 8;
  34666. offset = (128 << shift) + 0.5;
  34667. max = 255 * (1 << shift);
  34668. maxK = max * 0.5;
  34669. min = -maxK;
  34670. var component0 = tile.components[0];
  34671. var alpha01 = componentsCount - 3;
  34672. jj = y0items.length;
  34673. if (!component0.codingStyleParameters.reversibleTransformation) {
  34674. // inverse irreversible multiple component transform
  34675. for (j = 0; j < jj; j++, pos += alpha01) {
  34676. y0 = y0items[j] + offset;
  34677. y1 = y1items[j];
  34678. y2 = y2items[j];
  34679. r = y0 + 1.402 * y2;
  34680. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34681. b = y0 + 1.772 * y1;
  34682. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34683. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34684. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34685. }
  34686. } else {
  34687. // inverse reversible multiple component transform
  34688. for (j = 0; j < jj; j++, pos += alpha01) {
  34689. y0 = y0items[j] + offset;
  34690. y1 = y1items[j];
  34691. y2 = y2items[j];
  34692. g = y0 - ((y2 + y1) >> 2);
  34693. r = g + y2;
  34694. b = g + y1;
  34695. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34696. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34697. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34698. }
  34699. }
  34700. if (fourComponents) {
  34701. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34702. k = y3items[j];
  34703. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34704. }
  34705. }
  34706. } else { // no multi-component transform
  34707. for (c = 0; c < componentsCount; c++) {
  34708. var items = transformedTiles[c].items;
  34709. shift = components[c].precision - 8;
  34710. offset = (128 << shift) + 0.5;
  34711. max = (127.5 * (1 << shift));
  34712. min = -max;
  34713. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34714. val = items[j];
  34715. out[pos] = val <= min ? 0 :
  34716. val >= max ? 255 : (val + offset) >> shift;
  34717. pos += componentsCount;
  34718. }
  34719. }
  34720. }
  34721. resultImages.push(result);
  34722. }
  34723. return resultImages;
  34724. }
  34725. function initializeTile(context, tileIndex) {
  34726. var siz = context.SIZ;
  34727. var componentsCount = siz.Csiz;
  34728. var tile = context.tiles[tileIndex];
  34729. for (var c = 0; c < componentsCount; c++) {
  34730. var component = tile.components[c];
  34731. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34732. context.currentTile.QCC[c] : context.currentTile.QCD);
  34733. component.quantizationParameters = qcdOrQcc;
  34734. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34735. context.currentTile.COC[c] : context.currentTile.COD);
  34736. component.codingStyleParameters = codOrCoc;
  34737. }
  34738. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34739. }
  34740. // Section B.10.2 Tag trees
  34741. var TagTree = (function TagTreeClosure() {
  34742. function TagTree(width, height) {
  34743. var levelsLength = log2(Math.max(width, height)) + 1;
  34744. this.levels = [];
  34745. for (var i = 0; i < levelsLength; i++) {
  34746. var level = {
  34747. width: width,
  34748. height: height,
  34749. items: []
  34750. };
  34751. this.levels.push(level);
  34752. width = Math.ceil(width / 2);
  34753. height = Math.ceil(height / 2);
  34754. }
  34755. }
  34756. TagTree.prototype = {
  34757. reset: function TagTree_reset(i, j) {
  34758. var currentLevel = 0, value = 0, level;
  34759. while (currentLevel < this.levels.length) {
  34760. level = this.levels[currentLevel];
  34761. var index = i + j * level.width;
  34762. if (level.items[index] !== undefined) {
  34763. value = level.items[index];
  34764. break;
  34765. }
  34766. level.index = index;
  34767. i >>= 1;
  34768. j >>= 1;
  34769. currentLevel++;
  34770. }
  34771. currentLevel--;
  34772. level = this.levels[currentLevel];
  34773. level.items[level.index] = value;
  34774. this.currentLevel = currentLevel;
  34775. delete this.value;
  34776. },
  34777. incrementValue: function TagTree_incrementValue() {
  34778. var level = this.levels[this.currentLevel];
  34779. level.items[level.index]++;
  34780. },
  34781. nextLevel: function TagTree_nextLevel() {
  34782. var currentLevel = this.currentLevel;
  34783. var level = this.levels[currentLevel];
  34784. var value = level.items[level.index];
  34785. currentLevel--;
  34786. if (currentLevel < 0) {
  34787. this.value = value;
  34788. return false;
  34789. }
  34790. this.currentLevel = currentLevel;
  34791. level = this.levels[currentLevel];
  34792. level.items[level.index] = value;
  34793. return true;
  34794. }
  34795. };
  34796. return TagTree;
  34797. })();
  34798. var InclusionTree = (function InclusionTreeClosure() {
  34799. function InclusionTree(width, height, defaultValue) {
  34800. var levelsLength = log2(Math.max(width, height)) + 1;
  34801. this.levels = [];
  34802. for (var i = 0; i < levelsLength; i++) {
  34803. var items = new Uint8Array(width * height);
  34804. for (var j = 0, jj = items.length; j < jj; j++) {
  34805. items[j] = defaultValue;
  34806. }
  34807. var level = {
  34808. width: width,
  34809. height: height,
  34810. items: items
  34811. };
  34812. this.levels.push(level);
  34813. width = Math.ceil(width / 2);
  34814. height = Math.ceil(height / 2);
  34815. }
  34816. }
  34817. InclusionTree.prototype = {
  34818. reset: function InclusionTree_reset(i, j, stopValue) {
  34819. var currentLevel = 0;
  34820. while (currentLevel < this.levels.length) {
  34821. var level = this.levels[currentLevel];
  34822. var index = i + j * level.width;
  34823. level.index = index;
  34824. var value = level.items[index];
  34825. if (value === 0xFF) {
  34826. break;
  34827. }
  34828. if (value > stopValue) {
  34829. this.currentLevel = currentLevel;
  34830. // already know about this one, propagating the value to top levels
  34831. this.propagateValues();
  34832. return false;
  34833. }
  34834. i >>= 1;
  34835. j >>= 1;
  34836. currentLevel++;
  34837. }
  34838. this.currentLevel = currentLevel - 1;
  34839. return true;
  34840. },
  34841. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34842. var level = this.levels[this.currentLevel];
  34843. level.items[level.index] = stopValue + 1;
  34844. this.propagateValues();
  34845. },
  34846. propagateValues: function InclusionTree_propagateValues() {
  34847. var levelIndex = this.currentLevel;
  34848. var level = this.levels[levelIndex];
  34849. var currentValue = level.items[level.index];
  34850. while (--levelIndex >= 0) {
  34851. level = this.levels[levelIndex];
  34852. level.items[level.index] = currentValue;
  34853. }
  34854. },
  34855. nextLevel: function InclusionTree_nextLevel() {
  34856. var currentLevel = this.currentLevel;
  34857. var level = this.levels[currentLevel];
  34858. var value = level.items[level.index];
  34859. level.items[level.index] = 0xFF;
  34860. currentLevel--;
  34861. if (currentLevel < 0) {
  34862. return false;
  34863. }
  34864. this.currentLevel = currentLevel;
  34865. level = this.levels[currentLevel];
  34866. level.items[level.index] = value;
  34867. return true;
  34868. }
  34869. };
  34870. return InclusionTree;
  34871. })();
  34872. // Section D. Coefficient bit modeling
  34873. var BitModel = (function BitModelClosure() {
  34874. var UNIFORM_CONTEXT = 17;
  34875. var RUNLENGTH_CONTEXT = 18;
  34876. // Table D-1
  34877. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34878. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34879. var LLAndLHContextsLabel = new Uint8Array([
  34880. 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,
  34881. 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,
  34882. 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
  34883. ]);
  34884. var HLContextLabel = new Uint8Array([
  34885. 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,
  34886. 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,
  34887. 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
  34888. ]);
  34889. var HHContextLabel = new Uint8Array([
  34890. 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,
  34891. 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,
  34892. 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
  34893. ]);
  34894. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34895. this.width = width;
  34896. this.height = height;
  34897. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34898. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34899. var coefficientCount = width * height;
  34900. // coefficients outside the encoding region treated as insignificant
  34901. // add border state cells for significanceState
  34902. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34903. this.coefficentsSign = new Uint8Array(coefficientCount);
  34904. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34905. mb > 6 ? new Uint16Array(coefficientCount) :
  34906. new Uint8Array(coefficientCount);
  34907. this.processingFlags = new Uint8Array(coefficientCount);
  34908. var bitsDecoded = new Uint8Array(coefficientCount);
  34909. if (zeroBitPlanes !== 0) {
  34910. for (var i = 0; i < coefficientCount; i++) {
  34911. bitsDecoded[i] = zeroBitPlanes;
  34912. }
  34913. }
  34914. this.bitsDecoded = bitsDecoded;
  34915. this.reset();
  34916. }
  34917. BitModel.prototype = {
  34918. setDecoder: function BitModel_setDecoder(decoder) {
  34919. this.decoder = decoder;
  34920. },
  34921. reset: function BitModel_reset() {
  34922. // We have 17 contexts that are accessed via context labels,
  34923. // plus the uniform and runlength context.
  34924. this.contexts = new Int8Array(19);
  34925. // Contexts are packed into 1 byte:
  34926. // highest 7 bits carry the index, lowest bit carries mps
  34927. this.contexts[0] = (4 << 1) | 0;
  34928. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34929. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34930. },
  34931. setNeighborsSignificance:
  34932. function BitModel_setNeighborsSignificance(row, column, index) {
  34933. var neighborsSignificance = this.neighborsSignificance;
  34934. var width = this.width, height = this.height;
  34935. var left = (column > 0);
  34936. var right = (column + 1 < width);
  34937. var i;
  34938. if (row > 0) {
  34939. i = index - width;
  34940. if (left) {
  34941. neighborsSignificance[i - 1] += 0x10;
  34942. }
  34943. if (right) {
  34944. neighborsSignificance[i + 1] += 0x10;
  34945. }
  34946. neighborsSignificance[i] += 0x04;
  34947. }
  34948. if (row + 1 < height) {
  34949. i = index + width;
  34950. if (left) {
  34951. neighborsSignificance[i - 1] += 0x10;
  34952. }
  34953. if (right) {
  34954. neighborsSignificance[i + 1] += 0x10;
  34955. }
  34956. neighborsSignificance[i] += 0x04;
  34957. }
  34958. if (left) {
  34959. neighborsSignificance[index - 1] += 0x01;
  34960. }
  34961. if (right) {
  34962. neighborsSignificance[index + 1] += 0x01;
  34963. }
  34964. neighborsSignificance[index] |= 0x80;
  34965. },
  34966. runSignificancePropogationPass:
  34967. function BitModel_runSignificancePropogationPass() {
  34968. var decoder = this.decoder;
  34969. var width = this.width, height = this.height;
  34970. var coefficentsMagnitude = this.coefficentsMagnitude;
  34971. var coefficentsSign = this.coefficentsSign;
  34972. var neighborsSignificance = this.neighborsSignificance;
  34973. var processingFlags = this.processingFlags;
  34974. var contexts = this.contexts;
  34975. var labels = this.contextLabelTable;
  34976. var bitsDecoded = this.bitsDecoded;
  34977. var processedInverseMask = ~1;
  34978. var processedMask = 1;
  34979. var firstMagnitudeBitMask = 2;
  34980. for (var i0 = 0; i0 < height; i0 += 4) {
  34981. for (var j = 0; j < width; j++) {
  34982. var index = i0 * width + j;
  34983. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34984. var i = i0 + i1;
  34985. if (i >= height) {
  34986. break;
  34987. }
  34988. // clear processed flag first
  34989. processingFlags[index] &= processedInverseMask;
  34990. if (coefficentsMagnitude[index] ||
  34991. !neighborsSignificance[index]) {
  34992. continue;
  34993. }
  34994. var contextLabel = labels[neighborsSignificance[index]];
  34995. var decision = decoder.readBit(contexts, contextLabel);
  34996. if (decision) {
  34997. var sign = this.decodeSignBit(i, j, index);
  34998. coefficentsSign[index] = sign;
  34999. coefficentsMagnitude[index] = 1;
  35000. this.setNeighborsSignificance(i, j, index);
  35001. processingFlags[index] |= firstMagnitudeBitMask;
  35002. }
  35003. bitsDecoded[index]++;
  35004. processingFlags[index] |= processedMask;
  35005. }
  35006. }
  35007. }
  35008. },
  35009. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  35010. var width = this.width, height = this.height;
  35011. var coefficentsMagnitude = this.coefficentsMagnitude;
  35012. var coefficentsSign = this.coefficentsSign;
  35013. var contribution, sign0, sign1, significance1;
  35014. var contextLabel, decoded;
  35015. // calculate horizontal contribution
  35016. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  35017. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  35018. sign1 = coefficentsSign[index + 1];
  35019. if (significance1) {
  35020. sign0 = coefficentsSign[index - 1];
  35021. contribution = 1 - sign1 - sign0;
  35022. } else {
  35023. contribution = 1 - sign1 - sign1;
  35024. }
  35025. } else if (significance1) {
  35026. sign0 = coefficentsSign[index - 1];
  35027. contribution = 1 - sign0 - sign0;
  35028. } else {
  35029. contribution = 0;
  35030. }
  35031. var horizontalContribution = 3 * contribution;
  35032. // calculate vertical contribution and combine with the horizontal
  35033. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  35034. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  35035. sign1 = coefficentsSign[index + width];
  35036. if (significance1) {
  35037. sign0 = coefficentsSign[index - width];
  35038. contribution = 1 - sign1 - sign0 + horizontalContribution;
  35039. } else {
  35040. contribution = 1 - sign1 - sign1 + horizontalContribution;
  35041. }
  35042. } else if (significance1) {
  35043. sign0 = coefficentsSign[index - width];
  35044. contribution = 1 - sign0 - sign0 + horizontalContribution;
  35045. } else {
  35046. contribution = horizontalContribution;
  35047. }
  35048. if (contribution >= 0) {
  35049. contextLabel = 9 + contribution;
  35050. decoded = this.decoder.readBit(this.contexts, contextLabel);
  35051. } else {
  35052. contextLabel = 9 - contribution;
  35053. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  35054. }
  35055. return decoded;
  35056. },
  35057. runMagnitudeRefinementPass:
  35058. function BitModel_runMagnitudeRefinementPass() {
  35059. var decoder = this.decoder;
  35060. var width = this.width, height = this.height;
  35061. var coefficentsMagnitude = this.coefficentsMagnitude;
  35062. var neighborsSignificance = this.neighborsSignificance;
  35063. var contexts = this.contexts;
  35064. var bitsDecoded = this.bitsDecoded;
  35065. var processingFlags = this.processingFlags;
  35066. var processedMask = 1;
  35067. var firstMagnitudeBitMask = 2;
  35068. var length = width * height;
  35069. var width4 = width * 4;
  35070. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35071. indexNext = Math.min(length, index0 + width4);
  35072. for (var j = 0; j < width; j++) {
  35073. for (var index = index0 + j; index < indexNext; index += width) {
  35074. // significant but not those that have just become
  35075. if (!coefficentsMagnitude[index] ||
  35076. (processingFlags[index] & processedMask) !== 0) {
  35077. continue;
  35078. }
  35079. var contextLabel = 16;
  35080. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35081. processingFlags[index] ^= firstMagnitudeBitMask;
  35082. // first refinement
  35083. var significance = neighborsSignificance[index] & 127;
  35084. contextLabel = significance === 0 ? 15 : 14;
  35085. }
  35086. var bit = decoder.readBit(contexts, contextLabel);
  35087. coefficentsMagnitude[index] =
  35088. (coefficentsMagnitude[index] << 1) | bit;
  35089. bitsDecoded[index]++;
  35090. processingFlags[index] |= processedMask;
  35091. }
  35092. }
  35093. }
  35094. },
  35095. runCleanupPass: function BitModel_runCleanupPass() {
  35096. var decoder = this.decoder;
  35097. var width = this.width, height = this.height;
  35098. var neighborsSignificance = this.neighborsSignificance;
  35099. var coefficentsMagnitude = this.coefficentsMagnitude;
  35100. var coefficentsSign = this.coefficentsSign;
  35101. var contexts = this.contexts;
  35102. var labels = this.contextLabelTable;
  35103. var bitsDecoded = this.bitsDecoded;
  35104. var processingFlags = this.processingFlags;
  35105. var processedMask = 1;
  35106. var firstMagnitudeBitMask = 2;
  35107. var oneRowDown = width;
  35108. var twoRowsDown = width * 2;
  35109. var threeRowsDown = width * 3;
  35110. var iNext;
  35111. for (var i0 = 0; i0 < height; i0 = iNext) {
  35112. iNext = Math.min(i0 + 4, height);
  35113. var indexBase = i0 * width;
  35114. var checkAllEmpty = i0 + 3 < height;
  35115. for (var j = 0; j < width; j++) {
  35116. var index0 = indexBase + j;
  35117. // using the property: labels[neighborsSignificance[index]] === 0
  35118. // when neighborsSignificance[index] === 0
  35119. var allEmpty = (checkAllEmpty &&
  35120. processingFlags[index0] === 0 &&
  35121. processingFlags[index0 + oneRowDown] === 0 &&
  35122. processingFlags[index0 + twoRowsDown] === 0 &&
  35123. processingFlags[index0 + threeRowsDown] === 0 &&
  35124. neighborsSignificance[index0] === 0 &&
  35125. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35126. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35127. neighborsSignificance[index0 + threeRowsDown] === 0);
  35128. var i1 = 0, index = index0;
  35129. var i = i0, sign;
  35130. if (allEmpty) {
  35131. var hasSignificantCoefficent =
  35132. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35133. if (!hasSignificantCoefficent) {
  35134. bitsDecoded[index0]++;
  35135. bitsDecoded[index0 + oneRowDown]++;
  35136. bitsDecoded[index0 + twoRowsDown]++;
  35137. bitsDecoded[index0 + threeRowsDown]++;
  35138. continue; // next column
  35139. }
  35140. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35141. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35142. if (i1 !== 0) {
  35143. i = i0 + i1;
  35144. index += i1 * width;
  35145. }
  35146. sign = this.decodeSignBit(i, j, index);
  35147. coefficentsSign[index] = sign;
  35148. coefficentsMagnitude[index] = 1;
  35149. this.setNeighborsSignificance(i, j, index);
  35150. processingFlags[index] |= firstMagnitudeBitMask;
  35151. index = index0;
  35152. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35153. bitsDecoded[index]++;
  35154. }
  35155. i1++;
  35156. }
  35157. for (i = i0 + i1; i < iNext; i++, index += width) {
  35158. if (coefficentsMagnitude[index] ||
  35159. (processingFlags[index] & processedMask) !== 0) {
  35160. continue;
  35161. }
  35162. var contextLabel = labels[neighborsSignificance[index]];
  35163. var decision = decoder.readBit(contexts, contextLabel);
  35164. if (decision === 1) {
  35165. sign = this.decodeSignBit(i, j, index);
  35166. coefficentsSign[index] = sign;
  35167. coefficentsMagnitude[index] = 1;
  35168. this.setNeighborsSignificance(i, j, index);
  35169. processingFlags[index] |= firstMagnitudeBitMask;
  35170. }
  35171. bitsDecoded[index]++;
  35172. }
  35173. }
  35174. }
  35175. },
  35176. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35177. var decoder = this.decoder;
  35178. var contexts = this.contexts;
  35179. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35180. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35181. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35182. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35183. if (symbol !== 0xA) {
  35184. throw new Error('JPX Error: Invalid segmentation symbol');
  35185. }
  35186. }
  35187. };
  35188. return BitModel;
  35189. })();
  35190. // Section F, Discrete wavelet transformation
  35191. var Transform = (function TransformClosure() {
  35192. function Transform() {}
  35193. Transform.prototype.calculate =
  35194. function transformCalculate(subbands, u0, v0) {
  35195. var ll = subbands[0];
  35196. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35197. ll = this.iterate(ll, subbands[i], u0, v0);
  35198. }
  35199. return ll;
  35200. };
  35201. Transform.prototype.extend = function extend(buffer, offset, size) {
  35202. // Section F.3.7 extending... using max extension of 4
  35203. var i1 = offset - 1, j1 = offset + 1;
  35204. var i2 = offset + size - 2, j2 = offset + size;
  35205. buffer[i1--] = buffer[j1++];
  35206. buffer[j2++] = buffer[i2--];
  35207. buffer[i1--] = buffer[j1++];
  35208. buffer[j2++] = buffer[i2--];
  35209. buffer[i1--] = buffer[j1++];
  35210. buffer[j2++] = buffer[i2--];
  35211. buffer[i1] = buffer[j1];
  35212. buffer[j2] = buffer[i2];
  35213. };
  35214. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35215. u0, v0) {
  35216. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35217. var width = hl_lh_hh.width;
  35218. var height = hl_lh_hh.height;
  35219. var items = hl_lh_hh.items;
  35220. var i, j, k, l, u, v;
  35221. // Interleave LL according to Section F.3.3
  35222. for (k = 0, i = 0; i < llHeight; i++) {
  35223. l = i * 2 * width;
  35224. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35225. items[l] = llItems[k];
  35226. }
  35227. }
  35228. // The LL band is not needed anymore.
  35229. llItems = ll.items = null;
  35230. var bufferPadding = 4;
  35231. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35232. // Section F.3.4 HOR_SR
  35233. if (width === 1) {
  35234. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35235. if ((u0 & 1) !== 0) {
  35236. for (v = 0, k = 0; v < height; v++, k += width) {
  35237. items[k] *= 0.5;
  35238. }
  35239. }
  35240. } else {
  35241. for (v = 0, k = 0; v < height; v++, k += width) {
  35242. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35243. this.extend(rowBuffer, bufferPadding, width);
  35244. this.filter(rowBuffer, bufferPadding, width);
  35245. items.set(
  35246. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35247. k);
  35248. }
  35249. }
  35250. // Accesses to the items array can take long, because it may not fit into
  35251. // CPU cache and has to be fetched from main memory. Since subsequent
  35252. // accesses to the items array are not local when reading columns, we
  35253. // have a cache miss every time. To reduce cache misses, get up to
  35254. // 'numBuffers' items at a time and store them into the individual
  35255. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35256. var numBuffers = 16;
  35257. var colBuffers = [];
  35258. for (i = 0; i < numBuffers; i++) {
  35259. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35260. }
  35261. var b, currentBuffer = 0;
  35262. ll = bufferPadding + height;
  35263. // Section F.3.5 VER_SR
  35264. if (height === 1) {
  35265. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35266. if ((v0 & 1) !== 0) {
  35267. for (u = 0; u < width; u++) {
  35268. items[u] *= 0.5;
  35269. }
  35270. }
  35271. } else {
  35272. for (u = 0; u < width; u++) {
  35273. // if we ran out of buffers, copy several image columns at once
  35274. if (currentBuffer === 0) {
  35275. numBuffers = Math.min(width - u, numBuffers);
  35276. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35277. for (b = 0; b < numBuffers; b++) {
  35278. colBuffers[b][l] = items[k + b];
  35279. }
  35280. }
  35281. currentBuffer = numBuffers;
  35282. }
  35283. currentBuffer--;
  35284. var buffer = colBuffers[currentBuffer];
  35285. this.extend(buffer, bufferPadding, height);
  35286. this.filter(buffer, bufferPadding, height);
  35287. // If this is last buffer in this group of buffers, flush all buffers.
  35288. if (currentBuffer === 0) {
  35289. k = u - numBuffers + 1;
  35290. for (l = bufferPadding; l < ll; k += width, l++) {
  35291. for (b = 0; b < numBuffers; b++) {
  35292. items[k + b] = colBuffers[b][l];
  35293. }
  35294. }
  35295. }
  35296. }
  35297. }
  35298. return {
  35299. width: width,
  35300. height: height,
  35301. items: items
  35302. };
  35303. };
  35304. return Transform;
  35305. })();
  35306. // Section 3.8.2 Irreversible 9-7 filter
  35307. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35308. function IrreversibleTransform() {
  35309. Transform.call(this);
  35310. }
  35311. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35312. IrreversibleTransform.prototype.filter =
  35313. function irreversibleTransformFilter(x, offset, length) {
  35314. var len = length >> 1;
  35315. offset = offset | 0;
  35316. var j, n, current, next;
  35317. var alpha = -1.586134342059924;
  35318. var beta = -0.052980118572961;
  35319. var gamma = 0.882911075530934;
  35320. var delta = 0.443506852043971;
  35321. var K = 1.230174104914001;
  35322. var K_ = 1 / K;
  35323. // step 1 is combined with step 3
  35324. // step 2
  35325. j = offset - 3;
  35326. for (n = len + 4; n--; j += 2) {
  35327. x[j] *= K_;
  35328. }
  35329. // step 1 & 3
  35330. j = offset - 2;
  35331. current = delta * x[j -1];
  35332. for (n = len + 3; n--; j += 2) {
  35333. next = delta * x[j + 1];
  35334. x[j] = K * x[j] - current - next;
  35335. if (n--) {
  35336. j += 2;
  35337. current = delta * x[j + 1];
  35338. x[j] = K * x[j] - current - next;
  35339. } else {
  35340. break;
  35341. }
  35342. }
  35343. // step 4
  35344. j = offset - 1;
  35345. current = gamma * x[j - 1];
  35346. for (n = len + 2; n--; j += 2) {
  35347. next = gamma * x[j + 1];
  35348. x[j] -= current + next;
  35349. if (n--) {
  35350. j += 2;
  35351. current = gamma * x[j + 1];
  35352. x[j] -= current + next;
  35353. } else {
  35354. break;
  35355. }
  35356. }
  35357. // step 5
  35358. j = offset;
  35359. current = beta * x[j - 1];
  35360. for (n = len + 1; n--; j += 2) {
  35361. next = beta * x[j + 1];
  35362. x[j] -= current + next;
  35363. if (n--) {
  35364. j += 2;
  35365. current = beta * x[j + 1];
  35366. x[j] -= current + next;
  35367. } else {
  35368. break;
  35369. }
  35370. }
  35371. // step 6
  35372. if (len !== 0) {
  35373. j = offset + 1;
  35374. current = alpha * x[j - 1];
  35375. for (n = len; n--; j += 2) {
  35376. next = alpha * x[j + 1];
  35377. x[j] -= current + next;
  35378. if (n--) {
  35379. j += 2;
  35380. current = alpha * x[j + 1];
  35381. x[j] -= current + next;
  35382. } else {
  35383. break;
  35384. }
  35385. }
  35386. }
  35387. };
  35388. return IrreversibleTransform;
  35389. })();
  35390. // Section 3.8.1 Reversible 5-3 filter
  35391. var ReversibleTransform = (function ReversibleTransformClosure() {
  35392. function ReversibleTransform() {
  35393. Transform.call(this);
  35394. }
  35395. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35396. ReversibleTransform.prototype.filter =
  35397. function reversibleTransformFilter(x, offset, length) {
  35398. var len = length >> 1;
  35399. offset = offset | 0;
  35400. var j, n;
  35401. for (j = offset, n = len + 1; n--; j += 2) {
  35402. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35403. }
  35404. for (j = offset + 1, n = len; n--; j += 2) {
  35405. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35406. }
  35407. };
  35408. return ReversibleTransform;
  35409. })();
  35410. return JpxImage;
  35411. })();
  35412. var Jbig2Image = (function Jbig2ImageClosure() {
  35413. // Utility data structures
  35414. function ContextCache() {}
  35415. ContextCache.prototype = {
  35416. getContexts: function(id) {
  35417. if (id in this) {
  35418. return this[id];
  35419. }
  35420. return (this[id] = new Int8Array(1 << 16));
  35421. }
  35422. };
  35423. function DecodingContext(data, start, end) {
  35424. this.data = data;
  35425. this.start = start;
  35426. this.end = end;
  35427. }
  35428. DecodingContext.prototype = {
  35429. get decoder() {
  35430. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35431. return shadow(this, 'decoder', decoder);
  35432. },
  35433. get contextCache() {
  35434. var cache = new ContextCache();
  35435. return shadow(this, 'contextCache', cache);
  35436. }
  35437. };
  35438. // Annex A. Arithmetic Integer Decoding Procedure
  35439. // A.2 Procedure for decoding values
  35440. function decodeInteger(contextCache, procedure, decoder) {
  35441. var contexts = contextCache.getContexts(procedure);
  35442. var prev = 1;
  35443. function readBits(length) {
  35444. var v = 0;
  35445. for (var i = 0; i < length; i++) {
  35446. var bit = decoder.readBit(contexts, prev);
  35447. prev = (prev < 256 ? (prev << 1) | bit :
  35448. (((prev << 1) | bit) & 511) | 256);
  35449. v = (v << 1) | bit;
  35450. }
  35451. return v >>> 0;
  35452. }
  35453. var sign = readBits(1);
  35454. var value = readBits(1) ?
  35455. (readBits(1) ?
  35456. (readBits(1) ?
  35457. (readBits(1) ?
  35458. (readBits(1) ?
  35459. (readBits(32) + 4436) :
  35460. readBits(12) + 340) :
  35461. readBits(8) + 84) :
  35462. readBits(6) + 20) :
  35463. readBits(4) + 4) :
  35464. readBits(2);
  35465. return (sign === 0 ? value : (value > 0 ? -value : null));
  35466. }
  35467. // A.3 The IAID decoding procedure
  35468. function decodeIAID(contextCache, decoder, codeLength) {
  35469. var contexts = contextCache.getContexts('IAID');
  35470. var prev = 1;
  35471. for (var i = 0; i < codeLength; i++) {
  35472. var bit = decoder.readBit(contexts, prev);
  35473. prev = (prev << 1) | bit;
  35474. }
  35475. if (codeLength < 31) {
  35476. return prev & ((1 << codeLength) - 1);
  35477. }
  35478. return prev & 0x7FFFFFFF;
  35479. }
  35480. // 7.3 Segment types
  35481. var SegmentTypes = [
  35482. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35483. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35484. null, null, null, null, null, 'patternDictionary', null, null, null,
  35485. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35486. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35487. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35488. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35489. 'IntermediateGenericRefinementRegion', null,
  35490. 'ImmediateGenericRefinementRegion',
  35491. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35492. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35493. 'Tables', null, null, null, null, null, null, null, null,
  35494. 'Extension'
  35495. ];
  35496. var CodingTemplates = [
  35497. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35498. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35499. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35500. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35501. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35502. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35503. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35504. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35505. {x: -1, y: 0}],
  35506. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35507. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35508. ];
  35509. var RefinementTemplates = [
  35510. {
  35511. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35512. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35513. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35514. },
  35515. {
  35516. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35517. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35518. {x: 0, y: 1}, {x: 1, y: 1}]
  35519. }
  35520. ];
  35521. // See 6.2.5.7 Decoding the bitmap.
  35522. var ReusedContexts = [
  35523. 0x9B25, // 10011 0110010 0101
  35524. 0x0795, // 0011 110010 101
  35525. 0x00E5, // 001 11001 01
  35526. 0x0195 // 011001 0101
  35527. ];
  35528. var RefinementReusedContexts = [
  35529. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35530. 0x0008 // '0000' + '001000'
  35531. ];
  35532. function decodeBitmapTemplate0(width, height, decodingContext) {
  35533. var decoder = decodingContext.decoder;
  35534. var contexts = decodingContext.contextCache.getContexts('GB');
  35535. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35536. // ...ooooo....
  35537. // ..ooooooo... Context template for current pixel (X)
  35538. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35539. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35540. for (i = 0; i < height; i++) {
  35541. row = bitmap[i] = new Uint8Array(width);
  35542. row1 = (i < 1) ? row : bitmap[i - 1];
  35543. row2 = (i < 2) ? row : bitmap[i - 2];
  35544. // At the beginning of each row:
  35545. // Fill contextLabel with pixels that are above/right of (X)
  35546. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35547. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35548. (row1[3] << 4);
  35549. for (j = 0; j < width; j++) {
  35550. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35551. // At each pixel: Clear contextLabel pixels that are shifted
  35552. // out of the context, then add new ones.
  35553. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35554. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35555. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35556. }
  35557. }
  35558. return bitmap;
  35559. }
  35560. // 6.2 Generic Region Decoding Procedure
  35561. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35562. decodingContext) {
  35563. if (mmr) {
  35564. error('JBIG2 error: MMR encoding is not supported');
  35565. }
  35566. // Use optimized version for the most common case
  35567. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35568. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35569. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35570. return decodeBitmapTemplate0(width, height, decodingContext);
  35571. }
  35572. var useskip = !!skip;
  35573. var template = CodingTemplates[templateIndex].concat(at);
  35574. // Sorting is non-standard, and it is not required. But sorting increases
  35575. // the number of template bits that can be reused from the previous
  35576. // contextLabel in the main loop.
  35577. template.sort(function (a, b) {
  35578. return (a.y - b.y) || (a.x - b.x);
  35579. });
  35580. var templateLength = template.length;
  35581. var templateX = new Int8Array(templateLength);
  35582. var templateY = new Int8Array(templateLength);
  35583. var changingTemplateEntries = [];
  35584. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35585. var c, k;
  35586. for (k = 0; k < templateLength; k++) {
  35587. templateX[k] = template[k].x;
  35588. templateY[k] = template[k].y;
  35589. minX = Math.min(minX, template[k].x);
  35590. maxX = Math.max(maxX, template[k].x);
  35591. minY = Math.min(minY, template[k].y);
  35592. // Check if the template pixel appears in two consecutive context labels,
  35593. // so it can be reused. Otherwise, we add it to the list of changing
  35594. // template entries.
  35595. if (k < templateLength - 1 &&
  35596. template[k].y === template[k + 1].y &&
  35597. template[k].x === template[k + 1].x - 1) {
  35598. reuseMask |= 1 << (templateLength - 1 - k);
  35599. } else {
  35600. changingTemplateEntries.push(k);
  35601. }
  35602. }
  35603. var changingEntriesLength = changingTemplateEntries.length;
  35604. var changingTemplateX = new Int8Array(changingEntriesLength);
  35605. var changingTemplateY = new Int8Array(changingEntriesLength);
  35606. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35607. for (c = 0; c < changingEntriesLength; c++) {
  35608. k = changingTemplateEntries[c];
  35609. changingTemplateX[c] = template[k].x;
  35610. changingTemplateY[c] = template[k].y;
  35611. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35612. }
  35613. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35614. var sbb_left = -minX;
  35615. var sbb_top = -minY;
  35616. var sbb_right = width - maxX;
  35617. var pseudoPixelContext = ReusedContexts[templateIndex];
  35618. var row = new Uint8Array(width);
  35619. var bitmap = [];
  35620. var decoder = decodingContext.decoder;
  35621. var contexts = decodingContext.contextCache.getContexts('GB');
  35622. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35623. for (var i = 0; i < height; i++) {
  35624. if (prediction) {
  35625. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35626. ltp ^= sltp;
  35627. if (ltp) {
  35628. bitmap.push(row); // duplicate previous row
  35629. continue;
  35630. }
  35631. }
  35632. row = new Uint8Array(row);
  35633. bitmap.push(row);
  35634. for (j = 0; j < width; j++) {
  35635. if (useskip && skip[i][j]) {
  35636. row[j] = 0;
  35637. continue;
  35638. }
  35639. // Are we in the middle of a scanline, so we can reuse contextLabel
  35640. // bits?
  35641. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35642. // If yes, we can just shift the bits that are reusable and only
  35643. // fetch the remaining ones.
  35644. contextLabel = (contextLabel << 1) & reuseMask;
  35645. for (k = 0; k < changingEntriesLength; k++) {
  35646. i0 = i + changingTemplateY[k];
  35647. j0 = j + changingTemplateX[k];
  35648. bit = bitmap[i0][j0];
  35649. if (bit) {
  35650. bit = changingTemplateBit[k];
  35651. contextLabel |= bit;
  35652. }
  35653. }
  35654. } else {
  35655. // compute the contextLabel from scratch
  35656. contextLabel = 0;
  35657. shift = templateLength - 1;
  35658. for (k = 0; k < templateLength; k++, shift--) {
  35659. j0 = j + templateX[k];
  35660. if (j0 >= 0 && j0 < width) {
  35661. i0 = i + templateY[k];
  35662. if (i0 >= 0) {
  35663. bit = bitmap[i0][j0];
  35664. if (bit) {
  35665. contextLabel |= bit << shift;
  35666. }
  35667. }
  35668. }
  35669. }
  35670. }
  35671. var pixel = decoder.readBit(contexts, contextLabel);
  35672. row[j] = pixel;
  35673. }
  35674. }
  35675. return bitmap;
  35676. }
  35677. // 6.3.2 Generic Refinement Region Decoding Procedure
  35678. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35679. offsetX, offsetY, prediction, at,
  35680. decodingContext) {
  35681. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35682. if (templateIndex === 0) {
  35683. codingTemplate = codingTemplate.concat([at[0]]);
  35684. }
  35685. var codingTemplateLength = codingTemplate.length;
  35686. var codingTemplateX = new Int32Array(codingTemplateLength);
  35687. var codingTemplateY = new Int32Array(codingTemplateLength);
  35688. var k;
  35689. for (k = 0; k < codingTemplateLength; k++) {
  35690. codingTemplateX[k] = codingTemplate[k].x;
  35691. codingTemplateY[k] = codingTemplate[k].y;
  35692. }
  35693. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35694. if (templateIndex === 0) {
  35695. referenceTemplate = referenceTemplate.concat([at[1]]);
  35696. }
  35697. var referenceTemplateLength = referenceTemplate.length;
  35698. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35699. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35700. for (k = 0; k < referenceTemplateLength; k++) {
  35701. referenceTemplateX[k] = referenceTemplate[k].x;
  35702. referenceTemplateY[k] = referenceTemplate[k].y;
  35703. }
  35704. var referenceWidth = referenceBitmap[0].length;
  35705. var referenceHeight = referenceBitmap.length;
  35706. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35707. var bitmap = [];
  35708. var decoder = decodingContext.decoder;
  35709. var contexts = decodingContext.contextCache.getContexts('GR');
  35710. var ltp = 0;
  35711. for (var i = 0; i < height; i++) {
  35712. if (prediction) {
  35713. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35714. ltp ^= sltp;
  35715. if (ltp) {
  35716. error('JBIG2 error: prediction is not supported');
  35717. }
  35718. }
  35719. var row = new Uint8Array(width);
  35720. bitmap.push(row);
  35721. for (var j = 0; j < width; j++) {
  35722. var i0, j0;
  35723. var contextLabel = 0;
  35724. for (k = 0; k < codingTemplateLength; k++) {
  35725. i0 = i + codingTemplateY[k];
  35726. j0 = j + codingTemplateX[k];
  35727. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35728. contextLabel <<= 1; // out of bound pixel
  35729. } else {
  35730. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35731. }
  35732. }
  35733. for (k = 0; k < referenceTemplateLength; k++) {
  35734. i0 = i + referenceTemplateY[k] + offsetY;
  35735. j0 = j + referenceTemplateX[k] + offsetX;
  35736. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35737. j0 >= referenceWidth) {
  35738. contextLabel <<= 1; // out of bound pixel
  35739. } else {
  35740. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35741. }
  35742. }
  35743. var pixel = decoder.readBit(contexts, contextLabel);
  35744. row[j] = pixel;
  35745. }
  35746. }
  35747. return bitmap;
  35748. }
  35749. // 6.5.5 Decoding the symbol dictionary
  35750. function decodeSymbolDictionary(huffman, refinement, symbols,
  35751. numberOfNewSymbols, numberOfExportedSymbols,
  35752. huffmanTables, templateIndex, at,
  35753. refinementTemplateIndex, refinementAt,
  35754. decodingContext) {
  35755. if (huffman) {
  35756. error('JBIG2 error: huffman is not supported');
  35757. }
  35758. var newSymbols = [];
  35759. var currentHeight = 0;
  35760. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35761. var decoder = decodingContext.decoder;
  35762. var contextCache = decodingContext.contextCache;
  35763. while (newSymbols.length < numberOfNewSymbols) {
  35764. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35765. currentHeight += deltaHeight;
  35766. var currentWidth = 0;
  35767. var totalWidth = 0;
  35768. while (true) {
  35769. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35770. if (deltaWidth === null) {
  35771. break; // OOB
  35772. }
  35773. currentWidth += deltaWidth;
  35774. totalWidth += currentWidth;
  35775. var bitmap;
  35776. if (refinement) {
  35777. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35778. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35779. if (numberOfInstances > 1) {
  35780. bitmap = decodeTextRegion(huffman, refinement,
  35781. currentWidth, currentHeight, 0,
  35782. numberOfInstances, 1, //strip size
  35783. symbols.concat(newSymbols),
  35784. symbolCodeLength,
  35785. 0, //transposed
  35786. 0, //ds offset
  35787. 1, //top left 7.4.3.1.1
  35788. 0, //OR operator
  35789. huffmanTables,
  35790. refinementTemplateIndex, refinementAt,
  35791. decodingContext);
  35792. } else {
  35793. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35794. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35795. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35796. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35797. newSymbols[symbolId - symbols.length]);
  35798. bitmap = decodeRefinement(currentWidth, currentHeight,
  35799. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35800. decodingContext);
  35801. }
  35802. } else {
  35803. // 6.5.8.1 Direct-coded symbol bitmap
  35804. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35805. templateIndex, false, null, at, decodingContext);
  35806. }
  35807. newSymbols.push(bitmap);
  35808. }
  35809. }
  35810. // 6.5.10 Exported symbols
  35811. var exportedSymbols = [];
  35812. var flags = [], currentFlag = false;
  35813. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35814. while (flags.length < totalSymbolsLength) {
  35815. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35816. while (runLength--) {
  35817. flags.push(currentFlag);
  35818. }
  35819. currentFlag = !currentFlag;
  35820. }
  35821. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35822. if (flags[i]) {
  35823. exportedSymbols.push(symbols[i]);
  35824. }
  35825. }
  35826. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35827. if (flags[i]) {
  35828. exportedSymbols.push(newSymbols[j]);
  35829. }
  35830. }
  35831. return exportedSymbols;
  35832. }
  35833. function decodeTextRegion(huffman, refinement, width, height,
  35834. defaultPixelValue, numberOfSymbolInstances,
  35835. stripSize, inputSymbols, symbolCodeLength,
  35836. transposed, dsOffset, referenceCorner,
  35837. combinationOperator, huffmanTables,
  35838. refinementTemplateIndex, refinementAt,
  35839. decodingContext) {
  35840. if (huffman) {
  35841. error('JBIG2 error: huffman is not supported');
  35842. }
  35843. // Prepare bitmap
  35844. var bitmap = [];
  35845. var i, row;
  35846. for (i = 0; i < height; i++) {
  35847. row = new Uint8Array(width);
  35848. if (defaultPixelValue) {
  35849. for (var j = 0; j < width; j++) {
  35850. row[j] = defaultPixelValue;
  35851. }
  35852. }
  35853. bitmap.push(row);
  35854. }
  35855. var decoder = decodingContext.decoder;
  35856. var contextCache = decodingContext.contextCache;
  35857. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35858. var firstS = 0;
  35859. i = 0;
  35860. while (i < numberOfSymbolInstances) {
  35861. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35862. stripT += deltaT;
  35863. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35864. firstS += deltaFirstS;
  35865. var currentS = firstS;
  35866. do {
  35867. var currentT = (stripSize === 1 ? 0 :
  35868. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35869. var t = stripSize * stripT + currentT;
  35870. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35871. var applyRefinement = (refinement &&
  35872. decodeInteger(contextCache, 'IARI', decoder));
  35873. var symbolBitmap = inputSymbols[symbolId];
  35874. var symbolWidth = symbolBitmap[0].length;
  35875. var symbolHeight = symbolBitmap.length;
  35876. if (applyRefinement) {
  35877. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35878. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35879. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35880. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35881. symbolWidth += rdw;
  35882. symbolHeight += rdh;
  35883. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35884. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35885. (rdh >> 1) + rdy, false, refinementAt,
  35886. decodingContext);
  35887. }
  35888. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35889. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35890. var s2, t2, symbolRow;
  35891. if (transposed) {
  35892. // Place Symbol Bitmap from T1,S1
  35893. for (s2 = 0; s2 < symbolHeight; s2++) {
  35894. row = bitmap[offsetS + s2];
  35895. if (!row) {
  35896. continue;
  35897. }
  35898. symbolRow = symbolBitmap[s2];
  35899. // To ignore Parts of Symbol bitmap which goes
  35900. // outside bitmap region
  35901. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35902. switch (combinationOperator) {
  35903. case 0: // OR
  35904. for (t2 = 0; t2 < maxWidth; t2++) {
  35905. row[offsetT + t2] |= symbolRow[t2];
  35906. }
  35907. break;
  35908. case 2: // XOR
  35909. for (t2 = 0; t2 < maxWidth; t2++) {
  35910. row[offsetT + t2] ^= symbolRow[t2];
  35911. }
  35912. break;
  35913. default:
  35914. error('JBIG2 error: operator ' + combinationOperator +
  35915. ' is not supported');
  35916. }
  35917. }
  35918. currentS += symbolHeight - 1;
  35919. } else {
  35920. for (t2 = 0; t2 < symbolHeight; t2++) {
  35921. row = bitmap[offsetT + t2];
  35922. if (!row) {
  35923. continue;
  35924. }
  35925. symbolRow = symbolBitmap[t2];
  35926. switch (combinationOperator) {
  35927. case 0: // OR
  35928. for (s2 = 0; s2 < symbolWidth; s2++) {
  35929. row[offsetS + s2] |= symbolRow[s2];
  35930. }
  35931. break;
  35932. case 2: // XOR
  35933. for (s2 = 0; s2 < symbolWidth; s2++) {
  35934. row[offsetS + s2] ^= symbolRow[s2];
  35935. }
  35936. break;
  35937. default:
  35938. error('JBIG2 error: operator ' + combinationOperator +
  35939. ' is not supported');
  35940. }
  35941. }
  35942. currentS += symbolWidth - 1;
  35943. }
  35944. i++;
  35945. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35946. if (deltaS === null) {
  35947. break; // OOB
  35948. }
  35949. currentS += deltaS + dsOffset;
  35950. } while (true);
  35951. }
  35952. return bitmap;
  35953. }
  35954. function readSegmentHeader(data, start) {
  35955. var segmentHeader = {};
  35956. segmentHeader.number = readUint32(data, start);
  35957. var flags = data[start + 4];
  35958. var segmentType = flags & 0x3F;
  35959. if (!SegmentTypes[segmentType]) {
  35960. error('JBIG2 error: invalid segment type: ' + segmentType);
  35961. }
  35962. segmentHeader.type = segmentType;
  35963. segmentHeader.typeName = SegmentTypes[segmentType];
  35964. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35965. var pageAssociationFieldSize = !!(flags & 0x40);
  35966. var referredFlags = data[start + 5];
  35967. var referredToCount = (referredFlags >> 5) & 7;
  35968. var retainBits = [referredFlags & 31];
  35969. var position = start + 6;
  35970. if (referredFlags === 7) {
  35971. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35972. position += 3;
  35973. var bytes = (referredToCount + 7) >> 3;
  35974. retainBits[0] = data[position++];
  35975. while (--bytes > 0) {
  35976. retainBits.push(data[position++]);
  35977. }
  35978. } else if (referredFlags === 5 || referredFlags === 6) {
  35979. error('JBIG2 error: invalid referred-to flags');
  35980. }
  35981. segmentHeader.retainBits = retainBits;
  35982. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35983. (segmentHeader.number <= 65536 ? 2 : 4));
  35984. var referredTo = [];
  35985. var i, ii;
  35986. for (i = 0; i < referredToCount; i++) {
  35987. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35988. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35989. readUint32(data, position)));
  35990. referredTo.push(number);
  35991. position += referredToSegmentNumberSize;
  35992. }
  35993. segmentHeader.referredTo = referredTo;
  35994. if (!pageAssociationFieldSize) {
  35995. segmentHeader.pageAssociation = data[position++];
  35996. } else {
  35997. segmentHeader.pageAssociation = readUint32(data, position);
  35998. position += 4;
  35999. }
  36000. segmentHeader.length = readUint32(data, position);
  36001. position += 4;
  36002. if (segmentHeader.length === 0xFFFFFFFF) {
  36003. // 7.2.7 Segment data length, unknown segment length
  36004. if (segmentType === 38) { // ImmediateGenericRegion
  36005. var genericRegionInfo = readRegionSegmentInformation(data, position);
  36006. var genericRegionSegmentFlags = data[position +
  36007. RegionSegmentInformationFieldLength];
  36008. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  36009. // searching for the segment end
  36010. var searchPatternLength = 6;
  36011. var searchPattern = new Uint8Array(searchPatternLength);
  36012. if (!genericRegionMmr) {
  36013. searchPattern[0] = 0xFF;
  36014. searchPattern[1] = 0xAC;
  36015. }
  36016. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  36017. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  36018. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  36019. searchPattern[5] = genericRegionInfo.height & 0xFF;
  36020. for (i = position, ii = data.length; i < ii; i++) {
  36021. var j = 0;
  36022. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  36023. j++;
  36024. }
  36025. if (j === searchPatternLength) {
  36026. segmentHeader.length = i + searchPatternLength;
  36027. break;
  36028. }
  36029. }
  36030. if (segmentHeader.length === 0xFFFFFFFF) {
  36031. error('JBIG2 error: segment end was not found');
  36032. }
  36033. } else {
  36034. error('JBIG2 error: invalid unknown segment length');
  36035. }
  36036. }
  36037. segmentHeader.headerEnd = position;
  36038. return segmentHeader;
  36039. }
  36040. function readSegments(header, data, start, end) {
  36041. var segments = [];
  36042. var position = start;
  36043. while (position < end) {
  36044. var segmentHeader = readSegmentHeader(data, position);
  36045. position = segmentHeader.headerEnd;
  36046. var segment = {
  36047. header: segmentHeader,
  36048. data: data
  36049. };
  36050. if (!header.randomAccess) {
  36051. segment.start = position;
  36052. position += segmentHeader.length;
  36053. segment.end = position;
  36054. }
  36055. segments.push(segment);
  36056. if (segmentHeader.type === 51) {
  36057. break; // end of file is found
  36058. }
  36059. }
  36060. if (header.randomAccess) {
  36061. for (var i = 0, ii = segments.length; i < ii; i++) {
  36062. segments[i].start = position;
  36063. position += segments[i].header.length;
  36064. segments[i].end = position;
  36065. }
  36066. }
  36067. return segments;
  36068. }
  36069. // 7.4.1 Region segment information field
  36070. function readRegionSegmentInformation(data, start) {
  36071. return {
  36072. width: readUint32(data, start),
  36073. height: readUint32(data, start + 4),
  36074. x: readUint32(data, start + 8),
  36075. y: readUint32(data, start + 12),
  36076. combinationOperator: data[start + 16] & 7
  36077. };
  36078. }
  36079. var RegionSegmentInformationFieldLength = 17;
  36080. function processSegment(segment, visitor) {
  36081. var header = segment.header;
  36082. var data = segment.data, position = segment.start, end = segment.end;
  36083. var args, at, i, atLength;
  36084. switch (header.type) {
  36085. case 0: // SymbolDictionary
  36086. // 7.4.2 Symbol dictionary segment syntax
  36087. var dictionary = {};
  36088. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36089. dictionary.huffman = !!(dictionaryFlags & 1);
  36090. dictionary.refinement = !!(dictionaryFlags & 2);
  36091. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36092. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36093. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36094. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36095. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36096. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36097. dictionary.template = (dictionaryFlags >> 10) & 3;
  36098. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36099. position += 2;
  36100. if (!dictionary.huffman) {
  36101. atLength = dictionary.template === 0 ? 4 : 1;
  36102. at = [];
  36103. for (i = 0; i < atLength; i++) {
  36104. at.push({
  36105. x: readInt8(data, position),
  36106. y: readInt8(data, position + 1)
  36107. });
  36108. position += 2;
  36109. }
  36110. dictionary.at = at;
  36111. }
  36112. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36113. at = [];
  36114. for (i = 0; i < 2; i++) {
  36115. at.push({
  36116. x: readInt8(data, position),
  36117. y: readInt8(data, position + 1)
  36118. });
  36119. position += 2;
  36120. }
  36121. dictionary.refinementAt = at;
  36122. }
  36123. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36124. position += 4;
  36125. dictionary.numberOfNewSymbols = readUint32(data, position);
  36126. position += 4;
  36127. args = [dictionary, header.number, header.referredTo,
  36128. data, position, end];
  36129. break;
  36130. case 6: // ImmediateTextRegion
  36131. case 7: // ImmediateLosslessTextRegion
  36132. var textRegion = {};
  36133. textRegion.info = readRegionSegmentInformation(data, position);
  36134. position += RegionSegmentInformationFieldLength;
  36135. var textRegionSegmentFlags = readUint16(data, position);
  36136. position += 2;
  36137. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36138. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36139. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36140. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36141. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36142. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36143. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36144. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36145. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36146. if (textRegion.huffman) {
  36147. var textRegionHuffmanFlags = readUint16(data, position);
  36148. position += 2;
  36149. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36150. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36151. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36152. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36153. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36154. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36155. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36156. textRegion.huffmanRefinementSizeSelector =
  36157. !!(textRegionHuffmanFlags & 14);
  36158. }
  36159. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36160. at = [];
  36161. for (i = 0; i < 2; i++) {
  36162. at.push({
  36163. x: readInt8(data, position),
  36164. y: readInt8(data, position + 1)
  36165. });
  36166. position += 2;
  36167. }
  36168. textRegion.refinementAt = at;
  36169. }
  36170. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36171. position += 4;
  36172. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36173. if (textRegion.huffman) {
  36174. error('JBIG2 error: huffman is not supported');
  36175. }
  36176. args = [textRegion, header.referredTo, data, position, end];
  36177. break;
  36178. case 38: // ImmediateGenericRegion
  36179. case 39: // ImmediateLosslessGenericRegion
  36180. var genericRegion = {};
  36181. genericRegion.info = readRegionSegmentInformation(data, position);
  36182. position += RegionSegmentInformationFieldLength;
  36183. var genericRegionSegmentFlags = data[position++];
  36184. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36185. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36186. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36187. if (!genericRegion.mmr) {
  36188. atLength = genericRegion.template === 0 ? 4 : 1;
  36189. at = [];
  36190. for (i = 0; i < atLength; i++) {
  36191. at.push({
  36192. x: readInt8(data, position),
  36193. y: readInt8(data, position + 1)
  36194. });
  36195. position += 2;
  36196. }
  36197. genericRegion.at = at;
  36198. }
  36199. args = [genericRegion, data, position, end];
  36200. break;
  36201. case 48: // PageInformation
  36202. var pageInfo = {
  36203. width: readUint32(data, position),
  36204. height: readUint32(data, position + 4),
  36205. resolutionX: readUint32(data, position + 8),
  36206. resolutionY: readUint32(data, position + 12)
  36207. };
  36208. if (pageInfo.height === 0xFFFFFFFF) {
  36209. delete pageInfo.height;
  36210. }
  36211. var pageSegmentFlags = data[position + 16];
  36212. var pageStripingInformatiom = readUint16(data, position + 17);
  36213. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36214. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36215. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36216. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36217. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36218. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36219. args = [pageInfo];
  36220. break;
  36221. case 49: // EndOfPage
  36222. break;
  36223. case 50: // EndOfStripe
  36224. break;
  36225. case 51: // EndOfFile
  36226. break;
  36227. case 62: // 7.4.15 defines 2 extension types which
  36228. // are comments and can be ignored.
  36229. break;
  36230. default:
  36231. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36232. header.type + ') is not implemented');
  36233. }
  36234. var callbackName = 'on' + header.typeName;
  36235. if (callbackName in visitor) {
  36236. visitor[callbackName].apply(visitor, args);
  36237. }
  36238. }
  36239. function processSegments(segments, visitor) {
  36240. for (var i = 0, ii = segments.length; i < ii; i++) {
  36241. processSegment(segments[i], visitor);
  36242. }
  36243. }
  36244. function parseJbig2(data, start, end) {
  36245. var position = start;
  36246. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36247. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36248. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36249. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36250. error('JBIG2 error: invalid header');
  36251. }
  36252. var header = {};
  36253. position += 8;
  36254. var flags = data[position++];
  36255. header.randomAccess = !(flags & 1);
  36256. if (!(flags & 2)) {
  36257. header.numberOfPages = readUint32(data, position);
  36258. position += 4;
  36259. }
  36260. var segments = readSegments(header, data, position, end);
  36261. error('Not implemented');
  36262. // processSegments(segments, new SimpleSegmentVisitor());
  36263. }
  36264. function parseJbig2Chunks(chunks) {
  36265. var visitor = new SimpleSegmentVisitor();
  36266. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36267. var chunk = chunks[i];
  36268. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36269. processSegments(segments, visitor);
  36270. }
  36271. return visitor.buffer;
  36272. }
  36273. function SimpleSegmentVisitor() {}
  36274. SimpleSegmentVisitor.prototype = {
  36275. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36276. this.currentPageInfo = info;
  36277. var rowSize = (info.width + 7) >> 3;
  36278. var buffer = new Uint8Array(rowSize * info.height);
  36279. // The contents of ArrayBuffers are initialized to 0.
  36280. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36281. if (info.defaultPixelValue) {
  36282. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36283. buffer[i] = 0xFF;
  36284. }
  36285. }
  36286. this.buffer = buffer;
  36287. },
  36288. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36289. var pageInfo = this.currentPageInfo;
  36290. var width = regionInfo.width, height = regionInfo.height;
  36291. var rowSize = (pageInfo.width + 7) >> 3;
  36292. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36293. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36294. var buffer = this.buffer;
  36295. var mask0 = 128 >> (regionInfo.x & 7);
  36296. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36297. var i, j, mask, offset;
  36298. switch (combinationOperator) {
  36299. case 0: // OR
  36300. for (i = 0; i < height; i++) {
  36301. mask = mask0;
  36302. offset = offset0;
  36303. for (j = 0; j < width; j++) {
  36304. if (bitmap[i][j]) {
  36305. buffer[offset] |= mask;
  36306. }
  36307. mask >>= 1;
  36308. if (!mask) {
  36309. mask = 128;
  36310. offset++;
  36311. }
  36312. }
  36313. offset0 += rowSize;
  36314. }
  36315. break;
  36316. case 2: // XOR
  36317. for (i = 0; i < height; i++) {
  36318. mask = mask0;
  36319. offset = offset0;
  36320. for (j = 0; j < width; j++) {
  36321. if (bitmap[i][j]) {
  36322. buffer[offset] ^= mask;
  36323. }
  36324. mask >>= 1;
  36325. if (!mask) {
  36326. mask = 128;
  36327. offset++;
  36328. }
  36329. }
  36330. offset0 += rowSize;
  36331. }
  36332. break;
  36333. default:
  36334. error('JBIG2 error: operator ' + combinationOperator +
  36335. ' is not supported');
  36336. }
  36337. },
  36338. onImmediateGenericRegion:
  36339. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36340. start, end) {
  36341. var regionInfo = region.info;
  36342. var decodingContext = new DecodingContext(data, start, end);
  36343. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36344. region.template, region.prediction, null,
  36345. region.at, decodingContext);
  36346. this.drawBitmap(regionInfo, bitmap);
  36347. },
  36348. onImmediateLosslessGenericRegion:
  36349. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36350. this.onImmediateGenericRegion.apply(this, arguments);
  36351. },
  36352. onSymbolDictionary:
  36353. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36354. currentSegment,
  36355. referredSegments,
  36356. data, start, end) {
  36357. var huffmanTables;
  36358. if (dictionary.huffman) {
  36359. error('JBIG2 error: huffman is not supported');
  36360. }
  36361. // Combines exported symbols from all referred segments
  36362. var symbols = this.symbols;
  36363. if (!symbols) {
  36364. this.symbols = symbols = {};
  36365. }
  36366. var inputSymbols = [];
  36367. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36368. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36369. }
  36370. var decodingContext = new DecodingContext(data, start, end);
  36371. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36372. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36373. dictionary.numberOfExportedSymbols, huffmanTables,
  36374. dictionary.template, dictionary.at,
  36375. dictionary.refinementTemplate, dictionary.refinementAt,
  36376. decodingContext);
  36377. },
  36378. onImmediateTextRegion:
  36379. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36380. referredSegments,
  36381. data, start, end) {
  36382. var regionInfo = region.info;
  36383. var huffmanTables;
  36384. // Combines exported symbols from all referred segments
  36385. var symbols = this.symbols;
  36386. var inputSymbols = [];
  36387. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36388. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36389. }
  36390. var symbolCodeLength = log2(inputSymbols.length);
  36391. var decodingContext = new DecodingContext(data, start, end);
  36392. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36393. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36394. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36395. symbolCodeLength, region.transposed, region.dsOffset,
  36396. region.referenceCorner, region.combinationOperator, huffmanTables,
  36397. region.refinementTemplate, region.refinementAt, decodingContext);
  36398. this.drawBitmap(regionInfo, bitmap);
  36399. },
  36400. onImmediateLosslessTextRegion:
  36401. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36402. this.onImmediateTextRegion.apply(this, arguments);
  36403. }
  36404. };
  36405. function Jbig2Image() {}
  36406. Jbig2Image.prototype = {
  36407. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36408. return parseJbig2Chunks(chunks);
  36409. }
  36410. };
  36411. return Jbig2Image;
  36412. })();
  36413. var bidi = PDFJS.bidi = (function bidiClosure() {
  36414. // Character types for symbols from 0000 to 00FF.
  36415. var baseTypes = [
  36416. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36417. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36418. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36419. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36420. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36421. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36422. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36423. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36424. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36425. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36426. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36427. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36428. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36429. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36430. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36431. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36432. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36433. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36434. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36435. ];
  36436. // Character types for symbols from 0600 to 06FF
  36437. var arabicTypes = [
  36438. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36439. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36440. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36441. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36442. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36443. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36444. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36445. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36446. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36447. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36448. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36449. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36450. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36451. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36452. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36453. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36454. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36455. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36456. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36457. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36458. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36459. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36460. ];
  36461. function isOdd(i) {
  36462. return (i & 1) !== 0;
  36463. }
  36464. function isEven(i) {
  36465. return (i & 1) === 0;
  36466. }
  36467. function findUnequal(arr, start, value) {
  36468. for (var j = start, jj = arr.length; j < jj; ++j) {
  36469. if (arr[j] !== value) {
  36470. return j;
  36471. }
  36472. }
  36473. return j;
  36474. }
  36475. function setValues(arr, start, end, value) {
  36476. for (var j = start; j < end; ++j) {
  36477. arr[j] = value;
  36478. }
  36479. }
  36480. function reverseValues(arr, start, end) {
  36481. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36482. var temp = arr[i];
  36483. arr[i] = arr[j];
  36484. arr[j] = temp;
  36485. }
  36486. }
  36487. function createBidiText(str, isLTR, vertical) {
  36488. return {
  36489. str: str,
  36490. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36491. };
  36492. }
  36493. // These are used in bidi(), which is called frequently. We re-use them on
  36494. // each call to avoid unnecessary allocations.
  36495. var chars = [];
  36496. var types = [];
  36497. function bidi(str, startLevel, vertical) {
  36498. var isLTR = true;
  36499. var strLength = str.length;
  36500. if (strLength === 0 || vertical) {
  36501. return createBidiText(str, isLTR, vertical);
  36502. }
  36503. // Get types and fill arrays
  36504. chars.length = strLength;
  36505. types.length = strLength;
  36506. var numBidi = 0;
  36507. var i, ii;
  36508. for (i = 0; i < strLength; ++i) {
  36509. chars[i] = str.charAt(i);
  36510. var charCode = str.charCodeAt(i);
  36511. var charType = 'L';
  36512. if (charCode <= 0x00ff) {
  36513. charType = baseTypes[charCode];
  36514. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36515. charType = 'R';
  36516. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36517. charType = arabicTypes[charCode & 0xff];
  36518. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36519. charType = 'AL';
  36520. }
  36521. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36522. numBidi++;
  36523. }
  36524. types[i] = charType;
  36525. }
  36526. // Detect the bidi method
  36527. // - If there are no rtl characters then no bidi needed
  36528. // - If less than 30% chars are rtl then string is primarily ltr
  36529. // - If more than 30% chars are rtl then string is primarily rtl
  36530. if (numBidi === 0) {
  36531. isLTR = true;
  36532. return createBidiText(str, isLTR);
  36533. }
  36534. if (startLevel === -1) {
  36535. if ((strLength / numBidi) < 0.3) {
  36536. isLTR = true;
  36537. startLevel = 0;
  36538. } else {
  36539. isLTR = false;
  36540. startLevel = 1;
  36541. }
  36542. }
  36543. var levels = [];
  36544. for (i = 0; i < strLength; ++i) {
  36545. levels[i] = startLevel;
  36546. }
  36547. /*
  36548. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36549. */
  36550. var e = (isOdd(startLevel) ? 'R' : 'L');
  36551. var sor = e;
  36552. var eor = sor;
  36553. /*
  36554. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36555. type of the NSM to the type of the previous character. If the NSM is at the
  36556. start of the level run, it will get the type of sor.
  36557. */
  36558. var lastType = sor;
  36559. for (i = 0; i < strLength; ++i) {
  36560. if (types[i] === 'NSM') {
  36561. types[i] = lastType;
  36562. } else {
  36563. lastType = types[i];
  36564. }
  36565. }
  36566. /*
  36567. W2. Search backwards from each instance of a European number until the
  36568. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36569. the type of the European number to Arabic number.
  36570. */
  36571. lastType = sor;
  36572. var t;
  36573. for (i = 0; i < strLength; ++i) {
  36574. t = types[i];
  36575. if (t === 'EN') {
  36576. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36577. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36578. lastType = t;
  36579. }
  36580. }
  36581. /*
  36582. W3. Change all ALs to R.
  36583. */
  36584. for (i = 0; i < strLength; ++i) {
  36585. t = types[i];
  36586. if (t === 'AL') {
  36587. types[i] = 'R';
  36588. }
  36589. }
  36590. /*
  36591. W4. A single European separator between two European numbers changes to a
  36592. European number. A single common separator between two numbers of the same
  36593. type changes to that type:
  36594. */
  36595. for (i = 1; i < strLength - 1; ++i) {
  36596. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36597. types[i] = 'EN';
  36598. }
  36599. if (types[i] === 'CS' &&
  36600. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36601. types[i + 1] === types[i - 1]) {
  36602. types[i] = types[i - 1];
  36603. }
  36604. }
  36605. /*
  36606. W5. A sequence of European terminators adjacent to European numbers changes
  36607. to all European numbers:
  36608. */
  36609. for (i = 0; i < strLength; ++i) {
  36610. if (types[i] === 'EN') {
  36611. // do before
  36612. var j;
  36613. for (j = i - 1; j >= 0; --j) {
  36614. if (types[j] !== 'ET') {
  36615. break;
  36616. }
  36617. types[j] = 'EN';
  36618. }
  36619. // do after
  36620. for (j = i + 1; j < strLength; --j) {
  36621. if (types[j] !== 'ET') {
  36622. break;
  36623. }
  36624. types[j] = 'EN';
  36625. }
  36626. }
  36627. }
  36628. /*
  36629. W6. Otherwise, separators and terminators change to Other Neutral:
  36630. */
  36631. for (i = 0; i < strLength; ++i) {
  36632. t = types[i];
  36633. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36634. types[i] = 'ON';
  36635. }
  36636. }
  36637. /*
  36638. W7. Search backwards from each instance of a European number until the
  36639. first strong type (R, L, or sor) is found. If an L is found, then change
  36640. the type of the European number to L.
  36641. */
  36642. lastType = sor;
  36643. for (i = 0; i < strLength; ++i) {
  36644. t = types[i];
  36645. if (t === 'EN') {
  36646. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36647. } else if (t === 'R' || t === 'L') {
  36648. lastType = t;
  36649. }
  36650. }
  36651. /*
  36652. N1. A sequence of neutrals takes the direction of the surrounding strong
  36653. text if the text on both sides has the same direction. European and Arabic
  36654. numbers are treated as though they were R. Start-of-level-run (sor) and
  36655. end-of-level-run (eor) are used at level run boundaries.
  36656. */
  36657. for (i = 0; i < strLength; ++i) {
  36658. if (types[i] === 'ON') {
  36659. var end = findUnequal(types, i + 1, 'ON');
  36660. var before = sor;
  36661. if (i > 0) {
  36662. before = types[i - 1];
  36663. }
  36664. var after = eor;
  36665. if (end + 1 < strLength) {
  36666. after = types[end + 1];
  36667. }
  36668. if (before !== 'L') {
  36669. before = 'R';
  36670. }
  36671. if (after !== 'L') {
  36672. after = 'R';
  36673. }
  36674. if (before === after) {
  36675. setValues(types, i, end, before);
  36676. }
  36677. i = end - 1; // reset to end (-1 so next iteration is ok)
  36678. }
  36679. }
  36680. /*
  36681. N2. Any remaining neutrals take the embedding direction.
  36682. */
  36683. for (i = 0; i < strLength; ++i) {
  36684. if (types[i] === 'ON') {
  36685. types[i] = e;
  36686. }
  36687. }
  36688. /*
  36689. I1. For all characters with an even (left-to-right) embedding direction,
  36690. those of type R go up one level and those of type AN or EN go up two
  36691. levels.
  36692. I2. For all characters with an odd (right-to-left) embedding direction,
  36693. those of type L, EN or AN go up one level.
  36694. */
  36695. for (i = 0; i < strLength; ++i) {
  36696. t = types[i];
  36697. if (isEven(levels[i])) {
  36698. if (t === 'R') {
  36699. levels[i] += 1;
  36700. } else if (t === 'AN' || t === 'EN') {
  36701. levels[i] += 2;
  36702. }
  36703. } else { // isOdd
  36704. if (t === 'L' || t === 'AN' || t === 'EN') {
  36705. levels[i] += 1;
  36706. }
  36707. }
  36708. }
  36709. /*
  36710. L1. On each line, reset the embedding level of the following characters to
  36711. the paragraph embedding level:
  36712. segment separators,
  36713. paragraph separators,
  36714. any sequence of whitespace characters preceding a segment separator or
  36715. paragraph separator, and any sequence of white space characters at the end
  36716. of the line.
  36717. */
  36718. // don't bother as text is only single line
  36719. /*
  36720. L2. From the highest level found in the text to the lowest odd level on
  36721. each line, reverse any contiguous sequence of characters that are at that
  36722. level or higher.
  36723. */
  36724. // find highest level & lowest odd level
  36725. var highestLevel = -1;
  36726. var lowestOddLevel = 99;
  36727. var level;
  36728. for (i = 0, ii = levels.length; i < ii; ++i) {
  36729. level = levels[i];
  36730. if (highestLevel < level) {
  36731. highestLevel = level;
  36732. }
  36733. if (lowestOddLevel > level && isOdd(level)) {
  36734. lowestOddLevel = level;
  36735. }
  36736. }
  36737. // now reverse between those limits
  36738. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36739. // find segments to reverse
  36740. var start = -1;
  36741. for (i = 0, ii = levels.length; i < ii; ++i) {
  36742. if (levels[i] < level) {
  36743. if (start >= 0) {
  36744. reverseValues(chars, start, i);
  36745. start = -1;
  36746. }
  36747. } else if (start < 0) {
  36748. start = i;
  36749. }
  36750. }
  36751. if (start >= 0) {
  36752. reverseValues(chars, start, levels.length);
  36753. }
  36754. }
  36755. /*
  36756. L3. Combining marks applied to a right-to-left base character will at this
  36757. point precede their base character. If the rendering engine expects them to
  36758. follow the base characters in the final display process, then the ordering
  36759. of the marks and the base character must be reversed.
  36760. */
  36761. // don't bother for now
  36762. /*
  36763. L4. A character that possesses the mirrored property as specified by
  36764. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36765. directionality of that character is R.
  36766. */
  36767. // don't mirror as characters are already mirrored in the pdf
  36768. // Finally, return string
  36769. var result = '';
  36770. for (i = 0, ii = chars.length; i < ii; ++i) {
  36771. var ch = chars[i];
  36772. if (ch !== '<' && ch !== '>') {
  36773. result += ch;
  36774. }
  36775. }
  36776. return createBidiText(result, isLTR);
  36777. }
  36778. return bidi;
  36779. })();
  36780. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36781. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36782. /* Copyright 2014 Opera Software ASA
  36783. *
  36784. * Licensed under the Apache License, Version 2.0 (the "License");
  36785. * you may not use this file except in compliance with the License.
  36786. * You may obtain a copy of the License at
  36787. *
  36788. * http://www.apache.org/licenses/LICENSE-2.0
  36789. *
  36790. * Unless required by applicable law or agreed to in writing, software
  36791. * distributed under the License is distributed on an "AS IS" BASIS,
  36792. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36793. * See the License for the specific language governing permissions and
  36794. * limitations under the License.
  36795. *
  36796. *
  36797. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36798. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36799. */
  36800. /* globals Uint32ArrayView */
  36801. 'use strict';
  36802. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36803. // Workaround for missing math precison in JS.
  36804. var MASK_HIGH = 0xffff0000;
  36805. var MASK_LOW = 0xffff;
  36806. function MurmurHash3_64 (seed) {
  36807. var SEED = 0xc3d2e1f0;
  36808. this.h1 = seed ? seed & 0xffffffff : SEED;
  36809. this.h2 = seed ? seed & 0xffffffff : SEED;
  36810. }
  36811. var alwaysUseUint32ArrayView = false;
  36812. // old webkits have issues with non-aligned arrays
  36813. try {
  36814. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36815. } catch (e) {
  36816. alwaysUseUint32ArrayView = true;
  36817. }
  36818. MurmurHash3_64.prototype = {
  36819. update: function MurmurHash3_64_update(input) {
  36820. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36821. var i;
  36822. if (typeof input === 'string') {
  36823. var data = new Uint8Array(input.length * 2);
  36824. var length = 0;
  36825. for (i = 0; i < input.length; i++) {
  36826. var code = input.charCodeAt(i);
  36827. if (code <= 0xff) {
  36828. data[length++] = code;
  36829. }
  36830. else {
  36831. data[length++] = code >>> 8;
  36832. data[length++] = code & 0xff;
  36833. }
  36834. }
  36835. } else if (input instanceof Uint8Array) {
  36836. data = input;
  36837. length = data.length;
  36838. } else if (typeof input === 'object' && ('length' in input)) {
  36839. // processing regular arrays as well, e.g. for IE9
  36840. data = input;
  36841. length = data.length;
  36842. useUint32ArrayView = true;
  36843. } else {
  36844. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36845. 'Input must be a string or array.');
  36846. }
  36847. var blockCounts = length >> 2;
  36848. var tailLength = length - blockCounts * 4;
  36849. // we don't care about endianness here
  36850. var dataUint32 = useUint32ArrayView ?
  36851. new Uint32ArrayView(data, blockCounts) :
  36852. new Uint32Array(data.buffer, 0, blockCounts);
  36853. var k1 = 0;
  36854. var k2 = 0;
  36855. var h1 = this.h1;
  36856. var h2 = this.h2;
  36857. var C1 = 0xcc9e2d51;
  36858. var C2 = 0x1b873593;
  36859. var C1_LOW = C1 & MASK_LOW;
  36860. var C2_LOW = C2 & MASK_LOW;
  36861. for (i = 0; i < blockCounts; i++) {
  36862. if (i & 1) {
  36863. k1 = dataUint32[i];
  36864. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36865. k1 = k1 << 15 | k1 >>> 17;
  36866. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36867. h1 ^= k1;
  36868. h1 = h1 << 13 | h1 >>> 19;
  36869. h1 = h1 * 5 + 0xe6546b64;
  36870. } else {
  36871. k2 = dataUint32[i];
  36872. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36873. k2 = k2 << 15 | k2 >>> 17;
  36874. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36875. h2 ^= k2;
  36876. h2 = h2 << 13 | h2 >>> 19;
  36877. h2 = h2 * 5 + 0xe6546b64;
  36878. }
  36879. }
  36880. k1 = 0;
  36881. switch (tailLength) {
  36882. case 3:
  36883. k1 ^= data[blockCounts * 4 + 2] << 16;
  36884. /* falls through */
  36885. case 2:
  36886. k1 ^= data[blockCounts * 4 + 1] << 8;
  36887. /* falls through */
  36888. case 1:
  36889. k1 ^= data[blockCounts * 4];
  36890. /* falls through */
  36891. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36892. k1 = k1 << 15 | k1 >>> 17;
  36893. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36894. if (blockCounts & 1) {
  36895. h1 ^= k1;
  36896. } else {
  36897. h2 ^= k1;
  36898. }
  36899. }
  36900. this.h1 = h1;
  36901. this.h2 = h2;
  36902. return this;
  36903. },
  36904. hexdigest: function MurmurHash3_64_hexdigest () {
  36905. var h1 = this.h1;
  36906. var h2 = this.h2;
  36907. h1 ^= h2 >>> 1;
  36908. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36909. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36910. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36911. h1 ^= h2 >>> 1;
  36912. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36913. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36914. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36915. h1 ^= h2 >>> 1;
  36916. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36917. var hex = (arr[i] >>> 0).toString(16);
  36918. while (hex.length < 8) {
  36919. hex = '0' + hex;
  36920. }
  36921. str += hex;
  36922. }
  36923. return str;
  36924. }
  36925. };
  36926. return MurmurHash3_64;
  36927. })();
  36928. }).call((typeof window === 'undefined') ? this : window);
  36929. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36930. // workerSrc is not set -- using last script url to define default location
  36931. PDFJS.workerSrc = (function () {
  36932. 'use strict';
  36933. var scriptTagContainer = document.body ||
  36934. document.getElementsByTagName('head')[0];
  36935. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36936. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36937. })();
  36938. }